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