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

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

replaced os2.h includes by os2wrap.h

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