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