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

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

Set/GetParent changes/fixes

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