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