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