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