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>
27 // we only need theming, if we find a better include replace the following
28 #include <Carbon/Carbon.h>
32 #import <Cocoa/Cocoa.h>
36 // shared between Cocoa and Carbon
39 // bring in theming types without pulling in the headers
42 typedef SInt16 ThemeBrush
;
43 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
44 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
45 CGContextRef inContext
,
46 const CGRect
* inBounds
,
48 WX_NSImage WXDLLIMPEXP_CORE
wxOSXCreateNSImageFromCGImage( CGImageRef image
);
49 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
);
52 long UMAGetSystemVersion() ;
53 WXDLLIMPEXP_BASE
void wxMacStringToPascal( const wxString
&from
, StringPtr to
);
54 WXDLLIMPEXP_BASE wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
);
55 WXDLLIMPEXP_BASE OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
);
56 WXDLLIMPEXP_BASE wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
);
64 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
67 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
73 virtual bool IsVisible() const ;
74 virtual void SetVisibility(bool);
80 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
82 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
84 virtual void SetBackgroundColour(const wxColour
&);
86 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
87 virtual void Move(int x
, int y
, int width
, int height
);
88 virtual void GetPosition( int &x
, int &y
) const;
89 virtual void GetSize( int &width
, int &height
) const;
90 virtual void SetControlSize( wxWindowVariant variant
);
92 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
93 virtual bool GetNeedsDisplay() const;
95 virtual bool CanFocus() const;
96 // return true if successful
97 virtual bool SetFocus();
98 virtual bool HasFocus() const;
100 void RemoveFromParent();
101 void Embed( wxWidgetImpl
*parent
);
103 void SetDefaultButton( bool isDefault
);
105 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
107 void SetCursor( const wxCursor
& cursor
);
111 wxInt32
GetValue() const;
112 void SetValue( wxInt32 v
);
113 wxBitmap
GetBitmap() const;
114 void SetBitmap( const wxBitmap
& bitmap
);
115 void SetBitmapPosition( wxDirection dir
);
116 void SetupTabs( const wxNotebook
¬ebook
);
117 void GetBestRect( wxRect
*r
) const;
118 bool IsEnabled() const;
119 void Enable( bool enable
);
120 bool ButtonClickDidStateChange() { return true ;}
121 void SetMinimum( wxInt32 v
);
122 void SetMaximum( wxInt32 v
);
123 wxInt32
GetMinimum() const;
124 wxInt32
GetMaximum() const;
126 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
128 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
130 void InstallEventHandler( WXWidget control
= NULL
);
132 virtual bool DoHandleMouseEvent(NSEvent
*event
);
133 virtual bool DoHandleKeyEvent(NSEvent
*event
);
134 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
135 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
137 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
138 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
141 void SetFlipped(bool flipped
);
142 virtual bool IsFlipped() const { return m_isFlipped
; }
144 // cocoa thunk connected calls
146 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
147 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
148 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
149 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
150 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
151 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
152 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
153 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
154 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
155 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
156 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
157 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
158 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
159 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
161 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
162 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
166 NSEvent
* m_lastKeyDownEvent
;
168 // if it the control has an editor, that editor will already send some
169 // events, don't resend them
172 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
175 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
177 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
180 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
181 wxNonOwnedWindowCocoaImpl();
183 virtual ~wxNonOwnedWindowCocoaImpl();
185 virtual void Destroy() ;
186 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
187 long style
, long extraStyle
, const wxString
& name
) ;
189 WXWindow
GetWXWindow() const;
192 bool Show(bool show
);
193 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
196 bool SetTransparent(wxByte alpha
);
197 bool SetBackgroundColour(const wxColour
& col
);
198 void SetExtraStyle( long exStyle
);
199 bool SetBackgroundStyle(wxBackgroundStyle style
);
200 bool CanSetTransparent();
202 void MoveWindow(int x
, int y
, int width
, int height
);
203 void GetPosition( int &x
, int &y
) const;
204 void GetSize( int &width
, int &height
) const;
206 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
207 bool SetShape(const wxRegion
& region
);
209 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
211 virtual bool IsMaximized() const;
213 virtual bool IsIconized() const;
215 virtual void Iconize( bool iconize
);
217 virtual void Maximize(bool maximize
);
219 virtual bool IsFullScreen() const;
221 virtual bool ShowFullScreen(bool show
, long style
);
223 virtual void RequestUserAttention(int flags
);
225 virtual void ScreenToWindow( int *x
, int *y
);
227 virtual void WindowToScreen( int *x
, int *y
);
229 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
231 WX_wxNSWindow m_macWindow
;
232 void * m_macFullScreenData
;
233 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
238 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
239 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
240 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
241 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
243 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
244 bool adjustForOrigin
= true );
246 // used for many wxControls
248 @interface wxNSButton
: NSButton
254 @interface wxNSBox
: NSBox
260 @interface wxNSTextFieldEditor
: NSTextView
262 NSEvent
* lastKeyDownEvent
;
267 @interface wxNSTextField
: NSTextField
269 wxNSTextFieldEditor
* fieldEditor
;
272 - (wxNSTextFieldEditor
*) fieldEditor
;
273 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
277 @interface wxNSSecureTextField
: NSSecureTextField
284 @interface wxNSTextView
: NSTextView
290 @interface wxNSMenu
: NSMenu
295 - (void) setImplementation
:(wxMenuImpl
*) item
;
296 - (wxMenuImpl
*) implementation
;
300 @interface wxNSMenuItem
: NSMenuItem
302 wxMenuItemImpl
* impl
;
305 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
306 - (wxMenuItemImpl
*) implementation
;
308 - (void)clickedAction
:(id
)sender
;
309 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
313 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
316 We need this for ShowModal, as the sheet just disables the parent window and
317 returns control to the app, whereas we don't want to return from ShowModal
318 until the sheet has been dismissed.
320 @interface ModalDialogDelegate
: NSObject
328 - (void)waitForSheetToFinish
;
329 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
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_