1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ChartWindow.hxx"
21 #include "ChartController.hxx"
22 #include "HelpIds.hrc"
24 #include <vcl/help.hxx>
25 #include <vcl/openglwin.hxx>
26 #include <vcl/settings.hxx>
28 #include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
30 using namespace ::com::sun::star
;
34 ::Rectangle
lcl_AWTRectToVCLRect( const ::com::sun::star::awt::Rectangle
& rAWTRect
)
37 aResult
.setX( rAWTRect
.X
);
38 aResult
.setY( rAWTRect
.Y
);
39 aResult
.setWidth( rAWTRect
.Width
);
40 aResult
.setHeight( rAWTRect
.Height
);
43 } // anonymous namespace
48 ChartWindow::ChartWindow( ChartController
* pController
, vcl::Window
* pParent
, WinBits nStyle
)
49 : Window(pParent
, nStyle
)
50 , m_pWindowController( pController
)
52 , m_pOpenGLWindow(VclPtr
<OpenGLWindow
>::Create(this))
54 this->SetHelpId( HID_SCH_WIN_DOCUMENT
);
55 this->SetMapMode( MapMode(MAP_100TH_MM
) );
56 adjustHighContrastMode();
57 // chart does not depend on exact pixel painting => enable antialiased drawing
58 SetAntialiasing( AntialiasingFlags::EnableB2dDraw
| GetAntialiasing() );
61 pParent
->EnableRTL( false );// #i96215# necessary for a correct position of the context menu in rtl mode
65 m_pOpenGLWindow
->Show();
66 uno::Reference
< chart2::X3DChartWindowProvider
> x3DWindowProvider(pController
->getModel(), uno::UNO_QUERY_THROW
);
67 sal_uInt64 nWindowPtr
= reinterpret_cast<sal_uInt64
>(m_pOpenGLWindow
.get());
68 x3DWindowProvider
->setWindow(nWindowPtr
);
69 uno::Reference
<util::XUpdatable
> const xUpdatable(x3DWindowProvider
,
70 uno::UNO_QUERY_THROW
);
75 ChartWindow::~ChartWindow()
80 void ChartWindow::dispose()
82 if (m_pWindowController
&& m_pWindowController
->getModel().is())
84 uno::Reference
< chart2::X3DChartWindowProvider
> x3DWindowProvider(m_pWindowController
->getModel(), uno::UNO_QUERY_THROW
);
85 x3DWindowProvider
->setWindow(0);
86 uno::Reference
<util::XUpdatable
> const xUpdatable(x3DWindowProvider
,
87 uno::UNO_QUERY_THROW
);
90 m_pOpenGLWindow
.disposeAndClear();
91 vcl::Window::dispose();
94 void ChartWindow::clear()
96 m_pWindowController
=0;
100 void ChartWindow::PrePaint(vcl::RenderContext
& rRenderContext
)
102 // forward VCLs PrePaint window event to DrawingLayer
103 if (m_pWindowController
)
105 m_pWindowController
->PrePaint(rRenderContext
);
109 void ChartWindow::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
112 if (m_pOpenGLWindow
&& m_pOpenGLWindow
->IsVisible())
114 m_pOpenGLWindow
->Paint(rRenderContext
, rRect
);
116 else if (m_pWindowController
)
118 m_pWindowController
->execute_Paint(rRenderContext
, rRect
);
122 Window::Paint(rRenderContext
, rRect
);
127 void ChartWindow::MouseButtonDown(const MouseEvent
& rMEvt
)
129 if( m_pWindowController
)
130 m_pWindowController
->execute_MouseButtonDown(rMEvt
);
132 Window::MouseButtonDown(rMEvt
);
135 void ChartWindow::MouseMove( const MouseEvent
& rMEvt
)
137 if( m_pWindowController
)
138 m_pWindowController
->execute_MouseMove( rMEvt
);
140 Window::MouseMove( rMEvt
);
143 void ChartWindow::Tracking( const TrackingEvent
& rTEvt
)
145 if( m_pWindowController
)
146 m_pWindowController
->execute_Tracking( rTEvt
);
148 Window::Tracking( rTEvt
);
151 void ChartWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
153 if( m_pWindowController
)
154 m_pWindowController
->execute_MouseButtonUp( rMEvt
);
156 Window::MouseButtonUp( rMEvt
);
159 void ChartWindow::Resize()
161 if( m_pWindowController
)
162 m_pWindowController
->execute_Resize();
166 if( m_pOpenGLWindow
)
167 m_pOpenGLWindow
->SetSizePixel(GetSizePixel());
170 void ChartWindow::Activate()
172 if( m_pWindowController
)
173 m_pWindowController
->execute_Activate();
177 void ChartWindow::Deactivate()
179 if( m_pWindowController
)
180 m_pWindowController
->execute_Deactivate();
182 Window::Deactivate();
184 void ChartWindow::GetFocus()
186 if( m_pWindowController
)
187 m_pWindowController
->execute_GetFocus();
191 void ChartWindow::LoseFocus()
193 if( m_pWindowController
)
194 m_pWindowController
->execute_LoseFocus();
199 void ChartWindow::Command( const CommandEvent
& rCEvt
)
201 if( m_pWindowController
)
202 m_pWindowController
->execute_Command( rCEvt
);
204 Window::Command( rCEvt
);
207 void ChartWindow::KeyInput( const KeyEvent
& rKEvt
)
209 if( m_pWindowController
)
211 if( !m_pWindowController
->execute_KeyInput(rKEvt
) )
212 Window::KeyInput(rKEvt
);
215 Window::KeyInput( rKEvt
);
218 uno::Reference
< css::accessibility::XAccessible
> ChartWindow::CreateAccessible()
220 if( m_pWindowController
)
221 return m_pWindowController
->CreateAccessible();
223 return Window::CreateAccessible();
226 void ChartWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
228 vcl::Window::DataChanged( rDCEvt
);
230 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
231 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
233 adjustHighContrastMode();
237 void ChartWindow::RequestHelp( const HelpEvent
& rHEvt
)
239 bool bHelpHandled
= false;
240 if( ( rHEvt
.GetMode() & HelpEventMode::QUICK
) &&
241 m_pWindowController
)
243 // Point aLogicHitPos = PixelToLogic( rHEvt.GetMousePosPixel()); // old chart: GetPointerPosPixel()
244 Point aLogicHitPos
= PixelToLogic( GetPointerPosPixel());
245 OUString aQuickHelpText
;
246 awt::Rectangle aHelpRect
;
247 bool bIsBalloonHelp( Help::IsBalloonHelpEnabled() );
248 bHelpHandled
= m_pWindowController
->requestQuickHelp( aLogicHitPos
, bIsBalloonHelp
, aQuickHelpText
, aHelpRect
);
254 this, rHEvt
.GetMousePosPixel(), lcl_AWTRectToVCLRect( aHelpRect
), aQuickHelpText
);
257 this, lcl_AWTRectToVCLRect( aHelpRect
), aQuickHelpText
);
262 vcl::Window::RequestHelp( rHEvt
);
265 void ChartWindow::adjustHighContrastMode()
267 static const DrawModeFlags nContrastMode
=
268 DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
|
269 DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
;
271 bool bUseContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
272 SetDrawMode( bUseContrast
? nContrastMode
: DrawModeFlags::Default
);
275 void ChartWindow::ForceInvalidate()
277 vcl::Window::Invalidate();
280 m_pOpenGLWindow
->Invalidate();
283 void ChartWindow::Invalidate( sal_uInt16 nFlags
)
285 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
287 vcl::Window::Invalidate( nFlags
);
290 m_pOpenGLWindow
->Invalidate( nFlags
);
293 void ChartWindow::Invalidate( const Rectangle
& rRect
, sal_uInt16 nFlags
)
295 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
297 vcl::Window::Invalidate( rRect
, nFlags
);
300 m_pOpenGLWindow
->Invalidate( rRect
, nFlags
);
303 void ChartWindow::Invalidate( const vcl::Region
& rRegion
, sal_uInt16 nFlags
)
305 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
307 vcl::Window::Invalidate( rRegion
, nFlags
);
310 m_pOpenGLWindow
->Invalidate( rRegion
, nFlags
);
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */