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