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