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