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.

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