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