]> git.saurik.com Git - wxWidgets.git/blame - src/mac/window.cpp
wxFont can now raelly use the native fonts
[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
6264b550 9// Licence: wxWindows licence
e9576ca5
SC
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
d497dca4 48#include "wx/mac/uma.h"
519cb848 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)
1c310985 68 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
e766c8a9
SC
69 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
70 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
71 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
72 EVT_IDLE(wxWindowMac::OnIdle)
73 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
e9576ca5
SC
74END_EVENT_TABLE()
75
2f1ae414 76#endif
e9576ca5 77
1c310985 78#define wxMAC_USE_THEME_BORDER 0
e9576ca5 79
e7549107
SC
80
81// ===========================================================================
82// implementation
83// ===========================================================================
84
e7549107
SC
85
86// ----------------------------------------------------------------------------
87// constructors and such
88// ----------------------------------------------------------------------------
89
e766c8a9 90void wxWindowMac::Init()
519cb848 91{
e7549107
SC
92 // generic
93 InitBase();
94
95 // MSW specific
96 m_doubleClickAllowed = 0;
97 m_winCaptured = FALSE;
98
99 m_isBeingDeleted = FALSE;
100
101 m_useCtl3D = FALSE;
102 m_mouseInWindow = FALSE;
103
104 m_xThumbSize = 0;
105 m_yThumbSize = 0;
106 m_backgroundTransparent = FALSE;
107
108 // as all windows are created with WS_VISIBLE style...
109 m_isShown = TRUE;
110
6264b550
RR
111 m_x = 0;
112 m_y = 0 ;
113 m_width = 0 ;
114 m_height = 0 ;
e7549107 115
6264b550
RR
116 m_hScrollBar = NULL ;
117 m_vScrollBar = NULL ;
e9576ca5
SC
118
119#if wxUSE_DRAG_AND_DROP
519cb848 120 m_pDropTarget = NULL;
e9576ca5
SC
121#endif
122}
123
124// Destructor
e766c8a9 125wxWindowMac::~wxWindowMac()
e9576ca5 126{
fdaf613a
SC
127 // deleting a window while it is shown invalidates the region
128 if ( IsShown() ) {
e766c8a9 129 wxWindowMac* iter = this ;
fdaf613a 130 while( iter ) {
1c310985 131 if ( iter->IsTopLevel() )
fdaf613a
SC
132 {
133 Refresh() ;
134 break ;
135 }
136 iter = iter->GetParent() ;
137
138 }
139 }
140
e7549107
SC
141 m_isBeingDeleted = TRUE;
142
6264b550
RR
143 if ( s_lastMouseWindow == this )
144 {
145 s_lastMouseWindow = NULL ;
146 }
e7549107
SC
147
148 if ( gFocusWindow == this )
e9576ca5 149 {
6264b550 150 gFocusWindow = NULL ;
e9576ca5 151 }
519cb848 152
e7549107
SC
153 if ( m_parent )
154 m_parent->RemoveChild(this);
e9576ca5
SC
155
156 DestroyChildren();
e9576ca5
SC
157}
158
159// Constructor
e766c8a9 160bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
e9576ca5
SC
161 const wxPoint& pos,
162 const wxSize& size,
163 long style,
164 const wxString& name)
165{
e766c8a9 166 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
e9576ca5 167
e7549107 168 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
e9576ca5
SC
169 return FALSE;
170
e7549107 171 parent->AddChild(this);
e9576ca5 172
6264b550
RR
173 m_x = (int)pos.x;
174 m_y = (int)pos.y;
175 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
176 m_width = WidthDefault( size.x );
177 m_height = HeightDefault( size.y ) ;
e766c8a9 178#ifndef __WXUNIVERSAL__
6264b550
RR
179 if ( ! IsKindOf( CLASSINFO ( wxControl ) ) && ! IsKindOf( CLASSINFO( wxStatusBar ) ) )
180 {
181 MacCreateScrollBars( style ) ;
182 }
e766c8a9 183#endif
e9576ca5
SC
184 return TRUE;
185}
186
e766c8a9 187void wxWindowMac::SetFocus()
e9576ca5 188{
6264b550
RR
189 if ( gFocusWindow == this )
190 return ;
1c310985 191
6264b550
RR
192 if ( AcceptsFocus() )
193 {
194 if (gFocusWindow )
195 {
196 #if wxUSE_CARET
197 // Deal with caret
198 if ( gFocusWindow->m_caret )
199 {
200 gFocusWindow->m_caret->OnKillFocus();
201 }
202 #endif // wxUSE_CARET
e766c8a9 203 #ifndef __WXUNIVERSAL__
6264b550
RR
204 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
205 if ( control && control->GetMacControl() )
206 {
1c310985 207 UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
6264b550
RR
208 control->MacRedrawControl() ;
209 }
210 #endif
211 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
212 event.SetEventObject(gFocusWindow);
213 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
214 }
215 gFocusWindow = this ;
216 {
217 #if wxUSE_CARET
218 // Deal with caret
219 if ( m_caret )
220 {
221 m_caret->OnSetFocus();
222 }
223 #endif // wxUSE_CARET
224 // panel wants to track the window which was the last to have focus in it
c1fb8167 225 wxChildFocusEvent eventFocus(this);
1c310985 226 GetEventHandler()->ProcessEvent(eventFocus);
c1fb8167 227
e766c8a9 228 #ifndef __WXUNIVERSAL__
6264b550
RR
229 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
230 if ( control && control->GetMacControl() )
231 {
1c310985 232 UMASetKeyboardFocus( gFocusWindow->MacGetRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
6264b550 233 }
e766c8a9 234 #endif
6264b550
RR
235 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
236 event.SetEventObject(this);
237 GetEventHandler()->ProcessEvent(event) ;
238 }
239 }
e9576ca5
SC
240}
241
e766c8a9 242bool wxWindowMac::Enable(bool enable)
e9576ca5 243{
e7549107
SC
244 if ( !wxWindowBase::Enable(enable) )
245 return FALSE;
e7549107 246
1c310985 247 MacSuperEnabled( enable ) ;
e7549107
SC
248
249 return TRUE;
e9576ca5
SC
250}
251
e766c8a9 252void wxWindowMac::CaptureMouse()
e9576ca5 253{
519cb848 254 wxTheApp->s_captureWindow = this ;
e9576ca5
SC
255}
256
90b959ae
SC
257wxWindow* wxWindowBase::GetCapture()
258{
259 return wxTheApp->s_captureWindow ;
260}
261
e766c8a9 262void wxWindowMac::ReleaseMouse()
e9576ca5 263{
519cb848 264 wxTheApp->s_captureWindow = NULL ;
e9576ca5
SC
265}
266
e9576ca5
SC
267#if wxUSE_DRAG_AND_DROP
268
e766c8a9 269void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
e9576ca5
SC
270{
271 if ( m_pDropTarget != 0 ) {
272 delete m_pDropTarget;
273 }
274
275 m_pDropTarget = pDropTarget;
276 if ( m_pDropTarget != 0 )
277 {
278 // TODO
279 }
280}
281
282#endif
283
284// Old style file-manager drag&drop
e766c8a9 285void wxWindowMac::DragAcceptFiles(bool accept)
e9576ca5
SC
286{
287 // TODO
288}
289
290// Get total size
e766c8a9 291void wxWindowMac::DoGetSize(int *x, int *y) const
e9576ca5 292{
9453cf2b
SC
293 if(x) *x = m_width ;
294 if(y) *y = m_height ;
e9576ca5
SC
295}
296
e766c8a9 297void wxWindowMac::DoGetPosition(int *x, int *y) const
e9576ca5 298{
9453cf2b
SC
299 int xx,yy;
300
301 xx = m_x ;
302 yy = m_y ;
1c310985 303 if ( !IsTopLevel() && GetParent())
519cb848
SC
304 {
305 wxPoint pt(GetParent()->GetClientAreaOrigin());
9453cf2b
SC
306 xx -= pt.x;
307 yy -= pt.y;
519cb848 308 }
9453cf2b
SC
309 if(x) *x = xx;
310 if(y) *y = yy;
e9576ca5
SC
311}
312
e766c8a9
SC
313#if wxUSE_MENUS
314bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
51abe921 315{
6264b550 316 menu->SetInvokingWindow(this);
51abe921 317 menu->UpdateUI();
6264b550 318 ClientToScreen( &x , &y ) ;
51abe921 319
6264b550
RR
320 ::InsertMenu( menu->GetHMenu() , -1 ) ;
321 long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
322 menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
323 ::DeleteMenu( menu->MacGetMenuId() ) ;
324 menu->SetInvokingWindow(NULL);
51abe921
SC
325
326 return TRUE;
327}
e766c8a9 328#endif
51abe921 329
e766c8a9 330void wxWindowMac::DoScreenToClient(int *x, int *y) const
e9576ca5 331{
1c310985 332 WindowRef window = MacGetRootWindow() ;
519cb848 333
6264b550 334 Point localwhere = {0,0} ;
9453cf2b
SC
335
336 if(x) localwhere.h = * x ;
337 if(y) localwhere.v = * y ;
519cb848 338
6264b550
RR
339 GrafPtr port ;
340 ::GetPort( &port ) ;
341 ::SetPort( UMAGetWindowPort( window ) ) ;
342 ::GlobalToLocal( &localwhere ) ;
343 ::SetPort( port ) ;
519cb848 344
9453cf2b
SC
345 if(x) *x = localwhere.h ;
346 if(y) *y = localwhere.v ;
6264b550
RR
347
348 MacRootWindowToClient( x , y ) ;
e9576ca5
SC
349}
350
e766c8a9 351void wxWindowMac::DoClientToScreen(int *x, int *y) const
e9576ca5 352{
1c310985 353 WindowRef window = MacGetRootWindow() ;
6264b550
RR
354
355 MacClientToRootWindow( x , y ) ;
356
357 Point localwhere = { 0,0 };
9453cf2b
SC
358 if(x) localwhere.h = * x ;
359 if(y) localwhere.v = * y ;
6264b550
RR
360
361 GrafPtr port ;
362 ::GetPort( &port ) ;
363 ::SetPort( UMAGetWindowPort( window ) ) ;
364 ::SetOrigin( 0 , 0 ) ;
365 ::LocalToGlobal( &localwhere ) ;
366 ::SetPort( port ) ;
9453cf2b
SC
367 if(x) *x = localwhere.h ;
368 if(y) *y = localwhere.v ;
519cb848
SC
369}
370
e766c8a9 371void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
519cb848 372{
1c310985
SC
373 wxPoint origin = GetClientAreaOrigin() ;
374 if(x) *x += origin.x ;
375 if(y) *y += origin.y ;
376
377 MacWindowToRootWindow( x , y ) ;
378}
379
380void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
381{
382 wxPoint origin = GetClientAreaOrigin() ;
383 MacRootWindowToWindow( x , y ) ;
384 if(x) *x -= origin.x ;
385 if(y) *y -= origin.y ;
386}
387
388void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
389{
390 if ( !IsTopLevel() )
6264b550 391 {
1c310985
SC
392 if(x) *x += m_x ;
393 if(y) *y += m_y ;
394 GetParent()->MacWindowToRootWindow( x , y ) ;
6264b550 395 }
519cb848
SC
396}
397
1c310985 398void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
519cb848 399{
1c310985 400 if ( !IsTopLevel() )
6264b550 401 {
1c310985
SC
402 if(x) *x -= m_x ;
403 if(y) *y -= m_y ;
404 GetParent()->MacRootWindowToWindow( x , y ) ;
6264b550 405 }
e9576ca5
SC
406}
407
e766c8a9 408bool wxWindowMac::SetCursor(const wxCursor& cursor)
e9576ca5 409{
6618870d 410 if (m_cursor == cursor)
e7549107 411 return FALSE;
6618870d
SC
412
413 if (wxNullCursor == cursor)
414 {
415 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
416 return FALSE ;
417 }
418 else
419 {
420 if ( ! wxWindowBase::SetCursor( cursor ) )
421 return FALSE ;
422 }
e7549107
SC
423
424 wxASSERT_MSG( m_cursor.Ok(),
425 wxT("cursor must be valid after call to the base version"));
426
427 Point pt ;
e766c8a9 428 wxWindowMac *mouseWin ;
e7549107
SC
429 GetMouse( &pt ) ;
430
431 // Change the cursor NOW if we're within the correct window
432
433 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
e9576ca5 434 {
6264b550
RR
435 if ( mouseWin == this && !wxIsBusy() )
436 {
437 m_cursor.MacInstall() ;
438 }
e9576ca5 439 }
e7549107
SC
440
441 return TRUE ;
e9576ca5
SC
442}
443
444
445// Get size *available for subwindows* i.e. excluding menu bar etc.
e766c8a9 446void wxWindowMac::DoGetClientSize(int *x, int *y) const
e9576ca5 447{
9453cf2b
SC
448 int ww, hh;
449 ww = m_width ;
450 hh = m_height ;
519cb848 451
6264b550
RR
452 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
453 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
454
2f1ae414
SC
455 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
456 {
6264b550
RR
457 int x1 = 0 ;
458 int y1 = 0 ;
459 int w = m_width ;
460 int h = m_height ;
461
462 MacClientToRootWindow( &x1 , &y1 ) ;
463 MacClientToRootWindow( &w , &h ) ;
464
465 wxWindowMac *iter = (wxWindowMac*)this ;
466
467 int totW = 10000 , totH = 10000;
468 while( iter )
469 {
1c310985 470 if ( iter->IsTopLevel() )
6264b550
RR
471 {
472 totW = iter->m_width ;
473 totH = iter->m_height ;
474 break ;
475 }
476
477 iter = iter->GetParent() ;
478 }
479
480 if (m_hScrollBar && m_hScrollBar->IsShown() )
481 {
482 hh -= MAC_SCROLLBAR_SIZE;
483 if ( h-y1 >= totH )
484 {
485 hh += 1 ;
486 }
487 }
488 if (m_vScrollBar && m_vScrollBar->IsShown() )
489 {
490 ww -= MAC_SCROLLBAR_SIZE;
491 if ( w-x1 >= totW )
492 {
493 ww += 1 ;
494 }
495 }
2f1ae414 496 }
9453cf2b
SC
497 if(x) *x = ww;
498 if(y) *y = hh;
519cb848
SC
499}
500
51abe921
SC
501
502// ----------------------------------------------------------------------------
503// tooltips
504// ----------------------------------------------------------------------------
505
506#if wxUSE_TOOLTIPS
507
e766c8a9 508void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
51abe921
SC
509{
510 wxWindowBase::DoSetToolTip(tooltip);
511
6264b550
RR
512 if ( m_tooltip )
513 m_tooltip->SetWindow(this);
51abe921
SC
514}
515
516#endif // wxUSE_TOOLTIPS
517
e766c8a9 518void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
51abe921 519{
6264b550
RR
520 int former_x = m_x ;
521 int former_y = m_y ;
522 int former_w = m_width ;
523 int former_h = m_height ;
524
519cb848
SC
525 int actualWidth = width;
526 int actualHeight = height;
527 int actualX = x;
528 int actualY = y;
7810c95b 529
7810c95b 530 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
6264b550 531 actualWidth = m_minWidth;
7810c95b 532 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
6264b550 533 actualHeight = m_minHeight;
7810c95b 534 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
6264b550 535 actualWidth = m_maxWidth;
7810c95b 536 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
6264b550
RR
537 actualHeight = m_maxHeight;
538
539 bool doMove = false ;
540 bool doResize = false ;
541
542 if ( actualX != former_x || actualY != former_y )
543 {
544 doMove = true ;
545 }
546 if ( actualWidth != former_w || actualHeight != former_h )
547 {
548 doResize = true ;
549 }
550
551 if ( doMove || doResize )
552 {
1c310985
SC
553 // erase former position
554 wxMacDrawingHelper focus( this ) ;
555 if ( focus.Ok() )
6264b550 556 {
1c310985
SC
557 Rect clientrect = { 0 , 0 , m_height , m_width } ;
558 // ClipRect( &clientrect ) ;
559 InvalWindowRect( MacGetRootWindow() , &clientrect ) ;
6264b550 560 }
1c310985 561
6264b550
RR
562 m_x = actualX ;
563 m_y = actualY ;
564 m_width = actualWidth ;
565 m_height = actualHeight ;
1c310985
SC
566 // erase new position
567
6264b550 568 {
1c310985
SC
569 wxMacDrawingHelper focus( this ) ;
570 if ( focus.Ok() )
6264b550 571 {
1c310985
SC
572 Rect clientrect = { 0 , 0 , m_height , m_width } ;
573 // ClipRect( &clientrect ) ;
574 InvalWindowRect( MacGetRootWindow() , &clientrect ) ;
6264b550 575 }
6264b550 576 }
1c310985
SC
577
578 if ( doMove )
579 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
580
6264b550
RR
581 MacRepositionScrollBars() ;
582 if ( doMove )
583 {
584 wxPoint point(m_x, m_y);
585 wxMoveEvent event(point, m_windowId);
586 event.SetEventObject(this);
587 GetEventHandler()->ProcessEvent(event) ;
588 }
589 if ( doResize )
590 {
591 MacRepositionScrollBars() ;
592 wxSize size(m_width, m_height);
593 wxSizeEvent event(size, m_windowId);
594 event.SetEventObject(this);
595 GetEventHandler()->ProcessEvent(event);
596 }
597 }
598
954fc50b
SC
599}
600
601// set the size of the window: if the dimensions are positive, just use them,
602// but if any of them is equal to -1, it means that we must find the value for
603// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
604// which case -1 is a valid value for x and y)
605//
606// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
607// the width/height to best suit our contents, otherwise we reuse the current
608// width/height
609void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
610{
611 // get the current size and position...
612 int currentX, currentY;
613 GetPosition(&currentX, &currentY);
574bf507 614
954fc50b
SC
615 int currentW,currentH;
616 GetSize(&currentW, &currentH);
617
618 // ... and don't do anything (avoiding flicker) if it's already ok
619 if ( x == currentX && y == currentY &&
620 width == currentW && height == currentH )
621 {
6264b550 622 MacRepositionScrollBars() ; // we might have a real position shift
954fc50b
SC
623 return;
624 }
625
626 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
627 x = currentX;
628 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
629 y = currentY;
630
631 AdjustForParentClientOrigin(x, y, sizeFlags);
632
633 wxSize size(-1, -1);
634 if ( width == -1 )
635 {
636 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
637 {
638 size = DoGetBestSize();
639 width = size.x;
640 }
641 else
642 {
643 // just take the current one
644 width = currentW;
645 }
646 }
647
648 if ( height == -1 )
649 {
650 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
651 {
652 if ( size.x == -1 )
653 {
654 size = DoGetBestSize();
655 }
656 //else: already called DoGetBestSize() above
657
658 height = size.y;
659 }
660 else
661 {
662 // just take the current one
663 height = currentH;
664 }
665 }
666
667 DoMoveWindow(x, y, width, height);
668
e9576ca5 669}
e9576ca5
SC
670// For implementation purposes - sometimes decorations make the client area
671// smaller
519cb848 672
e766c8a9 673wxPoint wxWindowMac::GetClientAreaOrigin() const
e9576ca5 674{
5b781a67 675 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
e9576ca5
SC
676}
677
1c310985 678void wxWindow::SetTitle(const wxString& title)
e9576ca5 679{
1c310985 680 m_label = title ;
519cb848
SC
681}
682
1c310985 683wxString wxWindow::GetTitle() const
519cb848 684{
1c310985 685 return m_label ;
519cb848
SC
686}
687
e766c8a9 688bool wxWindowMac::Show(bool show)
e9576ca5 689{
e7549107
SC
690 if ( !wxWindowBase::Show(show) )
691 return FALSE;
692
6264b550
RR
693 MacSuperShown( show ) ;
694 if ( !show )
695 {
1c310985 696 WindowRef window = MacGetRootWindow() ;
6264b550
RR
697 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
698 if ( win && !win->m_isBeingDeleted )
699 Refresh() ;
700 }
701 else
702 {
703 Refresh() ;
704 }
fdaf613a 705
e7549107 706 return TRUE;
e9576ca5
SC
707}
708
e766c8a9 709void wxWindowMac::MacSuperShown( bool show )
8208e181 710{
6264b550
RR
711 wxNode *node = GetChildren().First();
712 while ( node )
713 {
714 wxWindowMac *child = (wxWindowMac *)node->Data();
715 if ( child->m_isShown )
716 child->MacSuperShown( show ) ;
717 node = node->Next();
718 }
8208e181
SC
719}
720
1c310985
SC
721void wxWindowMac::MacSuperEnabled( bool enabled )
722{
1c469f7f
SC
723 if ( !IsTopLevel() )
724 {
725 // to be absolutely correct we'd have to invalidate (with eraseBkground
726 // because unter MacOSX the frames are drawn with an addXXX mode)
727 // the borders area
728 }
1c310985
SC
729 wxNode *node = GetChildren().First();
730 while ( node )
731 {
732 wxWindowMac *child = (wxWindowMac *)node->Data();
733 if ( child->m_isShown )
734 child->MacSuperEnabled( enabled ) ;
735 node = node->Next();
736 }
737}
738
e766c8a9 739bool wxWindowMac::MacIsReallyShown() const
c809f3be 740{
6264b550
RR
741 if ( m_isShown && (m_parent != NULL) ) {
742 return m_parent->MacIsReallyShown();
743 }
744 return m_isShown;
745/*
746 bool status = m_isShown ;
747 wxWindowMac * win = this ;
748 while ( status && win->m_parent != NULL )
749 {
750 win = win->m_parent ;
751 status = win->m_isShown ;
752 }
753 return status ;
5fde6fcc 754*/
c809f3be
SC
755}
756
e766c8a9 757int wxWindowMac::GetCharHeight() const
e9576ca5 758{
6264b550
RR
759 wxClientDC dc ( (wxWindowMac*)this ) ;
760 return dc.GetCharHeight() ;
e9576ca5
SC
761}
762
e766c8a9 763int wxWindowMac::GetCharWidth() const
e9576ca5 764{
6264b550
RR
765 wxClientDC dc ( (wxWindowMac*)this ) ;
766 return dc.GetCharWidth() ;
e9576ca5
SC
767}
768
e766c8a9 769void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 770 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 771{
e7549107
SC
772 const wxFont *fontToUse = theFont;
773 if ( !fontToUse )
774 fontToUse = &m_font;
7c74e7fe 775
e766c8a9 776 wxClientDC dc( (wxWindowMac*) this ) ;
7c74e7fe 777 long lx,ly,ld,le ;
5fde6fcc 778 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414 779 if ( externalLeading )
6264b550 780 *externalLeading = le ;
2f1ae414 781 if ( descent )
6264b550 782 *descent = ld ;
2f1ae414 783 if ( x )
6264b550 784 *x = lx ;
2f1ae414 785 if ( y )
6264b550 786 *y = ly ;
e9576ca5
SC
787}
788
0a67a93b 789/*
1c310985
SC
790 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
791 * we always intersect with the entire window, not only with the client area
792 */
793
e766c8a9 794void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
e9576ca5 795{
1c310985
SC
796 wxPoint client ;
797 client = GetClientAreaOrigin( ) ;
798 Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ;
799 if ( rect )
6264b550 800 {
1c310985
SC
801 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
802 SectRect( &clientrect , &r , &clientrect ) ;
6264b550 803 }
1c310985 804 if ( !EmptyRect( &clientrect ) )
e9576ca5 805 {
1c310985
SC
806 int top = 0 , left = 0 ;
807
808 MacClientToRootWindow( &left , &top ) ;
809 OffsetRect( &clientrect , left , top ) ;
810
811 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
e9576ca5
SC
812 }
813}
814
e7549107
SC
815#if wxUSE_CARET && WXWIN_COMPATIBILITY
816// ---------------------------------------------------------------------------
e9576ca5 817// Caret manipulation
e7549107
SC
818// ---------------------------------------------------------------------------
819
e766c8a9 820void wxWindowMac::CreateCaret(int w, int h)
e9576ca5 821{
e7549107 822 SetCaret(new wxCaret(this, w, h));
e9576ca5
SC
823}
824
e766c8a9 825void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
e9576ca5 826{
e7549107 827 wxFAIL_MSG("not implemented");
e9576ca5
SC
828}
829
e766c8a9 830void wxWindowMac::ShowCaret(bool show)
e9576ca5 831{
e7549107
SC
832 wxCHECK_RET( m_caret, "no caret to show" );
833
834 m_caret->Show(show);
e9576ca5
SC
835}
836
e766c8a9 837void wxWindowMac::DestroyCaret()
e9576ca5 838{
e7549107 839 SetCaret(NULL);
e9576ca5
SC
840}
841
e766c8a9 842void wxWindowMac::SetCaretPos(int x, int y)
e9576ca5 843{
e7549107
SC
844 wxCHECK_RET( m_caret, "no caret to move" );
845
846 m_caret->Move(x, y);
e9576ca5
SC
847}
848
e766c8a9 849void wxWindowMac::GetCaretPos(int *x, int *y) const
e9576ca5 850{
e7549107
SC
851 wxCHECK_RET( m_caret, "no caret to get position of" );
852
853 m_caret->GetPosition(x, y);
e9576ca5 854}
e7549107 855#endif // wxUSE_CARET
e9576ca5 856
e766c8a9 857wxWindowMac *wxGetActiveWindow()
e9576ca5 858{
519cb848 859 // actually this is a windows-only concept
e9576ca5
SC
860 return NULL;
861}
862
e9576ca5 863// Coordinates relative to the window
e766c8a9 864void wxWindowMac::WarpPointer (int x_pos, int y_pos)
e9576ca5 865{
519cb848 866 // We really dont move the mouse programmatically under mac
e9576ca5
SC
867}
868
e766c8a9 869void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
e9576ca5 870{
1c310985
SC
871 wxMacDrawingHelper focus( this ) ;
872 if ( focus.Ok() )
873 {
874 WindowRef window = MacGetRootWindow() ;
875 Rect rect = {0, 0 , m_height , m_width } ;
876 RgnHandle updateRgn = GetUpdateRegion().GetWXHRGN() ;
877 SetClip( event.GetDC()->MacGetCurrentClipRgn() ) ;
878
879 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
880 {
881 SetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
882 }
883 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
884 {
885 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
886 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
887 // either a non gray background color or a non control window
888
889 wxWindowMac* parent = GetParent() ;
890 while( parent )
891 {
892 if ( parent->MacGetRootWindow() != window )
893 {
894 // we are in a different window on the mac system
895 parent = NULL ;
896 break ;
897 }
898 //if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
899 {
900 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE )
901 && parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
902 {
903 // if we have any other colours in the hierarchy
904 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
905 break ;
906 }
907 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
908 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
909 {
910 Rect box ;
911 GetRegionBounds( updateRgn , &box) ;
912 ::ApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
913 break ;
914 }
915 }
916 /*
917 else
918 {
919 // we have arrived at a non control item
920 parent = NULL ;
921 break ;
922 }
923 */
924 parent = parent->GetParent() ;
925 }
926 if ( !parent )
927 {
928 // if there is nothing special -> use default
929 SetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
930 }
931 }
932 else
933 {
934 RGBBackColor( &m_backgroundColour.GetPixel()) ;
935 }
936 EraseRect( &rect ) ;
937 }
938
939// event.GetDC()->Clear() ;
940}
941
942void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
943{
944 wxMacDrawingHelper focus( this ) ;
945 if ( focus.Ok() )
946 {
947 MacPaintBorders() ;
948 }
e9576ca5
SC
949}
950
e766c8a9 951int wxWindowMac::GetScrollPos(int orient) const
e9576ca5 952{
1c310985
SC
953 if ( orient == wxHORIZONTAL )
954 {
955 if ( m_hScrollBar )
956 return m_hScrollBar->GetThumbPosition() ;
957 }
958 else
959 {
960 if ( m_vScrollBar )
961 return m_vScrollBar->GetThumbPosition() ;
962 }
e9576ca5
SC
963 return 0;
964}
965
966// This now returns the whole range, not just the number
967// of positions that we can scroll.
e766c8a9 968int wxWindowMac::GetScrollRange(int orient) const
e9576ca5 969{
1c310985
SC
970 if ( orient == wxHORIZONTAL )
971 {
972 if ( m_hScrollBar )
973 return m_hScrollBar->GetRange() ;
974 }
975 else
976 {
977 if ( m_vScrollBar )
978 return m_vScrollBar->GetRange() ;
979 }
e9576ca5
SC
980 return 0;
981}
982
e766c8a9 983int wxWindowMac::GetScrollThumb(int orient) const
e9576ca5 984{
1c310985
SC
985 if ( orient == wxHORIZONTAL )
986 {
987 if ( m_hScrollBar )
988 return m_hScrollBar->GetThumbSize() ;
989 }
990 else
991 {
992 if ( m_vScrollBar )
993 return m_vScrollBar->GetThumbSize() ;
994 }
e9576ca5
SC
995 return 0;
996}
997
e766c8a9 998void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
e9576ca5 999{
1c310985 1000 if ( orient == wxHORIZONTAL )
6264b550 1001 {
1c310985
SC
1002 if ( m_hScrollBar )
1003 m_hScrollBar->SetThumbPosition( pos ) ;
6264b550
RR
1004 }
1005 else
1006 {
1c310985
SC
1007 if ( m_vScrollBar )
1008 m_vScrollBar->SetThumbPosition( pos ) ;
6264b550 1009 }
2f1ae414
SC
1010}
1011
e766c8a9 1012void wxWindowMac::MacPaintBorders( )
2f1ae414 1013{
1c310985 1014 if( IsTopLevel() )
6264b550
RR
1015 return ;
1016
1017 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1018 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1019 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1020 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1021 PenNormal() ;
2f1ae414
SC
1022
1023 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1024 {
1c310985
SC
1025#if wxMAC_USE_THEME_BORDER
1026 Rect rect = { 0 , 0 , m_height , m_width } ;
1027 SInt32 border = 0 ;
1028 /*
1029 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1030 InsetRect( &rect , border , border );
1031 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1032 */
1033
1034 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1035#else
1036 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
653b2449
SC
1037 RGBForeColor( &face );
1038 MoveTo( 0 , m_height - 2 );
1039 LineTo( 0 , 0 );
1040 LineTo( m_width - 2 , 0 );
1041
1042 MoveTo( 2 , m_height - 3 );
1043 LineTo( m_width - 3 , m_height - 3 );
1044 LineTo( m_width - 3 , 2 );
1045
1046 RGBForeColor( sunken ? &face : &black );
1047 MoveTo( 0 , m_height - 1 );
1048 LineTo( m_width - 1 , m_height - 1 );
1049 LineTo( m_width - 1 , 0 );
1050
1051 RGBForeColor( sunken ? &shadow : &white );
1052 MoveTo( 1 , m_height - 3 );
1053 LineTo( 1, 1 );
1054 LineTo( m_width - 3 , 1 );
1055
1056 RGBForeColor( sunken ? &white : &shadow );
1057 MoveTo( 1 , m_height - 2 );
1058 LineTo( m_width - 2 , m_height - 2 );
1059 LineTo( m_width - 2 , 1 );
1060
1061 RGBForeColor( sunken ? &black : &face );
1062 MoveTo( 2 , m_height - 4 );
1063 LineTo( 2 , 2 );
1064 LineTo( m_width - 4 , 2 );
1c310985 1065#endif
8208e181
SC
1066 }
1067 else if (HasFlag(wxSIMPLE_BORDER))
1068 {
6264b550
RR
1069 Rect rect = { 0 , 0 , m_height , m_width } ;
1070 RGBForeColor( &black ) ;
1071 FrameRect( &rect ) ;
2f1ae414 1072 }
8208e181
SC
1073}
1074
e9576ca5 1075// New function that will replace some of the above.
e766c8a9 1076void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
e9576ca5
SC
1077 int range, bool refresh)
1078{
6264b550
RR
1079 if ( orient == wxHORIZONTAL )
1080 {
1081 if ( m_hScrollBar )
1082 {
1083 if ( range == 0 || thumbVisible >= range )
1084 {
1085 if ( m_hScrollBar->IsShown() )
1086 m_hScrollBar->Show(false) ;
1087 }
1088 else
1089 {
1090 if ( !m_hScrollBar->IsShown() )
1091 m_hScrollBar->Show(true) ;
1092 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1093 }
1094 }
1095 }
1096 else
1097 {
1098 if ( m_vScrollBar )
1099 {
1100 if ( range == 0 || thumbVisible >= range )
1101 {
1102 if ( m_vScrollBar->IsShown() )
1103 m_vScrollBar->Show(false) ;
1104 }
1105 else
1106 {
1107 if ( !m_vScrollBar->IsShown() )
1108 m_vScrollBar->Show(true) ;
1109 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1110 }
1111 }
1112 }
1113 MacRepositionScrollBars() ;
e9576ca5
SC
1114}
1115
1116// Does a physical scroll
e766c8a9 1117void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
e9576ca5 1118{
6264b550
RR
1119 wxMacDrawingClientHelper focus( this ) ;
1120 if ( focus.Ok() )
1121 {
1122 int width , height ;
1123 GetClientSize( &width , &height ) ;
1124
1125 Rect scrollrect = { 0 , 0 , height , width } ;
1126
1127 RgnHandle updateRgn = NewRgn() ;
1128 ClipRect( &scrollrect ) ;
1129 if ( rect )
1130 {
1131 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1132 SectRect( &scrollrect , &r , &scrollrect ) ;
1133 }
1134 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1c310985 1135 InvalWindowRgn( MacGetRootWindow() , updateRgn ) ;
6264b550
RR
1136 DisposeRgn( updateRgn ) ;
1137 }
1138
1139 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1140 {
1141 wxWindowMac *child = (wxWindowMac*)node->Data();
1142 if (child == m_vScrollBar) continue;
1143 if (child == m_hScrollBar) continue;
1144 if (child->IsTopLevel()) continue;
1145 int x,y;
1146 child->GetPosition( &x, &y );
1147 int w,h;
1148 child->GetSize( &w, &h );
1149 child->SetSize( x+dx, y+dy, w, h );
1150 }
1151
e9576ca5
SC
1152}
1153
e766c8a9 1154void wxWindowMac::MacOnScroll(wxScrollEvent &event )
7c74e7fe 1155{
6264b550
RR
1156 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1157 {
1158 wxScrollWinEvent wevent;
1159 wevent.SetPosition(event.GetPosition());
1160 wevent.SetOrientation(event.GetOrientation());
1161 wevent.m_eventObject = this;
1162
1163 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1164 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1165 } else
1166 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1167 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1168 } else
1169 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1170 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1171 } else
1172 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1173 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1174 } else
1175 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1176 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1177 } else
1178 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1179 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1180 } else
1181 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1182 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1183 }
1184
1185 GetEventHandler()->ProcessEvent(wevent);
7c74e7fe
SC
1186 }
1187}
1188
e9576ca5 1189// Get the window with the focus
e766c8a9 1190wxWindowMac *wxWindowBase::FindFocus()
e9576ca5 1191{
6264b550 1192 return gFocusWindow ;
519cb848
SC
1193}
1194
e7549107 1195#if WXWIN_COMPATIBILITY
e9576ca5
SC
1196// If nothing defined for this, try the parent.
1197// E.g. we may be a button loaded from a resource, with no callback function
1198// defined.
e766c8a9 1199void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
e9576ca5 1200{
e7549107
SC
1201 if ( GetEventHandler()->ProcessEvent(event) )
1202 return;
1203 if ( m_parent )
1204 m_parent->GetEventHandler()->OnCommand(win, event);
e9576ca5 1205}
e7549107 1206#endif // WXWIN_COMPATIBILITY_2
e9576ca5 1207
e7549107 1208#if WXWIN_COMPATIBILITY
e766c8a9 1209wxObject* wxWindowMac::GetChild(int number) const
e9576ca5 1210{
e7549107
SC
1211 // Return a pointer to the Nth object in the Panel
1212 wxNode *node = GetChildren().First();
1213 int n = number;
1214 while (node && n--)
1215 node = node->Next();
1216 if ( node )
519cb848 1217 {
e7549107
SC
1218 wxObject *obj = (wxObject *)node->Data();
1219 return(obj);
519cb848
SC
1220 }
1221 else
e7549107 1222 return NULL;
e9576ca5 1223}
e7549107 1224#endif // WXWIN_COMPATIBILITY
e9576ca5 1225
e766c8a9 1226void wxWindowMac::OnSetFocus(wxFocusEvent& event)
7810c95b
SC
1227{
1228 // panel wants to track the window which was the last to have focus in it,
1229 // so we want to set ourselves as the window which last had focus
1230 //
1231 // notice that it's also important to do it upwards the tree becaus
1232 // otherwise when the top level panel gets focus, it won't set it back to
1233 // us, but to some other sibling
c1fb8167
SC
1234
1235 // CS:don't know if this is still needed:
1236 //wxChildFocusEvent eventFocus(this);
1237 //(void)GetEventHandler()->ProcessEvent(eventFocus);
7810c95b
SC
1238
1239 event.Skip();
1240}
1241
e766c8a9 1242void wxWindowMac::Clear()
e9576ca5 1243{
1c310985
SC
1244 wxClientDC dc(this);
1245 wxBrush brush(GetBackgroundColour(), wxSOLID);
1246 dc.SetBackground(brush);
1247 dc.Clear();
e9576ca5
SC
1248}
1249
e7549107 1250// Setup background and foreground colours correctly
e766c8a9 1251void wxWindowMac::SetupColours()
e9576ca5 1252{
e7549107
SC
1253 if ( GetParent() )
1254 SetBackgroundColour(GetParent()->GetBackgroundColour());
e9576ca5
SC
1255}
1256
e766c8a9 1257void wxWindowMac::OnIdle(wxIdleEvent& event)
e9576ca5 1258{
519cb848
SC
1259/*
1260 // Check if we need to send a LEAVE event
1261 if (m_mouseInWindow)
1262 {
1263 POINT pt;
1264 ::GetCursorPos(&pt);
1265 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1266 {
1267 // Generate a LEAVE event
1268 m_mouseInWindow = FALSE;
1269 MSWOnMouseLeave(pt.x, pt.y, 0);
1270 }
e9576ca5
SC
1271 }
1272*/
1273
1274 // This calls the UI-update mechanism (querying windows for
1275 // menu/toolbar/control state information)
6264b550 1276 UpdateWindowUI();
e9576ca5
SC
1277}
1278
1279// Raise the window to the top of the Z order
e766c8a9 1280void wxWindowMac::Raise()
e9576ca5 1281{
e9576ca5
SC
1282}
1283
1284// Lower the window to the bottom of the Z order
e766c8a9 1285void wxWindowMac::Lower()
e9576ca5 1286{
e9576ca5
SC
1287}
1288
e766c8a9 1289void wxWindowMac::DoSetClientSize(int width, int height)
519cb848 1290{
6264b550
RR
1291 if ( width != -1 || height != -1 )
1292 {
1293
1294 if ( width != -1 && m_vScrollBar )
1295 width += MAC_SCROLLBAR_SIZE ;
1296 if ( height != -1 && m_vScrollBar )
1297 height += MAC_SCROLLBAR_SIZE ;
519cb848 1298
6264b550
RR
1299 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1300 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
2f1ae414 1301
6264b550
RR
1302 DoSetSize( -1 , -1 , width , height ) ;
1303 }
519cb848
SC
1304}
1305
519cb848 1306
e766c8a9 1307wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
519cb848 1308
e766c8a9 1309bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
519cb848 1310{
6264b550
RR
1311 if ((point.x < m_x) || (point.y < m_y) ||
1312 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1313 return FALSE;
1314
1c310985 1315 WindowRef window = MacGetRootWindow() ;
519cb848 1316
6264b550 1317 wxPoint newPoint( point ) ;
519cb848 1318
6264b550
RR
1319 newPoint.x -= m_x;
1320 newPoint.y -= m_y;
1321
1322 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1323 {
1324 wxWindowMac *child = (wxWindowMac*)node->Data();
1325 // added the m_isShown test --dmazzoni
1c310985 1326 if ( child->MacGetRootWindow() == window && child->m_isShown )
6264b550
RR
1327 {
1328 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1329 return TRUE;
1330 }
1331 }
519cb848 1332
6264b550
RR
1333 *outWin = this ;
1334 return TRUE;
519cb848
SC
1335}
1336
e766c8a9 1337bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
519cb848 1338{
6264b550
RR
1339 WindowRef window ;
1340 Point pt = { screenpoint.y , screenpoint.x } ;
1341 if ( ::FindWindow( pt , &window ) == 3 )
1342 {
1343 wxPoint point( screenpoint ) ;
1344 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1345 if ( win )
1346 {
1347 win->ScreenToClient( point ) ;
1348 return win->MacGetWindowFromPointSub( point , outWin ) ;
1349 }
1350 }
1351 return FALSE ;
519cb848
SC
1352}
1353
1354extern int wxBusyCursorCount ;
1355
e766c8a9 1356bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
519cb848 1357{
6264b550
RR
1358 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1359 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1360 return FALSE;
1361
1362
1363 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1364 return FALSE ;
1365
1c310985 1366 WindowRef window = MacGetRootWindow() ;
6264b550
RR
1367
1368 event.m_x -= m_x;
1369 event.m_y -= m_y;
1370
1371 int x = event.m_x ;
1372 int y = event.m_y ;
1373
1374 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1375 {
1376 wxWindowMac *child = (wxWindowMac*)node->Data();
1c310985 1377 if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
6264b550
RR
1378 {
1379 if (child->MacDispatchMouseEvent(event))
1380 return TRUE;
1381 }
7810c95b 1382 }
2f1ae414 1383
6264b550
RR
1384 event.m_x = x ;
1385 event.m_y = y ;
1386
1387 if ( wxBusyCursorCount == 0 )
1388 {
1389 m_cursor.MacInstall() ;
1390 }
1391
1392 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1393 {
1394 // set focus to this window
1395 if (AcceptsFocus() && FindFocus()!=this)
1396 SetFocus();
1397 }
1398
2f1ae414
SC
1399#if wxUSE_TOOLTIPS
1400 if ( event.GetEventType() == wxEVT_MOTION
6264b550
RR
1401 || event.GetEventType() == wxEVT_ENTER_WINDOW
1402 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
2f1ae414
SC
1403 wxToolTip::RelayEvent( this , event);
1404#endif // wxUSE_TOOLTIPS
6264b550
RR
1405 GetEventHandler()->ProcessEvent( event ) ;
1406 return TRUE;
519cb848
SC
1407}
1408
e766c8a9 1409wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2f1ae414 1410{
6264b550
RR
1411 if ( m_tooltip )
1412 {
1413 return m_tooltip->GetTip() ;
1414 }
1415 return "" ;
2f1ae414 1416}
6264b550 1417
1c310985 1418void wxWindowMac::Update()
519cb848 1419{
1c310985
SC
1420 wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
1421 if ( win )
1422 win->MacUpdate( 0 ) ;
519cb848
SC
1423}
1424
1c310985 1425wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
519cb848 1426{
1c310985
SC
1427 wxTopLevelWindowMac* win = NULL ;
1428 WindowRef window = MacGetRootWindow() ;
1429 if ( window )
6264b550 1430 {
1c310985
SC
1431 win = wxFindWinFromMacWindow( window ) ;
1432 }
1433 return win ;
519cb848
SC
1434}
1435
1c310985 1436void wxWindowMac::MacRedraw( RgnHandle updatergn , long time, bool erase)
519cb848 1437{
6264b550 1438 // updatergn is always already clipped to our boundaries
1c310985
SC
1439 // it is in nc-coordinates
1440
1441 WindowRef window = MacGetRootWindow() ;
6264b550
RR
1442
1443 {
1c310985
SC
1444 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1445 RgnHandle ownUpdateRgn = NewRgn() ;
1446 CopyRgn( updatergn , ownUpdateRgn ) ;
1447 // subtract all children from updatergn, as soon as we start with transparent windows, these should
1448 // not be subtracted
1c310985
SC
1449
1450 RgnHandle childarea = NewRgn() ;
1451 for (wxNode *node = GetChildren().First(); node; node = node->Next())
6264b550 1452 {
1c310985
SC
1453 wxWindowMac *child = (wxWindowMac*)node->Data();
1454
1455 if ( child->MacGetRootWindow() == window && child->IsShown() )
6264b550 1456 {
1c310985 1457 SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
e8788ed0 1458 DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
6264b550 1459 }
1c310985
SC
1460 }
1461 DisposeRgn( childarea ) ;
1462
1463 // now intersect this with the client area
1464 // and shift it to client coordinates
6264b550 1465
1c310985
SC
1466 RgnHandle newupdate = NewRgn() ;
1467 wxSize point = GetClientSize() ;
1468 wxPoint origin = GetClientAreaOrigin() ;
6264b550 1469
1c310985
SC
1470 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1471 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1472 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1473 m_updateRegion = newupdate ;
1474 DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
e8788ed0 1475 if ( erase && !EmptyRgn(ownUpdateRgn) )
1c310985
SC
1476 {
1477 wxWindowDC dc(this);
e8788ed0 1478 dc.SetClippingRegion(wxRegion(ownUpdateRgn));
1c310985
SC
1479 wxEraseEvent eevent( GetId(), &dc );
1480 eevent.SetEventObject( this );
1481 GetEventHandler()->ProcessEvent( eevent );
1482
1483 wxNcPaintEvent eventNc( GetId() );
1484 eventNc.SetEventObject( this );
1485 GetEventHandler()->ProcessEvent( eventNc );
6264b550 1486 }
1c310985 1487 DisposeRgn( ownUpdateRgn ) ;
1c310985 1488 if ( !m_updateRegion.Empty() )
6264b550 1489 {
1c310985
SC
1490 wxPaintEvent event;
1491 event.m_timeStamp = time ;
1492 event.SetEventObject(this);
1493 GetEventHandler()->ProcessEvent(event);
1494 }
6264b550
RR
1495 }
1496
1c310985 1497 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
6264b550 1498
1c310985 1499 RgnHandle childupdate = NewRgn() ;
6264b550
RR
1500 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1501 {
1502 wxWindowMac *child = (wxWindowMac*)node->Data();
1503 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1504 SectRgn( childupdate , updatergn , childupdate ) ;
1505 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1c310985 1506 if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
6264b550
RR
1507 {
1508 // because dialogs may also be children
1c310985 1509 child->MacRedraw( childupdate , time , erase ) ;
6264b550
RR
1510 }
1511 }
1512 DisposeRgn( childupdate ) ;
1513 // eventually a draw grow box here
1c310985 1514
519cb848
SC
1515}
1516
1c310985 1517WindowRef wxWindowMac::MacGetRootWindow() const
519cb848 1518{
6264b550
RR
1519 wxWindowMac *iter = (wxWindowMac*)this ;
1520
1521 while( iter )
1522 {
1c310985
SC
1523 if ( iter->IsTopLevel() )
1524 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
519cb848 1525
6264b550
RR
1526 iter = iter->GetParent() ;
1527 }
1528 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1529 return NULL ;
519cb848
SC
1530}
1531
e766c8a9 1532void wxWindowMac::MacCreateScrollBars( long style )
519cb848 1533{
6264b550
RR
1534 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1535
1536 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1537 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1538 int width, height ;
1539 GetClientSize( &width , &height ) ;
1540
1541 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1542 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1543 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1544 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1545
1546 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1547 vSize , wxVERTICAL);
1548
1549 if ( style & wxVSCROLL )
1550 {
1551
1552 }
1553 else
1554 {
1555 m_vScrollBar->Show(false) ;
1556 }
1557 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1558 hSize , wxHORIZONTAL);
1559 if ( style & wxHSCROLL )
1560 {
1561 }
1562 else
1563 {
1564 m_hScrollBar->Show(false) ;
1565 }
1566
1567 // because the create does not take into account the client area origin
1568 MacRepositionScrollBars() ; // we might have a real position shift
519cb848
SC
1569}
1570
e766c8a9 1571void wxWindowMac::MacRepositionScrollBars()
519cb848 1572{
6264b550
RR
1573 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1574 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1575
1576 // get real client area
1577
1578 int width = m_width ;
1579 int height = m_height ;
1580
1581 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1582 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
1583
1584 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1585 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1586 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1587 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1588
1589 int x = 0 ;
1590 int y = 0 ;
1591 int w = m_width ;
1592 int h = m_height ;
1593
1594 MacClientToRootWindow( &x , &y ) ;
1595 MacClientToRootWindow( &w , &h ) ;
1596
1597 wxWindowMac *iter = (wxWindowMac*)this ;
1598
1599 int totW = 10000 , totH = 10000;
1600 while( iter )
1601 {
1c310985 1602 if ( iter->IsTopLevel() )
6264b550
RR
1603 {
1604 totW = iter->m_width ;
1605 totH = iter->m_height ;
1606 break ;
1607 }
1608
1609 iter = iter->GetParent() ;
1610 }
1611
1612 if ( x == 0 )
1613 {
1614 hPoint.x = -1 ;
1615 hSize.x += 1 ;
1616 }
1617 if ( y == 0 )
1618 {
1619 vPoint.y = -1 ;
1620 vSize.y += 1 ;
1621 }
1622
1623 if ( w-x >= totW )
1624 {
1625 hSize.x += 1 ;
1626 vPoint.x += 1 ;
1627 }
1628
1629 if ( h-y >= totH )
1630 {
1631 vSize.y += 1 ;
1632 hPoint.y += 1 ;
1633 }
1634
1635 if ( m_vScrollBar )
1636 {
1637 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
1638 }
1639 if ( m_hScrollBar )
1640 {
1641 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
1642 }
519cb848
SC
1643}
1644
e766c8a9 1645bool wxWindowMac::AcceptsFocus() const
7c551d95
SC
1646{
1647 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1648}
519cb848 1649
e766c8a9 1650ControlHandle wxWindowMac::MacGetContainerForEmbedding()
519cb848 1651{
1c310985 1652 return GetParent()->MacGetContainerForEmbedding() ;
519cb848
SC
1653}
1654
e766c8a9 1655void wxWindowMac::MacSuperChangedPosition()
519cb848 1656{
6264b550 1657 // only window-absolute structures have to be moved i.e. controls
519cb848 1658
6264b550
RR
1659 wxNode *node = GetChildren().First();
1660 while ( node )
1661 {
1662 wxWindowMac *child = (wxWindowMac *)node->Data();
1663 child->MacSuperChangedPosition() ;
1664 node = node->Next();
1665 }
519cb848 1666}
519cb848 1667
a3bf4a62
SC
1668void wxWindowMac::MacTopLevelWindowChangedPosition()
1669{
6264b550 1670 // only screen-absolute structures have to be moved i.e. glcanvas
a3bf4a62 1671
6264b550
RR
1672 wxNode *node = GetChildren().First();
1673 while ( node )
1674 {
1675 wxWindowMac *child = (wxWindowMac *)node->Data();
1676 child->MacTopLevelWindowChangedPosition() ;
1677 node = node->Next();
1678 }
a3bf4a62
SC
1679}
1680
e766c8a9 1681bool wxWindowMac::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
519cb848 1682{
6264b550
RR
1683 if ( window == NULL )
1684 return false ;
1685
1686 GrafPtr currPort;
1687 GrafPtr port ;
519cb848 1688
6264b550
RR
1689 ::GetPort(&currPort);
1690 port = UMAGetWindowPort( window) ;
1691 if (currPort != port )
1692 ::SetPort(port);
1693
1694// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
1695 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1696 return true;
519cb848
SC
1697}
1698
e766c8a9 1699bool wxWindowMac::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
519cb848 1700{
6264b550
RR
1701 if ( window == NULL )
1702 return false ;
1703
1704 GrafPtr currPort;
1705 GrafPtr port ;
1706 ::GetPort(&currPort);
1707 port = UMAGetWindowPort( window) ;
1708 if (currPort != port )
1709 ::SetPort(port);
1710// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
1711 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1712 ::ClipRect(&clipRect);
1713
1714 ::PenNormal() ;
1715 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
1716 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
1717 Pattern whiteColor ;
1718
1719 ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
1c310985 1720// ::SetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
6264b550 1721 return true;
519cb848
SC
1722}
1723
e766c8a9 1724void wxWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin)
519cb848 1725{
1c310985
SC
1726 wxASSERT( GetParent() != NULL ) ;
1727 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
1728 localOrigin->h += m_x;
1729 localOrigin->v += m_y;
1730 OffsetRect(clipRect, -m_x, -m_y);
1731
1732 Rect myClip;
1733 myClip.left = 0;
1734 myClip.top = 0;
1735 myClip.right = m_width;
1736 myClip.bottom = m_height;
1737 SectRect(clipRect, &myClip, clipRect);
519cb848
SC
1738}
1739
e766c8a9 1740void wxWindowMac::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
519cb848 1741{
1c310985 1742 wxASSERT( GetParent() != NULL ) ;
6264b550 1743
1c310985
SC
1744 GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
1745
1746 localOrigin->h += m_x;
1747 localOrigin->v += m_y;
1748 OffsetRect(clipRect, -m_x, -m_y);
1749
1750 Rect myClip;
1751 myClip.left = 0;
1752 myClip.top = 0;
1753 myClip.right = m_width ;//width;
1754 myClip.bottom = m_height ;// height;
1755 SectRect(clipRect, &myClip, clipRect);
519cb848
SC
1756}
1757
e766c8a9 1758void wxWindowMac::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
2f1ae414 1759{
6264b550 1760 MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
2f1ae414 1761
6264b550
RR
1762 int width , height ;
1763 GetClientSize( &width , &height ) ;
1764 wxPoint client ;
1765 client = GetClientAreaOrigin( ) ;
1766
1767 localOrigin->h += client.x;
1768 localOrigin->v += client.y;
1769 OffsetRect(clipRect, -client.x, -client.y);
2f1ae414 1770
6264b550
RR
1771 Rect myClip;
1772 myClip.left = 0;
1773 myClip.top = 0;
1774 myClip.right = width;
1775 myClip.bottom = height;
1776 SectRect(clipRect, &myClip, clipRect);
2f1ae414
SC
1777}
1778
e766c8a9 1779long wxWindowMac::MacGetLeftBorderSize( ) const
2f1ae414 1780{
1c310985 1781 if( IsTopLevel() )
6264b550 1782 return 0 ;
2f1ae414
SC
1783
1784 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
1785 {
1c310985
SC
1786 SInt32 border = 3 ;
1787#if wxMAC_USE_THEME_BORDER
1788#if TARGET_CARBON
1789 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1790#endif
1791#endif
1792 return border ;
2f1ae414
SC
1793 }
1794 else if ( m_windowStyle &wxDOUBLE_BORDER)
1795 {
1c310985
SC
1796 SInt32 border = 3 ;
1797#if wxMAC_USE_THEME_BORDER
1798#if TARGET_CARBON
1799 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1800#endif
1801#endif
1802 return border ;
2f1ae414
SC
1803 }
1804 else if (m_windowStyle &wxSIMPLE_BORDER)
1805 {
6264b550 1806 return 1 ;
2f1ae414 1807 }
6264b550 1808 return 0 ;
2f1ae414
SC
1809}
1810
e766c8a9 1811long wxWindowMac::MacGetRightBorderSize( ) const
5b781a67 1812{
1c310985
SC
1813 // they are all symmetric in mac themes
1814 return MacGetLeftBorderSize() ;
5b781a67
SC
1815}
1816
e766c8a9 1817long wxWindowMac::MacGetTopBorderSize( ) const
5b781a67 1818{
1c310985
SC
1819 // they are all symmetric in mac themes
1820 return MacGetLeftBorderSize() ;
5b781a67
SC
1821}
1822
e766c8a9 1823long wxWindowMac::MacGetBottomBorderSize( ) const
5b781a67 1824{
1c310985
SC
1825 // they are all symmetric in mac themes
1826 return MacGetLeftBorderSize() ;
5b781a67
SC
1827}
1828
e766c8a9 1829long wxWindowMac::MacRemoveBordersFromStyle( long style )
2f1ae414 1830{
6264b550 1831 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2f1ae414 1832}
0a67a93b 1833
b89dac78 1834
e766c8a9 1835wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac * theWindow )
519cb848 1836{
6264b550
RR
1837 m_ok = false ;
1838 Point localOrigin ;
1839 Rect clipRect ;
1840 WindowRef window ;
1841 wxWindowMac *rootwin ;
1842 m_currentPort = NULL ;
1843
1844 GetPort( &m_formerPort ) ;
1845 if ( theWindow )
1846 {
1847 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1848 m_currentPort = UMAGetWindowPort( window ) ;
1849 if ( m_formerPort != m_currentPort )
1850 SetPort( m_currentPort ) ;
1851 GetPenState( &m_savedPenState ) ;
1852 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1853 m_ok = true ;
1854 }
1855}
1856
519cb848
SC
1857wxMacDrawingHelper::~wxMacDrawingHelper()
1858{
6264b550
RR
1859 if ( m_ok )
1860 {
1861 SetPort( m_currentPort ) ;
1862 SetPenState( &m_savedPenState ) ;
1863 SetOrigin( 0 , 0 ) ;
1864 Rect portRect ;
1865 GetPortBounds( m_currentPort , &portRect ) ;
1866 ClipRect( &portRect ) ;
1867 }
1868
1869 if ( m_formerPort != m_currentPort )
1870 SetPort( m_formerPort ) ;
519cb848 1871}
519cb848 1872
e766c8a9 1873wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac * theWindow )
519cb848 1874{
6264b550
RR
1875 m_ok = false ;
1876 Point localOrigin ;
1877 Rect clipRect ;
1878 WindowRef window ;
1879 wxWindowMac *rootwin ;
1880 m_currentPort = NULL ;
1881
1882 GetPort( &m_formerPort ) ;
1883
1884 if ( theWindow )
1885 {
1886 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1887 m_currentPort = UMAGetWindowPort( window ) ;
1888 if ( m_formerPort != m_currentPort )
1889 SetPort( m_currentPort ) ;
1890 GetPenState( &m_savedPenState ) ;
1891 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1892 m_ok = true ;
1893 }
1894}
1895
519cb848
SC
1896wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1897{
6264b550
RR
1898 if ( m_ok )
1899 {
1900 SetPort( m_currentPort ) ;
1901 SetPenState( &m_savedPenState ) ;
1902 SetOrigin( 0 , 0 ) ;
1903 Rect portRect ;
1904 GetPortBounds( m_currentPort , &portRect ) ;
1905 ClipRect( &portRect ) ;
1906 }
1907
1908 if ( m_formerPort != m_currentPort )
1909 SetPort( m_formerPort ) ;
519cb848 1910}
3723b7b1 1911
e766c8a9 1912// Find the wxWindowMac at the current mouse position, returning the mouse
3723b7b1 1913// position.
e766c8a9 1914wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 1915{
59a12e90 1916 pt = wxGetMousePosition();
e766c8a9 1917 wxWindowMac* found = wxFindWindowAtPoint(pt);
59a12e90 1918 return found;
3723b7b1
JS
1919}
1920
1921// Get the current mouse position.
1922wxPoint wxGetMousePosition()
1923{
57591e0e
JS
1924 int x, y;
1925 wxGetMousePosition(& x, & y);
1926 return wxPoint(x, y);
3723b7b1
JS
1927}
1928