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.

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