The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

817 lines
31KB

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