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