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