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