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