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