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
);
43 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
);
44 wxBitmap WXDLLIMPEXP_CORE
wxOSXCreateSystemBitmap(const wxString
& id
, const wxString
&client
, const wxSize
& size
);
46 class WXDLLIMPEXP_FWD_CORE wxDialog
;
48 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
51 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false, bool isUserPane
= false ) ;
57 virtual bool IsVisible() const ;
58 virtual void SetVisibility(bool);
60 // we provide a static function which can be reused from
61 // wxNonOwnedWindowCocoaImpl too
62 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
67 virtual bool ShowWithEffect(bool show
,
75 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
77 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
79 virtual void SetBackgroundColour(const wxColour
&);
80 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
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 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
103 void SetCursor( const wxCursor
& cursor
);
107 wxInt32
GetValue() const;
108 void SetValue( wxInt32 v
);
109 wxBitmap
GetBitmap() const;
110 void SetBitmap( const wxBitmap
& bitmap
);
111 void SetBitmapPosition( wxDirection dir
);
112 void SetupTabs( const wxNotebook
¬ebook
);
113 void GetBestRect( wxRect
*r
) const;
114 bool IsEnabled() const;
115 void Enable( bool enable
);
116 bool ButtonClickDidStateChange() { return true ;}
117 void SetMinimum( wxInt32 v
);
118 void SetMaximum( wxInt32 v
);
119 wxInt32
GetMinimum() const;
120 wxInt32
GetMaximum() const;
122 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
124 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
125 void SetToolTip( wxToolTip
* tooltip
);
127 void InstallEventHandler( WXWidget control
= NULL
);
129 virtual bool DoHandleMouseEvent(NSEvent
*event
);
130 virtual bool DoHandleKeyEvent(NSEvent
*event
);
131 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
132 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
134 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
135 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
138 void SetFlipped(bool flipped
);
139 virtual bool IsFlipped() const { return m_isFlipped
; }
141 // cocoa thunk connected calls
143 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
144 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
145 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
146 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
147 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
148 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
149 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
150 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
151 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
152 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
153 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
154 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
155 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
156 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
158 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
159 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
161 // for wxTextCtrl-derived classes, put here since they don't all derive
162 // from the same pimpl class.
163 virtual void controlTextDidChange();
167 NSEvent
* m_lastKeyDownEvent
;
169 // if it the control has an editor, that editor will already send some
170 // events, don't resend them
173 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
176 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
178 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
181 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
182 wxNonOwnedWindowCocoaImpl();
184 virtual ~wxNonOwnedWindowCocoaImpl();
186 virtual void WillBeDestroyed() ;
187 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
188 long style
, long extraStyle
, const wxString
& name
) ;
189 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
191 WXWindow
GetWXWindow() const;
194 bool Show(bool show
);
196 virtual bool ShowWithEffect(bool show
,
201 bool SetTransparent(wxByte alpha
);
202 bool SetBackgroundColour(const wxColour
& col
);
203 void SetExtraStyle( long exStyle
);
204 void SetWindowStyleFlag( long style
);
205 bool SetBackgroundStyle(wxBackgroundStyle style
);
206 bool CanSetTransparent();
208 void MoveWindow(int x
, int y
, int width
, int height
);
209 void GetPosition( int &x
, int &y
) const;
210 void GetSize( int &width
, int &height
) const;
212 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
213 bool SetShape(const wxRegion
& region
);
215 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
217 virtual bool IsMaximized() const;
219 virtual bool IsIconized() const;
221 virtual void Iconize( bool iconize
);
223 virtual void Maximize(bool maximize
);
225 virtual bool IsFullScreen() const;
227 virtual bool ShowFullScreen(bool show
, long style
);
229 virtual void ShowWithoutActivating();
231 virtual void RequestUserAttention(int flags
);
233 virtual void ScreenToWindow( int *x
, int *y
);
235 virtual void WindowToScreen( int *x
, int *y
);
237 virtual bool IsActive();
239 virtual void SetModified(bool modified
);
240 virtual bool IsModified() const;
242 virtual void SetRepresentedFilename(const wxString
& filename
);
244 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
246 CGWindowLevel
GetWindowLevel() const { return m_macWindowLevel
; }
247 void RestoreWindowLevel();
249 CGWindowLevel m_macWindowLevel
;
250 WXWindow m_macWindow
;
251 void * m_macFullScreenData
;
252 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
257 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
258 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
259 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
260 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
261 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
263 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
264 bool adjustForOrigin
= true );
266 // used for many wxControls
268 @interface wxNSButton
: NSButton
270 NSTrackingRectTag rectTag
;
275 @interface wxNSBox
: NSBox
281 @interface wxNSTextFieldEditor
: NSTextView
283 NSEvent
* lastKeyDownEvent
;
288 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
290 wxNSTextFieldEditor
* fieldEditor
;
293 - (wxNSTextFieldEditor
*) fieldEditor
;
294 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
298 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
305 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
309 - (void)textDidChange
:(NSNotification
*)aNotification
;
313 @interface wxNSMenu
: NSMenu
318 - (void) setImplementation
:(wxMenuImpl
*) item
;
319 - (wxMenuImpl
*) implementation
;
323 @interface wxNSMenuItem
: NSMenuItem
325 wxMenuItemImpl
* impl
;
328 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
329 - (wxMenuItemImpl
*) implementation
;
331 - (void)clickedAction
:(id
)sender
;
332 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
336 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
339 We need this for ShowModal, as the sheet just disables the parent window and
340 returns control to the app, whereas we don't want to return from ShowModal
341 until the sheet has been dismissed.
343 @interface ModalDialogDelegate
: NSObject
350 - (void)setImplementation
: (wxDialog
*)dialog
;
353 - (void)waitForSheetToFinish
;
354 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
357 // This interface must be exported in shared 64 bit multilib build but
358 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
359 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
360 // builds but seems to be unnecessary there so to avoid the expense of a
361 // configure check verifying if this does work or not with the current
362 // compiler we just only use it for 64 bit builds where this is always
365 // NB: Currently this is the only place where we need to export an
366 // interface but if we need to do it elsewhere we should define a
367 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
368 // instead of duplicating this preprocessor check.
371 #endif // 64 bit builds
372 @interface wxNSAppController
: NSObject
wxOSX_10_6_AND_LATER(<NSApplicationDelegate
>)
382 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
383 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
384 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
385 void wxMacCocoaHideCursor();
386 void wxMacCocoaShowCursor();
388 typedef struct tagClassicCursor
395 const short kwxCursorBullseye
= 0;
396 const short kwxCursorBlank
= 1;
397 const short kwxCursorPencil
= 2;
398 const short kwxCursorMagnifier
= 3;
399 const short kwxCursorNoEntry
= 4;
400 const short kwxCursorPaintBrush
= 5;
401 const short kwxCursorPointRight
= 6;
402 const short kwxCursorPointLeft
= 7;
403 const short kwxCursorQuestionArrow
= 8;
404 const short kwxCursorRightArrow
= 9;
405 const short kwxCursorSizeNS
= 10;
406 const short kwxCursorSize
= 11;
407 const short kwxCursorSizeNESW
= 12;
408 const short kwxCursorSizeNWSE
= 13;
409 const short kwxCursorRoller
= 14;
410 const short kwxCursorWatch
= 15;
411 const short kwxCursorLast
= kwxCursorWatch
;
413 // exposing our fallback cursor map
415 extern ClassicCursor gMacCursors
[];
420 // _WX_PRIVATE_COCOA_H_