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.

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