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