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

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

window property fixes/changes

File size: 18.7 KB
Line 
1/* $Id: win32wbase.h,v 1.94 2000-05-05 11:32:37 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#define WIN32MSG_MAGICA 0x12345678
53#define WIN32MSG_MAGICW 0x12345679
54
55typedef struct
56{
57 ULONG Msg;
58 ULONG wParam;
59 ULONG lParam;
60} POSTMSG_PACKET;
61
62#define BROADCAST_SEND 0
63#define BROADCAST_POST 1
64
65#define HAS_DLGFRAME(style,exStyle) \
66 (((exStyle) & WS_EX_DLGMODALFRAME) || \
67 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
68
69#define HAS_THICKFRAME(style,exStyle) \
70 (((style) & WS_THICKFRAME) && \
71 !((exStyle) & WS_EX_DLGMODALFRAME) && \
72 !((style) & WS_CHILD))
73
74#define HAS_THINFRAME(style) \
75 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
76
77#define HAS_BIGFRAME(style,exStyle) \
78 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
79 ((exStyle) & WS_EX_DLGMODALFRAME))
80
81#define HAS_ANYFRAME(style,exStyle) \
82 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
83 ((exStyle) & WS_EX_DLGMODALFRAME) || \
84 !((style) & (WS_CHILD | WS_POPUP)))
85
86#define HAS_3DFRAME(exStyle) \
87 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
88
89#define HAS_BORDER(style, exStyle) \
90 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
91
92#define IS_OVERLAPPED(style) \
93 !(style & (WS_CHILD | WS_POPUP))
94
95#define HAS_MENU() (!(getStyle() & WS_CHILD) && (GetMenu() != 0))
96
97class Win32BaseWindow : public GenericObject, public ChildWindow
98{
99public:
100 DWORD magic;
101
102 Win32BaseWindow(DWORD objType);
103 Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode);
104virtual ~Win32BaseWindow();
105
106virtual ULONG MsgCreate(HWND hwndFrame, HWND hwndClient);
107 ULONG MsgQuit();
108 ULONG MsgClose();
109 ULONG MsgDestroy();
110virtual ULONG MsgEnable(BOOL fEnable);
111 ULONG MsgShow(BOOL fShow);
112 ULONG MsgPosChanging(LPARAM lp);
113 ULONG MsgPosChanged(LPARAM lp);
114 ULONG MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win);
115 ULONG MsgSetFocus(HWND hwnd);
116 ULONG MsgKillFocus(HWND hwnd);
117 ULONG MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos);
118 ULONG MsgButton(MSG *msg);
119 ULONG MsgMouseMove(MSG *msg);
120 ULONG MsgChar(MSG *msg);
121 ULONG MsgPaint(ULONG tmp1, BOOL select = TRUE);
122 ULONG MsgEraseBackGround(HDC hdc);
123 ULONG MsgHitTest(MSG *msg);
124 ULONG MsgNCPaint();
125 ULONG MsgFormatFrame(WINDOWPOS *lpWndPos);
126 ULONG DispatchMsgA(MSG *msg);
127 ULONG DispatchMsgW(MSG *msg);
128
129 ULONG MsgSetText(LPSTR lpsz, LONG cch);
130 ULONG MsgGetTextLength();
131 void MsgGetText(char *wndtext, ULONG textlength);
132 VOID updateWindowStyle(DWORD oldExStyle,DWORD oldStyle);
133
134virtual LONG SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
135virtual ULONG GetWindowLongA(int index, BOOL fUnicode = FALSE);
136virtual WORD SetWindowWord(int index, WORD value);
137virtual WORD GetWindowWord(int index);
138
139 DWORD getStyle() { return dwStyle; };
140 void setStyle(DWORD newstyle) { dwStyle = newstyle; };
141 DWORD getExStyle() { return dwExStyle; };
142 void setExStyle(DWORD newexstyle) { dwExStyle = newexstyle; };
143 ULONG getInstance() { return hInstance; };
144 void setInstance(ULONG newinstance) { hInstance = newinstance; };
145 HWND getWindowHandle() { return Win32Hwnd; };
146 HWND getOS2WindowHandle() { return OS2Hwnd; };
147 HWND getOS2FrameWindowHandle() { return OS2HwndFrame; };
148 Win32WndClass *getWindowClass() { return windowClass; };
149
150 LONG getLastHitTestVal() { return lastHitTestVal; }
151
152 DWORD getWindowContextHelpId() { return contextHelpId; };
153 void setWindowContextHelpId(DWORD id){ contextHelpId = id; };
154
155 BOOL isFrameWindow();
156virtual BOOL isMDIClient();
157virtual BOOL isMDIChild();
158
159 BOOL fHasParentDC() { return fParentDC; };
160
161Win32BaseWindow *getParent();
162 void setParent(Win32BaseWindow *pwindow) { ChildWindow::SetParent((ChildWindow *)pwindow); };
163 WNDPROC getWindowProc() { return win32wndproc; };
164 void setWindowProc(WNDPROC newproc) { win32wndproc = newproc; };
165 DWORD getWindowId() { return dwIDMenu; };
166 void setWindowId(DWORD id);
167 ULONG getWindowHeight() { return rectWindow.bottom - rectWindow.top; };
168 ULONG getWindowWidth() { return rectWindow.right - rectWindow.left; };
169 ULONG getClientHeight() { return rectClient.bottom - rectClient.top; };
170 ULONG getClientWidth() { return rectClient.right - rectClient.left; };
171 BOOL isChild();
172 PRECT getClientRectPtr() { return &rectClient; };
173 void getClientRect(PRECT rect)
174 {
175 *rect = rectClient;
176 rect->right -= rect->left;
177 rect->bottom -= rect->top;
178 rect->left = rect->top = 0;
179 }
180 void setClientRect(PRECT rect) { rectClient = *rect; };
181 PRECT getWindowRect() { return &rectWindow; };
182 void setClientRect(LONG left, LONG top, LONG right, LONG bottom)
183 {
184 rectClient.left = left; rectClient.top = top;
185 rectClient.right = right; rectClient.bottom = bottom;
186 };
187 void setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
188 {
189 rectWindow.left = left; rectWindow.top = top;
190 rectWindow.right = right; rectWindow.bottom = bottom;
191 };
192 void setWindowRect(PRECT rect) { rectWindow = *rect; };
193 DWORD getFlags() { return flags; };
194 void setFlags(DWORD newflags) { flags = newflags; };
195
196 HMENU GetMenu() { return dwIDMenu; };
197 VOID SetMenu(HMENU newMenu) { dwIDMenu = newMenu; };
198 void SetSysMenu(HMENU hSystemMenu) { hSysMenu = hSystemMenu; };
199 HMENU GetSysMenu() { return hSysMenu; }
200
201 HICON IconForWindow(WPARAM fType);
202
203 void SetWindowRegion(HRGN hRegion) { hWindowRegion = hRegion; };
204 HRGN GetWindowRegion() { return hWindowRegion; };
205
206 //Save old clip region for CS_OWNDC windows (in BeginPaint)
207 HRGN GetClipRegion() { return hClipRegion; };
208 void SetClipRegion(HRGN hRegion) { hClipRegion = hRegion; };
209
210 BOOL ShowWindow(ULONG nCmdShow);
211 BOOL SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
212 BOOL SetWindowPlacement(WINDOWPLACEMENT *winpos);
213 BOOL DestroyWindow();
214 HWND SetActiveWindow();
215 HWND GetParent();
216 HWND SetParent(HWND hwndNewParent);
217
218 BOOL IsChild(HWND hwndParent);
219
220 HWND GetTopWindow();
221Win32BaseWindow *GetTopParent();
222
223 HWND GetWindow(UINT uCmd);
224 virtual BOOL EnableWindow(BOOL fEnable);
225 BOOL CloseWindow();
226 static HWND GetActiveWindow();
227 //Window handle has already been verified, so just return true
228 BOOL IsWindow() { return TRUE; };
229 BOOL IsDialog() { return fIsDialog; };
230 BOOL IsModalDialog() { return fIsModalDialog; };
231 BOOL IsModalDialogOwner() { return fIsModalDialogOwner; };
232 VOID setModalDialogOwner(BOOL fMDO) { fIsModalDialogOwner = fMDO; };
233 VOID setOS2HwndModalDialog(HWND aHwnd) { OS2HwndModalDialog = aHwnd; };
234 HWND getOS2HwndModalDialog() { return OS2HwndModalDialog; };
235 BOOL CanReceiveSizeMsgs() { return !fNoSizeMsg; };
236 BOOL IsWindowCreated() { return fCreated; }
237 BOOL IsWindowDestroyed() { return fIsDestroyed; };
238 BOOL IsWindowEnabled();
239 BOOL IsWindowVisible();
240 BOOL IsWindowIconic();
241 //Window procedure type
242 BOOL IsWindowUnicode();
243
244 int GetWindowTextLength();
245 int GetWindowTextA(LPSTR lpsz, int cch);
246 int GetWindowTextW(LPWSTR lpsz, int cch);
247 BOOL SetWindowTextA(LPSTR lpsz);
248 BOOL SetWindowTextW(LPWSTR lpsz);
249 BOOL hasWindowName(LPSTR wndname, BOOL fUnicode = 0);
250 CHAR *getWindowNamePtrA();
251 WCHAR *getWindowNamePtrW();
252 VOID freeWindowNamePtr(PVOID namePtr);
253 CHAR *getWindowNameA() { return windowNameA; }; //only for MDI windows!
254 WCHAR *getWindowNameW() { return windowNameW; }; //only for MDI windows!
255Win32WndClass *getClass() { return windowClass; };
256Win32BaseWindow *getOwner() { return owner; };
257 void setOwner(Win32BaseWindow *newOwner) { owner = newOwner; };
258
259 SCROLLBAR_INFO *getScrollInfo(int nBar);
260
261 LRESULT SendMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
262 LRESULT SendMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
263static LRESULT BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam);
264static LRESULT BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam);
265 void CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = FALSE);
266
267 LRESULT DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam);
268 LRESULT DefWindowProcW(UINT msg, WPARAM wParam, LPARAM lParam);
269
270 LRESULT DefWndControlColor(UINT ctlType, HDC hdc);
271 LRESULT DefWndPrint(HDC hdc,ULONG uFlags);
272
273 void NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam);
274
275Win32BaseWindow *FindWindowById(int id);
276
277 static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow);
278
279 BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
280 BOOL EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam);
281 BOOL EnumWindows(WNDENUMPROC lpfn, LPARAM lParam);
282
283 HWND getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious);
284 HWND getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
285
286 BOOL isComingToTop() { return fComingToTop; };
287 void setComingToTop(BOOL fTop) { fComingToTop = fTop; };
288 BOOL isInTasklist() { return fTaskList; };
289
290 //window property methods
291 HANDLE getProp(LPCSTR str);
292 BOOL setProp(LPCSTR str, HANDLE handle);
293 HANDLE removeProp(LPCSTR str);
294 INT enumPropsExA(PROPENUMPROCEXA func, LPARAM lParam);
295 INT enumPropsExW(PROPENUMPROCEXW func, LPARAM lParam);
296
297 static HWND Win32ToOS2Handle(HWND hwnd);
298 static HWND Win32ToOS2FrameHandle(HWND hwnd);
299 static HWND OS2ToWin32Handle(HWND hwnd);
300 static BOOL IsOS2FrameWindowHandle(HWND hwndWin32, HWND hwndOS2);
301
302static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
303static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
304static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
305
306 static void DestroyAll();
307
308 PVOID getOldFrameProc() { return pOldFrameProc; };
309 VOID setOldFrameProc(PVOID aOldFrameProc) { pOldFrameProc = aOldFrameProc; };
310
311 PVOID getOldWndProc() { return pOldWndProc; }
312 VOID setOldWndProc(PVOID aOldWndProc) { pOldWndProc = aOldWndProc; }
313
314protected:
315#ifndef OS2_INCLUDED
316 BOOL CreateWindowExA(CREATESTRUCTA *lpCreateStruct, ATOM classAtom);
317#endif
318 LRESULT SendInternalMessageA(ULONG msg, WPARAM wParam, LPARAM lParam);
319 LRESULT SendInternalMessageW(ULONG msg, WPARAM wParam, LPARAM lParam);
320 void Init();
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 HWND OS2HwndFrame;
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 fTaskList; //should be listed in PM tasklist or not
362 BOOL fXDefault;
363 BOOL fCXDefault;
364 BOOL fParentDC;
365 BOOL fComingToTop;
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 PVOID pOldFrameProc;
373
374 PVOID pOldWndProc;
375
376 Win32BaseWindow *owner;
377 HICON hIcon,hIconSm;
378
379 char *windowNameA;
380 WCHAR *windowNameW;
381 ULONG wndNameLength; //including 0 terminator
382
383 ULONG *userWindowLong;
384 ULONG nrUserWindowLong;
385
386 RECT rectWindow; //relative to screen
387 RECT rectClient; //relative to parent
388
389 PROPERTY *propertyList;
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 LONG HandleWindowPosChanging(WINDOWPOS *winpos);
405 LONG HandleNCActivate(WPARAM wParam);
406 VOID TrackMinMaxHelpBox(WORD wParam);
407 VOID TrackCloseButton(WORD wParam);
408 VOID TrackScrollBar(WPARAM wParam,POINT pt);
409 LONG HandleNCLButtonDown(WPARAM wParam,LPARAM lParam);
410 LONG HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam);
411 LONG HandleNCRButtonUp(WPARAM wParam,LPARAM lParam);
412 VOID AdjustRectOuter(LPRECT rect,BOOL menu);
413 VOID AdjustRectInner(LPRECT rect);
414 LONG HandleNCCalcSize(BOOL calcValidRects,RECT *winRect);
415 VOID GetInsideRect(RECT *rect);
416 VOID DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active);
417public:
418 LONG HandleNCHitTest(POINT pt);
419 BOOL GetSysPopupPos(RECT* rect);
420private:
421 BOOL DrawSysButton(HDC hdc,RECT *rect);
422 BOOL DrawGrayButton(HDC hdc,int x,int y);
423 VOID DrawCloseButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
424 VOID DrawMaxButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
425 VOID DrawMinButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
426 VOID DrawContextHelpButton(HDC hdc,RECT *rect,BOOL down,BOOL bGrayed);
427 VOID DrawCaption(HDC hdc,RECT *rect,BOOL active);
428 VOID DoNCPaint(HRGN clip,BOOL suppress_menupaint);
429 LONG HandleNCPaint(HRGN clip);
430 LONG HandleSysCommand(WPARAM wParam, POINT *pt32);
431
432 LONG SendNCCalcSize(BOOL calcValidRect,
433 RECT *newWindowRect, RECT *oldWindowRect,
434 RECT *oldClientRect, WINDOWPOS *winpos,
435 RECT *newClientRect );
436
437 LRESULT SendInternalMessage(ULONG msg, WPARAM wParam, LPARAM lParam)
438 {
439 if(isUnicode)
440 return SendInternalMessageW(msg, wParam, lParam);
441 else return SendInternalMessageA(msg, wParam, lParam);
442 }
443#else
444friend BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fTranslateExtraMsgs);
445#endif
446
447public:
448 void SetFakeOpen32() { WinSetDAXData (OS2Hwnd, &fakeWinBase); }
449 void RemoveFakeOpen32() { WinSetDAXData (OS2Hwnd, NULL); }
450
451 fakeOpen32WinBaseClass fakeWinBase;
452
453 VOID AdjustMaximizedRect(LPRECT rect);
454 VOID AdjustTrackInfo(PPOINT minTrackSize,PPOINT maxTrackSize);
455
456#ifndef OS2_INCLUDED
457 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC); }
458#else
459 BOOL isOwnDC() { return (windowClass && windowClass->getStyle() & CS_OWNDC_W); }
460#endif
461 HDC getOwnDC() { return ownDC; }
462 void setOwnDC(HDC hdc) { ownDC = hdc; }
463protected:
464 HDC ownDC;
465
466 ULONG EraseBkgndFlag:1,
467 filler:31;
468public:
469 VOID setEraseBkgnd (BOOL erase) { EraseBkgndFlag = erase; }
470 BOOL needsEraseBkgnd() { return EraseBkgndFlag; }
471};
472
473#endif //__cplusplus
474
475#endif //__WIN32WNDBASE_H__
Note: See TracBrowser for help on using the repository browser.