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