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