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