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
wxOSXCreateNSImageFromCGImage( 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
&);
105 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
106 virtual void Move(int x
, int y
, int width
, int height
);
107 virtual void GetPosition( int &x
, int &y
) const;
108 virtual void GetSize( int &width
, int &height
) const;
109 virtual void SetControlSize( wxWindowVariant variant
);
111 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
112 virtual bool GetNeedsDisplay() const;
114 virtual bool CanFocus() const;
115 // return true if successful
116 virtual bool SetFocus();
117 virtual bool HasFocus() const;
119 void RemoveFromParent();
120 void Embed( wxWidgetImpl
*parent
);
122 void SetDefaultButton( bool isDefault
);
124 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
126 void SetCursor( const wxCursor
& cursor
);
130 wxInt32
GetValue() const;
131 void SetValue( wxInt32 v
);
132 wxBitmap
GetBitmap() const;
133 void SetBitmap( const wxBitmap
& bitmap
);
134 void SetBitmapPosition( wxDirection dir
);
135 void SetupTabs( const wxNotebook
¬ebook
);
136 void GetBestRect( wxRect
*r
) const;
137 bool IsEnabled() const;
138 void Enable( bool enable
);
139 bool ButtonClickDidStateChange() { return true ;}
140 void SetMinimum( wxInt32 v
);
141 void SetMaximum( wxInt32 v
);
142 wxInt32
GetMinimum() const;
143 wxInt32
GetMaximum() const;
145 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
147 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
148 void SetToolTip( wxToolTip
* tooltip
);
150 void InstallEventHandler( WXWidget control
= NULL
);
152 virtual bool DoHandleMouseEvent(NSEvent
*event
);
153 virtual bool DoHandleKeyEvent(NSEvent
*event
);
154 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
155 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
157 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
158 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
161 void SetFlipped(bool flipped
);
162 virtual bool IsFlipped() const { return m_isFlipped
; }
164 // cocoa thunk connected calls
166 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
167 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
168 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
169 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
170 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
171 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
172 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
173 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
174 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
175 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
176 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
177 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
178 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
179 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
181 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
182 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
184 // for wxTextCtrl-derived classes, put here since they don't all derive
185 // from the same pimpl class.
186 virtual void controlTextDidChange();
190 NSEvent
* m_lastKeyDownEvent
;
192 // if it the control has an editor, that editor will already send some
193 // events, don't resend them
196 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
199 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
201 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
204 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
205 wxNonOwnedWindowCocoaImpl();
207 virtual ~wxNonOwnedWindowCocoaImpl();
209 virtual void WillBeDestroyed() ;
210 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
211 long style
, long extraStyle
, const wxString
& name
) ;
213 WXWindow
GetWXWindow() const;
216 bool Show(bool show
);
218 virtual bool ShowWithEffect(bool show
,
223 bool SetTransparent(wxByte alpha
);
224 bool SetBackgroundColour(const wxColour
& col
);
225 void SetExtraStyle( long exStyle
);
226 void SetWindowStyleFlag( long style
);
227 bool SetBackgroundStyle(wxBackgroundStyle style
);
228 bool CanSetTransparent();
230 void MoveWindow(int x
, int y
, int width
, int height
);
231 void GetPosition( int &x
, int &y
) const;
232 void GetSize( int &width
, int &height
) const;
234 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
235 bool SetShape(const wxRegion
& region
);
237 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
239 virtual bool IsMaximized() const;
241 virtual bool IsIconized() const;
243 virtual void Iconize( bool iconize
);
245 virtual void Maximize(bool maximize
);
247 virtual bool IsFullScreen() const;
249 virtual bool ShowFullScreen(bool show
, long style
);
251 virtual void ShowWithoutActivating();
253 virtual void RequestUserAttention(int flags
);
255 virtual void ScreenToWindow( int *x
, int *y
);
257 virtual void WindowToScreen( int *x
, int *y
);
259 virtual bool IsActive();
261 virtual void SetModified(bool modified
);
262 virtual bool IsModified() const;
264 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
266 WX_wxNSWindow m_macWindow
;
267 void * m_macFullScreenData
;
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
273 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
274 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
275 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
276 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
278 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
279 bool adjustForOrigin
= true );
281 // used for many wxControls
283 @interface wxNSButton
: NSButton
285 NSTrackingRectTag rectTag
;
290 @interface wxNSBox
: NSBox
296 @interface wxNSTextFieldEditor
: NSTextView
298 NSEvent
* lastKeyDownEvent
;
303 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
305 wxNSTextFieldEditor
* fieldEditor
;
308 - (wxNSTextFieldEditor
*) fieldEditor
;
309 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
313 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
320 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
324 - (void)textDidChange
:(NSNotification
*)aNotification
;
328 @interface wxNSMenu
: NSMenu
333 - (void) setImplementation
:(wxMenuImpl
*) item
;
334 - (wxMenuImpl
*) implementation
;
338 @interface wxNSMenuItem
: NSMenuItem
340 wxMenuItemImpl
* impl
;
343 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
344 - (wxMenuItemImpl
*) implementation
;
346 - (void)clickedAction
:(id
)sender
;
347 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
351 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
354 We need this for ShowModal, as the sheet just disables the parent window and
355 returns control to the app, whereas we don't want to return from ShowModal
356 until the sheet has been dismissed.
358 @interface ModalDialogDelegate
: NSObject
365 - (void)setImplementation
: (wxDialog
*)dialog
;
368 - (void)waitForSheetToFinish
;
369 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
377 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
378 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
379 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
380 void wxMacCocoaHideCursor();
381 void wxMacCocoaShowCursor();
383 typedef struct tagClassicCursor
390 const short kwxCursorBullseye
= 0;
391 const short kwxCursorBlank
= 1;
392 const short kwxCursorPencil
= 2;
393 const short kwxCursorMagnifier
= 3;
394 const short kwxCursorNoEntry
= 4;
395 const short kwxCursorPaintBrush
= 5;
396 const short kwxCursorPointRight
= 6;
397 const short kwxCursorPointLeft
= 7;
398 const short kwxCursorQuestionArrow
= 8;
399 const short kwxCursorRightArrow
= 9;
400 const short kwxCursorSizeNS
= 10;
401 const short kwxCursorSize
= 11;
402 const short kwxCursorSizeNESW
= 12;
403 const short kwxCursorSizeNWSE
= 13;
404 const short kwxCursorRoller
= 14;
405 const short kwxCursorLast
= kwxCursorRoller
;
407 // exposing our fallback cursor map
409 extern ClassicCursor gMacCursors
[];
414 // _WX_PRIVATE_COCOA_H_