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