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 <ApplicationServices/ApplicationServices.h>
20 #import <Cocoa/Cocoa.h>
23 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
24 // available in 10.4 but not in the headers
26 kEventMouseScroll
= 11
30 // shared between Cocoa and Carbon
33 // bring in theming types without pulling in the headers
36 typedef SInt16 ThemeBrush
;
37 CGColorRef WXDLLIMPEXP_CORE
wxMacCreateCGColorFromHITheme( ThemeBrush brush
) ;
38 OSStatus WXDLLIMPEXP_CORE
wxMacDrawCGImage(
39 CGContextRef inContext
,
40 const CGRect
* inBounds
,
42 WX_NSImage WXDLLIMPEXP_CORE
wxOSXGetNSImageFromCGImage( CGImageRef image
);
43 CGImageRef WXDLLIMPEXP_CORE
wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage
);
45 class WXDLLIMPEXP_FWD_CORE wxDialog
;
47 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl
: public wxWidgetImpl
50 wxWidgetCocoaImpl( wxWindowMac
* peer
, WXWidget w
, bool isRootControl
= false ) ;
56 virtual bool IsVisible() const ;
57 virtual void SetVisibility(bool);
59 // we provide a static function which can be reused from
60 // wxNonOwnedWindowCocoaImpl too
61 static bool ShowViewOrWindowWithEffect(wxWindow
*win
,
66 virtual bool ShowWithEffect(bool show
,
74 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
);
76 virtual WXWidget
GetWXWidget() const { return m_osxView
; }
78 virtual void SetBackgroundColour(const wxColour
&);
79 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
81 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
82 virtual void Move(int x
, int y
, int width
, int height
);
83 virtual void GetPosition( int &x
, int &y
) const;
84 virtual void GetSize( int &width
, int &height
) const;
85 virtual void SetControlSize( wxWindowVariant variant
);
87 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
);
88 virtual bool GetNeedsDisplay() const;
90 virtual bool CanFocus() const;
91 // return true if successful
92 virtual bool SetFocus();
93 virtual bool HasFocus() const;
95 void RemoveFromParent();
96 void Embed( wxWidgetImpl
*parent
);
98 void SetDefaultButton( bool isDefault
);
100 virtual void SetLabel(const wxString
& title
, wxFontEncoding encoding
);
102 void SetCursor( const wxCursor
& cursor
);
106 wxInt32
GetValue() const;
107 void SetValue( wxInt32 v
);
108 wxBitmap
GetBitmap() const;
109 void SetBitmap( const wxBitmap
& bitmap
);
110 void SetBitmapPosition( wxDirection dir
);
111 void SetupTabs( const wxNotebook
¬ebook
);
112 void GetBestRect( wxRect
*r
) const;
113 bool IsEnabled() const;
114 void Enable( bool enable
);
115 bool ButtonClickDidStateChange() { return true ;}
116 void SetMinimum( wxInt32 v
);
117 void SetMaximum( wxInt32 v
);
118 wxInt32
GetMinimum() const;
119 wxInt32
GetMaximum() const;
121 void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
);
123 void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true );
124 void SetToolTip( wxToolTip
* tooltip
);
126 void InstallEventHandler( WXWidget control
= NULL
);
128 virtual bool DoHandleMouseEvent(NSEvent
*event
);
129 virtual bool DoHandleKeyEvent(NSEvent
*event
);
130 virtual bool DoHandleCharEvent(NSEvent
*event
, NSString
*text
);
131 virtual void DoNotifyFocusEvent(bool receivedFocus
, wxWidgetImpl
* otherWindow
);
133 virtual void SetupKeyEvent(wxKeyEvent
&wxevent
, NSEvent
* nsEvent
, NSString
* charString
= NULL
);
134 virtual void SetupMouseEvent(wxMouseEvent
&wxevent
, NSEvent
* nsEvent
);
137 void SetFlipped(bool flipped
);
138 virtual bool IsFlipped() const { return m_isFlipped
; }
140 // cocoa thunk connected calls
142 virtual unsigned int draggingEntered(void* sender
, WXWidget slf
, void* _cmd
);
143 virtual void draggingExited(void* sender
, WXWidget slf
, void* _cmd
);
144 virtual unsigned int draggingUpdated(void* sender
, WXWidget slf
, void* _cmd
);
145 virtual bool performDragOperation(void* sender
, WXWidget slf
, void* _cmd
);
146 virtual void mouseEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
147 virtual void keyEvent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
148 virtual void insertText(NSString
* text
, WXWidget slf
, void* _cmd
);
149 virtual bool performKeyEquivalent(WX_NSEvent event
, WXWidget slf
, void* _cmd
);
150 virtual bool acceptsFirstResponder(WXWidget slf
, void* _cmd
);
151 virtual bool becomeFirstResponder(WXWidget slf
, void* _cmd
);
152 virtual bool resignFirstResponder(WXWidget slf
, void* _cmd
);
153 virtual void resetCursorRects(WXWidget slf
, void* _cmd
);
154 virtual bool isFlipped(WXWidget slf
, void* _cmd
);
155 virtual void drawRect(void* rect
, WXWidget slf
, void* _cmd
);
157 virtual void controlAction(WXWidget slf
, void* _cmd
, void* sender
);
158 virtual void controlDoubleAction(WXWidget slf
, void* _cmd
, void *sender
);
160 // for wxTextCtrl-derived classes, put here since they don't all derive
161 // from the same pimpl class.
162 virtual void controlTextDidChange();
166 NSEvent
* m_lastKeyDownEvent
;
168 // if it the control has an editor, that editor will already send some
169 // events, don't resend them
172 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl
)
175 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow
);
177 class wxNonOwnedWindowCocoaImpl
: public wxNonOwnedWindowImpl
180 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow
* nonownedwnd
) ;
181 wxNonOwnedWindowCocoaImpl();
183 virtual ~wxNonOwnedWindowCocoaImpl();
185 virtual void WillBeDestroyed() ;
186 void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
187 long style
, long extraStyle
, const wxString
& name
) ;
188 void Create( wxWindow
* parent
, WXWindow nativeWindow
);
190 WXWindow
GetWXWindow() const;
193 bool Show(bool show
);
195 virtual bool ShowWithEffect(bool show
,
200 bool SetTransparent(wxByte alpha
);
201 bool SetBackgroundColour(const wxColour
& col
);
202 void SetExtraStyle( long exStyle
);
203 void SetWindowStyleFlag( long style
);
204 bool SetBackgroundStyle(wxBackgroundStyle style
);
205 bool CanSetTransparent();
207 void MoveWindow(int x
, int y
, int width
, int height
);
208 void GetPosition( int &x
, int &y
) const;
209 void GetSize( int &width
, int &height
) const;
211 void GetContentArea( int &left
, int &top
, int &width
, int &height
) const;
212 bool SetShape(const wxRegion
& region
);
214 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) ;
216 virtual bool IsMaximized() const;
218 virtual bool IsIconized() const;
220 virtual void Iconize( bool iconize
);
222 virtual void Maximize(bool maximize
);
224 virtual bool IsFullScreen() const;
226 virtual bool ShowFullScreen(bool show
, long style
);
228 virtual void ShowWithoutActivating();
230 virtual void RequestUserAttention(int flags
);
232 virtual void ScreenToWindow( int *x
, int *y
);
234 virtual void WindowToScreen( int *x
, int *y
);
236 virtual bool IsActive();
238 virtual void SetModified(bool modified
);
239 virtual bool IsModified() const;
241 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
243 WXWindow m_macWindow
;
244 void * m_macFullScreenData
;
245 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl
)
250 WXDLLIMPEXP_CORE NSScreen
* wxOSXGetMenuScreen();
251 WXDLLIMPEXP_CORE NSRect
wxToNSRect( NSView
* parent
, const wxRect
& r
);
252 WXDLLIMPEXP_CORE wxRect
wxFromNSRect( NSView
* parent
, const NSRect
& rect
);
253 WXDLLIMPEXP_CORE NSPoint
wxToNSPoint( NSView
* parent
, const wxPoint
& p
);
254 WXDLLIMPEXP_CORE wxPoint
wxFromNSPoint( NSView
* parent
, const NSPoint
& p
);
256 NSRect WXDLLIMPEXP_CORE
wxOSXGetFrameForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
,
257 bool adjustForOrigin
= true );
259 // used for many wxControls
261 @interface wxNSButton
: NSButton
263 NSTrackingRectTag rectTag
;
268 @interface wxNSBox
: NSBox
274 @interface wxNSTextFieldEditor
: NSTextView
276 NSEvent
* lastKeyDownEvent
;
281 @interface wxNSTextField
: NSTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
283 wxNSTextFieldEditor
* fieldEditor
;
286 - (wxNSTextFieldEditor
*) fieldEditor
;
287 - (void) setFieldEditor
:(wxNSTextFieldEditor
*) fieldEditor
;
291 @interface wxNSSecureTextField
: NSSecureTextField
wxOSX_10_6_AND_LATER(<NSTextFieldDelegate
>)
298 @interface wxNSTextView
: NSTextView
wxOSX_10_6_AND_LATER(<NSTextViewDelegate
>)
302 - (void)textDidChange
:(NSNotification
*)aNotification
;
306 @interface wxNSMenu
: NSMenu
311 - (void) setImplementation
:(wxMenuImpl
*) item
;
312 - (wxMenuImpl
*) implementation
;
316 @interface wxNSMenuItem
: NSMenuItem
318 wxMenuItemImpl
* impl
;
321 - (void) setImplementation
:(wxMenuItemImpl
*) item
;
322 - (wxMenuItemImpl
*) implementation
;
324 - (void)clickedAction
:(id
)sender
;
325 - (BOOL
)validateMenuItem
:(NSMenuItem
*)menuItem
;
329 void WXDLLIMPEXP_CORE
wxOSXCocoaClassAddWXMethods(Class c
);
332 We need this for ShowModal, as the sheet just disables the parent window and
333 returns control to the app, whereas we don't want to return from ShowModal
334 until the sheet has been dismissed.
336 @interface ModalDialogDelegate
: NSObject
343 - (void)setImplementation
: (wxDialog
*)dialog
;
346 - (void)waitForSheetToFinish
;
347 - (void)sheetDidEnd
:(NSWindow
*)sheet returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
;
355 WX_NSCursor
wxMacCocoaCreateStockCursor( int cursor_type
);
356 WX_NSCursor
wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef
, float hotSpotX
, float hotSpotY
);
357 void wxMacCocoaSetCursor( WX_NSCursor cursor
);
358 void wxMacCocoaHideCursor();
359 void wxMacCocoaShowCursor();
361 typedef struct tagClassicCursor
368 const short kwxCursorBullseye
= 0;
369 const short kwxCursorBlank
= 1;
370 const short kwxCursorPencil
= 2;
371 const short kwxCursorMagnifier
= 3;
372 const short kwxCursorNoEntry
= 4;
373 const short kwxCursorPaintBrush
= 5;
374 const short kwxCursorPointRight
= 6;
375 const short kwxCursorPointLeft
= 7;
376 const short kwxCursorQuestionArrow
= 8;
377 const short kwxCursorRightArrow
= 9;
378 const short kwxCursorSizeNS
= 10;
379 const short kwxCursorSize
= 11;
380 const short kwxCursorSizeNESW
= 12;
381 const short kwxCursorSizeNWSE
= 13;
382 const short kwxCursorRoller
= 14;
383 const short kwxCursorLast
= kwxCursorRoller
;
385 // exposing our fallback cursor map
387 extern ClassicCursor gMacCursors
[];
392 // _WX_PRIVATE_COCOA_H_