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