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