]> git.saurik.com Git - wxWidgets.git/blob - src/mac/window.cpp
added possibility to use several wxFileHistories (patch 685876)
[wxWidgets.git] / src / mac / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/window.h"
19 #include "wx/dc.h"
20 #include "wx/dcclient.h"
21 #include "wx/utils.h"
22 #include "wx/app.h"
23 #include "wx/panel.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/frame.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
38 #include "wx/spinctrl.h"
39 #include "wx/log.h"
40 #include "wx/geometry.h"
41
42 #if wxUSE_CARET
43 #include "wx/caret.h"
44 #endif // wxUSE_CARET
45
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
49
50 #include "wx/mac/uma.h"
51 #ifndef __DARWIN__
52 #include <Windows.h>
53 #include <ToolUtils.h>
54 #endif
55
56 #if wxUSE_DRAG_AND_DROP
57 #include "wx/dnd.h"
58 #endif
59
60 #include <string.h>
61
62 extern wxList wxPendingDelete;
63 wxWindowMac* gFocusWindow = NULL ;
64
65 #ifdef __WXUNIVERSAL__
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
67 #else // __WXMAC__
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
69 #endif // __WXUNIVERSAL__/__WXMAC__
70
71 #if !USE_SHARED_LIBRARY
72
73 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
74 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
75 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
76 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
77 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
78 EVT_IDLE(wxWindowMac::OnIdle)
79 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
80 END_EVENT_TABLE()
81
82 #endif
83
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
87 #endif
88
89 #define wxMAC_USE_THEME_BORDER 0
90
91
92 // ===========================================================================
93 // implementation
94 // ===========================================================================
95
96
97 // ----------------------------------------------------------------------------
98 // constructors and such
99 // ----------------------------------------------------------------------------
100
101 void wxWindowMac::Init()
102 {
103 // generic
104 InitBase();
105
106 // MSW specific
107 m_doubleClickAllowed = 0;
108 m_winCaptured = FALSE;
109
110 m_isBeingDeleted = FALSE;
111
112 m_useCtl3D = FALSE;
113 m_mouseInWindow = FALSE;
114
115 m_xThumbSize = 0;
116 m_yThumbSize = 0;
117 m_backgroundTransparent = FALSE;
118
119 // as all windows are created with WS_VISIBLE style...
120 m_isShown = TRUE;
121
122 m_x = 0;
123 m_y = 0 ;
124 m_width = 0 ;
125 m_height = 0 ;
126
127 m_hScrollBar = NULL ;
128 m_vScrollBar = NULL ;
129
130 m_label = wxEmptyString;
131 }
132
133 // Destructor
134 wxWindowMac::~wxWindowMac()
135 {
136 SendDestroyEvent();
137
138 // deleting a window while it is shown invalidates the region
139 if ( IsShown() ) {
140 wxWindowMac* iter = this ;
141 while( iter ) {
142 if ( iter->IsTopLevel() )
143 {
144 Refresh() ;
145 break ;
146 }
147 iter = iter->GetParent() ;
148
149 }
150 }
151
152 m_isBeingDeleted = TRUE;
153
154 #ifndef __WXUNIVERSAL__
155 // VS: make sure there's no wxFrame with last focus set to us:
156 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
157 {
158 wxFrame *frame = wxDynamicCast(win, wxFrame);
159 if ( frame )
160 {
161 if ( frame->GetLastFocus() == this )
162 {
163 frame->SetLastFocus((wxWindow*)NULL);
164 }
165 break;
166 }
167 }
168 #endif // __WXUNIVERSAL__
169
170 if ( s_lastMouseWindow == this )
171 {
172 s_lastMouseWindow = NULL ;
173 }
174
175 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
176 if ( frame )
177 {
178 if ( frame->GetLastFocus() == this )
179 frame->SetLastFocus( NULL ) ;
180 }
181
182 if ( gFocusWindow == this )
183 {
184 gFocusWindow = NULL ;
185 }
186
187 // CS: copied from MSW :
188 // VS: destroy children first and _then_ detach *this from its parent.
189 // If we'd do it the other way around, children wouldn't be able
190 // find their parent frame (see above).
191 DestroyChildren();
192
193 if ( m_parent )
194 m_parent->RemoveChild(this);
195
196 wxWindowDestroyEvent event((wxWindow *)this);
197 (void)GetEventHandler()->ProcessEvent(event);
198
199 // delete our drop target if we've got one
200 #if wxUSE_DRAG_AND_DROP
201 if ( m_dropTarget != NULL )
202 {
203 delete m_dropTarget;
204 m_dropTarget = NULL;
205 }
206 #endif // wxUSE_DRAG_AND_DROP
207 }
208
209 // Constructor
210 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
211 const wxPoint& pos,
212 const wxSize& size,
213 long style,
214 const wxString& name)
215 {
216 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
217
218 #if wxUSE_STATBOX
219 // wxGTK doesn't allow to create controls with static box as the parent so
220 // this will result in a crash when the program is ported to wxGTK - warn
221 // about it
222 //
223 // the correct solution is to create the controls as siblings of the
224 // static box
225 wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox),
226 _T("wxStaticBox can't be used as a window parent!") );
227 #endif // wxUSE_STATBOX
228
229 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
230 return FALSE;
231
232 parent->AddChild(this);
233
234 m_x = (int)pos.x;
235 m_y = (int)pos.y;
236 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
237 m_width = WidthDefault( size.x );
238 m_height = HeightDefault( size.y ) ;
239 #ifndef __WXUNIVERSAL__
240 // Don't give scrollbars to wxControls unless they ask for them
241 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
242 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
243 {
244 MacCreateScrollBars( style ) ;
245 }
246 #endif
247 return TRUE;
248 }
249
250 void wxWindowMac::SetFocus()
251 {
252 if ( gFocusWindow == this )
253 return ;
254
255 if ( AcceptsFocus() )
256 {
257 if (gFocusWindow )
258 {
259 #if wxUSE_CARET
260 // Deal with caret
261 if ( gFocusWindow->m_caret )
262 {
263 gFocusWindow->m_caret->OnKillFocus();
264 }
265 #endif // wxUSE_CARET
266 #ifndef __WXUNIVERSAL__
267 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
268 if ( control && control->GetMacControl() )
269 {
270 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ;
271 control->MacRedrawControl() ;
272 }
273 #endif
274 // Without testing the window id, for some reason
275 // a kill focus event can still be sent to
276 // the control just being focussed.
277 int thisId = this->m_windowId;
278 int gFocusWindowId = gFocusWindow->m_windowId;
279 if (gFocusWindowId != thisId)
280 {
281 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
282 event.SetEventObject(gFocusWindow);
283 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
284 }
285 }
286 gFocusWindow = this ;
287 {
288 #if wxUSE_CARET
289 // Deal with caret
290 if ( m_caret )
291 {
292 m_caret->OnSetFocus();
293 }
294 #endif // wxUSE_CARET
295 // panel wants to track the window which was the last to have focus in it
296 wxChildFocusEvent eventFocus(this);
297 GetEventHandler()->ProcessEvent(eventFocus);
298
299 #ifndef __WXUNIVERSAL__
300 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
301 if ( control && control->GetMacControl() )
302 {
303 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ;
304 }
305 #endif
306 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
307 event.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(event) ;
309 }
310 }
311 }
312
313 bool wxWindowMac::Enable(bool enable)
314 {
315 if ( !wxWindowBase::Enable(enable) )
316 return FALSE;
317
318 MacSuperEnabled( enable ) ;
319
320 return TRUE;
321 }
322
323 void wxWindowMac::DoCaptureMouse()
324 {
325 wxTheApp->s_captureWindow = this ;
326 }
327
328 wxWindow* wxWindowBase::GetCapture()
329 {
330 return wxTheApp->s_captureWindow ;
331 }
332
333 void wxWindowMac::DoReleaseMouse()
334 {
335 wxTheApp->s_captureWindow = NULL ;
336 }
337
338 #if wxUSE_DRAG_AND_DROP
339
340 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
341 {
342 if ( m_dropTarget != 0 ) {
343 delete m_dropTarget;
344 }
345
346 m_dropTarget = pDropTarget;
347 if ( m_dropTarget != 0 )
348 {
349 // TODO
350 }
351 }
352
353 #endif
354
355 // Old style file-manager drag&drop
356 void wxWindowMac::DragAcceptFiles(bool accept)
357 {
358 // TODO
359 }
360
361 // Get total size
362 void wxWindowMac::DoGetSize(int *x, int *y) const
363 {
364 if(x) *x = m_width ;
365 if(y) *y = m_height ;
366 }
367
368 void wxWindowMac::DoGetPosition(int *x, int *y) const
369 {
370 int xx,yy;
371
372 xx = m_x ;
373 yy = m_y ;
374 if ( !IsTopLevel() && GetParent())
375 {
376 wxPoint pt(GetParent()->GetClientAreaOrigin());
377 xx -= pt.x;
378 yy -= pt.y;
379 }
380 if(x) *x = xx;
381 if(y) *y = yy;
382 }
383
384 #if wxUSE_MENUS
385 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
386 {
387 menu->SetInvokingWindow(this);
388 menu->UpdateUI();
389 ClientToScreen( &x , &y ) ;
390
391 ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
392 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
393 if ( HiWord(menuResult) != 0 )
394 {
395 MenuCommand id ;
396 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
397
398 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id );
399 event.m_timeStamp = TickCount() ;
400 event.SetEventObject(this->GetEventHandler());
401 event.SetInt( id );
402 GetEventHandler()->ProcessEvent(event);
403 }
404 ::DeleteMenu( menu->MacGetMenuId() ) ;
405 menu->SetInvokingWindow(NULL);
406
407 return TRUE;
408 }
409 #endif
410
411 void wxWindowMac::DoScreenToClient(int *x, int *y) const
412 {
413 WindowRef window = (WindowRef) MacGetRootWindow() ;
414
415 Point localwhere = {0,0} ;
416
417 if(x) localwhere.h = * x ;
418 if(y) localwhere.v = * y ;
419
420 GrafPtr port ;
421 ::GetPort( &port ) ;
422 ::SetPort( UMAGetWindowPort( window ) ) ;
423 ::GlobalToLocal( &localwhere ) ;
424 ::SetPort( port ) ;
425
426 if(x) *x = localwhere.h ;
427 if(y) *y = localwhere.v ;
428
429 MacRootWindowToWindow( x , y ) ;
430 if ( x )
431 *x -= MacGetLeftBorderSize() ;
432 if ( y )
433 *y -= MacGetTopBorderSize() ;
434 }
435
436 void wxWindowMac::DoClientToScreen(int *x, int *y) const
437 {
438 WindowRef window = (WindowRef) MacGetRootWindow() ;
439
440 if ( x )
441 *x += MacGetLeftBorderSize() ;
442 if ( y )
443 *y += MacGetTopBorderSize() ;
444
445 MacWindowToRootWindow( x , y ) ;
446
447 Point localwhere = { 0,0 };
448 if(x) localwhere.h = * x ;
449 if(y) localwhere.v = * y ;
450
451 GrafPtr port ;
452 ::GetPort( &port ) ;
453 ::SetPort( UMAGetWindowPort( window ) ) ;
454
455 ::LocalToGlobal( &localwhere ) ;
456 ::SetPort( port ) ;
457 if(x) *x = localwhere.h ;
458 if(y) *y = localwhere.v ;
459 }
460
461 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
462 {
463 wxPoint origin = GetClientAreaOrigin() ;
464 if(x) *x += origin.x ;
465 if(y) *y += origin.y ;
466
467 MacWindowToRootWindow( x , y ) ;
468 }
469
470 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
471 {
472 wxPoint origin = GetClientAreaOrigin() ;
473 MacRootWindowToWindow( x , y ) ;
474 if(x) *x -= origin.x ;
475 if(y) *y -= origin.y ;
476 }
477
478 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
479 {
480 if ( !IsTopLevel() )
481 {
482 if(x) *x += m_x ;
483 if(y) *y += m_y ;
484 GetParent()->MacWindowToRootWindow( x , y ) ;
485 }
486 }
487
488 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
489 {
490 if ( !IsTopLevel() )
491 {
492 if(x) *x -= m_x ;
493 if(y) *y -= m_y ;
494 GetParent()->MacRootWindowToWindow( x , y ) ;
495 }
496 }
497
498 bool wxWindowMac::SetCursor(const wxCursor& cursor)
499 {
500 if (m_cursor == cursor)
501 return FALSE;
502
503 if (wxNullCursor == cursor)
504 {
505 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
506 return FALSE ;
507 }
508 else
509 {
510 if ( ! wxWindowBase::SetCursor( cursor ) )
511 return FALSE ;
512 }
513
514 wxASSERT_MSG( m_cursor.Ok(),
515 wxT("cursor must be valid after call to the base version"));
516
517 Point pt ;
518 wxWindowMac *mouseWin ;
519 GetMouse( &pt ) ;
520
521 // Change the cursor NOW if we're within the correct window
522
523 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
524 {
525 if ( mouseWin == this && !wxIsBusy() )
526 {
527 m_cursor.MacInstall() ;
528 }
529 }
530
531 return TRUE ;
532 }
533
534
535 // Get size *available for subwindows* i.e. excluding menu bar etc.
536 void wxWindowMac::DoGetClientSize(int *x, int *y) const
537 {
538 int ww, hh;
539 ww = m_width ;
540 hh = m_height ;
541
542 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
543 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
544
545 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
546 {
547 int x1 = 0 ;
548 int y1 = 0 ;
549 int w = m_width ;
550 int h = m_height ;
551
552 MacClientToRootWindow( &x1 , &y1 ) ;
553 MacClientToRootWindow( &w , &h ) ;
554
555 wxWindowMac *iter = (wxWindowMac*)this ;
556
557 int totW = 10000 , totH = 10000;
558 while( iter )
559 {
560 if ( iter->IsTopLevel() )
561 {
562 totW = iter->m_width ;
563 totH = iter->m_height ;
564 break ;
565 }
566
567 iter = iter->GetParent() ;
568 }
569
570 if (m_hScrollBar && m_hScrollBar->IsShown() )
571 {
572 hh -= MAC_SCROLLBAR_SIZE;
573 if ( h-y1 >= totH )
574 {
575 hh += 1 ;
576 }
577 }
578 if (m_vScrollBar && m_vScrollBar->IsShown() )
579 {
580 ww -= MAC_SCROLLBAR_SIZE;
581 if ( w-x1 >= totW )
582 {
583 ww += 1 ;
584 }
585 }
586 }
587 if(x) *x = ww;
588 if(y) *y = hh;
589 }
590
591
592 // ----------------------------------------------------------------------------
593 // tooltips
594 // ----------------------------------------------------------------------------
595
596 #if wxUSE_TOOLTIPS
597
598 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
599 {
600 wxWindowBase::DoSetToolTip(tooltip);
601
602 if ( m_tooltip )
603 m_tooltip->SetWindow(this);
604 }
605
606 #endif // wxUSE_TOOLTIPS
607
608 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
609 {
610 int former_x = m_x ;
611 int former_y = m_y ;
612 int former_w = m_width ;
613 int former_h = m_height ;
614
615 int actualWidth = width;
616 int actualHeight = height;
617 int actualX = x;
618 int actualY = y;
619
620 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
621 actualWidth = m_minWidth;
622 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
623 actualHeight = m_minHeight;
624 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
625 actualWidth = m_maxWidth;
626 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
627 actualHeight = m_maxHeight;
628
629 bool doMove = false ;
630 bool doResize = false ;
631
632 if ( actualX != former_x || actualY != former_y )
633 {
634 doMove = true ;
635 }
636 if ( actualWidth != former_w || actualHeight != former_h )
637 {
638 doResize = true ;
639 }
640
641 if ( doMove || doResize )
642 {
643 // erase former position
644
645 bool partialRepaint = false ;
646
647 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
648 {
649 wxPoint oldPos( m_x , m_y ) ;
650 wxPoint newPos( actualX , actualY ) ;
651 MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ;
652 MacWindowToRootWindow( &newPos.x , &newPos.y ) ;
653 if ( oldPos == newPos )
654 {
655 partialRepaint = true ;
656 RgnHandle oldRgn,newRgn,diffRgn ;
657 oldRgn = NewRgn() ;
658 newRgn = NewRgn() ;
659 diffRgn = NewRgn() ;
660 SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ;
661 SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ;
662 DiffRgn( newRgn , oldRgn , diffRgn ) ;
663 InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ;
664 DiffRgn( oldRgn , newRgn , diffRgn ) ;
665 InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ;
666 DisposeRgn(oldRgn) ;
667 DisposeRgn(newRgn) ;
668 DisposeRgn(diffRgn) ;
669 }
670 }
671
672 if ( !partialRepaint )
673 Refresh() ;
674
675 m_x = actualX ;
676 m_y = actualY ;
677 m_width = actualWidth ;
678 m_height = actualHeight ;
679
680 // update any low-level frame-relative positions
681
682 MacUpdateDimensions() ;
683 // erase new position
684
685 if ( !partialRepaint )
686 Refresh() ;
687 if ( doMove )
688 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
689
690 MacRepositionScrollBars() ;
691 if ( doMove )
692 {
693 wxPoint point(m_x, m_y);
694 wxMoveEvent event(point, m_windowId);
695 event.SetEventObject(this);
696 GetEventHandler()->ProcessEvent(event) ;
697 }
698 if ( doResize )
699 {
700 MacRepositionScrollBars() ;
701 wxSize size(m_width, m_height);
702 wxSizeEvent event(size, m_windowId);
703 event.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(event);
705 }
706 }
707
708 }
709
710 // set the size of the window: if the dimensions are positive, just use them,
711 // but if any of them is equal to -1, it means that we must find the value for
712 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
713 // which case -1 is a valid value for x and y)
714 //
715 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
716 // the width/height to best suit our contents, otherwise we reuse the current
717 // width/height
718 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
719 {
720 // get the current size and position...
721 int currentX, currentY;
722 GetPosition(&currentX, &currentY);
723
724 int currentW,currentH;
725 GetSize(&currentW, &currentH);
726
727 // ... and don't do anything (avoiding flicker) if it's already ok
728 if ( x == currentX && y == currentY &&
729 width == currentW && height == currentH )
730 {
731 MacRepositionScrollBars() ; // we might have a real position shift
732 return;
733 }
734
735 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
736 x = currentX;
737 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
738 y = currentY;
739
740 AdjustForParentClientOrigin(x, y, sizeFlags);
741
742 wxSize size(-1, -1);
743 if ( width == -1 )
744 {
745 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
746 {
747 size = DoGetBestSize();
748 width = size.x;
749 }
750 else
751 {
752 // just take the current one
753 width = currentW;
754 }
755 }
756
757 if ( height == -1 )
758 {
759 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
760 {
761 if ( size.x == -1 )
762 {
763 size = DoGetBestSize();
764 }
765 //else: already called DoGetBestSize() above
766
767 height = size.y;
768 }
769 else
770 {
771 // just take the current one
772 height = currentH;
773 }
774 }
775
776 DoMoveWindow(x, y, width, height);
777
778 }
779 // For implementation purposes - sometimes decorations make the client area
780 // smaller
781
782 wxPoint wxWindowMac::GetClientAreaOrigin() const
783 {
784 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
785 }
786
787 void wxWindowMac::SetTitle(const wxString& title)
788 {
789 m_label = title ;
790 }
791
792 wxString wxWindowMac::GetTitle() const
793 {
794 return m_label ;
795 }
796
797 bool wxWindowMac::Show(bool show)
798 {
799 if ( !wxWindowBase::Show(show) )
800 return FALSE;
801
802 /*
803 WindowRef window = (WindowRef) MacGetRootWindow() ;
804 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
805 if ( win == NULL && win->m_isBeingDeleted )
806 return FALSE ;
807 */
808 MacSuperShown( show ) ;
809 Refresh() ;
810 /*
811 if ( !show )
812 {
813 if ( win && !win->m_isBeingDeleted )
814 Refresh() ;
815 }
816 else
817 {
818 Refresh() ;
819 }
820 */
821 return TRUE;
822 }
823
824 void wxWindowMac::MacSuperShown( bool show )
825 {
826 wxWindowListNode *node = GetChildren().GetFirst();
827 while ( node )
828 {
829 wxWindowMac *child = (wxWindowMac *)node->GetData();
830 if ( child->m_isShown )
831 child->MacSuperShown( show ) ;
832 node = node->GetNext();
833 }
834 }
835
836 void wxWindowMac::MacSuperEnabled( bool enabled )
837 {
838 if ( !IsTopLevel() )
839 {
840 // to be absolutely correct we'd have to invalidate (with eraseBkground
841 // because unter MacOSX the frames are drawn with an addXXX mode)
842 // the borders area
843 }
844 wxWindowListNode *node = GetChildren().GetFirst();
845 while ( node )
846 {
847 wxWindowMac *child = (wxWindowMac *)node->GetData();
848 if ( child->m_isShown )
849 child->MacSuperEnabled( enabled ) ;
850 node = node->GetNext();
851 }
852 }
853
854 bool wxWindowMac::MacIsReallyShown() const
855 {
856 if ( m_isShown && (m_parent != NULL) ) {
857 return m_parent->MacIsReallyShown();
858 }
859 return m_isShown;
860 /*
861 bool status = m_isShown ;
862 wxWindowMac * win = this ;
863 while ( status && win->m_parent != NULL )
864 {
865 win = win->m_parent ;
866 status = win->m_isShown ;
867 }
868 return status ;
869 */
870 }
871
872 int wxWindowMac::GetCharHeight() const
873 {
874 wxClientDC dc ( (wxWindowMac*)this ) ;
875 return dc.GetCharHeight() ;
876 }
877
878 int wxWindowMac::GetCharWidth() const
879 {
880 wxClientDC dc ( (wxWindowMac*)this ) ;
881 return dc.GetCharWidth() ;
882 }
883
884 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
885 int *descent, int *externalLeading, const wxFont *theFont ) const
886 {
887 const wxFont *fontToUse = theFont;
888 if ( !fontToUse )
889 fontToUse = &m_font;
890
891 wxClientDC dc( (wxWindowMac*) this ) ;
892 long lx,ly,ld,le ;
893 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
894 if ( externalLeading )
895 *externalLeading = le ;
896 if ( descent )
897 *descent = ld ;
898 if ( x )
899 *x = lx ;
900 if ( y )
901 *y = ly ;
902 }
903
904 /*
905 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
906 * we always intersect with the entire window, not only with the client area
907 */
908
909 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
910 {
911 if ( MacGetTopLevelWindow() == NULL )
912 return ;
913
914 wxPoint client = GetClientAreaOrigin();
915 int x1 = -client.x;
916 int y1 = -client.y;
917 int x2 = m_width - client.x;
918 int y2 = m_height - client.y;
919
920 if (IsKindOf( CLASSINFO(wxButton)))
921 {
922 // buttons have an "aura"
923 y1 -= 5;
924 x1 -= 5;
925 y2 += 5;
926 x2 += 5;
927 }
928
929 Rect clientrect = { y1, x1, y2, x2 };
930
931 if ( rect )
932 {
933 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
934 SectRect( &clientrect , &r , &clientrect ) ;
935 }
936
937 if ( !EmptyRect( &clientrect ) )
938 {
939 int top = 0 , left = 0 ;
940
941 MacClientToRootWindow( &left , &top ) ;
942 OffsetRect( &clientrect , left , top ) ;
943
944 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
945 }
946 }
947
948 #if wxUSE_CARET && WXWIN_COMPATIBILITY
949 // ---------------------------------------------------------------------------
950 // Caret manipulation
951 // ---------------------------------------------------------------------------
952
953 void wxWindowMac::CreateCaret(int w, int h)
954 {
955 SetCaret(new wxCaret(this, w, h));
956 }
957
958 void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
959 {
960 wxFAIL_MSG("not implemented");
961 }
962
963 void wxWindowMac::ShowCaret(bool show)
964 {
965 wxCHECK_RET( m_caret, "no caret to show" );
966
967 m_caret->Show(show);
968 }
969
970 void wxWindowMac::DestroyCaret()
971 {
972 SetCaret(NULL);
973 }
974
975 void wxWindowMac::SetCaretPos(int x, int y)
976 {
977 wxCHECK_RET( m_caret, "no caret to move" );
978
979 m_caret->Move(x, y);
980 }
981
982 void wxWindowMac::GetCaretPos(int *x, int *y) const
983 {
984 wxCHECK_RET( m_caret, "no caret to get position of" );
985
986 m_caret->GetPosition(x, y);
987 }
988 #endif // wxUSE_CARET
989
990 wxWindowMac *wxGetActiveWindow()
991 {
992 // actually this is a windows-only concept
993 return NULL;
994 }
995
996 // Coordinates relative to the window
997 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
998 {
999 // We really don't move the mouse programmatically under Mac.
1000 }
1001
1002 const wxBrush& wxWindowMac::MacGetBackgroundBrush()
1003 {
1004 if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1005 {
1006 m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ;
1007 }
1008 else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
1009 {
1010 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1011 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1012 // either a non gray background color or a non control window
1013
1014 WindowRef window = (WindowRef) MacGetRootWindow() ;
1015
1016 wxWindowMac* parent = GetParent() ;
1017 while( parent )
1018 {
1019 if ( parent->MacGetRootWindow() != window )
1020 {
1021 // we are in a different window on the mac system
1022 parent = NULL ;
1023 break ;
1024 }
1025
1026 {
1027 if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
1028 && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1029 {
1030 // if we have any other colours in the hierarchy
1031 m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ;
1032 break ;
1033 }
1034 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1035 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1036 {
1037 Rect extent = { 0 , 0 , 0 , 0 } ;
1038 int x , y ;
1039 x = y = 0 ;
1040 wxSize size = parent->GetSize() ;
1041 parent->MacClientToRootWindow( &x , &y ) ;
1042 extent.left = x ;
1043 extent.top = y ;
1044 extent.top-- ;
1045 extent.right = x + size.x ;
1046 extent.bottom = y + size.y ;
1047 m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
1048 break ;
1049 }
1050 }
1051 parent = parent->GetParent() ;
1052 }
1053 if ( !parent )
1054 {
1055 m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive
1056 }
1057 }
1058 else
1059 {
1060 m_macBackgroundBrush.SetColour( m_backgroundColour ) ;
1061 }
1062
1063 return m_macBackgroundBrush ;
1064 }
1065
1066 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1067 {
1068 event.GetDC()->Clear() ;
1069 }
1070
1071 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1072 {
1073 wxWindowDC dc(this) ;
1074 wxMacPortSetter helper(&dc) ;
1075
1076 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1077 }
1078
1079 int wxWindowMac::GetScrollPos(int orient) const
1080 {
1081 if ( orient == wxHORIZONTAL )
1082 {
1083 if ( m_hScrollBar )
1084 return m_hScrollBar->GetThumbPosition() ;
1085 }
1086 else
1087 {
1088 if ( m_vScrollBar )
1089 return m_vScrollBar->GetThumbPosition() ;
1090 }
1091 return 0;
1092 }
1093
1094 // This now returns the whole range, not just the number
1095 // of positions that we can scroll.
1096 int wxWindowMac::GetScrollRange(int orient) const
1097 {
1098 if ( orient == wxHORIZONTAL )
1099 {
1100 if ( m_hScrollBar )
1101 return m_hScrollBar->GetRange() ;
1102 }
1103 else
1104 {
1105 if ( m_vScrollBar )
1106 return m_vScrollBar->GetRange() ;
1107 }
1108 return 0;
1109 }
1110
1111 int wxWindowMac::GetScrollThumb(int orient) const
1112 {
1113 if ( orient == wxHORIZONTAL )
1114 {
1115 if ( m_hScrollBar )
1116 return m_hScrollBar->GetThumbSize() ;
1117 }
1118 else
1119 {
1120 if ( m_vScrollBar )
1121 return m_vScrollBar->GetThumbSize() ;
1122 }
1123 return 0;
1124 }
1125
1126 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1127 {
1128 if ( orient == wxHORIZONTAL )
1129 {
1130 if ( m_hScrollBar )
1131 m_hScrollBar->SetThumbPosition( pos ) ;
1132 }
1133 else
1134 {
1135 if ( m_vScrollBar )
1136 m_vScrollBar->SetThumbPosition( pos ) ;
1137 }
1138 }
1139
1140 void wxWindowMac::MacPaintBorders( int left , int top )
1141 {
1142 if( IsTopLevel() )
1143 return ;
1144
1145 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1146 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1147 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1148 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1149 PenNormal() ;
1150
1151 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1152 {
1153 #if wxMAC_USE_THEME_BORDER
1154 Rect rect = { top , left , m_height + top , m_width + left } ;
1155 SInt32 border = 0 ;
1156 /*
1157 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1158 InsetRect( &rect , border , border );
1159 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1160 */
1161
1162 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1163 #else
1164 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1165 RGBForeColor( &face );
1166 MoveTo( left + 0 , top + m_height - 2 );
1167 LineTo( left + 0 , top + 0 );
1168 LineTo( left + m_width - 2 , top + 0 );
1169
1170 MoveTo( left + 2 , top + m_height - 3 );
1171 LineTo( left + m_width - 3 , top + m_height - 3 );
1172 LineTo( left + m_width - 3 , top + 2 );
1173
1174 RGBForeColor( sunken ? &face : &black );
1175 MoveTo( left + 0 , top + m_height - 1 );
1176 LineTo( left + m_width - 1 , top + m_height - 1 );
1177 LineTo( left + m_width - 1 , top + 0 );
1178
1179 RGBForeColor( sunken ? &shadow : &white );
1180 MoveTo( left + 1 , top + m_height - 3 );
1181 LineTo( left + 1, top + 1 );
1182 LineTo( left + m_width - 3 , top + 1 );
1183
1184 RGBForeColor( sunken ? &white : &shadow );
1185 MoveTo( left + 1 , top + m_height - 2 );
1186 LineTo( left + m_width - 2 , top + m_height - 2 );
1187 LineTo( left + m_width - 2 , top + 1 );
1188
1189 RGBForeColor( sunken ? &black : &face );
1190 MoveTo( left + 2 , top + m_height - 4 );
1191 LineTo( left + 2 , top + 2 );
1192 LineTo( left + m_width - 4 , top + 2 );
1193 #endif
1194 }
1195 else if (HasFlag(wxSIMPLE_BORDER))
1196 {
1197 Rect rect = { top , left , m_height + top , m_width + left } ;
1198 RGBForeColor( &black ) ;
1199 FrameRect( &rect ) ;
1200 }
1201 }
1202
1203 void wxWindowMac::RemoveChild( wxWindowBase *child )
1204 {
1205 if ( child == m_hScrollBar )
1206 m_hScrollBar = NULL ;
1207 if ( child == m_vScrollBar )
1208 m_vScrollBar = NULL ;
1209
1210 wxWindowBase::RemoveChild( child ) ;
1211 }
1212
1213 // New function that will replace some of the above.
1214 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1215 int range, bool refresh)
1216 {
1217 if ( orient == wxHORIZONTAL )
1218 {
1219 if ( m_hScrollBar )
1220 {
1221 if ( range == 0 || thumbVisible >= range )
1222 {
1223 if ( m_hScrollBar->IsShown() )
1224 m_hScrollBar->Show(false) ;
1225 }
1226 else
1227 {
1228 if ( !m_hScrollBar->IsShown() )
1229 m_hScrollBar->Show(true) ;
1230 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1231 }
1232 }
1233 }
1234 else
1235 {
1236 if ( m_vScrollBar )
1237 {
1238 if ( range == 0 || thumbVisible >= range )
1239 {
1240 if ( m_vScrollBar->IsShown() )
1241 m_vScrollBar->Show(false) ;
1242 }
1243 else
1244 {
1245 if ( !m_vScrollBar->IsShown() )
1246 m_vScrollBar->Show(true) ;
1247 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1248 }
1249 }
1250 }
1251 MacRepositionScrollBars() ;
1252 }
1253
1254 // Does a physical scroll
1255 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1256 {
1257 wxClientDC dc(this) ;
1258 wxMacPortSetter helper(&dc) ;
1259
1260 {
1261 int width , height ;
1262 GetClientSize( &width , &height ) ;
1263
1264 Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ;
1265 RgnHandle updateRgn = NewRgn() ;
1266 ClipRect( &scrollrect ) ;
1267 if ( rect )
1268 {
1269 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
1270 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
1271 SectRect( &scrollrect , &r , &scrollrect ) ;
1272 }
1273 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1274 InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ;
1275 DisposeRgn( updateRgn ) ;
1276 }
1277
1278 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1279 {
1280 wxWindowMac *child = (wxWindowMac*)node->GetData();
1281 if (child == m_vScrollBar) continue;
1282 if (child == m_hScrollBar) continue;
1283 if (child->IsTopLevel()) continue;
1284
1285 int x,y;
1286 child->GetPosition( &x, &y );
1287 int w,h;
1288 child->GetSize( &w, &h );
1289 child->SetSize( x+dx, y+dy, w, h );
1290 }
1291
1292 }
1293
1294 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
1295 {
1296 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1297 {
1298 wxScrollWinEvent wevent;
1299 wevent.SetPosition(event.GetPosition());
1300 wevent.SetOrientation(event.GetOrientation());
1301 wevent.m_eventObject = this;
1302
1303 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1304 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1305 } else
1306 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1307 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1308 } else
1309 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1310 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1311 } else
1312 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1313 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1314 } else
1315 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1316 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1317 } else
1318 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1319 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1320 } else
1321 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1322 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1323 }
1324
1325 GetEventHandler()->ProcessEvent(wevent);
1326 }
1327 }
1328
1329 // Get the window with the focus
1330 wxWindowMac *wxWindowBase::FindFocus()
1331 {
1332 return gFocusWindow ;
1333 }
1334
1335 #if WXWIN_COMPATIBILITY
1336 // If nothing defined for this, try the parent.
1337 // E.g. we may be a button loaded from a resource, with no callback function
1338 // defined.
1339 void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
1340 {
1341 if ( GetEventHandler()->ProcessEvent(event) )
1342 return;
1343 if ( m_parent )
1344 m_parent->GetEventHandler()->OnCommand(win, event);
1345 }
1346 #endif // WXWIN_COMPATIBILITY_2
1347
1348 #if WXWIN_COMPATIBILITY
1349 wxObject* wxWindowMac::GetChild(int number) const
1350 {
1351 // Return a pointer to the Nth object in the Panel
1352 wxNode *node = GetChildren().GetFirst();
1353 int n = number;
1354 while (node && n--)
1355 node = node->GetNext();
1356 if ( node )
1357 {
1358 wxObject *obj = (wxObject *)node->GetData();
1359 return(obj);
1360 }
1361 else
1362 return NULL;
1363 }
1364 #endif // WXWIN_COMPATIBILITY
1365
1366 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
1367 {
1368 // panel wants to track the window which was the last to have focus in it,
1369 // so we want to set ourselves as the window which last had focus
1370 //
1371 // notice that it's also important to do it upwards the tree becaus
1372 // otherwise when the top level panel gets focus, it won't set it back to
1373 // us, but to some other sibling
1374
1375 // CS:don't know if this is still needed:
1376 //wxChildFocusEvent eventFocus(this);
1377 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1378
1379 event.Skip();
1380 }
1381
1382 void wxWindowMac::Clear()
1383 {
1384 wxClientDC dc(this);
1385 wxBrush brush(GetBackgroundColour(), wxSOLID);
1386 dc.SetBackground(brush);
1387 dc.Clear();
1388 }
1389
1390 // Setup background and foreground colours correctly
1391 void wxWindowMac::SetupColours()
1392 {
1393 if ( GetParent() )
1394 SetBackgroundColour(GetParent()->GetBackgroundColour());
1395 }
1396
1397 void wxWindowMac::OnIdle(wxIdleEvent& event)
1398 {
1399 /*
1400 // Check if we need to send a LEAVE event
1401 if (m_mouseInWindow)
1402 {
1403 POINT pt;
1404 ::GetCursorPos(&pt);
1405 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1406 {
1407 // Generate a LEAVE event
1408 m_mouseInWindow = FALSE;
1409 MSWOnMouseLeave(pt.x, pt.y, 0);
1410 }
1411 }
1412 */
1413
1414 // This calls the UI-update mechanism (querying windows for
1415 // menu/toolbar/control state information)
1416 UpdateWindowUI();
1417 }
1418
1419 // Raise the window to the top of the Z order
1420 void wxWindowMac::Raise()
1421 {
1422 }
1423
1424 // Lower the window to the bottom of the Z order
1425 void wxWindowMac::Lower()
1426 {
1427 }
1428
1429 void wxWindowMac::DoSetClientSize(int width, int height)
1430 {
1431 if ( width != -1 || height != -1 )
1432 {
1433
1434 if ( width != -1 && m_vScrollBar )
1435 width += MAC_SCROLLBAR_SIZE ;
1436 if ( height != -1 && m_vScrollBar )
1437 height += MAC_SCROLLBAR_SIZE ;
1438
1439 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1440 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1441
1442 DoSetSize( -1 , -1 , width , height ) ;
1443 }
1444 }
1445
1446
1447 wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
1448
1449 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
1450 {
1451 if ( IsTopLevel() )
1452 {
1453 if ((point.x < 0) || (point.y < 0) ||
1454 (point.x > (m_width)) || (point.y > (m_height)))
1455 return FALSE;
1456 }
1457 else
1458 {
1459 if ((point.x < m_x) || (point.y < m_y) ||
1460 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1461 return FALSE;
1462 }
1463
1464 WindowRef window = (WindowRef) MacGetRootWindow() ;
1465
1466 wxPoint newPoint( point ) ;
1467
1468 if ( !IsTopLevel() )
1469 {
1470 newPoint.x -= m_x;
1471 newPoint.y -= m_y;
1472 }
1473
1474 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1475 {
1476 wxWindowMac *child = (wxWindowMac*)node->GetData();
1477 // added the m_isShown test --dmazzoni
1478 if ( child->MacGetRootWindow() == window && child->m_isShown )
1479 {
1480 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1481 return TRUE;
1482 }
1483 }
1484
1485 *outWin = this ;
1486 return TRUE;
1487 }
1488
1489 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
1490 {
1491 WindowRef window ;
1492
1493 Point pt = { screenpoint.y , screenpoint.x } ;
1494 if ( ::FindWindow( pt , &window ) == 3 )
1495 {
1496
1497 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1498 if ( win )
1499 {
1500 // No, this yields the CLIENT are, we need the whole frame. RR.
1501 // point = win->ScreenToClient( point ) ;
1502
1503 GrafPtr port;
1504 ::GetPort( &port ) ;
1505 ::SetPort( UMAGetWindowPort( window ) ) ;
1506 ::GlobalToLocal( &pt ) ;
1507 ::SetPort( port ) ;
1508
1509 wxPoint point( pt.h, pt.v ) ;
1510
1511 return win->MacGetWindowFromPointSub( point , outWin ) ;
1512 }
1513 }
1514 return FALSE ;
1515 }
1516
1517 static wxWindow *gs_lastWhich = NULL;
1518
1519 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
1520 {
1521 // first trigger a set cursor event
1522
1523 wxPoint clientorigin = GetClientAreaOrigin() ;
1524 wxSize clientsize = GetClientSize() ;
1525 wxCursor cursor ;
1526 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1527 {
1528 wxSetCursorEvent event( pt.x , pt.y );
1529
1530 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
1531 if ( processedEvtSetCursor && event.HasCursor() )
1532 {
1533 cursor = event.GetCursor() ;
1534 }
1535 else
1536 {
1537
1538 // the test for processedEvtSetCursor is here to prevent using m_cursor
1539 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1540 // it - this is a way to say that our cursor shouldn't be used for this
1541 // point
1542 if ( !processedEvtSetCursor && m_cursor.Ok() )
1543 {
1544 cursor = m_cursor ;
1545 }
1546 if ( wxIsBusy() )
1547 {
1548 }
1549 else
1550 {
1551 if ( !GetParent() )
1552 cursor = *wxSTANDARD_CURSOR ;
1553 }
1554 }
1555 if ( cursor.Ok() )
1556 cursor.MacInstall() ;
1557 }
1558 return cursor.Ok() ;
1559 }
1560
1561 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
1562 {
1563 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1564 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1565 return FALSE;
1566
1567
1568 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1569 return FALSE ;
1570
1571 WindowRef window = (WindowRef) MacGetRootWindow() ;
1572
1573 event.m_x -= m_x;
1574 event.m_y -= m_y;
1575
1576 int x = event.m_x ;
1577 int y = event.m_y ;
1578
1579 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1580 {
1581 wxWindowMac *child = (wxWindowMac*)node->GetData();
1582 if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
1583 {
1584 if (child->MacDispatchMouseEvent(event))
1585 return TRUE;
1586 }
1587 }
1588
1589 wxWindow* cursorTarget = this ;
1590 wxPoint cursorPoint( x , y ) ;
1591
1592 while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
1593 {
1594 cursorTarget = cursorTarget->GetParent() ;
1595 if ( cursorTarget )
1596 cursorPoint += cursorTarget->GetPosition() ;
1597 }
1598 event.m_x = x ;
1599 event.m_y = y ;
1600 event.SetEventObject( this ) ;
1601
1602 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1603 {
1604 // set focus to this window
1605 if (AcceptsFocus() && FindFocus()!=this)
1606 SetFocus();
1607 }
1608
1609 #if wxUSE_TOOLTIPS
1610 if ( event.GetEventType() == wxEVT_MOTION
1611 || event.GetEventType() == wxEVT_ENTER_WINDOW
1612 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1613 wxToolTip::RelayEvent( this , event);
1614 #endif // wxUSE_TOOLTIPS
1615
1616 if (gs_lastWhich != this)
1617 {
1618 gs_lastWhich = this;
1619
1620 // Double clicks must always occur on the same window
1621 if (event.GetEventType() == wxEVT_LEFT_DCLICK)
1622 event.SetEventType( wxEVT_LEFT_DOWN );
1623 if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
1624 event.SetEventType( wxEVT_RIGHT_DOWN );
1625
1626 // Same for mouse up events
1627 if (event.GetEventType() == wxEVT_LEFT_UP)
1628 return TRUE;
1629 if (event.GetEventType() == wxEVT_RIGHT_UP)
1630 return TRUE;
1631 }
1632
1633 GetEventHandler()->ProcessEvent( event ) ;
1634
1635 return TRUE;
1636 }
1637
1638 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
1639 {
1640 if ( m_tooltip )
1641 {
1642 return m_tooltip->GetTip() ;
1643 }
1644 return "" ;
1645 }
1646
1647 void wxWindowMac::Update()
1648 {
1649 wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
1650 if ( win )
1651 {
1652 win->MacUpdate( 0 ) ;
1653 #if TARGET_API_MAC_CARBON
1654 if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) )
1655 {
1656 QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ;
1657 }
1658 #endif
1659 }
1660 }
1661
1662 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
1663 {
1664 wxTopLevelWindowMac* win = NULL ;
1665 WindowRef window = (WindowRef) MacGetRootWindow() ;
1666 if ( window )
1667 {
1668 win = wxFindWinFromMacWindow( window ) ;
1669 }
1670 return win ;
1671 }
1672
1673 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings )
1674 {
1675 RgnHandle visRgn = NewRgn() ;
1676 RgnHandle tempRgn = NewRgn() ;
1677 RgnHandle tempStaticBoxRgn = NewRgn() ;
1678
1679 SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
1680
1681 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1682 if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
1683 {
1684 int borderTop = 14 ;
1685 int borderOther = 4 ;
1686
1687 SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
1688 DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ;
1689 }
1690
1691 if ( !IsTopLevel() )
1692 {
1693 wxWindow* parent = GetParent() ;
1694 while( parent )
1695 {
1696 wxSize size = parent->GetSize() ;
1697 int x , y ;
1698 x = y = 0 ;
1699 parent->MacWindowToRootWindow( &x, &y ) ;
1700 MacRootWindowToWindow( &x , &y ) ;
1701
1702 SetRectRgn( tempRgn ,
1703 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
1704 x + size.x - parent->MacGetRightBorderSize(),
1705 y + size.y - parent->MacGetBottomBorderSize()) ;
1706
1707 SectRgn( visRgn , tempRgn , visRgn ) ;
1708 if ( parent->IsTopLevel() )
1709 break ;
1710 parent = parent->GetParent() ;
1711 }
1712 }
1713 if ( respectChildrenAndSiblings )
1714 {
1715 if ( GetWindowStyle() & wxCLIP_CHILDREN )
1716 {
1717 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1718 {
1719 wxWindowMac *child = (wxWindowMac*)node->GetData();
1720
1721 if ( !child->IsTopLevel() && child->IsShown() )
1722 {
1723 SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1724 if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1725 {
1726 int borderTop = 14 ;
1727 int borderOther = 4 ;
1728
1729 SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ;
1730 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1731 }
1732 DiffRgn( visRgn , tempRgn , visRgn ) ;
1733 }
1734 }
1735 }
1736
1737 if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
1738 {
1739 bool thisWindowThrough = false ;
1740 for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext())
1741 {
1742 wxWindowMac *sibling = (wxWindowMac*)node->GetData();
1743 if ( sibling == this )
1744 {
1745 thisWindowThrough = true ;
1746 continue ;
1747 }
1748 if( !thisWindowThrough )
1749 {
1750 continue ;
1751 }
1752
1753 if ( !sibling->IsTopLevel() && sibling->IsShown() )
1754 {
1755 SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ;
1756 if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1757 {
1758 int borderTop = 14 ;
1759 int borderOther = 4 ;
1760
1761 SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ;
1762 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1763 }
1764 DiffRgn( visRgn , tempRgn , visRgn ) ;
1765 }
1766 }
1767 }
1768 }
1769 m_macVisibleRegion = visRgn ;
1770 DisposeRgn( visRgn ) ;
1771 DisposeRgn( tempRgn ) ;
1772 DisposeRgn( tempStaticBoxRgn ) ;
1773 return m_macVisibleRegion ;
1774 }
1775
1776 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
1777 {
1778 RgnHandle updatergn = (RgnHandle) updatergnr ;
1779 // updatergn is always already clipped to our boundaries
1780 // it is in window coordinates, not in client coordinates
1781
1782 WindowRef window = (WindowRef) MacGetRootWindow() ;
1783
1784 {
1785 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1786 RgnHandle ownUpdateRgn = NewRgn() ;
1787 CopyRgn( updatergn , ownUpdateRgn ) ;
1788
1789 SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
1790
1791 // newupdate is the update region in client coordinates
1792 RgnHandle newupdate = NewRgn() ;
1793 wxSize point = GetClientSize() ;
1794 wxPoint origin = GetClientAreaOrigin() ;
1795 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1796 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1797 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1798 m_updateRegion = newupdate ;
1799 DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
1800
1801 if ( erase && !EmptyRgn(ownUpdateRgn) )
1802 {
1803 wxWindowDC dc(this);
1804 if (!EmptyRgn(ownUpdateRgn))
1805 dc.SetClippingRegion(wxRegion(ownUpdateRgn));
1806 wxEraseEvent eevent( GetId(), &dc );
1807 eevent.SetEventObject( this );
1808 GetEventHandler()->ProcessEvent( eevent );
1809
1810 wxNcPaintEvent eventNc( GetId() );
1811 eventNc.SetEventObject( this );
1812 GetEventHandler()->ProcessEvent( eventNc );
1813 }
1814 DisposeRgn( ownUpdateRgn ) ;
1815 if ( !m_updateRegion.Empty() )
1816 {
1817 wxPaintEvent event;
1818 event.m_timeStamp = time ;
1819 event.SetEventObject(this);
1820 GetEventHandler()->ProcessEvent(event);
1821 }
1822 }
1823
1824 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1825
1826 RgnHandle childupdate = NewRgn() ;
1827 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1828 {
1829 // calculate the update region for the child windows by intersecting the window rectangle with our own
1830 // passed in update region and then offset it to be client-wise window coordinates again
1831 wxWindowMac *child = (wxWindowMac*)node->GetData();
1832 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1833 SectRgn( childupdate , updatergn , childupdate ) ;
1834 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1835 if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
1836 {
1837 // because dialogs may also be children
1838 child->MacRedraw( childupdate , time , erase ) ;
1839 }
1840 }
1841 DisposeRgn( childupdate ) ;
1842 // eventually a draw grow box here
1843
1844 }
1845
1846 WXHWND wxWindowMac::MacGetRootWindow() const
1847 {
1848 wxWindowMac *iter = (wxWindowMac*)this ;
1849
1850 while( iter )
1851 {
1852 if ( iter->IsTopLevel() )
1853 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
1854
1855 iter = iter->GetParent() ;
1856 }
1857 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1858 return NULL ;
1859 }
1860
1861 void wxWindowMac::MacCreateScrollBars( long style )
1862 {
1863 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1864
1865 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1866 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1867 int width, height ;
1868 GetClientSize( &width , &height ) ;
1869
1870 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1871 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1872 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1873 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1874
1875 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1876 vSize , wxVERTICAL);
1877
1878 if ( style & wxVSCROLL )
1879 {
1880
1881 }
1882 else
1883 {
1884 m_vScrollBar->Show(false) ;
1885 }
1886 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1887 hSize , wxHORIZONTAL);
1888 if ( style & wxHSCROLL )
1889 {
1890 }
1891 else
1892 {
1893 m_hScrollBar->Show(false) ;
1894 }
1895
1896 // because the create does not take into account the client area origin
1897 MacRepositionScrollBars() ; // we might have a real position shift
1898 }
1899
1900 void wxWindowMac::MacRepositionScrollBars()
1901 {
1902 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1903 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1904
1905 // get real client area
1906
1907 int width = m_width ;
1908 int height = m_height ;
1909
1910 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1911 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
1912
1913 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1914 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1915 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1916 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1917
1918 int x = 0 ;
1919 int y = 0 ;
1920 int w = m_width ;
1921 int h = m_height ;
1922
1923 MacClientToRootWindow( &x , &y ) ;
1924 MacClientToRootWindow( &w , &h ) ;
1925
1926 wxWindowMac *iter = (wxWindowMac*)this ;
1927
1928 int totW = 10000 , totH = 10000;
1929 while( iter )
1930 {
1931 if ( iter->IsTopLevel() )
1932 {
1933 totW = iter->m_width ;
1934 totH = iter->m_height ;
1935 break ;
1936 }
1937
1938 iter = iter->GetParent() ;
1939 }
1940
1941 if ( x == 0 )
1942 {
1943 hPoint.x = -1 ;
1944 hSize.x += 1 ;
1945 }
1946 if ( y == 0 )
1947 {
1948 vPoint.y = -1 ;
1949 vSize.y += 1 ;
1950 }
1951
1952 if ( w-x >= totW )
1953 {
1954 hSize.x += 1 ;
1955 vPoint.x += 1 ;
1956 }
1957
1958 if ( h-y >= totH )
1959 {
1960 vSize.y += 1 ;
1961 hPoint.y += 1 ;
1962 }
1963
1964 if ( m_vScrollBar )
1965 {
1966 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
1967 }
1968 if ( m_hScrollBar )
1969 {
1970 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
1971 }
1972 }
1973
1974 bool wxWindowMac::AcceptsFocus() const
1975 {
1976 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1977 }
1978
1979 WXWidget wxWindowMac::MacGetContainerForEmbedding()
1980 {
1981 return GetParent()->MacGetContainerForEmbedding() ;
1982 }
1983
1984 void wxWindowMac::MacSuperChangedPosition()
1985 {
1986 // only window-absolute structures have to be moved i.e. controls
1987
1988 wxWindowListNode *node = GetChildren().GetFirst();
1989 while ( node )
1990 {
1991 wxWindowMac *child = (wxWindowMac *)node->GetData();
1992 child->MacSuperChangedPosition() ;
1993 node = node->GetNext();
1994 }
1995 }
1996
1997 void wxWindowMac::MacTopLevelWindowChangedPosition()
1998 {
1999 // only screen-absolute structures have to be moved i.e. glcanvas
2000
2001 wxWindowListNode *node = GetChildren().GetFirst();
2002 while ( node )
2003 {
2004 wxWindowMac *child = (wxWindowMac *)node->GetData();
2005 child->MacTopLevelWindowChangedPosition() ;
2006 node = node->GetNext();
2007 }
2008 }
2009 long wxWindowMac::MacGetLeftBorderSize( ) const
2010 {
2011 if( IsTopLevel() )
2012 return 0 ;
2013
2014 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2015 {
2016 SInt32 border = 3 ;
2017 #if wxMAC_USE_THEME_BORDER
2018 #if TARGET_CARBON
2019 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2020 #endif
2021 #endif
2022 return border ;
2023 }
2024 else if ( m_windowStyle &wxDOUBLE_BORDER)
2025 {
2026 SInt32 border = 3 ;
2027 #if wxMAC_USE_THEME_BORDER
2028 #if TARGET_CARBON
2029 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2030 #endif
2031 #endif
2032 return border ;
2033 }
2034 else if (m_windowStyle &wxSIMPLE_BORDER)
2035 {
2036 return 1 ;
2037 }
2038 return 0 ;
2039 }
2040
2041 long wxWindowMac::MacGetRightBorderSize( ) const
2042 {
2043 // they are all symmetric in mac themes
2044 return MacGetLeftBorderSize() ;
2045 }
2046
2047 long wxWindowMac::MacGetTopBorderSize( ) const
2048 {
2049 // they are all symmetric in mac themes
2050 return MacGetLeftBorderSize() ;
2051 }
2052
2053 long wxWindowMac::MacGetBottomBorderSize( ) const
2054 {
2055 // they are all symmetric in mac themes
2056 return MacGetLeftBorderSize() ;
2057 }
2058
2059 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2060 {
2061 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2062 }
2063
2064 // Find the wxWindowMac at the current mouse position, returning the mouse
2065 // position.
2066 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2067 {
2068 pt = wxGetMousePosition();
2069 wxWindowMac* found = wxFindWindowAtPoint(pt);
2070 return found;
2071 }
2072
2073 // Get the current mouse position.
2074 wxPoint wxGetMousePosition()
2075 {
2076 int x, y;
2077 wxGetMousePosition(& x, & y);
2078 return wxPoint(x, y);
2079 }
2080