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

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

WM_NCHITTEST changes; no longer rely on PM

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