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