1 /////////////////////////////////////////////////////////////////////////////
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 WXDLLEXPORT wxButton
;
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // FIXME does anybody use those? they're unused by wxWindows...
50 // ---------------------------------------------------------------------------
51 // wxWindow declaration for OS/2 PM
52 // ---------------------------------------------------------------------------
54 class WXDLLEXPORT wxWindowOS2
: public wxWindowBase
62 wxWindowOS2( wxWindow
* pParent
64 ,const wxPoint
& rPos
= wxDefaultPosition
65 ,const wxSize
& rSize
= wxDefaultSize
67 ,const wxString
& rName
= wxPanelNameStr
80 virtual ~wxWindowOS2();
82 bool Create( wxWindow
* pParent
84 ,const wxPoint
& rPos
= wxDefaultPosition
85 ,const wxSize
& rSize
= wxDefaultSize
87 ,const wxString
& rName
= wxPanelNameStr
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 bool Reparent(wxWindow
* pNewParent
);
99 virtual void WarpPointer( int x
102 virtual void CaptureMouse(void);
103 virtual void ReleaseMouse(void);
104 virtual void Refresh( bool bEraseBackground
= TRUE
105 ,const wxRect
* pRect
= (const wxRect
*)NULL
107 virtual void Clear(void);
108 virtual void Freeze(void);
109 virtual void Update(void);
110 virtual void Thaw(void);
111 virtual bool SetCursor(const wxCursor
& rCursor
);
112 virtual bool SetFont(const wxFont
& rFont
);
113 virtual int GetCharHeight(void) const;
114 virtual int GetCharWidth(void) const;
115 virtual void GetTextExtent( const wxString
& rString
118 ,int* pDescent
= (int *)NULL
119 ,int* pExternalLeading
= (int *)NULL
120 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
122 #if wxUSE_MENUS_NATIVE
123 virtual bool DoPopupMenu( wxMenu
* pMenu
127 #endif // wxUSE_MENUS_NATIVE
129 virtual void SetScrollbar( int nOrient
133 ,bool bRefresh
= TRUE
135 virtual void SetScrollPos( int nOrient
137 ,bool bRefresh
= TRUE
139 virtual int GetScrollPos(int nOrient
) const;
140 virtual int GetScrollThumb(int nOrient
) const;
141 virtual int GetScrollRange(int nOrient
) const;
142 virtual void ScrollWindow( int nDx
144 ,const wxRect
* pRect
= (wxRect
*)NULL
147 #if wxUSE_DRAG_AND_DROP
148 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
149 #endif // wxUSE_DRAG_AND_DROP
151 // Accept files for dragging
152 virtual void DragAcceptFiles(bool bAccept
);
154 #if WXWIN_COMPATIBILITY
155 // Set/get scroll attributes
156 virtual void SetScrollRange( int nOrient
158 ,bool bRefresh
= TRUE
160 virtual void SetScrollPage( int nOrient
162 ,bool bRefresh
= TRUE
164 virtual int OldGetScrollRange(int nOrient
) const;
165 virtual int GetScrollPage(int nOrient
) const;
170 // Handle a control command
171 virtual void OnCommand( wxWindow
& rWin
172 ,wxCommandEvent
& rEvent
175 // Override to define new behaviour for default action (e.g. double
176 // clicking on a listbox)
177 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
178 #endif // WXWIN_COMPATIBILITY
180 #if wxUSE_CARET && WXWIN_COMPATIBILITY
181 void CreateCaret( int nWidth
184 void CreateCaret(const wxBitmap
* pBitmap
);
185 void DestroyCaret(void);
186 void ShowCaret(bool bShow
);
187 void SetCaretPos( int nX
190 void GetCaretPos( int* pX
193 #endif // wxUSE_CARET
195 #ifndef __WXUNIVERSAL__
196 // Native resource loading (implemented in src/os2/nativdlg.cpp)
197 // FIXME: should they really be all virtual?
198 virtual bool LoadNativeDialog( wxWindow
* pParent
201 virtual bool LoadNativeDialog( wxWindow
* pParent
202 ,const wxString
& rName
204 wxWindow
* GetWindowChild1(wxWindowID vId
);
205 wxWindow
* GetWindowChild(wxWindowID vId
);
206 #endif //__WXUNIVERSAL__
208 // implementation from now on
209 // --------------------------
214 WXHWND
GetHWND(void) const { return m_hWnd
; }
215 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
216 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
217 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
218 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
219 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
223 void OnSetFocus(wxFocusEvent
& rEvent
);
224 void OnEraseBackground(wxEraseEvent
& rEvent
);
225 void OnIdle(wxIdleEvent
& rEvent
);
228 // For implementation purposes - sometimes decorations make the client area
230 virtual wxPoint
GetClientAreaOrigin(void) const;
232 // Windows subclassing
233 void SubclassWin(WXHWND hWnd
);
234 void UnsubclassWin(void);
236 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
237 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
239 wxWindow
* FindItem(long lId
) const;
240 wxWindow
* FindItemByHWND( WXHWND hWnd
241 ,bool bControlOnly
= FALSE
244 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
245 static WXDWORD
MakeExtendedStyle( long lStyle
246 ,bool bEliminateBorders
= TRUE
248 // Determine whether 3D effects are wanted
249 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
253 // PM only: TRUE if this control is part of the main control
254 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
256 // returns TRUE if the window has been created
257 bool OS2Create( PSZ zClass
266 virtual bool OS2Command( WXUINT uParam
270 #if WXWIN_COMPATIBILITY
271 wxObject
* GetChild(int nNumber
) const;
272 virtual void OS2DeviceToLogical( float* pfX
275 #endif // WXWIN_COMPATIBILITY
277 #ifndef __WXUNIVERSAL__
278 // Create an appropriate wxWindow from a HWND
279 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
283 // Make sure the window style reflects the HWND style (roughly)
284 virtual void AdoptAttributesFromHWND(void);
287 // Setup background and foreground colours correctly
288 virtual void SetupColours(void);
290 // ------------------------------------------------------------------------
291 // helpers for message handlers: these perform the same function as the
292 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
293 // the correct parameters
294 // ------------------------------------------------------------------------
296 void UnpackCommand( WXWPARAM wParam
302 void UnpackActivate( WXWPARAM wParam
307 void UnpackScroll( WXWPARAM wParam
313 void UnpackMenuSelect( WXWPARAM wParam
320 // ------------------------------------------------------------------------
321 // internal handlers for OS2 messages: all handlers return a boolen value:
322 // TRUE means that the handler processed the event and FALSE that it didn't
323 // ------------------------------------------------------------------------
325 // there are several cases where we have virtual functions for PM
326 // message processing: this is because these messages often require to be
327 // processed in a different manner in the derived classes. For all other
328 // messages, however, we do *not* have corresponding OS2OnXXX() function
329 // and if the derived class wants to process them, it should override
330 // OS2WindowProc() directly.
332 // scroll event (both horizontal and vertical)
333 virtual bool OS2OnScroll( int nOrientation
339 // owner-drawn controls need to process these messages
340 virtual bool OS2OnDrawItem( int nId
341 ,WXDRAWITEMSTRUCT
* pItem
343 virtual bool OS2OnMeasureItem( int nId
344 ,WXMEASUREITEMSTRUCT
* pItem
347 // the rest are not virtual
348 bool HandleCreate( WXLPCREATESTRUCT vCs
351 bool HandleInitDialog(WXHWND hWndFocus
);
352 bool HandleDestroy(void);
353 bool HandlePaint(void);
354 bool HandleEraseBkgnd(WXHDC vDC
);
355 bool HandleMinimize(void);
356 bool HandleMaximize(void);
357 bool HandleSize( int nX
361 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
362 bool HandleShow( bool bShow
365 bool HandleActivate( int nFlag
368 bool HandleCommand( WXWORD nId
372 bool HandleSysCommand( WXWPARAM wParam
375 bool HandlePaletteChanged();
376 bool HandleSysColorChange(void);
377 bool HandleCtlColor(WXHBRUSH
* hBrush
);
378 bool HandleSetFocus(WXHWND hWnd
);
379 bool HandleKillFocus(WXHWND hWnd
);
380 bool HandleEndDrag(WXWPARAM wParam
);
381 bool HandleMouseEvent( WXUINT uMsg
386 bool HandleMouseMove( int nX
390 bool HandleChar( WXDWORD wParam
392 ,bool bIsASCII
= FALSE
394 bool HandleKeyDown( WXWORD wParam
397 bool HandleKeyUp( WXDWORD wParam
400 bool HandleQueryDragIcon(WXHICON
* phIcon
);
401 bool HandleSetCursor( USHORT vId
405 bool IsMouseInWindow(void) const;
406 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
415 virtual MRESULT
OS2WindowProc( WXUINT uMsg
420 // Calls an appropriate default window procedure
421 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
425 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
426 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
427 virtual void OS2DestroyWindow(void);
429 // Detach "Window" menu from menu bar so it doesn't get deleted
430 void OS2DetachWindowMenu(void);
432 // this function should return the brush to paint the window background
433 // with or 0 for the default brush
434 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
442 #if WXWIN_COMPATIBILITY
443 void SetShowing(bool bShow
) { (void)Show(show
); }
444 bool IsUserEnabled(void) const { return IsEnabled(); }
445 #endif // WXWIN_COMPATIBILITY
447 // Responds to colour changes: passes event on to children.
448 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
450 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
451 void InitMouseEvent( wxMouseEvent
& rEvent
457 void MoveChildren(int nDiff
);
460 // PM can't create some MSW styles natively but can perform these after
461 // creation by sending messages
462 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
463 ,kVertCaption
= 0x0002
464 ,kHorzCaption
= 0x0004
466 // Some internal sizeing id's to make it easy for event handlers
467 typedef enum size_types
{ kSizeNormal
474 // the old window proc (we subclass all windows)
475 WXFARPROC m_fnOldWndProc
;
477 // additional (OS2 specific) flags
478 bool m_bUseCtl3D
:1; // Using CTL3D for this control
479 bool m_bBackgroundTransparent
:1;
480 bool m_bMouseInWindow
:1;
481 bool m_bDoubleClickAllowed
:1;
482 bool m_bWinCaptured
:1;
485 // the size of one page for scrolling
489 #if wxUSE_MOUSEEVENT_HACK
490 // the coordinates of the last mouse event and the type of it
493 int m_nLastMouseEvent
;
494 #endif // wxUSE_MOUSEEVENT_HACK
496 WXHMENU m_hMenu
; // Menu, if any
497 unsigned long m_ulMenubarId
; // it's Id, if any
499 // the return value of WM_GETDLGCODE handler
502 // implement the base class pure virtuals
503 virtual void DoClientToScreen( int* pX
506 virtual void DoScreenToClient( int* pX
509 virtual void DoGetPosition( int* pX
512 virtual void DoGetSize( int* pWidth
515 virtual void DoGetClientSize( int* pWidth
518 virtual void DoSetSize( int nX
522 ,int nSizeFlags
= wxSIZE_AUTO
524 virtual void DoSetClientSize( int nWidth
528 // move the window to the specified location and resize it: this is called
529 // from both DoSetSize() and DoSetClientSize() and would usually just call
530 // ::WinSetWindowPos() except for composite controls which will want to arrange
531 // themselves inside the given rectangle
532 virtual void DoMoveWindow( int nX
539 virtual void DoSetToolTip(wxToolTip
* pTip
);
540 #endif // wxUSE_TOOLTIPS
542 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
545 // common part of all ctors
548 // the (non-virtual) handlers for the events
549 bool HandleMove( int nX
552 bool HandleJoystickEvent( WXUINT uMsg
558 bool HandleNotify( int nIdCtrl
562 // the helper functions used by HandleChar/KeyXXX methods
563 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
565 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
566 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
567 DECLARE_EVENT_TABLE()
569 HWND m_hWndScrollBarHorz
;
570 HWND m_hWndScrollBarVert
;
572 // Virtual function hiding supression
573 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
574 { return(wxWindowBase::Reparent(pNewParent
));};
575 }; // end of wxWindow
577 class wxWindowCreationHook
580 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
581 ~wxWindowCreationHook();
582 }; // end of CLASS wxWindowCreationHook
584 // ---------------------------------------------------------------------------
586 // ---------------------------------------------------------------------------
588 // kbd code translation
589 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
590 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId