osx new layout
[wxWidgets.git] / include / wx / osx / core / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/private.h
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets itself, it may contain identifiers which don't start
5 // with "wx".
6 // Author: Stefan Csomor
7 // Modified by:
8 // Created: 1998-01-01
9 // RCS-ID: $Id: private.h 53819 2008-05-29 14:11:45Z SC $
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifndef _WX_PRIVATE_CORE_H_
15 #define _WX_PRIVATE_CORE_H_
16
17 #include "wx/defs.h"
18
19 #include <CoreFoundation/CoreFoundation.h>
20
21 #include "wx/osx/core/cfstring.h"
22 #include "wx/osx/core/cfdataref.h"
23
24 #if wxOSX_USE_COCOA_OR_CARBON
25 WXDLLIMPEXP_BASE long UMAGetSystemVersion() ;
26 #endif
27
28 #if wxUSE_GUI
29
30 #if wxOSX_USE_IPHONE
31 #include <CoreGraphics/CoreGraphics.h>
32 #else
33 #include <ApplicationServices/ApplicationServices.h>
34 #endif
35
36 #include "wx/bitmap.h"
37 #include "wx/window.h"
38
39 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
40 {
41 DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver)
42
43 public:
44 wxMacCGContextStateSaver( CGContextRef cg )
45 {
46 m_cg = cg;
47 CGContextSaveGState( cg );
48 }
49 ~wxMacCGContextStateSaver()
50 {
51 CGContextRestoreGState( m_cg );
52 }
53 private:
54 CGContextRef m_cg;
55 };
56
57 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter : public wxObject
58 {
59 public :
60 wxDeferredObjectDeleter( wxObject* obj ) : m_obj(obj)
61 {
62 }
63 virtual ~wxDeferredObjectDeleter()
64 {
65 delete m_obj;
66 }
67 protected :
68 wxObject* m_obj ;
69 } ;
70
71 // Quartz
72
73 WXDLLIMPEXP_CORE CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap );
74
75 WXDLLIMPEXP_CORE CGDataProviderRef wxMacCGDataProviderCreateWithCFData( CFDataRef data );
76 WXDLLIMPEXP_CORE CGDataConsumerRef wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data );
77 WXDLLIMPEXP_CORE CGDataProviderRef wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer& buf );
78
79 CGColorSpaceRef WXDLLIMPEXP_CORE wxMacGetGenericRGBColorSpace(void);
80
81 class wxWindowMac;
82 // to
83 extern wxWindow* g_MacLastWindow;
84 class wxNonOwnedWindow;
85
86 // temporary typedef so that no additional casts are necessary within carbon code at the moment
87
88 class wxMacControl;
89 class wxWidgetImpl;
90 class wxNotebook;
91
92 #if wxOSX_USE_CARBON
93 typedef wxMacControl wxWidgetImplType;
94 #else
95 typedef wxWidgetImpl wxWidgetImplType;
96 #endif
97
98 class wxMenuItemImpl : public wxObject
99 {
100 public :
101 wxMenuItemImpl( wxMenuItem* peer ) : m_peer(peer)
102 {
103 }
104
105 virtual ~wxMenuItemImpl() ;
106 virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
107 virtual void Enable( bool enable ) = 0;
108 virtual void Check( bool check ) = 0;
109 virtual void SetLabel( const wxString& text, wxAcceleratorEntry *entry ) = 0;
110 virtual void Hide( bool hide = true ) = 0;
111
112 virtual void * GetHMenuItem() = 0;
113
114 wxMenuItem* GetWXPeer() { return m_peer ; }
115
116 static wxMenuItemImpl* Create( wxMenuItem* peer, wxMenu *pParentMenu,
117 int id,
118 const wxString& text,
119 wxAcceleratorEntry *entry,
120 const wxString& strHelp,
121 wxItemKind kind,
122 wxMenu *pSubMenu );
123
124 protected :
125 wxMenuItem* m_peer;
126
127 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl);
128 } ;
129
130 class wxMenuImpl : public wxObject
131 {
132 public :
133 wxMenuImpl( wxMenu* peer ) : m_peer(peer)
134 {
135 }
136
137 virtual ~wxMenuImpl() ;
138 virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) = 0;
139 virtual void Remove( wxMenuItem *pItem ) = 0;
140
141 virtual void MakeRoot() = 0;
142
143 virtual void SetTitle( const wxString& text ) = 0;
144
145 virtual WXHMENU GetHMenu() = 0;
146
147 wxMenu* GetWXPeer() { return m_peer ; }
148
149 static wxMenuImpl* Create( wxMenu* peer, const wxString& title );
150 static wxMenuImpl* CreateRootMenu( wxMenu* peer );
151 protected :
152 wxMenu* m_peer;
153
154 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl);
155 } ;
156
157
158
159 class WXDLLIMPEXP_CORE wxWidgetImpl : public wxObject
160 {
161 public :
162 wxWidgetImpl( wxWindowMac* peer , bool isRootControl = false );
163 wxWidgetImpl();
164 virtual ~wxWidgetImpl();
165
166 void Init();
167
168 bool IsRootControl() const { return m_isRootControl; }
169
170 wxWindowMac* GetWXPeer() const { return m_wxPeer; }
171
172 bool IsOk() const { return GetWXWidget() != NULL; }
173
174 // not only the control itself, but also all its parents must be visible
175 // in order for this function to return true
176 virtual bool IsVisible() const = 0;
177 // set the visibility of this widget (maybe latent)
178 virtual void SetVisibility( bool visible ) = 0;
179
180 virtual void Raise() = 0;
181
182 virtual void Lower() = 0;
183
184 virtual void ScrollRect( const wxRect *rect, int dx, int dy ) = 0;
185
186 virtual WXWidget GetWXWidget() const = 0;
187
188 virtual void SetBackgroundColour( const wxColour& col ) = 0;
189
190 // all coordinates in native parent widget relative coordinates
191 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const = 0;
192 virtual void Move(int x, int y, int width, int height) = 0;
193 virtual void GetPosition( int &x, int &y ) const = 0;
194 virtual void GetSize( int &width, int &height ) const = 0;
195 virtual void SetControlSize( wxWindowVariant variant ) = 0;
196
197 virtual void SetNeedsDisplay( const wxRect* where = NULL ) = 0;
198 virtual bool GetNeedsDisplay() const = 0;
199
200 virtual bool NeedsFocusRect() const;
201 virtual void SetNeedsFocusRect( bool needs );
202
203 virtual bool CanFocus() const = 0;
204 // return true if successful
205 virtual bool SetFocus() = 0;
206 virtual bool HasFocus() const = 0;
207
208 virtual void RemoveFromParent() = 0;
209 virtual void Embed( wxWidgetImpl *parent ) = 0;
210
211 virtual void SetDefaultButton( bool isDefault ) = 0;
212 virtual void PerformClick() = 0;
213 virtual void SetLabel( const wxString& title, wxFontEncoding encoding ) = 0;
214
215 virtual wxInt32 GetValue() const = 0;
216 virtual void SetValue( wxInt32 v ) = 0;
217 virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
218 virtual void SetupTabs( const wxNotebook &notebook ) =0;
219 virtual void GetBestRect( wxRect *r ) const = 0;
220 virtual bool IsEnabled() const = 0;
221 virtual void Enable( bool enable ) = 0;
222 virtual void SetMinimum( wxInt32 v ) = 0;
223 virtual void SetMaximum( wxInt32 v ) = 0;
224 virtual void PulseGauge() = 0;
225 virtual void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0;
226
227 // is the clicked event sent AFTER the state already changed, so no additional
228 // state changing logic is required from the outside
229 virtual bool ButtonClickDidStateChange() = 0;
230
231 // static creation methods, must be implemented by all toolkits
232
233 static wxWidgetImplType* CreateUserPane( wxWindowMac* wxpeer,
234 wxWindowMac* parent,
235 wxWindowID id,
236 const wxPoint& pos,
237 const wxSize& size,
238 long style,
239 long extraStyle) ;
240 static wxWidgetImplType* CreateContentView( wxNonOwnedWindow* now ) ;
241
242 static wxWidgetImplType* CreateButton( wxWindowMac* wxpeer,
243 wxWindowMac* parent,
244 wxWindowID id,
245 const wxString& label,
246 const wxPoint& pos,
247 const wxSize& size,
248 long style,
249 long extraStyle) ;
250
251 static wxWidgetImplType* CreateDisclosureTriangle( wxWindowMac* wxpeer,
252 wxWindowMac* parent,
253 wxWindowID id,
254 const wxString& label,
255 const wxPoint& pos,
256 const wxSize& size,
257 long style,
258 long extraStyle) ;
259
260 static wxWidgetImplType* CreateStaticLine( wxWindowMac* wxpeer,
261 wxWindowMac* parent,
262 wxWindowID id,
263 const wxPoint& pos,
264 const wxSize& size,
265 long style,
266 long extraStyle) ;
267
268 static wxWidgetImplType* CreateGroupBox( wxWindowMac* wxpeer,
269 wxWindowMac* parent,
270 wxWindowID id,
271 const wxString& label,
272 const wxPoint& pos,
273 const wxSize& size,
274 long style,
275 long extraStyle) ;
276
277 static wxWidgetImplType* CreateStaticText( wxWindowMac* wxpeer,
278 wxWindowMac* parent,
279 wxWindowID id,
280 const wxString& label,
281 const wxPoint& pos,
282 const wxSize& size,
283 long style,
284 long extraStyle) ;
285
286 static wxWidgetImplType* CreateTextControl( wxTextCtrl* wxpeer,
287 wxWindowMac* parent,
288 wxWindowID id,
289 const wxString& content,
290 const wxPoint& pos,
291 const wxSize& size,
292 long style,
293 long extraStyle) ;
294
295 static wxWidgetImplType* CreateCheckBox( wxWindowMac* wxpeer,
296 wxWindowMac* parent,
297 wxWindowID id,
298 const wxString& label,
299 const wxPoint& pos,
300 const wxSize& size,
301 long style,
302 long extraStyle);
303
304 static wxWidgetImplType* CreateRadioButton( wxWindowMac* wxpeer,
305 wxWindowMac* parent,
306 wxWindowID id,
307 const wxString& label,
308 const wxPoint& pos,
309 const wxSize& size,
310 long style,
311 long extraStyle);
312
313 static wxWidgetImplType* CreateToggleButton( wxWindowMac* wxpeer,
314 wxWindowMac* parent,
315 wxWindowID id,
316 const wxString& label,
317 const wxPoint& pos,
318 const wxSize& size,
319 long style,
320 long extraStyle);
321
322 static wxWidgetImplType* CreateBitmapToggleButton( wxWindowMac* wxpeer,
323 wxWindowMac* parent,
324 wxWindowID id,
325 const wxBitmap& bitmap,
326 const wxPoint& pos,
327 const wxSize& size,
328 long style,
329 long extraStyle);
330
331 static wxWidgetImplType* CreateBitmapButton( wxWindowMac* wxpeer,
332 wxWindowMac* parent,
333 wxWindowID id,
334 const wxBitmap& bitmap,
335 const wxPoint& pos,
336 const wxSize& size,
337 long style,
338 long extraStyle);
339
340 static wxWidgetImplType* CreateTabView( wxWindowMac* wxpeer,
341 wxWindowMac* parent,
342 wxWindowID id,
343 const wxPoint& pos,
344 const wxSize& size,
345 long style,
346 long extraStyle);
347
348 static wxWidgetImplType* CreateGauge( wxWindowMac* wxpeer,
349 wxWindowMac* parent,
350 wxWindowID id,
351 wxInt32 value,
352 wxInt32 minimum,
353 wxInt32 maximum,
354 const wxPoint& pos,
355 const wxSize& size,
356 long style,
357 long extraStyle);
358
359 static wxWidgetImplType* CreateSlider( wxWindowMac* wxpeer,
360 wxWindowMac* parent,
361 wxWindowID id,
362 wxInt32 value,
363 wxInt32 minimum,
364 wxInt32 maximum,
365 const wxPoint& pos,
366 const wxSize& size,
367 long style,
368 long extraStyle);
369
370 static wxWidgetImplType* CreateSpinButton( wxWindowMac* wxpeer,
371 wxWindowMac* parent,
372 wxWindowID id,
373 wxInt32 value,
374 wxInt32 minimum,
375 wxInt32 maximum,
376 const wxPoint& pos,
377 const wxSize& size,
378 long style,
379 long extraStyle);
380
381 static wxWidgetImplType* CreateScrollBar( wxWindowMac* wxpeer,
382 wxWindowMac* parent,
383 wxWindowID id,
384 const wxPoint& pos,
385 const wxSize& size,
386 long style,
387 long extraStyle);
388
389 static wxWidgetImplType* CreateChoice( wxWindowMac* wxpeer,
390 wxWindowMac* parent,
391 wxWindowID id,
392 wxMenu* menu,
393 const wxPoint& pos,
394 const wxSize& size,
395 long style,
396 long extraStyle);
397
398 static wxWidgetImplType* CreateListBox( wxWindowMac* wxpeer,
399 wxWindowMac* parent,
400 wxWindowID id,
401 const wxPoint& pos,
402 const wxSize& size,
403 long style,
404 long extraStyle);
405
406 // converts from Toplevel-Content relative to local
407 static void Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to );
408 protected :
409 bool m_isRootControl;
410 wxWindowMac* m_wxPeer;
411 bool m_needsFocusRect;
412
413 DECLARE_ABSTRACT_CLASS(wxWidgetImpl)
414 };
415
416 //
417 // the interface to be implemented eg by a listbox
418 //
419
420 class WXDLLIMPEXP_CORE wxMacDataItem ;
421
422 class WXDLLIMPEXP_CORE wxListWidgetColumn
423 {
424 public :
425 virtual ~wxListWidgetColumn() {}
426 } ;
427
428 class WXDLLIMPEXP_CORE wxListWidgetCellValue
429 {
430 public :
431 wxListWidgetCellValue() {}
432 virtual ~wxListWidgetCellValue() {}
433
434 virtual void Set( CFStringRef value ) = 0;
435 virtual void Set( const wxString& value ) = 0;
436 virtual void Set( int value ) = 0;
437
438 virtual int GetIntValue() const = 0;
439 virtual wxString GetStringValue() const = 0;
440 } ;
441
442 class WXDLLIMPEXP_CORE wxListWidgetImpl
443 {
444 public:
445 wxListWidgetImpl() {}
446 virtual ~wxListWidgetImpl() { }
447
448 virtual wxListWidgetColumn* InsertTextColumn( unsigned pos, const wxString& title, bool editable = false,
449 wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ;
450 virtual wxListWidgetColumn* InsertCheckColumn( unsigned pos , const wxString& title, bool editable = false,
451 wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ;
452
453 // add and remove
454
455 // TODO will be replaced
456 virtual void ListDelete( unsigned int n ) = 0;
457 virtual void ListInsert( unsigned int n ) = 0;
458 virtual void ListClear() = 0;
459
460 // selecting
461
462 virtual void ListDeselectAll() = 0;
463 virtual void ListSetSelection( unsigned int n, bool select, bool multi ) = 0;
464 virtual int ListGetSelection() const = 0;
465 virtual int ListGetSelections( wxArrayInt& aSelections ) const = 0;
466 virtual bool ListIsSelected( unsigned int n ) const = 0;
467
468 // display
469
470 virtual void ListScrollTo( unsigned int n ) = 0;
471 virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) = 0;
472 virtual void UpdateLineToEnd( unsigned int n) = 0;
473
474 // accessing content
475
476 virtual unsigned int ListGetCount() const = 0;
477 };
478
479 //
480 // toplevel window implementation class
481 //
482
483 class wxNonOwnedWindowImpl : public wxObject
484 {
485 public :
486 wxNonOwnedWindowImpl( wxNonOwnedWindow* nonownedwnd) : m_wxPeer(nonownedwnd)
487 {
488 }
489 wxNonOwnedWindowImpl()
490 {
491 }
492 virtual ~wxNonOwnedWindowImpl()
493 {
494 }
495
496 virtual void Destroy()
497 {
498 }
499
500 virtual void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
501 long style, long extraStyle, const wxString& name ) = 0;
502
503
504 virtual WXWindow GetWXWindow() const = 0;
505
506 virtual void Raise()
507 {
508 }
509
510 virtual void Lower()
511 {
512 }
513
514 virtual bool Show(bool WXUNUSED(show))
515 {
516 return false;
517 }
518
519 virtual bool ShowWithEffect(bool show, wxShowEffect WXUNUSED(effect), unsigned WXUNUSED(timeout))
520 {
521 return Show(show);
522 }
523
524 virtual void Update()
525 {
526 }
527
528 virtual bool SetTransparent(wxByte WXUNUSED(alpha))
529 {
530 return false;
531 }
532
533 virtual bool SetBackgroundColour(const wxColour& WXUNUSED(col) )
534 {
535 return false;
536 }
537
538 virtual void SetExtraStyle( long WXUNUSED(exStyle) )
539 {
540 }
541
542 virtual bool SetBackgroundStyle(wxBackgroundStyle WXUNUSED(style))
543 {
544 return false ;
545 }
546
547 bool CanSetTransparent()
548 {
549 return false;
550 }
551
552 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const = 0;
553 virtual void MoveWindow(int x, int y, int width, int height) = 0;
554 virtual void GetPosition( int &x, int &y ) const = 0;
555 virtual void GetSize( int &width, int &height ) const = 0;
556
557 virtual bool SetShape(const wxRegion& WXUNUSED(region))
558 {
559 return false;
560 }
561
562 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) = 0;
563
564 virtual bool IsMaximized() const = 0;
565
566 virtual bool IsIconized() const= 0;
567
568 virtual void Iconize( bool iconize )= 0;
569
570 virtual void Maximize(bool maximize) = 0;
571
572 virtual bool IsFullScreen() const= 0;
573
574 virtual bool ShowFullScreen(bool show, long style)= 0;
575
576 virtual void RequestUserAttention(int flags) = 0;
577
578 virtual void ScreenToWindow( int *x, int *y ) = 0;
579
580 virtual void WindowToScreen( int *x, int *y ) = 0;
581
582 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
583
584 // static creation methods, must be implemented by all toolkits
585
586 static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
587 long style, long extraStyle, const wxString& name ) ;
588
589 protected :
590 wxNonOwnedWindow* m_wxPeer;
591 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl)
592 };
593
594 #endif // wxUSE_GUI
595
596 //---------------------------------------------------------------------------
597 // cocoa bridging utilities
598 //---------------------------------------------------------------------------
599
600 bool wxMacInitCocoa();
601
602 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
603 {
604 public :
605 wxMacAutoreleasePool();
606 ~wxMacAutoreleasePool();
607 private :
608 void* m_pool;
609 };
610
611 // NSObject
612
613 void wxMacCocoaRelease( void* obj );
614 void wxMacCocoaAutorelease( void* obj );
615 void wxMacCocoaRetain( void* obj );
616
617
618 #endif
619 // _WX_PRIVATE_CORE_H_