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 wxInt32
GetValue() const;
104 void SetValue( wxInt32 v
);
105 void SetBitmap( const wxBitmap
& bitmap
);
106 void SetupTabs( const wxNotebook
¬ebook
);
107 void GetBestRect( wxRect
*r
) const;
108 bool IsEnabled() const;
109 void Enable( bool enable
);
110 bool ButtonClickDidStateChange() { return true ;}
111 void SetMinimum( wxInt32 v
);
112 void SetMaximum( wxInt32 v
);
114 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
116 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
118 void InstallEventHandler( WXWidget control
= NULL
);
120 virtual bool DoHandleMouseEvent(NSEvent
*event
);
121 virtual bool DoHandleKeyEvent(NSEvent
*event
);
125 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
128 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
130 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
133 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
134 wxNonOwnedWindowCocoaImpl();
136 virtual ~wxNonOwnedWindowCocoaImpl();
138 virtual void Destroy() ;
139 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
140 long style
, long extraStyle
, const wxString
& name
) ;
142 WXWindow
GetWXWindow() const;
145 bool Show(bool show
);
146 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
149 bool SetTransparent(wxByte alpha
);
150 bool SetBackgroundColour(const wxColour
& col
);
151 void SetExtraStyle( long exStyle
);
152 bool SetBackgroundStyle(wxBackgroundStyle style
);
153 bool CanSetTransparent();
155 void MoveWindow(int x
, int y
, int width
, int height
);
156 void GetPosition( int &x
, int &y
) const;
157 void GetSize( int &width
, int &height
) const;
159 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
160 bool SetShape(const wxRegion
& region
);
162 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
164 virtual bool IsMaximized() const;
166 virtual bool IsIconized() const;
168 virtual void Iconize( bool iconize
);
170 virtual void Maximize(bool maximize
);
172 virtual bool IsFullScreen() const;
174 virtual bool ShowFullScreen(bool show
, long style
);
176 virtual void RequestUserAttention(int flags
);
178 virtual void ScreenToWindow( int *x
, int *y
);
180 virtual void WindowToScreen( int *x
, int *y
);
182 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
184 WX_wxNSWindow m_macWindow
;
185 void * m_macFullScreenData
;
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
191 extern NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
192 extern wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
193 extern NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
194 extern wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
196 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
197 bool adjustForOrigin
= true );
199 // common code snippets for cocoa implementations
200 // later to be done using injection in method table
202 #define WXCOCOAIMPL_COMMON_MOUSE_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
203 -(void)rightMouseDown:(NSEvent *)event ;\
204 -(void)otherMouseDown:(NSEvent *)event ;\
205 -(void)mouseUp:(NSEvent *)event ;\
206 -(void)rightMouseUp:(NSEvent *)event ;\
207 -(void)otherMouseUp:(NSEvent *)event ;\
208 - (void)keyDown:(NSEvent *)event;\
209 - (void)keyUp:(NSEvent *)event;\
210 - (void)flagsChanged:(NSEvent *)event;\
212 #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
214 if ( !impl->DoHandleMouseEvent(event) )\
215 [super mouseDown:event];\
217 -(void)rightMouseDown:(NSEvent *)event\
219 if ( !impl->DoHandleMouseEvent(event) )\
220 [super rightMouseDown:event];\
222 -(void)otherMouseDown:(NSEvent *)event\
224 if ( !impl->DoHandleMouseEvent(event) )\
225 [super otherMouseDown:event];\
227 -(void)mouseUp:(NSEvent *)event\
229 if ( !impl->DoHandleMouseEvent(event) )\
230 [super mouseUp:event];\
232 -(void)rightMouseUp:(NSEvent *)event\
234 if ( !impl->DoHandleMouseEvent(event) )\
235 [super rightMouseUp:event];\
237 -(void)otherMouseUp:(NSEvent *)event\
239 if ( !impl->DoHandleMouseEvent(event) )\
240 [super otherMouseUp:event];\
242 -(void)keyDown:(NSEvent *)event\
244 if ( !impl->DoHandleKeyEvent(event) )\
245 [super keyDown:event];\
247 -(void)keyUp:(NSEvent *)event\
249 if ( !impl->DoHandleKeyEvent(event) )\
250 [super keyUp:event];\
252 -(void)flagsChanged:(NSEvent *)event\
254 if ( !impl->DoHandleKeyEvent(event) )\
255 [super flagsChanged:event];\
258 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
260 #define WXCOCOAIMPL_COMMON_INTERFACE \
261 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
262 - (wxWidgetCocoaImpl*) implementation;\
264 WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
266 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION \
267 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
269 impl = theImplementation;\
271 - (wxWidgetCocoaImpl*) implementation\
280 // used for many wxControls
282 @interface wxNSButton
: NSButton
284 WXCOCOAIMPL_COMMON_MEMBERS
287 WXCOCOAIMPL_COMMON_INTERFACE
288 - (void) clickedAction
: (id
) sender
;
292 @interface wxNSBox
: NSBox
294 WXCOCOAIMPL_COMMON_MEMBERS
297 WXCOCOAIMPL_COMMON_INTERFACE
301 @interface wxNSTextField
: NSTextField
303 WXCOCOAIMPL_COMMON_MEMBERS
306 WXCOCOAIMPL_COMMON_INTERFACE
310 @interface wxNSMenu
: NSMenu
315 - (void) setImplementation
:(wxMenuImpl
*) item
;
316 - (wxMenuImpl
*) implementation
;
320 @interface wxNSMenuItem
: NSMenuItem
322 wxMenuItemImpl
* impl
;
325 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
326 - (wxMenuItemImpl
*) implementation
;
328 - (void)clickedAction
:(id
)sender
;
329 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
337 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
338 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
339 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
340 void wxMacCocoaHideCursor();
341 void wxMacCocoaShowCursor();
343 typedef struct tagClassicCursor
350 const short kwxCursorBullseye
= 0;
351 const short kwxCursorBlank
= 1;
352 const short kwxCursorPencil
= 2;
353 const short kwxCursorMagnifier
= 3;
354 const short kwxCursorNoEntry
= 4;
355 const short kwxCursorPaintBrush
= 5;
356 const short kwxCursorPointRight
= 6;
357 const short kwxCursorPointLeft
= 7;
358 const short kwxCursorQuestionArrow
= 8;
359 const short kwxCursorRightArrow
= 9;
360 const short kwxCursorSizeNS
= 10;
361 const short kwxCursorSize
= 11;
362 const short kwxCursorSizeNESW
= 12;
363 const short kwxCursorSizeNWSE
= 13;
364 const short kwxCursorRoller
= 14;
365 const short kwxCursorLast
= kwxCursorRoller
;
367 // exposing our fallback cursor map
369 extern ClassicCursor gMacCursors
[];
374 // _WX_PRIVATE_COCOA_H_