Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

858 lines
32KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. } // (juce namespace)
  18. extern juce::JUCEApplicationBase* juce_CreateApplication(); // (from START_JUCE_APPLICATION)
  19. namespace juce
  20. {
  21. //==============================================================================
  22. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* env, jobject activity,
  23. jstring appFile, jstring appDataDir))
  24. {
  25. android.initialise (env, activity, appFile, appDataDir);
  26. DBG (SystemStats::getJUCEVersion());
  27. JUCEApplicationBase::createInstance = &juce_CreateApplication;
  28. initialiseJuce_GUI();
  29. if (JUCEApplicationBase* app = JUCEApplicationBase::createInstance())
  30. {
  31. if (! app->initialiseApp())
  32. exit (app->shutdownApp());
  33. }
  34. else
  35. {
  36. jassertfalse; // you must supply an application object for an android app!
  37. }
  38. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  39. }
  40. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, suspendApp, void, (JNIEnv* env, jobject activity))
  41. {
  42. if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
  43. app->suspended();
  44. }
  45. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, resumeApp, void, (JNIEnv* env, jobject activity))
  46. {
  47. if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
  48. app->resumed();
  49. }
  50. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity))
  51. {
  52. JUCEApplicationBase::appWillTerminateByForce();
  53. android.shutdown (env);
  54. }
  55. //==============================================================================
  56. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
  57. METHOD (drawBitmap, "drawBitmap", "([IIIFFIIZLandroid/graphics/Paint;)V") \
  58. METHOD (getClipBounds, "getClipBounds", "()Landroid/graphics/Rect;")
  59. DECLARE_JNI_CLASS (CanvasMinimal, "android/graphics/Canvas");
  60. #undef JNI_CLASS_MEMBERS
  61. //==============================================================================
  62. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
  63. METHOD (setViewName, "setViewName", "(Ljava/lang/String;)V") \
  64. METHOD (layout, "layout", "(IIII)V") \
  65. METHOD (getLeft, "getLeft", "()I") \
  66. METHOD (getTop, "getTop", "()I") \
  67. METHOD (getWidth, "getWidth", "()I") \
  68. METHOD (getHeight, "getHeight", "()I") \
  69. METHOD (getLocationOnScreen, "getLocationOnScreen", "([I)V") \
  70. METHOD (bringToFront, "bringToFront", "()V") \
  71. METHOD (requestFocus, "requestFocus", "()Z") \
  72. METHOD (setVisible, "setVisible", "(Z)V") \
  73. METHOD (isVisible, "isVisible", "()Z") \
  74. METHOD (hasFocus, "hasFocus", "()Z") \
  75. METHOD (invalidate, "invalidate", "(IIII)V") \
  76. METHOD (containsPoint, "containsPoint", "(II)Z") \
  77. METHOD (showKeyboard, "showKeyboard", "(Ljava/lang/String;)V") \
  78. METHOD (createGLView, "createGLView", "()L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView;") \
  79. DECLARE_JNI_CLASS (ComponentPeerView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView");
  80. #undef JNI_CLASS_MEMBERS
  81. //==============================================================================
  82. class AndroidComponentPeer : public ComponentPeer
  83. {
  84. public:
  85. AndroidComponentPeer (Component& comp, const int windowStyleFlags)
  86. : ComponentPeer (comp, windowStyleFlags),
  87. usingAndroidGraphics (false),
  88. fullScreen (false),
  89. sizeAllocated (0),
  90. scale ((float) Desktop::getInstance().getDisplays().getMainDisplay().scale)
  91. {
  92. // NB: must not put this in the initialiser list, as it invokes a callback,
  93. // which will fail if the peer is only half-constructed.
  94. view = GlobalRef (android.activity.callObjectMethod (JuceAppActivity.createNewView,
  95. (jboolean) component.isOpaque(),
  96. (jlong) this));
  97. if (isFocused())
  98. handleFocusGain();
  99. }
  100. ~AndroidComponentPeer()
  101. {
  102. if (MessageManager::getInstance()->isThisTheMessageThread())
  103. {
  104. android.activity.callVoidMethod (JuceAppActivity.deleteView, view.get());
  105. }
  106. else
  107. {
  108. struct ViewDeleter : public CallbackMessage
  109. {
  110. ViewDeleter (const GlobalRef& view_) : view (view_) {}
  111. void messageCallback() override
  112. {
  113. android.activity.callVoidMethod (JuceAppActivity.deleteView, view.get());
  114. }
  115. private:
  116. GlobalRef view;
  117. };
  118. (new ViewDeleter (view))->post();
  119. }
  120. view.clear();
  121. }
  122. void* getNativeHandle() const override
  123. {
  124. return (void*) view.get();
  125. }
  126. void setVisible (bool shouldBeVisible) override
  127. {
  128. if (MessageManager::getInstance()->isThisTheMessageThread())
  129. {
  130. view.callVoidMethod (ComponentPeerView.setVisible, shouldBeVisible);
  131. }
  132. else
  133. {
  134. struct VisibilityChanger : public CallbackMessage
  135. {
  136. VisibilityChanger (const GlobalRef& view_, bool shouldBeVisible_)
  137. : view (view_), shouldBeVisible (shouldBeVisible_)
  138. {}
  139. void messageCallback() override
  140. {
  141. view.callVoidMethod (ComponentPeerView.setVisible, shouldBeVisible);
  142. }
  143. private:
  144. GlobalRef view;
  145. bool shouldBeVisible;
  146. };
  147. (new VisibilityChanger (view, shouldBeVisible))->post();
  148. }
  149. }
  150. void setTitle (const String& title) override
  151. {
  152. view.callVoidMethod (ComponentPeerView.setViewName, javaString (title).get());
  153. }
  154. void setBounds (const Rectangle<int>& userRect, bool isNowFullScreen) override
  155. {
  156. Rectangle<int> r = userRect * scale;
  157. if (MessageManager::getInstance()->isThisTheMessageThread())
  158. {
  159. fullScreen = isNowFullScreen;
  160. view.callVoidMethod (ComponentPeerView.layout,
  161. r.getX(), r.getY(), r.getRight(), r.getBottom());
  162. }
  163. else
  164. {
  165. class ViewMover : public CallbackMessage
  166. {
  167. public:
  168. ViewMover (const GlobalRef& v, const Rectangle<int>& r) : view (v), bounds (r) {}
  169. void messageCallback() override
  170. {
  171. view.callVoidMethod (ComponentPeerView.layout,
  172. bounds.getX(), bounds.getY(), bounds.getRight(), bounds.getBottom());
  173. }
  174. private:
  175. GlobalRef view;
  176. Rectangle<int> bounds;
  177. };
  178. (new ViewMover (view, r))->post();
  179. }
  180. }
  181. Rectangle<int> getBounds() const override
  182. {
  183. return Rectangle<int> (view.callIntMethod (ComponentPeerView.getLeft),
  184. view.callIntMethod (ComponentPeerView.getTop),
  185. view.callIntMethod (ComponentPeerView.getWidth),
  186. view.callIntMethod (ComponentPeerView.getHeight)) / scale;
  187. }
  188. void handleScreenSizeChange()
  189. {
  190. ComponentPeer::handleScreenSizeChange();
  191. if (isFullScreen())
  192. setFullScreen (true);
  193. }
  194. Point<int> getScreenPosition() const
  195. {
  196. return Point<int> (view.callIntMethod (ComponentPeerView.getLeft),
  197. view.callIntMethod (ComponentPeerView.getTop)) / scale;
  198. }
  199. Point<float> localToGlobal (Point<float> relativePosition) override
  200. {
  201. return relativePosition + getScreenPosition().toFloat();
  202. }
  203. Point<float> globalToLocal (Point<float> screenPosition) override
  204. {
  205. return screenPosition - getScreenPosition().toFloat();
  206. }
  207. void setMinimised (bool shouldBeMinimised) override
  208. {
  209. // n/a
  210. }
  211. bool isMinimised() const override
  212. {
  213. return false;
  214. }
  215. void setFullScreen (bool shouldBeFullScreen) override
  216. {
  217. Rectangle<int> r (shouldBeFullScreen ? Desktop::getInstance().getDisplays().getMainDisplay().userArea
  218. : lastNonFullscreenBounds);
  219. if ((! shouldBeFullScreen) && r.isEmpty())
  220. r = getBounds();
  221. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  222. if (! r.isEmpty())
  223. setBounds (r, shouldBeFullScreen);
  224. component.repaint();
  225. }
  226. bool isFullScreen() const override
  227. {
  228. return fullScreen;
  229. }
  230. void setIcon (const Image& newIcon) override
  231. {
  232. // n/a
  233. }
  234. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  235. {
  236. return isPositiveAndBelow (localPos.x, component.getWidth())
  237. && isPositiveAndBelow (localPos.y, component.getHeight())
  238. && ((! trueIfInAChildWindow) || view.callBooleanMethod (ComponentPeerView.containsPoint,
  239. localPos.x * scale,
  240. localPos.y * scale));
  241. }
  242. BorderSize<int> getFrameSize() const override
  243. {
  244. // TODO
  245. return BorderSize<int>();
  246. }
  247. bool setAlwaysOnTop (bool alwaysOnTop) override
  248. {
  249. // TODO
  250. return false;
  251. }
  252. void toFront (bool makeActive) override
  253. {
  254. view.callVoidMethod (ComponentPeerView.bringToFront);
  255. if (makeActive)
  256. grabFocus();
  257. handleBroughtToFront();
  258. }
  259. void toBehind (ComponentPeer* other) override
  260. {
  261. // TODO
  262. }
  263. //==============================================================================
  264. void handleMouseDownCallback (int index, Point<float> sysPos, int64 time)
  265. {
  266. Point<float> pos = sysPos / scale;
  267. lastMousePos = pos;
  268. // this forces a mouse-enter/up event, in case for some reason we didn't get a mouse-up before.
  269. handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons(), time);
  270. if (isValidPeer (this))
  271. handleMouseDragCallback (index, sysPos, time);
  272. }
  273. void handleMouseDragCallback (int index, Point<float> pos, int64 time)
  274. {
  275. pos /= scale;
  276. lastMousePos = pos;
  277. jassert (index < 64);
  278. touchesDown = (touchesDown | (1 << (index & 63)));
  279. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  280. handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons()
  281. .withFlags (ModifierKeys::leftButtonModifier), time);
  282. }
  283. void handleMouseUpCallback (int index, Point<float> pos, int64 time)
  284. {
  285. pos /= scale;
  286. lastMousePos = pos;
  287. jassert (index < 64);
  288. touchesDown = (touchesDown & ~(1 << (index & 63)));
  289. if (touchesDown == 0)
  290. currentModifiers = currentModifiers.withoutMouseButtons();
  291. handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons(), time);
  292. }
  293. void handleKeyDownCallback (int k, int kc)
  294. {
  295. handleKeyPress (k, kc);
  296. }
  297. void handleKeyUpCallback (int k, int kc)
  298. {
  299. }
  300. //==============================================================================
  301. bool isFocused() const override
  302. {
  303. return view.callBooleanMethod (ComponentPeerView.hasFocus);
  304. }
  305. void grabFocus() override
  306. {
  307. view.callBooleanMethod (ComponentPeerView.requestFocus);
  308. }
  309. void handleFocusChangeCallback (bool hasFocus)
  310. {
  311. if (hasFocus)
  312. handleFocusGain();
  313. else
  314. handleFocusLoss();
  315. }
  316. static const char* getVirtualKeyboardType (TextInputTarget::VirtualKeyboardType type) noexcept
  317. {
  318. switch (type)
  319. {
  320. case TextInputTarget::textKeyboard: return "text";
  321. case TextInputTarget::numericKeyboard: return "number";
  322. case TextInputTarget::decimalKeyboard: return "numberDecimal";
  323. case TextInputTarget::urlKeyboard: return "textUri";
  324. case TextInputTarget::emailAddressKeyboard: return "textEmailAddress";
  325. case TextInputTarget::phoneNumberKeyboard: return "phone";
  326. default: jassertfalse; break;
  327. }
  328. return "text";
  329. }
  330. void textInputRequired (Point<int>, TextInputTarget& target) override
  331. {
  332. view.callVoidMethod (ComponentPeerView.showKeyboard,
  333. javaString (getVirtualKeyboardType (target.getKeyboardType())).get());
  334. }
  335. void dismissPendingTextInput() override
  336. {
  337. view.callVoidMethod (ComponentPeerView.showKeyboard, javaString ("").get());
  338. }
  339. //==============================================================================
  340. void handlePaintCallback (JNIEnv* env, jobject canvas, jobject paint)
  341. {
  342. jobject rect = env->CallObjectMethod (canvas, CanvasMinimal.getClipBounds);
  343. const int left = env->GetIntField (rect, RectClass.left);
  344. const int top = env->GetIntField (rect, RectClass.top);
  345. const int right = env->GetIntField (rect, RectClass.right);
  346. const int bottom = env->GetIntField (rect, RectClass.bottom);
  347. env->DeleteLocalRef (rect);
  348. const Rectangle<int> clip (left, top, right - left, bottom - top);
  349. const int sizeNeeded = clip.getWidth() * clip.getHeight();
  350. if (sizeAllocated < sizeNeeded)
  351. {
  352. buffer.clear();
  353. sizeAllocated = sizeNeeded;
  354. buffer = GlobalRef (env->NewIntArray (sizeNeeded));
  355. }
  356. if (jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0))
  357. {
  358. {
  359. Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(),
  360. dest, ! component.isOpaque()));
  361. {
  362. LowLevelGraphicsSoftwareRenderer g (temp);
  363. g.setOrigin (-clip.getPosition());
  364. g.addTransform (AffineTransform::scale (scale));
  365. handlePaint (g);
  366. }
  367. }
  368. env->ReleaseIntArrayElements ((jintArray) buffer.get(), dest, 0);
  369. env->CallVoidMethod (canvas, CanvasMinimal.drawBitmap, (jintArray) buffer.get(), 0, clip.getWidth(),
  370. (jfloat) clip.getX(), (jfloat) clip.getY(),
  371. clip.getWidth(), clip.getHeight(), true, paint);
  372. }
  373. }
  374. void repaint (const Rectangle<int>& userArea) override
  375. {
  376. Rectangle<int> area = userArea * scale;
  377. if (MessageManager::getInstance()->isThisTheMessageThread())
  378. {
  379. view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom());
  380. }
  381. else
  382. {
  383. struct ViewRepainter : public CallbackMessage
  384. {
  385. ViewRepainter (const GlobalRef& view_, const Rectangle<int>& area_)
  386. : view (view_), area (area_) {}
  387. void messageCallback() override
  388. {
  389. view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(),
  390. area.getRight(), area.getBottom());
  391. }
  392. private:
  393. GlobalRef view;
  394. const Rectangle<int> area;
  395. };
  396. (new ViewRepainter (view, area))->post();
  397. }
  398. }
  399. void performAnyPendingRepaintsNow() override
  400. {
  401. // TODO
  402. }
  403. void setAlpha (float newAlpha) override
  404. {
  405. // TODO
  406. }
  407. StringArray getAvailableRenderingEngines() override
  408. {
  409. return StringArray ("Software Renderer");
  410. }
  411. //==============================================================================
  412. static ModifierKeys currentModifiers;
  413. static Point<float> lastMousePos;
  414. static int64 touchesDown;
  415. private:
  416. //==============================================================================
  417. GlobalRef view;
  418. GlobalRef buffer;
  419. bool usingAndroidGraphics, fullScreen;
  420. int sizeAllocated;
  421. float scale;
  422. class PreallocatedImage : public ImagePixelData
  423. {
  424. public:
  425. PreallocatedImage (const int width_, const int height_, jint* data_, bool hasAlpha_)
  426. : ImagePixelData (Image::ARGB, width_, height_), data (data_), hasAlpha (hasAlpha_)
  427. {
  428. if (hasAlpha_)
  429. zeromem (data_, width * height * sizeof (jint));
  430. }
  431. ~PreallocatedImage()
  432. {
  433. if (hasAlpha)
  434. {
  435. PixelARGB* pix = (PixelARGB*) data;
  436. for (int i = width * height; --i >= 0;)
  437. {
  438. pix->unpremultiply();
  439. ++pix;
  440. }
  441. }
  442. }
  443. ImageType* createType() const override { return new SoftwareImageType(); }
  444. LowLevelGraphicsContext* createLowLevelContext() override { return new LowLevelGraphicsSoftwareRenderer (Image (this)); }
  445. void initialiseBitmapData (Image::BitmapData& bm, int x, int y, Image::BitmapData::ReadWriteMode mode)
  446. {
  447. bm.lineStride = width * sizeof (jint);
  448. bm.pixelStride = sizeof (jint);
  449. bm.pixelFormat = Image::ARGB;
  450. bm.data = (uint8*) (data + x + y * width);
  451. }
  452. ImagePixelData* clone()
  453. {
  454. PreallocatedImage* s = new PreallocatedImage (width, height, 0, hasAlpha);
  455. s->allocatedData.malloc (sizeof (jint) * width * height);
  456. s->data = s->allocatedData;
  457. memcpy (s->data, data, sizeof (jint) * width * height);
  458. return s;
  459. }
  460. private:
  461. jint* data;
  462. HeapBlock<jint> allocatedData;
  463. bool hasAlpha;
  464. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreallocatedImage)
  465. };
  466. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidComponentPeer)
  467. };
  468. ModifierKeys AndroidComponentPeer::currentModifiers = 0;
  469. Point<float> AndroidComponentPeer::lastMousePos;
  470. int64 AndroidComponentPeer::touchesDown = 0;
  471. //==============================================================================
  472. #define JUCE_VIEW_CALLBACK(returnType, javaMethodName, params, juceMethodInvocation) \
  473. JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024ComponentPeerView), javaMethodName, returnType, params) \
  474. { \
  475. if (AndroidComponentPeer* peer = (AndroidComponentPeer*) (pointer_sized_uint) host) \
  476. peer->juceMethodInvocation; \
  477. }
  478. JUCE_VIEW_CALLBACK (void, handlePaint, (JNIEnv* env, jobject view, jlong host, jobject canvas, jobject paint), handlePaintCallback (env, canvas, paint))
  479. JUCE_VIEW_CALLBACK (void, handleMouseDown, (JNIEnv* env, jobject view, jlong host, jint i, jfloat x, jfloat y, jlong time), handleMouseDownCallback (i, Point<float> ((float) x, (float) y), (int64) time))
  480. JUCE_VIEW_CALLBACK (void, handleMouseDrag, (JNIEnv* env, jobject view, jlong host, jint i, jfloat x, jfloat y, jlong time), handleMouseDragCallback (i, Point<float> ((float) x, (float) y), (int64) time))
  481. JUCE_VIEW_CALLBACK (void, handleMouseUp, (JNIEnv* env, jobject view, jlong host, jint i, jfloat x, jfloat y, jlong time), handleMouseUpCallback (i, Point<float> ((float) x, (float) y), (int64) time))
  482. JUCE_VIEW_CALLBACK (void, viewSizeChanged, (JNIEnv* env, jobject view, jlong host), handleMovedOrResized())
  483. JUCE_VIEW_CALLBACK (void, focusChanged, (JNIEnv* env, jobject view, jlong host, jboolean hasFocus), handleFocusChangeCallback (hasFocus))
  484. JUCE_VIEW_CALLBACK (void, handleKeyDown, (JNIEnv* env, jobject view, jlong host, jint k, jint kc), handleKeyDownCallback ((int) k, (int) kc))
  485. JUCE_VIEW_CALLBACK (void, handleKeyUp, (JNIEnv* env, jobject view, jlong host, jint k, jint kc), handleKeyUpCallback ((int) k, (int) kc))
  486. //==============================================================================
  487. ComponentPeer* Component::createNewPeer (int styleFlags, void*)
  488. {
  489. return new AndroidComponentPeer (*this, styleFlags);
  490. }
  491. jobject createOpenGLView (ComponentPeer* peer)
  492. {
  493. jobject parentView = static_cast<jobject> (peer->getNativeHandle());
  494. return getEnv()->CallObjectMethod (parentView, ComponentPeerView.createGLView);
  495. }
  496. //==============================================================================
  497. bool Desktop::canUseSemiTransparentWindows() noexcept
  498. {
  499. return true;
  500. }
  501. double Desktop::getDefaultMasterScale()
  502. {
  503. return 1.0;
  504. }
  505. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
  506. {
  507. // TODO
  508. return upright;
  509. }
  510. bool MouseInputSource::SourceList::addSource()
  511. {
  512. addSource (sources.size(), false);
  513. return true;
  514. }
  515. Point<float> MouseInputSource::getCurrentRawMousePosition()
  516. {
  517. return AndroidComponentPeer::lastMousePos;
  518. }
  519. void MouseInputSource::setRawMousePosition (Point<float>)
  520. {
  521. // not needed
  522. }
  523. //==============================================================================
  524. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  525. {
  526. // TODO
  527. return false;
  528. }
  529. void ModifierKeys::updateCurrentModifiers() noexcept
  530. {
  531. currentModifiers = AndroidComponentPeer::currentModifiers;
  532. }
  533. ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
  534. {
  535. return AndroidComponentPeer::currentModifiers;
  536. }
  537. //==============================================================================
  538. // TODO
  539. JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return true; }
  540. JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {}
  541. JUCE_API void JUCE_CALLTYPE Process::hide() {}
  542. //==============================================================================
  543. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
  544. const String& title, const String& message,
  545. Component* associatedComponent,
  546. ModalComponentManager::Callback* callback)
  547. {
  548. android.activity.callVoidMethod (JuceAppActivity.showMessageBox, javaString (title).get(),
  549. javaString (message).get(), (jlong) (pointer_sized_int) callback);
  550. }
  551. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
  552. const String& title, const String& message,
  553. Component* associatedComponent,
  554. ModalComponentManager::Callback* callback)
  555. {
  556. jassert (callback != nullptr); // on android, all alerts must be non-modal!!
  557. android.activity.callVoidMethod (JuceAppActivity.showOkCancelBox, javaString (title).get(),
  558. javaString (message).get(), (jlong) (pointer_sized_int) callback);
  559. return false;
  560. }
  561. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
  562. const String& title, const String& message,
  563. Component* associatedComponent,
  564. ModalComponentManager::Callback* callback)
  565. {
  566. jassert (callback != nullptr); // on android, all alerts must be non-modal!!
  567. android.activity.callVoidMethod (JuceAppActivity.showYesNoCancelBox, javaString (title).get(),
  568. javaString (message).get(), (jlong) (pointer_sized_int) callback);
  569. return 0;
  570. }
  571. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, alertDismissed, void, (JNIEnv* env, jobject activity,
  572. jlong callbackAsLong, jint result))
  573. {
  574. if (ModalComponentManager::Callback* callback = (ModalComponentManager::Callback*) callbackAsLong)
  575. {
  576. callback->modalStateFinished (result);
  577. delete callback;
  578. }
  579. }
  580. //==============================================================================
  581. void Desktop::setScreenSaverEnabled (const bool isEnabled)
  582. {
  583. // TODO
  584. }
  585. bool Desktop::isScreenSaverEnabled()
  586. {
  587. return true;
  588. }
  589. //==============================================================================
  590. void Desktop::setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  591. {
  592. // TODO
  593. }
  594. //==============================================================================
  595. bool juce_areThereAnyAlwaysOnTopWindows()
  596. {
  597. return false;
  598. }
  599. //==============================================================================
  600. void Desktop::Displays::findDisplays (float masterScale)
  601. {
  602. Display d;
  603. d.isMain = true;
  604. d.dpi = android.dpi;
  605. d.scale = masterScale * (d.dpi / 150.);
  606. d.userArea = d.totalArea = Rectangle<int> (android.screenWidth,
  607. android.screenHeight) / d.scale;
  608. displays.add (d);
  609. }
  610. JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, setScreenSize, void, (JNIEnv* env, jobject activity,
  611. jint screenWidth, jint screenHeight,
  612. jint dpi))
  613. {
  614. android.screenWidth = screenWidth;
  615. android.screenHeight = screenHeight;
  616. android.dpi = dpi;
  617. const_cast<Desktop::Displays&> (Desktop::getInstance().getDisplays()).refresh();
  618. }
  619. //==============================================================================
  620. Image juce_createIconForFile (const File& file)
  621. {
  622. return Image::null;
  623. }
  624. //==============================================================================
  625. void* CustomMouseCursorInfo::create() const { return nullptr; }
  626. void* MouseCursor::createStandardMouseCursor (const MouseCursor::StandardCursorType) { return nullptr; }
  627. void MouseCursor::deleteMouseCursor (void* const /*cursorHandle*/, const bool /*isStandard*/) {}
  628. //==============================================================================
  629. void MouseCursor::showInWindow (ComponentPeer*) const {}
  630. void MouseCursor::showInAllWindows() const {}
  631. //==============================================================================
  632. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  633. {
  634. return false;
  635. }
  636. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  637. {
  638. return false;
  639. }
  640. //==============================================================================
  641. void LookAndFeel::playAlertSound()
  642. {
  643. }
  644. //==============================================================================
  645. void SystemClipboard::copyTextToClipboard (const String& text)
  646. {
  647. const LocalRef<jstring> t (javaString (text));
  648. android.activity.callVoidMethod (JuceAppActivity.setClipboardContent, t.get());
  649. }
  650. String SystemClipboard::getTextFromClipboard()
  651. {
  652. const LocalRef<jstring> text ((jstring) android.activity.callObjectMethod (JuceAppActivity.getClipboardContent));
  653. return juceString (text);
  654. }
  655. //==============================================================================
  656. const int extendedKeyModifier = 0x10000;
  657. const int KeyPress::spaceKey = ' ';
  658. const int KeyPress::returnKey = 66;
  659. const int KeyPress::escapeKey = 4;
  660. const int KeyPress::backspaceKey = 67;
  661. const int KeyPress::leftKey = extendedKeyModifier + 1;
  662. const int KeyPress::rightKey = extendedKeyModifier + 2;
  663. const int KeyPress::upKey = extendedKeyModifier + 3;
  664. const int KeyPress::downKey = extendedKeyModifier + 4;
  665. const int KeyPress::pageUpKey = extendedKeyModifier + 5;
  666. const int KeyPress::pageDownKey = extendedKeyModifier + 6;
  667. const int KeyPress::endKey = extendedKeyModifier + 7;
  668. const int KeyPress::homeKey = extendedKeyModifier + 8;
  669. const int KeyPress::deleteKey = extendedKeyModifier + 9;
  670. const int KeyPress::insertKey = -1;
  671. const int KeyPress::tabKey = 61;
  672. const int KeyPress::F1Key = extendedKeyModifier + 10;
  673. const int KeyPress::F2Key = extendedKeyModifier + 11;
  674. const int KeyPress::F3Key = extendedKeyModifier + 12;
  675. const int KeyPress::F4Key = extendedKeyModifier + 13;
  676. const int KeyPress::F5Key = extendedKeyModifier + 14;
  677. const int KeyPress::F6Key = extendedKeyModifier + 16;
  678. const int KeyPress::F7Key = extendedKeyModifier + 17;
  679. const int KeyPress::F8Key = extendedKeyModifier + 18;
  680. const int KeyPress::F9Key = extendedKeyModifier + 19;
  681. const int KeyPress::F10Key = extendedKeyModifier + 20;
  682. const int KeyPress::F11Key = extendedKeyModifier + 21;
  683. const int KeyPress::F12Key = extendedKeyModifier + 22;
  684. const int KeyPress::F13Key = extendedKeyModifier + 23;
  685. const int KeyPress::F14Key = extendedKeyModifier + 24;
  686. const int KeyPress::F15Key = extendedKeyModifier + 25;
  687. const int KeyPress::F16Key = extendedKeyModifier + 26;
  688. const int KeyPress::numberPad0 = extendedKeyModifier + 27;
  689. const int KeyPress::numberPad1 = extendedKeyModifier + 28;
  690. const int KeyPress::numberPad2 = extendedKeyModifier + 29;
  691. const int KeyPress::numberPad3 = extendedKeyModifier + 30;
  692. const int KeyPress::numberPad4 = extendedKeyModifier + 31;
  693. const int KeyPress::numberPad5 = extendedKeyModifier + 32;
  694. const int KeyPress::numberPad6 = extendedKeyModifier + 33;
  695. const int KeyPress::numberPad7 = extendedKeyModifier + 34;
  696. const int KeyPress::numberPad8 = extendedKeyModifier + 35;
  697. const int KeyPress::numberPad9 = extendedKeyModifier + 36;
  698. const int KeyPress::numberPadAdd = extendedKeyModifier + 37;
  699. const int KeyPress::numberPadSubtract = extendedKeyModifier + 38;
  700. const int KeyPress::numberPadMultiply = extendedKeyModifier + 39;
  701. const int KeyPress::numberPadDivide = extendedKeyModifier + 40;
  702. const int KeyPress::numberPadSeparator = extendedKeyModifier + 41;
  703. const int KeyPress::numberPadDecimalPoint = extendedKeyModifier + 42;
  704. const int KeyPress::numberPadEquals = extendedKeyModifier + 43;
  705. const int KeyPress::numberPadDelete = extendedKeyModifier + 44;
  706. const int KeyPress::playKey = extendedKeyModifier + 45;
  707. const int KeyPress::stopKey = extendedKeyModifier + 46;
  708. const int KeyPress::fastForwardKey = extendedKeyModifier + 47;
  709. const int KeyPress::rewindKey = extendedKeyModifier + 48;