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

Last change on this file since 2657 was 2657, checked in by sandervl, 26 years ago

set style + mdi child creation fixes

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