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.

864 lines
32KB

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