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