]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/window.cpp
Convert to and from \n and \r in wxMac's text
[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
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
1c310985 597 // erase new position
de043984
SC
598
599 Refresh() ;
1c310985
SC
600 if ( doMove )
601 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
602
6264b550
RR
603 MacRepositionScrollBars() ;
604 if ( doMove )
605 {
606 wxPoint point(m_x, m_y);
607 wxMoveEvent event(point, m_windowId);
608 event.SetEventObject(this);
609 GetEventHandler()->ProcessEvent(event) ;
610 }
611 if ( doResize )
612 {
613 MacRepositionScrollBars() ;
614 wxSize size(m_width, m_height);
615 wxSizeEvent event(size, m_windowId);
616 event.SetEventObject(this);
617 GetEventHandler()->ProcessEvent(event);
618 }
619 }
14c9cbdb 620
954fc50b
SC
621}
622
623// set the size of the window: if the dimensions are positive, just use them,
624// but if any of them is equal to -1, it means that we must find the value for
625// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
626// which case -1 is a valid value for x and y)
627//
628// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
629// the width/height to best suit our contents, otherwise we reuse the current
630// width/height
631void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
632{
633 // get the current size and position...
634 int currentX, currentY;
635 GetPosition(&currentX, &currentY);
14c9cbdb 636
954fc50b
SC
637 int currentW,currentH;
638 GetSize(&currentW, &currentH);
639
640 // ... and don't do anything (avoiding flicker) if it's already ok
641 if ( x == currentX && y == currentY &&
642 width == currentW && height == currentH )
643 {
6264b550 644 MacRepositionScrollBars() ; // we might have a real position shift
954fc50b
SC
645 return;
646 }
647
648 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
649 x = currentX;
650 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
651 y = currentY;
652
653 AdjustForParentClientOrigin(x, y, sizeFlags);
654
655 wxSize size(-1, -1);
656 if ( width == -1 )
657 {
658 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
659 {
660 size = DoGetBestSize();
661 width = size.x;
662 }
663 else
664 {
665 // just take the current one
666 width = currentW;
667 }
668 }
669
670 if ( height == -1 )
671 {
672 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
673 {
674 if ( size.x == -1 )
675 {
676 size = DoGetBestSize();
677 }
678 //else: already called DoGetBestSize() above
679
680 height = size.y;
681 }
682 else
683 {
684 // just take the current one
685 height = currentH;
686 }
687 }
688
689 DoMoveWindow(x, y, width, height);
690
e9576ca5 691}
e9576ca5
SC
692// For implementation purposes - sometimes decorations make the client area
693// smaller
519cb848 694
e766c8a9 695wxPoint wxWindowMac::GetClientAreaOrigin() const
e9576ca5 696{
5b781a67 697 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
e9576ca5
SC
698}
699
d84afea9 700void wxWindowMac::SetTitle(const wxString& title)
e9576ca5 701{
ed60b502 702 m_label = title ;
519cb848
SC
703}
704
d84afea9 705wxString wxWindowMac::GetTitle() const
519cb848 706{
ed60b502 707 return m_label ;
519cb848
SC
708}
709
e766c8a9 710bool wxWindowMac::Show(bool show)
e9576ca5 711{
e7549107
SC
712 if ( !wxWindowBase::Show(show) )
713 return FALSE;
714
baf52e1c
SC
715/*
716 WindowRef window = (WindowRef) MacGetRootWindow() ;
717 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
718 if ( win == NULL && win->m_isBeingDeleted )
719 return FALSE ;
14c9cbdb 720*/
6264b550 721 MacSuperShown( show ) ;
14c9cbdb
RD
722 Refresh() ;
723/*
6264b550
RR
724 if ( !show )
725 {
6264b550 726 if ( win && !win->m_isBeingDeleted )
14c9cbdb 727 Refresh() ;
6264b550
RR
728 }
729 else
730 {
14c9cbdb 731 Refresh() ;
6264b550 732 }
baf52e1c 733*/
e7549107 734 return TRUE;
e9576ca5
SC
735}
736
14c9cbdb 737void wxWindowMac::MacSuperShown( bool show )
8208e181 738{
6264b550
RR
739 wxNode *node = GetChildren().First();
740 while ( node )
741 {
742 wxWindowMac *child = (wxWindowMac *)node->Data();
743 if ( child->m_isShown )
744 child->MacSuperShown( show ) ;
745 node = node->Next();
746 }
8208e181
SC
747}
748
14c9cbdb 749void wxWindowMac::MacSuperEnabled( bool enabled )
1c310985 750{
1c469f7f
SC
751 if ( !IsTopLevel() )
752 {
14c9cbdb 753 // to be absolutely correct we'd have to invalidate (with eraseBkground
1c469f7f
SC
754 // because unter MacOSX the frames are drawn with an addXXX mode)
755 // the borders area
756 }
1c310985
SC
757 wxNode *node = GetChildren().First();
758 while ( node )
759 {
760 wxWindowMac *child = (wxWindowMac *)node->Data();
761 if ( child->m_isShown )
762 child->MacSuperEnabled( enabled ) ;
763 node = node->Next();
764 }
765}
766
14c9cbdb 767bool wxWindowMac::MacIsReallyShown() const
c809f3be 768{
6264b550
RR
769 if ( m_isShown && (m_parent != NULL) ) {
770 return m_parent->MacIsReallyShown();
771 }
772 return m_isShown;
14c9cbdb 773/*
6264b550
RR
774 bool status = m_isShown ;
775 wxWindowMac * win = this ;
776 while ( status && win->m_parent != NULL )
777 {
778 win = win->m_parent ;
779 status = win->m_isShown ;
780 }
781 return status ;
5fde6fcc 782*/
c809f3be
SC
783}
784
e766c8a9 785int wxWindowMac::GetCharHeight() const
e9576ca5 786{
6264b550
RR
787 wxClientDC dc ( (wxWindowMac*)this ) ;
788 return dc.GetCharHeight() ;
e9576ca5
SC
789}
790
e766c8a9 791int wxWindowMac::GetCharWidth() const
e9576ca5 792{
6264b550
RR
793 wxClientDC dc ( (wxWindowMac*)this ) ;
794 return dc.GetCharWidth() ;
e9576ca5
SC
795}
796
e766c8a9 797void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 798 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 799{
e7549107
SC
800 const wxFont *fontToUse = theFont;
801 if ( !fontToUse )
802 fontToUse = &m_font;
14c9cbdb 803
e766c8a9 804 wxClientDC dc( (wxWindowMac*) this ) ;
7c74e7fe 805 long lx,ly,ld,le ;
5fde6fcc 806 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414 807 if ( externalLeading )
6264b550 808 *externalLeading = le ;
2f1ae414 809 if ( descent )
6264b550 810 *descent = ld ;
2f1ae414 811 if ( x )
6264b550 812 *x = lx ;
2f1ae414 813 if ( y )
6264b550 814 *y = ly ;
e9576ca5
SC
815}
816
0a67a93b 817/*
14c9cbdb 818 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1c310985
SC
819 * we always intersect with the entire window, not only with the client area
820 */
14c9cbdb 821
e766c8a9 822void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
e9576ca5 823{
94abc21f 824 if ( MacGetTopLevelWindow() == NULL )
9a456218 825 return ;
14c9cbdb 826
9a456218
RR
827 wxPoint client = GetClientAreaOrigin();
828 int x1 = -client.x;
829 int y1 = -client.y;
830 int x2 = m_width - client.x;
831 int y2 = m_height - client.y;
832
833 if (IsKindOf( CLASSINFO(wxButton)))
834 {
835 // buttons have an "aura"
836 y1 -= 5;
837 x1 -= 5;
838 y2 += 5;
839 x2 += 5;
840 }
841
842 Rect clientrect = { y1, x1, y2, x2 };
14c9cbdb 843
1c310985 844 if ( rect )
6264b550 845 {
1c310985 846 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
14c9cbdb 847 SectRect( &clientrect , &r , &clientrect ) ;
6264b550 848 }
14c9cbdb 849
1c310985 850 if ( !EmptyRect( &clientrect ) )
e9576ca5 851 {
1c310985 852 int top = 0 , left = 0 ;
14c9cbdb 853
1c310985
SC
854 MacClientToRootWindow( &left , &top ) ;
855 OffsetRect( &clientrect , left , top ) ;
14c9cbdb 856
1c310985 857 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
e9576ca5
SC
858 }
859}
860
e7549107
SC
861#if wxUSE_CARET && WXWIN_COMPATIBILITY
862// ---------------------------------------------------------------------------
e9576ca5 863// Caret manipulation
e7549107
SC
864// ---------------------------------------------------------------------------
865
e766c8a9 866void wxWindowMac::CreateCaret(int w, int h)
e9576ca5 867{
e7549107 868 SetCaret(new wxCaret(this, w, h));
e9576ca5
SC
869}
870
e766c8a9 871void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
e9576ca5 872{
e7549107 873 wxFAIL_MSG("not implemented");
e9576ca5
SC
874}
875
e766c8a9 876void wxWindowMac::ShowCaret(bool show)
e9576ca5 877{
e7549107
SC
878 wxCHECK_RET( m_caret, "no caret to show" );
879
880 m_caret->Show(show);
e9576ca5
SC
881}
882
e766c8a9 883void wxWindowMac::DestroyCaret()
e9576ca5 884{
e7549107 885 SetCaret(NULL);
e9576ca5
SC
886}
887
e766c8a9 888void wxWindowMac::SetCaretPos(int x, int y)
e9576ca5 889{
e7549107
SC
890 wxCHECK_RET( m_caret, "no caret to move" );
891
892 m_caret->Move(x, y);
e9576ca5
SC
893}
894
e766c8a9 895void wxWindowMac::GetCaretPos(int *x, int *y) const
e9576ca5 896{
e7549107
SC
897 wxCHECK_RET( m_caret, "no caret to get position of" );
898
899 m_caret->GetPosition(x, y);
e9576ca5 900}
e7549107 901#endif // wxUSE_CARET
e9576ca5 902
e766c8a9 903wxWindowMac *wxGetActiveWindow()
e9576ca5 904{
519cb848 905 // actually this is a windows-only concept
e9576ca5
SC
906 return NULL;
907}
908
e9576ca5 909// Coordinates relative to the window
e766c8a9 910void wxWindowMac::WarpPointer (int x_pos, int y_pos)
e9576ca5 911{
519cb848 912 // We really dont move the mouse programmatically under mac
e9576ca5
SC
913}
914
14c9cbdb 915const wxBrush& wxWindowMac::MacGetBackgroundBrush()
e9576ca5 916{
a756f210 917 if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1c310985 918 {
94abc21f 919 m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ;
1c310985 920 }
a756f210 921 else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
94abc21f
SC
922 {
923 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
924 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
925 // either a non gray background color or a non control window
14c9cbdb 926
76a5e5d2 927 WindowRef window = (WindowRef) MacGetRootWindow() ;
14c9cbdb 928
94abc21f
SC
929 wxWindowMac* parent = GetParent() ;
930 while( parent )
931 {
932 if ( parent->MacGetRootWindow() != window )
933 {
934 // we are in a different window on the mac system
935 parent = NULL ;
936 break ;
937 }
938
939 {
14c9cbdb 940 if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
a756f210 941 && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
94abc21f
SC
942 {
943 // if we have any other colours in the hierarchy
944 m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ;
945 break ;
946 }
947 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
948 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
949 {
7d9d1fd7
SC
950 Rect extent = { 0 , 0 , 0 , 0 } ;
951 int x , y ;
952 x = y = 0 ;
baf52e1c 953 wxSize size = parent->GetSize() ;
7d9d1fd7
SC
954 parent->MacClientToRootWindow( &x , &y ) ;
955 extent.left = x ;
956 extent.top = y ;
957 extent.top-- ;
958 extent.right = x + size.x ;
959 extent.bottom = y + size.y ;
76a5e5d2 960 m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
94abc21f
SC
961 break ;
962 }
963 }
964 parent = parent->GetParent() ;
965 }
966 if ( !parent )
967 {
968 m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive
969 }
970 }
971 else
972 {
973 m_macBackgroundBrush.SetColour( m_backgroundColour ) ;
974 }
975
976 return m_macBackgroundBrush ;
14c9cbdb 977
94abc21f
SC
978}
979
980void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
981{
982 event.GetDC()->Clear() ;
1c310985
SC
983}
984
985void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
986{
de043984
SC
987 wxWindowDC dc(this) ;
988 wxMacPortSetter helper(&dc) ;
14c9cbdb 989
76a5e5d2 990 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
e9576ca5
SC
991}
992
e766c8a9 993int wxWindowMac::GetScrollPos(int orient) const
e9576ca5 994{
1c310985
SC
995 if ( orient == wxHORIZONTAL )
996 {
997 if ( m_hScrollBar )
998 return m_hScrollBar->GetThumbPosition() ;
999 }
1000 else
1001 {
1002 if ( m_vScrollBar )
1003 return m_vScrollBar->GetThumbPosition() ;
1004 }
e9576ca5
SC
1005 return 0;
1006}
1007
1008// This now returns the whole range, not just the number
1009// of positions that we can scroll.
e766c8a9 1010int wxWindowMac::GetScrollRange(int orient) const
e9576ca5 1011{
1c310985
SC
1012 if ( orient == wxHORIZONTAL )
1013 {
1014 if ( m_hScrollBar )
1015 return m_hScrollBar->GetRange() ;
1016 }
1017 else
1018 {
1019 if ( m_vScrollBar )
1020 return m_vScrollBar->GetRange() ;
1021 }
e9576ca5
SC
1022 return 0;
1023}
1024
e766c8a9 1025int wxWindowMac::GetScrollThumb(int orient) const
e9576ca5 1026{
1c310985
SC
1027 if ( orient == wxHORIZONTAL )
1028 {
1029 if ( m_hScrollBar )
1030 return m_hScrollBar->GetThumbSize() ;
1031 }
1032 else
1033 {
1034 if ( m_vScrollBar )
1035 return m_vScrollBar->GetThumbSize() ;
1036 }
e9576ca5
SC
1037 return 0;
1038}
1039
e766c8a9 1040void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
e9576ca5 1041{
1c310985 1042 if ( orient == wxHORIZONTAL )
6264b550 1043 {
1c310985
SC
1044 if ( m_hScrollBar )
1045 m_hScrollBar->SetThumbPosition( pos ) ;
6264b550
RR
1046 }
1047 else
1048 {
1c310985
SC
1049 if ( m_vScrollBar )
1050 m_vScrollBar->SetThumbPosition( pos ) ;
6264b550 1051 }
2f1ae414
SC
1052}
1053
14c9cbdb 1054void wxWindowMac::MacPaintBorders( int left , int top )
2f1ae414 1055{
1c310985 1056 if( IsTopLevel() )
6264b550 1057 return ;
14c9cbdb 1058
6264b550
RR
1059 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1060 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1061 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1062 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1063 PenNormal() ;
2f1ae414
SC
1064
1065 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1066 {
1c310985 1067#if wxMAC_USE_THEME_BORDER
ed60b502
RR
1068 Rect rect = { top , left , m_height + top , m_width + left } ;
1069 SInt32 border = 0 ;
1070 /*
1071 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1072 InsetRect( &rect , border , border );
1c310985
SC
1073 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1074 */
14c9cbdb 1075
1c310985
SC
1076 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1077#else
ed60b502 1078 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
653b2449 1079 RGBForeColor( &face );
7d9d1fd7
SC
1080 MoveTo( left + 0 , top + m_height - 2 );
1081 LineTo( left + 0 , top + 0 );
1082 LineTo( left + m_width - 2 , top + 0 );
653b2449 1083
7d9d1fd7
SC
1084 MoveTo( left + 2 , top + m_height - 3 );
1085 LineTo( left + m_width - 3 , top + m_height - 3 );
1086 LineTo( left + m_width - 3 , top + 2 );
653b2449
SC
1087
1088 RGBForeColor( sunken ? &face : &black );
7d9d1fd7
SC
1089 MoveTo( left + 0 , top + m_height - 1 );
1090 LineTo( left + m_width - 1 , top + m_height - 1 );
1091 LineTo( left + m_width - 1 , top + 0 );
653b2449
SC
1092
1093 RGBForeColor( sunken ? &shadow : &white );
7d9d1fd7
SC
1094 MoveTo( left + 1 , top + m_height - 3 );
1095 LineTo( left + 1, top + 1 );
1096 LineTo( left + m_width - 3 , top + 1 );
653b2449
SC
1097
1098 RGBForeColor( sunken ? &white : &shadow );
7d9d1fd7
SC
1099 MoveTo( left + 1 , top + m_height - 2 );
1100 LineTo( left + m_width - 2 , top + m_height - 2 );
1101 LineTo( left + m_width - 2 , top + 1 );
653b2449
SC
1102
1103 RGBForeColor( sunken ? &black : &face );
7d9d1fd7
SC
1104 MoveTo( left + 2 , top + m_height - 4 );
1105 LineTo( left + 2 , top + 2 );
1106 LineTo( left + m_width - 4 , top + 2 );
1c310985 1107#endif
8208e181
SC
1108 }
1109 else if (HasFlag(wxSIMPLE_BORDER))
1110 {
ed60b502 1111 Rect rect = { top , left , m_height + top , m_width + left } ;
6264b550
RR
1112 RGBForeColor( &black ) ;
1113 FrameRect( &rect ) ;
2f1ae414 1114 }
8208e181
SC
1115}
1116
abda5788
SC
1117void wxWindowMac::RemoveChild( wxWindowBase *child )
1118{
1119 if ( child == m_hScrollBar )
1120 m_hScrollBar = NULL ;
1121 if ( child == m_vScrollBar )
1122 m_vScrollBar = NULL ;
14c9cbdb 1123
abda5788
SC
1124 wxWindowBase::RemoveChild( child ) ;
1125}
1126
e9576ca5 1127// New function that will replace some of the above.
e766c8a9 1128void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
e9576ca5
SC
1129 int range, bool refresh)
1130{
6264b550
RR
1131 if ( orient == wxHORIZONTAL )
1132 {
1133 if ( m_hScrollBar )
1134 {
1135 if ( range == 0 || thumbVisible >= range )
1136 {
1137 if ( m_hScrollBar->IsShown() )
1138 m_hScrollBar->Show(false) ;
1139 }
1140 else
1141 {
1142 if ( !m_hScrollBar->IsShown() )
1143 m_hScrollBar->Show(true) ;
1144 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1145 }
1146 }
1147 }
1148 else
1149 {
1150 if ( m_vScrollBar )
1151 {
1152 if ( range == 0 || thumbVisible >= range )
1153 {
1154 if ( m_vScrollBar->IsShown() )
1155 m_vScrollBar->Show(false) ;
1156 }
1157 else
1158 {
1159 if ( !m_vScrollBar->IsShown() )
1160 m_vScrollBar->Show(true) ;
1161 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1162 }
1163 }
1164 }
1165 MacRepositionScrollBars() ;
e9576ca5
SC
1166}
1167
1168// Does a physical scroll
e766c8a9 1169void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
e9576ca5 1170{
de043984
SC
1171 wxClientDC dc(this) ;
1172 wxMacPortSetter helper(&dc) ;
1173
6264b550
RR
1174 {
1175 int width , height ;
1176 GetClientSize( &width , &height ) ;
1177
de043984 1178 Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ;
6264b550
RR
1179 RgnHandle updateRgn = NewRgn() ;
1180 ClipRect( &scrollrect ) ;
1181 if ( rect )
1182 {
14c9cbdb 1183 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
de043984 1184 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
14c9cbdb 1185 SectRect( &scrollrect , &r , &scrollrect ) ;
6264b550
RR
1186 }
1187 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
76a5e5d2 1188 InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ;
6264b550
RR
1189 DisposeRgn( updateRgn ) ;
1190 }
14c9cbdb 1191
6264b550
RR
1192 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1193 {
1194 wxWindowMac *child = (wxWindowMac*)node->Data();
1195 if (child == m_vScrollBar) continue;
1196 if (child == m_hScrollBar) continue;
1197 if (child->IsTopLevel()) continue;
1198 int x,y;
1199 child->GetPosition( &x, &y );
1200 int w,h;
1201 child->GetSize( &w, &h );
1202 child->SetSize( x+dx, y+dy, w, h );
1203 }
14c9cbdb 1204
e9576ca5
SC
1205}
1206
e766c8a9 1207void wxWindowMac::MacOnScroll(wxScrollEvent &event )
7c74e7fe 1208{
6264b550
RR
1209 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1210 {
1211 wxScrollWinEvent wevent;
1212 wevent.SetPosition(event.GetPosition());
1213 wevent.SetOrientation(event.GetOrientation());
1214 wevent.m_eventObject = this;
14c9cbdb 1215
6264b550
RR
1216 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1217 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1218 } else
1219 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1220 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1221 } else
1222 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1223 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1224 } else
1225 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1226 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1227 } else
1228 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1229 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1230 } else
1231 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1232 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1233 } else
1234 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1235 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1236 }
14c9cbdb 1237
6264b550 1238 GetEventHandler()->ProcessEvent(wevent);
7c74e7fe
SC
1239 }
1240}
1241
e9576ca5 1242// Get the window with the focus
e766c8a9 1243wxWindowMac *wxWindowBase::FindFocus()
e9576ca5 1244{
6264b550 1245 return gFocusWindow ;
519cb848
SC
1246}
1247
e7549107 1248#if WXWIN_COMPATIBILITY
e9576ca5
SC
1249// If nothing defined for this, try the parent.
1250// E.g. we may be a button loaded from a resource, with no callback function
1251// defined.
e766c8a9 1252void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
e9576ca5 1253{
e7549107
SC
1254 if ( GetEventHandler()->ProcessEvent(event) )
1255 return;
1256 if ( m_parent )
1257 m_parent->GetEventHandler()->OnCommand(win, event);
e9576ca5 1258}
e7549107 1259#endif // WXWIN_COMPATIBILITY_2
e9576ca5 1260
e7549107 1261#if WXWIN_COMPATIBILITY
e766c8a9 1262wxObject* wxWindowMac::GetChild(int number) const
e9576ca5 1263{
e7549107
SC
1264 // Return a pointer to the Nth object in the Panel
1265 wxNode *node = GetChildren().First();
1266 int n = number;
1267 while (node && n--)
1268 node = node->Next();
1269 if ( node )
519cb848 1270 {
e7549107
SC
1271 wxObject *obj = (wxObject *)node->Data();
1272 return(obj);
519cb848
SC
1273 }
1274 else
e7549107 1275 return NULL;
e9576ca5 1276}
e7549107 1277#endif // WXWIN_COMPATIBILITY
e9576ca5 1278
e766c8a9 1279void wxWindowMac::OnSetFocus(wxFocusEvent& event)
7810c95b
SC
1280{
1281 // panel wants to track the window which was the last to have focus in it,
1282 // so we want to set ourselves as the window which last had focus
1283 //
1284 // notice that it's also important to do it upwards the tree becaus
1285 // otherwise when the top level panel gets focus, it won't set it back to
1286 // us, but to some other sibling
14c9cbdb 1287
c1fb8167
SC
1288 // CS:don't know if this is still needed:
1289 //wxChildFocusEvent eventFocus(this);
1290 //(void)GetEventHandler()->ProcessEvent(eventFocus);
7810c95b
SC
1291
1292 event.Skip();
1293}
1294
e766c8a9 1295void wxWindowMac::Clear()
e9576ca5 1296{
1c310985
SC
1297 wxClientDC dc(this);
1298 wxBrush brush(GetBackgroundColour(), wxSOLID);
1299 dc.SetBackground(brush);
1300 dc.Clear();
e9576ca5
SC
1301}
1302
e7549107 1303// Setup background and foreground colours correctly
e766c8a9 1304void wxWindowMac::SetupColours()
e9576ca5 1305{
e7549107
SC
1306 if ( GetParent() )
1307 SetBackgroundColour(GetParent()->GetBackgroundColour());
e9576ca5
SC
1308}
1309
e766c8a9 1310void wxWindowMac::OnIdle(wxIdleEvent& event)
e9576ca5 1311{
519cb848
SC
1312/*
1313 // Check if we need to send a LEAVE event
1314 if (m_mouseInWindow)
1315 {
1316 POINT pt;
1317 ::GetCursorPos(&pt);
1318 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1319 {
1320 // Generate a LEAVE event
1321 m_mouseInWindow = FALSE;
1322 MSWOnMouseLeave(pt.x, pt.y, 0);
1323 }
e9576ca5
SC
1324 }
1325*/
1326
1327 // This calls the UI-update mechanism (querying windows for
1328 // menu/toolbar/control state information)
6264b550 1329 UpdateWindowUI();
e9576ca5
SC
1330}
1331
1332// Raise the window to the top of the Z order
e766c8a9 1333void wxWindowMac::Raise()
e9576ca5 1334{
e9576ca5
SC
1335}
1336
1337// Lower the window to the bottom of the Z order
e766c8a9 1338void wxWindowMac::Lower()
e9576ca5 1339{
e9576ca5
SC
1340}
1341
e766c8a9 1342void wxWindowMac::DoSetClientSize(int width, int height)
519cb848 1343{
6264b550
RR
1344 if ( width != -1 || height != -1 )
1345 {
14c9cbdb 1346
6264b550
RR
1347 if ( width != -1 && m_vScrollBar )
1348 width += MAC_SCROLLBAR_SIZE ;
1349 if ( height != -1 && m_vScrollBar )
1350 height += MAC_SCROLLBAR_SIZE ;
519cb848 1351
6264b550
RR
1352 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1353 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
2f1ae414 1354
6264b550
RR
1355 DoSetSize( -1 , -1 , width , height ) ;
1356 }
519cb848
SC
1357}
1358
519cb848 1359
e766c8a9 1360wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
519cb848 1361
14c9cbdb 1362bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
519cb848 1363{
a07c1212
SC
1364 if ( IsTopLevel() )
1365 {
1366 if ((point.x < 0) || (point.y < 0) ||
1367 (point.x > (m_width)) || (point.y > (m_height)))
1368 return FALSE;
1369 }
1370 else
1371 {
1372 if ((point.x < m_x) || (point.y < m_y) ||
1373 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1374 return FALSE;
1375 }
14c9cbdb 1376
76a5e5d2 1377 WindowRef window = (WindowRef) MacGetRootWindow() ;
519cb848 1378
6264b550 1379 wxPoint newPoint( point ) ;
519cb848 1380
a07c1212
SC
1381 if ( !IsTopLevel() )
1382 {
1383 newPoint.x -= m_x;
1384 newPoint.y -= m_y;
1385 }
14c9cbdb 1386
6264b550
RR
1387 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1388 {
1389 wxWindowMac *child = (wxWindowMac*)node->Data();
1390 // added the m_isShown test --dmazzoni
1c310985 1391 if ( child->MacGetRootWindow() == window && child->m_isShown )
6264b550
RR
1392 {
1393 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1394 return TRUE;
1395 }
1396 }
519cb848 1397
6264b550
RR
1398 *outWin = this ;
1399 return TRUE;
519cb848
SC
1400}
1401
14c9cbdb 1402bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
519cb848 1403{
6264b550 1404 WindowRef window ;
14c9cbdb 1405
6264b550
RR
1406 Point pt = { screenpoint.y , screenpoint.x } ;
1407 if ( ::FindWindow( pt , &window ) == 3 )
1408 {
14c9cbdb 1409
a07c1212
SC
1410 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1411 if ( win )
1412 {
ed60b502
RR
1413 // No, this yields the CLIENT are, we need the whole frame. RR.
1414 // point = win->ScreenToClient( point ) ;
14c9cbdb
RD
1415
1416 GrafPtr port;
ed60b502
RR
1417 ::GetPort( &port ) ;
1418 ::SetPort( UMAGetWindowPort( window ) ) ;
1419 ::GlobalToLocal( &pt ) ;
1420 ::SetPort( port ) ;
1421
1422 wxPoint point( pt.h, pt.v ) ;
14c9cbdb 1423
6264b550 1424 return win->MacGetWindowFromPointSub( point , outWin ) ;
a07c1212 1425 }
6264b550
RR
1426 }
1427 return FALSE ;
519cb848
SC
1428}
1429
1430extern int wxBusyCursorCount ;
32b5be3d 1431static wxWindow *gs_lastWhich = NULL;
519cb848 1432
e766c8a9 1433bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
519cb848 1434{
6264b550
RR
1435 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1436 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1437 return FALSE;
14c9cbdb 1438
6264b550 1439
4ac219f6 1440 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxSpinCtrl ) ))
14c9cbdb
RD
1441 return FALSE ;
1442
76a5e5d2 1443 WindowRef window = (WindowRef) MacGetRootWindow() ;
6264b550
RR
1444
1445 event.m_x -= m_x;
1446 event.m_y -= m_y;
14c9cbdb 1447
6264b550
RR
1448 int x = event.m_x ;
1449 int y = event.m_y ;
1450
1451 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1452 {
1453 wxWindowMac *child = (wxWindowMac*)node->Data();
1c310985 1454 if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
6264b550
RR
1455 {
1456 if (child->MacDispatchMouseEvent(event))
1457 return TRUE;
1458 }
7810c95b 1459 }
2f1ae414 1460
6264b550
RR
1461 event.m_x = x ;
1462 event.m_y = y ;
2e6857fa 1463 event.SetEventObject( this ) ;
14c9cbdb 1464
6264b550
RR
1465 if ( wxBusyCursorCount == 0 )
1466 {
1467 m_cursor.MacInstall() ;
1468 }
14c9cbdb 1469
6264b550
RR
1470 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1471 {
1472 // set focus to this window
1473 if (AcceptsFocus() && FindFocus()!=this)
1474 SetFocus();
1475 }
14c9cbdb 1476
2f1ae414 1477#if wxUSE_TOOLTIPS
14c9cbdb 1478 if ( event.GetEventType() == wxEVT_MOTION
6264b550
RR
1479 || event.GetEventType() == wxEVT_ENTER_WINDOW
1480 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
2f1ae414
SC
1481 wxToolTip::RelayEvent( this , event);
1482#endif // wxUSE_TOOLTIPS
ed60b502 1483
32b5be3d
RR
1484 if (gs_lastWhich != this)
1485 {
1486 gs_lastWhich = this;
14c9cbdb 1487
32b5be3d
RR
1488 // Double clicks must always occur on the same window
1489 if (event.GetEventType() == wxEVT_LEFT_DCLICK)
1490 event.SetEventType( wxEVT_LEFT_DOWN );
1491 if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
1492 event.SetEventType( wxEVT_RIGHT_DOWN );
14c9cbdb 1493
32b5be3d
RR
1494 // Same for mouse up events
1495 if (event.GetEventType() == wxEVT_LEFT_UP)
1496 return TRUE;
1497 if (event.GetEventType() == wxEVT_RIGHT_UP)
1498 return TRUE;
1499 }
1500
6264b550 1501 GetEventHandler()->ProcessEvent( event ) ;
ed60b502 1502
6264b550 1503 return TRUE;
519cb848
SC
1504}
1505
e766c8a9 1506wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2f1ae414 1507{
6264b550
RR
1508 if ( m_tooltip )
1509 {
1510 return m_tooltip->GetTip() ;
1511 }
1512 return "" ;
2f1ae414 1513}
6264b550 1514
1c310985 1515void wxWindowMac::Update()
519cb848 1516{
1c310985
SC
1517 wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
1518 if ( win )
f1759123 1519 {
1c310985 1520 win->MacUpdate( 0 ) ;
bec721ec 1521#if TARGET_API_MAC_CARBON
ed60b502
RR
1522 if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) )
1523 {
1524 QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ;
1525 }
bec721ec 1526#endif
ed60b502 1527 }
519cb848
SC
1528}
1529
14c9cbdb 1530wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
519cb848 1531{
1c310985 1532 wxTopLevelWindowMac* win = NULL ;
76a5e5d2 1533 WindowRef window = (WindowRef) MacGetRootWindow() ;
1c310985 1534 if ( window )
6264b550 1535 {
1c310985 1536 win = wxFindWinFromMacWindow( window ) ;
14c9cbdb 1537 }
1c310985 1538 return win ;
519cb848
SC
1539}
1540
94abc21f
SC
1541const wxRegion& wxWindowMac::MacGetVisibleRegion()
1542{
1543 RgnHandle visRgn = NewRgn() ;
de043984 1544 RgnHandle tempRgn = NewRgn() ;
14c9cbdb 1545
94abc21f
SC
1546 SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
1547
de043984
SC
1548 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1549 if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
94abc21f 1550 {
de043984
SC
1551 int borderTop = 14 ;
1552 int borderOther = 4 ;
14c9cbdb 1553
de043984
SC
1554 SetRectRgn( tempRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
1555 DiffRgn( visRgn , tempRgn , visRgn ) ;
1556 }
94abc21f 1557
a07c1212 1558 if ( !IsTopLevel() )
de043984 1559 {
a07c1212
SC
1560 wxWindow* parent = GetParent() ;
1561 while( parent )
1562 {
1563 wxSize size = parent->GetSize() ;
1564 int x , y ;
1565 x = y = 0 ;
1566 parent->MacWindowToRootWindow( &x, &y ) ;
1567 MacRootWindowToWindow( &x , &y ) ;
1568 SetRectRgn( tempRgn , x , y , x + size.x , y + size.y ) ;
1569 SectRgn( visRgn , tempRgn , visRgn ) ;
1570 if ( parent->IsTopLevel() )
1571 break ;
1572 parent = parent->GetParent() ;
1573 }
de043984
SC
1574 }
1575 if ( GetWindowStyle() & wxCLIP_CHILDREN )
1576 {
94abc21f
SC
1577 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1578 {
1579 wxWindowMac *child = (wxWindowMac*)node->Data();
1580
1581 if ( !child->IsTopLevel() && child->IsShown() )
1582 {
de043984
SC
1583 SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1584 DiffRgn( visRgn , tempRgn , visRgn ) ;
94abc21f 1585 }
14c9cbdb 1586 }
94abc21f 1587 }
14c9cbdb 1588
94abc21f
SC
1589 if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
1590 {
94abc21f
SC
1591 bool thisWindowThrough = false ;
1592 for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next())
1593 {
1594 wxWindowMac *sibling = (wxWindowMac*)node->Data();
1595 if ( sibling == this )
1596 {
1597 thisWindowThrough = true ;
1598 continue ;
1599 }
1600 if( !thisWindowThrough )
1601 {
1602 continue ;
1603 }
1604
1605 if ( !sibling->IsTopLevel() && sibling->IsShown() )
1606 {
de043984
SC
1607 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 ) ;
1608 DiffRgn( visRgn , tempRgn , visRgn ) ;
94abc21f 1609 }
14c9cbdb 1610 }
94abc21f
SC
1611 }
1612 m_macVisibleRegion = visRgn ;
1613 DisposeRgn( visRgn ) ;
de043984 1614 DisposeRgn( tempRgn ) ;
94abc21f
SC
1615 return m_macVisibleRegion ;
1616}
1617
76a5e5d2 1618void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
519cb848 1619{
76a5e5d2 1620 RgnHandle updatergn = (RgnHandle) updatergnr ;
6264b550 1621 // updatergn is always already clipped to our boundaries
94abc21f 1622 // it is in window coordinates, not in client coordinates
14c9cbdb 1623
76a5e5d2 1624 WindowRef window = (WindowRef) MacGetRootWindow() ;
6264b550
RR
1625
1626 {
94abc21f 1627 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1c310985
SC
1628 RgnHandle ownUpdateRgn = NewRgn() ;
1629 CopyRgn( updatergn , ownUpdateRgn ) ;
14c9cbdb 1630
76a5e5d2 1631 SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
14c9cbdb 1632
94abc21f 1633 // newupdate is the update region in client coordinates
1c310985
SC
1634 RgnHandle newupdate = NewRgn() ;
1635 wxSize point = GetClientSize() ;
1636 wxPoint origin = GetClientAreaOrigin() ;
1c310985
SC
1637 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1638 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1639 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1640 m_updateRegion = newupdate ;
1641 DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
14c9cbdb 1642
e8788ed0 1643 if ( erase && !EmptyRgn(ownUpdateRgn) )
14c9cbdb 1644 {
1c310985 1645 wxWindowDC dc(this);
e8788ed0 1646 dc.SetClippingRegion(wxRegion(ownUpdateRgn));
1c310985
SC
1647 wxEraseEvent eevent( GetId(), &dc );
1648 eevent.SetEventObject( this );
1649 GetEventHandler()->ProcessEvent( eevent );
1650
1651 wxNcPaintEvent eventNc( GetId() );
1652 eventNc.SetEventObject( this );
1653 GetEventHandler()->ProcessEvent( eventNc );
6264b550 1654 }
14c9cbdb 1655 DisposeRgn( ownUpdateRgn ) ;
1c310985 1656 if ( !m_updateRegion.Empty() )
6264b550 1657 {
1c310985
SC
1658 wxPaintEvent event;
1659 event.m_timeStamp = time ;
1660 event.SetEventObject(this);
14c9cbdb
RD
1661 GetEventHandler()->ProcessEvent(event);
1662 }
6264b550 1663 }
14c9cbdb 1664
1c310985 1665 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
14c9cbdb
RD
1666
1667 RgnHandle childupdate = NewRgn() ;
6264b550
RR
1668 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1669 {
94abc21f
SC
1670 // calculate the update region for the child windows by intersecting the window rectangle with our own
1671 // passed in update region and then offset it to be client-wise window coordinates again
6264b550
RR
1672 wxWindowMac *child = (wxWindowMac*)node->Data();
1673 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1674 SectRgn( childupdate , updatergn , childupdate ) ;
1675 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1c310985 1676 if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
6264b550
RR
1677 {
1678 // because dialogs may also be children
1c310985 1679 child->MacRedraw( childupdate , time , erase ) ;
6264b550
RR
1680 }
1681 }
1682 DisposeRgn( childupdate ) ;
1683 // eventually a draw grow box here
14c9cbdb 1684
519cb848
SC
1685}
1686
76a5e5d2 1687WXHWND wxWindowMac::MacGetRootWindow() const
519cb848 1688{
6264b550 1689 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 1690
6264b550
RR
1691 while( iter )
1692 {
1c310985
SC
1693 if ( iter->IsTopLevel() )
1694 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
519cb848 1695
6264b550 1696 iter = iter->GetParent() ;
14c9cbdb 1697 }
6264b550
RR
1698 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1699 return NULL ;
519cb848
SC
1700}
1701
14c9cbdb 1702void wxWindowMac::MacCreateScrollBars( long style )
519cb848 1703{
6264b550 1704 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
14c9cbdb 1705
6264b550
RR
1706 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1707 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1708 int width, height ;
1709 GetClientSize( &width , &height ) ;
14c9cbdb 1710
6264b550
RR
1711 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1712 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1713 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1714 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
14c9cbdb
RD
1715
1716 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
6264b550
RR
1717 vSize , wxVERTICAL);
1718
1719 if ( style & wxVSCROLL )
1720 {
14c9cbdb 1721
6264b550
RR
1722 }
1723 else
1724 {
1725 m_vScrollBar->Show(false) ;
1726 }
14c9cbdb 1727 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
6264b550
RR
1728 hSize , wxHORIZONTAL);
1729 if ( style & wxHSCROLL )
1730 {
1731 }
1732 else
1733 {
1734 m_hScrollBar->Show(false) ;
1735 }
14c9cbdb 1736
6264b550
RR
1737 // because the create does not take into account the client area origin
1738 MacRepositionScrollBars() ; // we might have a real position shift
519cb848
SC
1739}
1740
e766c8a9 1741void wxWindowMac::MacRepositionScrollBars()
519cb848 1742{
6264b550
RR
1743 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1744 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
14c9cbdb 1745
6264b550 1746 // get real client area
14c9cbdb
RD
1747
1748 int width = m_width ;
6264b550
RR
1749 int height = m_height ;
1750
1751 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1752 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
14c9cbdb 1753
6264b550
RR
1754 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1755 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1756 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1757 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
14c9cbdb
RD
1758
1759 int x = 0 ;
6264b550
RR
1760 int y = 0 ;
1761 int w = m_width ;
1762 int h = m_height ;
14c9cbdb 1763
6264b550
RR
1764 MacClientToRootWindow( &x , &y ) ;
1765 MacClientToRootWindow( &w , &h ) ;
14c9cbdb 1766
6264b550 1767 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 1768
6264b550
RR
1769 int totW = 10000 , totH = 10000;
1770 while( iter )
1771 {
1c310985 1772 if ( iter->IsTopLevel() )
6264b550
RR
1773 {
1774 totW = iter->m_width ;
1775 totH = iter->m_height ;
1776 break ;
1777 }
1778
1779 iter = iter->GetParent() ;
14c9cbdb
RD
1780 }
1781
6264b550
RR
1782 if ( x == 0 )
1783 {
1784 hPoint.x = -1 ;
1785 hSize.x += 1 ;
1786 }
1787 if ( y == 0 )
1788 {
1789 vPoint.y = -1 ;
1790 vSize.y += 1 ;
1791 }
14c9cbdb 1792
6264b550
RR
1793 if ( w-x >= totW )
1794 {
1795 hSize.x += 1 ;
1796 vPoint.x += 1 ;
1797 }
14c9cbdb 1798
6264b550
RR
1799 if ( h-y >= totH )
1800 {
1801 vSize.y += 1 ;
1802 hPoint.y += 1 ;
1803 }
1804
1805 if ( m_vScrollBar )
1806 {
1807 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
1808 }
1809 if ( m_hScrollBar )
1810 {
1811 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
1812 }
519cb848
SC
1813}
1814
e766c8a9 1815bool wxWindowMac::AcceptsFocus() const
7c551d95
SC
1816{
1817 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1818}
519cb848 1819
14c9cbdb 1820WXWidget wxWindowMac::MacGetContainerForEmbedding()
519cb848 1821{
1c310985 1822 return GetParent()->MacGetContainerForEmbedding() ;
519cb848
SC
1823}
1824
14c9cbdb 1825void wxWindowMac::MacSuperChangedPosition()
519cb848 1826{
6264b550 1827 // only window-absolute structures have to be moved i.e. controls
519cb848 1828
6264b550
RR
1829 wxNode *node = GetChildren().First();
1830 while ( node )
1831 {
1832 wxWindowMac *child = (wxWindowMac *)node->Data();
1833 child->MacSuperChangedPosition() ;
1834 node = node->Next();
1835 }
519cb848 1836}
519cb848 1837
14c9cbdb 1838void wxWindowMac::MacTopLevelWindowChangedPosition()
a3bf4a62 1839{
6264b550 1840 // only screen-absolute structures have to be moved i.e. glcanvas
a3bf4a62 1841
6264b550
RR
1842 wxNode *node = GetChildren().First();
1843 while ( node )
1844 {
1845 wxWindowMac *child = (wxWindowMac *)node->Data();
1846 child->MacTopLevelWindowChangedPosition() ;
1847 node = node->Next();
1848 }
a3bf4a62 1849}
e766c8a9 1850long wxWindowMac::MacGetLeftBorderSize( ) const
2f1ae414 1851{
1c310985 1852 if( IsTopLevel() )
6264b550 1853 return 0 ;
2f1ae414
SC
1854
1855 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
1856 {
ed60b502 1857 SInt32 border = 3 ;
1c310985 1858#if wxMAC_USE_THEME_BORDER
14c9cbdb 1859#if TARGET_CARBON
ed60b502 1860 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1c310985
SC
1861#endif
1862#endif
ed60b502 1863 return border ;
2f1ae414
SC
1864 }
1865 else if ( m_windowStyle &wxDOUBLE_BORDER)
1866 {
ed60b502 1867 SInt32 border = 3 ;
1c310985 1868#if wxMAC_USE_THEME_BORDER
14c9cbdb 1869#if TARGET_CARBON
ed60b502 1870 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1c310985
SC
1871#endif
1872#endif
ed60b502 1873 return border ;
2f1ae414
SC
1874 }
1875 else if (m_windowStyle &wxSIMPLE_BORDER)
1876 {
6264b550 1877 return 1 ;
2f1ae414 1878 }
6264b550 1879 return 0 ;
2f1ae414
SC
1880}
1881
e766c8a9 1882long wxWindowMac::MacGetRightBorderSize( ) const
5b781a67 1883{
1c310985
SC
1884 // they are all symmetric in mac themes
1885 return MacGetLeftBorderSize() ;
5b781a67
SC
1886}
1887
e766c8a9 1888long wxWindowMac::MacGetTopBorderSize( ) const
5b781a67 1889{
1c310985
SC
1890 // they are all symmetric in mac themes
1891 return MacGetLeftBorderSize() ;
5b781a67
SC
1892}
1893
e766c8a9 1894long wxWindowMac::MacGetBottomBorderSize( ) const
5b781a67 1895{
1c310985
SC
1896 // they are all symmetric in mac themes
1897 return MacGetLeftBorderSize() ;
5b781a67
SC
1898}
1899
14c9cbdb 1900long wxWindowMac::MacRemoveBordersFromStyle( long style )
2f1ae414 1901{
6264b550 1902 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2f1ae414 1903}
0a67a93b 1904
e766c8a9 1905// Find the wxWindowMac at the current mouse position, returning the mouse
3723b7b1 1906// position.
e766c8a9 1907wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 1908{
59a12e90 1909 pt = wxGetMousePosition();
e766c8a9 1910 wxWindowMac* found = wxFindWindowAtPoint(pt);
59a12e90 1911 return found;
3723b7b1
JS
1912}
1913
1914// Get the current mouse position.
1915wxPoint wxGetMousePosition()
1916{
57591e0e
JS
1917 int x, y;
1918 wxGetMousePosition(& x, & y);
1919 return wxPoint(x, y);
3723b7b1
JS
1920}
1921