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