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>
36 // shared between Cocoa and Carbon
39 // bring in theming types without pulling in the headers
42 typedef SInt16 ThemeBrush
;
43 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
44 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
45 CGContextRef inContext
,
46 const CGRect
* inBounds
,
48 WX_NSImage WXDLLIMPEXP_CORE
wxOSXCreateNSImageFromCGImage( CGImageRef image
);
49 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
);
52 long UMAGetSystemVersion() ;
53 WXDLLIMPEXP_BASE
void wxMacStringToPascal( const wxString
&from
, StringPtr to
);
54 WXDLLIMPEXP_BASE wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
);
55 WXDLLIMPEXP_BASE OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
);
56 WXDLLIMPEXP_BASE wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
);
58 class WXDLLIMPEXP_FWD_CORE wxDialog
;
66 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
69 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
75 virtual bool IsVisible() const ;
76 virtual void SetVisibility(bool);
78 // we provide a static function which can be reused from
79 // wxNonOwnedWindowCocoaImpl too
80 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
85 virtual bool ShowWithEffect(bool show
,
93 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
95 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
97 virtual void SetBackgroundColour(const wxColour
&);
99 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
100 virtual void Move(int x
, int y
, int width
, int height
);
101 virtual void GetPosition( int &x
, int &y
) const;
102 virtual void GetSize( int &width
, int &height
) const;
103 virtual void SetControlSize( wxWindowVariant variant
);
105 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
106 virtual bool GetNeedsDisplay() const;
108 virtual bool CanFocus() const;
109 // return true if successful
110 virtual bool SetFocus();
111 virtual bool HasFocus() const;
113 void RemoveFromParent();
114 void Embed( wxWidgetImpl
*parent
);
116 void SetDefaultButton( bool isDefault
);
118 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
120 void SetCursor( const wxCursor
& cursor
);
124 wxInt32
GetValue() const;
125 void SetValue( wxInt32 v
);
126 wxBitmap
GetBitmap() const;
127 void SetBitmap( const wxBitmap
& bitmap
);
128 void SetBitmapPosition( wxDirection dir
);
129 void SetupTabs( const wxNotebook
¬ebook
);
130 void GetBestRect( wxRect
*r
) const;
131 bool IsEnabled() const;
132 void Enable( bool enable
);
133 bool ButtonClickDidStateChange() { return true ;}
134 void SetMinimum( wxInt32 v
);
135 void SetMaximum( wxInt32 v
);
136 wxInt32
GetMinimum() const;
137 wxInt32
GetMaximum() const;
139 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
141 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
143 void InstallEventHandler( WXWidget control
= NULL
);
145 virtual bool DoHandleMouseEvent(NSEvent
*event
);
146 virtual bool DoHandleKeyEvent(NSEvent
*event
);
147 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
148 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
150 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
151 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
154 void SetFlipped(bool flipped
);
155 virtual bool IsFlipped() const { return m_isFlipped
; }
157 // cocoa thunk connected calls
159 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
160 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
161 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
162 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
163 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
164 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
165 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
166 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
167 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
168 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
169 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
170 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
171 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
);
179 NSEvent
* m_lastKeyDownEvent
;
181 // if it the control has an editor, that editor will already send some
182 // events, don't resend them
185 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
188 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
190 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
193 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
194 wxNonOwnedWindowCocoaImpl();
196 virtual ~wxNonOwnedWindowCocoaImpl();
198 virtual void WillBeDestroyed() ;
199 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
200 long style
, long extraStyle
, const wxString
& name
) ;
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 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
255 WX_wxNSWindow m_macWindow
;
256 void * m_macFullScreenData
;
257 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
262 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
263 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
264 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
265 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
267 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
268 bool adjustForOrigin
= true );
270 // used for many wxControls
272 @interface wxNSButton
: NSButton
274 NSTrackingRectTag rectTag
;
279 @interface wxNSBox
: NSBox
285 @interface wxNSTextFieldEditor
: NSTextView
287 NSEvent
* lastKeyDownEvent
;
292 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
294 wxNSTextFieldEditor
* fieldEditor
;
297 - (wxNSTextFieldEditor
*) fieldEditor
;
298 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
302 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
309 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
313 - (void)textDidChange
:(NSNotification
*)aNotification
;
317 @interface wxNSMenu
: NSMenu
322 - (void) setImplementation
:(wxMenuImpl
*) item
;
323 - (wxMenuImpl
*) implementation
;
327 @interface wxNSMenuItem
: NSMenuItem
329 wxMenuItemImpl
* impl
;
332 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
333 - (wxMenuItemImpl
*) implementation
;
335 - (void)clickedAction
:(id
)sender
;
336 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
340 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
343 We need this for ShowModal, as the sheet just disables the parent window and
344 returns control to the app, whereas we don't want to return from ShowModal
345 until the sheet has been dismissed.
347 @interface ModalDialogDelegate
: NSObject
354 - (void)setImplementation
: (wxDialog
*)dialog
;
357 - (void)waitForSheetToFinish
;
358 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
366 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
367 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
368 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
369 void wxMacCocoaHideCursor();
370 void wxMacCocoaShowCursor();
372 typedef struct tagClassicCursor
379 const short kwxCursorBullseye
= 0;
380 const short kwxCursorBlank
= 1;
381 const short kwxCursorPencil
= 2;
382 const short kwxCursorMagnifier
= 3;
383 const short kwxCursorNoEntry
= 4;
384 const short kwxCursorPaintBrush
= 5;
385 const short kwxCursorPointRight
= 6;
386 const short kwxCursorPointLeft
= 7;
387 const short kwxCursorQuestionArrow
= 8;
388 const short kwxCursorRightArrow
= 9;
389 const short kwxCursorSizeNS
= 10;
390 const short kwxCursorSize
= 11;
391 const short kwxCursorSizeNESW
= 12;
392 const short kwxCursorSizeNWSE
= 13;
393 const short kwxCursorRoller
= 14;
394 const short kwxCursorLast
= kwxCursorRoller
;
396 // exposing our fallback cursor map
398 extern ClassicCursor gMacCursors
[];
403 // _WX_PRIVATE_COCOA_H_