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