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