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