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