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