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