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