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