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