llwindowwin32.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * @file llwindowwin32.h
  3. * @brief Windows 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_LLWINDOWWIN32_H
  33. #define LL_LLWINDOWWIN32_H
  34. // Limit Windows API to small and manageable set.
  35. #include "llwin32headerslean.h"
  36. #include "llwindow.h"
  37. // Hack for async host by name
  38. #define LL_WM_HOST_RESOLVED (WM_APP + 1)
  39. typedef void (*LLW32MsgCallback)(const MSG& msg);
  40. class LLWindowWin32 final : public LLWindow
  41. {
  42. friend class LLWindow;
  43. protected:
  44. LOG_CLASS(LLWindowWin32);
  45. public:
  46. void setWindowTitle(const std::string& title) override;
  47. void show() override;
  48. void hide() override;
  49. void close() override;
  50. void minimize() override;
  51. void restore() override;
  52. bool getVisible() override;
  53. bool getMinimized() override;
  54. bool getMaximized() override;
  55. bool maximize() override;
  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 cursor) 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 seconds) 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 void setFSAASamples(U32 n) override { mFSAASamples = n; }
  91. LL_INLINE U32 getFSAASamples() override { return mFSAASamples; }
  92. LL_INLINE ESwapMethod getSwapMethod() override { return mSwapMethod; }
  93. void gatherInput() override;
  94. 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* getPlatformWindow() override;
  107. void bringToFront() override;
  108. void focusClient() override;
  109. void allowLanguageTextInput(LLPreeditor* preeditor, bool b) override;
  110. void setLanguageTextInput(const LLCoordGL& pos) override;
  111. void updateLanguageTextInputArea() override;
  112. void interruptLanguageTextInput() override;
  113. void spawnWebBrowser(const std::string& escaped_url, bool async) override;
  114. F32 getSystemUISize() override;
  115. static void setDPIAwareness();
  116. static std::vector<std::string> getDynamicFallbackFontList();
  117. protected:
  118. LLWindowWin32(const std::string& title, S32 x, S32 y, U32 width,
  119. U32 height, U32 flags, bool fullscreen, bool disable_vsync,
  120. U32 fsaa_samples);
  121. ~LLWindowWin32() override;
  122. LL_INLINE bool isValid() override { return mWindowHandle != NULL; }
  123. LLSD getNativeKeyData() override;
  124. void initCursors();
  125. void initInputDevices();
  126. HCURSOR loadColorCursor(LPCTSTR name);
  127. void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
  128. // Changes display resolution. Returns true if successful
  129. bool setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh);
  130. // Go back to last fullscreen display resolution.
  131. bool setFullscreenResolution();
  132. // Restore the display resolution to its value before we ran the app.
  133. bool resetDisplayResolution();
  134. void fillCompositionForm(const LLRect& bounds, COMPOSITIONFORM* form);
  135. void fillCandidateForm(const LLCoordGL& caret, const LLRect& bounds,
  136. CANDIDATEFORM* form);
  137. void fillCharPosition(const LLCoordGL& caret, const LLRect& bounds,
  138. const LLRect& control, IMECHARPOSITION* char_pos);
  139. void fillCompositionLogfont(LOGFONT *logfont);
  140. U32 fillReconvertString(const LLWString& text, S32 focus, S32 focus_len,
  141. RECONVERTSTRING* reconvert_string);
  142. void handleStartCompositionMessage();
  143. void handleCompositionMessage(U32 indexes);
  144. bool handleImeRequests(WPARAM request, LPARAM param, LRESULT* result);
  145. //
  146. // Platform specific methods
  147. //
  148. bool getClientRectInScreenSpace(RECT* rectp);
  149. void updateJoystick();
  150. static LRESULT CALLBACK mainWindowProc(HWND h_wnd, UINT u_msg,
  151. WPARAM w_param, LPARAM l_param);
  152. static BOOL CALLBACK enumChildWindows(HWND h_wnd, LPARAM l_param);
  153. protected: // Platform specific variables
  154. WCHAR* mWindowTitle;
  155. WCHAR* mWindowClassName;
  156. HWND mWindowHandle; // Window handle
  157. HGLRC mhRC; // OpenGL rendering context
  158. HDC mhDC; // Windows Device context handle
  159. HINSTANCE mhInstance; // Handle to application instance
  160. RECT mOldMouseClip; // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse()
  161. WPARAM mLastSizeWParam;
  162. F32 mNativeAspectRatio;
  163. // Array of all mouse cursors
  164. HCURSOR mCursor[UI_CURSOR_COUNT];
  165. LPWSTR mIconResource;
  166. U32 mFSAASamples;
  167. WORD mPrevGammaRamp[3][256];
  168. WORD mCurrentGammaRamp[3][256];
  169. bool mCustomGammaSet;
  170. bool mMousePositionModified;
  171. bool mInputProcessingPaused;
  172. // Has the window class been registered ?
  173. static bool sIsClassRegistered;
  174. // The following variables are for Language Text Input control.
  175. // They are all static, since one context is shared by all LLWindowWin32
  176. // instances.
  177. static bool sLanguageTextInputAllowed;
  178. static bool sWinIMEOpened;
  179. static HKL sWinInputLocale;
  180. static DWORD sWinIMEConversionMode;
  181. static DWORD sWinIMESentenceMode;
  182. static LLCoordWindow sWinIMEWindowPosition;
  183. LLCoordGL mLanguageTextInputPointGL;
  184. LLRect mLanguageTextInputAreaGL;
  185. LLPreeditor* mPreeditor;
  186. U32 mKeyCharCode;
  187. U32 mKeyScanCode;
  188. U32 mKeyVirtualKey;
  189. U32 mRawMsg;
  190. U32 mRawWParam;
  191. U32 mRawLParam;
  192. bool mMouseVanish;
  193. };
  194. class LLSplashScreenWin32 final : public LLSplashScreen
  195. {
  196. public:
  197. LLSplashScreenWin32();
  198. void showImpl() override;
  199. void updateImpl(const std::string& mesg) override;
  200. void hideImpl() override;
  201. #if LL_WINDOWS
  202. static LRESULT CALLBACK windowProc(HWND h_wnd, UINT u_msg, WPARAM w_param,
  203. LPARAM l_param);
  204. #endif
  205. private:
  206. #if LL_WINDOWS
  207. HWND mWindow;
  208. #endif
  209. };
  210. extern LLW32MsgCallback gAsyncMsgCallback;
  211. extern LPWSTR gIconResource;
  212. extern bool gIgnoreHiDPIEvents;
  213. S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 type);
  214. #endif //LL_LLWINDOWWIN32_H