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