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