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