]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
Give some OSX specific methods OSX prefix, fixes hidden virtual method warning elsewhere
[wxWidgets.git] / include / wx / osx / cocoa / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/cocoa/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_COCOA_H_
15 #define _WX_PRIVATE_COCOA_H_
16
17 #include "wx/osx/core/private.h"
18
19 #include "wx/defs.h"
20
21 #include <ApplicationServices/ApplicationServices.h>
22
23 #if wxOSX_USE_ATSU_TEXT
24 // we need theming and atsu
25 #include <Carbon/Carbon.h>
26 #endif
27
28 #ifdef __OBJC__
29 #import <Cocoa/Cocoa.h>
30 #endif
31
32 //
33 // shared between Cocoa and Carbon
34 //
35
36 // bring in themeing types without pulling in the headers
37
38 #if wxUSE_GUI
39 typedef SInt16 ThemeBrush;
40 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
41 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
42 CGContextRef inContext,
43 const CGRect * inBounds,
44 CGImageRef inImage) ;
45 WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image );
46 #endif
47
48 long UMAGetSystemVersion() ;
49 WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
50 WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
51 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
52 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
53
54 //
55 //
56 //
57
58 #if wxUSE_GUI
59
60 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
61 {
62 public :
63 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ;
64 wxWidgetCocoaImpl() ;
65 ~wxWidgetCocoaImpl();
66
67 void Init();
68
69 virtual bool IsVisible() const ;
70 virtual void SetVisibility(bool);
71
72 virtual void Raise();
73
74 virtual void Lower();
75
76 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
77
78 virtual WXWidget GetWXWidget() const { return m_osxView; }
79
80 virtual void SetBackgroundColour(const wxColour&);
81
82 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const;
83 virtual void Move(int x, int y, int width, int height);
84 virtual void GetPosition( int &x, int &y ) const;
85 virtual void GetSize( int &width, int &height ) const;
86 virtual void SetControlSize( wxWindowVariant variant );
87
88 virtual void SetNeedsDisplay( const wxRect* where = NULL );
89 virtual bool GetNeedsDisplay() const;
90
91 virtual bool CanFocus() const;
92 // return true if successful
93 virtual bool SetFocus();
94 virtual bool HasFocus() const;
95
96 void RemoveFromParent();
97 void Embed( wxWidgetImpl *parent );
98
99 void SetDefaultButton( bool isDefault );
100 void PerformClick();
101 void SetLabel(const wxString& title, wxFontEncoding encoding);
102
103 void SetCursor( const wxCursor & cursor );
104 void CaptureMouse();
105 void ReleaseMouse();
106
107 wxInt32 GetValue() const;
108 void SetValue( wxInt32 v );
109 void SetBitmap( const wxBitmap& bitmap );
110 void SetupTabs( const wxNotebook &notebook );
111 void GetBestRect( wxRect *r ) const;
112 bool IsEnabled() const;
113 void Enable( bool enable );
114 bool ButtonClickDidStateChange() { return true ;}
115 void SetMinimum( wxInt32 v );
116 void SetMaximum( wxInt32 v );
117 wxInt32 GetMinimum() const;
118 wxInt32 GetMaximum() const;
119 void PulseGauge();
120 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
121
122 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
123
124 void InstallEventHandler( WXWidget control = NULL );
125
126 virtual bool DoHandleMouseEvent(NSEvent *event);
127 virtual bool DoHandleKeyEvent(NSEvent *event);
128 virtual void DoNotifyFocusEvent(bool receivedFocus);
129
130 protected:
131 WXWidget m_osxView;
132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
133 };
134
135 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
136
137 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
138 {
139 public :
140 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
141 wxNonOwnedWindowCocoaImpl();
142
143 virtual ~wxNonOwnedWindowCocoaImpl();
144
145 virtual void Destroy() ;
146 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
147 long style, long extraStyle, const wxString& name ) ;
148
149 WXWindow GetWXWindow() const;
150 void Raise();
151 void Lower();
152 bool Show(bool show);
153 bool ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout);
154
155 void Update();
156 bool SetTransparent(wxByte alpha);
157 bool SetBackgroundColour(const wxColour& col );
158 void SetExtraStyle( long exStyle );
159 bool SetBackgroundStyle(wxBackgroundStyle style);
160 bool CanSetTransparent();
161
162 void MoveWindow(int x, int y, int width, int height);
163 void GetPosition( int &x, int &y ) const;
164 void GetSize( int &width, int &height ) const;
165
166 void GetContentArea( int &left , int &top , int &width , int &height ) const;
167 bool SetShape(const wxRegion& region);
168
169 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
170
171 virtual bool IsMaximized() const;
172
173 virtual bool IsIconized() const;
174
175 virtual void Iconize( bool iconize );
176
177 virtual void Maximize(bool maximize);
178
179 virtual bool IsFullScreen() const;
180
181 virtual bool ShowFullScreen(bool show, long style);
182
183 virtual void RequestUserAttention(int flags);
184
185 virtual void ScreenToWindow( int *x, int *y );
186
187 virtual void WindowToScreen( int *x, int *y );
188
189 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
190 protected :
191 WX_wxNSWindow m_macWindow;
192 void * m_macFullScreenData ;
193 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
194 };
195
196 #ifdef __OBJC__
197
198 extern NSRect wxToNSRect( NSView* parent, const wxRect& r );
199 extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
200 extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
201 extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
202
203 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
204 bool adjustForOrigin = true );
205
206 // common code snippets for cocoa implementations
207 // later to be done using injection in method table
208
209 #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
210 - (void)rightMouseDown:(NSEvent *)event ;\
211 - (void)otherMouseDown:(NSEvent *)event ;\
212 - (void)mouseUp:(NSEvent *)event ;\
213 - (void)rightMouseUp:(NSEvent *)event ;\
214 - (void)otherMouseUp:(NSEvent *)event ;\
215 - (void)mouseMoved:(NSEvent *)event;\
216 - (void)mouseDragged:(NSEvent *)event;\
217 - (void)rightMouseDragged:(NSEvent *)event;\
218 - (void)otherMouseDragged:(NSEvent *)event;\
219 - (void)scrollWheel:(NSEvent *)theEvent;\
220 - (void)mouseEntered:(NSEvent *)event;\
221 - (void)mouseExited:(NSEvent *)event;\
222 - (void)keyDown:(NSEvent *)event;\
223 - (void)keyUp:(NSEvent *)event;\
224 - (BOOL)performKeyEquivalent:(NSEvent *)event;\
225 - (void)flagsChanged:(NSEvent *)event;\
226 - (BOOL)becomeFirstResponder;\
227 - (BOOL)resignFirstResponder;\
228 - (void)resetCursorRects;
229
230
231 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN -(void)rightMouseDown:(NSEvent *)event\
232 {\
233 if ( !impl->DoHandleMouseEvent(event) )\
234 [super rightMouseDown:event];\
235 }\
236 -(void)otherMouseDown:(NSEvent *)event\
237 {\
238 if ( !impl->DoHandleMouseEvent(event) )\
239 [super otherMouseDown:event];\
240 }\
241 -(void)mouseUp:(NSEvent *)event\
242 {\
243 if ( !impl->DoHandleMouseEvent(event) )\
244 [super mouseUp:event];\
245 }\
246 -(void)rightMouseUp:(NSEvent *)event\
247 {\
248 if ( !impl->DoHandleMouseEvent(event) )\
249 [super rightMouseUp:event];\
250 }\
251 -(void)otherMouseUp:(NSEvent *)event\
252 {\
253 if ( !impl->DoHandleMouseEvent(event) )\
254 [super otherMouseUp:event];\
255 }\
256 -(void)mouseMoved:(NSEvent *)event\
257 {\
258 if ( !impl->DoHandleMouseEvent(event) )\
259 [super mouseMoved:event];\
260 }\
261 -(void)mouseDragged:(NSEvent *)event\
262 {\
263 if ( !impl->DoHandleMouseEvent(event) )\
264 [super mouseDragged:event];\
265 }\
266 -(void)rightMouseDragged:(NSEvent *)event\
267 {\
268 if ( !impl->DoHandleMouseEvent(event) )\
269 [super rightMouseDragged:event];\
270 }\
271 -(void)otherMouseDragged:(NSEvent *)event\
272 {\
273 if ( !impl->DoHandleMouseEvent(event) )\
274 [super otherMouseDragged:event];\
275 }\
276 -(void)scrollWheel:(NSEvent *)event\
277 {\
278 if ( !impl->DoHandleMouseEvent(event) )\
279 [super scrollWheel:event];\
280 }\
281 -(void)mouseEntered:(NSEvent *)event\
282 {\
283 if ( !impl->DoHandleMouseEvent(event) )\
284 [super mouseEntered:event];\
285 }\
286 -(void)mouseExited:(NSEvent *)event\
287 {\
288 if ( !impl->DoHandleMouseEvent(event) )\
289 [super mouseExited:event];\
290 }\
291 -(BOOL)performKeyEquivalent:(NSEvent *)event\
292 {\
293 if ( !impl->DoHandleKeyEvent(event) )\
294 return [super performKeyEquivalent:event];\
295 return YES;\
296 }\
297 -(void)keyDown:(NSEvent *)event\
298 {\
299 if ( !impl->DoHandleKeyEvent(event) )\
300 [super keyDown:event];\
301 }\
302 -(void)keyUp:(NSEvent *)event\
303 {\
304 if ( !impl->DoHandleKeyEvent(event) )\
305 [super keyUp:event];\
306 }\
307 -(void)flagsChanged:(NSEvent *)event\
308 {\
309 if ( !impl->DoHandleKeyEvent(event) )\
310 [super flagsChanged:event];\
311 }\
312 - (BOOL) becomeFirstResponder\
313 {\
314 BOOL r = [super becomeFirstResponder];\
315 if ( r )\
316 impl->DoNotifyFocusEvent( true );\
317 return r;\
318 }\
319 - (BOOL) resignFirstResponder\
320 {\
321 BOOL r = [super resignFirstResponder];\
322 if ( r )\
323 impl->DoNotifyFocusEvent( false );\
324 return r;\
325 }\
326 - (void) resetCursorRects\
327 {\
328 if ( impl )\
329 {\
330 wxWindow* wxpeer = impl->GetWXPeer();\
331 if ( wxpeer )\
332 {\
333 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\
334 if (cursor == NULL)\
335 [super resetCursorRects];\
336 else\
337 [self addCursorRect: [self bounds]\
338 cursor: cursor];\
339 }\
340 }\
341 }
342
343 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
344 {\
345 if ( !impl->DoHandleMouseEvent(event) )\
346 [super mouseDown:event];\
347 }\
348 WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN
349
350 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
351
352 #define WXCOCOAIMPL_COMMON_INTERFACE \
353 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
354 - (wxWidgetCocoaImpl*) implementation;\
355 - (BOOL) isFlipped;\
356 WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
357
358 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
359 {\
360 impl = theImplementation;\
361 }\
362 - (wxWidgetCocoaImpl*) implementation\
363 {\
364 return impl;\
365 }\
366
367 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
368 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
369 - (BOOL) isFlipped\
370 {\
371 return YES;\
372 }
373
374 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \
375 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
376 - (BOOL) isFlipped\
377 {\
378 return YES;\
379 }
380
381
382 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
383 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
384 - (BOOL) isFlipped\
385 {\
386 return NO;\
387 }
388
389 // used for many wxControls
390
391 @interface wxNSButton : NSButton
392 {
393 WXCOCOAIMPL_COMMON_MEMBERS
394 }
395
396 WXCOCOAIMPL_COMMON_INTERFACE
397 - (void) clickedAction: (id) sender;
398
399 @end
400
401 @interface wxNSBox : NSBox
402 {
403 WXCOCOAIMPL_COMMON_MEMBERS
404 }
405
406 WXCOCOAIMPL_COMMON_INTERFACE
407
408 @end
409
410 @interface wxNSTextField : NSTextField
411 {
412 WXCOCOAIMPL_COMMON_MEMBERS
413 }
414
415 WXCOCOAIMPL_COMMON_INTERFACE
416
417 @end
418
419 @interface wxNSMenu : NSMenu
420 {
421 wxMenuImpl* impl;
422 }
423
424 - (void) setImplementation:(wxMenuImpl*) item;
425 - (wxMenuImpl*) implementation;
426
427 @end
428
429 @interface wxNSMenuItem : NSMenuItem
430 {
431 wxMenuItemImpl* impl;
432 }
433
434 - (void) setImplementation:(wxMenuItemImpl*) item;
435 - (wxMenuItemImpl*) implementation;
436
437 - (void)clickedAction:(id)sender;
438 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
439
440 @end
441
442 #endif // __OBJC__
443
444 // NSCursor
445
446 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
447 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
448 void wxMacCocoaSetCursor( WX_NSCursor cursor );
449 void wxMacCocoaHideCursor();
450 void wxMacCocoaShowCursor();
451
452 typedef struct tagClassicCursor
453 {
454 wxUint16 bits[16];
455 wxUint16 mask[16];
456 wxInt16 hotspot[2];
457 }ClassicCursor;
458
459 const short kwxCursorBullseye = 0;
460 const short kwxCursorBlank = 1;
461 const short kwxCursorPencil = 2;
462 const short kwxCursorMagnifier = 3;
463 const short kwxCursorNoEntry = 4;
464 const short kwxCursorPaintBrush = 5;
465 const short kwxCursorPointRight = 6;
466 const short kwxCursorPointLeft = 7;
467 const short kwxCursorQuestionArrow = 8;
468 const short kwxCursorRightArrow = 9;
469 const short kwxCursorSizeNS = 10;
470 const short kwxCursorSize = 11;
471 const short kwxCursorSizeNESW = 12;
472 const short kwxCursorSizeNWSE = 13;
473 const short kwxCursorRoller = 14;
474 const short kwxCursorLast = kwxCursorRoller;
475
476 // exposing our fallback cursor map
477
478 extern ClassicCursor gMacCursors[];
479
480 #endif
481
482 #endif
483 // _WX_PRIVATE_COCOA_H_
484