adding focus and border quartz support
[wxWidgets.git] / include / wx / mac / carbon / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "window.h"
17 #endif
18
19 #include "wx/brush.h"
20 #include "wx/dc.h"
21
22 // ---------------------------------------------------------------------------
23 // forward declarations
24 // ---------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxButton;
27 class WXDLLEXPORT wxScrollBar;
28 class WXDLLEXPORT wxTopLevelWindowMac;
29
30 // internal implementation classes
31
32 class wxMacControl ;
33
34 // ---------------------------------------------------------------------------
35 // constants
36 // ---------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxWindowMac: public wxWindowBase
39 {
40 DECLARE_DYNAMIC_CLASS(wxWindowMac)
41
42 friend class wxDC;
43 friend class wxPaintDC;
44
45 public:
46
47 wxWindowMac() ;
48
49 wxWindowMac(wxWindowMac *parent,
50 wxWindowID id,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = 0,
54 const wxString& name = wxPanelNameStr) ;
55
56 virtual ~wxWindowMac();
57
58 bool Create(wxWindowMac *parent,
59 wxWindowID id,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxString& name = wxPanelNameStr);
64
65
66 // implement base class pure virtuals
67 virtual void SetTitle( const wxString& title);
68 virtual wxString GetTitle() const;
69
70 virtual void Raise();
71 virtual void Lower();
72
73 virtual bool Show( bool show = TRUE );
74 virtual bool Enable( bool enable = TRUE );
75
76 virtual void SetFocus();
77
78 virtual void WarpPointer(int x, int y);
79
80 virtual void Refresh( bool eraseBackground = TRUE,
81 const wxRect *rect = (const wxRect *) NULL );
82 virtual void Freeze() ;
83 virtual void Thaw() ;
84
85 virtual void Update() ;
86 virtual void ClearBackground() ;
87
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 );
92
93 virtual int GetCharHeight() const;
94 virtual int GetCharWidth() const;
95 virtual void GetTextExtent(const wxString& string,
96 int *x, int *y,
97 int *descent = (int *) NULL,
98 int *externalLeading = (int *) NULL,
99 const wxFont *theFont = (const wxFont *) NULL)
100 const;
101
102 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
103
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
113 #if wxUSE_DRAG_AND_DROP
114 virtual void SetDropTarget( wxDropTarget *dropTarget );
115 #endif // wxUSE_DRAG_AND_DROP
116
117 // Accept files for dragging
118 virtual void DragAcceptFiles(bool accept);
119
120 // implementation from now on
121 // --------------------------
122
123 void MacClientToRootWindow( int *x , int *y ) const ;
124 void MacRootWindowToClient( int *x , int *y ) const ;
125
126 void MacWindowToRootWindow( int *x , int *y ) const ;
127 void MacWindowToRootWindow( short *x , short *y ) const ;
128
129 void MacRootWindowToWindow( int *x , int *y ) const ;
130 void MacRootWindowToWindow( short *x , short *y ) const ;
131
132 virtual wxString MacGetToolTipString( wxPoint &where ) ;
133
134 // simple accessors
135 // ----------------
136
137 virtual WXWidget GetHandle() const ;
138
139 #if WXWIN_COMPATIBILITY_2_4
140 bool GetTransparentBackground() const { return m_backgroundTransparent; }
141 void SetTransparent(bool t = TRUE) { m_backgroundTransparent = t; }
142 #endif
143
144 // event handlers
145 // --------------
146 void OnSetFocus(wxFocusEvent& event) ;
147 void OnNcPaint(wxNcPaintEvent& event);
148 void OnEraseBackground(wxEraseEvent& event);
149 void OnMouseEvent( wxMouseEvent &event ) ;
150
151 void MacOnScroll(wxScrollEvent&event ) ;
152
153 bool AcceptsFocus() const ;
154
155 public:
156 void OnInternalIdle();
157
158 // For implementation purposes - sometimes decorations make the client area
159 // smaller
160 virtual wxPoint GetClientAreaOrigin() const;
161
162 wxWindowMac *FindItem(long id) const;
163 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const;
164
165 public:
166 virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;
167 virtual bool MacDoRedraw( WXHRGN updatergn , long time ) ;
168 virtual bool MacCanFocus() const ;
169
170 // this should not be overriden in classes above wxWindowMac because it is called from its destructor via DeleteChildren
171 virtual void RemoveChild( wxWindowBase *child );
172 virtual void MacPaintBorders( int left , int top ) ;
173 WXWindow MacGetTopLevelWindowRef() const ;
174 wxTopLevelWindowMac* MacGetTopLevelWindow() const ;
175
176 virtual long MacGetLeftBorderSize() const ;
177 virtual long MacGetRightBorderSize() const ;
178 virtual long MacGetTopBorderSize() const ;
179 virtual long MacGetBottomBorderSize() const ;
180
181 static long MacRemoveBordersFromStyle( long style ) ;
182
183 virtual void MacSuperChangedPosition() ;
184 // the absolute coortinates of this window's root have changed
185 virtual void MacTopLevelWindowChangedPosition() ;
186
187 virtual void MacChildAdded() ;
188 virtual void MacVisibilityChanged() ;
189 virtual void MacEnabledStateChanged() ;
190 virtual void MacHiliteChanged() ;
191 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
192
193 bool MacIsReallyShown() ;
194 bool MacIsReallyEnabled() ;
195 bool MacIsReallyHilited() ;
196
197 bool MacIsUserPane() { return m_macIsUserPane; }
198
199 virtual bool MacSetupCursor( const wxPoint& pt ) ;
200
201 virtual void MacSetBackgroundBrush( const wxBrush &brush ) ;
202 const wxBrush& MacGetBackgroundBrush() const { return m_macBackgroundBrush ; }
203
204 // returns the visible region of this control in window ie non-client coordinates
205
206 wxRegion MacGetVisibleRegion( bool includeOuterStructures = false ) ;
207 // returns true if children have to clipped to the content area (eg scrolled window)
208 virtual bool MacClipChildren() const { return false ; }
209 // returns true if the grandchildren have to be clipped to the children's content area (eg
210 // splitter window)
211 virtual bool MacClipGrandChildren() const { return false ; }
212 bool MacIsWindowScrollbar( const wxScrollBar* sb )
213 { return (m_hScrollBar == sb || m_vScrollBar == sb) ; }
214
215 wxList& GetSubcontrols() { return m_subControls; }
216 virtual void MacInstallEventHandler(WXWidget native) ;
217 WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; }
218 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
219 #ifndef __WXMAC_OSX__
220 virtual void MacControlUserPaneDrawProc(wxInt16 part) ;
221 virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ;
222 virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ;
223 virtual void MacControlUserPaneIdleProc() ;
224 virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ;
225 virtual void MacControlUserPaneActivateProc(bool activating) ;
226 virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ;
227 virtual void MacControlUserPaneBackgroundProc(void* info) ;
228 #endif
229 // translate wxWidgets coords into ones suitable to be passed to
230 // the CreateControl calls
231 //
232 // returns TRUE if non default coords are returned, FALSE otherwise
233 bool MacGetBoundsForControl(const wxPoint& pos,
234 const wxSize& size,
235 int& x, int& y,
236 int& w, int& h , bool adjustForOrigin ) const ;
237 // calculates the real window position and size from the native control
238 void MacGetPositionAndSizeFromControl(int& x, int& y,
239 int& w, int& h) const ;
240 // gets the inset from every part
241 virtual void MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) ;
242
243 // flash the current invalid area, useful for debugging in OSX double buffered situation
244 void MacFlashInvalidAreas() ;
245 #if wxMAC_USE_CORE_GRAPHICS
246 void * MacGetCGContextRef() { return m_cgContextRef ; }
247 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
248 #endif
249 protected:
250 // For controls like radiobuttons which are really composite
251 wxList m_subControls;
252 // number of calls to Freeze() minus number of calls to Thaw()
253 unsigned int m_frozenness;
254 // the peer object, allowing for cleaner API support
255 wxMacControl* m_peer ;
256 #if wxMAC_USE_CORE_GRAPHICS
257 void * m_cgContextRef ;
258 #endif
259 // true if is is not a native control but a wxWindow control
260 bool m_macIsUserPane ;
261 wxBrush m_macBackgroundBrush ;
262 // topleft inset of the mac control from the wx top left corner
263 wxPoint m_macTopLeftInset ;
264 // bottom right inset of the mac control from the wx bottom right corner
265 wxPoint m_macBottomRightInset ;
266
267 wxScrollBar* m_hScrollBar ;
268 wxScrollBar* m_vScrollBar ;
269 wxString m_label ;
270
271 void MacCreateScrollBars( long style ) ;
272 void MacRepositionScrollBars() ;
273 void MacUpdateControlFont() ;
274
275 void MacPropagateVisibilityChanged() ;
276 void MacPropagateEnabledStateChanged() ;
277 void MacPropagateHiliteChanged() ;
278
279
280 #if WXWIN_COMPATIBILITY_2_4
281 bool m_backgroundTransparent ;
282 #endif
283
284 // implement the base class pure virtuals
285 virtual wxSize DoGetBestSize() const;
286 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
287 virtual void DoClientToScreen( int *x, int *y ) const;
288 virtual void DoScreenToClient( int *x, int *y ) const;
289 virtual void DoGetPosition( int *x, int *y ) const;
290 virtual void DoGetSize( int *width, int *height ) const;
291 virtual void DoGetClientSize( int *width, int *height ) const;
292 virtual void DoSetSize(int x, int y,
293 int width, int height,
294 int sizeFlags = wxSIZE_AUTO);
295 virtual void DoSetClientSize(int width, int height);
296
297 virtual void DoCaptureMouse();
298 virtual void DoReleaseMouse();
299
300 // move the window to the specified location and resize it: this is called
301 // from both DoSetSize() and DoSetClientSize() and would usually just call
302 // ::MoveWindow() except for composite controls which will want to arrange
303 // themselves inside the given rectangle
304 virtual void DoMoveWindow(int x, int y, int width, int height);
305 virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
306
307
308 #if wxUSE_TOOLTIPS
309 virtual void DoSetToolTip( wxToolTip *tip );
310 #endif // wxUSE_TOOLTIPS
311
312 private :
313
314 private:
315 // common part of all ctors
316 void Init();
317
318 WXEVENTHANDLERREF m_macControlEventHandler ;
319
320
321 DECLARE_NO_COPY_CLASS(wxWindowMac)
322 DECLARE_EVENT_TABLE()
323 };
324
325 #endif
326 // _WX_WINDOW_H_