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
6 // Author: Stefan Csomor
9 // RCS-ID: $Id: private.h 53819 2008-05-29 14:11:45Z SC $
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_COCOA_H_
15 #define _WX_PRIVATE_COCOA_H_
17 #include "wx/osx/core/private.h"
21 #include <ApplicationServices/ApplicationServices.h>
23 #if wxOSX_USE_ATSU_TEXT
24 // we need theming and atsu
25 #include <Carbon/Carbon.h>
29 #import <Cocoa/Cocoa.h>
33 // shared between Cocoa and Carbon
36 // bring in themeing types without pulling in the headers
39 typedef SInt16 ThemeBrush
;
40 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
41 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
42 CGContextRef inContext
,
43 const CGRect
* inBounds
,
45 WX_NSImage WXDLLIMPEXP_CORE
wxOSXCreateNSImageFromCGImage( CGImageRef image
);
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
);
60 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
63 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
69 virtual bool IsVisible() const ;
70 virtual void SetVisibility(bool);
76 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
78 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
80 virtual void SetBackgroundColour(const wxColour
&);
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
);
88 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
89 virtual bool GetNeedsDisplay() const;
91 virtual bool CanFocus() const;
92 // return true if successful
93 virtual bool SetFocus();
94 virtual bool HasFocus() const;
96 void RemoveFromParent();
97 void Embed( wxWidgetImpl
*parent
);
99 void SetDefaultButton( bool isDefault
);
101 void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
103 void SetCursor( const wxCursor
& cursor
);
107 wxInt32
GetValue() const;
108 void SetValue( wxInt32 v
);
109 void SetBitmap( const wxBitmap
& bitmap
);
110 void SetupTabs( const wxNotebook
¬ebook
);
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;
120 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
122 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
124 void InstallEventHandler( WXWidget control
= NULL
);
126 virtual bool DoHandleMouseEvent(NSEvent
*event
);
127 virtual bool DoHandleKeyEvent(NSEvent
*event
);
128 virtual void DoNotifyFocusEvent(bool receivedFocus
);
132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
135 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
137 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
140 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
141 wxNonOwnedWindowCocoaImpl();
143 virtual ~wxNonOwnedWindowCocoaImpl();
145 virtual void Destroy() ;
146 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
147 long style
, long extraStyle
, const wxString
& name
) ;
149 WXWindow
GetWXWindow() const;
152 bool Show(bool show
);
153 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
156 bool SetTransparent(wxByte alpha
);
157 bool SetBackgroundColour(const wxColour
& col
);
158 void SetExtraStyle( long exStyle
);
159 bool SetBackgroundStyle(wxBackgroundStyle style
);
160 bool CanSetTransparent();
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;
166 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
167 bool SetShape(const wxRegion
& region
);
169 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
171 virtual bool IsMaximized() const;
173 virtual bool IsIconized() const;
175 virtual void Iconize( bool iconize
);
177 virtual void Maximize(bool maximize
);
179 virtual bool IsFullScreen() const;
181 virtual bool ShowFullScreen(bool show
, long style
);
183 virtual void RequestUserAttention(int flags
);
185 virtual void ScreenToWindow( int *x
, int *y
);
187 virtual void WindowToScreen( int *x
, int *y
);
189 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
191 WX_wxNSWindow m_macWindow
;
192 void * m_macFullScreenData
;
193 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
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
);
203 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
204 bool adjustForOrigin
= true );
206 // common code snippets for cocoa implementations
207 // later to be done using injection in method table
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;
231 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN -(void)rightMouseDown:(NSEvent *)event\
233 if ( !impl->DoHandleMouseEvent(event) )\
234 [super rightMouseDown:event];\
236 -(void)otherMouseDown:(NSEvent *)event\
238 if ( !impl->DoHandleMouseEvent(event) )\
239 [super otherMouseDown:event];\
241 -(void)mouseUp:(NSEvent *)event\
243 if ( !impl->DoHandleMouseEvent(event) )\
244 [super mouseUp:event];\
246 -(void)rightMouseUp:(NSEvent *)event\
248 if ( !impl->DoHandleMouseEvent(event) )\
249 [super rightMouseUp:event];\
251 -(void)otherMouseUp:(NSEvent *)event\
253 if ( !impl->DoHandleMouseEvent(event) )\
254 [super otherMouseUp:event];\
256 -(void)mouseMoved:(NSEvent *)event\
258 if ( !impl->DoHandleMouseEvent(event) )\
259 [super mouseMoved:event];\
261 -(void)mouseDragged:(NSEvent *)event\
263 if ( !impl->DoHandleMouseEvent(event) )\
264 [super mouseDragged:event];\
266 -(void)rightMouseDragged:(NSEvent *)event\
268 if ( !impl->DoHandleMouseEvent(event) )\
269 [super rightMouseDragged:event];\
271 -(void)otherMouseDragged:(NSEvent *)event\
273 if ( !impl->DoHandleMouseEvent(event) )\
274 [super otherMouseDragged:event];\
276 -(void)scrollWheel:(NSEvent *)event\
278 if ( !impl->DoHandleMouseEvent(event) )\
279 [super scrollWheel:event];\
281 -(void)mouseEntered:(NSEvent *)event\
283 if ( !impl->DoHandleMouseEvent(event) )\
284 [super mouseEntered:event];\
286 -(void)mouseExited:(NSEvent *)event\
288 if ( !impl->DoHandleMouseEvent(event) )\
289 [super mouseExited:event];\
291 -(BOOL)performKeyEquivalent:(NSEvent *)event\
293 if ( !impl->DoHandleKeyEvent(event) )\
294 return [super performKeyEquivalent:event];\
297 -(void)keyDown:(NSEvent *)event\
299 if ( !impl->DoHandleKeyEvent(event) )\
300 [super keyDown:event];\
302 -(void)keyUp:(NSEvent *)event\
304 if ( !impl->DoHandleKeyEvent(event) )\
305 [super keyUp:event];\
307 -(void)flagsChanged:(NSEvent *)event\
309 if ( !impl->DoHandleKeyEvent(event) )\
310 [super flagsChanged:event];\
312 - (BOOL) becomeFirstResponder\
314 BOOL r = [super becomeFirstResponder];\
316 impl->DoNotifyFocusEvent( true );\
319 - (BOOL) resignFirstResponder\
321 BOOL r = [super resignFirstResponder];\
323 impl->DoNotifyFocusEvent( false );\
326 - (void) resetCursorRects\
330 wxWindow* wxpeer = impl->GetWXPeer();\
333 NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\
335 [super resetCursorRects];\
337 [self addCursorRect: [self bounds]\
343 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
345 if ( !impl->DoHandleMouseEvent(event) )\
346 [super mouseDown:event];\
348 WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN
350 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
352 #define WXCOCOAIMPL_COMMON_INTERFACE \
353 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
354 - (wxWidgetCocoaImpl*) implementation;\
356 WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
358 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
360 impl = theImplementation;\
362 - (wxWidgetCocoaImpl*) implementation\
367 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
368 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
374 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \
375 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
382 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
383 WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
389 // used for many wxControls
391 @interface wxNSButton
: NSButton
393 WXCOCOAIMPL_COMMON_MEMBERS
396 WXCOCOAIMPL_COMMON_INTERFACE
397 - (void) clickedAction
: (id
) sender
;
401 @interface wxNSBox
: NSBox
403 WXCOCOAIMPL_COMMON_MEMBERS
406 WXCOCOAIMPL_COMMON_INTERFACE
410 @interface wxNSTextField
: NSTextField
412 WXCOCOAIMPL_COMMON_MEMBERS
415 WXCOCOAIMPL_COMMON_INTERFACE
419 @interface wxNSMenu
: NSMenu
424 - (void) setImplementation
:(wxMenuImpl
*) item
;
425 - (wxMenuImpl
*) implementation
;
429 @interface wxNSMenuItem
: NSMenuItem
431 wxMenuItemImpl
* impl
;
434 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
435 - (wxMenuItemImpl
*) implementation
;
437 - (void)clickedAction
:(id
)sender
;
438 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
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();
452 typedef struct tagClassicCursor
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
;
476 // exposing our fallback cursor map
478 extern ClassicCursor gMacCursors
[];
483 // _WX_PRIVATE_COCOA_H_