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>
35 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
36 // available in 10.4 but not in the headers
38 kEventMouseScroll
= 11
42 // shared between Cocoa and Carbon
45 // bring in theming types without pulling in the headers
48 typedef SInt16 ThemeBrush
;
49 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
50 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
51 CGContextRef inContext
,
52 const CGRect
* inBounds
,
54 WX_NSImage WXDLLIMPEXP_CORE
wxOSXGetNSImageFromCGImage( CGImageRef image
);
55 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
);
58 long UMAGetSystemVersion() ;
59 WXDLLIMPEXP_BASE
void wxMacStringToPascal( const wxString
&from
, StringPtr to
);
60 WXDLLIMPEXP_BASE wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
);
61 WXDLLIMPEXP_BASE OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
);
62 WXDLLIMPEXP_BASE wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
);
64 class WXDLLIMPEXP_FWD_CORE wxDialog
;
72 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
75 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
81 virtual bool IsVisible() const ;
82 virtual void SetVisibility(bool);
84 // we provide a static function which can be reused from
85 // wxNonOwnedWindowCocoaImpl too
86 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
91 virtual bool ShowWithEffect(bool show
,
99 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
101 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
103 virtual void SetBackgroundColour(const wxColour
&);
104 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
106 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
107 virtual void Move(int x
, int y
, int width
, int height
);
108 virtual void GetPosition( int &x
, int &y
) const;
109 virtual void GetSize( int &width
, int &height
) const;
110 virtual void SetControlSize( wxWindowVariant variant
);
112 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
113 virtual bool GetNeedsDisplay() const;
115 virtual bool CanFocus() const;
116 // return true if successful
117 virtual bool SetFocus();
118 virtual bool HasFocus() const;
120 void RemoveFromParent();
121 void Embed( wxWidgetImpl
*parent
);
123 void SetDefaultButton( bool isDefault
);
125 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
127 void SetCursor( const wxCursor
& cursor
);
131 wxInt32
GetValue() const;
132 void SetValue( wxInt32 v
);
133 wxBitmap
GetBitmap() const;
134 void SetBitmap( const wxBitmap
& bitmap
);
135 void SetBitmapPosition( wxDirection dir
);
136 void SetupTabs( const wxNotebook
¬ebook
);
137 void GetBestRect( wxRect
*r
) const;
138 bool IsEnabled() const;
139 void Enable( bool enable
);
140 bool ButtonClickDidStateChange() { return true ;}
141 void SetMinimum( wxInt32 v
);
142 void SetMaximum( wxInt32 v
);
143 wxInt32
GetMinimum() const;
144 wxInt32
GetMaximum() const;
146 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
148 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
149 void SetToolTip( wxToolTip
* tooltip
);
151 void InstallEventHandler( WXWidget control
= NULL
);
153 virtual bool DoHandleMouseEvent(NSEvent
*event
);
154 virtual bool DoHandleKeyEvent(NSEvent
*event
);
155 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
156 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
158 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
159 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
162 void SetFlipped(bool flipped
);
163 virtual bool IsFlipped() const { return m_isFlipped
; }
165 // cocoa thunk connected calls
167 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
168 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
169 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
170 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
171 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
172 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
173 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
174 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
175 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
176 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
177 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
178 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
179 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
180 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
182 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
183 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
185 // for wxTextCtrl-derived classes, put here since they don't all derive
186 // from the same pimpl class.
187 virtual void controlTextDidChange();
191 NSEvent
* m_lastKeyDownEvent
;
193 // if it the control has an editor, that editor will already send some
194 // events, don't resend them
197 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
200 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
202 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
205 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
206 wxNonOwnedWindowCocoaImpl();
208 virtual ~wxNonOwnedWindowCocoaImpl();
210 virtual void WillBeDestroyed() ;
211 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
212 long style
, long extraStyle
, const wxString
& name
) ;
213 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
215 WXWindow
GetWXWindow() const;
218 bool Show(bool show
);
220 virtual bool ShowWithEffect(bool show
,
225 bool SetTransparent(wxByte alpha
);
226 bool SetBackgroundColour(const wxColour
& col
);
227 void SetExtraStyle( long exStyle
);
228 void SetWindowStyleFlag( long style
);
229 bool SetBackgroundStyle(wxBackgroundStyle style
);
230 bool CanSetTransparent();
232 void MoveWindow(int x
, int y
, int width
, int height
);
233 void GetPosition( int &x
, int &y
) const;
234 void GetSize( int &width
, int &height
) const;
236 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
237 bool SetShape(const wxRegion
& region
);
239 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
241 virtual bool IsMaximized() const;
243 virtual bool IsIconized() const;
245 virtual void Iconize( bool iconize
);
247 virtual void Maximize(bool maximize
);
249 virtual bool IsFullScreen() const;
251 virtual bool ShowFullScreen(bool show
, long style
);
253 virtual void ShowWithoutActivating();
255 virtual void RequestUserAttention(int flags
);
257 virtual void ScreenToWindow( int *x
, int *y
);
259 virtual void WindowToScreen( int *x
, int *y
);
261 virtual bool IsActive();
263 virtual void SetModified(bool modified
);
264 virtual bool IsModified() const;
266 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
268 WXWindow m_macWindow
;
269 void * m_macFullScreenData
;
270 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
275 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
276 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
277 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
278 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
279 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
281 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
282 bool adjustForOrigin
= true );
284 // used for many wxControls
286 @interface wxNSButton
: NSButton
288 NSTrackingRectTag rectTag
;
293 @interface wxNSBox
: NSBox
299 @interface wxNSTextFieldEditor
: NSTextView
301 NSEvent
* lastKeyDownEvent
;
306 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
308 wxNSTextFieldEditor
* fieldEditor
;
311 - (wxNSTextFieldEditor
*) fieldEditor
;
312 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
316 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
323 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
327 - (void)textDidChange
:(NSNotification
*)aNotification
;
331 @interface wxNSMenu
: NSMenu
336 - (void) setImplementation
:(wxMenuImpl
*) item
;
337 - (wxMenuImpl
*) implementation
;
341 @interface wxNSMenuItem
: NSMenuItem
343 wxMenuItemImpl
* impl
;
346 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
347 - (wxMenuItemImpl
*) implementation
;
349 - (void)clickedAction
:(id
)sender
;
350 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
354 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
357 We need this for ShowModal, as the sheet just disables the parent window and
358 returns control to the app, whereas we don't want to return from ShowModal
359 until the sheet has been dismissed.
361 @interface ModalDialogDelegate
: NSObject
368 - (void)setImplementation
: (wxDialog
*)dialog
;
371 - (void)waitForSheetToFinish
;
372 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
380 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
381 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
382 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
383 void wxMacCocoaHideCursor();
384 void wxMacCocoaShowCursor();
386 typedef struct tagClassicCursor
393 const short kwxCursorBullseye
= 0;
394 const short kwxCursorBlank
= 1;
395 const short kwxCursorPencil
= 2;
396 const short kwxCursorMagnifier
= 3;
397 const short kwxCursorNoEntry
= 4;
398 const short kwxCursorPaintBrush
= 5;
399 const short kwxCursorPointRight
= 6;
400 const short kwxCursorPointLeft
= 7;
401 const short kwxCursorQuestionArrow
= 8;
402 const short kwxCursorRightArrow
= 9;
403 const short kwxCursorSizeNS
= 10;
404 const short kwxCursorSize
= 11;
405 const short kwxCursorSizeNESW
= 12;
406 const short kwxCursorSizeNWSE
= 13;
407 const short kwxCursorRoller
= 14;
408 const short kwxCursorLast
= kwxCursorRoller
;
410 // exposing our fallback cursor map
412 extern ClassicCursor gMacCursors
[];
417 // _WX_PRIVATE_COCOA_H_