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
);
118 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
120 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
122 void InstallEventHandler( WXWidget control
= NULL
);
124 virtual bool DoHandleMouseEvent(NSEvent
*event
);
125 virtual bool DoHandleKeyEvent(NSEvent
*event
);
126 virtual void DoNotifyFocusEvent(bool receivedFocus
);
130 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
133 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
135 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
138 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
139 wxNonOwnedWindowCocoaImpl();
141 virtual ~wxNonOwnedWindowCocoaImpl();
143 virtual void Destroy() ;
144 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
145 long style
, long extraStyle
, const wxString
& name
) ;
147 WXWindow
GetWXWindow() const;
150 bool Show(bool show
);
151 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
154 bool SetTransparent(wxByte alpha
);
155 bool SetBackgroundColour(const wxColour
& col
);
156 void SetExtraStyle( long exStyle
);
157 bool SetBackgroundStyle(wxBackgroundStyle style
);
158 bool CanSetTransparent();
160 void MoveWindow(int x
, int y
, int width
, int height
);
161 void GetPosition( int &x
, int &y
) const;
162 void GetSize( int &width
, int &height
) const;
164 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
165 bool SetShape(const wxRegion
& region
);
167 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
169 virtual bool IsMaximized() const;
171 virtual bool IsIconized() const;
173 virtual void Iconize( bool iconize
);
175 virtual void Maximize(bool maximize
);
177 virtual bool IsFullScreen() const;
179 virtual bool ShowFullScreen(bool show
, long style
);
181 virtual void RequestUserAttention(int flags
);
183 virtual void ScreenToWindow( int *x
, int *y
);
185 virtual void WindowToScreen( int *x
, int *y
);
187 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
189 WX_wxNSWindow m_macWindow
;
190 void * m_macFullScreenData
;
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
196 extern NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
197 extern wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
198 extern NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
199 extern wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
201 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
202 bool adjustForOrigin
= true );
204 // common code snippets for cocoa implementations
205 // later to be done using injection in method table
207 #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
208 - (void)rightMouseDown:(NSEvent *)event ;\
209 - (void)otherMouseDown:(NSEvent *)event ;\
210 - (void)mouseUp:(NSEvent *)event ;\
211 - (void)rightMouseUp:(NSEvent *)event ;\
212 - (void)otherMouseUp:(NSEvent *)event ;\
213 - (void)mouseMoved:(NSEvent *)event;\
214 - (void)mouseDragged:(NSEvent *)event;\
215 - (void)rightMouseDragged:(NSEvent *)event;\
216 - (void)otherMouseDragged:(NSEvent *)event;\
217 - (void)scrollWheel:(NSEvent *)theEvent;\
218 - (void)mouseEntered:(NSEvent *)event;\
219 - (void)mouseExited:(NSEvent *)event;\
220 - (void)keyDown:(NSEvent *)event;\
221 - (void)keyUp:(NSEvent *)event;\
222 - (void)flagsChanged:(NSEvent *)event;\
223 - (BOOL) becomeFirstResponder;\
224 - (BOOL) resignFirstResponder;
226 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
228 if ( !impl->DoHandleMouseEvent(event) )\
229 [super mouseDown:event];\
231 -(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 -(void)keyDown:(NSEvent *)event\
293 if ( !impl->DoHandleKeyEvent(event) )\
294 [super keyDown:event];\
296 -(void)keyUp:(NSEvent *)event\
298 if ( !impl->DoHandleKeyEvent(event) )\
299 [super keyUp:event];\
301 -(void)flagsChanged:(NSEvent *)event\
303 if ( !impl->DoHandleKeyEvent(event) )\
304 [super flagsChanged:event];\
306 - (BOOL) becomeFirstResponder\
308 BOOL r = [super becomeFirstResponder];\
310 impl->DoNotifyFocusEvent( true );\
313 - (BOOL) resignFirstResponder\
315 BOOL r = [super resignFirstResponder];\
317 impl->DoNotifyFocusEvent( false );\
321 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
323 #define WXCOCOAIMPL_COMMON_INTERFACE \
324 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
325 - (wxWidgetCocoaImpl*) implementation;\
327 WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
329 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
330 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
332 impl = theImplementation;\
334 - (wxWidgetCocoaImpl*) implementation\
343 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
344 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
346 impl = theImplementation;\
348 - (wxWidgetCocoaImpl*) implementation\
357 // used for many wxControls
359 @interface wxNSButton
: NSButton
361 WXCOCOAIMPL_COMMON_MEMBERS
364 WXCOCOAIMPL_COMMON_INTERFACE
365 - (void) clickedAction
: (id
) sender
;
369 @interface wxNSBox
: NSBox
371 WXCOCOAIMPL_COMMON_MEMBERS
374 WXCOCOAIMPL_COMMON_INTERFACE
378 @interface wxNSTextField
: NSTextField
380 WXCOCOAIMPL_COMMON_MEMBERS
383 WXCOCOAIMPL_COMMON_INTERFACE
387 @interface wxNSMenu
: NSMenu
392 - (void) setImplementation
:(wxMenuImpl
*) item
;
393 - (wxMenuImpl
*) implementation
;
397 @interface wxNSMenuItem
: NSMenuItem
399 wxMenuItemImpl
* impl
;
402 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
403 - (wxMenuItemImpl
*) implementation
;
405 - (void)clickedAction
:(id
)sender
;
406 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
414 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
415 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
416 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
417 void wxMacCocoaHideCursor();
418 void wxMacCocoaShowCursor();
420 typedef struct tagClassicCursor
427 const short kwxCursorBullseye
= 0;
428 const short kwxCursorBlank
= 1;
429 const short kwxCursorPencil
= 2;
430 const short kwxCursorMagnifier
= 3;
431 const short kwxCursorNoEntry
= 4;
432 const short kwxCursorPaintBrush
= 5;
433 const short kwxCursorPointRight
= 6;
434 const short kwxCursorPointLeft
= 7;
435 const short kwxCursorQuestionArrow
= 8;
436 const short kwxCursorRightArrow
= 9;
437 const short kwxCursorSizeNS
= 10;
438 const short kwxCursorSize
= 11;
439 const short kwxCursorSizeNESW
= 12;
440 const short kwxCursorSizeNWSE
= 13;
441 const short kwxCursorRoller
= 14;
442 const short kwxCursorLast
= kwxCursorRoller
;
444 // exposing our fallback cursor map
446 extern ClassicCursor gMacCursors
[];
451 // _WX_PRIVATE_COCOA_H_