]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/cocoa/private.h
reference count the GtkMenuItem in wxMenuItem as well
[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);
141
4850cc8b 142
c551dc29 143#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 144 void SetFlipped(bool flipped);
ee032c59 145 virtual bool IsFlipped() const { return m_isFlipped; }
c551dc29 146#endif
96defed0
SC
147
148 // cocoa thunk connected calls
4dd9fdf8
SC
149
150 virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
151 virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
152 virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
153 virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
154 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
3a176763 155 virtual void cursorUpdate(WX_NSEvent event, WXWidget slf, void* _cmd);
4dd9fdf8 156 virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
f0e0116e 157 virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
4dd9fdf8 158 virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
09a9eb20 159 virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
4dd9fdf8
SC
160 virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
161 virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
c551dc29 162#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 163 virtual bool isFlipped(WXWidget slf, void* _cmd);
c551dc29 164#endif
4dd9fdf8 165 virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
03647350 166
e32090ba
SC
167 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
168 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
ce00f59b 169
75a2c6a1
KO
170 // for wxTextCtrl-derived classes, put here since they don't all derive
171 // from the same pimpl class.
172 virtual void controlTextDidChange();
4dd9fdf8 173
4849f027
SC
174protected:
175 WXWidget m_osxView;
f0e0116e 176 NSEvent* m_lastKeyDownEvent;
c551dc29 177#if !wxOSX_USE_NATIVE_FLIPPED
4dd9fdf8 178 bool m_isFlipped;
c551dc29 179#endif
7cb2a241 180 // if it the control has an editor, that editor will already send some
03647350 181 // events, don't resend them
7cb2a241 182 bool m_hasEditor;
03647350 183
4849f027
SC
184 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
185};
186
ffad7b0d
SC
187DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
188
4849f027
SC
189class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
190{
191public :
192 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
193 wxNonOwnedWindowCocoaImpl();
03647350 194
4849f027 195 virtual ~wxNonOwnedWindowCocoaImpl();
03647350 196
0aaa6ace 197 virtual void WillBeDestroyed() ;
4849f027
SC
198 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
199 long style, long extraStyle, const wxString& name ) ;
17e2694c 200 void Create( wxWindow* parent, WXWindow nativeWindow );
03647350 201
4849f027 202 WXWindow GetWXWindow() const;
03647350 203 void Raise();
4849f027 204 void Lower();
03647350 205 bool Show(bool show);
ab9a0b84
VZ
206
207 virtual bool ShowWithEffect(bool show,
208 wxShowEffect effect,
209 unsigned timeout);
03647350 210
4849f027
SC
211 void Update();
212 bool SetTransparent(wxByte alpha);
213 bool SetBackgroundColour(const wxColour& col );
03647350 214 void SetExtraStyle( long exStyle );
b6dc21e7 215 void SetWindowStyleFlag( long style );
03647350 216 bool SetBackgroundStyle(wxBackgroundStyle style);
4849f027
SC
217 bool CanSetTransparent();
218
219 void MoveWindow(int x, int y, int width, int height);
220 void GetPosition( int &x, int &y ) const;
221 void GetSize( int &width, int &height ) const;
222
03647350 223 void GetContentArea( int &left , int &top , int &width , int &height ) const;
4849f027 224 bool SetShape(const wxRegion& region);
03647350 225
4849f027 226 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
03647350 227
4849f027 228 virtual bool IsMaximized() const;
03647350 229
4849f027 230 virtual bool IsIconized() const;
03647350 231
4849f027 232 virtual void Iconize( bool iconize );
03647350 233
4849f027 234 virtual void Maximize(bool maximize);
03647350 235
4849f027 236 virtual bool IsFullScreen() const;
03647350 237
4849f027 238 virtual bool ShowFullScreen(bool show, long style);
030495ec 239
dbc7ceb9 240 virtual void ShowWithoutActivating();
4849f027
SC
241
242 virtual void RequestUserAttention(int flags);
03647350 243
4849f027 244 virtual void ScreenToWindow( int *x, int *y );
03647350 245
4849f027 246 virtual void WindowToScreen( int *x, int *y );
03647350 247
dbc7ceb9 248 virtual bool IsActive();
ce00f59b 249
efb2fa41 250 virtual void SetModified(bool modified);
ebf7d5c4 251 virtual bool IsModified() const;
030495ec 252
6a0e4ead
VZ
253 virtual void SetRepresentedFilename(const wxString& filename);
254
4849f027 255 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
9d243a47
SC
256
257 CGWindowLevel GetWindowLevel() const { return m_macWindowLevel; }
258 void RestoreWindowLevel();
4849f027 259protected :
9d243a47 260 CGWindowLevel m_macWindowLevel;
447e2772
SC
261 WXWindow m_macWindow;
262 void * m_macFullScreenData ;
4849f027 263 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
03647350 264};
4849f027 265
a1b719bc
SC
266DECLARE_WXCOCOA_OBJC_CLASS( wxNSButton );
267
268class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
269{
270public:
271 wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v);
272 virtual void SetBitmap(const wxBitmap& bitmap);
273#if wxUSE_MARKUP
274 virtual void SetLabelMarkup(const wxString& markup);
275#endif // wxUSE_MARKUP
276
277 void SetPressedBitmap( const wxBitmap& bitmap );
278 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const;
2ab67385
SC
279 void SetAcceleratorFromLabel(const wxString& label);
280
a1b719bc
SC
281 NSButton *GetNSButton() const;
282};
283
4850cc8b
SC
284#ifdef __OBJC__
285
5d57348e 286 WXDLLIMPEXP_CORE NSScreen* wxOSXGetMenuScreen();
2acc3915
SC
287 WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
288 WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
289 WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
290 WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
03647350
VZ
291
292 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
4850cc8b 293 bool adjustForOrigin = true );
03647350 294
b466e85a 295 // used for many wxControls
03647350 296
b466e85a
SC
297 @interface wxNSButton : NSButton
298 {
411a1c35 299 NSTrackingRectTag rectTag;
b466e85a 300 }
03647350 301
b466e85a
SC
302 @end
303
304 @interface wxNSBox : NSBox
305 {
b466e85a
SC
306 }
307
b466e85a
SC
308 @end
309
7cb2a241
SC
310 @interface wxNSTextFieldEditor : NSTextView
311 {
312 NSEvent* lastKeyDownEvent;
313 }
314
315 @end
316
c8fdb345 317 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
7cb2a241
SC
318 {
319 wxNSTextFieldEditor* fieldEditor;
320 }
321
322 - (wxNSTextFieldEditor*) fieldEditor;
323 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
324
325 @end
326
c8fdb345 327 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
b466e85a 328 {
b466e85a 329 }
7cb2a241
SC
330
331 @end
332
333
030495ec 334 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
7cb2a241
SC
335 {
336 }
030495ec 337
b9cf2753 338 - (void)textDidChange:(NSNotification *)aNotification;
030495ec 339
b466e85a
SC
340 @end
341
ffad7b0d
SC
342 @interface wxNSMenu : NSMenu
343 {
344 wxMenuImpl* impl;
345 }
346
347 - (void) setImplementation:(wxMenuImpl*) item;
348 - (wxMenuImpl*) implementation;
349
03647350 350 @end
ffad7b0d
SC
351
352 @interface wxNSMenuItem : NSMenuItem
353 {
354 wxMenuItemImpl* impl;
355 }
356
357 - (void) setImplementation:(wxMenuItemImpl*) item;
358 - (wxMenuItemImpl*) implementation;
359
360 - (void)clickedAction:(id)sender;
361 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
362
03647350
VZ
363 @end
364
485c6263 365 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
b466e85a 366
724999ee
KO
367 /*
368 We need this for ShowModal, as the sheet just disables the parent window and
369 returns control to the app, whereas we don't want to return from ShowModal
370 until the sheet has been dismissed.
371 */
372 @interface ModalDialogDelegate : NSObject
373 {
374 BOOL sheetFinished;
375 int resultCode;
bfa92264 376 wxDialog* impl;
724999ee
KO
377 }
378
bfa92264 379 - (void)setImplementation: (wxDialog *)dialog;
724999ee
KO
380 - (BOOL)finished;
381 - (int)code;
382 - (void)waitForSheetToFinish;
383 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
384 @end
385
040050b8
VZ
386 // This interface must be exported in shared 64 bit multilib build but
387 // using WXEXPORT with Objective C interfaces doesn't work with old (4.0.1)
388 // gcc when using 10.4 SDK. It does work with newer gcc even in 32 bit
389 // builds but seems to be unnecessary there so to avoid the expense of a
390 // configure check verifying if this does work or not with the current
391 // compiler we just only use it for 64 bit builds where this is always
392 // supported.
393 //
394 // NB: Currently this is the only place where we need to export an
395 // interface but if we need to do it elsewhere we should define a
396 // WXEXPORT_OBJC macro once and reuse it in all places it's needed
397 // instead of duplicating this preprocessor check.
398#ifdef __LP64__
399 WXEXPORT
400#endif // 64 bit builds
401 @interface wxNSAppController : NSObject wxOSX_10_6_AND_LATER(<NSApplicationDelegate>)
a5d0c88a
SC
402 {
403 }
404
405 @end
724999ee 406
4850cc8b
SC
407#endif // __OBJC__
408
4849f027
SC
409// NSCursor
410
411WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
412WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
413void wxMacCocoaSetCursor( WX_NSCursor cursor );
414void wxMacCocoaHideCursor();
415void wxMacCocoaShowCursor();
416
417typedef struct tagClassicCursor
418{
419 wxUint16 bits[16];
420 wxUint16 mask[16];
421 wxInt16 hotspot[2];
422}ClassicCursor;
423
524c47aa
SC
424const short kwxCursorBullseye = 0;
425const short kwxCursorBlank = 1;
426const short kwxCursorPencil = 2;
427const short kwxCursorMagnifier = 3;
428const short kwxCursorNoEntry = 4;
429const short kwxCursorPaintBrush = 5;
430const short kwxCursorPointRight = 6;
431const short kwxCursorPointLeft = 7;
432const short kwxCursorQuestionArrow = 8;
433const short kwxCursorRightArrow = 9;
434const short kwxCursorSizeNS = 10;
435const short kwxCursorSize = 11;
436const short kwxCursorSizeNESW = 12;
437const short kwxCursorSizeNWSE = 13;
438const short kwxCursorRoller = 14;
4c00ce28
SC
439const short kwxCursorWatch = 15;
440const short kwxCursorLast = kwxCursorWatch;
524c47aa
SC
441
442// exposing our fallback cursor map
443
444extern ClassicCursor gMacCursors[];
445
befe64ed
SC
446extern NSLayoutManager* gNSLayoutManager;
447
4849f027
SC
448#endif
449
450#endif
451 // _WX_PRIVATE_COCOA_H_
452