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.

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