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
;
51 bool m_macHasReceivedFirstActivate
;
55 wxWindow() { Init(); }
57 wxWindow(wxWindow
*parent
,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 const wxSize
& size
= wxDefaultSize
,
62 const wxString
& name
= wxPanelNameStr
)
65 Create(parent
, id
, pos
, size
, style
, name
);
70 bool Create(wxWindow
*parent
,
72 const wxPoint
& pos
= wxDefaultPosition
,
73 const wxSize
& size
= wxDefaultSize
,
75 const wxString
& name
= wxPanelNameStr
);
78 // implement base class pure virtuals
79 virtual void SetTitle( const wxString
& title
);
80 virtual wxString
GetTitle() const;
85 virtual bool Show( bool show
= TRUE
);
86 virtual bool Enable( bool enable
= TRUE
);
88 virtual void SetFocus();
90 virtual void WarpPointer(int x
, int y
);
91 virtual void CaptureMouse();
92 virtual void ReleaseMouse();
94 virtual void Refresh( bool eraseBackground
= TRUE
,
95 const wxRect
*rect
= (const wxRect
*) NULL
);
98 virtual bool SetCursor( const wxCursor
&cursor
);
99 virtual bool SetFont( const wxFont
&font
);
101 virtual int GetCharHeight() const;
102 virtual int GetCharWidth() const;
103 virtual void GetTextExtent(const wxString
& string
,
105 int *descent
= (int *) NULL
,
106 int *externalLeading
= (int *) NULL
,
107 const wxFont
*theFont
= (const wxFont
*) NULL
)
110 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
112 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
113 int range
, bool refresh
= TRUE
);
114 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
115 virtual int GetScrollPos( int orient
) const;
116 virtual int GetScrollThumb( int orient
) const;
117 virtual int GetScrollRange( int orient
) const;
118 virtual void ScrollWindow( int dx
, int dy
,
119 const wxRect
* rect
= (wxRect
*) NULL
);
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
123 #endif // wxUSE_DRAG_AND_DROP
125 // Accept files for dragging
126 virtual void DragAcceptFiles(bool accept
);
128 #if WXWIN_COMPATIBILITY
129 // Set/get scroll attributes
130 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
131 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
132 virtual int OldGetScrollRange(int orient
) const;
133 virtual int GetScrollPage(int orient
) const;
136 // Handle a control command
137 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
139 // Override to define new behaviour for default action (e.g. double
140 // clicking on a listbox)
141 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
142 #endif // WXWIN_COMPATIBILITY
144 #if wxUSE_CARET && WXWIN_COMPATIBILITY
145 // caret manipulation (old MSW only functions, see wxCaret class for the
147 void CreateCaret(int w
, int h
);
148 void CreateCaret(const wxBitmap
*bitmap
);
150 void ShowCaret(bool show
);
151 void SetCaretPos(int x
, int y
);
152 void GetCaretPos(int *x
, int *y
) const;
153 #endif // wxUSE_CARET
155 // Native resource loading (implemented in src/msw/nativdlg.cpp)
156 // FIXME: should they really be all virtual?
157 wxWindow
* GetWindowChild1(wxWindowID id
);
158 wxWindow
* GetWindowChild(wxWindowID id
);
160 // implementation from now on
161 // --------------------------
163 void MacClientToRootWindow( int *x
, int *y
) const ;
164 void MacRootWindowToClient( int *x
, int *y
) const ;
166 virtual wxString
MacGetToolTipString( wxPoint
&where
) ;
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 OnSetFocus(wxFocusEvent
& event
) ;
182 void OnEraseBackground(wxEraseEvent
& event
);
183 void OnIdle(wxIdleEvent
& event
);
184 void MacOnScroll(wxScrollEvent
&event
) ;
186 bool AcceptsFocus() const ;
189 // For implementation purposes - sometimes decorations make the client area
191 virtual wxPoint
GetClientAreaOrigin() const;
193 // Makes an adjustment to the window position (for example, a frame that has
194 // a toolbar that it manages itself).
195 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
197 wxWindow
*FindItem(long id
) const;
198 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
200 // Make a Windows extended style from the given wxWindows window style
201 static WXDWORD
MakeExtendedStyle(long style
,
202 bool eliminateBorders
= TRUE
);
203 // Determine whether 3D effects are wanted
204 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
206 // MSW only: TRUE if this control is part of the main control
207 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
209 #if WXWIN_COMPATIBILITY
210 wxObject
*GetChild(int number
) const;
211 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
212 #endif // WXWIN_COMPATIBILITY
214 // Setup background and foreground colours correctly
215 virtual void SetupColours();
218 #if WXWIN_COMPATIBILITY
219 void SetShowing(bool show
) { (void)Show(show
); }
220 bool IsUserEnabled() const { return IsEnabled(); }
221 #endif // WXWIN_COMPATIBILITY
223 // Responds to colour changes: passes event on to children.
224 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
226 virtual void MacCreateRealWindow( const wxString
& title
,
230 const wxString
& name
) ;
231 static bool MacGetWindowFromPoint( const wxPoint
&point
, wxWindow
** outWin
) ;
232 virtual void MacActivate( EventRecord
*ev
, bool inIsActivating
) ;
233 virtual void MacUpdate( EventRecord
*ev
) ;
234 virtual void MacUpdateImmediately() ;
235 virtual void MacRedraw( RgnHandle updatergn
, long time
) ;
236 virtual void MacMouseDown( EventRecord
*ev
, short windowPart
) ;
237 virtual void MacMouseUp( EventRecord
*ev
, short windowPart
) ;
238 virtual void MacMouseMoved( EventRecord
*ev
, short windowPart
) ;
239 virtual void MacKeyDown( EventRecord
*ev
) ;
240 virtual bool MacCanFocus() const { return true ; }
242 virtual void MacFireMouseEvent( EventRecord
*ev
) ;
243 virtual bool MacDispatchMouseEvent(wxMouseEvent
& event
) ;
244 virtual void MacEraseBackground( Rect
*rect
) ;
245 virtual void MacPaintBorders() ;
246 // obsolete : only for link compatibility
247 virtual void MacPaint( wxPaintEvent
&event
) ;
248 WindowRef
GetMacRootWindow() const ;
250 virtual ControlHandle
MacGetContainerForEmbedding() ;
252 virtual long MacGetLeftBorderSize() const ;
253 virtual long MacGetRightBorderSize() const ;
254 virtual long MacGetTopBorderSize() const ;
255 virtual long MacGetBottomBorderSize() const ;
257 static long MacRemoveBordersFromStyle( long style
) ;
258 virtual void MacSuperChangedPosition() ;
259 virtual void MacSuperShown( bool show
) ;
260 bool MacIsReallyShown() const ;
262 bool MacSetupFocusPort() ;
263 bool MacSetupDrawingPort() ;
264 bool MacSetupFocusClientPort() ;
265 bool MacSetupDrawingClientPort() ;
267 virtual bool MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
268 virtual bool MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* rootwin
) ;
270 virtual void MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
271 virtual void MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
272 virtual void MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
) ;
273 MacWindowData
* MacGetWindowData() { return m_macWindowData
; }
274 static WindowRef
MacGetWindowInUpdate() { return s_macWindowInUpdate
; }
275 bool MacIsWindowScrollbar( const wxScrollBar
* sb
) { return (m_hScrollBar
== sb
|| m_vScrollBar
== sb
) ; }
276 static wxWindow
* s_lastMouseWindow
;
278 virtual bool MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
) ;
280 MacWindowData
* m_macWindowData
;
281 static WindowRef s_macWindowInUpdate
;
282 RgnHandle m_macUpdateRgn
;
283 bool m_macEraseOnRedraw
;
290 wxScrollBar
* m_hScrollBar
;
291 wxScrollBar
* m_vScrollBar
;
294 void MacCreateScrollBars( long style
) ;
295 void MacRepositionScrollBars() ;
297 // additional (MSW specific) flags
298 bool m_useCtl3D
:1; // Using CTL3D for this control
299 bool m_backgroundTransparent
:1;
300 bool m_mouseInWindow
:1;
301 bool m_doubleClickAllowed
:1;
302 bool m_winCaptured
:1;
304 // the size of one page for scrolling
308 // WXHMENU m_hMenu; // Menu, if any
310 // implement the base class pure virtuals
311 virtual void DoClientToScreen( int *x
, int *y
) const;
312 virtual void DoScreenToClient( int *x
, int *y
) const;
313 virtual void DoGetPosition( int *x
, int *y
) const;
314 virtual void DoGetSize( int *width
, int *height
) const;
315 virtual void DoGetClientSize( int *width
, int *height
) const;
316 virtual void DoSetSize(int x
, int y
,
317 int width
, int height
,
318 int sizeFlags
= wxSIZE_AUTO
);
319 virtual void DoSetClientSize(int width
, int height
);
321 // move the window to the specified location and resize it: this is called
322 // from both DoSetSize() and DoSetClientSize() and would usually just call
323 // ::MoveWindow() except for composite controls which will want to arrange
324 // themselves inside the given rectangle
325 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
328 virtual void DoSetToolTip( wxToolTip
*tip
);
329 #endif // wxUSE_TOOLTIPS
332 // common part of all ctors
335 DECLARE_NO_COPY_CLASS(wxWindow
)
336 DECLARE_EVENT_TABLE()
339 // associate mac windows with wx counterparts
341 wxWindow
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
342 void wxAssociateWinWithMacWindow(WindowRef inWindow
, wxWindow
*win
) ;
343 void wxRemoveMacWindowAssociation(wxWindow
*win
) ;
346 class wxMacFocusHelper
349 wxMacFocusHelper( wxWindow * theWindow ) ;
350 ~wxMacFocusHelper() ;
351 bool Ok() { return m_ok ; }
354 GrafPtr m_formerPort ;
355 GrafPtr m_currentPort ;
360 class wxMacDrawingHelper
363 wxMacDrawingHelper( wxWindow
* theWindow
) ;
364 ~wxMacDrawingHelper() ;
365 bool Ok() { return m_ok
; }
368 GrafPtr m_formerPort
;
369 GrafPtr m_currentPort
;
370 PenState m_savedPenState
;
374 class wxMacFocusClientHelper
377 wxMacFocusClientHelper( wxWindow * theWindow ) ;
378 ~wxMacFocusClientHelper() ;
379 bool Ok() { return m_ok ; }
382 GrafPtr m_formerPort ;
383 GrafPtr m_currentPort ;
387 class wxMacDrawingClientHelper
390 wxMacDrawingClientHelper( wxWindow
* theWindow
) ;
391 ~wxMacDrawingClientHelper() ;
392 bool Ok() { return m_ok
; }
395 GrafPtr m_formerPort
;
396 GrafPtr m_currentPort
;
397 PenState m_savedPenState
;