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