]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/window.h
compilation fix for wxUSE_UTF8_LOCALE_ONLY case
[wxWidgets.git] / include / wx / osx / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/mac/carbon/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 #include "wx/brush.h"
16 #include "wx/dc.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxButton;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar;
20 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
21
22 #if wxOSX_USE_CARBON
23 class WXDLLIMPEXP_FWD_CORE wxMacControl ;
24 typedef wxMacControl wxOSXWidgetImpl;
25 #elif wxOSX_USE_COCOA
26 class WXDLLIMPEXP_FWD_CORE wxWidgetCocoaImpl ;
27 typedef wxWidgetCocoaImpl wxOSXWidgetImpl;
28 #elif wxOSX_USE_IPHONE
29 class WXDLLIMPEXP_FWD_CORE wxWidgetIPhoneImpl ;
30 typedef wxWidgetIPhoneImpl wxOSXWidgetImpl;
31 #endif
32
33
34 class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
35 {
36 DECLARE_DYNAMIC_CLASS(wxWindowMac)
37
38 friend class wxDC;
39 friend class wxPaintDC;
40
41 public:
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 // implement base class pure virtuals
61 virtual void SetLabel( const wxString& label );
62 virtual wxString GetLabel() const;
63
64 virtual void Raise();
65 virtual void Lower();
66
67 virtual bool Show( bool show = true );
68
69 virtual bool IsShownOnScreen() const;
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 = NULL );
77
78 virtual void Update() ;
79 virtual void ClearBackground();
80
81 virtual bool SetCursor( const wxCursor &cursor );
82 virtual bool SetFont( const wxFont &font );
83 virtual bool SetBackgroundColour( const wxColour &colour );
84 virtual bool SetForegroundColour( const wxColour &colour );
85
86 virtual int GetCharHeight() const;
87 virtual int GetCharWidth() const;
88 virtual void GetTextExtent( const wxString& string,
89 int *x, int *y,
90 int *descent = NULL,
91 int *externalLeading = NULL,
92 const wxFont *theFont = NULL )
93 const;
94 protected:
95 virtual void DoEnable( bool enable );
96 #if wxUSE_MENUS
97 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
98 #endif
99
100 virtual void DoFreeze();
101 virtual void DoThaw();
102
103 public:
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 = NULL );
112 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
113 virtual bool IsScrollbarAlwaysShown(int orient) const
114 {
115 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
116 : m_vScrollBarAlwaysShown;
117 }
118
119 virtual bool Reparent( wxWindowBase *newParent );
120
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget( wxDropTarget *dropTarget );
123 #endif
124
125 // Accept files for dragging
126 virtual void DragAcceptFiles( bool accept );
127
128 // implementation from now on
129 // --------------------------
130
131 void MacClientToRootWindow( int *x , int *y ) const;
132
133 void MacWindowToRootWindow( int *x , int *y ) const;
134
135 void MacRootWindowToWindow( int *x , int *y ) const;
136
137 virtual wxString MacGetToolTipString( wxPoint &where );
138
139 // simple accessors
140 // ----------------
141
142 virtual WXWidget GetHandle() const;
143
144 virtual bool SetTransparent(wxByte alpha);
145 virtual bool CanSetTransparent();
146 virtual wxByte GetTransparent() const ;
147
148 // event handlers
149 // --------------
150
151 void OnNcPaint( wxNcPaintEvent& event );
152 void OnEraseBackground(wxEraseEvent& event );
153 void OnMouseEvent( wxMouseEvent &event );
154
155 void MacOnScroll( wxScrollEvent&event );
156
157 virtual bool AcceptsFocus() const;
158
159 virtual bool IsDoubleBuffered() const { return true; }
160
161 public:
162 static long MacRemoveBordersFromStyle( long style ) ;
163
164 public:
165 void OnInternalIdle();
166
167 // For implementation purposes:
168 // sometimes decorations make the client area smaller
169 virtual wxPoint GetClientAreaOrigin() const;
170
171 wxWindowMac *FindItem(long id) const;
172 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
173
174 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
175 // this should not be overriden in classes above wxWindowMac
176 // because it is called from its destructor via DeleteChildren
177 virtual void RemoveChild( wxWindowBase *child );
178
179 virtual bool MacDoRedraw( long time ) ;
180 virtual void MacPaintChildrenBorders();
181 virtual void MacPaintBorders( int left , int top ) ;
182 void MacPaintGrowBox();
183
184 // invalidates the borders and focus area around the control;
185 // must not be virtual as it will be called during destruction
186 void MacInvalidateBorders() ;
187
188 WXWindow MacGetTopLevelWindowRef() const ;
189 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
190
191 virtual long MacGetLeftBorderSize() const ;
192 virtual long MacGetRightBorderSize() const ;
193 virtual long MacGetTopBorderSize() const ;
194 virtual long MacGetBottomBorderSize() const ;
195
196 virtual void MacSuperChangedPosition() ;
197
198 // absolute coordinates of this window's root have changed
199 virtual void MacTopLevelWindowChangedPosition() ;
200
201 virtual void MacChildAdded() ;
202 virtual void MacVisibilityChanged() ;
203 virtual void MacEnabledStateChanged() ;
204 virtual void MacHiliteChanged() ;
205 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
206
207 bool MacIsReallyEnabled() ;
208 bool MacIsReallyHilited() ;
209
210 #if WXWIN_COMPATIBILITY_2_8
211 bool MacIsUserPane() { return m_macIsUserPane; }
212 #endif
213 bool MacIsUserPane() const { return m_macIsUserPane; }
214
215 virtual bool MacSetupCursor( const wxPoint& pt ) ;
216
217 // return the rectangle that would be visible of this control,
218 // regardless whether controls are hidden
219 // only taking into account clipping by parent windows
220 const wxRect& MacGetClippedClientRect() const ;
221 const wxRect& MacGetClippedRect() const ;
222 const wxRect& MacGetClippedRectWithOuterStructure() const ;
223
224 // returns the visible region of this control in window ie non-client coordinates
225 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
226
227 // returns true if children have to clipped to the content area
228 // (e.g., scrolled windows)
229 bool MacClipChildren() const { return m_clipChildren ; }
230 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
231
232 // returns true if the grandchildren need to be clipped to the children's content area
233 // (e.g., splitter windows)
234 virtual bool MacClipGrandChildren() const { return false ; }
235 bool MacIsWindowScrollbar( const wxWindow* sb ) const
236 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
237 virtual bool IsClientAreaChild(const wxWindow *child) const
238 {
239 return !MacIsWindowScrollbar(child) &&
240 wxWindowBase::IsClientAreaChild(child);
241 }
242
243 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
244 wxList& GetSubcontrols() { return m_subControls; }
245
246 // translate wxWidgets coords into ones suitable
247 // to be passed to CreateControl calls
248 //
249 // returns true if non-default coords are returned, false otherwise
250 bool MacGetBoundsForControl(const wxPoint& pos,
251 const wxSize& size,
252 int& x, int& y,
253 int& w, int& h , bool adjustForOrigin ) const ;
254
255 // the 'true' OS level control for this wxWindow
256 wxOSXWidgetImpl* GetPeer() const { return m_peer ; }
257
258 void * MacGetCGContextRef() { return m_cgContextRef ; }
259 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
260
261 // osx specific event handling common for all osx-ports
262
263 virtual bool OSXHandleClicked( double timestampsec );
264 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
265 protected:
266 // For controls like radio buttons which are genuinely composite
267 wxList m_subControls;
268
269 // the peer object, allowing for cleaner API support
270 wxOSXWidgetImpl * m_peer ;
271
272 void * m_cgContextRef ;
273
274 // cache the clipped rectangles within the window hierarchy
275 void MacUpdateClippedRects() const ;
276
277 mutable bool m_cachedClippedRectValid ;
278 mutable wxRect m_cachedClippedRectWithOuterStructure ;
279 mutable wxRect m_cachedClippedRect ;
280 mutable wxRect m_cachedClippedClientRect ;
281 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
282 mutable wxRegion m_cachedClippedRegion ;
283 mutable wxRegion m_cachedClippedClientRegion ;
284
285 // true if is is not a native control but a wxWindow control
286 bool m_macIsUserPane ;
287
288 // insets of the mac control from the wx top left corner
289 wxPoint m_macTopLeftInset ;
290 wxPoint m_macBottomRightInset ;
291 wxByte m_macAlpha ;
292
293 wxScrollBar* m_hScrollBar ;
294 wxScrollBar* m_vScrollBar ;
295 bool m_hScrollBarAlwaysShown;
296 bool m_vScrollBarAlwaysShown;
297 wxString m_label ;
298
299 // set to true if we do a sharp clip at the content area of this window
300 // must be dynamic as eg a panel normally is not clipping precisely, but if
301 // it becomes the target window of a scrolled window it has to...
302 bool m_clipChildren ;
303
304 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
305
306 bool MacHasScrollBarCorner() const;
307 void MacCreateScrollBars( long style ) ;
308 void MacRepositionScrollBars() ;
309 void MacUpdateControlFont() ;
310
311 // implement the base class pure virtuals
312 virtual wxSize DoGetBestSize() const;
313 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
314 virtual void DoClientToScreen( int *x, int *y ) const;
315 virtual void DoScreenToClient( int *x, int *y ) const;
316 virtual void DoGetPosition( int *x, int *y ) const;
317 virtual void DoGetSize( int *width, int *height ) const;
318 virtual void DoGetClientSize( int *width, int *height ) const;
319 virtual void DoSetSize(int x, int y,
320 int width, int height,
321 int sizeFlags = wxSIZE_AUTO);
322 virtual void DoSetClientSize(int width, int height);
323
324 virtual void DoCaptureMouse();
325 virtual void DoReleaseMouse();
326
327 // move the window to the specified location and resize it: this is called
328 // from both DoSetSize() and DoSetClientSize() and would usually just call
329 // ::MoveWindow() except for composite controls which will want to arrange
330 // themselves inside the given rectangle
331 virtual void DoMoveWindow( int x, int y, int width, int height );
332 virtual void DoSetWindowVariant( wxWindowVariant variant );
333
334 #if wxUSE_TOOLTIPS
335 virtual void DoSetToolTip( wxToolTip *tip );
336 #endif
337
338 private:
339 // common part of all ctors
340 void Init();
341
342 // show/hide scrollbars as needed, common part of SetScrollbar() and
343 // AlwaysShowScrollbars()
344 void DoUpdateScrollbarVisibility();
345
346
347 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
348 DECLARE_EVENT_TABLE()
349 };
350
351 #endif // _WX_WINDOW_H_