1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindow class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "window.h"
19 // ---------------------------------------------------------------------------
20 // forward declarations
21 // ---------------------------------------------------------------------------
23 class WXDLLEXPORT wxButton
;
24 class WXDLLEXPORT wxScrollBar
;
26 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
30 // FIXME does anybody use those? they're unused by wxWindows...
37 class WXDLLEXPORT wxWindow
: public wxWindowBase
39 DECLARE_DYNAMIC_CLASS(wxWindow
);
42 friend class wxPaintDC
;
45 typedef struct MacWindowData
47 SInt16 m_macWindowBackgroundTheme
;
48 WindowRef m_macWindow
;
49 ControlHandle m_macRootControl
;
50 wxWindow
* m_macFocus
;
54 wxWindow() { Init(); }
56 wxWindow(wxWindow
*parent
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
61 const wxString
& name
= wxPanelNameStr
)
64 Create(parent
, id
, pos
, size
, style
, name
);
69 bool Create(wxWindow
*parent
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= wxPanelNameStr
);
77 // implement base class pure virtuals
78 virtual void SetTitle( const wxString
& title
);
79 virtual wxString
GetTitle() const;
84 virtual bool Show( bool show
= TRUE
);
85 virtual bool Enable( bool enable
= TRUE
);
87 virtual void SetFocus();
89 virtual bool Reparent( wxWindow
*newParent
);
91 virtual void WarpPointer(int x
, int y
);
92 virtual void CaptureMouse();
93 virtual void ReleaseMouse();
95 virtual void Refresh( bool eraseBackground
= TRUE
,
96 const wxRect
*rect
= (const wxRect
*) NULL
);
99 virtual bool SetCursor( const wxCursor
&cursor
);
100 virtual bool SetFont( const wxFont
&font
);
102 virtual int GetCharHeight() const;
103 virtual int GetCharWidth() const;
104 virtual void GetTextExtent(const wxString
& string
,
106 int *descent
= (int *) NULL
,
107 int *externalLeading
= (int *) NULL
,
108 const wxFont
*theFont
= (const wxFont
*) NULL
)
111 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
113 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
114 int range
, bool refresh
= TRUE
);
115 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
116 virtual int GetScrollPos( int orient
) const;
117 virtual int GetScrollThumb( int orient
) const;
118 virtual int GetScrollRange( int orient
) const;
119 virtual void ScrollWindow( int dx
, int dy
,
120 const wxRect
* rect
= (wxRect
*) NULL
);
122 #if wxUSE_DRAG_AND_DROP
123 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
124 #endif // wxUSE_DRAG_AND_DROP
126 // Accept files for dragging
127 virtual void DragAcceptFiles(bool accept
);
129 #if WXWIN_COMPATIBILITY
130 // Set/get scroll attributes
131 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
132 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
133 virtual int OldGetScrollRange(int orient
) const;
134 virtual int GetScrollPage(int orient
) const;
137 // Handle a control command
138 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
140 // Override to define new behaviour for default action (e.g. double
141 // clicking on a listbox)
142 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
143 #endif // WXWIN_COMPATIBILITY
145 #if wxUSE_CARET && WXWIN_COMPATIBILITY
146 // caret manipulation (old MSW only functions, see wxCaret class for the
148 void CreateCaret(int w
, int h
);
149 void CreateCaret(const wxBitmap
*bitmap
);
151 void ShowCaret(bool show
);
152 void SetCaretPos(int x
, int y
);
153 void GetCaretPos(int *x
, int *y
) const;
154 #endif // wxUSE_CARET
156 // Native resource loading (implemented in src/msw/nativdlg.cpp)
157 // FIXME: should they really be all virtual?
158 wxWindow
* GetWindowChild1(wxWindowID id
);
159 wxWindow
* GetWindowChild(wxWindowID id
);
161 // implementation from now on
162 // --------------------------
164 void MacClientToRootWindow( int *x
, int *y
) const ;
165 void MacRootWindowToClient( int *x
, int *y
) const ;
171 // WXHWND GetHWND() const { return m_hWnd; }
172 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
173 virtual WXWidget
GetHandle() const { return (WXWidget
) NULL
; }
175 bool GetUseCtl3D() const { return m_useCtl3D
; }
176 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
177 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
181 void OnEraseBackground(wxEraseEvent
& event
);
182 void OnIdle(wxIdleEvent
& event
);
183 void MacOnScroll(wxScrollEvent
&event
) ;
186 // For implementation purposes - sometimes decorations make the client area
188 virtual wxPoint
GetClientAreaOrigin() const;
190 // Makes an adjustment to the window position (for example, a frame that has
191 // a toolbar that it manages itself).
192 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
194 wxWindow
*FindItem(long id
) const;
195 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
197 // Make a Windows extended style from the given wxWindows window style
198 static WXDWORD
MakeExtendedStyle(long style
,
199 bool eliminateBorders
= TRUE
);
200 // Determine whether 3D effects are wanted
201 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
203 // MSW only: TRUE if this control is part of the main control
204 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
206 #if WXWIN_COMPATIBILITY
207 wxObject
*GetChild(int number
) const;
208 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
209 #endif // WXWIN_COMPATIBILITY
211 // Setup background and foreground colours correctly
212 virtual void SetupColours();
215 #if WXWIN_COMPATIBILITY
216 void SetShowing(bool show
) { (void)Show(show
); }
217 bool IsUserEnabled() const { return IsEnabled(); }
218 #endif // WXWIN_COMPATIBILITY
220 // Responds to colour changes: passes event on to children.
221 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
224 static bool MacGetWindowFromPoint( const wxPoint
&point
, wxWindow
** outWin
) ;
225 virtual void MacActivate( EventRecord
*ev
, bool inIsActivating
) ;
226 virtual void MacUpdate( EventRecord
*ev
) ;
227 virtual void MacUpdateImmediately() ;
228 virtual void MacRedraw( RgnHandle updatergn
, long time
) ;
229 virtual void MacMouseDown( EventRecord
*ev
, short windowPart
) ;
230 virtual void MacMouseUp( EventRecord
*ev
, short windowPart
) ;
231 virtual void MacMouseMoved( EventRecord
*ev
, short windowPart
) ;
232 virtual void MacKeyDown( EventRecord
*ev
) ;
233 virtual bool MacCanFocus() const { return true ; }
235 virtual void MacFireMouseEvent( EventRecord
*ev
) ;
236 virtual bool MacDispatchMouseEvent(wxMouseEvent
& event
) ;
237 virtual void MacEraseBackground( Rect
*rect
) ;
238 WindowRef
GetMacRootWindow() const ;
240 virtual ControlHandle
MacGetContainerForEmbedding() ;
241 virtual void MacSuperChangedPosition() ;
243 bool MacSetupFocusPort() ;
244 bool MacSetupDrawingPort() ;
245 bool MacSetupFocusClientPort() ;
246 bool MacSetupDrawingClientPort() ;
248 virtual bool MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
249 virtual bool MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
251 virtual void MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
252 virtual void MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
253 MacWindowData
* MacGetWindowData() { return m_macWindowData
; }
254 static WindowRef
MacGetWindowInUpdate() { return s_macWindowInUpdate
; }
255 bool MacIsWindowScrollbar( const wxScrollBar
* sb
) { return (m_hScrollBar
== sb
|| m_vScrollBar
== sb
) ; }
256 static wxWindow
* s_lastMouseWindow
;
258 virtual bool MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
) ;
261 MacWindowData
* m_macWindowData
;
262 static WindowRef s_macWindowInUpdate
;
269 wxScrollBar
* m_hScrollBar
;
270 wxScrollBar
* m_vScrollBar
;
273 void MacCreateScrollBars( long style
) ;
274 void MacRepositionScrollBars() ;
276 // additional (MSW specific) flags
277 bool m_useCtl3D
:1; // Using CTL3D for this control
278 bool m_backgroundTransparent
:1;
279 bool m_mouseInWindow
:1;
280 bool m_doubleClickAllowed
:1;
281 bool m_winCaptured
:1;
283 // the size of one page for scrolling
287 // WXHMENU m_hMenu; // Menu, if any
289 // implement the base class pure virtuals
290 virtual void DoClientToScreen( int *x
, int *y
) const;
291 virtual void DoScreenToClient( int *x
, int *y
) const;
292 virtual void DoGetPosition( int *x
, int *y
) const;
293 virtual void DoGetSize( int *width
, int *height
) const;
294 virtual void DoGetClientSize( int *width
, int *height
) const;
295 virtual void DoSetSize(int x
, int y
,
296 int width
, int height
,
297 int sizeFlags
= wxSIZE_AUTO
);
298 virtual void DoSetClientSize(int width
, int height
);
300 // get the size which best suits the window: e.g., for a static text it
301 // will be the width and height of the text
302 virtual wxSize
DoGetBestSize();
304 // move the window to the specified location and resize it: this is called
305 // from both DoSetSize() and DoSetClientSize() and would usually just call
306 // ::MoveWindow() except for composite controls which will want to arrange
307 // themselves inside the given rectangle
308 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
311 virtual void DoSetToolTip( wxToolTip
*tip
);
312 #endif // wxUSE_TOOLTIPS
315 // common part of all ctors
318 DECLARE_NO_COPY_CLASS(wxWindow
);
319 DECLARE_EVENT_TABLE()
322 // associate mac windows with wx counterparts
324 wxWindow
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
325 void wxAssociateWinWithMacWindow(WindowRef inWindow
, wxWindow
*win
) ;
326 void wxRemoveMacWindowAssociation(wxWindow
*win
) ;
328 class wxMacFocusHelper
331 wxMacFocusHelper( wxWindow
* theWindow
) ;
332 ~wxMacFocusHelper() ;
333 bool Ok() { return m_ok
; }
336 GrafPtr m_formerPort
;
337 GrafPtr m_currentPort
;
341 class wxMacDrawingHelper
344 wxMacDrawingHelper( wxWindow
* theWindow
) ;
345 ~wxMacDrawingHelper() ;
346 bool Ok() { return m_ok
; }
349 GrafPtr m_formerPort
;
350 GrafPtr m_currentPort
;
351 PenState m_savedPenState
;
355 class wxMacFocusClientHelper
358 wxMacFocusClientHelper( wxWindow
* theWindow
) ;
359 ~wxMacFocusClientHelper() ;
360 bool Ok() { return m_ok
; }
363 GrafPtr m_formerPort
;
364 GrafPtr m_currentPort
;
368 class wxMacDrawingClientHelper
371 wxMacDrawingClientHelper( wxWindow
* theWindow
) ;
372 ~wxMacDrawingClientHelper() ;
373 bool Ok() { return m_ok
; }
376 GrafPtr m_formerPort
;
377 GrafPtr m_currentPort
;
378 PenState m_savedPenState
;