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