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