supporting PopUp on osx cocoa as well, see #10361
[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 virtual void PopUp( wxWindow *win, int x, int y ) = 0;
156
157 static wxMenuImpl* Create( wxMenu* peer, const wxString& title );
158 static wxMenuImpl* CreateRootMenu( wxMenu* peer );
159 protected :
160 wxMenu* m_peer;
161
162 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl);
163 } ;
164
165
166
167 class WXDLLIMPEXP_CORE wxWidgetImpl : public wxObject
168 {
169 public :
170 wxWidgetImpl( wxWindowMac* peer , bool isRootControl = false );
171 wxWidgetImpl();
172 virtual ~wxWidgetImpl();
173
174 void Init();
175
176 bool IsRootControl() const { return m_isRootControl; }
177
178 wxWindowMac* GetWXPeer() const { return m_wxPeer; }
179
180 bool IsOk() const { return GetWXWidget() != NULL; }
181
182 // not only the control itself, but also all its parents must be visible
183 // in order for this function to return true
184 virtual bool IsVisible() const = 0;
185 // set the visibility of this widget (maybe latent)
186 virtual void SetVisibility( bool visible ) = 0;
187
188 virtual void Raise() = 0;
189
190 virtual void Lower() = 0;
191
192 virtual void ScrollRect( const wxRect *rect, int dx, int dy ) = 0;
193
194 virtual WXWidget GetWXWidget() const = 0;
195
196 virtual void SetBackgroundColour( const wxColour& col ) = 0;
197
198 // all coordinates in native parent widget relative coordinates
199 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const = 0;
200 virtual void Move(int x, int y, int width, int height) = 0;
201 virtual void GetPosition( int &x, int &y ) const = 0;
202 virtual void GetSize( int &width, int &height ) const = 0;
203 virtual void SetControlSize( wxWindowVariant variant ) = 0;
204
205 virtual void SetNeedsDisplay( const wxRect* where = NULL ) = 0;
206 virtual bool GetNeedsDisplay() const = 0;
207
208 virtual bool NeedsFocusRect() const;
209 virtual void SetNeedsFocusRect( bool needs );
210
211 virtual bool CanFocus() const = 0;
212 // return true if successful
213 virtual bool SetFocus() = 0;
214 virtual bool HasFocus() const = 0;
215
216 virtual void RemoveFromParent() = 0;
217 virtual void Embed( wxWidgetImpl *parent ) = 0;
218
219 virtual void SetDefaultButton( bool isDefault ) = 0;
220 virtual void PerformClick() = 0;
221 virtual void SetLabel( const wxString& title, wxFontEncoding encoding ) = 0;
222
223 virtual wxInt32 GetValue() const = 0;
224 virtual void SetValue( wxInt32 v ) = 0;
225 virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
226 virtual void SetupTabs( const wxNotebook &notebook ) =0;
227 virtual void GetBestRect( wxRect *r ) const = 0;
228 virtual bool IsEnabled() const = 0;
229 virtual void Enable( bool enable ) = 0;
230 virtual void SetMinimum( wxInt32 v ) = 0;
231 virtual void SetMaximum( wxInt32 v ) = 0;
232 virtual void PulseGauge() = 0;
233 virtual void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0;
234
235 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ) = 0;
236
237 // is the clicked event sent AFTER the state already changed, so no additional
238 // state changing logic is required from the outside
239 virtual bool ButtonClickDidStateChange() = 0;
240
241 virtual void InstallEventHandler( WXWidget control = NULL ) = 0;
242
243 // static methods for associating native controls and their implementations
244
245 static wxWidgetImpl*
246 FindFromWXWidget(WXWidget control);
247
248 static void RemoveAssociations( wxWidgetImpl* impl);
249
250 static void Associate( WXWidget control, wxWidgetImpl *impl );
251
252 // static creation methods, must be implemented by all toolkits
253
254 static wxWidgetImplType* CreateUserPane( wxWindowMac* wxpeer,
255 wxWindowMac* parent,
256 wxWindowID id,
257 const wxPoint& pos,
258 const wxSize& size,
259 long style,
260 long extraStyle) ;
261 static wxWidgetImplType* CreateContentView( wxNonOwnedWindow* now ) ;
262
263 static wxWidgetImplType* CreateButton( wxWindowMac* wxpeer,
264 wxWindowMac* parent,
265 wxWindowID id,
266 const wxString& label,
267 const wxPoint& pos,
268 const wxSize& size,
269 long style,
270 long extraStyle) ;
271
272 static wxWidgetImplType* CreateDisclosureTriangle( wxWindowMac* wxpeer,
273 wxWindowMac* parent,
274 wxWindowID id,
275 const wxString& label,
276 const wxPoint& pos,
277 const wxSize& size,
278 long style,
279 long extraStyle) ;
280
281 static wxWidgetImplType* CreateStaticLine( wxWindowMac* wxpeer,
282 wxWindowMac* parent,
283 wxWindowID id,
284 const wxPoint& pos,
285 const wxSize& size,
286 long style,
287 long extraStyle) ;
288
289 static wxWidgetImplType* CreateGroupBox( wxWindowMac* wxpeer,
290 wxWindowMac* parent,
291 wxWindowID id,
292 const wxString& label,
293 const wxPoint& pos,
294 const wxSize& size,
295 long style,
296 long extraStyle) ;
297
298 static wxWidgetImplType* CreateStaticText( wxWindowMac* wxpeer,
299 wxWindowMac* parent,
300 wxWindowID id,
301 const wxString& label,
302 const wxPoint& pos,
303 const wxSize& size,
304 long style,
305 long extraStyle) ;
306
307 static wxWidgetImplType* CreateTextControl( wxTextCtrl* wxpeer,
308 wxWindowMac* parent,
309 wxWindowID id,
310 const wxString& content,
311 const wxPoint& pos,
312 const wxSize& size,
313 long style,
314 long extraStyle) ;
315
316 static wxWidgetImplType* CreateSearchControl( wxTextCtrl* wxpeer,
317 wxWindowMac* parent,
318 wxWindowID id,
319 const wxString& content,
320 const wxPoint& pos,
321 const wxSize& size,
322 long style,
323 long extraStyle) ;
324
325 static wxWidgetImplType* CreateCheckBox( wxWindowMac* wxpeer,
326 wxWindowMac* parent,
327 wxWindowID id,
328 const wxString& label,
329 const wxPoint& pos,
330 const wxSize& size,
331 long style,
332 long extraStyle);
333
334 static wxWidgetImplType* CreateRadioButton( wxWindowMac* wxpeer,
335 wxWindowMac* parent,
336 wxWindowID id,
337 const wxString& label,
338 const wxPoint& pos,
339 const wxSize& size,
340 long style,
341 long extraStyle);
342
343 static wxWidgetImplType* CreateToggleButton( wxWindowMac* wxpeer,
344 wxWindowMac* parent,
345 wxWindowID id,
346 const wxString& label,
347 const wxPoint& pos,
348 const wxSize& size,
349 long style,
350 long extraStyle);
351
352 static wxWidgetImplType* CreateBitmapToggleButton( wxWindowMac* wxpeer,
353 wxWindowMac* parent,
354 wxWindowID id,
355 const wxBitmap& bitmap,
356 const wxPoint& pos,
357 const wxSize& size,
358 long style,
359 long extraStyle);
360
361 static wxWidgetImplType* CreateBitmapButton( wxWindowMac* wxpeer,
362 wxWindowMac* parent,
363 wxWindowID id,
364 const wxBitmap& bitmap,
365 const wxPoint& pos,
366 const wxSize& size,
367 long style,
368 long extraStyle);
369
370 static wxWidgetImplType* CreateTabView( wxWindowMac* wxpeer,
371 wxWindowMac* parent,
372 wxWindowID id,
373 const wxPoint& pos,
374 const wxSize& size,
375 long style,
376 long extraStyle);
377
378 static wxWidgetImplType* CreateGauge( wxWindowMac* wxpeer,
379 wxWindowMac* parent,
380 wxWindowID id,
381 wxInt32 value,
382 wxInt32 minimum,
383 wxInt32 maximum,
384 const wxPoint& pos,
385 const wxSize& size,
386 long style,
387 long extraStyle);
388
389 static wxWidgetImplType* CreateSlider( wxWindowMac* wxpeer,
390 wxWindowMac* parent,
391 wxWindowID id,
392 wxInt32 value,
393 wxInt32 minimum,
394 wxInt32 maximum,
395 const wxPoint& pos,
396 const wxSize& size,
397 long style,
398 long extraStyle);
399
400 static wxWidgetImplType* CreateSpinButton( wxWindowMac* wxpeer,
401 wxWindowMac* parent,
402 wxWindowID id,
403 wxInt32 value,
404 wxInt32 minimum,
405 wxInt32 maximum,
406 const wxPoint& pos,
407 const wxSize& size,
408 long style,
409 long extraStyle);
410
411 static wxWidgetImplType* CreateScrollBar( wxWindowMac* wxpeer,
412 wxWindowMac* parent,
413 wxWindowID id,
414 const wxPoint& pos,
415 const wxSize& size,
416 long style,
417 long extraStyle);
418
419 static wxWidgetImplType* CreateChoice( wxWindowMac* wxpeer,
420 wxWindowMac* parent,
421 wxWindowID id,
422 wxMenu* menu,
423 const wxPoint& pos,
424 const wxSize& size,
425 long style,
426 long extraStyle);
427
428 static wxWidgetImplType* CreateListBox( wxWindowMac* wxpeer,
429 wxWindowMac* parent,
430 wxWindowID id,
431 const wxPoint& pos,
432 const wxSize& size,
433 long style,
434 long extraStyle);
435
436 // converts from Toplevel-Content relative to local
437 static void Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to );
438 protected :
439 bool m_isRootControl;
440 wxWindowMac* m_wxPeer;
441 bool m_needsFocusRect;
442
443 DECLARE_ABSTRACT_CLASS(wxWidgetImpl)
444 };
445
446 //
447 // the interface to be implemented eg by a listbox
448 //
449
450 class WXDLLIMPEXP_CORE wxListWidgetColumn
451 {
452 public :
453 virtual ~wxListWidgetColumn() {}
454 } ;
455
456 class WXDLLIMPEXP_CORE wxListWidgetCellValue
457 {
458 public :
459 wxListWidgetCellValue() {}
460 virtual ~wxListWidgetCellValue() {}
461
462 virtual void Set( CFStringRef value ) = 0;
463 virtual void Set( const wxString& value ) = 0;
464 virtual void Set( int value ) = 0;
465
466 virtual int GetIntValue() const = 0;
467 virtual wxString GetStringValue() const = 0;
468 } ;
469
470 class WXDLLIMPEXP_CORE wxListWidgetImpl
471 {
472 public:
473 wxListWidgetImpl() {}
474 virtual ~wxListWidgetImpl() { }
475
476 virtual wxListWidgetColumn* InsertTextColumn( unsigned pos, const wxString& title, bool editable = false,
477 wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ;
478 virtual wxListWidgetColumn* InsertCheckColumn( unsigned pos , const wxString& title, bool editable = false,
479 wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ;
480
481 // add and remove
482
483 // TODO will be replaced
484 virtual void ListDelete( unsigned int n ) = 0;
485 virtual void ListInsert( unsigned int n ) = 0;
486 virtual void ListClear() = 0;
487
488 // selecting
489
490 virtual void ListDeselectAll() = 0;
491 virtual void ListSetSelection( unsigned int n, bool select, bool multi ) = 0;
492 virtual int ListGetSelection() const = 0;
493 virtual int ListGetSelections( wxArrayInt& aSelections ) const = 0;
494 virtual bool ListIsSelected( unsigned int n ) const = 0;
495
496 // display
497
498 virtual void ListScrollTo( unsigned int n ) = 0;
499 virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) = 0;
500 virtual void UpdateLineToEnd( unsigned int n) = 0;
501
502 // accessing content
503
504 virtual unsigned int ListGetCount() const = 0;
505 };
506
507 //
508 // interface to be implemented by a textcontrol
509 //
510
511 class WXDLLIMPEXP_FWD_CORE wxTextAttr;
512
513 // common interface for all implementations
514 class WXDLLIMPEXP_CORE wxTextWidgetImpl
515
516 {
517 public :
518 wxTextWidgetImpl() {}
519
520 virtual ~wxTextWidgetImpl() {}
521
522 virtual bool CanFocus() const { return true; }
523
524 virtual wxString GetStringValue() const = 0 ;
525 virtual void SetStringValue( const wxString &val ) = 0 ;
526 virtual void SetSelection( long from, long to ) = 0 ;
527 virtual void GetSelection( long* from, long* to ) const = 0 ;
528 virtual void WriteText( const wxString& str ) = 0 ;
529
530 virtual void SetStyle( long start, long end, const wxTextAttr& style ) ;
531 virtual void Copy() ;
532 virtual void Cut() ;
533 virtual void Paste() ;
534 virtual bool CanPaste() const ;
535 virtual void SetEditable( bool editable ) ;
536 virtual long GetLastPosition() const ;
537 virtual void Replace( long from, long to, const wxString &str ) ;
538 virtual void Remove( long from, long to ) ;
539
540
541 virtual bool HasOwnContextMenu() const
542 { return false ; }
543
544 virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) )
545 { return false ; }
546
547 virtual void Clear() ;
548 virtual bool CanUndo() const;
549 virtual void Undo() ;
550 virtual bool CanRedo() const;
551 virtual void Redo() ;
552 virtual int GetNumberOfLines() const ;
553 virtual long XYToPosition(long x, long y) const;
554 virtual bool PositionToXY(long pos, long *x, long *y) const ;
555 virtual void ShowPosition(long WXUNUSED(pos)) ;
556 virtual int GetLineLength(long lineNo) const ;
557 virtual wxString GetLineText(long lineNo) const ;
558 virtual void CheckSpelling(bool WXUNUSED(check)) { }
559 };
560
561 //
562 // common interface for search controls
563 //
564
565 class wxSearchWidgetImpl
566 {
567 public :
568 wxSearchWidgetImpl(){}
569 virtual ~wxSearchWidgetImpl(){}
570
571 // search field options
572 virtual void ShowSearchButton( bool show ) = 0;
573 virtual bool IsSearchButtonVisible() const = 0;
574
575 virtual void ShowCancelButton( bool show ) = 0;
576 virtual bool IsCancelButtonVisible() const = 0;
577
578 virtual void SetSearchMenu( wxMenu* menu ) = 0;
579
580 virtual void SetDescriptiveText(const wxString& text) = 0;
581 } ;
582
583 //
584 // toplevel window implementation class
585 //
586
587 class wxNonOwnedWindowImpl : public wxObject
588 {
589 public :
590 wxNonOwnedWindowImpl( wxNonOwnedWindow* nonownedwnd) : m_wxPeer(nonownedwnd)
591 {
592 }
593 wxNonOwnedWindowImpl()
594 {
595 }
596 virtual ~wxNonOwnedWindowImpl()
597 {
598 }
599
600 virtual void Destroy()
601 {
602 }
603
604 virtual void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
605 long style, long extraStyle, const wxString& name ) = 0;
606
607
608 virtual WXWindow GetWXWindow() const = 0;
609
610 virtual void Raise()
611 {
612 }
613
614 virtual void Lower()
615 {
616 }
617
618 virtual bool Show(bool WXUNUSED(show))
619 {
620 return false;
621 }
622
623 virtual bool ShowWithEffect(bool show, wxShowEffect WXUNUSED(effect), unsigned WXUNUSED(timeout))
624 {
625 return Show(show);
626 }
627
628 virtual void Update()
629 {
630 }
631
632 virtual bool SetTransparent(wxByte WXUNUSED(alpha))
633 {
634 return false;
635 }
636
637 virtual bool SetBackgroundColour(const wxColour& WXUNUSED(col) )
638 {
639 return false;
640 }
641
642 virtual void SetExtraStyle( long WXUNUSED(exStyle) )
643 {
644 }
645
646 virtual bool SetBackgroundStyle(wxBackgroundStyle WXUNUSED(style))
647 {
648 return false ;
649 }
650
651 bool CanSetTransparent()
652 {
653 return false;
654 }
655
656 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const = 0;
657 virtual void MoveWindow(int x, int y, int width, int height) = 0;
658 virtual void GetPosition( int &x, int &y ) const = 0;
659 virtual void GetSize( int &width, int &height ) const = 0;
660
661 virtual bool SetShape(const wxRegion& WXUNUSED(region))
662 {
663 return false;
664 }
665
666 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) = 0;
667
668 virtual bool IsMaximized() const = 0;
669
670 virtual bool IsIconized() const= 0;
671
672 virtual void Iconize( bool iconize )= 0;
673
674 virtual void Maximize(bool maximize) = 0;
675
676 virtual bool IsFullScreen() const= 0;
677
678 virtual bool ShowFullScreen(bool show, long style)= 0;
679
680 virtual void RequestUserAttention(int flags) = 0;
681
682 virtual void ScreenToWindow( int *x, int *y ) = 0;
683
684 virtual void WindowToScreen( int *x, int *y ) = 0;
685
686 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
687
688 // static creation methods, must be implemented by all toolkits
689
690 static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
691 long style, long extraStyle, const wxString& name ) ;
692
693 protected :
694 wxNonOwnedWindow* m_wxPeer;
695 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl)
696 };
697
698 #endif // wxUSE_GUI
699
700 //---------------------------------------------------------------------------
701 // cocoa bridging utilities
702 //---------------------------------------------------------------------------
703
704 bool wxMacInitCocoa();
705
706 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
707 {
708 public :
709 wxMacAutoreleasePool();
710 ~wxMacAutoreleasePool();
711 private :
712 void* m_pool;
713 };
714
715 // NSObject
716
717 void wxMacCocoaRelease( void* obj );
718 void wxMacCocoaAutorelease( void* obj );
719 void wxMacCocoaRetain( void* obj );
720
721
722 #endif
723 // _WX_PRIVATE_CORE_H_