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.

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