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