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
);
122 virtual void DoNotifyFocusEvent(bool receivedFocus
);
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
129 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
131 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
134 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
135 wxNonOwnedWindowCocoaImpl();
137 virtual ~wxNonOwnedWindowCocoaImpl();
139 virtual void Destroy() ;
140 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
141 long style
, long extraStyle
, const wxString
& name
) ;
143 WXWindow
GetWXWindow() const;
146 bool Show(bool show
);
147 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
150 bool SetTransparent(wxByte alpha
);
151 bool SetBackgroundColour(const wxColour
& col
);
152 void SetExtraStyle( long exStyle
);
153 bool SetBackgroundStyle(wxBackgroundStyle style
);
154 bool CanSetTransparent();
156 void MoveWindow(int x
, int y
, int width
, int height
);
157 void GetPosition( int &x
, int &y
) const;
158 void GetSize( int &width
, int &height
) const;
160 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
161 bool SetShape(const wxRegion
& region
);
163 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
165 virtual bool IsMaximized() const;
167 virtual bool IsIconized() const;
169 virtual void Iconize( bool iconize
);
171 virtual void Maximize(bool maximize
);
173 virtual bool IsFullScreen() const;
175 virtual bool ShowFullScreen(bool show
, long style
);
177 virtual void RequestUserAttention(int flags
);
179 virtual void ScreenToWindow( int *x
, int *y
);
181 virtual void WindowToScreen( int *x
, int *y
);
183 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
185 WX_wxNSWindow m_macWindow
;
186 void * m_macFullScreenData
;
187 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
192 extern NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
193 extern wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
194 extern NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
195 extern wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
197 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
198 bool adjustForOrigin
= true );
200 // common code snippets for cocoa implementations
201 // later to be done using injection in method table
203 #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
204 -(void)rightMouseDown:(NSEvent *)event ;\
205 -(void)otherMouseDown:(NSEvent *)event ;\
206 -(void)mouseUp:(NSEvent *)event ;\
207 -(void)rightMouseUp:(NSEvent *)event ;\
208 -(void)otherMouseUp:(NSEvent *)event ;\
209 - (void)keyDown:(NSEvent *)event;\
210 - (void)keyUp:(NSEvent *)event;\
211 - (void)flagsChanged:(NSEvent *)event;\
212 - (BOOL) becomeFirstResponder;\
213 - (BOOL) resignFirstResponder;
215 #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
217 if ( !impl->DoHandleMouseEvent(event) )\
218 [super mouseDown:event];\
220 -(void)rightMouseDown:(NSEvent *)event\
222 if ( !impl->DoHandleMouseEvent(event) )\
223 [super rightMouseDown:event];\
225 -(void)otherMouseDown:(NSEvent *)event\
227 if ( !impl->DoHandleMouseEvent(event) )\
228 [super otherMouseDown:event];\
230 -(void)mouseUp:(NSEvent *)event\
232 if ( !impl->DoHandleMouseEvent(event) )\
233 [super mouseUp:event];\
235 -(void)rightMouseUp:(NSEvent *)event\
237 if ( !impl->DoHandleMouseEvent(event) )\
238 [super rightMouseUp:event];\
240 -(void)otherMouseUp:(NSEvent *)event\
242 if ( !impl->DoHandleMouseEvent(event) )\
243 [super otherMouseUp:event];\
245 -(void)keyDown:(NSEvent *)event\
247 if ( !impl->DoHandleKeyEvent(event) )\
248 [super keyDown:event];\
250 -(void)keyUp:(NSEvent *)event\
252 if ( !impl->DoHandleKeyEvent(event) )\
253 [super keyUp:event];\
255 -(void)flagsChanged:(NSEvent *)event\
257 if ( !impl->DoHandleKeyEvent(event) )\
258 [super flagsChanged:event];\
260 - (BOOL) becomeFirstResponder\
262 BOOL r = [super becomeFirstResponder];\
264 impl->DoNotifyFocusEvent( true );\
267 - (BOOL) resignFirstResponder\
269 BOOL r = [super resignFirstResponder];\
271 impl->DoNotifyFocusEvent( false );\
275 #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
277 #define WXCOCOAIMPL_COMMON_INTERFACE \
278 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
279 - (wxWidgetCocoaImpl*) implementation;\
281 WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
283 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
284 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
286 impl = theImplementation;\
288 - (wxWidgetCocoaImpl*) implementation\
297 #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
298 - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
300 impl = theImplementation;\
302 - (wxWidgetCocoaImpl*) implementation\
311 // used for many wxControls
313 @interface wxNSButton
: NSButton
315 WXCOCOAIMPL_COMMON_MEMBERS
318 WXCOCOAIMPL_COMMON_INTERFACE
319 - (void) clickedAction
: (id
) sender
;
323 @interface wxNSBox
: NSBox
325 WXCOCOAIMPL_COMMON_MEMBERS
328 WXCOCOAIMPL_COMMON_INTERFACE
332 @interface wxNSTextField
: NSTextField
334 WXCOCOAIMPL_COMMON_MEMBERS
337 WXCOCOAIMPL_COMMON_INTERFACE
341 @interface wxNSMenu
: NSMenu
346 - (void) setImplementation
:(wxMenuImpl
*) item
;
347 - (wxMenuImpl
*) implementation
;
351 @interface wxNSMenuItem
: NSMenuItem
353 wxMenuItemImpl
* impl
;
356 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
357 - (wxMenuItemImpl
*) implementation
;
359 - (void)clickedAction
:(id
)sender
;
360 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
368 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
369 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
370 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
371 void wxMacCocoaHideCursor();
372 void wxMacCocoaShowCursor();
374 typedef struct tagClassicCursor
381 const short kwxCursorBullseye
= 0;
382 const short kwxCursorBlank
= 1;
383 const short kwxCursorPencil
= 2;
384 const short kwxCursorMagnifier
= 3;
385 const short kwxCursorNoEntry
= 4;
386 const short kwxCursorPaintBrush
= 5;
387 const short kwxCursorPointRight
= 6;
388 const short kwxCursorPointLeft
= 7;
389 const short kwxCursorQuestionArrow
= 8;
390 const short kwxCursorRightArrow
= 9;
391 const short kwxCursorSizeNS
= 10;
392 const short kwxCursorSize
= 11;
393 const short kwxCursorSizeNESW
= 12;
394 const short kwxCursorSizeNWSE
= 13;
395 const short kwxCursorRoller
= 14;
396 const short kwxCursorLast
= kwxCursorRoller
;
398 // exposing our fallback cursor map
400 extern ClassicCursor gMacCursors
[];
405 // _WX_PRIVATE_COCOA_H_