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