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
);
45 double WXDLLIMPEXP_CORE
wxOSXGetMainScreenContentScaleFactor();
47 wxBitmap WXDLLIMPEXP_CORE
wxOSXCreateSystemBitmap(const wxString
& id
, const wxString
&client
, const wxSize
& size
);
48 WXWindow WXDLLIMPEXP_CORE
wxOSXGetMainWindow();
50 class WXDLLIMPEXP_FWD_CORE wxDialog
;
52 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
55 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false, bool isUserPane
= false ) ;
61 virtual bool IsVisible() const ;
62 virtual void SetVisibility(bool);
64 // we provide a static function which can be reused from
65 // wxNonOwnedWindowCocoaImpl too
66 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
71 virtual bool ShowWithEffect(bool show
,
79 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
81 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
83 virtual void SetBackgroundColour(const wxColour
&);
84 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
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 void SetDrawingEnabled(bool enabled
);
97 virtual bool CanFocus() const;
98 // return true if successful
99 virtual bool SetFocus();
100 virtual bool HasFocus() const;
102 void RemoveFromParent();
103 void Embed( wxWidgetImpl
*parent
);
105 void SetDefaultButton( bool isDefault
);
107 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
109 void SetCursor( const wxCursor
& cursor
);
113 void SetDropTarget(wxDropTarget
* target
);
115 wxInt32
GetValue() const;
116 void SetValue( wxInt32 v
);
117 wxBitmap
GetBitmap() const;
118 void SetBitmap( const wxBitmap
& bitmap
);
119 void SetBitmapPosition( wxDirection dir
);
120 void SetupTabs( const wxNotebook
¬ebook
);
121 void GetBestRect( wxRect
*r
) const;
122 bool IsEnabled() const;
123 void Enable( bool enable
);
124 bool ButtonClickDidStateChange() { return true ;}
125 void SetMinimum( wxInt32 v
);
126 void SetMaximum( wxInt32 v
);
127 wxInt32
GetMinimum() const;
128 wxInt32
GetMaximum() const;
130 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
132 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
133 void SetToolTip( wxToolTip
* tooltip
);
135 void InstallEventHandler( WXWidget control
= NULL
);
137 virtual bool DoHandleMouseEvent(NSEvent
*event
);
138 virtual bool DoHandleKeyEvent(NSEvent
*event
);
139 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
140 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
142 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
143 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
144 void SetupCoordinates(wxCoord
&x
, wxCoord
&y
, NSEvent
*nsEvent
);
145 virtual bool SetupCursor(NSEvent
* event
);
148 #if !wxOSX_USE_NATIVE_FLIPPED
149 void SetFlipped(bool flipped
);
150 virtual bool IsFlipped() const { return m_isFlipped
; }
153 virtual double GetContentScaleFactor() const;
155 // cocoa thunk connected calls
157 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
158 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
159 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
160 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
161 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
162 virtual void cursorUpdate(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
163 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
164 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
165 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
166 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
167 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
168 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
169 #if !wxOSX_USE_NATIVE_FLIPPED
170 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
172 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
174 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
175 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
177 // for wxTextCtrl-derived classes, put here since they don't all derive
178 // from the same pimpl class.
179 virtual void controlTextDidChange();
183 NSEvent
* m_lastKeyDownEvent
;
184 #if !wxOSX_USE_NATIVE_FLIPPED
187 // if it the control has an editor, that editor will already send some
188 // events, don't resend them
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
194 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
196 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
199 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
200 wxNonOwnedWindowCocoaImpl();
202 virtual ~wxNonOwnedWindowCocoaImpl();
204 virtual void WillBeDestroyed() ;
205 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
206 long style
, long extraStyle
, const wxString
& name
) ;
207 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
209 WXWindow
GetWXWindow() const;
212 bool Show(bool show
);
214 virtual bool ShowWithEffect(bool show
,
219 bool SetTransparent(wxByte alpha
);
220 bool SetBackgroundColour(const wxColour
& col
);
221 void SetExtraStyle( long exStyle
);
222 void SetWindowStyleFlag( long style
);
223 bool SetBackgroundStyle(wxBackgroundStyle style
);
224 bool CanSetTransparent();
226 void MoveWindow(int x
, int y
, int width
, int height
);
227 void GetPosition( int &x
, int &y
) const;
228 void GetSize( int &width
, int &height
) const;
230 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
231 bool SetShape(const wxRegion
& region
);
233 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
235 virtual bool IsMaximized() const;
237 virtual bool IsIconized() const;
239 virtual void Iconize( bool iconize
);
241 virtual void Maximize(bool maximize
);
243 virtual bool IsFullScreen() const;
245 virtual bool ShowFullScreen(bool show
, long style
);
247 virtual void ShowWithoutActivating();
249 virtual void RequestUserAttention(int flags
);
251 virtual void ScreenToWindow( int *x
, int *y
);
253 virtual void WindowToScreen( int *x
, int *y
);
255 virtual bool IsActive();
257 virtual void SetModified(bool modified
);
258 virtual bool IsModified() const;
260 virtual void SetRepresentedFilename(const wxString
& filename
);
262 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
264 CGWindowLevel
GetWindowLevel() const { return m_macWindowLevel
; }
265 void RestoreWindowLevel();
267 static WX_NSResponder
GetNextFirstResponder() ;
269 CGWindowLevel m_macWindowLevel
;
270 WXWindow m_macWindow
;
271 void * m_macFullScreenData
;
272 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
275 DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton
);
277 class wxButtonCocoaImpl
: public wxWidgetCocoaImpl
, public wxButtonImpl
280 wxButtonCocoaImpl(wxWindowMac
*wxpeer
, wxNSButton
*v
);
281 virtual void SetBitmap(const wxBitmap
& bitmap
);
283 virtual void SetLabelMarkup(const wxString
& markup
);
284 #endif // wxUSE_MARKUP
286 void SetPressedBitmap( const wxBitmap
& bitmap
);
287 void GetLayoutInset(int &left
, int &top
, int &right
, int &bottom
) const;
288 void SetAcceleratorFromLabel(const wxString
& label
);
290 NSButton
*GetNSButton() const;
294 typedef void (*wxOSX_TextEventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSString
*event
);
295 typedef void (*wxOSX_EventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSEvent
*event
);
296 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr
)(NSView
* self
, SEL _cmd
, NSEvent
*event
);
297 typedef BOOL (*wxOSX_FocusHandlerPtr
)(NSView
* self
, SEL _cmd
);
300 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
301 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
302 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
303 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
304 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
306 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
307 bool adjustForOrigin
= true );
309 WXDLLIMPEXP_CORE NSView
* wxOSXGetViewFromResponder( NSResponder
* responder
);
311 // used for many wxControls
313 @interface wxNSButton
: NSButton
315 NSTrackingRectTag rectTag
;
320 @interface wxNSBox
: NSBox
326 @interface wxNSTextFieldEditor
: NSTextView
328 NSEvent
* lastKeyDownEvent
;
333 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
335 wxNSTextFieldEditor
* fieldEditor
;
338 - (wxNSTextFieldEditor
*) fieldEditor
;
339 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
343 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
350 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
354 - (void)textDidChange
:(NSNotification
*)aNotification
;
358 @interface wxNSComboBox
: NSComboBox
360 wxNSTextFieldEditor
* fieldEditor
;
363 - (wxNSTextFieldEditor
*) fieldEditor
;
364 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
370 @interface wxNSMenu
: NSMenu
375 - (void) setImplementation
:(wxMenuImpl
*) item
;
376 - (wxMenuImpl
*) implementation
;
380 @interface wxNSMenuItem
: NSMenuItem
382 wxMenuItemImpl
* impl
;
385 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
386 - (wxMenuItemImpl
*) implementation
;
388 - (void)clickedAction
:(id
)sender
;
389 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
393 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
396 We need this for ShowModal, as the sheet just disables the parent window and
397 returns control to the app, whereas we don't want to return from ShowModal
398 until the sheet has been dismissed.
400 @interface ModalDialogDelegate
: NSObject
407 - (void)setImplementation
: (wxDialog
*)dialog
;
410 - (void)waitForSheetToFinish
;
411 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
414 // This interface must be exported in shared 64 bit multilib build but
415 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
416 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
417 // builds but seems to be unnecessary there so to avoid the expense of a
418 // configure check verifying if this does work or not with the current
419 // compiler we just only use it for 64 bit builds where this is always
422 // NB: Currently this is the only place where we need to export an
423 // interface but if we need to do it elsewhere we should define a
424 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
425 // instead of duplicating this preprocessor check.
428 #endif // 64 bit builds
429 @interface wxNSAppController
: NSObject
wxOSX_10_6_AND_LATER(<NSApplicationDelegate
>)
439 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
440 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
441 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
442 void wxMacCocoaHideCursor();
443 void wxMacCocoaShowCursor();
445 typedef struct tagClassicCursor
452 const short kwxCursorBullseye
= 0;
453 const short kwxCursorBlank
= 1;
454 const short kwxCursorPencil
= 2;
455 const short kwxCursorMagnifier
= 3;
456 const short kwxCursorNoEntry
= 4;
457 const short kwxCursorPaintBrush
= 5;
458 const short kwxCursorPointRight
= 6;
459 const short kwxCursorPointLeft
= 7;
460 const short kwxCursorQuestionArrow
= 8;
461 const short kwxCursorRightArrow
= 9;
462 const short kwxCursorSizeNS
= 10;
463 const short kwxCursorSize
= 11;
464 const short kwxCursorSizeNESW
= 12;
465 const short kwxCursorSizeNWSE
= 13;
466 const short kwxCursorRoller
= 14;
467 const short kwxCursorWatch
= 15;
468 const short kwxCursorLast
= kwxCursorWatch
;
470 // exposing our fallback cursor map
472 extern ClassicCursor gMacCursors
[];
474 extern NSLayoutManager
* gNSLayoutManager
;
479 // _WX_PRIVATE_COCOA_H_