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

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

dispatch untranslated msgs + frame control button changes (manually change restore/min/max)

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