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