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

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

misc updates

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