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