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