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