]> git.saurik.com Git - wxWidgets.git/blame - src/osx/window_osx.cpp
Add wxTimer::StartOnce().
[wxWidgets.git] / src / osx / window_osx.cpp
CommitLineData
524c47aa 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/window_osx.cpp
524c47aa
SC
3// Purpose: wxWindowMac
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
524c47aa
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/window.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/panel.h"
21 #include "wx/frame.h"
22 #include "wx/dc.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
25 #include "wx/menu.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
38#endif
39
40#include "wx/tooltip.h"
41#include "wx/spinctrl.h"
42#include "wx/geometry.h"
43
44#if wxUSE_LISTCTRL
45 #include "wx/listctrl.h"
46#endif
47
48#if wxUSE_TREECTRL
49 #include "wx/treectrl.h"
50#endif
51
52#if wxUSE_CARET
53 #include "wx/caret.h"
54#endif
55
56#if wxUSE_POPUPWIN
57 #include "wx/popupwin.h"
58#endif
59
60#if wxUSE_DRAG_AND_DROP
0e1d0c53 61 #include "wx/dnd.h"
524c47aa
SC
62#endif
63
f55d9f74
SC
64#include "wx/graphics.h"
65
524c47aa 66#if wxOSX_USE_CARBON
0e1d0c53 67 #include "wx/osx/uma.h"
524c47aa 68#else
0e1d0c53 69 #include "wx/osx/private.h"
11fed901 70#endif
524c47aa
SC
71
72#define MAC_SCROLLBAR_SIZE 15
73#define MAC_SMALL_SCROLLBAR_SIZE 11
74
75#include <string.h>
76
77#ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
524c47aa
SC
79#endif
80
81BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
524c47aa
SC
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
83END_EVENT_TABLE()
84
85#define wxMAC_DEBUG_REDRAW 0
86#ifndef wxMAC_DEBUG_REDRAW
87#define wxMAC_DEBUG_REDRAW 0
88#endif
89
d15694e8
SC
90wxWidgetImplType* kOSXNoWidgetImpl = (wxWidgetImplType*) -1L;
91
c1313b54
SC
92#if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
93
94typedef struct {
95 EventHotKeyRef ref;
96 int keyId;
97 wxWindow* window;
98} wxHotKeyRec;
99
100wxVector<wxHotKeyRec> s_hotkeys;
101
102#endif
103
524c47aa
SC
104// ===========================================================================
105// implementation
106// ===========================================================================
107
82f8ea85
SC
108// the grow box has to be implemented as an inactive window, so that nothing can direct
109// the focus to it
110
111class WXDLLIMPEXP_CORE wxBlindPlateWindow : public wxWindow
112{
113public:
114 wxBlindPlateWindow() { Init(); }
c59aa14a 115
82f8ea85
SC
116 // Old-style constructor (no default values for coordinates to avoid
117 // ambiguity with the new one)
118 wxBlindPlateWindow(wxWindow *parent,
119 int x, int y, int width, int height,
120 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
121 const wxString& name = wxPanelNameStr)
122 {
123 Init();
c59aa14a 124
82f8ea85
SC
125 Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), style, name);
126 }
c59aa14a 127
82f8ea85
SC
128 // Constructor
129 wxBlindPlateWindow(wxWindow *parent,
130 wxWindowID winid = wxID_ANY,
131 const wxPoint& pos = wxDefaultPosition,
132 const wxSize& size = wxDefaultSize,
133 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
134 const wxString& name = wxPanelNameStr)
135 {
136 Init();
c59aa14a 137
82f8ea85
SC
138 Create(parent, winid, pos, size, style, name);
139 }
c59aa14a 140
82f8ea85
SC
141 // Pseudo ctor
142 bool Create(wxWindow *parent,
143 wxWindowID winid = wxID_ANY,
144 const wxPoint& pos = wxDefaultPosition,
145 const wxSize& size = wxDefaultSize,
146 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
147 const wxString& name = wxPanelNameStr)
148 {
149 if ( !wxWindow::Create(parent, winid, pos, size, style, name) )
150 return false;
c59aa14a 151
82f8ea85
SC
152 // so that non-solid background renders correctly under GTK+:
153 SetThemeEnabled(true);
48159545 154 return true;
82f8ea85 155 }
c59aa14a 156
82f8ea85 157 virtual ~wxBlindPlateWindow();
c59aa14a 158
82f8ea85
SC
159 virtual bool AcceptsFocus() const
160 {
161 return false;
162 }
c59aa14a 163
82f8ea85
SC
164protected:
165 // common part of all ctors
166 void Init()
167 {
168 }
c59aa14a 169
82f8ea85
SC
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow)
171 DECLARE_EVENT_TABLE()
172};
173
174wxBlindPlateWindow::~wxBlindPlateWindow()
175{
176}
177
178IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow, wxWindow)
179
180BEGIN_EVENT_TABLE(wxBlindPlateWindow, wxWindow)
181END_EVENT_TABLE()
182
183
524c47aa
SC
184// ----------------------------------------------------------------------------
185 // constructors and such
186// ----------------------------------------------------------------------------
187
188wxWindowMac::wxWindowMac()
189{
190 Init();
191}
192
193wxWindowMac::wxWindowMac(wxWindowMac *parent,
194 wxWindowID id,
195 const wxPoint& pos ,
196 const wxSize& size ,
197 long style ,
198 const wxString& name )
199{
200 Init();
201 Create(parent, id, pos, size, style, name);
202}
203
204void wxWindowMac::Init()
205{
206 m_peer = NULL ;
207 m_macAlpha = 255 ;
208 m_cgContextRef = NULL ;
209
210 // as all windows are created with WS_VISIBLE style...
211 m_isShown = true;
212
213 m_hScrollBar = NULL ;
214 m_vScrollBar = NULL ;
215 m_hScrollBarAlwaysShown = false;
216 m_vScrollBarAlwaysShown = false;
2ae3afa0 217 m_growBox = NULL ;
524c47aa 218
524c47aa
SC
219 m_clipChildren = false ;
220 m_cachedClippedRectValid = false ;
17e2694c 221 m_isNativeWindowWrapper = false;
524c47aa
SC
222}
223
224wxWindowMac::~wxWindowMac()
225{
226 SendDestroyEvent();
c1313b54
SC
227
228#if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
229 for ( int i = s_hotkeys.size()-1; i>=0; -- i )
230 {
231 if ( s_hotkeys[i].window == this )
232 {
233 EventHotKeyRef ref = s_hotkeys[i].ref;
234 s_hotkeys.erase(s_hotkeys.begin() + i);
235 if ( UnregisterEventHotKey(ref) != noErr )
236 {
237 wxLogLastError(wxT("UnregisterHotKey"));
238 }
239 }
240 }
241#endif
524c47aa 242
524c47aa
SC
243 MacInvalidateBorders() ;
244
245#ifndef __WXUNIVERSAL__
246 // VS: make sure there's no wxFrame with last focus set to us:
247 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
248 {
249 wxFrame *frame = wxDynamicCast(win, wxFrame);
250 if ( frame )
251 {
252 if ( frame->GetLastFocus() == this )
d3b9f782 253 frame->SetLastFocus(NULL);
524c47aa
SC
254 break;
255 }
256 }
257#endif
258
259 // destroy children before destroying this window itself
260 DestroyChildren();
261
262 // wxRemoveMacControlAssociation( this ) ;
263 // If we delete an item, we should initialize the parent panel,
264 // because it could now be invalid.
265 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow);
266 if ( tlw )
267 {
268 if ( tlw->GetDefaultItem() == (wxButton*) this)
269 tlw->SetDefaultItem(NULL);
270 }
271
272 if ( g_MacLastWindow == this )
273 g_MacLastWindow = NULL ;
274
275#ifndef __WXUNIVERSAL__
276 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ;
277 if ( frame )
278 {
279 if ( frame->GetLastFocus() == this )
280 frame->SetLastFocus( NULL ) ;
281 }
282#endif
283
284 // delete our drop target if we've got one
285#if wxUSE_DRAG_AND_DROP
5276b0a5 286 wxDELETE(m_dropTarget);
524c47aa
SC
287#endif
288
d15694e8 289 delete GetPeer() ;
524c47aa
SC
290}
291
292WXWidget wxWindowMac::GetHandle() const
293{
d15694e8
SC
294 if ( GetPeer() )
295 return (WXWidget) GetPeer()->GetWXWidget() ;
d4e4ba48 296 return NULL;
524c47aa
SC
297}
298
d15694e8
SC
299wxOSXWidgetImpl* wxWindowMac::GetPeer() const
300{
301 return m_peer == kOSXNoWidgetImpl ? NULL : m_peer ;
302}
303
ce63f2e9
VZ
304bool wxWindowMac::ShouldCreatePeer() const
305{
306 return m_peer != kOSXNoWidgetImpl;
307}
308
d15694e8
SC
309void wxWindowMac::DontCreatePeer()
310{
311 m_peer = kOSXNoWidgetImpl;
312}
313
314void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl* wrapper)
315{
316 wxOSXWidgetImpl* inner = GetPeer();
317 wxASSERT_MSG( inner != NULL && inner->IsOk(), "missing or incomplete inner peer" );
318 wxASSERT_MSG( wrapper != NULL && wrapper->IsOk(), "missing or incomplete wrapper" );
319
320 if ( !(inner != NULL && inner->IsOk() && wrapper != NULL && wrapper->IsOk()) )
321 return;
322
323 inner->RemoveFromParent();
324 wrapper->InstallEventHandler();
325 wrapper->Embed(inner);
326 m_peer = wrapper;
327}
328
22756322
SC
329void wxWindowMac::SetPeer(wxOSXWidgetImpl* peer)
330{
d15694e8
SC
331 if ( GetPeer() )
332 {
869aa41b
SC
333 if ( !GetPeer()->IsRootControl() )
334 GetPeer()->RemoveFromParent();
d15694e8
SC
335 wxDELETE(m_peer);
336 }
337
22756322 338 m_peer = peer;
d15694e8
SC
339
340 if ( GetPeer() && !GetPeer()->IsRootControl())
341 {
342 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
343
344 if (!GetParent()->GetChildren().Find((wxWindow*)this))
345 GetParent()->AddChild( this );
346
347 GetPeer()->InstallEventHandler();
348 GetPeer()->Embed(GetParent()->GetPeer());
349
350 GetParent()->MacChildAdded() ;
351
352 // adjust font, controlsize etc
cb04da13
SC
353 GetPeer()->SetControlSize( m_windowVariant );
354 InheritAttributes();
355 // in case nothing has been set, use the variant default fonts
356 if ( !m_hasFont )
357 DoSetWindowVariant( m_windowVariant );
d15694e8
SC
358
359 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
360
361 // for controls we want to use best size for wxDefaultSize params )
362 if ( !GetPeer()->IsUserPane() )
363 SetInitialSize(GetMinSize());
364
365 SetCursor( *wxSTANDARD_CURSOR ) ;
366 }
367}
368
369#if WXWIN_COMPATIBILITY_2_8
370
371bool wxWindowMac::MacIsUserPane()
372{
373 return GetPeer() == NULL || GetPeer()->IsUserPane();
374}
375
376#endif
377
378bool wxWindowMac::MacIsUserPane() const
379{
380 return GetPeer() == NULL || GetPeer()->IsUserPane();
22756322
SC
381}
382
524c47aa
SC
383// ---------------------------------------------------------------------------
384// Utility Routines to move between different coordinate systems
385// ---------------------------------------------------------------------------
386
387/*
388 * Right now we have the following setup :
389 * a border that is not part of the native control is always outside the
2392a466 390 * control's border (otherwise we lose all native intelligence, future ways
524c47aa
SC
391 * may be to have a second embedding control responsible for drawing borders
392 * and backgrounds eventually)
393 * so all this border calculations have to be taken into account when calling
394 * native methods or getting native oriented data
395 * so we have three coordinate systems here
396 * wx client coordinates
397 * wx window coordinates (including window frames)
398 * native coordinates
399 */
400
401//
402//
403
404// Constructor
405bool wxWindowMac::Create(wxWindowMac *parent,
406 wxWindowID id,
407 const wxPoint& pos,
408 const wxSize& size,
409 long style,
410 const wxString& name)
411{
412 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
413
414 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
415 return false;
416
417 m_windowVariant = parent->GetWindowVariant() ;
418
d15694e8 419 if ( m_peer != kOSXNoWidgetImpl )
524c47aa 420 {
d15694e8 421 SetPeer(wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() ));
524c47aa
SC
422 MacPostControlCreate(pos, size) ;
423 }
424
425#ifndef __WXUNIVERSAL__
426 // Don't give scrollbars to wxControls unless they ask for them
03647350 427 if ( (! IsKindOf(CLASSINFO(wxControl))
11fed901
SC
428#if wxUSE_STATUSBAR
429 && ! IsKindOf(CLASSINFO(wxStatusBar))
430#endif
431 )
524c47aa
SC
432 || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL))))
433 {
434 MacCreateScrollBars( style ) ;
435 }
436#endif
437
438 wxWindowCreateEvent event((wxWindow*)this);
439 GetEventHandler()->AddPendingEvent(event);
440
441 return true;
442}
443
444void wxWindowMac::MacChildAdded()
445{
11fed901 446#if wxUSE_SCROLLBAR
524c47aa
SC
447 if ( m_vScrollBar )
448 m_vScrollBar->Raise() ;
449 if ( m_hScrollBar )
450 m_hScrollBar->Raise() ;
2ae3afa0
JS
451 if ( m_growBox )
452 m_growBox->Raise() ;
11fed901 453#endif
524c47aa
SC
454}
455
6a06eecf
VZ
456void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos),
457 const wxSize& WXUNUSED(size))
524c47aa 458{
d15694e8
SC
459 // todo remove if refactoring works correctly
460#if 0
461 wxASSERT_MSG( GetPeer() != NULL && GetPeer()->IsOk() , wxT("No valid mac control") ) ;
524c47aa 462
d15694e8
SC
463 if (!GetParent()->GetChildren().Find((wxWindow*)this))
464 GetParent()->AddChild( this );
524c47aa 465
d15694e8
SC
466 GetPeer()->InstallEventHandler();
467 GetPeer()->Embed(GetParent()->GetPeer());
524c47aa 468
524c47aa
SC
469 GetParent()->MacChildAdded() ;
470
471 // adjust font, controlsize etc
472 DoSetWindowVariant( m_windowVariant ) ;
473
d15694e8 474 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
524c47aa 475
f55d9f74 476 // for controls we want to use best size for wxDefaultSize params )
d15694e8 477 if ( !GetPeer()->IsUserPane() )
524c47aa
SC
478 SetInitialSize(size);
479
480 SetCursor( *wxSTANDARD_CURSOR ) ;
d15694e8 481#endif
524c47aa
SC
482}
483
484void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
485{
486 // Don't assert, in case we set the window variant before
487 // the window is created
a1b806b9 488 // wxASSERT( GetPeer()->IsOk() ) ;
524c47aa
SC
489
490 m_windowVariant = variant ;
491
d15694e8 492 if (GetPeer() == NULL || !GetPeer()->IsOk())
524c47aa
SC
493 return;
494
d15694e8 495 GetPeer()->SetControlSize( variant );
c59aa14a 496
524c47aa
SC
497 switch ( variant )
498 {
499 case wxWINDOW_VARIANT_NORMAL :
7eb8aeb8
SC
500 static wxFont sysNormal(wxOSX_SYSTEM_FONT_NORMAL);
501 SetFont(sysNormal) ;
524c47aa
SC
502 break ;
503
504 case wxWINDOW_VARIANT_SMALL :
7eb8aeb8
SC
505 static wxFont sysSmall(wxOSX_SYSTEM_FONT_SMALL);
506 SetFont(sysSmall) ;
524c47aa
SC
507 break ;
508
509 case wxWINDOW_VARIANT_MINI :
7eb8aeb8
SC
510 static wxFont sysMini(wxOSX_SYSTEM_FONT_MINI);
511 SetFont(sysMini) ;
524c47aa
SC
512 break ;
513
514 case wxWINDOW_VARIANT_LARGE :
7eb8aeb8
SC
515 static wxFont sysLarge(wxOSX_SYSTEM_FONT_NORMAL);
516 SetFont(sysLarge) ;
524c47aa
SC
517 break ;
518
519 default:
9a83f860 520 wxFAIL_MSG(wxT("unexpected window variant"));
524c47aa
SC
521 break ;
522 }
524c47aa
SC
523}
524
525void wxWindowMac::MacUpdateControlFont()
526{
d15694e8
SC
527 if ( GetPeer() )
528 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1e181c7a 529
524c47aa
SC
530 // do not trigger refreshes upon invisible and possible partly created objects
531 if ( IsShownOnScreen() )
532 Refresh() ;
533}
534
535bool wxWindowMac::SetFont(const wxFont& font)
536{
537 bool retval = wxWindowBase::SetFont( font );
538
539 MacUpdateControlFont() ;
540
541 return retval;
542}
543
544bool wxWindowMac::SetForegroundColour(const wxColour& col )
545{
546 bool retval = wxWindowBase::SetForegroundColour( col );
547
548 if (retval)
549 MacUpdateControlFont();
550
551 return retval;
552}
553
bc5c09a3
SC
554bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style)
555{
556 if ( !wxWindowBase::SetBackgroundStyle(style) )
557 return false;
c59aa14a 558
d15694e8
SC
559 if ( GetPeer() )
560 GetPeer()->SetBackgroundStyle(style);
bc5c09a3
SC
561 return true;
562}
563
524c47aa
SC
564bool wxWindowMac::SetBackgroundColour(const wxColour& col )
565{
82f8ea85
SC
566 if (m_growBox)
567 {
a1b806b9 568 if ( m_backgroundColour.IsOk() )
82f8ea85
SC
569 m_growBox->SetBackgroundColour(m_backgroundColour);
570 else
571 m_growBox->SetBackgroundColour(*wxWHITE);
572 }
573
524c47aa
SC
574 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
575 return false ;
576
d15694e8
SC
577 if ( GetPeer() )
578 GetPeer()->SetBackgroundColour( col ) ;
524c47aa
SC
579
580 return true ;
581}
582
77a246e1
JS
583static bool wxIsWindowOrParentDisabled(wxWindow* w)
584{
585 while (w && !w->IsTopLevel())
586 {
587 if (!w->IsEnabled())
588 return true;
589 w = w->GetParent();
590 }
591 return false;
592}
593
524c47aa
SC
594void wxWindowMac::SetFocus()
595{
596 if ( !AcceptsFocus() )
597 return ;
598
77a246e1
JS
599 if (wxIsWindowOrParentDisabled((wxWindow*) this))
600 return;
601
524c47aa
SC
602 wxWindow* former = FindFocus() ;
603 if ( former == this )
604 return ;
605
d15694e8 606 GetPeer()->SetFocus() ;
524c47aa
SC
607}
608
3af58289
SC
609void wxWindowMac::OSXSimulateFocusEvents()
610{
611 wxWindow* former = FindFocus() ;
612 if ( former != NULL && former != this )
613 {
614 {
615 wxFocusEvent event( wxEVT_KILL_FOCUS, former->GetId());
616 event.SetEventObject(former);
e80711dd 617 event.SetWindow(this);
3af58289
SC
618 former->HandleWindowEvent(event) ;
619 }
620
621 {
622 wxFocusEvent event(wxEVT_SET_FOCUS, former->GetId());
623 event.SetEventObject(former);
e80711dd 624 event.SetWindow(this);
3af58289
SC
625 former->HandleWindowEvent(event);
626 }
627 }
628}
629
524c47aa
SC
630void wxWindowMac::DoCaptureMouse()
631{
632 wxApp::s_captureWindow = (wxWindow*) this ;
d15694e8 633 GetPeer()->CaptureMouse() ;
524c47aa
SC
634}
635
636wxWindow * wxWindowBase::GetCapture()
637{
638 return wxApp::s_captureWindow ;
639}
640
641void wxWindowMac::DoReleaseMouse()
642{
643 wxApp::s_captureWindow = NULL ;
54f11060 644
d15694e8 645 GetPeer()->ReleaseMouse() ;
524c47aa
SC
646}
647
648#if wxUSE_DRAG_AND_DROP
649
650void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
651{
0b1ca117 652 delete m_dropTarget;
524c47aa
SC
653
654 m_dropTarget = pDropTarget;
5ce7b0b5
SC
655
656 GetPeer()->SetDropTarget(m_dropTarget) ;
524c47aa
SC
657}
658
659#endif
660
661// Old-style File Manager Drag & Drop
662void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept))
663{
664 // TODO:
665}
666
667// From a wx position / size calculate the appropriate size of the native control
668
669bool wxWindowMac::MacGetBoundsForControl(
670 const wxPoint& pos,
671 const wxSize& size,
672 int& x, int& y,
673 int& w, int& h , bool adjustOrigin ) const
674{
675 // the desired size, minus the border pixels gives the correct size of the control
676 x = (int)pos.x;
677 y = (int)pos.y;
678
69ce9cea
VZ
679 w = WidthDefault( size.x );
680 h = HeightDefault( size.y );
524c47aa
SC
681
682 x += MacGetLeftBorderSize() ;
683 y += MacGetTopBorderSize() ;
684 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
685 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
686
687 if ( adjustOrigin )
688 AdjustForParentClientOrigin( x , y ) ;
689
690 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1a4e2d5b 691 if ( GetParent() && !GetParent()->IsTopLevel() )
524c47aa
SC
692 {
693 x -= GetParent()->MacGetLeftBorderSize() ;
694 y -= GetParent()->MacGetTopBorderSize() ;
695 }
696
697 return true ;
698}
699
700// Get window size (not client size)
701void wxWindowMac::DoGetSize(int *x, int *y) const
702{
703 int width, height;
d15694e8 704 GetPeer()->GetSize( width, height );
524c47aa
SC
705
706 if (x)
707 *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
708 if (y)
709 *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
710}
711
712// get the position of the bounds of this window in client coordinates of its parent
713void wxWindowMac::DoGetPosition(int *x, int *y) const
714{
715 int x1, y1;
69ce9cea 716
d15694e8 717 GetPeer()->GetPosition( x1, y1 ) ;
524c47aa
SC
718
719 // get the wx window position from the native one
720 x1 -= MacGetLeftBorderSize() ;
721 y1 -= MacGetTopBorderSize() ;
722
723 if ( !IsTopLevel() )
724 {
725 wxWindow *parent = GetParent();
726 if ( parent )
727 {
728 // we must first adjust it to be in window coordinates of the parent,
729 // as otherwise it gets lost by the ClientAreaOrigin fix
730 x1 += parent->MacGetLeftBorderSize() ;
731 y1 += parent->MacGetTopBorderSize() ;
732
733 // and now to client coordinates
734 wxPoint pt(parent->GetClientAreaOrigin());
735 x1 -= pt.x ;
736 y1 -= pt.y ;
737 }
738 }
739
740 if (x)
741 *x = x1 ;
742 if (y)
743 *y = y1 ;
744}
745
746void wxWindowMac::DoScreenToClient(int *x, int *y) const
747{
748 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
749 wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ;
750 tlw->GetNonOwnedPeer()->ScreenToWindow( x, y);
751 MacRootWindowToWindow( x , y ) ;
752
753 wxPoint origin = GetClientAreaOrigin() ;
754 if (x)
755 *x -= origin.x ;
756 if (y)
757 *y -= origin.y ;
758}
759
760void wxWindowMac::DoClientToScreen(int *x, int *y) const
761{
762 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
763 wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ;
764
765 wxPoint origin = GetClientAreaOrigin() ;
766 if (x)
767 *x += origin.x ;
768 if (y)
769 *y += origin.y ;
770
771 MacWindowToRootWindow( x , y ) ;
772 tlw->GetNonOwnedPeer()->WindowToScreen( x , y );
773}
774
775void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
776{
777 wxPoint origin = GetClientAreaOrigin() ;
778 if (x)
779 *x += origin.x ;
780 if (y)
781 *y += origin.y ;
782
783 MacWindowToRootWindow( x , y ) ;
784}
785
786void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
787{
788 wxPoint pt ;
789
790 if (x)
791 pt.x = *x ;
792 if (y)
793 pt.y = *y ;
794
795 if ( !IsTopLevel() )
796 {
797 wxNonOwnedWindow* top = MacGetTopLevelWindow();
798 if (top)
799 {
800 pt.x -= MacGetLeftBorderSize() ;
801 pt.y -= MacGetTopBorderSize() ;
d15694e8 802 wxWidgetImpl::Convert( &pt , GetPeer() , top->GetPeer() ) ;
524c47aa
SC
803 }
804 }
805
806 if (x)
807 *x = (int) pt.x ;
808 if (y)
809 *y = (int) pt.y ;
810}
811
812void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
813{
814 wxPoint pt ;
815
816 if (x)
817 pt.x = *x ;
818 if (y)
819 pt.y = *y ;
820
821 if ( !IsTopLevel() )
822 {
823 wxNonOwnedWindow* top = MacGetTopLevelWindow();
824 if (top)
825 {
d15694e8 826 wxWidgetImpl::Convert( &pt , top->GetPeer() , GetPeer() ) ;
524c47aa
SC
827 pt.x += MacGetLeftBorderSize() ;
828 pt.y += MacGetTopBorderSize() ;
829 }
830 }
831
832 if (x)
833 *x = (int) pt.x ;
834 if (y)
835 *y = (int) pt.y ;
836}
837
838wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
839{
840 wxSize sizeTotal = size;
841
842 int innerwidth, innerheight;
843 int left, top;
844 int outerwidth, outerheight;
69ce9cea 845
d15694e8
SC
846 GetPeer()->GetContentArea( left, top, innerwidth, innerheight );
847 GetPeer()->GetSize( outerwidth, outerheight );
69ce9cea 848
0c530e5a
SC
849 sizeTotal.x += outerwidth-innerwidth;
850 sizeTotal.y += outerheight-innerheight;
69ce9cea 851
524c47aa
SC
852 sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
853 sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
854
855 return sizeTotal;
856}
857
858// Get size *available for subwindows* i.e. excluding menu bar etc.
859void wxWindowMac::DoGetClientSize( int *x, int *y ) const
860{
861 int ww, hh;
862
863 int left, top;
69ce9cea 864
d15694e8 865 GetPeer()->GetContentArea( left, top, ww, hh );
11fed901 866#if wxUSE_SCROLLBAR
524c47aa
SC
867 if (m_hScrollBar && m_hScrollBar->IsShown() )
868 hh -= m_hScrollBar->GetSize().y ;
869
870 if (m_vScrollBar && m_vScrollBar->IsShown() )
871 ww -= m_vScrollBar->GetSize().x ;
872
11fed901 873#endif
524c47aa
SC
874 if (x)
875 *x = ww;
876 if (y)
877 *y = hh;
878}
879
880bool wxWindowMac::SetCursor(const wxCursor& cursor)
881{
882 if (m_cursor.IsSameAs(cursor))
883 return false;
884
885 if (!cursor.IsOk())
886 {
887 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
888 return false ;
889 }
890 else
891 {
892 if ( ! wxWindowBase::SetCursor( cursor ) )
893 return false ;
894 }
895
a1b806b9 896 wxASSERT_MSG( m_cursor.IsOk(),
524c47aa
SC
897 wxT("cursor must be valid after call to the base version"));
898
54f11060
SC
899 if ( GetPeer() != NULL )
900 GetPeer()->SetCursor( m_cursor );
524c47aa
SC
901
902 return true ;
903}
904
905#if wxUSE_MENUS
906bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
907{
908#ifndef __WXUNIVERSAL__
524c47aa
SC
909 menu->UpdateUI();
910
911 if ( x == wxDefaultCoord && y == wxDefaultCoord )
912 {
913 wxPoint mouse = wxGetMousePosition();
914 x = mouse.x;
915 y = mouse.y;
916 }
917 else
918 {
919 ClientToScreen( &x , &y ) ;
920 }
2cb5d2d2 921 menu->GetPeer()->PopUp(this, x, y);
524c47aa
SC
922 return true;
923#else
924 // actually this shouldn't be called, because universal is having its own implementation
925 return false;
926#endif
927}
928#endif
929
930// ----------------------------------------------------------------------------
931// tooltips
932// ----------------------------------------------------------------------------
933
934#if wxUSE_TOOLTIPS
935
936void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
937{
938 wxWindowBase::DoSetToolTip(tooltip);
939
940 if ( m_tooltip )
941 m_tooltip->SetWindow(this);
c59aa14a 942
d15694e8
SC
943 if (GetPeer())
944 GetPeer()->SetToolTip(tooltip);
524c47aa
SC
945}
946
947#endif
948
949void wxWindowMac::MacInvalidateBorders()
950{
d15694e8 951 if ( GetPeer() == NULL )
524c47aa
SC
952 return ;
953
954 bool vis = IsShownOnScreen() ;
955 if ( !vis )
956 return ;
957
958 int outerBorder = MacGetLeftBorderSize() ;
b2088388 959
d15694e8 960 if ( GetPeer()->NeedsFocusRect() )
524c47aa 961 outerBorder += 4 ;
524c47aa
SC
962
963 if ( outerBorder == 0 )
964 return ;
965
966 // now we know that we have something to do at all
524c47aa
SC
967
968 int tx,ty,tw,th;
69ce9cea 969
d15694e8
SC
970 GetPeer()->GetSize( tw, th );
971 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
972
973 wxRect leftupdate( tx-outerBorder,ty,outerBorder,th );
974 wxRect rightupdate( tx+tw, ty, outerBorder, th );
975 wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder );
976 wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder );
69ce9cea 977
1a4e2d5b 978 if (GetParent()) {
d15694e8
SC
979 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate);
980 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate);
981 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate);
982 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate);
1a4e2d5b 983 }
524c47aa
SC
984}
985
986void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
987{
988 // this is never called for a toplevel window, so we know we have a parent
989 int former_x , former_y , former_w, former_h ;
990
991 // Get true coordinates of former position
992 DoGetPosition( &former_x , &former_y ) ;
993 DoGetSize( &former_w , &former_h ) ;
994
995 wxWindow *parent = GetParent();
996 if ( parent )
997 {
998 wxPoint pt(parent->GetClientAreaOrigin());
999 former_x += pt.x ;
1000 former_y += pt.y ;
1001 }
1002
1003 int actualWidth = width ;
1004 int actualHeight = height ;
1005 int actualX = x;
1006 int actualY = y;
1007
f1b1c779
SC
1008#if 0
1009 // min and max sizes are only for sizers, not for explicit size setting
524c47aa
SC
1010 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1011 actualWidth = m_minWidth;
1012 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1013 actualHeight = m_minHeight;
1014 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1015 actualWidth = m_maxWidth;
1016 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1017 actualHeight = m_maxHeight;
f1b1c779 1018#endif
524c47aa
SC
1019
1020 bool doMove = false, doResize = false ;
1021
1022 if ( actualX != former_x || actualY != former_y )
1023 doMove = true ;
1024
1025 if ( actualWidth != former_w || actualHeight != former_h )
1026 doResize = true ;
1027
1028 if ( doMove || doResize )
1029 {
1030 // as the borders are drawn outside the native control, we adjust now
1031
1032 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1033 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1034 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1035
1a4e2d5b 1036 if ( parent && !parent->IsTopLevel() )
524c47aa 1037 {
1a4e2d5b 1038 bounds.Offset( -parent->MacGetLeftBorderSize(), -parent->MacGetTopBorderSize() );
524c47aa
SC
1039 }
1040
1041 MacInvalidateBorders() ;
1042
1043 m_cachedClippedRectValid = false ;
69ce9cea 1044
d15694e8 1045 GetPeer()->Move( bounds.x, bounds.y, bounds.width, bounds.height);
524c47aa
SC
1046
1047 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1048
1049 MacInvalidateBorders() ;
1050
1051 MacRepositionScrollBars() ;
1052 if ( doMove )
1053 {
1054 wxPoint point(actualX, actualY);
1055 wxMoveEvent event(point, m_windowId);
1056 event.SetEventObject(this);
1057 HandleWindowEvent(event) ;
1058 }
1059
1060 if ( doResize )
1061 {
1062 MacRepositionScrollBars() ;
cf83b0cf 1063 SendSizeEvent();
524c47aa
SC
1064 }
1065 }
1066}
1067
1068wxSize wxWindowMac::DoGetBestSize() const
1069{
d15694e8 1070 if ( GetPeer() == NULL || GetPeer()->IsUserPane() || IsTopLevel() )
524c47aa
SC
1071 {
1072 return wxWindowBase::DoGetBestSize() ;
1073 }
1074 else
1075 {
1076 wxRect r ;
69ce9cea 1077
d15694e8 1078 GetPeer()->GetBestRect(&r);
524c47aa
SC
1079
1080 if ( r.GetWidth() == 0 && r.GetHeight() == 0 )
1081 {
1082 r.x =
1083 r.y = 0 ;
1084 r.width =
1085 r.height = 16 ;
1086
11fed901 1087#if wxUSE_SCROLLBAR
65391c8f 1088 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
524c47aa
SC
1089 {
1090 r.height = 16 ;
1091 }
65391c8f 1092 else
11fed901
SC
1093#endif
1094#if wxUSE_SPINBTN
65391c8f 1095 if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
524c47aa
SC
1096 {
1097 r.height = 24 ;
1098 }
524c47aa 1099 else
65391c8f 1100#endif
524c47aa
SC
1101 {
1102 // return wxWindowBase::DoGetBestSize() ;
1103 }
1104 }
1105
69ce9cea 1106 int bestWidth = r.width + MacGetLeftBorderSize() +
524c47aa 1107 MacGetRightBorderSize();
69ce9cea 1108 int bestHeight = r.height + MacGetTopBorderSize() +
524c47aa
SC
1109 MacGetBottomBorderSize();
1110 if ( bestHeight < 10 )
1111 bestHeight = 13 ;
1112
1113 return wxSize(bestWidth, bestHeight);
1114 }
1115}
1116
cf83b0cf
SC
1117void wxWindowMac::SendSizeEvent(int flags)
1118{
1119 MacOnInternalSize();
1120 wxWindowBase::SendSizeEvent(flags);
1121}
1122
524c47aa
SC
1123// set the size of the window: if the dimensions are positive, just use them,
1124// but if any of them is equal to -1, it means that we must find the value for
1125// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1126// which case -1 is a valid value for x and y)
1127//
1128// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1129// the width/height to best suit our contents, otherwise we reuse the current
1130// width/height
1131void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1132{
1133 // get the current size and position...
1134 int currentX, currentY;
1135 int currentW, currentH;
1136
1137 GetPosition(&currentX, &currentY);
1138 GetSize(&currentW, &currentH);
1139
1140 // ... and don't do anything (avoiding flicker) if it's already ok
1141 if ( x == currentX && y == currentY &&
1142 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1143 {
1144 // TODO: REMOVE
1145 MacRepositionScrollBars() ; // we might have a real position shift
1146
e47e063a
RR
1147 if (sizeFlags & wxSIZE_FORCE_EVENT)
1148 {
cf83b0cf 1149 SendSizeEvent();
e47e063a
RR
1150 }
1151
524c47aa
SC
1152 return;
1153 }
1154
1155 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1156 {
1157 if ( x == wxDefaultCoord )
1158 x = currentX;
1159 if ( y == wxDefaultCoord )
1160 y = currentY;
1161 }
1162
1163 AdjustForParentClientOrigin( x, y, sizeFlags );
1164
1165 wxSize size = wxDefaultSize;
1166 if ( width == wxDefaultCoord )
1167 {
1168 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1169 {
1170 size = DoGetBestSize();
1171 width = size.x;
1172 }
1173 else
1174 {
1175 // just take the current one
1176 width = currentW;
1177 }
1178 }
1179
1180 if ( height == wxDefaultCoord )
1181 {
1182 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1183 {
1184 if ( size.x == wxDefaultCoord )
1185 size = DoGetBestSize();
1186 // else: already called DoGetBestSize() above
1187
1188 height = size.y;
1189 }
1190 else
1191 {
1192 // just take the current one
1193 height = currentH;
1194 }
1195 }
1196
1197 DoMoveWindow( x, y, width, height );
1198}
1199
1200wxPoint wxWindowMac::GetClientAreaOrigin() const
1201{
1202 int left,top,width,height;
d15694e8 1203 GetPeer()->GetContentArea( left , top , width , height);
524c47aa
SC
1204 return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() );
1205}
1206
1207void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1208{
1209 if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
1210 {
1211 int currentclientwidth , currentclientheight ;
1212 int currentwidth , currentheight ;
1213
1214 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1215 GetSize( &currentwidth , &currentheight ) ;
1216
1217 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1218 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1219 }
1220}
1221
1829d71c 1222double wxWindowMac::GetContentScaleFactor() const
f18b5ee7 1223{
d15694e8 1224 return GetPeer()->GetContentScaleFactor();
f18b5ee7
SC
1225}
1226
524c47aa
SC
1227void wxWindowMac::SetLabel(const wxString& title)
1228{
8c6c5778
VZ
1229 if ( title == m_label )
1230 return;
1231
524c47aa
SC
1232 m_label = title ;
1233
8c6c5778
VZ
1234 InvalidateBestSize();
1235
d15694e8
SC
1236 if ( GetPeer() && GetPeer()->IsOk() )
1237 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
524c47aa
SC
1238
1239 // do not trigger refreshes upon invisible and possible partly created objects
1240 if ( IsShownOnScreen() )
1241 Refresh() ;
1242}
1243
1244wxString wxWindowMac::GetLabel() const
1245{
1246 return m_label ;
1247}
1248
1249bool wxWindowMac::Show(bool show)
1250{
91722d74
SC
1251 if ( !show )
1252 MacInvalidateBorders();
1253
524c47aa
SC
1254 if ( !wxWindowBase::Show(show) )
1255 return false;
1256
d15694e8
SC
1257 if ( GetPeer() )
1258 GetPeer()->SetVisibility( show ) ;
524c47aa 1259
2d0744aa
SC
1260 if ( show )
1261 MacInvalidateBorders();
1262
4cc16dcb 1263#ifdef __WXOSX_IPHONE__
c59aa14a 1264 // only when there's no native event support
4cc16dcb
SC
1265 if ( !IsTopLevel() )
1266#endif
1267 {
1268 wxShowEvent eventShow(GetId(), show);
1269 eventShow.SetEventObject(this);
c59aa14a 1270
4cc16dcb
SC
1271 HandleWindowEvent(eventShow);
1272 }
c59aa14a 1273
524c47aa
SC
1274 return true;
1275}
1276
ab9a0b84
VZ
1277bool wxWindowMac::OSXShowWithEffect(bool show,
1278 wxShowEffect effect,
1279 unsigned timeout)
1280{
1281 if ( effect == wxSHOW_EFFECT_NONE ||
d15694e8 1282 !GetPeer() || !GetPeer()->ShowWithEffect(show, effect, timeout) )
ab9a0b84
VZ
1283 return Show(show);
1284
1285 return true;
1286}
1287
524c47aa
SC
1288void wxWindowMac::DoEnable(bool enable)
1289{
d15694e8 1290 GetPeer()->Enable( enable ) ;
c4a7e284 1291 MacInvalidateBorders();
524c47aa
SC
1292}
1293
1294//
1295// status change notifications
1296//
1297
1298void wxWindowMac::MacVisibilityChanged()
1299{
1300}
1301
1302void wxWindowMac::MacHiliteChanged()
1303{
1304}
1305
1306void wxWindowMac::MacEnabledStateChanged()
1307{
524c47aa
SC
1308}
1309
1310//
1311// status queries on the inherited window's state
1312//
1313
1314bool wxWindowMac::MacIsReallyEnabled()
1315{
d15694e8 1316 return GetPeer()->IsEnabled() ;
524c47aa
SC
1317}
1318
1319bool wxWindowMac::MacIsReallyHilited()
1320{
1321#if wxOSX_USE_CARBON
d15694e8 1322 return GetPeer()->IsActive();
524c47aa
SC
1323#else
1324 return true; // TODO
1325#endif
1326}
1327
1328int wxWindowMac::GetCharHeight() const
1329{
f55d9f74
SC
1330 wxCoord height;
1331 GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
524c47aa 1332
f55d9f74 1333 return height;
524c47aa
SC
1334}
1335
1336int wxWindowMac::GetCharWidth() const
1337{
f55d9f74
SC
1338 wxCoord width;
1339 GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
524c47aa 1340
f55d9f74 1341 return width;
524c47aa
SC
1342}
1343
6de70470
VZ
1344void wxWindowMac::DoGetTextExtent(const wxString& str,
1345 int *x, int *y,
1346 int *descent,
1347 int *externalLeading,
1348 const wxFont *theFont) const
524c47aa
SC
1349{
1350 const wxFont *fontToUse = theFont;
1351 wxFont tempFont;
1352 if ( !fontToUse )
1353 {
1354 tempFont = GetFont();
1355 fontToUse = &tempFont;
1356 }
1357
f55d9f74
SC
1358 wxGraphicsContext* ctx = wxGraphicsContext::Create();
1359 ctx->SetFont( *fontToUse, *wxBLACK );
1360
1361 wxDouble h , d , e , w;
1362 ctx->GetTextExtent( str, &w, &h, &d, &e );
69ce9cea 1363
f55d9f74 1364 delete ctx;
69ce9cea 1365
524c47aa 1366 if ( externalLeading )
f55d9f74 1367 *externalLeading = (wxCoord)(e+0.5);
524c47aa 1368 if ( descent )
f55d9f74 1369 *descent = (wxCoord)(d+0.5);
524c47aa 1370 if ( x )
f55d9f74 1371 *x = (wxCoord)(w+0.5);
524c47aa 1372 if ( y )
f55d9f74 1373 *y = (wxCoord)(h+0.5);
524c47aa
SC
1374}
1375
1376/*
1377 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1378 * we always intersect with the entire window, not only with the client area
1379 */
1380
1381void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
1382{
d15694e8 1383 if ( GetPeer() == NULL )
524c47aa
SC
1384 return ;
1385
1386 if ( !IsShownOnScreen() )
1387 return ;
2ab38025
SC
1388
1389 if ( IsFrozen() )
1390 return;
69ce9cea 1391
d15694e8 1392 GetPeer()->SetNeedsDisplay( rect ) ;
524c47aa
SC
1393}
1394
1395void wxWindowMac::DoFreeze()
1396{
d15694e8
SC
1397 if ( GetPeer() && GetPeer()->IsOk() )
1398 GetPeer()->SetDrawingEnabled( false ) ;
524c47aa
SC
1399}
1400
1401void wxWindowMac::DoThaw()
1402{
d15694e8 1403 if ( GetPeer() && GetPeer()->IsOk() )
d15694e8 1404 GetPeer()->SetDrawingEnabled( true ) ;
524c47aa
SC
1405}
1406
1407wxWindow *wxGetActiveWindow()
1408{
1409 // actually this is a windows-only concept
1410 return NULL;
1411}
1412
1413// Coordinates relative to the window
1508fcac 1414void wxWindowMac::WarpPointer(int x_pos, int y_pos)
524c47aa 1415{
b2665b86 1416#if wxOSX_USE_COCOA_OR_CARBON
1508fcac
JS
1417 int x = x_pos;
1418 int y = y_pos;
1419 DoClientToScreen(&x, &y);
1420 CGPoint cgpoint = CGPointMake( x, y );
1421 CGWarpMouseCursorPosition( cgpoint );
1422
1423 // At least GTK sends a mouse moved event after WarpMouse
1424 wxMouseEvent event(wxEVT_MOTION);
1425 event.m_x = x_pos;
1426 event.m_y = y_pos;
1427 wxMouseState mState = ::wxGetMouseState();
1428
1429 event.m_altDown = mState.AltDown();
1430 event.m_controlDown = mState.ControlDown();
b2665b86
SC
1431 event.m_leftDown = mState.LeftIsDown();
1432 event.m_middleDown = mState.MiddleIsDown();
1433 event.m_rightDown = mState.RightIsDown();
1508fcac
JS
1434 event.m_metaDown = mState.MetaDown();
1435 event.m_shiftDown = mState.ShiftDown();
1436 event.SetId(GetId());
1437 event.SetEventObject(this);
1438 GetEventHandler()->ProcessEvent(event);
b2665b86 1439#endif
524c47aa
SC
1440}
1441
524c47aa
SC
1442int wxWindowMac::GetScrollPos(int orient) const
1443{
11fed901 1444#if wxUSE_SCROLLBAR
524c47aa
SC
1445 if ( orient == wxHORIZONTAL )
1446 {
1447 if ( m_hScrollBar )
1448 return m_hScrollBar->GetThumbPosition() ;
1449 }
1450 else
1451 {
1452 if ( m_vScrollBar )
1453 return m_vScrollBar->GetThumbPosition() ;
1454 }
11fed901 1455#endif
524c47aa
SC
1456 return 0;
1457}
1458
1459// This now returns the whole range, not just the number
1460// of positions that we can scroll.
1461int wxWindowMac::GetScrollRange(int orient) const
1462{
11fed901 1463#if wxUSE_SCROLLBAR
524c47aa
SC
1464 if ( orient == wxHORIZONTAL )
1465 {
1466 if ( m_hScrollBar )
1467 return m_hScrollBar->GetRange() ;
1468 }
1469 else
1470 {
1471 if ( m_vScrollBar )
1472 return m_vScrollBar->GetRange() ;
1473 }
11fed901 1474#endif
524c47aa
SC
1475 return 0;
1476}
1477
1478int wxWindowMac::GetScrollThumb(int orient) const
1479{
11fed901 1480#if wxUSE_SCROLLBAR
524c47aa
SC
1481 if ( orient == wxHORIZONTAL )
1482 {
1483 if ( m_hScrollBar )
1484 return m_hScrollBar->GetThumbSize() ;
1485 }
1486 else
1487 {
1488 if ( m_vScrollBar )
1489 return m_vScrollBar->GetThumbSize() ;
1490 }
11fed901 1491#endif
524c47aa
SC
1492 return 0;
1493}
1494
1495void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1496{
11fed901 1497#if wxUSE_SCROLLBAR
524c47aa
SC
1498 if ( orient == wxHORIZONTAL )
1499 {
1500 if ( m_hScrollBar )
1501 m_hScrollBar->SetThumbPosition( pos ) ;
1502 }
1503 else
1504 {
1505 if ( m_vScrollBar )
1506 m_vScrollBar->SetThumbPosition( pos ) ;
1507 }
11fed901 1508#endif
524c47aa
SC
1509}
1510
1511void
1512wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag)
1513{
1514 bool needVisibilityUpdate = false;
1515
1516 if ( m_hScrollBarAlwaysShown != hflag )
1517 {
1518 m_hScrollBarAlwaysShown = hflag;
1519 needVisibilityUpdate = true;
1520 }
1521
1522 if ( m_vScrollBarAlwaysShown != vflag )
1523 {
1524 m_vScrollBarAlwaysShown = vflag;
1525 needVisibilityUpdate = true;
1526 }
1527
1528 if ( needVisibilityUpdate )
1529 DoUpdateScrollbarVisibility();
1530}
1531
1532//
1533// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1534// our own window origin is at leftOrigin/rightOrigin
1535//
1536
1537void wxWindowMac::MacPaintGrowBox()
1538{
1539 if ( IsTopLevel() )
1540 return ;
1541
11fed901 1542#if wxUSE_SCROLLBAR
524c47aa
SC
1543 if ( MacHasScrollBarCorner() )
1544 {
2ae3afa0 1545#if 0
524c47aa
SC
1546 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
1547 wxASSERT( cgContext ) ;
1548
1549 int tx,ty,tw,th;
69ce9cea 1550
d15694e8
SC
1551 GetPeer()->GetSize( tw, th );
1552 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
1553
1554 Rect rect = { ty,tx, ty+th, tx+tw };
1555
1556
1557 int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
1558 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
524c47aa
SC
1559 CGContextSaveGState( cgContext );
1560
a1b806b9 1561 if ( m_backgroundColour.IsOk() )
524c47aa
SC
1562 {
1563 CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() );
1564 }
1565 else
1566 {
1567 CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 );
1568 }
1569 CGContextFillRect( cgContext, cgrect );
1570 CGContextRestoreGState( cgContext );
2ae3afa0
JS
1571#else
1572 if (m_growBox)
1573 {
a1b806b9 1574 if ( m_backgroundColour.IsOk() )
2ae3afa0
JS
1575 m_growBox->SetBackgroundColour(m_backgroundColour);
1576 else
1577 m_growBox->SetBackgroundColour(*wxWHITE);
1578 }
1579#endif
524c47aa 1580 }
2ae3afa0 1581
11fed901 1582#endif
524c47aa
SC
1583}
1584
1585void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
1586{
1587 if ( IsTopLevel() )
1588 return ;
1589
d15694e8 1590 bool hasFocus = GetPeer()->NeedsFocusRect() && HasFocus();
524c47aa
SC
1591
1592 // back to the surrounding frame rectangle
1593 int tx,ty,tw,th;
69ce9cea 1594
d15694e8
SC
1595 GetPeer()->GetSize( tw, th );
1596 GetPeer()->GetPosition( tx, ty );
524c47aa 1597
524c47aa
SC
1598#if wxOSX_USE_COCOA_OR_CARBON
1599
524c47aa 1600 {
a6ac3d64
SC
1601 CGRect cgrect = CGRectMake( tx-1 , ty-1 , tw+2 ,
1602 th+2 ) ;
524c47aa 1603
524c47aa
SC
1604 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
1605 wxASSERT( cgContext ) ;
1606
d15694e8 1607 if ( GetPeer()->NeedsFrame() )
524c47aa 1608 {
f2f6030e
SC
1609 HIThemeFrameDrawInfo info ;
1610 memset( &info, 0 , sizeof(info) ) ;
1611
1612 info.version = 0 ;
1613 info.kind = 0 ;
1614 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1615 info.isFocused = hasFocus ;
1616
1617 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1618 {
1619 info.kind = kHIThemeFrameTextFieldSquare ;
1620 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1621 }
1622 else if ( HasFlag(wxSIMPLE_BORDER) )
1623 {
1624 info.kind = kHIThemeFrameListBox ;
1625 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1626 }
524c47aa 1627 }
69ce9cea 1628
f2f6030e 1629 if ( hasFocus )
524c47aa
SC
1630 {
1631 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
1632 }
524c47aa
SC
1633 }
1634#endif // wxOSX_USE_COCOA_OR_CARBON
1635}
1636
1637void wxWindowMac::RemoveChild( wxWindowBase *child )
1638{
11fed901 1639#if wxUSE_SCROLLBAR
524c47aa
SC
1640 if ( child == m_hScrollBar )
1641 m_hScrollBar = NULL ;
1642 if ( child == m_vScrollBar )
1643 m_vScrollBar = NULL ;
2ae3afa0
JS
1644 if ( child == m_growBox )
1645 m_growBox = NULL ;
11fed901 1646#endif
524c47aa
SC
1647 wxWindowBase::RemoveChild( child ) ;
1648}
1649
1650void wxWindowMac::DoUpdateScrollbarVisibility()
1651{
11fed901 1652#if wxUSE_SCROLLBAR
524c47aa
SC
1653 bool triggerSizeEvent = false;
1654
1655 if ( m_hScrollBar )
1656 {
1657 bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded();
1658
1659 if ( m_hScrollBar->IsShown() != showHScrollBar )
1660 {
1661 m_hScrollBar->Show( showHScrollBar );
1662 triggerSizeEvent = true;
1663 }
1664 }
1665
1666 if ( m_vScrollBar)
1667 {
1668 bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded();
1669
1670 if ( m_vScrollBar->IsShown() != showVScrollBar )
1671 {
1672 m_vScrollBar->Show( showVScrollBar ) ;
1673 triggerSizeEvent = true;
1674 }
1675 }
1676
1677 MacRepositionScrollBars() ;
1678 if ( triggerSizeEvent )
1679 {
cf83b0cf 1680 SendSizeEvent();
524c47aa 1681 }
11fed901 1682#endif
524c47aa
SC
1683}
1684
1685// New function that will replace some of the above.
1686void wxWindowMac::SetScrollbar(int orient, int pos, int thumb,
1687 int range, bool refresh)
1688{
11fed901 1689#if wxUSE_SCROLLBAR
209a9f58
VZ
1690 // Updating scrollbars when window is being deleted is useless and
1691 // currently results in asserts in client-to-screen coordinates conversion
1692 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1693 if ( m_isBeingDeleted )
1694 return;
1695
524c47aa
SC
1696 if ( orient == wxHORIZONTAL && m_hScrollBar )
1697 m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1698 else if ( orient == wxVERTICAL && m_vScrollBar )
1699 m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1700
1701 DoUpdateScrollbarVisibility();
11fed901 1702#endif
524c47aa
SC
1703}
1704
1705// Does a physical scroll
1706void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1707{
1708 if ( dx == 0 && dy == 0 )
1709 return ;
1710
1711 int width , height ;
1712 GetClientSize( &width , &height ) ;
1713
1714 {
1715 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
1716 if ( rect )
1717 scrollrect.Intersect( *rect ) ;
1718 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1719 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1720
d15694e8 1721 GetPeer()->ScrollRect( &scrollrect, dx, dy );
524c47aa
SC
1722 }
1723
1724 wxWindowMac *child;
1725 int x, y, w, h;
1726 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1727 {
1728 child = node->GetData();
1729 if (child == NULL)
1730 continue;
82f8ea85 1731
524c47aa
SC
1732 if (child->IsTopLevel())
1733 continue;
c59aa14a 1734
82f8ea85
SC
1735 if ( !IsClientAreaChild(child) )
1736 continue;
524c47aa
SC
1737
1738 child->GetPosition( &x, &y );
1739 child->GetSize( &w, &h );
1740 if (rect)
1741 {
1742 wxRect rc( x, y, w, h );
1743 if (rect->Intersects( rc ))
1744 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1745 }
1746 else
1747 {
1748 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1749 }
1750 }
1751}
1752
1753void wxWindowMac::MacOnScroll( wxScrollEvent &event )
1754{
11fed901 1755#if wxUSE_SCROLLBAR
524c47aa
SC
1756 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
1757 {
1758 wxScrollWinEvent wevent;
1759 wevent.SetPosition(event.GetPosition());
1760 wevent.SetOrientation(event.GetOrientation());
1761 wevent.SetEventObject(this);
1762
1763 if (event.GetEventType() == wxEVT_SCROLL_TOP)
1764 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
1765 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
1766 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
1767 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
1768 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
1769 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
1770 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
1771 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
1772 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
1773 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
1774 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
1775 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
1776 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
1777 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
1778 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
1779
1780 HandleWindowEvent(wevent);
1781 }
11fed901 1782#endif
524c47aa
SC
1783}
1784
524c47aa
SC
1785wxWindow *wxWindowBase::DoFindFocus()
1786{
f06e0fea 1787 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
524c47aa
SC
1788}
1789
524c47aa
SC
1790// Raise the window to the top of the Z order
1791void wxWindowMac::Raise()
1792{
d15694e8 1793 GetPeer()->Raise();
524c47aa
SC
1794}
1795
1796// Lower the window to the bottom of the Z order
1797void wxWindowMac::Lower()
1798{
d15694e8 1799 GetPeer()->Lower();
524c47aa
SC
1800}
1801
1802// static wxWindow *gs_lastWhich = NULL;
1803
1804bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
1805{
1806 // first trigger a set cursor event
1807
1808 wxPoint clientorigin = GetClientAreaOrigin() ;
1809 wxSize clientsize = GetClientSize() ;
1810 wxCursor cursor ;
1811 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1812 {
1813 wxSetCursorEvent event( pt.x , pt.y );
f1d0d07d
SC
1814 event.SetId(GetId());
1815 event.SetEventObject(this);
524c47aa
SC
1816
1817 bool processedEvtSetCursor = HandleWindowEvent(event);
1818 if ( processedEvtSetCursor && event.HasCursor() )
1819 {
1820 cursor = event.GetCursor() ;
1821 }
1822 else
1823 {
1824 // the test for processedEvtSetCursor is here to prevent using m_cursor
1825 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1826 // it - this is a way to say that our cursor shouldn't be used for this
1827 // point
a1b806b9 1828 if ( !processedEvtSetCursor && m_cursor.IsOk() )
524c47aa
SC
1829 cursor = m_cursor ;
1830
1831 if ( !wxIsBusy() && !GetParent() )
1832 cursor = *wxSTANDARD_CURSOR ;
1833 }
1834
a1b806b9 1835 if ( cursor.IsOk() )
524c47aa
SC
1836 cursor.MacInstall() ;
1837 }
1838
a1b806b9 1839 return cursor.IsOk() ;
524c47aa
SC
1840}
1841
1842wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) )
1843{
1844#if wxUSE_TOOLTIPS
1845 if ( m_tooltip )
1846 return m_tooltip->GetTip() ;
1847#endif
1848
1849 return wxEmptyString ;
1850}
1851
1852void wxWindowMac::ClearBackground()
1853{
1854 Refresh() ;
1855 Update() ;
1856}
1857
1858void wxWindowMac::Update()
1859{
1860 wxNonOwnedWindow* top = MacGetTopLevelWindow();
1861 if (top)
1862 top->Update() ;
1863}
1864
1865wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const
1866{
1867 wxWindowMac *iter = (wxWindowMac*)this ;
1868
1869 while ( iter )
1870 {
1871 if ( iter->IsTopLevel() )
1872 {
1873 wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow);
1874 if ( toplevel )
1875 return toplevel;
1876#if wxUSE_POPUPWIN
1877 wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow);
1878 if ( popupwin )
1879 return popupwin;
1880#endif
1881 }
1882 iter = iter->GetParent() ;
1883 }
1884
1885 return NULL ;
1886}
1887
1888const wxRect& wxWindowMac::MacGetClippedClientRect() const
1889{
1890 MacUpdateClippedRects() ;
1891
1892 return m_cachedClippedClientRect ;
1893}
1894
1895const wxRect& wxWindowMac::MacGetClippedRect() const
1896{
1897 MacUpdateClippedRects() ;
1898
1899 return m_cachedClippedRect ;
1900}
1901
1902const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1903{
1904 MacUpdateClippedRects() ;
1905
1906 return m_cachedClippedRectWithOuterStructure ;
1907}
1908
1909const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
1910{
1911 static wxRegion emptyrgn ;
1912
1913 if ( !m_isBeingDeleted && IsShownOnScreen() )
1914 {
1915 MacUpdateClippedRects() ;
1916 if ( includeOuterStructures )
1917 return m_cachedClippedRegionWithOuterStructure ;
1918 else
1919 return m_cachedClippedRegion ;
1920 }
1921 else
1922 {
1923 return emptyrgn ;
1924 }
1925}
1926
1927void wxWindowMac::MacUpdateClippedRects() const
1928{
1929#if wxOSX_USE_CARBON
1930 if ( m_cachedClippedRectValid )
1931 return ;
1932
1933 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1934 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1935 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1936 // to add focus borders everywhere
1937
1938 Rect rIncludingOuterStructures ;
1939
1940 int tx,ty,tw,th;
69ce9cea 1941
d15694e8
SC
1942 GetPeer()->GetSize( tw, th );
1943 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
1944
1945 Rect r = { ty,tx, ty+th, tx+tw };
1946
1947 r.left -= MacGetLeftBorderSize() ;
1948 r.top -= MacGetTopBorderSize() ;
1949 r.bottom += MacGetBottomBorderSize() ;
1950 r.right += MacGetRightBorderSize() ;
1951
1952 r.right -= r.left ;
1953 r.bottom -= r.top ;
1954 r.left = 0 ;
1955 r.top = 0 ;
1956
1957 rIncludingOuterStructures = r ;
1958 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
1959
1960 wxRect cl = GetClientRect() ;
1961 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
1962
1963 int x , y ;
1964 wxSize size ;
1965 const wxWindow* child = (wxWindow*) this ;
1966 const wxWindow* parent = NULL ;
1967
1968 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
1969 {
1970 if ( parent->MacIsChildOfClientArea(child) )
1971 {
1972 size = parent->GetClientSize() ;
1973 wxPoint origin = parent->GetClientAreaOrigin() ;
1974 x = origin.x ;
1975 y = origin.y ;
1976 }
1977 else
1978 {
1979 // this will be true for scrollbars, toolbars etc.
1980 size = parent->GetSize() ;
1981 y = parent->MacGetTopBorderSize() ;
1982 x = parent->MacGetLeftBorderSize() ;
1983 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
1984 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
1985 }
1986
1987 parent->MacWindowToRootWindow( &x, &y ) ;
1988 MacRootWindowToWindow( &x , &y ) ;
1989
1990 Rect rparent = { y , x , y + size.y , x + size.x } ;
1991
1992 // the wxwindow and client rects will always be clipped
1993 SectRect( &r , &rparent , &r ) ;
1994 SectRect( &rClient , &rparent , &rClient ) ;
1995
1996 // the structure only at 'hard' borders
1997 if ( parent->MacClipChildren() ||
1998 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
1999 {
2000 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
2001 }
2002
2003 child = parent ;
2004 }
2005
2006 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
2007 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
2008 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
2009 m_cachedClippedRectWithOuterStructure = wxRect(
2010 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
2011 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
2012 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
2013
2014 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
2015 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
2016 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
2017
2018 m_cachedClippedRectValid = true ;
2019#endif
2020}
2021
2022/*
2023 This function must not change the updatergn !
2024 */
5398a2e0 2025bool wxWindowMac::MacDoRedraw( long time )
524c47aa
SC
2026{
2027 bool handled = false ;
69ce9cea 2028
5398a2e0
SC
2029 wxRegion formerUpdateRgn = m_updateRegion;
2030 wxRegion clientUpdateRgn = formerUpdateRgn;
524c47aa 2031
69ce9cea
VZ
2032 const wxRect clientRect = GetClientRect();
2033
2034 clientUpdateRgn.Intersect(clientRect);
2035
5398a2e0 2036 // first send an erase event to the entire update area
69ce9cea 2037 const wxBackgroundStyle bgStyle = GetBackgroundStyle();
6a5594e0 2038 switch ( bgStyle )
524c47aa 2039 {
6a5594e0
VZ
2040 case wxBG_STYLE_ERASE:
2041 case wxBG_STYLE_SYSTEM:
8301a0e8 2042 case wxBG_STYLE_COLOUR:
69ce9cea 2043 {
6a5594e0
VZ
2044 // for the toplevel window this really is the entire area for
2045 // all the others only their client area, otherwise they might
2046 // be drawing with full alpha and eg put blue into the grow-box
2047 // area of a scrolled window (scroll sample)
2048 wxWindowDC dc(this);
2049 if ( IsTopLevel() )
2050 dc.SetDeviceClippingRegion(formerUpdateRgn);
2051 else
2052 dc.SetDeviceClippingRegion(clientUpdateRgn);
2053
2054 if ( bgStyle == wxBG_STYLE_ERASE )
2055 {
2056 wxEraseEvent eevent( GetId(), &dc );
2057 eevent.SetEventObject( this );
2058 if ( ProcessWindowEvent( eevent ) )
2059 break;
2060 }
2061
773809f5 2062 if ( UseBgCol() )
6a5594e0
VZ
2063 {
2064 dc.SetBackground(GetBackgroundColour());
2065 dc.Clear();
2066 }
69ce9cea 2067 }
6a5594e0
VZ
2068 break;
2069
2070 case wxBG_STYLE_PAINT:
4f6bcb83 2071 case wxBG_STYLE_TRANSPARENT:
6a5594e0
VZ
2072 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2073 // entire window client area
2074 break;
2075
2076 default:
2077 wxFAIL_MSG( "unsupported background style" );
5398a2e0 2078 }
524c47aa 2079
82f8ea85
SC
2080 // as this is a full window, shouldn't be necessary anymore
2081 // MacPaintGrowBox();
524c47aa 2082
69ce9cea
VZ
2083 // calculate a client-origin version of the update rgn and set
2084 // m_updateRegion to that
2085 clientUpdateRgn.Offset(-clientRect.GetPosition());
5398a2e0 2086 m_updateRegion = clientUpdateRgn ;
524c47aa 2087
5398a2e0
SC
2088 if ( !m_updateRegion.Empty() )
2089 {
2090 // paint the window itself
524c47aa 2091
45f5bb03 2092 wxPaintEvent event(GetId());
5398a2e0
SC
2093 event.SetTimestamp(time);
2094 event.SetEventObject(this);
2095 handled = HandleWindowEvent(event);
2096 }
524c47aa 2097
5398a2e0 2098 m_updateRegion = formerUpdateRgn;
7dc941e3
SC
2099
2100 wxNonOwnedWindow* top = MacGetTopLevelWindow();
2101 if (top)
2102 top->WindowWasPainted() ;
2103
5398a2e0
SC
2104 return handled;
2105}
524c47aa 2106
5398a2e0
SC
2107void wxWindowMac::MacPaintChildrenBorders()
2108{
2109 // now we cannot rely on having its borders drawn by a window itself, as it does not
2110 // get the updateRgn wide enough to always do so, so we do it from the parent
2111 // this would also be the place to draw any custom backgrounds for native controls
2112 // in Composited windowing
2113 wxPoint clientOrigin = GetClientAreaOrigin() ;
524c47aa 2114
5398a2e0
SC
2115 wxWindowMac *child;
2116 int x, y, w, h;
2117 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2118 {
2119 child = node->GetData();
2120 if (child == NULL)
2121 continue;
11fed901 2122#if wxUSE_SCROLLBAR
5398a2e0
SC
2123 if (child == m_vScrollBar)
2124 continue;
2125 if (child == m_hScrollBar)
2126 continue;
2ae3afa0
JS
2127 if (child == m_growBox)
2128 continue;
11fed901 2129#endif
5398a2e0
SC
2130 if (child->IsTopLevel())
2131 continue;
2132 if (!child->IsShown())
2133 continue;
2134
2135 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2136
2137 child->GetPosition( &x, &y );
2138 child->GetSize( &w, &h );
69ce9cea 2139
5398a2e0 2140 if ( m_updateRegion.Contains(clientOrigin.x+x-10, clientOrigin.y+y-10, w+20, h+20) )
524c47aa 2141 {
5398a2e0
SC
2142 // paint custom borders
2143 wxNcPaintEvent eventNc( child->GetId() );
2144 eventNc.SetEventObject( child );
2145 if ( !child->HandleWindowEvent( eventNc ) )
524c47aa 2146 {
5398a2e0 2147 child->MacPaintBorders(0, 0) ;
524c47aa
SC
2148 }
2149 }
2150 }
524c47aa
SC
2151}
2152
2153
2154WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2155{
69ce9cea 2156 wxNonOwnedWindow* tlw = MacGetTopLevelWindow();
524c47aa
SC
2157 return tlw ? tlw->GetWXWindow() : NULL ;
2158}
2159
2160bool wxWindowMac::MacHasScrollBarCorner() const
2161{
11fed901 2162#if wxUSE_SCROLLBAR
524c47aa
SC
2163 /* Returns whether the scroll bars in a wxScrolledWindow should be
2164 * shortened. Scroll bars should be shortened if either:
2165 *
2166 * - both scroll bars are visible, or
2167 *
2168 * - there is a resize box in the parent frame's corner and this
2169 * window shares the bottom and right edge with the parent
2170 * frame.
2171 */
2172
2173 if ( m_hScrollBar == NULL && m_vScrollBar == NULL )
2174 return false;
2175
2176 if ( ( m_hScrollBar && m_hScrollBar->IsShown() )
2177 && ( m_vScrollBar && m_vScrollBar->IsShown() ) )
2178 {
2179 // Both scroll bars visible
2180 return true;
2181 }
2182 else
2183 {
2184 wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight();
2185
2186 for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() )
2187 {
2188 const wxFrame *frame = wxDynamicCast( win, wxFrame ) ;
2189 if ( frame )
2190 {
b206de32
SC
2191 // starting from 10.7 there are no resize indicators anymore
2192 if ( (frame->GetWindowStyleFlag() & wxRESIZE_BORDER) && UMAGetSystemVersion() < 0x1070)
524c47aa
SC
2193 {
2194 // Parent frame has resize handle
2195 wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight();
2196
2197 // Note: allow for some wiggle room here as wxMac's
2198 // window rect calculations seem to be imprecise
2199 if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2
2200 && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 )
2201 {
2202 // Parent frame has resize handle and shares
2203 // right bottom corner
2204 return true ;
2205 }
2206 else
2207 {
2208 // Parent frame has resize handle but doesn't
2209 // share right bottom corner
2210 return false ;
2211 }
2212 }
2213 else
2214 {
2215 // Parent frame doesn't have resize handle
2216 return false ;
2217 }
2218 }
2219 }
2220
2221 // No parent frame found
2222 return false ;
2223 }
11fed901
SC
2224#else
2225 return false;
2226#endif
524c47aa
SC
2227}
2228
2229void wxWindowMac::MacCreateScrollBars( long style )
2230{
11fed901 2231#if wxUSE_SCROLLBAR
524c47aa
SC
2232 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2233
2234 if ( style & ( wxVSCROLL | wxHSCROLL ) )
2235 {
2236 int scrlsize = MAC_SCROLLBAR_SIZE ;
2237 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
2238 {
2239 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
2240 }
2241
2242 int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ;
2243 int width, height ;
2244 GetClientSize( &width , &height ) ;
2245
2246 wxPoint vPoint(width - scrlsize, 0) ;
2247 wxSize vSize(scrlsize, height - adjust) ;
2248 wxPoint hPoint(0, height - scrlsize) ;
2249 wxSize hSize(width - adjust, scrlsize) ;
2250
2251 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2252 if ( style & wxVSCROLL )
2253 {
2254 m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL);
2255 m_vScrollBar->SetMinSize( wxDefaultSize );
2256 }
2257
2258 if ( style & wxHSCROLL )
2259 {
2260 m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
2261 m_hScrollBar->SetMinSize( wxDefaultSize );
2262 }
2ae3afa0
JS
2263
2264 wxPoint gPoint(width - scrlsize, height - scrlsize);
2265 wxSize gSize(scrlsize, scrlsize);
82f8ea85 2266 m_growBox = new wxBlindPlateWindow((wxWindow *)this, wxID_ANY, gPoint, gSize, 0);
524c47aa
SC
2267 }
2268
2269 // because the create does not take into account the client area origin
2270 // we might have a real position shift
2271 MacRepositionScrollBars() ;
11fed901 2272#endif
524c47aa
SC
2273}
2274
2275bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
2276{
11fed901
SC
2277 bool result = ((child == NULL)
2278#if wxUSE_SCROLLBAR
2ae3afa0 2279 || ((child != m_hScrollBar) && (child != m_vScrollBar) && (child != m_growBox))
11fed901
SC
2280#endif
2281 );
524c47aa
SC
2282
2283 return result ;
2284}
2285
2286void wxWindowMac::MacRepositionScrollBars()
2287{
11fed901 2288#if wxUSE_SCROLLBAR
524c47aa
SC
2289 if ( !m_hScrollBar && !m_vScrollBar )
2290 return ;
2291
2292 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
2293 int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ;
2294
2295 // get real client area
2296 int width, height ;
2297 GetSize( &width , &height );
2298
2299 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2300 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2301
2302 wxPoint vPoint( width - scrlsize, 0 ) ;
2303 wxSize vSize( scrlsize, height - adjust ) ;
2304 wxPoint hPoint( 0 , height - scrlsize ) ;
2305 wxSize hSize( width - adjust, scrlsize ) ;
2306
2307 if ( m_vScrollBar )
2308 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
2309 if ( m_hScrollBar )
2310 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
2ae3afa0
JS
2311 if ( m_growBox )
2312 {
2313 if ( MacHasScrollBarCorner() )
2314 {
2315 m_growBox->SetSize( width - scrlsize, height - scrlsize, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING );
2316 if ( !m_growBox->IsShown() )
2317 m_growBox->Show();
2318 }
2319 else
2320 {
2321 if ( m_growBox->IsShown() )
2322 m_growBox->Hide();
2323 }
2324 }
11fed901 2325#endif
524c47aa
SC
2326}
2327
2328bool wxWindowMac::AcceptsFocus() const
2329{
d15694e8 2330 if ( GetPeer() == NULL || GetPeer()->IsUserPane() )
f06e0fea
SC
2331 return wxWindowBase::AcceptsFocus();
2332 else
d15694e8 2333 return GetPeer()->CanFocus();
524c47aa
SC
2334}
2335
2336void wxWindowMac::MacSuperChangedPosition()
2337{
2338 // only window-absolute structures have to be moved i.e. controls
2339
2340 m_cachedClippedRectValid = false ;
2341
2342 wxWindowMac *child;
2343 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2344 while ( node )
2345 {
2346 child = node->GetData();
2347 child->MacSuperChangedPosition() ;
2348
2349 node = node->GetNext();
2350 }
2351}
2352
2353void wxWindowMac::MacTopLevelWindowChangedPosition()
2354{
2355 // only screen-absolute structures have to be moved i.e. glcanvas
2356
2357 wxWindowMac *child;
2358 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2359 while ( node )
2360 {
2361 child = node->GetData();
2362 child->MacTopLevelWindowChangedPosition() ;
2363
2364 node = node->GetNext();
2365 }
2366}
2367
54ea2834 2368long wxWindowMac::MacGetWXBorderSize() const
524c47aa
SC
2369{
2370 if ( IsTopLevel() )
2371 return 0 ;
2372
2373 SInt32 border = 0 ;
2374
d15694e8 2375 if ( GetPeer() && GetPeer()->NeedsFrame() )
524c47aa 2376 {
f2f6030e
SC
2377 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
2378 {
524c47aa 2379#if wxOSX_USE_COCOA_OR_CARBON
f2f6030e
SC
2380 // this metric is only the 'outset' outside the simple frame rect
2381 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2382 border += 1;
524c47aa 2383#else
f2f6030e 2384 border += 2;
524c47aa 2385#endif
f2f6030e
SC
2386 }
2387 else if (HasFlag(wxSIMPLE_BORDER))
2388 {
524c47aa 2389#if wxOSX_USE_COCOA_OR_CARBON
f2f6030e
SC
2390 // this metric is only the 'outset' outside the simple frame rect
2391 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2392 border += 1;
524c47aa 2393#else
f2f6030e 2394 border += 1;
524c47aa 2395#endif
f2f6030e 2396 }
524c47aa
SC
2397 }
2398
2399 return border ;
2400}
2401
54ea2834
SC
2402long wxWindowMac::MacGetLeftBorderSize() const
2403{
2404 // the wx borders are all symmetric in mac themes
2405 long border = MacGetWXBorderSize() ;
2406
d15694e8 2407 if ( GetPeer() )
54ea2834
SC
2408 {
2409 int left, top, right, bottom;
d15694e8 2410 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2411 border -= left;
2412 }
2413
2414 return border;
2415}
2416
2417
524c47aa
SC
2418long wxWindowMac::MacGetRightBorderSize() const
2419{
54ea2834
SC
2420 // the wx borders are all symmetric in mac themes
2421 long border = MacGetWXBorderSize() ;
2422
d15694e8 2423 if ( GetPeer() )
54ea2834
SC
2424 {
2425 int left, top, right, bottom;
d15694e8 2426 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2427 border -= right;
2428 }
2429
2430 return border;
524c47aa
SC
2431}
2432
2433long wxWindowMac::MacGetTopBorderSize() const
2434{
54ea2834
SC
2435 // the wx borders are all symmetric in mac themes
2436 long border = MacGetWXBorderSize() ;
2437
d15694e8 2438 if ( GetPeer() )
54ea2834
SC
2439 {
2440 int left, top, right, bottom;
d15694e8 2441 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2442 border -= top;
2443 }
2444
2445 return border;
524c47aa
SC
2446}
2447
2448long wxWindowMac::MacGetBottomBorderSize() const
2449{
54ea2834
SC
2450 // the wx borders are all symmetric in mac themes
2451 long border = MacGetWXBorderSize() ;
2452
d15694e8 2453 if ( GetPeer() )
54ea2834
SC
2454 {
2455 int left, top, right, bottom;
d15694e8 2456 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2457 border -= bottom;
2458 }
2459
2460 return border;
524c47aa
SC
2461}
2462
2463long wxWindowMac::MacRemoveBordersFromStyle( long style )
2464{
2465 return style & ~wxBORDER_MASK ;
2466}
2467
2468// Find the wxWindowMac at the current mouse position, returning the mouse
2469// position.
2470wxWindow * wxFindWindowAtPointer( wxPoint& pt )
2471{
2472 pt = wxGetMousePosition();
2473 wxWindowMac* found = wxFindWindowAtPoint(pt);
2474
2475 return (wxWindow*) found;
2476}
2477
2478// Get the current mouse position.
2479wxPoint wxGetMousePosition()
2480{
2481 int x, y;
2482
2483 wxGetMousePosition( &x, &y );
2484
2485 return wxPoint(x, y);
2486}
2487
2488void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2489{
2490 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2491 {
2492 // copied from wxGTK : CS
2493 // VZ: shouldn't we move this to base class then?
2494
2495 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2496 // except that:
2497 //
2498 // (a) it's a command event and so is propagated to the parent
2499 // (b) under MSW it can be generated from kbd too
2500 // (c) it uses screen coords (because of (a))
2501 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2502 this->GetId(),
2503 this->ClientToScreen(event.GetPosition()));
2504 evtCtx.SetEventObject(this);
2505 if ( ! HandleWindowEvent(evtCtx) )
2506 event.Skip() ;
2507 }
2508 else
2509 {
2510 event.Skip() ;
2511 }
2512}
2513
19c7ac3d 2514void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
524c47aa
SC
2515{
2516}
2517
2518Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2519{
2520 int x, y, w, h ;
2521
2522 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
0601befc 2523 Rect bounds = { static_cast<short>(y), static_cast<short>(x), static_cast<short>(y + h), static_cast<short>(x + w) };
524c47aa
SC
2524
2525 return bounds ;
2526}
2527
0faf03bf 2528bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec) )
524c47aa
SC
2529{
2530 return false;
2531}
2532
2533wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
2534{
2535#if wxOSX_USE_COCOA_OR_CARBON
4eb5a0ec 2536 if ( OSXHandleClicked( GetEventTime((EventRef)event) ) )
524c47aa 2537 return noErr;
69ce9cea 2538
524c47aa
SC
2539 return eventNotHandledErr ;
2540#else
2541 return 0;
2542#endif
2543}
2544
2545bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
2546{
2547 wxWindowMac *newParent = (wxWindowMac *)newParentBase;
2548 if ( !wxWindowBase::Reparent(newParent) )
2549 return false;
2550
d15694e8
SC
2551 GetPeer()->RemoveFromParent();
2552 GetPeer()->Embed( GetParent()->GetPeer() );
b80fdc02
JS
2553
2554 MacChildAdded();
524c47aa
SC
2555 return true;
2556}
2557
2558bool wxWindowMac::SetTransparent(wxByte alpha)
2559{
2560 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
2561
2562 if ( alpha != m_macAlpha )
2563 {
2564 m_macAlpha = alpha ;
2565 Refresh() ;
2566 }
2567 return true ;
2568}
2569
2570
2571bool wxWindowMac::CanSetTransparent()
2572{
2573 return true ;
2574}
2575
2576wxByte wxWindowMac::GetTransparent() const
2577{
2578 return m_macAlpha ;
2579}
2580
2581bool wxWindowMac::IsShownOnScreen() const
2582{
d15694e8 2583 if ( GetPeer() && GetPeer()->IsOk() )
524c47aa 2584 {
d15694e8 2585 bool peerVis = GetPeer()->IsVisible();
524c47aa
SC
2586 bool wxVis = wxWindowBase::IsShownOnScreen();
2587 if( peerVis != wxVis )
2588 {
2589 // CS : put a breakpoint here to investigate differences
2590 // between native an wx visibilities
2591 // the only place where I've encountered them until now
2592 // are the hiding/showing sequences where the vis-changed event is
2593 // first sent to the innermost control, while wx does things
2594 // from the outmost control
2595 wxVis = wxWindowBase::IsShownOnScreen();
2596 return wxVis;
2597 }
2598
d15694e8 2599 return GetPeer()->IsVisible();
524c47aa
SC
2600 }
2601 return wxWindowBase::IsShownOnScreen();
2602}
2603
c1313b54
SC
2604#if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2605
97d5c7a3
VZ
2606OSStatus
2607wxHotKeyHandler(EventHandlerCallRef WXUNUSED(nextHandler),
2608 EventRef event,
2609 void* WXUNUSED(userData))
c1313b54
SC
2610{
2611 EventHotKeyID hotKeyId;
2612
2613 GetEventParameter( event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(hotKeyId), NULL, &hotKeyId);
2614
97d5c7a3 2615 for ( unsigned i = 0; i < s_hotkeys.size(); ++i )
c1313b54 2616 {
97d5c7a3 2617 if ( s_hotkeys[i].keyId == static_cast<int>(hotKeyId.id) )
c1313b54
SC
2618 {
2619 unsigned char charCode ;
2620 UInt32 keyCode ;
2621 UInt32 modifiers ;
c1313b54
SC
2622 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
2623
784d9056 2624 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode );
c1313b54
SC
2625 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
2626 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
c1313b54
SC
2627
2628 UInt32 keymessage = (keyCode << 8) + charCode;
2629
2630 wxKeyEvent wxevent(wxEVT_HOTKEY);
2631 wxevent.SetId(hotKeyId.id);
2632 wxTheApp->MacCreateKeyEvent( wxevent, s_hotkeys[i].window , keymessage ,
723aa01a 2633 modifiers , when , 0 ) ;
c1313b54
SC
2634
2635 s_hotkeys[i].window->HandleWindowEvent(wxevent);
2636 }
2637 }
2638
2639 return noErr;
2640}
2641
2642bool wxWindowMac::RegisterHotKey(int hotkeyId, int modifiers, int keycode)
2643{
97d5c7a3 2644 for ( unsigned i = 0; i < s_hotkeys.size(); ++i )
c1313b54
SC
2645 {
2646 if ( s_hotkeys[i].keyId == hotkeyId )
2647 {
2648 wxLogLastError(wxT("hotkeyId already registered"));
2649
2650 return false;
2651 }
2652 }
2653
2654 static bool installed = false;
2655 if ( !installed )
2656 {
2657 EventTypeSpec eventType;
2658 eventType.eventClass=kEventClassKeyboard;
2659 eventType.eventKind=kEventHotKeyPressed;
2660
2661 InstallApplicationEventHandler(&wxHotKeyHandler, 1, &eventType, NULL, NULL);
2662 installed = true;
2663 }
2664
2665 UInt32 mac_modifiers=0;
2666 if ( modifiers & wxMOD_ALT )
2667 mac_modifiers |= optionKey;
2668 if ( modifiers & wxMOD_SHIFT )
2669 mac_modifiers |= shiftKey;
3c5f6264 2670 if ( modifiers & wxMOD_RAW_CONTROL )
c1313b54 2671 mac_modifiers |= controlKey;
3c5f6264 2672 if ( modifiers & wxMOD_CONTROL )
c1313b54
SC
2673 mac_modifiers |= cmdKey;
2674
2675 EventHotKeyRef hotKeyRef;
2676 EventHotKeyID hotKeyIDmac;
2677
2678 hotKeyIDmac.signature = 'WXMC';
2679 hotKeyIDmac.id = hotkeyId;
2680
2681 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode)keycode), mac_modifiers, hotKeyIDmac,
2682 GetApplicationEventTarget(), 0, &hotKeyRef) != noErr )
2683 {
2684 wxLogLastError(wxT("RegisterHotKey"));
2685
2686 return false;
2687 }
2688 else
2689 {
2690 wxHotKeyRec v;
2691 v.ref = hotKeyRef;
2692 v.keyId = hotkeyId;
2693 v.window = this;
2694
2695 s_hotkeys.push_back(v);
2696 }
2697
2698 return true;
2699}
2700
2701bool wxWindowMac::UnregisterHotKey(int hotkeyId)
2702{
977b5d7d 2703 for ( int i = ((int)s_hotkeys.size())-1; i>=0; -- i )
c1313b54
SC
2704 {
2705 if ( s_hotkeys[i].keyId == hotkeyId )
2706 {
2707 EventHotKeyRef ref = s_hotkeys[i].ref;
2708 s_hotkeys.erase(s_hotkeys.begin() + i);
2709 if ( UnregisterEventHotKey(ref) != noErr )
2710 {
2711 wxLogLastError(wxT("UnregisterHotKey"));
2712
2713 return false;
2714 }
2715 else
2716 return true;
2717 }
2718 }
2719
2720 return false;
2721}
2722
2723#endif // wxUSE_HOTKEY
2724
4eb5a0ec 2725bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event )
19c7ac3d 2726{
ba950d44
SC
2727 bool handled = false;
2728
2729 // moved the ordinary key event sending AFTER the accel evaluation
19c7ac3d
SC
2730
2731#if wxUSE_ACCEL
2732 if ( !handled && event.GetEventType() == wxEVT_KEY_DOWN)
2733 {
2734 wxWindow *ancestor = this;
2735 while (ancestor)
2736 {
2737 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
2738 if (command != -1)
2739 {
2740 wxEvtHandler * const handler = ancestor->GetEventHandler();
2741
ce7fe42e 2742 wxCommandEvent command_event( wxEVT_MENU, command );
19c7ac3d
SC
2743 handled = handler->ProcessEvent( command_event );
2744
2745 if ( !handled )
2746 {
2747 // accelerators can also be used with buttons, try them too
ce7fe42e 2748 command_event.SetEventType(wxEVT_BUTTON);
19c7ac3d
SC
2749 handled = handler->ProcessEvent( command_event );
2750 }
2751
2752 break;
2753 }
2754
2755 if (ancestor->IsTopLevel())
2756 break;
2757
2758 ancestor = ancestor->GetParent();
2759 }
2760 }
2761#endif // wxUSE_ACCEL
ba950d44
SC
2762
2763 if ( !handled )
2764 {
2765 handled = HandleWindowEvent( event ) ;
2766 if ( handled && event.GetSkipped() )
2767 handled = false ;
2768 }
19c7ac3d
SC
2769
2770 return handled ;
2771}
2772
524c47aa 2773//
69ce9cea 2774// wxWidgetImpl
524c47aa
SC
2775//
2776
3678169c
SC
2777// we are maintaining a n:1 map from native controls (ControlRef / NSView*) to their wxWidgetImpl
2778// n:1 because we might have an embedded view eg within a scrollview, both being part of the same impl
2779// the impl is calling Associate with its newly created native control(s), e.g. in InstallHandler
2780
f55d9f74
SC
2781WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap);
2782
2783static MacControlMap wxWinMacControlList;
2784
2785wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
2786{
2787 wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl );
2788 if ( impl )
2789 return impl->GetWXPeer();
69ce9cea 2790
f55d9f74
SC
2791 return NULL;
2792}
2793
2794wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl )
2795{
2796 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
2797
2798 return (node == wxWinMacControlList.end()) ? NULL : node->second;
2799}
2800
2801void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl)
2802{
2803 // adding NULL ControlRef is (first) surely a result of an error and
2804 // (secondly) breaks native event processing
2805 wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") );
2806
2807 wxWinMacControlList[inControl] = impl;
2808}
2809
2810void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl)
2811{
2812 // iterate over all the elements in the class
2813 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2814 // we should go on...
2815
2816 bool found = true ;
2817 while ( found )
2818 {
2819 found = false ;
2820 MacControlMap::iterator it;
2821 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
2822 {
2823 if ( it->second == impl )
2824 {
2825 wxWinMacControlList.erase(it);
2826 found = true ;
2827 break;
2828 }
2829 }
2830 }
2831}
2832
524c47aa
SC
2833IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
2834
415f4a01 2835wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane )
524c47aa
SC
2836{
2837 Init();
2838 m_isRootControl = isRootControl;
415f4a01 2839 m_isUserPane = isUserPane;
524c47aa 2840 m_wxPeer = peer;
809020fc 2841 m_shouldSendEvents = true;
524c47aa
SC
2842}
2843
2844wxWidgetImpl::wxWidgetImpl()
2845{
2846 Init();
2847}
2848
2849wxWidgetImpl::~wxWidgetImpl()
2850{
2851}
2852
2853void wxWidgetImpl::Init()
2854{
2855 m_isRootControl = false;
2856 m_wxPeer = NULL;
2857 m_needsFocusRect = false;
f2f6030e 2858 m_needsFrame = true;
524c47aa
SC
2859}
2860
2861void wxWidgetImpl::SetNeedsFocusRect( bool needs )
2862{
2863 m_needsFocusRect = needs;
2864}
2865
2866bool wxWidgetImpl::NeedsFocusRect() const
2867{
2868 return m_needsFocusRect;
2869}
2870
f2f6030e
SC
2871void wxWidgetImpl::SetNeedsFrame( bool needs )
2872{
2873 m_needsFrame = needs;
2874}
2875
2876bool wxWidgetImpl::NeedsFrame() const
2877{
2878 return m_needsFrame;
2879}
2ab38025
SC
2880
2881void wxWidgetImpl::SetDrawingEnabled(bool WXUNUSED(enabled))
2882{
2392a466 2883}