]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/window.h
update project files
[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 virtual void SendSizeEvent(int flags = 0);
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 virtual bool ShowWithEffect(wxShowEffect effect,
69 unsigned timeout = 0)
70 {
71 return OSXShowWithEffect(true, effect, timeout);
72 }
73 virtual bool HideWithEffect(wxShowEffect effect,
74 unsigned timeout = 0)
75 {
76 return OSXShowWithEffect(false, effect, timeout);
77 }
78
79 virtual bool IsShownOnScreen() const;
80
81 virtual void SetFocus();
82
83 virtual void WarpPointer( int x, int y );
84
85 virtual void Refresh( bool eraseBackground = true,
86 const wxRect *rect = NULL );
87
88 virtual void Update() ;
89 virtual void ClearBackground();
90
91 virtual bool SetCursor( const wxCursor &cursor );
92 virtual bool SetFont( const wxFont &font );
93 virtual bool SetBackgroundColour( const wxColour &colour );
94 virtual bool SetForegroundColour( const wxColour &colour );
95
96 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
97
98 virtual int GetCharHeight() const;
99 virtual int GetCharWidth() const;
100
101 virtual double GetMagnificationFactor() const;
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_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
122 // hot keys (system wide accelerators)
123 // -----------------------------------
124
125 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
126 virtual bool UnregisterHotKey(int hotkeyId);
127 #endif // wxUSE_HOTKEY
128
129 #if wxUSE_DRAG_AND_DROP
130 virtual void SetDropTarget( wxDropTarget *dropTarget );
131 #endif
132
133 // Accept files for dragging
134 virtual void DragAcceptFiles( bool accept );
135
136 // implementation from now on
137 // --------------------------
138
139 void MacClientToRootWindow( int *x , int *y ) const;
140
141 void MacWindowToRootWindow( int *x , int *y ) const;
142
143 void MacRootWindowToWindow( int *x , int *y ) const;
144
145 virtual wxString MacGetToolTipString( wxPoint &where );
146
147 // simple accessors
148 // ----------------
149
150 virtual WXWidget GetHandle() const;
151
152 virtual bool SetTransparent(wxByte alpha);
153 virtual bool CanSetTransparent();
154 virtual wxByte GetTransparent() const ;
155
156 // event handlers
157 // --------------
158
159 void OnMouseEvent( wxMouseEvent &event );
160
161 void MacOnScroll( wxScrollEvent&event );
162
163 virtual bool AcceptsFocus() const;
164
165 virtual bool IsDoubleBuffered() const { return true; }
166
167 public:
168 static long MacRemoveBordersFromStyle( long style ) ;
169
170 public:
171 // For implementation purposes:
172 // sometimes decorations make the client area smaller
173 virtual wxPoint GetClientAreaOrigin() const;
174
175 wxWindowMac *FindItem(long id) const;
176 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
177
178 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
179 // this should not be overridden in classes above wxWindowMac
180 // because it is called from its destructor via DeleteChildren
181 virtual void RemoveChild( wxWindowBase *child );
182
183 virtual bool MacDoRedraw( long time ) ;
184 virtual void MacPaintChildrenBorders();
185 virtual void MacPaintBorders( int left , int top ) ;
186 void MacPaintGrowBox();
187
188 // invalidates the borders and focus area around the control;
189 // must not be virtual as it will be called during destruction
190 void MacInvalidateBorders() ;
191
192 WXWindow MacGetTopLevelWindowRef() const ;
193 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
194
195 virtual long MacGetWXBorderSize() const;
196 virtual long MacGetLeftBorderSize() const ;
197 virtual long MacGetRightBorderSize() const ;
198 virtual long MacGetTopBorderSize() const ;
199 virtual long MacGetBottomBorderSize() const ;
200
201 virtual void MacSuperChangedPosition() ;
202
203 // absolute coordinates of this window's root have changed
204 virtual void MacTopLevelWindowChangedPosition() ;
205
206 virtual void MacChildAdded() ;
207 virtual void MacVisibilityChanged() ;
208 virtual void MacEnabledStateChanged() ;
209 virtual void MacHiliteChanged() ;
210 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
211
212 bool MacIsReallyEnabled() ;
213 bool MacIsReallyHilited() ;
214
215 #if WXWIN_COMPATIBILITY_2_8
216 bool MacIsUserPane();
217 #endif
218 bool MacIsUserPane() const;
219
220 virtual bool MacSetupCursor( const wxPoint& pt ) ;
221
222 // return the rectangle that would be visible of this control,
223 // regardless whether controls are hidden
224 // only taking into account clipping by parent windows
225 const wxRect& MacGetClippedClientRect() const ;
226 const wxRect& MacGetClippedRect() const ;
227 const wxRect& MacGetClippedRectWithOuterStructure() const ;
228
229 // returns the visible region of this control in window ie non-client coordinates
230 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
231
232 // returns true if children have to clipped to the content area
233 // (e.g., scrolled windows)
234 bool MacClipChildren() const { return m_clipChildren ; }
235 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
236
237 // returns true if the grandchildren need to be clipped to the children's content area
238 // (e.g., splitter windows)
239 virtual bool MacClipGrandChildren() const { return false ; }
240 bool MacIsWindowScrollbar( const wxWindow* sb ) const
241 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
242 virtual bool IsClientAreaChild(const wxWindow *child) const
243 {
244 return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
245 wxWindowBase::IsClientAreaChild(child);
246 }
247
248 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
249 wxList& GetSubcontrols() { return m_subControls; }
250
251 // translate wxWidgets coords into ones suitable
252 // to be passed to CreateControl calls
253 //
254 // returns true if non-default coords are returned, false otherwise
255 bool MacGetBoundsForControl(const wxPoint& pos,
256 const wxSize& size,
257 int& x, int& y,
258 int& w, int& h , bool adjustForOrigin ) const ;
259
260 // the 'true' OS level control for this wxWindow
261 wxOSXWidgetImpl* GetPeer() const;
262
263 // optimization to avoid creating a user pane in wxWindow::Create if we already know
264 // we will replace it with our own peer
265 void DontCreatePeer();
266
267 // return true unless DontCreatePeer() had been called
268 bool ShouldCreatePeer() const;
269
270 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
271 // release existing peer
272 void SetPeer(wxOSXWidgetImpl* peer);
273
274 // wraps the already existing peer with the wrapper
275 void SetWrappingPeer(wxOSXWidgetImpl* wrapper);
276
277 #if wxOSX_USE_COCOA_OR_IPHONE
278 // the NSView or NSWindow of this window: can be used for both child and
279 // non-owned windows
280 //
281 // this is useful for a few Cocoa function which can work with either views
282 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
283 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
284 #endif // Cocoa
285
286 void * MacGetCGContextRef() { return m_cgContextRef ; }
287 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
288
289 // osx specific event handling common for all osx-ports
290
291 virtual bool OSXHandleClicked( double timestampsec );
292 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
293 virtual void OSXSimulateFocusEvents();
294
295 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
296
297 float GetContentScaleFactor() const ;
298
299 // internal response to size events
300 virtual void MacOnInternalSize() {}
301
302 protected:
303 // For controls like radio buttons which are genuinely composite
304 wxList m_subControls;
305
306 // the peer object, allowing for cleaner API support
307
308 void * m_cgContextRef ;
309
310 // cache the clipped rectangles within the window hierarchy
311 void MacUpdateClippedRects() const ;
312
313 mutable bool m_cachedClippedRectValid ;
314 mutable wxRect m_cachedClippedRectWithOuterStructure ;
315 mutable wxRect m_cachedClippedRect ;
316 mutable wxRect m_cachedClippedClientRect ;
317 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
318 mutable wxRegion m_cachedClippedRegion ;
319 mutable wxRegion m_cachedClippedClientRegion ;
320
321 // insets of the mac control from the wx top left corner
322 wxPoint m_macTopLeftInset ;
323 wxPoint m_macBottomRightInset ;
324 wxByte m_macAlpha ;
325
326 wxScrollBar* m_hScrollBar ;
327 wxScrollBar* m_vScrollBar ;
328 bool m_hScrollBarAlwaysShown;
329 bool m_vScrollBarAlwaysShown;
330 wxWindow* m_growBox ;
331 wxString m_label ;
332
333 bool m_isNativeWindowWrapper;
334
335 // set to true if we do a sharp clip at the content area of this window
336 // must be dynamic as eg a panel normally is not clipping precisely, but if
337 // it becomes the target window of a scrolled window it has to...
338 bool m_clipChildren ;
339
340 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
341
342 bool MacHasScrollBarCorner() const;
343 void MacCreateScrollBars( long style ) ;
344 void MacRepositionScrollBars() ;
345 void MacUpdateControlFont() ;
346
347 // implement the base class pure virtuals
348 virtual void DoGetTextExtent(const wxString& string,
349 int *x, int *y,
350 int *descent = NULL,
351 int *externalLeading = NULL,
352 const wxFont *theFont = NULL ) const;
353
354 virtual void DoEnable( bool enable );
355 #if wxUSE_MENUS
356 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
357 #endif
358
359 virtual void DoFreeze();
360 virtual void DoThaw();
361
362 virtual wxSize DoGetBestSize() const;
363 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
364 virtual void DoClientToScreen( int *x, int *y ) const;
365 virtual void DoScreenToClient( int *x, int *y ) const;
366 virtual void DoGetPosition( int *x, int *y ) const;
367 virtual void DoGetSize( int *width, int *height ) const;
368 virtual void DoGetClientSize( int *width, int *height ) const;
369 virtual void DoSetSize(int x, int y,
370 int width, int height,
371 int sizeFlags = wxSIZE_AUTO);
372 virtual void DoSetClientSize(int width, int height);
373
374 virtual void DoCaptureMouse();
375 virtual void DoReleaseMouse();
376
377 // move the window to the specified location and resize it: this is called
378 // from both DoSetSize() and DoSetClientSize() and would usually just call
379 // ::MoveWindow() except for composite controls which will want to arrange
380 // themselves inside the given rectangle
381 virtual void DoMoveWindow( int x, int y, int width, int height );
382 virtual void DoSetWindowVariant( wxWindowVariant variant );
383
384 #if wxUSE_TOOLTIPS
385 virtual void DoSetToolTip( wxToolTip *tip );
386 #endif
387
388 // common part of Show/HideWithEffect()
389 virtual bool OSXShowWithEffect(bool show,
390 wxShowEffect effect,
391 unsigned timeout);
392
393 private:
394 wxOSXWidgetImpl * m_peer ;
395 // common part of all ctors
396 void Init();
397
398 // show/hide scrollbars as needed, common part of SetScrollbar() and
399 // AlwaysShowScrollbars()
400 void DoUpdateScrollbarVisibility();
401
402 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
403 DECLARE_EVENT_TABLE()
404 };
405
406 #endif // _WX_WINDOW_H_