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