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