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