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