]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/window.h
Another attempt to fix wxTextMeasure compilation with VC6.
[wxWidgets.git] / include / wx / osx / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/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 wxPanel;
21 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
22
23 #if wxOSX_USE_CARBON
24 class WXDLLIMPEXP_FWD_CORE wxMacControl ;
25 typedef wxMacControl wxOSXWidgetImpl;
26 #elif wxOSX_USE_COCOA_OR_IPHONE
27 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl ;
28 typedef wxWidgetImpl wxOSXWidgetImpl;
29 #endif
30
31
32 class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
33 {
34 DECLARE_DYNAMIC_CLASS(wxWindowMac)
35
36 friend class wxDC;
37 friend class wxPaintDC;
38
39 public:
40 wxWindowMac();
41
42 wxWindowMac( wxWindowMac *parent,
43 wxWindowID id,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0,
47 const wxString& name = wxPanelNameStr );
48
49 virtual ~wxWindowMac();
50
51 bool Create( wxWindowMac *parent,
52 wxWindowID id,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = 0,
56 const wxString& name = wxPanelNameStr );
57
58 // implement base class pure virtuals
59 virtual void SetLabel( const wxString& label );
60 virtual wxString GetLabel() const;
61
62 virtual void Raise();
63 virtual void Lower();
64
65 virtual bool Show( bool show = true );
66 virtual bool ShowWithEffect(wxShowEffect effect,
67 unsigned timeout = 0)
68 {
69 return OSXShowWithEffect(true, effect, timeout);
70 }
71 virtual bool HideWithEffect(wxShowEffect effect,
72 unsigned timeout = 0)
73 {
74 return OSXShowWithEffect(false, effect, timeout);
75 }
76
77 virtual bool IsShownOnScreen() const;
78
79 virtual void SetFocus();
80
81 virtual void WarpPointer( int x, int y );
82
83 virtual void Refresh( bool eraseBackground = true,
84 const wxRect *rect = NULL );
85
86 virtual void Update() ;
87 virtual void ClearBackground();
88
89 virtual bool SetCursor( const wxCursor &cursor );
90 virtual bool SetFont( const wxFont &font );
91 virtual bool SetBackgroundColour( const wxColour &colour );
92 virtual bool SetForegroundColour( const wxColour &colour );
93
94 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
95
96 virtual int GetCharHeight() const;
97 virtual int GetCharWidth() const;
98
99 public:
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 = NULL );
108 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
109 virtual bool IsScrollbarAlwaysShown(int orient) const
110 {
111 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
112 : m_vScrollBarAlwaysShown;
113 }
114
115 virtual bool Reparent( wxWindowBase *newParent );
116
117 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
118 // hot keys (system wide accelerators)
119 // -----------------------------------
120
121 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
122 virtual bool UnregisterHotKey(int hotkeyId);
123 #endif // wxUSE_HOTKEY
124
125 #if wxUSE_DRAG_AND_DROP
126 virtual void SetDropTarget( wxDropTarget *dropTarget );
127 #endif
128
129 // Accept files for dragging
130 virtual void DragAcceptFiles( bool accept );
131
132 // implementation from now on
133 // --------------------------
134
135 void MacClientToRootWindow( int *x , int *y ) const;
136
137 void MacWindowToRootWindow( int *x , int *y ) const;
138
139 void MacRootWindowToWindow( int *x , int *y ) const;
140
141 virtual wxString MacGetToolTipString( wxPoint &where );
142
143 // simple accessors
144 // ----------------
145
146 virtual WXWidget GetHandle() const;
147
148 virtual bool SetTransparent(wxByte alpha);
149 virtual bool CanSetTransparent();
150 virtual wxByte GetTransparent() const ;
151
152 // event handlers
153 // --------------
154
155 void OnMouseEvent( wxMouseEvent &event );
156
157 void MacOnScroll( wxScrollEvent&event );
158
159 virtual bool AcceptsFocus() const;
160
161 virtual bool IsDoubleBuffered() const { return true; }
162
163 public:
164 static long MacRemoveBordersFromStyle( long style ) ;
165
166 public:
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 overridden 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 MacGetWXBorderSize() const;
192 virtual long MacGetLeftBorderSize() const ;
193 virtual long MacGetRightBorderSize() const ;
194 virtual long MacGetTopBorderSize() const ;
195 virtual long MacGetBottomBorderSize() const ;
196
197 virtual void MacSuperChangedPosition() ;
198
199 // absolute coordinates of this window's root have changed
200 virtual void MacTopLevelWindowChangedPosition() ;
201
202 virtual void MacChildAdded() ;
203 virtual void MacVisibilityChanged() ;
204 virtual void MacEnabledStateChanged() ;
205 virtual void MacHiliteChanged() ;
206 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
207
208 bool MacIsReallyEnabled() ;
209 bool MacIsReallyHilited() ;
210
211 #if WXWIN_COMPATIBILITY_2_8
212 bool MacIsUserPane();
213 #endif
214 bool MacIsUserPane() const;
215
216 virtual bool MacSetupCursor( const wxPoint& pt ) ;
217
218 // return the rectangle that would be visible of this control,
219 // regardless whether controls are hidden
220 // only taking into account clipping by parent windows
221 const wxRect& MacGetClippedClientRect() const ;
222 const wxRect& MacGetClippedRect() const ;
223 const wxRect& MacGetClippedRectWithOuterStructure() const ;
224
225 // returns the visible region of this control in window ie non-client coordinates
226 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
227
228 // returns true if children have to clipped to the content area
229 // (e.g., scrolled windows)
230 bool MacClipChildren() const { return m_clipChildren ; }
231 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
232
233 // returns true if the grandchildren need to be clipped to the children's content area
234 // (e.g., splitter windows)
235 virtual bool MacClipGrandChildren() const { return false ; }
236 bool MacIsWindowScrollbar( const wxWindow* sb ) const
237 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
238 virtual bool IsClientAreaChild(const wxWindow *child) const
239 {
240 return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
241 wxWindowBase::IsClientAreaChild(child);
242 }
243
244 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
245 wxList& GetSubcontrols() { return m_subControls; }
246
247 // translate wxWidgets coords into ones suitable
248 // to be passed to CreateControl calls
249 //
250 // returns true if non-default coords are returned, false otherwise
251 bool MacGetBoundsForControl(const wxPoint& pos,
252 const wxSize& size,
253 int& x, int& y,
254 int& w, int& h , bool adjustForOrigin ) const ;
255
256 // the 'true' OS level control for this wxWindow
257 wxOSXWidgetImpl* GetPeer() const;
258
259 // optimization to avoid creating a user pane in wxWindow::Create if we already know
260 // we will replace it with our own peer
261 void DontCreatePeer();
262
263 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
264 // release existing peer
265 void SetPeer(wxOSXWidgetImpl* peer);
266
267 // wraps the already existing peer with the wrapper
268 void SetWrappingPeer(wxOSXWidgetImpl* wrapper);
269
270 #if wxOSX_USE_COCOA_OR_IPHONE
271 // the NSView or NSWindow of this window: can be used for both child and
272 // non-owned windows
273 //
274 // this is useful for a few Cocoa function which can work with either views
275 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
276 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
277 #endif // Cocoa
278
279 void * MacGetCGContextRef() { return m_cgContextRef ; }
280 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
281
282 // osx specific event handling common for all osx-ports
283
284 virtual bool OSXHandleClicked( double timestampsec );
285 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
286
287 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
288
289 float GetContentScaleFactor() const ;
290
291 // internal response to size events
292 virtual void MacOnInternalSize() {}
293
294 protected:
295 // For controls like radio buttons which are genuinely composite
296 wxList m_subControls;
297
298 // the peer object, allowing for cleaner API support
299
300 void * m_cgContextRef ;
301
302 // cache the clipped rectangles within the window hierarchy
303 void MacUpdateClippedRects() const ;
304
305 mutable bool m_cachedClippedRectValid ;
306 mutable wxRect m_cachedClippedRectWithOuterStructure ;
307 mutable wxRect m_cachedClippedRect ;
308 mutable wxRect m_cachedClippedClientRect ;
309 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
310 mutable wxRegion m_cachedClippedRegion ;
311 mutable wxRegion m_cachedClippedClientRegion ;
312
313 // insets of the mac control from the wx top left corner
314 wxPoint m_macTopLeftInset ;
315 wxPoint m_macBottomRightInset ;
316 wxByte m_macAlpha ;
317
318 wxScrollBar* m_hScrollBar ;
319 wxScrollBar* m_vScrollBar ;
320 bool m_hScrollBarAlwaysShown;
321 bool m_vScrollBarAlwaysShown;
322 wxWindow* m_growBox ;
323 wxString m_label ;
324
325 bool m_isNativeWindowWrapper;
326
327 // set to true if we do a sharp clip at the content area of this window
328 // must be dynamic as eg a panel normally is not clipping precisely, but if
329 // it becomes the target window of a scrolled window it has to...
330 bool m_clipChildren ;
331
332 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
333
334 bool MacHasScrollBarCorner() const;
335 void MacCreateScrollBars( long style ) ;
336 void MacRepositionScrollBars() ;
337 void MacUpdateControlFont() ;
338
339 // implement the base class pure virtuals
340 virtual void DoGetTextExtent(const wxString& string,
341 int *x, int *y,
342 int *descent = NULL,
343 int *externalLeading = NULL,
344 const wxFont *theFont = NULL ) const;
345
346 virtual void DoEnable( bool enable );
347 #if wxUSE_MENUS
348 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
349 #endif
350
351 virtual void DoFreeze();
352 virtual void DoThaw();
353
354 virtual wxSize DoGetBestSize() const;
355 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
356 virtual void DoClientToScreen( int *x, int *y ) const;
357 virtual void DoScreenToClient( int *x, int *y ) const;
358 virtual void DoGetPosition( int *x, int *y ) const;
359 virtual void DoGetSize( int *width, int *height ) const;
360 virtual void DoGetClientSize( int *width, int *height ) const;
361 virtual void DoSetSize(int x, int y,
362 int width, int height,
363 int sizeFlags = wxSIZE_AUTO);
364 virtual void DoSetClientSize(int width, int height);
365
366 virtual void DoCaptureMouse();
367 virtual void DoReleaseMouse();
368
369 // move the window to the specified location and resize it: this is called
370 // from both DoSetSize() and DoSetClientSize() and would usually just call
371 // ::MoveWindow() except for composite controls which will want to arrange
372 // themselves inside the given rectangle
373 virtual void DoMoveWindow( int x, int y, int width, int height );
374 virtual void DoSetWindowVariant( wxWindowVariant variant );
375
376 #if wxUSE_TOOLTIPS
377 virtual void DoSetToolTip( wxToolTip *tip );
378 #endif
379
380 // common part of Show/HideWithEffect()
381 virtual bool OSXShowWithEffect(bool show,
382 wxShowEffect effect,
383 unsigned timeout);
384
385 private:
386 wxOSXWidgetImpl * m_peer ;
387 // common part of all ctors
388 void Init();
389
390 // show/hide scrollbars as needed, common part of SetScrollbar() and
391 // AlwaysShowScrollbars()
392 void DoUpdateScrollbarVisibility();
393
394 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
395 DECLARE_EVENT_TABLE()
396 };
397
398 #endif // _WX_WINDOW_H_