]> git.saurik.com Git - wxWidgets.git/blob - src/osx/window_osx.cpp
fix memory leak in SetColFormat() if the column already had an attribute (closes...
[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 if ( m_peer )
199 return (WXWidget) m_peer->GetWXWidget() ;
200 return NULL;
201 }
202
203 // ---------------------------------------------------------------------------
204 // Utility Routines to move between different coordinate systems
205 // ---------------------------------------------------------------------------
206
207 /*
208 * Right now we have the following setup :
209 * a border that is not part of the native control is always outside the
210 * control's border (otherwise we loose all native intelligence, future ways
211 * may be to have a second embedding control responsible for drawing borders
212 * and backgrounds eventually)
213 * so all this border calculations have to be taken into account when calling
214 * native methods or getting native oriented data
215 * so we have three coordinate systems here
216 * wx client coordinates
217 * wx window coordinates (including window frames)
218 * native coordinates
219 */
220
221 //
222 //
223
224 // Constructor
225 bool wxWindowMac::Create(wxWindowMac *parent,
226 wxWindowID id,
227 const wxPoint& pos,
228 const wxSize& size,
229 long style,
230 const wxString& name)
231 {
232 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
233
234 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
235 return false;
236
237 m_windowVariant = parent->GetWindowVariant() ;
238
239 if ( m_macIsUserPane )
240 {
241 m_peer = wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() );
242 MacPostControlCreate(pos, size) ;
243 }
244
245 #ifndef __WXUNIVERSAL__
246 // Don't give scrollbars to wxControls unless they ask for them
247 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar)))
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 ( m_vScrollBar )
263 m_vScrollBar->Raise() ;
264 if ( m_hScrollBar )
265 m_hScrollBar->Raise() ;
266 }
267
268 void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size)
269 {
270 wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ;
271
272 GetParent()->AddChild( this );
273
274 m_peer->InstallEventHandler();
275 m_peer->Embed(GetParent()->GetPeer());
276
277 GetParent()->MacChildAdded() ;
278
279 // adjust font, controlsize etc
280 DoSetWindowVariant( m_windowVariant ) ;
281
282 m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
283
284 // for controls we want to use best size for wxDefaultSize params )
285 if ( !m_macIsUserPane )
286 SetInitialSize(size);
287
288 SetCursor( *wxSTANDARD_CURSOR ) ;
289 }
290
291 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
292 {
293 // Don't assert, in case we set the window variant before
294 // the window is created
295 // wxASSERT( m_peer->Ok() ) ;
296
297 m_windowVariant = variant ;
298
299 if (m_peer == NULL || !m_peer->IsOk())
300 return;
301
302 m_peer->SetControlSize( variant );
303 #if wxOSX_USE_CARBON
304 ControlSize size ;
305
306 // we will get that from the settings later
307 // and make this NORMAL later, but first
308 // we have a few calculations that we must fix
309
310 switch ( variant )
311 {
312 case wxWINDOW_VARIANT_NORMAL :
313 size = kControlSizeNormal;
314 break ;
315
316 case wxWINDOW_VARIANT_SMALL :
317 size = kControlSizeSmall;
318 break ;
319
320 case wxWINDOW_VARIANT_MINI :
321 // not always defined in the headers
322 size = 3 ;
323 break ;
324
325 case wxWINDOW_VARIANT_LARGE :
326 size = kControlSizeLarge;
327 break ;
328
329 default:
330 wxFAIL_MSG(_T("unexpected window variant"));
331 break ;
332 }
333 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
334 #endif
335
336 wxFont font ;
337
338 wxOSXSystemFont systemFont = wxOSX_SYSTEM_FONT_NORMAL ;
339
340 switch ( variant )
341 {
342 case wxWINDOW_VARIANT_NORMAL :
343 systemFont = wxOSX_SYSTEM_FONT_NORMAL ;
344 break ;
345
346 case wxWINDOW_VARIANT_SMALL :
347 systemFont = wxOSX_SYSTEM_FONT_SMALL ;
348 break ;
349
350 case wxWINDOW_VARIANT_MINI :
351 systemFont = wxOSX_SYSTEM_FONT_MINI ;
352 break ;
353
354 case wxWINDOW_VARIANT_LARGE :
355 systemFont = wxOSX_SYSTEM_FONT_NORMAL ;
356 break ;
357
358 default:
359 wxFAIL_MSG(_T("unexpected window variant"));
360 break ;
361 }
362
363 font.CreateSystemFont( systemFont ) ;
364
365 SetFont( font ) ;
366 }
367
368 void wxWindowMac::MacUpdateControlFont()
369 {
370 if ( m_peer )
371 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
372
373 // do not trigger refreshes upon invisible and possible partly created objects
374 if ( IsShownOnScreen() )
375 Refresh() ;
376 }
377
378 bool wxWindowMac::SetFont(const wxFont& font)
379 {
380 bool retval = wxWindowBase::SetFont( font );
381
382 MacUpdateControlFont() ;
383
384 return retval;
385 }
386
387 bool wxWindowMac::SetForegroundColour(const wxColour& col )
388 {
389 bool retval = wxWindowBase::SetForegroundColour( col );
390
391 if (retval)
392 MacUpdateControlFont();
393
394 return retval;
395 }
396
397 bool wxWindowMac::SetBackgroundColour(const wxColour& col )
398 {
399 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
400 return false ;
401
402 if ( m_peer )
403 m_peer->SetBackgroundColour( col ) ;
404
405 return true ;
406 }
407
408 void wxWindowMac::SetFocus()
409 {
410 if ( !AcceptsFocus() )
411 return ;
412
413 wxWindow* former = FindFocus() ;
414 if ( former == this )
415 return ;
416
417 m_peer->SetFocus() ;
418 }
419
420 void wxWindowMac::DoCaptureMouse()
421 {
422 wxApp::s_captureWindow = (wxWindow*) this ;
423 m_peer->CaptureMouse() ;
424 }
425
426 wxWindow * wxWindowBase::GetCapture()
427 {
428 return wxApp::s_captureWindow ;
429 }
430
431 void wxWindowMac::DoReleaseMouse()
432 {
433 wxApp::s_captureWindow = NULL ;
434
435 m_peer->ReleaseMouse() ;
436 }
437
438 #if wxUSE_DRAG_AND_DROP
439
440 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
441 {
442 delete m_dropTarget;
443
444 m_dropTarget = pDropTarget;
445 if ( m_dropTarget != NULL )
446 {
447 // TODO:
448 }
449 }
450
451 #endif
452
453 // Old-style File Manager Drag & Drop
454 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept))
455 {
456 // TODO:
457 }
458
459 // From a wx position / size calculate the appropriate size of the native control
460
461 bool wxWindowMac::MacGetBoundsForControl(
462 const wxPoint& pos,
463 const wxSize& size,
464 int& x, int& y,
465 int& w, int& h , bool adjustOrigin ) const
466 {
467 // the desired size, minus the border pixels gives the correct size of the control
468 x = (int)pos.x;
469 y = (int)pos.y;
470
471 w = WidthDefault( size.x );
472 h = HeightDefault( size.y );
473
474 x += MacGetLeftBorderSize() ;
475 y += MacGetTopBorderSize() ;
476 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
477 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
478
479 if ( adjustOrigin )
480 AdjustForParentClientOrigin( x , y ) ;
481
482 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
483 if ( GetParent() && !GetParent()->IsTopLevel() )
484 {
485 x -= GetParent()->MacGetLeftBorderSize() ;
486 y -= GetParent()->MacGetTopBorderSize() ;
487 }
488
489 return true ;
490 }
491
492 // Get window size (not client size)
493 void wxWindowMac::DoGetSize(int *x, int *y) const
494 {
495 int width, height;
496 m_peer->GetSize( width, height );
497
498 if (x)
499 *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
500 if (y)
501 *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
502 }
503
504 // get the position of the bounds of this window in client coordinates of its parent
505 void wxWindowMac::DoGetPosition(int *x, int *y) const
506 {
507 int x1, y1;
508
509 m_peer->GetPosition( x1, y1 ) ;
510
511 // get the wx window position from the native one
512 x1 -= MacGetLeftBorderSize() ;
513 y1 -= MacGetTopBorderSize() ;
514
515 if ( !IsTopLevel() )
516 {
517 wxWindow *parent = GetParent();
518 if ( parent )
519 {
520 // we must first adjust it to be in window coordinates of the parent,
521 // as otherwise it gets lost by the ClientAreaOrigin fix
522 x1 += parent->MacGetLeftBorderSize() ;
523 y1 += parent->MacGetTopBorderSize() ;
524
525 // and now to client coordinates
526 wxPoint pt(parent->GetClientAreaOrigin());
527 x1 -= pt.x ;
528 y1 -= pt.y ;
529 }
530 }
531
532 if (x)
533 *x = x1 ;
534 if (y)
535 *y = y1 ;
536 }
537
538 void wxWindowMac::DoScreenToClient(int *x, int *y) const
539 {
540 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
541 wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ;
542 tlw->GetNonOwnedPeer()->ScreenToWindow( x, y);
543 MacRootWindowToWindow( x , y ) ;
544
545 wxPoint origin = GetClientAreaOrigin() ;
546 if (x)
547 *x -= origin.x ;
548 if (y)
549 *y -= origin.y ;
550 }
551
552 void wxWindowMac::DoClientToScreen(int *x, int *y) const
553 {
554 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
555 wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ;
556
557 wxPoint origin = GetClientAreaOrigin() ;
558 if (x)
559 *x += origin.x ;
560 if (y)
561 *y += origin.y ;
562
563 MacWindowToRootWindow( x , y ) ;
564 tlw->GetNonOwnedPeer()->WindowToScreen( x , y );
565 }
566
567 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
568 {
569 wxPoint origin = GetClientAreaOrigin() ;
570 if (x)
571 *x += origin.x ;
572 if (y)
573 *y += origin.y ;
574
575 MacWindowToRootWindow( x , y ) ;
576 }
577
578 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
579 {
580 wxPoint pt ;
581
582 if (x)
583 pt.x = *x ;
584 if (y)
585 pt.y = *y ;
586
587 if ( !IsTopLevel() )
588 {
589 wxNonOwnedWindow* top = MacGetTopLevelWindow();
590 if (top)
591 {
592 pt.x -= MacGetLeftBorderSize() ;
593 pt.y -= MacGetTopBorderSize() ;
594 wxWidgetImpl::Convert( &pt , m_peer , top->m_peer ) ;
595 }
596 }
597
598 if (x)
599 *x = (int) pt.x ;
600 if (y)
601 *y = (int) pt.y ;
602 }
603
604 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
605 {
606 wxPoint pt ;
607
608 if (x)
609 pt.x = *x ;
610 if (y)
611 pt.y = *y ;
612
613 if ( !IsTopLevel() )
614 {
615 wxNonOwnedWindow* top = MacGetTopLevelWindow();
616 if (top)
617 {
618 wxWidgetImpl::Convert( &pt , top->m_peer , m_peer ) ;
619 pt.x += MacGetLeftBorderSize() ;
620 pt.y += MacGetTopBorderSize() ;
621 }
622 }
623
624 if (x)
625 *x = (int) pt.x ;
626 if (y)
627 *y = (int) pt.y ;
628 }
629
630 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
631 {
632 wxSize sizeTotal = size;
633
634 int innerwidth, innerheight;
635 int left, top;
636 int outerwidth, outerheight;
637
638 m_peer->GetContentArea( left, top, innerwidth, innerheight );
639 m_peer->GetSize( outerwidth, outerheight );
640
641 sizeTotal.x += outerwidth-innerwidth;
642 sizeTotal.y += outerheight-innerheight;
643
644 sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
645 sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
646
647 return sizeTotal;
648 }
649
650 // Get size *available for subwindows* i.e. excluding menu bar etc.
651 void wxWindowMac::DoGetClientSize( int *x, int *y ) const
652 {
653 int ww, hh;
654
655 int left, top;
656
657 m_peer->GetContentArea( left, top, ww, hh );
658
659 if (m_hScrollBar && m_hScrollBar->IsShown() )
660 hh -= m_hScrollBar->GetSize().y ;
661
662 if (m_vScrollBar && m_vScrollBar->IsShown() )
663 ww -= m_vScrollBar->GetSize().x ;
664
665 if (x)
666 *x = ww;
667 if (y)
668 *y = hh;
669 }
670
671 bool wxWindowMac::SetCursor(const wxCursor& cursor)
672 {
673 if (m_cursor.IsSameAs(cursor))
674 return false;
675
676 if (!cursor.IsOk())
677 {
678 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
679 return false ;
680 }
681 else
682 {
683 if ( ! wxWindowBase::SetCursor( cursor ) )
684 return false ;
685 }
686
687 wxASSERT_MSG( m_cursor.Ok(),
688 wxT("cursor must be valid after call to the base version"));
689
690 if ( GetPeer() != NULL )
691 GetPeer()->SetCursor( m_cursor );
692
693 return true ;
694 }
695
696 #if wxUSE_MENUS
697 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
698 {
699 #ifndef __WXUNIVERSAL__
700 menu->SetInvokingWindow((wxWindow*)this);
701 menu->UpdateUI();
702
703 if ( x == wxDefaultCoord && y == wxDefaultCoord )
704 {
705 wxPoint mouse = wxGetMousePosition();
706 x = mouse.x;
707 y = mouse.y;
708 }
709 else
710 {
711 ClientToScreen( &x , &y ) ;
712 }
713 menu->GetPeer()->PopUp(this, x, y);
714 menu->SetInvokingWindow( NULL );
715 return true;
716 #else
717 // actually this shouldn't be called, because universal is having its own implementation
718 return false;
719 #endif
720 }
721 #endif
722
723 // ----------------------------------------------------------------------------
724 // tooltips
725 // ----------------------------------------------------------------------------
726
727 #if wxUSE_TOOLTIPS
728
729 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
730 {
731 wxWindowBase::DoSetToolTip(tooltip);
732
733 if ( m_tooltip )
734 m_tooltip->SetWindow(this);
735 }
736
737 #endif
738
739 void wxWindowMac::MacInvalidateBorders()
740 {
741 if ( m_peer == NULL )
742 return ;
743
744 bool vis = IsShownOnScreen() ;
745 if ( !vis )
746 return ;
747
748 int outerBorder = MacGetLeftBorderSize() ;
749
750 if ( m_peer->NeedsFocusRect() )
751 outerBorder += 4 ;
752
753 if ( outerBorder == 0 )
754 return ;
755
756 // now we know that we have something to do at all
757
758 int tx,ty,tw,th;
759
760 m_peer->GetSize( tw, th );
761 m_peer->GetPosition( tx, ty );
762
763 wxRect leftupdate( tx-outerBorder,ty,outerBorder,th );
764 wxRect rightupdate( tx+tw, ty, outerBorder, th );
765 wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder );
766 wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder );
767
768 if (GetParent()) {
769 GetParent()->m_peer->SetNeedsDisplay(&leftupdate);
770 GetParent()->m_peer->SetNeedsDisplay(&rightupdate);
771 GetParent()->m_peer->SetNeedsDisplay(&topupdate);
772 GetParent()->m_peer->SetNeedsDisplay(&bottomupdate);
773 }
774 }
775
776 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
777 {
778 // this is never called for a toplevel window, so we know we have a parent
779 int former_x , former_y , former_w, former_h ;
780
781 // Get true coordinates of former position
782 DoGetPosition( &former_x , &former_y ) ;
783 DoGetSize( &former_w , &former_h ) ;
784
785 wxWindow *parent = GetParent();
786 if ( parent )
787 {
788 wxPoint pt(parent->GetClientAreaOrigin());
789 former_x += pt.x ;
790 former_y += pt.y ;
791 }
792
793 int actualWidth = width ;
794 int actualHeight = height ;
795 int actualX = x;
796 int actualY = y;
797
798 #if 0
799 // min and max sizes are only for sizers, not for explicit size setting
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 #endif
809
810 bool doMove = false, doResize = false ;
811
812 if ( actualX != former_x || actualY != former_y )
813 doMove = true ;
814
815 if ( actualWidth != former_w || actualHeight != former_h )
816 doResize = true ;
817
818 if ( doMove || doResize )
819 {
820 // as the borders are drawn outside the native control, we adjust now
821
822 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
823 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
824 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
825
826 if ( parent && !parent->IsTopLevel() )
827 {
828 bounds.Offset( -parent->MacGetLeftBorderSize(), -parent->MacGetTopBorderSize() );
829 }
830
831 MacInvalidateBorders() ;
832
833 m_cachedClippedRectValid = false ;
834
835 m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height);
836
837 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
838
839 MacInvalidateBorders() ;
840
841 MacRepositionScrollBars() ;
842 if ( doMove )
843 {
844 wxPoint point(actualX, actualY);
845 wxMoveEvent event(point, m_windowId);
846 event.SetEventObject(this);
847 HandleWindowEvent(event) ;
848 }
849
850 if ( doResize )
851 {
852 MacRepositionScrollBars() ;
853 wxSize size(actualWidth, actualHeight);
854 wxSizeEvent event(size, m_windowId);
855 event.SetEventObject(this);
856 HandleWindowEvent(event);
857 }
858 }
859 }
860
861 wxSize wxWindowMac::DoGetBestSize() const
862 {
863 if ( m_macIsUserPane || IsTopLevel() )
864 {
865 return wxWindowBase::DoGetBestSize() ;
866 }
867 else
868 {
869 wxRect r ;
870
871 m_peer->GetBestRect(&r);
872
873 if ( r.GetWidth() == 0 && r.GetHeight() == 0 )
874 {
875 r.x =
876 r.y = 0 ;
877 r.width =
878 r.height = 16 ;
879
880 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
881 {
882 r.height = 16 ;
883 }
884 #if wxUSE_SPINBTN
885 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
886 {
887 r.height = 24 ;
888 }
889 #endif
890 else
891 {
892 // return wxWindowBase::DoGetBestSize() ;
893 }
894 }
895
896 int bestWidth = r.width + MacGetLeftBorderSize() +
897 MacGetRightBorderSize();
898 int bestHeight = r.height + MacGetTopBorderSize() +
899 MacGetBottomBorderSize();
900 if ( bestHeight < 10 )
901 bestHeight = 13 ;
902
903 return wxSize(bestWidth, bestHeight);
904 }
905 }
906
907 // set the size of the window: if the dimensions are positive, just use them,
908 // but if any of them is equal to -1, it means that we must find the value for
909 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
910 // which case -1 is a valid value for x and y)
911 //
912 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
913 // the width/height to best suit our contents, otherwise we reuse the current
914 // width/height
915 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
916 {
917 // get the current size and position...
918 int currentX, currentY;
919 int currentW, currentH;
920
921 GetPosition(&currentX, &currentY);
922 GetSize(&currentW, &currentH);
923
924 // ... and don't do anything (avoiding flicker) if it's already ok
925 if ( x == currentX && y == currentY &&
926 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
927 {
928 // TODO: REMOVE
929 MacRepositionScrollBars() ; // we might have a real position shift
930
931 if (sizeFlags & wxSIZE_FORCE_EVENT)
932 {
933 wxSizeEvent event( wxSize(width,height), GetId() );
934 event.SetEventObject( this );
935 HandleWindowEvent( event );
936 }
937
938 return;
939 }
940
941 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
942 {
943 if ( x == wxDefaultCoord )
944 x = currentX;
945 if ( y == wxDefaultCoord )
946 y = currentY;
947 }
948
949 AdjustForParentClientOrigin( x, y, sizeFlags );
950
951 wxSize size = wxDefaultSize;
952 if ( width == wxDefaultCoord )
953 {
954 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
955 {
956 size = DoGetBestSize();
957 width = size.x;
958 }
959 else
960 {
961 // just take the current one
962 width = currentW;
963 }
964 }
965
966 if ( height == wxDefaultCoord )
967 {
968 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
969 {
970 if ( size.x == wxDefaultCoord )
971 size = DoGetBestSize();
972 // else: already called DoGetBestSize() above
973
974 height = size.y;
975 }
976 else
977 {
978 // just take the current one
979 height = currentH;
980 }
981 }
982
983 DoMoveWindow( x, y, width, height );
984 }
985
986 wxPoint wxWindowMac::GetClientAreaOrigin() const
987 {
988 int left,top,width,height;
989 m_peer->GetContentArea( left , top , width , height);
990 return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() );
991 }
992
993 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
994 {
995 if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
996 {
997 int currentclientwidth , currentclientheight ;
998 int currentwidth , currentheight ;
999
1000 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1001 GetSize( &currentwidth , &currentheight ) ;
1002
1003 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1004 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1005 }
1006 }
1007
1008 void wxWindowMac::SetLabel(const wxString& title)
1009 {
1010 m_label = title ;
1011
1012 if ( m_peer && m_peer->IsOk() && !(IsKindOf( CLASSINFO(wxButton) ) && GetId() == wxID_HELP) )
1013 m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
1014
1015 // do not trigger refreshes upon invisible and possible partly created objects
1016 if ( IsShownOnScreen() )
1017 Refresh() ;
1018 }
1019
1020 wxString wxWindowMac::GetLabel() const
1021 {
1022 return m_label ;
1023 }
1024
1025 bool wxWindowMac::Show(bool show)
1026 {
1027 if ( !wxWindowBase::Show(show) )
1028 return false;
1029
1030 if ( m_peer )
1031 m_peer->SetVisibility( show ) ;
1032
1033 return true;
1034 }
1035
1036 void wxWindowMac::DoEnable(bool enable)
1037 {
1038 m_peer->Enable( enable ) ;
1039 }
1040
1041 //
1042 // status change notifications
1043 //
1044
1045 void wxWindowMac::MacVisibilityChanged()
1046 {
1047 }
1048
1049 void wxWindowMac::MacHiliteChanged()
1050 {
1051 }
1052
1053 void wxWindowMac::MacEnabledStateChanged()
1054 {
1055 OnEnabled( m_peer->IsEnabled() );
1056 }
1057
1058 //
1059 // status queries on the inherited window's state
1060 //
1061
1062 bool wxWindowMac::MacIsReallyEnabled()
1063 {
1064 return m_peer->IsEnabled() ;
1065 }
1066
1067 bool wxWindowMac::MacIsReallyHilited()
1068 {
1069 #if wxOSX_USE_CARBON
1070 return m_peer->IsActive();
1071 #else
1072 return true; // TODO
1073 #endif
1074 }
1075
1076 int wxWindowMac::GetCharHeight() const
1077 {
1078 wxCoord height;
1079 GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1080
1081 return height;
1082 }
1083
1084 int wxWindowMac::GetCharWidth() const
1085 {
1086 wxCoord width;
1087 GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1088
1089 return width;
1090 }
1091
1092 void wxWindowMac::DoGetTextExtent(const wxString& str,
1093 int *x, int *y,
1094 int *descent,
1095 int *externalLeading,
1096 const wxFont *theFont) const
1097 {
1098 const wxFont *fontToUse = theFont;
1099 wxFont tempFont;
1100 if ( !fontToUse )
1101 {
1102 tempFont = GetFont();
1103 fontToUse = &tempFont;
1104 }
1105
1106 wxGraphicsContext* ctx = wxGraphicsContext::Create();
1107 ctx->SetFont( *fontToUse, *wxBLACK );
1108
1109 wxDouble h , d , e , w;
1110 ctx->GetTextExtent( str, &w, &h, &d, &e );
1111
1112 delete ctx;
1113
1114 if ( externalLeading )
1115 *externalLeading = (wxCoord)(e+0.5);
1116 if ( descent )
1117 *descent = (wxCoord)(d+0.5);
1118 if ( x )
1119 *x = (wxCoord)(w+0.5);
1120 if ( y )
1121 *y = (wxCoord)(h+0.5);
1122 }
1123
1124 /*
1125 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1126 * we always intersect with the entire window, not only with the client area
1127 */
1128
1129 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
1130 {
1131 if ( m_peer == NULL )
1132 return ;
1133
1134 if ( !IsShownOnScreen() )
1135 return ;
1136
1137 m_peer->SetNeedsDisplay( rect ) ;
1138 }
1139
1140 void wxWindowMac::DoFreeze()
1141 {
1142 #if wxOSX_USE_CARBON
1143 if ( m_peer && m_peer->IsOk() )
1144 m_peer->SetDrawingEnabled( false ) ;
1145 #endif
1146 }
1147
1148 void wxWindowMac::DoThaw()
1149 {
1150 #if wxOSX_USE_CARBON
1151 if ( m_peer && m_peer->IsOk() )
1152 {
1153 m_peer->SetDrawingEnabled( true ) ;
1154 m_peer->InvalidateWithChildren() ;
1155 }
1156 #endif
1157 }
1158
1159 wxWindow *wxGetActiveWindow()
1160 {
1161 // actually this is a windows-only concept
1162 return NULL;
1163 }
1164
1165 // Coordinates relative to the window
1166 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos))
1167 {
1168 // We really don't move the mouse programmatically under Mac.
1169 }
1170
1171 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1172 {
1173 if ( MacGetTopLevelWindow() == NULL )
1174 return ;
1175 /*
1176 #if TARGET_API_MAC_OSX
1177 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1178 {
1179 }
1180 else
1181 #endif
1182 */
1183 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR )
1184 {
1185 event.GetDC()->Clear() ;
1186 }
1187 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
1188 {
1189 // don't skip the event here, custom background means that the app
1190 // is drawing it itself in its OnPaint(), so don't draw it at all
1191 // now to avoid flicker
1192 }
1193 else
1194 {
1195 event.Skip() ;
1196 }
1197 }
1198
1199 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1200 {
1201 event.Skip() ;
1202 }
1203
1204 int wxWindowMac::GetScrollPos(int orient) const
1205 {
1206 if ( orient == wxHORIZONTAL )
1207 {
1208 if ( m_hScrollBar )
1209 return m_hScrollBar->GetThumbPosition() ;
1210 }
1211 else
1212 {
1213 if ( m_vScrollBar )
1214 return m_vScrollBar->GetThumbPosition() ;
1215 }
1216
1217 return 0;
1218 }
1219
1220 // This now returns the whole range, not just the number
1221 // of positions that we can scroll.
1222 int wxWindowMac::GetScrollRange(int orient) const
1223 {
1224 if ( orient == wxHORIZONTAL )
1225 {
1226 if ( m_hScrollBar )
1227 return m_hScrollBar->GetRange() ;
1228 }
1229 else
1230 {
1231 if ( m_vScrollBar )
1232 return m_vScrollBar->GetRange() ;
1233 }
1234
1235 return 0;
1236 }
1237
1238 int wxWindowMac::GetScrollThumb(int orient) const
1239 {
1240 if ( orient == wxHORIZONTAL )
1241 {
1242 if ( m_hScrollBar )
1243 return m_hScrollBar->GetThumbSize() ;
1244 }
1245 else
1246 {
1247 if ( m_vScrollBar )
1248 return m_vScrollBar->GetThumbSize() ;
1249 }
1250
1251 return 0;
1252 }
1253
1254 void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1255 {
1256 if ( orient == wxHORIZONTAL )
1257 {
1258 if ( m_hScrollBar )
1259 m_hScrollBar->SetThumbPosition( pos ) ;
1260 }
1261 else
1262 {
1263 if ( m_vScrollBar )
1264 m_vScrollBar->SetThumbPosition( pos ) ;
1265 }
1266 }
1267
1268 void
1269 wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag)
1270 {
1271 bool needVisibilityUpdate = false;
1272
1273 if ( m_hScrollBarAlwaysShown != hflag )
1274 {
1275 m_hScrollBarAlwaysShown = hflag;
1276 needVisibilityUpdate = true;
1277 }
1278
1279 if ( m_vScrollBarAlwaysShown != vflag )
1280 {
1281 m_vScrollBarAlwaysShown = vflag;
1282 needVisibilityUpdate = true;
1283 }
1284
1285 if ( needVisibilityUpdate )
1286 DoUpdateScrollbarVisibility();
1287 }
1288
1289 //
1290 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1291 // our own window origin is at leftOrigin/rightOrigin
1292 //
1293
1294 void wxWindowMac::MacPaintGrowBox()
1295 {
1296 if ( IsTopLevel() )
1297 return ;
1298
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 }
1328
1329 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
1330 {
1331 if ( IsTopLevel() )
1332 return ;
1333
1334 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
1335
1336 // back to the surrounding frame rectangle
1337 int tx,ty,tw,th;
1338
1339 m_peer->GetSize( tw, th );
1340 m_peer->GetPosition( tx, ty );
1341
1342 Rect rect = { ty,tx, ty+th, tx+tw };
1343
1344 #if wxOSX_USE_COCOA_OR_CARBON
1345
1346 InsetRect( &rect, -1 , -1 ) ;
1347
1348 {
1349 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
1350 rect.bottom - rect.top ) ;
1351
1352 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
1353 wxASSERT( cgContext ) ;
1354
1355 if ( m_peer->NeedsFrame() )
1356 {
1357 HIThemeFrameDrawInfo info ;
1358 memset( &info, 0 , sizeof(info) ) ;
1359
1360 info.version = 0 ;
1361 info.kind = 0 ;
1362 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1363 info.isFocused = hasFocus ;
1364
1365 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1366 {
1367 info.kind = kHIThemeFrameTextFieldSquare ;
1368 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1369 }
1370 else if ( HasFlag(wxSIMPLE_BORDER) )
1371 {
1372 info.kind = kHIThemeFrameListBox ;
1373 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1374 }
1375 }
1376
1377 if ( hasFocus )
1378 {
1379 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
1380 }
1381 }
1382 #endif // wxOSX_USE_COCOA_OR_CARBON
1383 }
1384
1385 void wxWindowMac::RemoveChild( wxWindowBase *child )
1386 {
1387 if ( child == m_hScrollBar )
1388 m_hScrollBar = NULL ;
1389 if ( child == m_vScrollBar )
1390 m_vScrollBar = NULL ;
1391
1392 wxWindowBase::RemoveChild( child ) ;
1393 }
1394
1395 void wxWindowMac::DoUpdateScrollbarVisibility()
1396 {
1397 bool triggerSizeEvent = false;
1398
1399 if ( m_hScrollBar )
1400 {
1401 bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded();
1402
1403 if ( m_hScrollBar->IsShown() != showHScrollBar )
1404 {
1405 m_hScrollBar->Show( showHScrollBar );
1406 triggerSizeEvent = true;
1407 }
1408 }
1409
1410 if ( m_vScrollBar)
1411 {
1412 bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded();
1413
1414 if ( m_vScrollBar->IsShown() != showVScrollBar )
1415 {
1416 m_vScrollBar->Show( showVScrollBar ) ;
1417 triggerSizeEvent = true;
1418 }
1419 }
1420
1421 MacRepositionScrollBars() ;
1422 if ( triggerSizeEvent )
1423 {
1424 wxSizeEvent event(GetSize(), m_windowId);
1425 event.SetEventObject(this);
1426 HandleWindowEvent(event);
1427 }
1428 }
1429
1430 // New function that will replace some of the above.
1431 void wxWindowMac::SetScrollbar(int orient, int pos, int thumb,
1432 int range, bool refresh)
1433 {
1434 if ( orient == wxHORIZONTAL && m_hScrollBar )
1435 m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1436 else if ( orient == wxVERTICAL && m_vScrollBar )
1437 m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1438
1439 DoUpdateScrollbarVisibility();
1440 }
1441
1442 // Does a physical scroll
1443 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1444 {
1445 if ( dx == 0 && dy == 0 )
1446 return ;
1447
1448 int width , height ;
1449 GetClientSize( &width , &height ) ;
1450
1451 {
1452 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
1453 if ( rect )
1454 scrollrect.Intersect( *rect ) ;
1455 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1456 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1457
1458 m_peer->ScrollRect( &scrollrect, dx, dy );
1459 }
1460
1461 wxWindowMac *child;
1462 int x, y, w, h;
1463 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1464 {
1465 child = node->GetData();
1466 if (child == NULL)
1467 continue;
1468 if (child == m_vScrollBar)
1469 continue;
1470 if (child == m_hScrollBar)
1471 continue;
1472 if (child->IsTopLevel())
1473 continue;
1474
1475 child->GetPosition( &x, &y );
1476 child->GetSize( &w, &h );
1477 if (rect)
1478 {
1479 wxRect rc( x, y, w, h );
1480 if (rect->Intersects( rc ))
1481 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1482 }
1483 else
1484 {
1485 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1486 }
1487 }
1488 }
1489
1490 void wxWindowMac::MacOnScroll( wxScrollEvent &event )
1491 {
1492 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
1493 {
1494 wxScrollWinEvent wevent;
1495 wevent.SetPosition(event.GetPosition());
1496 wevent.SetOrientation(event.GetOrientation());
1497 wevent.SetEventObject(this);
1498
1499 if (event.GetEventType() == wxEVT_SCROLL_TOP)
1500 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
1501 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
1502 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
1503 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
1504 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
1505 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
1506 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
1507 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
1508 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
1509 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
1510 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
1511 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
1512 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
1513 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
1514 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
1515
1516 HandleWindowEvent(wevent);
1517 }
1518 }
1519
1520 wxWindow *wxWindowBase::DoFindFocus()
1521 {
1522 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1523 }
1524
1525 void wxWindowMac::OnInternalIdle()
1526 {
1527 // This calls the UI-update mechanism (querying windows for
1528 // menu/toolbar/control state information)
1529 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1530 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
1531 }
1532
1533 // Raise the window to the top of the Z order
1534 void wxWindowMac::Raise()
1535 {
1536 m_peer->Raise();
1537 }
1538
1539 // Lower the window to the bottom of the Z order
1540 void wxWindowMac::Lower()
1541 {
1542 m_peer->Lower();
1543 }
1544
1545 // static wxWindow *gs_lastWhich = NULL;
1546
1547 bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
1548 {
1549 // first trigger a set cursor event
1550
1551 wxPoint clientorigin = GetClientAreaOrigin() ;
1552 wxSize clientsize = GetClientSize() ;
1553 wxCursor cursor ;
1554 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1555 {
1556 wxSetCursorEvent event( pt.x , pt.y );
1557
1558 bool processedEvtSetCursor = HandleWindowEvent(event);
1559 if ( processedEvtSetCursor && event.HasCursor() )
1560 {
1561 cursor = event.GetCursor() ;
1562 }
1563 else
1564 {
1565 // the test for processedEvtSetCursor is here to prevent using m_cursor
1566 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1567 // it - this is a way to say that our cursor shouldn't be used for this
1568 // point
1569 if ( !processedEvtSetCursor && m_cursor.Ok() )
1570 cursor = m_cursor ;
1571
1572 if ( !wxIsBusy() && !GetParent() )
1573 cursor = *wxSTANDARD_CURSOR ;
1574 }
1575
1576 if ( cursor.Ok() )
1577 cursor.MacInstall() ;
1578 }
1579
1580 return cursor.Ok() ;
1581 }
1582
1583 wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) )
1584 {
1585 #if wxUSE_TOOLTIPS
1586 if ( m_tooltip )
1587 return m_tooltip->GetTip() ;
1588 #endif
1589
1590 return wxEmptyString ;
1591 }
1592
1593 void wxWindowMac::ClearBackground()
1594 {
1595 Refresh() ;
1596 Update() ;
1597 }
1598
1599 void wxWindowMac::Update()
1600 {
1601 wxNonOwnedWindow* top = MacGetTopLevelWindow();
1602 if (top)
1603 top->Update() ;
1604 }
1605
1606 wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const
1607 {
1608 wxWindowMac *iter = (wxWindowMac*)this ;
1609
1610 while ( iter )
1611 {
1612 if ( iter->IsTopLevel() )
1613 {
1614 wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow);
1615 if ( toplevel )
1616 return toplevel;
1617 #if wxUSE_POPUPWIN
1618 wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow);
1619 if ( popupwin )
1620 return popupwin;
1621 #endif
1622 }
1623 iter = iter->GetParent() ;
1624 }
1625
1626 return NULL ;
1627 }
1628
1629 const wxRect& wxWindowMac::MacGetClippedClientRect() const
1630 {
1631 MacUpdateClippedRects() ;
1632
1633 return m_cachedClippedClientRect ;
1634 }
1635
1636 const wxRect& wxWindowMac::MacGetClippedRect() const
1637 {
1638 MacUpdateClippedRects() ;
1639
1640 return m_cachedClippedRect ;
1641 }
1642
1643 const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1644 {
1645 MacUpdateClippedRects() ;
1646
1647 return m_cachedClippedRectWithOuterStructure ;
1648 }
1649
1650 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
1651 {
1652 static wxRegion emptyrgn ;
1653
1654 if ( !m_isBeingDeleted && IsShownOnScreen() )
1655 {
1656 MacUpdateClippedRects() ;
1657 if ( includeOuterStructures )
1658 return m_cachedClippedRegionWithOuterStructure ;
1659 else
1660 return m_cachedClippedRegion ;
1661 }
1662 else
1663 {
1664 return emptyrgn ;
1665 }
1666 }
1667
1668 void wxWindowMac::MacUpdateClippedRects() const
1669 {
1670 #if wxOSX_USE_CARBON
1671 if ( m_cachedClippedRectValid )
1672 return ;
1673
1674 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1675 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1676 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1677 // to add focus borders everywhere
1678
1679 Rect rIncludingOuterStructures ;
1680
1681 int tx,ty,tw,th;
1682
1683 m_peer->GetSize( tw, th );
1684 m_peer->GetPosition( tx, ty );
1685
1686 Rect r = { ty,tx, ty+th, tx+tw };
1687
1688 r.left -= MacGetLeftBorderSize() ;
1689 r.top -= MacGetTopBorderSize() ;
1690 r.bottom += MacGetBottomBorderSize() ;
1691 r.right += MacGetRightBorderSize() ;
1692
1693 r.right -= r.left ;
1694 r.bottom -= r.top ;
1695 r.left = 0 ;
1696 r.top = 0 ;
1697
1698 rIncludingOuterStructures = r ;
1699 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
1700
1701 wxRect cl = GetClientRect() ;
1702 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
1703
1704 int x , y ;
1705 wxSize size ;
1706 const wxWindow* child = (wxWindow*) this ;
1707 const wxWindow* parent = NULL ;
1708
1709 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
1710 {
1711 if ( parent->MacIsChildOfClientArea(child) )
1712 {
1713 size = parent->GetClientSize() ;
1714 wxPoint origin = parent->GetClientAreaOrigin() ;
1715 x = origin.x ;
1716 y = origin.y ;
1717 }
1718 else
1719 {
1720 // this will be true for scrollbars, toolbars etc.
1721 size = parent->GetSize() ;
1722 y = parent->MacGetTopBorderSize() ;
1723 x = parent->MacGetLeftBorderSize() ;
1724 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
1725 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
1726 }
1727
1728 parent->MacWindowToRootWindow( &x, &y ) ;
1729 MacRootWindowToWindow( &x , &y ) ;
1730
1731 Rect rparent = { y , x , y + size.y , x + size.x } ;
1732
1733 // the wxwindow and client rects will always be clipped
1734 SectRect( &r , &rparent , &r ) ;
1735 SectRect( &rClient , &rparent , &rClient ) ;
1736
1737 // the structure only at 'hard' borders
1738 if ( parent->MacClipChildren() ||
1739 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
1740 {
1741 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
1742 }
1743
1744 child = parent ;
1745 }
1746
1747 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
1748 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
1749 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
1750 m_cachedClippedRectWithOuterStructure = wxRect(
1751 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
1752 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
1753 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
1754
1755 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
1756 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
1757 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
1758
1759 m_cachedClippedRectValid = true ;
1760 #endif
1761 }
1762
1763 /*
1764 This function must not change the updatergn !
1765 */
1766 bool wxWindowMac::MacDoRedraw( long time )
1767 {
1768 bool handled = false ;
1769
1770 wxRegion formerUpdateRgn = m_updateRegion;
1771 wxRegion clientUpdateRgn = formerUpdateRgn;
1772
1773 wxSize sz = GetClientSize() ;
1774 wxPoint origin = GetClientAreaOrigin() ;
1775
1776 clientUpdateRgn.Intersect(origin.x , origin.y , origin.x + sz.x , origin.y + sz.y);
1777
1778 // first send an erase event to the entire update area
1779 {
1780 // for the toplevel window this really is the entire area
1781 // for all the others only their client area, otherwise they
1782 // might be drawing with full alpha and eg put blue into
1783 // the grow-box area of a scrolled window (scroll sample)
1784 wxDC* dc = new wxWindowDC(this);
1785 if ( IsTopLevel() )
1786 dc->SetDeviceClippingRegion(formerUpdateRgn);
1787 else
1788 dc->SetDeviceClippingRegion(clientUpdateRgn);
1789
1790 wxEraseEvent eevent( GetId(), dc );
1791 eevent.SetEventObject( this );
1792 HandleWindowEvent( eevent );
1793 delete dc ;
1794 }
1795
1796 MacPaintGrowBox();
1797
1798 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1799 clientUpdateRgn.Offset( -origin.x , -origin.y );
1800 m_updateRegion = clientUpdateRgn ;
1801
1802 if ( !m_updateRegion.Empty() )
1803 {
1804 // paint the window itself
1805
1806 wxPaintEvent event(GetId());
1807 event.SetTimestamp(time);
1808 event.SetEventObject(this);
1809 handled = HandleWindowEvent(event);
1810 }
1811
1812 m_updateRegion = formerUpdateRgn;
1813 return handled;
1814 }
1815
1816 void wxWindowMac::MacPaintChildrenBorders()
1817 {
1818 // now we cannot rely on having its borders drawn by a window itself, as it does not
1819 // get the updateRgn wide enough to always do so, so we do it from the parent
1820 // this would also be the place to draw any custom backgrounds for native controls
1821 // in Composited windowing
1822 wxPoint clientOrigin = GetClientAreaOrigin() ;
1823
1824 wxWindowMac *child;
1825 int x, y, w, h;
1826 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1827 {
1828 child = node->GetData();
1829 if (child == NULL)
1830 continue;
1831 if (child == m_vScrollBar)
1832 continue;
1833 if (child == m_hScrollBar)
1834 continue;
1835 if (child->IsTopLevel())
1836 continue;
1837 if (!child->IsShown())
1838 continue;
1839
1840 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1841
1842 child->GetPosition( &x, &y );
1843 child->GetSize( &w, &h );
1844
1845 if ( m_updateRegion.Contains(clientOrigin.x+x-10, clientOrigin.y+y-10, w+20, h+20) )
1846 {
1847 // paint custom borders
1848 wxNcPaintEvent eventNc( child->GetId() );
1849 eventNc.SetEventObject( child );
1850 if ( !child->HandleWindowEvent( eventNc ) )
1851 {
1852 child->MacPaintBorders(0, 0) ;
1853 }
1854 }
1855 }
1856 }
1857
1858
1859 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
1860 {
1861 wxNonOwnedWindow* tlw = MacGetTopLevelWindow();
1862 return tlw ? tlw->GetWXWindow() : NULL ;
1863 }
1864
1865 bool wxWindowMac::MacHasScrollBarCorner() const
1866 {
1867 /* Returns whether the scroll bars in a wxScrolledWindow should be
1868 * shortened. Scroll bars should be shortened if either:
1869 *
1870 * - both scroll bars are visible, or
1871 *
1872 * - there is a resize box in the parent frame's corner and this
1873 * window shares the bottom and right edge with the parent
1874 * frame.
1875 */
1876
1877 if ( m_hScrollBar == NULL && m_vScrollBar == NULL )
1878 return false;
1879
1880 if ( ( m_hScrollBar && m_hScrollBar->IsShown() )
1881 && ( m_vScrollBar && m_vScrollBar->IsShown() ) )
1882 {
1883 // Both scroll bars visible
1884 return true;
1885 }
1886 else
1887 {
1888 wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight();
1889
1890 for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() )
1891 {
1892 const wxFrame *frame = wxDynamicCast( win, wxFrame ) ;
1893 if ( frame )
1894 {
1895 if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER )
1896 {
1897 // Parent frame has resize handle
1898 wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight();
1899
1900 // Note: allow for some wiggle room here as wxMac's
1901 // window rect calculations seem to be imprecise
1902 if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2
1903 && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 )
1904 {
1905 // Parent frame has resize handle and shares
1906 // right bottom corner
1907 return true ;
1908 }
1909 else
1910 {
1911 // Parent frame has resize handle but doesn't
1912 // share right bottom corner
1913 return false ;
1914 }
1915 }
1916 else
1917 {
1918 // Parent frame doesn't have resize handle
1919 return false ;
1920 }
1921 }
1922 }
1923
1924 // No parent frame found
1925 return false ;
1926 }
1927 }
1928
1929 void wxWindowMac::MacCreateScrollBars( long style )
1930 {
1931 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
1932
1933 if ( style & ( wxVSCROLL | wxHSCROLL ) )
1934 {
1935 int scrlsize = MAC_SCROLLBAR_SIZE ;
1936 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
1937 {
1938 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
1939 }
1940
1941 int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ;
1942 int width, height ;
1943 GetClientSize( &width , &height ) ;
1944
1945 wxPoint vPoint(width - scrlsize, 0) ;
1946 wxSize vSize(scrlsize, height - adjust) ;
1947 wxPoint hPoint(0, height - scrlsize) ;
1948 wxSize hSize(width - adjust, scrlsize) ;
1949
1950 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
1951 if ( style & wxVSCROLL )
1952 {
1953 m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL);
1954 m_vScrollBar->SetMinSize( wxDefaultSize );
1955 }
1956
1957 if ( style & wxHSCROLL )
1958 {
1959 m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
1960 m_hScrollBar->SetMinSize( wxDefaultSize );
1961 }
1962 }
1963
1964 // because the create does not take into account the client area origin
1965 // we might have a real position shift
1966 MacRepositionScrollBars() ;
1967 }
1968
1969 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
1970 {
1971 bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar)));
1972
1973 return result ;
1974 }
1975
1976 void wxWindowMac::MacRepositionScrollBars()
1977 {
1978 if ( !m_hScrollBar && !m_vScrollBar )
1979 return ;
1980
1981 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
1982 int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ;
1983
1984 // get real client area
1985 int width, height ;
1986 GetSize( &width , &height );
1987
1988 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1989 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
1990
1991 wxPoint vPoint( width - scrlsize, 0 ) ;
1992 wxSize vSize( scrlsize, height - adjust ) ;
1993 wxPoint hPoint( 0 , height - scrlsize ) ;
1994 wxSize hSize( width - adjust, scrlsize ) ;
1995
1996 if ( m_vScrollBar )
1997 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
1998 if ( m_hScrollBar )
1999 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
2000 }
2001
2002 bool wxWindowMac::AcceptsFocus() const
2003 {
2004 if ( MacIsUserPane() )
2005 return wxWindowBase::AcceptsFocus();
2006 else
2007 return m_peer->CanFocus();
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 WXUNUSED(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 }