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

/Externals/wxWidgets3/src/msw/utilsgui.cpp

https://gitlab.com/Hexexpeck/dolphin-emulator
C++ | 276 lines | 170 code | 52 blank | 54 comment | 22 complexity | 4c52c6dd70eaefa4f57364c956eab664 MD5 | raw file
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: src/msw/utilsgui.cpp
  3. // Purpose: Various utility functions only available in wxMSW GUI
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 21.06.2003 (extracted from msw/utils.cpp)
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // declarations
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. // for compilers that support precompilation, includes "wx.h".
  17. #include "wx/wxprec.h"
  18. #ifdef __BORLANDC__
  19. #pragma hdrstop
  20. #endif
  21. #ifndef WX_PRECOMP
  22. #include "wx/cursor.h"
  23. #include "wx/window.h"
  24. #include "wx/utils.h"
  25. #endif //WX_PRECOMP
  26. #include "wx/msw/private.h" // includes <windows.h>
  27. #include "wx/msw/wrapwin.h"
  28. #include <shlwapi.h>
  29. // ============================================================================
  30. // implementation
  31. // ============================================================================
  32. // Emit a beeeeeep
  33. void wxBell()
  34. {
  35. ::MessageBeep((UINT)-1); // default sound
  36. }
  37. // ---------------------------------------------------------------------------
  38. // helper functions for showing a "busy" cursor
  39. // ---------------------------------------------------------------------------
  40. static HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
  41. static HCURSOR gs_wxBusyCursorOld = 0; // old cursor
  42. static int gs_wxBusyCursorCount = 0;
  43. extern HCURSOR wxGetCurrentBusyCursor()
  44. {
  45. return gs_wxBusyCursor;
  46. }
  47. // Set the cursor to the busy cursor for all windows
  48. void wxBeginBusyCursor(const wxCursor *cursor)
  49. {
  50. if ( gs_wxBusyCursorCount++ == 0 )
  51. {
  52. gs_wxBusyCursor = (HCURSOR)cursor->GetHCURSOR();
  53. gs_wxBusyCursorOld = ::SetCursor(gs_wxBusyCursor);
  54. }
  55. //else: nothing to do, already set
  56. }
  57. // Restore cursor to normal
  58. void wxEndBusyCursor()
  59. {
  60. wxCHECK_RET( gs_wxBusyCursorCount > 0,
  61. wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
  62. if ( --gs_wxBusyCursorCount == 0 )
  63. {
  64. ::SetCursor(gs_wxBusyCursorOld);
  65. gs_wxBusyCursorOld = 0;
  66. }
  67. }
  68. // true if we're between the above two calls
  69. bool wxIsBusy()
  70. {
  71. return gs_wxBusyCursorCount > 0;
  72. }
  73. // Check whether this window wants to process messages, e.g. Stop button
  74. // in long calculations.
  75. bool wxCheckForInterrupt(wxWindow *wnd)
  76. {
  77. wxCHECK( wnd, false );
  78. MSG msg;
  79. while ( ::PeekMessage(&msg, GetHwndOf(wnd), 0, 0, PM_REMOVE) )
  80. {
  81. ::TranslateMessage(&msg);
  82. ::DispatchMessage(&msg);
  83. }
  84. return true;
  85. }
  86. // ----------------------------------------------------------------------------
  87. // get display info
  88. // ----------------------------------------------------------------------------
  89. // See also the wxGetMousePosition in window.cpp
  90. // Deprecated: use wxPoint wxGetMousePosition() instead
  91. void wxGetMousePosition( int* x, int* y )
  92. {
  93. POINT pt;
  94. wxGetCursorPosMSW( & pt );
  95. if ( x ) *x = pt.x;
  96. if ( y ) *y = pt.y;
  97. }
  98. // Return true if we have a colour display
  99. bool wxColourDisplay()
  100. {
  101. // this function is called from wxDC ctor so it is called a *lot* of times
  102. // hence we optimize it a bit but doing the check only once
  103. //
  104. // this should be MT safe as only the GUI thread (holding the GUI mutex)
  105. // can call us
  106. static int s_isColour = -1;
  107. if ( s_isColour == -1 )
  108. {
  109. ScreenHDC dc;
  110. int noCols = ::GetDeviceCaps(dc, NUMCOLORS);
  111. s_isColour = (noCols == -1) || (noCols > 2);
  112. }
  113. return s_isColour != 0;
  114. }
  115. // Returns depth of screen
  116. int wxDisplayDepth()
  117. {
  118. ScreenHDC dc;
  119. return GetDeviceCaps(dc, PLANES) * GetDeviceCaps(dc, BITSPIXEL);
  120. }
  121. // Get size of display
  122. void wxDisplaySize(int *width, int *height)
  123. {
  124. ScreenHDC dc;
  125. if ( width )
  126. *width = ::GetDeviceCaps(dc, HORZRES);
  127. if ( height )
  128. *height = ::GetDeviceCaps(dc, VERTRES);
  129. }
  130. void wxDisplaySizeMM(int *width, int *height)
  131. {
  132. ScreenHDC dc;
  133. if ( width )
  134. *width = ::GetDeviceCaps(dc, HORZSIZE);
  135. if ( height )
  136. *height = ::GetDeviceCaps(dc, VERTSIZE);
  137. }
  138. // ---------------------------------------------------------------------------
  139. // window information functions
  140. // ---------------------------------------------------------------------------
  141. wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
  142. {
  143. wxString str;
  144. if ( hWnd )
  145. {
  146. int len = GetWindowTextLength((HWND)hWnd) + 1;
  147. ::GetWindowText((HWND)hWnd, wxStringBuffer(str, len), len);
  148. }
  149. return str;
  150. }
  151. wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd)
  152. {
  153. wxString str;
  154. if ( hWnd )
  155. {
  156. int len = 256; // some starting value
  157. for ( ;; )
  158. {
  159. int count = ::GetClassName((HWND)hWnd, wxStringBuffer(str, len), len);
  160. if ( count == len )
  161. {
  162. // the class name might have been truncated, retry with larger
  163. // buffer
  164. len *= 2;
  165. }
  166. else
  167. {
  168. break;
  169. }
  170. }
  171. }
  172. return str;
  173. }
  174. int WXDLLEXPORT wxGetWindowId(WXHWND hWnd)
  175. {
  176. return ::GetWindowLong((HWND)hWnd, GWL_ID);
  177. }
  178. // ----------------------------------------------------------------------------
  179. // Metafile helpers
  180. // ----------------------------------------------------------------------------
  181. void PixelToHIMETRIC(LONG *x, LONG *y, HDC hdcRef)
  182. {
  183. int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
  184. iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
  185. iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
  186. iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
  187. // Take care to use MulDiv() here to avoid overflow.
  188. *x = ::MulDiv(*x, iWidthMM * 100, iWidthPels);
  189. *y = ::MulDiv(*y, iHeightMM * 100, iHeightPels);
  190. }
  191. void HIMETRICToPixel(LONG *x, LONG *y, HDC hdcRef)
  192. {
  193. int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
  194. iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
  195. iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
  196. iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
  197. *x = ::MulDiv(*x, iWidthPels, iWidthMM * 100);
  198. *y = ::MulDiv(*y, iHeightPels, iHeightMM * 100);
  199. }
  200. void HIMETRICToPixel(LONG *x, LONG *y)
  201. {
  202. HIMETRICToPixel(x, y, ScreenHDC());
  203. }
  204. void PixelToHIMETRIC(LONG *x, LONG *y)
  205. {
  206. PixelToHIMETRIC(x, y, ScreenHDC());
  207. }
  208. void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2)
  209. {
  210. MoveToEx(hdc, x1, y1, NULL); LineTo((HDC) hdc, x2, y2);
  211. }
  212. // ----------------------------------------------------------------------------
  213. // Shell API wrappers
  214. // ----------------------------------------------------------------------------
  215. extern bool wxEnableFileNameAutoComplete(HWND hwnd)
  216. {
  217. HRESULT hr = ::SHAutoComplete(hwnd, 0x10 /* SHACF_FILESYS_ONLY */);
  218. if ( FAILED(hr) )
  219. {
  220. wxLogApiError(wxT("SHAutoComplete"), hr);
  221. return false;
  222. }
  223. return true;
  224. }