llwindowmacosx.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * @file llwindowmacosx.h
  3. * @brief Mac implementation of LLWindow class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLWINDOWMACOSX_H
  33. #define LL_LLWINDOWMACOSX_H
  34. #include "lltimer.h"
  35. #include "llwindow.h"
  36. #include "llwindowmacosx-objc.h"
  37. #include <ApplicationServices/ApplicationServices.h>
  38. #include <OpenGL/OpenGL.h>
  39. class LLWindowMacOSX final : public LLWindow
  40. {
  41. friend class LLWindow;
  42. protected:
  43. LOG_CLASS(LLWindowMacOSX);
  44. public:
  45. void setWindowTitle(const std::string& title) override;
  46. void show() override;
  47. void hide() override;
  48. void close() override;
  49. void minimize() override;
  50. void restore() override;
  51. bool getVisible() override;
  52. bool getMinimized() override;
  53. // *TODO
  54. LL_INLINE bool getMaximized() override { return false; }
  55. LL_INLINE bool maximize() override { return false; }
  56. LL_INLINE bool getFullscreen() override { return mFullscreen; }
  57. bool getPosition(LLCoordScreen* position) override;
  58. bool getSize(LLCoordScreen* size) override;
  59. bool getSize(LLCoordWindow* size) override;
  60. bool setPosition(LLCoordScreen position) override;
  61. bool setSize(LLCoordScreen size) override;
  62. bool switchContext(bool fullscreen, const LLCoordScreen& size,
  63. bool disable_vsync,
  64. const LLCoordScreen* const posp = NULL) override;
  65. void* createSharedContext() override;
  66. void makeContextCurrent(void* context) override;
  67. void destroySharedContext(void* context) override;
  68. bool setCursorPosition(const LLCoordWindow& position) override;
  69. bool getCursorPosition(LLCoordWindow* position) override;
  70. void showCursor() override;
  71. void hideCursor() override;
  72. void showCursorFromMouseMove() override;
  73. void hideCursorUntilMouseMove() override;
  74. LL_INLINE bool isCursorHidden() override { return mCursorHidden; }
  75. void setCursor(ECursorType c) override;
  76. void captureMouse() override;
  77. void releaseMouse() override;
  78. void setMouseClipping(bool b) override;
  79. bool isClipboardTextAvailable() override;
  80. bool pasteTextFromClipboard(LLWString& dst) override;
  81. bool copyTextToClipboard(const LLWString& src) override;
  82. bool isPrimaryTextAvailable() override;
  83. bool pasteTextFromPrimary(LLWString& text) override;
  84. bool copyTextToPrimary(const LLWString& text) override;
  85. void flashIcon(F32) override;
  86. // Sets the gamma
  87. bool setGamma(F32 gamma) override;
  88. // Restore original gamma table (before updating gamma)
  89. bool restoreGamma() override;
  90. LL_INLINE U32 getFSAASamples() override { return mFSAASamples; }
  91. void setFSAASamples(U32 fsaa_samples) override;
  92. LL_INLINE ESwapMethod getSwapMethod() override { return mSwapMethod; }
  93. void gatherInput() override;
  94. LL_INLINE void delayInputProcessing() override {}
  95. void swapBuffers() override;
  96. // handy coordinate space conversion routines
  97. bool convertCoords(LLCoordScreen from, LLCoordWindow* to) override;
  98. bool convertCoords(LLCoordWindow from, LLCoordScreen* to) override;
  99. bool convertCoords(LLCoordWindow from, LLCoordGL* to) override;
  100. bool convertCoords(LLCoordGL from, LLCoordWindow* to) override;
  101. bool convertCoords(LLCoordScreen from, LLCoordGL* to) override;
  102. bool convertCoords(LLCoordGL from, LLCoordScreen* to) override;
  103. LLWindowResolution* getSupportedResolutions(S32& num_res) override;
  104. F32 getNativeAspectRatio() override;
  105. F32 getPixelAspectRatio() override;
  106. void beforeDialog() override;
  107. void afterDialog() override;
  108. void* getPlatformWindow() override;
  109. LL_INLINE void bringToFront() override {}
  110. void allowLanguageTextInput(LLPreeditor* preeditor, bool b) override;
  111. void interruptLanguageTextInput() override;
  112. void spawnWebBrowser(const std::string& escaped_url, bool async) override;
  113. static std::vector<std::string> getDynamicFallbackFontList();
  114. LL_INLINE LLWindowCallbacks* getCallbacks() { return mCallbacks; }
  115. LL_INLINE LLPreeditor* getPreeditor() { return mPreeditor; }
  116. LL_INLINE bool allowsLanguageInput() { return mLanguageTextInputAllowed; }
  117. void updateCursor();
  118. void updateMouseDeltas(float* deltas);
  119. void getMouseDeltas(float* delta);
  120. protected:
  121. LLWindowMacOSX(const std::string& title, U32 flags, bool fullscreen,
  122. bool disable_vsync, U32 fsaa_samples);
  123. ~LLWindowMacOSX() override;
  124. bool isValid() override;
  125. LLSD getNativeKeyData() override;
  126. F32 getSystemUISize() override;
  127. void initCursors();
  128. void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
  129. //
  130. // Platform specific methods
  131. //
  132. // Create or re-create the GL context/window. Called from the constructor
  133. // and switchContext().
  134. bool createContext(bool fullscreen, bool disable_vsync);
  135. void destroyContext();
  136. void setupFailure(const std::string& text);
  137. void adjustCursorDecouple(bool warping_mouse = false);
  138. protected:
  139. //
  140. // Platform specific variables
  141. //
  142. NSWindowRef mWindow;
  143. GLViewRef mGLView;
  144. CGLContextObj mContext;
  145. CGLPixelFormatObj mPixelFormat;
  146. CGDirectDisplayID mDisplay;
  147. // Screen rect to which the mouse cursor was globally constrained before we
  148. // changed it in clipMouse():
  149. Rect mOldMouseClip;
  150. std::string mWindowTitle;
  151. double mOriginalAspectRatio;
  152. UInt32 mLastModifiers;
  153. S32 mCursorLastEventDeltaX;
  154. S32 mCursorLastEventDeltaY;
  155. U32 mFSAASamples;
  156. // Input method management through Text Service Manager.
  157. LLPreeditor* mPreeditor;
  158. bool mLanguageTextInputAllowed;
  159. bool mSimulatedRightClick;
  160. bool mCursorDecoupled;
  161. bool mCursorIgnoreNextDelta;
  162. bool mMinimized;
  163. bool mForceRebuild;
  164. public:
  165. static bool sUseMultGL;
  166. };
  167. class LLSplashScreenMacOSX final : public LLSplashScreen
  168. {
  169. public:
  170. LLSplashScreenMacOSX();
  171. void showImpl() override;
  172. void updateImpl(const std::string& mesg) override;
  173. void hideImpl() override;
  174. private:
  175. WindowRef mWindow;
  176. };
  177. S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption,
  178. U32 type);
  179. void load_url_external(const char* url);
  180. #endif //LL_LLWINDOWMACOSX_H