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