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