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