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