]> git.saurik.com Git - wxWidgets.git/blob - src/mac/window.cpp
mention Solaris 7 compilation fix
[wxWidgets.git] / src / mac / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindowMac
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/window.h"
19 #include "wx/dc.h"
20 #include "wx/dcclient.h"
21 #include "wx/utils.h"
22 #include "wx/app.h"
23 #include "wx/panel.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/frame.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
38 #include "wx/spinctrl.h"
39 #include "wx/log.h"
40 #include "wx/geometry.h"
41
42 #if wxUSE_CARET
43 #include "wx/caret.h"
44 #endif // wxUSE_CARET
45
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
49
50 #include "wx/mac/uma.h"
51 #ifndef __DARWIN__
52 #include <Windows.h>
53 #include <ToolUtils.h>
54 #endif
55
56 #if wxUSE_DRAG_AND_DROP
57 #include "wx/dnd.h"
58 #endif
59
60 #include <string.h>
61
62 extern wxList wxPendingDelete;
63 wxWindowMac* gFocusWindow = NULL ;
64
65 #ifdef __WXUNIVERSAL__
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
67 #else // __WXMAC__
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
69 #endif // __WXUNIVERSAL__/__WXMAC__
70
71 #if !USE_SHARED_LIBRARY
72
73 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
74 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
75 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
76 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
77 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
78 EVT_IDLE(wxWindowMac::OnIdle)
79 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
80 END_EVENT_TABLE()
81
82 #endif
83
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
87 #endif
88
89 #define wxMAC_USE_THEME_BORDER 0
90
91
92 // ===========================================================================
93 // implementation
94 // ===========================================================================
95
96
97 // ----------------------------------------------------------------------------
98 // constructors and such
99 // ----------------------------------------------------------------------------
100
101 void wxWindowMac::Init()
102 {
103 // generic
104 InitBase();
105
106 // MSW specific
107 m_doubleClickAllowed = 0;
108 m_winCaptured = FALSE;
109
110 m_isBeingDeleted = FALSE;
111
112 m_useCtl3D = FALSE;
113 m_mouseInWindow = FALSE;
114
115 m_xThumbSize = 0;
116 m_yThumbSize = 0;
117 m_backgroundTransparent = FALSE;
118
119 // as all windows are created with WS_VISIBLE style...
120 m_isShown = TRUE;
121
122 m_x = 0;
123 m_y = 0 ;
124 m_width = 0 ;
125 m_height = 0 ;
126
127 m_hScrollBar = NULL ;
128 m_vScrollBar = NULL ;
129
130 m_label = wxEmptyString;
131 }
132
133 // Destructor
134 wxWindowMac::~wxWindowMac()
135 {
136 // deleting a window while it is shown invalidates the region
137 if ( IsShown() ) {
138 wxWindowMac* iter = this ;
139 while( iter ) {
140 if ( iter->IsTopLevel() )
141 {
142 Refresh() ;
143 break ;
144 }
145 iter = iter->GetParent() ;
146
147 }
148 }
149
150 m_isBeingDeleted = TRUE;
151
152 #ifndef __WXUNIVERSAL__
153 // VS: make sure there's no wxFrame with last focus set to us:
154 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
155 {
156 wxFrame *frame = wxDynamicCast(win, wxFrame);
157 if ( frame )
158 {
159 if ( frame->GetLastFocus() == this )
160 {
161 frame->SetLastFocus((wxWindow*)NULL);
162 }
163 break;
164 }
165 }
166 #endif // __WXUNIVERSAL__
167
168 if ( s_lastMouseWindow == this )
169 {
170 s_lastMouseWindow = NULL ;
171 }
172
173 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
174 if ( frame )
175 {
176 if ( frame->GetLastFocus() == this )
177 frame->SetLastFocus( NULL ) ;
178 }
179
180 if ( gFocusWindow == this )
181 {
182 gFocusWindow = NULL ;
183 }
184
185 if ( m_parent )
186 m_parent->RemoveChild(this);
187
188 DestroyChildren();
189 }
190
191 // Constructor
192 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
193 const wxPoint& pos,
194 const wxSize& size,
195 long style,
196 const wxString& name)
197 {
198 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
199
200 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
201 return FALSE;
202
203 parent->AddChild(this);
204
205 m_x = (int)pos.x;
206 m_y = (int)pos.y;
207 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
208 m_width = WidthDefault( size.x );
209 m_height = HeightDefault( size.y ) ;
210 #ifndef __WXUNIVERSAL__
211 // Don't give scrollbars to wxControls unless they ask for them
212 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
213 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
214 {
215 MacCreateScrollBars( style ) ;
216 }
217 #endif
218 return TRUE;
219 }
220
221 void wxWindowMac::SetFocus()
222 {
223 if ( gFocusWindow == this )
224 return ;
225
226 if ( AcceptsFocus() )
227 {
228 if (gFocusWindow )
229 {
230 #if wxUSE_CARET
231 // Deal with caret
232 if ( gFocusWindow->m_caret )
233 {
234 gFocusWindow->m_caret->OnKillFocus();
235 }
236 #endif // wxUSE_CARET
237 #ifndef __WXUNIVERSAL__
238 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
239 if ( control && control->GetMacControl() )
240 {
241 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ;
242 control->MacRedrawControl() ;
243 }
244 #endif
245 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
246 event.SetEventObject(gFocusWindow);
247 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
248 }
249 gFocusWindow = this ;
250 {
251 #if wxUSE_CARET
252 // Deal with caret
253 if ( m_caret )
254 {
255 m_caret->OnSetFocus();
256 }
257 #endif // wxUSE_CARET
258 // panel wants to track the window which was the last to have focus in it
259 wxChildFocusEvent eventFocus(this);
260 GetEventHandler()->ProcessEvent(eventFocus);
261
262 #ifndef __WXUNIVERSAL__
263 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
264 if ( control && control->GetMacControl() )
265 {
266 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ;
267 }
268 #endif
269 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
270 event.SetEventObject(this);
271 GetEventHandler()->ProcessEvent(event) ;
272 }
273 }
274 }
275
276 bool wxWindowMac::Enable(bool enable)
277 {
278 if ( !wxWindowBase::Enable(enable) )
279 return FALSE;
280
281 MacSuperEnabled( enable ) ;
282
283 return TRUE;
284 }
285
286 void wxWindowMac::DoCaptureMouse()
287 {
288 wxTheApp->s_captureWindow = this ;
289 }
290
291 wxWindow* wxWindowBase::GetCapture()
292 {
293 return wxTheApp->s_captureWindow ;
294 }
295
296 void wxWindowMac::DoReleaseMouse()
297 {
298 wxTheApp->s_captureWindow = NULL ;
299 }
300
301 #if wxUSE_DRAG_AND_DROP
302
303 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
304 {
305 if ( m_dropTarget != 0 ) {
306 delete m_dropTarget;
307 }
308
309 m_dropTarget = pDropTarget;
310 if ( m_dropTarget != 0 )
311 {
312 // TODO
313 }
314 }
315
316 #endif
317
318 // Old style file-manager drag&drop
319 void wxWindowMac::DragAcceptFiles(bool accept)
320 {
321 // TODO
322 }
323
324 // Get total size
325 void wxWindowMac::DoGetSize(int *x, int *y) const
326 {
327 if(x) *x = m_width ;
328 if(y) *y = m_height ;
329 }
330
331 void wxWindowMac::DoGetPosition(int *x, int *y) const
332 {
333 int xx,yy;
334
335 xx = m_x ;
336 yy = m_y ;
337 if ( !IsTopLevel() && GetParent())
338 {
339 wxPoint pt(GetParent()->GetClientAreaOrigin());
340 xx -= pt.x;
341 yy -= pt.y;
342 }
343 if(x) *x = xx;
344 if(y) *y = yy;
345 }
346
347 #if wxUSE_MENUS
348 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
349 {
350 menu->SetInvokingWindow(this);
351 menu->UpdateUI();
352 ClientToScreen( &x , &y ) ;
353
354 ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
355 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
356 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
374 void 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
399 void 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
424 void 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
433 void 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
441 void 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
451 void 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
461 bool 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.
499 void 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
561 void 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
571 void 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
681 void 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
745 wxPoint wxWindowMac::GetClientAreaOrigin() const
746 {
747 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
748 }
749
750 void wxWindowMac::SetTitle(const wxString& title)
751 {
752 m_label = title ;
753 }
754
755 wxString wxWindowMac::GetTitle() const
756 {
757 return m_label ;
758 }
759
760 bool 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
787 void 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
799 void 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
817 bool 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
835 int wxWindowMac::GetCharHeight() const
836 {
837 wxClientDC dc ( (wxWindowMac*)this ) ;
838 return dc.GetCharHeight() ;
839 }
840
841 int wxWindowMac::GetCharWidth() const
842 {
843 wxClientDC dc ( (wxWindowMac*)this ) ;
844 return dc.GetCharWidth() ;
845 }
846
847 void 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
872 void 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
916 void wxWindowMac::CreateCaret(int w, int h)
917 {
918 SetCaret(new wxCaret(this, w, h));
919 }
920
921 void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
922 {
923 wxFAIL_MSG("not implemented");
924 }
925
926 void wxWindowMac::ShowCaret(bool show)
927 {
928 wxCHECK_RET( m_caret, "no caret to show" );
929
930 m_caret->Show(show);
931 }
932
933 void wxWindowMac::DestroyCaret()
934 {
935 SetCaret(NULL);
936 }
937
938 void 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
945 void 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
953 wxWindowMac *wxGetActiveWindow()
954 {
955 // actually this is a windows-only concept
956 return NULL;
957 }
958
959 // Coordinates relative to the window
960 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
961 {
962 // We really dont move the mouse programmatically under mac
963 }
964
965 const 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
1030 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1031 {
1032 event.GetDC()->Clear() ;
1033 }
1034
1035 void 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
1043 int 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.
1060 int 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
1075 int 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
1090 void 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
1104 void 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
1167 void 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.
1178 void 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
1219 void 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
1258 void 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
1294 wxWindowMac *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.
1303 void 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
1313 wxObject* 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
1330 void 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
1346 void 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
1355 void wxWindowMac::SetupColours()
1356 {
1357 if ( GetParent() )
1358 SetBackgroundColour(GetParent()->GetBackgroundColour());
1359 }
1360
1361 void 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
1384 void wxWindowMac::Raise()
1385 {
1386 }
1387
1388 // Lower the window to the bottom of the Z order
1389 void wxWindowMac::Lower()
1390 {
1391 }
1392
1393 void 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
1411 wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
1412
1413 bool 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
1453 bool 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
1481 static wxWindow *gs_lastWhich = NULL;
1482
1483 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
1484 {
1485 // first trigger a set cursor event
1486
1487 wxPoint clientorigin = GetClientAreaOrigin() ;
1488 wxSize clientsize = GetClientSize() ;
1489 wxCursor cursor ;
1490 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1491 {
1492 wxSetCursorEvent event( pt.x , pt.y );
1493
1494 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
1495 if ( processedEvtSetCursor && event.HasCursor() )
1496 {
1497 cursor = event.GetCursor() ;
1498 }
1499 else
1500 {
1501
1502 // the test for processedEvtSetCursor is here to prevent using m_cursor
1503 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1504 // it - this is a way to say that our cursor shouldn't be used for this
1505 // point
1506 if ( !processedEvtSetCursor && m_cursor.Ok() )
1507 {
1508 cursor = m_cursor ;
1509 }
1510 if ( wxIsBusy() )
1511 {
1512 }
1513 else
1514 {
1515 if ( !GetParent() )
1516 cursor = *wxSTANDARD_CURSOR ;
1517 }
1518 }
1519 if ( cursor.Ok() )
1520 cursor.MacInstall() ;
1521 }
1522 return cursor.Ok() ;
1523 }
1524
1525 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
1526 {
1527 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1528 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1529 return FALSE;
1530
1531
1532 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1533 return FALSE ;
1534
1535 WindowRef window = (WindowRef) MacGetRootWindow() ;
1536
1537 event.m_x -= m_x;
1538 event.m_y -= m_y;
1539
1540 int x = event.m_x ;
1541 int y = event.m_y ;
1542
1543 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1544 {
1545 wxWindowMac *child = (wxWindowMac*)node->Data();
1546 if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
1547 {
1548 if (child->MacDispatchMouseEvent(event))
1549 return TRUE;
1550 }
1551 }
1552
1553 wxWindow* cursorTarget = this ;
1554 wxPoint cursorPoint( x , y ) ;
1555
1556 while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
1557 {
1558 cursorTarget = cursorTarget->GetParent() ;
1559 if ( cursorTarget )
1560 cursorPoint += cursorTarget->GetPosition() ;
1561 }
1562 event.m_x = x ;
1563 event.m_y = y ;
1564 event.SetEventObject( this ) ;
1565
1566 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1567 {
1568 // set focus to this window
1569 if (AcceptsFocus() && FindFocus()!=this)
1570 SetFocus();
1571 }
1572
1573 #if wxUSE_TOOLTIPS
1574 if ( event.GetEventType() == wxEVT_MOTION
1575 || event.GetEventType() == wxEVT_ENTER_WINDOW
1576 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1577 wxToolTip::RelayEvent( this , event);
1578 #endif // wxUSE_TOOLTIPS
1579
1580 if (gs_lastWhich != this)
1581 {
1582 gs_lastWhich = this;
1583
1584 // Double clicks must always occur on the same window
1585 if (event.GetEventType() == wxEVT_LEFT_DCLICK)
1586 event.SetEventType( wxEVT_LEFT_DOWN );
1587 if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
1588 event.SetEventType( wxEVT_RIGHT_DOWN );
1589
1590 // Same for mouse up events
1591 if (event.GetEventType() == wxEVT_LEFT_UP)
1592 return TRUE;
1593 if (event.GetEventType() == wxEVT_RIGHT_UP)
1594 return TRUE;
1595 }
1596
1597 GetEventHandler()->ProcessEvent( event ) ;
1598
1599 return TRUE;
1600 }
1601
1602 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
1603 {
1604 if ( m_tooltip )
1605 {
1606 return m_tooltip->GetTip() ;
1607 }
1608 return "" ;
1609 }
1610
1611 void wxWindowMac::Update()
1612 {
1613 wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
1614 if ( win )
1615 {
1616 win->MacUpdate( 0 ) ;
1617 #if TARGET_API_MAC_CARBON
1618 if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) )
1619 {
1620 QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ;
1621 }
1622 #endif
1623 }
1624 }
1625
1626 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
1627 {
1628 wxTopLevelWindowMac* win = NULL ;
1629 WindowRef window = (WindowRef) MacGetRootWindow() ;
1630 if ( window )
1631 {
1632 win = wxFindWinFromMacWindow( window ) ;
1633 }
1634 return win ;
1635 }
1636
1637 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings )
1638 {
1639 RgnHandle visRgn = NewRgn() ;
1640 RgnHandle tempRgn = NewRgn() ;
1641 RgnHandle tempStaticBoxRgn = NewRgn() ;
1642
1643 SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
1644
1645 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1646 if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
1647 {
1648 int borderTop = 14 ;
1649 int borderOther = 4 ;
1650
1651 SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
1652 DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ;
1653 }
1654
1655 if ( !IsTopLevel() )
1656 {
1657 wxWindow* parent = GetParent() ;
1658 while( parent )
1659 {
1660 wxSize size = parent->GetSize() ;
1661 int x , y ;
1662 x = y = 0 ;
1663 parent->MacWindowToRootWindow( &x, &y ) ;
1664 MacRootWindowToWindow( &x , &y ) ;
1665
1666 SetRectRgn( tempRgn ,
1667 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
1668 x + size.x - parent->MacGetRightBorderSize(),
1669 y + size.y - parent->MacGetBottomBorderSize()) ;
1670
1671 SectRgn( visRgn , tempRgn , visRgn ) ;
1672 if ( parent->IsTopLevel() )
1673 break ;
1674 parent = parent->GetParent() ;
1675 }
1676 }
1677 if ( respectChildrenAndSiblings )
1678 {
1679 if ( GetWindowStyle() & wxCLIP_CHILDREN )
1680 {
1681 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1682 {
1683 wxWindowMac *child = (wxWindowMac*)node->Data();
1684
1685 if ( !child->IsTopLevel() && child->IsShown() )
1686 {
1687 SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1688 if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1689 {
1690 int borderTop = 14 ;
1691 int borderOther = 4 ;
1692
1693 SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ;
1694 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1695 }
1696 DiffRgn( visRgn , tempRgn , visRgn ) ;
1697 }
1698 }
1699 }
1700
1701 if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
1702 {
1703 bool thisWindowThrough = false ;
1704 for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next())
1705 {
1706 wxWindowMac *sibling = (wxWindowMac*)node->Data();
1707 if ( sibling == this )
1708 {
1709 thisWindowThrough = true ;
1710 continue ;
1711 }
1712 if( !thisWindowThrough )
1713 {
1714 continue ;
1715 }
1716
1717 if ( !sibling->IsTopLevel() && sibling->IsShown() )
1718 {
1719 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 ) ;
1720 if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1721 {
1722 int borderTop = 14 ;
1723 int borderOther = 4 ;
1724
1725 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 ) ;
1726 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1727 }
1728 DiffRgn( visRgn , tempRgn , visRgn ) ;
1729 }
1730 }
1731 }
1732 }
1733 m_macVisibleRegion = visRgn ;
1734 DisposeRgn( visRgn ) ;
1735 DisposeRgn( tempRgn ) ;
1736 DisposeRgn( tempStaticBoxRgn ) ;
1737 return m_macVisibleRegion ;
1738 }
1739
1740 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
1741 {
1742 RgnHandle updatergn = (RgnHandle) updatergnr ;
1743 // updatergn is always already clipped to our boundaries
1744 // it is in window coordinates, not in client coordinates
1745
1746 WindowRef window = (WindowRef) MacGetRootWindow() ;
1747
1748 {
1749 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1750 RgnHandle ownUpdateRgn = NewRgn() ;
1751 CopyRgn( updatergn , ownUpdateRgn ) ;
1752
1753 SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
1754
1755 // newupdate is the update region in client coordinates
1756 RgnHandle newupdate = NewRgn() ;
1757 wxSize point = GetClientSize() ;
1758 wxPoint origin = GetClientAreaOrigin() ;
1759 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1760 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1761 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1762 m_updateRegion = newupdate ;
1763 DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
1764
1765 if ( erase && !EmptyRgn(ownUpdateRgn) )
1766 {
1767 wxWindowDC dc(this);
1768 dc.SetClippingRegion(wxRegion(ownUpdateRgn));
1769 wxEraseEvent eevent( GetId(), &dc );
1770 eevent.SetEventObject( this );
1771 GetEventHandler()->ProcessEvent( eevent );
1772
1773 wxNcPaintEvent eventNc( GetId() );
1774 eventNc.SetEventObject( this );
1775 GetEventHandler()->ProcessEvent( eventNc );
1776 }
1777 DisposeRgn( ownUpdateRgn ) ;
1778 if ( !m_updateRegion.Empty() )
1779 {
1780 wxPaintEvent event;
1781 event.m_timeStamp = time ;
1782 event.SetEventObject(this);
1783 GetEventHandler()->ProcessEvent(event);
1784 }
1785 }
1786
1787 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1788
1789 RgnHandle childupdate = NewRgn() ;
1790 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1791 {
1792 // calculate the update region for the child windows by intersecting the window rectangle with our own
1793 // passed in update region and then offset it to be client-wise window coordinates again
1794 wxWindowMac *child = (wxWindowMac*)node->Data();
1795 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1796 SectRgn( childupdate , updatergn , childupdate ) ;
1797 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1798 if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
1799 {
1800 // because dialogs may also be children
1801 child->MacRedraw( childupdate , time , erase ) ;
1802 }
1803 }
1804 DisposeRgn( childupdate ) ;
1805 // eventually a draw grow box here
1806
1807 }
1808
1809 WXHWND wxWindowMac::MacGetRootWindow() const
1810 {
1811 wxWindowMac *iter = (wxWindowMac*)this ;
1812
1813 while( iter )
1814 {
1815 if ( iter->IsTopLevel() )
1816 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
1817
1818 iter = iter->GetParent() ;
1819 }
1820 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1821 return NULL ;
1822 }
1823
1824 void wxWindowMac::MacCreateScrollBars( long style )
1825 {
1826 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1827
1828 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1829 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1830 int width, height ;
1831 GetClientSize( &width , &height ) ;
1832
1833 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1834 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1835 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1836 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1837
1838 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1839 vSize , wxVERTICAL);
1840
1841 if ( style & wxVSCROLL )
1842 {
1843
1844 }
1845 else
1846 {
1847 m_vScrollBar->Show(false) ;
1848 }
1849 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1850 hSize , wxHORIZONTAL);
1851 if ( style & wxHSCROLL )
1852 {
1853 }
1854 else
1855 {
1856 m_hScrollBar->Show(false) ;
1857 }
1858
1859 // because the create does not take into account the client area origin
1860 MacRepositionScrollBars() ; // we might have a real position shift
1861 }
1862
1863 void wxWindowMac::MacRepositionScrollBars()
1864 {
1865 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1866 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1867
1868 // get real client area
1869
1870 int width = m_width ;
1871 int height = m_height ;
1872
1873 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1874 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
1875
1876 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1877 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1878 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1879 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1880
1881 int x = 0 ;
1882 int y = 0 ;
1883 int w = m_width ;
1884 int h = m_height ;
1885
1886 MacClientToRootWindow( &x , &y ) ;
1887 MacClientToRootWindow( &w , &h ) ;
1888
1889 wxWindowMac *iter = (wxWindowMac*)this ;
1890
1891 int totW = 10000 , totH = 10000;
1892 while( iter )
1893 {
1894 if ( iter->IsTopLevel() )
1895 {
1896 totW = iter->m_width ;
1897 totH = iter->m_height ;
1898 break ;
1899 }
1900
1901 iter = iter->GetParent() ;
1902 }
1903
1904 if ( x == 0 )
1905 {
1906 hPoint.x = -1 ;
1907 hSize.x += 1 ;
1908 }
1909 if ( y == 0 )
1910 {
1911 vPoint.y = -1 ;
1912 vSize.y += 1 ;
1913 }
1914
1915 if ( w-x >= totW )
1916 {
1917 hSize.x += 1 ;
1918 vPoint.x += 1 ;
1919 }
1920
1921 if ( h-y >= totH )
1922 {
1923 vSize.y += 1 ;
1924 hPoint.y += 1 ;
1925 }
1926
1927 if ( m_vScrollBar )
1928 {
1929 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
1930 }
1931 if ( m_hScrollBar )
1932 {
1933 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
1934 }
1935 }
1936
1937 bool wxWindowMac::AcceptsFocus() const
1938 {
1939 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1940 }
1941
1942 WXWidget wxWindowMac::MacGetContainerForEmbedding()
1943 {
1944 return GetParent()->MacGetContainerForEmbedding() ;
1945 }
1946
1947 void wxWindowMac::MacSuperChangedPosition()
1948 {
1949 // only window-absolute structures have to be moved i.e. controls
1950
1951 wxNode *node = GetChildren().First();
1952 while ( node )
1953 {
1954 wxWindowMac *child = (wxWindowMac *)node->Data();
1955 child->MacSuperChangedPosition() ;
1956 node = node->Next();
1957 }
1958 }
1959
1960 void wxWindowMac::MacTopLevelWindowChangedPosition()
1961 {
1962 // only screen-absolute structures have to be moved i.e. glcanvas
1963
1964 wxNode *node = GetChildren().First();
1965 while ( node )
1966 {
1967 wxWindowMac *child = (wxWindowMac *)node->Data();
1968 child->MacTopLevelWindowChangedPosition() ;
1969 node = node->Next();
1970 }
1971 }
1972 long wxWindowMac::MacGetLeftBorderSize( ) const
1973 {
1974 if( IsTopLevel() )
1975 return 0 ;
1976
1977 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
1978 {
1979 SInt32 border = 3 ;
1980 #if wxMAC_USE_THEME_BORDER
1981 #if TARGET_CARBON
1982 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1983 #endif
1984 #endif
1985 return border ;
1986 }
1987 else if ( m_windowStyle &wxDOUBLE_BORDER)
1988 {
1989 SInt32 border = 3 ;
1990 #if wxMAC_USE_THEME_BORDER
1991 #if TARGET_CARBON
1992 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1993 #endif
1994 #endif
1995 return border ;
1996 }
1997 else if (m_windowStyle &wxSIMPLE_BORDER)
1998 {
1999 return 1 ;
2000 }
2001 return 0 ;
2002 }
2003
2004 long wxWindowMac::MacGetRightBorderSize( ) const
2005 {
2006 // they are all symmetric in mac themes
2007 return MacGetLeftBorderSize() ;
2008 }
2009
2010 long wxWindowMac::MacGetTopBorderSize( ) const
2011 {
2012 // they are all symmetric in mac themes
2013 return MacGetLeftBorderSize() ;
2014 }
2015
2016 long wxWindowMac::MacGetBottomBorderSize( ) const
2017 {
2018 // they are all symmetric in mac themes
2019 return MacGetLeftBorderSize() ;
2020 }
2021
2022 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2023 {
2024 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2025 }
2026
2027 // Find the wxWindowMac at the current mouse position, returning the mouse
2028 // position.
2029 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2030 {
2031 pt = wxGetMousePosition();
2032 wxWindowMac* found = wxFindWindowAtPoint(pt);
2033 return found;
2034 }
2035
2036 // Get the current mouse position.
2037 wxPoint wxGetMousePosition()
2038 {
2039 int x, y;
2040 wxGetMousePosition(& x, & y);
2041 return wxPoint(x, y);
2042 }
2043