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.

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