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