1 | /* $Id: win32wbase.h,v 1.3 1999-09-21 17:05:36 dengert Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Base Class for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
11 | *
|
---|
12 | */
|
---|
13 | #ifndef __WIN32WNDBASE_H__
|
---|
14 | #define __WIN32WNDBASE_H__
|
---|
15 |
|
---|
16 | #ifdef __cplusplus
|
---|
17 |
|
---|
18 | #include <win32class.h>
|
---|
19 | #include "open32wbase.h"
|
---|
20 | #include <gen_object.h>
|
---|
21 | #include <win32wndchild.h>
|
---|
22 | #include <winres.h>
|
---|
23 | #include <winconst.h>
|
---|
24 |
|
---|
25 | class Win32BaseWindow;
|
---|
26 |
|
---|
27 | #define OFFSET_WIN32WNDPTR 0
|
---|
28 | #define OFFSET_WIN32PM_MAGIC 4
|
---|
29 | #define OFFSET_WIN32PM_SHAREDMEM 8
|
---|
30 | #define NROF_WIN32WNDBYTES 12
|
---|
31 |
|
---|
32 | #define WIN32PM_MAGIC 0x12345678
|
---|
33 | #define CheckMagicDword(a) (a==WIN32PM_MAGIC)
|
---|
34 |
|
---|
35 | #define WIN32APP_USERMSGBASE 0x1000
|
---|
36 |
|
---|
37 | typedef struct {
|
---|
38 | USHORT cb;
|
---|
39 | Win32BaseWindow *win32wnd;
|
---|
40 | ULONG win32CreateStruct; //or dialog create dword
|
---|
41 | } CUSTOMWNDDATA;
|
---|
42 |
|
---|
43 | typedef struct
|
---|
44 | {
|
---|
45 | ULONG Msg;
|
---|
46 | ULONG wParam;
|
---|
47 | ULONG lParam;
|
---|
48 | } POSTMSG_PACKET;
|
---|
49 |
|
---|
50 | #define WM_WIN32_POSTMESSAGEA 0x4000
|
---|
51 | #define WM_WIN32_POSTMESSAGEW 0x4001
|
---|
52 |
|
---|
53 | class Win32BaseWindow : public GenericObject, protected ChildWindow
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | DWORD magic;
|
---|
57 |
|
---|
58 | Win32BaseWindow(DWORD objType);
|
---|
59 | Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
|
---|
60 | virtual ~Win32BaseWindow();
|
---|
61 |
|
---|
62 | virtual ULONG MsgCreate(HWND hwndOS2, ULONG initParam);
|
---|
63 | ULONG MsgQuit();
|
---|
64 | ULONG MsgClose();
|
---|
65 | ULONG MsgDestroy();
|
---|
66 | ULONG MsgEnable(BOOL fEnable);
|
---|
67 | ULONG MsgShow(BOOL fShow);
|
---|
68 | ULONG MsgPosChanging(LPARAM lp);
|
---|
69 | ULONG MsgPosChanged(LPARAM lp);
|
---|
70 | ULONG MsgMove(ULONG x, ULONG y);
|
---|
71 | ULONG MsgHitTest(ULONG x, ULONG y);
|
---|
72 | ULONG MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize);
|
---|
73 | ULONG MsgActivate(BOOL fActivate, HWND hwnd);
|
---|
74 | ULONG MsgSetFocus(HWND hwnd);
|
---|
75 | ULONG MsgKillFocus(HWND hwnd);
|
---|
76 | ULONG MsgTimer(ULONG TimerID);
|
---|
77 | ULONG MsgCommand(ULONG cmd, ULONG Id, HWND hwnd);
|
---|
78 | ULONG MsgSysCommand(ULONG win32sc, ULONG x, ULONG y);
|
---|
79 | ULONG MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags);
|
---|
80 | ULONG MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly);
|
---|
81 | ULONG MsgMouseMove(ULONG keystate, ULONG x, ULONG y);
|
---|
82 | ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
|
---|
83 | ULONG MsgEraseBackGround(HDC hdc);
|
---|
84 | ULONG MsgSetText(LPSTR lpsz, LONG cch);
|
---|
85 | ULONG MsgGetTextLength();
|
---|
86 | char *MsgGetText();
|
---|
87 |
|
---|
88 | virtual LONG SetWindowLongA(int index, ULONG value);
|
---|
89 | virtual ULONG GetWindowLongA(int index);
|
---|
90 | virtual WORD SetWindowWord(int index, WORD value);
|
---|
91 | virtual WORD GetWindowWord(int index);
|
---|
92 |
|
---|
93 | DWORD getStyle() { return dwStyle; };
|
---|
94 | void setStyle(DWORD newstyle) { dwStyle = newstyle; };
|
---|
95 | DWORD getExStyle() { return dwExStyle; };
|
---|
96 | void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
|
---|
97 | HWND getWindowHandle() { return Win32Hwnd; };
|
---|
98 | HWND getOS2WindowHandle() { return OS2Hwnd; };
|
---|
99 | HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
|
---|
100 | Win32WndClass *getWindowClass() { return windowClass; };
|
---|
101 |
|
---|
102 | BOOL isFrameWindow() { return OS2Hwnd != OS2HwndFrame; };
|
---|
103 | Win32BaseWindow *getParent() { return (Win32BaseWindow *)ChildWindow::GetParent(); };
|
---|
104 | void setParent(Win32BaseWindow *pwindow) { ChildWindow::SetParent((ChildWindow *)pwindow); };
|
---|
105 | WNDPROC getWindowProc() { return win32wndproc; };
|
---|
106 | void setWindowProc(WNDPROC newproc) { win32wndproc = newproc; };
|
---|
107 | DWORD getWindowId() { return windowId; };
|
---|
108 | void setWindowId(DWORD id) { windowId = id; };
|
---|
109 | ULONG getWindowHeight() { return rectClient.bottom - rectClient.top; };
|
---|
110 | ULONG getWindowWidth() { return rectClient.right - rectClient.left; };
|
---|
111 | BOOL isChild();
|
---|
112 | PRECT getClientRect() { return &rectClient; };
|
---|
113 | void setClientRect(PRECT rect) { rectClient = *rect; };
|
---|
114 | PRECT getWindowRect() { return &rectWindow; };
|
---|
115 | void setClientRect(LONG left, LONG top, LONG right, LONG bottom)
|
---|
116 | {
|
---|
117 | rectClient.left = left; rectClient.top = top;
|
---|
118 | rectClient.right = right; rectClient.bottom = bottom;
|
---|
119 | };
|
---|
120 | void setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
|
---|
121 | {
|
---|
122 | rectWindow.left = left; rectWindow.top = top;
|
---|
123 | rectWindow.right = right; rectWindow.bottom = bottom;
|
---|
124 | };
|
---|
125 | void setWindowRect(PRECT rect) { rectWindow = *rect; };
|
---|
126 | DWORD getFlags() { return flags; };
|
---|
127 | void setFlags(DWORD newflags) { flags = newflags; };
|
---|
128 |
|
---|
129 | HACCEL GetAccelTable() { return (HACCEL) acceltableResource; };
|
---|
130 | BOOL SetAccelTable(ULONG hAccel);
|
---|
131 |
|
---|
132 | HMENU GetMenu() { return (HMENU) menuResource; };
|
---|
133 | BOOL SetMenu(ULONG hMenu);
|
---|
134 |
|
---|
135 | BOOL SetIcon(HICON hIcon);
|
---|
136 | HICON GetIcon() { return (HICON) iconResource; };
|
---|
137 |
|
---|
138 | BOOL ShowWindow(ULONG nCmdShow);
|
---|
139 | BOOL SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
|
---|
140 | BOOL DestroyWindow();
|
---|
141 | HWND SetActiveWindow();
|
---|
142 | HWND GetParent();
|
---|
143 | HWND SetParent(HWND hwndNewParent);
|
---|
144 | BOOL IsChild(HWND hwndParent);
|
---|
145 | HWND GetTopWindow();
|
---|
146 | BOOL UpdateWindow();
|
---|
147 | BOOL IsIconic();
|
---|
148 | HWND GetWindow(UINT uCmd);
|
---|
149 | BOOL EnableWindow(BOOL fEnable);
|
---|
150 | BOOL CloseWindow();
|
---|
151 | static HWND GetActiveWindow();
|
---|
152 | //Window handle has already been verified, so just return true
|
---|
153 | BOOL IsWindow() { return TRUE; };
|
---|
154 | BOOL IsDialog() { return fIsDialog; };
|
---|
155 |
|
---|
156 | BOOL IsWindowEnabled();
|
---|
157 | BOOL IsWindowVisible();
|
---|
158 | BOOL IsUnicode() { return isUnicode; };
|
---|
159 | BOOL GetWindowRect(PRECT pRect);
|
---|
160 | int GetWindowTextLength();
|
---|
161 | int GetWindowTextA(LPSTR lpsz, int cch);
|
---|
162 | int GetWindowTextW(LPWSTR lpsz, int cch);
|
---|
163 | BOOL SetWindowTextA(LPSTR lpsz);
|
---|
164 | BOOL SetWindowTextW(LPWSTR lpsz);
|
---|
165 | BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
|
---|
166 | Win32WndClass *getClass() { return windowClass; };
|
---|
167 | char *getWindowNameA() { return windowNameA; };
|
---|
168 | Win32BaseWindow *getOwner() { return owner; };
|
---|
169 |
|
---|
170 | Win32BaseWindow *getTopParent();
|
---|
171 |
|
---|
172 | LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
173 | LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
174 | BOOL PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
175 | BOOL PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
176 | LRESULT DefWindowProcA(UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
177 | LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
178 |
|
---|
179 | void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
|
---|
180 |
|
---|
181 | static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
|
---|
182 | BOOL fUnicode = 0);
|
---|
183 |
|
---|
184 | static HWND Win32ToOS2Handle(HWND hwnd)
|
---|
185 | {
|
---|
186 | Win32BaseWindow *window = GetWindowFromHandle(hwnd);
|
---|
187 |
|
---|
188 | if(window) {
|
---|
189 | return window->getOS2WindowHandle();
|
---|
190 | }
|
---|
191 | else return hwnd; //OS/2 window handle
|
---|
192 | }
|
---|
193 |
|
---|
194 | static HWND OS2ToWin32Handle(HWND hwnd)
|
---|
195 | {
|
---|
196 | Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
|
---|
197 |
|
---|
198 | if(window) {
|
---|
199 | return window->getWindowHandle();
|
---|
200 | }
|
---|
201 | else return hwnd; //OS/2 window handle
|
---|
202 | }
|
---|
203 |
|
---|
204 | static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
|
---|
205 | static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
|
---|
206 |
|
---|
207 | protected:
|
---|
208 | #ifndef OS2_INCLUDED
|
---|
209 | BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
|
---|
210 | #endif
|
---|
211 | LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
212 | LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
213 | void Init();
|
---|
214 |
|
---|
215 | HWND OS2Hwnd;
|
---|
216 | HWND OS2HwndFrame;
|
---|
217 | HWND OS2HwndMenu;
|
---|
218 | HWND Win32Hwnd;
|
---|
219 | BOOL isUnicode;
|
---|
220 |
|
---|
221 | int posx, posy, width, height;
|
---|
222 |
|
---|
223 | // values normally contained in the standard window words
|
---|
224 | ULONG dwExStyle; //GWL_EXSTYLE
|
---|
225 | ULONG dwStyle; //GWL_STYLE
|
---|
226 | WNDPROC win32wndproc; //GWL_WNDPROC
|
---|
227 | ULONG hInstance; //GWL_HINSTANCE
|
---|
228 | //Moved in ChildWindow class
|
---|
229 | ///// Win32BaseWindow *parent; //GWL_HWNDPARENT
|
---|
230 | ULONG windowId; //GWL_ID
|
---|
231 | ULONG userData; //GWL_USERDATA
|
---|
232 |
|
---|
233 | HWND hwndLinkAfter;
|
---|
234 | DWORD flags;
|
---|
235 | DWORD lastHitTestVal; //Last value returned by WM_NCHITTEST handler
|
---|
236 |
|
---|
237 | BOOL isIcon;
|
---|
238 | BOOL fCreated;
|
---|
239 | BOOL fFirstShow;
|
---|
240 | BOOL fIsDialog;
|
---|
241 |
|
---|
242 | Win32BaseWindow *owner;
|
---|
243 |
|
---|
244 | Win32Resource *acceltableResource;
|
---|
245 | Win32Resource *menuResource;
|
---|
246 | Win32Resource *iconResource;
|
---|
247 |
|
---|
248 | char *windowNameA;
|
---|
249 | WCHAR *windowNameW;
|
---|
250 | ULONG wndNameLength; //including 0 terminator
|
---|
251 |
|
---|
252 | ULONG *userWindowLong;
|
---|
253 | ULONG nrUserWindowLong;
|
---|
254 |
|
---|
255 | RECT rectWindow;
|
---|
256 | RECT rectClient;
|
---|
257 |
|
---|
258 | Win32WndClass *windowClass;
|
---|
259 |
|
---|
260 | static GenericObject *windows;
|
---|
261 |
|
---|
262 | private:
|
---|
263 | #ifndef OS2_INCLUDED
|
---|
264 | void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
|
---|
265 |
|
---|
266 | LONG SendNCCalcSize(BOOL calcValidRect,
|
---|
267 | RECT *newWindowRect, RECT *oldWindowRect,
|
---|
268 | RECT *oldClientRect, WINDOWPOS *winpos,
|
---|
269 | RECT *newClientRect );
|
---|
270 |
|
---|
271 | LRESULT SendInternalMessage(ULONG msg, WPARAM wParam, LPARAM lParam)
|
---|
272 | {
|
---|
273 | if(isUnicode)
|
---|
274 | return SendInternalMessageW(msg, wParam, lParam);
|
---|
275 | else return SendInternalMessageA(msg, wParam, lParam);
|
---|
276 | }
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | public:
|
---|
280 | void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
|
---|
281 | void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
|
---|
282 |
|
---|
283 | fakeOpen32WinBaseClass fakeWinBase;
|
---|
284 |
|
---|
285 | BOOL isOwnDC() { return (windowClass->getStyle() & CS_OWNDC_W); }
|
---|
286 | HDC getOwnDC() { return ownDC; }
|
---|
287 | void setOwnDC(HDC hdc) { ownDC = hdc; }
|
---|
288 | protected:
|
---|
289 | HDC ownDC;
|
---|
290 |
|
---|
291 | ULONG EraseBkgndFlag:1,
|
---|
292 | PSEraseFlag:1,
|
---|
293 | SupressEraseFlag:1,
|
---|
294 | filler:29;
|
---|
295 | public:
|
---|
296 | VOID setEraseBkgnd (BOOL erase, BOOL PSErase = FALSE)
|
---|
297 | { EraseBkgndFlag = erase; PSEraseFlag = PSErase; }
|
---|
298 | VOID setSupressErase (BOOL erase = FALSE)
|
---|
299 | { SupressEraseFlag = erase; }
|
---|
300 | BOOL isEraseBkgnd() { return EraseBkgndFlag; }
|
---|
301 | BOOL isPSErase() { return EraseBkgndFlag | PSEraseFlag; }
|
---|
302 | BOOL isSupressErase() { return SupressEraseFlag; }
|
---|
303 | };
|
---|
304 |
|
---|
305 |
|
---|
306 | #define BUTTON_LEFTDOWN 0
|
---|
307 | #define BUTTON_LEFTUP 1
|
---|
308 | #define BUTTON_LEFTDBLCLICK 2
|
---|
309 | #define BUTTON_RIGHTUP 3
|
---|
310 | #define BUTTON_RIGHTDOWN 4
|
---|
311 | #define BUTTON_RIGHTDBLCLICK 5
|
---|
312 | #define BUTTON_MIDDLEUP 6
|
---|
313 | #define BUTTON_MIDDLEDOWN 7
|
---|
314 | #define BUTTON_MIDDLEDBLCLICK 8
|
---|
315 |
|
---|
316 | #define WMMOVE_LBUTTON 1
|
---|
317 | #define WMMOVE_MBUTTON 2
|
---|
318 | #define WMMOVE_RBUTTON 4
|
---|
319 | #define WMMOVE_CTRL 8
|
---|
320 | #define WMMOVE_SHIFT 16
|
---|
321 |
|
---|
322 |
|
---|
323 | #define CMD_MENU 1
|
---|
324 | #define CMD_CONTROL 2
|
---|
325 | #define CMD_ACCELERATOR 3
|
---|
326 |
|
---|
327 | #define WIN32SC_SIZE 0xf000
|
---|
328 | #define WIN32SC_MOVE 0xf010
|
---|
329 | #define WIN32SC_MINIMIZE 0xf020
|
---|
330 | #define WIN32SC_MAXIMIZE 0xf030
|
---|
331 | #define WIN32SC_NEXTWINDOW 0xf040
|
---|
332 | #define WIN32SC_PREVWINDOW 0xf050
|
---|
333 | #define WIN32SC_CLOSE 0xf060
|
---|
334 | #define WIN32SC_VSCROLL 0xf070
|
---|
335 | #define WIN32SC_HSCROLL 0xf080
|
---|
336 | #define WIN32SC_MOUSEMENU 0xf090
|
---|
337 | #define WIN32SC_KEYMENU 0xf100
|
---|
338 | #define WIN32SC_ARRANGE 0xf110
|
---|
339 | #define WIN32SC_RESTORE 0xf120
|
---|
340 | #define WIN32SC_TASKLIST 0xf130
|
---|
341 | #define WIN32SC_SCREENSAVE 0xf140
|
---|
342 | #define WIN32SC_HOTKEY 0xf150
|
---|
343 |
|
---|
344 | #define KEY_ALTDOWN 1
|
---|
345 | #define KEY_PREVDOWN 2
|
---|
346 | #define KEY_UP 4
|
---|
347 | #define KEY_DEADKEY 8
|
---|
348 |
|
---|
349 | #endif //__cplusplus
|
---|
350 |
|
---|
351 | #endif //__WIN32WNDBASE_H__
|
---|