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 Refresh( bool bEraseBackground
= TRUE
103 ,const wxRect
* pRect
= (const wxRect
*)NULL
105 virtual void Clear(void);
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
);
229 // For implementation purposes - sometimes decorations make the client area
231 virtual wxPoint
GetClientAreaOrigin(void) const;
233 // Windows subclassing
234 void SubclassWin(WXHWND hWnd
);
235 void UnsubclassWin(void);
237 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
238 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
240 wxWindow
* FindItem(long lId
) const;
241 wxWindow
* FindItemByHWND( WXHWND hWnd
242 ,bool bControlOnly
= FALSE
245 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
246 static WXDWORD
MakeExtendedStyle( long lStyle
247 ,bool bEliminateBorders
= TRUE
249 // Determine whether 3D effects are wanted
250 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
254 // PM only: TRUE if this control is part of the main control
255 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
257 // translate wxWindows style flags for this control into the PM style
258 // and optional extended style for the corresponding native control
260 // this is the function that should be overridden in the derived classes,
261 // but you will mostly use OS2GetCreateWindowFlags() below
262 virtual WXDWORD
OS2GetStyle( long lFlags
263 ,WXDWORD
* pdwExstyle
= NULL
266 // get the MSW window flags corresponding to wxWindows ones
268 // the functions returns the flags (WS_XXX) directly and puts the ext
269 // (WS_EX_XXX) flags into the provided pointer if not NULL
270 WXDWORD
OS2GetCreateWindowFlags(WXDWORD
* pdwExflags
= NULL
) const
271 { return OS2GetStyle(GetWindowStyle(), pdwExflags
); }
274 // returns TRUE if the window has been created
275 bool OS2Create( PSZ zClass
284 virtual bool OS2Command( WXUINT uParam
288 #if WXWIN_COMPATIBILITY
289 wxObject
* GetChild(int nNumber
) const;
290 virtual void OS2DeviceToLogical( float* pfX
293 #endif // WXWIN_COMPATIBILITY
295 #ifndef __WXUNIVERSAL__
296 // Create an appropriate wxWindow from a HWND
297 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
301 // Make sure the window style reflects the HWND style (roughly)
302 virtual void AdoptAttributesFromHWND(void);
305 // Setup background and foreground colours correctly
306 virtual void SetupColours(void);
308 // ------------------------------------------------------------------------
309 // helpers for message handlers: these perform the same function as the
310 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
311 // the correct parameters
312 // ------------------------------------------------------------------------
314 void UnpackCommand( WXWPARAM wParam
320 void UnpackActivate( WXWPARAM wParam
325 void UnpackScroll( WXWPARAM wParam
331 void UnpackMenuSelect( WXWPARAM wParam
338 // ------------------------------------------------------------------------
339 // internal handlers for OS2 messages: all handlers return a boolen value:
340 // TRUE means that the handler processed the event and FALSE that it didn't
341 // ------------------------------------------------------------------------
343 // there are several cases where we have virtual functions for PM
344 // message processing: this is because these messages often require to be
345 // processed in a different manner in the derived classes. For all other
346 // messages, however, we do *not* have corresponding OS2OnXXX() function
347 // and if the derived class wants to process them, it should override
348 // OS2WindowProc() directly.
350 // scroll event (both horizontal and vertical)
351 virtual bool OS2OnScroll( int nOrientation
357 // owner-drawn controls need to process these messages
358 virtual bool OS2OnDrawItem( int nId
359 ,WXDRAWITEMSTRUCT
* pItem
361 virtual bool OS2OnMeasureItem( int nId
362 ,WXMEASUREITEMSTRUCT
* pItem
365 // the rest are not virtual
366 bool HandleCreate( WXLPCREATESTRUCT vCs
369 bool HandleInitDialog(WXHWND hWndFocus
);
370 bool HandleDestroy(void);
371 bool HandlePaint(void);
372 bool HandleEraseBkgnd(WXHDC vDC
);
373 bool HandleMinimize(void);
374 bool HandleMaximize(void);
375 bool HandleSize( int nX
379 bool HandleGetMinMaxInfo(PSWP pMmInfo
);
380 bool HandleShow( bool bShow
383 bool HandleActivate( int nFlag
386 bool HandleCommand( WXWORD nId
390 bool HandleSysCommand( WXWPARAM wParam
393 bool HandlePaletteChanged();
394 bool HandleSysColorChange(void);
395 bool HandleCtlColor(WXHBRUSH
* hBrush
);
396 bool HandleSetFocus(WXHWND hWnd
);
397 bool HandleKillFocus(WXHWND hWnd
);
398 bool HandleEndDrag(WXWPARAM wParam
);
399 bool HandleMouseEvent( WXUINT uMsg
404 bool HandleMouseMove( int nX
408 bool HandleChar( WXDWORD wParam
410 ,bool bIsASCII
= FALSE
412 bool HandleKeyDown( WXWORD wParam
415 bool HandleKeyUp( WXDWORD wParam
418 bool HandleQueryDragIcon(WXHICON
* phIcon
);
419 bool HandleSetCursor( USHORT vId
423 bool IsMouseInWindow(void) const;
424 bool OS2GetCreateWindowCoords( const wxPoint
& rPos
433 virtual MRESULT
OS2WindowProc( WXUINT uMsg
438 // Calls an appropriate default window procedure
439 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
443 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
444 virtual bool OS2ShouldPreProcessMessage(WXMSG
* pMsg
);
445 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
446 virtual void OS2DestroyWindow(void);
448 // this function should return the brush to paint the window background
449 // with or 0 for the default brush
450 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
458 #if WXWIN_COMPATIBILITY
459 void SetShowing(bool bShow
) { (void)Show(show
); }
460 bool IsUserEnabled(void) const { return IsEnabled(); }
461 #endif // WXWIN_COMPATIBILITY
463 // Responds to colour changes: passes event on to children.
464 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
466 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
467 void InitMouseEvent( wxMouseEvent
& rEvent
473 void MoveChildren(int nDiff
);
474 PSWP
GetSwp(void) {return &m_vWinSwp
;}
477 // PM can't create some MSW styles natively but can perform these after
478 // creation by sending messages
479 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
480 ,kVertCaption
= 0x0002
481 ,kHorzCaption
= 0x0004
483 // Some internal sizeing id's to make it easy for event handlers
484 typedef enum size_types
{ kSizeNormal
491 // the old window proc (we subclass all windows)
492 WXFARPROC m_fnOldWndProc
;
494 // additional (OS2 specific) flags
495 bool m_bUseCtl3D
:1; // Using CTL3D for this control
496 bool m_bBackgroundTransparent
:1;
497 bool m_bMouseInWindow
:1;
498 bool m_bDoubleClickAllowed
:1;
499 bool m_bWinCaptured
:1;
502 // the size of one page for scrolling
506 #if wxUSE_MOUSEEVENT_HACK
507 // the coordinates of the last mouse event and the type of it
510 int m_nLastMouseEvent
;
511 #endif // wxUSE_MOUSEEVENT_HACK
513 WXHMENU m_hMenu
; // Menu, if any
514 unsigned long m_ulMenubarId
; // it's Id, if any
516 // the return value of WM_GETDLGCODE handler
519 // implement the base class pure virtuals
520 virtual void DoClientToScreen( int* pX
523 virtual void DoScreenToClient( int* pX
526 virtual void DoGetPosition( int* pX
529 virtual void DoGetSize( int* pWidth
532 virtual void DoGetClientSize( int* pWidth
535 virtual void DoSetSize( int nX
539 ,int nSizeFlags
= wxSIZE_AUTO
541 virtual void DoSetClientSize( int nWidth
545 virtual void DoCaptureMouse(void);
546 virtual void DoReleaseMouse(void);
548 // move the window to the specified location and resize it: this is called
549 // from both DoSetSize() and DoSetClientSize() and would usually just call
550 // ::WinSetWindowPos() except for composite controls which will want to arrange
551 // themselves inside the given rectangle
552 virtual void DoMoveWindow( int nX
559 virtual void DoSetToolTip(wxToolTip
* pTip
);
560 #endif // wxUSE_TOOLTIPS
562 int GetOS2ParentHeight(wxWindowOS2
* pParent
);
565 // common part of all ctors
568 // the (non-virtual) handlers for the events
569 bool HandleMove( int nX
572 bool HandleJoystickEvent( WXUINT uMsg
578 bool HandleNotify( int nIdCtrl
582 // the helper functions used by HandleChar/KeyXXX methods
583 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
586 DECLARE_DYNAMIC_CLASS(wxWindowOS2
);
587 DECLARE_NO_COPY_CLASS(wxWindowOS2
)
588 DECLARE_EVENT_TABLE()
591 HWND m_hWndScrollBarHorz
;
592 HWND m_hWndScrollBarVert
;
595 // Virtual function hiding supression
596 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
597 { return(wxWindowBase::Reparent(pNewParent
));};
598 }; // end of wxWindow
600 class wxWindowCreationHook
603 wxWindowCreationHook(wxWindow
* pWinBeingCreated
);
604 ~wxWindowCreationHook();
605 }; // end of CLASS wxWindowCreationHook
607 // ---------------------------------------------------------------------------
609 // ---------------------------------------------------------------------------
611 // kbd code translation
612 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
613 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId