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
// Copyright: (c) Stefan Csomor
10
// Licence: wxWindows licence
11
/////////////////////////////////////////////////////////////////////////////
13
#ifndef _WX_PRIVATE_COCOA_H_
14
#define _WX_PRIVATE_COCOA_H_
16
#include <ApplicationServices/ApplicationServices.h>
19
#import <Cocoa/Cocoa.h>
22
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
23
// available in 10.4 but not in the headers
25
kEventMouseScroll = 11
29
// shared between Cocoa and Carbon
32
// bring in theming types without pulling in the headers
35
typedef SInt16 ThemeBrush;
36
CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
37
OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
38
CGContextRef inContext,
39
const CGRect * inBounds,
41
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0 );
42
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
43
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage);
45
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
46
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
48
class WXDLLIMPEXP_FWD_CORE wxDialog;
50
class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
53
wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false, bool isUserPane = false ) ;
59
virtual bool IsVisible() const ;
60
virtual void SetVisibility(bool);
62
// we provide a static function which can be reused from
63
// wxNonOwnedWindowCocoaImpl too
64
static bool ShowViewOrWindowWithEffect(wxWindow *win,
69
virtual bool ShowWithEffect(bool show,
77
virtual void ScrollRect( const wxRect *rect, int dx, int dy );
79
virtual WXWidget GetWXWidget() const { return m_osxView; }
81
virtual void SetBackgroundColour(const wxColour&);
82
virtual bool SetBackgroundStyle(wxBackgroundStyle style);
84
virtual void GetContentArea( int &left , int &top , int &width , int &height ) const;
85
virtual void Move(int x, int y, int width, int height);
86
virtual void GetPosition( int &x, int &y ) const;
87
virtual void GetSize( int &width, int &height ) const;
88
virtual void SetControlSize( wxWindowVariant variant );
90
virtual void SetNeedsDisplay( const wxRect* where = NULL );
91
virtual bool GetNeedsDisplay() const;
93
virtual void SetDrawingEnabled(bool enabled);
95
virtual bool CanFocus() const;
96
// return true if successful
97
virtual bool SetFocus();
98
virtual bool HasFocus() const;
100
void RemoveFromParent();
101
void Embed( wxWidgetImpl *parent );
103
void SetDefaultButton( bool isDefault );
105
virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
107
void SetCursor( const wxCursor & cursor );
111
void SetDropTarget(wxDropTarget* target);
113
wxInt32 GetValue() const;
114
void SetValue( wxInt32 v );
115
wxBitmap GetBitmap() const;
116
void SetBitmap( const wxBitmap& bitmap );
117
void SetBitmapPosition( wxDirection dir );
118
void SetupTabs( const wxNotebook ¬ebook );
119
void GetBestRect( wxRect *r ) const;
120
bool IsEnabled() const;
121
void Enable( bool enable );
122
bool ButtonClickDidStateChange() { return true ;}
123
void SetMinimum( wxInt32 v );
124
void SetMaximum( wxInt32 v );
125
wxInt32 GetMinimum() const;
126
wxInt32 GetMaximum() const;
128
void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
130
void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
131
void SetToolTip( wxToolTip* tooltip );
133
void InstallEventHandler( WXWidget control = NULL );
135
virtual bool DoHandleMouseEvent(NSEvent *event);
136
virtual bool DoHandleKeyEvent(NSEvent *event);
137
virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
138
virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
140
virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
141
virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
142
void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
143
virtual bool SetupCursor(NSEvent* event);
146
#if !wxOSX_USE_NATIVE_FLIPPED
147
void SetFlipped(bool flipped);
148
virtual bool IsFlipped() const { return m_isFlipped; }
151
virtual double GetContentScaleFactor() const;
153
// cocoa thunk connected calls
155
virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
156
virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
157
virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
158
virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
159
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
160
virtual void cursorUpdate(WX_NSEvent event, WXWidget slf, void* _cmd);
161
virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
162
virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
163
virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
164
virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
165
virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
166
virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
167
#if !wxOSX_USE_NATIVE_FLIPPED
168
virtual bool isFlipped(WXWidget slf, void* _cmd);
170
virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
172
virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
173
virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
175
// for wxTextCtrl-derived classes, put here since they don't all derive
176
// from the same pimpl class.
177
virtual void controlTextDidChange();
181
NSEvent* m_lastKeyDownEvent;
182
#if !wxOSX_USE_NATIVE_FLIPPED
185
// if it the control has an editor, that editor will already send some
186
// events, don't resend them
189
DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
192
DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
194
class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
197
wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
198
wxNonOwnedWindowCocoaImpl();
200
virtual ~wxNonOwnedWindowCocoaImpl();
202
virtual void WillBeDestroyed() ;
203
void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
204
long style, long extraStyle, const wxString& name ) ;
205
void Create( wxWindow* parent, WXWindow nativeWindow );
207
WXWindow GetWXWindow() const;
210
bool Show(bool show);
212
virtual bool ShowWithEffect(bool show,
217
bool SetTransparent(wxByte alpha);
218
bool SetBackgroundColour(const wxColour& col );
219
void SetExtraStyle( long exStyle );
220
void SetWindowStyleFlag( long style );
221
bool SetBackgroundStyle(wxBackgroundStyle style);
222
bool CanSetTransparent();
224
void MoveWindow(int x, int y, int width, int height);
225
void GetPosition( int &x, int &y ) const;
226
void GetSize( int &width, int &height ) const;
228
void GetContentArea( int &left , int &top , int &width , int &height ) const;
229
bool SetShape(const wxRegion& region);
231
virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
233
virtual bool IsMaximized() const;
235
virtual bool IsIconized() const;
237
virtual void Iconize( bool iconize );
239
virtual void Maximize(bool maximize);
241
virtual bool IsFullScreen() const;
243
virtual bool ShowFullScreen(bool show, long style);
245
virtual void ShowWithoutActivating();
247
virtual void RequestUserAttention(int flags);
249
virtual void ScreenToWindow( int *x, int *y );
251
virtual void WindowToScreen( int *x, int *y );
253
virtual bool IsActive();
255
virtual void SetModified(bool modified);
256
virtual bool IsModified() const;
258
virtual void SetRepresentedFilename(const wxString& filename);
260
wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
262
CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; }
263
void RestoreWindowLevel();
265
static WX_NSResponder GetNextFirstResponder() ;
267
CGWindowLevel m_macWindowLevel;
268
WXWindow m_macWindow;
269
void * m_macFullScreenData ;
270
DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
273
DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton );
275
class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
278
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v);
279
virtual void SetBitmap(const wxBitmap& bitmap);
281
virtual void SetLabelMarkup(const wxString& markup);
282
#endif // wxUSE_MARKUP
284
void SetPressedBitmap( const wxBitmap& bitmap );
285
void GetLayoutInset(int &left , int &top , int &right, int &bottom) const;
286
void SetAcceleratorFromLabel(const wxString& label);
288
NSButton *GetNSButton() const;
292
typedef void (*wxOSX_TextEventHandlerPtr)(NSView* self, SEL _cmd, NSString *event);
293
typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
294
typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
295
typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
298
WXDLLIMPEXP_CORE NSScreen* wxOSXGetMenuScreen();
299
WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
300
WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
301
WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
302
WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
304
NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
305
bool adjustForOrigin = true );
307
WXDLLIMPEXP_CORE NSView* wxOSXGetViewFromResponder( NSResponder* responder );
309
// used for many wxControls
311
@interface wxNSButton : NSButton
313
NSTrackingRectTag rectTag;
318
@interface wxNSBox : NSBox
324
@interface wxNSTextFieldEditor : NSTextView
326
NSEvent* lastKeyDownEvent;
331
@interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
333
wxNSTextFieldEditor* fieldEditor;
336
- (wxNSTextFieldEditor*) fieldEditor;
337
- (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
341
@interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
348
@interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
352
- (void)textDidChange:(NSNotification *)aNotification;
356
@interface wxNSComboBox : NSComboBox
358
wxNSTextFieldEditor* fieldEditor;
361
- (wxNSTextFieldEditor*) fieldEditor;
362
- (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
368
@interface wxNSMenu : NSMenu
373
- (void) setImplementation:(wxMenuImpl*) item;
374
- (wxMenuImpl*) implementation;
378
@interface wxNSMenuItem : NSMenuItem
380
wxMenuItemImpl* impl;
383
- (void) setImplementation:(wxMenuItemImpl*) item;
384
- (wxMenuItemImpl*) implementation;
386
- (void)clickedAction:(id)sender;
387
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
391
void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
394
We need this for ShowModal, as the sheet just disables the parent window and
395
returns control to the app, whereas we don't want to return from ShowModal
396
until the sheet has been dismissed.
398
@interface ModalDialogDelegate : NSObject
405
- (void)setImplementation: (wxDialog *)dialog;
408
- (void)waitForSheetToFinish;
409
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
412
// This interface must be exported in shared 64 bit multilib build but
413
// using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
414
// gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
415
// builds but seems to be unnecessary there so to avoid the expense of a
416
// configure check verifying if this does work or not with the current
417
// compiler we just only use it for 64 bit builds where this is always
420
// NB: Currently this is the only place where we need to export an
421
// interface but if we need to do it elsewhere we should define a
422
// WXEXPORT_OBJC macro once and reuse it in all places it's needed
423
// instead of duplicating this preprocessor check.
426
#endif // 64 bit builds
427
@interface wxNSAppController : NSObject wxOSX_10_6_AND_LATER(<NSApplicationDelegate>)
437
WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
438
WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
439
void wxMacCocoaSetCursor( WX_NSCursor cursor );
440
void wxMacCocoaHideCursor();
441
void wxMacCocoaShowCursor();
443
typedef struct tagClassicCursor
450
const short kwxCursorBullseye = 0;
451
const short kwxCursorBlank = 1;
452
const short kwxCursorPencil = 2;
453
const short kwxCursorMagnifier = 3;
454
const short kwxCursorNoEntry = 4;
455
const short kwxCursorPaintBrush = 5;
456
const short kwxCursorPointRight = 6;
457
const short kwxCursorPointLeft = 7;
458
const short kwxCursorQuestionArrow = 8;
459
const short kwxCursorRightArrow = 9;
460
const short kwxCursorSizeNS = 10;
461
const short kwxCursorSize = 11;
462
const short kwxCursorSizeNESW = 12;
463
const short kwxCursorSizeNWSE = 13;
464
const short kwxCursorRoller = 14;
465
const short kwxCursorWatch = 15;
466
const short kwxCursorLast = kwxCursorWatch;
468
// exposing our fallback cursor map
470
extern ClassicCursor gMacCursors[];
472
extern NSLayoutManager* gNSLayoutManager;
477
// _WX_PRIVATE_COCOA_H_