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

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

SetFocus fixes during WM_SETFOCUS

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