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
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_COCOA_H_
15 #define _WX_PRIVATE_COCOA_H_
17 #include <ApplicationServices/ApplicationServices.h>
20 #import <Cocoa/Cocoa.h>
23 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
24 // available in 10.4 but not in the headers
26 kEventMouseScroll
= 11
30 // shared between Cocoa and Carbon
33 // bring in theming types without pulling in the headers
36 typedef SInt16 ThemeBrush
;
37 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
38 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
39 CGContextRef inContext
,
40 const CGRect
* inBounds
,
42 WX_NSImage WXDLLIMPEXP_CORE
wxOSXGetNSImageFromCGImage( CGImageRef image
, double scale
= 1.0 );
43 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
, double *scale
= NULL
);
44 CGContextRef WXDLLIMPEXP_CORE
wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage
);
46 wxBitmap WXDLLIMPEXP_CORE
wxOSXCreateSystemBitmap(const wxString
& id
, const wxString
&client
, const wxSize
& size
);
47 WXWindow WXDLLIMPEXP_CORE
wxOSXGetMainWindow();
49 class WXDLLIMPEXP_FWD_CORE wxDialog
;
51 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
54 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false, bool isUserPane
= false ) ;
60 virtual bool IsVisible() const ;
61 virtual void SetVisibility(bool);
63 // we provide a static function which can be reused from
64 // wxNonOwnedWindowCocoaImpl too
65 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
70 virtual bool ShowWithEffect(bool show
,
78 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
80 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
82 virtual void SetBackgroundColour(const wxColour
&);
83 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
85 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
86 virtual void Move(int x
, int y
, int width
, int height
);
87 virtual void GetPosition( int &x
, int &y
) const;
88 virtual void GetSize( int &width
, int &height
) const;
89 virtual void SetControlSize( wxWindowVariant variant
);
91 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
92 virtual bool GetNeedsDisplay() const;
94 virtual void SetDrawingEnabled(bool enabled
);
96 virtual bool CanFocus() const;
97 // return true if successful
98 virtual bool SetFocus();
99 virtual bool HasFocus() const;
101 void RemoveFromParent();
102 void Embed( wxWidgetImpl
*parent
);
104 void SetDefaultButton( bool isDefault
);
106 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
108 void SetCursor( const wxCursor
& cursor
);
112 void SetDropTarget(wxDropTarget
* target
);
114 wxInt32
GetValue() const;
115 void SetValue( wxInt32 v
);
116 wxBitmap
GetBitmap() const;
117 void SetBitmap( const wxBitmap
& bitmap
);
118 void SetBitmapPosition( wxDirection dir
);
119 void SetupTabs( const wxNotebook
¬ebook
);
120 void GetBestRect( wxRect
*r
) const;
121 bool IsEnabled() const;
122 void Enable( bool enable
);
123 bool ButtonClickDidStateChange() { return true ;}
124 void SetMinimum( wxInt32 v
);
125 void SetMaximum( wxInt32 v
);
126 wxInt32
GetMinimum() const;
127 wxInt32
GetMaximum() const;
129 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
131 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
132 void SetToolTip( wxToolTip
* tooltip
);
134 void InstallEventHandler( WXWidget control
= NULL
);
136 virtual bool DoHandleMouseEvent(NSEvent
*event
);
137 virtual bool DoHandleKeyEvent(NSEvent
*event
);
138 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
139 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
141 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
142 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
143 void SetupCoordinates(wxCoord
&x
, wxCoord
&y
, NSEvent
*nsEvent
);
144 virtual bool SetupCursor(NSEvent
* event
);
147 #if !wxOSX_USE_NATIVE_FLIPPED
148 void SetFlipped(bool flipped
);
149 virtual bool IsFlipped() const { return m_isFlipped
; }
152 virtual double GetContentScaleFactor() const;
154 // cocoa thunk connected calls
156 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
157 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
158 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
159 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
160 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
161 virtual void cursorUpdate(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
162 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
163 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
164 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
165 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
166 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
167 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
168 #if !wxOSX_USE_NATIVE_FLIPPED
169 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
171 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
173 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
174 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
176 // for wxTextCtrl-derived classes, put here since they don't all derive
177 // from the same pimpl class.
178 virtual void controlTextDidChange();
182 NSEvent
* m_lastKeyDownEvent
;
183 #if !wxOSX_USE_NATIVE_FLIPPED
186 // if it the control has an editor, that editor will already send some
187 // events, don't resend them
190 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
193 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
195 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
198 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
199 wxNonOwnedWindowCocoaImpl();
201 virtual ~wxNonOwnedWindowCocoaImpl();
203 virtual void WillBeDestroyed() ;
204 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
205 long style
, long extraStyle
, const wxString
& name
) ;
206 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
208 WXWindow
GetWXWindow() const;
211 bool Show(bool show
);
213 virtual bool ShowWithEffect(bool show
,
218 bool SetTransparent(wxByte alpha
);
219 bool SetBackgroundColour(const wxColour
& col
);
220 void SetExtraStyle( long exStyle
);
221 void SetWindowStyleFlag( long style
);
222 bool SetBackgroundStyle(wxBackgroundStyle style
);
223 bool CanSetTransparent();
225 void MoveWindow(int x
, int y
, int width
, int height
);
226 void GetPosition( int &x
, int &y
) const;
227 void GetSize( int &width
, int &height
) const;
229 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
230 bool SetShape(const wxRegion
& region
);
232 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
234 virtual bool IsMaximized() const;
236 virtual bool IsIconized() const;
238 virtual void Iconize( bool iconize
);
240 virtual void Maximize(bool maximize
);
242 virtual bool IsFullScreen() const;
244 virtual bool ShowFullScreen(bool show
, long style
);
246 virtual void ShowWithoutActivating();
248 virtual void RequestUserAttention(int flags
);
250 virtual void ScreenToWindow( int *x
, int *y
);
252 virtual void WindowToScreen( int *x
, int *y
);
254 virtual bool IsActive();
256 virtual void SetModified(bool modified
);
257 virtual bool IsModified() const;
259 virtual void SetRepresentedFilename(const wxString
& filename
);
261 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
263 CGWindowLevel
GetWindowLevel() const { return m_macWindowLevel
; }
264 void RestoreWindowLevel();
266 static WX_NSResponder
GetNextFirstResponder() ;
268 CGWindowLevel m_macWindowLevel
;
269 WXWindow m_macWindow
;
270 void * m_macFullScreenData
;
271 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
274 DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton
);
276 class wxButtonCocoaImpl
: public wxWidgetCocoaImpl
, public wxButtonImpl
279 wxButtonCocoaImpl(wxWindowMac
*wxpeer
, wxNSButton
*v
);
280 virtual void SetBitmap(const wxBitmap
& bitmap
);
282 virtual void SetLabelMarkup(const wxString
& markup
);
283 #endif // wxUSE_MARKUP
285 void SetPressedBitmap( const wxBitmap
& bitmap
);
286 void GetLayoutInset(int &left
, int &top
, int &right
, int &bottom
) const;
287 void SetAcceleratorFromLabel(const wxString
& label
);
289 NSButton
*GetNSButton() const;
293 typedef void (*wxOSX_TextEventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSString
*event
);
294 typedef void (*wxOSX_EventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSEvent
*event
);
295 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSEvent
*event
);
296 typedef BOOL (*wxOSX_FocusHandlerPtr
)(NSView
* self
, SEL _cmd
);
299 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
300 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
301 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
302 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
303 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
305 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
306 bool adjustForOrigin
= true );
308 WXDLLIMPEXP_CORE NSView
* wxOSXGetViewFromResponder( NSResponder
* responder
);
310 // used for many wxControls
312 @interface wxNSButton
: NSButton
314 NSTrackingRectTag rectTag
;
319 @interface wxNSBox
: NSBox
325 @interface wxNSTextFieldEditor
: NSTextView
327 NSEvent
* lastKeyDownEvent
;
332 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
334 wxNSTextFieldEditor
* fieldEditor
;
337 - (wxNSTextFieldEditor
*) fieldEditor
;
338 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
342 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
349 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
353 - (void)textDidChange
:(NSNotification
*)aNotification
;
357 @interface wxNSComboBox
: NSComboBox
359 wxNSTextFieldEditor
* fieldEditor
;
362 - (wxNSTextFieldEditor
*) fieldEditor
;
363 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
369 @interface wxNSMenu
: NSMenu
374 - (void) setImplementation
:(wxMenuImpl
*) item
;
375 - (wxMenuImpl
*) implementation
;
379 @interface wxNSMenuItem
: NSMenuItem
381 wxMenuItemImpl
* impl
;
384 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
385 - (wxMenuItemImpl
*) implementation
;
387 - (void)clickedAction
:(id
)sender
;
388 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
392 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
395 We need this for ShowModal, as the sheet just disables the parent window and
396 returns control to the app, whereas we don't want to return from ShowModal
397 until the sheet has been dismissed.
399 @interface ModalDialogDelegate
: NSObject
406 - (void)setImplementation
: (wxDialog
*)dialog
;
409 - (void)waitForSheetToFinish
;
410 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
413 // This interface must be exported in shared 64 bit multilib build but
414 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
415 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
416 // builds but seems to be unnecessary there so to avoid the expense of a
417 // configure check verifying if this does work or not with the current
418 // compiler we just only use it for 64 bit builds where this is always
421 // NB: Currently this is the only place where we need to export an
422 // interface but if we need to do it elsewhere we should define a
423 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
424 // instead of duplicating this preprocessor check.
427 #endif // 64 bit builds
428 @interface wxNSAppController
: NSObject
wxOSX_10_6_AND_LATER(<NSApplicationDelegate
>)
438 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
439 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
440 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
441 void wxMacCocoaHideCursor();
442 void wxMacCocoaShowCursor();
444 typedef struct tagClassicCursor
451 const short kwxCursorBullseye
= 0;
452 const short kwxCursorBlank
= 1;
453 const short kwxCursorPencil
= 2;
454 const short kwxCursorMagnifier
= 3;
455 const short kwxCursorNoEntry
= 4;
456 const short kwxCursorPaintBrush
= 5;
457 const short kwxCursorPointRight
= 6;
458 const short kwxCursorPointLeft
= 7;
459 const short kwxCursorQuestionArrow
= 8;
460 const short kwxCursorRightArrow
= 9;
461 const short kwxCursorSizeNS
= 10;
462 const short kwxCursorSize
= 11;
463 const short kwxCursorSizeNESW
= 12;
464 const short kwxCursorSizeNWSE
= 13;
465 const short kwxCursorRoller
= 14;
466 const short kwxCursorWatch
= 15;
467 const short kwxCursorLast
= kwxCursorWatch
;
469 // exposing our fallback cursor map
471 extern ClassicCursor gMacCursors
[];
473 extern NSLayoutManager
* gNSLayoutManager
;
478 // _WX_PRIVATE_COCOA_H_