]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
Move wxEventLoopManual::m_shouldExit to wxEventLoopBase.
[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$
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, double scale = 1.0 );
43 CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
44 CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage);
45
46 wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
47 WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
48
49 class WXDLLIMPEXP_FWD_CORE wxDialog;
50
51 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
52 {
53 public :
54 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false, bool isUserPane = false ) ;
55 wxWidgetCocoaImpl() ;
56 ~wxWidgetCocoaImpl();
57
58 void Init();
59
60 virtual bool IsVisible() const ;
61 virtual void SetVisibility(bool);
62
63 // we provide a static function which can be reused from
64 // wxNonOwnedWindowCocoaImpl too
65 static bool ShowViewOrWindowWithEffect(wxWindow *win,
66 bool show,
67 wxShowEffect effect,
68 unsigned timeout);
69
70 virtual bool ShowWithEffect(bool show,
71 wxShowEffect effect,
72 unsigned timeout);
73
74 virtual void Raise();
75
76 virtual void Lower();
77
78 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
79
80 virtual WXWidget GetWXWidget() const { return m_osxView; }
81
82 virtual void SetBackgroundColour(const wxColour&);
83 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
84
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 );
90
91 virtual void SetNeedsDisplay( const wxRect* where = NULL );
92 virtual bool GetNeedsDisplay() const;
93
94 virtual void SetDrawingEnabled(bool enabled);
95
96 virtual bool CanFocus() const;
97 // return true if successful
98 virtual bool SetFocus();
99 virtual bool HasFocus() const;
100
101 void RemoveFromParent();
102 void Embed( wxWidgetImpl *parent );
103
104 void SetDefaultButton( bool isDefault );
105 void PerformClick();
106 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
107
108 void SetCursor( const wxCursor & cursor );
109 void CaptureMouse();
110 void ReleaseMouse();
111
112 void SetDropTarget(wxDropTarget* target);
113
114 wxInt32 GetValue() const;
115 void SetValue( wxInt32 v );
116 wxBitmap GetBitmap() const;
117 void SetBitmap( const wxBitmap& bitmap );
118 void SetBitmapPosition( wxDirection dir );
119 void SetupTabs( const wxNotebook &notebook );
120 void GetBestRect( wxRect *r ) const;
121 bool IsEnabled() const;
122 void Enable( bool enable );
123 bool ButtonClickDidStateChange() { return true ;}
124 void SetMinimum( wxInt32 v );
125 void SetMaximum( wxInt32 v );
126 wxInt32 GetMinimum() const;
127 wxInt32 GetMaximum() const;
128 void PulseGauge();
129 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
130
131 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
132 void SetToolTip( wxToolTip* tooltip );
133
134 void InstallEventHandler( WXWidget control = NULL );
135
136 virtual bool DoHandleMouseEvent(NSEvent *event);
137 virtual bool DoHandleKeyEvent(NSEvent *event);
138 virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
139 virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
140
141 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
142 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
143 void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
144 virtual bool SetupCursor(NSEvent* event);
145
146
147 #if !wxOSX_USE_NATIVE_FLIPPED
148 void SetFlipped(bool flipped);
149 virtual bool IsFlipped() const { return m_isFlipped; }
150 #endif
151
152 virtual double GetContentScaleFactor() const;
153
154 // cocoa thunk connected calls
155
156 virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
157 virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
158 virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
159 virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
160 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
161 virtual void cursorUpdate(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 #if !wxOSX_USE_NATIVE_FLIPPED
169 virtual bool isFlipped(WXWidget slf, void* _cmd);
170 #endif
171 virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
172
173 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
174 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
175
176 // for wxTextCtrl-derived classes, put here since they don't all derive
177 // from the same pimpl class.
178 virtual void controlTextDidChange();
179
180 protected:
181 WXWidget m_osxView;
182 NSEvent* m_lastKeyDownEvent;
183 #if !wxOSX_USE_NATIVE_FLIPPED
184 bool m_isFlipped;
185 #endif
186 // if it the control has an editor, that editor will already send some
187 // events, don't resend them
188 bool m_hasEditor;
189
190 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
191 };
192
193 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
194
195 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
196 {
197 public :
198 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
199 wxNonOwnedWindowCocoaImpl();
200
201 virtual ~wxNonOwnedWindowCocoaImpl();
202
203 virtual void WillBeDestroyed() ;
204 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
205 long style, long extraStyle, const wxString& name ) ;
206 void Create( wxWindow* parent, WXWindow nativeWindow );
207
208 WXWindow GetWXWindow() const;
209 void Raise();
210 void Lower();
211 bool Show(bool show);
212
213 virtual bool ShowWithEffect(bool show,
214 wxShowEffect effect,
215 unsigned timeout);
216
217 void Update();
218 bool SetTransparent(wxByte alpha);
219 bool SetBackgroundColour(const wxColour& col );
220 void SetExtraStyle( long exStyle );
221 void SetWindowStyleFlag( long style );
222 bool SetBackgroundStyle(wxBackgroundStyle style);
223 bool CanSetTransparent();
224
225 void MoveWindow(int x, int y, int width, int height);
226 void GetPosition( int &x, int &y ) const;
227 void GetSize( int &width, int &height ) const;
228
229 void GetContentArea( int &left , int &top , int &width , int &height ) const;
230 bool SetShape(const wxRegion& region);
231
232 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
233
234 virtual bool IsMaximized() const;
235
236 virtual bool IsIconized() const;
237
238 virtual void Iconize( bool iconize );
239
240 virtual void Maximize(bool maximize);
241
242 virtual bool IsFullScreen() const;
243
244 virtual bool ShowFullScreen(bool show, long style);
245
246 virtual void ShowWithoutActivating();
247
248 virtual void RequestUserAttention(int flags);
249
250 virtual void ScreenToWindow( int *x, int *y );
251
252 virtual void WindowToScreen( int *x, int *y );
253
254 virtual bool IsActive();
255
256 virtual void SetModified(bool modified);
257 virtual bool IsModified() const;
258
259 virtual void SetRepresentedFilename(const wxString& filename);
260
261 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
262
263 CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; }
264 void RestoreWindowLevel();
265
266 static WX_NSResponder GetNextFirstResponder() ;
267 protected :
268 CGWindowLevel m_macWindowLevel;
269 WXWindow m_macWindow;
270 void * m_macFullScreenData ;
271 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
272 };
273
274 DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton );
275
276 class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
277 {
278 public:
279 wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v);
280 virtual void SetBitmap(const wxBitmap& bitmap);
281 #if wxUSE_MARKUP
282 virtual void SetLabelMarkup(const wxString& markup);
283 #endif // wxUSE_MARKUP
284
285 void SetPressedBitmap( const wxBitmap& bitmap );
286 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const;
287 void SetAcceleratorFromLabel(const wxString& label);
288
289 NSButton *GetNSButton() const;
290 };
291
292 #ifdef __OBJC__
293 typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
294 typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
295 typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
296 typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
297
298
299 WXDLLIMPEXP_CORE NSScreen* wxOSXGetMenuScreen();
300 WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
301 WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
302 WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
303 WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
304
305 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
306 bool adjustForOrigin = true );
307
308 WXDLLIMPEXP_CORE NSView* wxOSXGetViewFromResponder( NSResponder* responder );
309
310 // used for many wxControls
311
312 @interface wxNSButton : NSButton
313 {
314 NSTrackingRectTag rectTag;
315 }
316
317 @end
318
319 @interface wxNSBox : NSBox
320 {
321 }
322
323 @end
324
325 @interface wxNSTextFieldEditor : NSTextView
326 {
327 NSEvent* lastKeyDownEvent;
328 }
329
330 @end
331
332 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
333 {
334 wxNSTextFieldEditor* fieldEditor;
335 }
336
337 - (wxNSTextFieldEditor*) fieldEditor;
338 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
339
340 @end
341
342 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
343 {
344 }
345
346 @end
347
348
349 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
350 {
351 }
352
353 - (void)textDidChange:(NSNotification *)aNotification;
354
355 @end
356
357 @interface wxNSComboBox : NSComboBox
358 {
359 wxNSTextFieldEditor* fieldEditor;
360 }
361
362 - (wxNSTextFieldEditor*) fieldEditor;
363 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
364
365 @end
366
367
368
369 @interface wxNSMenu : NSMenu
370 {
371 wxMenuImpl* impl;
372 }
373
374 - (void) setImplementation:(wxMenuImpl*) item;
375 - (wxMenuImpl*) implementation;
376
377 @end
378
379 @interface wxNSMenuItem : NSMenuItem
380 {
381 wxMenuItemImpl* impl;
382 }
383
384 - (void) setImplementation:(wxMenuItemImpl*) item;
385 - (wxMenuItemImpl*) implementation;
386
387 - (void)clickedAction:(id)sender;
388 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
389
390 @end
391
392 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
393
394 /*
395 We need this for ShowModal, as the sheet just disables the parent window and
396 returns control to the app, whereas we don't want to return from ShowModal
397 until the sheet has been dismissed.
398 */
399 @interface ModalDialogDelegate : NSObject
400 {
401 BOOL sheetFinished;
402 int resultCode;
403 wxDialog* impl;
404 }
405
406 - (void)setImplementation: (wxDialog *)dialog;
407 - (BOOL)finished;
408 - (int)code;
409 - (void)waitForSheetToFinish;
410 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
411 @end
412
413 // This interface must be exported in shared 64 bit multilib build but
414 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
415 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
416 // builds but seems to be unnecessary there so to avoid the expense of a
417 // configure check verifying if this does work or not with the current
418 // compiler we just only use it for 64 bit builds where this is always
419 // supported.
420 //
421 // NB: Currently this is the only place where we need to export an
422 // interface but if we need to do it elsewhere we should define a
423 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
424 // instead of duplicating this preprocessor check.
425 #ifdef __LP64__
426 WXEXPORT
427 #endif // 64 bit builds
428 @interface wxNSAppController : NSObject wxOSX_10_6_AND_LATER(<NSApplicationDelegate>)
429 {
430 }
431
432 @end
433
434 #endif // __OBJC__
435
436 // NSCursor
437
438 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
439 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
440 void wxMacCocoaSetCursor( WX_NSCursor cursor );
441 void wxMacCocoaHideCursor();
442 void wxMacCocoaShowCursor();
443
444 typedef struct tagClassicCursor
445 {
446 wxUint16 bits[16];
447 wxUint16 mask[16];
448 wxInt16 hotspot[2];
449 }ClassicCursor;
450
451 const short kwxCursorBullseye = 0;
452 const short kwxCursorBlank = 1;
453 const short kwxCursorPencil = 2;
454 const short kwxCursorMagnifier = 3;
455 const short kwxCursorNoEntry = 4;
456 const short kwxCursorPaintBrush = 5;
457 const short kwxCursorPointRight = 6;
458 const short kwxCursorPointLeft = 7;
459 const short kwxCursorQuestionArrow = 8;
460 const short kwxCursorRightArrow = 9;
461 const short kwxCursorSizeNS = 10;
462 const short kwxCursorSize = 11;
463 const short kwxCursorSizeNESW = 12;
464 const short kwxCursorSizeNWSE = 13;
465 const short kwxCursorRoller = 14;
466 const short kwxCursorWatch = 15;
467 const short kwxCursorLast = kwxCursorWatch;
468
469 // exposing our fallback cursor map
470
471 extern ClassicCursor gMacCursors[];
472
473 extern NSLayoutManager* gNSLayoutManager;
474
475 #endif
476
477 #endif
478 // _WX_PRIVATE_COCOA_H_
479