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

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

experimental WM_NCHITTEST generation (disabled) + MDI fixes

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