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

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

mdi, setcursor, min/max/restore, dlglist changes

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