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 class WXDLLEXPORT wxButton
;
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 // FIXME does anybody use those? they're unused by wxWindows...
43 // ---------------------------------------------------------------------------
44 // wxWindow declaration for OS/2 PM
45 // ---------------------------------------------------------------------------
47 class WXDLLEXPORT wxWindow
: public wxWindowBase
50 wxWindow() { Init(); }
52 wxWindow( wxWindow
* pParent
54 ,const wxPoint
& rPos
= wxDefaultPosition
55 ,const wxSize
& rSize
= wxDefaultSize
57 ,const wxString
& rName
= wxPanelNameStr
72 bool Create( wxWindow
* pParent
74 ,const wxPoint
& rPos
= wxDefaultPosition
75 ,const wxSize
& rSize
= wxDefaultSize
77 ,const wxString
& rName
= wxPanelNameStr
80 // implement base class pure virtuals
81 virtual void SetTitle(const wxString
& rTitle
);
82 virtual wxString
GetTitle(void) const;
83 virtual void Raise(void);
84 virtual void Lower(void);
85 virtual bool Show(bool bShow
= TRUE
);
86 virtual bool Enable(bool bEnable
= TRUE
);
87 virtual void SetFocus(void);
88 virtual bool Reparent(wxWindow
* pNewParent
);
89 virtual void WarpPointer( int x
92 virtual void CaptureMouse(void);
93 virtual void ReleaseMouse(void);
94 virtual void Refresh( bool bEraseBackground
= TRUE
95 ,const wxRect
* pRect
= (const wxRect
*)NULL
97 virtual void Clear(void);
98 virtual bool SetCursor(const wxCursor
& rCursor
);
99 virtual bool SetFont(const wxFont
& rFont
);
100 virtual int GetCharHeight(void) const;
101 virtual int GetCharWidth(void) const;
102 virtual void GetTextExtent( const wxString
& rString
105 ,int* pDescent
= (int *)NULL
106 ,int* pExternalLeading
= (int *)NULL
107 ,const wxFont
* pTheFont
= (const wxFont
*)NULL
109 virtual bool DoPopupMenu( wxMenu
* pMenu
114 virtual void SetScrollbar( int nOrient
118 ,bool bRefresh
= TRUE
120 virtual void SetScrollPos( int nOrient
122 ,bool bRefresh
= TRUE
124 virtual int GetScrollPos(int nOrient
) const;
125 virtual int GetScrollThumb(int nOrient
) const;
126 virtual int GetScrollRange(int nOrient
) const;
127 virtual void ScrollWindow( int nDx
129 ,const wxRect
* pRect
= (wxRect
*)NULL
132 #if wxUSE_DRAG_AND_DROP
133 virtual void SetDropTarget(wxDropTarget
* pDropTarget
);
134 #endif // wxUSE_DRAG_AND_DROP
136 // Accept files for dragging
137 virtual void DragAcceptFiles(bool bAccept
);
139 #if WXWIN_COMPATIBILITY
140 // Set/get scroll attributes
141 virtual void SetScrollRange( int nOrient
143 ,bool bRefresh
= TRUE
145 virtual void SetScrollPage( int nOrient
147 ,bool bRefresh
= TRUE
149 virtual int OldGetScrollRange(int nOrient
) const;
150 virtual int GetScrollPage(int nOrient
) const;
155 // Handle a control command
156 virtual void OnCommand( wxWindow
& rWin
157 ,wxCommandEvent
& rEvent
160 // Override to define new behaviour for default action (e.g. double
161 // clicking on a listbox)
162 virtual void OnDefaultAction(wxControl
* WXUNUSED(pInitiatingItem
)) { }
163 #endif // WXWIN_COMPATIBILITY
165 #if wxUSE_CARET && WXWIN_COMPATIBILITY
166 void CreateCaret( int nWidth
169 void CreateCaret(const wxBitmap
* pBitmap
);
170 void DestroyCaret(void);
171 void ShowCaret(bool bShow
);
172 void SetCaretPos( int nX
175 void GetCaretPos( int* pX
178 #endif // wxUSE_CARET
180 // Native resource loading (implemented in src/os2/nativdlg.cpp)
181 // FIXME: should they really be all virtual?
182 virtual bool LoadNativeDialog( wxWindow
* pParent
185 virtual bool LoadNativeDialog( wxWindow
* pParent
186 ,const wxString
& rName
188 wxWindow
* GetWindowChild1(wxWindowID vId
);
189 wxWindow
* GetWindowChild(wxWindowID vId
);
191 // implementation from now on
192 // --------------------------
197 WXHWND
GetHWND(void) const { return m_hWnd
; }
198 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
199 virtual WXWidget
GetHandle(void) const { return GetHWND(); }
200 bool GetUseCtl3D(void) const { return m_bUseCtl3D
; }
201 bool GetTransparentBackground(void) const { return m_bBackgroundTransparent
; }
202 void SetTransparent(bool bT
= TRUE
) { m_bBackgroundTransparent
= bT
; }
206 void OnSetFocus(wxFocusEvent
& rEvent
);
207 void OnEraseBackground(wxEraseEvent
& rEvent
);
208 void OnIdle(wxIdleEvent
& rEvent
);
211 // For implementation purposes - sometimes decorations make the client area
213 virtual wxPoint
GetClientAreaOrigin(void) const;
215 // Makes an adjustment to the window position (for example, a frame that has
216 // a toolbar that it manages itself).
217 virtual void AdjustForParentClientOrigin( int& rX
222 // Windows subclassing
223 void SubclassWin(WXHWND hWnd
);
224 void UnsubclassWin(void);
226 WXFARPROC
OS2GetOldWndProc(void) const { return m_fnOldWndProc
; }
227 void OS2SetOldWndProc(WXFARPROC fnProc
) { m_fnOldWndProc
= fnProc
; }
229 wxWindow
* FindItem(long lId
) const;
230 wxWindow
* FindItemByHWND( WXHWND hWnd
231 ,bool bControlOnly
= FALSE
234 // Make a Windows extended style from the given wxWindows window style ?? applicable to OS/2??
235 static WXDWORD
MakeExtendedStyle( long lStyle
236 ,bool bEliminateBorders
= TRUE
238 // Determine whether 3D effects are wanted
239 WXDWORD
Determine3DEffects( WXDWORD dwDefaultBorderStyle
243 // PM only: TRUE if this control is part of the main control
244 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
246 // returns TRUE if the window has been created
247 bool OS2Create( int nId
249 ,const wxChar
* zWclass
251 ,const wxChar
* zTitle
257 ,const wxChar
* zDialogTemplate
= NULL
258 ,WXDWORD dwExendedStyle
= 0
260 virtual bool OS2Command( WXUINT uParam
264 #if WXWIN_COMPATIBILITY
265 wxObject
* GetChild(int nNumber
) const;
266 virtual void OS2DeviceToLogical( float* pfX
269 #endif // WXWIN_COMPATIBILITY
271 // Create an appropriate wxWindow from a HWND
272 virtual wxWindow
* CreateWindowFromHWND( wxWindow
* pParent
276 // Make sure the window style reflects the HWND style (roughly)
277 virtual void AdoptAttributesFromHWND(void);
279 // Setup background and foreground colours correctly
280 virtual void SetupColours(void);
282 // ------------------------------------------------------------------------
283 // helpers for message handlers: these perform the same function as the
284 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
285 // the correct parameters
286 // ------------------------------------------------------------------------
288 void UnpackCommand( WXWPARAM wParam
294 void UnpackActivate( WXWPARAM wParam
300 void UnpackScroll( WXWPARAM wParam
306 void UnpackCtlColor( WXWPARAM wParam
312 void UnpackMenuSelect( WXWPARAM wParam
319 // ------------------------------------------------------------------------
320 // internal handlers for OS2 messages: all handlers return a boolen value:
321 // TRUE means that the handler processed the event and FALSE that it didn't
322 // ------------------------------------------------------------------------
324 // there are several cases where we have virtual functions for PM
325 // message processing: this is because these messages often require to be
326 // processed in a different manner in the derived classes. For all other
327 // messages, however, we do *not* have corresponding OS2OnXXX() function
328 // and if the derived class wants to process them, it should override
329 // OS2WindowProc() directly.
331 // scroll event (both horizontal and vertical)
332 virtual bool OS2OnScroll( int nOrientation
338 virtual bool OS2OnNotify( int nIdCtrl
343 // owner-drawn controls need to process these messages
344 virtual bool OS2OnDrawItem( int nId
345 ,WXDRAWITEMSTRUCT
* pItem
347 virtual bool OS2OnMeasureItem( int nId
348 ,WXMEASUREITEMSTRUCT
* pItem
351 // the rest are not virtual
352 bool HandleCreate( WXLPCREATESTRUCT vCs
355 bool HandleInitDialog(WXHWND hWndFocus
);
356 bool HandleDestroy(void);
357 bool HandlePaint(void);
358 bool HandleEraseBkgnd(WXHDC vDC
);
359 bool HandleMinimize(void);
360 bool HandleMaximize(void);
361 bool HandleSize( int nX
365 bool HandleGetMinMaxInfo(void* pMmInfo
);
366 bool HandleShow( bool bShow
369 bool HandleActivate( int nFlag
373 bool HandleCommand( WXWORD nId
377 bool HandleSysCommand( WXWPARAM wParam
380 bool HandleCtlColor( WXHBRUSH
* phBrush
388 bool HandlePaletteChanged(WXHWND hWndPalChange
);
389 bool HandleQueryNewPalette(void);
390 bool HandleSysColorChange(void);
391 bool HandleQueryEndSession( long lLogOff
394 bool HandleEndSession( bool bEndSession
397 bool HandleSetFocus(WXHWND hWnd
);
398 bool HandleKillFocus(WXHWND hWnd
);
399 bool HandleDropFiles(WXWPARAM wParam
);
400 bool HandleMouseEvent( WXUINT uMsg
405 bool HandleMouseMove( int nX
409 bool HandleChar( WXWORD wParam
411 ,bool bIsASCII
= FALSE
413 bool HandleKeyDown( WXWORD wParam
416 bool HandleKeyUp( WXWORD wParam
419 bool HandleQueryDragIcon(WXHICON
* phIcon
);
420 bool HandleSetCursor( WXHWND hWnd
426 virtual MRESULT
OS2WindowProc( WXUINT uMsg
431 // Calls an appropriate default window procedure
432 virtual MRESULT
OS2DefWindowProc( WXUINT uMsg
436 virtual bool OS2ProcessMessage(WXMSG
* pMsg
);
437 virtual bool OS2TranslateMessage(WXMSG
* pMsg
);
438 virtual void OS2DestroyWindow(void);
440 // Detach "Window" menu from menu bar so it doesn't get deleted
441 void OS2DetachWindowMenu(void);
443 // this function should return the brush to paint the window background
444 // with or 0 for the default brush
445 virtual WXHBRUSH
OnCtlColor( WXHDC hDC
453 #if WXWIN_COMPATIBILITY
454 void SetShowing(bool bShow
) { (void)Show(show
); }
455 bool IsUserEnabled(void) const { return IsEnabled(); }
456 #endif // WXWIN_COMPATIBILITY
458 // Responds to colour changes: passes event on to children.
459 void OnSysColourChanged(wxSysColourChangedEvent
& rEvent
);
461 // initialize various fields of wxMouseEvent (common part of OS2OnMouseXXX)
462 void InitMouseEvent( wxMouseEvent
& rEvent
469 // PM can't create some MSW styles natively but can perform these after
470 // creation by sending messages
471 typedef enum extra_flags
{ kFrameToolWindow
= 0x0001
472 ,kVertCaption
= 0x0002
473 ,kHorzCaption
= 0x0004
475 // Some internal sizeing id's to make it easy for event handlers
476 typedef enum size_types
{ kSizeNormal
483 // the old window proc (we subclass all windows)
484 WXFARPROC m_fnOldWndProc
;
486 // additional (MSW specific) flags
487 bool m_bUseCtl3D
:1; // Using CTL3D for this control
488 bool m_bBackgroundTransparent
:1;
489 bool m_bMouseInWindow
:1;
490 bool m_bDoubleClickAllowed
:1;
491 bool m_bWinCaptured
:1;
493 // the size of one page for scrolling
497 #if wxUSE_MOUSEEVENT_HACK
498 // the coordinates of the last mouse event and the type of it
501 int m_nLastMouseEvent
;
502 #endif // wxUSE_MOUSEEVENT_HACK
504 WXHMENU m_hMenu
; // Menu, if any
505 unsigned long m_ulMenubarId
; // it's Id, if any
507 // the return value of WM_GETDLGCODE handler
510 // implement the base class pure virtuals
511 virtual void DoClientToScreen( int* pX
514 virtual void DoScreenToClient( int* pX
517 virtual void DoGetPosition( int* pX
520 virtual void DoGetSize( int* pWidth
523 virtual void DoGetClientSize( int* pWidth
526 virtual void DoSetSize( int nX
530 ,int nSizeFlags
= wxSIZE_AUTO
532 virtual void DoSetClientSize( int nWidth
536 // move the window to the specified location and resize it: this is called
537 // from both DoSetSize() and DoSetClientSize() and would usually just call
538 // ::MoveWindow() except for composite controls which will want to arrange
539 // themselves inside the given rectangle
540 virtual void DoMoveWindow( int nX
547 virtual void DoSetToolTip(wxToolTip
* pTip
);
548 #endif // wxUSE_TOOLTIPS
551 // common part of all ctors
554 // the (non-virtual) handlers for the events
555 bool HandleMove( int nX
558 bool HandleJoystickEvent( WXUINT uMsg
564 bool HandleNotify( int nIdCtrl
568 // the helper functions used by HandleChar/KeyXXX methods
569 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
571 DECLARE_DYNAMIC_CLASS(wxWindow
);
572 DECLARE_NO_COPY_CLASS(wxWindow
);
573 DECLARE_EVENT_TABLE()
575 // Virtual function hiding supression
576 inline virtual bool Reparent(wxWindowBase
* pNewParent
)
577 { return(wxWindowBase::Reparent(pNewParent
));};
578 }; // end of wxWindow
580 // ---------------------------------------------------------------------------
582 // ---------------------------------------------------------------------------
584 // kbd code translation
585 WXDLLEXPORT
int wxCharCodeOS2ToWX(int nKeySym
);
586 WXDLLEXPORT
int wxCharCodeWXToOS2( int nId