1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "window.h"
22 // ---------------------------------------------------------------------------
23 // forward declarations
24 // ---------------------------------------------------------------------------
26 class WXDLLEXPORT wxButton
;
27 class WXDLLEXPORT wxScrollBar
;
28 class WXDLLEXPORT wxTopLevelWindowMac
;
30 // internal implementation classes
34 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 class WXDLLEXPORT wxWindowMac
: public wxWindowBase
40 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
43 friend class wxPaintDC
;
49 wxWindowMac(wxWindowMac
*parent
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
54 const wxString
& name
= wxPanelNameStr
) ;
56 virtual ~wxWindowMac();
58 bool Create(wxWindowMac
*parent
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxString
& name
= wxPanelNameStr
);
66 // implement base class pure virtuals
67 virtual void SetTitle( const wxString
& title
);
68 virtual wxString
GetTitle() const;
73 virtual bool Show( bool show
= TRUE
);
74 virtual bool Enable( bool enable
= TRUE
);
76 virtual void SetFocus();
78 virtual void WarpPointer(int x
, int y
);
80 virtual void Refresh( bool eraseBackground
= TRUE
,
81 const wxRect
*rect
= (const wxRect
*) NULL
);
82 virtual void Freeze() ;
85 virtual void Update() ;
86 virtual void ClearBackground() ;
88 virtual bool SetCursor( const wxCursor
&cursor
);
89 virtual bool SetFont( const wxFont
&font
) ;
90 virtual bool SetBackgroundColour( const wxColour
&colour
);
91 virtual bool SetForegroundColour( const wxColour
&colour
);
93 virtual int GetCharHeight() const;
94 virtual int GetCharWidth() const;
95 virtual void GetTextExtent(const wxString
& string
,
97 int *descent
= (int *) NULL
,
98 int *externalLeading
= (int *) NULL
,
99 const wxFont
*theFont
= (const wxFont
*) NULL
)
102 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
104 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
105 int range
, bool refresh
= TRUE
);
106 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
107 virtual int GetScrollPos( int orient
) const;
108 virtual int GetScrollThumb( int orient
) const;
109 virtual int GetScrollRange( int orient
) const;
110 virtual void ScrollWindow( int dx
, int dy
,
111 const wxRect
* rect
= (wxRect
*) NULL
);
112 virtual bool Reparent( wxWindowBase
*newParent
);
114 #if wxUSE_DRAG_AND_DROP
115 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
116 #endif // wxUSE_DRAG_AND_DROP
118 // Accept files for dragging
119 virtual void DragAcceptFiles(bool accept
);
121 // implementation from now on
122 // --------------------------
124 void MacClientToRootWindow( int *x
, int *y
) const ;
125 void MacRootWindowToClient( int *x
, int *y
) const ;
127 void MacWindowToRootWindow( int *x
, int *y
) const ;
128 void MacWindowToRootWindow( short *x
, short *y
) const ;
130 void MacRootWindowToWindow( int *x
, int *y
) const ;
131 void MacRootWindowToWindow( short *x
, short *y
) const ;
133 virtual wxString
MacGetToolTipString( wxPoint
&where
) ;
138 virtual WXWidget
GetHandle() const ;
140 #if WXWIN_COMPATIBILITY_2_4
141 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
142 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
147 void OnSetFocus(wxFocusEvent
& event
) ;
148 void OnPaint(wxPaintEvent
& event
);
149 void OnNcPaint(wxNcPaintEvent
& event
);
150 void OnEraseBackground(wxEraseEvent
& event
);
151 void OnMouseEvent( wxMouseEvent
&event
) ;
153 void MacOnScroll(wxScrollEvent
&event
) ;
155 bool AcceptsFocus() const ;
158 void OnInternalIdle();
160 // For implementation purposes - sometimes decorations make the client area
162 virtual wxPoint
GetClientAreaOrigin() const;
164 wxWindowMac
*FindItem(long id
) const;
165 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
168 virtual void MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
) ;
169 virtual bool MacDoRedraw( WXHRGN updatergn
, long time
) ;
170 virtual bool MacCanFocus() const ;
172 // this should not be overriden in classes above wxWindowMac because it is called from its destructor via DeleteChildren
173 virtual void RemoveChild( wxWindowBase
*child
);
174 virtual void MacPaintBorders( int left
, int top
) ;
175 // invalidates the borders and focus area around the control
176 // must not be virtual as it will be called during destruction
177 void MacInvalidateBorders() ;
178 WXWindow
MacGetTopLevelWindowRef() const ;
179 wxTopLevelWindowMac
* MacGetTopLevelWindow() const ;
181 virtual long MacGetLeftBorderSize() const ;
182 virtual long MacGetRightBorderSize() const ;
183 virtual long MacGetTopBorderSize() const ;
184 virtual long MacGetBottomBorderSize() const ;
186 static long MacRemoveBordersFromStyle( long style
) ;
188 virtual void MacSuperChangedPosition() ;
189 // the absolute coortinates of this window's root have changed
190 virtual void MacTopLevelWindowChangedPosition() ;
192 virtual void MacChildAdded() ;
193 virtual void MacVisibilityChanged() ;
194 virtual void MacEnabledStateChanged() ;
195 virtual void MacHiliteChanged() ;
196 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
198 bool MacIsReallyShown() ;
199 bool MacIsReallyEnabled() ;
200 bool MacIsReallyHilited() ;
202 bool MacIsUserPane() { return m_macIsUserPane
; }
204 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
206 virtual void MacSetBackgroundBrush( const wxBrush
&brush
) ;
207 const wxBrush
& MacGetBackgroundBrush() const { return m_macBackgroundBrush
; }
209 // return the rectangle that would be visible of this control, regardless whether controls are hidden
210 // only taking into account clipping by parent windows
211 const wxRect
& MacGetClippedClientRect() const ;
212 const wxRect
& MacGetClippedRect() const ;
213 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
214 // returns the visible region of this control in window ie non-client coordinates
215 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
216 // returns true if children have to clipped to the content area (eg scrolled window)
217 bool MacClipChildren() const { return m_clipChildren
; }
218 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
219 // returns true if the grandchildren have to be clipped to the children's content area (eg
221 virtual bool MacClipGrandChildren() const { return false ; }
222 bool MacIsWindowScrollbar( const wxScrollBar
* sb
)
223 { return (m_hScrollBar
== sb
|| m_vScrollBar
== sb
) ; }
225 wxList
& GetSubcontrols() { return m_subControls
; }
226 virtual void MacInstallEventHandler(WXWidget native
) ;
227 WXEVENTHANDLERREF
MacGetControlEventHandler() { return m_macControlEventHandler
; }
228 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
229 #ifndef __WXMAC_OSX__
230 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
231 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
232 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
233 virtual void MacControlUserPaneIdleProc() ;
234 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
235 virtual void MacControlUserPaneActivateProc(bool activating
) ;
236 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
237 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
239 // translate wxWidgets coords into ones suitable to be passed to
240 // the CreateControl calls
242 // returns TRUE if non default coords are returned, FALSE otherwise
243 bool MacGetBoundsForControl(const wxPoint
& pos
,
246 int& w
, int& h
, bool adjustForOrigin
) const ;
247 // calculates the real window position and size from the native control
248 void MacGetPositionAndSizeFromControl(int& x
, int& y
,
249 int& w
, int& h
) const ;
250 // gets the inset from every part
251 virtual void MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
) ;
253 // flash the current invalid area, useful for debugging in OSX double buffered situation
254 void MacFlashInvalidAreas() ;
256 // the 'true' OS level control for this wxWindow
257 wxMacControl
* GetPeer() const { return m_peer
; }
258 #if wxMAC_USE_CORE_GRAPHICS
259 void * MacGetCGContextRef() { return m_cgContextRef
; }
260 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
263 // For controls like radiobuttons which are really composite
264 wxList m_subControls
;
265 // number of calls to Freeze() minus number of calls to Thaw()
266 unsigned int m_frozenness
;
267 // the peer object, allowing for cleaner API support
268 wxMacControl
* m_peer
;
269 #if wxMAC_USE_CORE_GRAPHICS
270 void * m_cgContextRef
;
272 // cache the clipped rectangles within the window hierarchy
273 void MacUpdateClippedRects() const ;
274 mutable bool m_cachedClippedRectValid
;
275 mutable wxRect m_cachedClippedRectWithOuterStructure
;
276 mutable wxRect m_cachedClippedRect
;
277 mutable wxRect m_cachedClippedClientRect
;
278 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
279 mutable wxRegion m_cachedClippedRegion
;
280 mutable wxRegion m_cachedClippedClientRegion
;
281 // true if is is not a native control but a wxWindow control
282 bool m_macIsUserPane
;
283 wxBrush m_macBackgroundBrush
;
284 // topleft inset of the mac control from the wx top left corner
285 wxPoint m_macTopLeftInset
;
286 // bottom right inset of the mac control from the wx bottom right corner
287 wxPoint m_macBottomRightInset
;
289 wxScrollBar
* m_hScrollBar
;
290 wxScrollBar
* m_vScrollBar
;
292 // returns true if we do a sharp clip at the content area of this window
293 // must be dynamic as eg a panel normally is not clipping precisely, but if
294 // it becomes the target window of a scrolled window it has to...
295 bool m_clipChildren
;
297 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
299 void MacCreateScrollBars( long style
) ;
300 void MacRepositionScrollBars() ;
301 void MacUpdateControlFont() ;
303 void MacPropagateVisibilityChanged() ;
304 void MacPropagateEnabledStateChanged() ;
305 void MacPropagateHiliteChanged() ;
308 #if WXWIN_COMPATIBILITY_2_4
309 bool m_backgroundTransparent
;
312 // implement the base class pure virtuals
313 virtual wxSize
DoGetBestSize() const;
314 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
315 virtual void DoClientToScreen( int *x
, int *y
) const;
316 virtual void DoScreenToClient( int *x
, int *y
) const;
317 virtual void DoGetPosition( int *x
, int *y
) const;
318 virtual void DoGetSize( int *width
, int *height
) const;
319 virtual void DoGetClientSize( int *width
, int *height
) const;
320 virtual void DoSetSize(int x
, int y
,
321 int width
, int height
,
322 int sizeFlags
= wxSIZE_AUTO
);
323 virtual void DoSetClientSize(int width
, int height
);
325 virtual void DoCaptureMouse();
326 virtual void DoReleaseMouse();
328 // move the window to the specified location and resize it: this is called
329 // from both DoSetSize() and DoSetClientSize() and would usually just call
330 // ::MoveWindow() except for composite controls which will want to arrange
331 // themselves inside the given rectangle
332 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
333 virtual void DoSetWindowVariant( wxWindowVariant variant
) ;
337 virtual void DoSetToolTip( wxToolTip
*tip
);
338 #endif // wxUSE_TOOLTIPS
343 // common part of all ctors
346 WXEVENTHANDLERREF m_macControlEventHandler
;
349 DECLARE_NO_COPY_CLASS(wxWindowMac
)
350 DECLARE_EVENT_TABLE()