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