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
);
51 long UMAGetSystemVersion() ;
52 WXDLLIMPEXP_BASE
void wxMacStringToPascal( const wxString
&from
, StringPtr to
);
53 WXDLLIMPEXP_BASE wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
);
54 WXDLLIMPEXP_BASE OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
);
55 WXDLLIMPEXP_BASE wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
);
63 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
66 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
72 virtual bool IsVisible() const ;
73 virtual void SetVisibility(bool);
79 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
81 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
83 virtual void SetBackgroundColour(const wxColour
&);
85 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
86 virtual void Move(int x
, int y
, int width
, int height
);
87 virtual void GetPosition( int &x
, int &y
) const;
88 virtual void GetSize( int &width
, int &height
) const;
89 virtual void SetControlSize( wxWindowVariant variant
);
91 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
92 virtual bool GetNeedsDisplay() const;
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 wxInt32
GetValue() const;
111 void SetValue( wxInt32 v
);
112 wxBitmap
GetBitmap() const;
113 void SetBitmap( const wxBitmap
& bitmap
);
114 void SetBitmapPosition( wxDirection dir
);
115 void SetupTabs( const wxNotebook
¬ebook
);
116 void GetBestRect( wxRect
*r
) const;
117 bool IsEnabled() const;
118 void Enable( bool enable
);
119 bool ButtonClickDidStateChange() { return true ;}
120 void SetMinimum( wxInt32 v
);
121 void SetMaximum( wxInt32 v
);
122 wxInt32
GetMinimum() const;
123 wxInt32
GetMaximum() const;
125 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
127 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
129 void InstallEventHandler( WXWidget control
= NULL
);
131 virtual bool DoHandleMouseEvent(NSEvent
*event
);
132 virtual bool DoHandleKeyEvent(NSEvent
*event
);
133 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
134 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
136 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
137 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
140 void SetFlipped(bool flipped
);
141 virtual bool IsFlipped() const { return m_isFlipped
; }
143 // cocoa thunk connected calls
145 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
146 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
147 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
148 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
149 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
150 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
151 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
152 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
153 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
154 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
155 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
156 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
157 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
158 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
160 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
161 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
165 NSEvent
* m_lastKeyDownEvent
;
167 // if it the control has an editor, that editor will already send some
168 // events, don't resend them
171 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
174 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
176 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
179 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
180 wxNonOwnedWindowCocoaImpl();
182 virtual ~wxNonOwnedWindowCocoaImpl();
184 virtual void Destroy() ;
185 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
186 long style
, long extraStyle
, const wxString
& name
) ;
188 WXWindow
GetWXWindow() const;
191 bool Show(bool show
);
192 bool ShowWithEffect(bool show
, wxShowEffect effect
, unsigned timeout
);
195 bool SetTransparent(wxByte alpha
);
196 bool SetBackgroundColour(const wxColour
& col
);
197 void SetExtraStyle( long exStyle
);
198 bool SetBackgroundStyle(wxBackgroundStyle style
);
199 bool CanSetTransparent();
201 void MoveWindow(int x
, int y
, int width
, int height
);
202 void GetPosition( int &x
, int &y
) const;
203 void GetSize( int &width
, int &height
) const;
205 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
206 bool SetShape(const wxRegion
& region
);
208 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
210 virtual bool IsMaximized() const;
212 virtual bool IsIconized() const;
214 virtual void Iconize( bool iconize
);
216 virtual void Maximize(bool maximize
);
218 virtual bool IsFullScreen() const;
220 virtual bool ShowFullScreen(bool show
, long style
);
222 virtual void RequestUserAttention(int flags
);
224 virtual void ScreenToWindow( int *x
, int *y
);
226 virtual void WindowToScreen( int *x
, int *y
);
228 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
230 WX_wxNSWindow m_macWindow
;
231 void * m_macFullScreenData
;
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
237 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
238 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
239 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
240 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
242 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
243 bool adjustForOrigin
= true );
245 // used for many wxControls
247 @interface wxNSButton
: NSButton
253 @interface wxNSBox
: NSBox
259 @interface wxNSTextFieldEditor
: NSTextView
261 NSEvent
* lastKeyDownEvent
;
266 @interface wxNSTextField
: NSTextField
268 wxNSTextFieldEditor
* fieldEditor
;
271 - (wxNSTextFieldEditor
*) fieldEditor
;
272 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
276 @interface wxNSSecureTextField
: NSSecureTextField
283 @interface wxNSTextView
: NSTextView
289 @interface wxNSMenu
: NSMenu
294 - (void) setImplementation
:(wxMenuImpl
*) item
;
295 - (wxMenuImpl
*) implementation
;
299 @interface wxNSMenuItem
: NSMenuItem
301 wxMenuItemImpl
* impl
;
304 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
305 - (wxMenuItemImpl
*) implementation
;
307 - (void)clickedAction
:(id
)sender
;
308 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
312 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
315 We need this for ShowModal, as the sheet just disables the parent window and
316 returns control to the app, whereas we don't want to return from ShowModal
317 until the sheet has been dismissed.
319 @interface ModalDialogDelegate
: NSObject
327 - (void)waitForSheetToFinish
;
328 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
336 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
337 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
338 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
339 void wxMacCocoaHideCursor();
340 void wxMacCocoaShowCursor();
342 typedef struct tagClassicCursor
349 const short kwxCursorBullseye
= 0;
350 const short kwxCursorBlank
= 1;
351 const short kwxCursorPencil
= 2;
352 const short kwxCursorMagnifier
= 3;
353 const short kwxCursorNoEntry
= 4;
354 const short kwxCursorPaintBrush
= 5;
355 const short kwxCursorPointRight
= 6;
356 const short kwxCursorPointLeft
= 7;
357 const short kwxCursorQuestionArrow
= 8;
358 const short kwxCursorRightArrow
= 9;
359 const short kwxCursorSizeNS
= 10;
360 const short kwxCursorSize
= 11;
361 const short kwxCursorSizeNESW
= 12;
362 const short kwxCursorSizeNWSE
= 13;
363 const short kwxCursorRoller
= 14;
364 const short kwxCursorLast
= kwxCursorRoller
;
366 // exposing our fallback cursor map
368 extern ClassicCursor gMacCursors
[];
373 // _WX_PRIVATE_COCOA_H_