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