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