]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/cocoa/private.h
Cocoa text fields and views have their own context menus, so we should use those...
[wxWidgets.git] / include / wx / osx / cocoa / private.h
CommitLineData
4849f027
SC
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
5// with "wx".
6// Author: Stefan Csomor
7// Modified by:
8// Created: 1998-01-01
9// RCS-ID: $Id: private.h 53819 2008-05-29 14:11:45Z SC $
10// Copyright: (c) Stefan Csomor
11// Licence: wxWindows licence
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef _WX_PRIVATE_COCOA_H_
15#define _WX_PRIVATE_COCOA_H_
16
17#include "wx/osx/core/private.h"
18
935e6c7d
SC
19#include "wx/defs.h"
20
21#include <ApplicationServices/ApplicationServices.h>
22
7ac5e1c9
SC
23#if wxOSX_USE_ATSU_TEXT
24 // we need theming and atsu
25 #include <Carbon/Carbon.h>
0a84f928
SC
26#else
27 // we only need theming, if we find a better include replace the following
28 #include <Carbon/Carbon.h>
7ac5e1c9
SC
29#endif
30
4849f027 31#ifdef __OBJC__
4849f027 32 #import <Cocoa/Cocoa.h>
4850cc8b 33#endif
4849f027 34
126254a8
SC
35#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
36// available in 10.4 but not in the headers
37enum {
38 kEventMouseScroll = 11
39};
40#endif
524c47aa
SC
41//
42// shared between Cocoa and Carbon
43//
44
b3b17ee7 45// bring in theming types without pulling in the headers
524c47aa 46
935e6c7d 47#if wxUSE_GUI
524c47aa 48typedef SInt16 ThemeBrush;
6da991db 49CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
524c47aa
SC
50OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
51 CGContextRef inContext,
52 const CGRect * inBounds,
53 CGImageRef inImage) ;
6da991db 54WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image );
267ba369 55CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage );
935e6c7d 56#endif
524c47aa 57
935e6c7d 58long UMAGetSystemVersion() ;
524c47aa
SC
59WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
60WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
61WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
62WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
63
bfa92264
KO
64class WXDLLIMPEXP_FWD_CORE wxDialog;
65
524c47aa
SC
66//
67//
68//
69
4849f027
SC
70#if wxUSE_GUI
71
72class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
73{
74public :
03647350
VZ
75 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ;
76 wxWidgetCocoaImpl() ;
77 ~wxWidgetCocoaImpl();
78
4849f027 79 void Init();
03647350 80
4849f027 81 virtual bool IsVisible() const ;
524c47aa
SC
82 virtual void SetVisibility(bool);
83
ab9a0b84
VZ
84 // we provide a static function which can be reused from
85 // wxNonOwnedWindowCocoaImpl too
86 static bool ShowViewOrWindowWithEffect(wxWindow *win,
87 bool show,
88 wxShowEffect effect,
89 unsigned timeout);
90
91 virtual bool ShowWithEffect(bool show,
92 wxShowEffect effect,
93 unsigned timeout);
94
4849f027 95 virtual void Raise();
03647350 96
4849f027
SC
97 virtual void Lower();
98
99 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
100
101 virtual WXWidget GetWXWidget() const { return m_osxView; }
102
524c47aa
SC
103 virtual void SetBackgroundColour(const wxColour&);
104
4849f027
SC
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;
524c47aa 109 virtual void SetControlSize( wxWindowVariant variant );
4849f027
SC
110
111 virtual void SetNeedsDisplay( const wxRect* where = NULL );
112 virtual bool GetNeedsDisplay() const;
113
114 virtual bool CanFocus() const;
115 // return true if successful
116 virtual bool SetFocus();
117 virtual bool HasFocus() const;
118
119 void RemoveFromParent();
120 void Embed( wxWidgetImpl *parent );
524c47aa
SC
121
122 void SetDefaultButton( bool isDefault );
123 void PerformClick();
a4e32492 124 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
524c47aa 125
54f11060
SC
126 void SetCursor( const wxCursor & cursor );
127 void CaptureMouse();
128 void ReleaseMouse();
129
524c47aa
SC
130 wxInt32 GetValue() const;
131 void SetValue( wxInt32 v );
e5d05b90 132 wxBitmap GetBitmap() const;
524c47aa 133 void SetBitmap( const wxBitmap& bitmap );
e5d05b90 134 void SetBitmapPosition( wxDirection dir );
524c47aa
SC
135 void SetupTabs( const wxNotebook &notebook );
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 );
19c7ac3d
SC
142 wxInt32 GetMinimum() const;
143 wxInt32 GetMaximum() const;
524c47aa
SC
144 void PulseGauge();
145 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
146
1e181c7a 147 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
a7b9865d 148 void SetToolTip( wxToolTip* tooltip );
1e181c7a 149
c4825ef7 150 void InstallEventHandler( WXWidget control = NULL );
03647350
VZ
151
152 virtual bool DoHandleMouseEvent(NSEvent *event);
f0e0116e
KO
153 virtual bool DoHandleKeyEvent(NSEvent *event);
154 virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
03647350 155 virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
030495ec 156
ddbc8ac9
SC
157 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
158 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
159
4850cc8b 160
4dd9fdf8 161 void SetFlipped(bool flipped);
ee032c59 162 virtual bool IsFlipped() const { return m_isFlipped; }
96defed0
SC
163
164 // cocoa thunk connected calls
4dd9fdf8
SC
165
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);
f0e0116e 172 virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
4dd9fdf8 173 virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
09a9eb20 174 virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
4dd9fdf8
SC
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);
03647350 180
e32090ba
SC
181 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
182 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
75a2c6a1
KO
183
184 // for wxTextCtrl-derived classes, put here since they don't all derive
185 // from the same pimpl class.
186 virtual void controlTextDidChange();
4dd9fdf8 187
4849f027
SC
188protected:
189 WXWidget m_osxView;
f0e0116e 190 NSEvent* m_lastKeyDownEvent;
4dd9fdf8 191 bool m_isFlipped;
7cb2a241 192 // if it the control has an editor, that editor will already send some
03647350 193 // events, don't resend them
7cb2a241 194 bool m_hasEditor;
03647350 195
4849f027
SC
196 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
197};
198
ffad7b0d
SC
199DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
200
4849f027
SC
201class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
202{
203public :
204 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
205 wxNonOwnedWindowCocoaImpl();
03647350 206
4849f027 207 virtual ~wxNonOwnedWindowCocoaImpl();
03647350 208
0aaa6ace 209 virtual void WillBeDestroyed() ;
4849f027
SC
210 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
211 long style, long extraStyle, const wxString& name ) ;
03647350 212
4849f027 213 WXWindow GetWXWindow() const;
03647350 214 void Raise();
4849f027 215 void Lower();
03647350 216 bool Show(bool show);
ab9a0b84
VZ
217
218 virtual bool ShowWithEffect(bool show,
219 wxShowEffect effect,
220 unsigned timeout);
03647350 221
4849f027
SC
222 void Update();
223 bool SetTransparent(wxByte alpha);
224 bool SetBackgroundColour(const wxColour& col );
03647350 225 void SetExtraStyle( long exStyle );
b6dc21e7 226 void SetWindowStyleFlag( long style );
03647350 227 bool SetBackgroundStyle(wxBackgroundStyle style);
4849f027
SC
228 bool CanSetTransparent();
229
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;
233
03647350 234 void GetContentArea( int &left , int &top , int &width , int &height ) const;
4849f027 235 bool SetShape(const wxRegion& region);
03647350 236
4849f027 237 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
03647350 238
4849f027 239 virtual bool IsMaximized() const;
03647350 240
4849f027 241 virtual bool IsIconized() const;
03647350 242
4849f027 243 virtual void Iconize( bool iconize );
03647350 244
4849f027 245 virtual void Maximize(bool maximize);
03647350 246
4849f027 247 virtual bool IsFullScreen() const;
03647350 248
4849f027 249 virtual bool ShowFullScreen(bool show, long style);
030495ec 250
dbc7ceb9 251 virtual void ShowWithoutActivating();
4849f027
SC
252
253 virtual void RequestUserAttention(int flags);
03647350 254
4849f027 255 virtual void ScreenToWindow( int *x, int *y );
03647350 256
4849f027 257 virtual void WindowToScreen( int *x, int *y );
03647350 258
dbc7ceb9 259 virtual bool IsActive();
efb2fa41
KO
260
261 virtual void SetModified(bool modified);
ebf7d5c4 262 virtual bool IsModified() const;
030495ec 263
4849f027
SC
264 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
265protected :
ffad7b0d 266 WX_wxNSWindow m_macWindow;
4849f027
SC
267 void * m_macFullScreenData ;
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
03647350 269};
4849f027 270
4850cc8b
SC
271#ifdef __OBJC__
272
2acc3915
SC
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 );
03647350
VZ
277
278 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
4850cc8b 279 bool adjustForOrigin = true );
03647350 280
b466e85a 281 // used for many wxControls
03647350 282
b466e85a
SC
283 @interface wxNSButton : NSButton
284 {
411a1c35 285 NSTrackingRectTag rectTag;
b466e85a 286 }
03647350 287
b466e85a
SC
288 @end
289
290 @interface wxNSBox : NSBox
291 {
b466e85a
SC
292 }
293
b466e85a
SC
294 @end
295
7cb2a241
SC
296 @interface wxNSTextFieldEditor : NSTextView
297 {
298 NSEvent* lastKeyDownEvent;
299 }
300
301 @end
302
c8fdb345 303 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
7cb2a241
SC
304 {
305 wxNSTextFieldEditor* fieldEditor;
306 }
307
308 - (wxNSTextFieldEditor*) fieldEditor;
309 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
310
311 @end
312
c8fdb345 313 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
b466e85a 314 {
b466e85a 315 }
7cb2a241
SC
316
317 @end
318
319
030495ec 320 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
7cb2a241
SC
321 {
322 }
030495ec 323
b9cf2753 324 - (void)textDidChange:(NSNotification *)aNotification;
030495ec 325
b466e85a
SC
326 @end
327
ffad7b0d
SC
328 @interface wxNSMenu : NSMenu
329 {
330 wxMenuImpl* impl;
331 }
332
333 - (void) setImplementation:(wxMenuImpl*) item;
334 - (wxMenuImpl*) implementation;
335
03647350 336 @end
ffad7b0d
SC
337
338 @interface wxNSMenuItem : NSMenuItem
339 {
340 wxMenuItemImpl* impl;
341 }
342
343 - (void) setImplementation:(wxMenuItemImpl*) item;
344 - (wxMenuItemImpl*) implementation;
345
346 - (void)clickedAction:(id)sender;
347 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
348
03647350
VZ
349 @end
350
485c6263 351 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
b466e85a 352
724999ee
KO
353 /*
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.
357 */
358 @interface ModalDialogDelegate : NSObject
359 {
360 BOOL sheetFinished;
361 int resultCode;
bfa92264 362 wxDialog* impl;
724999ee
KO
363 }
364
bfa92264 365 - (void)setImplementation: (wxDialog *)dialog;
724999ee
KO
366 - (BOOL)finished;
367 - (int)code;
368 - (void)waitForSheetToFinish;
369 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
370 @end
371
372
4850cc8b
SC
373#endif // __OBJC__
374
4849f027
SC
375// NSCursor
376
377WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
378WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
379void wxMacCocoaSetCursor( WX_NSCursor cursor );
380void wxMacCocoaHideCursor();
381void wxMacCocoaShowCursor();
382
383typedef struct tagClassicCursor
384{
385 wxUint16 bits[16];
386 wxUint16 mask[16];
387 wxInt16 hotspot[2];
388}ClassicCursor;
389
524c47aa
SC
390const short kwxCursorBullseye = 0;
391const short kwxCursorBlank = 1;
392const short kwxCursorPencil = 2;
393const short kwxCursorMagnifier = 3;
394const short kwxCursorNoEntry = 4;
395const short kwxCursorPaintBrush = 5;
396const short kwxCursorPointRight = 6;
397const short kwxCursorPointLeft = 7;
398const short kwxCursorQuestionArrow = 8;
399const short kwxCursorRightArrow = 9;
400const short kwxCursorSizeNS = 10;
401const short kwxCursorSize = 11;
402const short kwxCursorSizeNESW = 12;
403const short kwxCursorSizeNWSE = 13;
404const short kwxCursorRoller = 14;
405const short kwxCursorLast = kwxCursorRoller;
406
407// exposing our fallback cursor map
408
409extern ClassicCursor gMacCursors[];
410
4849f027
SC
411#endif
412
413#endif
414 // _WX_PRIVATE_COCOA_H_
415