]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/cocoa/private.h
Get wxSearchCtrl text events working, and share the text event handler code among...
[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: private.h 53819 2008-05-29 14:11:45Z 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
17 #include "wx/osx/core/private.h"
18
19 #include "wx/defs.h"
20
21 #include <ApplicationServices/ApplicationServices.h>
22
23 #if wxOSX_USE_ATSU_TEXT
24 // we need theming and atsu
25 #include <Carbon/Carbon.h>
26 #else
27 // we only need theming, if we find a better include replace the following
28 #include <Carbon/Carbon.h>
29 #endif
30
31 #ifdef __OBJC__
32 #import <Cocoa/Cocoa.h>
33 #endif
34
35 //
36 // shared between Cocoa and Carbon
37 //
38
39 // bring in theming types without pulling in the headers
40
41 #if wxUSE_GUI
42 typedef SInt16 ThemeBrush;
43 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
44 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
45 CGContextRef inContext,
46 const CGRect * inBounds,
47 CGImageRef inImage) ;
48 WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image );
49 CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage );
50 #endif
51
52 long UMAGetSystemVersion() ;
53 WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
54 WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
55 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
56 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
57
58 class WXDLLIMPEXP_FWD_CORE wxDialog;
59
60 //
61 //
62 //
63
64 #if wxUSE_GUI
65
66 class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
67 {
68 public :
69 wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false ) ;
70 wxWidgetCocoaImpl() ;
71 ~wxWidgetCocoaImpl();
72
73 void Init();
74
75 virtual bool IsVisible() const ;
76 virtual void SetVisibility(bool);
77
78 // we provide a static function which can be reused from
79 // wxNonOwnedWindowCocoaImpl too
80 static bool ShowViewOrWindowWithEffect(wxWindow *win,
81 bool show,
82 wxShowEffect effect,
83 unsigned timeout);
84
85 virtual bool ShowWithEffect(bool show,
86 wxShowEffect effect,
87 unsigned timeout);
88
89 virtual void Raise();
90
91 virtual void Lower();
92
93 virtual void ScrollRect( const wxRect *rect, int dx, int dy );
94
95 virtual WXWidget GetWXWidget() const { return m_osxView; }
96
97 virtual void SetBackgroundColour(const wxColour&);
98
99 virtual void GetContentArea( int &left , int &top , int &width , int &height ) const;
100 virtual void Move(int x, int y, int width, int height);
101 virtual void GetPosition( int &x, int &y ) const;
102 virtual void GetSize( int &width, int &height ) const;
103 virtual void SetControlSize( wxWindowVariant variant );
104
105 virtual void SetNeedsDisplay( const wxRect* where = NULL );
106 virtual bool GetNeedsDisplay() const;
107
108 virtual bool CanFocus() const;
109 // return true if successful
110 virtual bool SetFocus();
111 virtual bool HasFocus() const;
112
113 void RemoveFromParent();
114 void Embed( wxWidgetImpl *parent );
115
116 void SetDefaultButton( bool isDefault );
117 void PerformClick();
118 virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
119
120 void SetCursor( const wxCursor & cursor );
121 void CaptureMouse();
122 void ReleaseMouse();
123
124 wxInt32 GetValue() const;
125 void SetValue( wxInt32 v );
126 wxBitmap GetBitmap() const;
127 void SetBitmap( const wxBitmap& bitmap );
128 void SetBitmapPosition( wxDirection dir );
129 void SetupTabs( const wxNotebook &notebook );
130 void GetBestRect( wxRect *r ) const;
131 bool IsEnabled() const;
132 void Enable( bool enable );
133 bool ButtonClickDidStateChange() { return true ;}
134 void SetMinimum( wxInt32 v );
135 void SetMaximum( wxInt32 v );
136 wxInt32 GetMinimum() const;
137 wxInt32 GetMaximum() const;
138 void PulseGauge();
139 void SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
140
141 void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
142
143 void InstallEventHandler( WXWidget control = NULL );
144
145 virtual bool DoHandleMouseEvent(NSEvent *event);
146 virtual bool DoHandleKeyEvent(NSEvent *event);
147 virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
148 virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
149
150 virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);
151 virtual void SetupMouseEvent(wxMouseEvent &wxevent, NSEvent * nsEvent);
152
153
154 void SetFlipped(bool flipped);
155 virtual bool IsFlipped() const { return m_isFlipped; }
156
157 // cocoa thunk connected calls
158
159 virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
160 virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
161 virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
162 virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
163 virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
164 virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
165 virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
166 virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
167 virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd);
168 virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
169 virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
170 virtual void resetCursorRects(WXWidget slf, void* _cmd);
171 virtual bool isFlipped(WXWidget slf, void* _cmd);
172 virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
173
174 virtual void controlAction(WXWidget slf, void* _cmd, void* sender);
175 virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender);
176
177 // for wxTextCtrl-derived classes, put here since they don't all derive
178 // from the same pimpl class.
179 virtual void controlTextDidChange();
180
181 protected:
182 WXWidget m_osxView;
183 NSEvent* m_lastKeyDownEvent;
184 bool m_isFlipped;
185 // if it the control has an editor, that editor will already send some
186 // events, don't resend them
187 bool m_hasEditor;
188
189 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
190 };
191
192 DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow );
193
194 class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl
195 {
196 public :
197 wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) ;
198 wxNonOwnedWindowCocoaImpl();
199
200 virtual ~wxNonOwnedWindowCocoaImpl();
201
202 virtual void WillBeDestroyed() ;
203 void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
204 long style, long extraStyle, const wxString& name ) ;
205
206 WXWindow GetWXWindow() const;
207 void Raise();
208 void Lower();
209 bool Show(bool show);
210
211 virtual bool ShowWithEffect(bool show,
212 wxShowEffect effect,
213 unsigned timeout);
214
215 void Update();
216 bool SetTransparent(wxByte alpha);
217 bool SetBackgroundColour(const wxColour& col );
218 void SetExtraStyle( long exStyle );
219 void SetWindowStyleFlag( long style );
220 bool SetBackgroundStyle(wxBackgroundStyle style);
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
227 void GetContentArea( int &left , int &top , int &width , int &height ) const;
228 bool SetShape(const wxRegion& region);
229
230 virtual void SetTitle( const wxString& title, wxFontEncoding encoding ) ;
231
232 virtual bool IsMaximized() const;
233
234 virtual bool IsIconized() const;
235
236 virtual void Iconize( bool iconize );
237
238 virtual void Maximize(bool maximize);
239
240 virtual bool IsFullScreen() const;
241
242 virtual bool ShowFullScreen(bool show, long style);
243
244 virtual void ShowWithoutActivating();
245
246 virtual void RequestUserAttention(int flags);
247
248 virtual void ScreenToWindow( int *x, int *y );
249
250 virtual void WindowToScreen( int *x, int *y );
251
252 virtual bool IsActive();
253
254 virtual void SetModified(bool modified);
255 virtual bool IsModified() const;
256
257 wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
258 protected :
259 WX_wxNSWindow m_macWindow;
260 void * m_macFullScreenData ;
261 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
262 };
263
264 #ifdef __OBJC__
265
266 WXDLLIMPEXP_CORE NSRect wxToNSRect( NSView* parent, const wxRect& r );
267 WXDLLIMPEXP_CORE wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
268 WXDLLIMPEXP_CORE NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
269 WXDLLIMPEXP_CORE wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
270
271 NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
272 bool adjustForOrigin = true );
273
274 // used for many wxControls
275
276 @interface wxNSButton : NSButton
277 {
278 NSTrackingRectTag rectTag;
279 }
280
281 @end
282
283 @interface wxNSBox : NSBox
284 {
285 }
286
287 @end
288
289 @interface wxNSTextFieldEditor : NSTextView
290 {
291 NSEvent* lastKeyDownEvent;
292 }
293
294 @end
295
296 @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
297 {
298 wxNSTextFieldEditor* fieldEditor;
299 }
300
301 - (wxNSTextFieldEditor*) fieldEditor;
302 - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor;
303
304 @end
305
306 @interface wxNSSecureTextField : NSSecureTextField wxOSX_10_6_AND_LATER(<NSTextFieldDelegate>)
307 {
308 }
309
310 @end
311
312
313 @interface wxNSTextView : NSTextView wxOSX_10_6_AND_LATER(<NSTextViewDelegate>)
314 {
315 }
316
317 - (void)textDidChange:(NSNotification *)aNotification;
318
319 @end
320
321 @interface wxNSMenu : NSMenu
322 {
323 wxMenuImpl* impl;
324 }
325
326 - (void) setImplementation:(wxMenuImpl*) item;
327 - (wxMenuImpl*) implementation;
328
329 @end
330
331 @interface wxNSMenuItem : NSMenuItem
332 {
333 wxMenuItemImpl* impl;
334 }
335
336 - (void) setImplementation:(wxMenuItemImpl*) item;
337 - (wxMenuItemImpl*) implementation;
338
339 - (void)clickedAction:(id)sender;
340 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
341
342 @end
343
344 void WXDLLIMPEXP_CORE wxOSXCocoaClassAddWXMethods(Class c);
345
346 /*
347 We need this for ShowModal, as the sheet just disables the parent window and
348 returns control to the app, whereas we don't want to return from ShowModal
349 until the sheet has been dismissed.
350 */
351 @interface ModalDialogDelegate : NSObject
352 {
353 BOOL sheetFinished;
354 int resultCode;
355 wxDialog* impl;
356 }
357
358 - (void)setImplementation: (wxDialog *)dialog;
359 - (BOOL)finished;
360 - (int)code;
361 - (void)waitForSheetToFinish;
362 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
363 @end
364
365
366 #endif // __OBJC__
367
368 // NSCursor
369
370 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
371 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
372 void wxMacCocoaSetCursor( WX_NSCursor cursor );
373 void wxMacCocoaHideCursor();
374 void wxMacCocoaShowCursor();
375
376 typedef struct tagClassicCursor
377 {
378 wxUint16 bits[16];
379 wxUint16 mask[16];
380 wxInt16 hotspot[2];
381 }ClassicCursor;
382
383 const short kwxCursorBullseye = 0;
384 const short kwxCursorBlank = 1;
385 const short kwxCursorPencil = 2;
386 const short kwxCursorMagnifier = 3;
387 const short kwxCursorNoEntry = 4;
388 const short kwxCursorPaintBrush = 5;
389 const short kwxCursorPointRight = 6;
390 const short kwxCursorPointLeft = 7;
391 const short kwxCursorQuestionArrow = 8;
392 const short kwxCursorRightArrow = 9;
393 const short kwxCursorSizeNS = 10;
394 const short kwxCursorSize = 11;
395 const short kwxCursorSizeNESW = 12;
396 const short kwxCursorSizeNWSE = 13;
397 const short kwxCursorRoller = 14;
398 const short kwxCursorLast = kwxCursorRoller;
399
400 // exposing our fallback cursor map
401
402 extern ClassicCursor gMacCursors[];
403
404 #endif
405
406 #endif
407 // _WX_PRIVATE_COCOA_H_
408