]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/cocoa/private.h
Add "OSX" prefix to wxCFEventLoop::DoRun() and DoStop() methods.
[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
a9a4f229 9// RCS-ID: $Id$
4849f027
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
935e6c7d
SC
17#include <ApplicationServices/ApplicationServices.h>
18
4849f027 19#ifdef __OBJC__
4849f027 20 #import <Cocoa/Cocoa.h>
4850cc8b 21#endif
4849f027 22
126254a8
SC
23#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
24// available in 10.4 but not in the headers
25enum {
26 kEventMouseScroll = 11
27};
28#endif
524c47aa
SC
29//
30// shared between Cocoa and Carbon
31//
32
b3b17ee7 33// bring in theming types without pulling in the headers
524c47aa 34
935e6c7d 35#if wxUSE_GUI
524c47aa 36typedef SInt16 ThemeBrush;
6da991db 37CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
524c47aa
SC
38OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
39 CGContextRef inContext,
40 const CGRect * inBounds,
41 CGImageRef inImage) ;
c944835a
SC
42WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0 );
43CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
44CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage);
45
ca9eebc3 46wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
78f21217 47WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
524c47aa 48
bfa92264
KO
49class WXDLLIMPEXP_FWD_CORE wxDialog;
50
4849f027
SC
51class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
52{
53public :
415f4a01 54 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false, bool isUserPane = false ) ;
03647350
VZ
55 wxWidgetCocoaImpl() ;
56 ~wxWidgetCocoaImpl();
57
4849f027 58 void Init();
03647350 59
4849f027 60 virtual bool IsVisible() const ;
524c47aa
SC
61 virtual void SetVisibility(bool);
62
ab9a0b84
VZ
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
4849f027 74 virtual void Raise();
03647350 75
4849f027
SC
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
524c47aa 82 virtual void SetBackgroundColour(const wxColour&);
bc5c09a3 83 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
524c47aa 84
4849f027
SC
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;
524c47aa 89 virtual void SetControlSize( wxWindowVariant variant );
4849f027
SC
90
91 virtual void SetNeedsDisplay( const wxRect* where = NULL );
92 virtual bool GetNeedsDisplay() const;
93
2ab38025
SC
94 virtual void SetDrawingEnabled(bool enabled);
95
4849f027
SC
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 );
524c47aa
SC
103
104 void SetDefaultButton( bool isDefault );
105 void PerformClick();
a4e32492 106 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
524c47aa 107
54f11060
SC
108 void SetCursor( const wxCursor & cursor );
109 void CaptureMouse();
110 void ReleaseMouse();
111
14de8214
SC
112 void SetDropTarget(wxDropTarget* target);
113
524c47aa
SC
114 wxInt32 GetValue() const;
115 void SetValue( wxInt32 v );
e5d05b90 116 wxBitmap GetBitmap() const;
524c47aa 117 void SetBitmap( const wxBitmap& bitmap );
e5d05b90 118 void SetBitmapPosition( wxDirection dir );
524c47aa
SC
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 );
19c7ac3d
SC
126 wxInt32 GetMinimum() const;
127 wxInt32 GetMaximum() const;
524c47aa
SC
128 void PulseGauge();
129 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
130
1e181c7a 131 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
a7b9865d 132 void SetToolTip( wxToolTip* tooltip );
1e181c7a 133
c4825ef7 134 void InstallEventHandler( WXWidget control = NULL );
03647350
VZ
135
136 virtual bool DoHandleMouseEvent(NSEvent *event);
f0e0116e
KO
137 virtual bool DoHandleKeyEvent(NSEvent *event);
138 virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
03647350 139 virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
030495ec 140
ddbc8ac9
SC
141 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
142 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
094fa9e9
SC
143 void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
144 virtual bool SetupCursor(NSEvent* event);
ddbc8ac9 145
4850cc8b 146
c551dc29 147#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 148 void SetFlipped(bool flipped);
ee032c59 149 virtual bool IsFlipped() const { return m_isFlipped; }
c551dc29 150#endif
96defed0 151
f082dcd5
SC
152 virtual double GetContentScaleFactor() const;
153
96defed0 154 // cocoa thunk connected calls
4dd9fdf8
SC
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);
3a176763 161 virtual void cursorUpdate(WX_NSEvent event, WXWidget slf, void* _cmd);
4dd9fdf8 162 virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
f0e0116e 163 virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
4dd9fdf8 164 virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
09a9eb20 165 virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
4dd9fdf8
SC
166 virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
167 virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
c551dc29 168#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 169 virtual bool isFlipped(WXWidget slf, void* _cmd);
c551dc29 170#endif
4dd9fdf8 171 virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
03647350 172
e32090ba
SC
173 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
174 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
ce00f59b 175
75a2c6a1
KO
176 // for wxTextCtrl-derived classes, put here since they don't all derive
177 // from the same pimpl class.
178 virtual void controlTextDidChange();
4dd9fdf8 179
4849f027
SC
180protected:
181 WXWidget m_osxView;
f0e0116e 182 NSEvent* m_lastKeyDownEvent;
c551dc29 183#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 184 bool m_isFlipped;
c551dc29 185#endif
7cb2a241 186 // if it the control has an editor, that editor will already send some
03647350 187 // events, don't resend them
7cb2a241 188 bool m_hasEditor;
03647350 189
4849f027
SC
190 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
191};
192
ffad7b0d
SC
193DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
194
4849f027
SC
195class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
196{
197public :
198 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
199 wxNonOwnedWindowCocoaImpl();
03647350 200
4849f027 201 virtual ~wxNonOwnedWindowCocoaImpl();
03647350 202
0aaa6ace 203 virtual void WillBeDestroyed() ;
4849f027
SC
204 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
205 long style, long extraStyle, const wxString& name ) ;
17e2694c 206 void Create( wxWindow* parent, WXWindow nativeWindow );
03647350 207
4849f027 208 WXWindow GetWXWindow() const;
03647350 209 void Raise();
4849f027 210 void Lower();
03647350 211 bool Show(bool show);
ab9a0b84
VZ
212
213 virtual bool ShowWithEffect(bool show,
214 wxShowEffect effect,
215 unsigned timeout);
03647350 216
4849f027
SC
217 void Update();
218 bool SetTransparent(wxByte alpha);
219 bool SetBackgroundColour(const wxColour& col );
03647350 220 void SetExtraStyle( long exStyle );
b6dc21e7 221 void SetWindowStyleFlag( long style );
03647350 222 bool SetBackgroundStyle(wxBackgroundStyle style);
4849f027
SC
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
03647350 229 void GetContentArea( int &left , int &top , int &width , int &height ) const;
4849f027 230 bool SetShape(const wxRegion& region);
03647350 231
4849f027 232 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
03647350 233
4849f027 234 virtual bool IsMaximized() const;
03647350 235
4849f027 236 virtual bool IsIconized() const;
03647350 237
4849f027 238 virtual void Iconize( bool iconize );
03647350 239
4849f027 240 virtual void Maximize(bool maximize);
03647350 241
4849f027 242 virtual bool IsFullScreen() const;
03647350 243
4849f027 244 virtual bool ShowFullScreen(bool show, long style);
030495ec 245
dbc7ceb9 246 virtual void ShowWithoutActivating();
4849f027
SC
247
248 virtual void RequestUserAttention(int flags);
03647350 249
4849f027 250 virtual void ScreenToWindow( int *x, int *y );
03647350 251
4849f027 252 virtual void WindowToScreen( int *x, int *y );
03647350 253
dbc7ceb9 254 virtual bool IsActive();
ce00f59b 255
efb2fa41 256 virtual void SetModified(bool modified);
ebf7d5c4 257 virtual bool IsModified() const;
030495ec 258
6a0e4ead
VZ
259 virtual void SetRepresentedFilename(const wxString& filename);
260
4849f027 261 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
9d243a47
SC
262
263 CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; }
264 void RestoreWindowLevel();
60d66be3
SC
265
266 static WX_NSResponder GetNextFirstResponder() ;
4849f027 267protected :
9d243a47 268 CGWindowLevel m_macWindowLevel;
447e2772
SC
269 WXWindow m_macWindow;
270 void * m_macFullScreenData ;
4849f027 271 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
03647350 272};
4849f027 273
a1b719bc
SC
274DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton );
275
276class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
277{
278public:
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;
2ab67385
SC
287 void SetAcceleratorFromLabel(const wxString& label);
288
a1b719bc
SC
289 NSButton *GetNSButton() const;
290};
291
4850cc8b 292#ifdef __OBJC__
13167e72
SC
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
4850cc8b 298
5d57348e 299 WXDLLIMPEXP_CORE NSScreen* wxOSXGetMenuScreen();
2acc3915
SC
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 );
03647350
VZ
304
305 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
4850cc8b 306 bool adjustForOrigin = true );
03647350 307
ba0cf6af
SC
308 WXDLLIMPEXP_CORE NSView* wxOSXGetViewFromResponder( NSResponder* responder );
309
b466e85a 310 // used for many wxControls
03647350 311
b466e85a
SC
312 @interface wxNSButton : NSButton
313 {
411a1c35 314 NSTrackingRectTag rectTag;
b466e85a 315 }
03647350 316
b466e85a
SC
317 @end
318
319 @interface wxNSBox : NSBox
320 {
b466e85a
SC
321 }
322
b466e85a
SC
323 @end
324
7cb2a241
SC
325 @interface wxNSTextFieldEditor : NSTextView
326 {
327 NSEvent* lastKeyDownEvent;
328 }
329
330 @end
331
c8fdb345 332 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
7cb2a241
SC
333 {
334 wxNSTextFieldEditor* fieldEditor;
335 }
336
337 - (wxNSTextFieldEditor*) fieldEditor;
338 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
339
340 @end
341
c8fdb345 342 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
b466e85a 343 {
b466e85a 344 }
7cb2a241
SC
345
346 @end
347
348
030495ec 349 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
7cb2a241
SC
350 {
351 }
030495ec 352
b9cf2753 353 - (void)textDidChange:(NSNotification *)aNotification;
030495ec 354
b466e85a
SC
355 @end
356
d9307d00
SC
357 @interface wxNSComboBox : NSComboBox
358 {
359 wxNSTextFieldEditor* fieldEditor;
360 }
361
362 - (wxNSTextFieldEditor*) fieldEditor;
363 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
364
365 @end
366
367
368
ffad7b0d
SC
369 @interface wxNSMenu : NSMenu
370 {
371 wxMenuImpl* impl;
372 }
373
374 - (void) setImplementation:(wxMenuImpl*) item;
375 - (wxMenuImpl*) implementation;
376
03647350 377 @end
ffad7b0d
SC
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
03647350
VZ
390 @end
391
485c6263 392 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
b466e85a 393
724999ee
KO
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;
bfa92264 403 wxDialog* impl;
724999ee
KO
404 }
405
bfa92264 406 - (void)setImplementation: (wxDialog *)dialog;
724999ee
KO
407 - (BOOL)finished;
408 - (int)code;
409 - (void)waitForSheetToFinish;
410 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
411 @end
412
040050b8
VZ
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>)
a5d0c88a
SC
429 {
430 }
431
432 @end
724999ee 433
4850cc8b
SC
434#endif // __OBJC__
435
4849f027
SC
436// NSCursor
437
438WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
439WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
440void wxMacCocoaSetCursor( WX_NSCursor cursor );
441void wxMacCocoaHideCursor();
442void wxMacCocoaShowCursor();
443
444typedef struct tagClassicCursor
445{
446 wxUint16 bits[16];
447 wxUint16 mask[16];
448 wxInt16 hotspot[2];
449}ClassicCursor;
450
524c47aa
SC
451const short kwxCursorBullseye = 0;
452const short kwxCursorBlank = 1;
453const short kwxCursorPencil = 2;
454const short kwxCursorMagnifier = 3;
455const short kwxCursorNoEntry = 4;
456const short kwxCursorPaintBrush = 5;
457const short kwxCursorPointRight = 6;
458const short kwxCursorPointLeft = 7;
459const short kwxCursorQuestionArrow = 8;
460const short kwxCursorRightArrow = 9;
461const short kwxCursorSizeNS = 10;
462const short kwxCursorSize = 11;
463const short kwxCursorSizeNESW = 12;
464const short kwxCursorSizeNWSE = 13;
465const short kwxCursorRoller = 14;
4c00ce28
SC
466const short kwxCursorWatch = 15;
467const short kwxCursorLast = kwxCursorWatch;
524c47aa
SC
468
469// exposing our fallback cursor map
470
471extern ClassicCursor gMacCursors[];
472
befe64ed
SC
473extern NSLayoutManager* gNSLayoutManager;
474
4849f027
SC
475#endif
476
477#endif
478 // _WX_PRIVATE_COCOA_H_
479