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