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