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