]>
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 | 2255 | } |
d1fabc12 SC |
2256 | else if ( m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) |
2257 | { | |
2258 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) | |
2259 | { | |
2260 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
2261 | } | |
2262 | } | |
94abc21f | 2263 | else |
be346c26 | 2264 | #endif |
7ebf5540 | 2265 | { |
8b573fb8 | 2266 | event.GetDC()->Clear() ; |
7ebf5540 | 2267 | } |
1c310985 SC |
2268 | } |
2269 | ||
2270 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
2271 | { | |
af6b7b80 | 2272 | event.Skip() ; |
e9576ca5 SC |
2273 | } |
2274 | ||
e766c8a9 | 2275 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 2276 | { |
1c310985 SC |
2277 | if ( orient == wxHORIZONTAL ) |
2278 | { | |
2279 | if ( m_hScrollBar ) | |
2280 | return m_hScrollBar->GetThumbPosition() ; | |
2281 | } | |
2282 | else | |
2283 | { | |
2284 | if ( m_vScrollBar ) | |
2285 | return m_vScrollBar->GetThumbPosition() ; | |
2286 | } | |
e9576ca5 SC |
2287 | return 0; |
2288 | } | |
2289 | ||
2290 | // This now returns the whole range, not just the number | |
2291 | // of positions that we can scroll. | |
e766c8a9 | 2292 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 2293 | { |
1c310985 SC |
2294 | if ( orient == wxHORIZONTAL ) |
2295 | { | |
2296 | if ( m_hScrollBar ) | |
2297 | return m_hScrollBar->GetRange() ; | |
2298 | } | |
2299 | else | |
2300 | { | |
2301 | if ( m_vScrollBar ) | |
2302 | return m_vScrollBar->GetRange() ; | |
2303 | } | |
e9576ca5 SC |
2304 | return 0; |
2305 | } | |
2306 | ||
e766c8a9 | 2307 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 2308 | { |
1c310985 SC |
2309 | if ( orient == wxHORIZONTAL ) |
2310 | { | |
2311 | if ( m_hScrollBar ) | |
2312 | return m_hScrollBar->GetThumbSize() ; | |
2313 | } | |
2314 | else | |
2315 | { | |
2316 | if ( m_vScrollBar ) | |
2317 | return m_vScrollBar->GetThumbSize() ; | |
2318 | } | |
e9576ca5 SC |
2319 | return 0; |
2320 | } | |
2321 | ||
e766c8a9 | 2322 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 2323 | { |
1c310985 | 2324 | if ( orient == wxHORIZONTAL ) |
6264b550 | 2325 | { |
1c310985 SC |
2326 | if ( m_hScrollBar ) |
2327 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
2328 | } |
2329 | else | |
2330 | { | |
1c310985 SC |
2331 | if ( m_vScrollBar ) |
2332 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 2333 | } |
2f1ae414 SC |
2334 | } |
2335 | ||
14c9cbdb | 2336 | void wxWindowMac::MacPaintBorders( int left , int top ) |
2f1ae414 | 2337 | { |
1c310985 | 2338 | if( IsTopLevel() ) |
6264b550 | 2339 | return ; |
8b573fb8 | 2340 | |
fd926bcc | 2341 | Rect rect ; |
8b573fb8 | 2342 | m_peer->GetRect( &rect ) ; |
fd926bcc SC |
2343 | InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; |
2344 | ||
2345 | if ( !IsTopLevel() ) | |
2346 | { | |
2347 | wxTopLevelWindowMac* top = MacGetTopLevelWindow(); | |
2348 | if (top) | |
2349 | { | |
2350 | wxPoint pt(0,0) ; | |
2351 | wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; | |
2352 | rect.left += pt.x ; | |
2353 | rect.right += pt.x ; | |
2354 | rect.top += pt.y ; | |
2355 | rect.bottom += pt.y ; | |
2356 | } | |
2357 | } | |
8b573fb8 | 2358 | |
2f1ae414 SC |
2359 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) |
2360 | { | |
af6b7b80 | 2361 | Rect srect = rect ; |
11d1adbf | 2362 | SInt32 border = 0 ; |
5ca0d812 | 2363 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; |
af6b7b80 SC |
2364 | InsetRect( &srect , border , border ); |
2365 | DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
8208e181 SC |
2366 | } |
2367 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2368 | { | |
af6b7b80 | 2369 | Rect srect = rect ; |
1a02aff9 SC |
2370 | SInt32 border = 0 ; |
2371 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
af6b7b80 | 2372 | InsetRect( &srect , border , border ); |
8b573fb8 | 2373 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
eec462f8 | 2374 | } |
8208e181 SC |
2375 | } |
2376 | ||
abda5788 SC |
2377 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
2378 | { | |
2379 | if ( child == m_hScrollBar ) | |
2380 | m_hScrollBar = NULL ; | |
2381 | if ( child == m_vScrollBar ) | |
2382 | m_vScrollBar = NULL ; | |
14c9cbdb | 2383 | |
abda5788 SC |
2384 | wxWindowBase::RemoveChild( child ) ; |
2385 | } | |
2386 | ||
e9576ca5 | 2387 | // New function that will replace some of the above. |
e766c8a9 | 2388 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
2389 | int range, bool refresh) |
2390 | { | |
e40298d5 JS |
2391 | if ( orient == wxHORIZONTAL ) |
2392 | { | |
2393 | if ( m_hScrollBar ) | |
6264b550 | 2394 | { |
e40298d5 | 2395 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2396 | { |
e40298d5 JS |
2397 | if ( m_hScrollBar->IsShown() ) |
2398 | m_hScrollBar->Show(false) ; | |
2399 | } | |
2400 | else | |
2401 | { | |
2402 | if ( !m_hScrollBar->IsShown() ) | |
2403 | m_hScrollBar->Show(true) ; | |
6264b550 | 2404 | } |
11ca2edf | 2405 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2406 | } |
e40298d5 JS |
2407 | } |
2408 | else | |
2409 | { | |
2410 | if ( m_vScrollBar ) | |
6264b550 | 2411 | { |
e40298d5 | 2412 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 2413 | { |
e40298d5 JS |
2414 | if ( m_vScrollBar->IsShown() ) |
2415 | m_vScrollBar->Show(false) ; | |
2416 | } | |
2417 | else | |
2418 | { | |
2419 | if ( !m_vScrollBar->IsShown() ) | |
2420 | m_vScrollBar->Show(true) ; | |
6264b550 | 2421 | } |
11ca2edf | 2422 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; |
6264b550 | 2423 | } |
e40298d5 JS |
2424 | } |
2425 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
2426 | } |
2427 | ||
2428 | // Does a physical scroll | |
e766c8a9 | 2429 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 2430 | { |
ba87f54c SC |
2431 | if( dx == 0 && dy ==0 ) |
2432 | return ; | |
8b573fb8 | 2433 | |
6ed71b4f | 2434 | |
6264b550 | 2435 | { |
adb8a71b | 2436 | |
6264b550 RR |
2437 | int width , height ; |
2438 | GetClientSize( &width , &height ) ; | |
adb8a71b | 2439 | #if TARGET_API_MAC_OSX |
002c9672 | 2440 | // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control |
8b573fb8 | 2441 | // area is scrolled, this does not occur if width and height are 2 pixels less, |
002c9672 | 2442 | // TODO write optimal workaround |
42ef83fa | 2443 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; |
8b573fb8 | 2444 | if ( rect ) |
adb8a71b | 2445 | { |
5ca0d812 | 2446 | scrollrect.Intersect( *rect ) ; |
adb8a71b | 2447 | } |
5ca0d812 | 2448 | if ( m_peer->GetNeedsDisplay() ) |
002c9672 SC |
2449 | { |
2450 | // becuase HIViewScrollRect does not scroll the already invalidated area we have two options | |
2451 | // either immediate redraw or full invalidate | |
2452 | #if 1 | |
2453 | // is the better overall solution, as it does not slow down scrolling | |
5ca0d812 | 2454 | m_peer->SetNeedsDisplay( true ) ; |
002c9672 | 2455 | #else |
8b573fb8 | 2456 | // this would be the preferred version for fast drawing controls |
002c9672 SC |
2457 | if( UMAGetSystemVersion() < 0x1030 ) |
2458 | Update() ; | |
2459 | else | |
42ef83fa | 2460 | HIViewRender(m_peer->GetControlRef()) ; |
002c9672 SC |
2461 | #endif |
2462 | } | |
84e5d27d SC |
2463 | // as the native control might be not a 0/0 wx window coordinates, we have to offset |
2464 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
5ca0d812 | 2465 | m_peer->ScrollRect( scrollrect , dx , dy ) ; |
adb8a71b | 2466 | #else |
6ed71b4f | 2467 | |
facd6764 | 2468 | wxPoint pos; |
8b573fb8 | 2469 | pos.x = pos.y = 0; |
430e1eed | 2470 | |
facd6764 | 2471 | Rect scrollrect; |
6264b550 | 2472 | RgnHandle updateRgn = NewRgn() ; |
430e1eed | 2473 | |
adb8a71b | 2474 | { |
430e1eed SC |
2475 | wxClientDC dc(this) ; |
2476 | wxMacPortSetter helper(&dc) ; | |
8b573fb8 | 2477 | |
5ca0d812 | 2478 | m_peer->GetRect( &scrollrect ) ; |
430e1eed SC |
2479 | scrollrect.top += MacGetTopBorderSize() ; |
2480 | scrollrect.left += MacGetLeftBorderSize() ; | |
2481 | scrollrect.bottom = scrollrect.top + height ; | |
2482 | scrollrect.right = scrollrect.left + width ; | |
8b573fb8 | 2483 | |
430e1eed SC |
2484 | if ( rect ) |
2485 | { | |
2486 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
2487 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
2488 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
2489 | } | |
2490 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
20b69855 SC |
2491 | |
2492 | // now scroll the former update region as well and add the new update region | |
2493 | ||
2494 | WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ; | |
2495 | RgnHandle formerUpdateRgn = NewRgn() ; | |
2496 | RgnHandle scrollRgn = NewRgn() ; | |
2497 | RectRgn( scrollRgn , &scrollrect ) ; | |
2498 | GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; | |
2499 | Point pt = {0,0} ; | |
2500 | LocalToGlobal( &pt ) ; | |
2501 | OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; | |
2502 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2503 | if ( !EmptyRgn( formerUpdateRgn ) ) | |
2504 | { | |
2505 | MacOffsetRgn( formerUpdateRgn , dx , dy ) ; | |
2506 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
2507 | InvalWindowRgn(rootWindow , formerUpdateRgn ) ; | |
2508 | } | |
2509 | InvalWindowRgn(rootWindow , updateRgn ) ; | |
2510 | DisposeRgn( updateRgn ) ; | |
2511 | DisposeRgn( formerUpdateRgn ) ; | |
2512 | DisposeRgn( scrollRgn ) ; | |
ba87f54c | 2513 | } |
facd6764 | 2514 | #endif |
6264b550 | 2515 | } |
6ed71b4f | 2516 | |
71f2fb52 | 2517 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 2518 | { |
9bd1404d | 2519 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
2520 | if (child == m_vScrollBar) continue; |
2521 | if (child == m_hScrollBar) continue; | |
2522 | if (child->IsTopLevel()) continue; | |
6ed71b4f | 2523 | |
6264b550 RR |
2524 | int x,y; |
2525 | child->GetPosition( &x, &y ); | |
2526 | int w,h; | |
2527 | child->GetSize( &w, &h ); | |
00f55394 SC |
2528 | if (rect) |
2529 | { | |
2530 | wxRect rc(x,y,w,h); | |
2531 | if (rect->Intersects(rc)) | |
2532 | child->SetSize( x+dx, y+dy, w, h ); | |
2533 | } | |
2534 | else | |
2535 | { | |
8b573fb8 VZ |
2536 | child->SetSize( x+dx, y+dy, w, h ); |
2537 | } | |
6264b550 | 2538 | } |
e9576ca5 SC |
2539 | } |
2540 | ||
e766c8a9 | 2541 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 2542 | { |
687706f5 | 2543 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) |
6264b550 RR |
2544 | { |
2545 | wxScrollWinEvent wevent; | |
2546 | wevent.SetPosition(event.GetPosition()); | |
2547 | wevent.SetOrientation(event.GetOrientation()); | |
687706f5 KH |
2548 | wevent.SetEventObject(this); |
2549 | ||
2550 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
2551 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
2552 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
2553 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
2554 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
2555 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
2556 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
2557 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
2558 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
2559 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
2560 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
2561 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
2562 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
2563 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
2564 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
2565 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
6ed71b4f VZ |
2566 | |
2567 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
2568 | } |
2569 | } | |
2570 | ||
e9576ca5 | 2571 | // Get the window with the focus |
0fe02759 | 2572 | wxWindowMac *wxWindowBase::DoFindFocus() |
e9576ca5 | 2573 | { |
f1d527c1 SC |
2574 | ControlRef control ; |
2575 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
2576 | return wxFindControlFromMacControl( control ) ; | |
519cb848 SC |
2577 | } |
2578 | ||
e766c8a9 | 2579 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
2580 | { |
2581 | // panel wants to track the window which was the last to have focus in it, | |
2582 | // so we want to set ourselves as the window which last had focus | |
2583 | // | |
2584 | // notice that it's also important to do it upwards the tree becaus | |
2585 | // otherwise when the top level panel gets focus, it won't set it back to | |
2586 | // us, but to some other sibling | |
6ed71b4f | 2587 | |
c1fb8167 SC |
2588 | // CS:don't know if this is still needed: |
2589 | //wxChildFocusEvent eventFocus(this); | |
2590 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b | 2591 | |
5ca0d812 SC |
2592 | if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) |
2593 | { | |
ff3795ee | 2594 | #if !wxMAC_USE_CORE_GRAPHICS |
788e118f | 2595 | wxMacWindowStateSaver sv( this ) ; |
5ca0d812 SC |
2596 | |
2597 | int w , h ; | |
788e118f SC |
2598 | int x , y ; |
2599 | x = y = 0 ; | |
2600 | MacWindowToRootWindow( &x , &y ) ; | |
5ca0d812 | 2601 | GetSize( &w , &h ) ; |
788e118f | 2602 | Rect rect = {y , x , h + y , w + x } ; |
5ca0d812 SC |
2603 | |
2604 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
2605 | DrawThemeFocusRect( &rect , true ) ; | |
2606 | else | |
af6b7b80 | 2607 | { |
5ca0d812 | 2608 | DrawThemeFocusRect( &rect , false ) ; |
8b573fb8 | 2609 | |
af6b7b80 | 2610 | // as this erases part of the frame we have to redraw borders |
101634b2 SC |
2611 | // and because our z-ordering is not always correct (staticboxes) |
2612 | // we have to invalidate things, we cannot simple redraw | |
2613 | RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ; | |
2614 | RectRgn( updateInner , &rect ) ; | |
2615 | InsetRect( &rect , -4 , -4 ) ; | |
2616 | RectRgn( updateOuter , &rect ) ; | |
2617 | DiffRgn( updateOuter , updateInner ,updateOuter ) ; | |
8b573fb8 | 2618 | wxPoint parent(0,0); |
101634b2 SC |
2619 | GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; |
2620 | parent -= GetParent()->GetClientAreaOrigin() ; | |
2621 | OffsetRgn( updateOuter , -parent.x , -parent.y ) ; | |
2622 | GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ; | |
2623 | DisposeRgn(updateOuter) ; | |
2624 | DisposeRgn(updateInner) ; | |
af6b7b80 | 2625 | } |
ff3795ee SC |
2626 | #else |
2627 | GetParent()->Refresh() ; | |
2628 | #endif | |
5ca0d812 SC |
2629 | } |
2630 | ||
7810c95b SC |
2631 | event.Skip(); |
2632 | } | |
2633 | ||
e39af974 | 2634 | void wxWindowMac::OnInternalIdle() |
e9576ca5 | 2635 | { |
e9576ca5 SC |
2636 | // This calls the UI-update mechanism (querying windows for |
2637 | // menu/toolbar/control state information) | |
e39af974 JS |
2638 | if (wxUpdateUIEvent::CanUpdate(this)) |
2639 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
e9576ca5 SC |
2640 | } |
2641 | ||
2642 | // Raise the window to the top of the Z order | |
e766c8a9 | 2643 | void wxWindowMac::Raise() |
e9576ca5 | 2644 | { |
5ca0d812 | 2645 | m_peer->SetZOrder( true , NULL ) ; |
e9576ca5 SC |
2646 | } |
2647 | ||
2648 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 2649 | void wxWindowMac::Lower() |
e9576ca5 | 2650 | { |
5ca0d812 | 2651 | m_peer->SetZOrder( false , NULL ) ; |
e9576ca5 SC |
2652 | } |
2653 | ||
6ed71b4f | 2654 | |
facd6764 | 2655 | // static wxWindow *gs_lastWhich = NULL; |
519cb848 | 2656 | |
7de59551 | 2657 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) |
467e3168 SC |
2658 | { |
2659 | // first trigger a set cursor event | |
6ed71b4f | 2660 | |
467e3168 SC |
2661 | wxPoint clientorigin = GetClientAreaOrigin() ; |
2662 | wxSize clientsize = GetClientSize() ; | |
2663 | wxCursor cursor ; | |
2664 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
7de59551 | 2665 | { |
467e3168 | 2666 | wxSetCursorEvent event( pt.x , pt.y ); |
6ed71b4f | 2667 | |
467e3168 SC |
2668 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); |
2669 | if ( processedEvtSetCursor && event.HasCursor() ) | |
2670 | { | |
e40298d5 | 2671 | cursor = event.GetCursor() ; |
467e3168 SC |
2672 | } |
2673 | else | |
2674 | { | |
6ed71b4f | 2675 | |
467e3168 SC |
2676 | // the test for processedEvtSetCursor is here to prevent using m_cursor |
2677 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
2678 | // it - this is a way to say that our cursor shouldn't be used for this | |
2679 | // point | |
2680 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
2681 | { | |
2682 | cursor = m_cursor ; | |
2683 | } | |
2684 | if ( wxIsBusy() ) | |
2685 | { | |
2686 | } | |
2687 | else | |
2688 | { | |
2689 | if ( !GetParent() ) | |
2690 | cursor = *wxSTANDARD_CURSOR ; | |
2691 | } | |
2692 | } | |
2693 | if ( cursor.Ok() ) | |
2694 | cursor.MacInstall() ; | |
2695 | } | |
2696 | return cursor.Ok() ; | |
2697 | } | |
2698 | ||
e766c8a9 | 2699 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 2700 | { |
6264b550 RR |
2701 | if ( m_tooltip ) |
2702 | { | |
2703 | return m_tooltip->GetTip() ; | |
2704 | } | |
427ff662 | 2705 | return wxEmptyString ; |
2f1ae414 | 2706 | } |
6264b550 | 2707 | |
cb4b0966 SC |
2708 | void wxWindowMac::ClearBackground() |
2709 | { | |
2710 | Refresh() ; | |
2711 | Update() ; | |
2712 | } | |
2713 | ||
1c310985 | 2714 | void wxWindowMac::Update() |
519cb848 | 2715 | { |
facd6764 | 2716 | #if TARGET_API_MAC_OSX |
957f865c | 2717 | |
430e1eed | 2718 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
957f865c RN |
2719 | WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ; |
2720 | ||
430e1eed SC |
2721 | // for composited windows this also triggers a redraw of all |
2722 | // invalid views in the window | |
2723 | if( UMAGetSystemVersion() >= 0x1030 ) | |
8b573fb8 VZ |
2724 | HIWindowFlush(window) ; |
2725 | else | |
430e1eed SC |
2726 | #endif |
2727 | { | |
2728 | // the only way to trigger the redrawing on earlier systems is to call | |
2729 | // ReceiveNextEvent | |
2730 | ||
2731 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
2732 | UInt32 currentEventClass = 0 ; | |
2733 | UInt32 currentEventKind = 0 ; | |
2734 | if ( currentEvent != NULL ) | |
2735 | { | |
2736 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
2737 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
8b573fb8 | 2738 | } |
430e1eed SC |
2739 | if ( currentEventClass != kEventClassMenu ) |
2740 | { | |
2741 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
2742 | ||
2743 | EventRef theEvent; | |
2744 | OSStatus status = noErr ; | |
2745 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
2746 | } | |
3e444781 | 2747 | else |
5ca0d812 | 2748 | m_peer->SetNeedsDisplay( true ) ; |
430e1eed | 2749 | } |
facd6764 | 2750 | #else |
5ca0d812 | 2751 | ::Draw1Control( m_peer->GetControlRef() ) ; |
bec721ec | 2752 | #endif |
519cb848 SC |
2753 | } |
2754 | ||
14c9cbdb | 2755 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const |
519cb848 | 2756 | { |
1c310985 | 2757 | wxTopLevelWindowMac* win = NULL ; |
facd6764 | 2758 | WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; |
1c310985 | 2759 | if ( window ) |
6264b550 | 2760 | { |
1c310985 | 2761 | win = wxFindWinFromMacWindow( window ) ; |
14c9cbdb | 2762 | } |
1c310985 | 2763 | return win ; |
519cb848 | 2764 | } |
facd6764 | 2765 | wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) |
94abc21f | 2766 | { |
0fa8508d SC |
2767 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. |
2768 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
2769 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
2770 | // to add focus borders everywhere | |
8b573fb8 | 2771 | |
facd6764 | 2772 | Rect r ; |
e40298d5 JS |
2773 | RgnHandle visRgn = NewRgn() ; |
2774 | RgnHandle tempRgn = NewRgn() ; | |
66ffb23b | 2775 | if ( !m_isBeingDeleted && m_peer->IsVisible()) |
e40298d5 | 2776 | { |
5ca0d812 SC |
2777 | m_peer->GetRect( &r ) ; |
2778 | r.left -= MacGetLeftBorderSize() ; | |
2779 | r.top -= MacGetTopBorderSize() ; | |
2780 | r.bottom += MacGetBottomBorderSize() ; | |
2781 | r.right += MacGetRightBorderSize() ; | |
8b573fb8 | 2782 | |
facd6764 | 2783 | if (! MacGetTopLevelWindow()->MacUsesCompositing() ) |
21f9e953 | 2784 | { |
facd6764 SC |
2785 | MacRootWindowToWindow( &r.left , & r.top ) ; |
2786 | MacRootWindowToWindow( &r.right , & r.bottom ) ; | |
21f9e953 | 2787 | } |
facd6764 SC |
2788 | else |
2789 | { | |
2790 | r.right -= r.left ; | |
2791 | r.bottom -= r.top ; | |
2792 | r.left = 0 ; | |
2793 | r.top = 0 ; | |
2794 | } | |
2795 | if ( includeOuterStructures ) | |
af6b7b80 | 2796 | InsetRect( &r , -4 , -4 ) ; |
facd6764 | 2797 | RectRgn( visRgn , &r ) ; |
db7a550b | 2798 | |
21f9e953 | 2799 | if ( !IsTopLevel() ) |
94abc21f | 2800 | { |
facd6764 SC |
2801 | wxWindow* child = this ; |
2802 | wxWindow* parent = child->GetParent() ; | |
21f9e953 SC |
2803 | while( parent ) |
2804 | { | |
21f9e953 | 2805 | int x , y ; |
facd6764 | 2806 | wxSize size ; |
d3e780ec SC |
2807 | // we have to find a better clipping algorithm here, in order not to clip things |
2808 | // positioned like status and toolbar | |
2809 | if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ ) | |
facd6764 SC |
2810 | { |
2811 | size = parent->GetSize() ; | |
2812 | x = y = 0 ; | |
2813 | } | |
2814 | else | |
2815 | { | |
2816 | size = parent->GetClientSize() ; | |
2817 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
2818 | x = origin.x ; | |
2819 | y = origin.y ; | |
2820 | } | |
21f9e953 SC |
2821 | parent->MacWindowToRootWindow( &x, &y ) ; |
2822 | MacRootWindowToWindow( &x , &y ) ; | |
2823 | ||
0fa8508d | 2824 | if ( !includeOuterStructures || ( |
7f17ac74 SC |
2825 | parent->MacClipChildren() || |
2826 | ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) | |
0fa8508d SC |
2827 | ) ) |
2828 | { | |
2829 | SetRectRgn( tempRgn , | |
2830 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
2831 | x + size.x - parent->MacGetRightBorderSize(), | |
2832 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
21f9e953 | 2833 | |
0fa8508d SC |
2834 | SectRgn( visRgn , tempRgn , visRgn ) ; |
2835 | } | |
21f9e953 SC |
2836 | if ( parent->IsTopLevel() ) |
2837 | break ; | |
facd6764 SC |
2838 | child = parent ; |
2839 | parent = child->GetParent() ; | |
7372fd0a | 2840 | } |
94abc21f | 2841 | } |
e40298d5 | 2842 | } |
facd6764 SC |
2843 | |
2844 | wxRegion vis = visRgn ; | |
e40298d5 JS |
2845 | DisposeRgn( visRgn ) ; |
2846 | DisposeRgn( tempRgn ) ; | |
facd6764 | 2847 | return vis ; |
94abc21f SC |
2848 | } |
2849 | ||
facd6764 SC |
2850 | /* |
2851 | This function must not change the updatergn ! | |
2852 | */ | |
8b573fb8 | 2853 | bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) |
519cb848 | 2854 | { |
76a5e5d2 | 2855 | RgnHandle updatergn = (RgnHandle) updatergnr ; |
facd6764 | 2856 | bool handled = false ; |
42ef83fa SC |
2857 | Rect updatebounds ; |
2858 | GetRegionBounds( updatergn , &updatebounds ) ; | |
20b69855 | 2859 | |
eec462f8 | 2860 | // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ; |
42ef83fa | 2861 | if ( !EmptyRgn(updatergn) ) |
6264b550 | 2862 | { |
1c310985 SC |
2863 | RgnHandle newupdate = NewRgn() ; |
2864 | wxSize point = GetClientSize() ; | |
2865 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 | 2866 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; |
facd6764 | 2867 | SectRgn( newupdate , updatergn , newupdate ) ; |
8b573fb8 | 2868 | |
eec462f8 SC |
2869 | // first send an erase event to the entire update area |
2870 | { | |
42ef83fa | 2871 | wxWindowDC dc(this); |
1a02aff9 | 2872 | dc.SetClippingRegion(wxRegion(updatergn)); |
42ef83fa SC |
2873 | wxEraseEvent eevent( GetId(), &dc ); |
2874 | eevent.SetEventObject( this ); | |
2875 | GetEventHandler()->ProcessEvent( eevent ); | |
eec462f8 | 2876 | } |
8b573fb8 | 2877 | |
42ef83fa | 2878 | // calculate a client-origin version of the update rgn and set m_updateRegion to that |
1c310985 SC |
2879 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; |
2880 | m_updateRegion = newupdate ; | |
8b573fb8 | 2881 | DisposeRgn( newupdate ) ; |
6ed71b4f | 2882 | |
1c310985 | 2883 | if ( !m_updateRegion.Empty() ) |
6264b550 | 2884 | { |
facd6764 | 2885 | // paint the window itself |
ff3795ee | 2886 | |
e40298d5 | 2887 | wxPaintEvent event; |
687706f5 | 2888 | event.SetTimestamp(time); |
e40298d5 | 2889 | event.SetEventObject(this); |
ff3795ee SC |
2890 | GetEventHandler()->ProcessEvent(event); |
2891 | handled = true ; | |
eec462f8 | 2892 | } |
8b573fb8 | 2893 | |
eec462f8 SC |
2894 | // now we cannot rely on having its borders drawn by a window itself, as it does not |
2895 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
2896 | // this would also be the place to draw any custom backgrounds for native controls | |
2897 | // in Composited windowing | |
36d7f54e | 2898 | wxPoint clientOrigin = GetClientAreaOrigin() ; |
8b573fb8 | 2899 | |
71f2fb52 | 2900 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) |
eec462f8 SC |
2901 | { |
2902 | wxWindowMac *child = node->GetData(); | |
2903 | if (child == m_vScrollBar) continue; | |
2904 | if (child == m_hScrollBar) continue; | |
2905 | if (child->IsTopLevel()) continue; | |
2906 | if (!child->IsShown()) continue; | |
fe779e40 | 2907 | |
af6b7b80 SC |
2908 | int x,y; |
2909 | child->GetPosition( &x, &y ); | |
2910 | int w,h; | |
2911 | child->GetSize( &w, &h ); | |
2912 | Rect childRect = { y , x , y + h , x + w } ; | |
36d7f54e | 2913 | OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; |
eec462f8 SC |
2914 | if ( child->MacGetTopBorderSize() ) |
2915 | { | |
eec462f8 SC |
2916 | if ( RectInRgn( &childRect , updatergn ) ) |
2917 | { | |
20b69855 | 2918 | #if wxMAC_USE_CORE_GRAPHICS |
cb4b0966 SC |
2919 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
2920 | if ( HIThemeDrawFrame ) | |
2921 | { | |
2922 | Rect srect = childRect ; | |
2923 | HIThemeFrameDrawInfo info ; | |
2924 | info.version = 0 ; | |
2925 | info.kind = 0 ; | |
2926 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
2927 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
2928 | { | |
2929 | SInt32 border = 0 ; | |
2930 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2931 | InsetRect( &srect , border , border ); | |
2932 | info.kind = kHIThemeFrameTextFieldSquare ; | |
2933 | } | |
2934 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2935 | { | |
2936 | SInt32 border = 0 ; | |
2937 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2938 | InsetRect( &srect , border , border ); | |
2939 | info.kind = kHIThemeFrameListBox ; | |
2940 | } | |
2941 | ||
2942 | CGRect rect = CGRectMake( srect.left , srect.top , srect.right - srect.left , | |
2943 | srect.bottom - srect.top ) ; | |
2944 | HIThemeDrawFrame( &rect , &info , (CGContextRef) MacGetCGContextRef() , kHIThemeOrientationNormal ) ; | |
2945 | } | |
2946 | #endif | |
20b69855 | 2947 | #else |
eec462f8 SC |
2948 | // paint custom borders |
2949 | wxNcPaintEvent eventNc( child->GetId() ); | |
2950 | eventNc.SetEventObject( child ); | |
af6b7b80 SC |
2951 | if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) |
2952 | { | |
2953 | wxWindowDC dc(this) ; | |
2954 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2955 | wxMacPortSetter helper(&dc) ; | |
36d7f54e | 2956 | child->MacPaintBorders( dc.m_macLocalOrigin.x + childRect.left , dc.m_macLocalOrigin.y + childRect.top) ; |
af6b7b80 | 2957 | } |
20b69855 | 2958 | #endif |
eec462f8 | 2959 | } |
8b573fb8 | 2960 | } |
af6b7b80 SC |
2961 | if ( child->m_peer->NeedsFocusRect() && child->m_peer->HasFocus() ) |
2962 | { | |
20b69855 | 2963 | #if wxMAC_USE_CORE_GRAPHICS |
cb4b0966 SC |
2964 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
2965 | if ( HIThemeDrawFocusRect ) | |
2966 | { | |
2967 | CGRect rect = CGRectMake( childRect.left , childRect.top , childRect.right - childRect.left , | |
2968 | childRect.bottom - childRect.top ) ; | |
2969 | HIThemeDrawFocusRect( &rect , true , (CGContextRef) MacGetCGContextRef() , kHIThemeOrientationNormal ) ; | |
2970 | } | |
2971 | #endif | |
20b69855 | 2972 | #else |
af6b7b80 SC |
2973 | wxWindowDC dc(this) ; |
2974 | dc.SetClippingRegion(wxRegion(updatergn)); | |
2975 | wxMacPortSetter helper(&dc) ; | |
7ebf5540 SC |
2976 | Rect r = childRect ; |
2977 | OffsetRect( &r , dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y ) ; | |
2978 | DrawThemeFocusRect( &r , true ) ; | |
20b69855 | 2979 | #endif |
af6b7b80 | 2980 | } |
14c9cbdb | 2981 | } |
6264b550 | 2982 | } |
facd6764 SC |
2983 | return handled ; |
2984 | } | |
6ed71b4f | 2985 | |
519cb848 | 2986 | |
facd6764 | 2987 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const |
519cb848 | 2988 | { |
6264b550 | 2989 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 2990 | |
6264b550 RR |
2991 | while( iter ) |
2992 | { | |
1c310985 SC |
2993 | if ( iter->IsTopLevel() ) |
2994 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
519cb848 | 2995 | |
6264b550 | 2996 | iter = iter->GetParent() ; |
14c9cbdb | 2997 | } |
427ff662 | 2998 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; |
6264b550 | 2999 | return NULL ; |
519cb848 SC |
3000 | } |
3001 | ||
14c9cbdb | 3002 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 3003 | { |
427ff662 | 3004 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; |
14c9cbdb | 3005 | |
aa99e0cd SC |
3006 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) |
3007 | { | |
3008 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
db7a550b | 3009 | int scrlsize = MAC_SCROLLBAR_SIZE ; |
8b573fb8 VZ |
3010 | wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ; |
3011 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
3012 | { | |
3013 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
3014 | variant = wxWINDOW_VARIANT_SMALL ; | |
3015 | } | |
db7a550b SC |
3016 | |
3017 | int adjust = hasBoth ? scrlsize - 1: 0 ; | |
aa99e0cd SC |
3018 | int width, height ; |
3019 | GetClientSize( &width , &height ) ; | |
3020 | ||
db7a550b SC |
3021 | wxPoint vPoint(width-scrlsize, 0) ; |
3022 | wxSize vSize(scrlsize, height - adjust) ; | |
3023 | wxPoint hPoint(0 , height-scrlsize ) ; | |
3024 | wxSize hSize( width - adjust, scrlsize) ; | |
aa99e0cd SC |
3025 | |
3026 | ||
3027 | if ( style & wxVSCROLL ) | |
3028 | { | |
375bb200 | 3029 | m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint, |
aa99e0cd SC |
3030 | vSize , wxVERTICAL); |
3031 | } | |
3032 | ||
3033 | if ( style & wxHSCROLL ) | |
3034 | { | |
375bb200 | 3035 | m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint, |
aa99e0cd SC |
3036 | hSize , wxHORIZONTAL); |
3037 | } | |
3038 | } | |
aa99e0cd | 3039 | |
14c9cbdb | 3040 | |
6264b550 RR |
3041 | // because the create does not take into account the client area origin |
3042 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
3043 | } |
3044 | ||
e766c8a9 | 3045 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 3046 | { |
aa99e0cd SC |
3047 | if ( !m_hScrollBar && !m_vScrollBar ) |
3048 | return ; | |
8b573fb8 | 3049 | |
6264b550 | 3050 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
db7a550b SC |
3051 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; |
3052 | int adjust = hasBoth ? scrlsize - 1 : 0 ; | |
14c9cbdb | 3053 | |
6264b550 | 3054 | // get real client area |
14c9cbdb | 3055 | |
facd6764 SC |
3056 | int width ; |
3057 | int height ; | |
3058 | GetSize( &width , &height ) ; | |
6264b550 RR |
3059 | |
3060 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
3061 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
14c9cbdb | 3062 | |
6264b550 RR |
3063 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; |
3064 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
3065 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
3066 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
db7a550b | 3067 | /* |
14c9cbdb | 3068 | int x = 0 ; |
6264b550 | 3069 | int y = 0 ; |
facd6764 SC |
3070 | int w ; |
3071 | int h ; | |
3072 | GetSize( &w , &h ) ; | |
14c9cbdb | 3073 | |
6264b550 RR |
3074 | MacClientToRootWindow( &x , &y ) ; |
3075 | MacClientToRootWindow( &w , &h ) ; | |
14c9cbdb | 3076 | |
6264b550 | 3077 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 3078 | |
6264b550 RR |
3079 | int totW = 10000 , totH = 10000; |
3080 | while( iter ) | |
3081 | { | |
1c310985 | 3082 | if ( iter->IsTopLevel() ) |
6264b550 | 3083 | { |
facd6764 | 3084 | iter->GetSize( &totW , &totH ) ; |
6264b550 RR |
3085 | break ; |
3086 | } | |
3087 | ||
3088 | iter = iter->GetParent() ; | |
14c9cbdb RD |
3089 | } |
3090 | ||
6264b550 RR |
3091 | if ( x == 0 ) |
3092 | { | |
3093 | hPoint.x = -1 ; | |
3094 | hSize.x += 1 ; | |
3095 | } | |
3096 | if ( y == 0 ) | |
3097 | { | |
3098 | vPoint.y = -1 ; | |
3099 | vSize.y += 1 ; | |
3100 | } | |
14c9cbdb | 3101 | |
6264b550 RR |
3102 | if ( w-x >= totW ) |
3103 | { | |
3104 | hSize.x += 1 ; | |
3105 | vPoint.x += 1 ; | |
3106 | } | |
14c9cbdb | 3107 | |
6264b550 RR |
3108 | if ( h-y >= totH ) |
3109 | { | |
3110 | vSize.y += 1 ; | |
3111 | hPoint.y += 1 ; | |
3112 | } | |
db7a550b | 3113 | */ |
6264b550 RR |
3114 | if ( m_vScrollBar ) |
3115 | { | |
3116 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
3117 | } | |
3118 | if ( m_hScrollBar ) | |
3119 | { | |
3120 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
3121 | } | |
519cb848 SC |
3122 | } |
3123 | ||
e766c8a9 | 3124 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
3125 | { |
3126 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
3127 | } | |
519cb848 | 3128 | |
14c9cbdb | 3129 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 3130 | { |
6264b550 | 3131 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 3132 | |
71f2fb52 | 3133 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
6264b550 RR |
3134 | while ( node ) |
3135 | { | |
9bd1404d | 3136 | wxWindowMac *child = node->GetData(); |
6264b550 | 3137 | child->MacSuperChangedPosition() ; |
eb22f2a6 | 3138 | node = node->GetNext(); |
6264b550 | 3139 | } |
519cb848 | 3140 | } |
519cb848 | 3141 | |
14c9cbdb | 3142 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
a3bf4a62 | 3143 | { |
6264b550 | 3144 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 3145 | |
71f2fb52 | 3146 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
6264b550 RR |
3147 | while ( node ) |
3148 | { | |
9bd1404d | 3149 | wxWindowMac *child = node->GetData(); |
6264b550 | 3150 | child->MacTopLevelWindowChangedPosition() ; |
eb22f2a6 | 3151 | node = node->GetNext(); |
6264b550 | 3152 | } |
a3bf4a62 | 3153 | } |
facd6764 | 3154 | |
e766c8a9 | 3155 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 3156 | { |
1c310985 | 3157 | if( IsTopLevel() ) |
6264b550 | 3158 | return 0 ; |
2f1ae414 SC |
3159 | |
3160 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
3161 | { | |
ed60b502 | 3162 | SInt32 border = 3 ; |
ed60b502 | 3163 | return border ; |
2f1ae414 SC |
3164 | } |
3165 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
3166 | { | |
ed60b502 | 3167 | SInt32 border = 3 ; |
ed60b502 | 3168 | return border ; |
2f1ae414 SC |
3169 | } |
3170 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
3171 | { | |
6264b550 | 3172 | return 1 ; |
2f1ae414 | 3173 | } |
6264b550 | 3174 | return 0 ; |
2f1ae414 SC |
3175 | } |
3176 | ||
e766c8a9 | 3177 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 3178 | { |
1c310985 SC |
3179 | // they are all symmetric in mac themes |
3180 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3181 | } |
3182 | ||
e766c8a9 | 3183 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 3184 | { |
1c310985 SC |
3185 | // they are all symmetric in mac themes |
3186 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3187 | } |
3188 | ||
e766c8a9 | 3189 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 3190 | { |
1c310985 SC |
3191 | // they are all symmetric in mac themes |
3192 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
3193 | } |
3194 | ||
14c9cbdb | 3195 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 3196 | { |
055a486b | 3197 | return style & ~wxBORDER_MASK ; |
2f1ae414 | 3198 | } |
0a67a93b | 3199 | |
e766c8a9 | 3200 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 3201 | // position. |
e766c8a9 | 3202 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 3203 | { |
59a12e90 | 3204 | pt = wxGetMousePosition(); |
e766c8a9 | 3205 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 3206 | return found; |
3723b7b1 JS |
3207 | } |
3208 | ||
3209 | // Get the current mouse position. | |
3210 | wxPoint wxGetMousePosition() | |
3211 | { | |
57591e0e JS |
3212 | int x, y; |
3213 | wxGetMousePosition(& x, & y); | |
3214 | return wxPoint(x, y); | |
3723b7b1 JS |
3215 | } |
3216 | ||
6ed71b4f | 3217 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) |
8950f7cc | 3218 | { |
8b573fb8 VZ |
3219 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) |
3220 | { | |
3221 | // copied from wxGTK : CS | |
249aad30 | 3222 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN |
8950f7cc SC |
3223 | // except that: |
3224 | // | |
3225 | // (a) it's a command event and so is propagated to the parent | |
3226 | // (b) under MSW it can be generated from kbd too | |
3227 | // (c) it uses screen coords (because of (a)) | |
3228 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
3229 | this->GetId(), | |
3230 | this->ClientToScreen(event.GetPosition())); | |
249aad30 SC |
3231 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) |
3232 | event.Skip() ; | |
8b573fb8 | 3233 | } |
facd6764 SC |
3234 | else |
3235 | { | |
8b573fb8 | 3236 | event.Skip() ; |
facd6764 | 3237 | } |
8950f7cc SC |
3238 | } |
3239 | ||
ff3795ee SC |
3240 | void wxWindowMac::OnPaint( wxPaintEvent & event ) |
3241 | { | |
d1fabc12 SC |
3242 | // in the other case we already have drawn from the OnEraseBackground Handler |
3243 | if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT || | |
3244 | m_macBackgroundBrush.MacGetBrushKind() != kwxMacBrushTheme ) | |
ff3795ee | 3245 | { |
d1fabc12 SC |
3246 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) |
3247 | { | |
3248 | CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
3249 | } | |
ff3795ee SC |
3250 | } |
3251 | } | |
3252 | ||
8b573fb8 | 3253 | void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) |
facd6764 | 3254 | { |
facd6764 SC |
3255 | } |
3256 | ||
8b573fb8 | 3257 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) |
3083eb85 SC |
3258 | { |
3259 | int x ,y , w ,h ; | |
8b573fb8 | 3260 | |
79392158 | 3261 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ; |
3083eb85 SC |
3262 | Rect bounds = { y , x , y+h , x+w }; |
3263 | return bounds ; | |
3264 | } | |
3265 | ||
8b573fb8 | 3266 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
f1d527c1 SC |
3267 | { |
3268 | return eventNotHandledErr ; | |
3269 | } | |
3270 | ||
facd6764 | 3271 |