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