]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
e766c8a9 | 3 | // Purpose: wxWindowMac |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "window.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 | 18 | #include "wx/menu.h" |
5fde6fcc | 19 | #include "wx/window.h" |
e9576ca5 SC |
20 | #include "wx/dc.h" |
21 | #include "wx/dcclient.h" | |
14c9cbdb | 22 | #include "wx/utils.h" |
e9576ca5 SC |
23 | #include "wx/app.h" |
24 | #include "wx/panel.h" | |
25 | #include "wx/layout.h" | |
26 | #include "wx/dialog.h" | |
03e11df5 GD |
27 | #include "wx/scrolbar.h" |
28 | #include "wx/statbox.h" | |
e9576ca5 SC |
29 | #include "wx/button.h" |
30 | #include "wx/settings.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/frame.h" | |
2f1ae414 | 33 | #include "wx/tooltip.h" |
c809f3be | 34 | #include "wx/statusbr.h" |
e9576ca5 | 35 | #include "wx/menuitem.h" |
4ac219f6 | 36 | #include "wx/spinctrl.h" |
e9576ca5 | 37 | #include "wx/log.h" |
467e3168 | 38 | #include "wx/geometry.h" |
00627198 | 39 | #include "wx/textctrl.h" |
e9576ca5 | 40 | |
facd6764 SC |
41 | #include "wx/toolbar.h" |
42 | #include "wx/dc.h" | |
43 | ||
7c551d95 SC |
44 | #if wxUSE_CARET |
45 | #include "wx/caret.h" | |
46 | #endif // wxUSE_CARET | |
47 | ||
db7a550b SC |
48 | #define MAC_SCROLLBAR_SIZE 15 |
49 | #define MAC_SMALL_SCROLLBAR_SIZE 11 | |
519cb848 | 50 | |
d497dca4 | 51 | #include "wx/mac/uma.h" |
66a09d47 SC |
52 | #ifndef __DARWIN__ |
53 | #include <Windows.h> | |
54 | #include <ToolUtils.h> | |
1d879215 DS |
55 | #include <Scrap.h> |
56 | #include <MacTextEditor.h> | |
66a09d47 | 57 | #endif |
519cb848 | 58 | |
41218df1 | 59 | #if TARGET_API_MAC_OSX |
facd6764 | 60 | #ifndef __HIVIEW__ |
8b573fb8 | 61 | #include <HIToolbox/HIView.h> |
facd6764 | 62 | #endif |
41218df1 | 63 | #endif |
facd6764 | 64 | |
e9576ca5 SC |
65 | #if wxUSE_DRAG_AND_DROP |
66 | #include "wx/dnd.h" | |
67 | #endif | |
68 | ||
69 | #include <string.h> | |
70 | ||
71 | extern wxList wxPendingDelete; | |
72 | ||
fc0daf84 SC |
73 | #ifdef __WXUNIVERSAL__ |
74 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
75 | #else // __WXMAC__ | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
77 | #endif // __WXUNIVERSAL__/__WXMAC__ | |
78 | ||
2f1ae414 | 79 | #if !USE_SHARED_LIBRARY |
fc0daf84 SC |
80 | |
81 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
facd6764 SC |
82 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) |
83 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
ff3795ee SC |
84 | #if TARGET_API_MAC_OSX |
85 | EVT_PAINT(wxWindowMac::OnPaint) | |
86 | #endif | |
5ca0d812 SC |
87 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) |
88 | EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) | |
facd6764 | 89 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) |
e9576ca5 SC |
90 | END_EVENT_TABLE() |
91 | ||
2f1ae414 | 92 | #endif |
e9576ca5 | 93 | |
94abc21f SC |
94 | #define wxMAC_DEBUG_REDRAW 0 |
95 | #ifndef wxMAC_DEBUG_REDRAW | |
96 | #define wxMAC_DEBUG_REDRAW 0 | |
97 | #endif | |
98 | ||
5ca0d812 | 99 | #define wxMAC_USE_THEME_BORDER 1 |
e9576ca5 | 100 | |
42ef83fa SC |
101 | // --------------------------------------------------------------------------- |
102 | // Utility Routines to move between different coordinate systems | |
103 | // --------------------------------------------------------------------------- | |
104 | ||
105 | /* | |
106 | * Right now we have the following setup : | |
107 | * a border that is not part of the native control is always outside the | |
108 | * control's border (otherwise we loose all native intelligence, future ways | |
109 | * may be to have a second embedding control responsible for drawing borders | |
110 | * and backgrounds eventually) | |
111 | * so all this border calculations have to be taken into account when calling | |
112 | * native methods or getting native oriented data | |
113 | * so we have three coordinate systems here | |
114 | * wx client coordinates | |
115 | * wx window coordinates (including window frames) | |
116 | * native coordinates | |
117 | */ | |
8b573fb8 | 118 | |
42ef83fa SC |
119 | // |
120 | // originating from native control | |
121 | // | |
122 | ||
123 | ||
124 | void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle ) | |
125 | { | |
8b573fb8 | 126 | OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
127 | } |
128 | ||
129 | void wxMacNativeToWindow( const wxWindow* window , Rect *rect ) | |
130 | { | |
8b573fb8 | 131 | OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
132 | } |
133 | ||
134 | // | |
135 | // directed towards native control | |
136 | // | |
137 | ||
138 | void wxMacWindowToNative( const wxWindow* window , RgnHandle handle ) | |
139 | { | |
8b573fb8 | 140 | OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); |
42ef83fa SC |
141 | } |
142 | ||
143 | void wxMacWindowToNative( const wxWindow* window , Rect *rect ) | |
144 | { | |
8b573fb8 | 145 | OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
146 | } |
147 | ||
148 | ||
facd6764 SC |
149 | // --------------------------------------------------------------------------- |
150 | // Carbon Events | |
151 | // --------------------------------------------------------------------------- | |
8b573fb8 | 152 | |
facd6764 SC |
153 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
154 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ; | |
155 | ||
f1d527c1 SC |
156 | #if TARGET_API_MAC_OSX |
157 | ||
8b573fb8 | 158 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 |
c2697b87 SC |
159 | enum { |
160 | kEventControlVisibilityChanged = 157 | |
161 | }; | |
162 | #endif | |
163 | ||
f1d527c1 SC |
164 | #endif |
165 | ||
facd6764 SC |
166 | static const EventTypeSpec eventList[] = |
167 | { | |
f1d527c1 | 168 | { kEventClassControl , kEventControlHit } , |
facd6764 | 169 | #if TARGET_API_MAC_OSX |
73fe67bd SC |
170 | { kEventClassControl , kEventControlDraw } , |
171 | { kEventClassControl , kEventControlVisibilityChanged } , | |
172 | { kEventClassControl , kEventControlEnabledStateChanged } , | |
173 | { kEventClassControl , kEventControlHiliteChanged } , | |
f1d527c1 | 174 | { kEventClassControl , kEventControlSetFocusPart } , |
8b573fb8 VZ |
175 | |
176 | { kEventClassService , kEventServiceGetTypes }, | |
177 | { kEventClassService , kEventServiceCopy }, | |
178 | { kEventClassService , kEventServicePaste }, | |
179 | ||
180 | // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only | |
facd6764 | 181 | // { kEventClassControl , kEventControlBoundsChanged } , |
facd6764 SC |
182 | #endif |
183 | } ; | |
184 | ||
185 | static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
186 | { | |
187 | OSStatus result = eventNotHandledErr ; | |
188 | ||
189 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 190 | |
facd6764 SC |
191 | ControlRef controlRef ; |
192 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
193 | ||
194 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
195 | ||
196 | switch( GetEventKind( event ) ) | |
197 | { | |
f1d527c1 | 198 | #if TARGET_API_MAC_OSX |
facd6764 SC |
199 | case kEventControlDraw : |
200 | { | |
1e8cde71 | 201 | RgnHandle updateRgn = NULL ; |
055a486b | 202 | RgnHandle allocatedRgn = NULL ; |
1e8cde71 | 203 | wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; |
8b573fb8 | 204 | if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr ) |
1e8cde71 SC |
205 | { |
206 | updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; | |
207 | } | |
055a486b SC |
208 | else |
209 | { | |
210 | if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) | |
211 | { | |
212 | allocatedRgn = NewRgn() ; | |
213 | CopyRgn( updateRgn , allocatedRgn ) ; | |
42ef83fa SC |
214 | // hide the given region by the new region that must be shifted |
215 | wxMacNativeToWindow( thisWindow , allocatedRgn ) ; | |
216 | updateRgn = allocatedRgn ; | |
055a486b SC |
217 | } |
218 | } | |
facd6764 | 219 | |
8b573fb8 | 220 | #if 0 |
125c7984 | 221 | // in case we would need a coregraphics compliant background erase first |
bcbd6987 | 222 | // now usable to track redraws |
facd6764 SC |
223 | if ( thisWindow->MacIsUserPane() ) |
224 | { | |
20b69855 | 225 | CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; |
bcbd6987 SC |
226 | static float color = 0.5 ; |
227 | static channel = 0 ; | |
8b573fb8 VZ |
228 | HIRect bounds; |
229 | HIViewGetBounds( controlRef, &bounds ); | |
230 | CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 , | |
231 | channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 ); | |
232 | CGContextFillRect( cgContext, bounds ); | |
233 | color += 0.1 ; | |
234 | if ( color > 0.9 ) | |
235 | { | |
236 | color = 0.5 ; | |
237 | channel++ ; | |
238 | if ( channel == 3 ) | |
239 | channel = 0 ; | |
240 | } | |
facd6764 | 241 | } |
20b69855 | 242 | #endif |
c79aad8b | 243 | { |
20b69855 | 244 | #if wxMAC_USE_CORE_GRAPHICS |
c79aad8b SC |
245 | CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; |
246 | thisWindow->MacSetCGContextRef( cgContext ) ; | |
247 | wxMacCGContextStateSaver sg( cgContext ) ; | |
facd6764 | 248 | #endif |
c79aad8b SC |
249 | if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) |
250 | result = noErr ; | |
20b69855 | 251 | #if wxMAC_USE_CORE_GRAPHICS |
c79aad8b | 252 | thisWindow->MacSetCGContextRef( NULL ) ; |
20b69855 | 253 | #endif |
c79aad8b | 254 | } |
055a486b SC |
255 | if ( allocatedRgn ) |
256 | DisposeRgn( allocatedRgn ) ; | |
facd6764 SC |
257 | } |
258 | break ; | |
73fe67bd SC |
259 | case kEventControlVisibilityChanged : |
260 | thisWindow->MacVisibilityChanged() ; | |
261 | break ; | |
262 | case kEventControlEnabledStateChanged : | |
263 | thisWindow->MacEnabledStateChanged() ; | |
264 | break ; | |
265 | case kEventControlHiliteChanged : | |
266 | thisWindow->MacHiliteChanged() ; | |
267 | break ; | |
f1d527c1 SC |
268 | case kEventControlSetFocusPart : |
269 | { | |
270 | Boolean focusEverything = false ; | |
271 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
272 | if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr ) | |
273 | { | |
274 | } | |
275 | if ( controlPart == kControlFocusNoPart ) | |
276 | { | |
277 | #if wxUSE_CARET | |
278 | if ( thisWindow->GetCaret() ) | |
279 | { | |
280 | thisWindow->GetCaret()->OnKillFocus(); | |
281 | } | |
282 | #endif // wxUSE_CARET | |
5ca0d812 | 283 | wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); |
f1d527c1 SC |
284 | event.SetEventObject(thisWindow); |
285 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
286 | } | |
287 | else | |
288 | { | |
289 | // panel wants to track the window which was the last to have focus in it | |
290 | wxChildFocusEvent eventFocus(thisWindow); | |
291 | thisWindow->GetEventHandler()->ProcessEvent(eventFocus); | |
8b573fb8 | 292 | |
f1d527c1 SC |
293 | #if wxUSE_CARET |
294 | if ( thisWindow->GetCaret() ) | |
295 | { | |
296 | thisWindow->GetCaret()->OnSetFocus(); | |
297 | } | |
298 | #endif // wxUSE_CARET | |
299 | ||
300 | wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); | |
301 | event.SetEventObject(thisWindow); | |
302 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
303 | } | |
64fec3ab SC |
304 | if ( thisWindow->MacIsUserPane() ) |
305 | result = noErr ; | |
f1d527c1 SC |
306 | } |
307 | break ; | |
308 | #endif | |
309 | case kEventControlHit : | |
310 | { | |
311 | result = thisWindow->MacControlHit( handler , event ) ; | |
312 | } | |
313 | break ; | |
facd6764 SC |
314 | default : |
315 | break ; | |
316 | } | |
317 | return result ; | |
318 | } | |
319 | ||
e4727773 SC |
320 | static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
321 | { | |
322 | OSStatus result = eventNotHandledErr ; | |
323 | ||
324 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 325 | |
e4727773 SC |
326 | ControlRef controlRef ; |
327 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
328 | wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ; | |
329 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
330 | ||
331 | switch( GetEventKind( event ) ) | |
332 | { | |
333 | case kEventServiceGetTypes : | |
334 | if( textCtrl ) | |
335 | { | |
336 | long from, to ; | |
337 | textCtrl->GetSelection( &from , &to ) ; | |
338 | ||
8b573fb8 | 339 | CFMutableArrayRef copyTypes = 0 , pasteTypes = 0; |
e4727773 SC |
340 | if( from != to ) |
341 | copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ; | |
342 | if ( textCtrl->IsEditable() ) | |
343 | pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ; | |
8b573fb8 VZ |
344 | |
345 | static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ }; | |
e4727773 SC |
346 | for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i ) |
347 | { | |
348 | CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]); | |
349 | if ( typestring ) | |
350 | { | |
351 | if ( copyTypes ) | |
352 | CFArrayAppendValue (copyTypes, typestring) ; | |
353 | if ( pasteTypes ) | |
354 | CFArrayAppendValue (pasteTypes, typestring) ; | |
355 | CFRelease( typestring ) ; | |
356 | } | |
357 | } | |
358 | result = noErr ; | |
359 | } | |
360 | break ; | |
361 | case kEventServiceCopy : | |
362 | if ( textCtrl ) | |
363 | { | |
364 | long from, to ; | |
365 | textCtrl->GetSelection( &from , &to ) ; | |
366 | wxString val = textCtrl->GetValue() ; | |
367 | val = val.Mid( from , to - from ) ; | |
368 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
369 | verify_noerr( ClearScrap( &scrapRef ) ) ; | |
370 | verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ; | |
371 | result = noErr ; | |
372 | } | |
373 | break ; | |
374 | case kEventServicePaste : | |
375 | if ( textCtrl ) | |
376 | { | |
377 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
378 | Size textSize, pastedSize ; | |
379 | verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ; | |
380 | textSize++ ; | |
381 | char *content = new char[textSize] ; | |
8b573fb8 | 382 | GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content ); |
e4727773 | 383 | content[textSize-1] = 0 ; |
8ef4d6e2 SC |
384 | #if wxUSE_UNICODE |
385 | textCtrl->WriteText( wxString( content , wxConvLocal ) ); | |
386 | #else | |
e4727773 | 387 | textCtrl->WriteText( wxString( content ) ) ; |
8ef4d6e2 | 388 | #endif |
e4727773 SC |
389 | delete[] content ; |
390 | result = noErr ; | |
391 | } | |
392 | break ; | |
393 | } | |
8b573fb8 | 394 | |
e4727773 | 395 | return result ; |
8b573fb8 | 396 | } |
e4727773 | 397 | |
facd6764 SC |
398 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
399 | { | |
af6b7b80 SC |
400 | EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; |
401 | EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
402 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
facd6764 SC |
403 | OSStatus result = eventNotHandledErr ; |
404 | ||
405 | switch ( GetEventClass( event ) ) | |
406 | { | |
407 | case kEventClassControl : | |
408 | result = wxMacWindowControlEventHandler( handler, event, data ) ; | |
409 | break ; | |
e4727773 SC |
410 | case kEventClassService : |
411 | result = wxMacWindowServiceEventHandler( handler, event , data ) ; | |
facd6764 SC |
412 | default : |
413 | break ; | |
414 | } | |
af6b7b80 | 415 | wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; |
facd6764 SC |
416 | return result ; |
417 | } | |
418 | ||
419 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
420 | ||
20b69855 SC |
421 | #if !TARGET_API_MAC_OSX |
422 | ||
facd6764 SC |
423 | // --------------------------------------------------------------------------- |
424 | // UserPane events for non OSX builds | |
425 | // --------------------------------------------------------------------------- | |
8b573fb8 | 426 | |
facd6764 SC |
427 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
428 | { | |
429 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
430 | if ( win ) |
431 | win->MacControlUserPaneDrawProc(part) ; | |
facd6764 SC |
432 | } |
433 | ||
434 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) | |
435 | { | |
436 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
437 | if ( win ) |
438 | return win->MacControlUserPaneHitTestProc(where.h , where.v) ; | |
439 | else | |
440 | return kControlNoPart ; | |
facd6764 SC |
441 | } |
442 | ||
443 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) | |
444 | { | |
445 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
446 | if ( win ) |
447 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; | |
448 | else | |
449 | return kControlNoPart ; | |
facd6764 SC |
450 | } |
451 | ||
452 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
453 | { | |
454 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
455 | if ( win ) |
456 | win->MacControlUserPaneIdleProc() ; | |
facd6764 SC |
457 | } |
458 | ||
459 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
460 | { | |
461 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
462 | if ( win ) |
463 | return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; | |
464 | else | |
465 | return kControlNoPart ; | |
facd6764 SC |
466 | } |
467 | ||
468 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
469 | { | |
470 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
471 | if ( win ) |
472 | win->MacControlUserPaneActivateProc(activating) ; | |
facd6764 SC |
473 | } |
474 | ||
475 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
476 | { | |
477 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
478 | if ( win ) |
479 | return win->MacControlUserPaneFocusProc(action) ; | |
480 | else | |
481 | return kControlNoPart ; | |
facd6764 SC |
482 | } |
483 | ||
484 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) | |
485 | { | |
486 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
487 | if ( win ) |
488 | win->MacControlUserPaneBackgroundProc(info) ; | |
facd6764 SC |
489 | } |
490 | ||
8b573fb8 | 491 | void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) |
facd6764 | 492 | { |
bcbd6987 SC |
493 | RgnHandle rgn = NewRgn() ; |
494 | GetClip( rgn ) ; | |
495 | wxMacWindowStateSaver sv( this ) ; | |
496 | SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; | |
497 | MacDoRedraw( rgn , 0 ) ; | |
498 | DisposeRgn( rgn ) ; | |
facd6764 SC |
499 | } |
500 | ||
8b573fb8 | 501 | wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
facd6764 SC |
502 | { |
503 | return kControlNoPart ; | |
504 | } | |
505 | ||
8b573fb8 | 506 | wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
facd6764 SC |
507 | { |
508 | return kControlNoPart ; | |
509 | } | |
510 | ||
8b573fb8 | 511 | void wxWindowMac::MacControlUserPaneIdleProc() |
facd6764 SC |
512 | { |
513 | } | |
514 | ||
8b573fb8 | 515 | wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
facd6764 SC |
516 | { |
517 | return kControlNoPart ; | |
518 | } | |
519 | ||
8b573fb8 | 520 | void wxWindowMac::MacControlUserPaneActivateProc(bool activating) |
facd6764 SC |
521 | { |
522 | } | |
523 | ||
8b573fb8 | 524 | wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) |
facd6764 SC |
525 | { |
526 | return kControlNoPart ; | |
527 | } | |
528 | ||
8b573fb8 | 529 | void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) |
facd6764 SC |
530 | { |
531 | } | |
532 | ||
533 | ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ; | |
534 | ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ; | |
535 | ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ; | |
536 | ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ; | |
537 | ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ; | |
538 | ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ; | |
539 | ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ; | |
540 | ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ; | |
e7549107 | 541 | |
20b69855 SC |
542 | #endif |
543 | ||
e7549107 SC |
544 | // =========================================================================== |
545 | // implementation | |
546 | // =========================================================================== | |
547 | ||
71f2fb52 | 548 | #if KEY_wxList_DEPRECATED |
facd6764 SC |
549 | wxList wxWinMacControlList(wxKEY_INTEGER); |
550 | ||
551 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
552 | { | |
553 | wxNode *node = wxWinMacControlList.Find((long)inControl); | |
554 | if (!node) | |
555 | return NULL; | |
556 | return (wxControl *)node->GetData(); | |
557 | } | |
558 | ||
559 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
560 | { | |
561 | // adding NULL ControlRef is (first) surely a result of an error and | |
562 | // (secondly) breaks native event processing | |
563 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
564 | ||
565 | if ( !wxWinMacControlList.Find((long)inControl) ) | |
566 | wxWinMacControlList.Append((long)inControl, control); | |
567 | } | |
568 | ||
569 | void wxRemoveMacControlAssociation(wxWindow *control) | |
570 | { | |
571 | wxWinMacControlList.DeleteObject(control); | |
572 | } | |
71f2fb52 RN |
573 | #else |
574 | ||
575 | WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); | |
576 | ||
577 | static MacControlMap wxWinMacControlList; | |
578 | ||
579 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
580 | { | |
581 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
582 | ||
583 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
584 | } | |
585 | ||
586 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
587 | { | |
588 | // adding NULL ControlRef is (first) surely a result of an error and | |
589 | // (secondly) breaks native event processing | |
590 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
591 | ||
592 | wxWinMacControlList[inControl] = control; | |
593 | } | |
594 | ||
595 | void wxRemoveMacControlAssociation(wxWindow *control) | |
596 | { | |
597 | // iterate over all the elements in the class | |
598 | MacControlMap::iterator it; | |
599 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
600 | { | |
601 | if ( it->second == control ) | |
602 | { | |
603 | wxWinMacControlList.erase(it); | |
604 | break; | |
605 | } | |
606 | } | |
607 | } | |
608 | #endif // deprecated wxList | |
facd6764 SC |
609 | |
610 | // UPP functions | |
611 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; | |
612 | ||
613 | ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; | |
614 | ||
615 | // we have to setup the brush in the current port and return noErr | |
8b573fb8 | 616 | // or return an error code so that the control manager walks further up the |
facd6764 SC |
617 | // hierarchy to find a correct background |
618 | ||
619 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) | |
620 | { | |
621 | OSStatus status = paramErr ; | |
622 | switch( iMessage ) | |
623 | { | |
624 | case kControlMsgApplyTextColor : | |
625 | break ; | |
626 | case kControlMsgSetUpBackground : | |
627 | { | |
628 | wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ; | |
629 | if ( wx != NULL ) | |
630 | { | |
db7a550b | 631 | /* |
facd6764 SC |
632 | const wxBrush &brush = wx->MacGetBackgroundBrush() ; |
633 | if ( brush.Ok() ) | |
634 | { | |
facd6764 | 635 | wxDC::MacSetupBackgroundForCurrentPort( brush ) ; |
db7a550b SC |
636 | */ |
637 | // this clipping is only needed for non HIView | |
8b573fb8 | 638 | |
facd6764 SC |
639 | RgnHandle clip = NewRgn() ; |
640 | int x = 0 , y = 0; | |
641 | ||
642 | wx->MacWindowToRootWindow( &x,&y ) ; | |
643 | CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ; | |
644 | OffsetRgn( clip , x , y ) ; | |
645 | SetClip( clip ) ; | |
646 | DisposeRgn( clip ) ; | |
647 | ||
648 | status = noErr ; | |
db7a550b | 649 | /* |
facd6764 SC |
650 | } |
651 | else if ( wx->MacIsUserPane() ) | |
652 | { | |
653 | // if we don't have a valid brush for such a control, we have to call the | |
654 | // setup of our parent ourselves | |
655 | status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ; | |
656 | } | |
db7a550b | 657 | */ |
facd6764 SC |
658 | } |
659 | } | |
660 | break ; | |
661 | default : | |
662 | break ; | |
663 | } | |
664 | return status ; | |
665 | } | |
666 | ||
667 | ||
668 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ; | |
669 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) | |
670 | { | |
671 | if ( partCode != 0) | |
672 | { | |
673 | wxWindow* wx = wxFindControlFromMacControl( control ) ; | |
674 | if ( wx ) | |
675 | { | |
676 | wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; | |
677 | } | |
678 | } | |
679 | } | |
e7549107 SC |
680 | |
681 | // ---------------------------------------------------------------------------- | |
facd6764 | 682 | // constructors and such |
e7549107 SC |
683 | // ---------------------------------------------------------------------------- |
684 | ||
94f9b1f0 | 685 | wxWindowMac::wxWindowMac() |
8b573fb8 VZ |
686 | { |
687 | Init(); | |
94f9b1f0 SC |
688 | } |
689 | ||
690 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
691 | wxWindowID id, | |
692 | const wxPoint& pos , | |
693 | const wxSize& size , | |
694 | long style , | |
695 | const wxString& name ) | |
696 | { | |
697 | Init(); | |
698 | Create(parent, id, pos, size, style, name); | |
699 | } | |
700 | ||
e766c8a9 | 701 | void wxWindowMac::Init() |
519cb848 | 702 | { |
21fd5529 | 703 | m_peer = NULL ; |
79392158 | 704 | m_frozenness = 0 ; |
557d6f32 | 705 | #if WXWIN_COMPATIBILITY_2_4 |
e7549107 | 706 | m_backgroundTransparent = FALSE; |
557d6f32 | 707 | #endif |
e7549107 SC |
708 | |
709 | // as all windows are created with WS_VISIBLE style... | |
710 | m_isShown = TRUE; | |
711 | ||
6264b550 RR |
712 | m_hScrollBar = NULL ; |
713 | m_vScrollBar = NULL ; | |
facd6764 SC |
714 | m_macBackgroundBrush = wxNullBrush ; |
715 | ||
facd6764 | 716 | m_macIsUserPane = TRUE; |
20b69855 SC |
717 | #if wxMAC_USE_CORE_GRAPHICS |
718 | m_cgContextRef = NULL ; | |
719 | #endif | |
facd6764 | 720 | // make sure all proc ptrs are available |
8b573fb8 | 721 | |
20b69855 | 722 | #if !TARGET_API_MAC_OSX |
facd6764 SC |
723 | if ( gControlUserPaneDrawUPP == NULL ) |
724 | { | |
725 | gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ; | |
726 | gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ; | |
727 | gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ; | |
728 | gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ; | |
729 | gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ; | |
730 | gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ; | |
731 | gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ; | |
732 | gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ; | |
733 | } | |
20b69855 | 734 | #endif |
facd6764 SC |
735 | if ( wxMacLiveScrollbarActionUPP == NULL ) |
736 | { | |
737 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); | |
738 | } | |
739 | ||
740 | if ( wxMacSetupControlBackgroundUPP == NULL ) | |
741 | { | |
742 | wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; | |
743 | } | |
744 | ||
c6f9fb05 SC |
745 | // we need a valid font for the encodings |
746 | wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
e9576ca5 SC |
747 | } |
748 | ||
749 | // Destructor | |
e766c8a9 | 750 | wxWindowMac::~wxWindowMac() |
e9576ca5 | 751 | { |
7de59551 RD |
752 | SendDestroyEvent(); |
753 | ||
140f2012 | 754 | m_isBeingDeleted = TRUE; |
6ed71b4f | 755 | |
7ebf5540 SC |
756 | if ( m_peer ) |
757 | { | |
758 | // deleting a window while it is shown invalidates the region occupied by border or | |
759 | // focus | |
760 | int outerBorder = MacGetLeftBorderSize() ; | |
761 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
8b573fb8 | 762 | outerBorder += 4 ; |
7ebf5540 SC |
763 | |
764 | if ( IsShown() && ( outerBorder > 0 ) ) | |
765 | { | |
766 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
767 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
8b573fb8 | 768 | |
7ebf5540 SC |
769 | Rect rect ; |
770 | ||
771 | m_peer->GetRect( &rect ) ; | |
772 | RectRgn( updateInner , &rect ) ; | |
773 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
774 | RectRgn( updateOuter , &rect ) ; | |
775 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
8b573fb8 | 776 | wxPoint parent(0,0); |
7ebf5540 SC |
777 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; |
778 | parent -= GetParent()->GetClientAreaOrigin() ; | |
779 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
8b573fb8 | 780 | CopyRgn( updateOuter , updateTotal ) ; |
7ebf5540 SC |
781 | |
782 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
783 | DisposeRgn(updateOuter) ; | |
784 | DisposeRgn(updateInner) ; | |
785 | DisposeRgn(updateTotal) ; | |
786 | } | |
787 | } | |
788 | ||
d4380aaf SC |
789 | #ifndef __WXUNIVERSAL__ |
790 | // VS: make sure there's no wxFrame with last focus set to us: | |
791 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
792 | { | |
793 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
794 | if ( frame ) | |
795 | { | |
796 | if ( frame->GetLastFocus() == this ) | |
797 | { | |
798 | frame->SetLastFocus((wxWindow*)NULL); | |
799 | } | |
800 | break; | |
801 | } | |
802 | } | |
803 | #endif // __WXUNIVERSAL__ | |
8b573fb8 VZ |
804 | |
805 | // destroy children before destroying this window itself | |
806 | DestroyChildren(); | |
807 | ||
facd6764 SC |
808 | // wxRemoveMacControlAssociation( this ) ; |
809 | // If we delete an item, we should initialize the parent panel, | |
810 | // because it could now be invalid. | |
811 | wxWindow *parent = GetParent() ; | |
812 | if ( parent ) | |
813 | { | |
814 | if (parent->GetDefaultItem() == (wxButton*) this) | |
815 | parent->SetDefaultItem(NULL); | |
816 | } | |
21fd5529 | 817 | if ( m_peer && m_peer->Ok() ) |
facd6764 SC |
818 | { |
819 | // in case the callback might be called during destruction | |
820 | wxRemoveMacControlAssociation( this) ; | |
5ca0d812 SC |
821 | // we currently are not using this hook |
822 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
823 | m_peer->Dispose() ; | |
facd6764 | 824 | } |
d4380aaf | 825 | |
facd6764 | 826 | if ( g_MacLastWindow == this ) |
6264b550 | 827 | { |
facd6764 | 828 | g_MacLastWindow = NULL ; |
6264b550 | 829 | } |
7de59551 | 830 | |
fd76aa8d SC |
831 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; |
832 | if ( frame ) | |
833 | { | |
e40298d5 JS |
834 | if ( frame->GetLastFocus() == this ) |
835 | frame->SetLastFocus( NULL ) ; | |
fd76aa8d | 836 | } |
e7549107 | 837 | |
42683dfb SC |
838 | // delete our drop target if we've got one |
839 | #if wxUSE_DRAG_AND_DROP | |
840 | if ( m_dropTarget != NULL ) | |
841 | { | |
842 | delete m_dropTarget; | |
843 | m_dropTarget = NULL; | |
844 | } | |
845 | #endif // wxUSE_DRAG_AND_DROP | |
21fd5529 SC |
846 | delete m_peer ; |
847 | } | |
848 | ||
8b573fb8 VZ |
849 | WXWidget wxWindowMac::GetHandle() const |
850 | { | |
851 | return (WXWidget) m_peer->GetControlRef() ; | |
e9576ca5 SC |
852 | } |
853 | ||
facd6764 | 854 | |
5ca0d812 | 855 | void wxWindowMac::MacInstallEventHandler( WXWidget control ) |
facd6764 | 856 | { |
5ca0d812 SC |
857 | wxAssociateControlWithMacControl( (ControlRef) control , this ) ; |
858 | InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(), | |
8b573fb8 | 859 | GetEventTypeCount(eventList), eventList, this, |
facd6764 | 860 | (EventHandlerRef *)&m_macControlEventHandler); |
4a63451b SC |
861 | #if !TARGET_API_MAC_OSX |
862 | if ( (ControlRef) control == m_peer->GetControlRef() ) | |
863 | { | |
864 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ; | |
865 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ; | |
866 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ; | |
867 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ; | |
868 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ; | |
869 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ; | |
870 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ; | |
871 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ; | |
872 | } | |
873 | #endif | |
facd6764 SC |
874 | |
875 | } | |
876 | ||
e9576ca5 | 877 | // Constructor |
e766c8a9 | 878 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, |
e9576ca5 SC |
879 | const wxPoint& pos, |
880 | const wxSize& size, | |
881 | long style, | |
882 | const wxString& name) | |
883 | { | |
e766c8a9 | 884 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 885 | |
e7549107 | 886 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
e9576ca5 SC |
887 | return FALSE; |
888 | ||
facd6764 | 889 | m_windowVariant = parent->GetWindowVariant() ; |
8b573fb8 | 890 | |
facd6764 SC |
891 | if ( m_macIsUserPane ) |
892 | { | |
893 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
8b573fb8 | 894 | |
ebe86b1e | 895 | UInt32 features = 0 |
8b573fb8 VZ |
896 | | kControlSupportsEmbedding |
897 | // | kControlSupportsLiveFeedback | |
898 | // | kControlHasSpecialBackground | |
899 | // | kControlSupportsCalcBestRect | |
900 | // | kControlHandlesTracking | |
901 | | kControlSupportsFocus | |
902 | // | kControlWantsActivate | |
903 | // | kControlWantsIdle | |
904 | ; | |
ebe86b1e | 905 | |
21fd5529 | 906 | m_peer = new wxMacControl() ; |
5ca0d812 | 907 | ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); |
8b573fb8 | 908 | |
facd6764 SC |
909 | |
910 | MacPostControlCreate(pos,size) ; | |
facd6764 | 911 | } |
e766c8a9 | 912 | #ifndef __WXUNIVERSAL__ |
14c9cbdb RD |
913 | // Don't give scrollbars to wxControls unless they ask for them |
914 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
915 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
6264b550 RR |
916 | { |
917 | MacCreateScrollBars( style ) ; | |
918 | } | |
e766c8a9 | 919 | #endif |
3dfafdb9 RD |
920 | |
921 | wxWindowCreateEvent event(this); | |
7e4a196e | 922 | GetEventHandler()->AddPendingEvent(event); |
3dfafdb9 | 923 | |
e9576ca5 SC |
924 | return TRUE; |
925 | } | |
926 | ||
08422003 SC |
927 | void wxWindowMac::MacChildAdded() |
928 | { | |
929 | if ( m_vScrollBar ) | |
930 | { | |
931 | m_vScrollBar->Raise() ; | |
932 | } | |
933 | if ( m_hScrollBar ) | |
934 | { | |
935 | m_hScrollBar->Raise() ; | |
936 | } | |
937 | ||
938 | } | |
939 | ||
facd6764 SC |
940 | void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) |
941 | { | |
21fd5529 | 942 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; |
facd6764 | 943 | |
5ca0d812 | 944 | m_peer->SetReference( (long) this ) ; |
488abb22 | 945 | GetParent()->AddChild(this); |
facd6764 | 946 | |
5ca0d812 | 947 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); |
facd6764 SC |
948 | |
949 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
950 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
5ca0d812 | 951 | ::EmbedControl( m_peer->GetControlRef() , container ) ; |
08422003 | 952 | GetParent()->MacChildAdded() ; |
facd6764 SC |
953 | |
954 | // adjust font, controlsize etc | |
955 | DoSetWindowVariant( m_windowVariant ) ; | |
956 | ||
957 | #if !TARGET_API_MAC_OSX | |
8b573fb8 | 958 | // eventually we can fix some clipping issues be reactivating this hook |
facd6764 | 959 | //if ( m_macIsUserPane ) |
be346c26 | 960 | // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ; |
facd6764 | 961 | #endif |
5ca0d812 | 962 | m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; |
facd6764 | 963 | |
facd6764 | 964 | if (!m_macIsUserPane) |
d3b5db4b RD |
965 | { |
966 | SetInitialBestSize(size); | |
facd6764 SC |
967 | } |
968 | ||
969 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
facd6764 SC |
970 | } |
971 | ||
972 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
973 | { | |
23176131 JS |
974 | // Don't assert, in case we set the window variant before |
975 | // the window is created | |
21fd5529 | 976 | // wxASSERT( m_peer->Ok() ) ; |
facd6764 | 977 | |
23176131 JS |
978 | m_windowVariant = variant ; |
979 | ||
21fd5529 | 980 | if (m_peer == NULL || !m_peer->Ok()) |
23176131 | 981 | return; |
facd6764 | 982 | |
8b573fb8 | 983 | ControlSize size ; |
facd6764 SC |
984 | ThemeFontID themeFont = kThemeSystemFont ; |
985 | ||
986 | // we will get that from the settings later | |
8b573fb8 | 987 | // and make this NORMAL later, but first |
facd6764 | 988 | // we have a few calculations that we must fix |
8b573fb8 | 989 | |
facd6764 SC |
990 | switch ( variant ) |
991 | { | |
992 | case wxWINDOW_VARIANT_NORMAL : | |
8b573fb8 VZ |
993 | size = kControlSizeNormal; |
994 | themeFont = kThemeSystemFont ; | |
facd6764 SC |
995 | break ; |
996 | case wxWINDOW_VARIANT_SMALL : | |
8b573fb8 VZ |
997 | size = kControlSizeSmall; |
998 | themeFont = kThemeSmallSystemFont ; | |
facd6764 SC |
999 | break ; |
1000 | case wxWINDOW_VARIANT_MINI : | |
1001 | if (UMAGetSystemVersion() >= 0x1030 ) | |
1002 | { | |
8b573fb8 VZ |
1003 | // not always defined in the headers |
1004 | size = 3 ; | |
1005 | themeFont = 109 ; | |
facd6764 SC |
1006 | } |
1007 | else | |
1008 | { | |
8b573fb8 VZ |
1009 | size = kControlSizeSmall; |
1010 | themeFont = kThemeSmallSystemFont ; | |
facd6764 SC |
1011 | } |
1012 | break ; | |
1013 | case wxWINDOW_VARIANT_LARGE : | |
8b573fb8 VZ |
1014 | size = kControlSizeLarge; |
1015 | themeFont = kThemeSystemFont ; | |
facd6764 SC |
1016 | break ; |
1017 | default: | |
1018 | wxFAIL_MSG(_T("unexpected window variant")); | |
1019 | break ; | |
1020 | } | |
5ca0d812 | 1021 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ; |
facd6764 SC |
1022 | |
1023 | wxFont font ; | |
1024 | font.MacCreateThemeFont( themeFont ) ; | |
1025 | SetFont( font ) ; | |
1026 | } | |
1027 | ||
8b573fb8 | 1028 | void wxWindowMac::MacUpdateControlFont() |
facd6764 | 1029 | { |
ac99838a | 1030 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; |
8b573fb8 | 1031 | Refresh() ; |
facd6764 SC |
1032 | } |
1033 | ||
1034 | bool wxWindowMac::SetFont(const wxFont& font) | |
1035 | { | |
d5ccba72 | 1036 | bool retval = wxWindowBase::SetFont( font ) ; |
8b573fb8 | 1037 | |
facd6764 | 1038 | MacUpdateControlFont() ; |
8b573fb8 | 1039 | |
facd6764 SC |
1040 | return retval; |
1041 | } | |
1042 | ||
1043 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
1044 | { | |
1045 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
1046 | return false ; | |
8b573fb8 | 1047 | |
facd6764 | 1048 | MacUpdateControlFont() ; |
8b573fb8 | 1049 | |
facd6764 SC |
1050 | return true ; |
1051 | } | |
1052 | ||
1053 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
1054 | { | |
1055 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
1056 | return false ; | |
1057 | ||
1058 | wxBrush brush ; | |
b52acd03 RD |
1059 | wxColour newCol(GetBackgroundColour()); |
1060 | if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
facd6764 SC |
1061 | { |
1062 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; | |
1063 | } | |
b52acd03 | 1064 | else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) |
facd6764 | 1065 | { |
8b573fb8 VZ |
1066 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; |
1067 | } | |
facd6764 SC |
1068 | else |
1069 | { | |
b52acd03 | 1070 | brush.SetColour( newCol ) ; |
facd6764 SC |
1071 | } |
1072 | MacSetBackgroundBrush( brush ) ; | |
8b573fb8 | 1073 | |
db7a550b | 1074 | MacUpdateControlFont() ; |
8b573fb8 | 1075 | |
facd6764 SC |
1076 | return true ; |
1077 | } | |
1078 | ||
7ea087b7 SC |
1079 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1080 | { | |
1081 | m_macBackgroundBrush = brush ; | |
1082 | m_peer->SetBackground( brush ) ; | |
1083 | } | |
facd6764 SC |
1084 | |
1085 | bool wxWindowMac::MacCanFocus() const | |
1086 | { | |
f6e3849c SC |
1087 | // there is currently no way to determine whether the window is running in full keyboard |
1088 | // access mode, therefore we cannot rely on these features, yet the only other way would be | |
1089 | // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems | |
1090 | // in event handlers... | |
f1d527c1 | 1091 | UInt32 features = 0 ; |
5ca0d812 | 1092 | m_peer->GetFeatures( & features ) ; |
8b573fb8 | 1093 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; |
facd6764 SC |
1094 | } |
1095 | ||
1096 | ||
e766c8a9 | 1097 | void wxWindowMac::SetFocus() |
e9576ca5 | 1098 | { |
6264b550 RR |
1099 | if ( AcceptsFocus() ) |
1100 | { | |
7d0cfe71 | 1101 | |
f1d527c1 | 1102 | wxWindow* former = FindFocus() ; |
7d0cfe71 SC |
1103 | if ( former == this ) |
1104 | return ; | |
1105 | ||
5ca0d812 | 1106 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; |
f1d527c1 SC |
1107 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only |
1108 | // leave in case of an error | |
1109 | if ( err == errCouldntSetFocus ) | |
1110 | return ; | |
1111 | ||
1112 | #if !TARGET_API_MAC_OSX | |
1113 | // emulate carbon events when running under carbonlib where they are not natively available | |
1114 | if ( former ) | |
1115 | { | |
1116 | EventRef evRef = NULL ; | |
1117 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1118 | &evRef ) ); | |
1119 | ||
1120 | wxMacCarbonEvent cEvent( evRef ) ; | |
1121 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1122 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
8b573fb8 | 1123 | |
f1d527c1 SC |
1124 | wxMacWindowEventHandler( NULL , evRef , former ) ; |
1125 | ReleaseEvent(evRef) ; | |
6264b550 | 1126 | } |
f1d527c1 | 1127 | // send new focus event |
6264b550 | 1128 | { |
f1d527c1 SC |
1129 | EventRef evRef = NULL ; |
1130 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1131 | &evRef ) ); | |
1132 | ||
1133 | wxMacCarbonEvent cEvent( evRef ) ; | |
1134 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1135 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
8b573fb8 | 1136 | |
f1d527c1 SC |
1137 | wxMacWindowEventHandler( NULL , evRef , this ) ; |
1138 | ReleaseEvent(evRef) ; | |
6264b550 | 1139 | } |
f1d527c1 | 1140 | #endif |
6264b550 | 1141 | } |
e9576ca5 SC |
1142 | } |
1143 | ||
e9576ca5 | 1144 | |
4116c221 | 1145 | void wxWindowMac::DoCaptureMouse() |
e9576ca5 | 1146 | { |
519cb848 | 1147 | wxTheApp->s_captureWindow = this ; |
e9576ca5 SC |
1148 | } |
1149 | ||
90b959ae SC |
1150 | wxWindow* wxWindowBase::GetCapture() |
1151 | { | |
1152 | return wxTheApp->s_captureWindow ; | |
1153 | } | |
1154 | ||
4116c221 | 1155 | void wxWindowMac::DoReleaseMouse() |
e9576ca5 | 1156 | { |
519cb848 | 1157 | wxTheApp->s_captureWindow = NULL ; |
e9576ca5 SC |
1158 | } |
1159 | ||
e9576ca5 SC |
1160 | #if wxUSE_DRAG_AND_DROP |
1161 | ||
e766c8a9 | 1162 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 | 1163 | { |
e40298d5 JS |
1164 | if ( m_dropTarget != 0 ) { |
1165 | delete m_dropTarget; | |
1166 | } | |
6ed71b4f | 1167 | |
e40298d5 JS |
1168 | m_dropTarget = pDropTarget; |
1169 | if ( m_dropTarget != 0 ) | |
1170 | { | |
1171 | // TODO | |
1172 | } | |
e9576ca5 SC |
1173 | } |
1174 | ||
1175 | #endif | |
1176 | ||
1177 | // Old style file-manager drag&drop | |
e766c8a9 | 1178 | void wxWindowMac::DragAcceptFiles(bool accept) |
e9576ca5 SC |
1179 | { |
1180 | // TODO | |
1181 | } | |
1182 | ||
055a486b SC |
1183 | // Returns the size of the native control. In the case of the toplevel window |
1184 | // this is the content area root control | |
1185 | ||
facd6764 | 1186 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, |
8b573fb8 | 1187 | int& w, int& h) const |
e9576ca5 | 1188 | { |
facd6764 | 1189 | Rect bounds ; |
8b573fb8 | 1190 | m_peer->GetRect( &bounds ) ; |
e9576ca5 | 1191 | |
14c9cbdb | 1192 | |
facd6764 SC |
1193 | x = bounds.left ; |
1194 | y = bounds.top ; | |
1195 | w = bounds.right - bounds.left ; | |
1196 | h = bounds.bottom - bounds.top ; | |
e9576ca5 SC |
1197 | } |
1198 | ||
055a486b | 1199 | // From a wx position / size calculate the appropriate size of the native control |
8b573fb8 | 1200 | |
facd6764 SC |
1201 | bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, |
1202 | const wxSize& size, | |
1203 | int& x, int& y, | |
8b573fb8 | 1204 | int& w, int& h , bool adjustOrigin ) const |
51abe921 | 1205 | { |
5ca0d812 | 1206 | // the desired size, minus the border pixels gives the correct size of the control |
8b573fb8 | 1207 | |
facd6764 SC |
1208 | x = (int)pos.x; |
1209 | y = (int)pos.y; | |
1210 | // todo the default calls may be used as soon as PostCreateControl Is moved here | |
1211 | w = size.x ; // WidthDefault( size.x ); | |
1212 | h = size.y ; // HeightDefault( size.y ) ; | |
1213 | #if !TARGET_API_MAC_OSX | |
1214 | GetParent()->MacWindowToRootWindow( &x , &y ) ; | |
1215 | #endif | |
5ca0d812 SC |
1216 | |
1217 | x += MacGetLeftBorderSize() ; | |
1218 | y += MacGetTopBorderSize() ; | |
1219 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1220 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
8b573fb8 | 1221 | |
79392158 SC |
1222 | if ( adjustOrigin ) |
1223 | AdjustForParentClientOrigin( x , y ) ; | |
7ebf5540 SC |
1224 | #if TARGET_API_MAC_OSX |
1225 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
1226 | if ( ! GetParent()->IsTopLevel() ) | |
1227 | { | |
1228 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1229 | y -= GetParent()->MacGetTopBorderSize() ; | |
1230 | } | |
1231 | #endif | |
facd6764 SC |
1232 | return true ; |
1233 | } | |
1234 | ||
42ef83fa | 1235 | // Get window size (not client size) |
facd6764 SC |
1236 | void wxWindowMac::DoGetSize(int *x, int *y) const |
1237 | { | |
5ca0d812 | 1238 | // take the size of the control and add the borders that have to be drawn outside |
42ef83fa SC |
1239 | int x1 , y1 , w1 , h1 ; |
1240 | ||
facd6764 | 1241 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; |
42ef83fa | 1242 | |
5ca0d812 SC |
1243 | w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
1244 | h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
8b573fb8 | 1245 | |
5ca0d812 SC |
1246 | if(x) *x = w1 ; |
1247 | if(y) *y = h1 ; | |
facd6764 SC |
1248 | } |
1249 | ||
42ef83fa | 1250 | // get the position of the bounds of this window in client coordinates of its parent |
facd6764 SC |
1251 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
1252 | { | |
facd6764 SC |
1253 | int x1 , y1 , w1 ,h1 ; |
1254 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; | |
5ca0d812 SC |
1255 | x1 -= MacGetLeftBorderSize() ; |
1256 | y1 -= MacGetTopBorderSize() ; | |
42ef83fa SC |
1257 | // to non-client |
1258 | #if !TARGET_API_MAC_OSX | |
1259 | if ( !GetParent()->IsTopLevel() ) | |
1260 | { | |
1261 | Rect bounds ; | |
1262 | GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ; | |
1263 | x1 -= bounds.left ; | |
1264 | y1 -= bounds.top ; | |
1265 | } | |
1266 | #endif | |
facd6764 | 1267 | if ( !IsTopLevel() ) |
2b5f62a0 | 1268 | { |
facd6764 SC |
1269 | wxWindow *parent = GetParent(); |
1270 | if ( parent ) | |
8950f7cc | 1271 | { |
1a02aff9 SC |
1272 | // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix |
1273 | x1 += parent->MacGetLeftBorderSize() ; | |
1274 | y1 += parent->MacGetTopBorderSize() ; | |
1275 | // and now to client coordinates | |
facd6764 SC |
1276 | wxPoint pt(parent->GetClientAreaOrigin()); |
1277 | x1 -= pt.x ; | |
1278 | y1 -= pt.y ; | |
6ed71b4f | 1279 | } |
2b5f62a0 | 1280 | } |
facd6764 SC |
1281 | if(x) *x = x1 ; |
1282 | if(y) *y = y1 ; | |
facd6764 | 1283 | } |
51abe921 | 1284 | |
e766c8a9 | 1285 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 1286 | { |
facd6764 | 1287 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
8b573fb8 | 1288 | |
facd6764 | 1289 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; |
8b573fb8 | 1290 | |
facd6764 SC |
1291 | { |
1292 | Point localwhere = {0,0} ; | |
519cb848 | 1293 | |
facd6764 SC |
1294 | if(x) localwhere.h = * x ; |
1295 | if(y) localwhere.v = * y ; | |
8b573fb8 | 1296 | |
a9de2608 | 1297 | QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1298 | if(x) *x = localwhere.h ; |
1299 | if(y) *y = localwhere.v ; | |
6ed71b4f | 1300 | |
facd6764 | 1301 | } |
2078220e | 1302 | MacRootWindowToWindow( x , y ) ; |
8b573fb8 | 1303 | |
facd6764 SC |
1304 | wxPoint origin = GetClientAreaOrigin() ; |
1305 | if(x) *x -= origin.x ; | |
1306 | if(y) *y -= origin.y ; | |
e9576ca5 SC |
1307 | } |
1308 | ||
e766c8a9 | 1309 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 1310 | { |
facd6764 SC |
1311 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1312 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
14c9cbdb | 1313 | |
facd6764 SC |
1314 | wxPoint origin = GetClientAreaOrigin() ; |
1315 | if(x) *x += origin.x ; | |
1316 | if(y) *y += origin.y ; | |
14c9cbdb | 1317 | |
2078220e | 1318 | MacWindowToRootWindow( x , y ) ; |
14c9cbdb | 1319 | |
facd6764 SC |
1320 | { |
1321 | Point localwhere = { 0,0 }; | |
1322 | if(x) localwhere.h = * x ; | |
1323 | if(y) localwhere.v = * y ; | |
a9de2608 | 1324 | QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1325 | if(x) *x = localwhere.h ; |
1326 | if(y) *y = localwhere.v ; | |
1327 | } | |
519cb848 SC |
1328 | } |
1329 | ||
e766c8a9 | 1330 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 1331 | { |
1c310985 SC |
1332 | wxPoint origin = GetClientAreaOrigin() ; |
1333 | if(x) *x += origin.x ; | |
1334 | if(y) *y += origin.y ; | |
14c9cbdb | 1335 | |
1c310985 SC |
1336 | MacWindowToRootWindow( x , y ) ; |
1337 | } | |
1338 | ||
1339 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1340 | { | |
1c310985 | 1341 | MacRootWindowToWindow( x , y ) ; |
facd6764 SC |
1342 | |
1343 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 SC |
1344 | if(x) *x -= origin.x ; |
1345 | if(y) *y -= origin.y ; | |
1346 | } | |
1347 | ||
1348 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1349 | { | |
facd6764 | 1350 | #if TARGET_API_MAC_OSX |
5ca0d812 | 1351 | wxPoint pt ; |
facd6764 SC |
1352 | if ( x ) pt.x = *x ; |
1353 | if ( y ) pt.y = *y ; | |
1354 | ||
125c7984 | 1355 | if ( !IsTopLevel() ) |
5437ff47 RD |
1356 | { |
1357 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1358 | if (top) | |
5ca0d812 SC |
1359 | { |
1360 | pt.x -= MacGetLeftBorderSize() ; | |
1361 | pt.y -= MacGetTopBorderSize() ; | |
1362 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1363 | } | |
5437ff47 | 1364 | } |
8b573fb8 | 1365 | |
facd6764 SC |
1366 | if ( x ) *x = (int) pt.x ; |
1367 | if ( y ) *y = (int) pt.y ; | |
1368 | #else | |
1c310985 | 1369 | if ( !IsTopLevel() ) |
6264b550 | 1370 | { |
facd6764 | 1371 | Rect bounds ; |
8b573fb8 | 1372 | m_peer->GetRect( &bounds ) ; |
055a486b SC |
1373 | if(x) *x += bounds.left - MacGetLeftBorderSize() ; |
1374 | if(y) *y += bounds.top - MacGetTopBorderSize() ; | |
6264b550 | 1375 | } |
facd6764 SC |
1376 | #endif |
1377 | } | |
1378 | ||
1379 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1380 | { | |
1381 | int x1 , y1 ; | |
1382 | if ( x ) x1 = *x ; | |
1383 | if ( y ) y1 = *y ; | |
1384 | MacWindowToRootWindow( &x1 , &y1 ) ; | |
1385 | if ( x ) *x = x1 ; | |
1386 | if ( y ) *y = y1 ; | |
519cb848 SC |
1387 | } |
1388 | ||
1c310985 | 1389 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const |
519cb848 | 1390 | { |
facd6764 | 1391 | #if TARGET_API_MAC_OSX |
5ca0d812 | 1392 | wxPoint pt ; |
facd6764 SC |
1393 | if ( x ) pt.x = *x ; |
1394 | if ( y ) pt.y = *y ; | |
1395 | ||
125c7984 | 1396 | if ( !IsTopLevel() ) |
5ca0d812 SC |
1397 | { |
1398 | wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ; | |
1399 | pt.x += MacGetLeftBorderSize() ; | |
1400 | pt.y += MacGetTopBorderSize() ; | |
1401 | } | |
8b573fb8 | 1402 | |
facd6764 SC |
1403 | if ( x ) *x = (int) pt.x ; |
1404 | if ( y ) *y = (int) pt.y ; | |
1405 | #else | |
1c310985 | 1406 | if ( !IsTopLevel() ) |
6264b550 | 1407 | { |
facd6764 | 1408 | Rect bounds ; |
8b573fb8 | 1409 | m_peer->GetRect( &bounds ) ; |
055a486b SC |
1410 | if(x) *x -= bounds.left + MacGetLeftBorderSize() ; |
1411 | if(y) *y -= bounds.top + MacGetTopBorderSize() ; | |
6264b550 | 1412 | } |
facd6764 | 1413 | #endif |
e9576ca5 SC |
1414 | } |
1415 | ||
facd6764 | 1416 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const |
e9576ca5 | 1417 | { |
facd6764 SC |
1418 | int x1 , y1 ; |
1419 | if ( x ) x1 = *x ; | |
1420 | if ( y ) y1 = *y ; | |
1421 | MacRootWindowToWindow( &x1 , &y1 ) ; | |
1422 | if ( x ) *x = x1 ; | |
1423 | if ( y ) *y = y1 ; | |
1424 | } | |
6ed71b4f | 1425 | |
29281095 SC |
1426 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1427 | { | |
1428 | RgnHandle rgn = NewRgn() ; | |
1429 | Rect content ; | |
5ca0d812 | 1430 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
29281095 SC |
1431 | { |
1432 | GetRegionBounds( rgn , &content ) ; | |
29281095 SC |
1433 | } |
1434 | else | |
1435 | { | |
5ca0d812 | 1436 | m_peer->GetRect( &content ) ; |
29281095 | 1437 | } |
7596e51d | 1438 | DisposeRgn( rgn ) ; |
29281095 | 1439 | Rect structure ; |
5ca0d812 | 1440 | m_peer->GetRect( &structure ) ; |
8b573fb8 | 1441 | #if !TARGET_API_MAC_OSX |
29281095 SC |
1442 | OffsetRect( &content , -structure.left , -structure.top ) ; |
1443 | #endif | |
1444 | left = content.left - structure.left ; | |
1445 | top = content.top - structure.top ; | |
1446 | right = structure.right - content.right ; | |
1447 | bottom = structure.bottom - content.bottom ; | |
1448 | } | |
1449 | ||
facd6764 SC |
1450 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const |
1451 | { | |
1452 | wxSize sizeTotal = size; | |
1453 | ||
1454 | RgnHandle rgn = NewRgn() ; | |
1455 | ||
1456 | Rect content ; | |
8b573fb8 | 1457 | |
5ca0d812 | 1458 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
6618870d | 1459 | { |
facd6764 | 1460 | GetRegionBounds( rgn , &content ) ; |
6618870d SC |
1461 | } |
1462 | else | |
1463 | { | |
5ca0d812 | 1464 | m_peer->GetRect( &content ) ; |
e40298d5 | 1465 | } |
7596e51d | 1466 | DisposeRgn( rgn ) ; |
facd6764 | 1467 | Rect structure ; |
5ca0d812 | 1468 | m_peer->GetRect( &structure ) ; |
8b573fb8 | 1469 | #if !TARGET_API_MAC_OSX |
facd6764 SC |
1470 | OffsetRect( &content , -structure.left , -structure.top ) ; |
1471 | #endif | |
6ed71b4f | 1472 | |
facd6764 | 1473 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; |
8b573fb8 | 1474 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; |
6ed71b4f | 1475 | |
facd6764 SC |
1476 | sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1477 | sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
6ed71b4f | 1478 | |
facd6764 | 1479 | return sizeTotal; |
e9576ca5 SC |
1480 | } |
1481 | ||
1482 | ||
1483 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
e766c8a9 | 1484 | void wxWindowMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 1485 | { |
9453cf2b | 1486 | int ww, hh; |
6ed71b4f | 1487 | |
facd6764 SC |
1488 | RgnHandle rgn = NewRgn() ; |
1489 | Rect content ; | |
5ca0d812 | 1490 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
facd6764 SC |
1491 | { |
1492 | GetRegionBounds( rgn , &content ) ; | |
facd6764 SC |
1493 | } |
1494 | else | |
1495 | { | |
5ca0d812 | 1496 | m_peer->GetRect( &content ) ; |
facd6764 | 1497 | } |
7596e51d | 1498 | DisposeRgn( rgn ) ; |
facd6764 SC |
1499 | #if !TARGET_API_MAC_OSX |
1500 | Rect structure ; | |
5ca0d812 | 1501 | m_peer->GetRect( &structure ) ; |
facd6764 | 1502 | OffsetRect( &content , -structure.left , -structure.top ) ; |
8b573fb8 | 1503 | #endif |
facd6764 SC |
1504 | ww = content.right - content.left ; |
1505 | hh = content.bottom - content.top ; | |
055a486b | 1506 | /* |
6264b550 RR |
1507 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1508 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
055a486b | 1509 | */ |
db7a550b | 1510 | /* |
e40298d5 JS |
1511 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) |
1512 | { | |
1513 | int x1 = 0 ; | |
1514 | int y1 = 0 ; | |
facd6764 SC |
1515 | int w ; |
1516 | int h ; | |
1517 | GetSize( &w , &h ) ; | |
8b573fb8 | 1518 | |
e40298d5 JS |
1519 | MacClientToRootWindow( &x1 , &y1 ) ; |
1520 | MacClientToRootWindow( &w , &h ) ; | |
6ed71b4f | 1521 | |
e40298d5 | 1522 | wxWindowMac *iter = (wxWindowMac*)this ; |
6ed71b4f | 1523 | |
e40298d5 JS |
1524 | int totW = 10000 , totH = 10000; |
1525 | while( iter ) | |
6264b550 | 1526 | { |
e40298d5 JS |
1527 | if ( iter->IsTopLevel() ) |
1528 | { | |
facd6764 | 1529 | iter->GetSize( &totW , &totH ) ; |
e40298d5 JS |
1530 | break ; |
1531 | } | |
6ed71b4f | 1532 | |
e40298d5 | 1533 | iter = iter->GetParent() ; |
6264b550 | 1534 | } |
6ed71b4f | 1535 | |
e40298d5 | 1536 | if (m_hScrollBar && m_hScrollBar->IsShown() ) |
6264b550 | 1537 | { |
db7a550b | 1538 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; |
e40298d5 JS |
1539 | if ( h-y1 >= totH ) |
1540 | { | |
1541 | hh += 1 ; | |
1542 | } | |
6264b550 | 1543 | } |
e40298d5 | 1544 | if (m_vScrollBar && m_vScrollBar->IsShown() ) |
6264b550 | 1545 | { |
db7a550b | 1546 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; |
e40298d5 JS |
1547 | if ( w-x1 >= totW ) |
1548 | { | |
1549 | ww += 1 ; | |
1550 | } | |
6264b550 RR |
1551 | } |
1552 | } | |
db7a550b SC |
1553 | */ |
1554 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
1555 | { | |
1556 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; | |
1557 | } | |
1558 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1559 | { | |
1560 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; | |
1561 | } | |
e40298d5 JS |
1562 | if(x) *x = ww; |
1563 | if(y) *y = hh; | |
facd6764 SC |
1564 | |
1565 | } | |
1566 | ||
1567 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1568 | { | |
1569 | if (m_cursor == cursor) | |
1570 | return FALSE; | |
1571 | ||
1572 | if (wxNullCursor == cursor) | |
1573 | { | |
1574 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
1575 | return FALSE ; | |
1576 | } | |
1577 | else | |
1578 | { | |
1579 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
1580 | return FALSE ; | |
1581 | } | |
1582 | ||
1583 | wxASSERT_MSG( m_cursor.Ok(), | |
1584 | wxT("cursor must be valid after call to the base version")); | |
8b573fb8 VZ |
1585 | |
1586 | ||
2d1760d3 | 1587 | wxWindowMac *mouseWin = 0 ; |
facd6764 | 1588 | { |
2d1760d3 SC |
1589 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1590 | CGrafPtr savePort ; | |
1591 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
8b573fb8 | 1592 | |
2d1760d3 SC |
1593 | // TODO If we ever get a GetCurrentEvent.. replacement for the mouse |
1594 | // position, use it... | |
8b573fb8 | 1595 | |
2d1760d3 SC |
1596 | Point pt ; |
1597 | GetMouse( &pt ) ; | |
1598 | ControlPartCode part ; | |
1599 | ControlRef control ; | |
1600 | control = wxMacFindControlUnderMouse( pt , window , &part ) ; | |
1601 | if ( control ) | |
1602 | mouseWin = wxFindControlFromMacControl( control ) ; | |
8b573fb8 | 1603 | |
2d1760d3 SC |
1604 | if ( swapped ) |
1605 | QDSwapPort( savePort , NULL ) ; | |
facd6764 | 1606 | } |
2d1760d3 SC |
1607 | |
1608 | if ( mouseWin == this && !wxIsBusy() ) | |
facd6764 SC |
1609 | { |
1610 | m_cursor.MacInstall() ; | |
1611 | } | |
1612 | ||
1613 | return TRUE ; | |
519cb848 SC |
1614 | } |
1615 | ||
facd6764 SC |
1616 | #if wxUSE_MENUS |
1617 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1618 | { | |
1619 | menu->SetInvokingWindow(this); | |
1620 | menu->UpdateUI(); | |
8b573fb8 | 1621 | |
971562cb VS |
1622 | if ( x == -1 && y == -1 ) |
1623 | { | |
1624 | wxPoint mouse = wxGetMousePosition(); | |
1625 | x = mouse.x; y = mouse.y; | |
1626 | } | |
1627 | else | |
1628 | { | |
1629 | ClientToScreen( &x , &y ) ; | |
1630 | } | |
facd6764 SC |
1631 | |
1632 | menu->MacBeforeDisplay( true ) ; | |
1633 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
1634 | if ( HiWord(menuResult) != 0 ) | |
1635 | { | |
1636 | MenuCommand id ; | |
1637 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
1638 | wxMenuItem* item = NULL ; | |
1639 | wxMenu* realmenu ; | |
1640 | item = menu->FindItem(id, &realmenu) ; | |
1641 | if (item->IsCheckable()) | |
1642 | { | |
1643 | item->Check( !item->IsChecked() ) ; | |
1644 | } | |
1645 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
1646 | } | |
1647 | menu->MacAfterDisplay( true ) ; | |
1648 | ||
1649 | menu->SetInvokingWindow(NULL); | |
1650 | ||
1651 | return TRUE; | |
1652 | } | |
1653 | #endif | |
51abe921 SC |
1654 | |
1655 | // ---------------------------------------------------------------------------- | |
1656 | // tooltips | |
1657 | // ---------------------------------------------------------------------------- | |
1658 | ||
1659 | #if wxUSE_TOOLTIPS | |
1660 | ||
e766c8a9 | 1661 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
1662 | { |
1663 | wxWindowBase::DoSetToolTip(tooltip); | |
6ed71b4f | 1664 | |
6264b550 RR |
1665 | if ( m_tooltip ) |
1666 | m_tooltip->SetWindow(this); | |
51abe921 SC |
1667 | } |
1668 | ||
1669 | #endif // wxUSE_TOOLTIPS | |
1670 | ||
e766c8a9 | 1671 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 1672 | { |
db7a550b | 1673 | // this is never called for a toplevel window, so we know we have a parent |
facd6764 | 1674 | int former_x , former_y , former_w, former_h ; |
db7a550b SC |
1675 | |
1676 | // Get true coordinates of former position | |
facd6764 SC |
1677 | DoGetPosition( &former_x , &former_y ) ; |
1678 | DoGetSize( &former_w , &former_h ) ; | |
db7a550b SC |
1679 | |
1680 | wxWindow *parent = GetParent(); | |
1681 | if ( parent ) | |
1682 | { | |
1683 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1684 | former_x += pt.x ; | |
1685 | former_y += pt.y ; | |
1686 | } | |
6ed71b4f | 1687 | |
e40298d5 JS |
1688 | int actualWidth = width; |
1689 | int actualHeight = height; | |
1690 | int actualX = x; | |
1691 | int actualY = y; | |
6ed71b4f | 1692 | |
14c9cbdb | 1693 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 1694 | actualWidth = m_minWidth; |
14c9cbdb | 1695 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 1696 | actualHeight = m_minHeight; |
14c9cbdb | 1697 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 1698 | actualWidth = m_maxWidth; |
14c9cbdb | 1699 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
6264b550 | 1700 | actualHeight = m_maxHeight; |
6ed71b4f | 1701 | |
6264b550 RR |
1702 | bool doMove = false ; |
1703 | bool doResize = false ; | |
6ed71b4f | 1704 | |
6264b550 RR |
1705 | if ( actualX != former_x || actualY != former_y ) |
1706 | { | |
1707 | doMove = true ; | |
1708 | } | |
1709 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1710 | { | |
1711 | doResize = true ; | |
1712 | } | |
6ed71b4f | 1713 | |
6264b550 RR |
1714 | if ( doMove || doResize ) |
1715 | { | |
79392158 SC |
1716 | // we don't adjust twice for the origin |
1717 | Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; | |
5ca0d812 | 1718 | bool vis = m_peer->IsVisible(); |
8b573fb8 | 1719 | |
d390fdcf SC |
1720 | int outerBorder = MacGetLeftBorderSize() ; |
1721 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
8b573fb8 | 1722 | outerBorder += 4 ; |
d390fdcf SC |
1723 | |
1724 | if ( vis && ( outerBorder > 0 ) ) | |
1725 | { | |
1726 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1727 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
8b573fb8 | 1728 | |
d390fdcf SC |
1729 | Rect rect ; |
1730 | ||
1731 | m_peer->GetRect( &rect ) ; | |
1732 | RectRgn( updateInner , &rect ) ; | |
1733 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1734 | RectRgn( updateOuter , &rect ) ; | |
1735 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
8b573fb8 | 1736 | wxPoint parent(0,0); |
c79aad8b SC |
1737 | #if TARGET_API_MAC_OSX |
1738 | // no offsetting needed when compositing | |
1739 | #else | |
d390fdcf SC |
1740 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; |
1741 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1742 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
c79aad8b | 1743 | #endif |
8b573fb8 VZ |
1744 | CopyRgn( updateOuter , updateTotal ) ; |
1745 | ||
d390fdcf SC |
1746 | rect = r ; |
1747 | RectRgn( updateInner , &rect ) ; | |
1748 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1749 | RectRgn( updateOuter , &rect ) ; | |
1750 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
7ebf5540 SC |
1751 | |
1752 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
8b573fb8 | 1753 | UnionRgn( updateOuter , updateTotal , updateTotal ) ; |
d390fdcf | 1754 | |
c79aad8b | 1755 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; |
d390fdcf SC |
1756 | DisposeRgn(updateOuter) ; |
1757 | DisposeRgn(updateInner) ; | |
1758 | DisposeRgn(updateTotal) ; | |
1759 | } | |
5ca0d812 | 1760 | |
b05bf6ee SC |
1761 | // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! |
1762 | if ( vis ) | |
5ca0d812 | 1763 | m_peer->SetVisibility( false , true ) ; |
d390fdcf | 1764 | |
8b573fb8 | 1765 | m_peer->SetRect( &r ) ; |
b05bf6ee | 1766 | if ( vis ) |
5ca0d812 SC |
1767 | m_peer->SetVisibility( true , true ) ; |
1768 | ||
6264b550 RR |
1769 | MacRepositionScrollBars() ; |
1770 | if ( doMove ) | |
1771 | { | |
facd6764 | 1772 | wxPoint point(actualX,actualY); |
6264b550 RR |
1773 | wxMoveEvent event(point, m_windowId); |
1774 | event.SetEventObject(this); | |
1775 | GetEventHandler()->ProcessEvent(event) ; | |
1776 | } | |
1777 | if ( doResize ) | |
1778 | { | |
e40298d5 | 1779 | MacRepositionScrollBars() ; |
facd6764 | 1780 | wxSize size(actualWidth, actualHeight); |
e40298d5 JS |
1781 | wxSizeEvent event(size, m_windowId); |
1782 | event.SetEventObject(this); | |
1783 | GetEventHandler()->ProcessEvent(event); | |
6264b550 RR |
1784 | } |
1785 | } | |
6ed71b4f | 1786 | |
954fc50b SC |
1787 | } |
1788 | ||
facd6764 SC |
1789 | wxSize wxWindowMac::DoGetBestSize() const |
1790 | { | |
eb69d46e SC |
1791 | if ( m_macIsUserPane || IsTopLevel() ) |
1792 | return wxWindowBase::DoGetBestSize() ; | |
8b573fb8 | 1793 | |
facd6764 | 1794 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
facd6764 | 1795 | int bestWidth, bestHeight ; |
5ca0d812 | 1796 | m_peer->GetBestRect( &bestsize ) ; |
facd6764 SC |
1797 | |
1798 | if ( EmptyRect( &bestsize ) ) | |
1799 | { | |
facd6764 SC |
1800 | bestsize.left = bestsize.top = 0 ; |
1801 | bestsize.right = 16 ; | |
1802 | bestsize.bottom = 16 ; | |
1803 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1804 | { | |
1805 | bestsize.bottom = 16 ; | |
1806 | } | |
e3e817d4 | 1807 | #if wxUSE_SPINBTN |
facd6764 SC |
1808 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) |
1809 | { | |
8b573fb8 | 1810 | bestsize.bottom = 24 ; |
facd6764 | 1811 | } |
e3e817d4 | 1812 | #endif // wxUSE_SPINBTN |
facd6764 SC |
1813 | else |
1814 | { | |
8b573fb8 | 1815 | // return wxWindowBase::DoGetBestSize() ; |
facd6764 SC |
1816 | } |
1817 | } | |
1818 | ||
1819 | bestWidth = bestsize.right - bestsize.left ; | |
1820 | bestHeight = bestsize.bottom - bestsize.top ; | |
1821 | if ( bestHeight < 10 ) | |
1822 | bestHeight = 13 ; | |
8b573fb8 | 1823 | |
facd6764 SC |
1824 | return wxSize(bestWidth, bestHeight); |
1825 | } | |
1826 | ||
1827 | ||
954fc50b SC |
1828 | // set the size of the window: if the dimensions are positive, just use them, |
1829 | // but if any of them is equal to -1, it means that we must find the value for | |
1830 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1831 | // which case -1 is a valid value for x and y) | |
1832 | // | |
1833 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1834 | // the width/height to best suit our contents, otherwise we reuse the current | |
1835 | // width/height | |
1836 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1837 | { | |
1838 | // get the current size and position... | |
1839 | int currentX, currentY; | |
1840 | GetPosition(¤tX, ¤tY); | |
6ed71b4f | 1841 | |
954fc50b SC |
1842 | int currentW,currentH; |
1843 | GetSize(¤tW, ¤tH); | |
6ed71b4f | 1844 | |
954fc50b SC |
1845 | // ... and don't do anything (avoiding flicker) if it's already ok |
1846 | if ( x == currentX && y == currentY && | |
769ac869 | 1847 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) |
954fc50b | 1848 | { |
facd6764 | 1849 | // TODO REMOVE |
6264b550 | 1850 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
1851 | return; |
1852 | } | |
6ed71b4f | 1853 | |
954fc50b SC |
1854 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
1855 | x = currentX; | |
1856 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1857 | y = currentY; | |
6ed71b4f | 1858 | |
954fc50b | 1859 | AdjustForParentClientOrigin(x, y, sizeFlags); |
6ed71b4f | 1860 | |
954fc50b SC |
1861 | wxSize size(-1, -1); |
1862 | if ( width == -1 ) | |
1863 | { | |
1864 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1865 | { | |
1866 | size = DoGetBestSize(); | |
1867 | width = size.x; | |
1868 | } | |
1869 | else | |
1870 | { | |
1871 | // just take the current one | |
1872 | width = currentW; | |
1873 | } | |
1874 | } | |
6ed71b4f | 1875 | |
954fc50b SC |
1876 | if ( height == -1 ) |
1877 | { | |
1878 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1879 | { | |
1880 | if ( size.x == -1 ) | |
1881 | { | |
1882 | size = DoGetBestSize(); | |
1883 | } | |
1884 | //else: already called DoGetBestSize() above | |
6ed71b4f | 1885 | |
954fc50b SC |
1886 | height = size.y; |
1887 | } | |
1888 | else | |
1889 | { | |
1890 | // just take the current one | |
1891 | height = currentH; | |
1892 | } | |
1893 | } | |
6ed71b4f | 1894 | |
954fc50b | 1895 | DoMoveWindow(x, y, width, height); |
6ed71b4f | 1896 | |
e9576ca5 | 1897 | } |
519cb848 | 1898 | |
e766c8a9 | 1899 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 1900 | { |
facd6764 SC |
1901 | RgnHandle rgn = NewRgn() ; |
1902 | Rect content ; | |
5ca0d812 | 1903 | m_peer->GetRegion( kControlContentMetaPart , rgn ) ; |
facd6764 SC |
1904 | GetRegionBounds( rgn , &content ) ; |
1905 | DisposeRgn( rgn ) ; | |
1906 | #if !TARGET_API_MAC_OSX | |
736fac3a SC |
1907 | // if the content rgn is empty / not supported |
1908 | // don't attempt to correct the coordinates to wxWindow relative ones | |
1909 | if (!::EmptyRect( &content ) ) | |
1910 | { | |
1911 | Rect structure ; | |
5ca0d812 | 1912 | m_peer->GetRect( &structure ) ; |
736fac3a SC |
1913 | OffsetRect( &content , -structure.left , -structure.top ) ; |
1914 | } | |
8b573fb8 | 1915 | #endif |
facd6764 SC |
1916 | |
1917 | return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); | |
1918 | } | |
1919 | ||
1920 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1921 | { | |
1922 | if ( clientheight != -1 || clientheight != -1 ) | |
1923 | { | |
1924 | int currentclientwidth , currentclientheight ; | |
1925 | int currentwidth , currentheight ; | |
1926 | ||
1927 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1928 | GetSize( ¤twidth , ¤theight ) ; | |
1929 | ||
1930 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
1931 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1932 | } | |
e9576ca5 SC |
1933 | } |
1934 | ||
d84afea9 | 1935 | void wxWindowMac::SetTitle(const wxString& title) |
e9576ca5 | 1936 | { |
facd6764 SC |
1937 | m_label = wxStripMenuCodes(title) ; |
1938 | ||
21fd5529 | 1939 | if ( m_peer && m_peer->Ok() ) |
facd6764 | 1940 | { |
5ca0d812 | 1941 | m_peer->SetTitle( m_label ) ; |
facd6764 SC |
1942 | } |
1943 | Refresh() ; | |
519cb848 SC |
1944 | } |
1945 | ||
d84afea9 | 1946 | wxString wxWindowMac::GetTitle() const |
519cb848 | 1947 | { |
ed60b502 | 1948 | return m_label ; |
519cb848 SC |
1949 | } |
1950 | ||
8ab50549 SC |
1951 | bool wxWindowMac::Show(bool show) |
1952 | { | |
542f604f | 1953 | bool former = MacIsReallyShown() ; |
8ab50549 SC |
1954 | if ( !wxWindowBase::Show(show) ) |
1955 | return FALSE; | |
8b573fb8 | 1956 | |
8ab50549 | 1957 | // TODO use visibilityChanged Carbon Event for OSX |
2c899c20 SC |
1958 | if ( m_peer ) |
1959 | { | |
2c899c20 | 1960 | m_peer->SetVisibility( show , true ) ; |
2c899c20 | 1961 | } |
542f604f SC |
1962 | if ( former != MacIsReallyShown() ) |
1963 | MacPropagateVisibilityChanged() ; | |
8ab50549 SC |
1964 | return TRUE; |
1965 | } | |
1966 | ||
1967 | bool wxWindowMac::Enable(bool enable) | |
1968 | { | |
21fd5529 | 1969 | wxASSERT( m_peer->Ok() ) ; |
542f604f | 1970 | bool former = MacIsReallyEnabled() ; |
8ab50549 SC |
1971 | if ( !wxWindowBase::Enable(enable) ) |
1972 | return FALSE; | |
1973 | ||
5ca0d812 | 1974 | m_peer->Enable( enable ) ; |
8ab50549 SC |
1975 | |
1976 | if ( former != MacIsReallyEnabled() ) | |
1977 | MacPropagateEnabledStateChanged() ; | |
1978 | return TRUE; | |
1979 | } | |
1980 | ||
8b573fb8 | 1981 | // |
8ab50549 SC |
1982 | // status change propagations (will be not necessary for OSX later ) |
1983 | // | |
1984 | ||
facd6764 SC |
1985 | void wxWindowMac::MacPropagateVisibilityChanged() |
1986 | { | |
73fe67bd | 1987 | #if !TARGET_API_MAC_OSX |
facd6764 | 1988 | MacVisibilityChanged() ; |
8b573fb8 | 1989 | |
71f2fb52 | 1990 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
facd6764 SC |
1991 | while ( node ) |
1992 | { | |
1993 | wxWindowMac *child = node->GetData(); | |
1994 | if ( child->IsShown() ) | |
1995 | child->MacPropagateVisibilityChanged( ) ; | |
1996 | node = node->GetNext(); | |
1997 | } | |
73fe67bd | 1998 | #endif |
facd6764 SC |
1999 | } |
2000 | ||
8ab50549 | 2001 | void wxWindowMac::MacPropagateEnabledStateChanged( ) |
e9576ca5 | 2002 | { |
73fe67bd | 2003 | #if !TARGET_API_MAC_OSX |
8ab50549 | 2004 | MacEnabledStateChanged() ; |
8b573fb8 | 2005 | |
71f2fb52 | 2006 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
8ab50549 SC |
2007 | while ( node ) |
2008 | { | |
2009 | wxWindowMac *child = node->GetData(); | |
2010 | if ( child->IsEnabled() ) | |
2011 | child->MacPropagateEnabledStateChanged() ; | |
2012 | node = node->GetNext(); | |
2013 | } | |
73fe67bd | 2014 | #endif |
8ab50549 SC |
2015 | } |
2016 | ||
2017 | void wxWindowMac::MacPropagateHiliteChanged( ) | |
2018 | { | |
73fe67bd | 2019 | #if !TARGET_API_MAC_OSX |
8ab50549 | 2020 | MacHiliteChanged() ; |
8b573fb8 | 2021 | |
71f2fb52 | 2022 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
8ab50549 SC |
2023 | while ( node ) |
2024 | { | |
2025 | wxWindowMac *child = node->GetData(); | |
2026 | // if ( child->IsEnabled() ) | |
2027 | child->MacPropagateHiliteChanged() ; | |
2028 | node = node->GetNext(); | |
2029 | } | |
73fe67bd | 2030 | #endif |
8ab50549 SC |
2031 | } |
2032 | ||
2033 | // | |
2034 | // status change notifications | |
8b573fb8 | 2035 | // |
8ab50549 | 2036 | |
8b573fb8 | 2037 | void wxWindowMac::MacVisibilityChanged() |
8ab50549 SC |
2038 | { |
2039 | } | |
2040 | ||
8b573fb8 | 2041 | void wxWindowMac::MacHiliteChanged() |
8ab50549 SC |
2042 | { |
2043 | } | |
2044 | ||
8b573fb8 | 2045 | void wxWindowMac::MacEnabledStateChanged() |
8ab50549 | 2046 | { |
facd6764 | 2047 | } |
e7549107 | 2048 | |
8ab50549 SC |
2049 | // |
2050 | // status queries on the inherited window's state | |
2051 | // | |
2052 | ||
8b573fb8 | 2053 | bool wxWindowMac::MacIsReallyShown() |
facd6764 SC |
2054 | { |
2055 | // only under OSX the visibility of the TLW is taken into account | |
66ffb23b SC |
2056 | if ( m_isBeingDeleted ) |
2057 | return false ; | |
2058 | ||
facd6764 | 2059 | #if TARGET_API_MAC_OSX |
aa522e33 SC |
2060 | if ( m_peer && m_peer->Ok() ) |
2061 | return m_peer->IsVisible(); | |
2062 | #endif | |
facd6764 SC |
2063 | wxWindow* win = this ; |
2064 | while( win->IsShown() ) | |
2065 | { | |
2066 | if ( win->IsTopLevel() ) | |
2067 | return true ; | |
8b573fb8 | 2068 | |
facd6764 SC |
2069 | win = win->GetParent() ; |
2070 | if ( win == NULL ) | |
2071 | return true ; | |
8b573fb8 | 2072 | |
facd6764 SC |
2073 | } ; |
2074 | return false ; | |
facd6764 | 2075 | } |
4241baae | 2076 | |
8b573fb8 | 2077 | bool wxWindowMac::MacIsReallyEnabled() |
facd6764 | 2078 | { |
5ca0d812 | 2079 | return m_peer->IsEnabled() ; |
facd6764 SC |
2080 | } |
2081 | ||
8b573fb8 | 2082 | bool wxWindowMac::MacIsReallyHilited() |
c809f3be | 2083 | { |
5ca0d812 | 2084 | return m_peer->IsActive(); |
c809f3be SC |
2085 | } |
2086 | ||
8b573fb8 | 2087 | void wxWindowMac::MacFlashInvalidAreas() |
002c9672 SC |
2088 | { |
2089 | #if TARGET_API_MAC_OSX | |
2090 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2091 | #endif | |
2092 | } | |
2093 | ||
8ab50549 SC |
2094 | // |
2095 | // | |
2096 | // | |
2097 | ||
e766c8a9 | 2098 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 2099 | { |
6264b550 RR |
2100 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2101 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
2102 | } |
2103 | ||
e766c8a9 | 2104 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 2105 | { |
6264b550 RR |
2106 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2107 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
2108 | } |
2109 | ||
e766c8a9 | 2110 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 2111 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 2112 | { |
e7549107 SC |
2113 | const wxFont *fontToUse = theFont; |
2114 | if ( !fontToUse ) | |
2115 | fontToUse = &m_font; | |
14c9cbdb | 2116 | |
e766c8a9 | 2117 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 2118 | long lx,ly,ld,le ; |
5fde6fcc | 2119 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 2120 | if ( externalLeading ) |
6264b550 | 2121 | *externalLeading = le ; |
2f1ae414 | 2122 | if ( descent ) |
6264b550 | 2123 | *descent = ld ; |
2f1ae414 | 2124 | if ( x ) |
6264b550 | 2125 | *x = lx ; |
2f1ae414 | 2126 | if ( y ) |
6264b550 | 2127 | *y = ly ; |
e9576ca5 SC |
2128 | } |
2129 | ||
0a67a93b | 2130 | /* |
14c9cbdb | 2131 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
1c310985 SC |
2132 | * we always intersect with the entire window, not only with the client area |
2133 | */ | |
14c9cbdb | 2134 | |
e766c8a9 | 2135 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 2136 | { |
065ab451 SC |
2137 | if ( m_peer == NULL ) |
2138 | return ; | |
8b573fb8 | 2139 | |
facd6764 | 2140 | #if TARGET_API_MAC_OSX |
1e8cde71 | 2141 | if ( rect == NULL ) |
8b573fb8 | 2142 | m_peer->SetNeedsDisplay( true ) ; |
1e8cde71 SC |
2143 | else |
2144 | { | |
2145 | RgnHandle update = NewRgn() ; | |
2146 | SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
84f6927e SC |
2147 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; |
2148 | wxPoint origin = GetClientAreaOrigin() ; | |
8b573fb8 | 2149 | OffsetRgn( update, origin.x , origin.y ) ; |
db7a550b SC |
2150 | // right now this is wx' window coordinates, as our native peer does not have borders, this is |
2151 | // inset | |
2152 | OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
8b573fb8 VZ |
2153 | m_peer->SetNeedsDisplay( true , update) ; |
2154 | DisposeRgn( update ) ; | |
1e8cde71 | 2155 | } |
facd6764 | 2156 | #else |
a9825a9b SC |
2157 | /* |
2158 | RgnHandle updateRgn = NewRgn() ; | |
2159 | if ( rect == NULL ) | |
2160 | { | |
2161 | CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ; | |
2162 | } | |
2163 | else | |
2164 | { | |
2165 | SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
8b573fb8 | 2166 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ; |
a9825a9b SC |
2167 | } |
2168 | InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; | |
2169 | DisposeRgn(updateRgn) ; | |
2170 | */ | |
5ca0d812 | 2171 | if ( m_peer->IsVisible()) |
facd6764 | 2172 | { |
5ca0d812 SC |
2173 | m_peer->SetVisibility( false , false ) ; |
2174 | m_peer->SetVisibility( true , true ) ; | |
facd6764 SC |
2175 | } |
2176 | /* | |
94abc21f | 2177 | if ( MacGetTopLevelWindow() == NULL ) |
9a456218 | 2178 | return ; |
14c9cbdb | 2179 | |
5ca0d812 | 2180 | if ( !m_peer->IsVisible()) |
8b573fb8 VZ |
2181 | return ; |
2182 | ||
c3a05e8a | 2183 | wxPoint client = GetClientAreaOrigin(); |
9a456218 RR |
2184 | int x1 = -client.x; |
2185 | int y1 = -client.y; | |
2186 | int x2 = m_width - client.x; | |
2187 | int y2 = m_height - client.y; | |
2188 | ||
2189 | if (IsKindOf( CLASSINFO(wxButton))) | |
2190 | { | |
2191 | // buttons have an "aura" | |
2192 | y1 -= 5; | |
2193 | x1 -= 5; | |
2194 | y2 += 5; | |
2195 | x2 += 5; | |
2196 | } | |
2197 | ||
2198 | Rect clientrect = { y1, x1, y2, x2 }; | |
14c9cbdb | 2199 | |
1c310985 | 2200 | if ( rect ) |
6264b550 | 2201 | { |
1c310985 | 2202 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; |
14c9cbdb | 2203 | SectRect( &clientrect , &r , &clientrect ) ; |
6264b550 | 2204 | } |
14c9cbdb | 2205 | |
1c310985 | 2206 | if ( !EmptyRect( &clientrect ) ) |
e9576ca5 | 2207 | { |
1c310985 | 2208 | int top = 0 , left = 0 ; |
14c9cbdb | 2209 | |
1c310985 SC |
2210 | MacClientToRootWindow( &left , &top ) ; |
2211 | OffsetRect( &clientrect , left , top ) ; | |
14c9cbdb | 2212 | |
1c310985 | 2213 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; |
e9576ca5 | 2214 | } |
facd6764 SC |
2215 | */ |
2216 | #endif | |
2217 | } | |
2218 | ||
79392158 SC |
2219 | void wxWindowMac::Freeze() |
2220 | { | |
2221 | #if TARGET_API_MAC_OSX | |
2222 | if ( !m_frozenness++ ) | |
2223 | { | |
52ef5c3c RD |
2224 | if ( m_peer && m_peer->Ok() ) |
2225 | m_peer->SetDrawingEnabled( false ) ; | |
79392158 SC |
2226 | } |
2227 | #endif | |
2228 | } | |
2229 | ||
b175b96b | 2230 | |
79392158 SC |
2231 | void wxWindowMac::Thaw() |
2232 | { | |
2233 | #if TARGET_API_MAC_OSX | |
2234 | wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); | |
2235 | ||
2236 | if ( !--m_frozenness ) | |
2237 | { | |
52ef5c3c RD |
2238 | if ( m_peer && m_peer->Ok() ) |
2239 | { | |
2240 | m_peer->SetDrawingEnabled( true ) ; | |
2241 | m_peer->InvalidateWithChildren() ; | |
2242 | } | |
79392158 SC |
2243 | } |
2244 | #endif | |
2245 | } | |
2246 | ||
e766c8a9 | 2247 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 2248 | { |
519cb848 | 2249 | // actually this is a windows-only concept |
e9576ca5 SC |
2250 | return NULL; |
2251 | } | |
2252 | ||
e9576ca5 | 2253 | // Coordinates relative to the window |
e766c8a9 | 2254 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 2255 | { |
e40298d5 | 2256 | // We really don't move the mouse programmatically under Mac. |
e9576ca5 SC |
2257 | } |
2258 | ||
facd6764 | 2259 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 2260 | { |
be346c26 | 2261 | #if TARGET_API_MAC_OSX |
facd6764 | 2262 | if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) |
94abc21f | 2263 | { |
facd6764 | 2264 | event.Skip() ; |
94abc21f SC |
2265 | } |
2266 | else | |
be346c26 | 2267 | #endif |
7ebf5540 | 2268 | { |
8b573fb8 | 2269 | event.GetDC()->Clear() ; |
7ebf5540 | 2270 | } |
1c310985 SC |
2271 | } |
2272 | ||
2273 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2274 | { | |
af6b7b80 | 2275 | event.Skip() ; |
e9576ca5 SC |
2276 | } |
2277 | ||
e766c8a9 | 2278 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 2279 | { |
1c310985 SC |
2280 | if ( orient == wxHORIZONTAL ) |
2281 | { | |
2282 | if ( m_hScrollBar ) | |
2283 | return m_hScrollBar->GetThumbPosition() ; | |
2284 | } | |
2285 | else | |
2286 | { | |
2287 | if ( m_vScrollBar ) | |
2288 | return m_vScrollBar->GetThumbPosition() ; | |
2289 | } | |
e9576ca5 SC |
2290 | return 0; |
2291 | } | |
2292 | ||
2293 | // This now returns the whole range, not just the number | |
2294 | // of positions that we can scroll. | |
e766c8a9 | 2295 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 2296 | { |
1c310985 SC |
2297 | if ( orient == wxHORIZONTAL ) |
2298 | { | |
2299 | if ( m_hScrollBar ) | |
2300 | return m_hScrollBar->GetRange() ; | |
2301 | } | |
2302 | else | |
2303 | { | |
2304 | if ( m_vScrollBar ) | |
2305 | return m_vScrollBar->GetRange() ; | |
2306 | } | |
e9576ca5 SC |
2307 | return 0; |
2308 | } | |
2309 | ||
e766c8a9 | 2310 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 2311 | { |
1c310985 SC |
2312 | if ( orient == wxHORIZONTAL ) |
2313 | { | |
2314 | if ( m_hScrollBar ) | |
2315 | return m_hScrollBar->GetThumbSize() ; | |
2316 | } | |
2317 | else | |
2318 | { | |
2319 | if ( m_vScrollBar ) | |
2320 | return m_vScrollBar->GetThumbSize() ; | |
2321 | } | |
e9576ca5 SC |
2322 | return 0; |
2323 | } | |
2324 | ||
e766c8a9 | 2325 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 2326 | { |
1c310985 | 2327 | if ( orient == wxHORIZONTAL ) |
6264b550 | 2328 | { |
1c310985 SC |
2329 | if ( m_hScrollBar ) |
2330 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
2331 | } |
2332 | else | |
2333 | { | |
1c310985 SC |
2334 | if ( m_vScrollBar ) |
2335 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 2336 | } |
2f1ae414 SC |
2337 | } |
2338 | ||
c79aad8b SC |
2339 | // |
2340 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
2341 | // our own window origin is at leftOrigin/rightOrigin | |
2342 | // | |
2343 | ||
2344 | void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) | |
2f1ae414 | 2345 | { |
1c310985 | 2346 | if( IsTopLevel() ) |
6264b550 | 2347 | return ; |
8b573fb8 | 2348 | |
fd926bcc | 2349 | Rect rect ; |
c79aad8b SC |
2350 | bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; |
2351 | bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
2352 | ||
8b573fb8 | 2353 | m_peer->GetRect( &rect ) ; |
fd926bcc SC |
2354 | InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; |
2355 | ||
c79aad8b SC |
2356 | #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
2357 | if ( HIThemeDrawFrame != 0) | |
2358 | { | |
2359 | Rect srect = rect ; | |
2360 | HIThemeFrameDrawInfo info ; | |
2361 | memset( &info, 0 , sizeof( info ) ) ; | |
2362 | ||
2363 | info.version = 0 ; | |
2364 | info.kind = 0 ; | |
2365 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2366 | info.isFocused = hasFocus ; | |
2367 | bool draw = false ; | |
2368 | ||
2369 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
2370 | wxASSERT( cgContext ) ; | |
2371 | ||
2372 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2373 | { | |
2374 | SInt32 border = 0 ; | |
2375 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2376 | InsetRect( &srect , border , border ); | |
2377 | info.kind = kHIThemeFrameTextFieldSquare ; | |
2378 | draw = true ; | |
2379 | } | |
2380 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2381 | { | |
2382 | SInt32 border = 0 ; | |
2383 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2384 | InsetRect( &srect , border , border ); | |
2385 | info.kind = kHIThemeFrameListBox ; | |
2386 | draw = true ; | |
2387 | } | |
2388 | ||
2389 | if ( draw ) | |
2390 | { | |
2391 | CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left , | |
2392 | srect.bottom - srect.top ) ; | |
2393 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2394 | } | |
2395 | else if ( hasFocus ) | |
2396 | { | |
2397 | srect = rect ; | |
2398 | CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left , | |
2399 | srect.bottom - srect.top ) ; | |
2400 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; | |
2401 | } | |
2402 | ||
2403 | m_peer->GetRect( &rect ) ; | |
2404 | if ( hasBothScrollbars ) | |
2405 | { | |
2406 | srect = rect ; | |
2407 | int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ; | |
2408 | CGRect cgrect = CGRectMake( srect.right - size , srect.bottom - size , size , size ) ; | |
2409 | CGPoint cgpoint = CGPointMake( srect.right - size , srect.bottom - size ) ; | |
2410 | HIThemeGrowBoxDrawInfo info ; | |
2411 | memset( &info, 0 , sizeof( info ) ) ; | |
2412 | info.version = 0 ; | |
2413 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2414 | info.kind = kHIThemeGrowBoxKindNone ; | |
2415 | info.size = kHIThemeGrowBoxSizeNormal ; | |
2416 | info.direction = kThemeGrowRight | kThemeGrowDown ; | |
2417 | HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2418 | } | |
2419 | } | |
2420 | else | |
2421 | #endif | |
fd926bcc SC |
2422 | { |
2423 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
2424 | if (top) | |
2425 | { | |
2426 | wxPoint pt(0,0) ; | |
2427 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
2428 | rect.left += pt.x ; | |
2429 | rect.right += pt.x ; | |
2430 | rect.top += pt.y ; | |
2431 | rect.bottom += pt.y ; | |
2432 | } | |
8b573fb8 | 2433 | |
c79aad8b SC |
2434 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
2435 | { | |
2436 | Rect srect = rect ; | |
2437 | SInt32 border = 0 ; | |
2438 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2439 | InsetRect( &srect , border , border ); | |
2440 | DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2441 | } | |
2442 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2443 | { | |
2444 | Rect srect = rect ; | |
2445 | SInt32 border = 0 ; | |
2446 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2447 | InsetRect( &srect , border , border ); | |
2448 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2449 | } | |
2450 | ||
2451 | if ( hasFocus ) | |
2452 | { | |
2453 | Rect srect = rect ; | |
2454 | DrawThemeFocusRect( &srect , true ) ; | |
2455 | } | |
2456 | if ( hasBothScrollbars ) | |
2457 | { | |
2458 | // GetThemeStandaloneGrowBoxBounds | |
2459 | //DrawThemeStandaloneNoGrowBox | |
2460 | } | |
eec462f8 | 2461 | } |
8208e181 SC |
2462 | } |
2463 | ||
abda5788 SC |
2464 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
2465 | { | |
2466 | if ( child == m_hScrollBar ) | |
2467 | m_hScrollBar = NULL ; | |
2468 | if ( child == m_vScrollBar ) | |
2469 | m_vScrollBar = NULL ; | |
14c9cbdb | 2470 | |
abda5788 SC |
2471 | wxWindowBase::RemoveChild( child ) ; |
2472 | } | |
2473 | ||
e9576ca5 | 2474 | // New function that will replace some of the above. |
e766c8a9 | 2475 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
2476 | int range, bool refresh) |
2477 | { | |
e40298d5 JS |
2478 | if ( orient == wxHORIZONTAL ) |
2479 | { | |
2480 | if ( m_hScrollBar ) | |
6264b550 | 2481 | { |
e40298d5 | 2482 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2483 | { |
e40298d5 JS |
2484 | if ( m_hScrollBar->IsShown() ) |
2485 | m_hScrollBar->Show(false) ; | |
2486 | } | |
2487 | else | |
2488 | { | |
2489 | if ( !m_hScrollBar->IsShown() ) | |
2490 | m_hScrollBar->Show(true) ; | |
6264b550 | 2491 | } |
11ca2edf | 2492 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2493 | } |
e40298d5 JS |
2494 | } |
2495 | else | |
2496 | { | |
2497 | if ( m_vScrollBar ) | |
6264b550 | 2498 | { |
e40298d5 | 2499 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2500 | { |
e40298d5 JS |
2501 | if ( m_vScrollBar->IsShown() ) |
2502 | m_vScrollBar->Show(false) ; | |
2503 | } | |
2504 | else | |
2505 | { | |
2506 | if ( !m_vScrollBar->IsShown() ) | |
2507 | m_vScrollBar->Show(true) ; | |
6264b550 | 2508 | } |
11ca2edf | 2509 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2510 | } |
e40298d5 JS |
2511 | } |
2512 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
2513 | } |
2514 | ||
2515 | // Does a physical scroll | |
e766c8a9 | 2516 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 2517 | { |
ba87f54c SC |
2518 | if( dx == 0 && dy ==0 ) |
2519 | return ; | |
8b573fb8 | 2520 | |
6ed71b4f | 2521 | |
6264b550 | 2522 | { |
adb8a71b | 2523 | |
6264b550 RR |
2524 | int width , height ; |
2525 | GetClientSize( &width , &height ) ; | |
adb8a71b | 2526 | #if TARGET_API_MAC_OSX |
002c9672 | 2527 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control |
8b573fb8 | 2528 | // area is scrolled, this does not occur if width and height are 2 pixels less, |
002c9672 | 2529 | // TODO write optimal workaround |
42ef83fa | 2530 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; |
8b573fb8 | 2531 | if ( rect ) |
adb8a71b | 2532 | { |
5ca0d812 | 2533 | scrollrect.Intersect( *rect ) ; |
adb8a71b | 2534 | } |
5ca0d812 | 2535 | if ( m_peer->GetNeedsDisplay() ) |
002c9672 SC |
2536 | { |
2537 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2538 | // either immediate redraw or full invalidate | |
2539 | #if 1 | |
2540 | // is the better overall solution, as it does not slow down scrolling | |
5ca0d812 | 2541 | m_peer->SetNeedsDisplay( true ) ; |
002c9672 | 2542 | #else |
8b573fb8 | 2543 | // this would be the preferred version for fast drawing controls |
002c9672 SC |
2544 | if( UMAGetSystemVersion() < 0x1030 ) |
2545 | Update() ; | |
2546 | else | |
42ef83fa | 2547 | HIViewRender(m_peer->GetControlRef()) ; |
002c9672 SC |
2548 | #endif |
2549 | } | |
84e5d27d SC |
2550 | // as the native control might be not a 0/0 wx window coordinates, we have to offset |
2551 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
5ca0d812 | 2552 | m_peer->ScrollRect( scrollrect , dx , dy ) ; |
adb8a71b | 2553 | #else |
6ed71b4f | 2554 | |
facd6764 | 2555 | wxPoint pos; |
8b573fb8 | 2556 | pos.x = pos.y = 0; |
430e1eed | 2557 | |
facd6764 | 2558 | Rect scrollrect; |
6264b550 | 2559 | RgnHandle updateRgn = NewRgn() ; |
430e1eed | 2560 | |
adb8a71b | 2561 | { |
430e1eed SC |
2562 | wxClientDC dc(this) ; |
2563 | wxMacPortSetter helper(&dc) ; | |
8b573fb8 | 2564 | |
5ca0d812 | 2565 | m_peer->GetRect( &scrollrect ) ; |
430e1eed SC |
2566 | scrollrect.top += MacGetTopBorderSize() ; |
2567 | scrollrect.left += MacGetLeftBorderSize() ; | |
2568 | scrollrect.bottom = scrollrect.top + height ; | |
2569 | scrollrect.right = scrollrect.left + width ; | |
8b573fb8 | 2570 | |
430e1eed SC |
2571 | if ( rect ) |
2572 | { | |
2573 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2574 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2575 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2576 | } | |
2577 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
20b69855 SC |
2578 | |
2579 | // now scroll the former update region as well and add the new update region | |
2580 | ||
2581 | WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ; | |
2582 | RgnHandle formerUpdateRgn = NewRgn() ; | |
2583 | RgnHandle scrollRgn = NewRgn() ; | |
2584 | RectRgn( scrollRgn , &scrollrect ) ; | |
2585 | GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; | |
2586 | Point pt = {0,0} ; | |
2587 | LocalToGlobal( &pt ) ; | |
2588 | OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; | |
2589 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2590 | if ( !EmptyRgn( formerUpdateRgn ) ) | |
2591 | { | |
2592 | MacOffsetRgn( formerUpdateRgn , dx , dy ) ; | |
2593 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2594 | InvalWindowRgn(rootWindow , formerUpdateRgn ) ; | |
2595 | } | |
2596 | InvalWindowRgn(rootWindow , updateRgn ) ; | |
2597 | DisposeRgn( updateRgn ) ; | |
2598 | DisposeRgn( formerUpdateRgn ) ; | |
2599 | DisposeRgn( scrollRgn ) ; | |
ba87f54c | 2600 | } |
facd6764 | 2601 | #endif |
6264b550 | 2602 | } |
6ed71b4f | 2603 | |
71f2fb52 | 2604 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 2605 | { |
9bd1404d | 2606 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
2607 | if (child == m_vScrollBar) continue; |
2608 | if (child == m_hScrollBar) continue; | |
2609 | if (child->IsTopLevel()) continue; | |
6ed71b4f | 2610 | |
6264b550 RR |
2611 | int x,y; |
2612 | child->GetPosition( &x, &y ); | |
2613 | int w,h; | |
2614 | child->GetSize( &w, &h ); | |
00f55394 SC |
2615 | if (rect) |
2616 | { | |
2617 | wxRect rc(x,y,w,h); | |
2618 | if (rect->Intersects(rc)) | |
2619 | child->SetSize( x+dx, y+dy, w, h ); | |
2620 | } | |
2621 | else | |
2622 | { | |
8b573fb8 VZ |
2623 | child->SetSize( x+dx, y+dy, w, h ); |
2624 | } | |
6264b550 | 2625 | } |
e9576ca5 SC |
2626 | } |
2627 | ||
e766c8a9 | 2628 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 2629 | { |
687706f5 | 2630 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) |
6264b550 RR |
2631 | { |
2632 | wxScrollWinEvent wevent; | |
2633 | wevent.SetPosition(event.GetPosition()); | |
2634 | wevent.SetOrientation(event.GetOrientation()); | |
687706f5 KH |
2635 | wevent.SetEventObject(this); |
2636 | ||
2637 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
2638 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
2639 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
2640 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
2641 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
2642 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
2643 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
2644 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
2645 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
2646 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
2647 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
2648 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
2649 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
2650 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
2651 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
2652 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
6ed71b4f VZ |
2653 | |
2654 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
2655 | } |
2656 | } | |
2657 | ||
e9576ca5 | 2658 | // Get the window with the focus |
0fe02759 | 2659 | wxWindowMac *wxWindowBase::DoFindFocus() |
e9576ca5 | 2660 | { |
f1d527c1 SC |
2661 | ControlRef control ; |
2662 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2663 | return wxFindControlFromMacControl( control ) ; | |
519cb848 SC |
2664 | } |
2665 | ||
e766c8a9 | 2666 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
2667 | { |
2668 | // panel wants to track the window which was the last to have focus in it, | |
2669 | // so we want to set ourselves as the window which last had focus | |
2670 | // | |
2671 | // notice that it's also important to do it upwards the tree becaus | |
2672 | // otherwise when the top level panel gets focus, it won't set it back to | |
2673 | // us, but to some other sibling | |
6ed71b4f | 2674 | |
c1fb8167 SC |
2675 | // CS:don't know if this is still needed: |
2676 | //wxChildFocusEvent eventFocus(this); | |
2677 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b | 2678 | |
5ca0d812 SC |
2679 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) |
2680 | { | |
ff3795ee | 2681 | #if !wxMAC_USE_CORE_GRAPHICS |
788e118f | 2682 | wxMacWindowStateSaver sv( this ) ; |
5ca0d812 SC |
2683 | |
2684 | int w , h ; | |
788e118f SC |
2685 | int x , y ; |
2686 | x = y = 0 ; | |
2687 | MacWindowToRootWindow( &x , &y ) ; | |
5ca0d812 | 2688 | GetSize( &w , &h ) ; |
788e118f | 2689 | Rect rect = {y , x , h + y , w + x } ; |
5ca0d812 SC |
2690 | |
2691 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
2692 | DrawThemeFocusRect( &rect , true ) ; | |
2693 | else | |
af6b7b80 | 2694 | { |
5ca0d812 | 2695 | DrawThemeFocusRect( &rect , false ) ; |
8b573fb8 | 2696 | |
af6b7b80 | 2697 | // as this erases part of the frame we have to redraw borders |
101634b2 SC |
2698 | // and because our z-ordering is not always correct (staticboxes) |
2699 | // we have to invalidate things, we cannot simple redraw | |
2700 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
2701 | RectRgn( updateInner , &rect ) ; | |
2702 | InsetRect( &rect , -4 , -4 ) ; | |
2703 | RectRgn( updateOuter , &rect ) ; | |
2704 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
8b573fb8 | 2705 | wxPoint parent(0,0); |
101634b2 SC |
2706 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; |
2707 | parent -= GetParent()->GetClientAreaOrigin() ; | |
2708 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
2709 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
2710 | DisposeRgn(updateOuter) ; | |
2711 | DisposeRgn(updateInner) ; | |
af6b7b80 | 2712 | } |
ff3795ee SC |
2713 | #else |
2714 | GetParent()->Refresh() ; | |
2715 | #endif | |
5ca0d812 SC |
2716 | } |
2717 | ||
7810c95b SC |
2718 | event.Skip(); |
2719 | } | |
2720 | ||
e39af974 | 2721 | void wxWindowMac::OnInternalIdle() |
e9576ca5 | 2722 | { |
e9576ca5 SC |
2723 | // This calls the UI-update mechanism (querying windows for |
2724 | // menu/toolbar/control state information) | |
e39af974 JS |
2725 | if (wxUpdateUIEvent::CanUpdate(this)) |
2726 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
e9576ca5 SC |
2727 | } |
2728 | ||
2729 | // Raise the window to the top of the Z order | |
e766c8a9 | 2730 | void wxWindowMac::Raise() |
e9576ca5 | 2731 | { |
5ca0d812 | 2732 | m_peer->SetZOrder( true , NULL ) ; |
e9576ca5 SC |
2733 | } |
2734 | ||
2735 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 2736 | void wxWindowMac::Lower() |
e9576ca5 | 2737 | { |
5ca0d812 | 2738 | m_peer->SetZOrder( false , NULL ) ; |
e9576ca5 SC |
2739 | } |
2740 | ||
6ed71b4f | 2741 | |
facd6764 | 2742 | // static wxWindow *gs_lastWhich = NULL; |
519cb848 | 2743 | |
7de59551 | 2744 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) |
467e3168 SC |
2745 | { |
2746 | // first trigger a set cursor event | |
6ed71b4f | 2747 | |
467e3168 SC |
2748 | wxPoint clientorigin = GetClientAreaOrigin() ; |
2749 | wxSize clientsize = GetClientSize() ; | |
2750 | wxCursor cursor ; | |
2751 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
7de59551 | 2752 | { |
467e3168 | 2753 | wxSetCursorEvent event( pt.x , pt.y ); |
6ed71b4f | 2754 | |
467e3168 SC |
2755 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); |
2756 | if ( processedEvtSetCursor && event.HasCursor() ) | |
2757 | { | |
e40298d5 | 2758 | cursor = event.GetCursor() ; |
467e3168 SC |
2759 | } |
2760 | else | |
2761 | { | |
6ed71b4f | 2762 | |
467e3168 SC |
2763 | // the test for processedEvtSetCursor is here to prevent using m_cursor |
2764 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
2765 | // it - this is a way to say that our cursor shouldn't be used for this | |
2766 | // point | |
2767 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
2768 | { | |
2769 | cursor = m_cursor ; | |
2770 | } | |
2771 | if ( wxIsBusy() ) | |
2772 | { | |
2773 | } | |
2774 | else | |
2775 | { | |
2776 | if ( !GetParent() ) | |
2777 | cursor = *wxSTANDARD_CURSOR ; | |
2778 | } | |
2779 | } | |
2780 | if ( cursor.Ok() ) | |
2781 | cursor.MacInstall() ; | |
2782 | } | |
2783 | return cursor.Ok() ; | |
2784 | } | |
2785 | ||
e766c8a9 | 2786 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 2787 | { |
6264b550 RR |
2788 | if ( m_tooltip ) |
2789 | { | |
2790 | return m_tooltip->GetTip() ; | |
2791 | } | |
427ff662 | 2792 | return wxEmptyString ; |
2f1ae414 | 2793 | } |
6264b550 | 2794 | |
cb4b0966 SC |
2795 | void wxWindowMac::ClearBackground() |
2796 | { | |
2797 | Refresh() ; | |
2798 | Update() ; | |
2799 | } | |
2800 | ||
1c310985 | 2801 | void wxWindowMac::Update() |
519cb848 | 2802 | { |
facd6764 | 2803 | #if TARGET_API_MAC_OSX |
957f865c | 2804 | |
430e1eed | 2805 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
957f865c RN |
2806 | WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ; |
2807 | ||
430e1eed SC |
2808 | // for composited windows this also triggers a redraw of all |
2809 | // invalid views in the window | |
2810 | if( UMAGetSystemVersion() >= 0x1030 ) | |
8b573fb8 VZ |
2811 | HIWindowFlush(window) ; |
2812 | else | |
430e1eed SC |
2813 | #endif |
2814 | { | |
2815 | // the only way to trigger the redrawing on earlier systems is to call | |
2816 | // ReceiveNextEvent | |
2817 | ||
2818 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
2819 | UInt32 currentEventClass = 0 ; | |
2820 | UInt32 currentEventKind = 0 ; | |
2821 | if ( currentEvent != NULL ) | |
2822 | { | |
2823 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
2824 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
8b573fb8 | 2825 | } |
430e1eed SC |
2826 | if ( currentEventClass != kEventClassMenu ) |
2827 | { | |
2828 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
2829 | ||
2830 | EventRef theEvent; | |
2831 | OSStatus status = noErr ; | |
2832 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
2833 | } | |
3e444781 | 2834 | else |
5ca0d812 | 2835 | m_peer->SetNeedsDisplay( true ) ; |
430e1eed | 2836 | } |
facd6764 | 2837 | #else |
5ca0d812 | 2838 | ::Draw1Control( m_peer->GetControlRef() ) ; |
bec721ec | 2839 | #endif |
519cb848 SC |
2840 | } |
2841 | ||
14c9cbdb | 2842 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const |
519cb848 | 2843 | { |
1c310985 | 2844 | wxTopLevelWindowMac* win = NULL ; |
facd6764 | 2845 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1c310985 | 2846 | if ( window ) |
6264b550 | 2847 | { |
1c310985 | 2848 | win = wxFindWinFromMacWindow( window ) ; |
14c9cbdb | 2849 | } |
1c310985 | 2850 | return win ; |
519cb848 | 2851 | } |
facd6764 | 2852 | wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) |
94abc21f | 2853 | { |
0fa8508d SC |
2854 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. |
2855 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
2856 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
2857 | // to add focus borders everywhere | |
8b573fb8 | 2858 | |
facd6764 | 2859 | Rect r ; |
e40298d5 JS |
2860 | RgnHandle visRgn = NewRgn() ; |
2861 | RgnHandle tempRgn = NewRgn() ; | |
66ffb23b | 2862 | if ( !m_isBeingDeleted && m_peer->IsVisible()) |
e40298d5 | 2863 | { |
5ca0d812 SC |
2864 | m_peer->GetRect( &r ) ; |
2865 | r.left -= MacGetLeftBorderSize() ; | |
2866 | r.top -= MacGetTopBorderSize() ; | |
2867 | r.bottom += MacGetBottomBorderSize() ; | |
2868 | r.right += MacGetRightBorderSize() ; | |
8b573fb8 | 2869 | |
facd6764 | 2870 | if (! MacGetTopLevelWindow()->MacUsesCompositing() ) |
21f9e953 | 2871 | { |
facd6764 SC |
2872 | MacRootWindowToWindow( &r.left , & r.top ) ; |
2873 | MacRootWindowToWindow( &r.right , & r.bottom ) ; | |
21f9e953 | 2874 | } |
facd6764 SC |
2875 | else |
2876 | { | |
2877 | r.right -= r.left ; | |
2878 | r.bottom -= r.top ; | |
2879 | r.left = 0 ; | |
2880 | r.top = 0 ; | |
2881 | } | |
2882 | if ( includeOuterStructures ) | |
af6b7b80 | 2883 | InsetRect( &r , -4 , -4 ) ; |
facd6764 | 2884 | RectRgn( visRgn , &r ) ; |
db7a550b | 2885 | |
21f9e953 | 2886 | if ( !IsTopLevel() ) |
94abc21f | 2887 | { |
facd6764 SC |
2888 | wxWindow* child = this ; |
2889 | wxWindow* parent = child->GetParent() ; | |
21f9e953 SC |
2890 | while( parent ) |
2891 | { | |
21f9e953 | 2892 | int x , y ; |
facd6764 | 2893 | wxSize size ; |
d3e780ec SC |
2894 | // we have to find a better clipping algorithm here, in order not to clip things |
2895 | // positioned like status and toolbar | |
2896 | if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ ) | |
facd6764 SC |
2897 | { |
2898 | size = parent->GetSize() ; | |
2899 | x = y = 0 ; | |
2900 | } | |
2901 | else | |
2902 | { | |
2903 | size = parent->GetClientSize() ; | |
2904 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
2905 | x = origin.x ; | |
2906 | y = origin.y ; | |
2907 | } | |
21f9e953 SC |
2908 | parent->MacWindowToRootWindow( &x, &y ) ; |
2909 | MacRootWindowToWindow( &x , &y ) ; | |
2910 | ||
0fa8508d | 2911 | if ( !includeOuterStructures || ( |
7f17ac74 SC |
2912 | parent->MacClipChildren() || |
2913 | ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) | |
0fa8508d SC |
2914 | ) ) |
2915 | { | |
2916 | SetRectRgn( tempRgn , | |
2917 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
2918 | x + size.x - parent->MacGetRightBorderSize(), | |
2919 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
21f9e953 | 2920 | |
0fa8508d SC |
2921 | SectRgn( visRgn , tempRgn , visRgn ) ; |
2922 | } | |
21f9e953 SC |
2923 | if ( parent->IsTopLevel() ) |
2924 | break ; | |
facd6764 SC |
2925 | child = parent ; |
2926 | parent = child->GetParent() ; | |
7372fd0a | 2927 | } |
94abc21f | 2928 | } |
e40298d5 | 2929 | } |
facd6764 SC |
2930 | |
2931 | wxRegion vis = visRgn ; | |
e40298d5 JS |
2932 | DisposeRgn( visRgn ) ; |
2933 | DisposeRgn( tempRgn ) ; | |
facd6764 | 2934 | return vis ; |
94abc21f SC |
2935 | } |
2936 | ||
facd6764 SC |
2937 | /* |
2938 | This function must not change the updatergn ! | |
2939 | */ | |
8b573fb8 | 2940 | bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) |
519cb848 | 2941 | { |
76a5e5d2 | 2942 | RgnHandle updatergn = (RgnHandle) updatergnr ; |
facd6764 | 2943 | bool handled = false ; |
42ef83fa SC |
2944 | Rect updatebounds ; |
2945 | GetRegionBounds( updatergn , &updatebounds ) ; | |
20b69855 | 2946 | |
c79aad8b SC |
2947 | // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ; |
2948 | ||
2949 | if ( !EmptyRgn(updatergn) ) | |
6264b550 | 2950 | { |
1c310985 SC |
2951 | RgnHandle newupdate = NewRgn() ; |
2952 | wxSize point = GetClientSize() ; | |
2953 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 | 2954 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; |
facd6764 | 2955 | SectRgn( newupdate , updatergn , newupdate ) ; |
8b573fb8 | 2956 | |
eec462f8 SC |
2957 | // first send an erase event to the entire update area |
2958 | { | |
c79aad8b SC |
2959 | // for the toplevel window this really is the entire area |
2960 | // for all the others only their client area, otherwise they | |
2961 | // might be drawing with full alpha and eg put blue into | |
2962 | // the grow-box area of a scrolled window (scroll sample) | |
2963 | wxDC* dc ; | |
2964 | if ( IsTopLevel() ) | |
2965 | dc = new wxWindowDC(this); | |
2966 | else | |
2967 | dc = new wxClientDC(this); | |
2968 | dc->SetClippingRegion(wxRegion(updatergn)); | |
2969 | wxEraseEvent eevent( GetId(), dc ); | |
42ef83fa SC |
2970 | eevent.SetEventObject( this ); |
2971 | GetEventHandler()->ProcessEvent( eevent ); | |
c79aad8b | 2972 | delete dc ; |
eec462f8 | 2973 | } |
8b573fb8 | 2974 | |
42ef83fa | 2975 | // calculate a client-origin version of the update rgn and set m_updateRegion to that |
1c310985 SC |
2976 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; |
2977 | m_updateRegion = newupdate ; | |
8b573fb8 | 2978 | DisposeRgn( newupdate ) ; |
6ed71b4f | 2979 | |
1c310985 | 2980 | if ( !m_updateRegion.Empty() ) |
6264b550 | 2981 | { |
facd6764 | 2982 | // paint the window itself |
ff3795ee | 2983 | |
e40298d5 | 2984 | wxPaintEvent event; |
687706f5 | 2985 | event.SetTimestamp(time); |
e40298d5 | 2986 | event.SetEventObject(this); |
ff3795ee SC |
2987 | GetEventHandler()->ProcessEvent(event); |
2988 | handled = true ; | |
eec462f8 | 2989 | } |
8b573fb8 | 2990 | |
eec462f8 SC |
2991 | // now we cannot rely on having its borders drawn by a window itself, as it does not |
2992 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
2993 | // this would also be the place to draw any custom backgrounds for native controls | |
2994 | // in Composited windowing | |
36d7f54e | 2995 | wxPoint clientOrigin = GetClientAreaOrigin() ; |
8b573fb8 | 2996 | |
71f2fb52 | 2997 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
eec462f8 SC |
2998 | { |
2999 | wxWindowMac *child = node->GetData(); | |
3000 | if (child == m_vScrollBar) continue; | |
3001 | if (child == m_hScrollBar) continue; | |
3002 | if (child->IsTopLevel()) continue; | |
3003 | if (!child->IsShown()) continue; | |
fe779e40 | 3004 | |
c79aad8b SC |
3005 | // only draw those in the update region (add a safety margin of 10 pixels for shadow effects |
3006 | ||
af6b7b80 SC |
3007 | int x,y; |
3008 | child->GetPosition( &x, &y ); | |
3009 | int w,h; | |
3010 | child->GetSize( &w, &h ); | |
3011 | Rect childRect = { y , x , y + h , x + w } ; | |
36d7f54e | 3012 | OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; |
c79aad8b SC |
3013 | InsetRect( &childRect , -10 , -10) ; |
3014 | ||
3015 | if ( RectInRgn( &childRect , updatergn ) ) | |
eec462f8 | 3016 | { |
c79aad8b SC |
3017 | |
3018 | // paint custom borders | |
3019 | wxNcPaintEvent eventNc( child->GetId() ); | |
3020 | eventNc.SetEventObject( child ); | |
3021 | if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) | |
eec462f8 | 3022 | { |
c79aad8b SC |
3023 | #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
3024 | if ( HIThemeDrawFrame != 0) | |
cb4b0966 | 3025 | { |
c79aad8b | 3026 | child->MacPaintBorders(0,0) ; |
cb4b0966 | 3027 | } |
c79aad8b | 3028 | else |
cb4b0966 | 3029 | #endif |
af6b7b80 SC |
3030 | { |
3031 | wxWindowDC dc(this) ; | |
3032 | dc.SetClippingRegion(wxRegion(updatergn)); | |
3033 | wxMacPortSetter helper(&dc) ; | |
c79aad8b | 3034 | child->MacPaintBorders(0,0) ; |
c79aad8b | 3035 | } |
eec462f8 | 3036 | } |
8b573fb8 | 3037 | } |
14c9cbdb | 3038 | } |
6264b550 | 3039 | } |
facd6764 SC |
3040 | return handled ; |
3041 | } | |
6ed71b4f | 3042 | |
519cb848 | 3043 | |
facd6764 | 3044 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const |
519cb848 | 3045 | { |
6264b550 | 3046 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 3047 | |
6264b550 RR |
3048 | while( iter ) |
3049 | { | |
1c310985 SC |
3050 | if ( iter->IsTopLevel() ) |
3051 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
519cb848 | 3052 | |
6264b550 | 3053 | iter = iter->GetParent() ; |
14c9cbdb | 3054 | } |
427ff662 | 3055 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; |
6264b550 | 3056 | return NULL ; |
519cb848 SC |
3057 | } |
3058 | ||
14c9cbdb | 3059 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 3060 | { |
427ff662 | 3061 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; |
14c9cbdb | 3062 | |
aa99e0cd SC |
3063 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) |
3064 | { | |
3065 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
db7a550b | 3066 | int scrlsize = MAC_SCROLLBAR_SIZE ; |
8b573fb8 VZ |
3067 | wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ; |
3068 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
3069 | { | |
3070 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
3071 | variant = wxWINDOW_VARIANT_SMALL ; | |
3072 | } | |
db7a550b SC |
3073 | |
3074 | int adjust = hasBoth ? scrlsize - 1: 0 ; | |
aa99e0cd SC |
3075 | int width, height ; |
3076 | GetClientSize( &width , &height ) ; | |
3077 | ||
db7a550b SC |
3078 | wxPoint vPoint(width-scrlsize, 0) ; |
3079 | wxSize vSize(scrlsize, height - adjust) ; | |
3080 | wxPoint hPoint(0 , height-scrlsize ) ; | |
3081 | wxSize hSize( width - adjust, scrlsize) ; | |
aa99e0cd SC |
3082 | |
3083 | ||
3084 | if ( style & wxVSCROLL ) | |
3085 | { | |
375bb200 | 3086 | m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint, |
aa99e0cd SC |
3087 | vSize , wxVERTICAL); |
3088 | } | |
3089 | ||
3090 | if ( style & wxHSCROLL ) | |
3091 | { | |
375bb200 | 3092 | m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint, |
aa99e0cd SC |
3093 | hSize , wxHORIZONTAL); |
3094 | } | |
3095 | } | |
aa99e0cd | 3096 | |
14c9cbdb | 3097 | |
6264b550 RR |
3098 | // because the create does not take into account the client area origin |
3099 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
3100 | } |
3101 | ||
e766c8a9 | 3102 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 3103 | { |
aa99e0cd SC |
3104 | if ( !m_hScrollBar && !m_vScrollBar ) |
3105 | return ; | |
8b573fb8 | 3106 | |
6264b550 | 3107 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
db7a550b SC |
3108 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; |
3109 | int adjust = hasBoth ? scrlsize - 1 : 0 ; | |
14c9cbdb | 3110 | |
6264b550 | 3111 | // get real client area |
14c9cbdb | 3112 | |
facd6764 SC |
3113 | int width ; |
3114 | int height ; | |
3115 | GetSize( &width , &height ) ; | |
6264b550 RR |
3116 | |
3117 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
3118 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
14c9cbdb | 3119 | |
6264b550 RR |
3120 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; |
3121 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
3122 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
3123 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
db7a550b | 3124 | /* |
14c9cbdb | 3125 | int x = 0 ; |
6264b550 | 3126 | int y = 0 ; |
facd6764 SC |
3127 | int w ; |
3128 | int h ; | |
3129 | GetSize( &w , &h ) ; | |
14c9cbdb | 3130 | |
6264b550 RR |
3131 | MacClientToRootWindow( &x , &y ) ; |
3132 | MacClientToRootWindow( &w , &h ) ; | |
14c9cbdb | 3133 | |
6264b550 | 3134 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 3135 | |
6264b550 RR |
3136 | int totW = 10000 , totH = 10000; |
3137 | while( iter ) | |
3138 | { | |
1c310985 | 3139 | if ( iter->IsTopLevel() ) |
6264b550 | 3140 | { |
facd6764 | 3141 | iter->GetSize( &totW , &totH ) ; |
6264b550 RR |
3142 | break ; |
3143 | } | |
3144 | ||
3145 | iter = iter->GetParent() ; | |
14c9cbdb RD |
3146 | } |
3147 | ||
6264b550 RR |
3148 | if ( x == 0 ) |
3149 | { | |
3150 | hPoint.x = -1 ; | |
3151 | hSize.x += 1 ; | |
3152 | } | |
3153 | if ( y == 0 ) | |
3154 | { | |
3155 | vPoint.y = -1 ; | |
3156 | vSize.y += 1 ; | |
3157 | } | |
14c9cbdb | 3158 | |
6264b550 RR |
3159 | if ( w-x >= totW ) |
3160 | { | |
3161 | hSize.x += 1 ; | |
3162 | vPoint.x += 1 ; | |
3163 | } | |
14c9cbdb | 3164 | |
6264b550 RR |
3165 | if ( h-y >= totH ) |
3166 | { | |
3167 | vSize.y += 1 ; | |
3168 | hPoint.y += 1 ; | |
3169 | } | |
db7a550b | 3170 | */ |
6264b550 RR |
3171 | if ( m_vScrollBar ) |
3172 | { | |
3173 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
3174 | } | |
3175 | if ( m_hScrollBar ) | |
3176 | { | |
3177 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
3178 | } | |
519cb848 SC |
3179 | } |
3180 | ||
e766c8a9 | 3181 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
3182 | { |
3183 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
3184 | } | |
519cb848 | 3185 | |
14c9cbdb | 3186 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 3187 | { |
6264b550 | 3188 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 3189 | |
71f2fb52 | 3190 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
6264b550 RR |
3191 | while ( node ) |
3192 | { | |
9bd1404d | 3193 | wxWindowMac *child = node->GetData(); |
6264b550 | 3194 | child->MacSuperChangedPosition() ; |
eb22f2a6 | 3195 | node = node->GetNext(); |
6264b550 | 3196 | } |
519cb848 | 3197 | } |
519cb848 | 3198 | |
14c9cbdb | 3199 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
a3bf4a62 | 3200 | { |
6264b550 | 3201 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 3202 | |
71f2fb52 | 3203 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
6264b550 RR |
3204 | while ( node ) |
3205 | { | |
9bd1404d | 3206 | wxWindowMac *child = node->GetData(); |
6264b550 | 3207 | child->MacTopLevelWindowChangedPosition() ; |
eb22f2a6 | 3208 | node = node->GetNext(); |
6264b550 | 3209 | } |
a3bf4a62 | 3210 | } |
facd6764 | 3211 | |
e766c8a9 | 3212 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 3213 | { |
1c310985 | 3214 | if( IsTopLevel() ) |
6264b550 | 3215 | return 0 ; |
2f1ae414 SC |
3216 | |
3217 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
3218 | { | |
ed60b502 | 3219 | SInt32 border = 3 ; |
ed60b502 | 3220 | return border ; |
2f1ae414 SC |
3221 | } |
3222 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
3223 | { | |
ed60b502 | 3224 | SInt32 border = 3 ; |
ed60b502 | 3225 | return border ; |
2f1ae414 SC |
3226 | } |
3227 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
3228 | { | |
6264b550 | 3229 | return 1 ; |
2f1ae414 | 3230 | } |
6264b550 | 3231 | return 0 ; |
2f1ae414 SC |
3232 | } |
3233 | ||
e766c8a9 | 3234 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 3235 | { |
1c310985 SC |
3236 | // they are all symmetric in mac themes |
3237 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3238 | } |
3239 | ||
e766c8a9 | 3240 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 3241 | { |
1c310985 SC |
3242 | // they are all symmetric in mac themes |
3243 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3244 | } |
3245 | ||
e766c8a9 | 3246 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 3247 | { |
1c310985 SC |
3248 | // they are all symmetric in mac themes |
3249 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3250 | } |
3251 | ||
14c9cbdb | 3252 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 3253 | { |
055a486b | 3254 | return style & ~wxBORDER_MASK ; |
2f1ae414 | 3255 | } |
0a67a93b | 3256 | |
e766c8a9 | 3257 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 3258 | // position. |
e766c8a9 | 3259 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 3260 | { |
59a12e90 | 3261 | pt = wxGetMousePosition(); |
e766c8a9 | 3262 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 3263 | return found; |
3723b7b1 JS |
3264 | } |
3265 | ||
3266 | // Get the current mouse position. | |
3267 | wxPoint wxGetMousePosition() | |
3268 | { | |
57591e0e JS |
3269 | int x, y; |
3270 | wxGetMousePosition(& x, & y); | |
3271 | return wxPoint(x, y); | |
3723b7b1 JS |
3272 | } |
3273 | ||
6ed71b4f | 3274 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) |
8950f7cc | 3275 | { |
8b573fb8 VZ |
3276 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) |
3277 | { | |
3278 | // copied from wxGTK : CS | |
249aad30 | 3279 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN |
8950f7cc SC |
3280 | // except that: |
3281 | // | |
3282 | // (a) it's a command event and so is propagated to the parent | |
3283 | // (b) under MSW it can be generated from kbd too | |
3284 | // (c) it uses screen coords (because of (a)) | |
3285 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
3286 | this->GetId(), | |
3287 | this->ClientToScreen(event.GetPosition())); | |
249aad30 SC |
3288 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) |
3289 | event.Skip() ; | |
8b573fb8 | 3290 | } |
facd6764 SC |
3291 | else |
3292 | { | |
8b573fb8 | 3293 | event.Skip() ; |
facd6764 | 3294 | } |
8950f7cc SC |
3295 | } |
3296 | ||
ff3795ee SC |
3297 | void wxWindowMac::OnPaint( wxPaintEvent & event ) |
3298 | { | |
c79aad8b | 3299 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) |
ff3795ee | 3300 | { |
c79aad8b | 3301 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; |
ff3795ee SC |
3302 | } |
3303 | } | |
3304 | ||
8b573fb8 | 3305 | void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) |
facd6764 | 3306 | { |
facd6764 SC |
3307 | } |
3308 | ||
8b573fb8 | 3309 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) |
3083eb85 SC |
3310 | { |
3311 | int x ,y , w ,h ; | |
8b573fb8 | 3312 | |
79392158 | 3313 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ; |
3083eb85 SC |
3314 | Rect bounds = { y , x , y+h , x+w }; |
3315 | return bounds ; | |
3316 | } | |
3317 | ||
8b573fb8 | 3318 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
f1d527c1 SC |
3319 | { |
3320 | return eventNotHandledErr ; | |
3321 | } | |
3322 | ||
facd6764 | 3323 |