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