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