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