]>
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 | #ifdef __GNUG__ | |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/window.h" | |
19 | #include "wx/dc.h" | |
20 | #include "wx/dcclient.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/app.h" | |
23 | #include "wx/panel.h" | |
24 | #include "wx/layout.h" | |
25 | #include "wx/dialog.h" | |
26 | #include "wx/scrolbar.h" | |
27 | #include "wx/scrolwin.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 | #include "wx/laywin.h" | |
41 | #include "wx/splitter.h" | |
42 | ||
43 | #include "wx/toolbar.h" | |
44 | #include "wx/dc.h" | |
45 | ||
46 | #if wxUSE_CARET | |
47 | #include "wx/caret.h" | |
48 | #endif // wxUSE_CARET | |
49 | ||
50 | #define wxWINDOW_HSCROLL 5998 | |
51 | #define wxWINDOW_VSCROLL 5997 | |
52 | ||
53 | #define MAC_SCROLLBAR_SIZE 15 | |
54 | #define MAC_SMALL_SCROLLBAR_SIZE 11 | |
55 | ||
56 | #include "wx/mac/uma.h" | |
57 | #ifndef __DARWIN__ | |
58 | #include <Windows.h> | |
59 | #include <ToolUtils.h> | |
60 | #include <Scrap.h> | |
61 | #include <MacTextEditor.h> | |
62 | #endif | |
63 | ||
64 | #if TARGET_API_MAC_OSX | |
65 | #ifndef __HIVIEW__ | |
66 | #include <HIToolbox/HIView.h> | |
67 | #endif | |
68 | #endif | |
69 | ||
70 | #if wxUSE_DRAG_AND_DROP | |
71 | #include "wx/dnd.h" | |
72 | #endif | |
73 | ||
74 | #include <string.h> | |
75 | ||
76 | extern wxList wxPendingDelete; | |
77 | ||
78 | #ifdef __WXUNIVERSAL__ | |
79 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
80 | #else // __WXMAC__ | |
81 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
82 | #endif // __WXUNIVERSAL__/__WXMAC__ | |
83 | ||
84 | #if !USE_SHARED_LIBRARY | |
85 | ||
86 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
87 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) | |
88 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
89 | // TODO EVT_PAINT(wxWindowMac::OnPaint) | |
90 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) | |
91 | EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) | |
92 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) | |
93 | END_EVENT_TABLE() | |
94 | ||
95 | #endif | |
96 | ||
97 | #define wxMAC_DEBUG_REDRAW 0 | |
98 | #ifndef wxMAC_DEBUG_REDRAW | |
99 | #define wxMAC_DEBUG_REDRAW 0 | |
100 | #endif | |
101 | ||
102 | #define wxMAC_USE_THEME_BORDER 1 | |
103 | ||
104 | // --------------------------------------------------------------------------- | |
105 | // Utility Routines to move between different coordinate systems | |
106 | // --------------------------------------------------------------------------- | |
107 | ||
108 | /* | |
109 | * Right now we have the following setup : | |
110 | * a border that is not part of the native control is always outside the | |
111 | * control's border (otherwise we loose all native intelligence, future ways | |
112 | * may be to have a second embedding control responsible for drawing borders | |
113 | * and backgrounds eventually) | |
114 | * so all this border calculations have to be taken into account when calling | |
115 | * native methods or getting native oriented data | |
116 | * so we have three coordinate systems here | |
117 | * wx client coordinates | |
118 | * wx window coordinates (including window frames) | |
119 | * native coordinates | |
120 | */ | |
121 | ||
122 | // | |
123 | // originating from native control | |
124 | // | |
125 | ||
126 | ||
127 | void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle ) | |
128 | { | |
129 | OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; | |
130 | } | |
131 | ||
132 | void wxMacNativeToWindow( const wxWindow* window , Rect *rect ) | |
133 | { | |
134 | OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ; | |
135 | } | |
136 | ||
137 | // | |
138 | // directed towards native control | |
139 | // | |
140 | ||
141 | void wxMacWindowToNative( const wxWindow* window , RgnHandle handle ) | |
142 | { | |
143 | OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); | |
144 | } | |
145 | ||
146 | void wxMacWindowToNative( const wxWindow* window , Rect *rect ) | |
147 | { | |
148 | OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ; | |
149 | } | |
150 | ||
151 | ||
152 | // --------------------------------------------------------------------------- | |
153 | // Carbon Events | |
154 | // --------------------------------------------------------------------------- | |
155 | ||
156 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
157 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ; | |
158 | ||
159 | #if TARGET_API_MAC_OSX | |
160 | ||
161 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 | |
162 | enum { | |
163 | kEventControlVisibilityChanged = 157 | |
164 | }; | |
165 | #endif | |
166 | ||
167 | #endif | |
168 | ||
169 | static const EventTypeSpec eventList[] = | |
170 | { | |
171 | { kEventClassControl , kEventControlHit } , | |
172 | #if TARGET_API_MAC_OSX | |
173 | { kEventClassControl , kEventControlDraw } , | |
174 | { kEventClassControl , kEventControlVisibilityChanged } , | |
175 | { kEventClassControl , kEventControlEnabledStateChanged } , | |
176 | { kEventClassControl , kEventControlHiliteChanged } , | |
177 | { kEventClassControl , kEventControlSetFocusPart } , | |
178 | ||
179 | { kEventClassService , kEventServiceGetTypes }, | |
180 | { kEventClassService , kEventServiceCopy }, | |
181 | { kEventClassService , kEventServicePaste }, | |
182 | ||
183 | // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only | |
184 | // { kEventClassControl , kEventControlBoundsChanged } , | |
185 | #endif | |
186 | } ; | |
187 | ||
188 | static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
189 | { | |
190 | OSStatus result = eventNotHandledErr ; | |
191 | ||
192 | wxMacCarbonEvent cEvent( event ) ; | |
193 | ||
194 | ControlRef controlRef ; | |
195 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
196 | ||
197 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
198 | ||
199 | switch( GetEventKind( event ) ) | |
200 | { | |
201 | #if TARGET_API_MAC_OSX | |
202 | case kEventControlDraw : | |
203 | { | |
204 | RgnHandle updateRgn = NULL ; | |
205 | RgnHandle allocatedRgn = NULL ; | |
206 | wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; | |
207 | if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr ) | |
208 | { | |
209 | updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; | |
210 | } | |
211 | else | |
212 | { | |
213 | if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) | |
214 | { | |
215 | allocatedRgn = NewRgn() ; | |
216 | CopyRgn( updateRgn , allocatedRgn ) ; | |
217 | // hide the given region by the new region that must be shifted | |
218 | wxMacNativeToWindow( thisWindow , allocatedRgn ) ; | |
219 | updateRgn = allocatedRgn ; | |
220 | } | |
221 | } | |
222 | ||
223 | #if 0 | |
224 | // in case we would need a coregraphics compliant background erase first | |
225 | // now usable to track redraws | |
226 | CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; | |
227 | if ( thisWindow->MacIsUserPane() ) | |
228 | { | |
229 | static float color = 0.5 ; | |
230 | static channel = 0 ; | |
231 | HIRect bounds; | |
232 | HIViewGetBounds( controlRef, &bounds ); | |
233 | CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 , | |
234 | channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 ); | |
235 | CGContextFillRect( cgContext, bounds ); | |
236 | color += 0.1 ; | |
237 | if ( color > 0.9 ) | |
238 | { | |
239 | color = 0.5 ; | |
240 | channel++ ; | |
241 | if ( channel == 3 ) | |
242 | channel = 0 ; | |
243 | } | |
244 | } | |
245 | #endif | |
246 | if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) | |
247 | result = noErr ; | |
248 | if ( allocatedRgn ) | |
249 | DisposeRgn( allocatedRgn ) ; | |
250 | } | |
251 | break ; | |
252 | case kEventControlVisibilityChanged : | |
253 | thisWindow->MacVisibilityChanged() ; | |
254 | break ; | |
255 | case kEventControlEnabledStateChanged : | |
256 | thisWindow->MacEnabledStateChanged() ; | |
257 | break ; | |
258 | case kEventControlHiliteChanged : | |
259 | thisWindow->MacHiliteChanged() ; | |
260 | break ; | |
261 | case kEventControlSetFocusPart : | |
262 | { | |
263 | Boolean focusEverything = false ; | |
264 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
265 | if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr ) | |
266 | { | |
267 | } | |
268 | if ( controlPart == kControlFocusNoPart ) | |
269 | { | |
270 | #if wxUSE_CARET | |
271 | if ( thisWindow->GetCaret() ) | |
272 | { | |
273 | thisWindow->GetCaret()->OnKillFocus(); | |
274 | } | |
275 | #endif // wxUSE_CARET | |
276 | wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); | |
277 | event.SetEventObject(thisWindow); | |
278 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
279 | } | |
280 | else | |
281 | { | |
282 | // panel wants to track the window which was the last to have focus in it | |
283 | wxChildFocusEvent eventFocus(thisWindow); | |
284 | thisWindow->GetEventHandler()->ProcessEvent(eventFocus); | |
285 | ||
286 | #if wxUSE_CARET | |
287 | if ( thisWindow->GetCaret() ) | |
288 | { | |
289 | thisWindow->GetCaret()->OnSetFocus(); | |
290 | } | |
291 | #endif // wxUSE_CARET | |
292 | ||
293 | wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); | |
294 | event.SetEventObject(thisWindow); | |
295 | thisWindow->GetEventHandler()->ProcessEvent(event) ; | |
296 | } | |
297 | if ( thisWindow->MacIsUserPane() ) | |
298 | result = noErr ; | |
299 | } | |
300 | break ; | |
301 | #endif | |
302 | case kEventControlHit : | |
303 | { | |
304 | result = thisWindow->MacControlHit( handler , event ) ; | |
305 | } | |
306 | break ; | |
307 | default : | |
308 | break ; | |
309 | } | |
310 | return result ; | |
311 | } | |
312 | ||
313 | static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
314 | { | |
315 | OSStatus result = eventNotHandledErr ; | |
316 | ||
317 | wxMacCarbonEvent cEvent( event ) ; | |
318 | ||
319 | ControlRef controlRef ; | |
320 | wxWindowMac* thisWindow = (wxWindowMac*) data ; | |
321 | wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ; | |
322 | cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; | |
323 | ||
324 | switch( GetEventKind( event ) ) | |
325 | { | |
326 | case kEventServiceGetTypes : | |
327 | if( textCtrl ) | |
328 | { | |
329 | long from, to ; | |
330 | textCtrl->GetSelection( &from , &to ) ; | |
331 | ||
332 | CFMutableArrayRef copyTypes = 0 , pasteTypes = 0; | |
333 | if( from != to ) | |
334 | copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ; | |
335 | if ( textCtrl->IsEditable() ) | |
336 | pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ; | |
337 | ||
338 | static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ }; | |
339 | for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i ) | |
340 | { | |
341 | CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]); | |
342 | if ( typestring ) | |
343 | { | |
344 | if ( copyTypes ) | |
345 | CFArrayAppendValue (copyTypes, typestring) ; | |
346 | if ( pasteTypes ) | |
347 | CFArrayAppendValue (pasteTypes, typestring) ; | |
348 | CFRelease( typestring ) ; | |
349 | } | |
350 | } | |
351 | result = noErr ; | |
352 | } | |
353 | break ; | |
354 | case kEventServiceCopy : | |
355 | if ( textCtrl ) | |
356 | { | |
357 | long from, to ; | |
358 | textCtrl->GetSelection( &from , &to ) ; | |
359 | wxString val = textCtrl->GetValue() ; | |
360 | val = val.Mid( from , to - from ) ; | |
361 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
362 | verify_noerr( ClearScrap( &scrapRef ) ) ; | |
363 | verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ; | |
364 | result = noErr ; | |
365 | } | |
366 | break ; | |
367 | case kEventServicePaste : | |
368 | if ( textCtrl ) | |
369 | { | |
370 | ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ; | |
371 | Size textSize, pastedSize ; | |
372 | verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ; | |
373 | textSize++ ; | |
374 | char *content = new char[textSize] ; | |
375 | GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content ); | |
376 | content[textSize-1] = 0 ; | |
377 | #if wxUSE_UNICODE | |
378 | textCtrl->WriteText( wxString( content , wxConvLocal ) ); | |
379 | #else | |
380 | textCtrl->WriteText( wxString( content ) ) ; | |
381 | #endif | |
382 | delete[] content ; | |
383 | result = noErr ; | |
384 | } | |
385 | break ; | |
386 | } | |
387 | ||
388 | return result ; | |
389 | } | |
390 | ||
391 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
392 | { | |
393 | EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
394 | EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
395 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
396 | OSStatus result = eventNotHandledErr ; | |
397 | ||
398 | switch ( GetEventClass( event ) ) | |
399 | { | |
400 | case kEventClassControl : | |
401 | result = wxMacWindowControlEventHandler( handler, event, data ) ; | |
402 | break ; | |
403 | case kEventClassService : | |
404 | result = wxMacWindowServiceEventHandler( handler, event , data ) ; | |
405 | default : | |
406 | break ; | |
407 | } | |
408 | wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ; | |
409 | return result ; | |
410 | } | |
411 | ||
412 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
413 | ||
414 | // --------------------------------------------------------------------------- | |
415 | // UserPane events for non OSX builds | |
416 | // --------------------------------------------------------------------------- | |
417 | ||
418 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) | |
419 | { | |
420 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
421 | wxCHECK_RET( win , wxT("Callback from unkown control") ) ; | |
422 | win->MacControlUserPaneDrawProc(part) ; | |
423 | } | |
424 | ||
425 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) | |
426 | { | |
427 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
428 | wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; | |
429 | return win->MacControlUserPaneHitTestProc(where.h , where.v) ; | |
430 | } | |
431 | ||
432 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) | |
433 | { | |
434 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
435 | wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; | |
436 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; | |
437 | } | |
438 | ||
439 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
440 | { | |
441 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
442 | wxCHECK_RET( win , wxT("Callback from unkown control") ) ; | |
443 | win->MacControlUserPaneIdleProc() ; | |
444 | } | |
445 | ||
446 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
447 | { | |
448 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
449 | wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; | |
450 | return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; | |
451 | } | |
452 | ||
453 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
454 | { | |
455 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
456 | wxCHECK_RET( win , wxT("Callback from unkown control") ) ; | |
457 | win->MacControlUserPaneActivateProc(activating) ; | |
458 | } | |
459 | ||
460 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
461 | { | |
462 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
463 | wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; | |
464 | return win->MacControlUserPaneFocusProc(action) ; | |
465 | } | |
466 | ||
467 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) | |
468 | { | |
469 | wxWindow * win = wxFindControlFromMacControl(control) ; | |
470 | wxCHECK_RET( win , wxT("Callback from unkown control") ) ; | |
471 | win->MacControlUserPaneBackgroundProc(info) ; | |
472 | } | |
473 | ||
474 | void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) | |
475 | { | |
476 | RgnHandle rgn = NewRgn() ; | |
477 | GetClip( rgn ) ; | |
478 | wxMacWindowStateSaver sv( this ) ; | |
479 | SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; | |
480 | MacDoRedraw( rgn , 0 ) ; | |
481 | DisposeRgn( rgn ) ; | |
482 | } | |
483 | ||
484 | wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) | |
485 | { | |
486 | return kControlNoPart ; | |
487 | } | |
488 | ||
489 | wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) | |
490 | { | |
491 | return kControlNoPart ; | |
492 | } | |
493 | ||
494 | void wxWindowMac::MacControlUserPaneIdleProc() | |
495 | { | |
496 | } | |
497 | ||
498 | wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) | |
499 | { | |
500 | return kControlNoPart ; | |
501 | } | |
502 | ||
503 | void wxWindowMac::MacControlUserPaneActivateProc(bool activating) | |
504 | { | |
505 | } | |
506 | ||
507 | wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) | |
508 | { | |
509 | return kControlNoPart ; | |
510 | } | |
511 | ||
512 | void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) | |
513 | { | |
514 | } | |
515 | ||
516 | ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ; | |
517 | ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ; | |
518 | ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ; | |
519 | ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ; | |
520 | ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ; | |
521 | ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ; | |
522 | ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ; | |
523 | ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ; | |
524 | ||
525 | // =========================================================================== | |
526 | // implementation | |
527 | // =========================================================================== | |
528 | ||
529 | wxList wxWinMacControlList(wxKEY_INTEGER); | |
530 | ||
531 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) | |
532 | { | |
533 | wxNode *node = wxWinMacControlList.Find((long)inControl); | |
534 | if (!node) | |
535 | return NULL; | |
536 | return (wxControl *)node->GetData(); | |
537 | } | |
538 | ||
539 | void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) | |
540 | { | |
541 | // adding NULL ControlRef is (first) surely a result of an error and | |
542 | // (secondly) breaks native event processing | |
543 | wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
544 | ||
545 | if ( !wxWinMacControlList.Find((long)inControl) ) | |
546 | wxWinMacControlList.Append((long)inControl, control); | |
547 | } | |
548 | ||
549 | void wxRemoveMacControlAssociation(wxWindow *control) | |
550 | { | |
551 | wxWinMacControlList.DeleteObject(control); | |
552 | } | |
553 | ||
554 | // UPP functions | |
555 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; | |
556 | ||
557 | ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; | |
558 | ||
559 | // we have to setup the brush in the current port and return noErr | |
560 | // or return an error code so that the control manager walks further up the | |
561 | // hierarchy to find a correct background | |
562 | ||
563 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) | |
564 | { | |
565 | OSStatus status = paramErr ; | |
566 | switch( iMessage ) | |
567 | { | |
568 | case kControlMsgApplyTextColor : | |
569 | break ; | |
570 | case kControlMsgSetUpBackground : | |
571 | { | |
572 | wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ; | |
573 | if ( wx != NULL ) | |
574 | { | |
575 | /* | |
576 | const wxBrush &brush = wx->MacGetBackgroundBrush() ; | |
577 | if ( brush.Ok() ) | |
578 | { | |
579 | wxDC::MacSetupBackgroundForCurrentPort( brush ) ; | |
580 | */ | |
581 | // this clipping is only needed for non HIView | |
582 | ||
583 | RgnHandle clip = NewRgn() ; | |
584 | int x = 0 , y = 0; | |
585 | ||
586 | wx->MacWindowToRootWindow( &x,&y ) ; | |
587 | CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ; | |
588 | OffsetRgn( clip , x , y ) ; | |
589 | SetClip( clip ) ; | |
590 | DisposeRgn( clip ) ; | |
591 | ||
592 | status = noErr ; | |
593 | /* | |
594 | } | |
595 | else if ( wx->MacIsUserPane() ) | |
596 | { | |
597 | // if we don't have a valid brush for such a control, we have to call the | |
598 | // setup of our parent ourselves | |
599 | status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ; | |
600 | } | |
601 | */ | |
602 | } | |
603 | } | |
604 | break ; | |
605 | default : | |
606 | break ; | |
607 | } | |
608 | return status ; | |
609 | } | |
610 | ||
611 | ||
612 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ; | |
613 | pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) | |
614 | { | |
615 | if ( partCode != 0) | |
616 | { | |
617 | wxWindow* wx = wxFindControlFromMacControl( control ) ; | |
618 | if ( wx ) | |
619 | { | |
620 | wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; | |
621 | } | |
622 | } | |
623 | } | |
624 | ||
625 | // ---------------------------------------------------------------------------- | |
626 | // constructors and such | |
627 | // ---------------------------------------------------------------------------- | |
628 | ||
629 | wxWindowMac::wxWindowMac() | |
630 | { | |
631 | Init(); | |
632 | } | |
633 | ||
634 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
635 | wxWindowID id, | |
636 | const wxPoint& pos , | |
637 | const wxSize& size , | |
638 | long style , | |
639 | const wxString& name ) | |
640 | { | |
641 | Init(); | |
642 | Create(parent, id, pos, size, style, name); | |
643 | } | |
644 | ||
645 | void wxWindowMac::Init() | |
646 | { | |
647 | m_peer = NULL ; | |
648 | m_frozenness = 0 ; | |
649 | #if WXWIN_COMPATIBILITY_2_4 | |
650 | m_backgroundTransparent = FALSE; | |
651 | #endif | |
652 | ||
653 | // as all windows are created with WS_VISIBLE style... | |
654 | m_isShown = TRUE; | |
655 | ||
656 | m_hScrollBar = NULL ; | |
657 | m_vScrollBar = NULL ; | |
658 | m_macBackgroundBrush = wxNullBrush ; | |
659 | ||
660 | m_macIsUserPane = TRUE; | |
661 | ||
662 | // make sure all proc ptrs are available | |
663 | ||
664 | if ( gControlUserPaneDrawUPP == NULL ) | |
665 | { | |
666 | gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ; | |
667 | gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ; | |
668 | gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ; | |
669 | gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ; | |
670 | gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ; | |
671 | gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ; | |
672 | gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ; | |
673 | gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ; | |
674 | } | |
675 | if ( wxMacLiveScrollbarActionUPP == NULL ) | |
676 | { | |
677 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); | |
678 | } | |
679 | ||
680 | if ( wxMacSetupControlBackgroundUPP == NULL ) | |
681 | { | |
682 | wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; | |
683 | } | |
684 | ||
685 | // we need a valid font for the encodings | |
686 | wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
687 | } | |
688 | ||
689 | // Destructor | |
690 | wxWindowMac::~wxWindowMac() | |
691 | { | |
692 | SendDestroyEvent(); | |
693 | ||
694 | m_isBeingDeleted = TRUE; | |
695 | ||
696 | if ( m_peer ) | |
697 | { | |
698 | // deleting a window while it is shown invalidates the region occupied by border or | |
699 | // focus | |
700 | int outerBorder = MacGetLeftBorderSize() ; | |
701 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
702 | outerBorder += 4 ; | |
703 | ||
704 | if ( IsShown() && ( outerBorder > 0 ) ) | |
705 | { | |
706 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
707 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
708 | ||
709 | Rect rect ; | |
710 | ||
711 | m_peer->GetRect( &rect ) ; | |
712 | RectRgn( updateInner , &rect ) ; | |
713 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
714 | RectRgn( updateOuter , &rect ) ; | |
715 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
716 | wxPoint parent(0,0); | |
717 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
718 | parent -= GetParent()->GetClientAreaOrigin() ; | |
719 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
720 | CopyRgn( updateOuter , updateTotal ) ; | |
721 | ||
722 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
723 | DisposeRgn(updateOuter) ; | |
724 | DisposeRgn(updateInner) ; | |
725 | DisposeRgn(updateTotal) ; | |
726 | } | |
727 | } | |
728 | ||
729 | #ifndef __WXUNIVERSAL__ | |
730 | // VS: make sure there's no wxFrame with last focus set to us: | |
731 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
732 | { | |
733 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
734 | if ( frame ) | |
735 | { | |
736 | if ( frame->GetLastFocus() == this ) | |
737 | { | |
738 | frame->SetLastFocus((wxWindow*)NULL); | |
739 | } | |
740 | break; | |
741 | } | |
742 | } | |
743 | #endif // __WXUNIVERSAL__ | |
744 | ||
745 | // wxRemoveMacControlAssociation( this ) ; | |
746 | // If we delete an item, we should initialize the parent panel, | |
747 | // because it could now be invalid. | |
748 | wxWindow *parent = GetParent() ; | |
749 | if ( parent ) | |
750 | { | |
751 | if (parent->GetDefaultItem() == (wxButton*) this) | |
752 | parent->SetDefaultItem(NULL); | |
753 | } | |
754 | if ( m_peer && m_peer->Ok() ) | |
755 | { | |
756 | // in case the callback might be called during destruction | |
757 | wxRemoveMacControlAssociation( this) ; | |
758 | // we currently are not using this hook | |
759 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
760 | m_peer->Dispose() ; | |
761 | } | |
762 | ||
763 | if ( g_MacLastWindow == this ) | |
764 | { | |
765 | g_MacLastWindow = NULL ; | |
766 | } | |
767 | ||
768 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; | |
769 | if ( frame ) | |
770 | { | |
771 | if ( frame->GetLastFocus() == this ) | |
772 | frame->SetLastFocus( NULL ) ; | |
773 | } | |
774 | ||
775 | DestroyChildren(); | |
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 | ||
801 | } | |
802 | ||
803 | // Constructor | |
804 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, | |
805 | const wxPoint& pos, | |
806 | const wxSize& size, | |
807 | long style, | |
808 | const wxString& name) | |
809 | { | |
810 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); | |
811 | ||
812 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
813 | return FALSE; | |
814 | ||
815 | parent->AddChild(this); | |
816 | ||
817 | m_windowVariant = parent->GetWindowVariant() ; | |
818 | ||
819 | if ( m_macIsUserPane ) | |
820 | { | |
821 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
822 | ||
823 | UInt32 features = 0 | |
824 | | kControlSupportsEmbedding | |
825 | // | kControlSupportsLiveFeedback | |
826 | // | kControlHasSpecialBackground | |
827 | // | kControlSupportsCalcBestRect | |
828 | // | kControlHandlesTracking | |
829 | | kControlSupportsFocus | |
830 | // | kControlWantsActivate | |
831 | // | kControlWantsIdle | |
832 | ; | |
833 | ||
834 | m_peer = new wxMacControl() ; | |
835 | ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); | |
836 | ||
837 | ||
838 | MacPostControlCreate(pos,size) ; | |
839 | #if !TARGET_API_MAC_OSX | |
840 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ; | |
841 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ; | |
842 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ; | |
843 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ; | |
844 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ; | |
845 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ; | |
846 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ; | |
847 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ; | |
848 | #endif | |
849 | } | |
850 | #ifndef __WXUNIVERSAL__ | |
851 | // Don't give scrollbars to wxControls unless they ask for them | |
852 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
853 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
854 | { | |
855 | MacCreateScrollBars( style ) ; | |
856 | } | |
857 | #endif | |
858 | ||
859 | wxWindowCreateEvent event(this); | |
860 | GetEventHandler()->AddPendingEvent(event); | |
861 | ||
862 | return TRUE; | |
863 | } | |
864 | ||
865 | void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) | |
866 | { | |
867 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; | |
868 | ||
869 | m_peer->SetReference( (long) this ) ; | |
870 | ||
871 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); | |
872 | ||
873 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
874 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
875 | ::EmbedControl( m_peer->GetControlRef() , container ) ; | |
876 | ||
877 | // adjust font, controlsize etc | |
878 | DoSetWindowVariant( m_windowVariant ) ; | |
879 | ||
880 | #if !TARGET_API_MAC_OSX | |
881 | // eventually we can fix some clipping issues be reactivating this hook | |
882 | //if ( m_macIsUserPane ) | |
883 | // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ; | |
884 | #endif | |
885 | m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; | |
886 | ||
887 | if (!m_macIsUserPane) | |
888 | { | |
889 | SetInitialBestSize(size); | |
890 | } | |
891 | ||
892 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
893 | } | |
894 | ||
895 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
896 | { | |
897 | // Don't assert, in case we set the window variant before | |
898 | // the window is created | |
899 | // wxASSERT( m_peer->Ok() ) ; | |
900 | ||
901 | m_windowVariant = variant ; | |
902 | ||
903 | if (m_peer == NULL || !m_peer->Ok()) | |
904 | return; | |
905 | ||
906 | ControlSize size ; | |
907 | ThemeFontID themeFont = kThemeSystemFont ; | |
908 | ||
909 | // we will get that from the settings later | |
910 | // and make this NORMAL later, but first | |
911 | // we have a few calculations that we must fix | |
912 | ||
913 | switch ( variant ) | |
914 | { | |
915 | case wxWINDOW_VARIANT_NORMAL : | |
916 | size = kControlSizeNormal; | |
917 | themeFont = kThemeSystemFont ; | |
918 | break ; | |
919 | case wxWINDOW_VARIANT_SMALL : | |
920 | size = kControlSizeSmall; | |
921 | themeFont = kThemeSmallSystemFont ; | |
922 | break ; | |
923 | case wxWINDOW_VARIANT_MINI : | |
924 | if (UMAGetSystemVersion() >= 0x1030 ) | |
925 | { | |
926 | // not always defined in the headers | |
927 | size = 3 ; | |
928 | themeFont = 109 ; | |
929 | } | |
930 | else | |
931 | { | |
932 | size = kControlSizeSmall; | |
933 | themeFont = kThemeSmallSystemFont ; | |
934 | } | |
935 | break ; | |
936 | case wxWINDOW_VARIANT_LARGE : | |
937 | size = kControlSizeLarge; | |
938 | themeFont = kThemeSystemFont ; | |
939 | break ; | |
940 | default: | |
941 | wxFAIL_MSG(_T("unexpected window variant")); | |
942 | break ; | |
943 | } | |
944 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ; | |
945 | ||
946 | wxFont font ; | |
947 | font.MacCreateThemeFont( themeFont ) ; | |
948 | SetFont( font ) ; | |
949 | } | |
950 | ||
951 | void wxWindowMac::MacUpdateControlFont() | |
952 | { | |
953 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; | |
954 | Refresh() ; | |
955 | } | |
956 | ||
957 | bool wxWindowMac::SetFont(const wxFont& font) | |
958 | { | |
959 | bool retval = !wxWindowBase::SetFont( font ) ; | |
960 | ||
961 | MacUpdateControlFont() ; | |
962 | ||
963 | return retval; | |
964 | } | |
965 | ||
966 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
967 | { | |
968 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
969 | return false ; | |
970 | ||
971 | MacUpdateControlFont() ; | |
972 | ||
973 | return true ; | |
974 | } | |
975 | ||
976 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
977 | { | |
978 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
979 | return false ; | |
980 | ||
981 | wxBrush brush ; | |
982 | wxColour newCol(GetBackgroundColour()); | |
983 | if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
984 | { | |
985 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; | |
986 | } | |
987 | else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
988 | { | |
989 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
990 | } | |
991 | else | |
992 | { | |
993 | brush.SetColour( newCol ) ; | |
994 | } | |
995 | MacSetBackgroundBrush( brush ) ; | |
996 | ||
997 | MacUpdateControlFont() ; | |
998 | ||
999 | return true ; | |
1000 | } | |
1001 | ||
1002 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) | |
1003 | { | |
1004 | m_macBackgroundBrush = brush ; | |
1005 | m_peer->SetBackground( brush ) ; | |
1006 | } | |
1007 | ||
1008 | bool wxWindowMac::MacCanFocus() const | |
1009 | { | |
1010 | // there is currently no way to determine whether the window is running in full keyboard | |
1011 | // access mode, therefore we cannot rely on these features, yet the only other way would be | |
1012 | // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems | |
1013 | // in event handlers... | |
1014 | UInt32 features = 0 ; | |
1015 | m_peer->GetFeatures( & features ) ; | |
1016 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; | |
1017 | } | |
1018 | ||
1019 | ||
1020 | void wxWindowMac::SetFocus() | |
1021 | { | |
1022 | if ( AcceptsFocus() ) | |
1023 | { | |
1024 | ||
1025 | wxWindow* former = FindFocus() ; | |
1026 | if ( former == this ) | |
1027 | return ; | |
1028 | ||
1029 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; | |
1030 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only | |
1031 | // leave in case of an error | |
1032 | if ( err == errCouldntSetFocus ) | |
1033 | return ; | |
1034 | ||
1035 | #if !TARGET_API_MAC_OSX | |
1036 | // emulate carbon events when running under carbonlib where they are not natively available | |
1037 | if ( former ) | |
1038 | { | |
1039 | EventRef evRef = NULL ; | |
1040 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1041 | &evRef ) ); | |
1042 | ||
1043 | wxMacCarbonEvent cEvent( evRef ) ; | |
1044 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1045 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
1046 | ||
1047 | wxMacWindowEventHandler( NULL , evRef , former ) ; | |
1048 | ReleaseEvent(evRef) ; | |
1049 | } | |
1050 | // send new focus event | |
1051 | { | |
1052 | EventRef evRef = NULL ; | |
1053 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1054 | &evRef ) ); | |
1055 | ||
1056 | wxMacCarbonEvent cEvent( evRef ) ; | |
1057 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1058 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
1059 | ||
1060 | wxMacWindowEventHandler( NULL , evRef , this ) ; | |
1061 | ReleaseEvent(evRef) ; | |
1062 | } | |
1063 | #endif | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | ||
1068 | void wxWindowMac::DoCaptureMouse() | |
1069 | { | |
1070 | wxTheApp->s_captureWindow = this ; | |
1071 | } | |
1072 | ||
1073 | wxWindow* wxWindowBase::GetCapture() | |
1074 | { | |
1075 | return wxTheApp->s_captureWindow ; | |
1076 | } | |
1077 | ||
1078 | void wxWindowMac::DoReleaseMouse() | |
1079 | { | |
1080 | wxTheApp->s_captureWindow = NULL ; | |
1081 | } | |
1082 | ||
1083 | #if wxUSE_DRAG_AND_DROP | |
1084 | ||
1085 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) | |
1086 | { | |
1087 | if ( m_dropTarget != 0 ) { | |
1088 | delete m_dropTarget; | |
1089 | } | |
1090 | ||
1091 | m_dropTarget = pDropTarget; | |
1092 | if ( m_dropTarget != 0 ) | |
1093 | { | |
1094 | // TODO | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | #endif | |
1099 | ||
1100 | // Old style file-manager drag&drop | |
1101 | void wxWindowMac::DragAcceptFiles(bool accept) | |
1102 | { | |
1103 | // TODO | |
1104 | } | |
1105 | ||
1106 | // Returns the size of the native control. In the case of the toplevel window | |
1107 | // this is the content area root control | |
1108 | ||
1109 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, | |
1110 | int& w, int& h) const | |
1111 | { | |
1112 | Rect bounds ; | |
1113 | m_peer->GetRect( &bounds ) ; | |
1114 | ||
1115 | ||
1116 | x = bounds.left ; | |
1117 | y = bounds.top ; | |
1118 | w = bounds.right - bounds.left ; | |
1119 | h = bounds.bottom - bounds.top ; | |
1120 | } | |
1121 | ||
1122 | // From a wx position / size calculate the appropriate size of the native control | |
1123 | ||
1124 | bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, | |
1125 | const wxSize& size, | |
1126 | int& x, int& y, | |
1127 | int& w, int& h , bool adjustOrigin ) const | |
1128 | { | |
1129 | // the desired size, minus the border pixels gives the correct size of the control | |
1130 | ||
1131 | x = (int)pos.x; | |
1132 | y = (int)pos.y; | |
1133 | // todo the default calls may be used as soon as PostCreateControl Is moved here | |
1134 | w = size.x ; // WidthDefault( size.x ); | |
1135 | h = size.y ; // HeightDefault( size.y ) ; | |
1136 | #if !TARGET_API_MAC_OSX | |
1137 | GetParent()->MacWindowToRootWindow( &x , &y ) ; | |
1138 | #endif | |
1139 | ||
1140 | x += MacGetLeftBorderSize() ; | |
1141 | y += MacGetTopBorderSize() ; | |
1142 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1143 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1144 | ||
1145 | if ( adjustOrigin ) | |
1146 | AdjustForParentClientOrigin( x , y ) ; | |
1147 | #if TARGET_API_MAC_OSX | |
1148 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
1149 | if ( ! GetParent()->IsTopLevel() ) | |
1150 | { | |
1151 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1152 | y -= GetParent()->MacGetTopBorderSize() ; | |
1153 | } | |
1154 | #endif | |
1155 | return true ; | |
1156 | } | |
1157 | ||
1158 | // Get window size (not client size) | |
1159 | void wxWindowMac::DoGetSize(int *x, int *y) const | |
1160 | { | |
1161 | // take the size of the control and add the borders that have to be drawn outside | |
1162 | int x1 , y1 , w1 , h1 ; | |
1163 | ||
1164 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; | |
1165 | ||
1166 | w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1167 | h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1168 | ||
1169 | if(x) *x = w1 ; | |
1170 | if(y) *y = h1 ; | |
1171 | } | |
1172 | ||
1173 | // get the position of the bounds of this window in client coordinates of its parent | |
1174 | void wxWindowMac::DoGetPosition(int *x, int *y) const | |
1175 | { | |
1176 | int x1 , y1 , w1 ,h1 ; | |
1177 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; | |
1178 | x1 -= MacGetLeftBorderSize() ; | |
1179 | y1 -= MacGetTopBorderSize() ; | |
1180 | // to non-client | |
1181 | #if !TARGET_API_MAC_OSX | |
1182 | if ( !GetParent()->IsTopLevel() ) | |
1183 | { | |
1184 | Rect bounds ; | |
1185 | GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ; | |
1186 | x1 -= bounds.left ; | |
1187 | y1 -= bounds.top ; | |
1188 | } | |
1189 | #endif | |
1190 | if ( !IsTopLevel() ) | |
1191 | { | |
1192 | wxWindow *parent = GetParent(); | |
1193 | if ( parent ) | |
1194 | { | |
1195 | // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix | |
1196 | x1 += parent->MacGetLeftBorderSize() ; | |
1197 | y1 += parent->MacGetTopBorderSize() ; | |
1198 | // and now to client coordinates | |
1199 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1200 | x1 -= pt.x ; | |
1201 | y1 -= pt.y ; | |
1202 | } | |
1203 | } | |
1204 | if(x) *x = x1 ; | |
1205 | if(y) *y = y1 ; | |
1206 | } | |
1207 | ||
1208 | void wxWindowMac::DoScreenToClient(int *x, int *y) const | |
1209 | { | |
1210 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
1211 | ||
1212 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
1213 | ||
1214 | { | |
1215 | Point localwhere = {0,0} ; | |
1216 | ||
1217 | if(x) localwhere.h = * x ; | |
1218 | if(y) localwhere.v = * y ; | |
1219 | ||
1220 | QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ; | |
1221 | if(x) *x = localwhere.h ; | |
1222 | if(y) *y = localwhere.v ; | |
1223 | ||
1224 | } | |
1225 | MacRootWindowToWindow( x , y ) ; | |
1226 | ||
1227 | wxPoint origin = GetClientAreaOrigin() ; | |
1228 | if(x) *x -= origin.x ; | |
1229 | if(y) *y -= origin.y ; | |
1230 | } | |
1231 | ||
1232 | void wxWindowMac::DoClientToScreen(int *x, int *y) const | |
1233 | { | |
1234 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
1235 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
1236 | ||
1237 | wxPoint origin = GetClientAreaOrigin() ; | |
1238 | if(x) *x += origin.x ; | |
1239 | if(y) *y += origin.y ; | |
1240 | ||
1241 | MacWindowToRootWindow( x , y ) ; | |
1242 | ||
1243 | { | |
1244 | Point localwhere = { 0,0 }; | |
1245 | if(x) localwhere.h = * x ; | |
1246 | if(y) localwhere.v = * y ; | |
1247 | QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ; | |
1248 | if(x) *x = localwhere.h ; | |
1249 | if(y) *y = localwhere.v ; | |
1250 | } | |
1251 | } | |
1252 | ||
1253 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const | |
1254 | { | |
1255 | wxPoint origin = GetClientAreaOrigin() ; | |
1256 | if(x) *x += origin.x ; | |
1257 | if(y) *y += origin.y ; | |
1258 | ||
1259 | MacWindowToRootWindow( x , y ) ; | |
1260 | } | |
1261 | ||
1262 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1263 | { | |
1264 | MacRootWindowToWindow( x , y ) ; | |
1265 | ||
1266 | wxPoint origin = GetClientAreaOrigin() ; | |
1267 | if(x) *x -= origin.x ; | |
1268 | if(y) *y -= origin.y ; | |
1269 | } | |
1270 | ||
1271 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1272 | { | |
1273 | #if TARGET_API_MAC_OSX | |
1274 | wxPoint pt ; | |
1275 | if ( x ) pt.x = *x ; | |
1276 | if ( y ) pt.y = *y ; | |
1277 | ||
1278 | if ( !IsTopLevel() ) | |
1279 | { | |
1280 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1281 | if (top) | |
1282 | { | |
1283 | pt.x -= MacGetLeftBorderSize() ; | |
1284 | pt.y -= MacGetTopBorderSize() ; | |
1285 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1286 | } | |
1287 | } | |
1288 | ||
1289 | if ( x ) *x = (int) pt.x ; | |
1290 | if ( y ) *y = (int) pt.y ; | |
1291 | #else | |
1292 | if ( !IsTopLevel() ) | |
1293 | { | |
1294 | Rect bounds ; | |
1295 | m_peer->GetRect( &bounds ) ; | |
1296 | if(x) *x += bounds.left - MacGetLeftBorderSize() ; | |
1297 | if(y) *y += bounds.top - MacGetTopBorderSize() ; | |
1298 | } | |
1299 | #endif | |
1300 | } | |
1301 | ||
1302 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1303 | { | |
1304 | int x1 , y1 ; | |
1305 | if ( x ) x1 = *x ; | |
1306 | if ( y ) y1 = *y ; | |
1307 | MacWindowToRootWindow( &x1 , &y1 ) ; | |
1308 | if ( x ) *x = x1 ; | |
1309 | if ( y ) *y = y1 ; | |
1310 | } | |
1311 | ||
1312 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const | |
1313 | { | |
1314 | #if TARGET_API_MAC_OSX | |
1315 | wxPoint pt ; | |
1316 | if ( x ) pt.x = *x ; | |
1317 | if ( y ) pt.y = *y ; | |
1318 | ||
1319 | if ( !IsTopLevel() ) | |
1320 | { | |
1321 | wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ; | |
1322 | pt.x += MacGetLeftBorderSize() ; | |
1323 | pt.y += MacGetTopBorderSize() ; | |
1324 | } | |
1325 | ||
1326 | if ( x ) *x = (int) pt.x ; | |
1327 | if ( y ) *y = (int) pt.y ; | |
1328 | #else | |
1329 | if ( !IsTopLevel() ) | |
1330 | { | |
1331 | Rect bounds ; | |
1332 | m_peer->GetRect( &bounds ) ; | |
1333 | if(x) *x -= bounds.left + MacGetLeftBorderSize() ; | |
1334 | if(y) *y -= bounds.top + MacGetTopBorderSize() ; | |
1335 | } | |
1336 | #endif | |
1337 | } | |
1338 | ||
1339 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const | |
1340 | { | |
1341 | int x1 , y1 ; | |
1342 | if ( x ) x1 = *x ; | |
1343 | if ( y ) y1 = *y ; | |
1344 | MacRootWindowToWindow( &x1 , &y1 ) ; | |
1345 | if ( x ) *x = x1 ; | |
1346 | if ( y ) *y = y1 ; | |
1347 | } | |
1348 | ||
1349 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) | |
1350 | { | |
1351 | RgnHandle rgn = NewRgn() ; | |
1352 | Rect content ; | |
1353 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1354 | { | |
1355 | GetRegionBounds( rgn , &content ) ; | |
1356 | DisposeRgn( rgn ) ; | |
1357 | } | |
1358 | else | |
1359 | { | |
1360 | m_peer->GetRect( &content ) ; | |
1361 | } | |
1362 | Rect structure ; | |
1363 | m_peer->GetRect( &structure ) ; | |
1364 | #if !TARGET_API_MAC_OSX | |
1365 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1366 | #endif | |
1367 | left = content.left - structure.left ; | |
1368 | top = content.top - structure.top ; | |
1369 | right = structure.right - content.right ; | |
1370 | bottom = structure.bottom - content.bottom ; | |
1371 | } | |
1372 | ||
1373 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const | |
1374 | { | |
1375 | wxSize sizeTotal = size; | |
1376 | ||
1377 | RgnHandle rgn = NewRgn() ; | |
1378 | ||
1379 | Rect content ; | |
1380 | ||
1381 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1382 | { | |
1383 | GetRegionBounds( rgn , &content ) ; | |
1384 | DisposeRgn( rgn ) ; | |
1385 | } | |
1386 | else | |
1387 | { | |
1388 | m_peer->GetRect( &content ) ; | |
1389 | } | |
1390 | Rect structure ; | |
1391 | m_peer->GetRect( &structure ) ; | |
1392 | #if !TARGET_API_MAC_OSX | |
1393 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1394 | #endif | |
1395 | ||
1396 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; | |
1397 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; | |
1398 | ||
1399 | sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; | |
1400 | sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
1401 | ||
1402 | return sizeTotal; | |
1403 | } | |
1404 | ||
1405 | ||
1406 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
1407 | void wxWindowMac::DoGetClientSize(int *x, int *y) const | |
1408 | { | |
1409 | int ww, hh; | |
1410 | ||
1411 | RgnHandle rgn = NewRgn() ; | |
1412 | Rect content ; | |
1413 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) | |
1414 | { | |
1415 | GetRegionBounds( rgn , &content ) ; | |
1416 | DisposeRgn( rgn ) ; | |
1417 | } | |
1418 | else | |
1419 | { | |
1420 | m_peer->GetRect( &content ) ; | |
1421 | } | |
1422 | #if !TARGET_API_MAC_OSX | |
1423 | Rect structure ; | |
1424 | m_peer->GetRect( &structure ) ; | |
1425 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1426 | #endif | |
1427 | ww = content.right - content.left ; | |
1428 | hh = content.bottom - content.top ; | |
1429 | /* | |
1430 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; | |
1431 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
1432 | */ | |
1433 | /* | |
1434 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) | |
1435 | { | |
1436 | int x1 = 0 ; | |
1437 | int y1 = 0 ; | |
1438 | int w ; | |
1439 | int h ; | |
1440 | GetSize( &w , &h ) ; | |
1441 | ||
1442 | MacClientToRootWindow( &x1 , &y1 ) ; | |
1443 | MacClientToRootWindow( &w , &h ) ; | |
1444 | ||
1445 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1446 | ||
1447 | int totW = 10000 , totH = 10000; | |
1448 | while( iter ) | |
1449 | { | |
1450 | if ( iter->IsTopLevel() ) | |
1451 | { | |
1452 | iter->GetSize( &totW , &totH ) ; | |
1453 | break ; | |
1454 | } | |
1455 | ||
1456 | iter = iter->GetParent() ; | |
1457 | } | |
1458 | ||
1459 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
1460 | { | |
1461 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; | |
1462 | if ( h-y1 >= totH ) | |
1463 | { | |
1464 | hh += 1 ; | |
1465 | } | |
1466 | } | |
1467 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1468 | { | |
1469 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; | |
1470 | if ( w-x1 >= totW ) | |
1471 | { | |
1472 | ww += 1 ; | |
1473 | } | |
1474 | } | |
1475 | } | |
1476 | */ | |
1477 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
1478 | { | |
1479 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; | |
1480 | } | |
1481 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1482 | { | |
1483 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; | |
1484 | } | |
1485 | if(x) *x = ww; | |
1486 | if(y) *y = hh; | |
1487 | ||
1488 | } | |
1489 | ||
1490 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1491 | { | |
1492 | if (m_cursor == cursor) | |
1493 | return FALSE; | |
1494 | ||
1495 | if (wxNullCursor == cursor) | |
1496 | { | |
1497 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
1498 | return FALSE ; | |
1499 | } | |
1500 | else | |
1501 | { | |
1502 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
1503 | return FALSE ; | |
1504 | } | |
1505 | ||
1506 | wxASSERT_MSG( m_cursor.Ok(), | |
1507 | wxT("cursor must be valid after call to the base version")); | |
1508 | ||
1509 | ||
1510 | wxWindowMac *mouseWin = 0 ; | |
1511 | { | |
1512 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
1513 | CGrafPtr savePort ; | |
1514 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
1515 | ||
1516 | // TODO If we ever get a GetCurrentEvent.. replacement for the mouse | |
1517 | // position, use it... | |
1518 | ||
1519 | Point pt ; | |
1520 | GetMouse( &pt ) ; | |
1521 | ControlPartCode part ; | |
1522 | ControlRef control ; | |
1523 | control = wxMacFindControlUnderMouse( pt , window , &part ) ; | |
1524 | if ( control ) | |
1525 | mouseWin = wxFindControlFromMacControl( control ) ; | |
1526 | ||
1527 | if ( swapped ) | |
1528 | QDSwapPort( savePort , NULL ) ; | |
1529 | } | |
1530 | ||
1531 | if ( mouseWin == this && !wxIsBusy() ) | |
1532 | { | |
1533 | m_cursor.MacInstall() ; | |
1534 | } | |
1535 | ||
1536 | return TRUE ; | |
1537 | } | |
1538 | ||
1539 | #if wxUSE_MENUS | |
1540 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1541 | { | |
1542 | menu->SetInvokingWindow(this); | |
1543 | menu->UpdateUI(); | |
1544 | ||
1545 | if ( x == -1 && y == -1 ) | |
1546 | { | |
1547 | wxPoint mouse = wxGetMousePosition(); | |
1548 | x = mouse.x; y = mouse.y; | |
1549 | } | |
1550 | else | |
1551 | { | |
1552 | ClientToScreen( &x , &y ) ; | |
1553 | } | |
1554 | ||
1555 | menu->MacBeforeDisplay( true ) ; | |
1556 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
1557 | if ( HiWord(menuResult) != 0 ) | |
1558 | { | |
1559 | MenuCommand id ; | |
1560 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
1561 | wxMenuItem* item = NULL ; | |
1562 | wxMenu* realmenu ; | |
1563 | item = menu->FindItem(id, &realmenu) ; | |
1564 | if (item->IsCheckable()) | |
1565 | { | |
1566 | item->Check( !item->IsChecked() ) ; | |
1567 | } | |
1568 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
1569 | } | |
1570 | menu->MacAfterDisplay( true ) ; | |
1571 | ||
1572 | menu->SetInvokingWindow(NULL); | |
1573 | ||
1574 | return TRUE; | |
1575 | } | |
1576 | #endif | |
1577 | ||
1578 | // ---------------------------------------------------------------------------- | |
1579 | // tooltips | |
1580 | // ---------------------------------------------------------------------------- | |
1581 | ||
1582 | #if wxUSE_TOOLTIPS | |
1583 | ||
1584 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) | |
1585 | { | |
1586 | wxWindowBase::DoSetToolTip(tooltip); | |
1587 | ||
1588 | if ( m_tooltip ) | |
1589 | m_tooltip->SetWindow(this); | |
1590 | } | |
1591 | ||
1592 | #endif // wxUSE_TOOLTIPS | |
1593 | ||
1594 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1595 | { | |
1596 | // this is never called for a toplevel window, so we know we have a parent | |
1597 | int former_x , former_y , former_w, former_h ; | |
1598 | ||
1599 | // Get true coordinates of former position | |
1600 | DoGetPosition( &former_x , &former_y ) ; | |
1601 | DoGetSize( &former_w , &former_h ) ; | |
1602 | ||
1603 | wxWindow *parent = GetParent(); | |
1604 | if ( parent ) | |
1605 | { | |
1606 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1607 | former_x += pt.x ; | |
1608 | former_y += pt.y ; | |
1609 | } | |
1610 | ||
1611 | int actualWidth = width; | |
1612 | int actualHeight = height; | |
1613 | int actualX = x; | |
1614 | int actualY = y; | |
1615 | ||
1616 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
1617 | actualWidth = m_minWidth; | |
1618 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
1619 | actualHeight = m_minHeight; | |
1620 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
1621 | actualWidth = m_maxWidth; | |
1622 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
1623 | actualHeight = m_maxHeight; | |
1624 | ||
1625 | bool doMove = false ; | |
1626 | bool doResize = false ; | |
1627 | ||
1628 | if ( actualX != former_x || actualY != former_y ) | |
1629 | { | |
1630 | doMove = true ; | |
1631 | } | |
1632 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1633 | { | |
1634 | doResize = true ; | |
1635 | } | |
1636 | ||
1637 | if ( doMove || doResize ) | |
1638 | { | |
1639 | // we don't adjust twice for the origin | |
1640 | Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; | |
1641 | bool vis = m_peer->IsVisible(); | |
1642 | ||
1643 | int outerBorder = MacGetLeftBorderSize() ; | |
1644 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
1645 | outerBorder += 4 ; | |
1646 | ||
1647 | if ( vis && ( outerBorder > 0 ) ) | |
1648 | { | |
1649 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1650 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1651 | ||
1652 | Rect rect ; | |
1653 | ||
1654 | m_peer->GetRect( &rect ) ; | |
1655 | RectRgn( updateInner , &rect ) ; | |
1656 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1657 | RectRgn( updateOuter , &rect ) ; | |
1658 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1659 | wxPoint parent(0,0); | |
1660 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1661 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1662 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
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 | UnionRgn( updateOuter , updateTotal , updateTotal ) ; | |
1673 | ||
1674 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
1675 | DisposeRgn(updateOuter) ; | |
1676 | DisposeRgn(updateInner) ; | |
1677 | DisposeRgn(updateTotal) ; | |
1678 | } | |
1679 | ||
1680 | // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! | |
1681 | if ( vis ) | |
1682 | m_peer->SetVisibility( false , true ) ; | |
1683 | ||
1684 | m_peer->SetRect( &r ) ; | |
1685 | if ( vis ) | |
1686 | m_peer->SetVisibility( true , true ) ; | |
1687 | ||
1688 | MacRepositionScrollBars() ; | |
1689 | if ( doMove ) | |
1690 | { | |
1691 | wxPoint point(actualX,actualY); | |
1692 | wxMoveEvent event(point, m_windowId); | |
1693 | event.SetEventObject(this); | |
1694 | GetEventHandler()->ProcessEvent(event) ; | |
1695 | } | |
1696 | if ( doResize ) | |
1697 | { | |
1698 | MacRepositionScrollBars() ; | |
1699 | wxSize size(actualWidth, actualHeight); | |
1700 | wxSizeEvent event(size, m_windowId); | |
1701 | event.SetEventObject(this); | |
1702 | GetEventHandler()->ProcessEvent(event); | |
1703 | } | |
1704 | } | |
1705 | ||
1706 | } | |
1707 | ||
1708 | wxSize wxWindowMac::DoGetBestSize() const | |
1709 | { | |
1710 | if ( m_macIsUserPane || IsTopLevel() ) | |
1711 | return wxWindowBase::DoGetBestSize() ; | |
1712 | ||
1713 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
1714 | int bestWidth, bestHeight ; | |
1715 | m_peer->GetBestRect( &bestsize ) ; | |
1716 | ||
1717 | if ( EmptyRect( &bestsize ) ) | |
1718 | { | |
1719 | bestsize.left = bestsize.top = 0 ; | |
1720 | bestsize.right = 16 ; | |
1721 | bestsize.bottom = 16 ; | |
1722 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1723 | { | |
1724 | bestsize.bottom = 16 ; | |
1725 | } | |
1726 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
1727 | { | |
1728 | bestsize.bottom = 24 ; | |
1729 | } | |
1730 | else | |
1731 | { | |
1732 | // return wxWindowBase::DoGetBestSize() ; | |
1733 | } | |
1734 | } | |
1735 | ||
1736 | bestWidth = bestsize.right - bestsize.left ; | |
1737 | bestHeight = bestsize.bottom - bestsize.top ; | |
1738 | if ( bestHeight < 10 ) | |
1739 | bestHeight = 13 ; | |
1740 | ||
1741 | return wxSize(bestWidth, bestHeight); | |
1742 | } | |
1743 | ||
1744 | ||
1745 | // set the size of the window: if the dimensions are positive, just use them, | |
1746 | // but if any of them is equal to -1, it means that we must find the value for | |
1747 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1748 | // which case -1 is a valid value for x and y) | |
1749 | // | |
1750 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1751 | // the width/height to best suit our contents, otherwise we reuse the current | |
1752 | // width/height | |
1753 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1754 | { | |
1755 | // get the current size and position... | |
1756 | int currentX, currentY; | |
1757 | GetPosition(¤tX, ¤tY); | |
1758 | ||
1759 | int currentW,currentH; | |
1760 | GetSize(¤tW, ¤tH); | |
1761 | ||
1762 | // ... and don't do anything (avoiding flicker) if it's already ok | |
1763 | if ( x == currentX && y == currentY && | |
1764 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) | |
1765 | { | |
1766 | // TODO REMOVE | |
1767 | MacRepositionScrollBars() ; // we might have a real position shift | |
1768 | return; | |
1769 | } | |
1770 | ||
1771 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1772 | x = currentX; | |
1773 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1774 | y = currentY; | |
1775 | ||
1776 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
1777 | ||
1778 | wxSize size(-1, -1); | |
1779 | if ( width == -1 ) | |
1780 | { | |
1781 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1782 | { | |
1783 | size = DoGetBestSize(); | |
1784 | width = size.x; | |
1785 | } | |
1786 | else | |
1787 | { | |
1788 | // just take the current one | |
1789 | width = currentW; | |
1790 | } | |
1791 | } | |
1792 | ||
1793 | if ( height == -1 ) | |
1794 | { | |
1795 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1796 | { | |
1797 | if ( size.x == -1 ) | |
1798 | { | |
1799 | size = DoGetBestSize(); | |
1800 | } | |
1801 | //else: already called DoGetBestSize() above | |
1802 | ||
1803 | height = size.y; | |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | // just take the current one | |
1808 | height = currentH; | |
1809 | } | |
1810 | } | |
1811 | ||
1812 | DoMoveWindow(x, y, width, height); | |
1813 | ||
1814 | } | |
1815 | ||
1816 | wxPoint wxWindowMac::GetClientAreaOrigin() const | |
1817 | { | |
1818 | RgnHandle rgn = NewRgn() ; | |
1819 | Rect content ; | |
1820 | m_peer->GetRegion( kControlContentMetaPart , rgn ) ; | |
1821 | GetRegionBounds( rgn , &content ) ; | |
1822 | DisposeRgn( rgn ) ; | |
1823 | #if !TARGET_API_MAC_OSX | |
1824 | // if the content rgn is empty / not supported | |
1825 | // don't attempt to correct the coordinates to wxWindow relative ones | |
1826 | if (!::EmptyRect( &content ) ) | |
1827 | { | |
1828 | Rect structure ; | |
1829 | m_peer->GetRect( &structure ) ; | |
1830 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1831 | } | |
1832 | #endif | |
1833 | ||
1834 | return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); | |
1835 | } | |
1836 | ||
1837 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1838 | { | |
1839 | if ( clientheight != -1 || clientheight != -1 ) | |
1840 | { | |
1841 | int currentclientwidth , currentclientheight ; | |
1842 | int currentwidth , currentheight ; | |
1843 | ||
1844 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1845 | GetSize( ¤twidth , ¤theight ) ; | |
1846 | ||
1847 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
1848 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1849 | } | |
1850 | } | |
1851 | ||
1852 | void wxWindowMac::SetTitle(const wxString& title) | |
1853 | { | |
1854 | m_label = wxStripMenuCodes(title) ; | |
1855 | ||
1856 | if ( m_peer && m_peer->Ok() ) | |
1857 | { | |
1858 | m_peer->SetTitle( m_label ) ; | |
1859 | } | |
1860 | Refresh() ; | |
1861 | } | |
1862 | ||
1863 | wxString wxWindowMac::GetTitle() const | |
1864 | { | |
1865 | return m_label ; | |
1866 | } | |
1867 | ||
1868 | bool wxWindowMac::Show(bool show) | |
1869 | { | |
1870 | if ( !wxWindowBase::Show(show) ) | |
1871 | return FALSE; | |
1872 | ||
1873 | // TODO use visibilityChanged Carbon Event for OSX | |
1874 | bool former = MacIsReallyShown() ; | |
1875 | ||
1876 | m_peer->SetVisibility( show , true ) ; | |
1877 | if ( former != MacIsReallyShown() ) | |
1878 | MacPropagateVisibilityChanged() ; | |
1879 | return TRUE; | |
1880 | } | |
1881 | ||
1882 | bool wxWindowMac::Enable(bool enable) | |
1883 | { | |
1884 | wxASSERT( m_peer->Ok() ) ; | |
1885 | if ( !wxWindowBase::Enable(enable) ) | |
1886 | return FALSE; | |
1887 | ||
1888 | bool former = MacIsReallyEnabled() ; | |
1889 | m_peer->Enable( enable ) ; | |
1890 | ||
1891 | if ( former != MacIsReallyEnabled() ) | |
1892 | MacPropagateEnabledStateChanged() ; | |
1893 | return TRUE; | |
1894 | } | |
1895 | ||
1896 | // | |
1897 | // status change propagations (will be not necessary for OSX later ) | |
1898 | // | |
1899 | ||
1900 | void wxWindowMac::MacPropagateVisibilityChanged() | |
1901 | { | |
1902 | #if !TARGET_API_MAC_OSX | |
1903 | MacVisibilityChanged() ; | |
1904 | ||
1905 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1906 | while ( node ) | |
1907 | { | |
1908 | wxWindowMac *child = node->GetData(); | |
1909 | if ( child->IsShown() ) | |
1910 | child->MacPropagateVisibilityChanged( ) ; | |
1911 | node = node->GetNext(); | |
1912 | } | |
1913 | #endif | |
1914 | } | |
1915 | ||
1916 | void wxWindowMac::MacPropagateEnabledStateChanged( ) | |
1917 | { | |
1918 | #if !TARGET_API_MAC_OSX | |
1919 | MacEnabledStateChanged() ; | |
1920 | ||
1921 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1922 | while ( node ) | |
1923 | { | |
1924 | wxWindowMac *child = node->GetData(); | |
1925 | if ( child->IsEnabled() ) | |
1926 | child->MacPropagateEnabledStateChanged() ; | |
1927 | node = node->GetNext(); | |
1928 | } | |
1929 | #endif | |
1930 | } | |
1931 | ||
1932 | void wxWindowMac::MacPropagateHiliteChanged( ) | |
1933 | { | |
1934 | #if !TARGET_API_MAC_OSX | |
1935 | MacHiliteChanged() ; | |
1936 | ||
1937 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1938 | while ( node ) | |
1939 | { | |
1940 | wxWindowMac *child = node->GetData(); | |
1941 | // if ( child->IsEnabled() ) | |
1942 | child->MacPropagateHiliteChanged() ; | |
1943 | node = node->GetNext(); | |
1944 | } | |
1945 | #endif | |
1946 | } | |
1947 | ||
1948 | // | |
1949 | // status change notifications | |
1950 | // | |
1951 | ||
1952 | void wxWindowMac::MacVisibilityChanged() | |
1953 | { | |
1954 | } | |
1955 | ||
1956 | void wxWindowMac::MacHiliteChanged() | |
1957 | { | |
1958 | } | |
1959 | ||
1960 | void wxWindowMac::MacEnabledStateChanged() | |
1961 | { | |
1962 | } | |
1963 | ||
1964 | // | |
1965 | // status queries on the inherited window's state | |
1966 | // | |
1967 | ||
1968 | bool wxWindowMac::MacIsReallyShown() | |
1969 | { | |
1970 | // only under OSX the visibility of the TLW is taken into account | |
1971 | #if TARGET_API_MAC_OSX | |
1972 | if ( m_peer && m_peer->Ok() ) | |
1973 | return m_peer->IsVisible(); | |
1974 | #endif | |
1975 | wxWindow* win = this ; | |
1976 | while( win->IsShown() ) | |
1977 | { | |
1978 | if ( win->IsTopLevel() ) | |
1979 | return true ; | |
1980 | ||
1981 | win = win->GetParent() ; | |
1982 | if ( win == NULL ) | |
1983 | return true ; | |
1984 | ||
1985 | } ; | |
1986 | return false ; | |
1987 | } | |
1988 | ||
1989 | bool wxWindowMac::MacIsReallyEnabled() | |
1990 | { | |
1991 | return m_peer->IsEnabled() ; | |
1992 | } | |
1993 | ||
1994 | bool wxWindowMac::MacIsReallyHilited() | |
1995 | { | |
1996 | return m_peer->IsActive(); | |
1997 | } | |
1998 | ||
1999 | void wxWindowMac::MacFlashInvalidAreas() | |
2000 | { | |
2001 | #if TARGET_API_MAC_OSX | |
2002 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2003 | #endif | |
2004 | } | |
2005 | ||
2006 | // | |
2007 | // | |
2008 | // | |
2009 | ||
2010 | int wxWindowMac::GetCharHeight() const | |
2011 | { | |
2012 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
2013 | return dc.GetCharHeight() ; | |
2014 | } | |
2015 | ||
2016 | int wxWindowMac::GetCharWidth() const | |
2017 | { | |
2018 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
2019 | return dc.GetCharWidth() ; | |
2020 | } | |
2021 | ||
2022 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, | |
2023 | int *descent, int *externalLeading, const wxFont *theFont ) const | |
2024 | { | |
2025 | const wxFont *fontToUse = theFont; | |
2026 | if ( !fontToUse ) | |
2027 | fontToUse = &m_font; | |
2028 | ||
2029 | wxClientDC dc( (wxWindowMac*) this ) ; | |
2030 | long lx,ly,ld,le ; | |
2031 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; | |
2032 | if ( externalLeading ) | |
2033 | *externalLeading = le ; | |
2034 | if ( descent ) | |
2035 | *descent = ld ; | |
2036 | if ( x ) | |
2037 | *x = lx ; | |
2038 | if ( y ) | |
2039 | *y = ly ; | |
2040 | } | |
2041 | ||
2042 | /* | |
2043 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect | |
2044 | * we always intersect with the entire window, not only with the client area | |
2045 | */ | |
2046 | ||
2047 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) | |
2048 | { | |
2049 | if ( m_peer == NULL ) | |
2050 | return ; | |
2051 | ||
2052 | #if TARGET_API_MAC_OSX | |
2053 | if ( rect == NULL ) | |
2054 | m_peer->SetNeedsDisplay( true ) ; | |
2055 | else | |
2056 | { | |
2057 | RgnHandle update = NewRgn() ; | |
2058 | SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
2059 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; | |
2060 | wxPoint origin = GetClientAreaOrigin() ; | |
2061 | OffsetRgn( update, origin.x , origin.y ) ; | |
2062 | // right now this is wx' window coordinates, as our native peer does not have borders, this is | |
2063 | // inset | |
2064 | OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
2065 | m_peer->SetNeedsDisplay( true , update) ; | |
2066 | DisposeRgn( update ) ; | |
2067 | } | |
2068 | #else | |
2069 | /* | |
2070 | RgnHandle updateRgn = NewRgn() ; | |
2071 | if ( rect == NULL ) | |
2072 | { | |
2073 | CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ; | |
2074 | } | |
2075 | else | |
2076 | { | |
2077 | SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
2078 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ; | |
2079 | } | |
2080 | InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; | |
2081 | DisposeRgn(updateRgn) ; | |
2082 | */ | |
2083 | if ( m_peer->IsVisible()) | |
2084 | { | |
2085 | m_peer->SetVisibility( false , false ) ; | |
2086 | m_peer->SetVisibility( true , true ) ; | |
2087 | } | |
2088 | /* | |
2089 | if ( MacGetTopLevelWindow() == NULL ) | |
2090 | return ; | |
2091 | ||
2092 | if ( !m_peer->IsVisible()) | |
2093 | return ; | |
2094 | ||
2095 | wxPoint client = GetClientAreaOrigin(); | |
2096 | int x1 = -client.x; | |
2097 | int y1 = -client.y; | |
2098 | int x2 = m_width - client.x; | |
2099 | int y2 = m_height - client.y; | |
2100 | ||
2101 | if (IsKindOf( CLASSINFO(wxButton))) | |
2102 | { | |
2103 | // buttons have an "aura" | |
2104 | y1 -= 5; | |
2105 | x1 -= 5; | |
2106 | y2 += 5; | |
2107 | x2 += 5; | |
2108 | } | |
2109 | ||
2110 | Rect clientrect = { y1, x1, y2, x2 }; | |
2111 | ||
2112 | if ( rect ) | |
2113 | { | |
2114 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
2115 | SectRect( &clientrect , &r , &clientrect ) ; | |
2116 | } | |
2117 | ||
2118 | if ( !EmptyRect( &clientrect ) ) | |
2119 | { | |
2120 | int top = 0 , left = 0 ; | |
2121 | ||
2122 | MacClientToRootWindow( &left , &top ) ; | |
2123 | OffsetRect( &clientrect , left , top ) ; | |
2124 | ||
2125 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; | |
2126 | } | |
2127 | */ | |
2128 | #endif | |
2129 | } | |
2130 | ||
2131 | void wxWindowMac::Freeze() | |
2132 | { | |
2133 | #if TARGET_API_MAC_OSX | |
2134 | if ( !m_frozenness++ ) | |
2135 | { | |
2136 | m_peer->SetDrawingEnabled( false ) ; | |
2137 | } | |
2138 | #endif | |
2139 | } | |
2140 | ||
2141 | ||
2142 | void wxWindowMac::Thaw() | |
2143 | { | |
2144 | #if TARGET_API_MAC_OSX | |
2145 | wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); | |
2146 | ||
2147 | if ( !--m_frozenness ) | |
2148 | { | |
2149 | m_peer->SetDrawingEnabled( true ) ; | |
2150 | m_peer->InvalidateWithChildren() ; | |
2151 | } | |
2152 | #endif | |
2153 | } | |
2154 | ||
2155 | void wxWindowMac::MacRedrawControl() | |
2156 | { | |
2157 | /* | |
2158 | if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible()) | |
2159 | { | |
2160 | #if TARGET_API_MAC_CARBON | |
2161 | Update() ; | |
2162 | #else | |
2163 | wxClientDC dc(this) ; | |
2164 | wxMacPortSetter helper(&dc) ; | |
2165 | wxMacWindowClipper clipper(this) ; | |
2166 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
2167 | UMADrawControl( *m_peer ) ; | |
2168 | #endif | |
2169 | } | |
2170 | */ | |
2171 | } | |
2172 | ||
2173 | /* TODO | |
2174 | void wxWindowMac::OnPaint(wxPaintEvent& event) | |
2175 | { | |
2176 | // why don't we skip that here ? | |
2177 | } | |
2178 | */ | |
2179 | ||
2180 | wxWindowMac *wxGetActiveWindow() | |
2181 | { | |
2182 | // actually this is a windows-only concept | |
2183 | return NULL; | |
2184 | } | |
2185 | ||
2186 | // Coordinates relative to the window | |
2187 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) | |
2188 | { | |
2189 | // We really don't move the mouse programmatically under Mac. | |
2190 | } | |
2191 | ||
2192 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
2193 | { | |
2194 | #if TARGET_API_MAC_OSX | |
2195 | if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) | |
2196 | { | |
2197 | event.Skip() ; | |
2198 | } | |
2199 | else | |
2200 | #endif | |
2201 | { | |
2202 | event.GetDC()->Clear() ; | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2207 | { | |
2208 | event.Skip() ; | |
2209 | } | |
2210 | ||
2211 | int wxWindowMac::GetScrollPos(int orient) const | |
2212 | { | |
2213 | if ( orient == wxHORIZONTAL ) | |
2214 | { | |
2215 | if ( m_hScrollBar ) | |
2216 | return m_hScrollBar->GetThumbPosition() ; | |
2217 | } | |
2218 | else | |
2219 | { | |
2220 | if ( m_vScrollBar ) | |
2221 | return m_vScrollBar->GetThumbPosition() ; | |
2222 | } | |
2223 | return 0; | |
2224 | } | |
2225 | ||
2226 | // This now returns the whole range, not just the number | |
2227 | // of positions that we can scroll. | |
2228 | int wxWindowMac::GetScrollRange(int orient) const | |
2229 | { | |
2230 | if ( orient == wxHORIZONTAL ) | |
2231 | { | |
2232 | if ( m_hScrollBar ) | |
2233 | return m_hScrollBar->GetRange() ; | |
2234 | } | |
2235 | else | |
2236 | { | |
2237 | if ( m_vScrollBar ) | |
2238 | return m_vScrollBar->GetRange() ; | |
2239 | } | |
2240 | return 0; | |
2241 | } | |
2242 | ||
2243 | int wxWindowMac::GetScrollThumb(int orient) const | |
2244 | { | |
2245 | if ( orient == wxHORIZONTAL ) | |
2246 | { | |
2247 | if ( m_hScrollBar ) | |
2248 | return m_hScrollBar->GetThumbSize() ; | |
2249 | } | |
2250 | else | |
2251 | { | |
2252 | if ( m_vScrollBar ) | |
2253 | return m_vScrollBar->GetThumbSize() ; | |
2254 | } | |
2255 | return 0; | |
2256 | } | |
2257 | ||
2258 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) | |
2259 | { | |
2260 | if ( orient == wxHORIZONTAL ) | |
2261 | { | |
2262 | if ( m_hScrollBar ) | |
2263 | m_hScrollBar->SetThumbPosition( pos ) ; | |
2264 | } | |
2265 | else | |
2266 | { | |
2267 | if ( m_vScrollBar ) | |
2268 | m_vScrollBar->SetThumbPosition( pos ) ; | |
2269 | } | |
2270 | } | |
2271 | ||
2272 | void wxWindowMac::MacPaintBorders( int left , int top ) | |
2273 | { | |
2274 | if( IsTopLevel() ) | |
2275 | return ; | |
2276 | ||
2277 | Rect rect ; | |
2278 | m_peer->GetRect( &rect ) ; | |
2279 | InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
2280 | ||
2281 | if ( !IsTopLevel() ) | |
2282 | { | |
2283 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
2284 | if (top) | |
2285 | { | |
2286 | wxPoint pt(0,0) ; | |
2287 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
2288 | rect.left += pt.x ; | |
2289 | rect.right += pt.x ; | |
2290 | rect.top += pt.y ; | |
2291 | rect.bottom += pt.y ; | |
2292 | } | |
2293 | } | |
2294 | ||
2295 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2296 | { | |
2297 | Rect srect = rect ; | |
2298 | SInt32 border = 0 ; | |
2299 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2300 | InsetRect( &srect , border , border ); | |
2301 | DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2302 | } | |
2303 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2304 | { | |
2305 | Rect srect = rect ; | |
2306 | SInt32 border = 0 ; | |
2307 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2308 | InsetRect( &srect , border , border ); | |
2309 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
2310 | } | |
2311 | } | |
2312 | ||
2313 | void wxWindowMac::RemoveChild( wxWindowBase *child ) | |
2314 | { | |
2315 | if ( child == m_hScrollBar ) | |
2316 | m_hScrollBar = NULL ; | |
2317 | if ( child == m_vScrollBar ) | |
2318 | m_vScrollBar = NULL ; | |
2319 | ||
2320 | wxWindowBase::RemoveChild( child ) ; | |
2321 | } | |
2322 | ||
2323 | // New function that will replace some of the above. | |
2324 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, | |
2325 | int range, bool refresh) | |
2326 | { | |
2327 | if ( orient == wxHORIZONTAL ) | |
2328 | { | |
2329 | if ( m_hScrollBar ) | |
2330 | { | |
2331 | if ( range == 0 || thumbVisible >= range ) | |
2332 | { | |
2333 | if ( m_hScrollBar->IsShown() ) | |
2334 | m_hScrollBar->Show(false) ; | |
2335 | } | |
2336 | else | |
2337 | { | |
2338 | if ( !m_hScrollBar->IsShown() ) | |
2339 | m_hScrollBar->Show(true) ; | |
2340 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
2341 | } | |
2342 | } | |
2343 | } | |
2344 | else | |
2345 | { | |
2346 | if ( m_vScrollBar ) | |
2347 | { | |
2348 | if ( range == 0 || thumbVisible >= range ) | |
2349 | { | |
2350 | if ( m_vScrollBar->IsShown() ) | |
2351 | m_vScrollBar->Show(false) ; | |
2352 | } | |
2353 | else | |
2354 | { | |
2355 | if ( !m_vScrollBar->IsShown() ) | |
2356 | m_vScrollBar->Show(true) ; | |
2357 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
2358 | } | |
2359 | } | |
2360 | } | |
2361 | MacRepositionScrollBars() ; | |
2362 | } | |
2363 | ||
2364 | // Does a physical scroll | |
2365 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) | |
2366 | { | |
2367 | if( dx == 0 && dy ==0 ) | |
2368 | return ; | |
2369 | ||
2370 | ||
2371 | { | |
2372 | ||
2373 | int width , height ; | |
2374 | GetClientSize( &width , &height ) ; | |
2375 | #if TARGET_API_MAC_OSX | |
2376 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control | |
2377 | // area is scrolled, this does not occur if width and height are 2 pixels less, | |
2378 | // TODO write optimal workaround | |
2379 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; | |
2380 | if ( rect ) | |
2381 | { | |
2382 | scrollrect.Intersect( *rect ) ; | |
2383 | } | |
2384 | if ( m_peer->GetNeedsDisplay() ) | |
2385 | { | |
2386 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2387 | // either immediate redraw or full invalidate | |
2388 | #if 1 | |
2389 | // is the better overall solution, as it does not slow down scrolling | |
2390 | m_peer->SetNeedsDisplay( true ) ; | |
2391 | #else | |
2392 | // this would be the preferred version for fast drawing controls | |
2393 | if( UMAGetSystemVersion() < 0x1030 ) | |
2394 | Update() ; | |
2395 | else | |
2396 | HIViewRender(m_peer->GetControlRef()) ; | |
2397 | #endif | |
2398 | } | |
2399 | // as the native control might be not a 0/0 wx window coordinates, we have to offset | |
2400 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
2401 | m_peer->ScrollRect( scrollrect , dx , dy ) ; | |
2402 | #else | |
2403 | ||
2404 | wxPoint pos; | |
2405 | pos.x = pos.y = 0; | |
2406 | ||
2407 | Rect scrollrect; | |
2408 | RgnHandle updateRgn = NewRgn() ; | |
2409 | ||
2410 | { | |
2411 | wxClientDC dc(this) ; | |
2412 | wxMacPortSetter helper(&dc) ; | |
2413 | ||
2414 | m_peer->GetRect( &scrollrect ) ; | |
2415 | scrollrect.top += MacGetTopBorderSize() ; | |
2416 | scrollrect.left += MacGetLeftBorderSize() ; | |
2417 | scrollrect.bottom = scrollrect.top + height ; | |
2418 | scrollrect.right = scrollrect.left + width ; | |
2419 | ||
2420 | if ( rect ) | |
2421 | { | |
2422 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2423 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2424 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2425 | } | |
2426 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
2427 | } | |
2428 | // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ; | |
2429 | #endif | |
2430 | } | |
2431 | ||
2432 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
2433 | { | |
2434 | wxWindowMac *child = node->GetData(); | |
2435 | if (child == m_vScrollBar) continue; | |
2436 | if (child == m_hScrollBar) continue; | |
2437 | if (child->IsTopLevel()) continue; | |
2438 | ||
2439 | int x,y; | |
2440 | child->GetPosition( &x, &y ); | |
2441 | int w,h; | |
2442 | child->GetSize( &w, &h ); | |
2443 | if (rect) | |
2444 | { | |
2445 | wxRect rc(x,y,w,h); | |
2446 | if (rect->Intersects(rc)) | |
2447 | child->SetSize( x+dx, y+dy, w, h ); | |
2448 | } | |
2449 | else | |
2450 | { | |
2451 | child->SetSize( x+dx, y+dy, w, h ); | |
2452 | } | |
2453 | } | |
2454 | } | |
2455 | ||
2456 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) | |
2457 | { | |
2458 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) | |
2459 | { | |
2460 | wxScrollWinEvent wevent; | |
2461 | wevent.SetPosition(event.GetPosition()); | |
2462 | wevent.SetOrientation(event.GetOrientation()); | |
2463 | wevent.m_eventObject = this; | |
2464 | ||
2465 | if (event.m_eventType == wxEVT_SCROLL_TOP) | |
2466 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
2467 | else if (event.m_eventType == wxEVT_SCROLL_BOTTOM) | |
2468 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
2469 | else if (event.m_eventType == wxEVT_SCROLL_LINEUP) | |
2470 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
2471 | else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) | |
2472 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
2473 | else if (event.m_eventType == wxEVT_SCROLL_PAGEUP) | |
2474 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
2475 | else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) | |
2476 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
2477 | else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) | |
2478 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
2479 | else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE) | |
2480 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE; | |
2481 | ||
2482 | GetEventHandler()->ProcessEvent(wevent); | |
2483 | } | |
2484 | } | |
2485 | ||
2486 | // Get the window with the focus | |
2487 | wxWindowMac *wxWindowBase::FindFocus() | |
2488 | { | |
2489 | ControlRef control ; | |
2490 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2491 | return wxFindControlFromMacControl( control ) ; | |
2492 | } | |
2493 | ||
2494 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) | |
2495 | { | |
2496 | // panel wants to track the window which was the last to have focus in it, | |
2497 | // so we want to set ourselves as the window which last had focus | |
2498 | // | |
2499 | // notice that it's also important to do it upwards the tree becaus | |
2500 | // otherwise when the top level panel gets focus, it won't set it back to | |
2501 | // us, but to some other sibling | |
2502 | ||
2503 | // CS:don't know if this is still needed: | |
2504 | //wxChildFocusEvent eventFocus(this); | |
2505 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
2506 | ||
2507 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) | |
2508 | { | |
2509 | wxMacWindowStateSaver sv( this ) ; | |
2510 | ||
2511 | int w , h ; | |
2512 | int x , y ; | |
2513 | x = y = 0 ; | |
2514 | MacWindowToRootWindow( &x , &y ) ; | |
2515 | GetSize( &w , &h ) ; | |
2516 | Rect rect = {y , x , h + y , w + x } ; | |
2517 | ||
2518 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
2519 | DrawThemeFocusRect( &rect , true ) ; | |
2520 | else | |
2521 | { | |
2522 | DrawThemeFocusRect( &rect , false ) ; | |
2523 | ||
2524 | // as this erases part of the frame we have to redraw borders | |
2525 | // and because our z-ordering is not always correct (staticboxes) | |
2526 | // we have to invalidate things, we cannot simple redraw | |
2527 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
2528 | RectRgn( updateInner , &rect ) ; | |
2529 | InsetRect( &rect , -4 , -4 ) ; | |
2530 | RectRgn( updateOuter , &rect ) ; | |
2531 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
2532 | wxPoint parent(0,0); | |
2533 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
2534 | parent -= GetParent()->GetClientAreaOrigin() ; | |
2535 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
2536 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
2537 | DisposeRgn(updateOuter) ; | |
2538 | DisposeRgn(updateInner) ; | |
2539 | } | |
2540 | } | |
2541 | ||
2542 | event.Skip(); | |
2543 | } | |
2544 | ||
2545 | void wxWindowMac::OnInternalIdle() | |
2546 | { | |
2547 | // This calls the UI-update mechanism (querying windows for | |
2548 | // menu/toolbar/control state information) | |
2549 | if (wxUpdateUIEvent::CanUpdate(this)) | |
2550 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
2551 | } | |
2552 | ||
2553 | // Raise the window to the top of the Z order | |
2554 | void wxWindowMac::Raise() | |
2555 | { | |
2556 | m_peer->SetZOrder( true , NULL ) ; | |
2557 | } | |
2558 | ||
2559 | // Lower the window to the bottom of the Z order | |
2560 | void wxWindowMac::Lower() | |
2561 | { | |
2562 | m_peer->SetZOrder( false , NULL ) ; | |
2563 | } | |
2564 | ||
2565 | ||
2566 | // static wxWindow *gs_lastWhich = NULL; | |
2567 | ||
2568 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) | |
2569 | { | |
2570 | // first trigger a set cursor event | |
2571 | ||
2572 | wxPoint clientorigin = GetClientAreaOrigin() ; | |
2573 | wxSize clientsize = GetClientSize() ; | |
2574 | wxCursor cursor ; | |
2575 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
2576 | { | |
2577 | wxSetCursorEvent event( pt.x , pt.y ); | |
2578 | ||
2579 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); | |
2580 | if ( processedEvtSetCursor && event.HasCursor() ) | |
2581 | { | |
2582 | cursor = event.GetCursor() ; | |
2583 | } | |
2584 | else | |
2585 | { | |
2586 | ||
2587 | // the test for processedEvtSetCursor is here to prevent using m_cursor | |
2588 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
2589 | // it - this is a way to say that our cursor shouldn't be used for this | |
2590 | // point | |
2591 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
2592 | { | |
2593 | cursor = m_cursor ; | |
2594 | } | |
2595 | if ( wxIsBusy() ) | |
2596 | { | |
2597 | } | |
2598 | else | |
2599 | { | |
2600 | if ( !GetParent() ) | |
2601 | cursor = *wxSTANDARD_CURSOR ; | |
2602 | } | |
2603 | } | |
2604 | if ( cursor.Ok() ) | |
2605 | cursor.MacInstall() ; | |
2606 | } | |
2607 | return cursor.Ok() ; | |
2608 | } | |
2609 | ||
2610 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) | |
2611 | { | |
2612 | if ( m_tooltip ) | |
2613 | { | |
2614 | return m_tooltip->GetTip() ; | |
2615 | } | |
2616 | return wxEmptyString ; | |
2617 | } | |
2618 | ||
2619 | void wxWindowMac::Update() | |
2620 | { | |
2621 | #if TARGET_API_MAC_OSX | |
2622 | WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ; | |
2623 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
2624 | // for composited windows this also triggers a redraw of all | |
2625 | // invalid views in the window | |
2626 | if( UMAGetSystemVersion() >= 0x1030 ) | |
2627 | HIWindowFlush(window) ; | |
2628 | else | |
2629 | #endif | |
2630 | { | |
2631 | // the only way to trigger the redrawing on earlier systems is to call | |
2632 | // ReceiveNextEvent | |
2633 | ||
2634 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
2635 | UInt32 currentEventClass = 0 ; | |
2636 | UInt32 currentEventKind = 0 ; | |
2637 | if ( currentEvent != NULL ) | |
2638 | { | |
2639 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
2640 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
2641 | } | |
2642 | if ( currentEventClass != kEventClassMenu ) | |
2643 | { | |
2644 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
2645 | ||
2646 | EventRef theEvent; | |
2647 | OSStatus status = noErr ; | |
2648 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
2649 | } | |
2650 | else | |
2651 | m_peer->SetNeedsDisplay( true ) ; | |
2652 | } | |
2653 | #else | |
2654 | ::Draw1Control( m_peer->GetControlRef() ) ; | |
2655 | #endif | |
2656 | } | |
2657 | ||
2658 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const | |
2659 | { | |
2660 | wxTopLevelWindowMac* win = NULL ; | |
2661 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; | |
2662 | if ( window ) | |
2663 | { | |
2664 | win = wxFindWinFromMacWindow( window ) ; | |
2665 | } | |
2666 | return win ; | |
2667 | } | |
2668 | wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) | |
2669 | { | |
2670 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. | |
2671 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
2672 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
2673 | // to add focus borders everywhere | |
2674 | ||
2675 | Rect r ; | |
2676 | RgnHandle visRgn = NewRgn() ; | |
2677 | RgnHandle tempRgn = NewRgn() ; | |
2678 | if ( m_peer->IsVisible()) | |
2679 | { | |
2680 | m_peer->GetRect( &r ) ; | |
2681 | r.left -= MacGetLeftBorderSize() ; | |
2682 | r.top -= MacGetTopBorderSize() ; | |
2683 | r.bottom += MacGetBottomBorderSize() ; | |
2684 | r.right += MacGetRightBorderSize() ; | |
2685 | ||
2686 | if (! MacGetTopLevelWindow()->MacUsesCompositing() ) | |
2687 | { | |
2688 | MacRootWindowToWindow( &r.left , & r.top ) ; | |
2689 | MacRootWindowToWindow( &r.right , & r.bottom ) ; | |
2690 | } | |
2691 | else | |
2692 | { | |
2693 | r.right -= r.left ; | |
2694 | r.bottom -= r.top ; | |
2695 | r.left = 0 ; | |
2696 | r.top = 0 ; | |
2697 | } | |
2698 | if ( includeOuterStructures ) | |
2699 | InsetRect( &r , -4 , -4 ) ; | |
2700 | RectRgn( visRgn , &r ) ; | |
2701 | ||
2702 | if ( !IsTopLevel() ) | |
2703 | { | |
2704 | wxWindow* child = this ; | |
2705 | wxWindow* parent = child->GetParent() ; | |
2706 | while( parent ) | |
2707 | { | |
2708 | int x , y ; | |
2709 | wxSize size ; | |
2710 | // we have to find a better clipping algorithm here, in order not to clip things | |
2711 | // positioned like status and toolbar | |
2712 | if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ ) | |
2713 | { | |
2714 | size = parent->GetSize() ; | |
2715 | x = y = 0 ; | |
2716 | } | |
2717 | else | |
2718 | { | |
2719 | size = parent->GetClientSize() ; | |
2720 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
2721 | x = origin.x ; | |
2722 | y = origin.y ; | |
2723 | } | |
2724 | parent->MacWindowToRootWindow( &x, &y ) ; | |
2725 | MacRootWindowToWindow( &x , &y ) ; | |
2726 | ||
2727 | if ( !includeOuterStructures || ( | |
2728 | parent->IsKindOf( CLASSINFO( wxScrolledWindow ) ) || | |
2729 | parent->IsKindOf( CLASSINFO( wxSashLayoutWindow ) ) || | |
2730 | ( parent->GetParent() && parent->GetParent()->IsKindOf( CLASSINFO( wxSplitterWindow ) ) ) | |
2731 | ) ) | |
2732 | { | |
2733 | SetRectRgn( tempRgn , | |
2734 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
2735 | x + size.x - parent->MacGetRightBorderSize(), | |
2736 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
2737 | ||
2738 | SectRgn( visRgn , tempRgn , visRgn ) ; | |
2739 | } | |
2740 | if ( parent->IsTopLevel() ) | |
2741 | break ; | |
2742 | child = parent ; | |
2743 | parent = child->GetParent() ; | |
2744 | } | |
2745 | } | |
2746 | } | |
2747 | ||
2748 | wxRegion vis = visRgn ; | |
2749 | DisposeRgn( visRgn ) ; | |
2750 | DisposeRgn( tempRgn ) ; | |
2751 | return vis ; | |
2752 | } | |
2753 | ||
2754 | /* | |
2755 | This function must not change the updatergn ! | |
2756 | */ | |
2757 | bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) | |
2758 | { | |
2759 | RgnHandle updatergn = (RgnHandle) updatergnr ; | |
2760 | bool handled = false ; | |
2761 | Rect updatebounds ; | |
2762 | GetRegionBounds( updatergn , &updatebounds ) ; | |
2763 | // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ; | |
2764 | if ( !EmptyRgn(updatergn) ) | |
2765 | { | |
2766 | RgnHandle newupdate = NewRgn() ; | |
2767 | wxSize point = GetClientSize() ; | |
2768 | wxPoint origin = GetClientAreaOrigin() ; | |
2769 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; | |
2770 | SectRgn( newupdate , updatergn , newupdate ) ; | |
2771 | ||
2772 | // first send an erase event to the entire update area | |
2773 | { | |
2774 | wxWindowDC dc(this); | |
2775 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2776 | wxEraseEvent eevent( GetId(), &dc ); | |
2777 | eevent.SetEventObject( this ); | |
2778 | GetEventHandler()->ProcessEvent( eevent ); | |
2779 | } | |
2780 | ||
2781 | // calculate a client-origin version of the update rgn and set m_updateRegion to that | |
2782 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
2783 | m_updateRegion = newupdate ; | |
2784 | DisposeRgn( newupdate ) ; | |
2785 | ||
2786 | if ( !m_updateRegion.Empty() ) | |
2787 | { | |
2788 | // paint the window itself | |
2789 | wxPaintEvent event; | |
2790 | event.m_timeStamp = time ; | |
2791 | event.SetEventObject(this); | |
2792 | handled = GetEventHandler()->ProcessEvent(event); | |
2793 | ||
2794 | // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards | |
2795 | if ( !handled ) | |
2796 | { | |
2797 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) | |
2798 | { | |
2799 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
2800 | handled = true ; | |
2801 | } | |
2802 | } | |
2803 | ||
2804 | } | |
2805 | ||
2806 | // now we cannot rely on having its borders drawn by a window itself, as it does not | |
2807 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
2808 | // this would also be the place to draw any custom backgrounds for native controls | |
2809 | // in Composited windowing | |
2810 | wxPoint clientOrigin = GetClientAreaOrigin() ; | |
2811 | ||
2812 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
2813 | { | |
2814 | wxWindowMac *child = node->GetData(); | |
2815 | if (child == m_vScrollBar) continue; | |
2816 | if (child == m_hScrollBar) continue; | |
2817 | if (child->IsTopLevel()) continue; | |
2818 | if (!child->IsShown()) continue; | |
2819 | ||
2820 | int x,y; | |
2821 | child->GetPosition( &x, &y ); | |
2822 | int w,h; | |
2823 | child->GetSize( &w, &h ); | |
2824 | Rect childRect = { y , x , y + h , x + w } ; | |
2825 | OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; | |
2826 | if ( child->MacGetTopBorderSize() ) | |
2827 | { | |
2828 | if ( RectInRgn( &childRect , updatergn ) ) | |
2829 | { | |
2830 | // paint custom borders | |
2831 | wxNcPaintEvent eventNc( child->GetId() ); | |
2832 | eventNc.SetEventObject( child ); | |
2833 | if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) | |
2834 | { | |
2835 | wxWindowDC dc(this) ; | |
2836 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2837 | wxMacPortSetter helper(&dc) ; | |
2838 | child->MacPaintBorders( dc.m_macLocalOrigin.x + childRect.left , dc.m_macLocalOrigin.y + childRect.top) ; | |
2839 | } | |
2840 | } | |
2841 | } | |
2842 | if ( child->m_peer->NeedsFocusRect() && child->m_peer->HasFocus() ) | |
2843 | { | |
2844 | wxWindowDC dc(this) ; | |
2845 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2846 | wxMacPortSetter helper(&dc) ; | |
2847 | Rect r = childRect ; | |
2848 | OffsetRect( &r , dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y ) ; | |
2849 | DrawThemeFocusRect( &r , true ) ; | |
2850 | } | |
2851 | } | |
2852 | } | |
2853 | return handled ; | |
2854 | } | |
2855 | ||
2856 | void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) | |
2857 | { | |
2858 | RgnHandle updatergn = (RgnHandle) updatergnr ; | |
2859 | // updatergn is always already clipped to our boundaries | |
2860 | // if we are in compositing mode then it is in relative to the upper left of the control | |
2861 | // if we are in non-compositing, then it is relatvie to the uppder left of the content area | |
2862 | // of the toplevel window | |
2863 | // it is in window coordinates, not in client coordinates | |
2864 | ||
2865 | // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates | |
2866 | RgnHandle ownUpdateRgn = NewRgn() ; | |
2867 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
2868 | ||
2869 | if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) | |
2870 | { | |
2871 | Rect bounds; | |
2872 | m_peer->GetRectInWindowCoords( &bounds ); | |
2873 | RgnHandle controlRgn = NewRgn(); | |
2874 | RectRgn( controlRgn, &bounds ); | |
2875 | //KO: This sets the ownUpdateRgn to the area of this control that is inside | |
2876 | // the window update region | |
2877 | SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn ); | |
2878 | DisposeRgn( controlRgn ); | |
2879 | ||
2880 | //KO: convert ownUpdateRgn to local coordinates | |
2881 | OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top ); | |
2882 | } | |
2883 | ||
2884 | MacDoRedraw( ownUpdateRgn , time ) ; | |
2885 | DisposeRgn( ownUpdateRgn ) ; | |
2886 | ||
2887 | } | |
2888 | ||
2889 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const | |
2890 | { | |
2891 | wxWindowMac *iter = (wxWindowMac*)this ; | |
2892 | ||
2893 | while( iter ) | |
2894 | { | |
2895 | if ( iter->IsTopLevel() ) | |
2896 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
2897 | ||
2898 | iter = iter->GetParent() ; | |
2899 | } | |
2900 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; | |
2901 | return NULL ; | |
2902 | } | |
2903 | ||
2904 | void wxWindowMac::MacCreateScrollBars( long style ) | |
2905 | { | |
2906 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; | |
2907 | ||
2908 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) | |
2909 | { | |
2910 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
2911 | int scrlsize = MAC_SCROLLBAR_SIZE ; | |
2912 | wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ; | |
2913 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
2914 | { | |
2915 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
2916 | variant = wxWINDOW_VARIANT_SMALL ; | |
2917 | } | |
2918 | ||
2919 | int adjust = hasBoth ? scrlsize - 1: 0 ; | |
2920 | int width, height ; | |
2921 | GetClientSize( &width , &height ) ; | |
2922 | ||
2923 | wxPoint vPoint(width-scrlsize, 0) ; | |
2924 | wxSize vSize(scrlsize, height - adjust) ; | |
2925 | wxPoint hPoint(0 , height-scrlsize ) ; | |
2926 | wxSize hSize( width - adjust, scrlsize) ; | |
2927 | ||
2928 | ||
2929 | if ( style & wxVSCROLL ) | |
2930 | { | |
2931 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
2932 | vSize , wxVERTICAL); | |
2933 | } | |
2934 | ||
2935 | if ( style & wxHSCROLL ) | |
2936 | { | |
2937 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
2938 | hSize , wxHORIZONTAL); | |
2939 | } | |
2940 | } | |
2941 | ||
2942 | ||
2943 | // because the create does not take into account the client area origin | |
2944 | MacRepositionScrollBars() ; // we might have a real position shift | |
2945 | } | |
2946 | ||
2947 | void wxWindowMac::MacRepositionScrollBars() | |
2948 | { | |
2949 | if ( !m_hScrollBar && !m_vScrollBar ) | |
2950 | return ; | |
2951 | ||
2952 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
2953 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
2954 | int adjust = hasBoth ? scrlsize - 1 : 0 ; | |
2955 | ||
2956 | // get real client area | |
2957 | ||
2958 | int width ; | |
2959 | int height ; | |
2960 | GetSize( &width , &height ) ; | |
2961 | ||
2962 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2963 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
2964 | ||
2965 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
2966 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2967 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2968 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
2969 | /* | |
2970 | int x = 0 ; | |
2971 | int y = 0 ; | |
2972 | int w ; | |
2973 | int h ; | |
2974 | GetSize( &w , &h ) ; | |
2975 | ||
2976 | MacClientToRootWindow( &x , &y ) ; | |
2977 | MacClientToRootWindow( &w , &h ) ; | |
2978 | ||
2979 | wxWindowMac *iter = (wxWindowMac*)this ; | |
2980 | ||
2981 | int totW = 10000 , totH = 10000; | |
2982 | while( iter ) | |
2983 | { | |
2984 | if ( iter->IsTopLevel() ) | |
2985 | { | |
2986 | iter->GetSize( &totW , &totH ) ; | |
2987 | break ; | |
2988 | } | |
2989 | ||
2990 | iter = iter->GetParent() ; | |
2991 | } | |
2992 | ||
2993 | if ( x == 0 ) | |
2994 | { | |
2995 | hPoint.x = -1 ; | |
2996 | hSize.x += 1 ; | |
2997 | } | |
2998 | if ( y == 0 ) | |
2999 | { | |
3000 | vPoint.y = -1 ; | |
3001 | vSize.y += 1 ; | |
3002 | } | |
3003 | ||
3004 | if ( w-x >= totW ) | |
3005 | { | |
3006 | hSize.x += 1 ; | |
3007 | vPoint.x += 1 ; | |
3008 | } | |
3009 | ||
3010 | if ( h-y >= totH ) | |
3011 | { | |
3012 | vSize.y += 1 ; | |
3013 | hPoint.y += 1 ; | |
3014 | } | |
3015 | */ | |
3016 | if ( m_vScrollBar ) | |
3017 | { | |
3018 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
3019 | } | |
3020 | if ( m_hScrollBar ) | |
3021 | { | |
3022 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
3023 | } | |
3024 | } | |
3025 | ||
3026 | bool wxWindowMac::AcceptsFocus() const | |
3027 | { | |
3028 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
3029 | } | |
3030 | ||
3031 | void wxWindowMac::MacSuperChangedPosition() | |
3032 | { | |
3033 | // only window-absolute structures have to be moved i.e. controls | |
3034 | ||
3035 | wxWindowListNode *node = GetChildren().GetFirst(); | |
3036 | while ( node ) | |
3037 | { | |
3038 | wxWindowMac *child = node->GetData(); | |
3039 | child->MacSuperChangedPosition() ; | |
3040 | node = node->GetNext(); | |
3041 | } | |
3042 | } | |
3043 | ||
3044 | void wxWindowMac::MacTopLevelWindowChangedPosition() | |
3045 | { | |
3046 | // only screen-absolute structures have to be moved i.e. glcanvas | |
3047 | ||
3048 | wxWindowListNode *node = GetChildren().GetFirst(); | |
3049 | while ( node ) | |
3050 | { | |
3051 | wxWindowMac *child = node->GetData(); | |
3052 | child->MacTopLevelWindowChangedPosition() ; | |
3053 | node = node->GetNext(); | |
3054 | } | |
3055 | } | |
3056 | ||
3057 | long wxWindowMac::MacGetLeftBorderSize( ) const | |
3058 | { | |
3059 | if( IsTopLevel() ) | |
3060 | return 0 ; | |
3061 | ||
3062 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
3063 | { | |
3064 | SInt32 border = 3 ; | |
3065 | return border ; | |
3066 | } | |
3067 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
3068 | { | |
3069 | SInt32 border = 3 ; | |
3070 | return border ; | |
3071 | } | |
3072 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
3073 | { | |
3074 | return 1 ; | |
3075 | } | |
3076 | return 0 ; | |
3077 | } | |
3078 | ||
3079 | long wxWindowMac::MacGetRightBorderSize( ) const | |
3080 | { | |
3081 | // they are all symmetric in mac themes | |
3082 | return MacGetLeftBorderSize() ; | |
3083 | } | |
3084 | ||
3085 | long wxWindowMac::MacGetTopBorderSize( ) const | |
3086 | { | |
3087 | // they are all symmetric in mac themes | |
3088 | return MacGetLeftBorderSize() ; | |
3089 | } | |
3090 | ||
3091 | long wxWindowMac::MacGetBottomBorderSize( ) const | |
3092 | { | |
3093 | // they are all symmetric in mac themes | |
3094 | return MacGetLeftBorderSize() ; | |
3095 | } | |
3096 | ||
3097 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) | |
3098 | { | |
3099 | return style & ~wxBORDER_MASK ; | |
3100 | } | |
3101 | ||
3102 | // Find the wxWindowMac at the current mouse position, returning the mouse | |
3103 | // position. | |
3104 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) | |
3105 | { | |
3106 | pt = wxGetMousePosition(); | |
3107 | wxWindowMac* found = wxFindWindowAtPoint(pt); | |
3108 | return found; | |
3109 | } | |
3110 | ||
3111 | // Get the current mouse position. | |
3112 | wxPoint wxGetMousePosition() | |
3113 | { | |
3114 | int x, y; | |
3115 | wxGetMousePosition(& x, & y); | |
3116 | return wxPoint(x, y); | |
3117 | } | |
3118 | ||
3119 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) | |
3120 | { | |
3121 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
3122 | { | |
3123 | // copied from wxGTK : CS | |
3124 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN | |
3125 | // except that: | |
3126 | // | |
3127 | // (a) it's a command event and so is propagated to the parent | |
3128 | // (b) under MSW it can be generated from kbd too | |
3129 | // (c) it uses screen coords (because of (a)) | |
3130 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
3131 | this->GetId(), | |
3132 | this->ClientToScreen(event.GetPosition())); | |
3133 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) | |
3134 | event.Skip() ; | |
3135 | } | |
3136 | else | |
3137 | { | |
3138 | event.Skip() ; | |
3139 | } | |
3140 | } | |
3141 | ||
3142 | void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) | |
3143 | { | |
3144 | } | |
3145 | ||
3146 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) | |
3147 | { | |
3148 | int x ,y , w ,h ; | |
3149 | ||
3150 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ; | |
3151 | Rect bounds = { y , x , y+h , x+w }; | |
3152 | return bounds ; | |
3153 | } | |
3154 | ||
3155 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) | |
3156 | { | |
3157 | return eventNotHandledErr ; | |
3158 | } | |
3159 | ||
3160 |