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