/indra/llwindow/llwindow.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 285 lines · 179 code · 43 blank · 63 comment · 0 complexity · c659b30bb06d099935b8cab327db30f1 MD5 · raw file

  1. /**
  2. * @file llwindow.h
  3. * @brief Basic graphical window 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_LLWINDOW_H
  27. #define LL_LLWINDOW_H
  28. #include "llrect.h"
  29. #include "llcoord.h"
  30. #include "llstring.h"
  31. #include "llcursortypes.h"
  32. #include "llsd.h"
  33. class LLSplashScreen;
  34. class LLPreeditor;
  35. class LLWindowCallbacks;
  36. // Refer to llwindow_test in test/common/llwindow for usage example
  37. class LLWindow
  38. {
  39. public:
  40. struct LLWindowResolution
  41. {
  42. S32 mWidth;
  43. S32 mHeight;
  44. };
  45. enum ESwapMethod
  46. {
  47. SWAP_METHOD_UNDEFINED,
  48. SWAP_METHOD_EXCHANGE,
  49. SWAP_METHOD_COPY
  50. };
  51. enum EFlags
  52. {
  53. // currently unused
  54. };
  55. public:
  56. virtual void show() = 0;
  57. virtual void hide() = 0;
  58. virtual void close() = 0;
  59. virtual BOOL getVisible() = 0;
  60. virtual BOOL getMinimized() = 0;
  61. virtual BOOL getMaximized() = 0;
  62. virtual BOOL maximize() = 0;
  63. virtual void minimize() = 0;
  64. virtual void restore() = 0;
  65. BOOL getFullscreen() { return mFullscreen; };
  66. virtual BOOL getPosition(LLCoordScreen *position) = 0;
  67. virtual BOOL getSize(LLCoordScreen *size) = 0;
  68. virtual BOOL getSize(LLCoordWindow *size) = 0;
  69. virtual BOOL setPosition(LLCoordScreen position) = 0;
  70. BOOL setSize(LLCoordScreen size);
  71. virtual void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true);
  72. virtual BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL) = 0;
  73. virtual BOOL setCursorPosition(LLCoordWindow position) = 0;
  74. virtual BOOL getCursorPosition(LLCoordWindow *position) = 0;
  75. virtual void showCursor() = 0;
  76. virtual void hideCursor() = 0;
  77. virtual BOOL isCursorHidden() = 0;
  78. virtual void showCursorFromMouseMove() = 0;
  79. virtual void hideCursorUntilMouseMove() = 0;
  80. // These two functions create a way to make a busy cursor instead
  81. // of an arrow when someone's busy doing something. Draw an
  82. // arrow/hour if busycount > 0.
  83. virtual void incBusyCount();
  84. virtual void decBusyCount();
  85. virtual void resetBusyCount();
  86. virtual S32 getBusyCount() const;
  87. // Sets cursor, may set to arrow+hourglass
  88. virtual void setCursor(ECursorType cursor) { mNextCursor = cursor; };
  89. virtual ECursorType getCursor() const;
  90. virtual void updateCursor() = 0;
  91. virtual void captureMouse() = 0;
  92. virtual void releaseMouse() = 0;
  93. virtual void setMouseClipping( BOOL b ) = 0;
  94. virtual BOOL isClipboardTextAvailable() = 0;
  95. virtual BOOL pasteTextFromClipboard(LLWString &dst) = 0;
  96. virtual BOOL copyTextToClipboard(const LLWString &src) = 0;
  97. virtual BOOL isPrimaryTextAvailable();
  98. virtual BOOL pasteTextFromPrimary(LLWString &dst);
  99. virtual BOOL copyTextToPrimary(const LLWString &src);
  100. virtual void flashIcon(F32 seconds) = 0;
  101. virtual F32 getGamma() = 0;
  102. virtual BOOL setGamma(const F32 gamma) = 0; // Set the gamma
  103. virtual void setFSAASamples(const U32 fsaa_samples) = 0; //set number of FSAA samples
  104. virtual U32 getFSAASamples() = 0;
  105. virtual BOOL restoreGamma() = 0; // Restore original gamma table (before updating gamma)
  106. virtual ESwapMethod getSwapMethod() { return mSwapMethod; }
  107. virtual void processMiscNativeEvents();
  108. virtual void gatherInput() = 0;
  109. virtual void delayInputProcessing() = 0;
  110. virtual void swapBuffers() = 0;
  111. virtual void bringToFront() = 0;
  112. virtual void focusClient() { }; // this may not have meaning or be required on other platforms, therefore, it's not abstract
  113. // handy coordinate space conversion routines
  114. // NB: screen to window and vice verse won't work on width/height coordinate pairs,
  115. // as the conversion must take into account left AND right border widths, etc.
  116. virtual BOOL convertCoords( LLCoordScreen from, LLCoordWindow *to) = 0;
  117. virtual BOOL convertCoords( LLCoordWindow from, LLCoordScreen *to) = 0;
  118. virtual BOOL convertCoords( LLCoordWindow from, LLCoordGL *to) = 0;
  119. virtual BOOL convertCoords( LLCoordGL from, LLCoordWindow *to) = 0;
  120. virtual BOOL convertCoords( LLCoordScreen from, LLCoordGL *to) = 0;
  121. virtual BOOL convertCoords( LLCoordGL from, LLCoordScreen *to) = 0;
  122. // query supported resolutions
  123. virtual LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) = 0;
  124. virtual F32 getNativeAspectRatio() = 0;
  125. virtual F32 getPixelAspectRatio() = 0;
  126. virtual void setNativeAspectRatio(F32 aspect) = 0;
  127. virtual void beforeDialog() {}; // prepare to put up an OS dialog (if special measures are required, such as in fullscreen mode)
  128. virtual void afterDialog() {}; // undo whatever was done in beforeDialog()
  129. // opens system default color picker, modally
  130. // Returns TRUE if valid color selected
  131. virtual BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
  132. // return a platform-specific window reference (HWND on Windows, WindowRef on the Mac, Gtk window on Linux)
  133. virtual void *getPlatformWindow() = 0;
  134. // return the platform-specific window reference we use to initialize llmozlib (HWND on Windows, WindowRef on the Mac, Gtk window on Linux)
  135. virtual void *getMediaWindow();
  136. // control platform's Language Text Input mechanisms.
  137. virtual void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) {}
  138. virtual void setLanguageTextInput( const LLCoordGL & pos ) {};
  139. virtual void updateLanguageTextInputArea() {}
  140. virtual void interruptLanguageTextInput() {}
  141. virtual void spawnWebBrowser(const std::string& escaped_url, bool async) {};
  142. static std::vector<std::string> getDynamicFallbackFontList();
  143. // Provide native key event data
  144. virtual LLSD getNativeKeyData() { return LLSD::emptyMap(); }
  145. protected:
  146. LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags);
  147. virtual ~LLWindow();
  148. // Defaults to true
  149. virtual BOOL isValid();
  150. // Defaults to true
  151. virtual BOOL canDelete();
  152. virtual BOOL setSizeImpl(LLCoordScreen size) = 0;
  153. protected:
  154. LLWindowCallbacks* mCallbacks;
  155. BOOL mPostQuit; // should this window post a quit message when destroyed?
  156. BOOL mFullscreen;
  157. S32 mFullscreenWidth;
  158. S32 mFullscreenHeight;
  159. S32 mFullscreenBits;
  160. S32 mFullscreenRefresh;
  161. LLWindowResolution* mSupportedResolutions;
  162. S32 mNumSupportedResolutions;
  163. ECursorType mCurrentCursor;
  164. ECursorType mNextCursor;
  165. BOOL mCursorHidden;
  166. S32 mBusyCount; // how deep is the "cursor busy" stack?
  167. BOOL mIsMouseClipping; // Is this window currently clipping the mouse
  168. ESwapMethod mSwapMethod;
  169. BOOL mHideCursorPermanent;
  170. U32 mFlags;
  171. U16 mHighSurrogate;
  172. S32 mMinWindowWidth;
  173. S32 mMinWindowHeight;
  174. // Handle a UTF-16 encoding unit received from keyboard.
  175. // Converting the series of UTF-16 encoding units to UTF-32 data,
  176. // this method passes the resulting UTF-32 data to mCallback's
  177. // handleUnicodeChar. The mask should be that to be passed to the
  178. // callback. This method uses mHighSurrogate as a dedicated work
  179. // variable.
  180. void handleUnicodeUTF16(U16 utf16, MASK mask);
  181. friend class LLWindowManager;
  182. };
  183. // LLSplashScreen
  184. // A simple, OS-specific splash screen that we can display
  185. // while initializing the application and before creating a GL
  186. // window
  187. class LLSplashScreen
  188. {
  189. public:
  190. LLSplashScreen() { };
  191. virtual ~LLSplashScreen() { };
  192. // Call to display the window.
  193. static LLSplashScreen * create();
  194. static void show();
  195. static void hide();
  196. static void update(const std::string& string);
  197. static bool isVisible();
  198. protected:
  199. // These are overridden by the platform implementation
  200. virtual void showImpl() = 0;
  201. virtual void updateImpl(const std::string& string) = 0;
  202. virtual void hideImpl() = 0;
  203. static BOOL sVisible;
  204. };
  205. // Platform-neutral for accessing the platform specific message box
  206. S32 OSMessageBox(const std::string& text, const std::string& caption, U32 type);
  207. const U32 OSMB_OK = 0;
  208. const U32 OSMB_OKCANCEL = 1;
  209. const U32 OSMB_YESNO = 2;
  210. const S32 OSBTN_YES = 0;
  211. const S32 OSBTN_NO = 1;
  212. const S32 OSBTN_OK = 2;
  213. const S32 OSBTN_CANCEL = 3;
  214. //
  215. // LLWindowManager
  216. // Manages window creation and error checking
  217. class LLWindowManager
  218. {
  219. public:
  220. static LLWindow *createWindow(
  221. LLWindowCallbacks* callbacks,
  222. const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height,
  223. U32 flags = 0,
  224. BOOL fullscreen = FALSE,
  225. BOOL clearBg = FALSE,
  226. BOOL disable_vsync = TRUE,
  227. BOOL use_gl = TRUE,
  228. BOOL ignore_pixel_depth = FALSE,
  229. U32 fsaa_samples = 0);
  230. static BOOL destroyWindow(LLWindow* window);
  231. static BOOL isWindowValid(LLWindow *window);
  232. };
  233. //
  234. // helper funcs
  235. //
  236. extern BOOL gDebugWindowProc;
  237. // Protocols, like "http" and "https" we support in URLs
  238. extern const S32 gURLProtocolWhitelistCount;
  239. extern const std::string gURLProtocolWhitelist[];
  240. extern const std::string gURLProtocolWhitelistHandler[];
  241. void simpleEscapeString ( std::string& stringIn );
  242. #endif // _LL_window_h_