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