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