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