]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/window.cpp
warning fix
[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 {
2f1ae414
SC
692 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
693 event.SetEventObject(this);
694 GetEventHandler()->ProcessEvent(event) ;
695 }
696 if ( doResize )
697 {
519cb848 698 MacRepositionScrollBars() ;
2f1ae414
SC
699 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
700 event.SetEventObject(this);
701 GetEventHandler()->ProcessEvent(event);
702 }
519cb848 703 }
e9576ca5 704}
e9576ca5
SC
705// For implementation purposes - sometimes decorations make the client area
706// smaller
519cb848 707
e9576ca5
SC
708wxPoint wxWindow::GetClientAreaOrigin() const
709{
5b781a67 710 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
e9576ca5
SC
711}
712
713// Makes an adjustment to the window position (for example, a frame that has
714// a toolbar that it manages itself).
715void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
716{
519cb848
SC
717 if( !m_macWindowData )
718 {
e9576ca5
SC
719 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
720 {
721 wxPoint pt(GetParent()->GetClientAreaOrigin());
722 x += pt.x; y += pt.y;
723 }
519cb848
SC
724 }
725}
726
727void wxWindow::SetTitle(const wxString& title)
728{
e7549107
SC
729 m_label = title ;
730
519cb848
SC
731 wxString label ;
732
733 if( wxApp::s_macDefaultEncodingIsPC )
734 label = wxMacMakeMacStringFromPC( title ) ;
735 else
736 label = title ;
737
738 if ( m_macWindowData )
739 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
740}
741
742wxString wxWindow::GetTitle() const
743{
e7549107 744 return m_label ;
519cb848
SC
745}
746
e9576ca5
SC
747bool wxWindow::Show(bool show)
748{
e7549107
SC
749 if ( !wxWindowBase::Show(show) )
750 return FALSE;
751
519cb848
SC
752 if ( m_macWindowData )
753 {
754 if (show)
755 {
756 UMAShowWindow( m_macWindowData->m_macWindow ) ;
757 UMASelectWindow( m_macWindowData->m_macWindow ) ;
2f1ae414
SC
758 // no need to generate events here, they will get them triggered by macos
759 // actually they should be , but apparently they are not
519cb848
SC
760 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
761 event.SetEventObject(this);
762 GetEventHandler()->ProcessEvent(event);
763 }
764 else
765 {
766 UMAHideWindow( m_macWindowData->m_macWindow ) ;
767 }
768 }
8208e181 769 MacSuperShown( show ) ;
519cb848 770 Refresh() ;
fdaf613a 771
e7549107 772 return TRUE;
e9576ca5
SC
773}
774
8208e181
SC
775void wxWindow::MacSuperShown( bool show )
776{
777 wxNode *node = GetChildren().First();
778 while ( node )
779 {
780 wxWindow *child = (wxWindow *)node->Data();
781 if ( child->m_isShown )
782 child->MacSuperShown( show ) ;
783 node = node->Next();
784 }
785}
786
c809f3be
SC
787bool wxWindow::MacIsReallyShown() const
788{
5fde6fcc
GD
789 if ( m_isShown && (m_parent != NULL) ) {
790 return m_parent->MacIsReallyShown();
791 }
792 return m_isShown;
793/*
c809f3be
SC
794 bool status = m_isShown ;
795 wxWindow * win = this ;
796 while ( status && win->m_parent != NULL )
797 {
798 win = win->m_parent ;
799 status = win->m_isShown ;
800 }
801 return status ;
5fde6fcc 802*/
c809f3be
SC
803}
804
e9576ca5
SC
805int wxWindow::GetCharHeight() const
806{
519cb848
SC
807 wxClientDC dc ( (wxWindow*)this ) ;
808 return dc.GetCharHeight() ;
e9576ca5
SC
809}
810
811int wxWindow::GetCharWidth() const
812{
519cb848
SC
813 wxClientDC dc ( (wxWindow*)this ) ;
814 return dc.GetCharWidth() ;
e9576ca5
SC
815}
816
817void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 818 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 819{
e7549107
SC
820 const wxFont *fontToUse = theFont;
821 if ( !fontToUse )
822 fontToUse = &m_font;
7c74e7fe 823
5b781a67 824 wxClientDC dc( (wxWindow*) this ) ;
7c74e7fe 825 long lx,ly,ld,le ;
5fde6fcc 826 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414
SC
827 if ( externalLeading )
828 *externalLeading = le ;
829 if ( descent )
830 *descent = ld ;
831 if ( x )
832 *x = lx ;
833 if ( y )
834 *y = ly ;
e9576ca5
SC
835}
836
519cb848
SC
837void wxWindow::MacEraseBackground( Rect *rect )
838{
0a67a93b 839/*
519cb848
SC
840 WindowRef window = GetMacRootWindow() ;
841 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
842 {
843 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
844 }
845 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
846 {
847 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
848 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
849 // either a non gray background color or a non control window
850
851 wxWindow* parent = GetParent() ;
852 while( parent )
853 {
854 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
855 {
856 // if we have any other colours in the hierarchy
857 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
858 break ;
859 }
860 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
861 {
862 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
863 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
864 {
2f1ae414 865 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
519cb848
SC
866 break ;
867 }
868 }
869 else
870 {
871 // we have arrived at a non control item
872 parent = NULL ;
873 break ;
874 }
875 parent = parent->GetParent() ;
876 }
877 if ( !parent )
878 {
879 // if there is nothing special -> use default
880 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
881 }
882 }
883 else
884 {
885 RGBBackColor( &m_backgroundColour.GetPixel()) ;
886 }
887
888 EraseRect( rect ) ;
889
e7549107 890 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848
SC
891 {
892 wxWindow *child = (wxWindow*)node->Data();
519cb848
SC
893
894 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
895 SectRect( &clientrect , rect , &clientrect ) ;
896
897 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
e7549107 898 if ( child->GetMacRootWindow() == window && child->IsShown() )
519cb848
SC
899 {
900 wxMacDrawingClientHelper focus( this ) ;
901 if ( focus.Ok() )
902 {
903 child->MacEraseBackground( &clientrect ) ;
904 }
905 }
906 }
0a67a93b 907*/
519cb848
SC
908}
909
e9576ca5
SC
910void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
911{
fdaf613a
SC
912// if ( !IsShown() )
913// return ;
914
2f1ae414 915 wxMacDrawingHelper focus( this ) ;
519cb848
SC
916 if ( focus.Ok() )
917 {
2f1ae414 918 Rect clientrect = { 0 , 0 , m_height , m_width } ;
a763ac03 919 // ClipRect( &clientrect ) ;
519cb848 920
2f1ae414
SC
921 if ( rect )
922 {
923 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
519cb848 924 SectRect( &clientrect , &r , &clientrect ) ;
2f1ae414
SC
925 }
926 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
519cb848 927 }
ca715d88
SC
928 if ( !eraseBack )
929 m_macEraseOnRedraw = false ;
930 else
931 m_macEraseOnRedraw = true ;
e9576ca5
SC
932}
933
934// Responds to colour changes: passes event on to children.
935void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
936{
937 wxNode *node = GetChildren().First();
938 while ( node )
939 {
940 // Only propagate to non-top-level windows
941 wxWindow *win = (wxWindow *)node->Data();
942 if ( win->GetParent() )
943 {
944 wxSysColourChangedEvent event2;
945 event.m_eventObject = win;
946 win->GetEventHandler()->ProcessEvent(event2);
947 }
948
949 node = node->Next();
950 }
951}
952
e7549107
SC
953#if wxUSE_CARET && WXWIN_COMPATIBILITY
954// ---------------------------------------------------------------------------
e9576ca5 955// Caret manipulation
e7549107
SC
956// ---------------------------------------------------------------------------
957
e9576ca5
SC
958void wxWindow::CreateCaret(int w, int h)
959{
e7549107 960 SetCaret(new wxCaret(this, w, h));
e9576ca5
SC
961}
962
963void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
964{
e7549107 965 wxFAIL_MSG("not implemented");
e9576ca5
SC
966}
967
968void wxWindow::ShowCaret(bool show)
969{
e7549107
SC
970 wxCHECK_RET( m_caret, "no caret to show" );
971
972 m_caret->Show(show);
e9576ca5
SC
973}
974
975void wxWindow::DestroyCaret()
976{
e7549107 977 SetCaret(NULL);
e9576ca5
SC
978}
979
980void wxWindow::SetCaretPos(int x, int y)
981{
e7549107
SC
982 wxCHECK_RET( m_caret, "no caret to move" );
983
984 m_caret->Move(x, y);
e9576ca5
SC
985}
986
987void wxWindow::GetCaretPos(int *x, int *y) const
988{
e7549107
SC
989 wxCHECK_RET( m_caret, "no caret to get position of" );
990
991 m_caret->GetPosition(x, y);
e9576ca5 992}
e7549107 993#endif // wxUSE_CARET
e9576ca5
SC
994
995wxWindow *wxGetActiveWindow()
996{
519cb848 997 // actually this is a windows-only concept
e9576ca5
SC
998 return NULL;
999}
1000
e9576ca5
SC
1001// Coordinates relative to the window
1002void wxWindow::WarpPointer (int x_pos, int y_pos)
1003{
519cb848 1004 // We really dont move the mouse programmatically under mac
e9576ca5
SC
1005}
1006
1007void wxWindow::OnEraseBackground(wxEraseEvent& event)
1008{
519cb848 1009 // TODO : probably we would adopt the EraseEvent structure
e9576ca5
SC
1010}
1011
1012int wxWindow::GetScrollPos(int orient) const
1013{
519cb848
SC
1014 if ( orient == wxHORIZONTAL )
1015 {
1016 if ( m_hScrollBar )
1017 return m_hScrollBar->GetThumbPosition() ;
1018 }
1019 else
1020 {
1021 if ( m_vScrollBar )
1022 return m_vScrollBar->GetThumbPosition() ;
1023 }
e9576ca5
SC
1024 return 0;
1025}
1026
1027// This now returns the whole range, not just the number
1028// of positions that we can scroll.
1029int wxWindow::GetScrollRange(int orient) const
1030{
519cb848
SC
1031 if ( orient == wxHORIZONTAL )
1032 {
1033 if ( m_hScrollBar )
1034 return m_hScrollBar->GetRange() ;
1035 }
1036 else
1037 {
1038 if ( m_vScrollBar )
1039 return m_vScrollBar->GetRange() ;
1040 }
e9576ca5
SC
1041 return 0;
1042}
1043
1044int wxWindow::GetScrollThumb(int orient) const
1045{
519cb848
SC
1046 if ( orient == wxHORIZONTAL )
1047 {
1048 if ( m_hScrollBar )
1049 return m_hScrollBar->GetThumbSize() ;
1050 }
1051 else
1052 {
1053 if ( m_vScrollBar )
1054 return m_vScrollBar->GetThumbSize() ;
1055 }
e9576ca5
SC
1056 return 0;
1057}
1058
1059void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
1060{
519cb848
SC
1061 if ( orient == wxHORIZONTAL )
1062 {
1063 if ( m_hScrollBar )
1064 m_hScrollBar->SetThumbPosition( pos ) ;
1065 }
1066 else
1067 {
1068 if ( m_vScrollBar )
1069 m_vScrollBar->SetThumbPosition( pos ) ;
1070 }
e9576ca5
SC
1071}
1072
2f1ae414
SC
1073void wxWindow::MacCreateRealWindow( const wxString& title,
1074 const wxPoint& pos,
1075 const wxSize& size,
1076 long style,
1077 const wxString& name )
8208e181 1078{
2f1ae414
SC
1079 SetName(name);
1080 m_windowStyle = style;
1081 m_isShown = FALSE;
8208e181 1082
2f1ae414 1083 // create frame.
8208e181 1084
2f1ae414
SC
1085 Rect theBoundsRect;
1086
1087 m_x = (int)pos.x;
1088 m_y = (int)pos.y;
1089 if ( m_y < 50 )
1090 m_y = 50 ;
1091 if ( m_x < 20 )
1092 m_x = 20 ;
1093
1094 m_width = size.x;
1095 if (m_width == -1)
1096 m_width = 20;
1097 m_height = size.y;
1098 if (m_height == -1)
1099 m_height = 20;
1100
1101 m_macWindowData = new MacWindowData() ;
1102
1103 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
1104
1105 // translate the window attributes in the appropriate window class and attributes
1106
03e11df5
GD
1107 WindowClass wclass = 0;
1108 WindowAttributes attr = kWindowNoAttributes ;
8208e181 1109
2f1ae414
SC
1110 if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) )
1111 {
1112 wclass = kFloatingWindowClass ;
1113 if ( HasFlag(wxTINY_CAPTION_VERT) )
1114 {
1115 attr |= kWindowSideTitlebarAttribute ;
1116 }
1117 }
59c78040 1118 else if ( HasFlag( wxCAPTION ) )
2f1ae414
SC
1119 {
1120 if ( HasFlag( wxDIALOG_MODAL ) )
1121 {
1122 wclass = kMovableModalWindowClass ;
1123 }
360a4636 1124 else
2f1ae414
SC
1125 {
1126 wclass = kDocumentWindowClass ;
1127 }
2f1ae414
SC
1128 }
1129 else
1130 {
1131 wclass = kModalWindowClass ;
1132 }
8208e181 1133
2f1ae414
SC
1134 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
1135 {
1136 attr |= kWindowFullZoomAttribute ;
1137 attr |= kWindowCollapseBoxAttribute ;
1138 }
1139 if ( HasFlag( wxRESIZE_BORDER ) )
1140 {
1141 attr |= kWindowResizableAttribute ;
1142 }
1143 if ( HasFlag( wxSYSTEM_MENU ) )
1144 {
1145 attr |= kWindowCloseBoxAttribute ;
1146 }
8208e181 1147
2f1ae414
SC
1148 UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ;
1149 wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ;
1150 wxString label ;
1151 if( wxApp::s_macDefaultEncodingIsPC )
1152 label = wxMacMakeMacStringFromPC( title ) ;
1153 else
1154 label = title ;
1155 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
1156 UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
1157
1158 m_macWindowData->m_macFocus = NULL ;
fdaf613a 1159 m_macWindowData->m_macHasReceivedFirstActivate = true ;
2f1ae414
SC
1160}
1161
1162void wxWindow::MacPaint( wxPaintEvent &event )
1163{
1164}
1165
1166void wxWindow::MacPaintBorders( )
1167{
1168 if( m_macWindowData )
1169 return ;
1170
1171 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1172 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1173 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1174 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1175 PenNormal() ;
1176
1177 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1178 {
1179 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1180 RGBColor pen1 = sunken ? white : black ;
1181 RGBColor pen2 = sunken ? shadow : face ;
1182 RGBColor pen3 = sunken ? face : shadow ;
1183 RGBColor pen4 = sunken ? black : white ;
1184
1185 RGBForeColor( &pen1 ) ;
1186 {
1187 Rect rect = { 0 , 0 , m_height , m_width } ;
1188 FrameRect( &rect ) ;
1189 }
1190 RGBForeColor( &pen2 ) ;
1191 {
1192 Rect rect = { 1 , 1 , m_height -1 , m_width -1} ;
1193 FrameRect( &rect ) ;
1194 }
1195 RGBForeColor( &pen3 ) ;
1196 {
1197 Rect rect = { 0 , 0 , m_height -2 , m_width -2} ;
1198 FrameRect( &rect ) ;
1199 }
1200 RGBForeColor( &pen4 ) ;
1201 {
1202 MoveTo( 0 , 0 ) ;
1203 LineTo( m_width - 3 , 0 ) ;
1204 MoveTo( 0 , 0 ) ;
1205 LineTo( 0 , m_height - 3 ) ;
1206 }
8208e181
SC
1207 }
1208 else if (HasFlag(wxSIMPLE_BORDER))
1209 {
2f1ae414
SC
1210 Rect rect = { 0 , 0 , m_height , m_width } ;
1211 RGBForeColor( &black ) ;
1212 FrameRect( &rect ) ;
1213 }
1214/*
1215 if ( this->GetParent() )
1216 {
1217 wxPaintDC dc(GetParent());
1218 GetParent()->PrepareDC(dc);
1219
1220 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1221 {
1222 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1223
1224 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1225 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1226
1227 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1228 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1229 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1230 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1231
1232 dc.SetPen(wxPen1);
1233 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1234
1235 dc.SetPen(wxPen2);
1236 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1237
1238 dc.SetPen(wxPen3);
1239 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1240
1241 dc.SetPen(wxPen4);
1242 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1243 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1244 }
1245 else if (HasFlag(wxDOUBLE_BORDER))
1246 {
1247 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1248
1249 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1250 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1251
1252 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1253 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1254 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1255 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1256
1257 dc.SetPen(wxPen1);
1258 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1259
1260 dc.SetPen(wxPen2);
1261 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1262
1263 dc.SetPen(wxPen3);
1264 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1265
1266 dc.SetPen(wxPen4);
1267 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1268 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1269 }
1270 else if (HasFlag(wxSIMPLE_BORDER))
1271 {
1272 dc.SetPen(*wxBLACK_PEN);
1273 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1274 }
8208e181 1275 }
2f1ae414 1276 */
8208e181
SC
1277}
1278
e9576ca5
SC
1279// New function that will replace some of the above.
1280void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
1281 int range, bool refresh)
1282{
519cb848
SC
1283 if ( orient == wxHORIZONTAL )
1284 {
1285 if ( m_hScrollBar )
1286 {
1287 if ( range == 0 || thumbVisible >= range )
1288 {
1289 if ( m_hScrollBar->IsShown() )
1290 m_hScrollBar->Show(false) ;
1291 }
1292 else
1293 {
1294 if ( !m_hScrollBar->IsShown() )
1295 m_hScrollBar->Show(true) ;
a49afa93 1296 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
519cb848
SC
1297 }
1298 }
1299 }
1300 else
1301 {
1302 if ( m_vScrollBar )
1303 {
1304 if ( range == 0 || thumbVisible >= range )
1305 {
1306 if ( m_vScrollBar->IsShown() )
1307 m_vScrollBar->Show(false) ;
1308 }
1309 else
1310 {
1311 if ( !m_vScrollBar->IsShown() )
1312 m_vScrollBar->Show(true) ;
a49afa93 1313 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
519cb848
SC
1314 }
1315 }
1316 }
1317 MacRepositionScrollBars() ;
e9576ca5
SC
1318}
1319
1320// Does a physical scroll
1321void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1322{
519cb848
SC
1323 wxMacDrawingClientHelper focus( this ) ;
1324 if ( focus.Ok() )
1325 {
2f1ae414
SC
1326 int width , height ;
1327 GetClientSize( &width , &height ) ;
1328
1329 Rect scrollrect = { 0 , 0 , height , width } ;
519cb848 1330
2f1ae414
SC
1331 RgnHandle updateRgn = NewRgn() ;
1332 ClipRect( &scrollrect ) ;
1333 if ( rect )
1334 {
1335 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
519cb848 1336 SectRect( &scrollrect , &r , &scrollrect ) ;
2f1ae414
SC
1337 }
1338 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1339 InvalWindowRgn( GetMacRootWindow() , updateRgn ) ;
1340 DisposeRgn( updateRgn ) ;
519cb848 1341 }
d467e0c7
RR
1342
1343 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1344 {
1345 wxWindow *child = (wxWindow*)node->Data();
1346 if (child == m_vScrollBar) continue;
1347 if (child == m_hScrollBar) continue;
1348 if (child->IsTopLevel()) continue;
1349 int x,y;
1350 child->GetPosition( &x, &y );
1351 int w,h;
1352 child->GetSize( &w, &h );
1353 child->SetSize( x+dx, y+dy, w, h );
1354 }
1355
e9576ca5
SC
1356}
1357
7c74e7fe
SC
1358void wxWindow::MacOnScroll(wxScrollEvent &event )
1359{
1360 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1361 {
1362 wxScrollWinEvent wevent;
1363 wevent.SetPosition(event.GetPosition());
1364 wevent.SetOrientation(event.GetOrientation());
1365 wevent.m_eventObject = this;
1366
3b700390 1367 if (event.m_eventType == wxEVT_SCROLL_TOP) {
7c74e7fe 1368 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
3b700390
GD
1369 } else
1370 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
7c74e7fe 1371 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
3b700390
GD
1372 } else
1373 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
7c74e7fe 1374 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3b700390
GD
1375 } else
1376 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
7c74e7fe 1377 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3b700390
GD
1378 } else
1379 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
7c74e7fe 1380 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3b700390
GD
1381 } else
1382 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
7c74e7fe 1383 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3b700390
GD
1384 } else
1385 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
7c74e7fe 1386 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
7c74e7fe
SC
1387 }
1388
1389 GetEventHandler()->ProcessEvent(wevent);
1390 }
1391}
1392
e7549107 1393bool wxWindow::SetFont(const wxFont& font)
e9576ca5 1394{
e7549107
SC
1395 if ( !wxWindowBase::SetFont(font) )
1396 {
1397 // nothing to do
1398 return FALSE;
e9576ca5 1399 }
e9576ca5 1400
e7549107 1401 return TRUE;
e9576ca5
SC
1402}
1403
1404// Get the window with the focus
e7549107 1405wxWindow *wxWindowBase::FindFocus()
e9576ca5 1406{
519cb848
SC
1407 return gFocusWindow ;
1408}
1409
e7549107 1410#if WXWIN_COMPATIBILITY
e9576ca5
SC
1411// If nothing defined for this, try the parent.
1412// E.g. we may be a button loaded from a resource, with no callback function
1413// defined.
1414void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1415{
e7549107
SC
1416 if ( GetEventHandler()->ProcessEvent(event) )
1417 return;
1418 if ( m_parent )
1419 m_parent->GetEventHandler()->OnCommand(win, event);
e9576ca5 1420}
e7549107 1421#endif // WXWIN_COMPATIBILITY_2
e9576ca5 1422
e7549107
SC
1423#if WXWIN_COMPATIBILITY
1424wxObject* wxWindow::GetChild(int number) const
e9576ca5 1425{
e7549107
SC
1426 // Return a pointer to the Nth object in the Panel
1427 wxNode *node = GetChildren().First();
1428 int n = number;
1429 while (node && n--)
1430 node = node->Next();
1431 if ( node )
519cb848 1432 {
e7549107
SC
1433 wxObject *obj = (wxObject *)node->Data();
1434 return(obj);
519cb848
SC
1435 }
1436 else
e7549107 1437 return NULL;
e9576ca5 1438}
e7549107 1439#endif // WXWIN_COMPATIBILITY
e9576ca5 1440
7810c95b
SC
1441void wxWindow::OnSetFocus(wxFocusEvent& event)
1442{
1443 // panel wants to track the window which was the last to have focus in it,
1444 // so we want to set ourselves as the window which last had focus
1445 //
1446 // notice that it's also important to do it upwards the tree becaus
1447 // otherwise when the top level panel gets focus, it won't set it back to
1448 // us, but to some other sibling
1449 wxWindow *win = this;
1450 while ( win )
1451 {
1452 wxWindow *parent = win->GetParent();
1453 wxPanel *panel = wxDynamicCast(parent, wxPanel);
1454 if ( panel )
1455 {
1456 panel->SetLastFocus(win);
1457 }
1458
1459 win = parent;
1460 }
1461
1462 event.Skip();
1463}
1464
e9576ca5
SC
1465void wxWindow::Clear()
1466{
519cb848
SC
1467 if ( m_macWindowData )
1468 {
1469 wxMacDrawingClientHelper helper ( this ) ;
1470 int w ,h ;
1471 wxPoint origin = GetClientAreaOrigin() ;
1472 GetClientSize( &w , &h ) ;
1473 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1474 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
1475 EraseRect( &r ) ;
1476 }
1477 else
1478 {
1479 wxClientDC dc(this);
2f1ae414
SC
1480 wxBrush brush(GetBackgroundColour(), wxSOLID);
1481 dc.SetBackground(brush);
1482 dc.Clear();
519cb848 1483 }
e9576ca5
SC
1484}
1485
e7549107
SC
1486// Setup background and foreground colours correctly
1487void wxWindow::SetupColours()
e9576ca5 1488{
e7549107
SC
1489 if ( GetParent() )
1490 SetBackgroundColour(GetParent()->GetBackgroundColour());
e9576ca5
SC
1491}
1492
1493void wxWindow::OnIdle(wxIdleEvent& event)
1494{
519cb848
SC
1495/*
1496 // Check if we need to send a LEAVE event
1497 if (m_mouseInWindow)
1498 {
1499 POINT pt;
1500 ::GetCursorPos(&pt);
1501 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1502 {
1503 // Generate a LEAVE event
1504 m_mouseInWindow = FALSE;
1505 MSWOnMouseLeave(pt.x, pt.y, 0);
1506 }
e9576ca5
SC
1507 }
1508*/
1509
1510 // This calls the UI-update mechanism (querying windows for
1511 // menu/toolbar/control state information)
1512 UpdateWindowUI();
1513}
1514
1515// Raise the window to the top of the Z order
1516void wxWindow::Raise()
1517{
1518 // TODO
1519}
1520
1521// Lower the window to the bottom of the Z order
1522void wxWindow::Lower()
1523{
1524 // TODO
1525}
1526
519cb848
SC
1527void wxWindow::DoSetClientSize(int width, int height)
1528{
1529 if ( width != -1 || height != -1 )
1530 {
1531
1532 if ( width != -1 && m_vScrollBar )
1533 width += MAC_SCROLLBAR_SIZE ;
1534 if ( height != -1 && m_vScrollBar )
1535 height += MAC_SCROLLBAR_SIZE ;
1536
5b781a67
SC
1537 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1538 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
2f1ae414 1539
519cb848
SC
1540 DoSetSize( -1 , -1 , width , height ) ;
1541 }
1542}
1543
519cb848
SC
1544
1545wxWindow* wxWindow::s_lastMouseWindow = NULL ;
1546
1547bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin )
1548{
1549 if ((point.x < m_x) || (point.y < m_y) ||
1550 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1551 return FALSE;
1552
1553 WindowRef window = GetMacRootWindow() ;
1554
1555 wxPoint newPoint( point ) ;
1556
1557 newPoint.x -= m_x;
1558 newPoint.y -= m_y;
1559
e7549107 1560 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848 1561 {
e7549107 1562 wxWindow *child = (wxWindow*)node->Data();
5b781a67
SC
1563 // added the m_isShown test --dmazzoni
1564 if ( child->GetMacRootWindow() == window && child->m_isShown )
519cb848 1565 {
e7549107
SC
1566 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1567 return TRUE;
519cb848
SC
1568 }
1569 }
1570
1571 *outWin = this ;
1572 return TRUE;
1573}
1574
1575bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin )
1576{
1577 WindowRef window ;
1578 Point pt = { screenpoint.y , screenpoint.x } ;
1579 if ( ::FindWindow( pt , &window ) == 3 )
1580 {
1581 wxPoint point( screenpoint ) ;
1582 wxWindow* win = wxFindWinFromMacWindow( window ) ;
5b781a67
SC
1583 if ( win )
1584 {
519cb848
SC
1585 win->ScreenToClient( point ) ;
1586 return win->MacGetWindowFromPointSub( point , outWin ) ;
1587 }
5b781a67 1588 }
519cb848
SC
1589 return FALSE ;
1590}
1591
1592extern int wxBusyCursorCount ;
1593
1594bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
1595{
1596 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1597 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1598 return FALSE;
1599
2f1ae414 1600
519cb848
SC
1601 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1602 return FALSE ;
1603
1604 WindowRef window = GetMacRootWindow() ;
1605
1606 event.m_x -= m_x;
1607 event.m_y -= m_y;
1608
1609 int x = event.m_x ;
1610 int y = event.m_y ;
1611
e7549107 1612 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848 1613 {
e7549107
SC
1614 wxWindow *child = (wxWindow*)node->Data();
1615 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
519cb848 1616 {
e7549107
SC
1617 if (child->MacDispatchMouseEvent(event))
1618 return TRUE;
519cb848
SC
1619 }
1620 }
1621
1622 event.m_x = x ;
1623 event.m_y = y ;
1624
1625 if ( wxBusyCursorCount == 0 )
1626 {
e7549107 1627 m_cursor.MacInstall() ;
519cb848 1628 }
7810c95b
SC
1629
1630 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1631 {
1632 // set focus to this window
1633 if (AcceptsFocus() && FindFocus()!=this)
1634 SetFocus();
1635 }
2f1ae414
SC
1636
1637#if wxUSE_TOOLTIPS
1638 if ( event.GetEventType() == wxEVT_MOTION
1639 || event.GetEventType() == wxEVT_ENTER_WINDOW
1640 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1641 wxToolTip::RelayEvent( this , event);
1642#endif // wxUSE_TOOLTIPS
519cb848
SC
1643 GetEventHandler()->ProcessEvent( event ) ;
1644 return TRUE;
1645}
1646
2f1ae414
SC
1647Point lastWhere ;
1648long lastWhen = 0 ;
1649
1650wxString wxWindow::MacGetToolTipString( wxPoint &pt )
1651{
1652 if ( m_tooltip )
1653 {
1654 return m_tooltip->GetTip() ;
1655 }
1656 return "" ;
1657}
519cb848
SC
1658void wxWindow::MacFireMouseEvent( EventRecord *ev )
1659{
1660 wxMouseEvent event(wxEVT_LEFT_DOWN);
1661 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1662 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1663
1664 event.m_leftDown = isDown && !controlDown;
1665 event.m_middleDown = FALSE;
1666 event.m_rightDown = isDown && controlDown;
1667
1668 if ( ev->what == mouseDown )
1669 {
1670 if ( controlDown )
1671 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1672 else
1673 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1674 }
1675 else if ( ev->what == mouseUp )
1676 {
1677 if ( controlDown )
1678 event.SetEventType(wxEVT_RIGHT_UP ) ;
1679 else
1680 event.SetEventType(wxEVT_LEFT_UP ) ;
1681 }
1682 else
1683 {
1684 event.SetEventType(wxEVT_MOTION ) ;
1685 }
1686
1687 event.m_shiftDown = ev->modifiers & shiftKey;
1688 event.m_controlDown = ev->modifiers & controlKey;
1689 event.m_altDown = ev->modifiers & optionKey;
1690 event.m_metaDown = ev->modifiers & cmdKey;
1691
1692 Point localwhere = ev->where ;
1693
1694 GrafPtr port ;
1695 ::GetPort( &port ) ;
1696 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1697 ::GlobalToLocal( &localwhere ) ;
1698 ::SetPort( port ) ;
1699
2f1ae414
SC
1700 if ( ev->what == mouseDown )
1701 {
1702 if ( ev->when - lastWhen <= GetDblTime() )
1703 {
1704 if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
1705 {
1706 if ( controlDown )
1707 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
1708 else
1709 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
1710 }
fdaf613a
SC
1711 lastWhen = 0 ;
1712 }
1713 else
1714 {
1715 lastWhen = ev->when ;
2f1ae414 1716 }
2f1ae414
SC
1717 lastWhere = localwhere ;
1718 }
1719
519cb848
SC
1720 event.m_x = localwhere.h;
1721 event.m_y = localwhere.v;
1722 event.m_x += m_x;
1723 event.m_y += m_y;
1724
1725/*
1726 wxPoint origin = GetClientAreaOrigin() ;
1727
1728 event.m_x += origin.x ;
1729 event.m_y += origin.y ;
1730*/
1731
1732 event.m_timeStamp = ev->when;
1733 event.SetEventObject(this);
1734 if ( wxTheApp->s_captureWindow )
1735 {
1736 int x = event.m_x ;
1737 int y = event.m_y ;
1738 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1739 event.m_x = x ;
1740 event.m_y = y ;
1741 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1742 if ( ev->what == mouseUp )
1743 {
1744 wxTheApp->s_captureWindow = NULL ;
1745 if ( wxBusyCursorCount == 0 )
1746 {
e7549107 1747 m_cursor.MacInstall() ;
519cb848
SC
1748 }
1749 }
1750 }
1751 else
1752 {
1753 MacDispatchMouseEvent( event ) ;
1754 }
1755}
1756
1757void wxWindow::MacMouseDown( EventRecord *ev , short part)
1758{
1759 MacFireMouseEvent( ev ) ;
1760}
1761
1762void wxWindow::MacMouseUp( EventRecord *ev , short part)
1763{
1764 WindowPtr frontWindow ;
1765 switch (part)
1766 {
1767 case inContent:
1768 {
1769 MacFireMouseEvent( ev ) ;
1770 }
1771 break ;
1772 }
1773}
1774
1775void wxWindow::MacMouseMoved( EventRecord *ev , short part)
1776{
1777 WindowPtr frontWindow ;
1778 switch (part)
1779 {
1780 case inContent:
1781 {
1782 MacFireMouseEvent( ev ) ;
1783 }
1784 break ;
1785 }
1786}
1787void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
1788{
fdaf613a
SC
1789 if ( !m_macWindowData->m_macHasReceivedFirstActivate )
1790 m_macWindowData->m_macHasReceivedFirstActivate = true ;
1791
90b22aca 1792 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
519cb848
SC
1793 event.m_timeStamp = ev->when ;
1794 event.SetEventObject(this);
1795
1796 GetEventHandler()->ProcessEvent(event);
1797
e42eaa04 1798 Refresh(false) ;
519cb848 1799 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
fdaf613a 1800// MacUpdateImmediately() ;
519cb848
SC
1801}
1802
1803void wxWindow::MacRedraw( RgnHandle updatergn , long time)
1804{
1805 // updatergn is always already clipped to our boundaries
1806 WindowRef window = GetMacRootWindow() ;
ca715d88
SC
1807 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1808 RgnHandle ownUpdateRgn = NewRgn() ;
1809 CopyRgn( updatergn , ownUpdateRgn ) ;
519cb848
SC
1810 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1811 {
2f1ae414 1812 wxMacDrawingHelper focus( this ) ; // was client
519cb848
SC
1813 if ( focus.Ok() )
1814 {
1815 WindowRef window = GetMacRootWindow() ;
7c551d95
SC
1816 bool eraseBackground = false ;
1817 if ( m_macWindowData )
1818 eraseBackground = true ;
519cb848
SC
1819 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1820 {
1821 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1822 }
1823 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1824 {
1825 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1826 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1827 // either a non gray background color or a non control window
1828
1829
1830 wxWindow* parent = GetParent() ;
1831 while( parent )
1832 {
1833 if ( parent->GetMacRootWindow() != window )
1834 {
1835 // we are in a different window on the mac system
1836 parent = NULL ;
1837 break ;
1838 }
1839
1840 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1841 {
1842 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1843 {
1844 // if we have any other colours in the hierarchy
7c551d95
SC
1845 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1846 break ;
519cb848
SC
1847 }
1848 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1849 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1850 {
2f1ae414
SC
1851 Rect box ;
1852 GetRegionBounds( updatergn , &box) ;
1853 UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
519cb848
SC
1854 break ;
1855 }
1856 }
1857 else
1858 {
1859 parent = NULL ;
1860 break ;
1861 }
1862 parent = parent->GetParent() ;
1863 }
1864 if ( !parent )
1865 {
1866 // if there is nothing special -> use default
1867 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1868 }
1869 }
1870 else
1871 {
1872 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1873 }
ca715d88 1874 // subtract all non transparent children from updatergn
fd2e20ff 1875
ca715d88
SC
1876 RgnHandle childarea = NewRgn() ;
1877 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1878 {
1879 wxWindow *child = (wxWindow*)node->Data();
1880 // eventually test for transparent windows
1881 if ( child->GetMacRootWindow() == window && child->IsShown() )
1882 {
fd2e20ff 1883 if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() )
27419164
SC
1884 {
1885 SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1886 DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
1887 }
ca715d88
SC
1888 }
1889 }
1890 DisposeRgn( childarea ) ;
1891
7c551d95
SC
1892 if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
1893 eraseBackground = true ;
a49afa93 1894 SetClip( ownUpdateRgn ) ;
ca715d88
SC
1895 if ( m_macEraseOnRedraw ) {
1896 if ( eraseBackground )
1897 {
1898 EraseRgn( ownUpdateRgn ) ;
1899 }
1900 }
1901 else {
1902 m_macEraseOnRedraw = true ;
1903 }
519cb848 1904 }
2f1ae414 1905
2f1ae414
SC
1906 {
1907 RgnHandle newupdate = NewRgn() ;
1908 wxSize point = GetClientSize() ;
1909 wxPoint origin = GetClientAreaOrigin() ;
d467e0c7 1910
2f1ae414 1911 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
ca715d88 1912 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
2f1ae414
SC
1913 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1914 m_updateRegion = newupdate ;
1915 DisposeRgn( newupdate ) ;
1916 }
1917
1918 MacPaintBorders() ;
1919 wxPaintEvent event;
1920 event.m_timeStamp = time ;
1921 event.SetEventObject(this);
1922 GetEventHandler()->ProcessEvent(event);
1923 }
519cb848 1924
519cb848
SC
1925
1926 RgnHandle childupdate = NewRgn() ;
d467e0c7 1927
e7549107 1928 for (wxNode *node = GetChildren().First(); node; node = node->Next())
519cb848
SC
1929 {
1930 wxWindow *child = (wxWindow*)node->Data();
2f1ae414 1931 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
ca715d88 1932 SectRgn( childupdate , updatergn , childupdate ) ;
519cb848 1933 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
2f1ae414 1934 if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
519cb848
SC
1935 {
1936 // because dialogs may also be children
1937 child->MacRedraw( childupdate , time ) ;
1938 }
1939 }
1940 DisposeRgn( childupdate ) ;
1941 // eventually a draw grow box here
1942}
1943
1944void wxWindow::MacUpdateImmediately()
1945{
1946 WindowRef window = GetMacRootWindow() ;
1947 if ( window )
1948 {
1949 wxWindow* win = wxFindWinFromMacWindow( window ) ;
2f1ae414
SC
1950 #if TARGET_CARBON
1951 AGAPortHelper help( GetWindowPort(window) ) ;
1952 #else
1953 AGAPortHelper help( (window) ) ;
1954 #endif
1955 SetOrigin( 0 , 0 ) ;
519cb848
SC
1956 BeginUpdate( window ) ;
1957 if ( win )
1958 {
2f1ae414
SC
1959 RgnHandle region = NewRgn();
1960
1961 if ( region )
519cb848 1962 {
2f1ae414
SC
1963 GetPortVisibleRegion( GetWindowPort( window ), region );
1964
1965 // if windowshade gives incompatibility , take the follwing out
fdaf613a 1966 if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
2f1ae414
SC
1967 {
1968 win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
1969 }
1970 DisposeRgn( region );
1971 }
519cb848
SC
1972 }
1973 EndUpdate( window ) ;
1974 }
1975}
1976
1977void wxWindow::MacUpdate( EventRecord *ev )
1978{
1979 WindowRef window = (WindowRef) ev->message ;
1980 wxWindow * win = wxFindWinFromMacWindow( window ) ;
2f1ae414
SC
1981 #if TARGET_CARBON
1982 AGAPortHelper help( GetWindowPort(window) ) ;
1983 #else
1984 AGAPortHelper help( (window) ) ;
1985 #endif
1986 SetOrigin( 0 , 0 ) ;
519cb848
SC
1987 BeginUpdate( window ) ;
1988 if ( win )
1989 {
2f1ae414
SC
1990 RgnHandle region = NewRgn();
1991
1992 if ( region )
519cb848 1993 {
2f1ae414
SC
1994 GetPortVisibleRegion( GetWindowPort( window ), region );
1995
1996 // if windowshade gives incompatibility , take the follwing out
fdaf613a 1997 if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
2f1ae414
SC
1998 {
1999 MacRedraw( region , ev->when ) ;
2000 }
2001 DisposeRgn( region );
2002 }
519cb848
SC
2003 }
2004 EndUpdate( window ) ;
2005}
2006
2007WindowRef wxWindow::GetMacRootWindow() const
2008{
2009 WindowRef window = NULL ;
2010 wxWindow *iter = (wxWindow*)this ;
2011
2012 while( iter )
2013 {
2014 if ( iter->m_macWindowData )
2015 return iter->m_macWindowData->m_macWindow ;
2016
2017 iter = iter->GetParent() ;
2018 }
2019 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2020 return NULL ;
2021}
2022
2023void wxWindow::MacCreateScrollBars( long style )
2024{
2025 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
2f1ae414 2026
519cb848
SC
2027 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2028 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2f1ae414
SC
2029 int width, height ;
2030 GetClientSize( &width , &height ) ;
519cb848 2031
2f1ae414
SC
2032 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2033 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2034 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2035 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2036
2037 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2038 vSize , wxVERTICAL);
2039
519cb848
SC
2040 if ( style & wxVSCROLL )
2041 {
2f1ae414
SC
2042
2043 }
2044 else
2045 {
2046 m_vScrollBar->Show(false) ;
519cb848 2047 }
2f1ae414
SC
2048 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2049 hSize , wxHORIZONTAL);
519cb848
SC
2050 if ( style & wxHSCROLL )
2051 {
2f1ae414
SC
2052 }
2053 else
2054 {
2055 m_hScrollBar->Show(false) ;
519cb848 2056 }
7c74e7fe 2057
519cb848
SC
2058 // because the create does not take into account the client area origin
2059 MacRepositionScrollBars() ; // we might have a real position shift
2060}
2061
2062void wxWindow::MacRepositionScrollBars()
2063{
2064 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2065 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2066
2f1ae414
SC
2067 // get real client area
2068
2069 int width = m_width ;
2070 int height = m_height ;
2071
5b781a67
SC
2072 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2073 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2f1ae414
SC
2074
2075 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2076 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2077 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2078 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2079
2080 int x = 0 ;
2081 int y = 0 ;
2082 int w = m_width ;
2083 int h = m_height ;
2084
2085 MacClientToRootWindow( &x , &y ) ;
2086 MacClientToRootWindow( &w , &h ) ;
2087
2088 WindowRef window = NULL ;
2089 wxWindow *iter = (wxWindow*)this ;
2090
2091 int totW = 10000 , totH = 10000;
2092 while( iter )
2093 {
2094 if ( iter->m_macWindowData )
2095 {
2096 totW = iter->m_width ;
2097 totH = iter->m_height ;
2098 break ;
2099 }
2100
2101 iter = iter->GetParent() ;
2102 }
2103
2104 if ( x == 0 )
2105 {
2106 hPoint.x = -1 ;
2107 hSize.x += 1 ;
2108 }
2109 if ( y == 0 )
2110 {
2111 vPoint.y = -1 ;
2112 vSize.y += 1 ;
2113 }
2114
2115 if ( w-x >= totW )
2116 {
2117 hSize.x += 1 ;
2118 vPoint.x += 1 ;
2119 }
2120
2121 if ( h-y >= totH )
2122 {
2123 vSize.y += 1 ;
2124 hPoint.y += 1 ;
2125 }
2126
519cb848
SC
2127 if ( m_vScrollBar )
2128 {
2f1ae414 2129 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
519cb848
SC
2130 }
2131 if ( m_hScrollBar )
2132 {
2f1ae414 2133 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
519cb848
SC
2134 }
2135}
2136
2137void wxWindow::MacKeyDown( EventRecord *ev )
2138{
2f1ae414 2139
519cb848
SC
2140}
2141
2142
7c551d95
SC
2143bool wxWindow::AcceptsFocus() const
2144{
2145 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2146}
519cb848
SC
2147
2148ControlHandle wxWindow::MacGetContainerForEmbedding()
2149{
2150 if ( m_macWindowData )
2151 return m_macWindowData->m_macRootControl ;
2152 else
2153 return GetParent()->MacGetContainerForEmbedding() ;
2154}
2155
2156void wxWindow::MacSuperChangedPosition()
2157{
2158 // only window-absolute structures have to be moved i.e. controls
2159
2160 wxNode *node = GetChildren().First();
2161 while ( node )
2162 {
2163 wxWindow *child = (wxWindow *)node->Data();
2164 child->MacSuperChangedPosition() ;
2165 node = node->Next();
2166 }
2167}
519cb848
SC
2168
2169bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2170{
2171 if ( window == NULL )
2172 return false ;
2173
2174 GrafPtr currPort;
2175 GrafPtr port ;
2176
2177 ::GetPort(&currPort);
2178 port = UMAGetWindowPort( window) ;
2179 if (currPort != port )
2180 ::SetPort(port);
2181
2f1ae414 2182// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
519cb848
SC
2183 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2184 return true;
2185}
2186
2187bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2188{
2189 if ( window == NULL )
2190 return false ;
2191
2192 GrafPtr currPort;
2193 GrafPtr port ;
2194 ::GetPort(&currPort);
2195 port = UMAGetWindowPort( window) ;
2196 if (currPort != port )
2197 ::SetPort(port);
2f1ae414 2198// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
519cb848
SC
2199 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2200 ::ClipRect(&clipRect);
2201
2202 ::PenNormal() ;
2203 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
2204 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
2f1ae414
SC
2205 Pattern whiteColor ;
2206
2207 ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
519cb848
SC
2208 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2209 return true;
2210}
2211
2212void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin)
2213{
2214 if ( m_macWindowData )
2215 {
2216 localOrigin->h = 0;
2217 localOrigin->v = 0;
2218 clipRect->left = 0;
2219 clipRect->top = 0;
2220 clipRect->right = m_width;
2221 clipRect->bottom = m_height;
2222 *window = m_macWindowData->m_macWindow ;
2223 *rootwin = this ;
2224 }
2225 else
2226 {
2227 wxASSERT( GetParent() != NULL ) ;
2228 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
2229 localOrigin->h += m_x;
2230 localOrigin->v += m_y;
2231 OffsetRect(clipRect, -m_x, -m_y);
2232
2233 Rect myClip;
2234 myClip.left = 0;
2235 myClip.top = 0;
2236 myClip.right = m_width;
2237 myClip.bottom = m_height;
2238 SectRect(clipRect, &myClip, clipRect);
2239 }
2240}
2241
2f1ae414 2242void wxWindow::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
519cb848 2243{
2f1ae414
SC
2244// int width , height ;
2245// GetClientSize( &width , &height ) ;
519cb848
SC
2246
2247 if ( m_macWindowData )
2248 {
2249 localOrigin->h = 0;
2250 localOrigin->v = 0;
2251 clipRect->left = 0;
2252 clipRect->top = 0;
2253 clipRect->right = m_width ;//width;
2254 clipRect->bottom = m_height ;// height;
2255 *window = m_macWindowData->m_macWindow ;
2256 *rootwin = this ;
2257 }
2258 else
2259 {
2260 wxASSERT( GetParent() != NULL ) ;
2261
2f1ae414 2262 GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
519cb848
SC
2263
2264 localOrigin->h += m_x;
2265 localOrigin->v += m_y;
2266 OffsetRect(clipRect, -m_x, -m_y);
2267
2268 Rect myClip;
2269 myClip.left = 0;
2270 myClip.top = 0;
2f1ae414
SC
2271 myClip.right = m_width ;//width;
2272 myClip.bottom = m_height ;// height;
519cb848
SC
2273 SectRect(clipRect, &myClip, clipRect);
2274 }
2275}
2276
2f1ae414
SC
2277void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
2278{
2279 MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
2280
2281 int width , height ;
2282 GetClientSize( &width , &height ) ;
2283 wxPoint client ;
2284 client = GetClientAreaOrigin( ) ;
2285
2286 localOrigin->h += client.x;
2287 localOrigin->v += client.y;
2288 OffsetRect(clipRect, -client.x, -client.y);
2289
2290 Rect myClip;
2291 myClip.left = 0;
2292 myClip.top = 0;
2293 myClip.right = width;
2294 myClip.bottom = height;
2295 SectRect(clipRect, &myClip, clipRect);
2296}
2297
5b781a67 2298long wxWindow::MacGetLeftBorderSize( ) const
2f1ae414
SC
2299{
2300 if( m_macWindowData )
2301 return 0 ;
2302
2303 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2304 {
2305 return 2 ;
2306 }
2307 else if ( m_windowStyle &wxDOUBLE_BORDER)
2308 {
2309 return 2 ;
2310 }
2311 else if (m_windowStyle &wxSIMPLE_BORDER)
2312 {
2313 return 1 ;
2314 }
2315 return 0 ;
2316}
2317
5b781a67
SC
2318long wxWindow::MacGetRightBorderSize( ) const
2319{
2320 if( m_macWindowData )
2321 return 0 ;
2322
2323 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2324 {
2325 return 3 ;
2326 }
2327 else if ( m_windowStyle &wxDOUBLE_BORDER)
2328 {
2329 return 3 ;
2330 }
2331 else if (m_windowStyle &wxSIMPLE_BORDER)
2332 {
2333 return 3 ;
2334 }
2335 return 0 ;
2336}
2337
2338long wxWindow::MacGetTopBorderSize( ) const
2339{
2340 if( m_macWindowData )
2341 return 0 ;
2342
2343 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2344 {
2345 return 2 ;
2346 }
2347 else if ( m_windowStyle &wxDOUBLE_BORDER)
2348 {
2349 return 2 ;
2350 }
2351 else if (m_windowStyle &wxSIMPLE_BORDER)
2352 {
2353 return 1 ;
2354 }
2355 return 0 ;
2356}
2357
2358long wxWindow::MacGetBottomBorderSize( ) const
2359{
2360 if( m_macWindowData )
2361 return 0 ;
2362
2363 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2364 {
2365 return 3 ;
2366 }
2367 else if ( m_windowStyle &wxDOUBLE_BORDER)
2368 {
2369 return 3 ;
2370 }
2371 else if (m_windowStyle &wxSIMPLE_BORDER)
2372 {
2373 return 3 ;
2374 }
2375 return 0 ;
2376}
2377
2f1ae414
SC
2378long wxWindow::MacRemoveBordersFromStyle( long style )
2379{
2380 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2381}
0a67a93b 2382
b89dac78 2383
519cb848
SC
2384wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow )
2385{
2386 m_ok = false ;
2387 Point localOrigin ;
2388 Rect clipRect ;
2389 WindowRef window ;
2390 wxWindow *rootwin ;
2391 m_currentPort = NULL ;
2392
2393 GetPort( &m_formerPort ) ;
2394 if ( theWindow )
2395 {
2396 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2397 m_currentPort = UMAGetWindowPort( window ) ;
2398 if ( m_formerPort != m_currentPort )
2399 SetPort( m_currentPort ) ;
2400 GetPenState( &m_savedPenState ) ;
2401 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2402 m_ok = true ;
2403 }
2404}
2405
2406wxMacDrawingHelper::~wxMacDrawingHelper()
2407{
2408 if ( m_ok )
2409 {
2f1ae414 2410 SetPort( m_currentPort ) ;
519cb848
SC
2411 SetPenState( &m_savedPenState ) ;
2412 SetOrigin( 0 , 0 ) ;
2f1ae414
SC
2413 Rect portRect ;
2414 GetPortBounds( m_currentPort , &portRect ) ;
2415 ClipRect( &portRect ) ;
519cb848
SC
2416 }
2417
2418 if ( m_formerPort != m_currentPort )
2419 SetPort( m_formerPort ) ;
2420}
519cb848
SC
2421
2422wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow )
2423{
2424 m_ok = false ;
2425 Point localOrigin ;
2426 Rect clipRect ;
2427 WindowRef window ;
2428 wxWindow *rootwin ;
2429 m_currentPort = NULL ;
2430
2431 GetPort( &m_formerPort ) ;
2432
2433 if ( theWindow )
2434 {
2435 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2436 m_currentPort = UMAGetWindowPort( window ) ;
2437 if ( m_formerPort != m_currentPort )
2438 SetPort( m_currentPort ) ;
2439 GetPenState( &m_savedPenState ) ;
2440 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2441 m_ok = true ;
2442 }
2443}
2444
2445wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2446{
2447 if ( m_ok )
2448 {
2f1ae414 2449 SetPort( m_currentPort ) ;
519cb848
SC
2450 SetPenState( &m_savedPenState ) ;
2451 SetOrigin( 0 , 0 ) ;
2f1ae414
SC
2452 Rect portRect ;
2453 GetPortBounds( m_currentPort , &portRect ) ;
2454 ClipRect( &portRect ) ;
519cb848
SC
2455 }
2456
2457 if ( m_formerPort != m_currentPort )
2458 SetPort( m_formerPort ) ;
2459}
3723b7b1
JS
2460
2461// Find the wxWindow at the current mouse position, returning the mouse
2462// position.
2463wxWindow* wxFindWindowAtPointer(wxPoint& pt)
2464{
59a12e90
JS
2465 pt = wxGetMousePosition();
2466 wxWindow* found = wxFindWindowAtPoint(pt);
2467 return found;
3723b7b1
JS
2468}
2469
2470// Get the current mouse position.
2471wxPoint wxGetMousePosition()
2472{
57591e0e
JS
2473 int x, y;
2474 wxGetMousePosition(& x, & y);
2475 return wxPoint(x, y);
3723b7b1
JS
2476}
2477