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