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 void WarpPointer(int x
, int y
);
90 virtual void CaptureMouse();
91 virtual void ReleaseMouse();
93 virtual void Refresh( bool eraseBackground
= TRUE
,
94 const wxRect
*rect
= (const wxRect
*) NULL
);
97 virtual bool SetCursor( const wxCursor
&cursor
);
98 virtual bool SetFont( const wxFont
&font
);
100 virtual int GetCharHeight() const;
101 virtual int GetCharWidth() const;
102 virtual void GetTextExtent(const wxString
& string
,
104 int *descent
= (int *) NULL
,
105 int *externalLeading
= (int *) NULL
,
106 const wxFont
*theFont
= (const wxFont
*) NULL
)
109 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
111 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
112 int range
, bool refresh
= TRUE
);
113 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
114 virtual int GetScrollPos( int orient
) const;
115 virtual int GetScrollThumb( int orient
) const;
116 virtual int GetScrollRange( int orient
) const;
117 virtual void ScrollWindow( int dx
, int dy
,
118 const wxRect
* rect
= (wxRect
*) NULL
);
120 #if wxUSE_DRAG_AND_DROP
121 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
122 #endif // wxUSE_DRAG_AND_DROP
124 // Accept files for dragging
125 virtual void DragAcceptFiles(bool accept
);
127 #if WXWIN_COMPATIBILITY
128 // Set/get scroll attributes
129 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
130 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
131 virtual int OldGetScrollRange(int orient
) const;
132 virtual int GetScrollPage(int orient
) const;
135 // Handle a control command
136 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
138 // Override to define new behaviour for default action (e.g. double
139 // clicking on a listbox)
140 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
141 #endif // WXWIN_COMPATIBILITY
143 #if wxUSE_CARET && WXWIN_COMPATIBILITY
144 // caret manipulation (old MSW only functions, see wxCaret class for the
146 void CreateCaret(int w
, int h
);
147 void CreateCaret(const wxBitmap
*bitmap
);
149 void ShowCaret(bool show
);
150 void SetCaretPos(int x
, int y
);
151 void GetCaretPos(int *x
, int *y
) const;
152 #endif // wxUSE_CARET
154 // Native resource loading (implemented in src/msw/nativdlg.cpp)
155 // FIXME: should they really be all virtual?
156 wxWindow
* GetWindowChild1(wxWindowID id
);
157 wxWindow
* GetWindowChild(wxWindowID id
);
159 // implementation from now on
160 // --------------------------
162 void MacClientToRootWindow( int *x
, int *y
) const ;
163 void MacRootWindowToClient( int *x
, int *y
) const ;
165 virtual wxString
MacGetToolTipString( wxPoint
&where
) ;
170 // WXHWND GetHWND() const { return m_hWnd; }
171 // void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
172 virtual WXWidget
GetHandle() const { return (WXWidget
) NULL
; }
174 bool GetUseCtl3D() const { return m_useCtl3D
; }
175 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
176 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
180 void OnEraseBackground(wxEraseEvent
& event
);
181 void OnIdle(wxIdleEvent
& event
);
182 void MacOnScroll(wxScrollEvent
&event
) ;
184 bool AcceptsFocus() const ;
187 // For implementation purposes - sometimes decorations make the client area
189 virtual wxPoint
GetClientAreaOrigin() const;
191 // Makes an adjustment to the window position (for example, a frame that has
192 // a toolbar that it manages itself).
193 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
195 wxWindow
*FindItem(long id
) const;
196 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
198 // Make a Windows extended style from the given wxWindows window style
199 static WXDWORD
MakeExtendedStyle(long style
,
200 bool eliminateBorders
= TRUE
);
201 // Determine whether 3D effects are wanted
202 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
204 // MSW only: TRUE if this control is part of the main control
205 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
207 #if WXWIN_COMPATIBILITY
208 wxObject
*GetChild(int number
) const;
209 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
210 #endif // WXWIN_COMPATIBILITY
212 // Setup background and foreground colours correctly
213 virtual void SetupColours();
216 #if WXWIN_COMPATIBILITY
217 void SetShowing(bool show
) { (void)Show(show
); }
218 bool IsUserEnabled() const { return IsEnabled(); }
219 #endif // WXWIN_COMPATIBILITY
221 // Responds to colour changes: passes event on to children.
222 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
224 virtual void MacCreateRealWindow( const wxString
& title
,
228 const wxString
& name
) ;
229 static bool MacGetWindowFromPoint( const wxPoint
&point
, wxWindow
** outWin
) ;
230 virtual void MacActivate( EventRecord
*ev
, bool inIsActivating
) ;
231 virtual void MacUpdate( EventRecord
*ev
) ;
232 virtual void MacUpdateImmediately() ;
233 virtual void MacRedraw( RgnHandle updatergn
, long time
) ;
234 virtual void MacMouseDown( EventRecord
*ev
, short windowPart
) ;
235 virtual void MacMouseUp( EventRecord
*ev
, short windowPart
) ;
236 virtual void MacMouseMoved( EventRecord
*ev
, short windowPart
) ;
237 virtual void MacKeyDown( EventRecord
*ev
) ;
238 virtual bool MacCanFocus() const { return true ; }
240 virtual void MacFireMouseEvent( EventRecord
*ev
) ;
241 virtual bool MacDispatchMouseEvent(wxMouseEvent
& event
) ;
242 virtual void MacEraseBackground( Rect
*rect
) ;
243 virtual void MacPaintBorders() ;
244 // obsolete : only for link compatibility
245 virtual void MacPaint( wxPaintEvent
&event
) ;
246 WindowRef
GetMacRootWindow() const ;
248 virtual ControlHandle
MacGetContainerForEmbedding() ;
250 virtual long MacGetLeftBorderSize() const ;
251 virtual long MacGetRightBorderSize() const ;
252 virtual long MacGetTopBorderSize() const ;
253 virtual long MacGetBottomBorderSize() const ;
255 static long MacRemoveBordersFromStyle( long style
) ;
256 virtual void MacSuperChangedPosition() ;
257 virtual void MacSuperShown( bool show
) ;
258 bool MacIsReallyShown() const ;
260 bool MacSetupFocusPort() ;
261 bool MacSetupDrawingPort() ;
262 bool MacSetupFocusClientPort() ;
263 bool MacSetupDrawingClientPort() ;
265 virtual bool MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
266 virtual bool MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
268 virtual void MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
269 virtual void MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
270 virtual void MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
271 MacWindowData
* MacGetWindowData() { return m_macWindowData
; }
272 static WindowRef
MacGetWindowInUpdate() { return s_macWindowInUpdate
; }
273 bool MacIsWindowScrollbar( const wxScrollBar
* sb
) { return (m_hScrollBar
== sb
|| m_vScrollBar
== sb
) ; }
274 static wxWindow
* s_lastMouseWindow
;
276 virtual bool MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
) ;
279 MacWindowData
* m_macWindowData
;
280 static WindowRef s_macWindowInUpdate
;
281 RgnHandle m_macUpdateRgn
;
288 wxScrollBar
* m_hScrollBar
;
289 wxScrollBar
* m_vScrollBar
;
292 void MacCreateScrollBars( long style
) ;
293 void MacRepositionScrollBars() ;
295 // additional (MSW specific) flags
296 bool m_useCtl3D
:1; // Using CTL3D for this control
297 bool m_backgroundTransparent
:1;
298 bool m_mouseInWindow
:1;
299 bool m_doubleClickAllowed
:1;
300 bool m_winCaptured
:1;
302 // the size of one page for scrolling
306 // WXHMENU m_hMenu; // Menu, if any
308 // implement the base class pure virtuals
309 virtual void DoClientToScreen( int *x
, int *y
) const;
310 virtual void DoScreenToClient( int *x
, int *y
) const;
311 virtual void DoGetPosition( int *x
, int *y
) const;
312 virtual void DoGetSize( int *width
, int *height
) const;
313 virtual void DoGetClientSize( int *width
, int *height
) const;
314 virtual void DoSetSize(int x
, int y
,
315 int width
, int height
,
316 int sizeFlags
= wxSIZE_AUTO
);
317 virtual void DoSetClientSize(int width
, int height
);
319 // move the window to the specified location and resize it: this is called
320 // from both DoSetSize() and DoSetClientSize() and would usually just call
321 // ::MoveWindow() except for composite controls which will want to arrange
322 // themselves inside the given rectangle
323 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
326 virtual void DoSetToolTip( wxToolTip
*tip
);
327 #endif // wxUSE_TOOLTIPS
330 // common part of all ctors
333 DECLARE_NO_COPY_CLASS(wxWindow
);
334 DECLARE_EVENT_TABLE()
337 // associate mac windows with wx counterparts
339 wxWindow
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
340 void wxAssociateWinWithMacWindow(WindowRef inWindow
, wxWindow
*win
) ;
341 void wxRemoveMacWindowAssociation(wxWindow
*win
) ;
344 class wxMacFocusHelper
347 wxMacFocusHelper( wxWindow * theWindow ) ;
348 ~wxMacFocusHelper() ;
349 bool Ok() { return m_ok ; }
352 GrafPtr m_formerPort ;
353 GrafPtr m_currentPort ;
358 class wxMacDrawingHelper
361 wxMacDrawingHelper( wxWindow
* theWindow
) ;
362 ~wxMacDrawingHelper() ;
363 bool Ok() { return m_ok
; }
366 GrafPtr m_formerPort
;
367 GrafPtr m_currentPort
;
368 PenState m_savedPenState
;
372 class wxMacFocusClientHelper
375 wxMacFocusClientHelper( wxWindow * theWindow ) ;
376 ~wxMacFocusClientHelper() ;
377 bool Ok() { return m_ok ; }
380 GrafPtr m_formerPort ;
381 GrafPtr m_currentPort ;
385 class wxMacDrawingClientHelper
388 wxMacDrawingClientHelper( wxWindow
* theWindow
) ;
389 ~wxMacDrawingClientHelper() ;
390 bool Ok() { return m_ok
; }
393 GrafPtr m_formerPort
;
394 GrafPtr m_currentPort
;
395 PenState m_savedPenState
;