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