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