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