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

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

ScrollWindow, maximized window + system menu fixes

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