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