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

Last change on this file since 6166 was 6166, checked in by sandervl, 24 years ago

SetParent bugfix

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