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

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

MDI activation fixes

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