1 | /* $Id: win32wbase.h,v 1.39 1999-11-03 18:00:29 cbratschi 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 | #include <scroll.h>
|
---|
25 |
|
---|
26 | class Win32BaseWindow;
|
---|
27 |
|
---|
28 | #define OFFSET_WIN32WNDPTR 0
|
---|
29 | #define OFFSET_WIN32PM_MAGIC 4
|
---|
30 | #define NROF_WIN32WNDBYTES 8
|
---|
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, public ChildWindow
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | DWORD magic;
|
---|
57 |
|
---|
58 | Win32BaseWindow(DWORD objType);
|
---|
59 | Win32BaseWindow(HWND os2Handle,VOID* win32WndProc);
|
---|
60 | Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
|
---|
61 | virtual ~Win32BaseWindow();
|
---|
62 |
|
---|
63 | virtual ULONG MsgCreate(HWND hwndFrame, HWND hwndClient);
|
---|
64 | ULONG MsgQuit();
|
---|
65 | ULONG MsgClose();
|
---|
66 | ULONG MsgDestroy();
|
---|
67 | virtual ULONG MsgEnable(BOOL fEnable);
|
---|
68 | ULONG MsgShow(BOOL fShow);
|
---|
69 | ULONG MsgPosChanging(LPARAM lp);
|
---|
70 | ULONG MsgPosChanged(LPARAM lp);
|
---|
71 | ULONG MsgMove(ULONG x, ULONG y);
|
---|
72 | ULONG MsgHitTest(ULONG x, ULONG y);
|
---|
73 | ULONG MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize);
|
---|
74 | virtual ULONG MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd);
|
---|
75 | ULONG MsgSetFocus(HWND hwnd);
|
---|
76 | ULONG MsgKillFocus(HWND hwnd);
|
---|
77 | ULONG MsgTimer(ULONG TimerID);
|
---|
78 | ULONG MsgSysTimer(ULONG TimerID);
|
---|
79 | ULONG MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos);
|
---|
80 | ULONG MsgCommand(ULONG cmd, ULONG Id, HWND hwnd);
|
---|
81 | ULONG MsgSysCommand(ULONG win32sc, ULONG x, ULONG y);
|
---|
82 | ULONG MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags);
|
---|
83 | ULONG MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey);
|
---|
84 | ULONG MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed);
|
---|
85 | ULONG MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey);
|
---|
86 | ULONG MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed);
|
---|
87 | ULONG MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly);
|
---|
88 | ULONG MsgMouseMove(ULONG keystate, ULONG x, ULONG y);
|
---|
89 | ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
|
---|
90 | ULONG MsgEraseBackGround(HDC hdc);
|
---|
91 | ULONG MsgSetText(LPSTR lpsz, LONG cch);
|
---|
92 | ULONG MsgGetTextLength();
|
---|
93 | char *MsgGetText();
|
---|
94 |
|
---|
95 | virtual LONG SetWindowLongA(int index, ULONG value);
|
---|
96 | virtual ULONG GetWindowLongA(int index);
|
---|
97 | virtual WORD SetWindowWord(int index, WORD value);
|
---|
98 | virtual WORD GetWindowWord(int index);
|
---|
99 |
|
---|
100 | DWORD getStyle() { return dwStyle; };
|
---|
101 | void setStyle(DWORD newstyle) { dwStyle = newstyle; };
|
---|
102 | DWORD getExStyle() { return dwExStyle; };
|
---|
103 | void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
|
---|
104 | HWND getWindowHandle() { return Win32Hwnd; };
|
---|
105 | HWND getOS2WindowHandle() { return OS2Hwnd; };
|
---|
106 | HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
|
---|
107 | Win32WndClass *getWindowClass() { return windowClass; };
|
---|
108 |
|
---|
109 | BOOL isFrameWindow();
|
---|
110 | virtual BOOL isMDIClient();
|
---|
111 | virtual BOOL isMDIChild();
|
---|
112 |
|
---|
113 | Win32BaseWindow *getParent() { return (Win32BaseWindow *)ChildWindow::GetParent(); };
|
---|
114 | void setParent(Win32BaseWindow *pwindow) { ChildWindow::SetParent((ChildWindow *)pwindow); };
|
---|
115 | WNDPROC getWindowProc() { return win32wndproc; };
|
---|
116 | void setWindowProc(WNDPROC newproc) { win32wndproc = newproc; };
|
---|
117 | DWORD getWindowId() { return windowId; };
|
---|
118 | void setWindowId(DWORD id);
|
---|
119 | ULONG getWindowHeight() { return rectClient.bottom - rectClient.top; };
|
---|
120 | ULONG getWindowWidth() { return rectClient.right - rectClient.left; };
|
---|
121 | BOOL isChild();
|
---|
122 | PRECT getClientRect() { return &rectClient; };
|
---|
123 | void setClientRect(PRECT rect) { rectClient = *rect; };
|
---|
124 | PRECT getWindowRect() { return &rectWindow; };
|
---|
125 | void setClientRect(LONG left, LONG top, LONG right, LONG bottom)
|
---|
126 | {
|
---|
127 | rectClient.left = left; rectClient.top = top;
|
---|
128 | rectClient.right = right; rectClient.bottom = bottom;
|
---|
129 | };
|
---|
130 | void setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
|
---|
131 | {
|
---|
132 | rectWindow.left = left; rectWindow.top = top;
|
---|
133 | rectWindow.right = right; rectWindow.bottom = bottom;
|
---|
134 | };
|
---|
135 | void setWindowRect(PRECT rect) { rectWindow = *rect; };
|
---|
136 | DWORD getFlags() { return flags; };
|
---|
137 | void setFlags(DWORD newflags) { flags = newflags; };
|
---|
138 |
|
---|
139 | HACCEL GetAccelTable() { return (HACCEL) acceltableResource; };
|
---|
140 | BOOL SetAccelTable(ULONG hAccel);
|
---|
141 |
|
---|
142 | HMENU GetMenu() { return (HMENU) OS2HwndMenu; };
|
---|
143 | BOOL SetMenu(ULONG hMenu);
|
---|
144 |
|
---|
145 | BOOL SetIcon(HICON hIcon);
|
---|
146 | HICON GetIcon() { return (HICON) iconResource; };
|
---|
147 |
|
---|
148 | BOOL ShowWindow(ULONG nCmdShow);
|
---|
149 | BOOL SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
|
---|
150 | BOOL SetWindowPlacement(WINDOWPLACEMENT *winpos);
|
---|
151 | BOOL DestroyWindow();
|
---|
152 | HWND SetActiveWindow();
|
---|
153 | HWND GetParent();
|
---|
154 | HWND SetParent(HWND hwndNewParent);
|
---|
155 | BOOL IsChild(HWND hwndParent);
|
---|
156 | HWND GetTopWindow();
|
---|
157 | Win32BaseWindow *GetTopParent();
|
---|
158 | BOOL UpdateWindow();
|
---|
159 | BOOL IsIconic();
|
---|
160 | HWND GetWindow(UINT uCmd);
|
---|
161 | virtual BOOL EnableWindow(BOOL fEnable);
|
---|
162 | BOOL CloseWindow();
|
---|
163 | static HWND GetActiveWindow();
|
---|
164 | //Window handle has already been verified, so just return true
|
---|
165 | BOOL IsWindow() { return TRUE; };
|
---|
166 | BOOL IsDialog() { return fIsDialog; };
|
---|
167 | BOOL IsModalDialog() { return fIsModalDialog; };
|
---|
168 | BOOL IsModalDialogOwner() { return fIsModalDialogOwner; };
|
---|
169 | VOID setModalDialogOwner(BOOL fMDO) { fIsModalDialogOwner = fMDO; };
|
---|
170 | VOID setOS2HwndModalDialog(HWND aHwnd) { OS2HwndModalDialog = aHwnd; };
|
---|
171 | HWND getOS2HwndModalDialog() { return OS2HwndModalDialog; };
|
---|
172 | BOOL CanReceiveSizeMsgs() { return !fNoSizeMsg; };
|
---|
173 | BOOL IsWindowDestroyed() { return fIsDestroyed; };
|
---|
174 | BOOL IsWindowEnabled();
|
---|
175 | BOOL IsWindowVisible();
|
---|
176 | BOOL IsUnicode() { return isUnicode; };
|
---|
177 | BOOL GetWindowRect(PRECT pRect);
|
---|
178 | int GetWindowTextLength();
|
---|
179 | int GetWindowTextA(LPSTR lpsz, int cch);
|
---|
180 | int GetWindowTextW(LPWSTR lpsz, int cch);
|
---|
181 | BOOL SetWindowTextA(LPSTR lpsz);
|
---|
182 | BOOL SetWindowTextW(LPWSTR lpsz);
|
---|
183 | BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
|
---|
184 | Win32WndClass *getClass() { return windowClass; };
|
---|
185 | char *getWindowNameA() { return windowNameA; };
|
---|
186 | Win32BaseWindow *getOwner() { return owner; };
|
---|
187 |
|
---|
188 | Win32BaseWindow *getTopParent();
|
---|
189 | SCROLLBAR_INFO *getScrollInfo(int nBar);
|
---|
190 | HWND getVertScrollHandle() { return hwndVertScroll; };
|
---|
191 | HWND getHorzScrollHandle() { return hwndHorzScroll; };
|
---|
192 | VOID subclassScrollBars(BOOL subHorz,BOOL subVert);
|
---|
193 |
|
---|
194 | LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
195 | LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
196 | BOOL PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
197 | BOOL PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
198 | LRESULT DefWindowProcA(UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
199 | LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
200 |
|
---|
201 | LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
|
---|
202 |
|
---|
203 | void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
|
---|
204 |
|
---|
205 | Win32BaseWindow *FindWindowById(int id);
|
---|
206 |
|
---|
207 | static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
|
---|
208 | BOOL fUnicode = 0);
|
---|
209 |
|
---|
210 | BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
|
---|
211 |
|
---|
212 | HWND getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious);
|
---|
213 | HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
|
---|
214 |
|
---|
215 | static HWND Win32ToOS2Handle(HWND hwnd);
|
---|
216 | static HWND Win32ToOS2FrameHandle(HWND hwnd);
|
---|
217 | static HWND OS2ToWin32Handle(HWND hwnd);
|
---|
218 |
|
---|
219 | static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
|
---|
220 | static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
|
---|
221 | static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
|
---|
222 |
|
---|
223 | static void DestroyAll();
|
---|
224 |
|
---|
225 | PVOID getOldFrameProc() { return pOldFrameProc; };
|
---|
226 | VOID setOldFrameProc(PVOID aOldFrameProc) { pOldFrameProc = aOldFrameProc; };
|
---|
227 | ULONG getBorderWidth() { return borderWidth; };
|
---|
228 | ULONG getBorderHeight() { return borderHeight; };
|
---|
229 |
|
---|
230 | static void NC_AdjustRectInner(LPRECT rect, DWORD style, DWORD exStyle);
|
---|
231 | static void NC_AdjustRectOuter(LPRECT rect, DWORD style, BOOL menu, DWORD exStyle);
|
---|
232 | static BOOL WindowNeedsWMBorder( DWORD style, DWORD exStyle );
|
---|
233 |
|
---|
234 | PVOID getOldWndProc() { return pOldWndProc; }
|
---|
235 | VOID setOldWndProc(PVOID aOldWndProc) { pOldWndProc = aOldWndProc; }
|
---|
236 | BOOL isSubclassedOS2Wnd() { return fIsSubclassedOS2Wnd; };
|
---|
237 |
|
---|
238 | protected:
|
---|
239 | #ifndef OS2_INCLUDED
|
---|
240 | BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
|
---|
241 | #endif
|
---|
242 | LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
243 | LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
|
---|
244 | void Init();
|
---|
245 | void setExtendedKey(ULONG virtualkey, ULONG *lParam);
|
---|
246 |
|
---|
247 | HWND OS2Hwnd;
|
---|
248 | HWND OS2HwndFrame;
|
---|
249 | HWND OS2HwndMenu;
|
---|
250 | HWND Win32Hwnd;
|
---|
251 | BOOL isUnicode;
|
---|
252 |
|
---|
253 | int posx, posy, width, height;
|
---|
254 |
|
---|
255 | // values normally contained in the standard window words
|
---|
256 | ULONG dwExStyle; //GWL_EXSTYLE
|
---|
257 | ULONG dwStyle; //GWL_STYLE
|
---|
258 | WNDPROC win32wndproc; //GWL_WNDPROC
|
---|
259 | ULONG hInstance; //GWL_HINSTANCE
|
---|
260 | //Moved in ChildWindow class
|
---|
261 | ///// Win32BaseWindow *parent; //GWL_HWNDPARENT
|
---|
262 | ULONG windowId; //GWL_ID
|
---|
263 | ULONG userData; //GWL_USERDATA
|
---|
264 |
|
---|
265 | HWND hwndLinkAfter;
|
---|
266 | DWORD flags;
|
---|
267 | LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
|
---|
268 |
|
---|
269 | BOOL isIcon;
|
---|
270 | BOOL fFirstShow;
|
---|
271 | BOOL fIsDialog;
|
---|
272 | BOOL fIsModalDialog;
|
---|
273 | BOOL fIsModalDialogOwner;
|
---|
274 | HWND OS2HwndModalDialog;
|
---|
275 | BOOL fInternalMsg; //Used to distinguish between messages
|
---|
276 | //sent by PM and those sent by apps
|
---|
277 | BOOL fNoSizeMsg;
|
---|
278 | BOOL fIsDestroyed;
|
---|
279 | BOOL fCreated;
|
---|
280 |
|
---|
281 | PVOID pOldFrameProc;
|
---|
282 | ULONG borderWidth;
|
---|
283 | ULONG borderHeight;
|
---|
284 |
|
---|
285 | PVOID pOldWndProc;
|
---|
286 | BOOL fIsSubclassedOS2Wnd; //subclassed OS/2 window: Netscape plug-in/scrollbar
|
---|
287 |
|
---|
288 | Win32BaseWindow *owner;
|
---|
289 |
|
---|
290 | Win32Resource *acceltableResource;
|
---|
291 | Win32Resource *iconResource;
|
---|
292 |
|
---|
293 | char *windowNameA;
|
---|
294 | WCHAR *windowNameW;
|
---|
295 | ULONG wndNameLength; //including 0 terminator
|
---|
296 |
|
---|
297 | ULONG *userWindowLong;
|
---|
298 | ULONG nrUserWindowLong;
|
---|
299 |
|
---|
300 | RECT rectWindow;
|
---|
301 | RECT rectClient;
|
---|
302 |
|
---|
303 | CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
|
---|
304 | ULONG sw; //set in CreateWindowExA, used in MsgCreate method
|
---|
305 |
|
---|
306 | SCROLLBAR_INFO *vertScrollInfo;
|
---|
307 | SCROLLBAR_INFO *horzScrollInfo;
|
---|
308 | HWND hwndHorzScroll; //os/2 handle
|
---|
309 | HWND hwndVertScroll; //os/2 handle
|
---|
310 |
|
---|
311 | Win32WndClass *windowClass;
|
---|
312 |
|
---|
313 | static GenericObject *windows;
|
---|
314 |
|
---|
315 | private:
|
---|
316 | #ifndef OS2_INCLUDED
|
---|
317 | void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
|
---|
318 | LONG HandleWindowPosChanging(WINDOWPOS *winpos);
|
---|
319 | LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
|
---|
320 |
|
---|
321 | LONG SendNCCalcSize(BOOL calcValidRect,
|
---|
322 | RECT *newWindowRect, RECT *oldWindowRect,
|
---|
323 | RECT *oldClientRect, WINDOWPOS *winpos,
|
---|
324 | RECT *newClientRect );
|
---|
325 |
|
---|
326 | LONG NCHandleCalcSize(WPARAM wParam, NCCALCSIZE_PARAMS *ncsize);
|
---|
327 |
|
---|
328 | LRESULT SendInternalMessage(ULONG msg, WPARAM wParam, LPARAM lParam)
|
---|
329 | {
|
---|
330 | if(isUnicode)
|
---|
331 | return SendInternalMessageW(msg, wParam, lParam);
|
---|
332 | else return SendInternalMessageA(msg, wParam, lParam);
|
---|
333 | }
|
---|
334 | #endif
|
---|
335 |
|
---|
336 | public:
|
---|
337 | void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
|
---|
338 | void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
|
---|
339 |
|
---|
340 | fakeOpen32WinBaseClass fakeWinBase;
|
---|
341 |
|
---|
342 | BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC_W); }
|
---|
343 | HDC getOwnDC() { return ownDC; }
|
---|
344 | void setOwnDC(HDC hdc) { ownDC = hdc; }
|
---|
345 | protected:
|
---|
346 | HDC ownDC;
|
---|
347 |
|
---|
348 | ULONG EraseBkgndFlag:1,
|
---|
349 | PSEraseFlag:1,
|
---|
350 | SupressEraseFlag:1,
|
---|
351 | filler:29;
|
---|
352 | public:
|
---|
353 | VOID setEraseBkgnd (BOOL erase, BOOL PSErase = FALSE)
|
---|
354 | { EraseBkgndFlag = erase; PSEraseFlag = PSErase; }
|
---|
355 | VOID setSupressErase (BOOL erase = FALSE)
|
---|
356 | { SupressEraseFlag = erase; }
|
---|
357 | BOOL isEraseBkgnd() { return EraseBkgndFlag; }
|
---|
358 | BOOL isPSErase() { return EraseBkgndFlag | PSEraseFlag; }
|
---|
359 | BOOL isSupressErase() { return SupressEraseFlag; }
|
---|
360 | };
|
---|
361 |
|
---|
362 |
|
---|
363 | #define BUTTON_LEFTDOWN 0
|
---|
364 | #define BUTTON_LEFTUP 1
|
---|
365 | #define BUTTON_LEFTDBLCLICK 2
|
---|
366 | #define BUTTON_RIGHTUP 3
|
---|
367 | #define BUTTON_RIGHTDOWN 4
|
---|
368 | #define BUTTON_RIGHTDBLCLICK 5
|
---|
369 | #define BUTTON_MIDDLEUP 6
|
---|
370 | #define BUTTON_MIDDLEDOWN 7
|
---|
371 | #define BUTTON_MIDDLEDBLCLICK 8
|
---|
372 |
|
---|
373 | #define WMMOVE_LBUTTON 1
|
---|
374 | #define WMMOVE_MBUTTON 2
|
---|
375 | #define WMMOVE_RBUTTON 4
|
---|
376 | #define WMMOVE_CTRL 8
|
---|
377 | #define WMMOVE_SHIFT 16
|
---|
378 |
|
---|
379 |
|
---|
380 | #define CMD_MENU 1
|
---|
381 | #define CMD_CONTROL 2
|
---|
382 | #define CMD_ACCELERATOR 3
|
---|
383 |
|
---|
384 | #define KEY_ALTDOWN 1
|
---|
385 | #define KEY_PREVDOWN 2
|
---|
386 | #define KEY_UP 4
|
---|
387 | #define KEY_DEADKEY 8
|
---|
388 |
|
---|
389 | #endif //__cplusplus
|
---|
390 |
|
---|
391 | #endif //__WIN32WNDBASE_H__
|
---|