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