]> git.saurik.com Git - wxWidgets.git/blame - src/osx/window_osx.cpp
fixing 64 bit compile
[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
967 return;
968 }
969
970 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
971 {
972 if ( x == wxDefaultCoord )
973 x = currentX;
974 if ( y == wxDefaultCoord )
975 y = currentY;
976 }
977
978 AdjustForParentClientOrigin( x, y, sizeFlags );
979
980 wxSize size = wxDefaultSize;
981 if ( width == wxDefaultCoord )
982 {
983 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
984 {
985 size = DoGetBestSize();
986 width = size.x;
987 }
988 else
989 {
990 // just take the current one
991 width = currentW;
992 }
993 }
994
995 if ( height == wxDefaultCoord )
996 {
997 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
998 {
999 if ( size.x == wxDefaultCoord )
1000 size = DoGetBestSize();
1001 // else: already called DoGetBestSize() above
1002
1003 height = size.y;
1004 }
1005 else
1006 {
1007 // just take the current one
1008 height = currentH;
1009 }
1010 }
1011
1012 DoMoveWindow( x, y, width, height );
1013}
1014
1015wxPoint wxWindowMac::GetClientAreaOrigin() const
1016{
1017 int left,top,width,height;
1018 m_peer->GetContentArea( left , top , width , height);
1019 return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() );
1020}
1021
1022void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1023{
1024 if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
1025 {
1026 int currentclientwidth , currentclientheight ;
1027 int currentwidth , currentheight ;
1028
1029 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1030 GetSize( &currentwidth , &currentheight ) ;
1031
1032 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1033 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1034 }
1035}
1036
1037void wxWindowMac::SetLabel(const wxString& title)
1038{
1039 m_label = title ;
1040
1041 if ( m_peer && m_peer->IsOk() )
1042 m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
1043
1044 // do not trigger refreshes upon invisible and possible partly created objects
1045 if ( IsShownOnScreen() )
1046 Refresh() ;
1047}
1048
1049wxString wxWindowMac::GetLabel() const
1050{
1051 return m_label ;
1052}
1053
1054bool wxWindowMac::Show(bool show)
1055{
1056 if ( !wxWindowBase::Show(show) )
1057 return false;
1058
1059 if ( m_peer )
1060 m_peer->SetVisibility( show ) ;
1061
1062 return true;
1063}
1064
1065void wxWindowMac::DoEnable(bool enable)
1066{
1067 m_peer->Enable( enable ) ;
1068}
1069
1070//
1071// status change notifications
1072//
1073
1074void wxWindowMac::MacVisibilityChanged()
1075{
1076}
1077
1078void wxWindowMac::MacHiliteChanged()
1079{
1080}
1081
1082void wxWindowMac::MacEnabledStateChanged()
1083{
1084 OnEnabled( m_peer->IsEnabled() );
1085}
1086
1087//
1088// status queries on the inherited window's state
1089//
1090
1091bool wxWindowMac::MacIsReallyEnabled()
1092{
1093 return m_peer->IsEnabled() ;
1094}
1095
1096bool wxWindowMac::MacIsReallyHilited()
1097{
1098#if wxOSX_USE_CARBON
1099 return m_peer->IsActive();
1100#else
1101 return true; // TODO
1102#endif
1103}
1104
1105int wxWindowMac::GetCharHeight() const
1106{
f55d9f74
SC
1107 wxCoord height;
1108 GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
524c47aa 1109
f55d9f74 1110 return height;
524c47aa
SC
1111}
1112
1113int wxWindowMac::GetCharWidth() const
1114{
f55d9f74
SC
1115 wxCoord width;
1116 GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
524c47aa 1117
f55d9f74 1118 return width;
524c47aa
SC
1119}
1120
f55d9f74 1121void wxWindowMac::GetTextExtent(const wxString& str, int *x, int *y,
524c47aa
SC
1122 int *descent, int *externalLeading, const wxFont *theFont ) const
1123{
1124 const wxFont *fontToUse = theFont;
1125 wxFont tempFont;
1126 if ( !fontToUse )
1127 {
1128 tempFont = GetFont();
1129 fontToUse = &tempFont;
1130 }
1131
f55d9f74
SC
1132 wxGraphicsContext* ctx = wxGraphicsContext::Create();
1133 ctx->SetFont( *fontToUse, *wxBLACK );
1134
1135 wxDouble h , d , e , w;
1136 ctx->GetTextExtent( str, &w, &h, &d, &e );
1137
1138 delete ctx;
1139
524c47aa 1140 if ( externalLeading )
f55d9f74 1141 *externalLeading = (wxCoord)(e+0.5);
524c47aa 1142 if ( descent )
f55d9f74 1143 *descent = (wxCoord)(d+0.5);
524c47aa 1144 if ( x )
f55d9f74 1145 *x = (wxCoord)(w+0.5);
524c47aa 1146 if ( y )
f55d9f74 1147 *y = (wxCoord)(h+0.5);
524c47aa
SC
1148}
1149
1150/*
1151 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1152 * we always intersect with the entire window, not only with the client area
1153 */
1154
1155void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
1156{
1157 if ( m_peer == NULL )
1158 return ;
1159
1160 if ( !IsShownOnScreen() )
1161 return ;
1162
1163 m_peer->SetNeedsDisplay( rect ) ;
1164}
1165
1166void wxWindowMac::DoFreeze()
1167{
1168#if wxOSX_USE_CARBON
1169 if ( m_peer && m_peer->IsOk() )
1170 m_peer->SetDrawingEnabled( false ) ;
1171#endif
1172}
1173
1174void wxWindowMac::DoThaw()
1175{
1176#if wxOSX_USE_CARBON
1177 if ( m_peer && m_peer->IsOk() )
1178 {
1179 m_peer->SetDrawingEnabled( true ) ;
1180 m_peer->InvalidateWithChildren() ;
1181 }
1182#endif
1183}
1184
1185wxWindow *wxGetActiveWindow()
1186{
1187 // actually this is a windows-only concept
1188 return NULL;
1189}
1190
1191// Coordinates relative to the window
1192void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos))
1193{
1194 // We really don't move the mouse programmatically under Mac.
1195}
1196
1197void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1198{
1199 if ( MacGetTopLevelWindow() == NULL )
1200 return ;
1201/*
1202#if TARGET_API_MAC_OSX
1203 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1204 {
1205 }
1206 else
1207#endif
1208*/
1209 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR )
1210 {
1211 event.GetDC()->Clear() ;
1212 }
1213 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
1214 {
1215 // don't skip the event here, custom background means that the app
1216 // is drawing it itself in its OnPaint(), so don't draw it at all
1217 // now to avoid flicker
1218 }
1219 else
1220 {
1221 event.Skip() ;
1222 }
1223}
1224
1225void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1226{
1227 event.Skip() ;
1228}
1229
1230int wxWindowMac::GetScrollPos(int orient) const
1231{
1232 if ( orient == wxHORIZONTAL )
1233 {
1234 if ( m_hScrollBar )
1235 return m_hScrollBar->GetThumbPosition() ;
1236 }
1237 else
1238 {
1239 if ( m_vScrollBar )
1240 return m_vScrollBar->GetThumbPosition() ;
1241 }
1242
1243 return 0;
1244}
1245
1246// This now returns the whole range, not just the number
1247// of positions that we can scroll.
1248int wxWindowMac::GetScrollRange(int orient) const
1249{
1250 if ( orient == wxHORIZONTAL )
1251 {
1252 if ( m_hScrollBar )
1253 return m_hScrollBar->GetRange() ;
1254 }
1255 else
1256 {
1257 if ( m_vScrollBar )
1258 return m_vScrollBar->GetRange() ;
1259 }
1260
1261 return 0;
1262}
1263
1264int wxWindowMac::GetScrollThumb(int orient) const
1265{
1266 if ( orient == wxHORIZONTAL )
1267 {
1268 if ( m_hScrollBar )
1269 return m_hScrollBar->GetThumbSize() ;
1270 }
1271 else
1272 {
1273 if ( m_vScrollBar )
1274 return m_vScrollBar->GetThumbSize() ;
1275 }
1276
1277 return 0;
1278}
1279
1280void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1281{
1282 if ( orient == wxHORIZONTAL )
1283 {
1284 if ( m_hScrollBar )
1285 m_hScrollBar->SetThumbPosition( pos ) ;
1286 }
1287 else
1288 {
1289 if ( m_vScrollBar )
1290 m_vScrollBar->SetThumbPosition( pos ) ;
1291 }
1292}
1293
1294void
1295wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag)
1296{
1297 bool needVisibilityUpdate = false;
1298
1299 if ( m_hScrollBarAlwaysShown != hflag )
1300 {
1301 m_hScrollBarAlwaysShown = hflag;
1302 needVisibilityUpdate = true;
1303 }
1304
1305 if ( m_vScrollBarAlwaysShown != vflag )
1306 {
1307 m_vScrollBarAlwaysShown = vflag;
1308 needVisibilityUpdate = true;
1309 }
1310
1311 if ( needVisibilityUpdate )
1312 DoUpdateScrollbarVisibility();
1313}
1314
1315//
1316// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1317// our own window origin is at leftOrigin/rightOrigin
1318//
1319
1320void wxWindowMac::MacPaintGrowBox()
1321{
1322 if ( IsTopLevel() )
1323 return ;
1324
1325 if ( MacHasScrollBarCorner() )
1326 {
1327 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
1328 wxASSERT( cgContext ) ;
1329
1330 int tx,ty,tw,th;
1331
1332 m_peer->GetSize( tw, th );
1333 m_peer->GetPosition( tx, ty );
1334
1335 Rect rect = { ty,tx, ty+th, tx+tw };
1336
1337
1338 int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
1339 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
1340 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
1341 CGContextSaveGState( cgContext );
1342
1343 if ( m_backgroundColour.Ok() )
1344 {
1345 CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() );
1346 }
1347 else
1348 {
1349 CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 );
1350 }
1351 CGContextFillRect( cgContext, cgrect );
1352 CGContextRestoreGState( cgContext );
1353 }
1354}
1355
1356void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
1357{
1358 if ( IsTopLevel() )
1359 return ;
1360
1361 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
1362
1363 // back to the surrounding frame rectangle
1364 int tx,ty,tw,th;
1365
1366 m_peer->GetSize( tw, th );
1367 m_peer->GetPosition( tx, ty );
1368
1369 Rect rect = { ty,tx, ty+th, tx+tw };
1370
1371#if wxOSX_USE_COCOA_OR_CARBON
1372
1373 InsetRect( &rect, -1 , -1 ) ;
1374
1375 {
1376 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
1377 rect.bottom - rect.top ) ;
1378
1379 HIThemeFrameDrawInfo info ;
1380 memset( &info, 0 , sizeof(info) ) ;
1381
1382 info.version = 0 ;
1383 info.kind = 0 ;
1384 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1385 info.isFocused = hasFocus ;
1386
1387 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
1388 wxASSERT( cgContext ) ;
1389
1390 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1391 {
1392 info.kind = kHIThemeFrameTextFieldSquare ;
1393 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1394 }
1395 else if ( HasFlag(wxSIMPLE_BORDER) )
1396 {
1397 info.kind = kHIThemeFrameListBox ;
1398 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1399 }
1400 else if ( hasFocus )
1401 {
1402 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
1403 }
1404#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1405 m_peer->GetRect( &rect ) ;
1406 if ( MacHasScrollBarCorner() )
1407 {
1408 int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant();
1409 int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
1410 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
1411 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
1412 HIThemeGrowBoxDrawInfo info ;
1413 memset( &info, 0, sizeof(info) ) ;
1414 info.version = 0 ;
1415 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1416 info.kind = kHIThemeGrowBoxKindNone ;
1417 // contrary to the docs ...SizeSmall does not work
1418 info.size = kHIThemeGrowBoxSizeNormal ;
1419 info.direction = 0 ;
1420 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
1421 }
1422#endif
1423 }
1424#endif // wxOSX_USE_COCOA_OR_CARBON
1425}
1426
1427void wxWindowMac::RemoveChild( wxWindowBase *child )
1428{
1429 if ( child == m_hScrollBar )
1430 m_hScrollBar = NULL ;
1431 if ( child == m_vScrollBar )
1432 m_vScrollBar = NULL ;
1433
1434 wxWindowBase::RemoveChild( child ) ;
1435}
1436
1437void wxWindowMac::DoUpdateScrollbarVisibility()
1438{
1439 bool triggerSizeEvent = false;
1440
1441 if ( m_hScrollBar )
1442 {
1443 bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded();
1444
1445 if ( m_hScrollBar->IsShown() != showHScrollBar )
1446 {
1447 m_hScrollBar->Show( showHScrollBar );
1448 triggerSizeEvent = true;
1449 }
1450 }
1451
1452 if ( m_vScrollBar)
1453 {
1454 bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded();
1455
1456 if ( m_vScrollBar->IsShown() != showVScrollBar )
1457 {
1458 m_vScrollBar->Show( showVScrollBar ) ;
1459 triggerSizeEvent = true;
1460 }
1461 }
1462
1463 MacRepositionScrollBars() ;
1464 if ( triggerSizeEvent )
1465 {
1466 wxSizeEvent event(GetSize(), m_windowId);
1467 event.SetEventObject(this);
1468 HandleWindowEvent(event);
1469 }
1470}
1471
1472// New function that will replace some of the above.
1473void wxWindowMac::SetScrollbar(int orient, int pos, int thumb,
1474 int range, bool refresh)
1475{
1476 if ( orient == wxHORIZONTAL && m_hScrollBar )
1477 m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1478 else if ( orient == wxVERTICAL && m_vScrollBar )
1479 m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1480
1481 DoUpdateScrollbarVisibility();
1482}
1483
1484// Does a physical scroll
1485void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1486{
1487 if ( dx == 0 && dy == 0 )
1488 return ;
1489
1490 int width , height ;
1491 GetClientSize( &width , &height ) ;
1492
1493 {
1494 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
1495 if ( rect )
1496 scrollrect.Intersect( *rect ) ;
1497 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1498 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1499
1500 m_peer->ScrollRect( &scrollrect, dx, dy );
1501 }
1502
1503 wxWindowMac *child;
1504 int x, y, w, h;
1505 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1506 {
1507 child = node->GetData();
1508 if (child == NULL)
1509 continue;
1510 if (child == m_vScrollBar)
1511 continue;
1512 if (child == m_hScrollBar)
1513 continue;
1514 if (child->IsTopLevel())
1515 continue;
1516
1517 child->GetPosition( &x, &y );
1518 child->GetSize( &w, &h );
1519 if (rect)
1520 {
1521 wxRect rc( x, y, w, h );
1522 if (rect->Intersects( rc ))
1523 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1524 }
1525 else
1526 {
1527 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1528 }
1529 }
1530}
1531
1532void wxWindowMac::MacOnScroll( wxScrollEvent &event )
1533{
1534 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
1535 {
1536 wxScrollWinEvent wevent;
1537 wevent.SetPosition(event.GetPosition());
1538 wevent.SetOrientation(event.GetOrientation());
1539 wevent.SetEventObject(this);
1540
1541 if (event.GetEventType() == wxEVT_SCROLL_TOP)
1542 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
1543 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
1544 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
1545 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
1546 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
1547 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
1548 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
1549 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
1550 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
1551 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
1552 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
1553 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
1554 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
1555 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
1556 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
1557
1558 HandleWindowEvent(wevent);
1559 }
1560}
1561
1562// Get the window with the focus
1563wxWindow *wxWindowBase::DoFindFocus()
1564{
1565#if wxOSX_USE_CARBON
1566 ControlRef control ;
1567 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
1568 return wxFindWindowFromWXWidget( (WXWidget) control ) ;
1569#else
1570 return NULL;
1571#endif
1572}
1573
1574void wxWindowMac::OnInternalIdle()
1575{
1576 // This calls the UI-update mechanism (querying windows for
1577 // menu/toolbar/control state information)
1578 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1579 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
1580}
1581
1582// Raise the window to the top of the Z order
1583void wxWindowMac::Raise()
1584{
1585 m_peer->Raise();
1586}
1587
1588// Lower the window to the bottom of the Z order
1589void wxWindowMac::Lower()
1590{
1591 m_peer->Lower();
1592}
1593
1594// static wxWindow *gs_lastWhich = NULL;
1595
1596bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
1597{
1598 // first trigger a set cursor event
1599
1600 wxPoint clientorigin = GetClientAreaOrigin() ;
1601 wxSize clientsize = GetClientSize() ;
1602 wxCursor cursor ;
1603 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1604 {
1605 wxSetCursorEvent event( pt.x , pt.y );
1606
1607 bool processedEvtSetCursor = HandleWindowEvent(event);
1608 if ( processedEvtSetCursor && event.HasCursor() )
1609 {
1610 cursor = event.GetCursor() ;
1611 }
1612 else
1613 {
1614 // the test for processedEvtSetCursor is here to prevent using m_cursor
1615 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1616 // it - this is a way to say that our cursor shouldn't be used for this
1617 // point
1618 if ( !processedEvtSetCursor && m_cursor.Ok() )
1619 cursor = m_cursor ;
1620
1621 if ( !wxIsBusy() && !GetParent() )
1622 cursor = *wxSTANDARD_CURSOR ;
1623 }
1624
1625 if ( cursor.Ok() )
1626 cursor.MacInstall() ;
1627 }
1628
1629 return cursor.Ok() ;
1630}
1631
1632wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) )
1633{
1634#if wxUSE_TOOLTIPS
1635 if ( m_tooltip )
1636 return m_tooltip->GetTip() ;
1637#endif
1638
1639 return wxEmptyString ;
1640}
1641
1642void wxWindowMac::ClearBackground()
1643{
1644 Refresh() ;
1645 Update() ;
1646}
1647
1648void wxWindowMac::Update()
1649{
1650 wxNonOwnedWindow* top = MacGetTopLevelWindow();
1651 if (top)
1652 top->Update() ;
1653}
1654
1655wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const
1656{
1657 wxWindowMac *iter = (wxWindowMac*)this ;
1658
1659 while ( iter )
1660 {
1661 if ( iter->IsTopLevel() )
1662 {
1663 wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow);
1664 if ( toplevel )
1665 return toplevel;
1666#if wxUSE_POPUPWIN
1667 wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow);
1668 if ( popupwin )
1669 return popupwin;
1670#endif
1671 }
1672 iter = iter->GetParent() ;
1673 }
1674
1675 return NULL ;
1676}
1677
1678const wxRect& wxWindowMac::MacGetClippedClientRect() const
1679{
1680 MacUpdateClippedRects() ;
1681
1682 return m_cachedClippedClientRect ;
1683}
1684
1685const wxRect& wxWindowMac::MacGetClippedRect() const
1686{
1687 MacUpdateClippedRects() ;
1688
1689 return m_cachedClippedRect ;
1690}
1691
1692const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1693{
1694 MacUpdateClippedRects() ;
1695
1696 return m_cachedClippedRectWithOuterStructure ;
1697}
1698
1699const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
1700{
1701 static wxRegion emptyrgn ;
1702
1703 if ( !m_isBeingDeleted && IsShownOnScreen() )
1704 {
1705 MacUpdateClippedRects() ;
1706 if ( includeOuterStructures )
1707 return m_cachedClippedRegionWithOuterStructure ;
1708 else
1709 return m_cachedClippedRegion ;
1710 }
1711 else
1712 {
1713 return emptyrgn ;
1714 }
1715}
1716
1717void wxWindowMac::MacUpdateClippedRects() const
1718{
1719#if wxOSX_USE_CARBON
1720 if ( m_cachedClippedRectValid )
1721 return ;
1722
1723 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1724 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1725 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1726 // to add focus borders everywhere
1727
1728 Rect rIncludingOuterStructures ;
1729
1730 int tx,ty,tw,th;
1731
1732 m_peer->GetSize( tw, th );
1733 m_peer->GetPosition( tx, ty );
1734
1735 Rect r = { ty,tx, ty+th, tx+tw };
1736
1737 r.left -= MacGetLeftBorderSize() ;
1738 r.top -= MacGetTopBorderSize() ;
1739 r.bottom += MacGetBottomBorderSize() ;
1740 r.right += MacGetRightBorderSize() ;
1741
1742 r.right -= r.left ;
1743 r.bottom -= r.top ;
1744 r.left = 0 ;
1745 r.top = 0 ;
1746
1747 rIncludingOuterStructures = r ;
1748 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
1749
1750 wxRect cl = GetClientRect() ;
1751 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
1752
1753 int x , y ;
1754 wxSize size ;
1755 const wxWindow* child = (wxWindow*) this ;
1756 const wxWindow* parent = NULL ;
1757
1758 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
1759 {
1760 if ( parent->MacIsChildOfClientArea(child) )
1761 {
1762 size = parent->GetClientSize() ;
1763 wxPoint origin = parent->GetClientAreaOrigin() ;
1764 x = origin.x ;
1765 y = origin.y ;
1766 }
1767 else
1768 {
1769 // this will be true for scrollbars, toolbars etc.
1770 size = parent->GetSize() ;
1771 y = parent->MacGetTopBorderSize() ;
1772 x = parent->MacGetLeftBorderSize() ;
1773 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
1774 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
1775 }
1776
1777 parent->MacWindowToRootWindow( &x, &y ) ;
1778 MacRootWindowToWindow( &x , &y ) ;
1779
1780 Rect rparent = { y , x , y + size.y , x + size.x } ;
1781
1782 // the wxwindow and client rects will always be clipped
1783 SectRect( &r , &rparent , &r ) ;
1784 SectRect( &rClient , &rparent , &rClient ) ;
1785
1786 // the structure only at 'hard' borders
1787 if ( parent->MacClipChildren() ||
1788 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
1789 {
1790 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
1791 }
1792
1793 child = parent ;
1794 }
1795
1796 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
1797 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
1798 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
1799 m_cachedClippedRectWithOuterStructure = wxRect(
1800 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
1801 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
1802 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
1803
1804 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
1805 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
1806 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
1807
1808 m_cachedClippedRectValid = true ;
1809#endif
1810}
1811
1812/*
1813 This function must not change the updatergn !
1814 */
1815bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
1816{
1817 bool handled = false ;
1818#if wxOSX_USE_CARBON
1819 Rect updatebounds ;
1820 RgnHandle updatergn = (RgnHandle) updatergnr ;
1821 GetRegionBounds( updatergn , &updatebounds ) ;
1822
1823 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1824
1825 if ( !EmptyRgn(updatergn) )
1826 {
1827 RgnHandle newupdate = NewRgn() ;
1828 wxSize point = GetClientSize() ;
1829 wxPoint origin = GetClientAreaOrigin() ;
1830 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ;
1831 SectRgn( newupdate , updatergn , newupdate ) ;
1832
1833 // first send an erase event to the entire update area
1834 {
1835 // for the toplevel window this really is the entire area
1836 // for all the others only their client area, otherwise they
1837 // might be drawing with full alpha and eg put blue into
1838 // the grow-box area of a scrolled window (scroll sample)
1839 wxDC* dc = new wxWindowDC(this);
1840 if ( IsTopLevel() )
f55d9f74 1841 dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn)));
524c47aa 1842 else
f55d9f74 1843 dc->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate)));
524c47aa
SC
1844
1845 wxEraseEvent eevent( GetId(), dc );
1846 eevent.SetEventObject( this );
1847 HandleWindowEvent( eevent );
1848 delete dc ;
1849 }
1850
1851 MacPaintGrowBox();
1852
1853 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1854 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1855 m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ;
1856 DisposeRgn( newupdate ) ;
1857
1858 if ( !m_updateRegion.Empty() )
1859 {
1860 // paint the window itself
1861
1862 wxPaintEvent event;
1863 event.SetTimestamp(time);
1864 event.SetEventObject(this);
1865 HandleWindowEvent(event);
1866 handled = true ;
1867 }
1868
1869 // now we cannot rely on having its borders drawn by a window itself, as it does not
1870 // get the updateRgn wide enough to always do so, so we do it from the parent
1871 // this would also be the place to draw any custom backgrounds for native controls
1872 // in Composited windowing
1873 wxPoint clientOrigin = GetClientAreaOrigin() ;
1874
1875 wxWindowMac *child;
1876 int x, y, w, h;
1877 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1878 {
1879 child = node->GetData();
1880 if (child == NULL)
1881 continue;
1882 if (child == m_vScrollBar)
1883 continue;
1884 if (child == m_hScrollBar)
1885 continue;
1886 if (child->IsTopLevel())
1887 continue;
1888 if (!child->IsShown())
1889 continue;
1890
1891 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1892
1893 child->GetPosition( &x, &y );
1894 child->GetSize( &w, &h );
1895 Rect childRect = { y , x , y + h , x + w } ;
1896 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
1897 InsetRect( &childRect , -10 , -10) ;
1898
1899 if ( RectInRgn( &childRect , updatergn ) )
1900 {
1901 // paint custom borders
1902 wxNcPaintEvent eventNc( child->GetId() );
1903 eventNc.SetEventObject( child );
1904 if ( !child->HandleWindowEvent( eventNc ) )
1905 {
1906 child->MacPaintBorders(0, 0) ;
1907 }
1908 }
1909 }
1910 }
1911#endif
1912 return handled ;
1913}
1914
1915
1916WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
1917{
1918 wxNonOwnedWindow* tlw = MacGetTopLevelWindow();
1919 return tlw ? tlw->GetWXWindow() : NULL ;
1920}
1921
1922bool wxWindowMac::MacHasScrollBarCorner() const
1923{
1924 /* Returns whether the scroll bars in a wxScrolledWindow should be
1925 * shortened. Scroll bars should be shortened if either:
1926 *
1927 * - both scroll bars are visible, or
1928 *
1929 * - there is a resize box in the parent frame's corner and this
1930 * window shares the bottom and right edge with the parent
1931 * frame.
1932 */
1933
1934 if ( m_hScrollBar == NULL && m_vScrollBar == NULL )
1935 return false;
1936
1937 if ( ( m_hScrollBar && m_hScrollBar->IsShown() )
1938 && ( m_vScrollBar && m_vScrollBar->IsShown() ) )
1939 {
1940 // Both scroll bars visible
1941 return true;
1942 }
1943 else
1944 {
1945 wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight();
1946
1947 for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() )
1948 {
1949 const wxFrame *frame = wxDynamicCast( win, wxFrame ) ;
1950 if ( frame )
1951 {
1952 if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER )
1953 {
1954 // Parent frame has resize handle
1955 wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight();
1956
1957 // Note: allow for some wiggle room here as wxMac's
1958 // window rect calculations seem to be imprecise
1959 if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2
1960 && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 )
1961 {
1962 // Parent frame has resize handle and shares
1963 // right bottom corner
1964 return true ;
1965 }
1966 else
1967 {
1968 // Parent frame has resize handle but doesn't
1969 // share right bottom corner
1970 return false ;
1971 }
1972 }
1973 else
1974 {
1975 // Parent frame doesn't have resize handle
1976 return false ;
1977 }
1978 }
1979 }
1980
1981 // No parent frame found
1982 return false ;
1983 }
1984}
1985
1986void wxWindowMac::MacCreateScrollBars( long style )
1987{
1988 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
1989
1990 if ( style & ( wxVSCROLL | wxHSCROLL ) )
1991 {
1992 int scrlsize = MAC_SCROLLBAR_SIZE ;
1993 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
1994 {
1995 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
1996 }
1997
1998 int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ;
1999 int width, height ;
2000 GetClientSize( &width , &height ) ;
2001
2002 wxPoint vPoint(width - scrlsize, 0) ;
2003 wxSize vSize(scrlsize, height - adjust) ;
2004 wxPoint hPoint(0, height - scrlsize) ;
2005 wxSize hSize(width - adjust, scrlsize) ;
2006
2007 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2008 if ( style & wxVSCROLL )
2009 {
2010 m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL);
2011 m_vScrollBar->SetMinSize( wxDefaultSize );
2012 }
2013
2014 if ( style & wxHSCROLL )
2015 {
2016 m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
2017 m_hScrollBar->SetMinSize( wxDefaultSize );
2018 }
2019 }
2020
2021 // because the create does not take into account the client area origin
2022 // we might have a real position shift
2023 MacRepositionScrollBars() ;
2024}
2025
2026bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
2027{
2028 bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar)));
2029
2030 return result ;
2031}
2032
2033void wxWindowMac::MacRepositionScrollBars()
2034{
2035 if ( !m_hScrollBar && !m_vScrollBar )
2036 return ;
2037
2038 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
2039 int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ;
2040
2041 // get real client area
2042 int width, height ;
2043 GetSize( &width , &height );
2044
2045 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2046 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2047
2048 wxPoint vPoint( width - scrlsize, 0 ) ;
2049 wxSize vSize( scrlsize, height - adjust ) ;
2050 wxPoint hPoint( 0 , height - scrlsize ) ;
2051 wxSize hSize( width - adjust, scrlsize ) ;
2052
2053 if ( m_vScrollBar )
2054 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
2055 if ( m_hScrollBar )
2056 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
2057}
2058
2059bool wxWindowMac::AcceptsFocus() const
2060{
2061 return m_peer->CanFocus() && wxWindowBase::AcceptsFocus();
2062}
2063
2064void wxWindowMac::MacSuperChangedPosition()
2065{
2066 // only window-absolute structures have to be moved i.e. controls
2067
2068 m_cachedClippedRectValid = false ;
2069
2070 wxWindowMac *child;
2071 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2072 while ( node )
2073 {
2074 child = node->GetData();
2075 child->MacSuperChangedPosition() ;
2076
2077 node = node->GetNext();
2078 }
2079}
2080
2081void wxWindowMac::MacTopLevelWindowChangedPosition()
2082{
2083 // only screen-absolute structures have to be moved i.e. glcanvas
2084
2085 wxWindowMac *child;
2086 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2087 while ( node )
2088 {
2089 child = node->GetData();
2090 child->MacTopLevelWindowChangedPosition() ;
2091
2092 node = node->GetNext();
2093 }
2094}
2095
2096long wxWindowMac::MacGetLeftBorderSize() const
2097{
2098 if ( IsTopLevel() )
2099 return 0 ;
2100
2101 SInt32 border = 0 ;
2102
2103 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
2104 {
2105#if wxOSX_USE_COCOA_OR_CARBON
2106 // this metric is only the 'outset' outside the simple frame rect
2107 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2108 border += 1;
2109#else
2110 border += 2;
2111#endif
2112 }
2113 else if (HasFlag(wxSIMPLE_BORDER))
2114 {
2115#if wxOSX_USE_COCOA_OR_CARBON
2116 // this metric is only the 'outset' outside the simple frame rect
2117 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2118 border += 1;
2119#else
2120 border += 1;
2121#endif
2122 }
2123
2124 return border ;
2125}
2126
2127long wxWindowMac::MacGetRightBorderSize() const
2128{
2129 // they are all symmetric in mac themes
2130 return MacGetLeftBorderSize() ;
2131}
2132
2133long wxWindowMac::MacGetTopBorderSize() const
2134{
2135 // they are all symmetric in mac themes
2136 return MacGetLeftBorderSize() ;
2137}
2138
2139long wxWindowMac::MacGetBottomBorderSize() const
2140{
2141 // they are all symmetric in mac themes
2142 return MacGetLeftBorderSize() ;
2143}
2144
2145long wxWindowMac::MacRemoveBordersFromStyle( long style )
2146{
2147 return style & ~wxBORDER_MASK ;
2148}
2149
2150// Find the wxWindowMac at the current mouse position, returning the mouse
2151// position.
2152wxWindow * wxFindWindowAtPointer( wxPoint& pt )
2153{
2154 pt = wxGetMousePosition();
2155 wxWindowMac* found = wxFindWindowAtPoint(pt);
2156
2157 return (wxWindow*) found;
2158}
2159
2160// Get the current mouse position.
2161wxPoint wxGetMousePosition()
2162{
2163 int x, y;
2164
2165 wxGetMousePosition( &x, &y );
2166
2167 return wxPoint(x, y);
2168}
2169
2170void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2171{
2172 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2173 {
2174 // copied from wxGTK : CS
2175 // VZ: shouldn't we move this to base class then?
2176
2177 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2178 // except that:
2179 //
2180 // (a) it's a command event and so is propagated to the parent
2181 // (b) under MSW it can be generated from kbd too
2182 // (c) it uses screen coords (because of (a))
2183 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2184 this->GetId(),
2185 this->ClientToScreen(event.GetPosition()));
2186 evtCtx.SetEventObject(this);
2187 if ( ! HandleWindowEvent(evtCtx) )
2188 event.Skip() ;
2189 }
2190 else
2191 {
2192 event.Skip() ;
2193 }
2194}
2195
2196void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) )
2197{
2198#if wxOSX_USE_COCOA_OR_CARBON
2199 // for native controls: call their native paint method
2200 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
2201 {
2202 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL
2203 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
2204 CallNextEventHandler(
2205 (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
2206 (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
2207 }
2208#endif
2209}
2210
19c7ac3d 2211void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
524c47aa
SC
2212{
2213}
2214
2215Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2216{
2217 int x, y, w, h ;
2218
2219 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
2220 Rect bounds = { y, x, y + h, x + w };
2221
2222 return bounds ;
2223}
2224
4eb5a0ec 2225bool wxWindowMac::OSXHandleClicked( double timestampsec )
524c47aa
SC
2226{
2227 return false;
2228}
2229
2230wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
2231{
2232#if wxOSX_USE_COCOA_OR_CARBON
4eb5a0ec 2233 if ( OSXHandleClicked( GetEventTime((EventRef)event) ) )
524c47aa
SC
2234 return noErr;
2235
2236 return eventNotHandledErr ;
2237#else
2238 return 0;
2239#endif
2240}
2241
2242bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
2243{
2244 wxWindowMac *newParent = (wxWindowMac *)newParentBase;
2245 if ( !wxWindowBase::Reparent(newParent) )
2246 return false;
2247
2248 m_peer->RemoveFromParent();
2249 m_peer->Embed( GetParent()->GetPeer() );
2250 return true;
2251}
2252
2253bool wxWindowMac::SetTransparent(wxByte alpha)
2254{
2255 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
2256
2257 if ( alpha != m_macAlpha )
2258 {
2259 m_macAlpha = alpha ;
2260 Refresh() ;
2261 }
2262 return true ;
2263}
2264
2265
2266bool wxWindowMac::CanSetTransparent()
2267{
2268 return true ;
2269}
2270
2271wxByte wxWindowMac::GetTransparent() const
2272{
2273 return m_macAlpha ;
2274}
2275
2276bool wxWindowMac::IsShownOnScreen() const
2277{
2278 if ( m_peer && m_peer->IsOk() )
2279 {
2280 bool peerVis = m_peer->IsVisible();
2281 bool wxVis = wxWindowBase::IsShownOnScreen();
2282 if( peerVis != wxVis )
2283 {
2284 // CS : put a breakpoint here to investigate differences
2285 // between native an wx visibilities
2286 // the only place where I've encountered them until now
2287 // are the hiding/showing sequences where the vis-changed event is
2288 // first sent to the innermost control, while wx does things
2289 // from the outmost control
2290 wxVis = wxWindowBase::IsShownOnScreen();
2291 return wxVis;
2292 }
2293
2294 return m_peer->IsVisible();
2295 }
2296 return wxWindowBase::IsShownOnScreen();
2297}
2298
4eb5a0ec 2299bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event )
19c7ac3d
SC
2300{
2301 bool handled = HandleWindowEvent( event ) ;
2302 if ( handled && event.GetSkipped() )
2303 handled = false ;
2304
2305#if wxUSE_ACCEL
2306 if ( !handled && event.GetEventType() == wxEVT_KEY_DOWN)
2307 {
2308 wxWindow *ancestor = this;
2309 while (ancestor)
2310 {
2311 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
2312 if (command != -1)
2313 {
2314 wxEvtHandler * const handler = ancestor->GetEventHandler();
2315
2316 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
2317 handled = handler->ProcessEvent( command_event );
2318
2319 if ( !handled )
2320 {
2321 // accelerators can also be used with buttons, try them too
2322 command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED);
2323 handled = handler->ProcessEvent( command_event );
2324 }
2325
2326 break;
2327 }
2328
2329 if (ancestor->IsTopLevel())
2330 break;
2331
2332 ancestor = ancestor->GetParent();
2333 }
2334 }
2335#endif // wxUSE_ACCEL
2336
2337 return handled ;
2338}
2339
524c47aa
SC
2340//
2341// wxWidgetImpl
2342//
2343
f55d9f74
SC
2344WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap);
2345
2346static MacControlMap wxWinMacControlList;
2347
2348wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
2349{
2350 wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl );
2351 if ( impl )
2352 return impl->GetWXPeer();
2353
2354 return NULL;
2355}
2356
2357wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl )
2358{
2359 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
2360
2361 return (node == wxWinMacControlList.end()) ? NULL : node->second;
2362}
2363
2364void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl)
2365{
2366 // adding NULL ControlRef is (first) surely a result of an error and
2367 // (secondly) breaks native event processing
2368 wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") );
2369
2370 wxWinMacControlList[inControl] = impl;
2371}
2372
2373void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl)
2374{
2375 // iterate over all the elements in the class
2376 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2377 // we should go on...
2378
2379 bool found = true ;
2380 while ( found )
2381 {
2382 found = false ;
2383 MacControlMap::iterator it;
2384 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
2385 {
2386 if ( it->second == impl )
2387 {
2388 wxWinMacControlList.erase(it);
2389 found = true ;
2390 break;
2391 }
2392 }
2393 }
2394}
2395
524c47aa
SC
2396IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
2397
2398wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
2399{
2400 Init();
2401 m_isRootControl = isRootControl;
2402 m_wxPeer = peer;
2403}
2404
2405wxWidgetImpl::wxWidgetImpl()
2406{
2407 Init();
2408}
2409
2410wxWidgetImpl::~wxWidgetImpl()
2411{
2412}
2413
2414void wxWidgetImpl::Init()
2415{
2416 m_isRootControl = false;
2417 m_wxPeer = NULL;
2418 m_needsFocusRect = false;
2419}
2420
2421void wxWidgetImpl::SetNeedsFocusRect( bool needs )
2422{
2423 m_needsFocusRect = needs;
2424}
2425
2426bool wxWidgetImpl::NeedsFocusRect() const
2427{
2428 return m_needsFocusRect;
2429}
2430