]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
adding standard menu items for cocoa, adding translation macro to menulabels, fixes...
[wxWidgets.git] / include / wx / osx / cocoa / private.h
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 <ApplicationServices/ApplicationServices.h>
18
19 #ifdef __OBJC__
20 #import <Cocoa/Cocoa.h>
21 #endif
22
23 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
24 // available in 10.4 but not in the headers
25 enum {
26 kEventMouseScroll = 11
27 };
28 #endif
29 //
30 // shared between Cocoa and Carbon
31 //
32
33 // bring in theming types without pulling in the headers
34
35 #if wxUSE_GUI
36 typedef SInt16 ThemeBrush;
37 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
38 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
39 CGContextRef inContext,
40 const CGRect * inBounds,
41 CGImageRef inImage) ;
42 WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image );
43 CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage );
44
45 class WXDLLIMPEXP_FWD_CORE wxDialog;
46
47 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
48 {
49 public :
50 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ;
51 wxWidgetCocoaImpl() ;
52 ~wxWidgetCocoaImpl();
53
54 void Init();
55
56 virtual bool IsVisible() const ;
57 virtual void SetVisibility(bool);
58
59 // we provide a static function which can be reused from
60 // wxNonOwnedWindowCocoaImpl too
61 static bool ShowViewOrWindowWithEffect(wxWindow *win,
62 bool show,
63 wxShowEffect effect,
64 unsigned timeout);
65
66 virtual bool ShowWithEffect(bool show,
67 wxShowEffect effect,
68 unsigned timeout);
69
70 virtual void Raise();
71
72 virtual void Lower();
73
74 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
75
76 virtual WXWidget GetWXWidget() const { return m_osxView; }
77
78 virtual void SetBackgroundColour(const wxColour&);
79 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
80
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 );
86
87 virtual void SetNeedsDisplay( const wxRect* where = NULL );
88 virtual bool GetNeedsDisplay() const;
89
90 virtual bool CanFocus() const;
91 // return true if successful
92 virtual bool SetFocus();
93 virtual bool HasFocus() const;
94
95 void RemoveFromParent();
96 void Embed( wxWidgetImpl *parent );
97
98 void SetDefaultButton( bool isDefault );
99 void PerformClick();
100 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
101
102 void SetCursor( const wxCursor & cursor );
103 void CaptureMouse();
104 void ReleaseMouse();
105
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 &notebook );
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;
120 void PulseGauge();
121 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
122
123 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
124 void SetToolTip( wxToolTip* tooltip );
125
126 void InstallEventHandler( WXWidget control = NULL );
127
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);
132
133 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
134 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
135
136
137 void SetFlipped(bool flipped);
138 virtual bool IsFlipped() const { return m_isFlipped; }
139
140 // cocoa thunk connected calls
141
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);
156
157 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
158 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
159
160 // for wxTextCtrl-derived classes, put here since they don't all derive
161 // from the same pimpl class.
162 virtual void controlTextDidChange();
163
164 protected:
165 WXWidget m_osxView;
166 NSEvent* m_lastKeyDownEvent;
167 bool m_isFlipped;
168 // if it the control has an editor, that editor will already send some
169 // events, don't resend them
170 bool m_hasEditor;
171
172 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
173 };
174
175 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
176
177 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
178 {
179 public :
180 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
181 wxNonOwnedWindowCocoaImpl();
182
183 virtual ~wxNonOwnedWindowCocoaImpl();
184
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 );
189
190 WXWindow GetWXWindow() const;
191 void Raise();
192 void Lower();
193 bool Show(bool show);
194
195 virtual bool ShowWithEffect(bool show,
196 wxShowEffect effect,
197 unsigned timeout);
198
199 void Update();
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();
206
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;
210
211 void GetContentArea( int &left , int &top , int &width , int &height ) const;
212 bool SetShape(const wxRegion& region);
213
214 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
215
216 virtual bool IsMaximized() const;
217
218 virtual bool IsIconized() const;
219
220 virtual void Iconize( bool iconize );
221
222 virtual void Maximize(bool maximize);
223
224 virtual bool IsFullScreen() const;
225
226 virtual bool ShowFullScreen(bool show, long style);
227
228 virtual void ShowWithoutActivating();
229
230 virtual void RequestUserAttention(int flags);
231
232 virtual void ScreenToWindow( int *x, int *y );
233
234 virtual void WindowToScreen( int *x, int *y );
235
236 virtual bool IsActive();
237
238 virtual void SetModified(bool modified);
239 virtual bool IsModified() const;
240
241 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
242 protected :
243 WXWindow m_macWindow;
244 void * m_macFullScreenData ;
245 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
246 };
247
248 #ifdef __OBJC__
249
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 );
255
256 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
257 bool adjustForOrigin = true );
258
259 // used for many wxControls
260
261 @interface wxNSButton : NSButton
262 {
263 NSTrackingRectTag rectTag;
264 }
265
266 @end
267
268 @interface wxNSBox : NSBox
269 {
270 }
271
272 @end
273
274 @interface wxNSTextFieldEditor : NSTextView
275 {
276 NSEvent* lastKeyDownEvent;
277 }
278
279 @end
280
281 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
282 {
283 wxNSTextFieldEditor* fieldEditor;
284 }
285
286 - (wxNSTextFieldEditor*) fieldEditor;
287 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
288
289 @end
290
291 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
292 {
293 }
294
295 @end
296
297
298 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
299 {
300 }
301
302 - (void)textDidChange:(NSNotification *)aNotification;
303
304 @end
305
306 @interface wxNSMenu : NSMenu
307 {
308 wxMenuImpl* impl;
309 }
310
311 - (void) setImplementation:(wxMenuImpl*) item;
312 - (wxMenuImpl*) implementation;
313
314 @end
315
316 @interface wxNSMenuItem : NSMenuItem
317 {
318 wxMenuItemImpl* impl;
319 }
320
321 - (void) setImplementation:(wxMenuItemImpl*) item;
322 - (wxMenuItemImpl*) implementation;
323
324 - (void)clickedAction:(id)sender;
325 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
326
327 @end
328
329 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
330
331 /*
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.
335 */
336 @interface ModalDialogDelegate : NSObject
337 {
338 BOOL sheetFinished;
339 int resultCode;
340 wxDialog* impl;
341 }
342
343 - (void)setImplementation: (wxDialog *)dialog;
344 - (BOOL)finished;
345 - (int)code;
346 - (void)waitForSheetToFinish;
347 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
348 @end
349
350
351 #endif // __OBJC__
352
353 // NSCursor
354
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();
360
361 typedef struct tagClassicCursor
362 {
363 wxUint16 bits[16];
364 wxUint16 mask[16];
365 wxInt16 hotspot[2];
366 }ClassicCursor;
367
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;
384
385 // exposing our fallback cursor map
386
387 extern ClassicCursor gMacCursors[];
388
389 #endif
390
391 #endif
392 // _WX_PRIVATE_COCOA_H_
393