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