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

Last change on this file since 2383 was 2383, checked in by sandervl, 26 years ago

Several updates/bug fixes

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