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