]>
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 | ||
fc0daf84 | 79 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) |
facd6764 SC |
80 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) |
81 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
ff3795ee SC |
82 | #if TARGET_API_MAC_OSX |
83 | EVT_PAINT(wxWindowMac::OnPaint) | |
84 | #endif | |
5ca0d812 SC |
85 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) |
86 | EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) | |
facd6764 | 87 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) |
e9576ca5 SC |
88 | END_EVENT_TABLE() |
89 | ||
94abc21f SC |
90 | #define wxMAC_DEBUG_REDRAW 0 |
91 | #ifndef wxMAC_DEBUG_REDRAW | |
92 | #define wxMAC_DEBUG_REDRAW 0 | |
93 | #endif | |
94 | ||
5ca0d812 | 95 | #define wxMAC_USE_THEME_BORDER 1 |
e9576ca5 | 96 | |
42ef83fa SC |
97 | // --------------------------------------------------------------------------- |
98 | // Utility Routines to move between different coordinate systems | |
99 | // --------------------------------------------------------------------------- | |
100 | ||
101 | /* | |
102 | * Right now we have the following setup : | |
103 | * a border that is not part of the native control is always outside the | |
104 | * control's border (otherwise we loose all native intelligence, future ways | |
105 | * may be to have a second embedding control responsible for drawing borders | |
106 | * and backgrounds eventually) | |
107 | * so all this border calculations have to be taken into account when calling | |
108 | * native methods or getting native oriented data | |
109 | * so we have three coordinate systems here | |
110 | * wx client coordinates | |
111 | * wx window coordinates (including window frames) | |
112 | * native coordinates | |
113 | */ | |
8b573fb8 | 114 | |
42ef83fa SC |
115 | // |
116 | // originating from native control | |
117 | // | |
118 | ||
119 | ||
120 | void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle ) | |
121 | { | |
8b573fb8 | 122 | OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
123 | } |
124 | ||
125 | void wxMacNativeToWindow( const wxWindow* window , Rect *rect ) | |
126 | { | |
8b573fb8 | 127 | OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
128 | } |
129 | ||
130 | // | |
131 | // directed towards native control | |
132 | // | |
133 | ||
134 | void wxMacWindowToNative( const wxWindow* window , RgnHandle handle ) | |
135 | { | |
8b573fb8 | 136 | OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); |
42ef83fa SC |
137 | } |
138 | ||
139 | void wxMacWindowToNative( const wxWindow* window , Rect *rect ) | |
140 | { | |
8b573fb8 | 141 | OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ; |
42ef83fa SC |
142 | } |
143 | ||
144 | ||
facd6764 SC |
145 | // --------------------------------------------------------------------------- |
146 | // Carbon Events | |
147 | // --------------------------------------------------------------------------- | |
8b573fb8 | 148 | |
facd6764 SC |
149 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
150 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ; | |
151 | ||
f1d527c1 SC |
152 | #if TARGET_API_MAC_OSX |
153 | ||
8b573fb8 | 154 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 |
c2697b87 SC |
155 | enum { |
156 | kEventControlVisibilityChanged = 157 | |
157 | }; | |
158 | #endif | |
159 | ||
f1d527c1 SC |
160 | #endif |
161 | ||
facd6764 SC |
162 | static const EventTypeSpec eventList[] = |
163 | { | |
f1d527c1 | 164 | { kEventClassControl , kEventControlHit } , |
facd6764 | 165 | #if TARGET_API_MAC_OSX |
73fe67bd SC |
166 | { kEventClassControl , kEventControlDraw } , |
167 | { kEventClassControl , kEventControlVisibilityChanged } , | |
168 | { kEventClassControl , kEventControlEnabledStateChanged } , | |
169 | { kEventClassControl , kEventControlHiliteChanged } , | |
f1d527c1 | 170 | { kEventClassControl , kEventControlSetFocusPart } , |
8b573fb8 VZ |
171 | |
172 | { kEventClassService , kEventServiceGetTypes }, | |
173 | { kEventClassService , kEventServiceCopy }, | |
174 | { kEventClassService , kEventServicePaste }, | |
175 | ||
176 | // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only | |
facd6764 | 177 | // { kEventClassControl , kEventControlBoundsChanged } , |
facd6764 SC |
178 | #endif |
179 | } ; | |
180 | ||
181 | static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
182 | { | |
183 | OSStatus result = eventNotHandledErr ; | |
184 | ||
185 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 186 | |
facd6764 SC |
187 | ControlRef controlRef ; |
188 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
189 | ||
190 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
191 | ||
192 | switch( GetEventKind( event ) ) | |
193 | { | |
f1d527c1 | 194 | #if TARGET_API_MAC_OSX |
facd6764 SC |
195 | case kEventControlDraw : |
196 | { | |
1e8cde71 | 197 | RgnHandle updateRgn = NULL ; |
055a486b | 198 | RgnHandle allocatedRgn = NULL ; |
1e8cde71 | 199 | wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; |
e6616741 SC |
200 | Rect controlBounds ; |
201 | if ( thisWindow->GetPeer()->IsCompositing() == false ) | |
202 | { | |
203 | if ( thisWindow->GetPeer()->IsRootControl() == false ) | |
204 | { | |
205 | GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ; | |
206 | } | |
207 | else | |
208 | { | |
209 | thisWindow->GetPeer()->GetRect( &controlBounds ) ; | |
210 | } | |
211 | } | |
212 | ||
76c7012c | 213 | if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr ) |
1e8cde71 SC |
214 | { |
215 | updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; | |
216 | } | |
055a486b SC |
217 | else |
218 | { | |
e6616741 | 219 | if ( thisWindow->GetPeer()->IsCompositing() == false ) |
055a486b | 220 | { |
5c840e5b | 221 | /* |
e6616741 SC |
222 | if ( thisWindow->GetPeer()->IsRootControl() == false ) |
223 | { | |
224 | GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ; | |
225 | } | |
226 | else | |
227 | { | |
228 | thisWindow->GetPeer()->GetRect( &controlBounds ) ; | |
229 | } | |
5c840e5b | 230 | */ |
055a486b SC |
231 | allocatedRgn = NewRgn() ; |
232 | CopyRgn( updateRgn , allocatedRgn ) ; | |
e6616741 | 233 | OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ; |
42ef83fa SC |
234 | // hide the given region by the new region that must be shifted |
235 | wxMacNativeToWindow( thisWindow , allocatedRgn ) ; | |
e6616741 SC |
236 | updateRgn = allocatedRgn ; |
237 | } | |
238 | else | |
239 | { | |
240 | if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) | |
241 | { | |
242 | // as this update region is in native window locals we must adapt it to wx window local | |
243 | allocatedRgn = NewRgn() ; | |
244 | CopyRgn( updateRgn , allocatedRgn ) ; | |
245 | // hide the given region by the new region that must be shifted | |
246 | wxMacNativeToWindow( thisWindow , allocatedRgn ) ; | |
247 | updateRgn = allocatedRgn ; | |
248 | } | |
055a486b SC |
249 | } |
250 | } | |
e6616741 SC |
251 | Rect rgnBounds ; |
252 | GetRegionBounds( updateRgn , &rgnBounds ) ; | |
1f1c8bd4 | 253 | #if wxMAC_DEBUG_REDRAW |
facd6764 SC |
254 | if ( thisWindow->MacIsUserPane() ) |
255 | { | |
20b69855 | 256 | CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; |
bcbd6987 SC |
257 | static float color = 0.5 ; |
258 | static channel = 0 ; | |
8b573fb8 VZ |
259 | HIRect bounds; |
260 | HIViewGetBounds( controlRef, &bounds ); | |
261 | CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 , | |
262 | channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 ); | |
263 | CGContextFillRect( cgContext, bounds ); | |
264 | color += 0.1 ; | |
265 | if ( color > 0.9 ) | |
266 | { | |
267 | color = 0.5 ; | |
268 | channel++ ; | |
269 | if ( channel == 3 ) | |
270 | channel = 0 ; | |
271 | } | |
facd6764 | 272 | } |
20b69855 | 273 | #endif |
c79aad8b | 274 | { |
20b69855 | 275 | #if wxMAC_USE_CORE_GRAPHICS |
e6616741 SC |
276 | bool created = false ; |
277 | CGContextRef cgContext = 0 ; | |
278 | if ( cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) != noErr ) | |
279 | { | |
280 | wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ; | |
281 | ||
282 | // this parameter is not provided on non-composited windows | |
283 | created = true ; | |
284 | // rest of the code expects this to be already transformed and clipped for local | |
285 | CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ; | |
286 | Rect bounds ; | |
287 | GetPortBounds( port , &bounds ) ; | |
288 | CreateCGContextForPort( port , &cgContext ) ; | |
289 | ||
290 | wxMacWindowToNative( thisWindow , updateRgn ) ; | |
291 | OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ; | |
292 | ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ; | |
293 | wxMacNativeToWindow( thisWindow , updateRgn ) ; | |
294 | OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ; | |
295 | ||
296 | CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; | |
297 | CGContextScaleCTM( cgContext , 1 , -1 ) ; | |
298 | ||
299 | CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ; | |
300 | ||
301 | /* | |
302 | CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ; | |
303 | CGContextFillRect(cgContext , CGRectMake( 0 , 0 , | |
304 | controlBounds.right - controlBounds.left , | |
305 | controlBounds.bottom - controlBounds.top ) ); | |
306 | */ | |
307 | ||
308 | } | |
c79aad8b | 309 | thisWindow->MacSetCGContextRef( cgContext ) ; |
e6616741 SC |
310 | { |
311 | wxMacCGContextStateSaver sg( cgContext ) ; | |
facd6764 | 312 | #endif |
e6616741 SC |
313 | if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) |
314 | result = noErr ; | |
20b69855 | 315 | #if wxMAC_USE_CORE_GRAPHICS |
e6616741 SC |
316 | thisWindow->MacSetCGContextRef( NULL ) ; |
317 | } | |
318 | if ( created ) | |
319 | { | |
320 | CGContextRelease( cgContext ) ; | |
321 | } | |
20b69855 | 322 | #endif |
c79aad8b | 323 | } |
055a486b SC |
324 | if ( allocatedRgn ) |
325 | DisposeRgn( allocatedRgn ) ; | |
facd6764 SC |
326 | } |
327 | break ; | |
73fe67bd SC |
328 | case kEventControlVisibilityChanged : |
329 | thisWindow->MacVisibilityChanged() ; | |
330 | break ; | |
331 | case kEventControlEnabledStateChanged : | |
332 | thisWindow->MacEnabledStateChanged() ; | |
333 | break ; | |
334 | case kEventControlHiliteChanged : | |
335 | thisWindow->MacHiliteChanged() ; | |
336 | break ; | |
6449b3a8 SC |
337 | #endif |
338 | // we emulate this event under Carbon CFM | |
f1d527c1 SC |
339 | case kEventControlSetFocusPart : |
340 | { | |
341 | Boolean focusEverything = false ; | |
342 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
6449b3a8 | 343 | #ifdef __WXMAC_OSX__ |
f1d527c1 SC |
344 | if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr ) |
345 | { | |
346 | } | |
6449b3a8 | 347 | #endif |
f1d527c1 SC |
348 | if ( controlPart == kControlFocusNoPart ) |
349 | { | |
350 | #if wxUSE_CARET | |
351 | if ( thisWindow->GetCaret() ) | |
352 | { | |
353 | thisWindow->GetCaret()->OnKillFocus(); | |
354 | } | |
355 | #endif // wxUSE_CARET | |
5ca0d812 | 356 | wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); |
f1d527c1 SC |
357 | event.SetEventObject(thisWindow); |
358 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
359 | } | |
360 | else | |
361 | { | |
362 | // panel wants to track the window which was the last to have focus in it | |
363 | wxChildFocusEvent eventFocus(thisWindow); | |
364 | thisWindow->GetEventHandler()->ProcessEvent(eventFocus); | |
8b573fb8 | 365 | |
f1d527c1 SC |
366 | #if wxUSE_CARET |
367 | if ( thisWindow->GetCaret() ) | |
368 | { | |
369 | thisWindow->GetCaret()->OnSetFocus(); | |
370 | } | |
371 | #endif // wxUSE_CARET | |
372 | ||
373 | wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); | |
374 | event.SetEventObject(thisWindow); | |
375 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
376 | } | |
64fec3ab SC |
377 | if ( thisWindow->MacIsUserPane() ) |
378 | result = noErr ; | |
f1d527c1 SC |
379 | } |
380 | break ; | |
f1d527c1 SC |
381 | case kEventControlHit : |
382 | { | |
383 | result = thisWindow->MacControlHit( handler , event ) ; | |
384 | } | |
385 | break ; | |
facd6764 SC |
386 | default : |
387 | break ; | |
388 | } | |
389 | return result ; | |
390 | } | |
391 | ||
e4727773 SC |
392 | static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
393 | { | |
394 | OSStatus result = eventNotHandledErr ; | |
395 | ||
396 | wxMacCarbonEvent cEvent( event ) ; | |
8b573fb8 | 397 | |
e4727773 SC |
398 | ControlRef controlRef ; |
399 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
400 | wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ; | |
401 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
402 | ||
403 | switch( GetEventKind( event ) ) | |
404 | { | |
405 | case kEventServiceGetTypes : | |
406 | if( textCtrl ) | |
407 | { | |
408 | long from, to ; | |
409 | textCtrl->GetSelection( &from , &to ) ; | |
410 | ||
8b573fb8 | 411 | CFMutableArrayRef copyTypes = 0 , pasteTypes = 0; |
e4727773 SC |
412 | if( from != to ) |
413 | copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ; | |
414 | if ( textCtrl->IsEditable() ) | |
415 | pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ; | |
8b573fb8 VZ |
416 | |
417 | static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ }; | |
e4727773 SC |
418 | for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i ) |
419 | { | |
420 | CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]); | |
421 | if ( typestring ) | |
422 | { | |
423 | if ( copyTypes ) | |
424 | CFArrayAppendValue (copyTypes, typestring) ; | |
425 | if ( pasteTypes ) | |
426 | CFArrayAppendValue (pasteTypes, typestring) ; | |
427 | CFRelease( typestring ) ; | |
428 | } | |
429 | } | |
430 | result = noErr ; | |
431 | } | |
432 | break ; | |
433 | case kEventServiceCopy : | |
434 | if ( textCtrl ) | |
435 | { | |
436 | long from, to ; | |
437 | textCtrl->GetSelection( &from , &to ) ; | |
438 | wxString val = textCtrl->GetValue() ; | |
439 | val = val.Mid( from , to - from ) ; | |
440 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
441 | verify_noerr( ClearScrap( &scrapRef ) ) ; | |
442 | verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ; | |
443 | result = noErr ; | |
444 | } | |
445 | break ; | |
446 | case kEventServicePaste : | |
447 | if ( textCtrl ) | |
448 | { | |
449 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
450 | Size textSize, pastedSize ; | |
451 | verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ; | |
452 | textSize++ ; | |
453 | char *content = new char[textSize] ; | |
8b573fb8 | 454 | GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content ); |
e4727773 | 455 | content[textSize-1] = 0 ; |
8ef4d6e2 SC |
456 | #if wxUSE_UNICODE |
457 | textCtrl->WriteText( wxString( content , wxConvLocal ) ); | |
458 | #else | |
e4727773 | 459 | textCtrl->WriteText( wxString( content ) ) ; |
8ef4d6e2 | 460 | #endif |
e4727773 SC |
461 | delete[] content ; |
462 | result = noErr ; | |
463 | } | |
464 | break ; | |
465 | } | |
8b573fb8 | 466 | |
e4727773 | 467 | return result ; |
8b573fb8 | 468 | } |
e4727773 | 469 | |
facd6764 SC |
470 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
471 | { | |
af6b7b80 SC |
472 | EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; |
473 | EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
474 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
facd6764 SC |
475 | OSStatus result = eventNotHandledErr ; |
476 | ||
477 | switch ( GetEventClass( event ) ) | |
478 | { | |
479 | case kEventClassControl : | |
480 | result = wxMacWindowControlEventHandler( handler, event, data ) ; | |
481 | break ; | |
e4727773 SC |
482 | case kEventClassService : |
483 | result = wxMacWindowServiceEventHandler( handler, event , data ) ; | |
facd6764 SC |
484 | default : |
485 | break ; | |
486 | } | |
af6b7b80 | 487 | wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; |
facd6764 SC |
488 | return result ; |
489 | } | |
490 | ||
491 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
492 | ||
20b69855 SC |
493 | #if !TARGET_API_MAC_OSX |
494 | ||
facd6764 SC |
495 | // --------------------------------------------------------------------------- |
496 | // UserPane events for non OSX builds | |
497 | // --------------------------------------------------------------------------- | |
8b573fb8 | 498 | |
facd6764 SC |
499 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
500 | { | |
501 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
502 | if ( win ) |
503 | win->MacControlUserPaneDrawProc(part) ; | |
facd6764 | 504 | } |
1f1c8bd4 | 505 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ; |
facd6764 SC |
506 | |
507 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) | |
508 | { | |
509 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
510 | if ( win ) |
511 | return win->MacControlUserPaneHitTestProc(where.h , where.v) ; | |
512 | else | |
513 | return kControlNoPart ; | |
facd6764 | 514 | } |
1f1c8bd4 | 515 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ; |
facd6764 SC |
516 | |
517 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) | |
518 | { | |
519 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
520 | if ( win ) |
521 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; | |
522 | else | |
523 | return kControlNoPart ; | |
facd6764 | 524 | } |
1f1c8bd4 | 525 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ; |
facd6764 SC |
526 | |
527 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
528 | { | |
529 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
530 | if ( win ) |
531 | win->MacControlUserPaneIdleProc() ; | |
facd6764 | 532 | } |
1f1c8bd4 | 533 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ; |
facd6764 SC |
534 | |
535 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
536 | { | |
537 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
538 | if ( win ) |
539 | return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; | |
540 | else | |
541 | return kControlNoPart ; | |
facd6764 | 542 | } |
1f1c8bd4 | 543 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ; |
facd6764 SC |
544 | |
545 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
546 | { | |
547 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
548 | if ( win ) |
549 | win->MacControlUserPaneActivateProc(activating) ; | |
facd6764 | 550 | } |
1f1c8bd4 | 551 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ; |
facd6764 SC |
552 | |
553 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
554 | { | |
555 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
556 | if ( win ) |
557 | return win->MacControlUserPaneFocusProc(action) ; | |
558 | else | |
559 | return kControlNoPart ; | |
facd6764 | 560 | } |
1f1c8bd4 | 561 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ; |
facd6764 SC |
562 | |
563 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) | |
564 | { | |
565 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
542f604f SC |
566 | if ( win ) |
567 | win->MacControlUserPaneBackgroundProc(info) ; | |
facd6764 | 568 | } |
1f1c8bd4 | 569 | wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ; |
facd6764 | 570 | |
8b573fb8 | 571 | void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) |
facd6764 | 572 | { |
bcbd6987 SC |
573 | RgnHandle rgn = NewRgn() ; |
574 | GetClip( rgn ) ; | |
d35bd499 SC |
575 | int x = 0 , y = 0; |
576 | MacWindowToRootWindow( &x,&y ) ; | |
577 | OffsetRgn( rgn , -x , -y ) ; | |
bcbd6987 SC |
578 | wxMacWindowStateSaver sv( this ) ; |
579 | SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; | |
580 | MacDoRedraw( rgn , 0 ) ; | |
581 | DisposeRgn( rgn ) ; | |
facd6764 SC |
582 | } |
583 | ||
8b573fb8 | 584 | wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
facd6764 SC |
585 | { |
586 | return kControlNoPart ; | |
587 | } | |
588 | ||
8b573fb8 | 589 | wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
facd6764 SC |
590 | { |
591 | return kControlNoPart ; | |
592 | } | |
593 | ||
8b573fb8 | 594 | void wxWindowMac::MacControlUserPaneIdleProc() |
facd6764 SC |
595 | { |
596 | } | |
597 | ||
8b573fb8 | 598 | wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
facd6764 SC |
599 | { |
600 | return kControlNoPart ; | |
601 | } | |
602 | ||
8b573fb8 | 603 | void wxWindowMac::MacControlUserPaneActivateProc(bool activating) |
facd6764 SC |
604 | { |
605 | } | |
606 | ||
8b573fb8 | 607 | wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) |
facd6764 SC |
608 | { |
609 | return kControlNoPart ; | |
610 | } | |
611 | ||
8b573fb8 | 612 | void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) |
facd6764 SC |
613 | { |
614 | } | |
615 | ||
20b69855 SC |
616 | #endif |
617 | ||
1f1c8bd4 SC |
618 | // --------------------------------------------------------------------------- |
619 | // Scrollbar Tracking for all | |
620 | // --------------------------------------------------------------------------- | |
621 | ||
622 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ; | |
623 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) | |
624 | { | |
625 | if ( partCode != 0) | |
626 | { | |
627 | wxWindow* wx = wxFindControlFromMacControl( control ) ; | |
628 | if ( wx ) | |
629 | { | |
630 | wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; | |
631 | } | |
632 | } | |
633 | } | |
634 | wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ; | |
635 | ||
e7549107 SC |
636 | // =========================================================================== |
637 | // implementation | |
638 | // =========================================================================== | |
639 | ||
71f2fb52 | 640 | #if KEY_wxList_DEPRECATED |
facd6764 SC |
641 | wxList wxWinMacControlList(wxKEY_INTEGER); |
642 | ||
643 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
644 | { | |
645 | wxNode *node = wxWinMacControlList.Find((long)inControl); | |
646 | if (!node) | |
647 | return NULL; | |
648 | return (wxControl *)node->GetData(); | |
649 | } | |
650 | ||
651 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
652 | { | |
653 | // adding NULL ControlRef is (first) surely a result of an error and | |
654 | // (secondly) breaks native event processing | |
655 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
656 | ||
657 | if ( !wxWinMacControlList.Find((long)inControl) ) | |
658 | wxWinMacControlList.Append((long)inControl, control); | |
659 | } | |
660 | ||
661 | void wxRemoveMacControlAssociation(wxWindow *control) | |
662 | { | |
a8683134 SC |
663 | // remove all associations pointing to us |
664 | while ( wxWinMacControlList.DeleteObject(control) ) | |
665 | {} | |
facd6764 | 666 | } |
71f2fb52 RN |
667 | #else |
668 | ||
669 | WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); | |
670 | ||
671 | static MacControlMap wxWinMacControlList; | |
672 | ||
673 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
674 | { | |
675 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
676 | ||
677 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
678 | } | |
679 | ||
680 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
681 | { | |
682 | // adding NULL ControlRef is (first) surely a result of an error and | |
683 | // (secondly) breaks native event processing | |
684 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
685 | ||
686 | wxWinMacControlList[inControl] = control; | |
687 | } | |
688 | ||
689 | void wxRemoveMacControlAssociation(wxWindow *control) | |
690 | { | |
691 | // iterate over all the elements in the class | |
a8683134 SC |
692 | // is the iterator stable ? as we might have two associations pointing to the same wxWindow |
693 | // we should go on... | |
694 | ||
695 | bool found = true ; | |
696 | while( found ) | |
71f2fb52 | 697 | { |
a8683134 SC |
698 | found = false ; |
699 | MacControlMap::iterator it; | |
700 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
71f2fb52 | 701 | { |
a8683134 SC |
702 | if ( it->second == control ) |
703 | { | |
704 | wxWinMacControlList.erase(it); | |
705 | found = true ; | |
706 | break; | |
707 | } | |
71f2fb52 RN |
708 | } |
709 | } | |
710 | } | |
711 | #endif // deprecated wxList | |
facd6764 | 712 | |
e7549107 | 713 | // ---------------------------------------------------------------------------- |
facd6764 | 714 | // constructors and such |
e7549107 SC |
715 | // ---------------------------------------------------------------------------- |
716 | ||
94f9b1f0 | 717 | wxWindowMac::wxWindowMac() |
8b573fb8 VZ |
718 | { |
719 | Init(); | |
94f9b1f0 SC |
720 | } |
721 | ||
722 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
723 | wxWindowID id, | |
724 | const wxPoint& pos , | |
725 | const wxSize& size , | |
726 | long style , | |
727 | const wxString& name ) | |
728 | { | |
729 | Init(); | |
730 | Create(parent, id, pos, size, style, name); | |
731 | } | |
732 | ||
e766c8a9 | 733 | void wxWindowMac::Init() |
519cb848 | 734 | { |
21fd5529 | 735 | m_peer = NULL ; |
79392158 | 736 | m_frozenness = 0 ; |
557d6f32 | 737 | #if WXWIN_COMPATIBILITY_2_4 |
e7549107 | 738 | m_backgroundTransparent = FALSE; |
557d6f32 | 739 | #endif |
e7549107 SC |
740 | |
741 | // as all windows are created with WS_VISIBLE style... | |
742 | m_isShown = TRUE; | |
743 | ||
6264b550 RR |
744 | m_hScrollBar = NULL ; |
745 | m_vScrollBar = NULL ; | |
facd6764 SC |
746 | m_macBackgroundBrush = wxNullBrush ; |
747 | ||
facd6764 | 748 | m_macIsUserPane = TRUE; |
20b69855 SC |
749 | #if wxMAC_USE_CORE_GRAPHICS |
750 | m_cgContextRef = NULL ; | |
751 | #endif | |
8adc196b | 752 | m_clipChildren = false ; |
5c840e5b | 753 | m_cachedClippedRectValid = false ; |
c6f9fb05 SC |
754 | // we need a valid font for the encodings |
755 | wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
e9576ca5 SC |
756 | } |
757 | ||
758 | // Destructor | |
e766c8a9 | 759 | wxWindowMac::~wxWindowMac() |
e9576ca5 | 760 | { |
7de59551 RD |
761 | SendDestroyEvent(); |
762 | ||
140f2012 | 763 | m_isBeingDeleted = TRUE; |
6ed71b4f | 764 | |
6449b3a8 | 765 | MacInvalidateBorders() ; |
7ebf5540 | 766 | |
d4380aaf SC |
767 | #ifndef __WXUNIVERSAL__ |
768 | // VS: make sure there's no wxFrame with last focus set to us: | |
769 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
770 | { | |
771 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
772 | if ( frame ) | |
773 | { | |
774 | if ( frame->GetLastFocus() == this ) | |
775 | { | |
776 | frame->SetLastFocus((wxWindow*)NULL); | |
777 | } | |
778 | break; | |
779 | } | |
780 | } | |
781 | #endif // __WXUNIVERSAL__ | |
8b573fb8 VZ |
782 | |
783 | // destroy children before destroying this window itself | |
784 | DestroyChildren(); | |
785 | ||
facd6764 SC |
786 | // wxRemoveMacControlAssociation( this ) ; |
787 | // If we delete an item, we should initialize the parent panel, | |
788 | // because it could now be invalid. | |
789 | wxWindow *parent = GetParent() ; | |
790 | if ( parent ) | |
791 | { | |
792 | if (parent->GetDefaultItem() == (wxButton*) this) | |
793 | parent->SetDefaultItem(NULL); | |
794 | } | |
21fd5529 | 795 | if ( m_peer && m_peer->Ok() ) |
facd6764 SC |
796 | { |
797 | // in case the callback might be called during destruction | |
798 | wxRemoveMacControlAssociation( this) ; | |
5ca0d812 SC |
799 | // we currently are not using this hook |
800 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
801 | m_peer->Dispose() ; | |
facd6764 | 802 | } |
d4380aaf | 803 | |
facd6764 | 804 | if ( g_MacLastWindow == this ) |
6264b550 | 805 | { |
facd6764 | 806 | g_MacLastWindow = NULL ; |
6264b550 | 807 | } |
7de59551 | 808 | |
fd76aa8d SC |
809 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; |
810 | if ( frame ) | |
811 | { | |
e40298d5 JS |
812 | if ( frame->GetLastFocus() == this ) |
813 | frame->SetLastFocus( NULL ) ; | |
fd76aa8d | 814 | } |
e7549107 | 815 | |
42683dfb SC |
816 | // delete our drop target if we've got one |
817 | #if wxUSE_DRAG_AND_DROP | |
818 | if ( m_dropTarget != NULL ) | |
819 | { | |
820 | delete m_dropTarget; | |
821 | m_dropTarget = NULL; | |
822 | } | |
823 | #endif // wxUSE_DRAG_AND_DROP | |
21fd5529 SC |
824 | delete m_peer ; |
825 | } | |
826 | ||
8b573fb8 VZ |
827 | WXWidget wxWindowMac::GetHandle() const |
828 | { | |
829 | return (WXWidget) m_peer->GetControlRef() ; | |
e9576ca5 SC |
830 | } |
831 | ||
facd6764 | 832 | |
5ca0d812 | 833 | void wxWindowMac::MacInstallEventHandler( WXWidget control ) |
facd6764 | 834 | { |
5ca0d812 SC |
835 | wxAssociateControlWithMacControl( (ControlRef) control , this ) ; |
836 | InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(), | |
8b573fb8 | 837 | GetEventTypeCount(eventList), eventList, this, |
facd6764 | 838 | (EventHandlerRef *)&m_macControlEventHandler); |
4a63451b SC |
839 | #if !TARGET_API_MAC_OSX |
840 | if ( (ControlRef) control == m_peer->GetControlRef() ) | |
841 | { | |
1f1c8bd4 SC |
842 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,GetwxMacControlUserPaneDrawProc()) ; |
843 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,GetwxMacControlUserPaneHitTestProc()) ; | |
844 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,GetwxMacControlUserPaneTrackingProc()) ; | |
845 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,GetwxMacControlUserPaneIdleProc()) ; | |
846 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,GetwxMacControlUserPaneKeyDownProc()) ; | |
847 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,GetwxMacControlUserPaneActivateProc()) ; | |
848 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,GetwxMacControlUserPaneFocusProc()) ; | |
849 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,GetwxMacControlUserPaneBackgroundProc()) ; | |
4a63451b SC |
850 | } |
851 | #endif | |
facd6764 SC |
852 | |
853 | } | |
854 | ||
e9576ca5 | 855 | // Constructor |
e766c8a9 | 856 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, |
e9576ca5 SC |
857 | const wxPoint& pos, |
858 | const wxSize& size, | |
859 | long style, | |
860 | const wxString& name) | |
861 | { | |
e766c8a9 | 862 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 863 | |
e7549107 | 864 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
e9576ca5 SC |
865 | return FALSE; |
866 | ||
facd6764 | 867 | m_windowVariant = parent->GetWindowVariant() ; |
8b573fb8 | 868 | |
facd6764 SC |
869 | if ( m_macIsUserPane ) |
870 | { | |
871 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
8b573fb8 | 872 | |
ebe86b1e | 873 | UInt32 features = 0 |
8b573fb8 | 874 | | kControlSupportsEmbedding |
1f1c8bd4 SC |
875 | | kControlSupportsLiveFeedback |
876 | | kControlGetsFocusOnClick | |
8b573fb8 VZ |
877 | // | kControlHasSpecialBackground |
878 | // | kControlSupportsCalcBestRect | |
1f1c8bd4 | 879 | | kControlHandlesTracking |
8b573fb8 | 880 | | kControlSupportsFocus |
1f1c8bd4 SC |
881 | | kControlWantsActivate |
882 | | kControlWantsIdle | |
8b573fb8 | 883 | ; |
ebe86b1e | 884 | |
6449b3a8 | 885 | m_peer = new wxMacControl(this) ; |
5ca0d812 | 886 | ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); |
8b573fb8 | 887 | |
facd6764 SC |
888 | |
889 | MacPostControlCreate(pos,size) ; | |
facd6764 | 890 | } |
e766c8a9 | 891 | #ifndef __WXUNIVERSAL__ |
14c9cbdb RD |
892 | // Don't give scrollbars to wxControls unless they ask for them |
893 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
894 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
6264b550 RR |
895 | { |
896 | MacCreateScrollBars( style ) ; | |
897 | } | |
e766c8a9 | 898 | #endif |
3dfafdb9 RD |
899 | |
900 | wxWindowCreateEvent event(this); | |
7e4a196e | 901 | GetEventHandler()->AddPendingEvent(event); |
3dfafdb9 | 902 | |
e9576ca5 SC |
903 | return TRUE; |
904 | } | |
905 | ||
08422003 SC |
906 | void wxWindowMac::MacChildAdded() |
907 | { | |
908 | if ( m_vScrollBar ) | |
909 | { | |
910 | m_vScrollBar->Raise() ; | |
911 | } | |
912 | if ( m_hScrollBar ) | |
913 | { | |
914 | m_hScrollBar->Raise() ; | |
915 | } | |
916 | ||
917 | } | |
918 | ||
facd6764 SC |
919 | void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) |
920 | { | |
21fd5529 | 921 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; |
facd6764 | 922 | |
5ca0d812 | 923 | m_peer->SetReference( (long) this ) ; |
488abb22 | 924 | GetParent()->AddChild(this); |
facd6764 | 925 | |
5ca0d812 | 926 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); |
facd6764 SC |
927 | |
928 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
929 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
5ca0d812 | 930 | ::EmbedControl( m_peer->GetControlRef() , container ) ; |
08422003 | 931 | GetParent()->MacChildAdded() ; |
facd6764 SC |
932 | |
933 | // adjust font, controlsize etc | |
934 | DoSetWindowVariant( m_windowVariant ) ; | |
935 | ||
5ca0d812 | 936 | m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; |
facd6764 | 937 | |
facd6764 | 938 | if (!m_macIsUserPane) |
d3b5db4b RD |
939 | { |
940 | SetInitialBestSize(size); | |
facd6764 SC |
941 | } |
942 | ||
943 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
facd6764 SC |
944 | } |
945 | ||
946 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
947 | { | |
23176131 JS |
948 | // Don't assert, in case we set the window variant before |
949 | // the window is created | |
21fd5529 | 950 | // wxASSERT( m_peer->Ok() ) ; |
facd6764 | 951 | |
23176131 JS |
952 | m_windowVariant = variant ; |
953 | ||
21fd5529 | 954 | if (m_peer == NULL || !m_peer->Ok()) |
23176131 | 955 | return; |
facd6764 | 956 | |
8b573fb8 | 957 | ControlSize size ; |
facd6764 SC |
958 | ThemeFontID themeFont = kThemeSystemFont ; |
959 | ||
960 | // we will get that from the settings later | |
8b573fb8 | 961 | // and make this NORMAL later, but first |
facd6764 | 962 | // we have a few calculations that we must fix |
8b573fb8 | 963 | |
facd6764 SC |
964 | switch ( variant ) |
965 | { | |
966 | case wxWINDOW_VARIANT_NORMAL : | |
8b573fb8 VZ |
967 | size = kControlSizeNormal; |
968 | themeFont = kThemeSystemFont ; | |
facd6764 SC |
969 | break ; |
970 | case wxWINDOW_VARIANT_SMALL : | |
8b573fb8 VZ |
971 | size = kControlSizeSmall; |
972 | themeFont = kThemeSmallSystemFont ; | |
facd6764 SC |
973 | break ; |
974 | case wxWINDOW_VARIANT_MINI : | |
975 | if (UMAGetSystemVersion() >= 0x1030 ) | |
976 | { | |
8b573fb8 VZ |
977 | // not always defined in the headers |
978 | size = 3 ; | |
979 | themeFont = 109 ; | |
facd6764 SC |
980 | } |
981 | else | |
982 | { | |
8b573fb8 VZ |
983 | size = kControlSizeSmall; |
984 | themeFont = kThemeSmallSystemFont ; | |
facd6764 SC |
985 | } |
986 | break ; | |
987 | case wxWINDOW_VARIANT_LARGE : | |
8b573fb8 VZ |
988 | size = kControlSizeLarge; |
989 | themeFont = kThemeSystemFont ; | |
facd6764 SC |
990 | break ; |
991 | default: | |
992 | wxFAIL_MSG(_T("unexpected window variant")); | |
993 | break ; | |
994 | } | |
5ca0d812 | 995 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ; |
facd6764 SC |
996 | |
997 | wxFont font ; | |
998 | font.MacCreateThemeFont( themeFont ) ; | |
999 | SetFont( font ) ; | |
1000 | } | |
1001 | ||
8b573fb8 | 1002 | void wxWindowMac::MacUpdateControlFont() |
facd6764 | 1003 | { |
ac99838a | 1004 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; |
8b573fb8 | 1005 | Refresh() ; |
facd6764 SC |
1006 | } |
1007 | ||
1008 | bool wxWindowMac::SetFont(const wxFont& font) | |
1009 | { | |
d5ccba72 | 1010 | bool retval = wxWindowBase::SetFont( font ) ; |
8b573fb8 | 1011 | |
facd6764 | 1012 | MacUpdateControlFont() ; |
8b573fb8 | 1013 | |
facd6764 SC |
1014 | return retval; |
1015 | } | |
1016 | ||
1017 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
1018 | { | |
1019 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
1020 | return false ; | |
8b573fb8 | 1021 | |
facd6764 | 1022 | MacUpdateControlFont() ; |
8b573fb8 | 1023 | |
facd6764 SC |
1024 | return true ; |
1025 | } | |
1026 | ||
1027 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
1028 | { | |
1029 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
1030 | return false ; | |
1031 | ||
1032 | wxBrush brush ; | |
b52acd03 RD |
1033 | wxColour newCol(GetBackgroundColour()); |
1034 | if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
facd6764 SC |
1035 | { |
1036 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; | |
1037 | } | |
b52acd03 | 1038 | else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) |
facd6764 | 1039 | { |
8b573fb8 VZ |
1040 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; |
1041 | } | |
facd6764 SC |
1042 | else |
1043 | { | |
b52acd03 | 1044 | brush.SetColour( newCol ) ; |
facd6764 SC |
1045 | } |
1046 | MacSetBackgroundBrush( brush ) ; | |
8b573fb8 | 1047 | |
db7a550b | 1048 | MacUpdateControlFont() ; |
8b573fb8 | 1049 | |
facd6764 SC |
1050 | return true ; |
1051 | } | |
1052 | ||
7ea087b7 SC |
1053 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1054 | { | |
1055 | m_macBackgroundBrush = brush ; | |
1056 | m_peer->SetBackground( brush ) ; | |
1057 | } | |
facd6764 SC |
1058 | |
1059 | bool wxWindowMac::MacCanFocus() const | |
1060 | { | |
f6e3849c SC |
1061 | // there is currently no way to determine whether the window is running in full keyboard |
1062 | // access mode, therefore we cannot rely on these features, yet the only other way would be | |
1063 | // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems | |
1064 | // in event handlers... | |
f1d527c1 | 1065 | UInt32 features = 0 ; |
5ca0d812 | 1066 | m_peer->GetFeatures( & features ) ; |
8b573fb8 | 1067 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; |
facd6764 SC |
1068 | } |
1069 | ||
1070 | ||
e766c8a9 | 1071 | void wxWindowMac::SetFocus() |
e9576ca5 | 1072 | { |
6264b550 RR |
1073 | if ( AcceptsFocus() ) |
1074 | { | |
7d0cfe71 | 1075 | |
f1d527c1 | 1076 | wxWindow* former = FindFocus() ; |
7d0cfe71 SC |
1077 | if ( former == this ) |
1078 | return ; | |
1079 | ||
5ca0d812 | 1080 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; |
f1d527c1 SC |
1081 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only |
1082 | // leave in case of an error | |
1083 | if ( err == errCouldntSetFocus ) | |
1084 | return ; | |
1085 | ||
1086 | #if !TARGET_API_MAC_OSX | |
1087 | // emulate carbon events when running under carbonlib where they are not natively available | |
1088 | if ( former ) | |
1089 | { | |
1090 | EventRef evRef = NULL ; | |
1091 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1092 | &evRef ) ); | |
1093 | ||
1094 | wxMacCarbonEvent cEvent( evRef ) ; | |
1095 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1096 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
8b573fb8 | 1097 | |
f1d527c1 SC |
1098 | wxMacWindowEventHandler( NULL , evRef , former ) ; |
1099 | ReleaseEvent(evRef) ; | |
6264b550 | 1100 | } |
f1d527c1 | 1101 | // send new focus event |
6264b550 | 1102 | { |
f1d527c1 SC |
1103 | EventRef evRef = NULL ; |
1104 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1105 | &evRef ) ); | |
1106 | ||
1107 | wxMacCarbonEvent cEvent( evRef ) ; | |
1108 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1109 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
8b573fb8 | 1110 | |
f1d527c1 SC |
1111 | wxMacWindowEventHandler( NULL , evRef , this ) ; |
1112 | ReleaseEvent(evRef) ; | |
6264b550 | 1113 | } |
f1d527c1 | 1114 | #endif |
6264b550 | 1115 | } |
e9576ca5 SC |
1116 | } |
1117 | ||
e9576ca5 | 1118 | |
4116c221 | 1119 | void wxWindowMac::DoCaptureMouse() |
e9576ca5 | 1120 | { |
2a1f999f | 1121 | wxApp::s_captureWindow = this ; |
e9576ca5 SC |
1122 | } |
1123 | ||
90b959ae SC |
1124 | wxWindow* wxWindowBase::GetCapture() |
1125 | { | |
2a1f999f | 1126 | return wxApp::s_captureWindow ; |
90b959ae SC |
1127 | } |
1128 | ||
4116c221 | 1129 | void wxWindowMac::DoReleaseMouse() |
e9576ca5 | 1130 | { |
2a1f999f | 1131 | wxApp::s_captureWindow = NULL ; |
e9576ca5 SC |
1132 | } |
1133 | ||
e9576ca5 SC |
1134 | #if wxUSE_DRAG_AND_DROP |
1135 | ||
e766c8a9 | 1136 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 | 1137 | { |
e40298d5 JS |
1138 | if ( m_dropTarget != 0 ) { |
1139 | delete m_dropTarget; | |
1140 | } | |
6ed71b4f | 1141 | |
e40298d5 JS |
1142 | m_dropTarget = pDropTarget; |
1143 | if ( m_dropTarget != 0 ) | |
1144 | { | |
1145 | // TODO | |
1146 | } | |
e9576ca5 SC |
1147 | } |
1148 | ||
1149 | #endif | |
1150 | ||
1151 | // Old style file-manager drag&drop | |
e766c8a9 | 1152 | void wxWindowMac::DragAcceptFiles(bool accept) |
e9576ca5 SC |
1153 | { |
1154 | // TODO | |
1155 | } | |
1156 | ||
055a486b SC |
1157 | // Returns the size of the native control. In the case of the toplevel window |
1158 | // this is the content area root control | |
1159 | ||
facd6764 | 1160 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, |
8b573fb8 | 1161 | int& w, int& h) const |
e9576ca5 | 1162 | { |
1f1c8bd4 | 1163 | wxFAIL_MSG( wxT("Not supported anymore") ) ; |
e9576ca5 SC |
1164 | } |
1165 | ||
055a486b | 1166 | // From a wx position / size calculate the appropriate size of the native control |
8b573fb8 | 1167 | |
facd6764 SC |
1168 | bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, |
1169 | const wxSize& size, | |
1170 | int& x, int& y, | |
8b573fb8 | 1171 | int& w, int& h , bool adjustOrigin ) const |
51abe921 | 1172 | { |
789ae0cf SC |
1173 | bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; |
1174 | ||
5ca0d812 | 1175 | // the desired size, minus the border pixels gives the correct size of the control |
8b573fb8 | 1176 | |
facd6764 SC |
1177 | x = (int)pos.x; |
1178 | y = (int)pos.y; | |
1179 | // todo the default calls may be used as soon as PostCreateControl Is moved here | |
29ee02df SC |
1180 | w = wxMax(size.x,0) ; // WidthDefault( size.x ); |
1181 | h = wxMax(size.y,0) ; // HeightDefault( size.y ) ; | |
789ae0cf SC |
1182 | |
1183 | if ( !isCompositing ) | |
1184 | GetParent()->MacWindowToRootWindow( &x , &y ) ; | |
5ca0d812 SC |
1185 | |
1186 | x += MacGetLeftBorderSize() ; | |
1187 | y += MacGetTopBorderSize() ; | |
1188 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1189 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
8b573fb8 | 1190 | |
79392158 SC |
1191 | if ( adjustOrigin ) |
1192 | AdjustForParentClientOrigin( x , y ) ; | |
789ae0cf | 1193 | |
7ebf5540 | 1194 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border |
789ae0cf | 1195 | if ( !GetParent()->IsTopLevel() ) |
7ebf5540 SC |
1196 | { |
1197 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1198 | y -= GetParent()->MacGetTopBorderSize() ; | |
1199 | } | |
789ae0cf | 1200 | |
facd6764 SC |
1201 | return true ; |
1202 | } | |
1203 | ||
42ef83fa | 1204 | // Get window size (not client size) |
facd6764 SC |
1205 | void wxWindowMac::DoGetSize(int *x, int *y) const |
1206 | { | |
1f1c8bd4 SC |
1207 | Rect bounds ; |
1208 | m_peer->GetRect( &bounds ) ; | |
8b573fb8 | 1209 | |
1f1c8bd4 SC |
1210 | if(x) *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
1211 | if(y) *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
facd6764 SC |
1212 | } |
1213 | ||
42ef83fa | 1214 | // get the position of the bounds of this window in client coordinates of its parent |
facd6764 SC |
1215 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
1216 | { | |
1f1c8bd4 SC |
1217 | Rect bounds ; |
1218 | m_peer->GetRect( &bounds ) ; | |
bc2b0c1b | 1219 | |
1f1c8bd4 SC |
1220 | int x1 = bounds.left ; |
1221 | int y1 = bounds.top ; | |
789ae0cf | 1222 | |
bc2b0c1b SC |
1223 | // get the wx window position from the native one |
1224 | x1 -= MacGetLeftBorderSize() ; | |
1225 | y1 -= MacGetTopBorderSize() ; | |
1226 | ||
facd6764 | 1227 | if ( !IsTopLevel() ) |
2b5f62a0 | 1228 | { |
facd6764 SC |
1229 | wxWindow *parent = GetParent(); |
1230 | if ( parent ) | |
8950f7cc | 1231 | { |
1a02aff9 SC |
1232 | // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix |
1233 | x1 += parent->MacGetLeftBorderSize() ; | |
1234 | y1 += parent->MacGetTopBorderSize() ; | |
1235 | // and now to client coordinates | |
facd6764 SC |
1236 | wxPoint pt(parent->GetClientAreaOrigin()); |
1237 | x1 -= pt.x ; | |
1238 | y1 -= pt.y ; | |
6ed71b4f | 1239 | } |
2b5f62a0 | 1240 | } |
facd6764 SC |
1241 | if(x) *x = x1 ; |
1242 | if(y) *y = y1 ; | |
facd6764 | 1243 | } |
51abe921 | 1244 | |
e766c8a9 | 1245 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 1246 | { |
facd6764 | 1247 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
8b573fb8 | 1248 | |
facd6764 | 1249 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; |
8b573fb8 | 1250 | |
facd6764 SC |
1251 | { |
1252 | Point localwhere = {0,0} ; | |
519cb848 | 1253 | |
facd6764 SC |
1254 | if(x) localwhere.h = * x ; |
1255 | if(y) localwhere.v = * y ; | |
8b573fb8 | 1256 | |
a9de2608 | 1257 | QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1258 | if(x) *x = localwhere.h ; |
1259 | if(y) *y = localwhere.v ; | |
6ed71b4f | 1260 | |
facd6764 | 1261 | } |
2078220e | 1262 | MacRootWindowToWindow( x , y ) ; |
8b573fb8 | 1263 | |
facd6764 SC |
1264 | wxPoint origin = GetClientAreaOrigin() ; |
1265 | if(x) *x -= origin.x ; | |
1266 | if(y) *y -= origin.y ; | |
e9576ca5 SC |
1267 | } |
1268 | ||
e766c8a9 | 1269 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 1270 | { |
facd6764 SC |
1271 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1272 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
14c9cbdb | 1273 | |
facd6764 SC |
1274 | wxPoint origin = GetClientAreaOrigin() ; |
1275 | if(x) *x += origin.x ; | |
1276 | if(y) *y += origin.y ; | |
14c9cbdb | 1277 | |
2078220e | 1278 | MacWindowToRootWindow( x , y ) ; |
14c9cbdb | 1279 | |
facd6764 SC |
1280 | { |
1281 | Point localwhere = { 0,0 }; | |
1282 | if(x) localwhere.h = * x ; | |
1283 | if(y) localwhere.v = * y ; | |
a9de2608 | 1284 | QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1285 | if(x) *x = localwhere.h ; |
1286 | if(y) *y = localwhere.v ; | |
1287 | } | |
519cb848 SC |
1288 | } |
1289 | ||
e766c8a9 | 1290 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 1291 | { |
1c310985 SC |
1292 | wxPoint origin = GetClientAreaOrigin() ; |
1293 | if(x) *x += origin.x ; | |
1294 | if(y) *y += origin.y ; | |
14c9cbdb | 1295 | |
1c310985 SC |
1296 | MacWindowToRootWindow( x , y ) ; |
1297 | } | |
1298 | ||
1299 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1300 | { | |
1c310985 | 1301 | MacRootWindowToWindow( x , y ) ; |
facd6764 SC |
1302 | |
1303 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 SC |
1304 | if(x) *x -= origin.x ; |
1305 | if(y) *y -= origin.y ; | |
1306 | } | |
1307 | ||
1308 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1309 | { | |
5ca0d812 | 1310 | wxPoint pt ; |
facd6764 SC |
1311 | if ( x ) pt.x = *x ; |
1312 | if ( y ) pt.y = *y ; | |
1313 | ||
125c7984 | 1314 | if ( !IsTopLevel() ) |
5437ff47 RD |
1315 | { |
1316 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1317 | if (top) | |
5ca0d812 SC |
1318 | { |
1319 | pt.x -= MacGetLeftBorderSize() ; | |
1320 | pt.y -= MacGetTopBorderSize() ; | |
1321 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1322 | } | |
5437ff47 | 1323 | } |
8b573fb8 | 1324 | |
facd6764 SC |
1325 | if ( x ) *x = (int) pt.x ; |
1326 | if ( y ) *y = (int) pt.y ; | |
facd6764 SC |
1327 | } |
1328 | ||
1329 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1330 | { | |
1331 | int x1 , y1 ; | |
1332 | if ( x ) x1 = *x ; | |
1333 | if ( y ) y1 = *y ; | |
1334 | MacWindowToRootWindow( &x1 , &y1 ) ; | |
1335 | if ( x ) *x = x1 ; | |
1336 | if ( y ) *y = y1 ; | |
519cb848 SC |
1337 | } |
1338 | ||
1c310985 | 1339 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const |
519cb848 | 1340 | { |
5ca0d812 | 1341 | wxPoint pt ; |
facd6764 SC |
1342 | if ( x ) pt.x = *x ; |
1343 | if ( y ) pt.y = *y ; | |
1344 | ||
125c7984 | 1345 | if ( !IsTopLevel() ) |
5ca0d812 | 1346 | { |
5c840e5b SC |
1347 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); |
1348 | if (top) | |
1349 | { | |
1350 | wxMacControl::Convert( &pt , top->m_peer , m_peer ) ; | |
1351 | pt.x += MacGetLeftBorderSize() ; | |
1352 | pt.y += MacGetTopBorderSize() ; | |
1353 | } | |
5ca0d812 | 1354 | } |
8b573fb8 | 1355 | |
facd6764 SC |
1356 | if ( x ) *x = (int) pt.x ; |
1357 | if ( y ) *y = (int) pt.y ; | |
e9576ca5 SC |
1358 | } |
1359 | ||
facd6764 | 1360 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const |
e9576ca5 | 1361 | { |
facd6764 SC |
1362 | int x1 , y1 ; |
1363 | if ( x ) x1 = *x ; | |
1364 | if ( y ) y1 = *y ; | |
1365 | MacRootWindowToWindow( &x1 , &y1 ) ; | |
1366 | if ( x ) *x = x1 ; | |
1367 | if ( y ) *y = y1 ; | |
1368 | } | |
6ed71b4f | 1369 | |
29281095 SC |
1370 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1371 | { | |
1372 | RgnHandle rgn = NewRgn() ; | |
5ca0d812 | 1373 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
29281095 | 1374 | { |
1f1c8bd4 SC |
1375 | Rect structure ; |
1376 | Rect content ; | |
29281095 | 1377 | GetRegionBounds( rgn , &content ) ; |
1f1c8bd4 SC |
1378 | m_peer->GetRect( &structure ) ; |
1379 | OffsetRect( &structure, -structure.left , -structure.top ) ; | |
1380 | ||
1381 | left = content.left - structure.left ; | |
1382 | top = content.top - structure.top ; | |
1383 | right = structure.right - content.right ; | |
1384 | bottom = structure.bottom - content.bottom ; | |
29281095 SC |
1385 | } |
1386 | else | |
1387 | { | |
1f1c8bd4 | 1388 | left = top = right = bottom = 0 ; |
29281095 | 1389 | } |
7596e51d | 1390 | DisposeRgn( rgn ) ; |
29281095 SC |
1391 | } |
1392 | ||
facd6764 SC |
1393 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const |
1394 | { | |
1395 | wxSize sizeTotal = size; | |
1396 | ||
1397 | RgnHandle rgn = NewRgn() ; | |
1398 | ||
5ca0d812 | 1399 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
6618870d | 1400 | { |
1f1c8bd4 SC |
1401 | Rect content ; |
1402 | Rect structure ; | |
facd6764 | 1403 | GetRegionBounds( rgn , &content ) ; |
789ae0cf | 1404 | |
1f1c8bd4 SC |
1405 | m_peer->GetRect( &structure ) ; |
1406 | // structure is in parent coordinates, but we only need width and height, so it's ok | |
6ed71b4f | 1407 | |
1f1c8bd4 SC |
1408 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; |
1409 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; | |
1410 | } | |
1411 | DisposeRgn( rgn ) ; | |
6ed71b4f | 1412 | |
facd6764 SC |
1413 | sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1414 | sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
6ed71b4f | 1415 | |
facd6764 | 1416 | return sizeTotal; |
e9576ca5 SC |
1417 | } |
1418 | ||
1419 | ||
1420 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
e766c8a9 | 1421 | void wxWindowMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 1422 | { |
9453cf2b | 1423 | int ww, hh; |
6ed71b4f | 1424 | |
facd6764 SC |
1425 | RgnHandle rgn = NewRgn() ; |
1426 | Rect content ; | |
5ca0d812 | 1427 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
facd6764 SC |
1428 | { |
1429 | GetRegionBounds( rgn , &content ) ; | |
facd6764 SC |
1430 | } |
1431 | else | |
1432 | { | |
5ca0d812 | 1433 | m_peer->GetRect( &content ) ; |
facd6764 | 1434 | } |
7596e51d | 1435 | DisposeRgn( rgn ) ; |
789ae0cf | 1436 | |
facd6764 SC |
1437 | ww = content.right - content.left ; |
1438 | hh = content.bottom - content.top ; | |
6ed71b4f | 1439 | |
db7a550b SC |
1440 | if (m_hScrollBar && m_hScrollBar->IsShown() ) |
1441 | { | |
e905b636 | 1442 | hh -= m_hScrollBar->GetSize().y ; |
db7a550b SC |
1443 | } |
1444 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1445 | { | |
e905b636 | 1446 | ww -= m_vScrollBar->GetSize().x ; |
db7a550b | 1447 | } |
e40298d5 JS |
1448 | if(x) *x = ww; |
1449 | if(y) *y = hh; | |
facd6764 SC |
1450 | |
1451 | } | |
1452 | ||
1453 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1454 | { | |
1455 | if (m_cursor == cursor) | |
1456 | return FALSE; | |
1457 | ||
1458 | if (wxNullCursor == cursor) | |
1459 | { | |
1460 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
1461 | return FALSE ; | |
1462 | } | |
1463 | else | |
1464 | { | |
1465 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
1466 | return FALSE ; | |
1467 | } | |
1468 | ||
1469 | wxASSERT_MSG( m_cursor.Ok(), | |
1470 | wxT("cursor must be valid after call to the base version")); | |
8b573fb8 VZ |
1471 | |
1472 | ||
2d1760d3 | 1473 | wxWindowMac *mouseWin = 0 ; |
facd6764 | 1474 | { |
789ae0cf SC |
1475 | wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ; |
1476 | WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ; | |
2d1760d3 SC |
1477 | CGrafPtr savePort ; |
1478 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
8b573fb8 | 1479 | |
2d1760d3 SC |
1480 | // TODO If we ever get a GetCurrentEvent.. replacement for the mouse |
1481 | // position, use it... | |
8b573fb8 | 1482 | |
2d1760d3 SC |
1483 | Point pt ; |
1484 | GetMouse( &pt ) ; | |
1485 | ControlPartCode part ; | |
1486 | ControlRef control ; | |
789ae0cf | 1487 | control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ; |
2d1760d3 SC |
1488 | if ( control ) |
1489 | mouseWin = wxFindControlFromMacControl( control ) ; | |
8b573fb8 | 1490 | |
2d1760d3 SC |
1491 | if ( swapped ) |
1492 | QDSwapPort( savePort , NULL ) ; | |
facd6764 | 1493 | } |
2d1760d3 SC |
1494 | |
1495 | if ( mouseWin == this && !wxIsBusy() ) | |
facd6764 SC |
1496 | { |
1497 | m_cursor.MacInstall() ; | |
1498 | } | |
1499 | ||
1500 | return TRUE ; | |
519cb848 SC |
1501 | } |
1502 | ||
facd6764 SC |
1503 | #if wxUSE_MENUS |
1504 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1505 | { | |
1506 | menu->SetInvokingWindow(this); | |
1507 | menu->UpdateUI(); | |
8b573fb8 | 1508 | |
971562cb VS |
1509 | if ( x == -1 && y == -1 ) |
1510 | { | |
1511 | wxPoint mouse = wxGetMousePosition(); | |
1512 | x = mouse.x; y = mouse.y; | |
1513 | } | |
1514 | else | |
1515 | { | |
1516 | ClientToScreen( &x , &y ) ; | |
1517 | } | |
facd6764 SC |
1518 | |
1519 | menu->MacBeforeDisplay( true ) ; | |
1520 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
1521 | if ( HiWord(menuResult) != 0 ) | |
1522 | { | |
1523 | MenuCommand id ; | |
1524 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
1525 | wxMenuItem* item = NULL ; | |
1526 | wxMenu* realmenu ; | |
1527 | item = menu->FindItem(id, &realmenu) ; | |
1528 | if (item->IsCheckable()) | |
1529 | { | |
1530 | item->Check( !item->IsChecked() ) ; | |
1531 | } | |
1532 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
1533 | } | |
1534 | menu->MacAfterDisplay( true ) ; | |
1535 | ||
1536 | menu->SetInvokingWindow(NULL); | |
1537 | ||
1538 | return TRUE; | |
1539 | } | |
1540 | #endif | |
51abe921 SC |
1541 | |
1542 | // ---------------------------------------------------------------------------- | |
1543 | // tooltips | |
1544 | // ---------------------------------------------------------------------------- | |
1545 | ||
1546 | #if wxUSE_TOOLTIPS | |
1547 | ||
e766c8a9 | 1548 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
1549 | { |
1550 | wxWindowBase::DoSetToolTip(tooltip); | |
6ed71b4f | 1551 | |
6264b550 RR |
1552 | if ( m_tooltip ) |
1553 | m_tooltip->SetWindow(this); | |
51abe921 SC |
1554 | } |
1555 | ||
1556 | #endif // wxUSE_TOOLTIPS | |
1557 | ||
6449b3a8 SC |
1558 | void wxWindowMac::MacInvalidateBorders() |
1559 | { | |
1560 | if ( m_peer == NULL ) | |
1561 | return ; | |
1562 | ||
1563 | bool vis = MacIsReallyShown() ; | |
1564 | if ( !vis ) | |
1565 | return ; | |
1566 | ||
1567 | int outerBorder = MacGetLeftBorderSize() ; | |
1568 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1569 | outerBorder += 4 ; | |
1570 | ||
1571 | if ( outerBorder == 0 ) | |
1572 | return ; | |
1573 | ||
1574 | // now we know that we have something to do at all | |
1575 | ||
1576 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1577 | RgnHandle updateInner = NewRgn() , | |
1578 | updateOuter = NewRgn() ; | |
1579 | ||
1580 | // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon | |
1581 | Rect rect ; | |
1582 | m_peer->GetRect( &rect ) ; | |
1583 | RectRgn( updateInner , &rect ) ; | |
1584 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1585 | RectRgn( updateOuter , &rect ) ; | |
1586 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1587 | #ifdef __WXMAC_OSX__ | |
1f1c8bd4 | 1588 | GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ; |
6449b3a8 SC |
1589 | #else |
1590 | WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ; | |
1591 | if ( tlw ) | |
1592 | InvalWindowRgn( tlw , updateOuter ) ; | |
1593 | #endif | |
1594 | DisposeRgn(updateOuter) ; | |
1595 | DisposeRgn(updateInner) ; | |
1596 | /* | |
1597 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
1598 | RectRgn( updateInner , &rect ) ; | |
1599 | InsetRect( &rect , -4 , -4 ) ; | |
1600 | RectRgn( updateOuter , &rect ) ; | |
1601 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1602 | wxPoint parent(0,0); | |
1603 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1604 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1605 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1606 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
1607 | DisposeRgn(updateOuter) ; | |
1608 | DisposeRgn(updateInner) ; | |
1609 | */ | |
1610 | /* | |
1611 | if ( m_peer ) | |
1612 | { | |
1613 | // deleting a window while it is shown invalidates the region occupied by border or | |
1614 | // focus | |
1615 | ||
1616 | if ( IsShown() && ( outerBorder > 0 ) ) | |
1617 | { | |
1618 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1619 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1620 | ||
1621 | Rect rect ; | |
1622 | ||
1623 | m_peer->GetRect( &rect ) ; | |
1624 | RectRgn( updateInner , &rect ) ; | |
1625 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1626 | RectRgn( updateOuter , &rect ) ; | |
1627 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1628 | wxPoint parent(0,0); | |
1629 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1630 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1631 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1632 | CopyRgn( updateOuter , updateTotal ) ; | |
1633 | ||
1634 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
1635 | DisposeRgn(updateOuter) ; | |
1636 | DisposeRgn(updateInner) ; | |
1637 | DisposeRgn(updateTotal) ; | |
1638 | } | |
1639 | } | |
1640 | */ | |
1641 | #if 0 | |
1642 | Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; | |
1643 | ||
1644 | int outerBorder = MacGetLeftBorderSize() ; | |
1645 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1646 | outerBorder += 4 ; | |
1647 | ||
1648 | if ( vis && ( outerBorder > 0 ) ) | |
1649 | { | |
1650 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1651 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1652 | ||
1653 | Rect rect ; | |
1654 | ||
1655 | m_peer->GetRect( &rect ) ; | |
1656 | RectRgn( updateInner , &rect ) ; | |
1657 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1658 | RectRgn( updateOuter , &rect ) ; | |
1659 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1660 | /* | |
1661 | wxPoint parent(0,0); | |
1662 | #if TARGET_API_MAC_OSX | |
1663 | // no offsetting needed when compositing | |
1664 | #else | |
1665 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1666 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1667 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1668 | #endif | |
1669 | */ | |
1670 | CopyRgn( updateOuter , updateTotal ) ; | |
1671 | ||
1672 | rect = r ; | |
1673 | RectRgn( updateInner , &rect ) ; | |
1674 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1675 | RectRgn( updateOuter , &rect ) ; | |
1676 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1677 | /* | |
1678 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1679 | */ | |
1680 | UnionRgn( updateOuter , updateTotal , updateTotal ) ; | |
1681 | ||
1f1c8bd4 | 1682 | GetParent()->m_peer->SetNeedsDisplay( updateTotal ) ; |
6449b3a8 SC |
1683 | DisposeRgn(updateOuter) ; |
1684 | DisposeRgn(updateInner) ; | |
1685 | DisposeRgn(updateTotal) ; | |
1686 | } | |
1687 | #endif | |
1688 | } | |
1689 | ||
e766c8a9 | 1690 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 1691 | { |
db7a550b | 1692 | // this is never called for a toplevel window, so we know we have a parent |
facd6764 | 1693 | int former_x , former_y , former_w, former_h ; |
db7a550b SC |
1694 | |
1695 | // Get true coordinates of former position | |
facd6764 SC |
1696 | DoGetPosition( &former_x , &former_y ) ; |
1697 | DoGetSize( &former_w , &former_h ) ; | |
db7a550b SC |
1698 | |
1699 | wxWindow *parent = GetParent(); | |
1700 | if ( parent ) | |
1701 | { | |
1702 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1703 | former_x += pt.x ; | |
1704 | former_y += pt.y ; | |
1705 | } | |
6ed71b4f | 1706 | |
29ee02df SC |
1707 | int actualWidth = width ; |
1708 | int actualHeight = height ; | |
e40298d5 JS |
1709 | int actualX = x; |
1710 | int actualY = y; | |
6ed71b4f | 1711 | |
14c9cbdb | 1712 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 1713 | actualWidth = m_minWidth; |
14c9cbdb | 1714 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 1715 | actualHeight = m_minHeight; |
14c9cbdb | 1716 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 1717 | actualWidth = m_maxWidth; |
14c9cbdb | 1718 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
c0624ca2 | 1719 | actualHeight = m_maxHeight; |
6ed71b4f | 1720 | |
6264b550 RR |
1721 | bool doMove = false ; |
1722 | bool doResize = false ; | |
6ed71b4f | 1723 | |
6264b550 RR |
1724 | if ( actualX != former_x || actualY != former_y ) |
1725 | { | |
1726 | doMove = true ; | |
1727 | } | |
1728 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1729 | { | |
1730 | doResize = true ; | |
1731 | } | |
6ed71b4f | 1732 | |
6264b550 RR |
1733 | if ( doMove || doResize ) |
1734 | { | |
1f1c8bd4 SC |
1735 | // as the borders are drawn outside the native control, we adjust now |
1736 | ||
1737 | wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), | |
1738 | wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , | |
1739 | actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; | |
1740 | ||
1741 | Rect r ; | |
1742 | wxMacRectToNative( &bounds , &r ) ; | |
1743 | ||
1744 | if ( !GetParent()->IsTopLevel() ) | |
1745 | { | |
1746 | wxMacWindowToNative( GetParent() , &r ) ; | |
1747 | } | |
8b573fb8 | 1748 | |
6449b3a8 | 1749 | MacInvalidateBorders() ; |
789ae0cf | 1750 | |
5c840e5b | 1751 | m_cachedClippedRectValid = false ; |
8b573fb8 | 1752 | m_peer->SetRect( &r ) ; |
5c840e5b | 1753 | |
e905b636 | 1754 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified |
91ae6e3a | 1755 | |
6449b3a8 SC |
1756 | MacInvalidateBorders() ; |
1757 | ||
6264b550 RR |
1758 | MacRepositionScrollBars() ; |
1759 | if ( doMove ) | |
1760 | { | |
facd6764 | 1761 | wxPoint point(actualX,actualY); |
6264b550 RR |
1762 | wxMoveEvent event(point, m_windowId); |
1763 | event.SetEventObject(this); | |
1764 | GetEventHandler()->ProcessEvent(event) ; | |
1765 | } | |
1766 | if ( doResize ) | |
1767 | { | |
e40298d5 | 1768 | MacRepositionScrollBars() ; |
facd6764 | 1769 | wxSize size(actualWidth, actualHeight); |
e40298d5 JS |
1770 | wxSizeEvent event(size, m_windowId); |
1771 | event.SetEventObject(this); | |
1772 | GetEventHandler()->ProcessEvent(event); | |
6264b550 RR |
1773 | } |
1774 | } | |
6ed71b4f | 1775 | |
954fc50b SC |
1776 | } |
1777 | ||
facd6764 SC |
1778 | wxSize wxWindowMac::DoGetBestSize() const |
1779 | { | |
eb69d46e SC |
1780 | if ( m_macIsUserPane || IsTopLevel() ) |
1781 | return wxWindowBase::DoGetBestSize() ; | |
8b573fb8 | 1782 | |
facd6764 | 1783 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
facd6764 | 1784 | int bestWidth, bestHeight ; |
5ca0d812 | 1785 | m_peer->GetBestRect( &bestsize ) ; |
facd6764 SC |
1786 | |
1787 | if ( EmptyRect( &bestsize ) ) | |
1788 | { | |
facd6764 SC |
1789 | bestsize.left = bestsize.top = 0 ; |
1790 | bestsize.right = 16 ; | |
1791 | bestsize.bottom = 16 ; | |
1792 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1793 | { | |
1794 | bestsize.bottom = 16 ; | |
1795 | } | |
e3e817d4 | 1796 | #if wxUSE_SPINBTN |
facd6764 SC |
1797 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) |
1798 | { | |
8b573fb8 | 1799 | bestsize.bottom = 24 ; |
facd6764 | 1800 | } |
e3e817d4 | 1801 | #endif // wxUSE_SPINBTN |
facd6764 SC |
1802 | else |
1803 | { | |
8b573fb8 | 1804 | // return wxWindowBase::DoGetBestSize() ; |
facd6764 SC |
1805 | } |
1806 | } | |
1807 | ||
1808 | bestWidth = bestsize.right - bestsize.left ; | |
1809 | bestHeight = bestsize.bottom - bestsize.top ; | |
1810 | if ( bestHeight < 10 ) | |
1811 | bestHeight = 13 ; | |
8b573fb8 | 1812 | |
facd6764 SC |
1813 | return wxSize(bestWidth, bestHeight); |
1814 | } | |
1815 | ||
1816 | ||
954fc50b SC |
1817 | // set the size of the window: if the dimensions are positive, just use them, |
1818 | // but if any of them is equal to -1, it means that we must find the value for | |
1819 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1820 | // which case -1 is a valid value for x and y) | |
1821 | // | |
1822 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1823 | // the width/height to best suit our contents, otherwise we reuse the current | |
1824 | // width/height | |
1825 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1826 | { | |
1827 | // get the current size and position... | |
1828 | int currentX, currentY; | |
1829 | GetPosition(¤tX, ¤tY); | |
6ed71b4f | 1830 | |
954fc50b SC |
1831 | int currentW,currentH; |
1832 | GetSize(¤tW, ¤tH); | |
6ed71b4f | 1833 | |
954fc50b SC |
1834 | // ... and don't do anything (avoiding flicker) if it's already ok |
1835 | if ( x == currentX && y == currentY && | |
769ac869 | 1836 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) |
954fc50b | 1837 | { |
facd6764 | 1838 | // TODO REMOVE |
6264b550 | 1839 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
1840 | return; |
1841 | } | |
6ed71b4f | 1842 | |
954fc50b SC |
1843 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
1844 | x = currentX; | |
1845 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1846 | y = currentY; | |
6ed71b4f | 1847 | |
954fc50b | 1848 | AdjustForParentClientOrigin(x, y, sizeFlags); |
6ed71b4f | 1849 | |
954fc50b SC |
1850 | wxSize size(-1, -1); |
1851 | if ( width == -1 ) | |
1852 | { | |
1853 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1854 | { | |
1855 | size = DoGetBestSize(); | |
1856 | width = size.x; | |
1857 | } | |
1858 | else | |
1859 | { | |
1860 | // just take the current one | |
1861 | width = currentW; | |
1862 | } | |
1863 | } | |
6ed71b4f | 1864 | |
954fc50b SC |
1865 | if ( height == -1 ) |
1866 | { | |
1867 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1868 | { | |
1869 | if ( size.x == -1 ) | |
1870 | { | |
1871 | size = DoGetBestSize(); | |
1872 | } | |
1873 | //else: already called DoGetBestSize() above | |
6ed71b4f | 1874 | |
954fc50b SC |
1875 | height = size.y; |
1876 | } | |
1877 | else | |
1878 | { | |
1879 | // just take the current one | |
1880 | height = currentH; | |
1881 | } | |
1882 | } | |
6ed71b4f | 1883 | |
954fc50b | 1884 | DoMoveWindow(x, y, width, height); |
6ed71b4f | 1885 | |
e9576ca5 | 1886 | } |
519cb848 | 1887 | |
e766c8a9 | 1888 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 1889 | { |
facd6764 SC |
1890 | RgnHandle rgn = NewRgn() ; |
1891 | Rect content ; | |
04d4e684 | 1892 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
21638402 SC |
1893 | { |
1894 | GetRegionBounds( rgn , &content ) ; | |
1895 | } | |
1896 | else | |
1897 | { | |
1898 | content.left = content.top = 0 ; | |
1899 | } | |
facd6764 | 1900 | DisposeRgn( rgn ) ; |
facd6764 SC |
1901 | return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); |
1902 | } | |
1903 | ||
1904 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1905 | { | |
1906 | if ( clientheight != -1 || clientheight != -1 ) | |
1907 | { | |
1908 | int currentclientwidth , currentclientheight ; | |
1909 | int currentwidth , currentheight ; | |
1910 | ||
1911 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1912 | GetSize( ¤twidth , ¤theight ) ; | |
1913 | ||
1914 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
1915 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1916 | } | |
e9576ca5 SC |
1917 | } |
1918 | ||
d84afea9 | 1919 | void wxWindowMac::SetTitle(const wxString& title) |
e9576ca5 | 1920 | { |
facd6764 SC |
1921 | m_label = wxStripMenuCodes(title) ; |
1922 | ||
21fd5529 | 1923 | if ( m_peer && m_peer->Ok() ) |
facd6764 | 1924 | { |
5ca0d812 | 1925 | m_peer->SetTitle( m_label ) ; |
facd6764 SC |
1926 | } |
1927 | Refresh() ; | |
519cb848 SC |
1928 | } |
1929 | ||
d84afea9 | 1930 | wxString wxWindowMac::GetTitle() const |
519cb848 | 1931 | { |
ed60b502 | 1932 | return m_label ; |
519cb848 SC |
1933 | } |
1934 | ||
8ab50549 SC |
1935 | bool wxWindowMac::Show(bool show) |
1936 | { | |
542f604f | 1937 | bool former = MacIsReallyShown() ; |
8ab50549 SC |
1938 | if ( !wxWindowBase::Show(show) ) |
1939 | return FALSE; | |
8b573fb8 | 1940 | |
8ab50549 | 1941 | // TODO use visibilityChanged Carbon Event for OSX |
2c899c20 SC |
1942 | if ( m_peer ) |
1943 | { | |
2c899c20 | 1944 | m_peer->SetVisibility( show , true ) ; |
2c899c20 | 1945 | } |
542f604f SC |
1946 | if ( former != MacIsReallyShown() ) |
1947 | MacPropagateVisibilityChanged() ; | |
8ab50549 SC |
1948 | return TRUE; |
1949 | } | |
1950 | ||
1951 | bool wxWindowMac::Enable(bool enable) | |
1952 | { | |
21fd5529 | 1953 | wxASSERT( m_peer->Ok() ) ; |
542f604f | 1954 | bool former = MacIsReallyEnabled() ; |
8ab50549 SC |
1955 | if ( !wxWindowBase::Enable(enable) ) |
1956 | return FALSE; | |
1957 | ||
5ca0d812 | 1958 | m_peer->Enable( enable ) ; |
8ab50549 SC |
1959 | |
1960 | if ( former != MacIsReallyEnabled() ) | |
1961 | MacPropagateEnabledStateChanged() ; | |
1962 | return TRUE; | |
1963 | } | |
1964 | ||
8b573fb8 | 1965 | // |
8ab50549 SC |
1966 | // status change propagations (will be not necessary for OSX later ) |
1967 | // | |
1968 | ||
facd6764 SC |
1969 | void wxWindowMac::MacPropagateVisibilityChanged() |
1970 | { | |
73fe67bd | 1971 | #if !TARGET_API_MAC_OSX |
facd6764 | 1972 | MacVisibilityChanged() ; |
8b573fb8 | 1973 | |
71f2fb52 | 1974 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
facd6764 SC |
1975 | while ( node ) |
1976 | { | |
1977 | wxWindowMac *child = node->GetData(); | |
1978 | if ( child->IsShown() ) | |
1979 | child->MacPropagateVisibilityChanged( ) ; | |
1980 | node = node->GetNext(); | |
1981 | } | |
73fe67bd | 1982 | #endif |
facd6764 SC |
1983 | } |
1984 | ||
8ab50549 | 1985 | void wxWindowMac::MacPropagateEnabledStateChanged( ) |
e9576ca5 | 1986 | { |
73fe67bd | 1987 | #if !TARGET_API_MAC_OSX |
8ab50549 | 1988 | MacEnabledStateChanged() ; |
8b573fb8 | 1989 | |
71f2fb52 | 1990 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
8ab50549 SC |
1991 | while ( node ) |
1992 | { | |
1993 | wxWindowMac *child = node->GetData(); | |
1994 | if ( child->IsEnabled() ) | |
1995 | child->MacPropagateEnabledStateChanged() ; | |
1996 | node = node->GetNext(); | |
1997 | } | |
73fe67bd | 1998 | #endif |
8ab50549 SC |
1999 | } |
2000 | ||
2001 | void wxWindowMac::MacPropagateHiliteChanged( ) | |
2002 | { | |
73fe67bd | 2003 | #if !TARGET_API_MAC_OSX |
8ab50549 | 2004 | MacHiliteChanged() ; |
8b573fb8 | 2005 | |
71f2fb52 | 2006 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
8ab50549 SC |
2007 | while ( node ) |
2008 | { | |
2009 | wxWindowMac *child = node->GetData(); | |
2010 | // if ( child->IsEnabled() ) | |
2011 | child->MacPropagateHiliteChanged() ; | |
2012 | node = node->GetNext(); | |
2013 | } | |
73fe67bd | 2014 | #endif |
8ab50549 SC |
2015 | } |
2016 | ||
2017 | // | |
2018 | // status change notifications | |
8b573fb8 | 2019 | // |
8ab50549 | 2020 | |
8b573fb8 | 2021 | void wxWindowMac::MacVisibilityChanged() |
8ab50549 SC |
2022 | { |
2023 | } | |
2024 | ||
8b573fb8 | 2025 | void wxWindowMac::MacHiliteChanged() |
8ab50549 SC |
2026 | { |
2027 | } | |
2028 | ||
8b573fb8 | 2029 | void wxWindowMac::MacEnabledStateChanged() |
8ab50549 | 2030 | { |
facd6764 | 2031 | } |
e7549107 | 2032 | |
8ab50549 SC |
2033 | // |
2034 | // status queries on the inherited window's state | |
2035 | // | |
2036 | ||
8b573fb8 | 2037 | bool wxWindowMac::MacIsReallyShown() |
facd6764 SC |
2038 | { |
2039 | // only under OSX the visibility of the TLW is taken into account | |
66ffb23b SC |
2040 | if ( m_isBeingDeleted ) |
2041 | return false ; | |
2042 | ||
facd6764 | 2043 | #if TARGET_API_MAC_OSX |
aa522e33 SC |
2044 | if ( m_peer && m_peer->Ok() ) |
2045 | return m_peer->IsVisible(); | |
2046 | #endif | |
facd6764 SC |
2047 | wxWindow* win = this ; |
2048 | while( win->IsShown() ) | |
2049 | { | |
2050 | if ( win->IsTopLevel() ) | |
2051 | return true ; | |
8b573fb8 | 2052 | |
facd6764 SC |
2053 | win = win->GetParent() ; |
2054 | if ( win == NULL ) | |
2055 | return true ; | |
8b573fb8 | 2056 | |
facd6764 SC |
2057 | } ; |
2058 | return false ; | |
facd6764 | 2059 | } |
4241baae | 2060 | |
8b573fb8 | 2061 | bool wxWindowMac::MacIsReallyEnabled() |
facd6764 | 2062 | { |
5ca0d812 | 2063 | return m_peer->IsEnabled() ; |
facd6764 SC |
2064 | } |
2065 | ||
8b573fb8 | 2066 | bool wxWindowMac::MacIsReallyHilited() |
c809f3be | 2067 | { |
5ca0d812 | 2068 | return m_peer->IsActive(); |
c809f3be SC |
2069 | } |
2070 | ||
8b573fb8 | 2071 | void wxWindowMac::MacFlashInvalidAreas() |
002c9672 SC |
2072 | { |
2073 | #if TARGET_API_MAC_OSX | |
2074 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2075 | #endif | |
2076 | } | |
2077 | ||
8ab50549 SC |
2078 | // |
2079 | // | |
2080 | // | |
2081 | ||
e766c8a9 | 2082 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 2083 | { |
6264b550 RR |
2084 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2085 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
2086 | } |
2087 | ||
e766c8a9 | 2088 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 2089 | { |
6264b550 RR |
2090 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2091 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
2092 | } |
2093 | ||
e766c8a9 | 2094 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 2095 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 2096 | { |
e7549107 SC |
2097 | const wxFont *fontToUse = theFont; |
2098 | if ( !fontToUse ) | |
2099 | fontToUse = &m_font; | |
14c9cbdb | 2100 | |
e766c8a9 | 2101 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 2102 | long lx,ly,ld,le ; |
5fde6fcc | 2103 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 2104 | if ( externalLeading ) |
6264b550 | 2105 | *externalLeading = le ; |
2f1ae414 | 2106 | if ( descent ) |
6264b550 | 2107 | *descent = ld ; |
2f1ae414 | 2108 | if ( x ) |
6264b550 | 2109 | *x = lx ; |
2f1ae414 | 2110 | if ( y ) |
6264b550 | 2111 | *y = ly ; |
e9576ca5 SC |
2112 | } |
2113 | ||
0a67a93b | 2114 | /* |
14c9cbdb | 2115 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
1c310985 SC |
2116 | * we always intersect with the entire window, not only with the client area |
2117 | */ | |
14c9cbdb | 2118 | |
e766c8a9 | 2119 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 2120 | { |
065ab451 SC |
2121 | if ( m_peer == NULL ) |
2122 | return ; | |
8b573fb8 | 2123 | |
1f1c8bd4 SC |
2124 | if ( !MacIsReallyShown() ) |
2125 | return ; | |
789ae0cf | 2126 | |
1f1c8bd4 | 2127 | if ( rect ) |
1e8cde71 | 2128 | { |
1f1c8bd4 SC |
2129 | Rect r ; |
2130 | wxMacRectToNative( rect , &r ) ; | |
2131 | m_peer->SetNeedsDisplay( &r ) ; | |
facd6764 | 2132 | } |
1f1c8bd4 | 2133 | else |
9a456218 | 2134 | { |
1f1c8bd4 | 2135 | m_peer->SetNeedsDisplay() ; |
e9576ca5 | 2136 | } |
facd6764 SC |
2137 | } |
2138 | ||
79392158 SC |
2139 | void wxWindowMac::Freeze() |
2140 | { | |
2141 | #if TARGET_API_MAC_OSX | |
2142 | if ( !m_frozenness++ ) | |
2143 | { | |
52ef5c3c RD |
2144 | if ( m_peer && m_peer->Ok() ) |
2145 | m_peer->SetDrawingEnabled( false ) ; | |
79392158 SC |
2146 | } |
2147 | #endif | |
2148 | } | |
2149 | ||
b175b96b | 2150 | |
79392158 SC |
2151 | void wxWindowMac::Thaw() |
2152 | { | |
2153 | #if TARGET_API_MAC_OSX | |
2154 | wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); | |
2155 | ||
2156 | if ( !--m_frozenness ) | |
2157 | { | |
52ef5c3c RD |
2158 | if ( m_peer && m_peer->Ok() ) |
2159 | { | |
2160 | m_peer->SetDrawingEnabled( true ) ; | |
2161 | m_peer->InvalidateWithChildren() ; | |
2162 | } | |
79392158 SC |
2163 | } |
2164 | #endif | |
2165 | } | |
2166 | ||
e766c8a9 | 2167 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 2168 | { |
519cb848 | 2169 | // actually this is a windows-only concept |
e9576ca5 SC |
2170 | return NULL; |
2171 | } | |
2172 | ||
e9576ca5 | 2173 | // Coordinates relative to the window |
e766c8a9 | 2174 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 2175 | { |
e40298d5 | 2176 | // We really don't move the mouse programmatically under Mac. |
e9576ca5 SC |
2177 | } |
2178 | ||
facd6764 | 2179 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 2180 | { |
be346c26 | 2181 | #if TARGET_API_MAC_OSX |
789ae0cf | 2182 | if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) ) |
94abc21f | 2183 | { |
facd6764 | 2184 | event.Skip() ; |
94abc21f SC |
2185 | } |
2186 | else | |
be346c26 | 2187 | #endif |
7ebf5540 | 2188 | { |
8b573fb8 | 2189 | event.GetDC()->Clear() ; |
7ebf5540 | 2190 | } |
1c310985 SC |
2191 | } |
2192 | ||
2193 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2194 | { | |
af6b7b80 | 2195 | event.Skip() ; |
e9576ca5 SC |
2196 | } |
2197 | ||
e766c8a9 | 2198 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 2199 | { |
1c310985 SC |
2200 | if ( orient == wxHORIZONTAL ) |
2201 | { | |
2202 | if ( m_hScrollBar ) | |
2203 | return m_hScrollBar->GetThumbPosition() ; | |
2204 | } | |
2205 | else | |
2206 | { | |
2207 | if ( m_vScrollBar ) | |
2208 | return m_vScrollBar->GetThumbPosition() ; | |
2209 | } | |
e9576ca5 SC |
2210 | return 0; |
2211 | } | |
2212 | ||
2213 | // This now returns the whole range, not just the number | |
2214 | // of positions that we can scroll. | |
e766c8a9 | 2215 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 2216 | { |
1c310985 SC |
2217 | if ( orient == wxHORIZONTAL ) |
2218 | { | |
2219 | if ( m_hScrollBar ) | |
2220 | return m_hScrollBar->GetRange() ; | |
2221 | } | |
2222 | else | |
2223 | { | |
2224 | if ( m_vScrollBar ) | |
2225 | return m_vScrollBar->GetRange() ; | |
2226 | } | |
e9576ca5 SC |
2227 | return 0; |
2228 | } | |
2229 | ||
e766c8a9 | 2230 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 2231 | { |
1c310985 SC |
2232 | if ( orient == wxHORIZONTAL ) |
2233 | { | |
2234 | if ( m_hScrollBar ) | |
2235 | return m_hScrollBar->GetThumbSize() ; | |
2236 | } | |
2237 | else | |
2238 | { | |
2239 | if ( m_vScrollBar ) | |
2240 | return m_vScrollBar->GetThumbSize() ; | |
2241 | } | |
e9576ca5 SC |
2242 | return 0; |
2243 | } | |
2244 | ||
e766c8a9 | 2245 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 2246 | { |
1c310985 | 2247 | if ( orient == wxHORIZONTAL ) |
6264b550 | 2248 | { |
1c310985 SC |
2249 | if ( m_hScrollBar ) |
2250 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
2251 | } |
2252 | else | |
2253 | { | |
1c310985 SC |
2254 | if ( m_vScrollBar ) |
2255 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 2256 | } |
2f1ae414 SC |
2257 | } |
2258 | ||
c79aad8b SC |
2259 | // |
2260 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
2261 | // our own window origin is at leftOrigin/rightOrigin | |
2262 | // | |
2263 | ||
2264 | void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) | |
2f1ae414 | 2265 | { |
1c310985 | 2266 | if( IsTopLevel() ) |
6264b550 | 2267 | return ; |
8b573fb8 | 2268 | |
fd926bcc | 2269 | Rect rect ; |
c79aad8b SC |
2270 | bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; |
2271 | bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
2272 | ||
8b573fb8 | 2273 | m_peer->GetRect( &rect ) ; |
8f39b6c4 SC |
2274 | // back to the surrounding frame rectangle |
2275 | InsetRect( &rect, -1 , -1 ) ; | |
fd926bcc | 2276 | |
c79aad8b | 2277 | #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
91ae6e3a | 2278 | if ( UMAGetSystemVersion() >= 0x1030 ) |
c79aad8b | 2279 | { |
8f39b6c4 SC |
2280 | CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , |
2281 | rect.bottom - rect.top ) ; | |
2282 | ||
c79aad8b SC |
2283 | HIThemeFrameDrawInfo info ; |
2284 | memset( &info, 0 , sizeof( info ) ) ; | |
2285 | ||
2286 | info.version = 0 ; | |
2287 | info.kind = 0 ; | |
2288 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2289 | info.isFocused = hasFocus ; | |
c79aad8b SC |
2290 | |
2291 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
2292 | wxASSERT( cgContext ) ; | |
2293 | ||
2294 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2295 | { | |
c79aad8b | 2296 | info.kind = kHIThemeFrameTextFieldSquare ; |
8f39b6c4 | 2297 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; |
c79aad8b SC |
2298 | } |
2299 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2300 | { | |
c79aad8b | 2301 | info.kind = kHIThemeFrameListBox ; |
c79aad8b SC |
2302 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; |
2303 | } | |
2304 | else if ( hasFocus ) | |
2305 | { | |
c79aad8b SC |
2306 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; |
2307 | } | |
2308 | ||
2309 | m_peer->GetRect( &rect ) ; | |
2310 | if ( hasBothScrollbars ) | |
2311 | { | |
c79aad8b | 2312 | int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ; |
8f39b6c4 SC |
2313 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; |
2314 | CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; | |
c79aad8b SC |
2315 | HIThemeGrowBoxDrawInfo info ; |
2316 | memset( &info, 0 , sizeof( info ) ) ; | |
2317 | info.version = 0 ; | |
2318 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2319 | info.kind = kHIThemeGrowBoxKindNone ; | |
2320 | info.size = kHIThemeGrowBoxSizeNormal ; | |
2321 | info.direction = kThemeGrowRight | kThemeGrowDown ; | |
2322 | HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2323 | } | |
2324 | } | |
2325 | else | |
2326 | #endif | |
fd926bcc SC |
2327 | { |
2328 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1f1c8bd4 | 2329 | if (top ) |
fd926bcc SC |
2330 | { |
2331 | wxPoint pt(0,0) ; | |
2332 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
1f1c8bd4 | 2333 | OffsetRect( &rect , pt.x , pt.y ) ; |
fd926bcc | 2334 | } |
8b573fb8 | 2335 | |
c79aad8b SC |
2336 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
2337 | { | |
8f39b6c4 | 2338 | DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
c79aad8b SC |
2339 | } |
2340 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2341 | { | |
c79aad8b SC |
2342 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
2343 | } | |
2344 | ||
2345 | if ( hasFocus ) | |
2346 | { | |
8f39b6c4 | 2347 | DrawThemeFocusRect( &rect , true ) ; |
c79aad8b | 2348 | } |
8f39b6c4 | 2349 | |
c79aad8b SC |
2350 | if ( hasBothScrollbars ) |
2351 | { | |
2352 | // GetThemeStandaloneGrowBoxBounds | |
2353 | //DrawThemeStandaloneNoGrowBox | |
2354 | } | |
eec462f8 | 2355 | } |
8208e181 SC |
2356 | } |
2357 | ||
abda5788 SC |
2358 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
2359 | { | |
2360 | if ( child == m_hScrollBar ) | |
2361 | m_hScrollBar = NULL ; | |
2362 | if ( child == m_vScrollBar ) | |
2363 | m_vScrollBar = NULL ; | |
14c9cbdb | 2364 | |
abda5788 SC |
2365 | wxWindowBase::RemoveChild( child ) ; |
2366 | } | |
2367 | ||
e9576ca5 | 2368 | // New function that will replace some of the above. |
e766c8a9 | 2369 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
2370 | int range, bool refresh) |
2371 | { | |
e40298d5 JS |
2372 | if ( orient == wxHORIZONTAL ) |
2373 | { | |
2374 | if ( m_hScrollBar ) | |
6264b550 | 2375 | { |
e40298d5 | 2376 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2377 | { |
e40298d5 JS |
2378 | if ( m_hScrollBar->IsShown() ) |
2379 | m_hScrollBar->Show(false) ; | |
2380 | } | |
2381 | else | |
2382 | { | |
2383 | if ( !m_hScrollBar->IsShown() ) | |
2384 | m_hScrollBar->Show(true) ; | |
6264b550 | 2385 | } |
11ca2edf | 2386 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2387 | } |
e40298d5 JS |
2388 | } |
2389 | else | |
2390 | { | |
2391 | if ( m_vScrollBar ) | |
6264b550 | 2392 | { |
e40298d5 | 2393 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2394 | { |
e40298d5 JS |
2395 | if ( m_vScrollBar->IsShown() ) |
2396 | m_vScrollBar->Show(false) ; | |
2397 | } | |
2398 | else | |
2399 | { | |
2400 | if ( !m_vScrollBar->IsShown() ) | |
2401 | m_vScrollBar->Show(true) ; | |
6264b550 | 2402 | } |
11ca2edf | 2403 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2404 | } |
e40298d5 JS |
2405 | } |
2406 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
2407 | } |
2408 | ||
2409 | // Does a physical scroll | |
e766c8a9 | 2410 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 2411 | { |
ba87f54c SC |
2412 | if( dx == 0 && dy ==0 ) |
2413 | return ; | |
8b573fb8 | 2414 | |
6264b550 RR |
2415 | int width , height ; |
2416 | GetClientSize( &width , &height ) ; | |
adb8a71b | 2417 | #if TARGET_API_MAC_OSX |
92346151 SC |
2418 | if ( 1 /* m_peer->IsCompositing() */ ) |
2419 | { | |
002c9672 | 2420 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control |
8b573fb8 | 2421 | // area is scrolled, this does not occur if width and height are 2 pixels less, |
002c9672 | 2422 | // TODO write optimal workaround |
42ef83fa | 2423 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; |
8b573fb8 | 2424 | if ( rect ) |
adb8a71b | 2425 | { |
5ca0d812 | 2426 | scrollrect.Intersect( *rect ) ; |
adb8a71b | 2427 | } |
5ca0d812 | 2428 | if ( m_peer->GetNeedsDisplay() ) |
002c9672 SC |
2429 | { |
2430 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2431 | // either immediate redraw or full invalidate | |
2432 | #if 1 | |
2433 | // is the better overall solution, as it does not slow down scrolling | |
1f1c8bd4 | 2434 | m_peer->SetNeedsDisplay() ; |
002c9672 | 2435 | #else |
8b573fb8 | 2436 | // this would be the preferred version for fast drawing controls |
92346151 | 2437 | |
f474cc8c SC |
2438 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
2439 | if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) | |
42ef83fa | 2440 | HIViewRender(m_peer->GetControlRef()) ; |
f474cc8c SC |
2441 | else |
2442 | #endif | |
2443 | Update() ; | |
002c9672 SC |
2444 | #endif |
2445 | } | |
84e5d27d SC |
2446 | // as the native control might be not a 0/0 wx window coordinates, we have to offset |
2447 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
92346151 SC |
2448 | m_peer->ScrollRect( (&scrollrect) , dx , dy ) ; |
2449 | ||
2450 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2451 | // either immediate redraw or full invalidate | |
2452 | #if 0 | |
2453 | // is the better overall solution, as it does not slow down scrolling | |
2454 | m_peer->SetNeedsDisplay() ; | |
adb8a71b | 2455 | #else |
92346151 SC |
2456 | // this would be the preferred version for fast drawing controls |
2457 | ||
f474cc8c SC |
2458 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
2459 | if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) | |
2460 | HIViewRender(m_peer->GetControlRef()) ; | |
2461 | else | |
2462 | #endif | |
d35bd499 | 2463 | Update() ; |
f474cc8c | 2464 | |
92346151 SC |
2465 | #endif |
2466 | } | |
2467 | else | |
2468 | #endif | |
2469 | { | |
6ed71b4f | 2470 | |
facd6764 | 2471 | wxPoint pos; |
8b573fb8 | 2472 | pos.x = pos.y = 0; |
430e1eed | 2473 | |
facd6764 | 2474 | Rect scrollrect; |
6264b550 | 2475 | RgnHandle updateRgn = NewRgn() ; |
430e1eed | 2476 | |
adb8a71b | 2477 | { |
430e1eed SC |
2478 | wxClientDC dc(this) ; |
2479 | wxMacPortSetter helper(&dc) ; | |
8b573fb8 | 2480 | |
92346151 SC |
2481 | m_peer->GetRectInWindowCoords( &scrollrect ) ; |
2482 | //scrollrect.top += MacGetTopBorderSize() ; | |
2483 | //scrollrect.left += MacGetLeftBorderSize() ; | |
430e1eed SC |
2484 | scrollrect.bottom = scrollrect.top + height ; |
2485 | scrollrect.right = scrollrect.left + width ; | |
8b573fb8 | 2486 | |
430e1eed SC |
2487 | if ( rect ) |
2488 | { | |
2489 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2490 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2491 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2492 | } | |
2493 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
20b69855 SC |
2494 | |
2495 | // now scroll the former update region as well and add the new update region | |
2496 | ||
2497 | WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ; | |
2498 | RgnHandle formerUpdateRgn = NewRgn() ; | |
2499 | RgnHandle scrollRgn = NewRgn() ; | |
2500 | RectRgn( scrollRgn , &scrollrect ) ; | |
2501 | GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; | |
2502 | Point pt = {0,0} ; | |
2503 | LocalToGlobal( &pt ) ; | |
2504 | OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; | |
2505 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2506 | if ( !EmptyRgn( formerUpdateRgn ) ) | |
2507 | { | |
2508 | MacOffsetRgn( formerUpdateRgn , dx , dy ) ; | |
2509 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2510 | InvalWindowRgn(rootWindow , formerUpdateRgn ) ; | |
2511 | } | |
2512 | InvalWindowRgn(rootWindow , updateRgn ) ; | |
2513 | DisposeRgn( updateRgn ) ; | |
2514 | DisposeRgn( formerUpdateRgn ) ; | |
2515 | DisposeRgn( scrollRgn ) ; | |
ba87f54c | 2516 | } |
92346151 | 2517 | Update() ; |
6264b550 | 2518 | } |
6ed71b4f | 2519 | |
71f2fb52 | 2520 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 2521 | { |
9bd1404d | 2522 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
2523 | if (child == m_vScrollBar) continue; |
2524 | if (child == m_hScrollBar) continue; | |
2525 | if (child->IsTopLevel()) continue; | |
6ed71b4f | 2526 | |
6264b550 RR |
2527 | int x,y; |
2528 | child->GetPosition( &x, &y ); | |
2529 | int w,h; | |
2530 | child->GetSize( &w, &h ); | |
00f55394 SC |
2531 | if (rect) |
2532 | { | |
2533 | wxRect rc(x,y,w,h); | |
2534 | if (rect->Intersects(rc)) | |
2535 | child->SetSize( x+dx, y+dy, w, h ); | |
2536 | } | |
2537 | else | |
2538 | { | |
8b573fb8 VZ |
2539 | child->SetSize( x+dx, y+dy, w, h ); |
2540 | } | |
6264b550 | 2541 | } |
e9576ca5 SC |
2542 | } |
2543 | ||
e766c8a9 | 2544 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 2545 | { |
687706f5 | 2546 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) |
6264b550 RR |
2547 | { |
2548 | wxScrollWinEvent wevent; | |
2549 | wevent.SetPosition(event.GetPosition()); | |
2550 | wevent.SetOrientation(event.GetOrientation()); | |
687706f5 KH |
2551 | wevent.SetEventObject(this); |
2552 | ||
2553 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
2554 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
2555 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
2556 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
2557 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
2558 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
2559 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
2560 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
2561 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
2562 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
2563 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
2564 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
2565 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
2566 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
2567 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
2568 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
6ed71b4f VZ |
2569 | |
2570 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
2571 | } |
2572 | } | |
2573 | ||
e9576ca5 | 2574 | // Get the window with the focus |
0fe02759 | 2575 | wxWindowMac *wxWindowBase::DoFindFocus() |
e9576ca5 | 2576 | { |
f1d527c1 SC |
2577 | ControlRef control ; |
2578 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2579 | return wxFindControlFromMacControl( control ) ; | |
519cb848 SC |
2580 | } |
2581 | ||
e766c8a9 | 2582 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
2583 | { |
2584 | // panel wants to track the window which was the last to have focus in it, | |
2585 | // so we want to set ourselves as the window which last had focus | |
2586 | // | |
2587 | // notice that it's also important to do it upwards the tree becaus | |
2588 | // otherwise when the top level panel gets focus, it won't set it back to | |
2589 | // us, but to some other sibling | |
6ed71b4f | 2590 | |
c1fb8167 SC |
2591 | // CS:don't know if this is still needed: |
2592 | //wxChildFocusEvent eventFocus(this); | |
2593 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b | 2594 | |
5ca0d812 SC |
2595 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) |
2596 | { | |
ff3795ee | 2597 | #if !wxMAC_USE_CORE_GRAPHICS |
788e118f | 2598 | wxMacWindowStateSaver sv( this ) ; |
6449b3a8 SC |
2599 | Rect rect ; |
2600 | m_peer->GetRect( &rect ) ; | |
8f39b6c4 SC |
2601 |