juce_android_Windowing.cpp 32 KB

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