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