]>
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 | |
7ebf5540 SC |
696 | if ( m_peer ) |
697 | { | |
698 | // deleting a window while it is shown invalidates the region occupied by border or | |
699 | // focus | |
700 | int outerBorder = MacGetLeftBorderSize() ; | |
701 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
702 | outerBorder += 4 ; | |
703 | ||
704 | if ( IsShown() && ( outerBorder > 0 ) ) | |
705 | { | |
706 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
707 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
708 | ||
709 | Rect rect ; | |
710 | ||
711 | m_peer->GetRect( &rect ) ; | |
712 | RectRgn( updateInner , &rect ) ; | |
713 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
714 | RectRgn( updateOuter , &rect ) ; | |
715 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
716 | wxPoint parent(0,0); | |
717 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
718 | parent -= GetParent()->GetClientAreaOrigin() ; | |
719 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
720 | CopyRgn( updateOuter , updateTotal ) ; | |
721 | ||
722 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
723 | DisposeRgn(updateOuter) ; | |
724 | DisposeRgn(updateInner) ; | |
725 | DisposeRgn(updateTotal) ; | |
726 | } | |
727 | } | |
728 | ||
d4380aaf SC |
729 | #ifndef __WXUNIVERSAL__ |
730 | // VS: make sure there's no wxFrame with last focus set to us: | |
731 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
732 | { | |
733 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
734 | if ( frame ) | |
735 | { | |
736 | if ( frame->GetLastFocus() == this ) | |
737 | { | |
738 | frame->SetLastFocus((wxWindow*)NULL); | |
739 | } | |
740 | break; | |
741 | } | |
742 | } | |
743 | #endif // __WXUNIVERSAL__ | |
facd6764 SC |
744 | |
745 | // wxRemoveMacControlAssociation( this ) ; | |
746 | // If we delete an item, we should initialize the parent panel, | |
747 | // because it could now be invalid. | |
748 | wxWindow *parent = GetParent() ; | |
749 | if ( parent ) | |
750 | { | |
751 | if (parent->GetDefaultItem() == (wxButton*) this) | |
752 | parent->SetDefaultItem(NULL); | |
753 | } | |
21fd5529 | 754 | if ( m_peer && m_peer->Ok() ) |
facd6764 SC |
755 | { |
756 | // in case the callback might be called during destruction | |
757 | wxRemoveMacControlAssociation( this) ; | |
5ca0d812 SC |
758 | // we currently are not using this hook |
759 | // ::SetControlColorProc( *m_peer , NULL ) ; | |
760 | m_peer->Dispose() ; | |
facd6764 | 761 | } |
d4380aaf | 762 | |
facd6764 | 763 | if ( g_MacLastWindow == this ) |
6264b550 | 764 | { |
facd6764 | 765 | g_MacLastWindow = NULL ; |
6264b550 | 766 | } |
7de59551 | 767 | |
fd76aa8d SC |
768 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; |
769 | if ( frame ) | |
770 | { | |
e40298d5 JS |
771 | if ( frame->GetLastFocus() == this ) |
772 | frame->SetLastFocus( NULL ) ; | |
fd76aa8d | 773 | } |
e7549107 | 774 | |
42683dfb SC |
775 | DestroyChildren(); |
776 | ||
42683dfb SC |
777 | // delete our drop target if we've got one |
778 | #if wxUSE_DRAG_AND_DROP | |
779 | if ( m_dropTarget != NULL ) | |
780 | { | |
781 | delete m_dropTarget; | |
782 | m_dropTarget = NULL; | |
783 | } | |
784 | #endif // wxUSE_DRAG_AND_DROP | |
21fd5529 SC |
785 | delete m_peer ; |
786 | } | |
787 | ||
788 | WXWidget wxWindowMac::GetHandle() const | |
789 | { | |
5ca0d812 | 790 | return (WXWidget) m_peer->GetControlRef() ; |
e9576ca5 SC |
791 | } |
792 | ||
facd6764 | 793 | |
5ca0d812 | 794 | void wxWindowMac::MacInstallEventHandler( WXWidget control ) |
facd6764 | 795 | { |
5ca0d812 SC |
796 | wxAssociateControlWithMacControl( (ControlRef) control , this ) ; |
797 | InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(), | |
facd6764 SC |
798 | GetEventTypeCount(eventList), eventList, this, |
799 | (EventHandlerRef *)&m_macControlEventHandler); | |
800 | ||
801 | } | |
802 | ||
e9576ca5 | 803 | // Constructor |
e766c8a9 | 804 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, |
e9576ca5 SC |
805 | const wxPoint& pos, |
806 | const wxSize& size, | |
807 | long style, | |
808 | const wxString& name) | |
809 | { | |
e766c8a9 | 810 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 811 | |
e7549107 | 812 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
e9576ca5 SC |
813 | return FALSE; |
814 | ||
e7549107 | 815 | parent->AddChild(this); |
e9576ca5 | 816 | |
facd6764 SC |
817 | m_windowVariant = parent->GetWindowVariant() ; |
818 | ||
819 | if ( m_macIsUserPane ) | |
820 | { | |
821 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
822 | ||
ebe86b1e SC |
823 | UInt32 features = 0 |
824 | | kControlSupportsEmbedding | |
825 | // | kControlSupportsLiveFeedback | |
826 | // | kControlHasSpecialBackground | |
827 | // | kControlSupportsCalcBestRect | |
828 | // | kControlHandlesTracking | |
829 | | kControlSupportsFocus | |
830 | // | kControlWantsActivate | |
831 | // | kControlWantsIdle | |
832 | ; | |
833 | ||
21fd5529 | 834 | m_peer = new wxMacControl() ; |
5ca0d812 | 835 | ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); |
21fd5529 | 836 | |
facd6764 SC |
837 | |
838 | MacPostControlCreate(pos,size) ; | |
bcbd6987 | 839 | #if !TARGET_API_MAC_OSX |
5ca0d812 SC |
840 | m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ; |
841 | m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ; | |
842 | m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ; | |
843 | m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ; | |
844 | m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ; | |
845 | m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ; | |
846 | m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ; | |
847 | m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ; | |
facd6764 SC |
848 | #endif |
849 | } | |
e766c8a9 | 850 | #ifndef __WXUNIVERSAL__ |
14c9cbdb RD |
851 | // Don't give scrollbars to wxControls unless they ask for them |
852 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
853 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
6264b550 RR |
854 | { |
855 | MacCreateScrollBars( style ) ; | |
856 | } | |
e766c8a9 | 857 | #endif |
3dfafdb9 RD |
858 | |
859 | wxWindowCreateEvent event(this); | |
7e4a196e | 860 | GetEventHandler()->AddPendingEvent(event); |
3dfafdb9 | 861 | |
e9576ca5 SC |
862 | return TRUE; |
863 | } | |
864 | ||
facd6764 SC |
865 | void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) |
866 | { | |
21fd5529 | 867 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; |
facd6764 | 868 | |
5ca0d812 | 869 | m_peer->SetReference( (long) this ) ; |
facd6764 | 870 | |
5ca0d812 | 871 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); |
facd6764 SC |
872 | |
873 | ControlRef container = (ControlRef) GetParent()->GetHandle() ; | |
874 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
5ca0d812 | 875 | ::EmbedControl( m_peer->GetControlRef() , container ) ; |
facd6764 SC |
876 | |
877 | // adjust font, controlsize etc | |
878 | DoSetWindowVariant( m_windowVariant ) ; | |
879 | ||
880 | #if !TARGET_API_MAC_OSX | |
881 | // eventually we can fix some clipping issues be reactivating this hook | |
882 | //if ( m_macIsUserPane ) | |
be346c26 | 883 | // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ; |
facd6764 | 884 | #endif |
5ca0d812 | 885 | m_peer->SetTitle( wxStripMenuCodes(m_label) ) ; |
facd6764 | 886 | |
facd6764 | 887 | if (!m_macIsUserPane) |
d3b5db4b RD |
888 | { |
889 | SetInitialBestSize(size); | |
facd6764 SC |
890 | } |
891 | ||
892 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
facd6764 SC |
893 | } |
894 | ||
895 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
896 | { | |
23176131 JS |
897 | // Don't assert, in case we set the window variant before |
898 | // the window is created | |
21fd5529 | 899 | // wxASSERT( m_peer->Ok() ) ; |
facd6764 | 900 | |
23176131 JS |
901 | m_windowVariant = variant ; |
902 | ||
21fd5529 | 903 | if (m_peer == NULL || !m_peer->Ok()) |
23176131 | 904 | return; |
facd6764 SC |
905 | |
906 | ControlSize size ; | |
907 | ThemeFontID themeFont = kThemeSystemFont ; | |
908 | ||
909 | // we will get that from the settings later | |
910 | // and make this NORMAL later, but first | |
911 | // we have a few calculations that we must fix | |
912 | ||
913 | switch ( variant ) | |
914 | { | |
915 | case wxWINDOW_VARIANT_NORMAL : | |
916 | size = kControlSizeNormal; | |
917 | themeFont = kThemeSystemFont ; | |
918 | break ; | |
919 | case wxWINDOW_VARIANT_SMALL : | |
920 | size = kControlSizeSmall; | |
921 | themeFont = kThemeSmallSystemFont ; | |
922 | break ; | |
923 | case wxWINDOW_VARIANT_MINI : | |
924 | if (UMAGetSystemVersion() >= 0x1030 ) | |
925 | { | |
926 | // not always defined in the headers | |
927 | size = 3 ; | |
928 | themeFont = 109 ; | |
929 | } | |
930 | else | |
931 | { | |
932 | size = kControlSizeSmall; | |
933 | themeFont = kThemeSmallSystemFont ; | |
934 | } | |
935 | break ; | |
936 | case wxWINDOW_VARIANT_LARGE : | |
937 | size = kControlSizeLarge; | |
938 | themeFont = kThemeSystemFont ; | |
939 | break ; | |
940 | default: | |
941 | wxFAIL_MSG(_T("unexpected window variant")); | |
942 | break ; | |
943 | } | |
5ca0d812 | 944 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ; |
facd6764 SC |
945 | |
946 | wxFont font ; | |
947 | font.MacCreateThemeFont( themeFont ) ; | |
948 | SetFont( font ) ; | |
949 | } | |
950 | ||
951 | void wxWindowMac::MacUpdateControlFont() | |
952 | { | |
ac99838a | 953 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; |
facd6764 SC |
954 | Refresh() ; |
955 | } | |
956 | ||
957 | bool wxWindowMac::SetFont(const wxFont& font) | |
958 | { | |
959 | bool retval = !wxWindowBase::SetFont( font ) ; | |
960 | ||
961 | MacUpdateControlFont() ; | |
962 | ||
963 | return retval; | |
964 | } | |
965 | ||
966 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
967 | { | |
968 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
969 | return false ; | |
970 | ||
971 | MacUpdateControlFont() ; | |
972 | ||
973 | return true ; | |
974 | } | |
975 | ||
976 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
977 | { | |
978 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
979 | return false ; | |
980 | ||
981 | wxBrush brush ; | |
b52acd03 RD |
982 | wxColour newCol(GetBackgroundColour()); |
983 | if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
facd6764 SC |
984 | { |
985 | brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; | |
986 | } | |
b52acd03 | 987 | else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) |
facd6764 SC |
988 | { |
989 | brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
990 | } | |
991 | else | |
992 | { | |
b52acd03 | 993 | brush.SetColour( newCol ) ; |
facd6764 SC |
994 | } |
995 | MacSetBackgroundBrush( brush ) ; | |
996 | ||
db7a550b SC |
997 | MacUpdateControlFont() ; |
998 | ||
facd6764 SC |
999 | return true ; |
1000 | } | |
1001 | ||
7ea087b7 SC |
1002 | void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1003 | { | |
1004 | m_macBackgroundBrush = brush ; | |
1005 | m_peer->SetBackground( brush ) ; | |
1006 | } | |
facd6764 SC |
1007 | |
1008 | bool wxWindowMac::MacCanFocus() const | |
1009 | { | |
f6e3849c SC |
1010 | // there is currently no way to determine whether the window is running in full keyboard |
1011 | // access mode, therefore we cannot rely on these features, yet the only other way would be | |
1012 | // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems | |
1013 | // in event handlers... | |
f1d527c1 | 1014 | UInt32 features = 0 ; |
5ca0d812 | 1015 | m_peer->GetFeatures( & features ) ; |
f1d527c1 | 1016 | return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; |
facd6764 SC |
1017 | } |
1018 | ||
1019 | ||
e766c8a9 | 1020 | void wxWindowMac::SetFocus() |
e9576ca5 | 1021 | { |
6264b550 RR |
1022 | if ( AcceptsFocus() ) |
1023 | { | |
7d0cfe71 | 1024 | |
f1d527c1 | 1025 | wxWindow* former = FindFocus() ; |
7d0cfe71 SC |
1026 | if ( former == this ) |
1027 | return ; | |
1028 | ||
5ca0d812 | 1029 | OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; |
f1d527c1 SC |
1030 | // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only |
1031 | // leave in case of an error | |
1032 | if ( err == errCouldntSetFocus ) | |
1033 | return ; | |
1034 | ||
1035 | #if !TARGET_API_MAC_OSX | |
1036 | // emulate carbon events when running under carbonlib where they are not natively available | |
1037 | if ( former ) | |
1038 | { | |
1039 | EventRef evRef = NULL ; | |
1040 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1041 | &evRef ) ); | |
1042 | ||
1043 | wxMacCarbonEvent cEvent( evRef ) ; | |
1044 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; | |
1045 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; | |
1046 | ||
1047 | wxMacWindowEventHandler( NULL , evRef , former ) ; | |
1048 | ReleaseEvent(evRef) ; | |
6264b550 | 1049 | } |
f1d527c1 | 1050 | // send new focus event |
6264b550 | 1051 | { |
f1d527c1 SC |
1052 | EventRef evRef = NULL ; |
1053 | verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , | |
1054 | &evRef ) ); | |
1055 | ||
1056 | wxMacCarbonEvent cEvent( evRef ) ; | |
1057 | cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; | |
1058 | cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; | |
1059 | ||
1060 | wxMacWindowEventHandler( NULL , evRef , this ) ; | |
1061 | ReleaseEvent(evRef) ; | |
6264b550 | 1062 | } |
f1d527c1 | 1063 | #endif |
6264b550 | 1064 | } |
e9576ca5 SC |
1065 | } |
1066 | ||
e9576ca5 | 1067 | |
4116c221 | 1068 | void wxWindowMac::DoCaptureMouse() |
e9576ca5 | 1069 | { |
519cb848 | 1070 | wxTheApp->s_captureWindow = this ; |
e9576ca5 SC |
1071 | } |
1072 | ||
90b959ae SC |
1073 | wxWindow* wxWindowBase::GetCapture() |
1074 | { | |
1075 | return wxTheApp->s_captureWindow ; | |
1076 | } | |
1077 | ||
4116c221 | 1078 | void wxWindowMac::DoReleaseMouse() |
e9576ca5 | 1079 | { |
519cb848 | 1080 | wxTheApp->s_captureWindow = NULL ; |
e9576ca5 SC |
1081 | } |
1082 | ||
e9576ca5 SC |
1083 | #if wxUSE_DRAG_AND_DROP |
1084 | ||
e766c8a9 | 1085 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 | 1086 | { |
e40298d5 JS |
1087 | if ( m_dropTarget != 0 ) { |
1088 | delete m_dropTarget; | |
1089 | } | |
6ed71b4f | 1090 | |
e40298d5 JS |
1091 | m_dropTarget = pDropTarget; |
1092 | if ( m_dropTarget != 0 ) | |
1093 | { | |
1094 | // TODO | |
1095 | } | |
e9576ca5 SC |
1096 | } |
1097 | ||
1098 | #endif | |
1099 | ||
1100 | // Old style file-manager drag&drop | |
e766c8a9 | 1101 | void wxWindowMac::DragAcceptFiles(bool accept) |
e9576ca5 SC |
1102 | { |
1103 | // TODO | |
1104 | } | |
1105 | ||
055a486b SC |
1106 | // Returns the size of the native control. In the case of the toplevel window |
1107 | // this is the content area root control | |
1108 | ||
facd6764 SC |
1109 | void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, |
1110 | int& w, int& h) const | |
e9576ca5 | 1111 | { |
facd6764 | 1112 | Rect bounds ; |
5ca0d812 | 1113 | m_peer->GetRect( &bounds ) ; |
e9576ca5 | 1114 | |
14c9cbdb | 1115 | |
facd6764 SC |
1116 | x = bounds.left ; |
1117 | y = bounds.top ; | |
1118 | w = bounds.right - bounds.left ; | |
1119 | h = bounds.bottom - bounds.top ; | |
e9576ca5 SC |
1120 | } |
1121 | ||
055a486b SC |
1122 | // From a wx position / size calculate the appropriate size of the native control |
1123 | ||
facd6764 SC |
1124 | bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, |
1125 | const wxSize& size, | |
1126 | int& x, int& y, | |
79392158 | 1127 | int& w, int& h , bool adjustOrigin ) const |
51abe921 | 1128 | { |
5ca0d812 SC |
1129 | // the desired size, minus the border pixels gives the correct size of the control |
1130 | ||
facd6764 SC |
1131 | x = (int)pos.x; |
1132 | y = (int)pos.y; | |
1133 | // todo the default calls may be used as soon as PostCreateControl Is moved here | |
1134 | w = size.x ; // WidthDefault( size.x ); | |
1135 | h = size.y ; // HeightDefault( size.y ) ; | |
1136 | #if !TARGET_API_MAC_OSX | |
1137 | GetParent()->MacWindowToRootWindow( &x , &y ) ; | |
1138 | #endif | |
5ca0d812 SC |
1139 | |
1140 | x += MacGetLeftBorderSize() ; | |
1141 | y += MacGetTopBorderSize() ; | |
1142 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
1143 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1144 | ||
79392158 SC |
1145 | if ( adjustOrigin ) |
1146 | AdjustForParentClientOrigin( x , y ) ; | |
7ebf5540 SC |
1147 | #if TARGET_API_MAC_OSX |
1148 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
1149 | if ( ! GetParent()->IsTopLevel() ) | |
1150 | { | |
1151 | x -= GetParent()->MacGetLeftBorderSize() ; | |
1152 | y -= GetParent()->MacGetTopBorderSize() ; | |
1153 | } | |
1154 | #endif | |
facd6764 SC |
1155 | return true ; |
1156 | } | |
1157 | ||
42ef83fa | 1158 | // Get window size (not client size) |
facd6764 SC |
1159 | void wxWindowMac::DoGetSize(int *x, int *y) const |
1160 | { | |
5ca0d812 | 1161 | // take the size of the control and add the borders that have to be drawn outside |
42ef83fa SC |
1162 | int x1 , y1 , w1 , h1 ; |
1163 | ||
facd6764 | 1164 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; |
42ef83fa | 1165 | |
5ca0d812 SC |
1166 | w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
1167 | h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
1168 | ||
1169 | if(x) *x = w1 ; | |
1170 | if(y) *y = h1 ; | |
facd6764 SC |
1171 | } |
1172 | ||
42ef83fa | 1173 | // get the position of the bounds of this window in client coordinates of its parent |
facd6764 SC |
1174 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
1175 | { | |
facd6764 SC |
1176 | int x1 , y1 , w1 ,h1 ; |
1177 | MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; | |
5ca0d812 SC |
1178 | x1 -= MacGetLeftBorderSize() ; |
1179 | y1 -= MacGetTopBorderSize() ; | |
42ef83fa SC |
1180 | // to non-client |
1181 | #if !TARGET_API_MAC_OSX | |
1182 | if ( !GetParent()->IsTopLevel() ) | |
1183 | { | |
1184 | Rect bounds ; | |
1185 | GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ; | |
1186 | x1 -= bounds.left ; | |
1187 | y1 -= bounds.top ; | |
1188 | } | |
1189 | #endif | |
facd6764 | 1190 | if ( !IsTopLevel() ) |
2b5f62a0 | 1191 | { |
facd6764 SC |
1192 | wxWindow *parent = GetParent(); |
1193 | if ( parent ) | |
8950f7cc | 1194 | { |
1a02aff9 SC |
1195 | // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix |
1196 | x1 += parent->MacGetLeftBorderSize() ; | |
1197 | y1 += parent->MacGetTopBorderSize() ; | |
1198 | // and now to client coordinates | |
facd6764 SC |
1199 | wxPoint pt(parent->GetClientAreaOrigin()); |
1200 | x1 -= pt.x ; | |
1201 | y1 -= pt.y ; | |
6ed71b4f | 1202 | } |
2b5f62a0 | 1203 | } |
facd6764 SC |
1204 | if(x) *x = x1 ; |
1205 | if(y) *y = y1 ; | |
facd6764 | 1206 | } |
51abe921 | 1207 | |
e766c8a9 | 1208 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 1209 | { |
facd6764 SC |
1210 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1211 | ||
1212 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
1213 | ||
1214 | { | |
1215 | Point localwhere = {0,0} ; | |
519cb848 | 1216 | |
facd6764 SC |
1217 | if(x) localwhere.h = * x ; |
1218 | if(y) localwhere.v = * y ; | |
1219 | ||
a9de2608 | 1220 | QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1221 | if(x) *x = localwhere.h ; |
1222 | if(y) *y = localwhere.v ; | |
6ed71b4f | 1223 | |
facd6764 | 1224 | } |
2078220e | 1225 | MacRootWindowToWindow( x , y ) ; |
facd6764 SC |
1226 | |
1227 | wxPoint origin = GetClientAreaOrigin() ; | |
1228 | if(x) *x -= origin.x ; | |
1229 | if(y) *y -= origin.y ; | |
e9576ca5 SC |
1230 | } |
1231 | ||
e766c8a9 | 1232 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 1233 | { |
facd6764 SC |
1234 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1235 | wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; | |
14c9cbdb | 1236 | |
facd6764 SC |
1237 | wxPoint origin = GetClientAreaOrigin() ; |
1238 | if(x) *x += origin.x ; | |
1239 | if(y) *y += origin.y ; | |
14c9cbdb | 1240 | |
2078220e | 1241 | MacWindowToRootWindow( x , y ) ; |
14c9cbdb | 1242 | |
facd6764 SC |
1243 | { |
1244 | Point localwhere = { 0,0 }; | |
1245 | if(x) localwhere.h = * x ; | |
1246 | if(y) localwhere.v = * y ; | |
a9de2608 | 1247 | QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ; |
facd6764 SC |
1248 | if(x) *x = localwhere.h ; |
1249 | if(y) *y = localwhere.v ; | |
1250 | } | |
519cb848 SC |
1251 | } |
1252 | ||
e766c8a9 | 1253 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 1254 | { |
1c310985 SC |
1255 | wxPoint origin = GetClientAreaOrigin() ; |
1256 | if(x) *x += origin.x ; | |
1257 | if(y) *y += origin.y ; | |
14c9cbdb | 1258 | |
1c310985 SC |
1259 | MacWindowToRootWindow( x , y ) ; |
1260 | } | |
1261 | ||
1262 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
1263 | { | |
1c310985 | 1264 | MacRootWindowToWindow( x , y ) ; |
facd6764 SC |
1265 | |
1266 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 SC |
1267 | if(x) *x -= origin.x ; |
1268 | if(y) *y -= origin.y ; | |
1269 | } | |
1270 | ||
1271 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
1272 | { | |
facd6764 | 1273 | #if TARGET_API_MAC_OSX |
5ca0d812 | 1274 | wxPoint pt ; |
facd6764 SC |
1275 | if ( x ) pt.x = *x ; |
1276 | if ( y ) pt.y = *y ; | |
1277 | ||
125c7984 | 1278 | if ( !IsTopLevel() ) |
5437ff47 RD |
1279 | { |
1280 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
1281 | if (top) | |
5ca0d812 SC |
1282 | { |
1283 | pt.x -= MacGetLeftBorderSize() ; | |
1284 | pt.y -= MacGetTopBorderSize() ; | |
1285 | wxMacControl::Convert( &pt , m_peer , top->m_peer ) ; | |
1286 | } | |
5437ff47 | 1287 | } |
facd6764 SC |
1288 | |
1289 | if ( x ) *x = (int) pt.x ; | |
1290 | if ( y ) *y = (int) pt.y ; | |
1291 | #else | |
1c310985 | 1292 | if ( !IsTopLevel() ) |
6264b550 | 1293 | { |
facd6764 | 1294 | Rect bounds ; |
5ca0d812 | 1295 | m_peer->GetRect( &bounds ) ; |
055a486b SC |
1296 | if(x) *x += bounds.left - MacGetLeftBorderSize() ; |
1297 | if(y) *y += bounds.top - MacGetTopBorderSize() ; | |
6264b550 | 1298 | } |
facd6764 SC |
1299 | #endif |
1300 | } | |
1301 | ||
1302 | void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const | |
1303 | { | |
1304 | int x1 , y1 ; | |
1305 | if ( x ) x1 = *x ; | |
1306 | if ( y ) y1 = *y ; | |
1307 | MacWindowToRootWindow( &x1 , &y1 ) ; | |
1308 | if ( x ) *x = x1 ; | |
1309 | if ( y ) *y = y1 ; | |
519cb848 SC |
1310 | } |
1311 | ||
1c310985 | 1312 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const |
519cb848 | 1313 | { |
facd6764 | 1314 | #if TARGET_API_MAC_OSX |
5ca0d812 | 1315 | wxPoint pt ; |
facd6764 SC |
1316 | if ( x ) pt.x = *x ; |
1317 | if ( y ) pt.y = *y ; | |
1318 | ||
125c7984 | 1319 | if ( !IsTopLevel() ) |
5ca0d812 SC |
1320 | { |
1321 | wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ; | |
1322 | pt.x += MacGetLeftBorderSize() ; | |
1323 | pt.y += MacGetTopBorderSize() ; | |
1324 | } | |
facd6764 SC |
1325 | |
1326 | if ( x ) *x = (int) pt.x ; | |
1327 | if ( y ) *y = (int) pt.y ; | |
1328 | #else | |
1c310985 | 1329 | if ( !IsTopLevel() ) |
6264b550 | 1330 | { |
facd6764 | 1331 | Rect bounds ; |
5ca0d812 | 1332 | m_peer->GetRect( &bounds ) ; |
055a486b SC |
1333 | if(x) *x -= bounds.left + MacGetLeftBorderSize() ; |
1334 | if(y) *y -= bounds.top + MacGetTopBorderSize() ; | |
6264b550 | 1335 | } |
facd6764 | 1336 | #endif |
e9576ca5 SC |
1337 | } |
1338 | ||
facd6764 | 1339 | void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const |
e9576ca5 | 1340 | { |
facd6764 SC |
1341 | int x1 , y1 ; |
1342 | if ( x ) x1 = *x ; | |
1343 | if ( y ) y1 = *y ; | |
1344 | MacRootWindowToWindow( &x1 , &y1 ) ; | |
1345 | if ( x ) *x = x1 ; | |
1346 | if ( y ) *y = y1 ; | |
1347 | } | |
6ed71b4f | 1348 | |
29281095 SC |
1349 | void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1350 | { | |
1351 | RgnHandle rgn = NewRgn() ; | |
1352 | Rect content ; | |
5ca0d812 | 1353 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
29281095 SC |
1354 | { |
1355 | GetRegionBounds( rgn , &content ) ; | |
1356 | DisposeRgn( rgn ) ; | |
1357 | } | |
1358 | else | |
1359 | { | |
5ca0d812 | 1360 | m_peer->GetRect( &content ) ; |
29281095 SC |
1361 | } |
1362 | Rect structure ; | |
5ca0d812 | 1363 | m_peer->GetRect( &structure ) ; |
29281095 SC |
1364 | #if !TARGET_API_MAC_OSX |
1365 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1366 | #endif | |
1367 | left = content.left - structure.left ; | |
1368 | top = content.top - structure.top ; | |
1369 | right = structure.right - content.right ; | |
1370 | bottom = structure.bottom - content.bottom ; | |
1371 | } | |
1372 | ||
facd6764 SC |
1373 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const |
1374 | { | |
1375 | wxSize sizeTotal = size; | |
1376 | ||
1377 | RgnHandle rgn = NewRgn() ; | |
1378 | ||
1379 | Rect content ; | |
1380 | ||
5ca0d812 | 1381 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
6618870d | 1382 | { |
facd6764 SC |
1383 | GetRegionBounds( rgn , &content ) ; |
1384 | DisposeRgn( rgn ) ; | |
6618870d SC |
1385 | } |
1386 | else | |
1387 | { | |
5ca0d812 | 1388 | m_peer->GetRect( &content ) ; |
e40298d5 | 1389 | } |
facd6764 | 1390 | Rect structure ; |
5ca0d812 | 1391 | m_peer->GetRect( &structure ) ; |
facd6764 SC |
1392 | #if !TARGET_API_MAC_OSX |
1393 | OffsetRect( &content , -structure.left , -structure.top ) ; | |
1394 | #endif | |
6ed71b4f | 1395 | |
facd6764 SC |
1396 | sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; |
1397 | sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; | |
6ed71b4f | 1398 | |
facd6764 SC |
1399 | sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1400 | sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
6ed71b4f | 1401 | |
facd6764 | 1402 | return sizeTotal; |
e9576ca5 SC |
1403 | } |
1404 | ||
1405 | ||
1406 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
e766c8a9 | 1407 | void wxWindowMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 1408 | { |
9453cf2b | 1409 | int ww, hh; |
6ed71b4f | 1410 | |
facd6764 SC |
1411 | RgnHandle rgn = NewRgn() ; |
1412 | Rect content ; | |
5ca0d812 | 1413 | if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) |
facd6764 SC |
1414 | { |
1415 | GetRegionBounds( rgn , &content ) ; | |
1416 | DisposeRgn( rgn ) ; | |
1417 | } | |
1418 | else | |
1419 | { | |
5ca0d812 | 1420 | m_peer->GetRect( &content ) ; |
facd6764 SC |
1421 | } |
1422 | #if !TARGET_API_MAC_OSX | |
1423 | Rect structure ; | |
5ca0d812 | 1424 | m_peer->GetRect( &structure ) ; |
facd6764 SC |
1425 | OffsetRect( &content , -structure.left , -structure.top ) ; |
1426 | #endif | |
1427 | ww = content.right - content.left ; | |
1428 | hh = content.bottom - content.top ; | |
055a486b | 1429 | /* |
6264b550 RR |
1430 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1431 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
055a486b | 1432 | */ |
db7a550b | 1433 | /* |
e40298d5 JS |
1434 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) |
1435 | { | |
1436 | int x1 = 0 ; | |
1437 | int y1 = 0 ; | |
facd6764 SC |
1438 | int w ; |
1439 | int h ; | |
1440 | GetSize( &w , &h ) ; | |
1441 | ||
e40298d5 JS |
1442 | MacClientToRootWindow( &x1 , &y1 ) ; |
1443 | MacClientToRootWindow( &w , &h ) ; | |
6ed71b4f | 1444 | |
e40298d5 | 1445 | wxWindowMac *iter = (wxWindowMac*)this ; |
6ed71b4f | 1446 | |
e40298d5 JS |
1447 | int totW = 10000 , totH = 10000; |
1448 | while( iter ) | |
6264b550 | 1449 | { |
e40298d5 JS |
1450 | if ( iter->IsTopLevel() ) |
1451 | { | |
facd6764 | 1452 | iter->GetSize( &totW , &totH ) ; |
e40298d5 JS |
1453 | break ; |
1454 | } | |
6ed71b4f | 1455 | |
e40298d5 | 1456 | iter = iter->GetParent() ; |
6264b550 | 1457 | } |
6ed71b4f | 1458 | |
e40298d5 | 1459 | if (m_hScrollBar && m_hScrollBar->IsShown() ) |
6264b550 | 1460 | { |
db7a550b | 1461 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; |
e40298d5 JS |
1462 | if ( h-y1 >= totH ) |
1463 | { | |
1464 | hh += 1 ; | |
1465 | } | |
6264b550 | 1466 | } |
e40298d5 | 1467 | if (m_vScrollBar && m_vScrollBar->IsShown() ) |
6264b550 | 1468 | { |
db7a550b | 1469 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; |
e40298d5 JS |
1470 | if ( w-x1 >= totW ) |
1471 | { | |
1472 | ww += 1 ; | |
1473 | } | |
6264b550 RR |
1474 | } |
1475 | } | |
db7a550b SC |
1476 | */ |
1477 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
1478 | { | |
1479 | hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ; | |
1480 | } | |
1481 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
1482 | { | |
1483 | ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE; | |
1484 | } | |
e40298d5 JS |
1485 | if(x) *x = ww; |
1486 | if(y) *y = hh; | |
facd6764 SC |
1487 | |
1488 | } | |
1489 | ||
1490 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
1491 | { | |
1492 | if (m_cursor == cursor) | |
1493 | return FALSE; | |
1494 | ||
1495 | if (wxNullCursor == cursor) | |
1496 | { | |
1497 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
1498 | return FALSE ; | |
1499 | } | |
1500 | else | |
1501 | { | |
1502 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
1503 | return FALSE ; | |
1504 | } | |
1505 | ||
1506 | wxASSERT_MSG( m_cursor.Ok(), | |
1507 | wxT("cursor must be valid after call to the base version")); | |
facd6764 | 1508 | |
facd6764 | 1509 | |
2d1760d3 | 1510 | wxWindowMac *mouseWin = 0 ; |
facd6764 | 1511 | { |
2d1760d3 SC |
1512 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1513 | CGrafPtr savePort ; | |
1514 | Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; | |
1515 | ||
1516 | // TODO If we ever get a GetCurrentEvent.. replacement for the mouse | |
1517 | // position, use it... | |
1518 | ||
1519 | Point pt ; | |
1520 | GetMouse( &pt ) ; | |
1521 | ControlPartCode part ; | |
1522 | ControlRef control ; | |
1523 | control = wxMacFindControlUnderMouse( pt , window , &part ) ; | |
1524 | if ( control ) | |
1525 | mouseWin = wxFindControlFromMacControl( control ) ; | |
1526 | ||
1527 | if ( swapped ) | |
1528 | QDSwapPort( savePort , NULL ) ; | |
facd6764 | 1529 | } |
2d1760d3 SC |
1530 | |
1531 | if ( mouseWin == this && !wxIsBusy() ) | |
facd6764 SC |
1532 | { |
1533 | m_cursor.MacInstall() ; | |
1534 | } | |
1535 | ||
1536 | return TRUE ; | |
519cb848 SC |
1537 | } |
1538 | ||
facd6764 SC |
1539 | #if wxUSE_MENUS |
1540 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
1541 | { | |
1542 | menu->SetInvokingWindow(this); | |
1543 | menu->UpdateUI(); | |
971562cb VS |
1544 | |
1545 | if ( x == -1 && y == -1 ) | |
1546 | { | |
1547 | wxPoint mouse = wxGetMousePosition(); | |
1548 | x = mouse.x; y = mouse.y; | |
1549 | } | |
1550 | else | |
1551 | { | |
1552 | ClientToScreen( &x , &y ) ; | |
1553 | } | |
facd6764 SC |
1554 | |
1555 | menu->MacBeforeDisplay( true ) ; | |
1556 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
1557 | if ( HiWord(menuResult) != 0 ) | |
1558 | { | |
1559 | MenuCommand id ; | |
1560 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
1561 | wxMenuItem* item = NULL ; | |
1562 | wxMenu* realmenu ; | |
1563 | item = menu->FindItem(id, &realmenu) ; | |
1564 | if (item->IsCheckable()) | |
1565 | { | |
1566 | item->Check( !item->IsChecked() ) ; | |
1567 | } | |
1568 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
1569 | } | |
1570 | menu->MacAfterDisplay( true ) ; | |
1571 | ||
1572 | menu->SetInvokingWindow(NULL); | |
1573 | ||
1574 | return TRUE; | |
1575 | } | |
1576 | #endif | |
51abe921 SC |
1577 | |
1578 | // ---------------------------------------------------------------------------- | |
1579 | // tooltips | |
1580 | // ---------------------------------------------------------------------------- | |
1581 | ||
1582 | #if wxUSE_TOOLTIPS | |
1583 | ||
e766c8a9 | 1584 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
1585 | { |
1586 | wxWindowBase::DoSetToolTip(tooltip); | |
6ed71b4f | 1587 | |
6264b550 RR |
1588 | if ( m_tooltip ) |
1589 | m_tooltip->SetWindow(this); | |
51abe921 SC |
1590 | } |
1591 | ||
1592 | #endif // wxUSE_TOOLTIPS | |
1593 | ||
e766c8a9 | 1594 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 1595 | { |
db7a550b | 1596 | // this is never called for a toplevel window, so we know we have a parent |
facd6764 | 1597 | int former_x , former_y , former_w, former_h ; |
db7a550b SC |
1598 | |
1599 | // Get true coordinates of former position | |
facd6764 SC |
1600 | DoGetPosition( &former_x , &former_y ) ; |
1601 | DoGetSize( &former_w , &former_h ) ; | |
db7a550b SC |
1602 | |
1603 | wxWindow *parent = GetParent(); | |
1604 | if ( parent ) | |
1605 | { | |
1606 | wxPoint pt(parent->GetClientAreaOrigin()); | |
1607 | former_x += pt.x ; | |
1608 | former_y += pt.y ; | |
1609 | } | |
6ed71b4f | 1610 | |
e40298d5 JS |
1611 | int actualWidth = width; |
1612 | int actualHeight = height; | |
1613 | int actualX = x; | |
1614 | int actualY = y; | |
6ed71b4f | 1615 | |
14c9cbdb | 1616 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 1617 | actualWidth = m_minWidth; |
14c9cbdb | 1618 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 1619 | actualHeight = m_minHeight; |
14c9cbdb | 1620 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 1621 | actualWidth = m_maxWidth; |
14c9cbdb | 1622 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
6264b550 | 1623 | actualHeight = m_maxHeight; |
6ed71b4f | 1624 | |
6264b550 RR |
1625 | bool doMove = false ; |
1626 | bool doResize = false ; | |
6ed71b4f | 1627 | |
6264b550 RR |
1628 | if ( actualX != former_x || actualY != former_y ) |
1629 | { | |
1630 | doMove = true ; | |
1631 | } | |
1632 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1633 | { | |
1634 | doResize = true ; | |
1635 | } | |
6ed71b4f | 1636 | |
6264b550 RR |
1637 | if ( doMove || doResize ) |
1638 | { | |
79392158 SC |
1639 | // we don't adjust twice for the origin |
1640 | Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; | |
5ca0d812 | 1641 | bool vis = m_peer->IsVisible(); |
d390fdcf SC |
1642 | |
1643 | int outerBorder = MacGetLeftBorderSize() ; | |
1644 | if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) | |
7ebf5540 | 1645 | outerBorder += 4 ; |
d390fdcf SC |
1646 | |
1647 | if ( vis && ( outerBorder > 0 ) ) | |
1648 | { | |
1649 | // as the borders are drawn on the parent we have to properly invalidate all these areas | |
1650 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ; | |
1651 | ||
1652 | Rect rect ; | |
1653 | ||
1654 | m_peer->GetRect( &rect ) ; | |
1655 | RectRgn( updateInner , &rect ) ; | |
1656 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1657 | RectRgn( updateOuter , &rect ) ; | |
1658 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
1659 | wxPoint parent(0,0); | |
1660 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
1661 | parent -= GetParent()->GetClientAreaOrigin() ; | |
1662 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
1663 | CopyRgn( updateOuter , updateTotal ) ; | |
1664 | ||
1665 | rect = r ; | |
1666 | RectRgn( updateInner , &rect ) ; | |
1667 | InsetRect( &rect , -outerBorder , -outerBorder ) ; | |
1668 | RectRgn( updateOuter , &rect ) ; | |
1669 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
7ebf5540 SC |
1670 | |
1671 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
ac8c7f49 | 1672 | UnionRgn( updateOuter , updateTotal , updateTotal ) ; |
d390fdcf SC |
1673 | |
1674 | GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ; | |
1675 | DisposeRgn(updateOuter) ; | |
1676 | DisposeRgn(updateInner) ; | |
1677 | DisposeRgn(updateTotal) ; | |
1678 | } | |
5ca0d812 | 1679 | |
b05bf6ee SC |
1680 | // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! |
1681 | if ( vis ) | |
5ca0d812 | 1682 | m_peer->SetVisibility( false , true ) ; |
d390fdcf | 1683 | |
5ca0d812 | 1684 | m_peer->SetRect( &r ) ; |
b05bf6ee | 1685 | if ( vis ) |
5ca0d812 SC |
1686 | m_peer->SetVisibility( true , true ) ; |
1687 | ||
6264b550 RR |
1688 | MacRepositionScrollBars() ; |
1689 | if ( doMove ) | |
1690 | { | |
facd6764 | 1691 | wxPoint point(actualX,actualY); |
6264b550 RR |
1692 | wxMoveEvent event(point, m_windowId); |
1693 | event.SetEventObject(this); | |
1694 | GetEventHandler()->ProcessEvent(event) ; | |
1695 | } | |
1696 | if ( doResize ) | |
1697 | { | |
e40298d5 | 1698 | MacRepositionScrollBars() ; |
facd6764 | 1699 | wxSize size(actualWidth, actualHeight); |
e40298d5 JS |
1700 | wxSizeEvent event(size, m_windowId); |
1701 | event.SetEventObject(this); | |
1702 | GetEventHandler()->ProcessEvent(event); | |
6264b550 RR |
1703 | } |
1704 | } | |
6ed71b4f | 1705 | |
954fc50b SC |
1706 | } |
1707 | ||
facd6764 SC |
1708 | wxSize wxWindowMac::DoGetBestSize() const |
1709 | { | |
eb69d46e SC |
1710 | if ( m_macIsUserPane || IsTopLevel() ) |
1711 | return wxWindowBase::DoGetBestSize() ; | |
1712 | ||
facd6764 | 1713 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
facd6764 | 1714 | int bestWidth, bestHeight ; |
5ca0d812 | 1715 | m_peer->GetBestRect( &bestsize ) ; |
facd6764 SC |
1716 | |
1717 | if ( EmptyRect( &bestsize ) ) | |
1718 | { | |
facd6764 SC |
1719 | bestsize.left = bestsize.top = 0 ; |
1720 | bestsize.right = 16 ; | |
1721 | bestsize.bottom = 16 ; | |
1722 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1723 | { | |
1724 | bestsize.bottom = 16 ; | |
1725 | } | |
1726 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
1727 | { | |
1728 | bestsize.bottom = 24 ; | |
1729 | } | |
1730 | else | |
1731 | { | |
1732 | // return wxWindowBase::DoGetBestSize() ; | |
1733 | } | |
1734 | } | |
1735 | ||
1736 | bestWidth = bestsize.right - bestsize.left ; | |
1737 | bestHeight = bestsize.bottom - bestsize.top ; | |
1738 | if ( bestHeight < 10 ) | |
1739 | bestHeight = 13 ; | |
1740 | ||
1741 | return wxSize(bestWidth, bestHeight); | |
1742 | } | |
1743 | ||
1744 | ||
954fc50b SC |
1745 | // set the size of the window: if the dimensions are positive, just use them, |
1746 | // but if any of them is equal to -1, it means that we must find the value for | |
1747 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1748 | // which case -1 is a valid value for x and y) | |
1749 | // | |
1750 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1751 | // the width/height to best suit our contents, otherwise we reuse the current | |
1752 | // width/height | |
1753 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1754 | { | |
1755 | // get the current size and position... | |
1756 | int currentX, currentY; | |
1757 | GetPosition(¤tX, ¤tY); | |
6ed71b4f | 1758 | |
954fc50b SC |
1759 | int currentW,currentH; |
1760 | GetSize(¤tW, ¤tH); | |
6ed71b4f | 1761 | |
954fc50b SC |
1762 | // ... and don't do anything (avoiding flicker) if it's already ok |
1763 | if ( x == currentX && y == currentY && | |
769ac869 | 1764 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) |
954fc50b | 1765 | { |
facd6764 | 1766 | // TODO REMOVE |
6264b550 | 1767 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
1768 | return; |
1769 | } | |
6ed71b4f | 1770 | |
954fc50b SC |
1771 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
1772 | x = currentX; | |
1773 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1774 | y = currentY; | |
6ed71b4f | 1775 | |
954fc50b | 1776 | AdjustForParentClientOrigin(x, y, sizeFlags); |
6ed71b4f | 1777 | |
954fc50b SC |
1778 | wxSize size(-1, -1); |
1779 | if ( width == -1 ) | |
1780 | { | |
1781 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1782 | { | |
1783 | size = DoGetBestSize(); | |
1784 | width = size.x; | |
1785 | } | |
1786 | else | |
1787 | { | |
1788 | // just take the current one | |
1789 | width = currentW; | |
1790 | } | |
1791 | } | |
6ed71b4f | 1792 | |
954fc50b SC |
1793 | if ( height == -1 ) |
1794 | { | |
1795 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1796 | { | |
1797 | if ( size.x == -1 ) | |
1798 | { | |
1799 | size = DoGetBestSize(); | |
1800 | } | |
1801 | //else: already called DoGetBestSize() above | |
6ed71b4f | 1802 | |
954fc50b SC |
1803 | height = size.y; |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | // just take the current one | |
1808 | height = currentH; | |
1809 | } | |
1810 | } | |
6ed71b4f | 1811 | |
954fc50b | 1812 | DoMoveWindow(x, y, width, height); |
6ed71b4f | 1813 | |
e9576ca5 | 1814 | } |
519cb848 | 1815 | |
e766c8a9 | 1816 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 1817 | { |
facd6764 SC |
1818 | RgnHandle rgn = NewRgn() ; |
1819 | Rect content ; | |
5ca0d812 | 1820 | m_peer->GetRegion( kControlContentMetaPart , rgn ) ; |
facd6764 SC |
1821 | GetRegionBounds( rgn , &content ) ; |
1822 | DisposeRgn( rgn ) ; | |
1823 | #if !TARGET_API_MAC_OSX | |
736fac3a SC |
1824 | // if the content rgn is empty / not supported |
1825 | // don't attempt to correct the coordinates to wxWindow relative ones | |
1826 | if (!::EmptyRect( &content ) ) | |
1827 | { | |
1828 | Rect structure ; | |
5ca0d812 | 1829 | m_peer->GetRect( &structure ) ; |
736fac3a SC |
1830 | OffsetRect( &content , -structure.left , -structure.top ) ; |
1831 | } | |
facd6764 SC |
1832 | #endif |
1833 | ||
1834 | return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); | |
1835 | } | |
1836 | ||
1837 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1838 | { | |
1839 | if ( clientheight != -1 || clientheight != -1 ) | |
1840 | { | |
1841 | int currentclientwidth , currentclientheight ; | |
1842 | int currentwidth , currentheight ; | |
1843 | ||
1844 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1845 | GetSize( ¤twidth , ¤theight ) ; | |
1846 | ||
1847 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
1848 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1849 | } | |
e9576ca5 SC |
1850 | } |
1851 | ||
d84afea9 | 1852 | void wxWindowMac::SetTitle(const wxString& title) |
e9576ca5 | 1853 | { |
facd6764 SC |
1854 | m_label = wxStripMenuCodes(title) ; |
1855 | ||
21fd5529 | 1856 | if ( m_peer && m_peer->Ok() ) |
facd6764 | 1857 | { |
5ca0d812 | 1858 | m_peer->SetTitle( m_label ) ; |
facd6764 SC |
1859 | } |
1860 | Refresh() ; | |
519cb848 SC |
1861 | } |
1862 | ||
d84afea9 | 1863 | wxString wxWindowMac::GetTitle() const |
519cb848 | 1864 | { |
ed60b502 | 1865 | return m_label ; |
519cb848 SC |
1866 | } |
1867 | ||
8ab50549 SC |
1868 | bool wxWindowMac::Show(bool show) |
1869 | { | |
1870 | if ( !wxWindowBase::Show(show) ) | |
1871 | return FALSE; | |
1872 | ||
1873 | // TODO use visibilityChanged Carbon Event for OSX | |
1874 | bool former = MacIsReallyShown() ; | |
1875 | ||
5ca0d812 | 1876 | m_peer->SetVisibility( show , true ) ; |
8ab50549 SC |
1877 | if ( former != MacIsReallyShown() ) |
1878 | MacPropagateVisibilityChanged() ; | |
1879 | return TRUE; | |
1880 | } | |
1881 | ||
1882 | bool wxWindowMac::Enable(bool enable) | |
1883 | { | |
21fd5529 | 1884 | wxASSERT( m_peer->Ok() ) ; |
8ab50549 SC |
1885 | if ( !wxWindowBase::Enable(enable) ) |
1886 | return FALSE; | |
1887 | ||
1888 | bool former = MacIsReallyEnabled() ; | |
5ca0d812 | 1889 | m_peer->Enable( enable ) ; |
8ab50549 SC |
1890 | |
1891 | if ( former != MacIsReallyEnabled() ) | |
1892 | MacPropagateEnabledStateChanged() ; | |
1893 | return TRUE; | |
1894 | } | |
1895 | ||
1896 | // | |
1897 | // status change propagations (will be not necessary for OSX later ) | |
1898 | // | |
1899 | ||
facd6764 SC |
1900 | void wxWindowMac::MacPropagateVisibilityChanged() |
1901 | { | |
73fe67bd | 1902 | #if !TARGET_API_MAC_OSX |
facd6764 SC |
1903 | MacVisibilityChanged() ; |
1904 | ||
1905 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1906 | while ( node ) | |
1907 | { | |
1908 | wxWindowMac *child = node->GetData(); | |
1909 | if ( child->IsShown() ) | |
1910 | child->MacPropagateVisibilityChanged( ) ; | |
1911 | node = node->GetNext(); | |
1912 | } | |
73fe67bd | 1913 | #endif |
facd6764 SC |
1914 | } |
1915 | ||
8ab50549 | 1916 | void wxWindowMac::MacPropagateEnabledStateChanged( ) |
e9576ca5 | 1917 | { |
73fe67bd | 1918 | #if !TARGET_API_MAC_OSX |
8ab50549 | 1919 | MacEnabledStateChanged() ; |
facd6764 | 1920 | |
8ab50549 SC |
1921 | wxWindowListNode *node = GetChildren().GetFirst(); |
1922 | while ( node ) | |
1923 | { | |
1924 | wxWindowMac *child = node->GetData(); | |
1925 | if ( child->IsEnabled() ) | |
1926 | child->MacPropagateEnabledStateChanged() ; | |
1927 | node = node->GetNext(); | |
1928 | } | |
73fe67bd | 1929 | #endif |
8ab50549 SC |
1930 | } |
1931 | ||
1932 | void wxWindowMac::MacPropagateHiliteChanged( ) | |
1933 | { | |
73fe67bd | 1934 | #if !TARGET_API_MAC_OSX |
8ab50549 | 1935 | MacHiliteChanged() ; |
facd6764 | 1936 | |
8ab50549 SC |
1937 | wxWindowListNode *node = GetChildren().GetFirst(); |
1938 | while ( node ) | |
1939 | { | |
1940 | wxWindowMac *child = node->GetData(); | |
1941 | // if ( child->IsEnabled() ) | |
1942 | child->MacPropagateHiliteChanged() ; | |
1943 | node = node->GetNext(); | |
1944 | } | |
73fe67bd | 1945 | #endif |
8ab50549 SC |
1946 | } |
1947 | ||
1948 | // | |
1949 | // status change notifications | |
1950 | // | |
1951 | ||
1952 | void wxWindowMac::MacVisibilityChanged() | |
1953 | { | |
1954 | } | |
1955 | ||
1956 | void wxWindowMac::MacHiliteChanged() | |
1957 | { | |
1958 | } | |
1959 | ||
1960 | void wxWindowMac::MacEnabledStateChanged() | |
1961 | { | |
facd6764 | 1962 | } |
e7549107 | 1963 | |
8ab50549 SC |
1964 | // |
1965 | // status queries on the inherited window's state | |
1966 | // | |
1967 | ||
facd6764 SC |
1968 | bool wxWindowMac::MacIsReallyShown() |
1969 | { | |
1970 | // only under OSX the visibility of the TLW is taken into account | |
1971 | #if TARGET_API_MAC_OSX | |
aa522e33 SC |
1972 | if ( m_peer && m_peer->Ok() ) |
1973 | return m_peer->IsVisible(); | |
1974 | #endif | |
facd6764 SC |
1975 | wxWindow* win = this ; |
1976 | while( win->IsShown() ) | |
1977 | { | |
1978 | if ( win->IsTopLevel() ) | |
1979 | return true ; | |
1980 | ||
1981 | win = win->GetParent() ; | |
1982 | if ( win == NULL ) | |
1983 | return true ; | |
1984 | ||
1985 | } ; | |
1986 | return false ; | |
facd6764 | 1987 | } |
4241baae | 1988 | |
facd6764 SC |
1989 | bool wxWindowMac::MacIsReallyEnabled() |
1990 | { | |
5ca0d812 | 1991 | return m_peer->IsEnabled() ; |
facd6764 SC |
1992 | } |
1993 | ||
8ab50549 | 1994 | bool wxWindowMac::MacIsReallyHilited() |
c809f3be | 1995 | { |
5ca0d812 | 1996 | return m_peer->IsActive(); |
c809f3be SC |
1997 | } |
1998 | ||
002c9672 SC |
1999 | void wxWindowMac::MacFlashInvalidAreas() |
2000 | { | |
2001 | #if TARGET_API_MAC_OSX | |
2002 | HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ; | |
2003 | #endif | |
2004 | } | |
2005 | ||
8ab50549 SC |
2006 | // |
2007 | // | |
2008 | // | |
2009 | ||
e766c8a9 | 2010 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 2011 | { |
6264b550 RR |
2012 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2013 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
2014 | } |
2015 | ||
e766c8a9 | 2016 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 2017 | { |
6264b550 RR |
2018 | wxClientDC dc ( (wxWindowMac*)this ) ; |
2019 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
2020 | } |
2021 | ||
e766c8a9 | 2022 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 2023 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 2024 | { |
e7549107 SC |
2025 | const wxFont *fontToUse = theFont; |
2026 | if ( !fontToUse ) | |
2027 | fontToUse = &m_font; | |
14c9cbdb | 2028 | |
e766c8a9 | 2029 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 2030 | long lx,ly,ld,le ; |
5fde6fcc | 2031 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 2032 | if ( externalLeading ) |
6264b550 | 2033 | *externalLeading = le ; |
2f1ae414 | 2034 | if ( descent ) |
6264b550 | 2035 | *descent = ld ; |
2f1ae414 | 2036 | if ( x ) |
6264b550 | 2037 | *x = lx ; |
2f1ae414 | 2038 | if ( y ) |
6264b550 | 2039 | *y = ly ; |
e9576ca5 SC |
2040 | } |
2041 | ||
0a67a93b | 2042 | /* |
14c9cbdb | 2043 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
1c310985 SC |
2044 | * we always intersect with the entire window, not only with the client area |
2045 | */ | |
14c9cbdb | 2046 | |
e766c8a9 | 2047 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 2048 | { |
065ab451 SC |
2049 | if ( m_peer == NULL ) |
2050 | return ; | |
2051 | ||
facd6764 | 2052 | #if TARGET_API_MAC_OSX |
1e8cde71 | 2053 | if ( rect == NULL ) |
5ca0d812 | 2054 | m_peer->SetNeedsDisplay( true ) ; |
1e8cde71 SC |
2055 | else |
2056 | { | |
2057 | RgnHandle update = NewRgn() ; | |
2058 | SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
84f6927e SC |
2059 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; |
2060 | wxPoint origin = GetClientAreaOrigin() ; | |
5ca0d812 | 2061 | OffsetRgn( update, origin.x , origin.y ) ; |
db7a550b SC |
2062 | // right now this is wx' window coordinates, as our native peer does not have borders, this is |
2063 | // inset | |
2064 | OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
4b5aa5c8 SC |
2065 | m_peer->SetNeedsDisplay( true , update) ; |
2066 | DisposeRgn( update ) ; | |
1e8cde71 | 2067 | } |
facd6764 | 2068 | #else |
a9825a9b SC |
2069 | /* |
2070 | RgnHandle updateRgn = NewRgn() ; | |
2071 | if ( rect == NULL ) | |
2072 | { | |
2073 | CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ; | |
2074 | } | |
2075 | else | |
2076 | { | |
2077 | SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; | |
2078 | SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ; | |
2079 | } | |
2080 | InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; | |
2081 | DisposeRgn(updateRgn) ; | |
2082 | */ | |
5ca0d812 | 2083 | if ( m_peer->IsVisible()) |
facd6764 | 2084 | { |
5ca0d812 SC |
2085 | m_peer->SetVisibility( false , false ) ; |
2086 | m_peer->SetVisibility( true , true ) ; | |
facd6764 SC |
2087 | } |
2088 | /* | |
94abc21f | 2089 | if ( MacGetTopLevelWindow() == NULL ) |
9a456218 | 2090 | return ; |
14c9cbdb | 2091 | |
5ca0d812 | 2092 | if ( !m_peer->IsVisible()) |
c3a05e8a SC |
2093 | return ; |
2094 | ||
2095 | wxPoint client = GetClientAreaOrigin(); | |
9a456218 RR |
2096 | int x1 = -client.x; |
2097 | int y1 = -client.y; | |
2098 | int x2 = m_width - client.x; | |
2099 | int y2 = m_height - client.y; | |
2100 | ||
2101 | if (IsKindOf( CLASSINFO(wxButton))) | |
2102 | { | |
2103 | // buttons have an "aura" | |
2104 | y1 -= 5; | |
2105 | x1 -= 5; | |
2106 | y2 += 5; | |
2107 | x2 += 5; | |
2108 | } | |
2109 | ||
2110 | Rect clientrect = { y1, x1, y2, x2 }; | |
14c9cbdb | 2111 | |
1c310985 | 2112 | if ( rect ) |
6264b550 | 2113 | { |
1c310985 | 2114 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; |
14c9cbdb | 2115 | SectRect( &clientrect , &r , &clientrect ) ; |
6264b550 | 2116 | } |
14c9cbdb | 2117 | |
1c310985 | 2118 | if ( !EmptyRect( &clientrect ) ) |
e9576ca5 | 2119 | { |
1c310985 | 2120 | int top = 0 , left = 0 ; |
14c9cbdb | 2121 | |
1c310985 SC |
2122 | MacClientToRootWindow( &left , &top ) ; |
2123 | OffsetRect( &clientrect , left , top ) ; | |
14c9cbdb | 2124 | |
1c310985 | 2125 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; |
e9576ca5 | 2126 | } |
facd6764 SC |
2127 | */ |
2128 | #endif | |
2129 | } | |
2130 | ||
79392158 SC |
2131 | void wxWindowMac::Freeze() |
2132 | { | |
2133 | #if TARGET_API_MAC_OSX | |
2134 | if ( !m_frozenness++ ) | |
2135 | { | |
5ca0d812 | 2136 | m_peer->SetDrawingEnabled( false ) ; |
79392158 SC |
2137 | } |
2138 | #endif | |
2139 | } | |
2140 | ||
b175b96b | 2141 | |
79392158 SC |
2142 | void wxWindowMac::Thaw() |
2143 | { | |
2144 | #if TARGET_API_MAC_OSX | |
2145 | wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); | |
2146 | ||
2147 | if ( !--m_frozenness ) | |
2148 | { | |
5ca0d812 SC |
2149 | m_peer->SetDrawingEnabled( true ) ; |
2150 | m_peer->InvalidateWithChildren() ; | |
79392158 SC |
2151 | } |
2152 | #endif | |
2153 | } | |
2154 | ||
facd6764 SC |
2155 | void wxWindowMac::MacRedrawControl() |
2156 | { | |
2157 | /* | |
5ca0d812 | 2158 | if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible()) |
facd6764 SC |
2159 | { |
2160 | #if TARGET_API_MAC_CARBON | |
2161 | Update() ; | |
2162 | #else | |
2163 | wxClientDC dc(this) ; | |
2164 | wxMacPortSetter helper(&dc) ; | |
2165 | wxMacWindowClipper clipper(this) ; | |
2166 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
21fd5529 | 2167 | UMADrawControl( *m_peer ) ; |
facd6764 SC |
2168 | #endif |
2169 | } | |
2170 | */ | |
2171 | } | |
2172 | ||
2173 | /* TODO | |
2174 | void wxWindowMac::OnPaint(wxPaintEvent& event) | |
2175 | { | |
2176 | // why don't we skip that here ? | |
e9576ca5 | 2177 | } |
facd6764 | 2178 | */ |
e9576ca5 | 2179 | |
e766c8a9 | 2180 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 2181 | { |
519cb848 | 2182 | // actually this is a windows-only concept |
e9576ca5 SC |
2183 | return NULL; |
2184 | } | |
2185 | ||
e9576ca5 | 2186 | // Coordinates relative to the window |
e766c8a9 | 2187 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 2188 | { |
e40298d5 | 2189 | // We really don't move the mouse programmatically under Mac. |
e9576ca5 SC |
2190 | } |
2191 | ||
facd6764 | 2192 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 2193 | { |
be346c26 | 2194 | #if TARGET_API_MAC_OSX |
facd6764 | 2195 | if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) |
94abc21f | 2196 | { |
facd6764 | 2197 | event.Skip() ; |
94abc21f SC |
2198 | } |
2199 | else | |
be346c26 | 2200 | #endif |
7ebf5540 SC |
2201 | { |
2202 | event.GetDC()->Clear() ; | |
2203 | } | |
1c310985 SC |
2204 | } |
2205 | ||
2206 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2207 | { | |
af6b7b80 | 2208 | event.Skip() ; |
e9576ca5 SC |
2209 | } |
2210 | ||
e766c8a9 | 2211 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 2212 | { |
1c310985 SC |
2213 | if ( orient == wxHORIZONTAL ) |
2214 | { | |
2215 | if ( m_hScrollBar ) | |
2216 | return m_hScrollBar->GetThumbPosition() ; | |
2217 | } | |
2218 | else | |
2219 | { | |
2220 | if ( m_vScrollBar ) | |
2221 | return m_vScrollBar->GetThumbPosition() ; | |
2222 | } | |
e9576ca5 SC |
2223 | return 0; |
2224 | } | |
2225 | ||
2226 | // This now returns the whole range, not just the number | |
2227 | // of positions that we can scroll. | |
e766c8a9 | 2228 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 2229 | { |
1c310985 SC |
2230 | if ( orient == wxHORIZONTAL ) |
2231 | { | |
2232 | if ( m_hScrollBar ) | |
2233 | return m_hScrollBar->GetRange() ; | |
2234 | } | |
2235 | else | |
2236 | { | |
2237 | if ( m_vScrollBar ) | |
2238 | return m_vScrollBar->GetRange() ; | |
2239 | } | |
e9576ca5 SC |
2240 | return 0; |
2241 | } | |
2242 | ||
e766c8a9 | 2243 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 2244 | { |
1c310985 SC |
2245 | if ( orient == wxHORIZONTAL ) |
2246 | { | |
2247 | if ( m_hScrollBar ) | |
2248 | return m_hScrollBar->GetThumbSize() ; | |
2249 | } | |
2250 | else | |
2251 | { | |
2252 | if ( m_vScrollBar ) | |
2253 | return m_vScrollBar->GetThumbSize() ; | |
2254 | } | |
e9576ca5 SC |
2255 | return 0; |
2256 | } | |
2257 | ||
e766c8a9 | 2258 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 2259 | { |
1c310985 | 2260 | if ( orient == wxHORIZONTAL ) |
6264b550 | 2261 | { |
1c310985 SC |
2262 | if ( m_hScrollBar ) |
2263 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
2264 | } |
2265 | else | |
2266 | { | |
1c310985 SC |
2267 | if ( m_vScrollBar ) |
2268 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 2269 | } |
2f1ae414 SC |
2270 | } |
2271 | ||
14c9cbdb | 2272 | void wxWindowMac::MacPaintBorders( int left , int top ) |
2f1ae414 | 2273 | { |
1c310985 | 2274 | if( IsTopLevel() ) |
6264b550 | 2275 | return ; |
11d1adbf | 2276 | |
fd926bcc SC |
2277 | Rect rect ; |
2278 | m_peer->GetRect( &rect ) ; | |
2279 | InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
2280 | ||
2281 | if ( !IsTopLevel() ) | |
2282 | { | |
2283 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
2284 | if (top) | |
2285 | { | |
2286 | wxPoint pt(0,0) ; | |
2287 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
2288 | rect.left += pt.x ; | |
2289 | rect.right += pt.x ; | |
2290 | rect.top += pt.y ; | |
2291 | rect.bottom += pt.y ; | |
2292 | } | |
2293 | } | |
2294 | ||
2f1ae414 SC |
2295 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
2296 | { | |
af6b7b80 | 2297 | Rect srect = rect ; |
11d1adbf | 2298 | SInt32 border = 0 ; |
5ca0d812 | 2299 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; |
af6b7b80 SC |
2300 | InsetRect( &srect , border , border ); |
2301 | DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
8208e181 SC |
2302 | } |
2303 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2304 | { | |
af6b7b80 | 2305 | Rect srect = rect ; |
1a02aff9 SC |
2306 | SInt32 border = 0 ; |
2307 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
af6b7b80 | 2308 | InsetRect( &srect , border , border ); |
1a02aff9 | 2309 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
eec462f8 | 2310 | } |
8208e181 SC |
2311 | } |
2312 | ||
abda5788 SC |
2313 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
2314 | { | |
2315 | if ( child == m_hScrollBar ) | |
2316 | m_hScrollBar = NULL ; | |
2317 | if ( child == m_vScrollBar ) | |
2318 | m_vScrollBar = NULL ; | |
14c9cbdb | 2319 | |
abda5788 SC |
2320 | wxWindowBase::RemoveChild( child ) ; |
2321 | } | |
2322 | ||
e9576ca5 | 2323 | // New function that will replace some of the above. |
e766c8a9 | 2324 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
2325 | int range, bool refresh) |
2326 | { | |
e40298d5 JS |
2327 | if ( orient == wxHORIZONTAL ) |
2328 | { | |
2329 | if ( m_hScrollBar ) | |
6264b550 | 2330 | { |
e40298d5 | 2331 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2332 | { |
e40298d5 JS |
2333 | if ( m_hScrollBar->IsShown() ) |
2334 | m_hScrollBar->Show(false) ; | |
2335 | } | |
2336 | else | |
2337 | { | |
2338 | if ( !m_hScrollBar->IsShown() ) | |
2339 | m_hScrollBar->Show(true) ; | |
2340 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
6264b550 RR |
2341 | } |
2342 | } | |
e40298d5 JS |
2343 | } |
2344 | else | |
2345 | { | |
2346 | if ( m_vScrollBar ) | |
6264b550 | 2347 | { |
e40298d5 | 2348 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2349 | { |
e40298d5 JS |
2350 | if ( m_vScrollBar->IsShown() ) |
2351 | m_vScrollBar->Show(false) ; | |
2352 | } | |
2353 | else | |
2354 | { | |
2355 | if ( !m_vScrollBar->IsShown() ) | |
2356 | m_vScrollBar->Show(true) ; | |
2357 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
6264b550 RR |
2358 | } |
2359 | } | |
e40298d5 JS |
2360 | } |
2361 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
2362 | } |
2363 | ||
2364 | // Does a physical scroll | |
e766c8a9 | 2365 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 2366 | { |
ba87f54c SC |
2367 | if( dx == 0 && dy ==0 ) |
2368 | return ; | |
2369 | ||
6ed71b4f | 2370 | |
6264b550 | 2371 | { |
adb8a71b | 2372 | |
6264b550 RR |
2373 | int width , height ; |
2374 | GetClientSize( &width , &height ) ; | |
adb8a71b | 2375 | #if TARGET_API_MAC_OSX |
002c9672 SC |
2376 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control |
2377 | // area is scrolled, this does not occur if width and height are 2 pixels less, | |
2378 | // TODO write optimal workaround | |
42ef83fa | 2379 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; |
adb8a71b SC |
2380 | if ( rect ) |
2381 | { | |
5ca0d812 | 2382 | scrollrect.Intersect( *rect ) ; |
adb8a71b | 2383 | } |
5ca0d812 | 2384 | if ( m_peer->GetNeedsDisplay() ) |
002c9672 SC |
2385 | { |
2386 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2387 | // either immediate redraw or full invalidate | |
2388 | #if 1 | |
2389 | // is the better overall solution, as it does not slow down scrolling | |
5ca0d812 | 2390 | m_peer->SetNeedsDisplay( true ) ; |
002c9672 SC |
2391 | #else |
2392 | // this would be the preferred version for fast drawing controls | |
2393 | if( UMAGetSystemVersion() < 0x1030 ) | |
2394 | Update() ; | |
2395 | else | |
42ef83fa | 2396 | HIViewRender(m_peer->GetControlRef()) ; |
002c9672 SC |
2397 | #endif |
2398 | } | |
84e5d27d SC |
2399 | // as the native control might be not a 0/0 wx window coordinates, we have to offset |
2400 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
5ca0d812 | 2401 | m_peer->ScrollRect( scrollrect , dx , dy ) ; |
adb8a71b | 2402 | #else |
6ed71b4f | 2403 | |
facd6764 SC |
2404 | wxPoint pos; |
2405 | pos.x = pos.y = 0; | |
430e1eed | 2406 | |
facd6764 | 2407 | Rect scrollrect; |
6264b550 | 2408 | RgnHandle updateRgn = NewRgn() ; |
430e1eed | 2409 | |
adb8a71b | 2410 | { |
430e1eed SC |
2411 | wxClientDC dc(this) ; |
2412 | wxMacPortSetter helper(&dc) ; | |
2413 | ||
5ca0d812 | 2414 | m_peer->GetRect( &scrollrect ) ; |
430e1eed SC |
2415 | scrollrect.top += MacGetTopBorderSize() ; |
2416 | scrollrect.left += MacGetLeftBorderSize() ; | |
2417 | scrollrect.bottom = scrollrect.top + height ; | |
2418 | scrollrect.right = scrollrect.left + width ; | |
2419 | ||
2420 | if ( rect ) | |
2421 | { | |
2422 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2423 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2424 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2425 | } | |
2426 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
ba87f54c | 2427 | } |
430e1eed | 2428 | // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ; |
facd6764 | 2429 | #endif |
6264b550 | 2430 | } |
6ed71b4f | 2431 | |
eb22f2a6 | 2432 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 2433 | { |
9bd1404d | 2434 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
2435 | if (child == m_vScrollBar) continue; |
2436 | if (child == m_hScrollBar) continue; | |
2437 | if (child->IsTopLevel()) continue; | |
6ed71b4f | 2438 | |
6264b550 RR |
2439 | int x,y; |
2440 | child->GetPosition( &x, &y ); | |
2441 | int w,h; | |
2442 | child->GetSize( &w, &h ); | |
00f55394 SC |
2443 | if (rect) |
2444 | { | |
2445 | wxRect rc(x,y,w,h); | |
2446 | if (rect->Intersects(rc)) | |
2447 | child->SetSize( x+dx, y+dy, w, h ); | |
2448 | } | |
2449 | else | |
2450 | { | |
2451 | child->SetSize( x+dx, y+dy, w, h ); | |
2452 | } | |
6264b550 | 2453 | } |
e9576ca5 SC |
2454 | } |
2455 | ||
e766c8a9 | 2456 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 2457 | { |
6264b550 RR |
2458 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) |
2459 | { | |
2460 | wxScrollWinEvent wevent; | |
2461 | wevent.SetPosition(event.GetPosition()); | |
2462 | wevent.SetOrientation(event.GetOrientation()); | |
2463 | wevent.m_eventObject = this; | |
6ed71b4f VZ |
2464 | |
2465 | if (event.m_eventType == wxEVT_SCROLL_TOP) | |
6264b550 | 2466 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; |
6ed71b4f VZ |
2467 | else if (event.m_eventType == wxEVT_SCROLL_BOTTOM) |
2468 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
2469 | else if (event.m_eventType == wxEVT_SCROLL_LINEUP) | |
2470 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
2471 | else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) | |
2472 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
2473 | else if (event.m_eventType == wxEVT_SCROLL_PAGEUP) | |
2474 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
2475 | else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) | |
2476 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
2477 | else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) | |
2478 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
2479 | else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE) | |
2480 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE; | |
2481 | ||
2482 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
2483 | } |
2484 | } | |
2485 | ||
e9576ca5 | 2486 | // Get the window with the focus |
e766c8a9 | 2487 | wxWindowMac *wxWindowBase::FindFocus() |
e9576ca5 | 2488 | { |
f1d527c1 SC |
2489 | ControlRef control ; |
2490 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2491 | return wxFindControlFromMacControl( control ) ; | |
519cb848 SC |
2492 | } |
2493 | ||
e766c8a9 | 2494 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
2495 | { |
2496 | // panel wants to track the window which was the last to have focus in it, | |
2497 | // so we want to set ourselves as the window which last had focus | |
2498 | // | |
2499 | // notice that it's also important to do it upwards the tree becaus | |
2500 | // otherwise when the top level panel gets focus, it won't set it back to | |
2501 | // us, but to some other sibling | |
6ed71b4f | 2502 | |
c1fb8167 SC |
2503 | // CS:don't know if this is still needed: |
2504 | //wxChildFocusEvent eventFocus(this); | |
2505 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b | 2506 | |
5ca0d812 SC |
2507 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) |
2508 | { | |
788e118f | 2509 | wxMacWindowStateSaver sv( this ) ; |
5ca0d812 SC |
2510 | |
2511 | int w , h ; | |
788e118f SC |
2512 | int x , y ; |
2513 | x = y = 0 ; | |
2514 | MacWindowToRootWindow( &x , &y ) ; | |
5ca0d812 | 2515 | GetSize( &w , &h ) ; |
788e118f | 2516 | Rect rect = {y , x , h + y , w + x } ; |
5ca0d812 SC |
2517 | |
2518 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
2519 | DrawThemeFocusRect( &rect , true ) ; | |
2520 | else | |
af6b7b80 | 2521 | { |
5ca0d812 | 2522 | DrawThemeFocusRect( &rect , false ) ; |
101634b2 | 2523 | |
af6b7b80 | 2524 | // as this erases part of the frame we have to redraw borders |
101634b2 SC |
2525 | // and because our z-ordering is not always correct (staticboxes) |
2526 | // we have to invalidate things, we cannot simple redraw | |
2527 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
2528 | RectRgn( updateInner , &rect ) ; | |
2529 | InsetRect( &rect , -4 , -4 ) ; | |
2530 | RectRgn( updateOuter , &rect ) ; | |
2531 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
2532 | wxPoint parent(0,0); | |
2533 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; | |
2534 | parent -= GetParent()->GetClientAreaOrigin() ; | |
2535 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
2536 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
2537 | DisposeRgn(updateOuter) ; | |
2538 | DisposeRgn(updateInner) ; | |
af6b7b80 | 2539 | } |
5ca0d812 SC |
2540 | } |
2541 | ||
7810c95b SC |
2542 | event.Skip(); |
2543 | } | |
2544 | ||
e39af974 | 2545 | void wxWindowMac::OnInternalIdle() |
e9576ca5 | 2546 | { |
e9576ca5 SC |
2547 | // This calls the UI-update mechanism (querying windows for |
2548 | // menu/toolbar/control state information) | |
e39af974 JS |
2549 | if (wxUpdateUIEvent::CanUpdate(this)) |
2550 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
e9576ca5 SC |
2551 | } |
2552 | ||
2553 | // Raise the window to the top of the Z order | |
e766c8a9 | 2554 | void wxWindowMac::Raise() |
e9576ca5 | 2555 | { |
5ca0d812 | 2556 | m_peer->SetZOrder( true , NULL ) ; |
e9576ca5 SC |
2557 | } |
2558 | ||
2559 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 2560 | void wxWindowMac::Lower() |
e9576ca5 | 2561 | { |
5ca0d812 | 2562 | m_peer->SetZOrder( false , NULL ) ; |
e9576ca5 SC |
2563 | } |
2564 | ||
6ed71b4f | 2565 | |
facd6764 | 2566 | // static wxWindow *gs_lastWhich = NULL; |
519cb848 | 2567 | |
7de59551 | 2568 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) |
467e3168 SC |
2569 | { |
2570 | // first trigger a set cursor event | |
6ed71b4f | 2571 | |
467e3168 SC |
2572 | wxPoint clientorigin = GetClientAreaOrigin() ; |
2573 | wxSize clientsize = GetClientSize() ; | |
2574 | wxCursor cursor ; | |
2575 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
7de59551 | 2576 | { |
467e3168 | 2577 | wxSetCursorEvent event( pt.x , pt.y ); |
6ed71b4f | 2578 | |
467e3168 SC |
2579 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); |
2580 | if ( processedEvtSetCursor && event.HasCursor() ) | |
2581 | { | |
e40298d5 | 2582 | cursor = event.GetCursor() ; |
467e3168 SC |
2583 | } |
2584 | else | |
2585 | { | |
6ed71b4f | 2586 | |
467e3168 SC |
2587 | // the test for processedEvtSetCursor is here to prevent using m_cursor |
2588 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
2589 | // it - this is a way to say that our cursor shouldn't be used for this | |
2590 | // point | |
2591 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
2592 | { | |
2593 | cursor = m_cursor ; | |
2594 | } | |
2595 | if ( wxIsBusy() ) | |
2596 | { | |
2597 | } | |
2598 | else | |
2599 | { | |
2600 | if ( !GetParent() ) | |
2601 | cursor = *wxSTANDARD_CURSOR ; | |
2602 | } | |
2603 | } | |
2604 | if ( cursor.Ok() ) | |
2605 | cursor.MacInstall() ; | |
2606 | } | |
2607 | return cursor.Ok() ; | |
2608 | } | |
2609 | ||
e766c8a9 | 2610 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 2611 | { |
6264b550 RR |
2612 | if ( m_tooltip ) |
2613 | { | |
2614 | return m_tooltip->GetTip() ; | |
2615 | } | |
427ff662 | 2616 | return wxEmptyString ; |
2f1ae414 | 2617 | } |
6264b550 | 2618 | |
1c310985 | 2619 | void wxWindowMac::Update() |
519cb848 | 2620 | { |
facd6764 | 2621 | #if TARGET_API_MAC_OSX |
430e1eed SC |
2622 | WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ; |
2623 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
2624 | // for composited windows this also triggers a redraw of all | |
2625 | // invalid views in the window | |
2626 | if( UMAGetSystemVersion() >= 0x1030 ) | |
2627 | HIWindowFlush(window) ; | |
2628 | else | |
2629 | #endif | |
2630 | { | |
2631 | // the only way to trigger the redrawing on earlier systems is to call | |
2632 | // ReceiveNextEvent | |
2633 | ||
2634 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
2635 | UInt32 currentEventClass = 0 ; | |
2636 | UInt32 currentEventKind = 0 ; | |
2637 | if ( currentEvent != NULL ) | |
2638 | { | |
2639 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
2640 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
2641 | } | |
2642 | if ( currentEventClass != kEventClassMenu ) | |
2643 | { | |
2644 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
2645 | ||
2646 | EventRef theEvent; | |
2647 | OSStatus status = noErr ; | |
2648 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
2649 | } | |
3e444781 | 2650 | else |
5ca0d812 | 2651 | m_peer->SetNeedsDisplay( true ) ; |
430e1eed | 2652 | } |
facd6764 | 2653 | #else |
5ca0d812 | 2654 | ::Draw1Control( m_peer->GetControlRef() ) ; |
bec721ec | 2655 | #endif |
519cb848 SC |
2656 | } |
2657 | ||
14c9cbdb | 2658 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const |
519cb848 | 2659 | { |
1c310985 | 2660 | wxTopLevelWindowMac* win = NULL ; |
facd6764 | 2661 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1c310985 | 2662 | if ( window ) |
6264b550 | 2663 | { |
1c310985 | 2664 | win = wxFindWinFromMacWindow( window ) ; |
14c9cbdb | 2665 | } |
1c310985 | 2666 | return win ; |
519cb848 | 2667 | } |
facd6764 | 2668 | wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) |
94abc21f | 2669 | { |
0fa8508d SC |
2670 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. |
2671 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
2672 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
2673 | // to add focus borders everywhere | |
2674 | ||
facd6764 | 2675 | Rect r ; |
e40298d5 JS |
2676 | RgnHandle visRgn = NewRgn() ; |
2677 | RgnHandle tempRgn = NewRgn() ; | |
5ca0d812 | 2678 | if ( m_peer->IsVisible()) |
e40298d5 | 2679 | { |
5ca0d812 SC |
2680 | m_peer->GetRect( &r ) ; |
2681 | r.left -= MacGetLeftBorderSize() ; | |
2682 | r.top -= MacGetTopBorderSize() ; | |
2683 | r.bottom += MacGetBottomBorderSize() ; | |
2684 | r.right += MacGetRightBorderSize() ; | |
2685 | ||
facd6764 | 2686 | if (! MacGetTopLevelWindow()->MacUsesCompositing() ) |
21f9e953 | 2687 | { |
facd6764 SC |
2688 | MacRootWindowToWindow( &r.left , & r.top ) ; |
2689 | MacRootWindowToWindow( &r.right , & r.bottom ) ; | |
21f9e953 | 2690 | } |
facd6764 SC |
2691 | else |
2692 | { | |
2693 | r.right -= r.left ; | |
2694 | r.bottom -= r.top ; | |
2695 | r.left = 0 ; | |
2696 | r.top = 0 ; | |
2697 | } | |
2698 | if ( includeOuterStructures ) | |
af6b7b80 | 2699 | InsetRect( &r , -4 , -4 ) ; |
facd6764 | 2700 | RectRgn( visRgn , &r ) ; |
db7a550b | 2701 | |
21f9e953 | 2702 | if ( !IsTopLevel() ) |
94abc21f | 2703 | { |
facd6764 SC |
2704 | wxWindow* child = this ; |
2705 | wxWindow* parent = child->GetParent() ; | |
21f9e953 SC |
2706 | while( parent ) |
2707 | { | |
21f9e953 | 2708 | int x , y ; |
facd6764 | 2709 | wxSize size ; |
d3e780ec SC |
2710 | // we have to find a better clipping algorithm here, in order not to clip things |
2711 | // positioned like status and toolbar | |
2712 | if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ ) | |
facd6764 SC |
2713 | { |
2714 | size = parent->GetSize() ; | |
2715 | x = y = 0 ; | |
2716 | } | |
2717 | else | |
2718 | { | |
2719 | size = parent->GetClientSize() ; | |
2720 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
2721 | x = origin.x ; | |
2722 | y = origin.y ; | |
2723 | } | |
21f9e953 SC |
2724 | parent->MacWindowToRootWindow( &x, &y ) ; |
2725 | MacRootWindowToWindow( &x , &y ) ; | |
2726 | ||
0fa8508d SC |
2727 | if ( !includeOuterStructures || ( |
2728 | parent->IsKindOf( CLASSINFO( wxScrolledWindow ) ) || | |
2729 | parent->IsKindOf( CLASSINFO( wxSashLayoutWindow ) ) || | |
2730 | ( parent->GetParent() && parent->GetParent()->IsKindOf( CLASSINFO( wxSplitterWindow ) ) ) | |
2731 | ) ) | |
2732 | { | |
2733 | SetRectRgn( tempRgn , | |
2734 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
2735 | x + size.x - parent->MacGetRightBorderSize(), | |
2736 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
21f9e953 | 2737 | |
0fa8508d SC |
2738 | SectRgn( visRgn , tempRgn , visRgn ) ; |
2739 | } | |
21f9e953 SC |
2740 | if ( parent->IsTopLevel() ) |
2741 | break ; | |
facd6764 SC |
2742 | child = parent ; |
2743 | parent = child->GetParent() ; | |
7372fd0a | 2744 | } |
94abc21f | 2745 | } |
e40298d5 | 2746 | } |
facd6764 SC |
2747 | |
2748 | wxRegion vis = visRgn ; | |
e40298d5 JS |
2749 | DisposeRgn( visRgn ) ; |
2750 | DisposeRgn( tempRgn ) ; | |
facd6764 | 2751 | return vis ; |
94abc21f SC |
2752 | } |
2753 | ||
facd6764 SC |
2754 | /* |
2755 | This function must not change the updatergn ! | |
2756 | */ | |
2757 | bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) | |
519cb848 | 2758 | { |
76a5e5d2 | 2759 | RgnHandle updatergn = (RgnHandle) updatergnr ; |
facd6764 | 2760 | bool handled = false ; |
42ef83fa SC |
2761 | Rect updatebounds ; |
2762 | GetRegionBounds( updatergn , &updatebounds ) ; | |
eec462f8 | 2763 | // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ; |
42ef83fa | 2764 | if ( !EmptyRgn(updatergn) ) |
6264b550 | 2765 | { |
1c310985 SC |
2766 | RgnHandle newupdate = NewRgn() ; |
2767 | wxSize point = GetClientSize() ; | |
2768 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 | 2769 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; |
facd6764 | 2770 | SectRgn( newupdate , updatergn , newupdate ) ; |
42ef83fa | 2771 | |
eec462f8 SC |
2772 | // first send an erase event to the entire update area |
2773 | { | |
42ef83fa | 2774 | wxWindowDC dc(this); |
1a02aff9 | 2775 | dc.SetClippingRegion(wxRegion(updatergn)); |
42ef83fa SC |
2776 | wxEraseEvent eevent( GetId(), &dc ); |
2777 | eevent.SetEventObject( this ); | |
2778 | GetEventHandler()->ProcessEvent( eevent ); | |
eec462f8 | 2779 | } |
42ef83fa SC |
2780 | |
2781 | // calculate a client-origin version of the update rgn and set m_updateRegion to that | |
1c310985 SC |
2782 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; |
2783 | m_updateRegion = newupdate ; | |
facd6764 | 2784 | DisposeRgn( newupdate ) ; |
6ed71b4f | 2785 | |
1c310985 | 2786 | if ( !m_updateRegion.Empty() ) |
6264b550 | 2787 | { |
facd6764 | 2788 | // paint the window itself |
e40298d5 JS |
2789 | wxPaintEvent event; |
2790 | event.m_timeStamp = time ; | |
2791 | event.SetEventObject(this); | |
facd6764 | 2792 | handled = GetEventHandler()->ProcessEvent(event); |
af6b7b80 SC |
2793 | |
2794 | // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards | |
2795 | if ( !handled ) | |
2796 | { | |
2797 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) | |
2798 | { | |
2799 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
2800 | handled = true ; | |
2801 | } | |
2802 | } | |
2803 | ||
eec462f8 SC |
2804 | } |
2805 | ||
2806 | // now we cannot rely on having its borders drawn by a window itself, as it does not | |
2807 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
2808 | // this would also be the place to draw any custom backgrounds for native controls | |
2809 | // in Composited windowing | |
36d7f54e SC |
2810 | wxPoint clientOrigin = GetClientAreaOrigin() ; |
2811 | ||
eec462f8 SC |
2812 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
2813 | { | |
2814 | wxWindowMac *child = node->GetData(); | |
2815 | if (child == m_vScrollBar) continue; | |
2816 | if (child == m_hScrollBar) continue; | |
2817 | if (child->IsTopLevel()) continue; | |
2818 | if (!child->IsShown()) continue; | |
fe779e40 | 2819 | |
af6b7b80 SC |
2820 | int x,y; |
2821 | child->GetPosition( &x, &y ); | |
2822 | int w,h; | |
2823 | child->GetSize( &w, &h ); | |
2824 | Rect childRect = { y , x , y + h , x + w } ; | |
36d7f54e | 2825 | OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; |
eec462f8 SC |
2826 | if ( child->MacGetTopBorderSize() ) |
2827 | { | |
eec462f8 SC |
2828 | if ( RectInRgn( &childRect , updatergn ) ) |
2829 | { | |
2830 | // paint custom borders | |
2831 | wxNcPaintEvent eventNc( child->GetId() ); | |
2832 | eventNc.SetEventObject( child ); | |
af6b7b80 SC |
2833 | if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) |
2834 | { | |
2835 | wxWindowDC dc(this) ; | |
2836 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2837 | wxMacPortSetter helper(&dc) ; | |
36d7f54e | 2838 | child->MacPaintBorders( dc.m_macLocalOrigin.x + childRect.left , dc.m_macLocalOrigin.y + childRect.top) ; |
af6b7b80 | 2839 | } |
eec462f8 | 2840 | } |
af6b7b80 SC |
2841 | } |
2842 | if ( child->m_peer->NeedsFocusRect() && child->m_peer->HasFocus() ) | |
2843 | { | |
2844 | wxWindowDC dc(this) ; | |
2845 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2846 | wxMacPortSetter helper(&dc) ; | |
7ebf5540 SC |
2847 | Rect r = childRect ; |
2848 | OffsetRect( &r , dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y ) ; | |
2849 | DrawThemeFocusRect( &r , true ) ; | |
af6b7b80 | 2850 | } |
14c9cbdb | 2851 | } |
6264b550 | 2852 | } |
facd6764 SC |
2853 | return handled ; |
2854 | } | |
6ed71b4f | 2855 | |
facd6764 SC |
2856 | void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) |
2857 | { | |
2858 | RgnHandle updatergn = (RgnHandle) updatergnr ; | |
2859 | // updatergn is always already clipped to our boundaries | |
2860 | // if we are in compositing mode then it is in relative to the upper left of the control | |
2861 | // if we are in non-compositing, then it is relatvie to the uppder left of the content area | |
2862 | // of the toplevel window | |
2863 | // it is in window coordinates, not in client coordinates | |
6ed71b4f | 2864 | |
facd6764 SC |
2865 | // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates |
2866 | RgnHandle ownUpdateRgn = NewRgn() ; | |
2867 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
2868 | ||
2869 | if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) | |
2870 | { | |
2871 | Rect bounds; | |
5ca0d812 | 2872 | m_peer->GetRectInWindowCoords( &bounds ); |
facd6764 SC |
2873 | RgnHandle controlRgn = NewRgn(); |
2874 | RectRgn( controlRgn, &bounds ); | |
2875 | //KO: This sets the ownUpdateRgn to the area of this control that is inside | |
2876 | // the window update region | |
2877 | SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn ); | |
2878 | DisposeRgn( controlRgn ); | |
2879 | ||
2880 | //KO: convert ownUpdateRgn to local coordinates | |
2881 | OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top ); | |
6264b550 | 2882 | } |
facd6764 SC |
2883 | |
2884 | MacDoRedraw( ownUpdateRgn , time ) ; | |
2885 | DisposeRgn( ownUpdateRgn ) ; | |
6ed71b4f | 2886 | |
519cb848 SC |
2887 | } |
2888 | ||
facd6764 | 2889 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const |
519cb848 | 2890 | { |
6264b550 | 2891 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 2892 | |
6264b550 RR |
2893 | while( iter ) |
2894 | { | |
1c310985 SC |
2895 | if ( iter->IsTopLevel() ) |
2896 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
519cb848 | 2897 | |
6264b550 | 2898 | iter = iter->GetParent() ; |
14c9cbdb | 2899 | } |
427ff662 | 2900 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; |
6264b550 | 2901 | return NULL ; |
519cb848 SC |
2902 | } |
2903 | ||
14c9cbdb | 2904 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 2905 | { |
427ff662 | 2906 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; |
14c9cbdb | 2907 | |
aa99e0cd SC |
2908 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) |
2909 | { | |
2910 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
db7a550b SC |
2911 | int scrlsize = MAC_SCROLLBAR_SIZE ; |
2912 | wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ; | |
2913 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
2914 | { | |
2915 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
2916 | variant = wxWINDOW_VARIANT_SMALL ; | |
2917 | } | |
2918 | ||
2919 | int adjust = hasBoth ? scrlsize - 1: 0 ; | |
aa99e0cd SC |
2920 | int width, height ; |
2921 | GetClientSize( &width , &height ) ; | |
2922 | ||
db7a550b SC |
2923 | wxPoint vPoint(width-scrlsize, 0) ; |
2924 | wxSize vSize(scrlsize, height - adjust) ; | |
2925 | wxPoint hPoint(0 , height-scrlsize ) ; | |
2926 | wxSize hSize( width - adjust, scrlsize) ; | |
aa99e0cd SC |
2927 | |
2928 | ||
2929 | if ( style & wxVSCROLL ) | |
2930 | { | |
2931 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
2932 | vSize , wxVERTICAL); | |
2933 | } | |
2934 | ||
2935 | if ( style & wxHSCROLL ) | |
2936 | { | |
2937 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
2938 | hSize , wxHORIZONTAL); | |
2939 | } | |
2940 | } | |
aa99e0cd | 2941 | |
14c9cbdb | 2942 | |
6264b550 RR |
2943 | // because the create does not take into account the client area origin |
2944 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
2945 | } |
2946 | ||
e766c8a9 | 2947 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 2948 | { |
aa99e0cd SC |
2949 | if ( !m_hScrollBar && !m_vScrollBar ) |
2950 | return ; | |
2951 | ||
6264b550 | 2952 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
db7a550b SC |
2953 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; |
2954 | int adjust = hasBoth ? scrlsize - 1 : 0 ; | |
14c9cbdb | 2955 | |
6264b550 | 2956 | // get real client area |
14c9cbdb | 2957 | |
facd6764 SC |
2958 | int width ; |
2959 | int height ; | |
2960 | GetSize( &width , &height ) ; | |
6264b550 RR |
2961 | |
2962 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2963 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
14c9cbdb | 2964 | |
6264b550 RR |
2965 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; |
2966 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2967 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2968 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
db7a550b | 2969 | /* |
14c9cbdb | 2970 | int x = 0 ; |
6264b550 | 2971 | int y = 0 ; |
facd6764 SC |
2972 | int w ; |
2973 | int h ; | |
2974 | GetSize( &w , &h ) ; | |
14c9cbdb | 2975 | |
6264b550 RR |
2976 | MacClientToRootWindow( &x , &y ) ; |
2977 | MacClientToRootWindow( &w , &h ) ; | |
14c9cbdb | 2978 | |
6264b550 | 2979 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 2980 | |
6264b550 RR |
2981 | int totW = 10000 , totH = 10000; |
2982 | while( iter ) | |
2983 | { | |
1c310985 | 2984 | if ( iter->IsTopLevel() ) |
6264b550 | 2985 | { |
facd6764 | 2986 | iter->GetSize( &totW , &totH ) ; |
6264b550 RR |
2987 | break ; |
2988 | } | |
2989 | ||
2990 | iter = iter->GetParent() ; | |
14c9cbdb RD |
2991 | } |
2992 | ||
6264b550 RR |
2993 | if ( x == 0 ) |
2994 | { | |
2995 | hPoint.x = -1 ; | |
2996 | hSize.x += 1 ; | |
2997 | } | |
2998 | if ( y == 0 ) | |
2999 | { | |
3000 | vPoint.y = -1 ; | |
3001 | vSize.y += 1 ; | |
3002 | } | |
14c9cbdb | 3003 | |
6264b550 RR |
3004 | if ( w-x >= totW ) |
3005 | { | |
3006 | hSize.x += 1 ; | |
3007 | vPoint.x += 1 ; | |
3008 | } | |
14c9cbdb | 3009 | |
6264b550 RR |
3010 | if ( h-y >= totH ) |
3011 | { | |
3012 | vSize.y += 1 ; | |
3013 | hPoint.y += 1 ; | |
3014 | } | |
db7a550b | 3015 | */ |
6264b550 RR |
3016 | if ( m_vScrollBar ) |
3017 | { | |
3018 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
3019 | } | |
3020 | if ( m_hScrollBar ) | |
3021 | { | |
3022 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
3023 | } | |
519cb848 SC |
3024 | } |
3025 | ||
e766c8a9 | 3026 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
3027 | { |
3028 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
3029 | } | |
519cb848 | 3030 | |
14c9cbdb | 3031 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 3032 | { |
6264b550 | 3033 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 3034 | |
eb22f2a6 | 3035 | wxWindowListNode *node = GetChildren().GetFirst(); |
6264b550 RR |
3036 | while ( node ) |
3037 | { | |
9bd1404d | 3038 | wxWindowMac *child = node->GetData(); |
6264b550 | 3039 | child->MacSuperChangedPosition() ; |
eb22f2a6 | 3040 | node = node->GetNext(); |
6264b550 | 3041 | } |
519cb848 | 3042 | } |
519cb848 | 3043 | |
14c9cbdb | 3044 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
a3bf4a62 | 3045 | { |
6264b550 | 3046 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 3047 | |
eb22f2a6 | 3048 | wxWindowListNode *node = GetChildren().GetFirst(); |
6264b550 RR |
3049 | while ( node ) |
3050 | { | |
9bd1404d | 3051 | wxWindowMac *child = node->GetData(); |
6264b550 | 3052 | child->MacTopLevelWindowChangedPosition() ; |
eb22f2a6 | 3053 | node = node->GetNext(); |
6264b550 | 3054 | } |
a3bf4a62 | 3055 | } |
facd6764 | 3056 | |
e766c8a9 | 3057 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 3058 | { |
1c310985 | 3059 | if( IsTopLevel() ) |
6264b550 | 3060 | return 0 ; |
2f1ae414 SC |
3061 | |
3062 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
3063 | { | |
ed60b502 | 3064 | SInt32 border = 3 ; |
ed60b502 | 3065 | return border ; |
2f1ae414 SC |
3066 | } |
3067 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
3068 | { | |
ed60b502 | 3069 | SInt32 border = 3 ; |
ed60b502 | 3070 | return border ; |
2f1ae414 SC |
3071 | } |
3072 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
3073 | { | |
6264b550 | 3074 | return 1 ; |
2f1ae414 | 3075 | } |
6264b550 | 3076 | return 0 ; |
2f1ae414 SC |
3077 | } |
3078 | ||
e766c8a9 | 3079 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 3080 | { |
1c310985 SC |
3081 | // they are all symmetric in mac themes |
3082 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3083 | } |
3084 | ||
e766c8a9 | 3085 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 3086 | { |
1c310985 SC |
3087 | // they are all symmetric in mac themes |
3088 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3089 | } |
3090 | ||
e766c8a9 | 3091 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 3092 | { |
1c310985 SC |
3093 | // they are all symmetric in mac themes |
3094 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3095 | } |
3096 | ||
14c9cbdb | 3097 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 3098 | { |
055a486b | 3099 | return style & ~wxBORDER_MASK ; |
2f1ae414 | 3100 | } |
0a67a93b | 3101 | |
e766c8a9 | 3102 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 3103 | // position. |
e766c8a9 | 3104 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 3105 | { |
59a12e90 | 3106 | pt = wxGetMousePosition(); |
e766c8a9 | 3107 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 3108 | return found; |
3723b7b1 JS |
3109 | } |
3110 | ||
3111 | // Get the current mouse position. | |
3112 | wxPoint wxGetMousePosition() | |
3113 | { | |
57591e0e JS |
3114 | int x, y; |
3115 | wxGetMousePosition(& x, & y); | |
3116 | return wxPoint(x, y); | |
3723b7b1 JS |
3117 | } |
3118 | ||
6ed71b4f | 3119 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) |
8950f7cc SC |
3120 | { |
3121 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
3122 | { | |
3123 | // copied from wxGTK : CS | |
249aad30 | 3124 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN |
8950f7cc SC |
3125 | // except that: |
3126 | // | |
3127 | // (a) it's a command event and so is propagated to the parent | |
3128 | // (b) under MSW it can be generated from kbd too | |
3129 | // (c) it uses screen coords (because of (a)) | |
3130 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
3131 | this->GetId(), | |
3132 | this->ClientToScreen(event.GetPosition())); | |
249aad30 SC |
3133 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) |
3134 | event.Skip() ; | |
8950f7cc | 3135 | } |
facd6764 SC |
3136 | else |
3137 | { | |
3138 | event.Skip() ; | |
3139 | } | |
8950f7cc SC |
3140 | } |
3141 | ||
facd6764 SC |
3142 | void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) |
3143 | { | |
facd6764 SC |
3144 | } |
3145 | ||
79392158 | 3146 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) |
3083eb85 SC |
3147 | { |
3148 | int x ,y , w ,h ; | |
3149 | ||
79392158 | 3150 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ; |
3083eb85 SC |
3151 | Rect bounds = { y , x , y+h , x+w }; |
3152 | return bounds ; | |
3153 | } | |
3154 | ||
f1d527c1 SC |
3155 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
3156 | { | |
3157 | return eventNotHandledErr ; | |
3158 | } | |
3159 | ||
facd6764 | 3160 |