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