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 WXDLLEXPORT 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(wxWindow
* pNewParent
);
89 virtual void WarpPointer( int x
92 virtual void Refresh( bool bEraseBackground
= true
93 ,const wxRect
* pRect
= (const wxRect
*)NULL
95 virtual void Freeze(void);
96 virtual void Update(void);
97 virtual void Thaw(void);
98 virtual void SetWindowStyleFlag(long lStyle
);
99 virtual bool SetCursor(const wxCursor
& rCursor
);
100 virtual bool SetFont(const wxFont
& rFont
);
101 virtual int GetCharHeight(void) const;
102 virtual int GetCharWidth(void) const;
103 virtual void GetTextExtent( const wxString
& rString
106 ,int* pDescent
= (int *)NULL
107 ,int* pExternalLeading
= (int *)NULL
108 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
110 #if wxUSE_MENUS_NATIVE
111 virtual bool DoPopupMenu( wxMenu
* pMenu
115 #endif // wxUSE_MENUS_NATIVE
117 virtual void SetScrollbar( int nOrient
121 ,bool bRefresh
= true
123 virtual void SetScrollPos( int nOrient
125 ,bool bRefresh
= true
127 virtual int GetScrollPos(int nOrient
) const;
128 virtual int GetScrollThumb(int nOrient
) const;
129 virtual int GetScrollRange(int nOrient
) const;
130 virtual void ScrollWindow( int nDx
132 ,const wxRect
* pRect
= (wxRect
*)NULL
135 inline HWND
GetScrollBarHorz(void) const {return m_hWndScrollBarHorz
;}
136 inline HWND
GetScrollBarVert(void) const {return m_hWndScrollBarVert
;};
137 #if wxUSE_DRAG_AND_DROP
138 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
139 #endif // wxUSE_DRAG_AND_DROP
141 // Accept files for dragging
142 virtual void DragAcceptFiles(bool bAccept
);
144 #ifndef __WXUNIVERSAL__
145 // Native resource loading (implemented in src/os2/nativdlg.cpp)
146 // FIXME: should they really be all virtual?
147 virtual bool LoadNativeDialog( wxWindow
* pParent
150 virtual bool LoadNativeDialog( wxWindow
* pParent
151 ,const wxString
& rName
153 wxWindow
* GetWindowChild1(wxWindowID vId
);
154 wxWindow
* GetWindowChild(wxWindowID vId
);
155 #endif //__WXUNIVERSAL__
157 // implementation from now on
158 // --------------------------
163 WXHWND
GetHWND(void) const { return m_hWnd
; }
164 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
165 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
166 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
167 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
168 void SetTransparentBackground(bool bT
= true) { m_bBackgroundTransparent
= bT
; }
172 void OnSetFocus(wxFocusEvent
& rEvent
);
173 void OnEraseBackground(wxEraseEvent
& rEvent
);
174 void OnIdle(wxIdleEvent
& rEvent
);
178 // Windows subclassing
179 void SubclassWin(WXHWND hWnd
);
180 void UnsubclassWin(void);
182 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
183 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
185 // Return true if the window is of a standard (i.e. not wxWidgets') class
187 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
189 wxWindow
* FindItem(long lId
) const;
190 wxWindow
* FindItemByHWND( WXHWND hWnd
191 ,bool bControlOnly
= false
194 // Make a Windows extended style from the given wxWidgets window style ?? applicable to OS/2??
195 static WXDWORD
MakeExtendedStyle( long lStyle
196 ,bool bEliminateBorders
= true
199 // PM only: true if this control is part of the main control
200 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
202 // translate wxWidgets style flags for this control into the PM style
203 // and optional extended style for the corresponding native control
205 // this is the function that should be overridden in the derived classes,
206 // but you will mostly use OS2GetCreateWindowFlags() below
207 virtual WXDWORD
OS2GetStyle( long lFlags
208 ,WXDWORD
* pdwExstyle
= NULL
211 // get the MSW window flags corresponding to wxWidgets ones
213 // the functions returns the flags (WS_XXX) directly and puts the ext
214 // (WS_EX_XXX) flags into the provided pointer if not NULL
215 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
216 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
219 // get the HWND to be used as parent of this window with CreateWindow()
220 virtual WXHWND
OS2GetParent(void) const;
222 // returns true if the window has been created
223 bool OS2Create( PSZ zClass
224 ,const wxChar
* zTitle
232 virtual bool OS2Command( WXUINT uParam
236 #ifndef __WXUNIVERSAL__
237 // Create an appropriate wxWindow from a HWND
238 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
242 // Make sure the window style reflects the HWND style (roughly)
243 virtual void AdoptAttributesFromHWND(void);
246 // Setup background and foreground colours correctly
247 virtual void SetupColours(void);
249 // ------------------------------------------------------------------------
250 // helpers for message handlers: these perform the same function as the
251 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
252 // the correct parameters
253 // ------------------------------------------------------------------------
255 void UnpackCommand( WXWPARAM wParam
261 void UnpackActivate( WXWPARAM wParam
266 void UnpackScroll( WXWPARAM wParam
272 void UnpackMenuSelect( WXWPARAM wParam
279 // ------------------------------------------------------------------------
280 // internal handlers for OS2 messages: all handlers return a boolen value:
281 // true means that the handler processed the event and false that it didn't
282 // ------------------------------------------------------------------------
284 // there are several cases where we have virtual functions for PM
285 // message processing: this is because these messages often require to be
286 // processed in a different manner in the derived classes. For all other
287 // messages, however, we do *not* have corresponding OS2OnXXX() function
288 // and if the derived class wants to process them, it should override
289 // OS2WindowProc() directly.
291 // scroll event (both horizontal and vertical)
292 virtual bool OS2OnScroll( int nOrientation
298 // owner-drawn controls need to process these messages
299 virtual bool OS2OnDrawItem( int nId
300 ,WXDRAWITEMSTRUCT
* pItem
302 virtual long OS2OnMeasureItem( int nId
303 ,WXMEASUREITEMSTRUCT
* pItem
306 virtual void OnPaint(wxPaintEvent
& rEvent
);
308 // the rest are not virtual
309 bool HandleCreate( WXLPCREATESTRUCT vCs
312 bool HandleInitDialog(WXHWND hWndFocus
);
313 bool HandleDestroy(void);
314 bool HandlePaint(void);
315 bool HandleEraseBkgnd(WXHDC vDC
);
316 bool HandleMinimize(void);
317 bool HandleMaximize(void);
318 bool HandleSize( int nX
322 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
323 bool HandleShow( bool bShow
326 bool HandleActivate( int nFlag
329 bool HandleCommand( WXWORD nId
333 bool HandleSysCommand( WXWPARAM wParam
336 bool HandlePaletteChanged(void);
337 bool HandleQueryNewPalette(void);
338 bool HandleSysColorChange(void);
339 bool HandleDisplayChange(void);
340 bool HandleCaptureChanged(WXHWND hBainedCapture
);
342 bool HandleCtlColor(WXHBRUSH
* hBrush
);
343 bool HandleSetFocus(WXHWND hWnd
);
344 bool HandleKillFocus(WXHWND hWnd
);
345 bool HandleEndDrag(WXWPARAM wParam
);
346 bool HandleMouseEvent( WXUINT uMsg
351 bool HandleMouseMove( int nX
355 bool HandleChar( WXWPARAM wParam
357 ,bool bIsASCII
= false
359 bool HandleKeyDown( WXWPARAM wParam
362 bool HandleKeyUp( WXWPARAM wParam
365 bool HandleQueryDragIcon(WXHICON
* phIcon
);
366 bool HandleSetCursor( USHORT vId
370 bool IsMouseInWindow(void) const;
371 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
380 virtual MRESULT
OS2WindowProc( WXUINT uMsg
385 // Calls an appropriate default window procedure
386 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
390 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
391 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
392 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
393 virtual void OS2DestroyWindow(void);
395 // this function should return the brush to paint the window background
396 // with or 0 for the default brush
397 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
405 // Responds to colour changes: passes event on to children.
406 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
408 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
409 void InitMouseEvent( wxMouseEvent
& rEvent
415 void MoveChildren(int nDiff
);
416 PSWP
GetSwp(void) {return &m_vWinSwp
;}
419 // PM can't create some MSW styles natively but can perform these after
420 // creation by sending messages
421 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
422 ,kVertCaption
= 0x0002
423 ,kHorzCaption
= 0x0004
425 // Some internal sizeing id's to make it easy for event handlers
426 typedef enum size_types
{ kSizeNormal
433 // the old window proc (we subclass all windows)
434 WXFARPROC m_fnOldWndProc
;
436 // additional (OS2 specific) flags
437 bool m_bUseCtl3D
:1; // Using CTL3D for this control
438 bool m_bBackgroundTransparent
:1;
439 bool m_bMouseInWindow
:1;
440 bool m_bLastKeydownProcessed
:1;
441 bool m_bWinCaptured
:1;
444 // the size of one page for scrolling
448 #if wxUSE_MOUSEEVENT_HACK
449 // the coordinates of the last mouse event and the type of it
452 int m_nLastMouseEvent
;
453 #endif // wxUSE_MOUSEEVENT_HACK
455 WXHMENU m_hMenu
; // Menu, if any
456 unsigned long m_ulMenubarId
; // it's Id, if any
458 // the return value of WM_GETDLGCODE handler
461 // implement the base class pure virtuals
462 virtual void DoClientToScreen( int* pX
465 virtual void DoScreenToClient( int* pX
468 virtual void DoGetPosition( int* pX
471 virtual void DoGetSize( int* pWidth
474 virtual void DoGetClientSize( int* pWidth
477 virtual void DoSetSize( int nX
481 ,int nSizeFlags
= wxSIZE_AUTO
483 virtual void DoSetClientSize( int nWidth
487 virtual void DoCaptureMouse(void);
488 virtual void DoReleaseMouse(void);
490 // move the window to the specified location and resize it: this is called
491 // from both DoSetSize() and DoSetClientSize() and would usually just call
492 // ::WinSetWindowPos() except for composite controls which will want to arrange
493 // themselves inside the given rectangle
494 virtual void DoMoveWindow( int nX
501 virtual void DoSetToolTip(wxToolTip
* pTip
);
502 #endif // wxUSE_TOOLTIPS
504 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
507 // common part of all ctors
510 // the (non-virtual) handlers for the events
511 bool HandleMove( int nX
514 bool HandleJoystickEvent( WXUINT uMsg
520 bool HandleNotify( int nIdCtrl
524 // the helper functions used by HandleChar/KeyXXX methods
525 wxKeyEvent
CreateKeyEvent( wxEventType evType
531 HWND m_hWndScrollBarHorz
;
532 HWND m_hWndScrollBarVert
;
535 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
536 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
537 DECLARE_EVENT_TABLE()
540 // Virtual function hiding supression
542 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
543 { return(wxWindowBase::Reparent(pNewParent
));}
544 }; // end of wxWindow
546 class wxWindowCreationHook
549 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
550 ~wxWindowCreationHook();
551 }; // end of CLASS wxWindowCreationHook
553 // ---------------------------------------------------------------------------
555 // ---------------------------------------------------------------------------
557 // kbd code translation
558 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
559 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId
560 ,bool* pbIsVirtual
= NULL
563 // ----------------------------------------------------------------------------
565 // ----------------------------------------------------------------------------
567 // notice that this hash must be defined after wxWindow declaration as it
568 // needs to "see" its dtor and not just forward declaration
571 // pseudo-template HWND <-> wxWindow hash table
572 WX_DECLARE_HASH(wxWindowOS2
, wxWindowList
, wxWinHashTable
);
574 extern wxWinHashTable
*wxWinHandleHash
;
576 #endif // _WX_WINDOW_H_