other-licenses/7zstub/src/Windows/Window.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // Windows/Window.cpp
michael@0 2
michael@0 3 #include "StdAfx.h"
michael@0 4
michael@0 5 #ifndef _UNICODE
michael@0 6 #include "Common/StringConvert.h"
michael@0 7 #endif
michael@0 8 #include "Windows/Window.h"
michael@0 9
michael@0 10 #ifndef _UNICODE
michael@0 11 extern bool g_IsNT;
michael@0 12 #endif
michael@0 13
michael@0 14 namespace NWindows {
michael@0 15
michael@0 16 #ifndef _UNICODE
michael@0 17 ATOM MyRegisterClass(CONST WNDCLASSW *wndClass)
michael@0 18 {
michael@0 19 if (g_IsNT)
michael@0 20 return RegisterClassW(wndClass);
michael@0 21 WNDCLASSA wndClassA;
michael@0 22 wndClassA.style = wndClass->style;
michael@0 23 wndClassA.lpfnWndProc = wndClass->lpfnWndProc;
michael@0 24 wndClassA.cbClsExtra = wndClass->cbClsExtra;
michael@0 25 wndClassA.cbWndExtra = wndClass->cbWndExtra;
michael@0 26 wndClassA.hInstance = wndClass->hInstance;
michael@0 27 wndClassA.hIcon = wndClass->hIcon;
michael@0 28 wndClassA.hCursor = wndClass->hCursor;
michael@0 29 wndClassA.hbrBackground = wndClass->hbrBackground;
michael@0 30 AString menuName;
michael@0 31 AString className;
michael@0 32 if (IS_INTRESOURCE(wndClass->lpszMenuName))
michael@0 33 wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName;
michael@0 34 else
michael@0 35 {
michael@0 36 menuName = GetSystemString(wndClass->lpszMenuName);
michael@0 37 wndClassA.lpszMenuName = menuName;
michael@0 38 }
michael@0 39 if (IS_INTRESOURCE(wndClass->lpszClassName))
michael@0 40 wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName;
michael@0 41 else
michael@0 42 {
michael@0 43 className = GetSystemString(wndClass->lpszClassName);
michael@0 44 wndClassA.lpszClassName = className;
michael@0 45 }
michael@0 46 return RegisterClassA(&wndClassA);
michael@0 47 }
michael@0 48
michael@0 49 bool CWindow::Create(LPCWSTR className,
michael@0 50 LPCWSTR windowName, DWORD style,
michael@0 51 int x, int y, int width, int height,
michael@0 52 HWND parentWindow, HMENU idOrHMenu,
michael@0 53 HINSTANCE instance, LPVOID createParam)
michael@0 54 {
michael@0 55 if (g_IsNT)
michael@0 56 {
michael@0 57 _window = ::CreateWindowW(className, windowName,
michael@0 58 style, x, y, width, height, parentWindow,
michael@0 59 idOrHMenu, instance, createParam);
michael@0 60 return (_window != NULL);
michael@0 61 }
michael@0 62 return Create(GetSystemString(className), GetSystemString(windowName),
michael@0 63 style, x, y, width, height, parentWindow,
michael@0 64 idOrHMenu, instance, createParam);
michael@0 65 }
michael@0 66
michael@0 67 bool CWindow::CreateEx(DWORD exStyle, LPCWSTR className,
michael@0 68 LPCWSTR windowName, DWORD style,
michael@0 69 int x, int y, int width, int height,
michael@0 70 HWND parentWindow, HMENU idOrHMenu,
michael@0 71 HINSTANCE instance, LPVOID createParam)
michael@0 72 {
michael@0 73 if (g_IsNT)
michael@0 74 {
michael@0 75 _window = ::CreateWindowExW(exStyle, className, windowName,
michael@0 76 style, x, y, width, height, parentWindow,
michael@0 77 idOrHMenu, instance, createParam);
michael@0 78 return (_window != NULL);
michael@0 79 }
michael@0 80 AString classNameA;
michael@0 81 LPCSTR classNameP;
michael@0 82 if (IS_INTRESOURCE(className))
michael@0 83 classNameP = (LPCSTR)className;
michael@0 84 else
michael@0 85 {
michael@0 86 classNameA = GetSystemString(className);
michael@0 87 classNameP = classNameA;
michael@0 88 }
michael@0 89 AString windowNameA;
michael@0 90 LPCSTR windowNameP;
michael@0 91 if (IS_INTRESOURCE(windowName))
michael@0 92 windowNameP = (LPCSTR)windowName;
michael@0 93 else
michael@0 94 {
michael@0 95 windowNameA = GetSystemString(windowName);
michael@0 96 windowNameP = windowNameA;
michael@0 97 }
michael@0 98 return CreateEx(exStyle, classNameP, windowNameP,
michael@0 99 style, x, y, width, height, parentWindow,
michael@0 100 idOrHMenu, instance, createParam);
michael@0 101 }
michael@0 102
michael@0 103 #endif
michael@0 104
michael@0 105 #ifndef _UNICODE
michael@0 106 bool MySetWindowText(HWND wnd, LPCWSTR s)
michael@0 107 {
michael@0 108 if (g_IsNT)
michael@0 109 return BOOLToBool(::SetWindowTextW(wnd, s));
michael@0 110 return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s)));
michael@0 111 }
michael@0 112 #endif
michael@0 113
michael@0 114 bool CWindow::GetText(CSysString &s)
michael@0 115 {
michael@0 116 s.Empty();
michael@0 117 int length = GetTextLength();
michael@0 118 if (length == 0)
michael@0 119 return (::GetLastError() == ERROR_SUCCESS);
michael@0 120 length = GetText(s.GetBuffer(length), length + 1);
michael@0 121 s.ReleaseBuffer();
michael@0 122 if (length == 0)
michael@0 123 return (::GetLastError() != ERROR_SUCCESS);
michael@0 124 return true;
michael@0 125 }
michael@0 126
michael@0 127 #ifndef _UNICODE
michael@0 128 bool CWindow::GetText(UString &s)
michael@0 129 {
michael@0 130 if (g_IsNT)
michael@0 131 {
michael@0 132 s.Empty();
michael@0 133 int length = GetWindowTextLengthW(_window);
michael@0 134 if (length == 0)
michael@0 135 return (::GetLastError() == ERROR_SUCCESS);
michael@0 136 length = GetWindowTextW(_window, s.GetBuffer(length), length + 1);
michael@0 137 s.ReleaseBuffer();
michael@0 138 if (length == 0)
michael@0 139 return (::GetLastError() == ERROR_SUCCESS);
michael@0 140 return true;
michael@0 141 }
michael@0 142 CSysString sysString;
michael@0 143 bool result = GetText(sysString);
michael@0 144 s = GetUnicodeString(sysString);
michael@0 145 return result;
michael@0 146 }
michael@0 147 #endif
michael@0 148
michael@0 149
michael@0 150 /*
michael@0 151 bool CWindow::ModifyStyleBase(int styleOffset,
michael@0 152 DWORD remove, DWORD add, UINT flags)
michael@0 153 {
michael@0 154 DWORD style = GetWindowLong(styleOffset);
michael@0 155 DWORD newStyle = (style & ~remove) | add;
michael@0 156 if (style == newStyle)
michael@0 157 return false; // it is not good
michael@0 158
michael@0 159 SetWindowLong(styleOffset, newStyle);
michael@0 160 if (flags != 0)
michael@0 161 {
michael@0 162 ::SetWindowPos(_window, NULL, 0, 0, 0, 0,
michael@0 163 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | flags);
michael@0 164 }
michael@0 165 return TRUE;
michael@0 166 }
michael@0 167 */
michael@0 168
michael@0 169 }

mercurial