1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/carbon/window.h
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
18 // ---------------------------------------------------------------------------
19 // forward declarations
20 // ---------------------------------------------------------------------------
22 class WXDLLEXPORT wxButton
;
23 class WXDLLEXPORT wxScrollBar
;
24 class WXDLLEXPORT wxTopLevelWindowMac
;
26 // internal implementation classes
30 // ---------------------------------------------------------------------------
32 // ---------------------------------------------------------------------------
34 class WXDLLEXPORT wxWindowMac
: public wxWindowBase
36 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
39 friend class wxPaintDC
;
45 wxWindowMac(wxWindowMac
*parent
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxString
& name
= wxPanelNameStr
) ;
52 virtual ~wxWindowMac();
54 bool Create(wxWindowMac
*parent
,
56 const wxPoint
& pos
= wxDefaultPosition
,
57 const wxSize
& size
= wxDefaultSize
,
59 const wxString
& name
= wxPanelNameStr
);
62 // implement base class pure virtuals
63 virtual void SetLabel( const wxString
& label
);
64 virtual wxString
GetLabel() const;
69 virtual bool Show( bool show
= true );
70 virtual bool Enable( bool enable
= true );
72 virtual void SetFocus();
74 virtual void WarpPointer(int x
, int y
);
76 virtual void Refresh( bool eraseBackground
= true,
77 const wxRect
*rect
= (const wxRect
*) NULL
);
78 virtual void Freeze() ;
81 virtual void Update() ;
82 virtual void ClearBackground() ;
84 virtual bool SetCursor( const wxCursor
&cursor
);
85 virtual bool SetFont( const wxFont
&font
) ;
86 virtual bool SetBackgroundColour( const wxColour
&colour
);
87 virtual bool SetForegroundColour( const wxColour
&colour
);
89 virtual int GetCharHeight() const;
90 virtual int GetCharWidth() const;
91 virtual void GetTextExtent(const wxString
& string
,
93 int *descent
= (int *) NULL
,
94 int *externalLeading
= (int *) NULL
,
95 const wxFont
*theFont
= (const wxFont
*) NULL
)
98 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
100 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
101 int range
, bool refresh
= true );
102 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
103 virtual int GetScrollPos( int orient
) const;
104 virtual int GetScrollThumb( int orient
) const;
105 virtual int GetScrollRange( int orient
) const;
106 virtual void ScrollWindow( int dx
, int dy
,
107 const wxRect
* rect
= (wxRect
*) NULL
);
108 virtual bool Reparent( wxWindowBase
*newParent
);
110 #if wxUSE_DRAG_AND_DROP
111 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
112 #endif // wxUSE_DRAG_AND_DROP
114 // Accept files for dragging
115 virtual void DragAcceptFiles(bool accept
);
117 // implementation from now on
118 // --------------------------
120 void MacClientToRootWindow( int *x
, int *y
) const ;
121 void MacRootWindowToClient( int *x
, int *y
) const ;
123 void MacWindowToRootWindow( int *x
, int *y
) const ;
124 void MacWindowToRootWindow( short *x
, short *y
) const ;
126 void MacRootWindowToWindow( int *x
, int *y
) const ;
127 void MacRootWindowToWindow( short *x
, short *y
) const ;
129 virtual wxString
MacGetToolTipString( wxPoint
&where
) ;
134 virtual WXWidget
GetHandle() const ;
136 #if WXWIN_COMPATIBILITY_2_4
137 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
138 void SetTransparent(bool t
= true) { m_backgroundTransparent
= t
; }
143 void OnSetFocus(wxFocusEvent
& event
) ;
144 void OnPaint(wxPaintEvent
& event
);
145 void OnNcPaint(wxNcPaintEvent
& event
);
146 void OnEraseBackground(wxEraseEvent
& event
);
147 void OnMouseEvent( wxMouseEvent
&event
) ;
149 void MacOnScroll(wxScrollEvent
&event
) ;
151 bool AcceptsFocus() const ;
154 void OnInternalIdle();
156 // For implementation purposes - sometimes decorations make the client area
158 virtual wxPoint
GetClientAreaOrigin() const;
160 wxWindowMac
*FindItem(long id
) const;
161 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
164 virtual void MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool mouseStillDown
) ;
165 virtual bool MacDoRedraw( WXHRGN updatergn
, long time
) ;
166 virtual bool MacCanFocus() const ;
168 // this should not be overriden in classes above wxWindowMac because it is called from its destructor via DeleteChildren
169 virtual void RemoveChild( wxWindowBase
*child
);
170 virtual void MacPaintBorders( int left
, int top
) ;
171 // invalidates the borders and focus area around the control
172 // must not be virtual as it will be called during destruction
173 void MacInvalidateBorders() ;
174 WXWindow
MacGetTopLevelWindowRef() const ;
175 wxTopLevelWindowMac
* MacGetTopLevelWindow() const ;
177 virtual long MacGetLeftBorderSize() const ;
178 virtual long MacGetRightBorderSize() const ;
179 virtual long MacGetTopBorderSize() const ;
180 virtual long MacGetBottomBorderSize() const ;
182 static long MacRemoveBordersFromStyle( long style
) ;
184 virtual void MacSuperChangedPosition() ;
185 // the absolute coortinates of this window's root have changed
186 virtual void MacTopLevelWindowChangedPosition() ;
188 virtual void MacChildAdded() ;
189 virtual void MacVisibilityChanged() ;
190 virtual void MacEnabledStateChanged() ;
191 virtual void MacHiliteChanged() ;
192 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
194 bool MacIsReallyShown() ;
195 bool MacIsReallyEnabled() ;
196 bool MacIsReallyHilited() ;
198 bool MacIsUserPane() { return m_macIsUserPane
; }
200 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
202 virtual void MacSetBackgroundBrush( const wxBrush
&brush
) ;
203 const wxBrush
& MacGetBackgroundBrush() const { return m_macBackgroundBrush
; }
205 // return the rectangle that would be visible of this control, regardless whether controls are hidden
206 // only taking into account clipping by parent windows
207 const wxRect
& MacGetClippedClientRect() const ;
208 const wxRect
& MacGetClippedRect() const ;
209 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
210 // returns the visible region of this control in window ie non-client coordinates
211 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
212 // returns true if children have to clipped to the content area (eg scrolled window)
213 bool MacClipChildren() const { return m_clipChildren
; }
214 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
215 // returns true if the grandchildren have to be clipped to the children's content area (eg
217 virtual bool MacClipGrandChildren() const { return false ; }
218 bool MacIsWindowScrollbar( const wxScrollBar
* sb
)
219 { return (m_hScrollBar
== sb
|| m_vScrollBar
== sb
) ; }
221 wxList
& GetSubcontrols() { return m_subControls
; }
222 virtual void MacInstallEventHandler(WXWidget native
) ;
223 WXEVENTHANDLERREF
MacGetControlEventHandler() { return m_macControlEventHandler
; }
224 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
225 #ifndef __WXMAC_OSX__
226 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
227 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
228 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
229 virtual void MacControlUserPaneIdleProc() ;
230 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
231 virtual void MacControlUserPaneActivateProc(bool activating
) ;
232 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
233 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
235 // translate wxWidgets coords into ones suitable to be passed to
236 // the CreateControl calls
238 // returns true if non default coords are returned, false otherwise
239 bool MacGetBoundsForControl(const wxPoint
& pos
,
242 int& w
, int& h
, bool adjustForOrigin
) const ;
243 // calculates the real window position and size from the native control
244 void MacGetPositionAndSizeFromControl(int& x
, int& y
,
245 int& w
, int& h
) const ;
246 // gets the inset from every part
247 virtual void MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
) ;
249 // flash the current invalid area, useful for debugging in OSX double buffered situation
250 void MacFlashInvalidAreas() ;
252 // the 'true' OS level control for this wxWindow
253 wxMacControl
* GetPeer() const { return m_peer
; }
254 #if wxMAC_USE_CORE_GRAPHICS
255 void * MacGetCGContextRef() { return m_cgContextRef
; }
256 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
259 // For controls like radiobuttons which are really composite
260 wxList m_subControls
;
261 // number of calls to Freeze() minus number of calls to Thaw()
262 unsigned int m_frozenness
;
263 // the peer object, allowing for cleaner API support
264 wxMacControl
* m_peer
;
265 #if wxMAC_USE_CORE_GRAPHICS
266 void * m_cgContextRef
;
268 // cache the clipped rectangles within the window hierarchy
269 void MacUpdateClippedRects() const ;
270 mutable bool m_cachedClippedRectValid
;
271 mutable wxRect m_cachedClippedRectWithOuterStructure
;
272 mutable wxRect m_cachedClippedRect
;
273 mutable wxRect m_cachedClippedClientRect
;
274 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
275 mutable wxRegion m_cachedClippedRegion
;
276 mutable wxRegion m_cachedClippedClientRegion
;
277 // true if is is not a native control but a wxWindow control
278 bool m_macIsUserPane
;
279 wxBrush m_macBackgroundBrush
;
280 // topleft inset of the mac control from the wx top left corner
281 wxPoint m_macTopLeftInset
;
282 // bottom right inset of the mac control from the wx bottom right corner
283 wxPoint m_macBottomRightInset
;
285 wxScrollBar
* m_hScrollBar
;
286 wxScrollBar
* m_vScrollBar
;
288 // returns true if we do a sharp clip at the content area of this window
289 // must be dynamic as eg a panel normally is not clipping precisely, but if
290 // it becomes the target window of a scrolled window it has to...
291 bool m_clipChildren
;
293 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
295 void MacCreateScrollBars( long style
) ;
296 void MacRepositionScrollBars() ;
297 void MacUpdateControlFont() ;
299 void MacPropagateVisibilityChanged() ;
300 void MacPropagateEnabledStateChanged() ;
301 void MacPropagateHiliteChanged() ;
304 #if WXWIN_COMPATIBILITY_2_4
305 bool m_backgroundTransparent
;
308 // implement the base class pure virtuals
309 virtual wxSize
DoGetBestSize() const;
310 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
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 virtual void DoCaptureMouse();
322 virtual void DoReleaseMouse();
324 // move the window to the specified location and resize it: this is called
325 // from both DoSetSize() and DoSetClientSize() and would usually just call
326 // ::MoveWindow() except for composite controls which will want to arrange
327 // themselves inside the given rectangle
328 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
329 virtual void DoSetWindowVariant( wxWindowVariant variant
) ;
333 virtual void DoSetToolTip( wxToolTip
*tip
);
334 #endif // wxUSE_TOOLTIPS
339 // common part of all ctors
342 WXEVENTHANDLERREF m_macControlEventHandler
;
345 DECLARE_NO_COPY_CLASS(wxWindowMac
)
346 DECLARE_EVENT_TABLE()