]>
Commit | Line | Data |
---|---|---|
524c47aa SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/carbon/window.cpp | |
3 | // Purpose: wxWindowMac | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/window.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/log.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/panel.h" | |
21 | #include "wx/frame.h" | |
22 | #include "wx/dc.h" | |
23 | #include "wx/dcclient.h" | |
24 | #include "wx/button.h" | |
25 | #include "wx/menu.h" | |
26 | #include "wx/dialog.h" | |
27 | #include "wx/settings.h" | |
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/scrolbar.h" | |
30 | #include "wx/statbox.h" | |
31 | #include "wx/textctrl.h" | |
32 | #include "wx/toolbar.h" | |
33 | #include "wx/layout.h" | |
34 | #include "wx/statusbr.h" | |
35 | #include "wx/menuitem.h" | |
36 | #include "wx/treectrl.h" | |
37 | #include "wx/listctrl.h" | |
38 | #endif | |
39 | ||
40 | #include "wx/tooltip.h" | |
41 | #include "wx/spinctrl.h" | |
42 | #include "wx/geometry.h" | |
43 | ||
44 | #if wxUSE_LISTCTRL | |
45 | #include "wx/listctrl.h" | |
46 | #endif | |
47 | ||
48 | #if wxUSE_TREECTRL | |
49 | #include "wx/treectrl.h" | |
50 | #endif | |
51 | ||
52 | #if wxUSE_CARET | |
53 | #include "wx/caret.h" | |
54 | #endif | |
55 | ||
56 | #if wxUSE_POPUPWIN | |
57 | #include "wx/popupwin.h" | |
58 | #endif | |
59 | ||
60 | #if wxUSE_DRAG_AND_DROP | |
61 | #include "wx/dnd.h" | |
62 | #endif | |
63 | ||
f55d9f74 SC |
64 | #include "wx/graphics.h" |
65 | ||
524c47aa SC |
66 | #if wxOSX_USE_CARBON |
67 | #include "wx/osx/uma.h" | |
68 | #else | |
69 | #include "wx/osx/private.h" | |
70 | // bring in themeing | |
71 | #include <Carbon/Carbon.h> | |
72 | #endif | |
73 | ||
74 | #define MAC_SCROLLBAR_SIZE 15 | |
75 | #define MAC_SMALL_SCROLLBAR_SIZE 11 | |
76 | ||
77 | #include <string.h> | |
78 | ||
79 | #ifdef __WXUNIVERSAL__ | |
80 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
81 | #else | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
83 | #endif | |
84 | ||
85 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
86 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) | |
87 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
88 | EVT_PAINT(wxWindowMac::OnPaint) | |
89 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) | |
90 | END_EVENT_TABLE() | |
91 | ||
92 | #define wxMAC_DEBUG_REDRAW 0 | |
93 | #ifndef wxMAC_DEBUG_REDRAW | |
94 | #define wxMAC_DEBUG_REDRAW 0 | |
95 | #endif | |
96 | ||
97 | // =========================================================================== | |
98 | // implementation | |
99 | // =========================================================================== | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // constructors and such | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
105 | wxWindowMac::wxWindowMac() | |
106 | { | |
107 | Init(); | |
108 | } | |
109 | ||
110 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
111 | wxWindowID id, | |
112 | const wxPoint& pos , | |
113 | const wxSize& size , | |
114 | long style , | |
115 | const wxString& name ) | |
116 | { | |
117 | Init(); | |
118 | Create(parent, id, pos, size, style, name); | |
119 | } | |
120 | ||
121 | void wxWindowMac::Init() | |
122 | { | |
123 | m_peer = NULL ; | |
124 | m_macAlpha = 255 ; | |
125 | m_cgContextRef = NULL ; | |
126 | ||
127 | // as all windows are created with WS_VISIBLE style... | |
128 | m_isShown = true; | |
129 | ||
130 | m_hScrollBar = NULL ; | |
131 | m_vScrollBar = NULL ; | |
132 | m_hScrollBarAlwaysShown = false; | |
133 | m_vScrollBarAlwaysShown = false; | |
134 | ||
135 | m_macIsUserPane = true; | |
136 | m_clipChildren = false ; | |
137 | m_cachedClippedRectValid = false ; | |
138 | } | |
139 | ||
140 | wxWindowMac::~wxWindowMac() | |
141 | { | |
142 | SendDestroyEvent(); | |
143 | ||
144 | m_isBeingDeleted = true; | |
145 | ||
146 | MacInvalidateBorders() ; | |
147 | ||
148 | #ifndef __WXUNIVERSAL__ | |
149 | // VS: make sure there's no wxFrame with last focus set to us: | |
150 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
151 | { | |
152 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
153 | if ( frame ) | |
154 | { | |
155 | if ( frame->GetLastFocus() == this ) | |
156 | frame->SetLastFocus((wxWindow*)NULL); | |
157 | break; | |
158 | } | |
159 | } | |
160 | #endif | |
161 | ||
162 | // destroy children before destroying this window itself | |
163 | DestroyChildren(); | |
164 | ||
165 | // wxRemoveMacControlAssociation( this ) ; | |
166 | // If we delete an item, we should initialize the parent panel, | |
167 | // because it could now be invalid. | |
168 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); | |
169 | if ( tlw ) | |
170 | { | |
171 | if ( tlw->GetDefaultItem() == (wxButton*) this) | |
172 | tlw->SetDefaultItem(NULL); | |
173 | } | |
174 | ||
175 | if ( g_MacLastWindow == this ) | |
176 | g_MacLastWindow = NULL ; | |
177 | ||
178 | #ifndef __WXUNIVERSAL__ | |
179 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ; | |
180 | if ( frame ) | |
181 | { | |
182 | if ( frame->GetLastFocus() == this ) | |
183 | frame->SetLastFocus( NULL ) ; | |
184 | } | |
185 | #endif | |
186 | ||
187 | // delete our drop target if we've got one | |
188 | #if wxUSE_DRAG_AND_DROP | |
189 | if ( m_dropTarget != NULL ) | |
190 | { | |
191 | delete m_dropTarget; | |
192 | m_dropTarget = NULL; | |
193 | } | |
194 | #endif | |
195 | ||
196 | delete m_peer ; | |
197 | } | |
198 | ||
199 | WXWidget wxWindowMac::GetHandle() const | |
200 | { | |
201 | return (WXWidget) m_peer->GetWXWidget() ; | |
202 | } | |
203 | ||
204 | // | |
205 | // TODO END move to window_osx.cpp | |
206 | // | |
207 | ||
208 | // --------------------------------------------------------------------------- | |
209 | // Utility Routines to move between different coordinate systems | |
210 | // --------------------------------------------------------------------------- | |
211 | ||
212 | /* | |
213 | * Right now we have the following setup : | |
214 | * a border that is not part of the native control is always outside the | |
215 | * control's border (otherwise we loose all native intelligence, future ways | |
216 | * may be to have a second embedding control responsible for drawing borders | |
217 | * and backgrounds eventually) | |
218 | * so all this border calculations have to be taken into account when calling | |
219 | * native methods or getting native oriented data | |
220 | * so we have three coordinate systems here | |
221 | * wx client coordinates | |
222 | * wx window coordinates (including window frames) | |
223 | * native coordinates | |
224 | */ | |
225 | ||
226 | // | |
227 | // | |
228 | ||
229 | // Constructor | |
230 | bool wxWindowMac::Create(wxWindowMac *parent, | |
231 | wxWindowID id, | |
232 | const wxPoint& pos, | |
233 | const wxSize& size, | |
234 | long style, | |
235 | const wxString& name) | |
236 | { | |
237 | wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); | |
238 | ||
239 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
240 | return false; | |
241 | ||
242 | m_windowVariant = parent->GetWindowVariant() ; | |
243 | ||
244 | if ( m_macIsUserPane ) | |
245 | { | |
246 | m_peer = wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() ); | |
247 | MacPostControlCreate(pos, size) ; | |
248 | } | |
249 | ||
250 | #ifndef __WXUNIVERSAL__ | |
251 | // Don't give scrollbars to wxControls unless they ask for them | |
252 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) | |
253 | || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) | |
254 | { | |
255 | MacCreateScrollBars( style ) ; | |
256 | } | |
257 | #endif | |
258 | ||
259 | wxWindowCreateEvent event((wxWindow*)this); | |
260 | GetEventHandler()->AddPendingEvent(event); | |
261 | ||
262 | return true; | |
263 | } | |
264 | ||
265 | void wxWindowMac::MacChildAdded() | |
266 | { | |
267 | if ( m_vScrollBar ) | |
268 | m_vScrollBar->Raise() ; | |
269 | if ( m_hScrollBar ) | |
270 | m_hScrollBar->Raise() ; | |
271 | } | |
272 | ||
273 | void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) | |
274 | { | |
275 | wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ; | |
276 | ||
524c47aa SC |
277 | GetParent()->AddChild( this ); |
278 | ||
524c47aa | 279 | m_peer->InstallEventHandler(); |
c4825ef7 | 280 | m_peer->Embed(GetParent()->GetPeer()); |
524c47aa | 281 | |
524c47aa SC |
282 | GetParent()->MacChildAdded() ; |
283 | ||
284 | // adjust font, controlsize etc | |
285 | DoSetWindowVariant( m_windowVariant ) ; | |
286 | ||
287 | m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; | |
288 | ||
f55d9f74 SC |
289 | // for controls we want to use best size for wxDefaultSize params ) |
290 | if ( !m_macIsUserPane ) | |
524c47aa SC |
291 | SetInitialSize(size); |
292 | ||
293 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
294 | } | |
295 | ||
296 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
297 | { | |
298 | // Don't assert, in case we set the window variant before | |
299 | // the window is created | |
300 | // wxASSERT( m_peer->Ok() ) ; | |
301 | ||
302 | m_windowVariant = variant ; | |
303 | ||
304 | if (m_peer == NULL || !m_peer->IsOk()) | |
305 | return; | |
306 | ||
307 | m_peer->SetControlSize( variant ); | |
308 | #if wxOSX_USE_COCOA_OR_CARBON | |
309 | wxFont font ; | |
310 | ||
311 | #if wxOSX_USE_CARBON | |
312 | ControlSize size ; | |
313 | ThemeFontID themeFont = kThemeSystemFont ; | |
314 | ||
315 | // we will get that from the settings later | |
316 | // and make this NORMAL later, but first | |
317 | // we have a few calculations that we must fix | |
318 | ||
319 | switch ( variant ) | |
320 | { | |
321 | case wxWINDOW_VARIANT_NORMAL : | |
322 | size = kControlSizeNormal; | |
323 | themeFont = kThemeSystemFont ; | |
324 | break ; | |
325 | ||
326 | case wxWINDOW_VARIANT_SMALL : | |
327 | size = kControlSizeSmall; | |
328 | themeFont = kThemeSmallSystemFont ; | |
329 | break ; | |
330 | ||
331 | case wxWINDOW_VARIANT_MINI : | |
332 | // not always defined in the headers | |
333 | size = 3 ; | |
334 | themeFont = 109 ; | |
335 | break ; | |
336 | ||
337 | case wxWINDOW_VARIANT_LARGE : | |
338 | size = kControlSizeLarge; | |
339 | themeFont = kThemeSystemFont ; | |
340 | break ; | |
341 | ||
342 | default: | |
343 | wxFAIL_MSG(_T("unexpected window variant")); | |
344 | break ; | |
345 | } | |
346 | ||
347 | m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ; | |
348 | font.MacCreateFromThemeFont( themeFont ) ; | |
349 | #else | |
350 | CTFontUIFontType themeFont = kCTFontSystemFontType ; | |
351 | switch ( variant ) | |
352 | { | |
353 | case wxWINDOW_VARIANT_NORMAL : | |
354 | themeFont = kCTFontSystemFontType; | |
355 | break ; | |
356 | ||
357 | case wxWINDOW_VARIANT_SMALL : | |
358 | themeFont = kCTFontSmallSystemFontType; | |
359 | break ; | |
360 | ||
361 | case wxWINDOW_VARIANT_MINI : | |
362 | themeFont = kCTFontMiniSystemFontType; | |
363 | break ; | |
364 | ||
365 | case wxWINDOW_VARIANT_LARGE : | |
366 | themeFont = kCTFontSystemFontType; | |
367 | break ; | |
368 | ||
369 | default: | |
370 | wxFAIL_MSG(_T("unexpected window variant")); | |
371 | break ; | |
372 | } | |
373 | font.MacCreateFromUIFont( themeFont ) ; | |
374 | #endif | |
375 | ||
376 | SetFont( font ) ; | |
377 | #endif | |
378 | } | |
379 | ||
380 | void wxWindowMac::MacUpdateControlFont() | |
381 | { | |
f55d9f74 SC |
382 | if ( m_peer ) |
383 | m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; | |
1e181c7a | 384 | |
524c47aa SC |
385 | // do not trigger refreshes upon invisible and possible partly created objects |
386 | if ( IsShownOnScreen() ) | |
387 | Refresh() ; | |
388 | } | |
389 | ||
390 | bool wxWindowMac::SetFont(const wxFont& font) | |
391 | { | |
392 | bool retval = wxWindowBase::SetFont( font ); | |
393 | ||
394 | MacUpdateControlFont() ; | |
395 | ||
396 | return retval; | |
397 | } | |
398 | ||
399 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
400 | { | |
401 | bool retval = wxWindowBase::SetForegroundColour( col ); | |
402 | ||
403 | if (retval) | |
404 | MacUpdateControlFont(); | |
405 | ||
406 | return retval; | |
407 | } | |
408 | ||
409 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
410 | { | |
411 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
412 | return false ; | |
413 | ||
414 | if ( m_peer ) | |
415 | m_peer->SetBackgroundColour( col ) ; | |
416 | ||
417 | return true ; | |
418 | } | |
419 | ||
420 | void wxWindowMac::SetFocus() | |
421 | { | |
422 | if ( !AcceptsFocus() ) | |
423 | return ; | |
424 | ||
425 | wxWindow* former = FindFocus() ; | |
426 | if ( former == this ) | |
427 | return ; | |
428 | ||
429 | m_peer->SetFocus() ; | |
430 | } | |
431 | ||
432 | void wxWindowMac::DoCaptureMouse() | |
433 | { | |
434 | wxApp::s_captureWindow = (wxWindow*) this ; | |
435 | } | |
436 | ||
437 | wxWindow * wxWindowBase::GetCapture() | |
438 | { | |
439 | return wxApp::s_captureWindow ; | |
440 | } | |
441 | ||
442 | void wxWindowMac::DoReleaseMouse() | |
443 | { | |
444 | wxApp::s_captureWindow = NULL ; | |
445 | } | |
446 | ||
447 | #if wxUSE_DRAG_AND_DROP | |
448 | ||
449 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) | |
450 | { | |
0b1ca117 | 451 | delete m_dropTarget; |
524c47aa SC |
452 | |
453 | m_dropTarget = pDropTarget; | |
454 | if ( m_dropTarget != NULL ) | |
455 | { | |
456 | // TODO: | |
457 | } | |
458 | } | |
459 | ||
460 | #endif | |
461 | ||
462 | // Old-style File Manager Drag & Drop | |
463 | void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept)) | |
464 | { | |
465 | // TODO: | |
466 | } | |
467 | ||
468 | // From a wx position / size calculate the appropriate size of the native control | |
469 | ||
470 | bool wxWindowMac::MacGetBoundsForControl( | |
471 | const wxPoint& pos, | |
472 | const wxSize& size, | |
473 | int& x, int& y, | |
474 | int& w, int& h , bool adjustOrigin ) const | |
475 | { | |
476 | // the desired size, minus the border pixels gives the correct size of the control | |
477 | x = (int)pos.x; | |
478 | y = (int)pos.y; | |
479 | ||
f55d9f74 SC |
480 | w = WidthDefault( size.x ); |
481 | h = HeightDefault( size.y ); | |
524c47aa SC |
482 | |
483 | x += MacGetLeftBorderSize() ; | |
484 | y += MacGetTopBorderSize() ; | |
485 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
486 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
487 | ||
488 | if ( adjustOrigin ) | |
489 | AdjustForParentClientOrigin( x , y ) ; | |
490 | ||
491 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
1a4e2d5b | 492 | if ( GetParent() && !GetParent()->IsTopLevel() ) |
524c47aa SC |
493 | { |
494 | x -= GetParent()->MacGetLeftBorderSize() ; | |
495 | y -= GetParent()->MacGetTopBorderSize() ; | |
496 | } | |
497 | ||
498 | return true ; | |
499 | } | |
500 | ||
501 | // Get window size (not client size) | |
502 | void wxWindowMac::DoGetSize(int *x, int *y) const | |
503 | { | |
504 | int width, height; | |
505 | m_peer->GetSize( width, height ); | |
506 | ||
507 | if (x) | |
508 | *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
509 | if (y) | |
510 | *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
511 | } | |
512 | ||
513 | // get the position of the bounds of this window in client coordinates of its parent | |
514 | void wxWindowMac::DoGetPosition(int *x, int *y) const | |
515 | { | |
516 | int x1, y1; | |
517 | ||
518 | m_peer->GetPosition( x1, y1 ) ; | |
519 | ||
520 | // get the wx window position from the native one | |
521 | x1 -= MacGetLeftBorderSize() ; | |
522 | y1 -= MacGetTopBorderSize() ; | |
523 | ||
524 | if ( !IsTopLevel() ) | |
525 | { | |
526 | wxWindow *parent = GetParent(); | |
527 | if ( parent ) | |
528 | { | |
529 | // we must first adjust it to be in window coordinates of the parent, | |
530 | // as otherwise it gets lost by the ClientAreaOrigin fix | |
531 | x1 += parent->MacGetLeftBorderSize() ; | |
532 | y1 += parent->MacGetTopBorderSize() ; | |
533 | ||
534 | // and now to client coordinates | |
535 | wxPoint pt(parent->GetClientAreaOrigin()); | |
536 | x1 -= pt.x ; | |
537 | y1 -= pt.y ; | |
538 | } | |
539 | } | |
540 | ||
541 | if (x) | |
542 | *x = x1 ; | |
543 | if (y) | |
544 | *y = y1 ; | |
545 | } | |
546 | ||
547 | void wxWindowMac::DoScreenToClient(int *x, int *y) const | |
548 | { | |
549 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; | |
550 | wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ; | |
551 | tlw->GetNonOwnedPeer()->ScreenToWindow( x, y); | |
552 | MacRootWindowToWindow( x , y ) ; | |
553 | ||
554 | wxPoint origin = GetClientAreaOrigin() ; | |
555 | if (x) | |
556 | *x -= origin.x ; | |
557 | if (y) | |
558 | *y -= origin.y ; | |
559 | } | |
560 | ||
561 | void wxWindowMac::DoClientToScreen(int *x, int *y) const | |
562 | { | |
563 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; | |
564 | wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ; | |
565 | ||
566 | wxPoint origin = GetClientAreaOrigin() ; | |
567 | if (x) | |
568 | *x += origin.x ; | |
569 | if (y) | |
570 | *y += origin.y ; | |
571 | ||
572 | MacWindowToRootWindow( x , y ) ; | |
573 | tlw->GetNonOwnedPeer()->WindowToScreen( x , y ); | |
574 | } | |
575 | ||
576 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const | |
577 | { | |
578 | wxPoint origin = GetClientAreaOrigin() ; | |
579 | if (x) | |
580 | *x += origin.x ; | |
581 | if (y) | |
582 | *y += origin.y ; | |
583 | ||
584 | MacWindowToRootWindow( x , y ) ; | |
585 | } | |
586 | ||
587 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
588 | { | |
589 | wxPoint pt ; | |
590 | ||
591 | if (x) | |
592 | pt.x = *x ; | |
593 | if (y) | |
594 | pt.y = *y ; | |
595 | ||
596 | if ( !IsTopLevel() ) | |
597 | { | |
598 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
599 | if (top) | |
600 | { | |
601 | pt.x -= MacGetLeftBorderSize() ; | |
602 | pt.y -= MacGetTopBorderSize() ; | |
603 | wxWidgetImpl::Convert( &pt , m_peer , top->m_peer ) ; | |
604 | } | |
605 | } | |
606 | ||
607 | if (x) | |
608 | *x = (int) pt.x ; | |
609 | if (y) | |
610 | *y = (int) pt.y ; | |
611 | } | |
612 | ||
613 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const | |
614 | { | |
615 | wxPoint pt ; | |
616 | ||
617 | if (x) | |
618 | pt.x = *x ; | |
619 | if (y) | |
620 | pt.y = *y ; | |
621 | ||
622 | if ( !IsTopLevel() ) | |
623 | { | |
624 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
625 | if (top) | |
626 | { | |
627 | wxWidgetImpl::Convert( &pt , top->m_peer , m_peer ) ; | |
628 | pt.x += MacGetLeftBorderSize() ; | |
629 | pt.y += MacGetTopBorderSize() ; | |
630 | } | |
631 | } | |
632 | ||
633 | if (x) | |
634 | *x = (int) pt.x ; | |
635 | if (y) | |
636 | *y = (int) pt.y ; | |
637 | } | |
638 | ||
639 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const | |
640 | { | |
641 | wxSize sizeTotal = size; | |
642 | ||
643 | int innerwidth, innerheight; | |
644 | int left, top; | |
645 | int outerwidth, outerheight; | |
646 | ||
647 | m_peer->GetContentArea( left, top, innerwidth, innerheight ); | |
648 | m_peer->GetSize( outerwidth, outerheight ); | |
649 | ||
650 | sizeTotal.x += left + (outerwidth-innerwidth); | |
651 | sizeTotal.y += top + (outerheight-innerheight); | |
652 | ||
653 | sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
654 | sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
655 | ||
656 | return sizeTotal; | |
657 | } | |
658 | ||
659 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
660 | void wxWindowMac::DoGetClientSize( int *x, int *y ) const | |
661 | { | |
662 | int ww, hh; | |
663 | ||
664 | int left, top; | |
665 | ||
666 | m_peer->GetContentArea( left, top, ww, hh ); | |
667 | ||
668 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
669 | hh -= m_hScrollBar->GetSize().y ; | |
670 | ||
671 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
672 | ww -= m_vScrollBar->GetSize().x ; | |
673 | ||
674 | if (x) | |
675 | *x = ww; | |
676 | if (y) | |
677 | *y = hh; | |
678 | } | |
679 | ||
680 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
681 | { | |
682 | if (m_cursor.IsSameAs(cursor)) | |
683 | return false; | |
684 | ||
685 | if (!cursor.IsOk()) | |
686 | { | |
687 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
688 | return false ; | |
689 | } | |
690 | else | |
691 | { | |
692 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
693 | return false ; | |
694 | } | |
695 | ||
696 | wxASSERT_MSG( m_cursor.Ok(), | |
697 | wxT("cursor must be valid after call to the base version")); | |
698 | ||
699 | wxWindowMac *mouseWin = 0 ; | |
700 | #if wxOSX_USE_CARBON | |
701 | { | |
702 | wxNonOwnedWindow *tlw = MacGetTopLevelWindow() ; | |
703 | WindowRef window = (WindowRef) ( tlw ? tlw->GetWXWindow() : 0 ) ; | |
704 | ||
705 | ControlPartCode part ; | |
706 | ControlRef control ; | |
707 | Point pt ; | |
708 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 | |
709 | HIPoint hiPoint ; | |
710 | HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint); | |
711 | pt.h = hiPoint.x; | |
712 | pt.v = hiPoint.y; | |
713 | #else | |
714 | GetGlobalMouse( &pt ); | |
715 | int x = pt.h; | |
716 | int y = pt.v; | |
717 | ScreenToClient(&x, &y); | |
718 | pt.h = x; | |
719 | pt.v = y; | |
720 | #endif | |
721 | control = FindControlUnderMouse( pt , window , &part ) ; | |
722 | if ( control ) | |
723 | mouseWin = wxFindWindowFromWXWidget( (WXWidget) control ) ; | |
724 | ||
725 | } | |
726 | #endif | |
727 | ||
728 | if ( mouseWin == this && !wxIsBusy() ) | |
729 | m_cursor.MacInstall() ; | |
730 | ||
731 | return true ; | |
732 | } | |
733 | ||
734 | #if wxUSE_MENUS | |
735 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
736 | { | |
737 | #ifndef __WXUNIVERSAL__ | |
738 | menu->SetInvokingWindow((wxWindow*)this); | |
739 | menu->UpdateUI(); | |
740 | ||
741 | if ( x == wxDefaultCoord && y == wxDefaultCoord ) | |
742 | { | |
743 | wxPoint mouse = wxGetMousePosition(); | |
744 | x = mouse.x; | |
745 | y = mouse.y; | |
746 | } | |
747 | else | |
748 | { | |
749 | ClientToScreen( &x , &y ) ; | |
750 | } | |
751 | #ifdef __WXOSX_CARBON__ | |
752 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; | |
753 | if ( HiWord(menuResult) != 0 ) | |
754 | { | |
755 | MenuCommand macid; | |
756 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); | |
757 | int id = wxMacCommandToId( macid ); | |
758 | wxMenuItem* item = NULL ; | |
759 | wxMenu* realmenu ; | |
760 | item = menu->FindItem( id, &realmenu ) ; | |
761 | if ( item ) | |
762 | { | |
763 | if (item->IsCheckable()) | |
764 | item->Check( !item->IsChecked() ) ; | |
765 | ||
766 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
767 | } | |
768 | } | |
769 | ||
524c47aa SC |
770 | #else |
771 | menu->SetInvokingWindow( NULL ); | |
772 | return false; | |
773 | #endif | |
774 | ||
775 | return true; | |
776 | #else | |
777 | // actually this shouldn't be called, because universal is having its own implementation | |
778 | return false; | |
779 | #endif | |
780 | } | |
781 | #endif | |
782 | ||
783 | // ---------------------------------------------------------------------------- | |
784 | // tooltips | |
785 | // ---------------------------------------------------------------------------- | |
786 | ||
787 | #if wxUSE_TOOLTIPS | |
788 | ||
789 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) | |
790 | { | |
791 | wxWindowBase::DoSetToolTip(tooltip); | |
792 | ||
793 | if ( m_tooltip ) | |
794 | m_tooltip->SetWindow(this); | |
795 | } | |
796 | ||
797 | #endif | |
798 | ||
799 | void wxWindowMac::MacInvalidateBorders() | |
800 | { | |
801 | if ( m_peer == NULL ) | |
802 | return ; | |
803 | ||
804 | bool vis = IsShownOnScreen() ; | |
805 | if ( !vis ) | |
806 | return ; | |
807 | ||
808 | int outerBorder = MacGetLeftBorderSize() ; | |
809 | #if wxOSX_USE_CARBON | |
810 | if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ ) | |
811 | outerBorder += 4 ; | |
812 | #endif | |
813 | ||
814 | if ( outerBorder == 0 ) | |
815 | return ; | |
816 | ||
817 | // now we know that we have something to do at all | |
818 | ||
819 | ||
820 | int tx,ty,tw,th; | |
821 | ||
822 | m_peer->GetSize( tw, th ); | |
823 | m_peer->GetPosition( tx, ty ); | |
824 | ||
825 | wxRect leftupdate( tx-outerBorder,ty,outerBorder,th ); | |
826 | wxRect rightupdate( tx+tw, ty, outerBorder, th ); | |
827 | wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder ); | |
828 | wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder ); | |
829 | ||
1a4e2d5b KO |
830 | if (GetParent()) { |
831 | GetParent()->m_peer->SetNeedsDisplay(&leftupdate); | |
832 | GetParent()->m_peer->SetNeedsDisplay(&rightupdate); | |
833 | GetParent()->m_peer->SetNeedsDisplay(&topupdate); | |
834 | GetParent()->m_peer->SetNeedsDisplay(&bottomupdate); | |
835 | } | |
524c47aa SC |
836 | } |
837 | ||
838 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
839 | { | |
840 | // this is never called for a toplevel window, so we know we have a parent | |
841 | int former_x , former_y , former_w, former_h ; | |
842 | ||
843 | // Get true coordinates of former position | |
844 | DoGetPosition( &former_x , &former_y ) ; | |
845 | DoGetSize( &former_w , &former_h ) ; | |
846 | ||
847 | wxWindow *parent = GetParent(); | |
848 | if ( parent ) | |
849 | { | |
850 | wxPoint pt(parent->GetClientAreaOrigin()); | |
851 | former_x += pt.x ; | |
852 | former_y += pt.y ; | |
853 | } | |
854 | ||
855 | int actualWidth = width ; | |
856 | int actualHeight = height ; | |
857 | int actualX = x; | |
858 | int actualY = y; | |
859 | ||
860 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
861 | actualWidth = m_minWidth; | |
862 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
863 | actualHeight = m_minHeight; | |
864 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
865 | actualWidth = m_maxWidth; | |
866 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
867 | actualHeight = m_maxHeight; | |
868 | ||
869 | bool doMove = false, doResize = false ; | |
870 | ||
871 | if ( actualX != former_x || actualY != former_y ) | |
872 | doMove = true ; | |
873 | ||
874 | if ( actualWidth != former_w || actualHeight != former_h ) | |
875 | doResize = true ; | |
876 | ||
877 | if ( doMove || doResize ) | |
878 | { | |
879 | // as the borders are drawn outside the native control, we adjust now | |
880 | ||
881 | wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), | |
882 | wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , | |
883 | actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; | |
884 | ||
1a4e2d5b | 885 | if ( parent && !parent->IsTopLevel() ) |
524c47aa | 886 | { |
1a4e2d5b | 887 | bounds.Offset( -parent->MacGetLeftBorderSize(), -parent->MacGetTopBorderSize() ); |
524c47aa SC |
888 | } |
889 | ||
890 | MacInvalidateBorders() ; | |
891 | ||
892 | m_cachedClippedRectValid = false ; | |
893 | ||
894 | m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height); | |
895 | ||
896 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
897 | ||
898 | MacInvalidateBorders() ; | |
899 | ||
900 | MacRepositionScrollBars() ; | |
901 | if ( doMove ) | |
902 | { | |
903 | wxPoint point(actualX, actualY); | |
904 | wxMoveEvent event(point, m_windowId); | |
905 | event.SetEventObject(this); | |
906 | HandleWindowEvent(event) ; | |
907 | } | |
908 | ||
909 | if ( doResize ) | |
910 | { | |
911 | MacRepositionScrollBars() ; | |
912 | wxSize size(actualWidth, actualHeight); | |
913 | wxSizeEvent event(size, m_windowId); | |
914 | event.SetEventObject(this); | |
915 | HandleWindowEvent(event); | |
916 | } | |
917 | } | |
918 | } | |
919 | ||
920 | wxSize wxWindowMac::DoGetBestSize() const | |
921 | { | |
922 | if ( m_macIsUserPane || IsTopLevel() ) | |
923 | { | |
924 | return wxWindowBase::DoGetBestSize() ; | |
925 | } | |
926 | else | |
927 | { | |
928 | wxRect r ; | |
929 | ||
930 | m_peer->GetBestRect(&r); | |
931 | ||
932 | if ( r.GetWidth() == 0 && r.GetHeight() == 0 ) | |
933 | { | |
934 | r.x = | |
935 | r.y = 0 ; | |
936 | r.width = | |
937 | r.height = 16 ; | |
938 | ||
939 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
940 | { | |
941 | r.height = 16 ; | |
942 | } | |
943 | #if wxUSE_SPINBTN | |
944 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
945 | { | |
946 | r.height = 24 ; | |
947 | } | |
948 | #endif | |
949 | else | |
950 | { | |
951 | // return wxWindowBase::DoGetBestSize() ; | |
952 | } | |
953 | } | |
954 | ||
955 | int bestWidth = r.width + MacGetLeftBorderSize() + | |
956 | MacGetRightBorderSize(); | |
957 | int bestHeight = r.height + MacGetTopBorderSize() + | |
958 | MacGetBottomBorderSize(); | |
959 | if ( bestHeight < 10 ) | |
960 | bestHeight = 13 ; | |
961 | ||
962 | return wxSize(bestWidth, bestHeight); | |
963 | } | |
964 | } | |
965 | ||
966 | // set the size of the window: if the dimensions are positive, just use them, | |
967 | // but if any of them is equal to -1, it means that we must find the value for | |
968 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
969 | // which case -1 is a valid value for x and y) | |
970 | // | |
971 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
972 | // the width/height to best suit our contents, otherwise we reuse the current | |
973 | // width/height | |
974 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
975 | { | |
976 | // get the current size and position... | |
977 | int currentX, currentY; | |
978 | int currentW, currentH; | |
979 | ||
980 | GetPosition(¤tX, ¤tY); | |
981 | GetSize(¤tW, ¤tH); | |
982 | ||
983 | // ... and don't do anything (avoiding flicker) if it's already ok | |
984 | if ( x == currentX && y == currentY && | |
985 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) | |
986 | { | |
987 | // TODO: REMOVE | |
988 | MacRepositionScrollBars() ; // we might have a real position shift | |
989 | ||
990 | return; | |
991 | } | |
992 | ||
993 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
994 | { | |
995 | if ( x == wxDefaultCoord ) | |
996 | x = currentX; | |
997 | if ( y == wxDefaultCoord ) | |
998 | y = currentY; | |
999 | } | |
1000 | ||
1001 | AdjustForParentClientOrigin( x, y, sizeFlags ); | |
1002 | ||
1003 | wxSize size = wxDefaultSize; | |
1004 | if ( width == wxDefaultCoord ) | |
1005 | { | |
1006 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1007 | { | |
1008 | size = DoGetBestSize(); | |
1009 | width = size.x; | |
1010 | } | |
1011 | else | |
1012 | { | |
1013 | // just take the current one | |
1014 | width = currentW; | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | if ( height == wxDefaultCoord ) | |
1019 | { | |
1020 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1021 | { | |
1022 | if ( size.x == wxDefaultCoord ) | |
1023 | size = DoGetBestSize(); | |
1024 | // else: already called DoGetBestSize() above | |
1025 | ||
1026 | height = size.y; | |
1027 | } | |
1028 | else | |
1029 | { | |
1030 | // just take the current one | |
1031 | height = currentH; | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | DoMoveWindow( x, y, width, height ); | |
1036 | } | |
1037 | ||
1038 | wxPoint wxWindowMac::GetClientAreaOrigin() const | |
1039 | { | |
1040 | int left,top,width,height; | |
1041 | m_peer->GetContentArea( left , top , width , height); | |
1042 | return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() ); | |
1043 | } | |
1044 | ||
1045 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1046 | { | |
1047 | if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord ) | |
1048 | { | |
1049 | int currentclientwidth , currentclientheight ; | |
1050 | int currentwidth , currentheight ; | |
1051 | ||
1052 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1053 | GetSize( ¤twidth , ¤theight ) ; | |
1054 | ||
1055 | DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , | |
1056 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | void wxWindowMac::SetLabel(const wxString& title) | |
1061 | { | |
1062 | m_label = title ; | |
1063 | ||
1064 | if ( m_peer && m_peer->IsOk() ) | |
1065 | m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; | |
1066 | ||
1067 | // do not trigger refreshes upon invisible and possible partly created objects | |
1068 | if ( IsShownOnScreen() ) | |
1069 | Refresh() ; | |
1070 | } | |
1071 | ||
1072 | wxString wxWindowMac::GetLabel() const | |
1073 | { | |
1074 | return m_label ; | |
1075 | } | |
1076 | ||
1077 | bool wxWindowMac::Show(bool show) | |
1078 | { | |
1079 | if ( !wxWindowBase::Show(show) ) | |
1080 | return false; | |
1081 | ||
1082 | if ( m_peer ) | |
1083 | m_peer->SetVisibility( show ) ; | |
1084 | ||
1085 | return true; | |
1086 | } | |
1087 | ||
1088 | void wxWindowMac::DoEnable(bool enable) | |
1089 | { | |
1090 | m_peer->Enable( enable ) ; | |
1091 | } | |
1092 | ||
1093 | // | |
1094 | // status change notifications | |
1095 | // | |
1096 | ||
1097 | void wxWindowMac::MacVisibilityChanged() | |
1098 | { | |
1099 | } | |
1100 | ||
1101 | void wxWindowMac::MacHiliteChanged() | |
1102 | { | |
1103 | } | |
1104 | ||
1105 | void wxWindowMac::MacEnabledStateChanged() | |
1106 | { | |
1107 | OnEnabled( m_peer->IsEnabled() ); | |
1108 | } | |
1109 | ||
1110 | // | |
1111 | // status queries on the inherited window's state | |
1112 | // | |
1113 | ||
1114 | bool wxWindowMac::MacIsReallyEnabled() | |
1115 | { | |
1116 | return m_peer->IsEnabled() ; | |
1117 | } | |
1118 | ||
1119 | bool wxWindowMac::MacIsReallyHilited() | |
1120 | { | |
1121 | #if wxOSX_USE_CARBON | |
1122 | return m_peer->IsActive(); | |
1123 | #else | |
1124 | return true; // TODO | |
1125 | #endif | |
1126 | } | |
1127 | ||
1128 | int wxWindowMac::GetCharHeight() const | |
1129 | { | |
f55d9f74 SC |
1130 | wxCoord height; |
1131 | GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ); | |
524c47aa | 1132 | |
f55d9f74 | 1133 | return height; |
524c47aa SC |
1134 | } |
1135 | ||
1136 | int wxWindowMac::GetCharWidth() const | |
1137 | { | |
f55d9f74 SC |
1138 | wxCoord width; |
1139 | GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ); | |
524c47aa | 1140 | |
f55d9f74 | 1141 | return width; |
524c47aa SC |
1142 | } |
1143 | ||
f55d9f74 | 1144 | void wxWindowMac::GetTextExtent(const wxString& str, int *x, int *y, |
524c47aa SC |
1145 | int *descent, int *externalLeading, const wxFont *theFont ) const |
1146 | { | |
1147 | const wxFont *fontToUse = theFont; | |
1148 | wxFont tempFont; | |
1149 | if ( !fontToUse ) | |
1150 | { | |
1151 | tempFont = GetFont(); | |
1152 | fontToUse = &tempFont; | |
1153 | } | |
1154 | ||
f55d9f74 SC |
1155 | wxGraphicsContext* ctx = wxGraphicsContext::Create(); |
1156 | ctx->SetFont( *fontToUse, *wxBLACK ); | |
1157 | ||
1158 | wxDouble h , d , e , w; | |
1159 | ctx->GetTextExtent( str, &w, &h, &d, &e ); | |
1160 | ||
1161 | delete ctx; | |
1162 | ||
524c47aa | 1163 | if ( externalLeading ) |
f55d9f74 | 1164 | *externalLeading = (wxCoord)(e+0.5); |
524c47aa | 1165 | if ( descent ) |
f55d9f74 | 1166 | *descent = (wxCoord)(d+0.5); |
524c47aa | 1167 | if ( x ) |
f55d9f74 | 1168 | *x = (wxCoord)(w+0.5); |
524c47aa | 1169 | if ( y ) |
f55d9f74 | 1170 | *y = (wxCoord)(h+0.5); |
524c47aa SC |
1171 | } |
1172 | ||
1173 | /* | |
1174 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect | |
1175 | * we always intersect with the entire window, not only with the client area | |
1176 | */ | |
1177 | ||
1178 | void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) | |
1179 | { | |
1180 | if ( m_peer == NULL ) | |
1181 | return ; | |
1182 | ||
1183 | if ( !IsShownOnScreen() ) | |
1184 | return ; | |
1185 | ||
1186 | m_peer->SetNeedsDisplay( rect ) ; | |
1187 | } | |
1188 | ||
1189 | void wxWindowMac::DoFreeze() | |
1190 | { | |
1191 | #if wxOSX_USE_CARBON | |
1192 | if ( m_peer && m_peer->IsOk() ) | |
1193 | m_peer->SetDrawingEnabled( false ) ; | |
1194 | #endif | |
1195 | } | |
1196 | ||
1197 | void wxWindowMac::DoThaw() | |
1198 | { | |
1199 | #if wxOSX_USE_CARBON | |
1200 | if ( m_peer && m_peer->IsOk() ) | |
1201 | { | |
1202 | m_peer->SetDrawingEnabled( true ) ; | |
1203 | m_peer->InvalidateWithChildren() ; | |
1204 | } | |
1205 | #endif | |
1206 | } | |
1207 | ||
1208 | wxWindow *wxGetActiveWindow() | |
1209 | { | |
1210 | // actually this is a windows-only concept | |
1211 | return NULL; | |
1212 | } | |
1213 | ||
1214 | // Coordinates relative to the window | |
1215 | void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos)) | |
1216 | { | |
1217 | // We really don't move the mouse programmatically under Mac. | |
1218 | } | |
1219 | ||
1220 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
1221 | { | |
1222 | if ( MacGetTopLevelWindow() == NULL ) | |
1223 | return ; | |
1224 | /* | |
1225 | #if TARGET_API_MAC_OSX | |
1226 | if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
1227 | { | |
1228 | } | |
1229 | else | |
1230 | #endif | |
1231 | */ | |
1232 | if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR ) | |
1233 | { | |
1234 | event.GetDC()->Clear() ; | |
1235 | } | |
1236 | else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM ) | |
1237 | { | |
1238 | // don't skip the event here, custom background means that the app | |
1239 | // is drawing it itself in its OnPaint(), so don't draw it at all | |
1240 | // now to avoid flicker | |
1241 | } | |
1242 | else | |
1243 | { | |
1244 | event.Skip() ; | |
1245 | } | |
1246 | } | |
1247 | ||
1248 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
1249 | { | |
1250 | event.Skip() ; | |
1251 | } | |
1252 | ||
1253 | int wxWindowMac::GetScrollPos(int orient) const | |
1254 | { | |
1255 | if ( orient == wxHORIZONTAL ) | |
1256 | { | |
1257 | if ( m_hScrollBar ) | |
1258 | return m_hScrollBar->GetThumbPosition() ; | |
1259 | } | |
1260 | else | |
1261 | { | |
1262 | if ( m_vScrollBar ) | |
1263 | return m_vScrollBar->GetThumbPosition() ; | |
1264 | } | |
1265 | ||
1266 | return 0; | |
1267 | } | |
1268 | ||
1269 | // This now returns the whole range, not just the number | |
1270 | // of positions that we can scroll. | |
1271 | int wxWindowMac::GetScrollRange(int orient) const | |
1272 | { | |
1273 | if ( orient == wxHORIZONTAL ) | |
1274 | { | |
1275 | if ( m_hScrollBar ) | |
1276 | return m_hScrollBar->GetRange() ; | |
1277 | } | |
1278 | else | |
1279 | { | |
1280 | if ( m_vScrollBar ) | |
1281 | return m_vScrollBar->GetRange() ; | |
1282 | } | |
1283 | ||
1284 | return 0; | |
1285 | } | |
1286 | ||
1287 | int wxWindowMac::GetScrollThumb(int orient) const | |
1288 | { | |
1289 | if ( orient == wxHORIZONTAL ) | |
1290 | { | |
1291 | if ( m_hScrollBar ) | |
1292 | return m_hScrollBar->GetThumbSize() ; | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | if ( m_vScrollBar ) | |
1297 | return m_vScrollBar->GetThumbSize() ; | |
1298 | } | |
1299 | ||
1300 | return 0; | |
1301 | } | |
1302 | ||
1303 | void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) | |
1304 | { | |
1305 | if ( orient == wxHORIZONTAL ) | |
1306 | { | |
1307 | if ( m_hScrollBar ) | |
1308 | m_hScrollBar->SetThumbPosition( pos ) ; | |
1309 | } | |
1310 | else | |
1311 | { | |
1312 | if ( m_vScrollBar ) | |
1313 | m_vScrollBar->SetThumbPosition( pos ) ; | |
1314 | } | |
1315 | } | |
1316 | ||
1317 | void | |
1318 | wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag) | |
1319 | { | |
1320 | bool needVisibilityUpdate = false; | |
1321 | ||
1322 | if ( m_hScrollBarAlwaysShown != hflag ) | |
1323 | { | |
1324 | m_hScrollBarAlwaysShown = hflag; | |
1325 | needVisibilityUpdate = true; | |
1326 | } | |
1327 | ||
1328 | if ( m_vScrollBarAlwaysShown != vflag ) | |
1329 | { | |
1330 | m_vScrollBarAlwaysShown = vflag; | |
1331 | needVisibilityUpdate = true; | |
1332 | } | |
1333 | ||
1334 | if ( needVisibilityUpdate ) | |
1335 | DoUpdateScrollbarVisibility(); | |
1336 | } | |
1337 | ||
1338 | // | |
1339 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
1340 | // our own window origin is at leftOrigin/rightOrigin | |
1341 | // | |
1342 | ||
1343 | void wxWindowMac::MacPaintGrowBox() | |
1344 | { | |
1345 | if ( IsTopLevel() ) | |
1346 | return ; | |
1347 | ||
1348 | if ( MacHasScrollBarCorner() ) | |
1349 | { | |
1350 | CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; | |
1351 | wxASSERT( cgContext ) ; | |
1352 | ||
1353 | int tx,ty,tw,th; | |
1354 | ||
1355 | m_peer->GetSize( tw, th ); | |
1356 | m_peer->GetPosition( tx, ty ); | |
1357 | ||
1358 | Rect rect = { ty,tx, ty+th, tx+tw }; | |
1359 | ||
1360 | ||
1361 | int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
1362 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; | |
1363 | CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; | |
1364 | CGContextSaveGState( cgContext ); | |
1365 | ||
1366 | if ( m_backgroundColour.Ok() ) | |
1367 | { | |
1368 | CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); | |
1369 | } | |
1370 | else | |
1371 | { | |
1372 | CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 ); | |
1373 | } | |
1374 | CGContextFillRect( cgContext, cgrect ); | |
1375 | CGContextRestoreGState( cgContext ); | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) | |
1380 | { | |
1381 | if ( IsTopLevel() ) | |
1382 | return ; | |
1383 | ||
1384 | bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; | |
1385 | ||
1386 | // back to the surrounding frame rectangle | |
1387 | int tx,ty,tw,th; | |
1388 | ||
1389 | m_peer->GetSize( tw, th ); | |
1390 | m_peer->GetPosition( tx, ty ); | |
1391 | ||
1392 | Rect rect = { ty,tx, ty+th, tx+tw }; | |
1393 | ||
1394 | #if wxOSX_USE_COCOA_OR_CARBON | |
1395 | ||
1396 | InsetRect( &rect, -1 , -1 ) ; | |
1397 | ||
1398 | { | |
1399 | CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , | |
1400 | rect.bottom - rect.top ) ; | |
1401 | ||
1402 | HIThemeFrameDrawInfo info ; | |
1403 | memset( &info, 0 , sizeof(info) ) ; | |
1404 | ||
1405 | info.version = 0 ; | |
1406 | info.kind = 0 ; | |
1407 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
1408 | info.isFocused = hasFocus ; | |
1409 | ||
1410 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
1411 | wxASSERT( cgContext ) ; | |
1412 | ||
1413 | if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1414 | { | |
1415 | info.kind = kHIThemeFrameTextFieldSquare ; | |
1416 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
1417 | } | |
1418 | else if ( HasFlag(wxSIMPLE_BORDER) ) | |
1419 | { | |
1420 | info.kind = kHIThemeFrameListBox ; | |
1421 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
1422 | } | |
1423 | else if ( hasFocus ) | |
1424 | { | |
1425 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; | |
1426 | } | |
1427 | #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself | |
1428 | m_peer->GetRect( &rect ) ; | |
1429 | if ( MacHasScrollBarCorner() ) | |
1430 | { | |
1431 | int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant(); | |
1432 | int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
1433 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; | |
1434 | CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; | |
1435 | HIThemeGrowBoxDrawInfo info ; | |
1436 | memset( &info, 0, sizeof(info) ) ; | |
1437 | info.version = 0 ; | |
1438 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
1439 | info.kind = kHIThemeGrowBoxKindNone ; | |
1440 | // contrary to the docs ...SizeSmall does not work | |
1441 | info.size = kHIThemeGrowBoxSizeNormal ; | |
1442 | info.direction = 0 ; | |
1443 | HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; | |
1444 | } | |
1445 | #endif | |
1446 | } | |
1447 | #endif // wxOSX_USE_COCOA_OR_CARBON | |
1448 | } | |
1449 | ||
1450 | void wxWindowMac::RemoveChild( wxWindowBase *child ) | |
1451 | { | |
1452 | if ( child == m_hScrollBar ) | |
1453 | m_hScrollBar = NULL ; | |
1454 | if ( child == m_vScrollBar ) | |
1455 | m_vScrollBar = NULL ; | |
1456 | ||
1457 | wxWindowBase::RemoveChild( child ) ; | |
1458 | } | |
1459 | ||
1460 | void wxWindowMac::DoUpdateScrollbarVisibility() | |
1461 | { | |
1462 | bool triggerSizeEvent = false; | |
1463 | ||
1464 | if ( m_hScrollBar ) | |
1465 | { | |
1466 | bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded(); | |
1467 | ||
1468 | if ( m_hScrollBar->IsShown() != showHScrollBar ) | |
1469 | { | |
1470 | m_hScrollBar->Show( showHScrollBar ); | |
1471 | triggerSizeEvent = true; | |
1472 | } | |
1473 | } | |
1474 | ||
1475 | if ( m_vScrollBar) | |
1476 | { | |
1477 | bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded(); | |
1478 | ||
1479 | if ( m_vScrollBar->IsShown() != showVScrollBar ) | |
1480 | { | |
1481 | m_vScrollBar->Show( showVScrollBar ) ; | |
1482 | triggerSizeEvent = true; | |
1483 | } | |
1484 | } | |
1485 | ||
1486 | MacRepositionScrollBars() ; | |
1487 | if ( triggerSizeEvent ) | |
1488 | { | |
1489 | wxSizeEvent event(GetSize(), m_windowId); | |
1490 | event.SetEventObject(this); | |
1491 | HandleWindowEvent(event); | |
1492 | } | |
1493 | } | |
1494 | ||
1495 | // New function that will replace some of the above. | |
1496 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, | |
1497 | int range, bool refresh) | |
1498 | { | |
1499 | if ( orient == wxHORIZONTAL && m_hScrollBar ) | |
1500 | m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
1501 | else if ( orient == wxVERTICAL && m_vScrollBar ) | |
1502 | m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
1503 | ||
1504 | DoUpdateScrollbarVisibility(); | |
1505 | } | |
1506 | ||
1507 | // Does a physical scroll | |
1508 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) | |
1509 | { | |
1510 | if ( dx == 0 && dy == 0 ) | |
1511 | return ; | |
1512 | ||
1513 | int width , height ; | |
1514 | GetClientSize( &width , &height ) ; | |
1515 | ||
1516 | { | |
1517 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; | |
1518 | if ( rect ) | |
1519 | scrollrect.Intersect( *rect ) ; | |
1520 | // as the native control might be not a 0/0 wx window coordinates, we have to offset | |
1521 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
1522 | ||
1523 | m_peer->ScrollRect( &scrollrect, dx, dy ); | |
1524 | } | |
1525 | ||
1526 | wxWindowMac *child; | |
1527 | int x, y, w, h; | |
1528 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1529 | { | |
1530 | child = node->GetData(); | |
1531 | if (child == NULL) | |
1532 | continue; | |
1533 | if (child == m_vScrollBar) | |
1534 | continue; | |
1535 | if (child == m_hScrollBar) | |
1536 | continue; | |
1537 | if (child->IsTopLevel()) | |
1538 | continue; | |
1539 | ||
1540 | child->GetPosition( &x, &y ); | |
1541 | child->GetSize( &w, &h ); | |
1542 | if (rect) | |
1543 | { | |
1544 | wxRect rc( x, y, w, h ); | |
1545 | if (rect->Intersects( rc )) | |
1546 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); | |
1547 | } | |
1548 | else | |
1549 | { | |
1550 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); | |
1551 | } | |
1552 | } | |
1553 | } | |
1554 | ||
1555 | void wxWindowMac::MacOnScroll( wxScrollEvent &event ) | |
1556 | { | |
1557 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) | |
1558 | { | |
1559 | wxScrollWinEvent wevent; | |
1560 | wevent.SetPosition(event.GetPosition()); | |
1561 | wevent.SetOrientation(event.GetOrientation()); | |
1562 | wevent.SetEventObject(this); | |
1563 | ||
1564 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
1565 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
1566 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
1567 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
1568 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
1569 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
1570 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
1571 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
1572 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
1573 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
1574 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
1575 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
1576 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
1577 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
1578 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
1579 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
1580 | ||
1581 | HandleWindowEvent(wevent); | |
1582 | } | |
1583 | } | |
1584 | ||
1585 | // Get the window with the focus | |
1586 | wxWindow *wxWindowBase::DoFindFocus() | |
1587 | { | |
1588 | #if wxOSX_USE_CARBON | |
1589 | ControlRef control ; | |
1590 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
1591 | return wxFindWindowFromWXWidget( (WXWidget) control ) ; | |
1592 | #else | |
1593 | return NULL; | |
1594 | #endif | |
1595 | } | |
1596 | ||
1597 | void wxWindowMac::OnInternalIdle() | |
1598 | { | |
1599 | // This calls the UI-update mechanism (querying windows for | |
1600 | // menu/toolbar/control state information) | |
1601 | if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) | |
1602 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
1603 | } | |
1604 | ||
1605 | // Raise the window to the top of the Z order | |
1606 | void wxWindowMac::Raise() | |
1607 | { | |
1608 | m_peer->Raise(); | |
1609 | } | |
1610 | ||
1611 | // Lower the window to the bottom of the Z order | |
1612 | void wxWindowMac::Lower() | |
1613 | { | |
1614 | m_peer->Lower(); | |
1615 | } | |
1616 | ||
1617 | // static wxWindow *gs_lastWhich = NULL; | |
1618 | ||
1619 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt ) | |
1620 | { | |
1621 | // first trigger a set cursor event | |
1622 | ||
1623 | wxPoint clientorigin = GetClientAreaOrigin() ; | |
1624 | wxSize clientsize = GetClientSize() ; | |
1625 | wxCursor cursor ; | |
1626 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
1627 | { | |
1628 | wxSetCursorEvent event( pt.x , pt.y ); | |
1629 | ||
1630 | bool processedEvtSetCursor = HandleWindowEvent(event); | |
1631 | if ( processedEvtSetCursor && event.HasCursor() ) | |
1632 | { | |
1633 | cursor = event.GetCursor() ; | |
1634 | } | |
1635 | else | |
1636 | { | |
1637 | // the test for processedEvtSetCursor is here to prevent using m_cursor | |
1638 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
1639 | // it - this is a way to say that our cursor shouldn't be used for this | |
1640 | // point | |
1641 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
1642 | cursor = m_cursor ; | |
1643 | ||
1644 | if ( !wxIsBusy() && !GetParent() ) | |
1645 | cursor = *wxSTANDARD_CURSOR ; | |
1646 | } | |
1647 | ||
1648 | if ( cursor.Ok() ) | |
1649 | cursor.MacInstall() ; | |
1650 | } | |
1651 | ||
1652 | return cursor.Ok() ; | |
1653 | } | |
1654 | ||
1655 | wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) ) | |
1656 | { | |
1657 | #if wxUSE_TOOLTIPS | |
1658 | if ( m_tooltip ) | |
1659 | return m_tooltip->GetTip() ; | |
1660 | #endif | |
1661 | ||
1662 | return wxEmptyString ; | |
1663 | } | |
1664 | ||
1665 | void wxWindowMac::ClearBackground() | |
1666 | { | |
1667 | Refresh() ; | |
1668 | Update() ; | |
1669 | } | |
1670 | ||
1671 | void wxWindowMac::Update() | |
1672 | { | |
1673 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
1674 | if (top) | |
1675 | top->Update() ; | |
1676 | } | |
1677 | ||
1678 | wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const | |
1679 | { | |
1680 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1681 | ||
1682 | while ( iter ) | |
1683 | { | |
1684 | if ( iter->IsTopLevel() ) | |
1685 | { | |
1686 | wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow); | |
1687 | if ( toplevel ) | |
1688 | return toplevel; | |
1689 | #if wxUSE_POPUPWIN | |
1690 | wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow); | |
1691 | if ( popupwin ) | |
1692 | return popupwin; | |
1693 | #endif | |
1694 | } | |
1695 | iter = iter->GetParent() ; | |
1696 | } | |
1697 | ||
1698 | return NULL ; | |
1699 | } | |
1700 | ||
1701 | const wxRect& wxWindowMac::MacGetClippedClientRect() const | |
1702 | { | |
1703 | MacUpdateClippedRects() ; | |
1704 | ||
1705 | return m_cachedClippedClientRect ; | |
1706 | } | |
1707 | ||
1708 | const wxRect& wxWindowMac::MacGetClippedRect() const | |
1709 | { | |
1710 | MacUpdateClippedRects() ; | |
1711 | ||
1712 | return m_cachedClippedRect ; | |
1713 | } | |
1714 | ||
1715 | const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const | |
1716 | { | |
1717 | MacUpdateClippedRects() ; | |
1718 | ||
1719 | return m_cachedClippedRectWithOuterStructure ; | |
1720 | } | |
1721 | ||
1722 | const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) | |
1723 | { | |
1724 | static wxRegion emptyrgn ; | |
1725 | ||
1726 | if ( !m_isBeingDeleted && IsShownOnScreen() ) | |
1727 | { | |
1728 | MacUpdateClippedRects() ; | |
1729 | if ( includeOuterStructures ) | |
1730 | return m_cachedClippedRegionWithOuterStructure ; | |
1731 | else | |
1732 | return m_cachedClippedRegion ; | |
1733 | } | |
1734 | else | |
1735 | { | |
1736 | return emptyrgn ; | |
1737 | } | |
1738 | } | |
1739 | ||
1740 | void wxWindowMac::MacUpdateClippedRects() const | |
1741 | { | |
1742 | #if wxOSX_USE_CARBON | |
1743 | if ( m_cachedClippedRectValid ) | |
1744 | return ; | |
1745 | ||
1746 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. | |
1747 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
1748 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
1749 | // to add focus borders everywhere | |
1750 | ||
1751 | Rect rIncludingOuterStructures ; | |
1752 | ||
1753 | int tx,ty,tw,th; | |
1754 | ||
1755 | m_peer->GetSize( tw, th ); | |
1756 | m_peer->GetPosition( tx, ty ); | |
1757 | ||
1758 | Rect r = { ty,tx, ty+th, tx+tw }; | |
1759 | ||
1760 | r.left -= MacGetLeftBorderSize() ; | |
1761 | r.top -= MacGetTopBorderSize() ; | |
1762 | r.bottom += MacGetBottomBorderSize() ; | |
1763 | r.right += MacGetRightBorderSize() ; | |
1764 | ||
1765 | r.right -= r.left ; | |
1766 | r.bottom -= r.top ; | |
1767 | r.left = 0 ; | |
1768 | r.top = 0 ; | |
1769 | ||
1770 | rIncludingOuterStructures = r ; | |
1771 | InsetRect( &rIncludingOuterStructures , -4 , -4 ) ; | |
1772 | ||
1773 | wxRect cl = GetClientRect() ; | |
1774 | Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ; | |
1775 | ||
1776 | int x , y ; | |
1777 | wxSize size ; | |
1778 | const wxWindow* child = (wxWindow*) this ; | |
1779 | const wxWindow* parent = NULL ; | |
1780 | ||
1781 | while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL ) | |
1782 | { | |
1783 | if ( parent->MacIsChildOfClientArea(child) ) | |
1784 | { | |
1785 | size = parent->GetClientSize() ; | |
1786 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
1787 | x = origin.x ; | |
1788 | y = origin.y ; | |
1789 | } | |
1790 | else | |
1791 | { | |
1792 | // this will be true for scrollbars, toolbars etc. | |
1793 | size = parent->GetSize() ; | |
1794 | y = parent->MacGetTopBorderSize() ; | |
1795 | x = parent->MacGetLeftBorderSize() ; | |
1796 | size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ; | |
1797 | size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ; | |
1798 | } | |
1799 | ||
1800 | parent->MacWindowToRootWindow( &x, &y ) ; | |
1801 | MacRootWindowToWindow( &x , &y ) ; | |
1802 | ||
1803 | Rect rparent = { y , x , y + size.y , x + size.x } ; | |
1804 | ||
1805 | // the wxwindow and client rects will always be clipped | |
1806 | SectRect( &r , &rparent , &r ) ; | |
1807 | SectRect( &rClient , &rparent , &rClient ) ; | |
1808 | ||
1809 | // the structure only at 'hard' borders | |
1810 | if ( parent->MacClipChildren() || | |
1811 | ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) ) | |
1812 | { | |
1813 | SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ; | |
1814 | } | |
1815 | ||
1816 | child = parent ; | |
1817 | } | |
1818 | ||
1819 | m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ; | |
1820 | m_cachedClippedClientRect = wxRect( rClient.left , rClient.top , | |
1821 | rClient.right - rClient.left , rClient.bottom - rClient.top ) ; | |
1822 | m_cachedClippedRectWithOuterStructure = wxRect( | |
1823 | rIncludingOuterStructures.left , rIncludingOuterStructures.top , | |
1824 | rIncludingOuterStructures.right - rIncludingOuterStructures.left , | |
1825 | rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ; | |
1826 | ||
1827 | m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ; | |
1828 | m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ; | |
1829 | m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ; | |
1830 | ||
1831 | m_cachedClippedRectValid = true ; | |
1832 | #endif | |
1833 | } | |
1834 | ||
1835 | /* | |
1836 | This function must not change the updatergn ! | |
1837 | */ | |
1838 | bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) | |
1839 | { | |
1840 | bool handled = false ; | |
1841 | #if wxOSX_USE_CARBON | |
1842 | Rect updatebounds ; | |
1843 | RgnHandle updatergn = (RgnHandle) updatergnr ; | |
1844 | GetRegionBounds( updatergn , &updatebounds ) ; | |
1845 | ||
1846 | // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ; | |
1847 | ||
1848 | if ( !EmptyRgn(updatergn) ) | |
1849 | { | |
1850 | RgnHandle newupdate = NewRgn() ; | |
1851 | wxSize point = GetClientSize() ; | |
1852 | wxPoint origin = GetClientAreaOrigin() ; | |
1853 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ; | |
1854 | SectRgn( newupdate , updatergn , newupdate ) ; | |
1855 | ||
1856 | // first send an erase event to the entire update area | |
1857 | { | |
1858 | // for the toplevel window this really is the entire area | |
1859 | // for all the others only their client area, otherwise they | |
1860 | // might be drawing with full alpha and eg put blue into | |
1861 | // the grow-box area of a scrolled window (scroll sample) | |
1862 | wxDC* dc = new wxWindowDC(this); | |
1863 | if ( IsTopLevel() ) | |
f55d9f74 | 1864 | dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn))); |
524c47aa | 1865 | else |
f55d9f74 | 1866 | dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate))); |
524c47aa SC |
1867 | |
1868 | wxEraseEvent eevent( GetId(), dc ); | |
1869 | eevent.SetEventObject( this ); | |
1870 | HandleWindowEvent( eevent ); | |
1871 | delete dc ; | |
1872 | } | |
1873 | ||
1874 | MacPaintGrowBox(); | |
1875 | ||
1876 | // calculate a client-origin version of the update rgn and set m_updateRegion to that | |
1877 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1878 | m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ; | |
1879 | DisposeRgn( newupdate ) ; | |
1880 | ||
1881 | if ( !m_updateRegion.Empty() ) | |
1882 | { | |
1883 | // paint the window itself | |
1884 | ||
1885 | wxPaintEvent event; | |
1886 | event.SetTimestamp(time); | |
1887 | event.SetEventObject(this); | |
1888 | HandleWindowEvent(event); | |
1889 | handled = true ; | |
1890 | } | |
1891 | ||
1892 | // now we cannot rely on having its borders drawn by a window itself, as it does not | |
1893 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
1894 | // this would also be the place to draw any custom backgrounds for native controls | |
1895 | // in Composited windowing | |
1896 | wxPoint clientOrigin = GetClientAreaOrigin() ; | |
1897 | ||
1898 | wxWindowMac *child; | |
1899 | int x, y, w, h; | |
1900 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1901 | { | |
1902 | child = node->GetData(); | |
1903 | if (child == NULL) | |
1904 | continue; | |
1905 | if (child == m_vScrollBar) | |
1906 | continue; | |
1907 | if (child == m_hScrollBar) | |
1908 | continue; | |
1909 | if (child->IsTopLevel()) | |
1910 | continue; | |
1911 | if (!child->IsShown()) | |
1912 | continue; | |
1913 | ||
1914 | // only draw those in the update region (add a safety margin of 10 pixels for shadow effects | |
1915 | ||
1916 | child->GetPosition( &x, &y ); | |
1917 | child->GetSize( &w, &h ); | |
1918 | Rect childRect = { y , x , y + h , x + w } ; | |
1919 | OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; | |
1920 | InsetRect( &childRect , -10 , -10) ; | |
1921 | ||
1922 | if ( RectInRgn( &childRect , updatergn ) ) | |
1923 | { | |
1924 | // paint custom borders | |
1925 | wxNcPaintEvent eventNc( child->GetId() ); | |
1926 | eventNc.SetEventObject( child ); | |
1927 | if ( !child->HandleWindowEvent( eventNc ) ) | |
1928 | { | |
1929 | child->MacPaintBorders(0, 0) ; | |
1930 | } | |
1931 | } | |
1932 | } | |
1933 | } | |
1934 | #endif | |
1935 | return handled ; | |
1936 | } | |
1937 | ||
1938 | ||
1939 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const | |
1940 | { | |
1941 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); | |
1942 | return tlw ? tlw->GetWXWindow() : NULL ; | |
1943 | } | |
1944 | ||
1945 | bool wxWindowMac::MacHasScrollBarCorner() const | |
1946 | { | |
1947 | /* Returns whether the scroll bars in a wxScrolledWindow should be | |
1948 | * shortened. Scroll bars should be shortened if either: | |
1949 | * | |
1950 | * - both scroll bars are visible, or | |
1951 | * | |
1952 | * - there is a resize box in the parent frame's corner and this | |
1953 | * window shares the bottom and right edge with the parent | |
1954 | * frame. | |
1955 | */ | |
1956 | ||
1957 | if ( m_hScrollBar == NULL && m_vScrollBar == NULL ) | |
1958 | return false; | |
1959 | ||
1960 | if ( ( m_hScrollBar && m_hScrollBar->IsShown() ) | |
1961 | && ( m_vScrollBar && m_vScrollBar->IsShown() ) ) | |
1962 | { | |
1963 | // Both scroll bars visible | |
1964 | return true; | |
1965 | } | |
1966 | else | |
1967 | { | |
1968 | wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight(); | |
1969 | ||
1970 | for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() ) | |
1971 | { | |
1972 | const wxFrame *frame = wxDynamicCast( win, wxFrame ) ; | |
1973 | if ( frame ) | |
1974 | { | |
1975 | if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER ) | |
1976 | { | |
1977 | // Parent frame has resize handle | |
1978 | wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight(); | |
1979 | ||
1980 | // Note: allow for some wiggle room here as wxMac's | |
1981 | // window rect calculations seem to be imprecise | |
1982 | if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2 | |
1983 | && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 ) | |
1984 | { | |
1985 | // Parent frame has resize handle and shares | |
1986 | // right bottom corner | |
1987 | return true ; | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | // Parent frame has resize handle but doesn't | |
1992 | // share right bottom corner | |
1993 | return false ; | |
1994 | } | |
1995 | } | |
1996 | else | |
1997 | { | |
1998 | // Parent frame doesn't have resize handle | |
1999 | return false ; | |
2000 | } | |
2001 | } | |
2002 | } | |
2003 | ||
2004 | // No parent frame found | |
2005 | return false ; | |
2006 | } | |
2007 | } | |
2008 | ||
2009 | void wxWindowMac::MacCreateScrollBars( long style ) | |
2010 | { | |
2011 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; | |
2012 | ||
2013 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) | |
2014 | { | |
2015 | int scrlsize = MAC_SCROLLBAR_SIZE ; | |
2016 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
2017 | { | |
2018 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
2019 | } | |
2020 | ||
2021 | int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ; | |
2022 | int width, height ; | |
2023 | GetClientSize( &width , &height ) ; | |
2024 | ||
2025 | wxPoint vPoint(width - scrlsize, 0) ; | |
2026 | wxSize vSize(scrlsize, height - adjust) ; | |
2027 | wxPoint hPoint(0, height - scrlsize) ; | |
2028 | wxSize hSize(width - adjust, scrlsize) ; | |
2029 | ||
2030 | // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize) | |
2031 | if ( style & wxVSCROLL ) | |
2032 | { | |
2033 | m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL); | |
2034 | m_vScrollBar->SetMinSize( wxDefaultSize ); | |
2035 | } | |
2036 | ||
2037 | if ( style & wxHSCROLL ) | |
2038 | { | |
2039 | m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL); | |
2040 | m_hScrollBar->SetMinSize( wxDefaultSize ); | |
2041 | } | |
2042 | } | |
2043 | ||
2044 | // because the create does not take into account the client area origin | |
2045 | // we might have a real position shift | |
2046 | MacRepositionScrollBars() ; | |
2047 | } | |
2048 | ||
2049 | bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const | |
2050 | { | |
2051 | bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar))); | |
2052 | ||
2053 | return result ; | |
2054 | } | |
2055 | ||
2056 | void wxWindowMac::MacRepositionScrollBars() | |
2057 | { | |
2058 | if ( !m_hScrollBar && !m_vScrollBar ) | |
2059 | return ; | |
2060 | ||
2061 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
2062 | int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ; | |
2063 | ||
2064 | // get real client area | |
2065 | int width, height ; | |
2066 | GetSize( &width , &height ); | |
2067 | ||
2068 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2069 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
2070 | ||
2071 | wxPoint vPoint( width - scrlsize, 0 ) ; | |
2072 | wxSize vSize( scrlsize, height - adjust ) ; | |
2073 | wxPoint hPoint( 0 , height - scrlsize ) ; | |
2074 | wxSize hSize( width - adjust, scrlsize ) ; | |
2075 | ||
2076 | if ( m_vScrollBar ) | |
2077 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE ); | |
2078 | if ( m_hScrollBar ) | |
2079 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE ); | |
2080 | } | |
2081 | ||
2082 | bool wxWindowMac::AcceptsFocus() const | |
2083 | { | |
2084 | return m_peer->CanFocus() && wxWindowBase::AcceptsFocus(); | |
2085 | } | |
2086 | ||
2087 | void wxWindowMac::MacSuperChangedPosition() | |
2088 | { | |
2089 | // only window-absolute structures have to be moved i.e. controls | |
2090 | ||
2091 | m_cachedClippedRectValid = false ; | |
2092 | ||
2093 | wxWindowMac *child; | |
2094 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2095 | while ( node ) | |
2096 | { | |
2097 | child = node->GetData(); | |
2098 | child->MacSuperChangedPosition() ; | |
2099 | ||
2100 | node = node->GetNext(); | |
2101 | } | |
2102 | } | |
2103 | ||
2104 | void wxWindowMac::MacTopLevelWindowChangedPosition() | |
2105 | { | |
2106 | // only screen-absolute structures have to be moved i.e. glcanvas | |
2107 | ||
2108 | wxWindowMac *child; | |
2109 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2110 | while ( node ) | |
2111 | { | |
2112 | child = node->GetData(); | |
2113 | child->MacTopLevelWindowChangedPosition() ; | |
2114 | ||
2115 | node = node->GetNext(); | |
2116 | } | |
2117 | } | |
2118 | ||
2119 | long wxWindowMac::MacGetLeftBorderSize() const | |
2120 | { | |
2121 | if ( IsTopLevel() ) | |
2122 | return 0 ; | |
2123 | ||
2124 | SInt32 border = 0 ; | |
2125 | ||
2126 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) | |
2127 | { | |
2128 | #if wxOSX_USE_COCOA_OR_CARBON | |
2129 | // this metric is only the 'outset' outside the simple frame rect | |
2130 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2131 | border += 1; | |
2132 | #else | |
2133 | border += 2; | |
2134 | #endif | |
2135 | } | |
2136 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2137 | { | |
2138 | #if wxOSX_USE_COCOA_OR_CARBON | |
2139 | // this metric is only the 'outset' outside the simple frame rect | |
2140 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2141 | border += 1; | |
2142 | #else | |
2143 | border += 1; | |
2144 | #endif | |
2145 | } | |
2146 | ||
2147 | return border ; | |
2148 | } | |
2149 | ||
2150 | long wxWindowMac::MacGetRightBorderSize() const | |
2151 | { | |
2152 | // they are all symmetric in mac themes | |
2153 | return MacGetLeftBorderSize() ; | |
2154 | } | |
2155 | ||
2156 | long wxWindowMac::MacGetTopBorderSize() const | |
2157 | { | |
2158 | // they are all symmetric in mac themes | |
2159 | return MacGetLeftBorderSize() ; | |
2160 | } | |
2161 | ||
2162 | long wxWindowMac::MacGetBottomBorderSize() const | |
2163 | { | |
2164 | // they are all symmetric in mac themes | |
2165 | return MacGetLeftBorderSize() ; | |
2166 | } | |
2167 | ||
2168 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) | |
2169 | { | |
2170 | return style & ~wxBORDER_MASK ; | |
2171 | } | |
2172 | ||
2173 | // Find the wxWindowMac at the current mouse position, returning the mouse | |
2174 | // position. | |
2175 | wxWindow * wxFindWindowAtPointer( wxPoint& pt ) | |
2176 | { | |
2177 | pt = wxGetMousePosition(); | |
2178 | wxWindowMac* found = wxFindWindowAtPoint(pt); | |
2179 | ||
2180 | return (wxWindow*) found; | |
2181 | } | |
2182 | ||
2183 | // Get the current mouse position. | |
2184 | wxPoint wxGetMousePosition() | |
2185 | { | |
2186 | int x, y; | |
2187 | ||
2188 | wxGetMousePosition( &x, &y ); | |
2189 | ||
2190 | return wxPoint(x, y); | |
2191 | } | |
2192 | ||
2193 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) | |
2194 | { | |
2195 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
2196 | { | |
2197 | // copied from wxGTK : CS | |
2198 | // VZ: shouldn't we move this to base class then? | |
2199 | ||
2200 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN | |
2201 | // except that: | |
2202 | // | |
2203 | // (a) it's a command event and so is propagated to the parent | |
2204 | // (b) under MSW it can be generated from kbd too | |
2205 | // (c) it uses screen coords (because of (a)) | |
2206 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
2207 | this->GetId(), | |
2208 | this->ClientToScreen(event.GetPosition())); | |
2209 | evtCtx.SetEventObject(this); | |
2210 | if ( ! HandleWindowEvent(evtCtx) ) | |
2211 | event.Skip() ; | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | event.Skip() ; | |
2216 | } | |
2217 | } | |
2218 | ||
2219 | void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) ) | |
2220 | { | |
2221 | #if wxOSX_USE_COCOA_OR_CARBON | |
2222 | // for native controls: call their native paint method | |
2223 | if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) ) | |
2224 | { | |
2225 | if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL | |
2226 | && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT ) | |
2227 | CallNextEventHandler( | |
2228 | (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , | |
2229 | (EventRef) wxTheApp->MacGetCurrentEvent() ) ; | |
2230 | } | |
2231 | #endif | |
2232 | } | |
2233 | ||
2234 | void wxWindowMac::MacHandleControlClick(WXWidget WXUNUSED(control), | |
2235 | wxInt16 WXUNUSED(controlpart), | |
2236 | bool WXUNUSED(mouseStillDown)) | |
2237 | { | |
2238 | } | |
2239 | ||
2240 | Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) | |
2241 | { | |
2242 | int x, y, w, h ; | |
2243 | ||
2244 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ; | |
2245 | Rect bounds = { y, x, y + h, x + w }; | |
2246 | ||
2247 | return bounds ; | |
2248 | } | |
2249 | ||
2250 | bool wxWindowMac::HandleClicked( double timestampsec ) | |
2251 | { | |
2252 | return false; | |
2253 | } | |
2254 | ||
2255 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event ) | |
2256 | { | |
2257 | #if wxOSX_USE_COCOA_OR_CARBON | |
2258 | if ( HandleClicked( GetEventTime((EventRef)event) ) ) | |
2259 | return noErr; | |
2260 | ||
2261 | return eventNotHandledErr ; | |
2262 | #else | |
2263 | return 0; | |
2264 | #endif | |
2265 | } | |
2266 | ||
2267 | bool wxWindowMac::Reparent(wxWindowBase *newParentBase) | |
2268 | { | |
2269 | wxWindowMac *newParent = (wxWindowMac *)newParentBase; | |
2270 | if ( !wxWindowBase::Reparent(newParent) ) | |
2271 | return false; | |
2272 | ||
2273 | m_peer->RemoveFromParent(); | |
2274 | m_peer->Embed( GetParent()->GetPeer() ); | |
2275 | return true; | |
2276 | } | |
2277 | ||
2278 | bool wxWindowMac::SetTransparent(wxByte alpha) | |
2279 | { | |
2280 | SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); | |
2281 | ||
2282 | if ( alpha != m_macAlpha ) | |
2283 | { | |
2284 | m_macAlpha = alpha ; | |
2285 | Refresh() ; | |
2286 | } | |
2287 | return true ; | |
2288 | } | |
2289 | ||
2290 | ||
2291 | bool wxWindowMac::CanSetTransparent() | |
2292 | { | |
2293 | return true ; | |
2294 | } | |
2295 | ||
2296 | wxByte wxWindowMac::GetTransparent() const | |
2297 | { | |
2298 | return m_macAlpha ; | |
2299 | } | |
2300 | ||
2301 | bool wxWindowMac::IsShownOnScreen() const | |
2302 | { | |
2303 | if ( m_peer && m_peer->IsOk() ) | |
2304 | { | |
2305 | bool peerVis = m_peer->IsVisible(); | |
2306 | bool wxVis = wxWindowBase::IsShownOnScreen(); | |
2307 | if( peerVis != wxVis ) | |
2308 | { | |
2309 | // CS : put a breakpoint here to investigate differences | |
2310 | // between native an wx visibilities | |
2311 | // the only place where I've encountered them until now | |
2312 | // are the hiding/showing sequences where the vis-changed event is | |
2313 | // first sent to the innermost control, while wx does things | |
2314 | // from the outmost control | |
2315 | wxVis = wxWindowBase::IsShownOnScreen(); | |
2316 | return wxVis; | |
2317 | } | |
2318 | ||
2319 | return m_peer->IsVisible(); | |
2320 | } | |
2321 | return wxWindowBase::IsShownOnScreen(); | |
2322 | } | |
2323 | ||
2324 | // | |
2325 | // wxWidgetImpl | |
2326 | // | |
2327 | ||
f55d9f74 SC |
2328 | WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap); |
2329 | ||
2330 | static MacControlMap wxWinMacControlList; | |
2331 | ||
2332 | wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl ) | |
2333 | { | |
2334 | wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl ); | |
2335 | if ( impl ) | |
2336 | return impl->GetWXPeer(); | |
2337 | ||
2338 | return NULL; | |
2339 | } | |
2340 | ||
2341 | wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl ) | |
2342 | { | |
2343 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
2344 | ||
2345 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
2346 | } | |
2347 | ||
2348 | void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl) | |
2349 | { | |
2350 | // adding NULL ControlRef is (first) surely a result of an error and | |
2351 | // (secondly) breaks native event processing | |
2352 | wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") ); | |
2353 | ||
2354 | wxWinMacControlList[inControl] = impl; | |
2355 | } | |
2356 | ||
2357 | void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl) | |
2358 | { | |
2359 | // iterate over all the elements in the class | |
2360 | // is the iterator stable ? as we might have two associations pointing to the same wxWindow | |
2361 | // we should go on... | |
2362 | ||
2363 | bool found = true ; | |
2364 | while ( found ) | |
2365 | { | |
2366 | found = false ; | |
2367 | MacControlMap::iterator it; | |
2368 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
2369 | { | |
2370 | if ( it->second == impl ) | |
2371 | { | |
2372 | wxWinMacControlList.erase(it); | |
2373 | found = true ; | |
2374 | break; | |
2375 | } | |
2376 | } | |
2377 | } | |
2378 | } | |
2379 | ||
524c47aa SC |
2380 | IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject ) |
2381 | ||
2382 | wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl ) | |
2383 | { | |
2384 | Init(); | |
2385 | m_isRootControl = isRootControl; | |
2386 | m_wxPeer = peer; | |
2387 | } | |
2388 | ||
2389 | wxWidgetImpl::wxWidgetImpl() | |
2390 | { | |
2391 | Init(); | |
2392 | } | |
2393 | ||
2394 | wxWidgetImpl::~wxWidgetImpl() | |
2395 | { | |
2396 | } | |
2397 | ||
2398 | void wxWidgetImpl::Init() | |
2399 | { | |
2400 | m_isRootControl = false; | |
2401 | m_wxPeer = NULL; | |
2402 | m_needsFocusRect = false; | |
2403 | } | |
2404 | ||
2405 | void wxWidgetImpl::SetNeedsFocusRect( bool needs ) | |
2406 | { | |
2407 | m_needsFocusRect = needs; | |
2408 | } | |
2409 | ||
2410 | bool wxWidgetImpl::NeedsFocusRect() const | |
2411 | { | |
2412 | return m_needsFocusRect; | |
2413 | } | |
2414 |