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

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

mouse message translation + dc reset after resize fixes

File size: 19.4 KB
Line 
1/* $Id: win32wbase.h,v 1.115 2001-04-27 17:36:39 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
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);
231 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();
240Win32BaseWindow *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 IsWindowCreated() { return fCreated; }
256 BOOL IsWindowDestroyed() { return fIsDestroyed; };
257 BOOL IsWindowIconic();
258 //Window procedure type
259 BOOL IsWindowUnicode();
260 BOOL IsMixMaxStateChanging() { return fMinMaxChange; };
261
262 int GetWindowTextLength(BOOL fUnicode);
263 int GetWindowTextLengthA() { return GetWindowTextLength(FALSE); };
264 int GetWindowTextLengthW() { return GetWindowTextLength(TRUE); };
265
266 int GetWindowTextA(LPSTR lpsz, int cch);
267 int GetWindowTextW(LPWSTR lpsz, int cch);
268 BOOL SetWindowTextA(LPSTR lpsz);
269 BOOL SetWindowTextW(LPWSTR lpsz);
270 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
271 CHAR *getWindowNamePtrA();
272 WCHAR *getWindowNamePtrW();
273 VOID freeWindowNamePtr(PVOID namePtr);
274 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
275 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
276Win32WndClass *getClass() { return windowClass; };
277Win32BaseWindow *getOwner() { return owner; };
278 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
279
280 SCROLLBAR_INFO *getScrollInfo(int nBar);
281
282 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
283 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
284static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
285static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
286 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
287
288 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
289 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
290
291 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
292 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
293
294 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
295
296Win32BaseWindow *FindWindowById(int id);
297
298 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow);
299
300 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
301 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
302 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
303
304 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
305
306 BOOL isComingToTop() { return fComingToTop; };
307 void setComingToTop(BOOL fTop) { fComingToTop = fTop; };
308 BOOL isInTasklist() { return fTaskList; };
309
310 //window property methods
311 HANDLE getProp(LPCSTR str);
312 BOOL setProp(LPCSTR str, HANDLE handle);
313 HANDLE removeProp(LPCSTR str);
314 INT enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
315 INT enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
316
317static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
318static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
319
320 static void DestroyAll();
321
322protected:
323#ifndef OS2_INCLUDED
324 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
325#endif
326 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
327 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
328 void Init();
329
330 void NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect);
331
332 //called in destructor to remove all (if any) window properties
333 void removeWindowProps();
334 PROPERTY *findWindowProperty(LPCSTR str);
335
336 HWND OS2Hwnd;
337 HMENU hSysMenu;
338 HWND Win32Hwnd;
339
340 int posx, posy, width, height;
341
342 // values normally contained in the standard window words
343 ULONG dwExStyle; //GWL_EXSTYLE
344 ULONG dwStyle; //GWL_STYLE
345 WNDPROC win32wndproc; //GWL_WNDPROC
346 ULONG hInstance; //GWL_HINSTANCE
347//Moved in ChildWindow class
348///// Win32BaseWindow *parent; //GWL_HWNDPARENT
349 ULONG dwIDMenu; //GWL_ID
350 ULONG userData; //GWL_USERDATA
351
352 HWND hwndLinkAfter;
353 DWORD flags;
354 DWORD contextHelpId;
355 DWORD hotkey;
356 LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
357
358 HWND OS2HwndModalDialog;
359
360 unsigned fFirstShow:1;
361 unsigned fIsDialog:1;
362 unsigned fIsModalDialog:1;
363 unsigned fIsModalDialogOwner:1;
364 unsigned fInternalMsg:1; //Used to distinguish between messages
365 //sent by PM and those sent by apps
366 unsigned fNoSizeMsg:1;
367 unsigned fIsDestroyed:1;
368 unsigned fDestroyWindowCalled:1; //DestroyWindow was called for this window
369 unsigned fCreated:1;
370 unsigned fCreationFinished:1; //True when window or dialog has been created successfully
371 //Needed to prevent DestroyWindow from deleting the window
372 //object during construction
373 unsigned fTaskList:1; //should be listed in PM tasklist or not
374 unsigned fXDefault:1;
375 unsigned fCXDefault:1;
376 unsigned fParentDC:1;
377 unsigned fComingToTop:1;
378 unsigned fCreateSetWindowPos:1; //FALSE -> SetWindowPos in Win32BaseWindow::MsgCreate not yet called
379 unsigned isUnicode:1;
380 unsigned fMinMaxChange:1; //set when switching between min/max/restored state
381 unsigned fOwnDCDirty:1; //set when selectClientArea must reset the origin + visible region
382
383 HRGN hWindowRegion;
384 HRGN hClipRegion;
385
386 DWORD dwThreadId; //id of thread that created this window
387 DWORD dwProcessId; //id of process that created this window
388
389 Win32BaseWindow *owner;
390 HICON hIcon,hIconSm;
391
392 char *windowNameA;
393 WCHAR *windowNameW;
394
395 char *userWindowBytes;
396 ULONG nrUserWindowBytes;
397
398 RECT rectWindow; //relative to parent
399 RECT rectClient; //relative to frame
400WINDOWPLACEMENT windowpos;
401
402 PROPERTY *propertyList;
403
404 HANDLE hTaskList; //PM specific (switchentry handle)
405
406CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
407 ULONG sw; //set in CreateWindowExA, used in MsgCreate method
408
409SCROLLBAR_INFO *vertScrollInfo;
410SCROLLBAR_INFO *horzScrollInfo;
411
412Win32WndClass *windowClass;
413
414static GenericObject *windows;
415
416private:
417#ifndef OS2_INCLUDED
418 void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
419 UINT MinMaximize(UINT cmd, LPRECT lpRect);
420 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
421 LONG HandleNCActivate(WPARAM wParam);
422 VOID TrackMinMaxHelpBox(WORD wParam);
423 VOID TrackCloseButton(WORD wParam);
424 VOID TrackScrollBar(WPARAM wParam,POINT pt);
425 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
426 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
427 LONG HandleNCRButtonUp(WPARAM wParam,LPARAM lParam);
428 VOID AdjustRectOuter(LPRECT rect,BOOL menu);
429 VOID AdjustRectInner(LPRECT rect);
430 LONG HandleNCCalcSize(BOOL calcValidRects,RECT *winRect);
431 VOID GetInsideRect(RECT *rect);
432 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
433public:
434 LONG HandleNCHitTest(POINT pt);
435 BOOL GetSysPopupPos(RECT* rect);
436private:
437 BOOL DrawSysButton(HDC hdc,RECT *rect);
438 BOOL DrawGrayButton(HDC hdc,int x,int y);
439 VOID DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
440 VOID DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
441 VOID DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
442 VOID DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
443 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
444 VOID DoNCPaint(HRGN clip,BOOL suppress_menupaint);
445 LONG HandleNCPaint(HRGN clip);
446 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
447
448 LONG SendNCCalcSize(BOOL calcValidRect,
449 RECT *newWindowRect, RECT *oldWindowRect,
450 RECT *oldClientRect, WINDOWPOS *winpos,
451 RECT *newClientRect );
452
453#else
454friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
455#endif
456
457public:
458 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
459 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
460
461 fakeOpen32WinBaseClass fakeWinBase;
462
463 VOID AdjustMaximizedRect(LPRECT rect);
464 VOID AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize);
465
466#ifndef OS2_INCLUDED
467 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC); }
468#else
469 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC_W); }
470#endif
471 void invalidateOwnDC() { fOwnDCDirty = TRUE; };
472 void validateOwnDC() { fOwnDCDirty = FALSE; };
473 BOOL isOwnDCDirty() { return fOwnDCDirty; };
474
475 HDC getOwnDC() { return ownDC; }
476 void setOwnDC(HDC hdc) { ownDC = hdc; }
477protected:
478 HDC ownDC;
479
480 ULONG EraseBkgndFlag:1,
481 filler:31;
482public:
483 VOID setEraseBkgnd (BOOL erase) { EraseBkgndFlag = erase; }
484 BOOL needsEraseBkgnd() { return EraseBkgndFlag; }
485};
486
487#endif //__cplusplus
488
489#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.