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