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
);
45 WXWindow WXDLLIMPEXP_CORE
wxOSXGetMainWindow();
47 class WXDLLIMPEXP_FWD_CORE wxDialog
;
49 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
52 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false, bool isUserPane
= false ) ;
58 virtual bool IsVisible() const ;
59 virtual void SetVisibility(bool);
61 // we provide a static function which can be reused from
62 // wxNonOwnedWindowCocoaImpl too
63 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
68 virtual bool ShowWithEffect(bool show
,
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
&);
81 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
83 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
84 virtual void Move(int x
, int y
, int width
, int height
);
85 virtual void GetPosition( int &x
, int &y
) const;
86 virtual void GetSize( int &width
, int &height
) const;
87 virtual void SetControlSize( wxWindowVariant variant
);
89 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
90 virtual bool GetNeedsDisplay() const;
92 virtual void SetDrawingEnabled(bool enabled
);
94 virtual bool CanFocus() const;
95 // return true if successful
96 virtual bool SetFocus();
97 virtual bool HasFocus() const;
99 void RemoveFromParent();
100 void Embed( wxWidgetImpl
*parent
);
102 void SetDefaultButton( bool isDefault
);
104 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
106 void SetCursor( const wxCursor
& cursor
);
110 void SetDropTarget(wxDropTarget
* target
);
112 wxInt32
GetValue() const;
113 void SetValue( wxInt32 v
);
114 wxBitmap
GetBitmap() const;
115 void SetBitmap( const wxBitmap
& bitmap
);
116 void SetBitmapPosition( wxDirection dir
);
117 void SetupTabs( const wxNotebook
¬ebook
);
118 void GetBestRect( wxRect
*r
) const;
119 bool IsEnabled() const;
120 void Enable( bool enable
);
121 bool ButtonClickDidStateChange() { return true ;}
122 void SetMinimum( wxInt32 v
);
123 void SetMaximum( wxInt32 v
);
124 wxInt32
GetMinimum() const;
125 wxInt32
GetMaximum() const;
127 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
129 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
130 void SetToolTip( wxToolTip
* tooltip
);
132 void InstallEventHandler( WXWidget control
= NULL
);
134 virtual bool DoHandleMouseEvent(NSEvent
*event
);
135 virtual bool DoHandleKeyEvent(NSEvent
*event
);
136 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
137 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
139 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
140 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
143 #if !wxOSX_USE_NATIVE_FLIPPED
144 void SetFlipped(bool flipped
);
145 virtual bool IsFlipped() const { return m_isFlipped
; }
148 // cocoa thunk connected calls
150 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
151 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
152 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
153 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
154 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
155 virtual void cursorUpdate(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
156 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
157 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
158 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
159 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
160 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
161 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
162 #if !wxOSX_USE_NATIVE_FLIPPED
163 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
165 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
167 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
168 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
170 // for wxTextCtrl-derived classes, put here since they don't all derive
171 // from the same pimpl class.
172 virtual void controlTextDidChange();
176 NSEvent
* m_lastKeyDownEvent
;
177 #if !wxOSX_USE_NATIVE_FLIPPED
180 // if it the control has an editor, that editor will already send some
181 // events, don't resend them
184 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
187 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
189 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
192 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
193 wxNonOwnedWindowCocoaImpl();
195 virtual ~wxNonOwnedWindowCocoaImpl();
197 virtual void WillBeDestroyed() ;
198 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
199 long style
, long extraStyle
, const wxString
& name
) ;
200 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
202 WXWindow
GetWXWindow() const;
205 bool Show(bool show
);
207 virtual bool ShowWithEffect(bool show
,
212 bool SetTransparent(wxByte alpha
);
213 bool SetBackgroundColour(const wxColour
& col
);
214 void SetExtraStyle( long exStyle
);
215 void SetWindowStyleFlag( long style
);
216 bool SetBackgroundStyle(wxBackgroundStyle style
);
217 bool CanSetTransparent();
219 void MoveWindow(int x
, int y
, int width
, int height
);
220 void GetPosition( int &x
, int &y
) const;
221 void GetSize( int &width
, int &height
) const;
223 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
224 bool SetShape(const wxRegion
& region
);
226 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
228 virtual bool IsMaximized() const;
230 virtual bool IsIconized() const;
232 virtual void Iconize( bool iconize
);
234 virtual void Maximize(bool maximize
);
236 virtual bool IsFullScreen() const;
238 virtual bool ShowFullScreen(bool show
, long style
);
240 virtual void ShowWithoutActivating();
242 virtual void RequestUserAttention(int flags
);
244 virtual void ScreenToWindow( int *x
, int *y
);
246 virtual void WindowToScreen( int *x
, int *y
);
248 virtual bool IsActive();
250 virtual void SetModified(bool modified
);
251 virtual bool IsModified() const;
253 virtual void SetRepresentedFilename(const wxString
& filename
);
255 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
257 CGWindowLevel
GetWindowLevel() const { return m_macWindowLevel
; }
258 void RestoreWindowLevel();
260 CGWindowLevel m_macWindowLevel
;
261 WXWindow m_macWindow
;
262 void * m_macFullScreenData
;
263 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
266 DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton
);
268 class wxButtonCocoaImpl
: public wxWidgetCocoaImpl
, public wxButtonImpl
271 wxButtonCocoaImpl(wxWindowMac
*wxpeer
, wxNSButton
*v
);
272 virtual void SetBitmap(const wxBitmap
& bitmap
);
274 virtual void SetLabelMarkup(const wxString
& markup
);
275 #endif // wxUSE_MARKUP
277 void SetPressedBitmap( const wxBitmap
& bitmap
);
278 void GetLayoutInset(int &left
, int &top
, int &right
, int &bottom
) const;
279 void SetAcceleratorFromLabel(const wxString
& label
);
281 NSButton
*GetNSButton() const;
286 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
287 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
288 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
289 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
290 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
292 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
293 bool adjustForOrigin
= true );
295 // used for many wxControls
297 @interface wxNSButton
: NSButton
299 NSTrackingRectTag rectTag
;
304 @interface wxNSBox
: NSBox
310 @interface wxNSTextFieldEditor
: NSTextView
312 NSEvent
* lastKeyDownEvent
;
317 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
319 wxNSTextFieldEditor
* fieldEditor
;
322 - (wxNSTextFieldEditor
*) fieldEditor
;
323 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
327 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
334 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
338 - (void)textDidChange
:(NSNotification
*)aNotification
;
342 @interface wxNSMenu
: NSMenu
347 - (void) setImplementation
:(wxMenuImpl
*) item
;
348 - (wxMenuImpl
*) implementation
;
352 @interface wxNSMenuItem
: NSMenuItem
354 wxMenuItemImpl
* impl
;
357 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
358 - (wxMenuItemImpl
*) implementation
;
360 - (void)clickedAction
:(id
)sender
;
361 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
365 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
368 We need this for ShowModal, as the sheet just disables the parent window and
369 returns control to the app, whereas we don't want to return from ShowModal
370 until the sheet has been dismissed.
372 @interface ModalDialogDelegate
: NSObject
379 - (void)setImplementation
: (wxDialog
*)dialog
;
382 - (void)waitForSheetToFinish
;
383 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
386 // This interface must be exported in shared 64 bit multilib build but
387 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
388 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
389 // builds but seems to be unnecessary there so to avoid the expense of a
390 // configure check verifying if this does work or not with the current
391 // compiler we just only use it for 64 bit builds where this is always
394 // NB: Currently this is the only place where we need to export an
395 // interface but if we need to do it elsewhere we should define a
396 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
397 // instead of duplicating this preprocessor check.
400 #endif // 64 bit builds
401 @interface wxNSAppController
: NSObject
wxOSX_10_6_AND_LATER(<NSApplicationDelegate
>)
411 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
412 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
413 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
414 void wxMacCocoaHideCursor();
415 void wxMacCocoaShowCursor();
417 typedef struct tagClassicCursor
424 const short kwxCursorBullseye
= 0;
425 const short kwxCursorBlank
= 1;
426 const short kwxCursorPencil
= 2;
427 const short kwxCursorMagnifier
= 3;
428 const short kwxCursorNoEntry
= 4;
429 const short kwxCursorPaintBrush
= 5;
430 const short kwxCursorPointRight
= 6;
431 const short kwxCursorPointLeft
= 7;
432 const short kwxCursorQuestionArrow
= 8;
433 const short kwxCursorRightArrow
= 9;
434 const short kwxCursorSizeNS
= 10;
435 const short kwxCursorSize
= 11;
436 const short kwxCursorSizeNESW
= 12;
437 const short kwxCursorSizeNWSE
= 13;
438 const short kwxCursorRoller
= 14;
439 const short kwxCursorWatch
= 15;
440 const short kwxCursorLast
= kwxCursorWatch
;
442 // exposing our fallback cursor map
444 extern ClassicCursor gMacCursors
[];
446 extern NSLayoutManager
* gNSLayoutManager
;
451 // _WX_PRIVATE_COCOA_H_