]> git.saurik.com Git - wxWidgets.git/blame - src/mac/window.cpp
Added wxYieldIfNeeded
[wxWidgets.git] / src / mac / window.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: windows.cpp
3// Purpose: wxWindow
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "window.h"
14#endif
15
16#include "wx/setup.h"
17#include "wx/menu.h"
18#include "wx/dc.h"
19#include "wx/dcclient.h"
519cb848 20#include "wx/utils.h"
e9576ca5
SC
21#include "wx/app.h"
22#include "wx/panel.h"
23#include "wx/layout.h"
24#include "wx/dialog.h"
25#include "wx/listbox.h"
03e11df5
GD
26#include "wx/scrolbar.h"
27#include "wx/statbox.h"
e9576ca5
SC
28#include "wx/button.h"
29#include "wx/settings.h"
30#include "wx/msgdlg.h"
31#include "wx/frame.h"
519cb848
SC
32#include "wx/notebook.h"
33#include "wx/tabctrl.h"
2f1ae414 34#include "wx/tooltip.h"
519cb848 35// TODO remove the line below, just for lookup-up convenience CS
03e11df5 36#include "wx/window.h"
e9576ca5
SC
37
38#include "wx/menuitem.h"
39#include "wx/log.h"
40
7c551d95
SC
41#if wxUSE_CARET
42 #include "wx/caret.h"
43#endif // wxUSE_CARET
44
519cb848
SC
45#define wxWINDOW_HSCROLL 5998
46#define wxWINDOW_VSCROLL 5997
47#define MAC_SCROLLBAR_SIZE 16
48
49#include <wx/mac/uma.h>
50
e9576ca5
SC
51#if wxUSE_DRAG_AND_DROP
52#include "wx/dnd.h"
53#endif
54
55#include <string.h>
56
57extern wxList wxPendingDelete;
519cb848 58wxWindow* gFocusWindow = NULL ;
e9576ca5 59
2f1ae414 60#if !USE_SHARED_LIBRARY
e9576ca5 61IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
e9576ca5 62BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
e9576ca5
SC
63 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
64 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
65 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
66 EVT_IDLE(wxWindow::OnIdle)
7c74e7fe 67// EVT_SCROLL(wxWindow::OnScroll)
e9576ca5
SC
68END_EVENT_TABLE()
69
2f1ae414 70#endif
e9576ca5
SC
71
72
e7549107
SC
73
74// ===========================================================================
75// implementation
76// ===========================================================================
77
78// ---------------------------------------------------------------------------
79// wxWindow utility functions
80// ---------------------------------------------------------------------------
81
82// Find an item given the Macintosh Window Reference
83
84wxList *wxWinMacWindowList = NULL;
85wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef)
e9576ca5 86{
e7549107
SC
87 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
88 if (!node)
89 return NULL;
90 return (wxWindow *)node->Data();
519cb848
SC
91}
92
e7549107
SC
93void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win)
94{
95 // adding NULL WindowRef is (first) surely a result of an error and
96 // (secondly) breaks menu command processing
97 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
98
99 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
100 wxWinMacWindowList->Append((long)inWindowRef, win);
101}
102
103void wxRemoveMacWindowAssociation(wxWindow *win)
104{
105 wxWinMacWindowList->DeleteObject(win);
106}
107
108// ----------------------------------------------------------------------------
109// constructors and such
110// ----------------------------------------------------------------------------
111
519cb848
SC
112void wxWindow::Init()
113{
e7549107
SC
114 // generic
115 InitBase();
116
117 // MSW specific
118 m_doubleClickAllowed = 0;
119 m_winCaptured = FALSE;
120
121 m_isBeingDeleted = FALSE;
122
123 m_useCtl3D = FALSE;
124 m_mouseInWindow = FALSE;
125
126 m_xThumbSize = 0;
127 m_yThumbSize = 0;
128 m_backgroundTransparent = FALSE;
129
130 // as all windows are created with WS_VISIBLE style...
131 m_isShown = TRUE;
132
519cb848 133 m_macWindowData = NULL ;
e7549107 134
519cb848
SC
135 m_x = 0;
136 m_y = 0 ;
137 m_width = 0 ;
138 m_height = 0 ;
e7549107 139
519cb848
SC
140 m_hScrollBar = NULL ;
141 m_vScrollBar = NULL ;
e9576ca5
SC
142
143#if wxUSE_DRAG_AND_DROP
519cb848 144 m_pDropTarget = NULL;
e9576ca5
SC
145#endif
146}
147
148// Destructor
149wxWindow::~wxWindow()
150{
e7549107
SC
151 m_isBeingDeleted = TRUE;
152
519cb848
SC
153 if ( s_lastMouseWindow == this )
154 {
155 s_lastMouseWindow = NULL ;
156 }
e7549107
SC
157
158 if ( gFocusWindow == this )
e9576ca5 159 {
e7549107 160 gFocusWindow = NULL ;
e9576ca5 161 }
519cb848 162
e7549107
SC
163 if ( m_parent )
164 m_parent->RemoveChild(this);
e9576ca5
SC
165
166 DestroyChildren();
167
e7549107
SC
168 if ( m_macWindowData )
169 {
2f1ae414 170 wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ;
519cb848
SC
171 UMADisposeWindow( m_macWindowData->m_macWindow ) ;
172 delete m_macWindowData ;
173 wxRemoveMacWindowAssociation( this ) ;
174 }
e9576ca5
SC
175}
176
177// Constructor
178bool wxWindow::Create(wxWindow *parent, wxWindowID id,
179 const wxPoint& pos,
180 const wxSize& size,
181 long style,
182 const wxString& name)
183{
e7549107 184 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
e9576ca5 185
e7549107 186 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
e9576ca5
SC
187 return FALSE;
188
e7549107 189 parent->AddChild(this);
e9576ca5 190
519cb848
SC
191 m_x = (int)pos.x;
192 m_y = (int)pos.y;
e7549107
SC
193 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
194 m_width = WidthDefault( size.x );
195 m_height = HeightDefault( size.y ) ;
519cb848 196
2f1ae414
SC
197 if ( ! IsKindOf( CLASSINFO ( wxControl ) ) )
198 {
199 MacCreateScrollBars( style ) ;
200 }
e9576ca5
SC
201
202 return TRUE;
203}
204
205void wxWindow::SetFocus()
206{
519cb848
SC
207 if ( AcceptsFocus() )
208 {
209 if (gFocusWindow )
210 {
7c551d95
SC
211 #if wxUSE_CARET
212 // Deal with caret
213 if ( gFocusWindow->m_caret )
214 {
215 gFocusWindow->m_caret->OnKillFocus();
216 }
217 #endif // wxUSE_CARET
519cb848
SC
218 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
219 if ( control && control->GetMacControl() )
220 {
221 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
2f1ae414 222 control->MacRedrawControl() ;
519cb848 223 }
7c551d95
SC
224 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
225 event.SetEventObject(gFocusWindow);
519cb848
SC
226 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
227 }
228 gFocusWindow = this ;
229 {
7c551d95
SC
230 #if wxUSE_CARET
231 // Deal with caret
232 if ( m_caret )
233 {
234 m_caret->OnSetFocus();
235 }
236 #endif // wxUSE_CARET
237 // panel wants to track the window which was the last to have focus in it
238 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
239 if ( panel )
240 {
241 panel->SetLastFocus(this);
242 }
519cb848
SC
243 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
244 if ( control && control->GetMacControl() )
245 {
246 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
247 }
248
7c551d95
SC
249 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
250 event.SetEventObject(this);
519cb848
SC
251 GetEventHandler()->ProcessEvent(event) ;
252 }
253 }
e9576ca5
SC
254}
255
e7549107 256bool wxWindow::Enable(bool enable)
e9576ca5 257{
e7549107
SC
258 if ( !wxWindowBase::Enable(enable) )
259 return FALSE;
e7549107
SC
260
261 wxWindowList::Node *node = GetChildren().GetFirst();
262 while ( node )
263 {
264 wxWindow *child = node->GetData();
265 child->Enable(enable);
266
267 node = node->GetNext();
268 }
269
270 return TRUE;
e9576ca5
SC
271}
272
273void wxWindow::CaptureMouse()
274{
519cb848 275 wxTheApp->s_captureWindow = this ;
e9576ca5
SC
276}
277
278void wxWindow::ReleaseMouse()
279{
519cb848 280 wxTheApp->s_captureWindow = NULL ;
e9576ca5
SC
281}
282
e9576ca5
SC
283#if wxUSE_DRAG_AND_DROP
284
285void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
286{
287 if ( m_pDropTarget != 0 ) {
288 delete m_pDropTarget;
289 }
290
291 m_pDropTarget = pDropTarget;
292 if ( m_pDropTarget != 0 )
293 {
294 // TODO
295 }
296}
297
298#endif
299
300// Old style file-manager drag&drop
301void wxWindow::DragAcceptFiles(bool accept)
302{
303 // TODO
304}
305
306// Get total size
e7549107 307void wxWindow::DoGetSize(int *x, int *y) const
e9576ca5 308{
519cb848
SC
309 *x = m_width ;
310 *y = m_height ;
e9576ca5
SC
311}
312
e7549107 313void wxWindow::DoGetPosition(int *x, int *y) const
e9576ca5 314{
519cb848
SC
315 *x = m_x ;
316 *y = m_y ;
317 if (GetParent())
318 {
319 wxPoint pt(GetParent()->GetClientAreaOrigin());
320 *x -= pt.x;
321 *y -= pt.y;
322 }
e9576ca5
SC
323}
324
51abe921 325
51abe921
SC
326bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
327{
328 menu->SetInvokingWindow(this);
329 menu->UpdateUI();
330 ClientToScreen( &x , &y ) ;
331
332 ::InsertMenu( menu->GetHMenu() , -1 ) ;
333 long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
334 menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
335 ::DeleteMenu( menu->MacGetMenuId() ) ;
336 menu->SetInvokingWindow(NULL);
337
338 return TRUE;
339}
340
e7549107 341void wxWindow::DoScreenToClient(int *x, int *y) const
e9576ca5 342{
519cb848
SC
343 WindowRef window = GetMacRootWindow() ;
344
345 Point localwhere ;
346 localwhere.h = * x ;
347 localwhere.v = * y ;
348
349 GrafPtr port ;
350 ::GetPort( &port ) ;
351 ::SetPort( UMAGetWindowPort( window ) ) ;
352 ::GlobalToLocal( &localwhere ) ;
353 ::SetPort( port ) ;
354
355 *x = localwhere.h ;
356 *y = localwhere.v ;
357
358 MacRootWindowToClient( x , y ) ;
e9576ca5
SC
359}
360
e7549107 361void wxWindow::DoClientToScreen(int *x, int *y) const
e9576ca5 362{
519cb848
SC
363 WindowRef window = GetMacRootWindow() ;
364
365 MacClientToRootWindow( x , y ) ;
366
367 Point localwhere ;
368 localwhere.h = * x ;
369 localwhere.v = * y ;
370
371 GrafPtr port ;
372 ::GetPort( &port ) ;
373 ::SetPort( UMAGetWindowPort( window ) ) ;
2f1ae414 374 ::SetOrigin( 0 , 0 ) ;
519cb848
SC
375 ::LocalToGlobal( &localwhere ) ;
376 ::SetPort( port ) ;
377 *x = localwhere.h ;
378 *y = localwhere.v ;
379}
380
381void wxWindow::MacClientToRootWindow( int *x , int *y ) const
382{
383 if ( m_macWindowData )
384 {
385 }
386 else
387 {
388 *x += m_x ;
389 *y += m_y ;
390 GetParent()->MacClientToRootWindow( x , y ) ;
391 }
392}
393
394void wxWindow::MacRootWindowToClient( int *x , int *y ) const
395{
396 if ( m_macWindowData )
397 {
398 }
399 else
400 {
401 *x -= m_x ;
402 *y -= m_y ;
403 GetParent()->MacRootWindowToClient( x , y ) ;
404 }
e9576ca5
SC
405}
406
e7549107 407bool wxWindow::SetCursor(const wxCursor& cursor)
e9576ca5 408{
e7549107
SC
409 if ( !wxWindowBase::SetCursor(cursor) )
410 {
411 // no change
412 return FALSE;
413 }
414
415 wxASSERT_MSG( m_cursor.Ok(),
416 wxT("cursor must be valid after call to the base version"));
417
418 Point pt ;
419 wxWindow *mouseWin ;
420 GetMouse( &pt ) ;
421
422 // Change the cursor NOW if we're within the correct window
423
424 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
e9576ca5 425 {
e7549107
SC
426 if ( mouseWin == this && !wxIsBusy() )
427 {
428 cursor.MacInstall() ;
429 }
e9576ca5 430 }
e7549107
SC
431
432 return TRUE ;
e9576ca5
SC
433}
434
435
436// Get size *available for subwindows* i.e. excluding menu bar etc.
e7549107 437void wxWindow::DoGetClientSize(int *x, int *y) const
e9576ca5 438{
519cb848
SC
439 *x = m_width ;
440 *y = m_height ;
441
5b781a67
SC
442 *x -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
443 *y -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
2f1ae414
SC
444
445 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
446 {
447 int x1 = 0 ;
448 int y1 = 0 ;
449 int w = m_width ;
450 int h = m_height ;
451
452 MacClientToRootWindow( &x1 , &y1 ) ;
453 MacClientToRootWindow( &w , &h ) ;
454
455 WindowRef window = NULL ;
456 wxWindow *iter = (wxWindow*)this ;
457
458 int totW = 10000 , totH = 10000;
459 while( iter )
460 {
461 if ( iter->m_macWindowData )
462 {
463 totW = iter->m_width ;
464 totH = iter->m_height ;
465 break ;
466 }
467
468 iter = iter->GetParent() ;
469 }
470
471 if (m_hScrollBar && m_hScrollBar->IsShown() )
472 {
473 (*y) -= MAC_SCROLLBAR_SIZE;
474 if ( h-y1 >= totH )
475 {
476 (*y)+= 1 ;
477 }
478 }
479 if (m_vScrollBar && m_vScrollBar->IsShown() )
480 {
481 (*x) -= MAC_SCROLLBAR_SIZE;
482 if ( w-x1 >= totW )
483 {
484 (*x) += 1 ;
485 }
486 }
487 }
519cb848
SC
488}
489
51abe921
SC
490
491// ----------------------------------------------------------------------------
492// tooltips
493// ----------------------------------------------------------------------------
494
495#if wxUSE_TOOLTIPS
496
497void wxWindow::DoSetToolTip(wxToolTip *tooltip)
498{
499 wxWindowBase::DoSetToolTip(tooltip);
500
2f1ae414
SC
501 if ( m_tooltip )
502 m_tooltip->SetWindow(this);
51abe921
SC
503}
504
505#endif // wxUSE_TOOLTIPS
506
507void wxWindow::DoMoveWindow(int x, int y, int width, int height)
508{
509 DoSetSize( x,y, width, height ) ;
510}
511
519cb848
SC
512void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
513{
2f1ae414 514
519cb848
SC
515 int former_x = m_x ;
516 int former_y = m_y ;
517 int former_w = m_width ;
518 int former_h = m_height ;
519
520 int currentX, currentY;
521 GetPosition(&currentX, &currentY);
522 int currentW,currentH;
523 GetSize(&currentW, &currentH);
524
525 int actualWidth = width;
526 int actualHeight = height;
527 int actualX = x;
528 int actualY = y;
2f1ae414 529 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848 530 actualX = currentX;
2f1ae414 531 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848
SC
532 actualY = currentY;
533 if (width == -1)
534 actualWidth = currentW ;
535 if (height == -1)
536 actualHeight = currentH ;
537
538 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
539 {
540 MacRepositionScrollBars() ; // we might have a real position shift
541 return ;
542 }
e9576ca5 543
519cb848
SC
544 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
545
546
547 bool doMove = false ;
548 bool doResize = false ;
549
550 if ( actualX != former_x || actualY != former_y )
551 {
552 doMove = true ;
553 }
554 if ( actualWidth != former_w || actualHeight != former_h )
555 {
556 doResize = true ;
557 }
e9576ca5 558
519cb848
SC
559 if ( doMove || doResize )
560 {
561 if ( m_macWindowData )
562 {
563 }
564 else
565 {
566 // erase former position
567 {
568 wxMacDrawingClientHelper focus( this ) ;
569 if ( focus.Ok() )
570 {
571 Rect clientrect = { 0 , 0 , m_height , m_width } ;
2f1ae414 572 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
519cb848
SC
573 }
574 }
575 }
576 m_x = actualX ;
577 m_y = actualY ;
578 m_width = actualWidth ;
579 m_height = actualHeight ;
580 if ( m_macWindowData )
581 {
582 if ( doMove )
2f1ae414 583 ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost
519cb848
SC
584
585 if ( doResize )
2f1ae414 586 ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true);
519cb848
SC
587
588 // the OS takes care of invalidating and erasing
589
590 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
591 {
592 wxFrame* frame = (wxFrame*) this ;
2f1ae414
SC
593 frame->PositionStatusBar();
594 frame->PositionToolBar();
519cb848
SC
595 }
596 }
597 else
598 {
599 // erase new position
600 {
601 wxMacDrawingClientHelper focus( this ) ;
602 if ( focus.Ok() )
603 {
2f1ae414
SC
604 Rect clientrect = { 0 , 0 , m_height , m_width } ;
605 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
519cb848
SC
606 }
607 }
608 if ( doMove )
609 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
610 }
611 MacRepositionScrollBars() ;
612 if ( doMove )
613 {
2f1ae414
SC
614 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
615 event.SetEventObject(this);
616 GetEventHandler()->ProcessEvent(event) ;
617 }
618 if ( doResize )
619 {
519cb848 620 MacRepositionScrollBars() ;
2f1ae414
SC
621 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
622 event.SetEventObject(this);
623 GetEventHandler()->ProcessEvent(event);
624 }
519cb848 625 }
e9576ca5 626}
e9576ca5
SC
627// For implementation purposes - sometimes decorations make the client area
628// smaller
519cb848 629
e9576ca5
SC
630wxPoint wxWindow::GetClientAreaOrigin() const
631{
5b781a67 632 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
e9576ca5
SC
633}
634
635// Makes an adjustment to the window position (for example, a frame that has
636// a toolbar that it manages itself).
637void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
638{
519cb848
SC
639 if( !m_macWindowData )
640 {
e9576ca5
SC
641 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
642 {
643 wxPoint pt(GetParent()->GetClientAreaOrigin());
644 x += pt.x; y += pt.y;
645 }
519cb848
SC
646 }
647}
648
649void wxWindow::SetTitle(const wxString& title)
650{
e7549107
SC
651 m_label = title ;
652
519cb848
SC
653 wxString label ;
654
655 if( wxApp::s_macDefaultEncodingIsPC )
656 label = wxMacMakeMacStringFromPC( title ) ;
657 else
658 label = title ;
659
660 if ( m_macWindowData )
661 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
662}
663
664wxString wxWindow::GetTitle() const
665{
e7549107 666 return m_label ;
519cb848
SC
667}
668
e9576ca5
SC
669bool wxWindow::Show(bool show)
670{
e7549107
SC
671 if ( !wxWindowBase::Show(show) )
672 return FALSE;
673
519cb848
SC
674 if ( m_macWindowData )
675 {
676 if (show)
677 {
678 UMAShowWindow( m_macWindowData->m_macWindow ) ;
679 UMASelectWindow( m_macWindowData->m_macWindow ) ;
2f1ae414
SC
680 // no need to generate events here, they will get them triggered by macos
681 // actually they should be , but apparently they are not
519cb848
SC
682 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
683 event.SetEventObject(this);
684 GetEventHandler()->ProcessEvent(event);
685 }
686 else
687 {
688 UMAHideWindow( m_macWindowData->m_macWindow ) ;
689 }
690 }
8208e181 691 MacSuperShown( show ) ;
519cb848 692 Refresh() ;
2f1ae414
SC
693 if(m_macWindowData)
694 MacUpdateImmediately() ;
e9576ca5 695
e7549107 696 return TRUE;
e9576ca5
SC
697}
698
8208e181
SC
699void wxWindow::MacSuperShown( bool show )
700{
701 wxNode *node = GetChildren().First();
702 while ( node )
703 {
704 wxWindow *child = (wxWindow *)node->Data();
705 if ( child->m_isShown )
706 child->MacSuperShown( show ) ;
707 node = node->Next();
708 }
709}
710
e9576ca5
SC
711int wxWindow::GetCharHeight() const
712{
519cb848
SC
713 wxClientDC dc ( (wxWindow*)this ) ;
714 return dc.GetCharHeight() ;
e9576ca5
SC
715}
716
717int wxWindow::GetCharWidth() const
718{
519cb848
SC
719 wxClientDC dc ( (wxWindow*)this ) ;
720 return dc.GetCharWidth() ;
e9576ca5
SC
721}
722
723void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 724 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 725{
e7549107
SC
726 const wxFont *fontToUse = theFont;
727 if ( !fontToUse )
728 fontToUse = &m_font;
7c74e7fe 729
5b781a67 730 wxClientDC dc( (wxWindow*) this ) ;
7c74e7fe
SC
731 long lx,ly,ld,le ;
732 dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ;
2f1ae414
SC
733 if ( externalLeading )
734 *externalLeading = le ;
735 if ( descent )
736 *descent = ld ;
737 if ( x )
738 *x = lx ;
739 if ( y )
740 *y = ly ;
e9576ca5
SC
741}
742
519cb848
SC
743void wxWindow::MacEraseBackground( Rect *rect )
744{
745 WindowRef window = GetMacRootWindow() ;
746 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
747 {
748 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
749 }
750 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
751 {
752 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
753 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
754 // either a non gray background color or a non control window
755
756 wxWindow* parent = GetParent() ;
757 while( parent )
758 {
759 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
760 {
761 // if we have any other colours in the hierarchy
762 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
763 break ;
764 }
765 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
766 {
767 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
768 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
769 {
2f1ae414 770 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
519cb848
SC
771 break ;
772 }
773 }
774 else
775 {
776 // we have arrived at a non control item
777 parent = NULL ;
778 break ;
779 }
780 parent = parent->GetParent() ;
781 }
782 if ( !parent )
783 {
784 // if there is nothing special -> use default
785 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
786 }
787 }
788 else
789 {
790 RGBBackColor( &m_backgroundColour.GetPixel()) ;
791 }
792
793 EraseRect( rect ) ;
794
e7549107 795 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848
SC
796 {
797 wxWindow *child = (wxWindow*)node->Data();
519cb848
SC
798
799 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
800 SectRect( &clientrect , rect , &clientrect ) ;
801
802 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
e7549107 803 if ( child->GetMacRootWindow() == window && child->IsShown() )
519cb848
SC
804 {
805 wxMacDrawingClientHelper focus( this ) ;
806 if ( focus.Ok() )
807 {
808 child->MacEraseBackground( &clientrect ) ;
809 }
810 }
811 }
812}
813
e9576ca5
SC
814void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
815{
2f1ae414 816 wxMacDrawingHelper focus( this ) ;
519cb848
SC
817 if ( focus.Ok() )
818 {
2f1ae414
SC
819 Rect clientrect = { 0 , 0 , m_height , m_width } ;
820 ClipRect( &clientrect ) ;
519cb848 821
2f1ae414
SC
822 if ( rect )
823 {
824 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
519cb848 825 SectRect( &clientrect , &r , &clientrect ) ;
2f1ae414
SC
826 }
827 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
519cb848 828 }
e9576ca5
SC
829}
830
831// Responds to colour changes: passes event on to children.
832void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
833{
834 wxNode *node = GetChildren().First();
835 while ( node )
836 {
837 // Only propagate to non-top-level windows
838 wxWindow *win = (wxWindow *)node->Data();
839 if ( win->GetParent() )
840 {
841 wxSysColourChangedEvent event2;
842 event.m_eventObject = win;
843 win->GetEventHandler()->ProcessEvent(event2);
844 }
845
846 node = node->Next();
847 }
848}
849
e7549107
SC
850#if wxUSE_CARET && WXWIN_COMPATIBILITY
851// ---------------------------------------------------------------------------
e9576ca5 852// Caret manipulation
e7549107
SC
853// ---------------------------------------------------------------------------
854
e9576ca5
SC
855void wxWindow::CreateCaret(int w, int h)
856{
e7549107 857 SetCaret(new wxCaret(this, w, h));
e9576ca5
SC
858}
859
860void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
861{
e7549107 862 wxFAIL_MSG("not implemented");
e9576ca5
SC
863}
864
865void wxWindow::ShowCaret(bool show)
866{
e7549107
SC
867 wxCHECK_RET( m_caret, "no caret to show" );
868
869 m_caret->Show(show);
e9576ca5
SC
870}
871
872void wxWindow::DestroyCaret()
873{
e7549107 874 SetCaret(NULL);
e9576ca5
SC
875}
876
877void wxWindow::SetCaretPos(int x, int y)
878{
e7549107
SC
879 wxCHECK_RET( m_caret, "no caret to move" );
880
881 m_caret->Move(x, y);
e9576ca5
SC
882}
883
884void wxWindow::GetCaretPos(int *x, int *y) const
885{
e7549107
SC
886 wxCHECK_RET( m_caret, "no caret to get position of" );
887
888 m_caret->GetPosition(x, y);
e9576ca5 889}
e7549107 890#endif // wxUSE_CARET
e9576ca5
SC
891
892wxWindow *wxGetActiveWindow()
893{
519cb848 894 // actually this is a windows-only concept
e9576ca5
SC
895 return NULL;
896}
897
e9576ca5
SC
898// Coordinates relative to the window
899void wxWindow::WarpPointer (int x_pos, int y_pos)
900{
519cb848 901 // We really dont move the mouse programmatically under mac
e9576ca5
SC
902}
903
904void wxWindow::OnEraseBackground(wxEraseEvent& event)
905{
519cb848 906 // TODO : probably we would adopt the EraseEvent structure
e9576ca5
SC
907}
908
909int wxWindow::GetScrollPos(int orient) const
910{
519cb848
SC
911 if ( orient == wxHORIZONTAL )
912 {
913 if ( m_hScrollBar )
914 return m_hScrollBar->GetThumbPosition() ;
915 }
916 else
917 {
918 if ( m_vScrollBar )
919 return m_vScrollBar->GetThumbPosition() ;
920 }
e9576ca5
SC
921 return 0;
922}
923
924// This now returns the whole range, not just the number
925// of positions that we can scroll.
926int wxWindow::GetScrollRange(int orient) const
927{
519cb848
SC
928 if ( orient == wxHORIZONTAL )
929 {
930 if ( m_hScrollBar )
931 return m_hScrollBar->GetRange() ;
932 }
933 else
934 {
935 if ( m_vScrollBar )
936 return m_vScrollBar->GetRange() ;
937 }
e9576ca5
SC
938 return 0;
939}
940
941int wxWindow::GetScrollThumb(int orient) const
942{
519cb848
SC
943 if ( orient == wxHORIZONTAL )
944 {
945 if ( m_hScrollBar )
946 return m_hScrollBar->GetThumbSize() ;
947 }
948 else
949 {
950 if ( m_vScrollBar )
951 return m_vScrollBar->GetThumbSize() ;
952 }
e9576ca5
SC
953 return 0;
954}
955
956void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
957{
519cb848
SC
958 if ( orient == wxHORIZONTAL )
959 {
960 if ( m_hScrollBar )
961 m_hScrollBar->SetThumbPosition( pos ) ;
962 }
963 else
964 {
965 if ( m_vScrollBar )
966 m_vScrollBar->SetThumbPosition( pos ) ;
967 }
e9576ca5
SC
968}
969
2f1ae414
SC
970void wxWindow::MacCreateRealWindow( const wxString& title,
971 const wxPoint& pos,
972 const wxSize& size,
973 long style,
974 const wxString& name )
8208e181 975{
2f1ae414
SC
976 SetName(name);
977 m_windowStyle = style;
978 m_isShown = FALSE;
8208e181 979
2f1ae414 980 // create frame.
8208e181 981
2f1ae414
SC
982 Rect theBoundsRect;
983
984 m_x = (int)pos.x;
985 m_y = (int)pos.y;
986 if ( m_y < 50 )
987 m_y = 50 ;
988 if ( m_x < 20 )
989 m_x = 20 ;
990
991 m_width = size.x;
992 if (m_width == -1)
993 m_width = 20;
994 m_height = size.y;
995 if (m_height == -1)
996 m_height = 20;
997
998 m_macWindowData = new MacWindowData() ;
999
1000 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
1001
1002 // translate the window attributes in the appropriate window class and attributes
1003
03e11df5
GD
1004 WindowClass wclass = 0;
1005 WindowAttributes attr = kWindowNoAttributes ;
8208e181 1006
2f1ae414
SC
1007 if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) )
1008 {
1009 wclass = kFloatingWindowClass ;
1010 if ( HasFlag(wxTINY_CAPTION_VERT) )
1011 {
1012 attr |= kWindowSideTitlebarAttribute ;
1013 }
1014 }
1015 else if ( HasFlag( wxTHICK_FRAME ) )
1016 {
1017 if ( HasFlag( wxDIALOG_MODAL ) )
1018 {
1019 wclass = kMovableModalWindowClass ;
1020 }
1021 else if ( HasFlag( wxDIALOG_MODELESS ) )
1022 {
1023 wclass = kDocumentWindowClass ;
1024 }
1025 else
1026 {
1027 if ( HasFlag( wxCAPTION ) )
1028 {
1029 wclass = kDocumentWindowClass ;
1030 }
1031 else
1032 {
1033 wclass = kModalWindowClass ;
1034 }
1035 }
1036 }
1037 else
1038 {
1039 wclass = kModalWindowClass ;
1040 }
8208e181 1041
2f1ae414
SC
1042 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
1043 {
1044 attr |= kWindowFullZoomAttribute ;
1045 attr |= kWindowCollapseBoxAttribute ;
1046 }
1047 if ( HasFlag( wxRESIZE_BORDER ) )
1048 {
1049 attr |= kWindowResizableAttribute ;
1050 }
1051 if ( HasFlag( wxSYSTEM_MENU ) )
1052 {
1053 attr |= kWindowCloseBoxAttribute ;
1054 }
8208e181 1055
2f1ae414
SC
1056 UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ;
1057 wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ;
1058 wxString label ;
1059 if( wxApp::s_macDefaultEncodingIsPC )
1060 label = wxMacMakeMacStringFromPC( title ) ;
1061 else
1062 label = title ;
1063 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
1064 UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
1065
1066 m_macWindowData->m_macFocus = NULL ;
1067}
1068
1069void wxWindow::MacPaint( wxPaintEvent &event )
1070{
1071}
1072
1073void wxWindow::MacPaintBorders( )
1074{
1075 if( m_macWindowData )
1076 return ;
1077
1078 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1079 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1080 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1081 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1082 PenNormal() ;
1083
1084 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1085 {
1086 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1087 RGBColor pen1 = sunken ? white : black ;
1088 RGBColor pen2 = sunken ? shadow : face ;
1089 RGBColor pen3 = sunken ? face : shadow ;
1090 RGBColor pen4 = sunken ? black : white ;
1091
1092 RGBForeColor( &pen1 ) ;
1093 {
1094 Rect rect = { 0 , 0 , m_height , m_width } ;
1095 FrameRect( &rect ) ;
1096 }
1097 RGBForeColor( &pen2 ) ;
1098 {
1099 Rect rect = { 1 , 1 , m_height -1 , m_width -1} ;
1100 FrameRect( &rect ) ;
1101 }
1102 RGBForeColor( &pen3 ) ;
1103 {
1104 Rect rect = { 0 , 0 , m_height -2 , m_width -2} ;
1105 FrameRect( &rect ) ;
1106 }
1107 RGBForeColor( &pen4 ) ;
1108 {
1109 MoveTo( 0 , 0 ) ;
1110 LineTo( m_width - 3 , 0 ) ;
1111 MoveTo( 0 , 0 ) ;
1112 LineTo( 0 , m_height - 3 ) ;
1113 }
8208e181
SC
1114 }
1115 else if (HasFlag(wxSIMPLE_BORDER))
1116 {
2f1ae414
SC
1117 Rect rect = { 0 , 0 , m_height , m_width } ;
1118 RGBForeColor( &black ) ;
1119 FrameRect( &rect ) ;
1120 }
1121/*
1122 if ( this->GetParent() )
1123 {
1124 wxPaintDC dc(GetParent());
1125 GetParent()->PrepareDC(dc);
1126
1127 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1128 {
1129 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1130
1131 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1132 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1133
1134 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1135 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1136 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1137 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1138
1139 dc.SetPen(wxPen1);
1140 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1141
1142 dc.SetPen(wxPen2);
1143 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1144
1145 dc.SetPen(wxPen3);
1146 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1147
1148 dc.SetPen(wxPen4);
1149 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1150 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1151 }
1152 else if (HasFlag(wxDOUBLE_BORDER))
1153 {
1154 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1155
1156 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1157 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1158
1159 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1160 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1161 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1162 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1163
1164 dc.SetPen(wxPen1);
1165 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1166
1167 dc.SetPen(wxPen2);
1168 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1169
1170 dc.SetPen(wxPen3);
1171 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1172
1173 dc.SetPen(wxPen4);
1174 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1175 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1176 }
1177 else if (HasFlag(wxSIMPLE_BORDER))
1178 {
1179 dc.SetPen(*wxBLACK_PEN);
1180 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1181 }
8208e181 1182 }
2f1ae414 1183 */
8208e181
SC
1184}
1185
e9576ca5
SC
1186// New function that will replace some of the above.
1187void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
1188 int range, bool refresh)
1189{
519cb848
SC
1190 if ( orient == wxHORIZONTAL )
1191 {
1192 if ( m_hScrollBar )
1193 {
1194 if ( range == 0 || thumbVisible >= range )
1195 {
1196 if ( m_hScrollBar->IsShown() )
1197 m_hScrollBar->Show(false) ;
1198 }
1199 else
1200 {
1201 if ( !m_hScrollBar->IsShown() )
1202 m_hScrollBar->Show(true) ;
1203 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
1204 }
1205 }
1206 }
1207 else
1208 {
1209 if ( m_vScrollBar )
1210 {
1211 if ( range == 0 || thumbVisible >= range )
1212 {
1213 if ( m_vScrollBar->IsShown() )
1214 m_vScrollBar->Show(false) ;
1215 }
1216 else
1217 {
1218 if ( !m_vScrollBar->IsShown() )
1219 m_vScrollBar->Show(true) ;
1220 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
1221 }
1222 }
1223 }
1224 MacRepositionScrollBars() ;
e9576ca5
SC
1225}
1226
1227// Does a physical scroll
1228void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1229{
519cb848
SC
1230 wxMacDrawingClientHelper focus( this ) ;
1231 if ( focus.Ok() )
1232 {
2f1ae414
SC
1233 int width , height ;
1234 GetClientSize( &width , &height ) ;
1235
1236 Rect scrollrect = { 0 , 0 , height , width } ;
519cb848 1237
2f1ae414
SC
1238 RgnHandle updateRgn = NewRgn() ;
1239 ClipRect( &scrollrect ) ;
1240 if ( rect )
1241 {
1242 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
519cb848 1243 SectRect( &scrollrect , &r , &scrollrect ) ;
2f1ae414
SC
1244 }
1245 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1246 InvalWindowRgn( GetMacRootWindow() , updateRgn ) ;
1247 DisposeRgn( updateRgn ) ;
519cb848 1248 }
d467e0c7
RR
1249
1250 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1251 {
1252 wxWindow *child = (wxWindow*)node->Data();
1253 if (child == m_vScrollBar) continue;
1254 if (child == m_hScrollBar) continue;
1255 if (child->IsTopLevel()) continue;
1256 int x,y;
1257 child->GetPosition( &x, &y );
1258 int w,h;
1259 child->GetSize( &w, &h );
1260 child->SetSize( x+dx, y+dy, w, h );
1261 }
1262
e9576ca5
SC
1263}
1264
7c74e7fe
SC
1265void wxWindow::MacOnScroll(wxScrollEvent &event )
1266{
1267 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1268 {
1269 wxScrollWinEvent wevent;
1270 wevent.SetPosition(event.GetPosition());
1271 wevent.SetOrientation(event.GetOrientation());
1272 wevent.m_eventObject = this;
1273
3b700390 1274 if (event.m_eventType == wxEVT_SCROLL_TOP) {
7c74e7fe 1275 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
3b700390
GD
1276 } else
1277 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
7c74e7fe 1278 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
3b700390
GD
1279 } else
1280 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
7c74e7fe 1281 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3b700390
GD
1282 } else
1283 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
7c74e7fe 1284 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3b700390
GD
1285 } else
1286 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
7c74e7fe 1287 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3b700390
GD
1288 } else
1289 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
7c74e7fe 1290 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3b700390
GD
1291 } else
1292 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
7c74e7fe 1293 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
7c74e7fe
SC
1294 }
1295
1296 GetEventHandler()->ProcessEvent(wevent);
1297 }
1298}
1299
e7549107 1300bool wxWindow::SetFont(const wxFont& font)
e9576ca5 1301{
e7549107
SC
1302 if ( !wxWindowBase::SetFont(font) )
1303 {
1304 // nothing to do
1305 return FALSE;
e9576ca5 1306 }
e9576ca5 1307
e7549107 1308 return TRUE;
e9576ca5
SC
1309}
1310
1311// Get the window with the focus
e7549107 1312wxWindow *wxWindowBase::FindFocus()
e9576ca5 1313{
519cb848
SC
1314 return gFocusWindow ;
1315}
1316
e7549107 1317#if WXWIN_COMPATIBILITY
e9576ca5
SC
1318// If nothing defined for this, try the parent.
1319// E.g. we may be a button loaded from a resource, with no callback function
1320// defined.
1321void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1322{
e7549107
SC
1323 if ( GetEventHandler()->ProcessEvent(event) )
1324 return;
1325 if ( m_parent )
1326 m_parent->GetEventHandler()->OnCommand(win, event);
e9576ca5 1327}
e7549107 1328#endif // WXWIN_COMPATIBILITY_2
e9576ca5 1329
e7549107
SC
1330#if WXWIN_COMPATIBILITY
1331wxObject* wxWindow::GetChild(int number) const
e9576ca5 1332{
e7549107
SC
1333 // Return a pointer to the Nth object in the Panel
1334 wxNode *node = GetChildren().First();
1335 int n = number;
1336 while (node && n--)
1337 node = node->Next();
1338 if ( node )
519cb848 1339 {
e7549107
SC
1340 wxObject *obj = (wxObject *)node->Data();
1341 return(obj);
519cb848
SC
1342 }
1343 else
e7549107 1344 return NULL;
e9576ca5 1345}
e7549107 1346#endif // WXWIN_COMPATIBILITY
e9576ca5
SC
1347
1348void wxWindow::Clear()
1349{
519cb848
SC
1350 if ( m_macWindowData )
1351 {
1352 wxMacDrawingClientHelper helper ( this ) ;
1353 int w ,h ;
1354 wxPoint origin = GetClientAreaOrigin() ;
1355 GetClientSize( &w , &h ) ;
1356 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1357 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
1358 EraseRect( &r ) ;
1359 }
1360 else
1361 {
1362 wxClientDC dc(this);
2f1ae414
SC
1363 wxBrush brush(GetBackgroundColour(), wxSOLID);
1364 dc.SetBackground(brush);
1365 dc.Clear();
519cb848 1366 }
e9576ca5
SC
1367}
1368
e7549107
SC
1369// Setup background and foreground colours correctly
1370void wxWindow::SetupColours()
e9576ca5 1371{
e7549107
SC
1372 if ( GetParent() )
1373 SetBackgroundColour(GetParent()->GetBackgroundColour());
e9576ca5
SC
1374}
1375
1376void wxWindow::OnIdle(wxIdleEvent& event)
1377{
519cb848
SC
1378/*
1379 // Check if we need to send a LEAVE event
1380 if (m_mouseInWindow)
1381 {
1382 POINT pt;
1383 ::GetCursorPos(&pt);
1384 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1385 {
1386 // Generate a LEAVE event
1387 m_mouseInWindow = FALSE;
1388 MSWOnMouseLeave(pt.x, pt.y, 0);
1389 }
e9576ca5
SC
1390 }
1391*/
1392
1393 // This calls the UI-update mechanism (querying windows for
1394 // menu/toolbar/control state information)
1395 UpdateWindowUI();
1396}
1397
1398// Raise the window to the top of the Z order
1399void wxWindow::Raise()
1400{
1401 // TODO
1402}
1403
1404// Lower the window to the bottom of the Z order
1405void wxWindow::Lower()
1406{
1407 // TODO
1408}
1409
519cb848
SC
1410void wxWindow::DoSetClientSize(int width, int height)
1411{
1412 if ( width != -1 || height != -1 )
1413 {
1414
1415 if ( width != -1 && m_vScrollBar )
1416 width += MAC_SCROLLBAR_SIZE ;
1417 if ( height != -1 && m_vScrollBar )
1418 height += MAC_SCROLLBAR_SIZE ;
1419
5b781a67
SC
1420 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1421 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
2f1ae414 1422
519cb848
SC
1423 DoSetSize( -1 , -1 , width , height ) ;
1424 }
1425}
1426
519cb848
SC
1427
1428wxWindow* wxWindow::s_lastMouseWindow = NULL ;
1429
1430bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin )
1431{
1432 if ((point.x < m_x) || (point.y < m_y) ||
1433 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1434 return FALSE;
1435
1436 WindowRef window = GetMacRootWindow() ;
1437
1438 wxPoint newPoint( point ) ;
1439
1440 newPoint.x -= m_x;
1441 newPoint.y -= m_y;
1442
e7549107 1443 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848 1444 {
e7549107 1445 wxWindow *child = (wxWindow*)node->Data();
5b781a67
SC
1446 // added the m_isShown test --dmazzoni
1447 if ( child->GetMacRootWindow() == window && child->m_isShown )
519cb848 1448 {
e7549107
SC
1449 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1450 return TRUE;
519cb848
SC
1451 }
1452 }
1453
1454 *outWin = this ;
1455 return TRUE;
1456}
1457
1458bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin )
1459{
1460 WindowRef window ;
1461 Point pt = { screenpoint.y , screenpoint.x } ;
1462 if ( ::FindWindow( pt , &window ) == 3 )
1463 {
1464 wxPoint point( screenpoint ) ;
1465 wxWindow* win = wxFindWinFromMacWindow( window ) ;
5b781a67
SC
1466 if ( win )
1467 {
519cb848
SC
1468 win->ScreenToClient( point ) ;
1469 return win->MacGetWindowFromPointSub( point , outWin ) ;
1470 }
5b781a67 1471 }
519cb848
SC
1472 return FALSE ;
1473}
1474
1475extern int wxBusyCursorCount ;
1476
1477bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
1478{
1479 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1480 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1481 return FALSE;
1482
2f1ae414 1483
519cb848
SC
1484 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1485 return FALSE ;
1486
1487 WindowRef window = GetMacRootWindow() ;
1488
1489 event.m_x -= m_x;
1490 event.m_y -= m_y;
1491
1492 int x = event.m_x ;
1493 int y = event.m_y ;
1494
e7549107 1495 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848 1496 {
e7549107
SC
1497 wxWindow *child = (wxWindow*)node->Data();
1498 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
519cb848 1499 {
e7549107
SC
1500 if (child->MacDispatchMouseEvent(event))
1501 return TRUE;
519cb848
SC
1502 }
1503 }
1504
1505 event.m_x = x ;
1506 event.m_y = y ;
1507
1508 if ( wxBusyCursorCount == 0 )
1509 {
e7549107 1510 m_cursor.MacInstall() ;
519cb848 1511 }
2f1ae414
SC
1512
1513#if wxUSE_TOOLTIPS
1514 if ( event.GetEventType() == wxEVT_MOTION
1515 || event.GetEventType() == wxEVT_ENTER_WINDOW
1516 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1517 wxToolTip::RelayEvent( this , event);
1518#endif // wxUSE_TOOLTIPS
519cb848
SC
1519 GetEventHandler()->ProcessEvent( event ) ;
1520 return TRUE;
1521}
1522
2f1ae414
SC
1523Point lastWhere ;
1524long lastWhen = 0 ;
1525
1526wxString wxWindow::MacGetToolTipString( wxPoint &pt )
1527{
1528 if ( m_tooltip )
1529 {
1530 return m_tooltip->GetTip() ;
1531 }
1532 return "" ;
1533}
519cb848
SC
1534void wxWindow::MacFireMouseEvent( EventRecord *ev )
1535{
1536 wxMouseEvent event(wxEVT_LEFT_DOWN);
1537 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1538 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1539
1540 event.m_leftDown = isDown && !controlDown;
1541 event.m_middleDown = FALSE;
1542 event.m_rightDown = isDown && controlDown;
1543
1544 if ( ev->what == mouseDown )
1545 {
1546 if ( controlDown )
1547 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1548 else
1549 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1550 }
1551 else if ( ev->what == mouseUp )
1552 {
1553 if ( controlDown )
1554 event.SetEventType(wxEVT_RIGHT_UP ) ;
1555 else
1556 event.SetEventType(wxEVT_LEFT_UP ) ;
1557 }
1558 else
1559 {
1560 event.SetEventType(wxEVT_MOTION ) ;
1561 }
1562
1563 event.m_shiftDown = ev->modifiers & shiftKey;
1564 event.m_controlDown = ev->modifiers & controlKey;
1565 event.m_altDown = ev->modifiers & optionKey;
1566 event.m_metaDown = ev->modifiers & cmdKey;
1567
1568 Point localwhere = ev->where ;
1569
1570 GrafPtr port ;
1571 ::GetPort( &port ) ;
1572 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1573 ::GlobalToLocal( &localwhere ) ;
1574 ::SetPort( port ) ;
1575
2f1ae414
SC
1576 if ( ev->what == mouseDown )
1577 {
1578 if ( ev->when - lastWhen <= GetDblTime() )
1579 {
1580 if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
1581 {
1582 if ( controlDown )
1583 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
1584 else
1585 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
1586 }
1587 }
1588 lastWhen = ev->when ;
1589 lastWhere = localwhere ;
1590 }
1591
519cb848
SC
1592 event.m_x = localwhere.h;
1593 event.m_y = localwhere.v;
1594 event.m_x += m_x;
1595 event.m_y += m_y;
1596
1597/*
1598 wxPoint origin = GetClientAreaOrigin() ;
1599
1600 event.m_x += origin.x ;
1601 event.m_y += origin.y ;
1602*/
1603
1604 event.m_timeStamp = ev->when;
1605 event.SetEventObject(this);
1606 if ( wxTheApp->s_captureWindow )
1607 {
1608 int x = event.m_x ;
1609 int y = event.m_y ;
1610 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1611 event.m_x = x ;
1612 event.m_y = y ;
1613 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1614 if ( ev->what == mouseUp )
1615 {
1616 wxTheApp->s_captureWindow = NULL ;
1617 if ( wxBusyCursorCount == 0 )
1618 {
e7549107 1619 m_cursor.MacInstall() ;
519cb848
SC
1620 }
1621 }
1622 }
1623 else
1624 {
1625 MacDispatchMouseEvent( event ) ;
1626 }
1627}
1628
1629void wxWindow::MacMouseDown( EventRecord *ev , short part)
1630{
1631 MacFireMouseEvent( ev ) ;
1632}
1633
1634void wxWindow::MacMouseUp( EventRecord *ev , short part)
1635{
1636 WindowPtr frontWindow ;
1637 switch (part)
1638 {
1639 case inContent:
1640 {
1641 MacFireMouseEvent( ev ) ;
1642 }
1643 break ;
1644 }
1645}
1646
1647void wxWindow::MacMouseMoved( EventRecord *ev , short part)
1648{
1649 WindowPtr frontWindow ;
1650 switch (part)
1651 {
1652 case inContent:
1653 {
1654 MacFireMouseEvent( ev ) ;
1655 }
1656 break ;
1657 }
1658}
1659void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
1660{
1661 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating);
1662 event.m_timeStamp = ev->when ;
1663 event.SetEventObject(this);
1664
1665 GetEventHandler()->ProcessEvent(event);
1666
1667 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
1668}
1669
1670void wxWindow::MacRedraw( RgnHandle updatergn , long time)
1671{
1672 // updatergn is always already clipped to our boundaries
1673 WindowRef window = GetMacRootWindow() ;
1674 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1675 {
2f1ae414 1676 wxMacDrawingHelper focus( this ) ; // was client
519cb848
SC
1677 if ( focus.Ok() )
1678 {
1679 WindowRef window = GetMacRootWindow() ;
7c551d95
SC
1680 bool eraseBackground = false ;
1681 if ( m_macWindowData )
1682 eraseBackground = true ;
519cb848
SC
1683 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1684 {
1685 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1686 }
1687 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1688 {
1689 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1690 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1691 // either a non gray background color or a non control window
1692
1693
1694 wxWindow* parent = GetParent() ;
1695 while( parent )
1696 {
1697 if ( parent->GetMacRootWindow() != window )
1698 {
1699 // we are in a different window on the mac system
1700 parent = NULL ;
1701 break ;
1702 }
1703
1704 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1705 {
1706 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1707 {
1708 // if we have any other colours in the hierarchy
7c551d95
SC
1709 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1710 break ;
519cb848
SC
1711 }
1712 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1713 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1714 {
2f1ae414
SC
1715 Rect box ;
1716 GetRegionBounds( updatergn , &box) ;
1717 UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
519cb848
SC
1718 break ;
1719 }
1720 }
1721 else
1722 {
1723 parent = NULL ;
1724 break ;
1725 }
1726 parent = parent->GetParent() ;
1727 }
1728 if ( !parent )
1729 {
1730 // if there is nothing special -> use default
1731 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1732 }
1733 }
1734 else
1735 {
1736 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1737 }
7c551d95
SC
1738 if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
1739 eraseBackground = true ;
519cb848 1740 SetClip( updatergn ) ;
7c551d95
SC
1741 if ( eraseBackground )
1742 {
1743 EraseRgn( updatergn ) ;
1744 }
519cb848 1745 }
2f1ae414
SC
1746
1747 m_macUpdateRgn = updatergn ;
1748 {
1749 RgnHandle newupdate = NewRgn() ;
1750 wxSize point = GetClientSize() ;
1751 wxPoint origin = GetClientAreaOrigin() ;
d467e0c7 1752
2f1ae414
SC
1753 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1754 SectRgn( newupdate , m_macUpdateRgn , newupdate ) ;
1755 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1756 m_updateRegion = newupdate ;
1757 DisposeRgn( newupdate ) ;
1758 }
1759
1760 MacPaintBorders() ;
1761 wxPaintEvent event;
1762 event.m_timeStamp = time ;
1763 event.SetEventObject(this);
1764 GetEventHandler()->ProcessEvent(event);
1765 }
519cb848 1766
519cb848
SC
1767
1768 RgnHandle childupdate = NewRgn() ;
d467e0c7 1769
e7549107 1770 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848
SC
1771 {
1772 wxWindow *child = (wxWindow*)node->Data();
2f1ae414
SC
1773 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1774 SectRgn( childupdate , m_macUpdateRgn , childupdate ) ;
519cb848 1775 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
2f1ae414 1776 if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
519cb848
SC
1777 {
1778 // because dialogs may also be children
1779 child->MacRedraw( childupdate , time ) ;
1780 }
1781 }
1782 DisposeRgn( childupdate ) ;
1783 // eventually a draw grow box here
1784}
1785
1786void wxWindow::MacUpdateImmediately()
1787{
1788 WindowRef window = GetMacRootWindow() ;
1789 if ( window )
1790 {
1791 wxWindow* win = wxFindWinFromMacWindow( window ) ;
2f1ae414
SC
1792 #if TARGET_CARBON
1793 AGAPortHelper help( GetWindowPort(window) ) ;
1794 #else
1795 AGAPortHelper help( (window) ) ;
1796 #endif
1797 SetOrigin( 0 , 0 ) ;
519cb848
SC
1798 BeginUpdate( window ) ;
1799 if ( win )
1800 {
2f1ae414
SC
1801 RgnHandle region = NewRgn();
1802
1803 if ( region )
519cb848 1804 {
2f1ae414
SC
1805 GetPortVisibleRegion( GetWindowPort( window ), region );
1806
1807 // if windowshade gives incompatibility , take the follwing out
1808 if ( !EmptyRgn( region ) )
1809 {
1810 win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
1811 }
1812 DisposeRgn( region );
1813 }
519cb848
SC
1814 }
1815 EndUpdate( window ) ;
1816 }
1817}
1818
1819void wxWindow::MacUpdate( EventRecord *ev )
1820{
1821 WindowRef window = (WindowRef) ev->message ;
1822 wxWindow * win = wxFindWinFromMacWindow( window ) ;
2f1ae414
SC
1823 #if TARGET_CARBON
1824 AGAPortHelper help( GetWindowPort(window) ) ;
1825 #else
1826 AGAPortHelper help( (window) ) ;
1827 #endif
1828 SetOrigin( 0 , 0 ) ;
519cb848
SC
1829 BeginUpdate( window ) ;
1830 if ( win )
1831 {
2f1ae414
SC
1832 RgnHandle region = NewRgn();
1833
1834 if ( region )
519cb848 1835 {
2f1ae414
SC
1836 GetPortVisibleRegion( GetWindowPort( window ), region );
1837
1838 // if windowshade gives incompatibility , take the follwing out
1839 if ( !EmptyRgn( region ) )
1840 {
1841 MacRedraw( region , ev->when ) ;
1842 }
1843 DisposeRgn( region );
1844 }
519cb848
SC
1845 }
1846 EndUpdate( window ) ;
1847}
1848
1849WindowRef wxWindow::GetMacRootWindow() const
1850{
1851 WindowRef window = NULL ;
1852 wxWindow *iter = (wxWindow*)this ;
1853
1854 while( iter )
1855 {
1856 if ( iter->m_macWindowData )
1857 return iter->m_macWindowData->m_macWindow ;
1858
1859 iter = iter->GetParent() ;
1860 }
1861 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1862 return NULL ;
1863}
1864
1865void wxWindow::MacCreateScrollBars( long style )
1866{
1867 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
2f1ae414 1868
519cb848
SC
1869 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1870 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2f1ae414
SC
1871 int width, height ;
1872 GetClientSize( &width , &height ) ;
519cb848 1873
2f1ae414
SC
1874 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1875 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1876 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1877 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1878
1879 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1880 vSize , wxVERTICAL);
1881
519cb848
SC
1882 if ( style & wxVSCROLL )
1883 {
2f1ae414
SC
1884
1885 }
1886 else
1887 {
1888 m_vScrollBar->Show(false) ;
519cb848 1889 }
2f1ae414
SC
1890 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1891 hSize , wxHORIZONTAL);
519cb848
SC
1892 if ( style & wxHSCROLL )
1893 {
2f1ae414
SC
1894 }
1895 else
1896 {
1897 m_hScrollBar->Show(false) ;
519cb848 1898 }
7c74e7fe 1899
519cb848
SC
1900 // because the create does not take into account the client area origin
1901 MacRepositionScrollBars() ; // we might have a real position shift
1902}
1903
1904void wxWindow::MacRepositionScrollBars()
1905{
1906 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1907 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1908
2f1ae414
SC
1909 // get real client area
1910
1911 int width = m_width ;
1912 int height = m_height ;
1913
5b781a67
SC
1914 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1915 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2f1ae414
SC
1916
1917 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1918 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1919 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1920 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1921
1922 int x = 0 ;
1923 int y = 0 ;
1924 int w = m_width ;
1925 int h = m_height ;
1926
1927 MacClientToRootWindow( &x , &y ) ;
1928 MacClientToRootWindow( &w , &h ) ;
1929
1930 WindowRef window = NULL ;
1931 wxWindow *iter = (wxWindow*)this ;
1932
1933 int totW = 10000 , totH = 10000;
1934 while( iter )
1935 {
1936 if ( iter->m_macWindowData )
1937 {
1938 totW = iter->m_width ;
1939 totH = iter->m_height ;
1940 break ;
1941 }
1942
1943 iter = iter->GetParent() ;
1944 }
1945
1946 if ( x == 0 )
1947 {
1948 hPoint.x = -1 ;
1949 hSize.x += 1 ;
1950 }
1951 if ( y == 0 )
1952 {
1953 vPoint.y = -1 ;
1954 vSize.y += 1 ;
1955 }
1956
1957 if ( w-x >= totW )
1958 {
1959 hSize.x += 1 ;
1960 vPoint.x += 1 ;
1961 }
1962
1963 if ( h-y >= totH )
1964 {
1965 vSize.y += 1 ;
1966 hPoint.y += 1 ;
1967 }
1968
519cb848
SC
1969 if ( m_vScrollBar )
1970 {
2f1ae414 1971 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
519cb848
SC
1972 }
1973 if ( m_hScrollBar )
1974 {
2f1ae414 1975 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
519cb848
SC
1976 }
1977}
1978
1979void wxWindow::MacKeyDown( EventRecord *ev )
1980{
2f1ae414 1981
519cb848
SC
1982}
1983
1984
7c551d95
SC
1985bool wxWindow::AcceptsFocus() const
1986{
1987 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1988}
519cb848
SC
1989
1990ControlHandle wxWindow::MacGetContainerForEmbedding()
1991{
1992 if ( m_macWindowData )
1993 return m_macWindowData->m_macRootControl ;
1994 else
1995 return GetParent()->MacGetContainerForEmbedding() ;
1996}
1997
1998void wxWindow::MacSuperChangedPosition()
1999{
2000 // only window-absolute structures have to be moved i.e. controls
2001
2002 wxNode *node = GetChildren().First();
2003 while ( node )
2004 {
2005 wxWindow *child = (wxWindow *)node->Data();
2006 child->MacSuperChangedPosition() ;
2007 node = node->Next();
2008 }
2009}
2f1ae414
SC
2010/*
2011
519cb848
SC
2012bool wxWindow::MacSetupFocusPort( )
2013{
2014 Point localOrigin ;
2015 Rect clipRect ;
2016 WindowRef window ;
2017 wxWindow *rootwin ;
2018 GrafPtr port ;
2019
2020 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2021 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2022}
2023
2024bool wxWindow::MacSetupFocusClientPort( )
2025{
2026 Point localOrigin ;
2027 Rect clipRect ;
2028 WindowRef window ;
2029 wxWindow *rootwin ;
2030 GrafPtr port ;
2031
2032 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2033 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2034}
2035
2036bool wxWindow::MacSetupDrawingPort( )
2037{
2038 Point localOrigin ;
2039 Rect clipRect ;
2040 WindowRef window ;
2041 wxWindow *rootwin ;
2042 GrafPtr port ;
2043
2044 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2045 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2046}
2047
2048bool wxWindow::MacSetupDrawingClientPort( )
2049{
2050 Point localOrigin ;
2051 Rect clipRect ;
2052 WindowRef window ;
2053 wxWindow *rootwin ;
2054 GrafPtr port ;
2055
2056 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2057 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2058}
2f1ae414 2059*/
519cb848
SC
2060
2061bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2062{
2063 if ( window == NULL )
2064 return false ;
2065
2066 GrafPtr currPort;
2067 GrafPtr port ;
2068
2069 ::GetPort(&currPort);
2070 port = UMAGetWindowPort( window) ;
2071 if (currPort != port )
2072 ::SetPort(port);
2073
2f1ae414 2074// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
519cb848
SC
2075 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2076 return true;
2077}
2078
2079bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2080{
2081 if ( window == NULL )
2082 return false ;
2083
2084 GrafPtr currPort;
2085 GrafPtr port ;
2086 ::GetPort(&currPort);
2087 port = UMAGetWindowPort( window) ;
2088 if (currPort != port )
2089 ::SetPort(port);
2f1ae414 2090// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
519cb848
SC
2091 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2092 ::ClipRect(&clipRect);
2093
2094 ::PenNormal() ;
2095 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
2096 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
2f1ae414
SC
2097 Pattern whiteColor ;
2098
2099 ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
519cb848
SC
2100 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2101 return true;
2102}
2103
2104void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin)
2105{
2106 if ( m_macWindowData )
2107 {
2108 localOrigin->h = 0;
2109 localOrigin->v = 0;
2110 clipRect->left = 0;
2111 clipRect->top = 0;
2112 clipRect->right = m_width;
2113 clipRect->bottom = m_height;
2114 *window = m_macWindowData->m_macWindow ;
2115 *rootwin = this ;
2116 }
2117 else
2118 {
2119 wxASSERT( GetParent() != NULL ) ;
2120 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
2121 localOrigin->h += m_x;
2122 localOrigin->v += m_y;
2123 OffsetRect(clipRect, -m_x, -m_y);
2124
2125 Rect myClip;
2126 myClip.left = 0;
2127 myClip.top = 0;
2128 myClip.right = m_width;
2129 myClip.bottom = m_height;
2130 SectRect(clipRect, &myClip, clipRect);
2131 }
2132}
2133
2f1ae414 2134void wxWindow::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
519cb848 2135{
2f1ae414
SC
2136// int width , height ;
2137// GetClientSize( &width , &height ) ;
519cb848
SC
2138
2139 if ( m_macWindowData )
2140 {
2141 localOrigin->h = 0;
2142 localOrigin->v = 0;
2143 clipRect->left = 0;
2144 clipRect->top = 0;
2145 clipRect->right = m_width ;//width;
2146 clipRect->bottom = m_height ;// height;
2147 *window = m_macWindowData->m_macWindow ;
2148 *rootwin = this ;
2149 }
2150 else
2151 {
2152 wxASSERT( GetParent() != NULL ) ;
2153
2f1ae414 2154 GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
519cb848
SC
2155
2156 localOrigin->h += m_x;
2157 localOrigin->v += m_y;
2158 OffsetRect(clipRect, -m_x, -m_y);
2159
2160 Rect myClip;
2161 myClip.left = 0;
2162 myClip.top = 0;
2f1ae414
SC
2163 myClip.right = m_width ;//width;
2164 myClip.bottom = m_height ;// height;
519cb848
SC
2165 SectRect(clipRect, &myClip, clipRect);
2166 }
2167}
2168
2f1ae414
SC
2169void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
2170{
2171 MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
2172
2173 int width , height ;
2174 GetClientSize( &width , &height ) ;
2175 wxPoint client ;
2176 client = GetClientAreaOrigin( ) ;
2177
2178 localOrigin->h += client.x;
2179 localOrigin->v += client.y;
2180 OffsetRect(clipRect, -client.x, -client.y);
2181
2182 Rect myClip;
2183 myClip.left = 0;
2184 myClip.top = 0;
2185 myClip.right = width;
2186 myClip.bottom = height;
2187 SectRect(clipRect, &myClip, clipRect);
2188}
2189
5b781a67 2190long wxWindow::MacGetLeftBorderSize( ) const
2f1ae414
SC
2191{
2192 if( m_macWindowData )
2193 return 0 ;
2194
2195 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2196 {
2197 return 2 ;
2198 }
2199 else if ( m_windowStyle &wxDOUBLE_BORDER)
2200 {
2201 return 2 ;
2202 }
2203 else if (m_windowStyle &wxSIMPLE_BORDER)
2204 {
2205 return 1 ;
2206 }
2207 return 0 ;
2208}
2209
5b781a67
SC
2210long wxWindow::MacGetRightBorderSize( ) const
2211{
2212 if( m_macWindowData )
2213 return 0 ;
2214
2215 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2216 {
2217 return 3 ;
2218 }
2219 else if ( m_windowStyle &wxDOUBLE_BORDER)
2220 {
2221 return 3 ;
2222 }
2223 else if (m_windowStyle &wxSIMPLE_BORDER)
2224 {
2225 return 3 ;
2226 }
2227 return 0 ;
2228}
2229
2230long wxWindow::MacGetTopBorderSize( ) const
2231{
2232 if( m_macWindowData )
2233 return 0 ;
2234
2235 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2236 {
2237 return 2 ;
2238 }
2239 else if ( m_windowStyle &wxDOUBLE_BORDER)
2240 {
2241 return 2 ;
2242 }
2243 else if (m_windowStyle &wxSIMPLE_BORDER)
2244 {
2245 return 1 ;
2246 }
2247 return 0 ;
2248}
2249
2250long wxWindow::MacGetBottomBorderSize( ) const
2251{
2252 if( m_macWindowData )
2253 return 0 ;
2254
2255 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2256 {
2257 return 3 ;
2258 }
2259 else if ( m_windowStyle &wxDOUBLE_BORDER)
2260 {
2261 return 3 ;
2262 }
2263 else if (m_windowStyle &wxSIMPLE_BORDER)
2264 {
2265 return 3 ;
2266 }
2267 return 0 ;
2268}
2269
2f1ae414
SC
2270long wxWindow::MacRemoveBordersFromStyle( long style )
2271{
2272 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2273}
2274/*
519cb848
SC
2275wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
2276{
2277 m_ok = false ;
2278 Point localOrigin ;
2279 Rect clipRect ;
2280 WindowRef window ;
2281 wxWindow *rootwin ;
2282 m_currentPort = NULL ;
2283 GetPort( &m_formerPort ) ;
2284 if ( theWindow )
2285 {
2286
2287 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2288 m_currentPort = UMAGetWindowPort( window ) ;
2289 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2290 m_ok = true ;
2291 }
2292}
2293
2294wxMacFocusHelper::~wxMacFocusHelper()
2295{
2296 if ( m_ok )
2297 {
2f1ae414 2298 SetPort( m_currentPort ) ;
519cb848
SC
2299 SetOrigin( 0 , 0 ) ;
2300 }
2301 if ( m_formerPort != m_currentPort )
2302 SetPort( m_formerPort ) ;
2303}
2f1ae414 2304*/
519cb848
SC
2305wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow )
2306{
2307 m_ok = false ;
2308 Point localOrigin ;
2309 Rect clipRect ;
2310 WindowRef window ;
2311 wxWindow *rootwin ;
2312 m_currentPort = NULL ;
2313
2314 GetPort( &m_formerPort ) ;
2315 if ( theWindow )
2316 {
2317 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2318 m_currentPort = UMAGetWindowPort( window ) ;
2319 if ( m_formerPort != m_currentPort )
2320 SetPort( m_currentPort ) ;
2321 GetPenState( &m_savedPenState ) ;
2322 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2323 m_ok = true ;
2324 }
2325}
2326
2327wxMacDrawingHelper::~wxMacDrawingHelper()
2328{
2329 if ( m_ok )
2330 {
2f1ae414 2331 SetPort( m_currentPort ) ;
519cb848
SC
2332 SetPenState( &m_savedPenState ) ;
2333 SetOrigin( 0 , 0 ) ;
2f1ae414
SC
2334 Rect portRect ;
2335 GetPortBounds( m_currentPort , &portRect ) ;
2336 ClipRect( &portRect ) ;
519cb848
SC
2337 }
2338
2339 if ( m_formerPort != m_currentPort )
2340 SetPort( m_formerPort ) ;
2341}
2f1ae414 2342/*
519cb848
SC
2343wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
2344{
2345 m_ok = false ;
2346 Point localOrigin ;
2347 Rect clipRect ;
2348 WindowRef window ;
2349 wxWindow *rootwin ;
2350 m_currentPort = NULL ;
2351
2352 GetPort( &m_formerPort ) ;
2353
2354 if ( theWindow )
2355 {
2356 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2357 m_currentPort = UMAGetWindowPort( window ) ;
2358 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2359 m_ok = true ;
2360 }
2361}
2362
2363wxMacFocusClientHelper::~wxMacFocusClientHelper()
2364{
2365 if ( m_ok )
2366 {
2f1ae414 2367 SetPort( m_currentPort ) ;
519cb848
SC
2368 SetOrigin( 0 , 0 ) ;
2369 }
2370 if ( m_formerPort != m_currentPort )
2371 SetPort( m_formerPort ) ;
2372}
2f1ae414 2373*/
519cb848
SC
2374
2375wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow )
2376{
2377 m_ok = false ;
2378 Point localOrigin ;
2379 Rect clipRect ;
2380 WindowRef window ;
2381 wxWindow *rootwin ;
2382 m_currentPort = NULL ;
2383
2384 GetPort( &m_formerPort ) ;
2385
2386 if ( theWindow )
2387 {
2388 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2389 m_currentPort = UMAGetWindowPort( window ) ;
2390 if ( m_formerPort != m_currentPort )
2391 SetPort( m_currentPort ) ;
2392 GetPenState( &m_savedPenState ) ;
2393 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2394 m_ok = true ;
2395 }
2396}
2397
2398wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2399{
2400 if ( m_ok )
2401 {
2f1ae414 2402 SetPort( m_currentPort ) ;
519cb848
SC
2403 SetPenState( &m_savedPenState ) ;
2404 SetOrigin( 0 , 0 ) ;
2f1ae414
SC
2405 Rect portRect ;
2406 GetPortBounds( m_currentPort , &portRect ) ;
2407 ClipRect( &portRect ) ;
519cb848
SC
2408 }
2409
2410 if ( m_formerPort != m_currentPort )
2411 SetPort( m_formerPort ) ;
2412}
3723b7b1
JS
2413
2414// Find the wxWindow at the current mouse position, returning the mouse
2415// position.
2416wxWindow* wxFindWindowAtPointer(wxPoint& pt)
2417{
59a12e90
JS
2418 pt = wxGetMousePosition();
2419 wxWindow* found = wxFindWindowAtPoint(pt);
2420 return found;
3723b7b1
JS
2421}
2422
2423// Get the current mouse position.
2424wxPoint wxGetMousePosition()
2425{
57591e0e
JS
2426 int x, y;
2427 wxGetMousePosition(& x, & y);
2428 return wxPoint(x, y);
3723b7b1
JS
2429}
2430