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