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