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