1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/mac/carbon/window.h
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
18 class WXDLLIMPEXP_FWD_CORE wxButton
;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar
;
20 class WXDLLIMPEXP_FWD_CORE wxTopLevelWindowMac
;
24 class WXDLLEXPORT wxWindowMac
: public wxWindowBase
26 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
29 friend class wxPaintDC
;
34 wxWindowMac( wxWindowMac
*parent
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
,
39 const wxString
& name
= wxPanelNameStr
);
41 virtual ~wxWindowMac();
43 bool Create( wxWindowMac
*parent
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
,
48 const wxString
& name
= wxPanelNameStr
);
50 // implement base class pure virtuals
51 virtual void SetLabel( const wxString
& label
);
52 virtual wxString
GetLabel() const;
57 virtual bool Show( bool show
= true );
59 virtual void SetFocus();
61 virtual void WarpPointer( int x
, int y
);
63 virtual void Refresh( bool eraseBackground
= true,
64 const wxRect
*rect
= NULL
);
65 virtual void Freeze();
67 virtual bool IsFrozen() const;
69 virtual void Update() ;
70 virtual void ClearBackground();
72 virtual bool SetCursor( const wxCursor
&cursor
);
73 virtual bool SetFont( const wxFont
&font
);
74 virtual bool SetBackgroundColour( const wxColour
&colour
);
75 virtual bool SetForegroundColour( const wxColour
&colour
);
77 virtual int GetCharHeight() const;
78 virtual int GetCharWidth() const;
79 virtual void GetTextExtent( const wxString
& string
,
82 int *externalLeading
= NULL
,
83 const wxFont
*theFont
= NULL
)
86 virtual void DoEnable( bool enable
);
87 virtual void OnEnabled( bool enabled
);
88 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
91 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
92 int range
, bool refresh
= true );
93 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
94 virtual int GetScrollPos( int orient
) const;
95 virtual int GetScrollThumb( int orient
) const;
96 virtual int GetScrollRange( int orient
) const;
97 virtual void ScrollWindow( int dx
, int dy
,
98 const wxRect
* rect
= (wxRect
*) NULL
);
99 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
100 virtual bool IsScrollbarAlwaysShown(int orient
) const
102 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
103 : m_vScrollBarAlwaysShown
;
106 virtual bool Reparent( wxWindowBase
*newParent
);
108 #if wxUSE_DRAG_AND_DROP
109 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
112 // Accept files for dragging
113 virtual void DragAcceptFiles( bool accept
);
115 // implementation from now on
116 // --------------------------
118 void MacClientToRootWindow( int *x
, int *y
) const;
119 void MacRootWindowToClient( int *x
, int *y
) const;
121 void MacWindowToRootWindow( int *x
, int *y
) const;
122 void MacWindowToRootWindow( short *x
, short *y
) const;
124 void MacRootWindowToWindow( int *x
, int *y
) const;
125 void MacRootWindowToWindow( short *x
, short *y
) const;
127 virtual wxString
MacGetToolTipString( wxPoint
&where
);
132 virtual WXWidget
GetHandle() const;
134 virtual bool SetTransparent(wxByte alpha
);
135 virtual bool CanSetTransparent();
136 virtual wxByte
GetTransparent() const ;
140 void OnSetFocus( wxFocusEvent
& event
);
141 void OnPaint( wxPaintEvent
& event
);
142 void OnNcPaint( wxNcPaintEvent
& event
);
143 void OnEraseBackground(wxEraseEvent
& event
);
144 void OnMouseEvent( wxMouseEvent
&event
);
146 void MacOnScroll( wxScrollEvent
&event
);
148 bool AcceptsFocus() const;
150 virtual bool IsDoubleBuffered() const { return true; }
153 static long MacRemoveBordersFromStyle( long style
) ;
156 void OnInternalIdle();
158 // For implementation purposes:
159 // sometimes decorations make the client area smaller
160 virtual wxPoint
GetClientAreaOrigin() const;
162 wxWindowMac
*FindItem(long id
) const;
163 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
165 virtual void MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
) ;
166 virtual bool MacDoRedraw( WXHRGN updatergn
, long time
) ;
167 virtual bool MacCanFocus() const ;
169 // this should not be overriden in classes above wxWindowMac
170 // because it is called from its destructor via DeleteChildren
171 virtual void RemoveChild( wxWindowBase
*child
);
172 virtual void MacPaintBorders( int left
, int top
) ;
174 // invalidates the borders and focus area around the control;
175 // must not be virtual as it will be called during destruction
176 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 virtual void MacSuperChangedPosition() ;
188 // absolute coordinates of this window's root have changed
189 virtual void MacTopLevelWindowChangedPosition() ;
191 virtual void MacChildAdded() ;
192 virtual void MacVisibilityChanged() ;
193 virtual void MacEnabledStateChanged() ;
194 virtual void MacHiliteChanged() ;
195 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
197 bool MacIsReallyShown() ;
198 bool MacIsReallyEnabled() ;
199 bool MacIsReallyHilited() ;
201 bool MacIsUserPane() { return m_macIsUserPane
; }
203 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
204 virtual void MacSetBackgroundBrush( const wxBrush
&brush
) ;
205 const wxBrush
& MacGetBackgroundBrush() const { return m_macBackgroundBrush
; }
207 // return the rectangle that would be visible of this control,
208 // regardless whether controls are hidden
209 // only taking into account clipping by parent windows
210 const wxRect
& MacGetClippedClientRect() const ;
211 const wxRect
& MacGetClippedRect() const ;
212 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 ) ;
217 // returns true if children have to clipped to the content area
218 // (e.g., scrolled windows)
219 bool MacClipChildren() const { return m_clipChildren
; }
220 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
222 // returns true if the grandchildren need to be clipped to the children's content area
223 // (e.g., splitter windows)
224 virtual bool MacClipGrandChildren() const { return false ; }
225 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
226 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
227 virtual bool IsClientAreaChild(const wxWindow
*child
) const
229 return !MacIsWindowScrollbar(child
) &&
230 wxWindowBase::IsClientAreaChild(child
);
233 virtual void MacInstallEventHandler(WXWidget native
) ;
234 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
235 wxList
& GetSubcontrols() { return m_subControls
; }
236 WXEVENTHANDLERREF
MacGetControlEventHandler() { return m_macControlEventHandler
; }
238 #ifndef __WXMAC_OSX__
239 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
240 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
241 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
242 virtual void MacControlUserPaneIdleProc() ;
243 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
244 virtual void MacControlUserPaneActivateProc(bool activating
) ;
245 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
246 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
249 // translate wxWidgets coords into ones suitable
250 // to be passed to CreateControl calls
252 // returns true if non-default coords are returned, false otherwise
253 bool MacGetBoundsForControl(const wxPoint
& pos
,
256 int& w
, int& h
, bool adjustForOrigin
) const ;
258 // calculates the real window position and size from the native control
259 void MacGetPositionAndSizeFromControl(int& x
, int& y
,
260 int& w
, int& h
) const ;
262 // gets the inset from every part
263 virtual void MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
) ;
265 // visibly flash the current invalid area:
266 // useful for debugging in OSX composited (double-buffered) situation
267 void MacFlashInvalidAreas() ;
269 // the 'true' OS level control for this wxWindow
270 wxMacControl
* GetPeer() const { return m_peer
; }
272 #if wxMAC_USE_CORE_GRAPHICS
273 void * MacGetCGContextRef() { return m_cgContextRef
; }
274 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
278 // For controls like radio buttons which are genuinely composite
279 wxList m_subControls
;
281 // number of calls to Freeze() minus number of calls to Thaw()
282 unsigned int m_frozenness
;
284 // the peer object, allowing for cleaner API support
285 wxMacControl
* m_peer
;
287 #if wxMAC_USE_CORE_GRAPHICS
288 void * m_cgContextRef
;
291 // cache the clipped rectangles within the window hierarchy
292 void MacUpdateClippedRects() const ;
294 mutable bool m_cachedClippedRectValid
;
295 mutable wxRect m_cachedClippedRectWithOuterStructure
;
296 mutable wxRect m_cachedClippedRect
;
297 mutable wxRect m_cachedClippedClientRect
;
298 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
299 mutable wxRegion m_cachedClippedRegion
;
300 mutable wxRegion m_cachedClippedClientRegion
;
302 // true if is is not a native control but a wxWindow control
303 bool m_macIsUserPane
;
304 wxBrush m_macBackgroundBrush
;
306 // insets of the mac control from the wx top left corner
307 wxPoint m_macTopLeftInset
;
308 wxPoint m_macBottomRightInset
;
311 wxScrollBar
* m_hScrollBar
;
312 wxScrollBar
* m_vScrollBar
;
313 bool m_hScrollBarAlwaysShown
;
314 bool m_vScrollBarAlwaysShown
;
317 // set to true if we do a sharp clip at the content area of this window
318 // must be dynamic as eg a panel normally is not clipping precisely, but if
319 // it becomes the target window of a scrolled window it has to...
320 bool m_clipChildren
;
322 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
324 void MacCreateScrollBars( long style
) ;
325 void MacRepositionScrollBars() ;
326 void MacUpdateControlFont() ;
328 void MacPropagateVisibilityChanged() ;
329 void MacPropagateHiliteChanged() ;
331 // implement the base class pure virtuals
332 virtual wxSize
DoGetBestSize() const;
333 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
334 virtual void DoClientToScreen( int *x
, int *y
) const;
335 virtual void DoScreenToClient( int *x
, int *y
) const;
336 virtual void DoGetPosition( int *x
, int *y
) const;
337 virtual void DoGetSize( int *width
, int *height
) const;
338 virtual void DoGetClientSize( int *width
, int *height
) const;
339 virtual void DoSetSize(int x
, int y
,
340 int width
, int height
,
341 int sizeFlags
= wxSIZE_AUTO
);
342 virtual void DoSetClientSize(int width
, int height
);
344 virtual void DoCaptureMouse();
345 virtual void DoReleaseMouse();
347 // move the window to the specified location and resize it: this is called
348 // from both DoSetSize() and DoSetClientSize() and would usually just call
349 // ::MoveWindow() except for composite controls which will want to arrange
350 // themselves inside the given rectangle
351 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
352 virtual void DoSetWindowVariant( wxWindowVariant variant
);
355 virtual void DoSetToolTip( wxToolTip
*tip
);
359 // common part of all ctors
362 // show/hide scrollbars as needed, common part of SetScrollbar() and
363 // AlwaysShowScrollbars()
364 void DoUpdateScrollbarVisibility();
367 WXEVENTHANDLERREF m_macControlEventHandler
;
369 DECLARE_NO_COPY_CLASS(wxWindowMac
)
370 DECLARE_EVENT_TABLE()
373 #endif // _WX_WINDOW_H_