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

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

reserved 1 window ulong for odin apps (like Opera)

File size: 20.0 KB
Line 
1/* $Id: win32wbase.h,v 1.121 2001-06-22 18:32:11 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_RESERVED 0 //reserved for odin apps (such as Opera)
28#define OFFSET_WIN32WNDPTR 4
29#define OFFSET_WIN32PM_MAGIC 8
30#define OFFSET_WIN32FLAGS 12
31#define NROF_WIN32WNDBYTES 16
32
33#define WINDOWFLAG_ACTIVE 1
34
35#define WIN32PM_MAGIC 0x12345678
36#define CheckMagicDword(a) (a==WIN32PM_MAGIC)
37
38#define RELEASE_WNDOBJ(a) { a->release(); a = NULL; }
39
40typedef struct {
41 USHORT cb;
42 Win32BaseWindow *win32wnd;
43 ULONG win32CreateStruct; //or dialog create dword
44} CUSTOMWNDDATA;
45
46typedef struct tagPROPERTY
47{
48 struct tagPROPERTY *next; /* Next property in window list */
49 HANDLE handle; /* User's data */
50 LPSTR string; /* Property string (or atom) */
51} PROPERTY;
52
53//PostThreadMessage is done through Open32; which means the message id will be translated
54//(0xc00 added)
55#define OPEN32_MSGDIFF 0xC00
56#define WIN32APP_POSTMSG (0x1000+OPEN32_MSGDIFF)
57
58//PM doesn't allow SetFocus during WM_SETFOCUS message processing; must delay
59//this by posting a message
60//NOTE Must be smaller than WIN32APP_POSTMSG!
61#define WIN32APP_SETFOCUSMSG (WIN32APP_POSTMSG-1)
62
63#define WIN32MSG_MAGICA 0x12345678
64#define WIN32MSG_MAGICW 0x12345679
65
66typedef struct
67{
68 ULONG wParam;
69 ULONG lParam;
70} POSTMSG_PACKET;
71
72#define BROADCAST_SEND 0
73#define BROADCAST_POST 1
74
75#define HAS_DLGFRAME(style,exStyle) \
76 (((exStyle) & WS_EX_DLGMODALFRAME) || \
77 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
78
79#define HAS_THICKFRAME(style,exStyle) \
80 (((style) & WS_THICKFRAME) && \
81 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
82#if 0
83 (((style) & WS_THICKFRAME) && \
84 !((exStyle) & WS_EX_DLGMODALFRAME) && \
85 !((style) & WS_CHILD))
86#endif
87
88#define HAS_THINFRAME(style) \
89 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
90
91#define HAS_BIGFRAME(style,exStyle) \
92 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
93 ((exStyle) & WS_EX_DLGMODALFRAME))
94
95#define HAS_ANYFRAME(style,exStyle) \
96 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
97 ((exStyle) & WS_EX_DLGMODALFRAME) || \
98 !((style) & (WS_CHILD | WS_POPUP)))
99
100#define HAS_3DFRAME(exStyle) \
101 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
102
103#define HAS_BORDER(style, exStyle) \
104 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
105
106#define IS_OVERLAPPED(style) \
107 !(style & (WS_CHILD | WS_POPUP))
108
109#define HAS_MENU() (!(getStyle() & WS_CHILD) && (GetMenu() != 0))
110
111class Win32BaseWindow : public GenericObject, public ChildWindow
112{
113public:
114 Win32BaseWindow();
115 Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
116 Win32BaseWindow(HWND hwndOS2, ULONG reserved);
117
118virtual ~Win32BaseWindow();
119
120virtual ULONG MsgCreate(HWND hwndOS2);
121 ULONG MsgQuit();
122 ULONG MsgClose();
123 ULONG MsgDestroy();
124virtual ULONG MsgEnable(BOOL fEnable);
125 ULONG MsgShow(BOOL fShow);
126 ULONG MsgPosChanging(LPARAM lp);
127 ULONG MsgPosChanged(LPARAM lp);
128 ULONG MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win);
129 ULONG MsgSetFocus(HWND hwnd);
130 ULONG MsgKillFocus(HWND hwnd);
131 ULONG MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos);
132 ULONG MsgButton(MSG *msg);
133 ULONG MsgMouseMove(MSG *msg);
134 ULONG MsgChar(MSG *msg);
135 ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
136 ULONG MsgEraseBackGround(HDC hdc);
137 ULONG MsgNCPaint(PRECT pUpdateRect);
138 ULONG MsgFormatFrame(WINDOWPOS *lpWndPos);
139 ULONG DispatchMsgA(MSG *msg);
140 ULONG DispatchMsgW(MSG *msg);
141
142 ULONG MsgSetText(LPSTR lpsz, LONG cch);
143 ULONG MsgGetTextLength();
144 void MsgGetText(char *wndtext, ULONG textlength);
145 VOID updateWindowStyle(DWORD oldExStyle,DWORD oldStyle);
146
147virtual LONG SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
148virtual ULONG GetWindowLongA(int index, BOOL fUnicode = FALSE);
149virtual WORD SetWindowWord(int index, WORD value);
150virtual WORD GetWindowWord(int index);
151
152 DWORD getStyle() { return dwStyle; };
153 DWORD getOldStyle() { return dwOldStyle; };
154 void setStyle(DWORD newstyle) { dwStyle = newstyle; };
155 DWORD getExStyle() { return dwExStyle; };
156 void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
157 ULONG getInstance() { return hInstance; };
158 void setInstance(ULONG newinstance) { hInstance = newinstance; };
159 HWND getWindowHandle() { return Win32Hwnd; };
160 HWND getOS2WindowHandle() { return OS2Hwnd; };
161 HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
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);
231virtual 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();
240 HWND 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 void SetVisibleRegionChanged(BOOL changed) { fVisibleRegionChanged = changed; };
263 BOOL IsVisibleRegionChanged() { return fVisibleRegionChanged; };
264
265 int GetWindowTextLength(BOOL fUnicode);
266 int GetWindowTextLengthA() { return GetWindowTextLength(FALSE); };
267 int GetWindowTextLengthW() { return GetWindowTextLength(TRUE); };
268
269 int GetWindowTextA(LPSTR lpsz, int cch);
270 int GetWindowTextW(LPWSTR lpsz, int cch);
271 BOOL SetWindowTextA(LPSTR lpsz);
272 BOOL SetWindowTextW(LPWSTR lpsz);
273 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
274 CHAR *getWindowNamePtrA();
275 WCHAR *getWindowNamePtrW();
276 VOID freeWindowNamePtr(PVOID namePtr);
277 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
278 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
279Win32WndClass *getClass() { return windowClass; };
280Win32BaseWindow *getOwner() { return owner; };
281 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
282
283 SCROLLBAR_INFO *getScrollInfo(int nBar);
284
285 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
286 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
287static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
288static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
289 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
290
291 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
292 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
293
294 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
295 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
296
297 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
298
299 HWND FindWindowById(int id);
300
301 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow);
302
303 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
304 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
305 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
306
307 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
308
309 BOOL isComingToTop() { return fComingToTop; };
310 void setComingToTop(BOOL fTop) { fComingToTop = fTop; };
311 BOOL isInTasklist() { return fTaskList; };
312
313 //window property methods
314 HANDLE getProp(LPCSTR str);
315 BOOL setProp(LPCSTR str, HANDLE handle);
316 HANDLE removeProp(LPCSTR str);
317 INT enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
318 INT enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
319
320//Locates window in linked list and increases reference count (if found)
321//Window object must be unreferenced after usage
322static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
323static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
324static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
325
326 static void DestroyAll();
327
328protected:
329#ifndef OS2_INCLUDED
330 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
331#endif
332 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
333 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
334 void Init();
335
336 void NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect);
337
338 //called in destructor to remove all (if any) window properties
339 void removeWindowProps();
340 PROPERTY *findWindowProperty(LPCSTR str);
341
342 HWND OS2Hwnd, OS2HwndFrame;
343 HMENU hSysMenu;
344 HWND Win32Hwnd;
345
346 int posx, posy, width, height;
347
348 // values normally contained in the standard window words
349 ULONG dwExStyle; //GWL_EXSTYLE
350 ULONG dwStyle; //GWL_STYLE
351 ULONG dwOldStyle; //Used to determine which frame control buttons to change (OS/2 mode)
352 WNDPROC win32wndproc; //GWL_WNDPROC
353 ULONG hInstance; //GWL_HINSTANCE
354//Moved in ChildWindow class
355///// Win32BaseWindow *parent; //GWL_HWNDPARENT
356 ULONG dwIDMenu; //GWL_ID
357 ULONG userData; //GWL_USERDATA
358
359
360 HWND hwndLinkAfter;
361 DWORD flags;
362 DWORD contextHelpId;
363 DWORD hotkey;
364 LONG lastHitTestVal; //Last value returned by WM_NCHITTEST handler
365
366 HWND OS2HwndModalDialog;
367
368 ULONG fFirstShow:1,
369 fIsDialog:1,
370 fIsModalDialog:1,
371 fIsModalDialogOwner:1,
372 fInternalMsg:1, //Used to distinguish between messages
373 //sent by PM and those sent by apps
374 fNoSizeMsg:1,
375 fIsDestroyed:1,
376 fDestroyWindowCalled:1, //DestroyWindow was called for this window
377 fCreated:1,
378 fCreationFinished:1, //True when window or dialog has been created successfully
379 //Needed to prevent DestroyWindow from deleting the window
380 //object during construction
381 fTaskList:1, //should be listed in PM tasklist or not
382 fXDefault:1,
383 fCXDefault:1,
384 fParentDC:1,
385 fComingToTop:1,
386 fCreateSetWindowPos:1, //FALSE -> SetWindowPos in Win32BaseWindow::MsgCreate not yet called
387 isUnicode:1,
388 fMinMaxChange:1, //set when switching between min/max/restored state
389 fVisibleRegionChanged:1, //set when visible region has changed -> erase background must be sent during next BeginPaint
390 fEraseBkgndFlag:1;
391
392 HRGN hWindowRegion;
393 HRGN hClipRegion;
394
395 DWORD dwThreadId; //id of thread that created this window
396 DWORD dwProcessId; //id of process that created this window
397
398 Win32BaseWindow *owner;
399 HICON hIcon,hIconSm;
400
401 char *windowNameA;
402 WCHAR *windowNameW;
403
404 char *userWindowBytes;
405 ULONG nrUserWindowBytes;
406
407 RECT rectWindow; //relative to parent
408 RECT rectClient; //relative to frame
409WINDOWPLACEMENT windowpos;
410
411 PROPERTY *propertyList;
412
413 HANDLE hTaskList; //PM specific (switchentry handle)
414
415CREATESTRUCTA *tmpcs; //temporary pointer to CREATESTRUCT used in CreateWindowEx
416 ULONG sw; //set in CreateWindowExA, used in MsgCreate method
417
418SCROLLBAR_INFO *vertScrollInfo;
419SCROLLBAR_INFO *horzScrollInfo;
420
421Win32WndClass *windowClass;
422
423static GenericObject *windows;
424static CRITICAL_SECTION critsect;
425
426private:
427#ifndef OS2_INCLUDED
428 void GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
429 UINT MinMaximize(UINT cmd, LPRECT lpRect);
430 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
431 LONG HandleNCActivate(WPARAM wParam);
432 VOID TrackMinMaxHelpBox(WORD wParam);
433 VOID TrackCloseButton(WORD wParam);
434 VOID TrackScrollBar(WPARAM wParam,POINT pt);
435 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
436 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
437 LONG HandleNCRButtonUp(WPARAM wParam,LPARAM lParam);
438 VOID AdjustRectOuter(LPRECT rect,BOOL menu);
439 VOID AdjustRectInner(LPRECT rect);
440 LONG HandleNCCalcSize(BOOL calcValidRects,RECT *winRect);
441 VOID GetInsideRect(RECT *rect);
442 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
443public:
444 LONG HandleNCHitTest(POINT pt);
445 BOOL GetSysPopupPos(RECT* rect);
446private:
447 BOOL DrawSysButton(HDC hdc,RECT *rect);
448 BOOL DrawGrayButton(HDC hdc,int x,int y);
449 VOID DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
450 VOID DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
451 VOID DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
452 VOID DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
453 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
454 VOID DoNCPaint(HRGN clip,BOOL suppress_menupaint);
455 LONG HandleNCPaint(HRGN clip);
456 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
457
458 LONG SendNCCalcSize(BOOL calcValidRect,
459 RECT *newWindowRect, RECT *oldWindowRect,
460 RECT *oldClientRect, WINDOWPOS *winpos,
461 RECT *newClientRect );
462
463#else
464friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
465#endif
466
467public:
468 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
469 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
470
471 fakeOpen32WinBaseClass fakeWinBase;
472
473 VOID AdjustMaximizedRect(LPRECT rect);
474 VOID AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize);
475
476 //Temporary hack for CS_CLASSDC style (do the same as for CS_OWNDC)
477#ifndef OS2_INCLUDED
478 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & (CS_OWNDC|CS_CLASSDC)); }
479#else
480 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & (CS_OWNDC_W|CS_CLASSDC_W)); }
481#endif
482
483 HDC getOwnDC() { return ownDC; }
484 void setOwnDC(HDC hdc) { ownDC = hdc; }
485protected:
486 HDC ownDC;
487
488public:
489 VOID setEraseBkgnd (BOOL erase) { fEraseBkgndFlag = erase; }
490 BOOL needsEraseBkgnd() { return fEraseBkgndFlag; }
491};
492
493#endif //__cplusplus
494
495#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.