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