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