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