source: trunk/src/user32/win32wbase.h@ 5173

Last change on this file since 5173 was 5173, checked in by sandervl, 25 years ago

DestroyWindow during CreateWindow fix

File size: 18.7 KB
Line 
1/* $Id: win32wbase.h,v 1.106 2001-02-18 17:59:05 sandervl 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 <scroll.h>
24
25class Win32BaseWindow;
26
27#define OFFSET_WIN32WNDPTR 0
28#define OFFSET_WIN32PM_MAGIC 4
29#define OFFSET_WIN32FLAGS 8
30#define NROF_WIN32WNDBYTES 12
31
32#define WIN32PM_MAGIC 0x12345678
33#define CheckMagicDword(a) (a==WIN32PM_MAGIC)
34
35typedef struct {
36 USHORT cb;
37 Win32BaseWindow *win32wnd;
38 ULONG win32CreateStruct; //or dialog create dword
39} CUSTOMWNDDATA;
40
41typedef struct tagPROPERTY
42{
43 struct tagPROPERTY *next; /* Next property in window list */
44 HANDLE handle; /* User's data */
45 LPSTR string; /* Property string (or atom) */
46} PROPERTY;
47
48//PostThreadMessage is done through Open32; which means the message id will be translated
49//(0xc00 added)
50#define OPEN32_MSGDIFF 0xC00
51#define WIN32APP_POSTMSG (0x1000+OPEN32_MSGDIFF)
52
53//PM doesn't allow SetFocus during WM_SETFOCUS message processing; must delay
54//this by posting a message
55#define WIN32APP_SETFOCUSMSG (0x1001+OPEN32_MSGDIFF)
56
57#define WIN32MSG_MAGICA 0x12345678
58#define WIN32MSG_MAGICW 0x12345679
59
60typedef struct
61{
62 ULONG Msg;
63 ULONG wParam;
64 ULONG lParam;
65} POSTMSG_PACKET;
66
67#define BROADCAST_SEND 0
68#define BROADCAST_POST 1
69
70#define HAS_DLGFRAME(style,exStyle) \
71 (((exStyle) & WS_EX_DLGMODALFRAME) || \
72 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
73
74#define HAS_THICKFRAME(style,exStyle) \
75 (((style) & WS_THICKFRAME) && \
76 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
77#if 0
78 (((style) & WS_THICKFRAME) && \
79 !((exStyle) & WS_EX_DLGMODALFRAME) && \
80 !((style) & WS_CHILD))
81#endif
82
83#define HAS_THINFRAME(style) \
84 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
85
86#define HAS_BIGFRAME(style,exStyle) \
87 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
88 ((exStyle) & WS_EX_DLGMODALFRAME))
89
90#define HAS_ANYFRAME(style,exStyle) \
91 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
92 ((exStyle) & WS_EX_DLGMODALFRAME) || \
93 !((style) & (WS_CHILD | WS_POPUP)))
94
95#define HAS_3DFRAME(exStyle) \
96 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
97
98#define HAS_BORDER(style, exStyle) \
99 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
100
101#define IS_OVERLAPPED(style) \
102 !(style & (WS_CHILD | WS_POPUP))
103
104#define HAS_MENU() (!(getStyle() & WS_CHILD) && (GetMenu() != 0))
105
106class Win32BaseWindow : public GenericObject, public ChildWindow
107{
108public:
109 DWORD magic;
110
111 Win32BaseWindow(DWORD objType);
112 Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
113virtual ~Win32BaseWindow();
114
115virtual ULONG MsgCreate(HWND hwndOS2);
116 ULONG MsgQuit();
117 ULONG MsgClose();
118 ULONG MsgDestroy();
119virtual ULONG MsgEnable(BOOL fEnable);
120 ULONG MsgShow(BOOL fShow);
121 ULONG MsgPosChanging(LPARAM lp);
122 ULONG MsgPosChanged(LPARAM lp);
123 ULONG MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win);
124 ULONG MsgSetFocus(HWND hwnd);
125 ULONG MsgKillFocus(HWND hwnd);
126 ULONG MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos);
127 ULONG MsgButton(MSG *msg);
128 ULONG MsgMouseMove(MSG *msg);
129 ULONG MsgChar(MSG *msg);
130 ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
131 ULONG MsgEraseBackGround(HDC hdc);
132 ULONG MsgHitTest(MSG *msg);
133 ULONG MsgNCPaint();
134 ULONG MsgFormatFrame(WINDOWPOS *lpWndPos);
135 ULONG DispatchMsgA(MSG *msg);
136 ULONG DispatchMsgW(MSG *msg);
137
138 ULONG MsgSetText(LPSTR lpsz, LONG cch);
139 ULONG MsgGetTextLength();
140 void MsgGetText(char *wndtext, ULONG textlength);
141 VOID updateWindowStyle(DWORD oldExStyle,DWORD oldStyle);
142
143virtual LONG SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
144virtual ULONG GetWindowLongA(int index, BOOL fUnicode = FALSE);
145virtual WORD SetWindowWord(int index, WORD value);
146virtual WORD GetWindowWord(int index);
147
148 DWORD getStyle() { return dwStyle; };
149 void setStyle(DWORD newstyle) { dwStyle = newstyle; };
150 DWORD getExStyle() { return dwExStyle; };
151 void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
152 ULONG getInstance() { return hInstance; };
153 void setInstance(ULONG newinstance) { hInstance = newinstance; };
154 HWND getWindowHandle() { return Win32Hwnd; };
155 HWND getOS2WindowHandle() { return OS2Hwnd; };
156 Win32WndClass *getWindowClass() { return windowClass; };
157
158 LONG getLastHitTestVal() { return lastHitTestVal; }
159 LONG sendHitTest(ULONG lParam);
160
161 DWORD getWindowContextHelpId() { return contextHelpId; };
162 void setWindowContextHelpId(DWORD id){ contextHelpId = id; };
163
164 BOOL isFrameWindow();
165virtual BOOL isMDIClient();
166virtual BOOL isMDIChild();
167virtual BOOL isDesktopWindow();
168
169 BOOL fHasParentDC() { return fParentDC; };
170
171Win32BaseWindow *getParent();
172 void setParent(Win32BaseWindow *pwindow) { setParentOfChild((ChildWindow *)pwindow); };
173 WNDPROC getWindowProc() { return win32wndproc; };
174 void setWindowProc(WNDPROC newproc) { win32wndproc = newproc; };
175 DWORD getWindowId() { return dwIDMenu; };
176 void setWindowId(DWORD id);
177 ULONG getWindowHeight() { return rectWindow.bottom - rectWindow.top; };
178 ULONG getWindowWidth() { return rectWindow.right - rectWindow.left; };
179 ULONG getClientHeight() { return rectClient.bottom - rectClient.top; };
180 ULONG getClientWidth() { return rectClient.right - rectClient.left; };
181 BOOL isChild();
182 PRECT getClientRectPtr() { return &rectClient; };
183 void getClientRect(PRECT rect)
184 {
185 *rect = rectClient;
186 rect->right -= rect->left;
187 rect->bottom -= rect->top;
188 rect->left = rect->top = 0;
189 }
190 void setClientRect(PRECT rect) { rectClient = *rect; };
191 PRECT getWindowRect() { return &rectWindow; };
192 void setClientRect(LONG left, LONG top, LONG right, LONG bottom)
193 {
194 rectClient.left = left; rectClient.top = top;
195 rectClient.right = right; rectClient.bottom = bottom;
196 };
197 void setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
198 {
199 rectWindow.left = left; rectWindow.top = top;
200 rectWindow.right = right; rectWindow.bottom = bottom;
201 };
202 void setWindowRect(PRECT rect) { rectWindow = *rect; };
203 DWORD getFlags() { return flags; };
204 void setFlags(DWORD newflags) { flags = newflags; };
205
206 HMENU GetMenu() { return dwIDMenu; };
207 VOID SetMenu(HMENU newMenu) { dwIDMenu = newMenu; };
208 void SetSysMenu(HMENU hSystemMenu) { hSysMenu = hSystemMenu; };
209 HMENU GetSysMenu() { return hSysMenu; }
210
211 HICON IconForWindow(WPARAM fType);
212
213 void SetWindowRegion(HRGN hRegion) { hWindowRegion = hRegion; };
214 HRGN GetWindowRegion() { return hWindowRegion; };
215
216 //Save old clip region for CS_OWNDC windows (in BeginPaint)
217 HRGN GetClipRegion() { return hClipRegion; };
218 void SetClipRegion(HRGN hRegion) { hClipRegion = hRegion; };
219
220 BOOL ShowWindow(ULONG nCmdShow);
221 BOOL SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
222 BOOL SetWindowPlacement(WINDOWPLACEMENT *winpos);
223 BOOL GetWindowPlacement(LPWINDOWPLACEMENT winpos);
224 BOOL DestroyWindow();
225 HWND SetActiveWindow();
226 HWND GetParent();
227 HWND SetParent(HWND hwndNewParent);
228
229 BOOL IsChild(HWND hwndParent);
230
231 HWND GetTopWindow();
232Win32BaseWindow *GetTopParent();
233
234 HWND GetWindow(UINT uCmd);
235 virtual BOOL EnableWindow(BOOL fEnable);
236 BOOL CloseWindow();
237 static HWND GetActiveWindow();
238 //Window handle has already been verified, so just return true
239 BOOL IsWindow() { return TRUE; };
240 BOOL IsDialog() { return fIsDialog; };
241 BOOL IsModalDialog() { return fIsModalDialog; };
242 BOOL IsModalDialogOwner() { return fIsModalDialogOwner; };
243 VOID setModalDialogOwner(BOOL fMDO) { fIsModalDialogOwner = fMDO; };
244 VOID setOS2HwndModalDialog(HWND aHwnd) { OS2HwndModalDialog = aHwnd; };
245 HWND getOS2HwndModalDialog() { return OS2HwndModalDialog; };
246 BOOL CanReceiveSizeMsgs() { return !fNoSizeMsg; };
247 BOOL IsWindowCreated() { return fCreated; }
248 BOOL IsWindowDestroyed() { return fIsDestroyed; };
249 BOOL IsWindowEnabled();
250 BOOL IsWindowVisible();
251 BOOL IsWindowIconic();
252 //Window procedure type
253 BOOL IsWindowUnicode();
254
255 int GetWindowTextLength();
256 int GetWindowTextA(LPSTR lpsz, int cch);
257 int GetWindowTextW(LPWSTR lpsz, int cch);
258 BOOL SetWindowTextA(LPSTR lpsz);
259 BOOL SetWindowTextW(LPWSTR lpsz);
260 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
261 CHAR *getWindowNamePtrA();
262 WCHAR *getWindowNamePtrW();
263 VOID freeWindowNamePtr(PVOID namePtr);
264 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
265 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
266Win32WndClass *getClass() { return windowClass; };
267Win32BaseWindow *getOwner() { return owner; };
268 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
269
270 SCROLLBAR_INFO *getScrollInfo(int nBar);
271
272 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
273 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
274static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
275static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
276 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
277
278 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
279 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
280
281 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
282 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
283
284 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
285
286Win32BaseWindow *FindWindowById(int id);
287
288 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow);
289
290 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
291 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
292 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
293
294 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
295
296 BOOL isComingToTop() { return fComingToTop; };
297 void setComingToTop(BOOL fTop) { fComingToTop = fTop; };
298 BOOL isInTasklist() { return fTaskList; };
299
300 //window property methods
301 HANDLE getProp(LPCSTR str);
302 BOOL setProp(LPCSTR str, HANDLE handle);
303 HANDLE removeProp(LPCSTR str);
304 INT enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
305 INT enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
306
307static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
308static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
309
310 static void DestroyAll();
311
312protected:
313#ifndef OS2_INCLUDED
314 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
315#endif
316 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
317 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
318 void Init();
319
320 void NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect);
321
322 //called in destructor to remove all (if any) window properties
323 void removeWindowProps();
324 PROPERTY *findWindowProperty(LPCSTR str);
325
326 HWND OS2Hwnd;
327 HMENU hSysMenu;
328 HWND Win32Hwnd;
329 BOOL isUnicode;
330
331 int posx, posy, width, height;
332
333 // values normally contained in the standard window words
334 ULONG dwExStyle; //GWL_EXSTYLE
335 ULONG dwStyle; //GWL_STYLE
336 WNDPROC win32wndproc; //GWL_WNDPROC
337 ULONG hInstance; //GWL_HINSTANCE
338//Moved in ChildWindow class
339///// Win32BaseWindow *parent; //GWL_HWNDPARENT
340 ULONG dwIDMenu; //GWL_ID
341 ULONG userData; //GWL_USERDATA
342
343 HWND hwndLinkAfter;
344 DWORD flags;
345 DWORD contextHelpId;
346 DWORD hotkey;
347 LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
348
349 BOOL fFirstShow;
350 BOOL fIsDialog;
351 BOOL fIsModalDialog;
352 BOOL fIsModalDialogOwner;
353 HWND OS2HwndModalDialog;
354 BOOL fInternalMsg; //Used to distinguish between messages
355 //sent by PM and those sent by apps
356 BOOL fNoSizeMsg;
357 BOOL fIsDestroyed;
358 BOOL fDestroyWindowCalled; //DestroyWindow was called for this window
359 BOOL fCreated;
360 BOOL fCreationFinished; //True when window or dialog has been created successfully
361 //Needed to prevent DestroyWindow from deleting the window
362 //object during construction
363 BOOL fTaskList; //should be listed in PM tasklist or not
364 BOOL fXDefault;
365 BOOL fCXDefault;
366 BOOL fParentDC;
367 BOOL fComingToTop;
368 BOOL fCreateSetWindowPos; //FALSE -> SetWindowPos in Win32BaseWindow::MsgCreate not yet called
369
370 HRGN hWindowRegion;
371 HRGN hClipRegion;
372
373 DWORD dwThreadId; //id of thread that created this window
374 DWORD dwProcessId; //id of process that created this window
375
376 Win32BaseWindow *owner;
377 HICON hIcon,hIconSm;
378
379 char *windowNameA;
380 WCHAR *windowNameW;
381 ULONG wndNameLength; //including 0 terminator
382
383 ULONG *userWindowLong;
384 ULONG nrUserWindowLong;
385
386 RECT rectWindow; //relative to parent
387 RECT rectClient; //relative to frame
388WINDOWPLACEMENT windowpos;
389
390 PROPERTY *propertyList;
391
392 HANDLE hTaskList; //PM specific (switchentry handle)
393
394CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
395 ULONG sw; //set in CreateWindowExA, used in MsgCreate method
396
397SCROLLBAR_INFO *vertScrollInfo;
398SCROLLBAR_INFO *horzScrollInfo;
399
400Win32WndClass *windowClass;
401
402static GenericObject *windows;
403
404private:
405#ifndef OS2_INCLUDED
406 void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
407 UINT MinMaximize(UINT cmd, LPRECT lpRect);
408 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
409 LONG HandleNCActivate(WPARAM wParam);
410 VOID TrackMinMaxHelpBox(WORD wParam);
411 VOID TrackCloseButton(WORD wParam);
412 VOID TrackScrollBar(WPARAM wParam,POINT pt);
413 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
414 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
415 LONG HandleNCRButtonUp(WPARAM wParam,LPARAM lParam);
416 VOID AdjustRectOuter(LPRECT rect,BOOL menu);
417 VOID AdjustRectInner(LPRECT rect);
418 LONG HandleNCCalcSize(BOOL calcValidRects,RECT *winRect);
419 VOID GetInsideRect(RECT *rect);
420 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
421public:
422 LONG HandleNCHitTest(POINT pt);
423 BOOL GetSysPopupPos(RECT* rect);
424private:
425 BOOL DrawSysButton(HDC hdc,RECT *rect);
426 BOOL DrawGrayButton(HDC hdc,int x,int y);
427 VOID DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
428 VOID DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
429 VOID DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
430 VOID DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
431 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
432 VOID DoNCPaint(HRGN clip,BOOL suppress_menupaint);
433 LONG HandleNCPaint(HRGN clip);
434 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
435
436 LONG SendNCCalcSize(BOOL calcValidRect,
437 RECT *newWindowRect, RECT *oldWindowRect,
438 RECT *oldClientRect, WINDOWPOS *winpos,
439 RECT *newClientRect );
440
441#else
442friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
443#endif
444
445public:
446 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
447 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
448
449 fakeOpen32WinBaseClass fakeWinBase;
450
451 VOID AdjustMaximizedRect(LPRECT rect);
452 VOID AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize);
453
454#ifndef OS2_INCLUDED
455 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC); }
456#else
457 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC_W); }
458#endif
459 HDC getOwnDC() { return ownDC; }
460 void setOwnDC(HDC hdc) { ownDC = hdc; }
461protected:
462 HDC ownDC;
463
464 ULONG EraseBkgndFlag:1,
465 filler:31;
466public:
467 VOID setEraseBkgnd (BOOL erase) { EraseBkgndFlag = erase; }
468 BOOL needsEraseBkgnd() { return EraseBkgndFlag; }
469};
470
471#endif //__cplusplus
472
473#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.