]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/os2/window.h
Don't infinitely recurse when setting the child focus. Without
[wxWidgets.git] / include / wx / os2 / window.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose: wxWindow class
4// Author: David Webster
5// Modified by:
6// Created: 10/12/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
15#define wxUSE_MOUSEEVENT_HACK 0
16
17// ---------------------------------------------------------------------------
18// headers
19// ---------------------------------------------------------------------------
20#define INCL_DOS
21#define INCL_PM
22#define INCL_GPI
23#include <os2.h>
24
25
26// ---------------------------------------------------------------------------
27// forward declarations
28// ---------------------------------------------------------------------------
29#ifndef CW_USEDEFAULT
30# define CW_USEDEFAULT ((int)0x80000000)
31#endif
32
33// ---------------------------------------------------------------------------
34// forward declarations
35// ---------------------------------------------------------------------------
36
37class WXDLLEXPORT wxButton;
38
39// ---------------------------------------------------------------------------
40// constants
41// ---------------------------------------------------------------------------
42
43// FIXME does anybody use those? they're unused by wxWindows...
44enum
45{
46 wxKEY_SHIFT = 1,
47 wxKEY_CTRL = 2
48};
49
50// ---------------------------------------------------------------------------
51// wxWindow declaration for OS/2 PM
52// ---------------------------------------------------------------------------
53
54class WXDLLEXPORT wxWindowOS2 : public wxWindowBase
55{
56public:
57 wxWindowOS2()
58 {
59 Init();
60 }
61
62 wxWindowOS2( wxWindow* pParent
63 ,wxWindowID vId
64 ,const wxPoint& rPos = wxDefaultPosition
65 ,const wxSize& rSize = wxDefaultSize
66 ,long lStyle = 0
67 ,const wxString& rName = wxPanelNameStr
68 )
69 {
70 Init();
71 Create( pParent
72 ,vId
73 ,rPos
74 ,rSize
75 ,lStyle
76 ,rName
77 );
78 }
79
80 virtual ~wxWindowOS2();
81
82 bool Create( wxWindow* pParent
83 ,wxWindowID vId
84 ,const wxPoint& rPos = wxDefaultPosition
85 ,const wxSize& rSize = wxDefaultSize
86 ,long lStyle = 0
87 ,const wxString& rName = wxPanelNameStr
88 );
89
90 // implement base class pure virtuals
91 virtual void SetTitle(const wxString& rTitle);
92 virtual wxString GetTitle(void) const;
93 virtual void Raise(void);
94 virtual void Lower(void);
95 virtual bool Show(bool bShow = TRUE);
96 virtual bool Enable(bool bEnable = TRUE);
97 virtual void SetFocus(void);
98 virtual void SetFocusFromKbd(void);
99 virtual bool Reparent(wxWindow* pNewParent);
100 virtual void WarpPointer( int x
101 ,int y
102 );
103 virtual void Refresh( bool bEraseBackground = TRUE
104 ,const wxRect* pRect = (const wxRect *)NULL
105 );
106 virtual void Freeze(void);
107 virtual void Update(void);
108 virtual void Thaw(void);
109 virtual void SetWindowStyleFlag(long lStyle);
110 virtual bool SetCursor(const wxCursor& rCursor);
111 virtual bool SetFont(const wxFont& rFont);
112 virtual int GetCharHeight(void) const;
113 virtual int GetCharWidth(void) const;
114 virtual void GetTextExtent( const wxString& rString
115 ,int* pX
116 ,int* pY
117 ,int* pDescent = (int *)NULL
118 ,int* pExternalLeading = (int *)NULL
119 ,const wxFont* pTheFont = (const wxFont *)NULL
120 ) const;
121#if wxUSE_MENUS_NATIVE
122 virtual bool DoPopupMenu( wxMenu* pMenu
123 ,int nX
124 ,int nY
125 );
126#endif // wxUSE_MENUS_NATIVE
127
128 virtual void SetScrollbar( int nOrient
129 ,int nPos
130 ,int nThumbVisible
131 ,int nRange
132 ,bool bRefresh = TRUE
133 );
134 virtual void SetScrollPos( int nOrient
135 ,int nPos
136 ,bool bRefresh = TRUE
137 );
138 virtual int GetScrollPos(int nOrient) const;
139 virtual int GetScrollThumb(int nOrient) const;
140 virtual int GetScrollRange(int nOrient) const;
141 virtual void ScrollWindow( int nDx
142 ,int nDy
143 ,const wxRect* pRect = (wxRect *)NULL
144 );
145
146 inline HWND GetScrollBarHorz(void) const {return m_hWndScrollBarHorz;}
147 inline HWND GetScrollBarVert(void) const {return m_hWndScrollBarVert;};
148#if wxUSE_DRAG_AND_DROP
149 virtual void SetDropTarget(wxDropTarget* pDropTarget);
150#endif // wxUSE_DRAG_AND_DROP
151
152 // Accept files for dragging
153 virtual void DragAcceptFiles(bool bAccept);
154
155#ifndef __WXUNIVERSAL__
156 // Native resource loading (implemented in src/os2/nativdlg.cpp)
157 // FIXME: should they really be all virtual?
158 virtual bool LoadNativeDialog( wxWindow* pParent
159 ,wxWindowID& vId
160 );
161 virtual bool LoadNativeDialog( wxWindow* pParent
162 ,const wxString& rName
163 );
164 wxWindow* GetWindowChild1(wxWindowID vId);
165 wxWindow* GetWindowChild(wxWindowID vId);
166#endif //__WXUNIVERSAL__
167
168 // implementation from now on
169 // --------------------------
170
171 // simple accessors
172 // ----------------
173
174 WXHWND GetHWND(void) const { return m_hWnd; }
175 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
176 virtual WXWidget GetHandle(void) const { return GetHWND(); }
177 bool GetUseCtl3D(void) const { return m_bUseCtl3D; }
178 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent; }
179 void SetTransparent(bool bT = TRUE) { m_bBackgroundTransparent = bT; }
180
181 // event handlers
182 // --------------
183 void OnSetFocus(wxFocusEvent& rEvent);
184 void OnEraseBackground(wxEraseEvent& rEvent);
185 void OnIdle(wxIdleEvent& rEvent);
186
187public:
188
189 // For implementation purposes - sometimes decorations make the client area
190 // smaller
191 virtual wxPoint GetClientAreaOrigin(void) const;
192
193 // Windows subclassing
194 void SubclassWin(WXHWND hWnd);
195 void UnsubclassWin(void);
196
197 WXFARPROC OS2GetOldWndProc(void) const { return m_fnOldWndProc; }
198 void OS2SetOldWndProc(WXFARPROC fnProc) { m_fnOldWndProc = fnProc; }
199 //
200 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
201 //
202 bool IsOfStandardClass(void) const { return m_fnOldWndProc != NULL; }
203
204 wxWindow* FindItem(long lId) const;
205 wxWindow* FindItemByHWND( WXHWND hWnd
206 ,bool bControlOnly = FALSE
207 ) const;
208
209 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
210 static WXDWORD MakeExtendedStyle( long lStyle
211 ,bool bEliminateBorders = TRUE
212 );
213
214 // PM only: TRUE if this control is part of the main control
215 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
216
217 // translate wxWindows style flags for this control into the PM style
218 // and optional extended style for the corresponding native control
219 //
220 // this is the function that should be overridden in the derived classes,
221 // but you will mostly use OS2GetCreateWindowFlags() below
222 virtual WXDWORD OS2GetStyle( long lFlags
223 ,WXDWORD* pdwExstyle = NULL
224 ) const;
225
226 // get the MSW window flags corresponding to wxWindows ones
227 //
228 // the functions returns the flags (WS_XXX) directly and puts the ext
229 // (WS_EX_XXX) flags into the provided pointer if not NULL
230 WXDWORD OS2GetCreateWindowFlags(WXDWORD* pdwExflags = NULL) const
231 { return OS2GetStyle(GetWindowStyle(), pdwExflags); }
232
233
234 // get the HWND to be used as parent of this window with CreateWindow()
235 virtual WXHWND OS2GetParent(void) const;
236
237 // returns TRUE if the window has been created
238 bool OS2Create( PSZ zClass
239 ,const char* zTitle
240 ,WXDWORD dwStyle
241 ,const wxPoint& rPos
242 ,const wxSize& rSize
243 ,void* pCtlData
244 ,WXDWORD dwExStyle
245 ,bool bIsChild
246 );
247 virtual bool OS2Command( WXUINT uParam
248 ,WXWORD nId
249 );
250
251#ifndef __WXUNIVERSAL__
252 // Create an appropriate wxWindow from a HWND
253 virtual wxWindow* CreateWindowFromHWND( wxWindow* pParent
254 ,WXHWND hWnd
255 );
256
257 // Make sure the window style reflects the HWND style (roughly)
258 virtual void AdoptAttributesFromHWND(void);
259#endif
260
261 // Setup background and foreground colours correctly
262 virtual void SetupColours(void);
263
264 // ------------------------------------------------------------------------
265 // helpers for message handlers: these perform the same function as the
266 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
267 // the correct parameters
268 // ------------------------------------------------------------------------
269
270 void UnpackCommand( WXWPARAM wParam
271 ,WXLPARAM lParam,
272 WXWORD* pId
273 ,WXHWND* pHwnd
274 ,WXWORD* pCmd
275 );
276 void UnpackActivate( WXWPARAM wParam
277 ,WXLPARAM lParam
278 ,WXWORD* pState
279 ,WXHWND* pHwnd
280 );
281 void UnpackScroll( WXWPARAM wParam
282 ,WXLPARAM lParam
283 ,WXWORD* pCode
284 ,WXWORD* pPos
285 ,WXHWND* pHwnd
286 );
287 void UnpackMenuSelect( WXWPARAM wParam
288 ,WXLPARAM lParam
289 ,WXWORD* pTtem
290 ,WXWORD* pFlags
291 ,WXHMENU* pHmenu
292 );
293
294 // ------------------------------------------------------------------------
295 // internal handlers for OS2 messages: all handlers return a boolen value:
296 // TRUE means that the handler processed the event and FALSE that it didn't
297 // ------------------------------------------------------------------------
298
299 // there are several cases where we have virtual functions for PM
300 // message processing: this is because these messages often require to be
301 // processed in a different manner in the derived classes. For all other
302 // messages, however, we do *not* have corresponding OS2OnXXX() function
303 // and if the derived class wants to process them, it should override
304 // OS2WindowProc() directly.
305
306 // scroll event (both horizontal and vertical)
307 virtual bool OS2OnScroll( int nOrientation
308 ,WXWORD nSBCode
309 ,WXWORD pos
310 ,WXHWND control
311 );
312
313 // owner-drawn controls need to process these messages
314 virtual bool OS2OnDrawItem( int nId
315 ,WXDRAWITEMSTRUCT* pItem
316 );
317 virtual long OS2OnMeasureItem( int nId
318 ,WXMEASUREITEMSTRUCT* pItem
319 );
320
321 virtual void OnPaint(wxPaintEvent& rEvent);
322
323 // the rest are not virtual
324 bool HandleCreate( WXLPCREATESTRUCT vCs
325 ,bool* pMayCreate
326 );
327 bool HandleInitDialog(WXHWND hWndFocus);
328 bool HandleDestroy(void);
329 bool HandlePaint(void);
330 bool HandleEraseBkgnd(WXHDC vDC);
331 bool HandleMinimize(void);
332 bool HandleMaximize(void);
333 bool HandleSize( int nX
334 ,int nY
335 ,WXUINT uFlag
336 );
337 bool HandleGetMinMaxInfo(PSWP pMmInfo);
338 bool HandleShow( bool bShow
339 ,int nStatus
340 );
341 bool HandleActivate( int nFlag
342 ,WXHWND hActivate
343 );
344 bool HandleCommand( WXWORD nId
345 ,WXWORD nCmd
346 ,WXHWND hControl
347 );
348 bool HandleSysCommand( WXWPARAM wParam
349 ,WXLPARAM lParam
350 );
351 bool HandlePaletteChanged(void);
352 bool HandleQueryNewPalette(void);
353 bool HandleSysColorChange(void);
354 bool HandleDisplayChange(void);
355 bool HandleCaptureChanged(WXHWND hBainedCapture);
356
357 bool HandleCtlColor(WXHBRUSH* hBrush);
358 bool HandleSetFocus(WXHWND hWnd);
359 bool HandleKillFocus(WXHWND hWnd);
360 bool HandleEndDrag(WXWPARAM wParam);
361 bool HandleMouseEvent( WXUINT uMsg
362 ,int nX
363 ,int nY
364 ,WXUINT uFlags
365 );
366 bool HandleMouseMove( int nX
367 ,int nY
368 ,WXUINT uFlags
369 );
370 bool HandleChar( WXWPARAM wParam
371 ,WXLPARAM lParam
372 ,bool bIsASCII = FALSE
373 );
374 bool HandleKeyDown( WXWPARAM wParam
375 ,WXLPARAM lParam
376 );
377 bool HandleKeyUp( WXWPARAM wParam
378 ,WXLPARAM lParam
379 );
380 bool HandleQueryDragIcon(WXHICON* phIcon);
381 bool HandleSetCursor( USHORT vId
382 ,WXHWND hWnd
383 );
384
385 bool IsMouseInWindow(void) const;
386 bool OS2GetCreateWindowCoords( const wxPoint& rPos
387 ,const wxSize& rSize
388 ,int& rnX
389 ,int& rnY
390 ,int& rnWidth
391 ,int& rnHeight
392 ) const;
393
394 // Window procedure
395 virtual MRESULT OS2WindowProc( WXUINT uMsg
396 ,WXWPARAM wParam
397 ,WXLPARAM lParam
398 );
399
400 // Calls an appropriate default window procedure
401 virtual MRESULT OS2DefWindowProc( WXUINT uMsg
402 ,WXWPARAM wParam
403 ,WXLPARAM lParam
404 );
405 virtual bool OS2ProcessMessage(WXMSG* pMsg);
406 virtual bool OS2ShouldPreProcessMessage(WXMSG* pMsg);
407 virtual bool OS2TranslateMessage(WXMSG* pMsg);
408 virtual void OS2DestroyWindow(void);
409
410 // this function should return the brush to paint the window background
411 // with or 0 for the default brush
412 virtual WXHBRUSH OnCtlColor( WXHDC hDC
413 ,WXHWND hWnd
414 ,WXUINT uCtlColor
415 ,WXUINT uMessage
416 ,WXWPARAM wParam
417 ,WXLPARAM lParam
418 );
419
420 // Responds to colour changes: passes event on to children.
421 void OnSysColourChanged(wxSysColourChangedEvent& rEvent);
422
423 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
424 void InitMouseEvent( wxMouseEvent& rEvent
425 ,int nX
426 ,int nY
427 ,WXUINT uFlags
428 );
429
430 void MoveChildren(int nDiff);
431 PSWP GetSwp(void) {return &m_vWinSwp;}
432
433protected:
434 // PM can't create some MSW styles natively but can perform these after
435 // creation by sending messages
436 typedef enum extra_flags { kFrameToolWindow = 0x0001
437 ,kVertCaption = 0x0002
438 ,kHorzCaption = 0x0004
439 } EExtraFlags;
440 // Some internal sizeing id's to make it easy for event handlers
441 typedef enum size_types { kSizeNormal
442 ,kSizeMax
443 ,kSizeMin
444 } ESizeTypes;
445 // the window handle
446 WXHWND m_hWnd;
447
448 // the old window proc (we subclass all windows)
449 WXFARPROC m_fnOldWndProc;
450
451 // additional (OS2 specific) flags
452 bool m_bUseCtl3D:1; // Using CTL3D for this control
453 bool m_bBackgroundTransparent:1;
454 bool m_bMouseInWindow:1;
455 bool m_bLastKeydownProcessed:1;
456 bool m_bWinCaptured:1;
457 WXDWORD m_dwExStyle;
458
459 // the size of one page for scrolling
460 int m_nXThumbSize;
461 int m_nYThumbSize;
462
463#if wxUSE_MOUSEEVENT_HACK
464 // the coordinates of the last mouse event and the type of it
465 long m_lLastMouseX,
466 long m_lLastMouseY;
467 int m_nLastMouseEvent;
468#endif // wxUSE_MOUSEEVENT_HACK
469
470 WXHMENU m_hMenu; // Menu, if any
471 unsigned long m_ulMenubarId; // it's Id, if any
472
473 // the return value of WM_GETDLGCODE handler
474 long m_lDlgCode;
475
476 // implement the base class pure virtuals
477 virtual void DoClientToScreen( int* pX
478 ,int* pY
479 ) const;
480 virtual void DoScreenToClient( int* pX
481 ,int* pY
482 ) const;
483 virtual void DoGetPosition( int* pX
484 ,int* pY
485 ) const;
486 virtual void DoGetSize( int* pWidth
487 ,int* pHeight
488 ) const;
489 virtual void DoGetClientSize( int* pWidth
490 ,int* pHeight
491 ) const;
492 virtual void DoSetSize( int nX
493 ,int nY
494 ,int nWidth
495 ,int nHeight
496 ,int nSizeFlags = wxSIZE_AUTO
497 );
498 virtual void DoSetClientSize( int nWidth
499 ,int nHeight
500 );
501
502 virtual void DoCaptureMouse(void);
503 virtual void DoReleaseMouse(void);
504
505 // move the window to the specified location and resize it: this is called
506 // from both DoSetSize() and DoSetClientSize() and would usually just call
507 // ::WinSetWindowPos() except for composite controls which will want to arrange
508 // themselves inside the given rectangle
509 virtual void DoMoveWindow( int nX
510 ,int nY
511 ,int nWidth
512 ,int nHeight
513 );
514
515#if wxUSE_TOOLTIPS
516 virtual void DoSetToolTip(wxToolTip* pTip);
517#endif // wxUSE_TOOLTIPS
518
519 int GetOS2ParentHeight(wxWindowOS2* pParent);
520
521private:
522 // common part of all ctors
523 void Init(void);
524
525 // the (non-virtual) handlers for the events
526 bool HandleMove( int nX
527 ,int nY
528 );
529 bool HandleJoystickEvent( WXUINT uMsg
530 ,int pX
531 ,int pY
532 ,WXUINT uFlags
533 );
534
535 bool HandleNotify( int nIdCtrl
536 ,WXLPARAM lParam
537 ,WXLPARAM* pResult
538 );
539 // the helper functions used by HandleChar/KeyXXX methods
540 wxKeyEvent CreateKeyEvent( wxEventType evType
541 ,int nId
542 ,WXLPARAM lParam = 0
543 ,WXWPARAM wParam = 0
544 ) const;
545
546 wxWindowList* m_pChildrenDisabled;
547 HWND m_hWndScrollBarHorz;
548 HWND m_hWndScrollBarVert;
549 SWP m_vWinSwp;
550
551 DECLARE_DYNAMIC_CLASS(wxWindowOS2);
552 DECLARE_NO_COPY_CLASS(wxWindowOS2)
553 DECLARE_EVENT_TABLE()
554
555 //
556 // Virtual function hiding supression
557 //
558 inline virtual bool Reparent(wxWindowBase* pNewParent)
559 { return(wxWindowBase::Reparent(pNewParent));}
560}; // end of wxWindow
561
562class wxWindowCreationHook
563{
564public:
565 wxWindowCreationHook(wxWindow* pWinBeingCreated);
566 ~wxWindowCreationHook();
567}; // end of CLASS wxWindowCreationHook
568
569// ---------------------------------------------------------------------------
570// global functions
571// ---------------------------------------------------------------------------
572
573// kbd code translation
574WXDLLEXPORT int wxCharCodeOS2ToWX(int nKeySym);
575WXDLLEXPORT int wxCharCodeWXToOS2( int nId
576 ,bool* pbIsVirtual
577 );
578#endif
579 // _WX_WINDOW_H_