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