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