1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/window.h
3 // Purpose: wxWindow class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #define wxUSE_MOUSEEVENT_HACK 0
17 // ---------------------------------------------------------------------------
19 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
27 // forward declarations
28 // ---------------------------------------------------------------------------
30 # define CW_USEDEFAULT ((int)0x80000000)
33 // ---------------------------------------------------------------------------
34 // forward declarations
35 // ---------------------------------------------------------------------------
37 class WXDLLIMPEXP_FWD_CORE wxButton
;
39 // ---------------------------------------------------------------------------
40 // wxWindow declaration for OS/2 PM
41 // ---------------------------------------------------------------------------
43 class WXDLLIMPEXP_CORE wxWindowOS2
: public wxWindowBase
51 wxWindowOS2( wxWindow
* pParent
53 ,const wxPoint
& rPos
= wxDefaultPosition
54 ,const wxSize
& rSize
= wxDefaultSize
56 ,const wxString
& rName
= wxPanelNameStr
69 virtual ~wxWindowOS2();
71 bool Create( wxWindow
* pParent
73 ,const wxPoint
& rPos
= wxDefaultPosition
74 ,const wxSize
& rSize
= wxDefaultSize
76 ,const wxString
& rName
= wxPanelNameStr
79 // implement base class pure virtuals
80 virtual void SetLabel(const wxString
& label
);
81 virtual wxString
GetLabel(void) const;
82 virtual void Raise(void);
83 virtual void Lower(void);
84 virtual bool Show(bool bShow
= true);
85 virtual void DoEnable(bool bEnable
);
86 virtual void SetFocus(void);
87 virtual void SetFocusFromKbd(void);
88 virtual bool Reparent(wxWindowBase
* pNewParent
);
89 virtual void WarpPointer( int x
92 virtual void Refresh( bool bEraseBackground
= true
93 ,const wxRect
* pRect
= (const wxRect
*)NULL
95 virtual void Update(void);
96 virtual void SetWindowStyleFlag(long lStyle
);
97 virtual bool SetCursor(const wxCursor
& rCursor
);
98 virtual bool SetFont(const wxFont
& rFont
);
99 virtual int GetCharHeight(void) const;
100 virtual int GetCharWidth(void) const;
101 virtual void GetTextExtent( const wxString
& rString
104 ,int* pDescent
= (int *)NULL
105 ,int* pExternalLeading
= (int *)NULL
106 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
108 #if wxUSE_MENUS_NATIVE
109 virtual bool DoPopupMenu( wxMenu
* pMenu
113 #endif // wxUSE_MENUS_NATIVE
115 virtual void SetScrollbar( int nOrient
119 ,bool bRefresh
= true
121 virtual void SetScrollPos( int nOrient
123 ,bool bRefresh
= true
125 virtual int GetScrollPos(int nOrient
) const;
126 virtual int GetScrollThumb(int nOrient
) const;
127 virtual int GetScrollRange(int nOrient
) const;
128 virtual void ScrollWindow( int nDx
130 ,const wxRect
* pRect
= (wxRect
*)NULL
133 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
134 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;};
135 #if wxUSE_DRAG_AND_DROP
136 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
137 #endif // wxUSE_DRAG_AND_DROP
139 // Accept files for dragging
140 virtual void DragAcceptFiles(bool bAccept
);
142 #ifndef __WXUNIVERSAL__
143 // Native resource loading (implemented in src/os2/nativdlg.cpp)
144 // FIXME: should they really be all virtual?
145 virtual bool LoadNativeDialog( wxWindow
* pParent
148 virtual bool LoadNativeDialog( wxWindow
* pParent
149 ,const wxString
& rName
151 wxWindow
* GetWindowChild1(wxWindowID vId
);
152 wxWindow
* GetWindowChild(wxWindowID vId
);
153 #endif //__WXUNIVERSAL__
155 // implementation from now on
156 // --------------------------
161 WXHWND
GetHWND(void) const { return m_hWnd
; }
162 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
163 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
164 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
165 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
166 void SetTransparentBackground(bool bT
= true) { m_bBackgroundTransparent
= bT
; }
170 void OnSetFocus(wxFocusEvent
& rEvent
);
171 void OnEraseBackground(wxEraseEvent
& rEvent
);
172 void OnIdle(wxIdleEvent
& rEvent
);
176 // Windows subclassing
177 void SubclassWin(WXHWND hWnd
);
178 void UnsubclassWin(void);
180 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
181 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
183 // Return true if the window is of a standard (i.e. not wxWidgets') class
185 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
187 wxWindow
* FindItem(long lId
) const;
188 wxWindow
* FindItemByHWND( WXHWND hWnd
189 ,bool bControlOnly
= false
192 // Make a Windows extended style from the given wxWidgets window style ?? applicable to OS/2??
193 static WXDWORD
MakeExtendedStyle( long lStyle
194 ,bool bEliminateBorders
= true
197 // PM only: true if this control is part of the main control
198 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
200 // translate wxWidgets style flags for this control into the PM style
201 // and optional extended style for the corresponding native control
203 // this is the function that should be overridden in the derived classes,
204 // but you will mostly use OS2GetCreateWindowFlags() below
205 virtual WXDWORD
OS2GetStyle( long lFlags
206 ,WXDWORD
* pdwExstyle
= NULL
209 // get the MSW window flags corresponding to wxWidgets ones
211 // the functions returns the flags (WS_XXX) directly and puts the ext
212 // (WS_EX_XXX) flags into the provided pointer if not NULL
213 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
214 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
217 // get the HWND to be used as parent of this window with CreateWindow()
218 virtual WXHWND
OS2GetParent(void) const;
220 // returns true if the window has been created
221 bool OS2Create( PSZ zClass
222 ,const wxChar
* zTitle
230 virtual bool OS2Command( WXUINT uParam
234 #ifndef __WXUNIVERSAL__
235 // Create an appropriate wxWindow from a HWND
236 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
240 // Make sure the window style reflects the HWND style (roughly)
241 virtual void AdoptAttributesFromHWND(void);
244 // Setup background and foreground colours correctly
245 virtual void SetupColours(void);
247 // ------------------------------------------------------------------------
248 // helpers for message handlers: these perform the same function as the
249 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
250 // the correct parameters
251 // ------------------------------------------------------------------------
253 void UnpackCommand( WXWPARAM wParam
259 void UnpackActivate( WXWPARAM wParam
264 void UnpackScroll( WXWPARAM wParam
270 void UnpackMenuSelect( WXWPARAM wParam
277 // ------------------------------------------------------------------------
278 // internal handlers for OS2 messages: all handlers return a boolen value:
279 // true means that the handler processed the event and false that it didn't
280 // ------------------------------------------------------------------------
282 // there are several cases where we have virtual functions for PM
283 // message processing: this is because these messages often require to be
284 // processed in a different manner in the derived classes. For all other
285 // messages, however, we do *not* have corresponding OS2OnXXX() function
286 // and if the derived class wants to process them, it should override
287 // OS2WindowProc() directly.
289 // scroll event (both horizontal and vertical)
290 virtual bool OS2OnScroll( int nOrientation
296 // owner-drawn controls need to process these messages
297 virtual bool OS2OnDrawItem( int nId
298 ,WXDRAWITEMSTRUCT
* pItem
300 virtual long OS2OnMeasureItem( int nId
301 ,WXMEASUREITEMSTRUCT
* pItem
304 virtual void OnPaint(wxPaintEvent
& rEvent
);
306 // the rest are not virtual
307 bool HandleCreate( WXLPCREATESTRUCT vCs
310 bool HandleInitDialog(WXHWND hWndFocus
);
311 bool HandleDestroy(void);
312 bool HandlePaint(void);
313 bool HandleEraseBkgnd(WXHDC vDC
);
314 bool HandleMinimize(void);
315 bool HandleMaximize(void);
316 bool HandleSize( int nX
320 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
321 bool HandleShow( bool bShow
324 bool HandleActivate( int nFlag
327 bool HandleCommand( WXWORD nId
331 bool HandleSysCommand( WXWPARAM wParam
334 bool HandlePaletteChanged(void);
335 bool HandleQueryNewPalette(void);
336 bool HandleSysColorChange(void);
337 bool HandleDisplayChange(void);
338 bool HandleCaptureChanged(WXHWND hBainedCapture
);
340 bool HandleCtlColor(WXHBRUSH
* hBrush
);
341 bool HandleSetFocus(WXHWND hWnd
);
342 bool HandleKillFocus(WXHWND hWnd
);
343 bool HandleEndDrag(WXWPARAM wParam
);
344 bool HandleMouseEvent( WXUINT uMsg
349 bool HandleMouseMove( int nX
353 bool HandleChar( WXWPARAM wParam
355 ,bool bIsASCII
= false
357 bool HandleKeyDown( WXWPARAM wParam
360 bool HandleKeyUp( WXWPARAM wParam
363 bool HandleQueryDragIcon(WXHICON
* phIcon
);
364 bool HandleSetCursor( USHORT vId
368 bool IsMouseInWindow(void) const;
369 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
378 virtual MRESULT
OS2WindowProc( WXUINT uMsg
383 // Calls an appropriate default window procedure
384 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
388 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
389 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
390 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
391 virtual void OS2DestroyWindow(void);
393 // this function should return the brush to paint the window background
394 // with or 0 for the default brush
395 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
403 // Responds to colour changes: passes event on to children.
404 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
406 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
407 void InitMouseEvent( wxMouseEvent
& rEvent
413 void MoveChildren(int nDiff
);
414 PSWP
GetSwp(void) {return &m_vWinSwp
;}
417 virtual void DoFreeze(void);
418 virtual void DoThaw(void);
420 // PM can't create some MSW styles natively but can perform these after
421 // creation by sending messages
422 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
423 ,kVertCaption
= 0x0002
424 ,kHorzCaption
= 0x0004
426 // Some internal sizeing id's to make it easy for event handlers
427 typedef enum size_types
{ kSizeNormal
434 // the old window proc (we subclass all windows)
435 WXFARPROC m_fnOldWndProc
;
437 // additional (OS2 specific) flags
438 bool m_bUseCtl3D
:1; // Using CTL3D for this control
439 bool m_bBackgroundTransparent
:1;
440 bool m_bMouseInWindow
:1;
441 bool m_bLastKeydownProcessed
:1;
442 bool m_bWinCaptured
:1;
445 // the size of one page for scrolling
449 #if wxUSE_MOUSEEVENT_HACK
450 // the coordinates of the last mouse event and the type of it
453 int m_nLastMouseEvent
;
454 #endif // wxUSE_MOUSEEVENT_HACK
456 WXHMENU m_hMenu
; // Menu, if any
457 unsigned long m_ulMenubarId
; // it's Id, if any
459 // the return value of WM_GETDLGCODE handler
462 // implement the base class pure virtuals
463 virtual void DoClientToScreen( int* pX
466 virtual void DoScreenToClient( int* pX
469 virtual void DoGetPosition( int* pX
472 virtual void DoGetSize( int* pWidth
475 virtual void DoGetClientSize( int* pWidth
478 virtual void DoSetSize( int nX
482 ,int nSizeFlags
= wxSIZE_AUTO
484 virtual void DoSetClientSize( int nWidth
488 virtual void DoCaptureMouse(void);
489 virtual void DoReleaseMouse(void);
491 // move the window to the specified location and resize it: this is called
492 // from both DoSetSize() and DoSetClientSize() and would usually just call
493 // ::WinSetWindowPos() except for composite controls which will want to arrange
494 // themselves inside the given rectangle
495 virtual void DoMoveWindow( int nX
502 virtual void DoSetToolTip(wxToolTip
* pTip
);
503 #endif // wxUSE_TOOLTIPS
505 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
508 // common part of all ctors
511 // the (non-virtual) handlers for the events
512 bool HandleMove( int nX
515 bool HandleJoystickEvent( WXUINT uMsg
521 bool HandleNotify( int nIdCtrl
525 // the helper functions used by HandleChar/KeyXXX methods
526 wxKeyEvent
CreateKeyEvent( wxEventType evType
532 HWND m_hWndScrollBarHorz
;
533 HWND m_hWndScrollBarVert
;
536 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
537 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
538 DECLARE_EVENT_TABLE()
539 }; // end of wxWindow
541 class wxWindowCreationHook
544 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
545 ~wxWindowCreationHook();
546 }; // end of CLASS wxWindowCreationHook
548 // ---------------------------------------------------------------------------
550 // ---------------------------------------------------------------------------
552 // kbd code translation
553 WXDLLIMPEXP_CORE
int wxCharCodeOS2ToWX(int nKeySym
);
554 WXDLLIMPEXP_CORE
int wxCharCodeWXToOS2( int nId
555 ,bool* pbIsVirtual
= NULL
558 // ----------------------------------------------------------------------------
560 // ----------------------------------------------------------------------------
562 // notice that this hash must be defined after wxWindow declaration as it
563 // needs to "see" its dtor and not just forward declaration
566 // pseudo-template HWND <-> wxWindow hash table
567 WX_DECLARE_HASH(wxWindowOS2
, wxWindowList
, wxWinHashTable
);
569 extern wxWinHashTable
*wxWinHandleHash
;
571 #endif // _WX_WINDOW_H_