PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llwindow/llwindowmacosx.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 243 lines | 161 code | 42 blank | 40 comment | 0 complexity | 01adaa276e45bf4cc8ab670c1b396917 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwindowmacosx.h
  3. * @brief Mac implementation of LLWindow class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLWINDOWMACOSX_H
  27. #define LL_LLWINDOWMACOSX_H
  28. #include "llwindow.h"
  29. #include "llwindowcallbacks.h"
  30. #include "lltimer.h"
  31. #include <Carbon/Carbon.h>
  32. #include <AGL/agl.h>
  33. // AssertMacros.h does bad things.
  34. #undef verify
  35. #undef check
  36. #undef require
  37. class LLWindowMacOSX : public LLWindow
  38. {
  39. public:
  40. /*virtual*/ void show();
  41. /*virtual*/ void hide();
  42. /*virtual*/ void close();
  43. /*virtual*/ BOOL getVisible();
  44. /*virtual*/ BOOL getMinimized();
  45. /*virtual*/ BOOL getMaximized();
  46. /*virtual*/ BOOL maximize();
  47. /*virtual*/ void minimize();
  48. /*virtual*/ void restore();
  49. /*virtual*/ BOOL getFullscreen();
  50. /*virtual*/ BOOL getPosition(LLCoordScreen *position);
  51. /*virtual*/ BOOL getSize(LLCoordScreen *size);
  52. /*virtual*/ BOOL getSize(LLCoordWindow *size);
  53. /*virtual*/ BOOL setPosition(LLCoordScreen position);
  54. /*virtual*/ BOOL setSizeImpl(LLCoordScreen size);
  55. /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL);
  56. /*virtual*/ BOOL setCursorPosition(LLCoordWindow position);
  57. /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position);
  58. /*virtual*/ void showCursor();
  59. /*virtual*/ void hideCursor();
  60. /*virtual*/ void showCursorFromMouseMove();
  61. /*virtual*/ void hideCursorUntilMouseMove();
  62. /*virtual*/ BOOL isCursorHidden();
  63. /*virtual*/ void updateCursor();
  64. /*virtual*/ ECursorType getCursor() const;
  65. /*virtual*/ void captureMouse();
  66. /*virtual*/ void releaseMouse();
  67. /*virtual*/ void setMouseClipping( BOOL b );
  68. /*virtual*/ BOOL isClipboardTextAvailable();
  69. /*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst);
  70. /*virtual*/ BOOL copyTextToClipboard(const LLWString & src);
  71. /*virtual*/ void flashIcon(F32 seconds);
  72. /*virtual*/ F32 getGamma();
  73. /*virtual*/ BOOL setGamma(const F32 gamma); // Set the gamma
  74. /*virtual*/ U32 getFSAASamples();
  75. /*virtual*/ void setFSAASamples(const U32 fsaa_samples);
  76. /*virtual*/ BOOL restoreGamma(); // Restore original gamma table (before updating gamma)
  77. /*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; }
  78. /*virtual*/ void gatherInput();
  79. /*virtual*/ void delayInputProcessing() {};
  80. /*virtual*/ void swapBuffers();
  81. // handy coordinate space conversion routines
  82. /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to);
  83. /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to);
  84. /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to);
  85. /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to);
  86. /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to);
  87. /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to);
  88. /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions);
  89. /*virtual*/ F32 getNativeAspectRatio();
  90. /*virtual*/ F32 getPixelAspectRatio();
  91. /*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; }
  92. /*virtual*/ void beforeDialog();
  93. /*virtual*/ void afterDialog();
  94. /*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
  95. /*virtual*/ void *getPlatformWindow();
  96. /*virtual*/ void *getMediaWindow();
  97. /*virtual*/ void bringToFront() {};
  98. /*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b);
  99. /*virtual*/ void interruptLanguageTextInput();
  100. /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async);
  101. static std::vector<std::string> getDynamicFallbackFontList();
  102. // Provide native key event data
  103. /*virtual*/ LLSD getNativeKeyData();
  104. protected:
  105. LLWindowMacOSX(LLWindowCallbacks* callbacks,
  106. const std::string& title, const std::string& name, int x, int y, int width, int height, U32 flags,
  107. BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl,
  108. BOOL ignore_pixel_depth,
  109. U32 fsaa_samples);
  110. ~LLWindowMacOSX();
  111. void initCursors();
  112. BOOL isValid();
  113. void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
  114. // Changes display resolution. Returns true if successful
  115. BOOL setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh);
  116. // Go back to last fullscreen display resolution.
  117. BOOL setFullscreenResolution();
  118. // Restore the display resolution to its value before we ran the app.
  119. BOOL resetDisplayResolution();
  120. BOOL shouldPostQuit() { return mPostQuit; }
  121. protected:
  122. //
  123. // Platform specific methods
  124. //
  125. // create or re-create the GL context/window. Called from the constructor and switchContext().
  126. BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync);
  127. void destroyContext();
  128. void setupFailure(const std::string& text, const std::string& caption, U32 type);
  129. static pascal OSStatus staticEventHandler (EventHandlerCallRef myHandler, EventRef event, void* userData);
  130. static pascal Boolean staticMoveEventComparator( EventRef event, void* data);
  131. OSStatus eventHandler (EventHandlerCallRef myHandler, EventRef event);
  132. void adjustCursorDecouple(bool warpingMouse = false);
  133. void stopDockTileBounce();
  134. static MASK modifiersToMask(SInt16 modifiers);
  135. #if LL_OS_DRAGDROP_ENABLED
  136. static OSErr dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow,
  137. void * handlerRefCon, DragRef theDrag);
  138. static OSErr dragReceiveHandler(WindowRef theWindow, void * handlerRefCon, DragRef theDrag);
  139. OSErr handleDragNDrop(DragRef theDrag, LLWindowCallbacks::DragNDropAction action);
  140. #endif // LL_OS_DRAGDROP_ENABLED
  141. //
  142. // Platform specific variables
  143. //
  144. WindowRef mWindow;
  145. AGLContext mContext;
  146. AGLPixelFormat mPixelFormat;
  147. CGDirectDisplayID mDisplay;
  148. CFDictionaryRef mOldDisplayMode;
  149. EventLoopTimerRef mTimer;
  150. EventHandlerUPP mEventHandlerUPP;
  151. EventHandlerRef mGlobalHandlerRef;
  152. EventHandlerRef mWindowHandlerRef;
  153. EventComparatorUPP mMoveEventCampartorUPP;
  154. Rect mOldMouseClip; // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse()
  155. Rect mPreviousWindowRect; // Save previous window for un-maximize event
  156. Str255 mWindowTitle;
  157. double mOriginalAspectRatio;
  158. BOOL mSimulatedRightClick;
  159. UInt32 mLastModifiers;
  160. BOOL mHandsOffEvents; // When true, temporarially disable CarbonEvent processing.
  161. // Used to allow event processing when putting up dialogs in fullscreen mode.
  162. BOOL mCursorDecoupled;
  163. S32 mCursorLastEventDeltaX;
  164. S32 mCursorLastEventDeltaY;
  165. BOOL mCursorIgnoreNextDelta;
  166. BOOL mNeedsResize; // Constructor figured out the window is too big, it needs a resize.
  167. LLCoordScreen mNeedsResizeSize;
  168. F32 mOverrideAspectRatio;
  169. BOOL mMaximized;
  170. BOOL mMinimized;
  171. U32 mFSAASamples;
  172. BOOL mForceRebuild;
  173. S32 mDragOverrideCursor;
  174. F32 mBounceTime;
  175. NMRec mBounceRec;
  176. LLTimer mBounceTimer;
  177. // Input method management through Text Service Manager.
  178. TSMDocumentID mTSMDocument;
  179. BOOL mLanguageTextInputAllowed;
  180. ScriptCode mTSMScriptCode;
  181. LangCode mTSMLangCode;
  182. LLPreeditor* mPreeditor;
  183. static BOOL sUseMultGL;
  184. friend class LLWindowManager;
  185. static WindowRef sMediaWindow;
  186. EventRef mRawKeyEvent;
  187. };
  188. class LLSplashScreenMacOSX : public LLSplashScreen
  189. {
  190. public:
  191. LLSplashScreenMacOSX();
  192. virtual ~LLSplashScreenMacOSX();
  193. /*virtual*/ void showImpl();
  194. /*virtual*/ void updateImpl(const std::string& mesg);
  195. /*virtual*/ void hideImpl();
  196. private:
  197. WindowRef mWindow;
  198. };
  199. S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption, U32 type);
  200. void load_url_external(const char* url);
  201. #endif //LL_LLWINDOWMACOSX_H