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