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