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 void SetFocusFromKbd(void);
99 virtual bool Reparent(wxWindow
* pNewParent
);
100 virtual void WarpPointer( int x
103 virtual void Refresh( bool bEraseBackground
= TRUE
104 ,const wxRect
* pRect
= (const wxRect
*)NULL
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
117 ,int* pDescent
= (int *)NULL
118 ,int* pExternalLeading
= (int *)NULL
119 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
121 #if wxUSE_MENUS_NATIVE
122 virtual bool DoPopupMenu( wxMenu
* pMenu
126 #endif // wxUSE_MENUS_NATIVE
128 virtual void SetScrollbar( int nOrient
132 ,bool bRefresh
= TRUE
134 virtual void SetScrollPos( int nOrient
136 ,bool bRefresh
= TRUE
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
143 ,const wxRect
* pRect
= (wxRect
*)NULL
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
152 // Accept files for dragging
153 virtual void DragAcceptFiles(bool bAccept
);
155 #if WXWIN_COMPATIBILITY
156 // Set/get scroll attributes
157 virtual void SetScrollRange( int nOrient
159 ,bool bRefresh
= TRUE
161 virtual void SetScrollPage( int nOrient
163 ,bool bRefresh
= TRUE
165 virtual int OldGetScrollRange(int nOrient
) const;
166 virtual int GetScrollPage(int nOrient
) const;
171 // Handle a control command
172 virtual void OnCommand( wxWindow
& rWin
173 ,wxCommandEvent
& rEvent
176 // Override to define new behaviour for default action (e.g. double
177 // clicking on a listbox)
178 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
179 #endif // WXWIN_COMPATIBILITY
181 #if wxUSE_CARET && WXWIN_COMPATIBILITY
182 void CreateCaret( int nWidth
185 void CreateCaret(const wxBitmap
* pBitmap
);
186 void DestroyCaret(void);
187 void ShowCaret(bool bShow
);
188 void SetCaretPos( int nX
191 void GetCaretPos( int* pX
194 #endif // wxUSE_CARET
196 #ifndef __WXUNIVERSAL__
197 // Native resource loading (implemented in src/os2/nativdlg.cpp)
198 // FIXME: should they really be all virtual?
199 virtual bool LoadNativeDialog( wxWindow
* pParent
202 virtual bool LoadNativeDialog( wxWindow
* pParent
203 ,const wxString
& rName
205 wxWindow
* GetWindowChild1(wxWindowID vId
);
206 wxWindow
* GetWindowChild(wxWindowID vId
);
207 #endif //__WXUNIVERSAL__
209 // implementation from now on
210 // --------------------------
215 WXHWND
GetHWND(void) const { return m_hWnd
; }
216 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
217 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
218 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
219 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
220 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
224 void OnSetFocus(wxFocusEvent
& rEvent
);
225 void OnEraseBackground(wxEraseEvent
& rEvent
);
226 void OnIdle(wxIdleEvent
& rEvent
);
230 // For implementation purposes - sometimes decorations make the client area
232 virtual wxPoint
GetClientAreaOrigin(void) const;
234 // Windows subclassing
235 void SubclassWin(WXHWND hWnd
);
236 void UnsubclassWin(void);
238 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
239 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
241 // Return TRUE if the window is of a standard (i.e. not wxWindows') class
243 bool IsOfStandardClass(void) const { return m_fnOldWndProc
!= NULL
; }
245 wxWindow
* FindItem(long lId
) const;
246 wxWindow
* FindItemByHWND( WXHWND hWnd
247 ,bool bControlOnly
= FALSE
250 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
251 static WXDWORD
MakeExtendedStyle( long lStyle
252 ,bool bEliminateBorders
= TRUE
254 // Determine whether 3D effects are wanted
255 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
259 // PM only: TRUE if this control is part of the main control
260 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
262 // translate wxWindows style flags for this control into the PM style
263 // and optional extended style for the corresponding native control
265 // this is the function that should be overridden in the derived classes,
266 // but you will mostly use OS2GetCreateWindowFlags() below
267 virtual WXDWORD
OS2GetStyle( long lFlags
268 ,WXDWORD
* pdwExstyle
= NULL
271 // get the MSW window flags corresponding to wxWindows ones
273 // the functions returns the flags (WS_XXX) directly and puts the ext
274 // (WS_EX_XXX) flags into the provided pointer if not NULL
275 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
276 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
279 // get the HWND to be used as parent of this window with CreateWindow()
280 virtual WXHWND
OS2GetParent(void) const;
282 // returns TRUE if the window has been created
283 bool OS2Create( PSZ zClass
292 virtual bool OS2Command( WXUINT uParam
296 #if WXWIN_COMPATIBILITY
297 wxObject
* GetChild(int nNumber
) const;
298 virtual void OS2DeviceToLogical( float* pfX
301 #endif // WXWIN_COMPATIBILITY
303 #ifndef __WXUNIVERSAL__
304 // Create an appropriate wxWindow from a HWND
305 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
309 // Make sure the window style reflects the HWND style (roughly)
310 virtual void AdoptAttributesFromHWND(void);
313 // Setup background and foreground colours correctly
314 virtual void SetupColours(void);
316 // ------------------------------------------------------------------------
317 // helpers for message handlers: these perform the same function as the
318 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
319 // the correct parameters
320 // ------------------------------------------------------------------------
322 void UnpackCommand( WXWPARAM wParam
328 void UnpackActivate( WXWPARAM wParam
333 void UnpackScroll( WXWPARAM wParam
339 void UnpackMenuSelect( WXWPARAM wParam
346 // ------------------------------------------------------------------------
347 // internal handlers for OS2 messages: all handlers return a boolen value:
348 // TRUE means that the handler processed the event and FALSE that it didn't
349 // ------------------------------------------------------------------------
351 // there are several cases where we have virtual functions for PM
352 // message processing: this is because these messages often require to be
353 // processed in a different manner in the derived classes. For all other
354 // messages, however, we do *not* have corresponding OS2OnXXX() function
355 // and if the derived class wants to process them, it should override
356 // OS2WindowProc() directly.
358 // scroll event (both horizontal and vertical)
359 virtual bool OS2OnScroll( int nOrientation
365 // owner-drawn controls need to process these messages
366 virtual bool OS2OnDrawItem( int nId
367 ,WXDRAWITEMSTRUCT
* pItem
369 virtual long OS2OnMeasureItem( int nId
370 ,WXMEASUREITEMSTRUCT
* pItem
373 virtual void OnPaint(wxPaintEvent
& rEvent
);
375 // the rest are not virtual
376 bool HandleCreate( WXLPCREATESTRUCT vCs
379 bool HandleInitDialog(WXHWND hWndFocus
);
380 bool HandleDestroy(void);
381 bool HandlePaint(void);
382 bool HandleEraseBkgnd(WXHDC vDC
);
383 bool HandleMinimize(void);
384 bool HandleMaximize(void);
385 bool HandleSize( int nX
389 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
390 bool HandleShow( bool bShow
393 bool HandleActivate( int nFlag
396 bool HandleCommand( WXWORD nId
400 bool HandleSysCommand( WXWPARAM wParam
403 bool HandlePaletteChanged(void);
404 bool HandleQueryNewPalette(void);
405 bool HandleSysColorChange(void);
406 bool HandleDisplayChange(void);
407 bool HandleCaptureChanged(WXHWND hBainedCapture
);
409 bool HandleCtlColor(WXHBRUSH
* hBrush
);
410 bool HandleSetFocus(WXHWND hWnd
);
411 bool HandleKillFocus(WXHWND hWnd
);
412 bool HandleEndDrag(WXWPARAM wParam
);
413 bool HandleMouseEvent( WXUINT uMsg
418 bool HandleMouseMove( int nX
422 bool HandleChar( WXWPARAM wParam
424 ,bool bIsASCII
= FALSE
426 bool HandleKeyDown( WXWPARAM wParam
429 bool HandleKeyUp( WXWPARAM wParam
432 bool HandleQueryDragIcon(WXHICON
* phIcon
);
433 bool HandleSetCursor( USHORT vId
437 bool IsMouseInWindow(void) const;
438 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
447 virtual MRESULT
OS2WindowProc( WXUINT uMsg
452 // Calls an appropriate default window procedure
453 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
457 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
458 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
459 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
460 virtual void OS2DestroyWindow(void);
462 // this function should return the brush to paint the window background
463 // with or 0 for the default brush
464 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
472 #if WXWIN_COMPATIBILITY
473 void SetShowing(bool bShow
) { (void)Show(show
); }
474 bool IsUserEnabled(void) const { return IsEnabled(); }
475 #endif // WXWIN_COMPATIBILITY
477 // Responds to colour changes: passes event on to children.
478 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
480 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
481 void InitMouseEvent( wxMouseEvent
& rEvent
487 void MoveChildren(int nDiff
);
488 PSWP
GetSwp(void) {return &m_vWinSwp
;}
491 // PM can't create some MSW styles natively but can perform these after
492 // creation by sending messages
493 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
494 ,kVertCaption
= 0x0002
495 ,kHorzCaption
= 0x0004
497 // Some internal sizeing id's to make it easy for event handlers
498 typedef enum size_types
{ kSizeNormal
505 // the old window proc (we subclass all windows)
506 WXFARPROC m_fnOldWndProc
;
508 // additional (OS2 specific) flags
509 bool m_bUseCtl3D
:1; // Using CTL3D for this control
510 bool m_bBackgroundTransparent
:1;
511 bool m_bMouseInWindow
:1;
512 bool m_bLastKeydownProcessed
:1;
513 bool m_bWinCaptured
:1;
516 // the size of one page for scrolling
520 #if wxUSE_MOUSEEVENT_HACK
521 // the coordinates of the last mouse event and the type of it
524 int m_nLastMouseEvent
;
525 #endif // wxUSE_MOUSEEVENT_HACK
527 WXHMENU m_hMenu
; // Menu, if any
528 unsigned long m_ulMenubarId
; // it's Id, if any
530 // the return value of WM_GETDLGCODE handler
533 // implement the base class pure virtuals
534 virtual void DoClientToScreen( int* pX
537 virtual void DoScreenToClient( int* pX
540 virtual void DoGetPosition( int* pX
543 virtual void DoGetSize( int* pWidth
546 virtual void DoGetClientSize( int* pWidth
549 virtual void DoSetSize( int nX
553 ,int nSizeFlags
= wxSIZE_AUTO
555 virtual void DoSetClientSize( int nWidth
559 virtual void DoCaptureMouse(void);
560 virtual void DoReleaseMouse(void);
562 // move the window to the specified location and resize it: this is called
563 // from both DoSetSize() and DoSetClientSize() and would usually just call
564 // ::WinSetWindowPos() except for composite controls which will want to arrange
565 // themselves inside the given rectangle
566 virtual void DoMoveWindow( int nX
573 virtual void DoSetToolTip(wxToolTip
* pTip
);
574 #endif // wxUSE_TOOLTIPS
576 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
579 // common part of all ctors
582 // the (non-virtual) handlers for the events
583 bool HandleMove( int nX
586 bool HandleJoystickEvent( WXUINT uMsg
592 bool HandleNotify( int nIdCtrl
596 // the helper functions used by HandleChar/KeyXXX methods
597 wxKeyEvent
CreateKeyEvent( wxEventType evType
603 wxWindowList
* m_pChildrenDisabled
;
604 HWND m_hWndScrollBarHorz
;
605 HWND m_hWndScrollBarVert
;
608 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
609 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
610 DECLARE_EVENT_TABLE()
613 // Virtual function hiding supression
615 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
616 { return(wxWindowBase::Reparent(pNewParent
));}
617 }; // end of wxWindow
619 class wxWindowCreationHook
622 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
623 ~wxWindowCreationHook();
624 }; // end of CLASS wxWindowCreationHook
626 // ---------------------------------------------------------------------------
628 // ---------------------------------------------------------------------------
630 // kbd code translation
631 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
632 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId