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