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