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