]> git.saurik.com Git - wxWidgets.git/blob - src/mac/window.cpp
added virtual listctrl support
[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/log.h"
39
40 #if wxUSE_CARET
41 #include "wx/caret.h"
42 #endif // wxUSE_CARET
43
44 #define wxWINDOW_HSCROLL 5998
45 #define wxWINDOW_VSCROLL 5997
46 #define MAC_SCROLLBAR_SIZE 16
47
48 #include <wx/mac/uma.h>
49
50 #if wxUSE_DRAG_AND_DROP
51 #include "wx/dnd.h"
52 #endif
53
54 #include <string.h>
55
56 extern wxList wxPendingDelete;
57 wxWindowMac* gFocusWindow = NULL ;
58
59 #if !USE_SHARED_LIBRARY
60 IMPLEMENT_DYNAMIC_CLASS(wxWindowMac, wxEvtHandler)
61 BEGIN_EVENT_TABLE(wxWindowMac, wxEvtHandler)
62 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
63 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
64 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
65 EVT_IDLE(wxWindowMac::OnIdle)
66 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
67 END_EVENT_TABLE()
68
69 #endif
70
71
72
73 // ===========================================================================
74 // implementation
75 // ===========================================================================
76
77 // ---------------------------------------------------------------------------
78 // wxWindowMac utility functions
79 // ---------------------------------------------------------------------------
80
81 // Find an item given the Macintosh Window Reference
82
83 wxList *wxWinMacWindowList = NULL;
84 wxWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
85 {
86 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
87 if (!node)
88 return NULL;
89 return (wxWindowMac *)node->Data();
90 }
91
92 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindowMac *win)
93 {
94 // adding NULL WindowRef is (first) surely a result of an error and
95 // (secondly) breaks menu command processing
96 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
97
98 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
99 wxWinMacWindowList->Append((long)inWindowRef, win);
100 }
101
102 void wxRemoveMacWindowAssociation(wxWindowMac *win)
103 {
104 wxWinMacWindowList->DeleteObject(win);
105 }
106
107 // ----------------------------------------------------------------------------
108 // constructors and such
109 // ----------------------------------------------------------------------------
110
111 WindowRef wxWindowMac::s_macWindowInUpdate = NULL;
112
113 void wxWindowMac::Init()
114 {
115 // generic
116 InitBase();
117
118 m_macEraseOnRedraw = true ;
119
120 // MSW specific
121 m_doubleClickAllowed = 0;
122 m_winCaptured = FALSE;
123
124 m_isBeingDeleted = FALSE;
125
126 m_useCtl3D = FALSE;
127 m_mouseInWindow = FALSE;
128
129 m_xThumbSize = 0;
130 m_yThumbSize = 0;
131 m_backgroundTransparent = FALSE;
132
133 // as all windows are created with WS_VISIBLE style...
134 m_isShown = TRUE;
135
136 m_macWindowData = NULL ;
137 m_macEraseOnRedraw = true ;
138
139 m_x = 0;
140 m_y = 0 ;
141 m_width = 0 ;
142 m_height = 0 ;
143
144 m_hScrollBar = NULL ;
145 m_vScrollBar = NULL ;
146
147 #if wxUSE_DRAG_AND_DROP
148 m_pDropTarget = NULL;
149 #endif
150 }
151
152 // Destructor
153 wxWindowMac::~wxWindowMac()
154 {
155 // deleting a window while it is shown invalidates the region
156 if ( IsShown() ) {
157 wxWindowMac* iter = this ;
158 while( iter ) {
159 if ( iter->m_macWindowData )
160 {
161 Refresh() ;
162 break ;
163 }
164 iter = iter->GetParent() ;
165
166 }
167 }
168
169 m_isBeingDeleted = TRUE;
170
171 if ( s_lastMouseWindow == this )
172 {
173 s_lastMouseWindow = NULL ;
174 }
175
176 if ( gFocusWindow == this )
177 {
178 gFocusWindow = NULL ;
179 }
180
181 if ( m_parent )
182 m_parent->RemoveChild(this);
183
184 DestroyChildren();
185
186 if ( m_macWindowData )
187 {
188 wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ;
189 UMADisposeWindow( m_macWindowData->m_macWindow ) ;
190 delete m_macWindowData ;
191 wxRemoveMacWindowAssociation( this ) ;
192 }
193 }
194
195 // Constructor
196 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
197 const wxPoint& pos,
198 const wxSize& size,
199 long style,
200 const wxString& name)
201 {
202 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
203
204 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
205 return FALSE;
206
207 parent->AddChild(this);
208
209 m_x = (int)pos.x;
210 m_y = (int)pos.y;
211 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
212 m_width = WidthDefault( size.x );
213 m_height = HeightDefault( size.y ) ;
214 #ifndef __WXUNIVERSAL__
215 if ( ! IsKindOf( CLASSINFO ( wxControl ) ) && ! IsKindOf( CLASSINFO( wxStatusBar ) ) )
216 {
217 MacCreateScrollBars( style ) ;
218 }
219 #endif
220 return TRUE;
221 }
222
223 void wxWindowMac::SetFocus()
224 {
225 if ( gFocusWindow == this )
226 return ;
227
228 if ( AcceptsFocus() )
229 {
230 if (gFocusWindow )
231 {
232 #if wxUSE_CARET
233 // Deal with caret
234 if ( gFocusWindow->m_caret )
235 {
236 gFocusWindow->m_caret->OnKillFocus();
237 }
238 #endif // wxUSE_CARET
239 #ifndef __WXUNIVERSAL__
240 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
241 if ( control && control->GetMacControl() )
242 {
243 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
244 control->MacRedrawControl() ;
245 }
246 #endif
247 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
248 event.SetEventObject(gFocusWindow);
249 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
250 }
251 gFocusWindow = this ;
252 {
253 #if wxUSE_CARET
254 // Deal with caret
255 if ( m_caret )
256 {
257 m_caret->OnSetFocus();
258 }
259 #endif // wxUSE_CARET
260 // panel wants to track the window which was the last to have focus in it
261 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
262 if ( panel )
263 {
264 panel->SetLastFocus((wxWindow*)this);
265 }
266 #ifndef __WXUNIVERSAL__
267 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
268 if ( control && control->GetMacControl() )
269 {
270 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
271 }
272 #endif
273 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
274 event.SetEventObject(this);
275 GetEventHandler()->ProcessEvent(event) ;
276 }
277 }
278 }
279
280 bool wxWindowMac::Enable(bool enable)
281 {
282 if ( !wxWindowBase::Enable(enable) )
283 return FALSE;
284
285 wxWindowList::Node *node = GetChildren().GetFirst();
286 while ( node )
287 {
288 wxWindowMac *child = node->GetData();
289 child->Enable(enable);
290
291 node = node->GetNext();
292 }
293
294 return TRUE;
295 }
296
297 void wxWindowMac::CaptureMouse()
298 {
299 wxTheApp->s_captureWindow = this ;
300 }
301
302 wxWindow* wxWindowBase::GetCapture()
303 {
304 return wxTheApp->s_captureWindow ;
305 }
306
307 void wxWindowMac::ReleaseMouse()
308 {
309 wxTheApp->s_captureWindow = NULL ;
310 }
311
312 #if wxUSE_DRAG_AND_DROP
313
314 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
315 {
316 if ( m_pDropTarget != 0 ) {
317 delete m_pDropTarget;
318 }
319
320 m_pDropTarget = pDropTarget;
321 if ( m_pDropTarget != 0 )
322 {
323 // TODO
324 }
325 }
326
327 #endif
328
329 // Old style file-manager drag&drop
330 void wxWindowMac::DragAcceptFiles(bool accept)
331 {
332 // TODO
333 }
334
335 // Get total size
336 void wxWindowMac::DoGetSize(int *x, int *y) const
337 {
338 *x = m_width ;
339 *y = m_height ;
340 }
341
342 void wxWindowMac::DoGetPosition(int *x, int *y) const
343 {
344 *x = m_x ;
345 *y = m_y ;
346 if (GetParent())
347 {
348 wxPoint pt(GetParent()->GetClientAreaOrigin());
349 *x -= pt.x;
350 *y -= pt.y;
351 }
352 }
353
354 #if wxUSE_MENUS
355 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
356 {
357 menu->SetInvokingWindow(this);
358 menu->UpdateUI();
359 ClientToScreen( &x , &y ) ;
360
361 ::InsertMenu( menu->GetHMenu() , -1 ) ;
362 long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
363 menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
364 ::DeleteMenu( menu->MacGetMenuId() ) ;
365 menu->SetInvokingWindow(NULL);
366
367 return TRUE;
368 }
369 #endif
370
371 void wxWindowMac::DoScreenToClient(int *x, int *y) const
372 {
373 WindowRef window = GetMacRootWindow() ;
374
375 Point localwhere ;
376 localwhere.h = * x ;
377 localwhere.v = * y ;
378
379 GrafPtr port ;
380 ::GetPort( &port ) ;
381 ::SetPort( UMAGetWindowPort( window ) ) ;
382 ::GlobalToLocal( &localwhere ) ;
383 ::SetPort( port ) ;
384
385 *x = localwhere.h ;
386 *y = localwhere.v ;
387
388 MacRootWindowToClient( x , y ) ;
389 }
390
391 void wxWindowMac::DoClientToScreen(int *x, int *y) const
392 {
393 WindowRef window = GetMacRootWindow() ;
394
395 MacClientToRootWindow( x , y ) ;
396
397 Point localwhere ;
398 localwhere.h = * x ;
399 localwhere.v = * y ;
400
401 GrafPtr port ;
402 ::GetPort( &port ) ;
403 ::SetPort( UMAGetWindowPort( window ) ) ;
404 ::SetOrigin( 0 , 0 ) ;
405 ::LocalToGlobal( &localwhere ) ;
406 ::SetPort( port ) ;
407 *x = localwhere.h ;
408 *y = localwhere.v ;
409 }
410
411 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
412 {
413 if ( m_macWindowData )
414 {
415 }
416 else
417 {
418 *x += m_x ;
419 *y += m_y ;
420 GetParent()->MacClientToRootWindow( x , y ) ;
421 }
422 }
423
424 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
425 {
426 if ( m_macWindowData )
427 {
428 }
429 else
430 {
431 *x -= m_x ;
432 *y -= m_y ;
433 GetParent()->MacRootWindowToClient( x , y ) ;
434 }
435 }
436
437 bool wxWindowMac::SetCursor(const wxCursor& cursor)
438 {
439 if (m_cursor == cursor)
440 return FALSE;
441
442 if (wxNullCursor == cursor)
443 {
444 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
445 return FALSE ;
446 }
447 else
448 {
449 if ( ! wxWindowBase::SetCursor( cursor ) )
450 return FALSE ;
451 }
452
453 wxASSERT_MSG( m_cursor.Ok(),
454 wxT("cursor must be valid after call to the base version"));
455
456 Point pt ;
457 wxWindowMac *mouseWin ;
458 GetMouse( &pt ) ;
459
460 // Change the cursor NOW if we're within the correct window
461
462 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
463 {
464 if ( mouseWin == this && !wxIsBusy() )
465 {
466 m_cursor.MacInstall() ;
467 }
468 }
469
470 return TRUE ;
471 }
472
473
474 // Get size *available for subwindows* i.e. excluding menu bar etc.
475 void wxWindowMac::DoGetClientSize(int *x, int *y) const
476 {
477 *x = m_width ;
478 *y = m_height ;
479
480 *x -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
481 *y -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
482
483 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
484 {
485 int x1 = 0 ;
486 int y1 = 0 ;
487 int w = m_width ;
488 int h = m_height ;
489
490 MacClientToRootWindow( &x1 , &y1 ) ;
491 MacClientToRootWindow( &w , &h ) ;
492
493 WindowRef window = NULL ;
494 wxWindowMac *iter = (wxWindowMac*)this ;
495
496 int totW = 10000 , totH = 10000;
497 while( iter )
498 {
499 if ( iter->m_macWindowData )
500 {
501 totW = iter->m_width ;
502 totH = iter->m_height ;
503 break ;
504 }
505
506 iter = iter->GetParent() ;
507 }
508
509 if (m_hScrollBar && m_hScrollBar->IsShown() )
510 {
511 (*y) -= MAC_SCROLLBAR_SIZE;
512 if ( h-y1 >= totH )
513 {
514 (*y)+= 1 ;
515 }
516 }
517 if (m_vScrollBar && m_vScrollBar->IsShown() )
518 {
519 (*x) -= MAC_SCROLLBAR_SIZE;
520 if ( w-x1 >= totW )
521 {
522 (*x) += 1 ;
523 }
524 }
525 }
526 }
527
528
529 // ----------------------------------------------------------------------------
530 // tooltips
531 // ----------------------------------------------------------------------------
532
533 #if wxUSE_TOOLTIPS
534
535 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
536 {
537 wxWindowBase::DoSetToolTip(tooltip);
538
539 if ( m_tooltip )
540 m_tooltip->SetWindow(this);
541 }
542
543 #endif // wxUSE_TOOLTIPS
544
545 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
546 {
547 DoSetSize( x,y, width, height ) ;
548 }
549
550 // set the size of the window: if the dimensions are positive, just use them,
551 // but if any of them is equal to -1, it means that we must find the value for
552 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
553 // which case -1 is a valid value for x and y)
554 //
555 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
556 // the width/height to best suit our contents, otherwise we reuse the current
557 // width/height
558 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
559 {
560
561 int former_x = m_x ;
562 int former_y = m_y ;
563 int former_w = m_width ;
564 int former_h = m_height ;
565
566 int currentX, currentY;
567 GetPosition(&currentX, &currentY);
568 int currentW,currentH;
569 GetSize(&currentW, &currentH);
570
571 int actualWidth = width;
572 int actualHeight = height;
573 int actualX = x;
574 int actualY = y;
575 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
576 actualX = currentX;
577 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
578 actualY = currentY;
579
580 wxSize size( -1 , -1 ) ;
581
582 if (width == -1 || height == -1 )
583 {
584 size = DoGetBestSize() ;
585 }
586
587 if ( width == -1 )
588 {
589 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
590 {
591 actualWidth = size.x ;
592 if ( actualWidth == -1 )
593 actualWidth = 80 ;
594 }
595 else
596 {
597 actualWidth = currentW ;
598 }
599 }
600 if (height == -1)
601 {
602 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
603 {
604 actualHeight = size.y ;
605 if ( actualHeight == -1 )
606 actualHeight = 26 ;
607 }
608 else
609 {
610 actualHeight = currentH ;
611 }
612 }
613
614 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
615 actualWidth = m_minWidth;
616 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
617 actualHeight = m_minHeight;
618 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
619 actualWidth = m_maxWidth;
620 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
621 actualHeight = m_maxHeight;
622 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
623 {
624 MacRepositionScrollBars() ; // we might have a real position shift
625 return ;
626 }
627
628 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
629
630
631 bool doMove = false ;
632 bool doResize = false ;
633
634 if ( actualX != former_x || actualY != former_y )
635 {
636 doMove = true ;
637 }
638 if ( actualWidth != former_w || actualHeight != former_h )
639 {
640 doResize = true ;
641 }
642
643 if ( doMove || doResize )
644 {
645 if ( m_macWindowData )
646 {
647 }
648 else
649 {
650 // erase former position
651 wxMacDrawingHelper focus( this ) ;
652 if ( focus.Ok() )
653 {
654 Rect clientrect = { 0 , 0 , m_height , m_width } ;
655 // ClipRect( &clientrect ) ;
656 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
657 }
658 }
659 m_x = actualX ;
660 m_y = actualY ;
661 m_width = actualWidth ;
662 m_height = actualHeight ;
663 if ( m_macWindowData )
664 {
665 if ( doMove )
666 ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost
667
668 if ( doResize )
669 ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true);
670
671 // the OS takes care of invalidating and erasing the new area
672 // we have erased the old one
673
674 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
675 {
676 wxFrame* frame = (wxFrame*) this ;
677 frame->PositionStatusBar();
678 frame->PositionToolBar();
679 }
680 }
681 else
682 {
683 // erase new position
684
685 {
686 wxMacDrawingHelper focus( this ) ;
687 if ( focus.Ok() )
688 {
689 Rect clientrect = { 0 , 0 , m_height , m_width } ;
690 // ClipRect( &clientrect ) ;
691 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
692 }
693 }
694
695 if ( doMove )
696 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
697 }
698 MacRepositionScrollBars() ;
699 if ( doMove )
700 {
701 wxPoint point(m_x, m_y);
702 wxMoveEvent event(point, m_windowId);
703 event.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(event) ;
705 }
706 if ( doResize )
707 {
708 MacRepositionScrollBars() ;
709 wxSize size(m_width, m_height);
710 wxSizeEvent event(size, m_windowId);
711 event.SetEventObject(this);
712 GetEventHandler()->ProcessEvent(event);
713 }
714 }
715 }
716 // For implementation purposes - sometimes decorations make the client area
717 // smaller
718
719 wxPoint wxWindowMac::GetClientAreaOrigin() const
720 {
721 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
722 }
723
724 // Makes an adjustment to the window position (for example, a frame that has
725 // a toolbar that it manages itself).
726 void wxWindowMac::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
727 {
728 if( !m_macWindowData )
729 {
730 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
731 {
732 wxPoint pt(GetParent()->GetClientAreaOrigin());
733 x += pt.x; y += pt.y;
734 }
735 }
736 }
737
738 void wxWindowMac::SetTitle(const wxString& title)
739 {
740 m_label = title ;
741
742 wxString label ;
743
744 if( wxApp::s_macDefaultEncodingIsPC )
745 label = wxMacMakeMacStringFromPC( title ) ;
746 else
747 label = title ;
748
749 if ( m_macWindowData )
750 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
751 }
752
753 wxString wxWindowMac::GetTitle() const
754 {
755 return m_label ;
756 }
757
758 bool wxWindowMac::Show(bool show)
759 {
760 if ( !wxWindowBase::Show(show) )
761 return FALSE;
762
763 if ( m_macWindowData )
764 {
765 if (show)
766 {
767 UMAShowWindow( m_macWindowData->m_macWindow ) ;
768 UMASelectWindow( m_macWindowData->m_macWindow ) ;
769 // no need to generate events here, they will get them triggered by macos
770 // actually they should be , but apparently they are not
771 wxSize size(m_width, m_height);
772 wxSizeEvent event(size, m_windowId);
773 event.SetEventObject(this);
774 GetEventHandler()->ProcessEvent(event);
775 }
776 else
777 {
778 UMAHideWindow( m_macWindowData->m_macWindow ) ;
779 }
780 }
781 MacSuperShown( show ) ;
782 if ( !show )
783 {
784 WindowRef window = GetMacRootWindow() ;
785 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
786 if ( !win->m_isBeingDeleted )
787 Refresh() ;
788 }
789 else
790 {
791 Refresh() ;
792 }
793
794 return TRUE;
795 }
796
797 void wxWindowMac::MacSuperShown( bool show )
798 {
799 wxNode *node = GetChildren().First();
800 while ( node )
801 {
802 wxWindowMac *child = (wxWindowMac *)node->Data();
803 if ( child->m_isShown )
804 child->MacSuperShown( show ) ;
805 node = node->Next();
806 }
807 }
808
809 bool wxWindowMac::MacIsReallyShown() const
810 {
811 if ( m_isShown && (m_parent != NULL) ) {
812 return m_parent->MacIsReallyShown();
813 }
814 return m_isShown;
815 /*
816 bool status = m_isShown ;
817 wxWindowMac * win = this ;
818 while ( status && win->m_parent != NULL )
819 {
820 win = win->m_parent ;
821 status = win->m_isShown ;
822 }
823 return status ;
824 */
825 }
826
827 int wxWindowMac::GetCharHeight() const
828 {
829 wxClientDC dc ( (wxWindowMac*)this ) ;
830 return dc.GetCharHeight() ;
831 }
832
833 int wxWindowMac::GetCharWidth() const
834 {
835 wxClientDC dc ( (wxWindowMac*)this ) ;
836 return dc.GetCharWidth() ;
837 }
838
839 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
840 int *descent, int *externalLeading, const wxFont *theFont ) const
841 {
842 const wxFont *fontToUse = theFont;
843 if ( !fontToUse )
844 fontToUse = &m_font;
845
846 wxClientDC dc( (wxWindowMac*) this ) ;
847 long lx,ly,ld,le ;
848 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
849 if ( externalLeading )
850 *externalLeading = le ;
851 if ( descent )
852 *descent = ld ;
853 if ( x )
854 *x = lx ;
855 if ( y )
856 *y = ly ;
857 }
858
859 void wxWindowMac::MacEraseBackground( Rect *rect )
860 {
861 /*
862 WindowRef window = GetMacRootWindow() ;
863 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
864 {
865 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
866 }
867 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
868 {
869 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
870 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
871 // either a non gray background color or a non control window
872
873 wxWindowMac* parent = GetParent() ;
874 while( parent )
875 {
876 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
877 {
878 // if we have any other colours in the hierarchy
879 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
880 break ;
881 }
882 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
883 {
884 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
885 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
886 {
887 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
888 break ;
889 }
890 }
891 else
892 {
893 // we have arrived at a non control item
894 parent = NULL ;
895 break ;
896 }
897 parent = parent->GetParent() ;
898 }
899 if ( !parent )
900 {
901 // if there is nothing special -> use default
902 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
903 }
904 }
905 else
906 {
907 RGBBackColor( &m_backgroundColour.GetPixel()) ;
908 }
909
910 EraseRect( rect ) ;
911
912 for (wxNode *node = GetChildren().First(); node; node = node->Next())
913 {
914 wxWindowMac *child = (wxWindowMac*)node->Data();
915
916 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
917 SectRect( &clientrect , rect , &clientrect ) ;
918
919 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
920 if ( child->GetMacRootWindow() == window && child->IsShown() )
921 {
922 wxMacDrawingClientHelper focus( this ) ;
923 if ( focus.Ok() )
924 {
925 child->MacEraseBackground( &clientrect ) ;
926 }
927 }
928 }
929 */
930 }
931
932 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
933 {
934 // if ( !IsShown() )
935 // return ;
936
937 wxMacDrawingClientHelper focus( this ) ;
938 if ( focus.Ok() )
939 {
940 wxPoint client ;
941 client = GetClientAreaOrigin( ) ;
942 Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ;
943 // ClipRect( &clientrect ) ;
944
945 if ( rect )
946 {
947 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
948 SectRect( &clientrect , &r , &clientrect ) ;
949 }
950 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
951 }
952 if ( !eraseBack )
953 m_macEraseOnRedraw = false ;
954 else
955 m_macEraseOnRedraw = true ;
956 }
957
958 // Responds to colour changes: passes event on to children.
959 void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent& event)
960 {
961 wxNode *node = GetChildren().First();
962 while ( node )
963 {
964 // Only propagate to non-top-level windows
965 wxWindowMac *win = (wxWindowMac *)node->Data();
966 if ( win->GetParent() )
967 {
968 wxSysColourChangedEvent event2;
969 event.m_eventObject = win;
970 win->GetEventHandler()->ProcessEvent(event2);
971 }
972
973 node = node->Next();
974 }
975 }
976
977 #if wxUSE_CARET && WXWIN_COMPATIBILITY
978 // ---------------------------------------------------------------------------
979 // Caret manipulation
980 // ---------------------------------------------------------------------------
981
982 void wxWindowMac::CreateCaret(int w, int h)
983 {
984 SetCaret(new wxCaret(this, w, h));
985 }
986
987 void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
988 {
989 wxFAIL_MSG("not implemented");
990 }
991
992 void wxWindowMac::ShowCaret(bool show)
993 {
994 wxCHECK_RET( m_caret, "no caret to show" );
995
996 m_caret->Show(show);
997 }
998
999 void wxWindowMac::DestroyCaret()
1000 {
1001 SetCaret(NULL);
1002 }
1003
1004 void wxWindowMac::SetCaretPos(int x, int y)
1005 {
1006 wxCHECK_RET( m_caret, "no caret to move" );
1007
1008 m_caret->Move(x, y);
1009 }
1010
1011 void wxWindowMac::GetCaretPos(int *x, int *y) const
1012 {
1013 wxCHECK_RET( m_caret, "no caret to get position of" );
1014
1015 m_caret->GetPosition(x, y);
1016 }
1017 #endif // wxUSE_CARET
1018
1019 wxWindowMac *wxGetActiveWindow()
1020 {
1021 // actually this is a windows-only concept
1022 return NULL;
1023 }
1024
1025 // Coordinates relative to the window
1026 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1027 {
1028 // We really dont move the mouse programmatically under mac
1029 }
1030
1031 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1032 {
1033 // TODO : probably we would adopt the EraseEvent structure
1034 }
1035
1036 int wxWindowMac::GetScrollPos(int orient) const
1037 {
1038 if ( orient == wxHORIZONTAL )
1039 {
1040 if ( m_hScrollBar )
1041 return m_hScrollBar->GetThumbPosition() ;
1042 }
1043 else
1044 {
1045 if ( m_vScrollBar )
1046 return m_vScrollBar->GetThumbPosition() ;
1047 }
1048 return 0;
1049 }
1050
1051 // This now returns the whole range, not just the number
1052 // of positions that we can scroll.
1053 int wxWindowMac::GetScrollRange(int orient) const
1054 {
1055 if ( orient == wxHORIZONTAL )
1056 {
1057 if ( m_hScrollBar )
1058 return m_hScrollBar->GetRange() ;
1059 }
1060 else
1061 {
1062 if ( m_vScrollBar )
1063 return m_vScrollBar->GetRange() ;
1064 }
1065 return 0;
1066 }
1067
1068 int wxWindowMac::GetScrollThumb(int orient) const
1069 {
1070 if ( orient == wxHORIZONTAL )
1071 {
1072 if ( m_hScrollBar )
1073 return m_hScrollBar->GetThumbSize() ;
1074 }
1075 else
1076 {
1077 if ( m_vScrollBar )
1078 return m_vScrollBar->GetThumbSize() ;
1079 }
1080 return 0;
1081 }
1082
1083 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1084 {
1085 if ( orient == wxHORIZONTAL )
1086 {
1087 if ( m_hScrollBar )
1088 m_hScrollBar->SetThumbPosition( pos ) ;
1089 }
1090 else
1091 {
1092 if ( m_vScrollBar )
1093 m_vScrollBar->SetThumbPosition( pos ) ;
1094 }
1095 }
1096
1097 void wxWindowMac::MacCreateRealWindow( const wxString& title,
1098 const wxPoint& pos,
1099 const wxSize& size,
1100 long style,
1101 const wxString& name )
1102 {
1103 SetName(name);
1104 m_windowStyle = style;
1105 m_isShown = FALSE;
1106
1107 // create frame.
1108
1109 Rect theBoundsRect;
1110
1111 m_x = (int)pos.x;
1112 m_y = (int)pos.y;
1113 if ( m_y < 50 )
1114 m_y = 50 ;
1115 if ( m_x < 20 )
1116 m_x = 20 ;
1117
1118 m_width = size.x;
1119 if (m_width == -1)
1120 m_width = 20;
1121 m_height = size.y;
1122 if (m_height == -1)
1123 m_height = 20;
1124
1125 m_macWindowData = new MacWindowData() ;
1126
1127 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
1128
1129 // translate the window attributes in the appropriate window class and attributes
1130
1131 WindowClass wclass = 0;
1132 WindowAttributes attr = kWindowNoAttributes ;
1133
1134 if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) )
1135 {
1136 wclass = kFloatingWindowClass ;
1137 if ( HasFlag(wxTINY_CAPTION_VERT) )
1138 {
1139 attr |= kWindowSideTitlebarAttribute ;
1140 }
1141 }
1142 else if ( HasFlag( wxCAPTION ) )
1143 {
1144 if ( HasFlag( wxDIALOG_MODAL ) )
1145 {
1146 wclass = kMovableModalWindowClass ;
1147 }
1148 else
1149 {
1150 wclass = kDocumentWindowClass ;
1151 }
1152 }
1153 else
1154 {
1155 wclass = kModalWindowClass ;
1156 }
1157
1158 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
1159 {
1160 attr |= kWindowFullZoomAttribute ;
1161 attr |= kWindowCollapseBoxAttribute ;
1162 }
1163 if ( HasFlag( wxRESIZE_BORDER ) )
1164 {
1165 attr |= kWindowResizableAttribute ;
1166 }
1167 if ( HasFlag( wxSYSTEM_MENU ) )
1168 {
1169 attr |= kWindowCloseBoxAttribute ;
1170 }
1171
1172 UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ;
1173 wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ;
1174 wxString label ;
1175 if( wxApp::s_macDefaultEncodingIsPC )
1176 label = wxMacMakeMacStringFromPC( title ) ;
1177 else
1178 label = title ;
1179 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
1180 UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
1181
1182 m_macWindowData->m_macFocus = NULL ;
1183 m_macWindowData->m_macHasReceivedFirstActivate = true ;
1184 }
1185
1186 void wxWindowMac::MacPaint( wxPaintEvent &event )
1187 {
1188 }
1189
1190 void wxWindowMac::MacPaintBorders( )
1191 {
1192 if( m_macWindowData )
1193 return ;
1194
1195 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1196 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1197 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1198 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1199 PenNormal() ;
1200
1201 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1202 {
1203 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1204 RGBColor pen1 = sunken ? white : black ;
1205 RGBColor pen2 = sunken ? shadow : face ;
1206 RGBColor pen3 = sunken ? face : shadow ;
1207 RGBColor pen4 = sunken ? black : white ;
1208
1209 RGBForeColor( &pen1 ) ;
1210 {
1211 Rect rect = { 0 , 0 , m_height , m_width } ;
1212 FrameRect( &rect ) ;
1213 }
1214 RGBForeColor( &pen2 ) ;
1215 {
1216 Rect rect = { 1 , 1 , m_height -1 , m_width -1} ;
1217 FrameRect( &rect ) ;
1218 }
1219 RGBForeColor( &pen3 ) ;
1220 {
1221 Rect rect = { 0 , 0 , m_height -2 , m_width -2} ;
1222 FrameRect( &rect ) ;
1223 }
1224 RGBForeColor( &pen4 ) ;
1225 {
1226 MoveTo( 0 , 0 ) ;
1227 LineTo( m_width - 3 , 0 ) ;
1228 MoveTo( 0 , 0 ) ;
1229 LineTo( 0 , m_height - 3 ) ;
1230 }
1231 }
1232 else if (HasFlag(wxSIMPLE_BORDER))
1233 {
1234 Rect rect = { 0 , 0 , m_height , m_width } ;
1235 RGBForeColor( &black ) ;
1236 FrameRect( &rect ) ;
1237 }
1238 /*
1239 if ( this->GetParent() )
1240 {
1241 wxPaintDC dc(GetParent());
1242 GetParent()->PrepareDC(dc);
1243
1244 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1245 {
1246 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1247
1248 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1249 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1250
1251 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1252 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1253 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1254 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1255
1256 dc.SetPen(wxPen1);
1257 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1258
1259 dc.SetPen(wxPen2);
1260 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1261
1262 dc.SetPen(wxPen3);
1263 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1264
1265 dc.SetPen(wxPen4);
1266 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1267 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1268 }
1269 else if (HasFlag(wxDOUBLE_BORDER))
1270 {
1271 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1272
1273 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1274 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1275
1276 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1277 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1278 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1279 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1280
1281 dc.SetPen(wxPen1);
1282 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1283
1284 dc.SetPen(wxPen2);
1285 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1286
1287 dc.SetPen(wxPen3);
1288 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1289
1290 dc.SetPen(wxPen4);
1291 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1292 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1293 }
1294 else if (HasFlag(wxSIMPLE_BORDER))
1295 {
1296 dc.SetPen(*wxBLACK_PEN);
1297 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1298 }
1299 }
1300 */
1301 }
1302
1303 // New function that will replace some of the above.
1304 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1305 int range, bool refresh)
1306 {
1307 if ( orient == wxHORIZONTAL )
1308 {
1309 if ( m_hScrollBar )
1310 {
1311 if ( range == 0 || thumbVisible >= range )
1312 {
1313 if ( m_hScrollBar->IsShown() )
1314 m_hScrollBar->Show(false) ;
1315 }
1316 else
1317 {
1318 if ( !m_hScrollBar->IsShown() )
1319 m_hScrollBar->Show(true) ;
1320 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1321 }
1322 }
1323 }
1324 else
1325 {
1326 if ( m_vScrollBar )
1327 {
1328 if ( range == 0 || thumbVisible >= range )
1329 {
1330 if ( m_vScrollBar->IsShown() )
1331 m_vScrollBar->Show(false) ;
1332 }
1333 else
1334 {
1335 if ( !m_vScrollBar->IsShown() )
1336 m_vScrollBar->Show(true) ;
1337 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1338 }
1339 }
1340 }
1341 MacRepositionScrollBars() ;
1342 }
1343
1344 // Does a physical scroll
1345 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1346 {
1347 wxMacDrawingClientHelper focus( this ) ;
1348 if ( focus.Ok() )
1349 {
1350 int width , height ;
1351 GetClientSize( &width , &height ) ;
1352
1353 Rect scrollrect = { 0 , 0 , height , width } ;
1354
1355 RgnHandle updateRgn = NewRgn() ;
1356 ClipRect( &scrollrect ) ;
1357 if ( rect )
1358 {
1359 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1360 SectRect( &scrollrect , &r , &scrollrect ) ;
1361 }
1362 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1363 InvalWindowRgn( GetMacRootWindow() , updateRgn ) ;
1364 DisposeRgn( updateRgn ) ;
1365 }
1366
1367 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1368 {
1369 wxWindowMac *child = (wxWindowMac*)node->Data();
1370 if (child == m_vScrollBar) continue;
1371 if (child == m_hScrollBar) continue;
1372 if (child->IsTopLevel()) continue;
1373 int x,y;
1374 child->GetPosition( &x, &y );
1375 int w,h;
1376 child->GetSize( &w, &h );
1377 child->SetSize( x+dx, y+dy, w, h );
1378 }
1379
1380 }
1381
1382 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
1383 {
1384 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1385 {
1386 wxScrollWinEvent wevent;
1387 wevent.SetPosition(event.GetPosition());
1388 wevent.SetOrientation(event.GetOrientation());
1389 wevent.m_eventObject = this;
1390
1391 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1392 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1393 } else
1394 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1395 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1396 } else
1397 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1398 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1399 } else
1400 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1401 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1402 } else
1403 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1404 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1405 } else
1406 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1407 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1408 } else
1409 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1410 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1411 }
1412
1413 GetEventHandler()->ProcessEvent(wevent);
1414 }
1415 }
1416
1417 bool wxWindowMac::SetFont(const wxFont& font)
1418 {
1419 if ( !wxWindowBase::SetFont(font) )
1420 {
1421 // nothing to do
1422 return FALSE;
1423 }
1424
1425 return TRUE;
1426 }
1427
1428 // Get the window with the focus
1429 wxWindowMac *wxWindowBase::FindFocus()
1430 {
1431 return gFocusWindow ;
1432 }
1433
1434 #if WXWIN_COMPATIBILITY
1435 // If nothing defined for this, try the parent.
1436 // E.g. we may be a button loaded from a resource, with no callback function
1437 // defined.
1438 void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
1439 {
1440 if ( GetEventHandler()->ProcessEvent(event) )
1441 return;
1442 if ( m_parent )
1443 m_parent->GetEventHandler()->OnCommand(win, event);
1444 }
1445 #endif // WXWIN_COMPATIBILITY_2
1446
1447 #if WXWIN_COMPATIBILITY
1448 wxObject* wxWindowMac::GetChild(int number) const
1449 {
1450 // Return a pointer to the Nth object in the Panel
1451 wxNode *node = GetChildren().First();
1452 int n = number;
1453 while (node && n--)
1454 node = node->Next();
1455 if ( node )
1456 {
1457 wxObject *obj = (wxObject *)node->Data();
1458 return(obj);
1459 }
1460 else
1461 return NULL;
1462 }
1463 #endif // WXWIN_COMPATIBILITY
1464
1465 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
1466 {
1467 // panel wants to track the window which was the last to have focus in it,
1468 // so we want to set ourselves as the window which last had focus
1469 //
1470 // notice that it's also important to do it upwards the tree becaus
1471 // otherwise when the top level panel gets focus, it won't set it back to
1472 // us, but to some other sibling
1473 wxWindowMac *win = this;
1474 while ( win )
1475 {
1476 wxWindowMac *parent = win->GetParent();
1477 wxPanel *panel = wxDynamicCast(parent, wxPanel);
1478 if ( panel )
1479 {
1480 panel->SetLastFocus(win);
1481 }
1482
1483 win = parent;
1484 }
1485
1486 event.Skip();
1487 }
1488
1489 void wxWindowMac::Clear()
1490 {
1491 if ( m_macWindowData )
1492 {
1493 wxMacDrawingClientHelper helper ( this ) ;
1494 int w ,h ;
1495 wxPoint origin = GetClientAreaOrigin() ;
1496 GetClientSize( &w , &h ) ;
1497 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1498 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
1499 EraseRect( &r ) ;
1500 }
1501 else
1502 {
1503 wxClientDC dc(this);
1504 wxBrush brush(GetBackgroundColour(), wxSOLID);
1505 dc.SetBackground(brush);
1506 dc.Clear();
1507 }
1508 }
1509
1510 // Setup background and foreground colours correctly
1511 void wxWindowMac::SetupColours()
1512 {
1513 if ( GetParent() )
1514 SetBackgroundColour(GetParent()->GetBackgroundColour());
1515 }
1516
1517 void wxWindowMac::OnIdle(wxIdleEvent& event)
1518 {
1519 /*
1520 // Check if we need to send a LEAVE event
1521 if (m_mouseInWindow)
1522 {
1523 POINT pt;
1524 ::GetCursorPos(&pt);
1525 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1526 {
1527 // Generate a LEAVE event
1528 m_mouseInWindow = FALSE;
1529 MSWOnMouseLeave(pt.x, pt.y, 0);
1530 }
1531 }
1532 */
1533
1534 // This calls the UI-update mechanism (querying windows for
1535 // menu/toolbar/control state information)
1536 UpdateWindowUI();
1537 }
1538
1539 // Raise the window to the top of the Z order
1540 void wxWindowMac::Raise()
1541 {
1542 if ( m_macWindowData )
1543 {
1544 UMABringToFront( m_macWindowData->m_macWindow ) ;
1545 }
1546 }
1547
1548 // Lower the window to the bottom of the Z order
1549 void wxWindowMac::Lower()
1550 {
1551 if ( m_macWindowData )
1552 {
1553 UMASendBehind( m_macWindowData->m_macWindow , NULL ) ;
1554 }
1555 }
1556
1557 void wxWindowMac::DoSetClientSize(int width, int height)
1558 {
1559 if ( width != -1 || height != -1 )
1560 {
1561
1562 if ( width != -1 && m_vScrollBar )
1563 width += MAC_SCROLLBAR_SIZE ;
1564 if ( height != -1 && m_vScrollBar )
1565 height += MAC_SCROLLBAR_SIZE ;
1566
1567 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1568 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1569
1570 DoSetSize( -1 , -1 , width , height ) ;
1571 }
1572 }
1573
1574
1575 wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
1576
1577 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
1578 {
1579 if ((point.x < m_x) || (point.y < m_y) ||
1580 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1581 return FALSE;
1582
1583 WindowRef window = GetMacRootWindow() ;
1584
1585 wxPoint newPoint( point ) ;
1586
1587 newPoint.x -= m_x;
1588 newPoint.y -= m_y;
1589
1590 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1591 {
1592 wxWindowMac *child = (wxWindowMac*)node->Data();
1593 // added the m_isShown test --dmazzoni
1594 if ( child->GetMacRootWindow() == window && child->m_isShown )
1595 {
1596 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1597 return TRUE;
1598 }
1599 }
1600
1601 *outWin = this ;
1602 return TRUE;
1603 }
1604
1605 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
1606 {
1607 WindowRef window ;
1608 Point pt = { screenpoint.y , screenpoint.x } ;
1609 if ( ::FindWindow( pt , &window ) == 3 )
1610 {
1611 wxPoint point( screenpoint ) ;
1612 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1613 if ( win )
1614 {
1615 win->ScreenToClient( point ) ;
1616 return win->MacGetWindowFromPointSub( point , outWin ) ;
1617 }
1618 }
1619 return FALSE ;
1620 }
1621
1622 extern int wxBusyCursorCount ;
1623
1624 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
1625 {
1626 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1627 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1628 return FALSE;
1629
1630
1631 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1632 return FALSE ;
1633
1634 WindowRef window = GetMacRootWindow() ;
1635
1636 event.m_x -= m_x;
1637 event.m_y -= m_y;
1638
1639 int x = event.m_x ;
1640 int y = event.m_y ;
1641
1642 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1643 {
1644 wxWindowMac *child = (wxWindowMac*)node->Data();
1645 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
1646 {
1647 if (child->MacDispatchMouseEvent(event))
1648 return TRUE;
1649 }
1650 }
1651
1652 event.m_x = x ;
1653 event.m_y = y ;
1654
1655 if ( wxBusyCursorCount == 0 )
1656 {
1657 m_cursor.MacInstall() ;
1658 }
1659
1660 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1661 {
1662 // set focus to this window
1663 if (AcceptsFocus() && FindFocus()!=this)
1664 SetFocus();
1665 }
1666
1667 #if wxUSE_TOOLTIPS
1668 if ( event.GetEventType() == wxEVT_MOTION
1669 || event.GetEventType() == wxEVT_ENTER_WINDOW
1670 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1671 wxToolTip::RelayEvent( this , event);
1672 #endif // wxUSE_TOOLTIPS
1673 GetEventHandler()->ProcessEvent( event ) ;
1674 return TRUE;
1675 }
1676
1677 Point lastWhere ;
1678 long lastWhen = 0 ;
1679
1680 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
1681 {
1682 if ( m_tooltip )
1683 {
1684 return m_tooltip->GetTip() ;
1685 }
1686 return "" ;
1687 }
1688 void wxWindowMac::MacFireMouseEvent( EventRecord *ev )
1689 {
1690 wxMouseEvent event(wxEVT_LEFT_DOWN);
1691 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1692 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1693
1694 event.m_leftDown = isDown && !controlDown;
1695 event.m_middleDown = FALSE;
1696 event.m_rightDown = isDown && controlDown;
1697
1698 if ( ev->what == mouseDown )
1699 {
1700 if ( controlDown )
1701 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1702 else
1703 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1704 }
1705 else if ( ev->what == mouseUp )
1706 {
1707 if ( controlDown )
1708 event.SetEventType(wxEVT_RIGHT_UP ) ;
1709 else
1710 event.SetEventType(wxEVT_LEFT_UP ) ;
1711 }
1712 else
1713 {
1714 event.SetEventType(wxEVT_MOTION ) ;
1715 }
1716
1717 event.m_shiftDown = ev->modifiers & shiftKey;
1718 event.m_controlDown = ev->modifiers & controlKey;
1719 event.m_altDown = ev->modifiers & optionKey;
1720 event.m_metaDown = ev->modifiers & cmdKey;
1721
1722 Point localwhere = ev->where ;
1723
1724 GrafPtr port ;
1725 ::GetPort( &port ) ;
1726 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1727 ::GlobalToLocal( &localwhere ) ;
1728 ::SetPort( port ) ;
1729
1730 if ( ev->what == mouseDown )
1731 {
1732 if ( ev->when - lastWhen <= GetDblTime() )
1733 {
1734 if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
1735 {
1736 if ( controlDown )
1737 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
1738 else
1739 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
1740 }
1741 lastWhen = 0 ;
1742 }
1743 else
1744 {
1745 lastWhen = ev->when ;
1746 }
1747 lastWhere = localwhere ;
1748 }
1749
1750 event.m_x = localwhere.h;
1751 event.m_y = localwhere.v;
1752 event.m_x += m_x;
1753 event.m_y += m_y;
1754
1755 /*
1756 wxPoint origin = GetClientAreaOrigin() ;
1757
1758 event.m_x += origin.x ;
1759 event.m_y += origin.y ;
1760 */
1761
1762 event.m_timeStamp = ev->when;
1763 event.SetEventObject(this);
1764 if ( wxTheApp->s_captureWindow )
1765 {
1766 int x = event.m_x ;
1767 int y = event.m_y ;
1768 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1769 event.m_x = x ;
1770 event.m_y = y ;
1771 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1772 if ( ev->what == mouseUp )
1773 {
1774 wxTheApp->s_captureWindow = NULL ;
1775 if ( wxBusyCursorCount == 0 )
1776 {
1777 m_cursor.MacInstall() ;
1778 }
1779 }
1780 }
1781 else
1782 {
1783 MacDispatchMouseEvent( event ) ;
1784 }
1785 }
1786
1787 void wxWindowMac::MacMouseDown( EventRecord *ev , short part)
1788 {
1789 MacFireMouseEvent( ev ) ;
1790 }
1791
1792 void wxWindowMac::MacMouseUp( EventRecord *ev , short part)
1793 {
1794 WindowPtr frontWindow ;
1795 switch (part)
1796 {
1797 case inContent:
1798 {
1799 MacFireMouseEvent( ev ) ;
1800 }
1801 break ;
1802 }
1803 }
1804
1805 void wxWindowMac::MacMouseMoved( EventRecord *ev , short part)
1806 {
1807 WindowPtr frontWindow ;
1808 switch (part)
1809 {
1810 case inContent:
1811 {
1812 MacFireMouseEvent( ev ) ;
1813 }
1814 break ;
1815 }
1816 }
1817 void wxWindowMac::MacActivate( EventRecord *ev , bool inIsActivating )
1818 {
1819 if ( !m_macWindowData->m_macHasReceivedFirstActivate )
1820 m_macWindowData->m_macHasReceivedFirstActivate = true ;
1821
1822 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
1823 event.m_timeStamp = ev->when ;
1824 event.SetEventObject(this);
1825
1826 GetEventHandler()->ProcessEvent(event);
1827
1828 Refresh(false) ;
1829 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
1830 // MacUpdateImmediately() ;
1831 }
1832
1833 void wxWindowMac::MacRedraw( RgnHandle updatergn , long time)
1834 {
1835 // updatergn is always already clipped to our boundaries
1836 WindowRef window = GetMacRootWindow() ;
1837 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1838 RgnHandle ownUpdateRgn = NewRgn() ;
1839 CopyRgn( updatergn , ownUpdateRgn ) ;
1840 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1841 {
1842 wxMacDrawingHelper focus( this ) ; // was client
1843 if ( focus.Ok() )
1844 {
1845 WindowRef window = GetMacRootWindow() ;
1846 bool eraseBackground = false ;
1847 if ( m_macWindowData )
1848 eraseBackground = true ;
1849 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1850 {
1851 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1852 }
1853 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1854 {
1855 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1856 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1857 // either a non gray background color or a non control window
1858
1859
1860 wxWindowMac* parent = GetParent() ;
1861 while( parent )
1862 {
1863 if ( parent->GetMacRootWindow() != window )
1864 {
1865 // we are in a different window on the mac system
1866 parent = NULL ;
1867 break ;
1868 }
1869
1870 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1871 {
1872 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1873 {
1874 // if we have any other colours in the hierarchy
1875 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1876 break ;
1877 }
1878 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1879 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1880 {
1881 Rect box ;
1882 GetRegionBounds( updatergn , &box) ;
1883 UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
1884 break ;
1885 }
1886 }
1887 else
1888 {
1889 parent = NULL ;
1890 break ;
1891 }
1892 parent = parent->GetParent() ;
1893 }
1894 if ( !parent )
1895 {
1896 // if there is nothing special -> use default
1897 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1898 }
1899 }
1900 else
1901 {
1902 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1903 }
1904 // subtract all non transparent children from updatergn
1905
1906 RgnHandle childarea = NewRgn() ;
1907 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1908 {
1909 wxWindowMac *child = (wxWindowMac*)node->Data();
1910 // eventually test for transparent windows
1911 if ( child->GetMacRootWindow() == window && child->IsShown() )
1912 {
1913 if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() )
1914 {
1915 SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1916 DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
1917 }
1918 }
1919 }
1920 DisposeRgn( childarea ) ;
1921
1922 if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
1923 eraseBackground = true ;
1924 SetClip( ownUpdateRgn ) ;
1925 if ( m_macEraseOnRedraw ) {
1926 if ( eraseBackground )
1927 {
1928 EraseRgn( ownUpdateRgn ) ;
1929 }
1930 }
1931 else {
1932 m_macEraseOnRedraw = true ;
1933 }
1934 }
1935
1936 {
1937 RgnHandle newupdate = NewRgn() ;
1938 wxSize point = GetClientSize() ;
1939 wxPoint origin = GetClientAreaOrigin() ;
1940
1941 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1942 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1943 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1944 m_updateRegion = newupdate ;
1945 DisposeRgn( newupdate ) ;
1946 }
1947
1948 MacPaintBorders() ;
1949 wxPaintEvent event;
1950 event.m_timeStamp = time ;
1951 event.SetEventObject(this);
1952 GetEventHandler()->ProcessEvent(event);
1953 }
1954
1955
1956 RgnHandle childupdate = NewRgn() ;
1957
1958 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1959 {
1960 wxWindowMac *child = (wxWindowMac*)node->Data();
1961 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1962 SectRgn( childupdate , updatergn , childupdate ) ;
1963 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1964 if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
1965 {
1966 // because dialogs may also be children
1967 child->MacRedraw( childupdate , time ) ;
1968 }
1969 }
1970 DisposeRgn( childupdate ) ;
1971 // eventually a draw grow box here
1972 }
1973
1974 void wxWindowMac::MacUpdateImmediately()
1975 {
1976 WindowRef window = GetMacRootWindow() ;
1977 if ( window )
1978 {
1979 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1980 #if TARGET_CARBON
1981 AGAPortHelper help( GetWindowPort(window) ) ;
1982 #else
1983 AGAPortHelper help( (window) ) ;
1984 #endif
1985 SetOrigin( 0 , 0 ) ;
1986 BeginUpdate( window ) ;
1987 if ( win )
1988 {
1989 RgnHandle region = NewRgn();
1990
1991 if ( region )
1992 {
1993 GetPortVisibleRegion( GetWindowPort( window ), region );
1994
1995 // if windowshade gives incompatibility , take the follwing out
1996 if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
1997 {
1998 win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
1999 }
2000 DisposeRgn( region );
2001 }
2002 }
2003 EndUpdate( window ) ;
2004 }
2005 }
2006
2007 void wxWindowMac::MacUpdate( EventRecord *ev )
2008 {
2009 WindowRef window = (WindowRef) ev->message ;
2010 wxWindowMac * win = wxFindWinFromMacWindow( window ) ;
2011 #if TARGET_CARBON
2012 AGAPortHelper help( GetWindowPort(window) ) ;
2013 #else
2014 AGAPortHelper help( (window) ) ;
2015 #endif
2016 SetOrigin( 0 , 0 ) ;
2017 BeginUpdate( window ) ;
2018 if ( win )
2019 {
2020 RgnHandle region = NewRgn();
2021
2022 if ( region )
2023 {
2024 GetPortVisibleRegion( GetWindowPort( window ), region );
2025
2026 // if windowshade gives incompatibility , take the follwing out
2027 if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
2028 {
2029 MacRedraw( region , ev->when ) ;
2030 }
2031 DisposeRgn( region );
2032 }
2033 }
2034 EndUpdate( window ) ;
2035 }
2036
2037 WindowRef wxWindowMac::GetMacRootWindow() const
2038 {
2039 WindowRef window = NULL ;
2040 wxWindowMac *iter = (wxWindowMac*)this ;
2041
2042 while( iter )
2043 {
2044 if ( iter->m_macWindowData )
2045 return iter->m_macWindowData->m_macWindow ;
2046
2047 iter = iter->GetParent() ;
2048 }
2049 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2050 return NULL ;
2051 }
2052
2053 void wxWindowMac::MacCreateScrollBars( long style )
2054 {
2055 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
2056
2057 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2058 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2059 int width, height ;
2060 GetClientSize( &width , &height ) ;
2061
2062 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2063 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2064 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2065 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2066
2067 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2068 vSize , wxVERTICAL);
2069
2070 if ( style & wxVSCROLL )
2071 {
2072
2073 }
2074 else
2075 {
2076 m_vScrollBar->Show(false) ;
2077 }
2078 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2079 hSize , wxHORIZONTAL);
2080 if ( style & wxHSCROLL )
2081 {
2082 }
2083 else
2084 {
2085 m_hScrollBar->Show(false) ;
2086 }
2087
2088 // because the create does not take into account the client area origin
2089 MacRepositionScrollBars() ; // we might have a real position shift
2090 }
2091
2092 void wxWindowMac::MacRepositionScrollBars()
2093 {
2094 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2095 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2096
2097 // get real client area
2098
2099 int width = m_width ;
2100 int height = m_height ;
2101
2102 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2103 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2104
2105 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2106 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2107 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2108 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2109
2110 int x = 0 ;
2111 int y = 0 ;
2112 int w = m_width ;
2113 int h = m_height ;
2114
2115 MacClientToRootWindow( &x , &y ) ;
2116 MacClientToRootWindow( &w , &h ) ;
2117
2118 WindowRef window = NULL ;
2119 wxWindowMac *iter = (wxWindowMac*)this ;
2120
2121 int totW = 10000 , totH = 10000;
2122 while( iter )
2123 {
2124 if ( iter->m_macWindowData )
2125 {
2126 totW = iter->m_width ;
2127 totH = iter->m_height ;
2128 break ;
2129 }
2130
2131 iter = iter->GetParent() ;
2132 }
2133
2134 if ( x == 0 )
2135 {
2136 hPoint.x = -1 ;
2137 hSize.x += 1 ;
2138 }
2139 if ( y == 0 )
2140 {
2141 vPoint.y = -1 ;
2142 vSize.y += 1 ;
2143 }
2144
2145 if ( w-x >= totW )
2146 {
2147 hSize.x += 1 ;
2148 vPoint.x += 1 ;
2149 }
2150
2151 if ( h-y >= totH )
2152 {
2153 vSize.y += 1 ;
2154 hPoint.y += 1 ;
2155 }
2156
2157 if ( m_vScrollBar )
2158 {
2159 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2160 }
2161 if ( m_hScrollBar )
2162 {
2163 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2164 }
2165 }
2166
2167 void wxWindowMac::MacKeyDown( EventRecord *ev )
2168 {
2169
2170 }
2171
2172
2173 bool wxWindowMac::AcceptsFocus() const
2174 {
2175 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2176 }
2177
2178 ControlHandle wxWindowMac::MacGetContainerForEmbedding()
2179 {
2180 if ( m_macWindowData )
2181 return m_macWindowData->m_macRootControl ;
2182 else
2183 return GetParent()->MacGetContainerForEmbedding() ;
2184 }
2185
2186 void wxWindowMac::MacSuperChangedPosition()
2187 {
2188 // only window-absolute structures have to be moved i.e. controls
2189
2190 wxNode *node = GetChildren().First();
2191 while ( node )
2192 {
2193 wxWindowMac *child = (wxWindowMac *)node->Data();
2194 child->MacSuperChangedPosition() ;
2195 node = node->Next();
2196 }
2197 }
2198
2199 bool wxWindowMac::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
2200 {
2201 if ( window == NULL )
2202 return false ;
2203
2204 GrafPtr currPort;
2205 GrafPtr port ;
2206
2207 ::GetPort(&currPort);
2208 port = UMAGetWindowPort( window) ;
2209 if (currPort != port )
2210 ::SetPort(port);
2211
2212 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2213 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2214 return true;
2215 }
2216
2217 bool wxWindowMac::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
2218 {
2219 if ( window == NULL )
2220 return false ;
2221
2222 GrafPtr currPort;
2223 GrafPtr port ;
2224 ::GetPort(&currPort);
2225 port = UMAGetWindowPort( window) ;
2226 if (currPort != port )
2227 ::SetPort(port);
2228 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2229 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2230 ::ClipRect(&clipRect);
2231
2232 ::PenNormal() ;
2233 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
2234 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
2235 Pattern whiteColor ;
2236
2237 ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
2238 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2239 return true;
2240 }
2241
2242 void wxWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin)
2243 {
2244 if ( m_macWindowData )
2245 {
2246 localOrigin->h = 0;
2247 localOrigin->v = 0;
2248 clipRect->left = 0;
2249 clipRect->top = 0;
2250 clipRect->right = m_width;
2251 clipRect->bottom = m_height;
2252 *window = m_macWindowData->m_macWindow ;
2253 *rootwin = this ;
2254 }
2255 else
2256 {
2257 wxASSERT( GetParent() != NULL ) ;
2258 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
2259 localOrigin->h += m_x;
2260 localOrigin->v += m_y;
2261 OffsetRect(clipRect, -m_x, -m_y);
2262
2263 Rect myClip;
2264 myClip.left = 0;
2265 myClip.top = 0;
2266 myClip.right = m_width;
2267 myClip.bottom = m_height;
2268 SectRect(clipRect, &myClip, clipRect);
2269 }
2270 }
2271
2272 void wxWindowMac::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
2273 {
2274 // int width , height ;
2275 // GetClientSize( &width , &height ) ;
2276
2277 if ( m_macWindowData )
2278 {
2279 localOrigin->h = 0;
2280 localOrigin->v = 0;
2281 clipRect->left = 0;
2282 clipRect->top = 0;
2283 clipRect->right = m_width ;//width;
2284 clipRect->bottom = m_height ;// height;
2285 *window = m_macWindowData->m_macWindow ;
2286 *rootwin = this ;
2287 }
2288 else
2289 {
2290 wxASSERT( GetParent() != NULL ) ;
2291
2292 GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
2293
2294 localOrigin->h += m_x;
2295 localOrigin->v += m_y;
2296 OffsetRect(clipRect, -m_x, -m_y);
2297
2298 Rect myClip;
2299 myClip.left = 0;
2300 myClip.top = 0;
2301 myClip.right = m_width ;//width;
2302 myClip.bottom = m_height ;// height;
2303 SectRect(clipRect, &myClip, clipRect);
2304 }
2305 }
2306
2307 void wxWindowMac::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
2308 {
2309 MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
2310
2311 int width , height ;
2312 GetClientSize( &width , &height ) ;
2313 wxPoint client ;
2314 client = GetClientAreaOrigin( ) ;
2315
2316 localOrigin->h += client.x;
2317 localOrigin->v += client.y;
2318 OffsetRect(clipRect, -client.x, -client.y);
2319
2320 Rect myClip;
2321 myClip.left = 0;
2322 myClip.top = 0;
2323 myClip.right = width;
2324 myClip.bottom = height;
2325 SectRect(clipRect, &myClip, clipRect);
2326 }
2327
2328 long wxWindowMac::MacGetLeftBorderSize( ) const
2329 {
2330 if( m_macWindowData )
2331 return 0 ;
2332
2333 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2334 {
2335 return 2 ;
2336 }
2337 else if ( m_windowStyle &wxDOUBLE_BORDER)
2338 {
2339 return 2 ;
2340 }
2341 else if (m_windowStyle &wxSIMPLE_BORDER)
2342 {
2343 return 1 ;
2344 }
2345 return 0 ;
2346 }
2347
2348 long wxWindowMac::MacGetRightBorderSize( ) const
2349 {
2350 if( m_macWindowData )
2351 return 0 ;
2352
2353 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2354 {
2355 return 3 ;
2356 }
2357 else if ( m_windowStyle &wxDOUBLE_BORDER)
2358 {
2359 return 3 ;
2360 }
2361 else if (m_windowStyle &wxSIMPLE_BORDER)
2362 {
2363 return 3 ;
2364 }
2365 return 0 ;
2366 }
2367
2368 long wxWindowMac::MacGetTopBorderSize( ) const
2369 {
2370 if( m_macWindowData )
2371 return 0 ;
2372
2373 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2374 {
2375 return 2 ;
2376 }
2377 else if ( m_windowStyle &wxDOUBLE_BORDER)
2378 {
2379 return 2 ;
2380 }
2381 else if (m_windowStyle &wxSIMPLE_BORDER)
2382 {
2383 return 1 ;
2384 }
2385 return 0 ;
2386 }
2387
2388 long wxWindowMac::MacGetBottomBorderSize( ) const
2389 {
2390 if( m_macWindowData )
2391 return 0 ;
2392
2393 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2394 {
2395 return 3 ;
2396 }
2397 else if ( m_windowStyle &wxDOUBLE_BORDER)
2398 {
2399 return 3 ;
2400 }
2401 else if (m_windowStyle &wxSIMPLE_BORDER)
2402 {
2403 return 3 ;
2404 }
2405 return 0 ;
2406 }
2407
2408 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2409 {
2410 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2411 }
2412
2413
2414 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac * theWindow )
2415 {
2416 m_ok = false ;
2417 Point localOrigin ;
2418 Rect clipRect ;
2419 WindowRef window ;
2420 wxWindowMac *rootwin ;
2421 m_currentPort = NULL ;
2422
2423 GetPort( &m_formerPort ) ;
2424 if ( theWindow )
2425 {
2426 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2427 m_currentPort = UMAGetWindowPort( window ) ;
2428 if ( m_formerPort != m_currentPort )
2429 SetPort( m_currentPort ) ;
2430 GetPenState( &m_savedPenState ) ;
2431 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2432 m_ok = true ;
2433 }
2434 }
2435
2436 wxMacDrawingHelper::~wxMacDrawingHelper()
2437 {
2438 if ( m_ok )
2439 {
2440 SetPort( m_currentPort ) ;
2441 SetPenState( &m_savedPenState ) ;
2442 SetOrigin( 0 , 0 ) ;
2443 Rect portRect ;
2444 GetPortBounds( m_currentPort , &portRect ) ;
2445 ClipRect( &portRect ) ;
2446 }
2447
2448 if ( m_formerPort != m_currentPort )
2449 SetPort( m_formerPort ) ;
2450 }
2451
2452 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac * theWindow )
2453 {
2454 m_ok = false ;
2455 Point localOrigin ;
2456 Rect clipRect ;
2457 WindowRef window ;
2458 wxWindowMac *rootwin ;
2459 m_currentPort = NULL ;
2460
2461 GetPort( &m_formerPort ) ;
2462
2463 if ( theWindow )
2464 {
2465 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2466 m_currentPort = UMAGetWindowPort( window ) ;
2467 if ( m_formerPort != m_currentPort )
2468 SetPort( m_currentPort ) ;
2469 GetPenState( &m_savedPenState ) ;
2470 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2471 m_ok = true ;
2472 }
2473 }
2474
2475 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2476 {
2477 if ( m_ok )
2478 {
2479 SetPort( m_currentPort ) ;
2480 SetPenState( &m_savedPenState ) ;
2481 SetOrigin( 0 , 0 ) ;
2482 Rect portRect ;
2483 GetPortBounds( m_currentPort , &portRect ) ;
2484 ClipRect( &portRect ) ;
2485 }
2486
2487 if ( m_formerPort != m_currentPort )
2488 SetPort( m_formerPort ) ;
2489 }
2490
2491 // Find the wxWindowMac at the current mouse position, returning the mouse
2492 // position.
2493 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2494 {
2495 pt = wxGetMousePosition();
2496 wxWindowMac* found = wxFindWindowAtPoint(pt);
2497 return found;
2498 }
2499
2500 // Get the current mouse position.
2501 wxPoint wxGetMousePosition()
2502 {
2503 int x, y;
2504 wxGetMousePosition(& x, & y);
2505 return wxPoint(x, y);
2506 }
2507