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