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