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

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

FillRect & CS_CLASSDC fixes; use critical secions for hooks

File size: 19.8 KB
Line 
1/* $Id: win32wbase.h,v 1.119 2001-06-12 17:02: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
37#define RELEASE_WNDOBJ(a) { a->release(); a = NULL; }
38
39typedef struct {
40 USHORT cb;
41 Win32BaseWindow *win32wnd;
42 ULONG win32CreateStruct; //or dialog create dword
43} CUSTOMWNDDATA;
44
45typedef struct tagPROPERTY
46{
47 struct tagPROPERTY *next; /* Next property in window list */
48 HANDLE handle; /* User's data */
49 LPSTR string; /* Property string (or atom) */
50} PROPERTY;
51
52//PostThreadMessage is done through Open32; which means the message id will be translated
53//(0xc00 added)
54#define OPEN32_MSGDIFF 0xC00
55#define WIN32APP_POSTMSG (0x1000+OPEN32_MSGDIFF)
56
57//PM doesn't allow SetFocus during WM_SETFOCUS message processing; must delay
58//this by posting a message
59//NOTE Must be smaller than WIN32APP_POSTMSG!
60#define WIN32APP_SETFOCUSMSG (WIN32APP_POSTMSG-1)
61
62#define WIN32MSG_MAGICA 0x12345678
63#define WIN32MSG_MAGICW 0x12345679
64
65typedef struct
66{
67 ULONG wParam;
68 ULONG lParam;
69} POSTMSG_PACKET;
70
71#define BROADCAST_SEND 0
72#define BROADCAST_POST 1
73
74#define HAS_DLGFRAME(style,exStyle) \
75 (((exStyle) & WS_EX_DLGMODALFRAME) || \
76 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
77
78#define HAS_THICKFRAME(style,exStyle) \
79 (((style) & WS_THICKFRAME) && \
80 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
81#if 0
82 (((style) & WS_THICKFRAME) && \
83 !((exStyle) & WS_EX_DLGMODALFRAME) && \
84 !((style) & WS_CHILD))
85#endif
86
87#define HAS_THINFRAME(style) \
88 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
89
90#define HAS_BIGFRAME(style,exStyle) \
91 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
92 ((exStyle) & WS_EX_DLGMODALFRAME))
93
94#define HAS_ANYFRAME(style,exStyle) \
95 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
96 ((exStyle) & WS_EX_DLGMODALFRAME) || \
97 !((style) & (WS_CHILD | WS_POPUP)))
98
99#define HAS_3DFRAME(exStyle) \
100 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
101
102#define HAS_BORDER(style, exStyle) \
103 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
104
105#define IS_OVERLAPPED(style) \
106 !(style & (WS_CHILD | WS_POPUP))
107
108#define HAS_MENU() (!(getStyle() & WS_CHILD) && (GetMenu() != 0))
109
110class Win32BaseWindow : public GenericObject, public ChildWindow
111{
112public:
113 Win32BaseWindow();
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 MsgNCPaint(PRECT pUpdateRect);
137 ULONG MsgFormatFrame(WINDOWPOS *lpWndPos);
138 ULONG DispatchMsgA(MSG *msg);
139 ULONG DispatchMsgW(MSG *msg);
140
141 ULONG MsgSetText(LPSTR lpsz, LONG cch);
142 ULONG MsgGetTextLength();
143 void MsgGetText(char *wndtext, ULONG textlength);
144 VOID updateWindowStyle(DWORD oldExStyle,DWORD oldStyle);
145
146virtual LONG SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
147virtual ULONG GetWindowLongA(int index, BOOL fUnicode = FALSE);
148virtual WORD SetWindowWord(int index, WORD value);
149virtual WORD GetWindowWord(int index);
150
151 DWORD getStyle() { return dwStyle; };
152 void setStyle(DWORD newstyle) { dwStyle = newstyle; };
153 DWORD getExStyle() { return dwExStyle; };
154 void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
155 ULONG getInstance() { return hInstance; };
156 void setInstance(ULONG newinstance) { hInstance = newinstance; };
157 HWND getWindowHandle() { return Win32Hwnd; };
158 HWND getOS2WindowHandle() { return OS2Hwnd; };
159 HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
160
161 Win32WndClass *getWindowClass() { return windowClass; };
162
163 LONG getLastHitTestVal() { return lastHitTestVal; }
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);
229virtual 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();
238 HWND 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 IsWindowIconic();
256 //Window procedure type
257 BOOL IsWindowUnicode();
258 BOOL IsMixMaxStateChanging() { return fMinMaxChange; };
259
260 void SetVisibleRegionChanged(BOOL changed) { fVisibleRegionChanged = changed; };
261 BOOL IsVisibleRegionChanged() { return fVisibleRegionChanged; };
262
263 int GetWindowTextLength(BOOL fUnicode);
264 int GetWindowTextLengthA() { return GetWindowTextLength(FALSE); };
265 int GetWindowTextLengthW() { return GetWindowTextLength(TRUE); };
266
267 int GetWindowTextA(LPSTR lpsz, int cch);
268 int GetWindowTextW(LPWSTR lpsz, int cch);
269 BOOL SetWindowTextA(LPSTR lpsz);
270 BOOL SetWindowTextW(LPWSTR lpsz);
271 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
272 CHAR *getWindowNamePtrA();
273 WCHAR *getWindowNamePtrW();
274 VOID freeWindowNamePtr(PVOID namePtr);
275 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
276 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
277Win32WndClass *getClass() { return windowClass; };
278Win32BaseWindow *getOwner() { return owner; };
279 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
280
281 SCROLLBAR_INFO *getScrollInfo(int nBar);
282
283 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
284 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
285static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
286static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
287 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
288
289 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
290 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
291
292 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
293 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
294
295 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
296
297 HWND FindWindowById(int id);
298
299 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow);
300
301 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
302 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
303 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
304
305 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
306
307 BOOL isComingToTop() { return fComingToTop; };
308 void setComingToTop(BOOL fTop) { fComingToTop = fTop; };
309 BOOL isInTasklist() { return fTaskList; };
310
311 //window property methods
312 HANDLE getProp(LPCSTR str);
313 BOOL setProp(LPCSTR str, HANDLE handle);
314 HANDLE removeProp(LPCSTR str);
315 INT enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
316 INT enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
317
318//Locates window in linked list and increases reference count (if found)
319//Window object must be unreferenced after usage
320static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
321static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
322static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
323
324 static void DestroyAll();
325
326protected:
327#ifndef OS2_INCLUDED
328 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
329#endif
330 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
331 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
332 void Init();
333
334 void NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect);
335
336 //called in destructor to remove all (if any) window properties
337 void removeWindowProps();
338 PROPERTY *findWindowProperty(LPCSTR str);
339
340 HWND OS2Hwnd, OS2HwndFrame;
341 HMENU hSysMenu;
342 HWND Win32Hwnd;
343
344 int posx, posy, width, height;
345
346 // values normally contained in the standard window words
347 ULONG dwExStyle; //GWL_EXSTYLE
348 ULONG dwStyle; //GWL_STYLE
349 WNDPROC win32wndproc; //GWL_WNDPROC
350 ULONG hInstance; //GWL_HINSTANCE
351//Moved in ChildWindow class
352///// Win32BaseWindow *parent; //GWL_HWNDPARENT
353 ULONG dwIDMenu; //GWL_ID
354 ULONG userData; //GWL_USERDATA
355
356
357 HWND hwndLinkAfter;
358 DWORD flags;
359 DWORD contextHelpId;
360 DWORD hotkey;
361 LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
362
363 HWND OS2HwndModalDialog;
364
365 ULONG fFirstShow:1,
366 fIsDialog:1,
367 fIsModalDialog:1,
368 fIsModalDialogOwner:1,
369 fInternalMsg:1, //Used to distinguish between messages
370 //sent by PM and those sent by apps
371 fNoSizeMsg:1,
372 fIsDestroyed:1,
373 fDestroyWindowCalled:1, //DestroyWindow was called for this window
374 fCreated:1,
375 fCreationFinished:1, //True when window or dialog has been created successfully
376 //Needed to prevent DestroyWindow from deleting the window
377 //object during construction
378 fTaskList:1, //should be listed in PM tasklist or not
379 fXDefault:1,
380 fCXDefault:1,
381 fParentDC:1,
382 fComingToTop:1,
383 fCreateSetWindowPos:1, //FALSE -> SetWindowPos in Win32BaseWindow::MsgCreate not yet called
384 isUnicode:1,
385 fMinMaxChange:1, //set when switching between min/max/restored state
386 fVisibleRegionChanged:1, //set when visible region has changed -> erase background must be sent during next BeginPaint
387 fEraseBkgndFlag:1;
388
389 HRGN hWindowRegion;
390 HRGN hClipRegion;
391
392 DWORD dwThreadId; //id of thread that created this window
393 DWORD dwProcessId; //id of process that created this window
394
395 Win32BaseWindow *owner;
396 HICON hIcon,hIconSm;
397
398 char *windowNameA;
399 WCHAR *windowNameW;
400
401 char *userWindowBytes;
402 ULONG nrUserWindowBytes;
403
404 RECT rectWindow; //relative to parent
405 RECT rectClient; //relative to frame
406WINDOWPLACEMENT windowpos;
407
408 PROPERTY *propertyList;
409
410 HANDLE hTaskList; //PM specific (switchentry handle)
411
412CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
413 ULONG sw; //set in CreateWindowExA, used in MsgCreate method
414
415SCROLLBAR_INFO *vertScrollInfo;
416SCROLLBAR_INFO *horzScrollInfo;
417
418Win32WndClass *windowClass;
419
420static GenericObject *windows;
421static CRITICAL_SECTION critsect;
422
423private:
424#ifndef OS2_INCLUDED
425 void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
426 UINT MinMaximize(UINT cmd, LPRECT lpRect);
427 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
428 LONG HandleNCActivate(WPARAM wParam);
429 VOID TrackMinMaxHelpBox(WORD wParam);
430 VOID TrackCloseButton(WORD wParam);
431 VOID TrackScrollBar(WPARAM wParam,POINT pt);
432 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
433 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
434 LONG HandleNCRButtonUp(WPARAM wParam,LPARAM lParam);
435 VOID AdjustRectOuter(LPRECT rect,BOOL menu);
436 VOID AdjustRectInner(LPRECT rect);
437 LONG HandleNCCalcSize(BOOL calcValidRects,RECT *winRect);
438 VOID GetInsideRect(RECT *rect);
439 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
440public:
441 LONG HandleNCHitTest(POINT pt);
442 BOOL GetSysPopupPos(RECT* rect);
443private:
444 BOOL DrawSysButton(HDC hdc,RECT *rect);
445 BOOL DrawGrayButton(HDC hdc,int x,int y);
446 VOID DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
447 VOID DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
448 VOID DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
449 VOID DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
450 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
451 VOID DoNCPaint(HRGN clip,BOOL suppress_menupaint);
452 LONG HandleNCPaint(HRGN clip);
453 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
454
455 LONG SendNCCalcSize(BOOL calcValidRect,
456 RECT *newWindowRect, RECT *oldWindowRect,
457 RECT *oldClientRect, WINDOWPOS *winpos,
458 RECT *newClientRect );
459
460#else
461friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
462#endif
463
464public:
465 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
466 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
467
468 fakeOpen32WinBaseClass fakeWinBase;
469
470 VOID AdjustMaximizedRect(LPRECT rect);
471 VOID AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize);
472
473 //Temporary hack for CS_CLASSDC style (do the same as for CS_OWNDC)
474#ifndef OS2_INCLUDED
475 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & (CS_OWNDC|CS_CLASSDC)); }
476#else
477 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & (CS_OWNDC_W|CS_CLASSDC_W)); }
478#endif
479
480 HDC getOwnDC() { return ownDC; }
481 void setOwnDC(HDC hdc) { ownDC = hdc; }
482protected:
483 HDC ownDC;
484
485public:
486 VOID setEraseBkgnd (BOOL erase) { fEraseBkgndFlag = erase; }
487 BOOL needsEraseBkgnd() { return fEraseBkgndFlag; }
488};
489
490#endif //__cplusplus
491
492#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.