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