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.

831 lines
30KB

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