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