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
);
64 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
67 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
73 virtual bool IsVisible() const ;
74 virtual void SetVisibility(bool);
76 // we provide a static function which can be reused from
77 // wxNonOwnedWindowCocoaImpl too
78 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
83 virtual bool ShowWithEffect(bool show
,
91 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
93 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
95 virtual void SetBackgroundColour(const wxColour
&);
97 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
98 virtual void Move(int x
, int y
, int width
, int height
);
99 virtual void GetPosition( int &x
, int &y
) const;
100 virtual void GetSize( int &width
, int &height
) const;
101 virtual void SetControlSize( wxWindowVariant variant
);
103 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
104 virtual bool GetNeedsDisplay() const;
106 virtual bool CanFocus() const;
107 // return true if successful
108 virtual bool SetFocus();
109 virtual bool HasFocus() const;
111 void RemoveFromParent();
112 void Embed( wxWidgetImpl
*parent
);
114 void SetDefaultButton( bool isDefault
);
116 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
118 void SetCursor( const wxCursor
& cursor
);
122 wxInt32
GetValue() const;
123 void SetValue( wxInt32 v
);
124 wxBitmap
GetBitmap() const;
125 void SetBitmap( const wxBitmap
& bitmap
);
126 void SetBitmapPosition( wxDirection dir
);
127 void SetupTabs( const wxNotebook
¬ebook
);
128 void GetBestRect( wxRect
*r
) const;
129 bool IsEnabled() const;
130 void Enable( bool enable
);
131 bool ButtonClickDidStateChange() { return true ;}
132 void SetMinimum( wxInt32 v
);
133 void SetMaximum( wxInt32 v
);
134 wxInt32
GetMinimum() const;
135 wxInt32
GetMaximum() const;
137 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
139 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
141 void InstallEventHandler( WXWidget control
= NULL
);
143 virtual bool DoHandleMouseEvent(NSEvent
*event
);
144 virtual bool DoHandleKeyEvent(NSEvent
*event
);
145 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
146 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
148 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
149 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
152 void SetFlipped(bool flipped
);
153 virtual bool IsFlipped() const { return m_isFlipped
; }
155 // cocoa thunk connected calls
157 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
158 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
159 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
160 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
161 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
162 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
163 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
164 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
165 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
166 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
167 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
168 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
169 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
170 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
172 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
173 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
177 NSEvent
* m_lastKeyDownEvent
;
179 // if it the control has an editor, that editor will already send some
180 // events, don't resend them
183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
186 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
188 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
191 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
192 wxNonOwnedWindowCocoaImpl();
194 virtual ~wxNonOwnedWindowCocoaImpl();
196 virtual void Destroy() ;
197 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
198 long style
, long extraStyle
, const wxString
& name
) ;
200 WXWindow
GetWXWindow() const;
203 bool Show(bool show
);
205 virtual bool ShowWithEffect(bool show
,
210 bool SetTransparent(wxByte alpha
);
211 bool SetBackgroundColour(const wxColour
& col
);
212 void SetExtraStyle( long exStyle
);
213 bool SetBackgroundStyle(wxBackgroundStyle style
);
214 bool CanSetTransparent();
216 void MoveWindow(int x
, int y
, int width
, int height
);
217 void GetPosition( int &x
, int &y
) const;
218 void GetSize( int &width
, int &height
) const;
220 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
221 bool SetShape(const wxRegion
& region
);
223 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
225 virtual bool IsMaximized() const;
227 virtual bool IsIconized() const;
229 virtual void Iconize( bool iconize
);
231 virtual void Maximize(bool maximize
);
233 virtual bool IsFullScreen() const;
235 virtual bool ShowFullScreen(bool show
, long style
);
237 virtual void ShowWithoutActivating();
239 virtual void RequestUserAttention(int flags
);
241 virtual void ScreenToWindow( int *x
, int *y
);
243 virtual void WindowToScreen( int *x
, int *y
);
245 virtual bool IsActive();
247 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
249 WX_wxNSWindow m_macWindow
;
250 void * m_macFullScreenData
;
251 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
256 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
257 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
258 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
259 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
261 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
262 bool adjustForOrigin
= true );
264 // used for many wxControls
266 @interface wxNSButton
: NSButton
268 NSTrackingRectTag rectTag
;
273 @interface wxNSBox
: NSBox
279 @interface wxNSTextFieldEditor
: NSTextView
281 NSEvent
* lastKeyDownEvent
;
286 @interface wxNSTextField
: NSTextField
288 wxNSTextFieldEditor
* fieldEditor
;
291 - (wxNSTextFieldEditor
*) fieldEditor
;
292 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
296 @interface wxNSSecureTextField
: NSSecureTextField
303 @interface wxNSTextView
: NSTextView
309 @interface wxNSMenu
: NSMenu
314 - (void) setImplementation
:(wxMenuImpl
*) item
;
315 - (wxMenuImpl
*) implementation
;
319 @interface wxNSMenuItem
: NSMenuItem
321 wxMenuItemImpl
* impl
;
324 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
325 - (wxMenuItemImpl
*) implementation
;
327 - (void)clickedAction
:(id
)sender
;
328 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
332 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
335 We need this for ShowModal, as the sheet just disables the parent window and
336 returns control to the app, whereas we don't want to return from ShowModal
337 until the sheet has been dismissed.
339 @interface ModalDialogDelegate
: NSObject
347 - (void)waitForSheetToFinish
;
348 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
356 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
357 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
358 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
359 void wxMacCocoaHideCursor();
360 void wxMacCocoaShowCursor();
362 typedef struct tagClassicCursor
369 const short kwxCursorBullseye
= 0;
370 const short kwxCursorBlank
= 1;
371 const short kwxCursorPencil
= 2;
372 const short kwxCursorMagnifier
= 3;
373 const short kwxCursorNoEntry
= 4;
374 const short kwxCursorPaintBrush
= 5;
375 const short kwxCursorPointRight
= 6;
376 const short kwxCursorPointLeft
= 7;
377 const short kwxCursorQuestionArrow
= 8;
378 const short kwxCursorRightArrow
= 9;
379 const short kwxCursorSizeNS
= 10;
380 const short kwxCursorSize
= 11;
381 const short kwxCursorSizeNESW
= 12;
382 const short kwxCursorSizeNWSE
= 13;
383 const short kwxCursorRoller
= 14;
384 const short kwxCursorLast
= kwxCursorRoller
;
386 // exposing our fallback cursor map
388 extern ClassicCursor gMacCursors
[];
393 // _WX_PRIVATE_COCOA_H_