]>
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 | WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); | |
632 | ||
633 | static MacControlMap wxWinMacControlList; | |
634 | ||
635 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
636 | { | |
637 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
638 | ||
639 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
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 | wxWinMacControlList[inControl] = control; | |
649 | } | |
650 | ||
651 | void wxRemoveMacControlAssociation(wxWindow *control) | |
652 | { | |
653 | // iterate over all the elements in the class | |
654 | // is the iterator stable ? as we might have two associations pointing to the same wxWindow | |
655 | // we should go on... | |
656 | ||
657 | bool found = true ; | |
658 | while( found ) | |
659 | { | |
660 | found = false ; | |
661 | MacControlMap::iterator it; | |
662 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
663 | { | |
664 | if ( it->second == control ) | |
665 | { | |
666 | wxWinMacControlList.erase(it); | |
667 | found = true ; | |
668 | break; | |
669 | } | |
670 | } | |
671 | } | |
672 | } | |
673 | ||
674 | // ---------------------------------------------------------------------------- | |
675 | // constructors and such | |
676 | // ---------------------------------------------------------------------------- | |
677 | ||
678 | wxWindowMac::wxWindowMac() | |
679 | { | |
680 | Init(); | |
681 | } | |
682 | ||
683 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
684 | wxWindowID id, | |
685 | const wxPoint& pos , | |
686 | const wxSize& size , | |
687 | long style , | |
688 | const wxString& name ) | |
689 | { | |
690 | Init(); | |
691 | Create(parent, id, pos, size, style, name); | |
692 | } | |
693 | ||
694 | void wxWindowMac::Init() | |
695 | { | |
696 | m_peer = NULL ; | |
697 | m_frozenness = 0 ; | |
698 | #if WXWIN_COMPATIBILITY_2_4 | |
699 | m_backgroundTransparent = false; | |
700 | #endif | |
701 | ||
702 | // as all windows are created with WS_VISIBLE style... | |
703 | m_isShown = true; | |
704 | ||
705 | m_hScrollBar = NULL ; | |
706 | m_vScrollBar = NULL ; | |
707 | m_macBackgroundBrush = wxNullBrush ; | |
708 | ||
709 | m_macIsUserPane = true; | |
710 | #if wxMAC_USE_CORE_GRAPHICS | |
711 | m_cgContextRef = NULL ; | |
712 | #endif | |
713 | m_clipChildren = false ; | |
714 | m_cachedClippedRectValid = false ; | |
715 | // we need a valid font for the encodings | |
716 | wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
717 | } | |
718 | ||
719 | // Destructor | |
720 | wxWindowMac::~wxWindowMac() | |
721 | { | |
722 | SendDestroyEvent(); | |
723 | ||
724 | m_isBeingDeleted = true; | |
725 | ||
726 | MacInvalidateBorders() ; | |
727 | ||
728 | #ifndef __WXUNIVERSAL__ | |
729 | // VS: make sure there's no wxFrame with last focus set to us: | |
730 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
731 | { | |
732 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
733 | if ( frame ) | |
734 | { | |
735 | if ( frame->GetLastFocus() == this ) | |
736 | { | |
737 | frame->SetLastFocus((wxWindow*)NULL); | |
738 | } | |
739 | break; | |
740 | } | |
741 | } | |
742 | #endif // __WXUNIVERSAL__ | |
743 | ||
744 | // destroy children before destroying this window itself | |
745 | DestroyChildren(); | |
746 | ||
747 | // wxRemoveMacControlAssociation( this ) ; | |
748 | // If we delete an item, we should initialize the parent panel, | |
749 | // because it could now be invalid. | |
750 | wxWindow *parent = GetParent() ; | |
751 | if ( parent ) | |
752 | { | |
753 | if (parent->GetDefaultItem() == (wxButton*) this) | |
754 | parent->SetDefaultItem(NULL); | |
755 | } | |
756 | if ( m_peer && m_peer->Ok() ) | |
757 | { | |
758 | // in case the callback might be called during destruction | |
759 | wxRemoveMacControlAssociation( this) ; | |
760 | // we currently are not using this hook | |
761 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
762 | m_peer->Dispose() ; | |
763 | } | |
764 | ||
765 | if ( g_MacLastWindow == this ) | |
766 | { | |
767 | g_MacLastWindow = NULL ; | |
768 | } | |
769 | ||
770 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; | |
771 | if ( frame ) | |
772 | { | |
773 | if ( frame->GetLastFocus() == this ) | |
774 | frame->SetLastFocus( NULL ) ; | |
775 | } | |
776 | ||
777 | // delete our drop target if we've got one | |
778 | #if wxUSE_DRAG_AND_DROP | |
779 | if ( m_dropTarget != NULL ) | |
780 | { | |
781 | delete m_dropTarget; | |
782 | m_dropTarget = NULL; | |
783 | } | |
784 | #endif // wxUSE_DRAG_AND_DROP | |
785 | delete m_peer ; | |
786 | } | |
787 | ||
788 | WXWidget wxWindowMac::GetHandle() const | |
789 | { | |
790 | return (WXWidget) m_peer->GetControlRef() ; | |
791 | } | |
792 | ||
793 | ||
794 | void wxWindowMac::MacInstallEventHandler( WXWidget control ) | |
795 | { | |
796 | wxAssociateControlWithMacControl( (ControlRef) control , this ) ; | |
797 | InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(), | |
798 | GetEventTypeCount(eventList), eventList, this, | |
799 | (EventHandlerRef *)&m_macControlEventHandler); | |
800 | #if !TARGET_API_MAC_OSX | |
801 | if ( (ControlRef) control == m_peer->GetControlRef() ) | |
802 | { | |
803 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,GetwxMacControlUserPaneDrawProc()) ; | |
804 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,GetwxMacControlUserPaneHitTestProc()) ; | |
805 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,GetwxMacControlUserPaneTrackingProc()) ; | |
806 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,GetwxMacControlUserPaneIdleProc()) ; | |
807 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,GetwxMacControlUserPaneKeyDownProc()) ; | |
808 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,GetwxMacControlUserPaneActivateProc()) ; | |
809 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,GetwxMacControlUserPaneFocusProc()) ; | |
810 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,GetwxMacControlUserPaneBackgroundProc()) ; | |
811 | } | |
812 | #endif | |
813 | ||
814 | } | |
815 | ||
816 | // Constructor | |
817 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, | |
818 | const wxPoint& pos, | |
819 | const wxSize& size, | |
820 | long style, | |
821 | const wxString& name) | |
822 | { | |
823 | wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); | |
824 | ||
825 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
826 | return false; | |
827 | ||
828 | m_windowVariant = parent->GetWindowVariant() ; | |
829 | ||
830 | if ( m_macIsUserPane ) | |
831 | { | |
832 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
833 | ||
834 | UInt32 features = 0 | |
835 | | kControlSupportsEmbedding | |
836 | | kControlSupportsLiveFeedback | |
837 | | kControlGetsFocusOnClick | |
838 | // | kControlHasSpecialBackground | |
839 | // | kControlSupportsCalcBestRect | |
840 | | kControlHandlesTracking | |
841 | | kControlSupportsFocus | |
842 | | kControlWantsActivate | |
843 | | kControlWantsIdle | |
844 | ; | |
845 | ||
846 | m_peer = new wxMacControl(this) ; | |
847 | ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); | |
848 | ||
849 | ||
850 | MacPostControlCreate(pos,size) ; | |
851 | } | |
852 | #ifndef __WXUNIVERSAL__ | |
853 | // Don't give scrollbars to wxControls unless they ask for them | |
854 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
855 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
856 | { | |
857 | MacCreateScrollBars( style ) ; | |
858 | } | |
859 | #endif | |
860 | ||
861 | wxWindowCreateEvent event(this); | |
862 | GetEventHandler()->AddPendingEvent(event); | |
863 | ||
864 | return true; | |
865 | } | |
866 | ||
867 | void wxWindowMac::MacChildAdded() | |
868 | { | |
869 | if ( m_vScrollBar ) | |
870 | { | |
871 | m_vScrollBar->Raise() ; | |
872 | } | |
873 | if ( m_hScrollBar ) | |
874 | { | |
875 | m_hScrollBar->Raise() ; | |
876 | } | |
877 | ||
878 | } | |
879 | ||
880 | void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) | |
881 | { | |
882 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; | |
883 | ||
884 | m_peer->SetReference( (long) this ) ; | |
885 | GetParent()->AddChild(this); | |
886 | ||
887 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); | |
888 | ||
889 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
890 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
891 | ::EmbedControl( m_peer->GetControlRef() , container ) ; | |
892 | GetParent()->MacChildAdded() ; | |
893 | ||
894 | // adjust font, controlsize etc | |
895 | DoSetWindowVariant( m_windowVariant ) ; | |
896 | ||
897 | m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; | |
898 | ||
899 | if (!m_macIsUserPane) | |
900 | { | |
901 | SetInitialBestSize(size); | |
902 | } | |
903 | ||
904 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
905 | } | |
906 | ||
907 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
908 | { | |
909 | // Don't assert, in case we set the window variant before | |
910 | // the window is created | |
911 | // wxASSERT( m_peer->Ok() ) ; | |
912 | ||
913 | m_windowVariant = variant ; | |
914 | ||
915 | if (m_peer == NULL || !m_peer->Ok()) | |
916 | return; | |
917 | ||
918 | ControlSize size ; | |
919 | ThemeFontID themeFont = kThemeSystemFont ; | |
920 | ||
921 | // we will get that from the settings later | |
922 | // and make this NORMAL later, but first | |
923 | // we have a few calculations that we must fix | |
924 | ||
925 | switch ( variant ) | |
926 | { | |
927 | case wxWINDOW_VARIANT_NORMAL : | |
928 | size = kControlSizeNormal; | |
929 | themeFont = kThemeSystemFont ; | |
930 | break ; | |
931 | case wxWINDOW_VARIANT_SMALL : | |
932 | size = kControlSizeSmall; | |
933 | themeFont = kThemeSmallSystemFont ; | |
934 | break ; | |
935 | case wxWINDOW_VARIANT_MINI : | |
936 | if (UMAGetSystemVersion() >= 0x1030 ) | |
937 | { | |
938 | // not always defined in the headers | |
939 | size = 3 ; | |
940 | themeFont = 109 ; | |
941 | } | |
942 | else | |
943 | { | |
944 | size = kControlSizeSmall; | |
945 | themeFont = kThemeSmallSystemFont ; | |
946 | } | |
947 | break ; | |
948 | case wxWINDOW_VARIANT_LARGE : | |
949 | size = kControlSizeLarge; | |
950 | themeFont = kThemeSystemFont ; | |
951 | break ; | |
952 | default: | |
953 | wxFAIL_MSG(_T("unexpected window variant")); | |
954 | break ; | |
955 | } | |
956 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ; | |
957 | ||
958 | wxFont font ; | |
959 | font.MacCreateThemeFont( themeFont ) ; | |
960 | SetFont( font ) ; | |
961 | } | |
962 | ||
963 | void wxWindowMac::MacUpdateControlFont() | |
964 | { | |
965 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; | |
966 | Refresh() ; | |
967 | } | |
968 | ||
969 | bool wxWindowMac::SetFont(const wxFont& font) | |
970 | { | |
971 | bool retval = wxWindowBase::SetFont( font ) ; | |
972 | ||
973 | MacUpdateControlFont() ; | |
974 | ||
975 | return retval; | |
976 | } | |
977 | ||
978 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
979 | { | |
980 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
981 | return false ; | |
982 | ||
983 | MacUpdateControlFont() ; | |
984 | ||
985 | return true ; | |
986 | } | |
987 | ||
988 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
989 | { | |
990 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
991 | return false ; | |
992 | ||
993 | wxBrush brush ; | |
994 | wxColour newCol(GetBackgroundColour()); | |
995 | if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
996 | { | |
997 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; | |
998 | } | |
999 | else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
1000 | { | |
1001 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
1002 | } | |
1003 | else | |
1004 | { | |
1005 | brush.SetColour( newCol ) ; | |
1006 | } | |
1007 | MacSetBackgroundBrush( brush ) ; | |
1008 | ||
1009 | MacUpdateControlFont() ; | |
1010 | ||
1011 | return true ; | |
1012 | } | |
1013 | ||
1014 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) | |
1015 | { | |
1016 | m_macBackgroundBrush = brush ; | |
1017 | m_peer->SetBackground( brush ) ; | |
1018 | } | |
1019 | ||
1020 | bool wxWindowMac::MacCanFocus() const | |
1021 | { | |
1022 | // there is currently no way to determine whether the window is running in full keyboard | |
1023 | // access mode, therefore we cannot rely on these features, yet the only other way would be | |
1024 | // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems | |
1025 | // in event handlers... | |
1026 | UInt32 features = 0 ; | |
1027 | m_peer->GetFeatures( & features ) ; | |
1028 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; | |
1029 | } | |
1030 | ||
1031 | ||
1032 | void wxWindowMac::SetFocus() | |
1033 | { | |
1034 | if ( AcceptsFocus() ) | |
1035 | { | |
1036 | ||
1037 | wxWindow* former = FindFocus() ; | |
1038 | if ( former == this ) | |
1039 | return ; | |
1040 | ||
1041 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; | |
1042 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only | |
1043 | // leave in case of an error | |
1044 | if ( err == errCouldntSetFocus ) | |
1045 | return ; | |
1046 | ||
1047 | #if !TARGET_API_MAC_OSX | |
1048 | // emulate carbon events when running under carbonlib where they are not natively available | |
1049 | if ( former ) | |
1050 | { | |
1051 | EventRef evRef = NULL ; | |
1052 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1053 | &evRef ) ); | |
1054 | ||
1055 | wxMacCarbonEvent cEvent( evRef ) ; | |
1056 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1057 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
1058 | ||
1059 | wxMacWindowEventHandler( NULL , evRef , former ) ; | |
1060 | ReleaseEvent(evRef) ; | |
1061 | } | |
1062 | // send new focus event | |
1063 | { | |
1064 | EventRef evRef = NULL ; | |
1065 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1066 | &evRef ) ); | |
1067 | ||
1068 | wxMacCarbonEvent cEvent( evRef ) ; | |
1069 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1070 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
1071 | ||
1072 | wxMacWindowEventHandler( NULL , evRef , this ) ; | |
1073 | ReleaseEvent(evRef) ; | |
1074 | } | |
1075 | #endif | |
1076 | } | |
1077 | } | |
1078 | ||
1079 | ||
1080 | void wxWindowMac::DoCaptureMouse() | |
1081 | { | |
1082 | wxApp::s_captureWindow = this ; | |
1083 | } | |
1084 | ||
1085 | wxWindow* wxWindowBase::GetCapture() | |
1086 | { | |
1087 | return wxApp::s_captureWindow ; | |
1088 | } | |
1089 | ||
1090 | void wxWindowMac::DoReleaseMouse() | |
1091 | { | |
1092 | wxApp::s_captureWindow = NULL ; | |
1093 | } | |
1094 | ||
1095 | #if wxUSE_DRAG_AND_DROP | |
1096 | ||
1097 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) | |
1098 | { | |
1099 | if ( m_dropTarget != 0 ) { | |
1100 | delete m_dropTarget; | |
1101 | } | |
1102 | ||
1103 | m_dropTarget = pDropTarget; | |
1104 | if ( m_dropTarget != 0 ) | |
1105 | { | |
1106 | // TODO | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | #endif | |
1111 | ||
1112 | // Old style file-manager drag&drop | |
1113 | void wxWindowMac::DragAcceptFiles(bool accept) | |
1114 | { | |
1115 | // TODO | |
1116 | } | |
1117 | ||
1118 | // Returns the size of the native control. In the case of the toplevel window | |
1119 | // this is the content area root control | |
1120 | ||
1121 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, | |
1122 | int& w, int& h) const | |
1123 | { | |
1124 | wxFAIL_MSG( wxT("Not supported anymore") ) ; | |
1125 | } | |
1126 | ||
1127 | // From a wx position / size calculate the appropriate size of the native control | |
1128 | ||
1129 | bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, | |
1130 | const wxSize& size, | |
1131 | int& x, int& y, | |
1132 | int& w, int& h , bool adjustOrigin ) const | |
1133 | { | |
1134 | bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; | |
1135 | ||
1136 | // the desired size, minus the border pixels gives the correct size of the control | |
1137 | ||
1138 | x = (int)pos.x; | |
1139 | y = (int)pos.y; | |
1140 | // todo the default calls may be used as soon as PostCreateControl Is moved here | |
1141 | w = wxMax(size.x,0) ; // WidthDefault( size.x ); | |
1142 | h = wxMax(size.y,0) ; // HeightDefault( size.y ) ; | |
1143 | ||
1144 | if ( !isCompositing ) | |
1145 | GetParent()->MacWindowToRootWindow( &x , &y ) ; | |
1146 | ||
1147 | x += MacGetLeftBorderSize() ; | |
1148 | y += MacGetTopBorderSize() ; | |
1149 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1150 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1151 | ||
1152 | if ( adjustOrigin ) | |
1153 | AdjustForParentClientOrigin( x , y ) ; | |
1154 | ||
1155 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
1156 | if ( !GetParent()->IsTopLevel() ) | |
1157 | { | |
1158 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1159 | y -= GetParent()->MacGetTopBorderSize() ; | |
1160 | } | |
1161 | ||
1162 | return true ; | |
1163 | } | |
1164 | ||
1165 | // Get window size (not client size) | |
1166 | void wxWindowMac::DoGetSize(int *x, int *y) const | |
1167 | { | |
1168 | Rect bounds ; | |
1169 | m_peer->GetRect( &bounds ) ; | |
1170 | ||
1171 | if(x) *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1172 | if(y) *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1173 | } | |
1174 | ||
1175 | // get the position of the bounds of this window in client coordinates of its parent | |
1176 | void wxWindowMac::DoGetPosition(int *x, int *y) const | |
1177 | { | |
1178 | Rect bounds ; | |
1179 | m_peer->GetRect( &bounds ) ; | |
1180 | ||
1181 | int x1 = bounds.left ; | |
1182 | int y1 = bounds.top ; | |
1183 | ||
1184 | // get the wx window position from the native one | |
1185 | x1 -= MacGetLeftBorderSize() ; | |
1186 | y1 -= MacGetTopBorderSize() ; | |
1187 | ||
1188 | if ( !IsTopLevel() ) | |
1189 | { | |
1190 | wxWindow *parent = GetParent(); | |
1191 | if ( parent ) | |
1192 | { | |
1193 | // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix | |
1194 | x1 += parent->MacGetLeftBorderSize() ; | |
1195 | y1 += parent->MacGetTopBorderSize() ; | |
1196 | // and now to client coordinates | |
1197 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1198 | x1 -= pt.x ; | |
1199 | y1 -= pt.y ; | |
1200 | } | |
1201 | } | |
1202 | if(x) *x = x1 ; | |
1203 | if(y) *y = y1 ; | |
1204 | } | |
1205 | ||
1206 | void wxWindowMac::DoScreenToClient(int *x, int *y) const | |
1207 | { | |
1208 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
1209 | ||
1210 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
1211 | ||
1212 | { | |
1213 | Point localwhere = {0,0} ; | |
1214 | ||
1215 | if(x) localwhere.h = * x ; | |
1216 | if(y) localwhere.v = * y ; | |
1217 | ||
1218 | QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ; | |
1219 | if(x) *x = localwhere.h ; | |
1220 | if(y) *y = localwhere.v ; | |
1221 | ||
1222 | } | |
1223 | MacRootWindowToWindow( x , y ) ; | |
1224 | ||
1225 | wxPoint origin = GetClientAreaOrigin() ; | |
1226 | if(x) *x -= origin.x ; | |
1227 | if(y) *y -= origin.y ; | |
1228 | } | |
1229 | ||
1230 | void wxWindowMac::DoClientToScreen(int *x, int *y) const | |
1231 | { | |
1232 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
1233 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
1234 | ||
1235 | wxPoint origin = GetClientAreaOrigin() ; | |
1236 | if(x) *x += origin.x ; | |
1237 | if(y) *y += origin.y ; | |
1238 | ||
1239 | MacWindowToRootWindow( x , y ) ; | |
1240 | ||
1241 | { | |
1242 | Point localwhere = { 0,0 }; | |
1243 | if(x) localwhere.h = * x ; | |
1244 | if(y) localwhere.v = * y ; | |
1245 | QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ; | |
1246 | if(x) *x = localwhere.h ; | |
1247 | if(y) *y = localwhere.v ; | |
1248 | } | |
1249 | } | |
1250 | ||
1251 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const | |
1252 | { | |
1253 | wxPoint origin = GetClientAreaOrigin() ; | |
1254 | if(x) *x += origin.x ; | |
1255 | if(y) *y += origin.y ; | |
1256 | ||
1257 | MacWindowToRootWindow( x , y ) ; | |
1258 | } | |
1259 | ||
1260 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1261 | { | |
1262 | MacRootWindowToWindow( x , y ) ; | |
1263 | ||
1264 | wxPoint origin = GetClientAreaOrigin() ; | |
1265 | if(x) *x -= origin.x ; | |
1266 | if(y) *y -= origin.y ; | |
1267 | } | |
1268 | ||
1269 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1270 | { | |
1271 | wxPoint pt ; | |
1272 | if ( x ) pt.x = *x ; | |
1273 | if ( y ) pt.y = *y ; | |
1274 | ||
1275 | if ( !IsTopLevel() ) | |
1276 | { | |
1277 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1278 | if (top) | |
1279 | { | |
1280 | pt.x -= MacGetLeftBorderSize() ; | |
1281 | pt.y -= MacGetTopBorderSize() ; | |
1282 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1283 | } | |
1284 | } | |
1285 | ||
1286 | if ( x ) *x = (int) pt.x ; | |
1287 | if ( y ) *y = (int) pt.y ; | |
1288 | } | |
1289 | ||
1290 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1291 | { | |
1292 | int x1 , y1 ; | |
1293 | if ( x ) x1 = *x ; | |
1294 | if ( y ) y1 = *y ; | |
1295 | MacWindowToRootWindow( &x1 , &y1 ) ; | |
1296 | if ( x ) *x = x1 ; | |
1297 | if ( y ) *y = y1 ; | |
1298 | } | |
1299 | ||
1300 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const | |
1301 | { | |
1302 | wxPoint pt ; | |
1303 | if ( x ) pt.x = *x ; | |
1304 | if ( y ) pt.y = *y ; | |
1305 | ||
1306 | if ( !IsTopLevel() ) | |
1307 | { | |
1308 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1309 | if (top) | |
1310 | { | |
1311 | wxMacControl::Convert( &pt , top->m_peer , m_peer ) ; | |
1312 | pt.x += MacGetLeftBorderSize() ; | |
1313 | pt.y += MacGetTopBorderSize() ; | |
1314 | } | |
1315 | } | |
1316 | ||
1317 | if ( x ) *x = (int) pt.x ; | |
1318 | if ( y ) *y = (int) pt.y ; | |
1319 | } | |
1320 | ||
1321 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const | |
1322 | { | |
1323 | int x1 , y1 ; | |
1324 | if ( x ) x1 = *x ; | |
1325 | if ( y ) y1 = *y ; | |
1326 | MacRootWindowToWindow( &x1 , &y1 ) ; | |
1327 | if ( x ) *x = x1 ; | |
1328 | if ( y ) *y = y1 ; | |
1329 | } | |
1330 | ||
1331 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) | |
1332 | { | |
1333 | RgnHandle rgn = NewRgn() ; | |
1334 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1335 | { | |
1336 | Rect structure ; | |
1337 | Rect content ; | |
1338 | GetRegionBounds( rgn , &content ) ; | |
1339 | m_peer->GetRect( &structure ) ; | |
1340 | OffsetRect( &structure, -structure.left , -structure.top ) ; | |
1341 | ||
1342 | left = content.left - structure.left ; | |
1343 | top = content.top - structure.top ; | |
1344 | right = structure.right - content.right ; | |
1345 | bottom = structure.bottom - content.bottom ; | |
1346 | } | |
1347 | else | |
1348 | { | |
1349 | left = top = right = bottom = 0 ; | |
1350 | } | |
1351 | DisposeRgn( rgn ) ; | |
1352 | } | |
1353 | ||
1354 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const | |
1355 | { | |
1356 | wxSize sizeTotal = size; | |
1357 | ||
1358 | RgnHandle rgn = NewRgn() ; | |
1359 | ||
1360 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1361 | { | |
1362 | Rect content ; | |
1363 | Rect structure ; | |
1364 | GetRegionBounds( rgn , &content ) ; | |
1365 | ||
1366 | m_peer->GetRect( &structure ) ; | |
1367 | // structure is in parent coordinates, but we only need width and height, so it's ok | |
1368 | ||
1369 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; | |
1370 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; | |
1371 | } | |
1372 | DisposeRgn( rgn ) ; | |
1373 | ||
1374 | sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; | |
1375 | sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
1376 | ||
1377 | return sizeTotal; | |
1378 | } | |
1379 | ||
1380 | ||
1381 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
1382 | void wxWindowMac::DoGetClientSize(int *x, int *y) const | |
1383 | { | |
1384 | int ww, hh; | |
1385 | ||
1386 | RgnHandle rgn = NewRgn() ; | |
1387 | Rect content ; | |
1388 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1389 | { | |
1390 | GetRegionBounds( rgn , &content ) ; | |
1391 | } | |
1392 | else | |
1393 | { | |
1394 | m_peer->GetRect( &content ) ; | |
1395 | } | |
1396 | DisposeRgn( rgn ) ; | |
1397 | ||
1398 | ww = content.right - content.left ; | |
1399 | hh = content.bottom - content.top ; | |
1400 | ||
1401 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
1402 | { | |
1403 | hh -= m_hScrollBar->GetSize().y ; | |
1404 | } | |
1405 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1406 | { | |
1407 | ww -= m_vScrollBar->GetSize().x ; | |
1408 | } | |
1409 | if(x) *x = ww; | |
1410 | if(y) *y = hh; | |
1411 | ||
1412 | } | |
1413 | ||
1414 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1415 | { | |
1416 | if (m_cursor == cursor) | |
1417 | return false; | |
1418 | ||
1419 | if (wxNullCursor == cursor) | |
1420 | { | |
1421 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
1422 | return false ; | |
1423 | } | |
1424 | else | |
1425 | { | |
1426 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
1427 | return false ; | |
1428 | } | |
1429 | ||
1430 | wxASSERT_MSG( m_cursor.Ok(), | |
1431 | wxT("cursor must be valid after call to the base version")); | |
1432 | ||
1433 | ||
1434 | wxWindowMac *mouseWin = 0 ; | |
1435 | { | |
1436 | wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ; | |
1437 | WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ; | |
1438 | CGrafPtr savePort ; | |
1439 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
1440 | ||
1441 | // TODO If we ever get a GetCurrentEvent.. replacement for the mouse | |
1442 | // position, use it... | |
1443 | ||
1444 | Point pt ; | |
1445 | GetMouse( &pt ) ; | |
1446 | ControlPartCode part ; | |
1447 | ControlRef control ; | |
1448 | control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ; | |
1449 | if ( control ) | |
1450 | mouseWin = wxFindControlFromMacControl( control ) ; | |
1451 | ||
1452 | if ( swapped ) | |
1453 | QDSwapPort( savePort , NULL ) ; | |
1454 | } | |
1455 | ||
1456 | if ( mouseWin == this && !wxIsBusy() ) | |
1457 | { | |
1458 | m_cursor.MacInstall() ; | |
1459 | } | |
1460 | ||
1461 | return true ; | |
1462 | } | |
1463 | ||
1464 | #if wxUSE_MENUS | |
1465 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1466 | { | |
1467 | menu->SetInvokingWindow(this); | |
1468 | menu->UpdateUI(); | |
1469 | ||
1470 | if ( x == -1 && y == -1 ) | |
1471 | { | |
1472 | wxPoint mouse = wxGetMousePosition(); | |
1473 | x = mouse.x; y = mouse.y; | |
1474 | } | |
1475 | else | |
1476 | { | |
1477 | ClientToScreen( &x , &y ) ; | |
1478 | } | |
1479 | ||
1480 | menu->MacBeforeDisplay( true ) ; | |
1481 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
1482 | if ( HiWord(menuResult) != 0 ) | |
1483 | { | |
1484 | MenuCommand id ; | |
1485 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
1486 | wxMenuItem* item = NULL ; | |
1487 | wxMenu* realmenu ; | |
1488 | item = menu->FindItem(id, &realmenu) ; | |
1489 | if (item->IsCheckable()) | |
1490 | { | |
1491 | item->Check( !item->IsChecked() ) ; | |
1492 | } | |
1493 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
1494 | } | |
1495 | menu->MacAfterDisplay( true ) ; | |
1496 | ||
1497 | menu->SetInvokingWindow(NULL); | |
1498 | ||
1499 | return true; | |
1500 | } | |
1501 | #endif | |
1502 | ||
1503 | // ---------------------------------------------------------------------------- | |
1504 | // tooltips | |
1505 | // ---------------------------------------------------------------------------- | |
1506 | ||
1507 | #if wxUSE_TOOLTIPS | |
1508 | ||
1509 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) | |
1510 | { | |
1511 | wxWindowBase::DoSetToolTip(tooltip); | |
1512 | ||
1513 | if ( m_tooltip ) | |
1514 | m_tooltip->SetWindow(this); | |
1515 | } | |
1516 | ||
1517 | #endif // wxUSE_TOOLTIPS | |
1518 | ||
1519 | void wxWindowMac::MacInvalidateBorders() | |
1520 | { | |
1521 | if ( m_peer == NULL ) | |
1522 | return ; | |
1523 | ||
1524 | bool vis = MacIsReallyShown() ; | |
1525 | if ( !vis ) | |
1526 | return ; | |
1527 | ||
1528 | int outerBorder = MacGetLeftBorderSize() ; | |
1529 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1530 | outerBorder += 4 ; | |
1531 | ||
1532 | if ( outerBorder == 0 ) | |
1533 | return ; | |
1534 | ||
1535 | // now we know that we have something to do at all | |
1536 | ||
1537 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1538 | RgnHandle updateInner = NewRgn() , | |
1539 | updateOuter = NewRgn() ; | |
1540 | ||
1541 | // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon | |
1542 | Rect rect ; | |
1543 | m_peer->GetRect( &rect ) ; | |
1544 | RectRgn( updateInner , &rect ) ; | |
1545 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1546 | RectRgn( updateOuter , &rect ) ; | |
1547 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1548 | #ifdef __WXMAC_OSX__ | |
1549 | GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ; | |
1550 | #else | |
1551 | WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ; | |
1552 | if ( tlw ) | |
1553 | InvalWindowRgn( tlw , updateOuter ) ; | |
1554 | #endif | |
1555 | DisposeRgn(updateOuter) ; | |
1556 | DisposeRgn(updateInner) ; | |
1557 | /* | |
1558 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
1559 | RectRgn( updateInner , &rect ) ; | |
1560 | InsetRect( &rect , -4 , -4 ) ; | |
1561 | RectRgn( updateOuter , &rect ) ; | |
1562 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1563 | wxPoint parent(0,0); | |
1564 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1565 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1566 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1567 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
1568 | DisposeRgn(updateOuter) ; | |
1569 | DisposeRgn(updateInner) ; | |
1570 | */ | |
1571 | /* | |
1572 | if ( m_peer ) | |
1573 | { | |
1574 | // deleting a window while it is shown invalidates the region occupied by border or | |
1575 | // focus | |
1576 | ||
1577 | if ( IsShown() && ( outerBorder > 0 ) ) | |
1578 | { | |
1579 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1580 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1581 | ||
1582 | Rect rect ; | |
1583 | ||
1584 | m_peer->GetRect( &rect ) ; | |
1585 | RectRgn( updateInner , &rect ) ; | |
1586 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1587 | RectRgn( updateOuter , &rect ) ; | |
1588 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1589 | wxPoint parent(0,0); | |
1590 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1591 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1592 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1593 | CopyRgn( updateOuter , updateTotal ) ; | |
1594 | ||
1595 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
1596 | DisposeRgn(updateOuter) ; | |
1597 | DisposeRgn(updateInner) ; | |
1598 | DisposeRgn(updateTotal) ; | |
1599 | } | |
1600 | } | |
1601 | */ | |
1602 | #if 0 | |
1603 | Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; | |
1604 | ||
1605 | int outerBorder = MacGetLeftBorderSize() ; | |
1606 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1607 | outerBorder += 4 ; | |
1608 | ||
1609 | if ( vis && ( outerBorder > 0 ) ) | |
1610 | { | |
1611 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1612 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1613 | ||
1614 | Rect rect ; | |
1615 | ||
1616 | m_peer->GetRect( &rect ) ; | |
1617 | RectRgn( updateInner , &rect ) ; | |
1618 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1619 | RectRgn( updateOuter , &rect ) ; | |
1620 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1621 | /* | |
1622 | wxPoint parent(0,0); | |
1623 | #if TARGET_API_MAC_OSX | |
1624 | // no offsetting needed when compositing | |
1625 | #else | |
1626 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1627 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1628 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1629 | #endif | |
1630 | */ | |
1631 | CopyRgn( updateOuter , updateTotal ) ; | |
1632 | ||
1633 | rect = r ; | |
1634 | RectRgn( updateInner , &rect ) ; | |
1635 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1636 | RectRgn( updateOuter , &rect ) ; | |
1637 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1638 | /* | |
1639 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1640 | */ | |
1641 | UnionRgn( updateOuter , updateTotal , updateTotal ) ; | |
1642 | ||
1643 | GetParent()->m_peer->SetNeedsDisplay( updateTotal ) ; | |
1644 | DisposeRgn(updateOuter) ; | |
1645 | DisposeRgn(updateInner) ; | |
1646 | DisposeRgn(updateTotal) ; | |
1647 | } | |
1648 | #endif | |
1649 | } | |
1650 | ||
1651 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1652 | { | |
1653 | // this is never called for a toplevel window, so we know we have a parent | |
1654 | int former_x , former_y , former_w, former_h ; | |
1655 | ||
1656 | // Get true coordinates of former position | |
1657 | DoGetPosition( &former_x , &former_y ) ; | |
1658 | DoGetSize( &former_w , &former_h ) ; | |
1659 | ||
1660 | wxWindow *parent = GetParent(); | |
1661 | if ( parent ) | |
1662 | { | |
1663 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1664 | former_x += pt.x ; | |
1665 | former_y += pt.y ; | |
1666 | } | |
1667 | ||
1668 | int actualWidth = width ; | |
1669 | int actualHeight = height ; | |
1670 | int actualX = x; | |
1671 | int actualY = y; | |
1672 | ||
1673 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
1674 | actualWidth = m_minWidth; | |
1675 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
1676 | actualHeight = m_minHeight; | |
1677 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
1678 | actualWidth = m_maxWidth; | |
1679 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
1680 | actualHeight = m_maxHeight; | |
1681 | ||
1682 | bool doMove = false ; | |
1683 | bool doResize = false ; | |
1684 | ||
1685 | if ( actualX != former_x || actualY != former_y ) | |
1686 | { | |
1687 | doMove = true ; | |
1688 | } | |
1689 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1690 | { | |
1691 | doResize = true ; | |
1692 | } | |
1693 | ||
1694 | if ( doMove || doResize ) | |
1695 | { | |
1696 | // as the borders are drawn outside the native control, we adjust now | |
1697 | ||
1698 | wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), | |
1699 | wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , | |
1700 | actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; | |
1701 | ||
1702 | Rect r ; | |
1703 | wxMacRectToNative( &bounds , &r ) ; | |
1704 | ||
1705 | if ( !GetParent()->IsTopLevel() ) | |
1706 | { | |
1707 | wxMacWindowToNative( GetParent() , &r ) ; | |
1708 | } | |
1709 | ||
1710 | MacInvalidateBorders() ; | |
1711 | ||
1712 | m_cachedClippedRectValid = false ; | |
1713 | m_peer->SetRect( &r ) ; | |
1714 | ||
1715 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
1716 | ||
1717 | MacInvalidateBorders() ; | |
1718 | ||
1719 | MacRepositionScrollBars() ; | |
1720 | if ( doMove ) | |
1721 | { | |
1722 | wxPoint point(actualX,actualY); | |
1723 | wxMoveEvent event(point, m_windowId); | |
1724 | event.SetEventObject(this); | |
1725 | GetEventHandler()->ProcessEvent(event) ; | |
1726 | } | |
1727 | if ( doResize ) | |
1728 | { | |
1729 | MacRepositionScrollBars() ; | |
1730 | wxSize size(actualWidth, actualHeight); | |
1731 | wxSizeEvent event(size, m_windowId); | |
1732 | event.SetEventObject(this); | |
1733 | GetEventHandler()->ProcessEvent(event); | |
1734 | } | |
1735 | } | |
1736 | ||
1737 | } | |
1738 | ||
1739 | wxSize wxWindowMac::DoGetBestSize() const | |
1740 | { | |
1741 | if ( m_macIsUserPane || IsTopLevel() ) | |
1742 | return wxWindowBase::DoGetBestSize() ; | |
1743 | ||
1744 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
1745 | int bestWidth, bestHeight ; | |
1746 | m_peer->GetBestRect( &bestsize ) ; | |
1747 | ||
1748 | if ( EmptyRect( &bestsize ) ) | |
1749 | { | |
1750 | bestsize.left = bestsize.top = 0 ; | |
1751 | bestsize.right = 16 ; | |
1752 | bestsize.bottom = 16 ; | |
1753 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1754 | { | |
1755 | bestsize.bottom = 16 ; | |
1756 | } | |
1757 | #if wxUSE_SPINBTN | |
1758 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
1759 | { | |
1760 | bestsize.bottom = 24 ; | |
1761 | } | |
1762 | #endif // wxUSE_SPINBTN | |
1763 | else | |
1764 | { | |
1765 | // return wxWindowBase::DoGetBestSize() ; | |
1766 | } | |
1767 | } | |
1768 | ||
1769 | bestWidth = bestsize.right - bestsize.left ; | |
1770 | bestHeight = bestsize.bottom - bestsize.top ; | |
1771 | if ( bestHeight < 10 ) | |
1772 | bestHeight = 13 ; | |
1773 | ||
1774 | return wxSize(bestWidth, bestHeight); | |
1775 | } | |
1776 | ||
1777 | ||
1778 | // set the size of the window: if the dimensions are positive, just use them, | |
1779 | // but if any of them is equal to -1, it means that we must find the value for | |
1780 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1781 | // which case -1 is a valid value for x and y) | |
1782 | // | |
1783 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1784 | // the width/height to best suit our contents, otherwise we reuse the current | |
1785 | // width/height | |
1786 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1787 | { | |
1788 | // get the current size and position... | |
1789 | int currentX, currentY; | |
1790 | GetPosition(¤tX, ¤tY); | |
1791 | ||
1792 | int currentW,currentH; | |
1793 | GetSize(¤tW, ¤tH); | |
1794 | ||
1795 | // ... and don't do anything (avoiding flicker) if it's already ok | |
1796 | if ( x == currentX && y == currentY && | |
1797 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) | |
1798 | { | |
1799 | // TODO REMOVE | |
1800 | MacRepositionScrollBars() ; // we might have a real position shift | |
1801 | return; | |
1802 | } | |
1803 | ||
1804 | if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1805 | x = currentX; | |
1806 | if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1807 | y = currentY; | |
1808 | ||
1809 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
1810 | ||
1811 | wxSize size = wxDefaultSize; | |
1812 | if ( width == wxDefaultCoord ) | |
1813 | { | |
1814 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1815 | { | |
1816 | size = DoGetBestSize(); | |
1817 | width = size.x; | |
1818 | } | |
1819 | else | |
1820 | { | |
1821 | // just take the current one | |
1822 | width = currentW; | |
1823 | } | |
1824 | } | |
1825 | ||
1826 | if ( height == wxDefaultCoord ) | |
1827 | { | |
1828 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1829 | { | |
1830 | if ( size.x == wxDefaultCoord ) | |
1831 | { | |
1832 | size = DoGetBestSize(); | |
1833 | } | |
1834 | //else: already called DoGetBestSize() above | |
1835 | ||
1836 | height = size.y; | |
1837 | } | |
1838 | else | |
1839 | { | |
1840 | // just take the current one | |
1841 | height = currentH; | |
1842 | } | |
1843 | } | |
1844 | ||
1845 | DoMoveWindow(x, y, width, height); | |
1846 | ||
1847 | } | |
1848 | ||
1849 | wxPoint wxWindowMac::GetClientAreaOrigin() const | |
1850 | { | |
1851 | RgnHandle rgn = NewRgn() ; | |
1852 | Rect content ; | |
1853 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1854 | { | |
1855 | GetRegionBounds( rgn , &content ) ; | |
1856 | } | |
1857 | else | |
1858 | { | |
1859 | content.left = content.top = 0 ; | |
1860 | } | |
1861 | DisposeRgn( rgn ) ; | |
1862 | return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); | |
1863 | } | |
1864 | ||
1865 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1866 | { | |
1867 | if ( clientheight != wxDefaultCoord || clientheight != wxDefaultCoord ) | |
1868 | { | |
1869 | int currentclientwidth , currentclientheight ; | |
1870 | int currentwidth , currentheight ; | |
1871 | ||
1872 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1873 | GetSize( ¤twidth , ¤theight ) ; | |
1874 | ||
1875 | DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , | |
1876 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1877 | } | |
1878 | } | |
1879 | ||
1880 | void wxWindowMac::SetTitle(const wxString& title) | |
1881 | { | |
1882 | m_label = wxStripMenuCodes(title) ; | |
1883 | ||
1884 | if ( m_peer && m_peer->Ok() ) | |
1885 | { | |
1886 | m_peer->SetTitle( m_label ) ; | |
1887 | } | |
1888 | Refresh() ; | |
1889 | } | |
1890 | ||
1891 | wxString wxWindowMac::GetTitle() const | |
1892 | { | |
1893 | return m_label ; | |
1894 | } | |
1895 | ||
1896 | bool wxWindowMac::Show(bool show) | |
1897 | { | |
1898 | bool former = MacIsReallyShown() ; | |
1899 | if ( !wxWindowBase::Show(show) ) | |
1900 | return false; | |
1901 | ||
1902 | // TODO use visibilityChanged Carbon Event for OSX | |
1903 | if ( m_peer ) | |
1904 | { | |
1905 | m_peer->SetVisibility( show , true ) ; | |
1906 | } | |
1907 | if ( former != MacIsReallyShown() ) | |
1908 | MacPropagateVisibilityChanged() ; | |
1909 | return true; | |
1910 | } | |
1911 | ||
1912 | bool wxWindowMac::Enable(bool enable) | |
1913 | { | |
1914 | wxASSERT( m_peer->Ok() ) ; | |
1915 | bool former = MacIsReallyEnabled() ; | |
1916 | if ( !wxWindowBase::Enable(enable) ) | |
1917 | return false; | |
1918 | ||
1919 | m_peer->Enable( enable ) ; | |
1920 | ||
1921 | if ( former != MacIsReallyEnabled() ) | |
1922 | MacPropagateEnabledStateChanged() ; | |
1923 | return true; | |
1924 | } | |
1925 | ||
1926 | // | |
1927 | // status change propagations (will be not necessary for OSX later ) | |
1928 | // | |
1929 | ||
1930 | void wxWindowMac::MacPropagateVisibilityChanged() | |
1931 | { | |
1932 | #if !TARGET_API_MAC_OSX | |
1933 | MacVisibilityChanged() ; | |
1934 | ||
1935 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1936 | while ( node ) | |
1937 | { | |
1938 | wxWindowMac *child = node->GetData(); | |
1939 | if ( child->IsShown() ) | |
1940 | child->MacPropagateVisibilityChanged( ) ; | |
1941 | node = node->GetNext(); | |
1942 | } | |
1943 | #endif | |
1944 | } | |
1945 | ||
1946 | void wxWindowMac::MacPropagateEnabledStateChanged( ) | |
1947 | { | |
1948 | #if !TARGET_API_MAC_OSX | |
1949 | MacEnabledStateChanged() ; | |
1950 | ||
1951 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1952 | while ( node ) | |
1953 | { | |
1954 | wxWindowMac *child = node->GetData(); | |
1955 | if ( child->IsEnabled() ) | |
1956 | child->MacPropagateEnabledStateChanged() ; | |
1957 | node = node->GetNext(); | |
1958 | } | |
1959 | #endif | |
1960 | } | |
1961 | ||
1962 | void wxWindowMac::MacPropagateHiliteChanged( ) | |
1963 | { | |
1964 | #if !TARGET_API_MAC_OSX | |
1965 | MacHiliteChanged() ; | |
1966 | ||
1967 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
1968 | while ( node ) | |
1969 | { | |
1970 | wxWindowMac *child = node->GetData(); | |
1971 | // if ( child->IsEnabled() ) | |
1972 | child->MacPropagateHiliteChanged() ; | |
1973 | node = node->GetNext(); | |
1974 | } | |
1975 | #endif | |
1976 | } | |
1977 | ||
1978 | // | |
1979 | // status change notifications | |
1980 | // | |
1981 | ||
1982 | void wxWindowMac::MacVisibilityChanged() | |
1983 | { | |
1984 | } | |
1985 | ||
1986 | void wxWindowMac::MacHiliteChanged() | |
1987 | { | |
1988 | } | |
1989 | ||
1990 | void wxWindowMac::MacEnabledStateChanged() | |
1991 | { | |
1992 | } | |
1993 | ||
1994 | // | |
1995 | // status queries on the inherited window's state | |
1996 | // | |
1997 | ||
1998 | bool wxWindowMac::MacIsReallyShown() | |
1999 | { | |
2000 | // only under OSX the visibility of the TLW is taken into account | |
2001 | if ( m_isBeingDeleted ) | |
2002 | return false ; | |
2003 | ||
2004 | #if TARGET_API_MAC_OSX | |
2005 | if ( m_peer && m_peer->Ok() ) | |
2006 | return m_peer->IsVisible(); | |
2007 | #endif | |
2008 | wxWindow* win = this ; | |
2009 | while( win->IsShown() ) | |
2010 | { | |
2011 | if ( win->IsTopLevel() ) | |
2012 | return true ; | |
2013 | ||
2014 | win = win->GetParent() ; | |
2015 | if ( win == NULL ) | |
2016 | return true ; | |
2017 | ||
2018 | } ; | |
2019 | return false ; | |
2020 | } | |
2021 | ||
2022 | bool wxWindowMac::MacIsReallyEnabled() | |
2023 | { | |
2024 | return m_peer->IsEnabled() ; | |
2025 | } | |
2026 | ||
2027 | bool wxWindowMac::MacIsReallyHilited() | |
2028 | { | |
2029 | return m_peer->IsActive(); | |
2030 | } | |
2031 | ||
2032 | void wxWindowMac::MacFlashInvalidAreas() | |
2033 | { | |
2034 | #if TARGET_API_MAC_OSX | |
2035 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2036 | #endif | |
2037 | } | |
2038 | ||
2039 | // | |
2040 | // | |
2041 | // | |
2042 | ||
2043 | int wxWindowMac::GetCharHeight() const | |
2044 | { | |
2045 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
2046 | return dc.GetCharHeight() ; | |
2047 | } | |
2048 | ||
2049 | int wxWindowMac::GetCharWidth() const | |
2050 | { | |
2051 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
2052 | return dc.GetCharWidth() ; | |
2053 | } | |
2054 | ||
2055 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, | |
2056 | int *descent, int *externalLeading, const wxFont *theFont ) const | |
2057 | { | |
2058 | const wxFont *fontToUse = theFont; | |
2059 | if ( !fontToUse ) | |
2060 | fontToUse = &m_font; | |
2061 | ||
2062 | wxClientDC dc( (wxWindowMac*) this ) ; | |
2063 | long lx,ly,ld,le ; | |
2064 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; | |
2065 | if ( externalLeading ) | |
2066 | *externalLeading = le ; | |
2067 | if ( descent ) | |
2068 | *descent = ld ; | |
2069 | if ( x ) | |
2070 | *x = lx ; | |
2071 | if ( y ) | |
2072 | *y = ly ; | |
2073 | } | |
2074 | ||
2075 | /* | |
2076 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect | |
2077 | * we always intersect with the entire window, not only with the client area | |
2078 | */ | |
2079 | ||
2080 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) | |
2081 | { | |
2082 | if ( m_peer == NULL ) | |
2083 | return ; | |
2084 | ||
2085 | if ( !MacIsReallyShown() ) | |
2086 | return ; | |
2087 | ||
2088 | if ( rect ) | |
2089 | { | |
2090 | Rect r ; | |
2091 | wxMacRectToNative( rect , &r ) ; | |
2092 | m_peer->SetNeedsDisplay( &r ) ; | |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | m_peer->SetNeedsDisplay() ; | |
2097 | } | |
2098 | } | |
2099 | ||
2100 | void wxWindowMac::Freeze() | |
2101 | { | |
2102 | #if TARGET_API_MAC_OSX | |
2103 | if ( !m_frozenness++ ) | |
2104 | { | |
2105 | if ( m_peer && m_peer->Ok() ) | |
2106 | m_peer->SetDrawingEnabled( false ) ; | |
2107 | } | |
2108 | #endif | |
2109 | } | |
2110 | ||
2111 | ||
2112 | void wxWindowMac::Thaw() | |
2113 | { | |
2114 | #if TARGET_API_MAC_OSX | |
2115 | wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); | |
2116 | ||
2117 | if ( !--m_frozenness ) | |
2118 | { | |
2119 | if ( m_peer && m_peer->Ok() ) | |
2120 | { | |
2121 | m_peer->SetDrawingEnabled( true ) ; | |
2122 | m_peer->InvalidateWithChildren() ; | |
2123 | } | |
2124 | } | |
2125 | #endif | |
2126 | } | |
2127 | ||
2128 | wxWindowMac *wxGetActiveWindow() | |
2129 | { | |
2130 | // actually this is a windows-only concept | |
2131 | return NULL; | |
2132 | } | |
2133 | ||
2134 | // Coordinates relative to the window | |
2135 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) | |
2136 | { | |
2137 | // We really don't move the mouse programmatically under Mac. | |
2138 | } | |
2139 | ||
2140 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
2141 | { | |
2142 | if ( MacGetTopLevelWindow() == NULL ) | |
2143 | return ; | |
2144 | #if TARGET_API_MAC_OSX | |
2145 | if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) ) | |
2146 | { | |
2147 | event.Skip() ; | |
2148 | } | |
2149 | else | |
2150 | #endif | |
2151 | { | |
2152 | event.GetDC()->Clear() ; | |
2153 | } | |
2154 | } | |
2155 | ||
2156 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2157 | { | |
2158 | event.Skip() ; | |
2159 | } | |
2160 | ||
2161 | int wxWindowMac::GetScrollPos(int orient) const | |
2162 | { | |
2163 | if ( orient == wxHORIZONTAL ) | |
2164 | { | |
2165 | if ( m_hScrollBar ) | |
2166 | return m_hScrollBar->GetThumbPosition() ; | |
2167 | } | |
2168 | else | |
2169 | { | |
2170 | if ( m_vScrollBar ) | |
2171 | return m_vScrollBar->GetThumbPosition() ; | |
2172 | } | |
2173 | return 0; | |
2174 | } | |
2175 | ||
2176 | // This now returns the whole range, not just the number | |
2177 | // of positions that we can scroll. | |
2178 | int wxWindowMac::GetScrollRange(int orient) const | |
2179 | { | |
2180 | if ( orient == wxHORIZONTAL ) | |
2181 | { | |
2182 | if ( m_hScrollBar ) | |
2183 | return m_hScrollBar->GetRange() ; | |
2184 | } | |
2185 | else | |
2186 | { | |
2187 | if ( m_vScrollBar ) | |
2188 | return m_vScrollBar->GetRange() ; | |
2189 | } | |
2190 | return 0; | |
2191 | } | |
2192 | ||
2193 | int wxWindowMac::GetScrollThumb(int orient) const | |
2194 | { | |
2195 | if ( orient == wxHORIZONTAL ) | |
2196 | { | |
2197 | if ( m_hScrollBar ) | |
2198 | return m_hScrollBar->GetThumbSize() ; | |
2199 | } | |
2200 | else | |
2201 | { | |
2202 | if ( m_vScrollBar ) | |
2203 | return m_vScrollBar->GetThumbSize() ; | |
2204 | } | |
2205 | return 0; | |
2206 | } | |
2207 | ||
2208 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) | |
2209 | { | |
2210 | if ( orient == wxHORIZONTAL ) | |
2211 | { | |
2212 | if ( m_hScrollBar ) | |
2213 | m_hScrollBar->SetThumbPosition( pos ) ; | |
2214 | } | |
2215 | else | |
2216 | { | |
2217 | if ( m_vScrollBar ) | |
2218 | m_vScrollBar->SetThumbPosition( pos ) ; | |
2219 | } | |
2220 | } | |
2221 | ||
2222 | // | |
2223 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
2224 | // our own window origin is at leftOrigin/rightOrigin | |
2225 | // | |
2226 | ||
2227 | void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) | |
2228 | { | |
2229 | if( IsTopLevel() ) | |
2230 | return ; | |
2231 | ||
2232 | Rect rect ; | |
2233 | bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; | |
2234 | bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
2235 | ||
2236 | m_peer->GetRect( &rect ) ; | |
2237 | // back to the surrounding frame rectangle | |
2238 | InsetRect( &rect, -1 , -1 ) ; | |
2239 | ||
2240 | #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
2241 | if ( UMAGetSystemVersion() >= 0x1030 ) | |
2242 | { | |
2243 | CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , | |
2244 | rect.bottom - rect.top ) ; | |
2245 | ||
2246 | HIThemeFrameDrawInfo info ; | |
2247 | memset( &info, 0 , sizeof( info ) ) ; | |
2248 | ||
2249 | info.version = 0 ; | |
2250 | info.kind = 0 ; | |
2251 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2252 | info.isFocused = hasFocus ; | |
2253 | ||
2254 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
2255 | wxASSERT( cgContext ) ; | |
2256 | ||
2257 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2258 | { | |
2259 | info.kind = kHIThemeFrameTextFieldSquare ; | |
2260 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2261 | } | |
2262 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2263 | { | |
2264 | info.kind = kHIThemeFrameListBox ; | |
2265 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2266 | } | |
2267 | else if ( hasFocus ) | |
2268 | { | |
2269 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; | |
2270 | } | |
2271 | ||
2272 | m_peer->GetRect( &rect ) ; | |
2273 | if ( hasBothScrollbars ) | |
2274 | { | |
2275 | int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ; | |
2276 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; | |
2277 | CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; | |
2278 | HIThemeGrowBoxDrawInfo info ; | |
2279 | memset( &info, 0 , sizeof( info ) ) ; | |
2280 | info.version = 0 ; | |
2281 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2282 | info.kind = kHIThemeGrowBoxKindNone ; | |
2283 | info.size = kHIThemeGrowBoxSizeNormal ; | |
2284 | info.direction = kThemeGrowRight | kThemeGrowDown ; | |
2285 | HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; | |
2286 | } | |
2287 | } | |
2288 | else | |
2289 | #endif | |
2290 | { | |
2291 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
2292 | if (top ) | |
2293 | { | |
2294 | wxPoint pt(0,0) ; | |
2295 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
2296 | OffsetRect( &rect , pt.x , pt.y ) ; | |
2297 | } | |
2298 | ||
2299 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2300 | { | |
2301 | DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2302 | } | |
2303 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2304 | { | |
2305 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2306 | } | |
2307 | ||
2308 | if ( hasFocus ) | |
2309 | { | |
2310 | DrawThemeFocusRect( &rect , true ) ; | |
2311 | } | |
2312 | ||
2313 | if ( hasBothScrollbars ) | |
2314 | { | |
2315 | // GetThemeStandaloneGrowBoxBounds | |
2316 | //DrawThemeStandaloneNoGrowBox | |
2317 | } | |
2318 | } | |
2319 | } | |
2320 | ||
2321 | void wxWindowMac::RemoveChild( wxWindowBase *child ) | |
2322 | { | |
2323 | if ( child == m_hScrollBar ) | |
2324 | m_hScrollBar = NULL ; | |
2325 | if ( child == m_vScrollBar ) | |
2326 | m_vScrollBar = NULL ; | |
2327 | ||
2328 | wxWindowBase::RemoveChild( child ) ; | |
2329 | } | |
2330 | ||
2331 | // New function that will replace some of the above. | |
2332 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, | |
2333 | int range, bool refresh) | |
2334 | { | |
2335 | if ( orient == wxHORIZONTAL ) | |
2336 | { | |
2337 | if ( m_hScrollBar ) | |
2338 | { | |
2339 | if ( range == 0 || thumbVisible >= range ) | |
2340 | { | |
2341 | if ( m_hScrollBar->IsShown() ) | |
2342 | m_hScrollBar->Show(false) ; | |
2343 | } | |
2344 | else | |
2345 | { | |
2346 | if ( !m_hScrollBar->IsShown() ) | |
2347 | m_hScrollBar->Show(true) ; | |
2348 | } | |
2349 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
2350 | } | |
2351 | } | |
2352 | else | |
2353 | { | |
2354 | if ( m_vScrollBar ) | |
2355 | { | |
2356 | if ( range == 0 || thumbVisible >= range ) | |
2357 | { | |
2358 | if ( m_vScrollBar->IsShown() ) | |
2359 | m_vScrollBar->Show(false) ; | |
2360 | } | |
2361 | else | |
2362 | { | |
2363 | if ( !m_vScrollBar->IsShown() ) | |
2364 | m_vScrollBar->Show(true) ; | |
2365 | } | |
2366 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
2367 | } | |
2368 | } | |
2369 | MacRepositionScrollBars() ; | |
2370 | } | |
2371 | ||
2372 | // Does a physical scroll | |
2373 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) | |
2374 | { | |
2375 | if( dx == 0 && dy ==0 ) | |
2376 | return ; | |
2377 | ||
2378 | int width , height ; | |
2379 | GetClientSize( &width , &height ) ; | |
2380 | #if TARGET_API_MAC_OSX | |
2381 | if ( 1 /* m_peer->IsCompositing() */ ) | |
2382 | { | |
2383 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control | |
2384 | // area is scrolled, this does not occur if width and height are 2 pixels less, | |
2385 | // TODO write optimal workaround | |
2386 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; | |
2387 | if ( rect ) | |
2388 | { | |
2389 | scrollrect.Intersect( *rect ) ; | |
2390 | } | |
2391 | if ( m_peer->GetNeedsDisplay() ) | |
2392 | { | |
2393 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2394 | // either immediate redraw or full invalidate | |
2395 | #if 1 | |
2396 | // is the better overall solution, as it does not slow down scrolling | |
2397 | m_peer->SetNeedsDisplay() ; | |
2398 | #else | |
2399 | // this would be the preferred version for fast drawing controls | |
2400 | ||
2401 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
2402 | if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) | |
2403 | HIViewRender(m_peer->GetControlRef()) ; | |
2404 | else | |
2405 | #endif | |
2406 | Update() ; | |
2407 | #endif | |
2408 | } | |
2409 | // as the native control might be not a 0/0 wx window coordinates, we have to offset | |
2410 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
2411 | m_peer->ScrollRect( (&scrollrect) , dx , dy ) ; | |
2412 | ||
2413 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2414 | // either immediate redraw or full invalidate | |
2415 | #if 0 | |
2416 | // is the better overall solution, as it does not slow down scrolling | |
2417 | m_peer->SetNeedsDisplay() ; | |
2418 | #else | |
2419 | // this would be the preferred version for fast drawing controls | |
2420 | ||
2421 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
2422 | if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) | |
2423 | HIViewRender(m_peer->GetControlRef()) ; | |
2424 | else | |
2425 | #endif | |
2426 | Update() ; | |
2427 | ||
2428 | #endif | |
2429 | } | |
2430 | else | |
2431 | #endif | |
2432 | { | |
2433 | ||
2434 | wxPoint pos; | |
2435 | pos.x = pos.y = 0; | |
2436 | ||
2437 | Rect scrollrect; | |
2438 | RgnHandle updateRgn = NewRgn() ; | |
2439 | ||
2440 | { | |
2441 | wxClientDC dc(this) ; | |
2442 | wxMacPortSetter helper(&dc) ; | |
2443 | ||
2444 | m_peer->GetRectInWindowCoords( &scrollrect ) ; | |
2445 | //scrollrect.top += MacGetTopBorderSize() ; | |
2446 | //scrollrect.left += MacGetLeftBorderSize() ; | |
2447 | scrollrect.bottom = scrollrect.top + height ; | |
2448 | scrollrect.right = scrollrect.left + width ; | |
2449 | ||
2450 | if ( rect ) | |
2451 | { | |
2452 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2453 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2454 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2455 | } | |
2456 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
2457 | ||
2458 | // now scroll the former update region as well and add the new update region | |
2459 | ||
2460 | WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ; | |
2461 | RgnHandle formerUpdateRgn = NewRgn() ; | |
2462 | RgnHandle scrollRgn = NewRgn() ; | |
2463 | RectRgn( scrollRgn , &scrollrect ) ; | |
2464 | GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; | |
2465 | Point pt = {0,0} ; | |
2466 | LocalToGlobal( &pt ) ; | |
2467 | OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; | |
2468 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2469 | if ( !EmptyRgn( formerUpdateRgn ) ) | |
2470 | { | |
2471 | MacOffsetRgn( formerUpdateRgn , dx , dy ) ; | |
2472 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2473 | InvalWindowRgn(rootWindow , formerUpdateRgn ) ; | |
2474 | } | |
2475 | InvalWindowRgn(rootWindow , updateRgn ) ; | |
2476 | DisposeRgn( updateRgn ) ; | |
2477 | DisposeRgn( formerUpdateRgn ) ; | |
2478 | DisposeRgn( scrollRgn ) ; | |
2479 | } | |
2480 | Update() ; | |
2481 | } | |
2482 | ||
2483 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
2484 | { | |
2485 | wxWindowMac *child = node->GetData(); | |
2486 | if (child == m_vScrollBar) continue; | |
2487 | if (child == m_hScrollBar) continue; | |
2488 | if (child->IsTopLevel()) continue; | |
2489 | ||
2490 | int x,y; | |
2491 | child->GetPosition( &x, &y ); | |
2492 | int w,h; | |
2493 | child->GetSize( &w, &h ); | |
2494 | if (rect) | |
2495 | { | |
2496 | wxRect rc(x,y,w,h); | |
2497 | if (rect->Intersects(rc)) | |
2498 | child->SetSize( x+dx, y+dy, w, h ); | |
2499 | } | |
2500 | else | |
2501 | { | |
2502 | child->SetSize( x+dx, y+dy, w, h ); | |
2503 | } | |
2504 | } | |
2505 | } | |
2506 | ||
2507 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) | |
2508 | { | |
2509 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) | |
2510 | { | |
2511 | wxScrollWinEvent wevent; | |
2512 | wevent.SetPosition(event.GetPosition()); | |
2513 | wevent.SetOrientation(event.GetOrientation()); | |
2514 | wevent.SetEventObject(this); | |
2515 | ||
2516 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
2517 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
2518 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
2519 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
2520 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
2521 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
2522 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
2523 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
2524 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
2525 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
2526 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
2527 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
2528 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
2529 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
2530 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
2531 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
2532 | ||
2533 | GetEventHandler()->ProcessEvent(wevent); | |
2534 | } | |
2535 | } | |
2536 | ||
2537 | // Get the window with the focus | |
2538 | wxWindowMac *wxWindowBase::DoFindFocus() | |
2539 | { | |
2540 | ControlRef control ; | |
2541 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2542 | return wxFindControlFromMacControl( control ) ; | |
2543 | } | |
2544 | ||
2545 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) | |
2546 | { | |
2547 | // panel wants to track the window which was the last to have focus in it, | |
2548 | // so we want to set ourselves as the window which last had focus | |
2549 | // | |
2550 | // notice that it's also important to do it upwards the tree becaus | |
2551 | // otherwise when the top level panel gets focus, it won't set it back to | |
2552 | // us, but to some other sibling | |
2553 | ||
2554 | // CS:don't know if this is still needed: | |
2555 | //wxChildFocusEvent eventFocus(this); | |
2556 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
2557 | ||
2558 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) | |
2559 | { | |
2560 | #if !wxMAC_USE_CORE_GRAPHICS | |
2561 | wxMacWindowStateSaver sv( this ) ; | |
2562 | Rect rect ; | |
2563 | m_peer->GetRect( &rect ) ; | |
2564 |