LibreOffice Module chart2 (master) 1
ChartWindow.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_wasm_strip.h>
21#include <ChartWindow.hxx>
22#include <ChartController.hxx>
23#include <helpids.h>
24#include <uiobject.hxx>
25
26#include <vcl/help.hxx>
27#include <vcl/settings.hxx>
28
29#include <sfx2/ipclient.hxx>
30#include <sfx2/viewsh.hxx>
31#include <sfx2/lokhelper.hxx>
32#include <comphelper/lok.hxx>
33
34using namespace ::com::sun::star;
35
36namespace
37{
38::tools::Rectangle lcl_AWTRectToVCLRect( const css::awt::Rectangle & rAWTRect )
39{
40 ::tools::Rectangle aResult(rAWTRect.X, rAWTRect.Y);
41 aResult.setWidth( rAWTRect.Width );
42 aResult.setHeight( rAWTRect.Height );
43 return aResult;
44}
45} // anonymous namespace
46
47namespace chart
48{
49
51 : Window(pParent, nStyle)
52 , m_pWindowController( pController )
53 , m_bInPaint(false)
54 , m_pViewShellWindow( nullptr )
55{
56 set_id("chart_window");
58 SetMapMode( MapMode(MapUnit::Map100thMM) );
60 // chart does not depend on exact pixel painting => enable antialiased drawing
61 GetOutDev()->SetAntialiasing( AntialiasingFlags::Enable | GetOutDev()->GetAntialiasing() );
62 EnableRTL( false );
63 if( pParent )
64 pParent->EnableRTL( false );// #i96215# necessary for a correct position of the context menu in rtl mode
65}
66
68{
70}
71
73{
74 m_pWindowController = nullptr;
77}
78
80{
81 // forward VCLs PrePaint window event to DrawingLayer
83 {
85 }
86}
87
88void ChartWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
89{
90 if (comphelper::LibreOfficeKit::isActive() && !rRenderContext.IsVirtual())
91 return;
92
93 m_bInPaint = true;
95 {
96 m_pWindowController->execute_Paint(rRenderContext, rRect);
97 }
98 else
99 {
100 Window::Paint(rRenderContext, rRect);
101 }
102 m_bInPaint = false;
103}
104
106{
109 else
110 Window::MouseButtonDown(rMEvt);
111}
112
114{
117 else
118 Window::MouseMove( rMEvt );
119}
120
122{
124 Window::Tracking( rTEvt );
125}
126
128{
131 else
132 Window::MouseButtonUp( rMEvt );
133}
134
136{
139 else
140 Window::Resize();
141}
142
144{
146 Window::Activate();
147}
149{
151 Window::Deactivate();
152}
154{
156 Window::GetFocus();
157}
159{
161 Window::LoseFocus();
162}
163
165{
168 else
169 Window::Command( rCEvt );
170}
171
172void ChartWindow::KeyInput( const KeyEvent& rKEvt )
173{
175 {
177 Window::KeyInput(rKEvt);
178 }
179 else
180 Window::KeyInput( rKEvt );
181}
182
184{
185#if !ENABLE_WASM_STRIP_ACCESSIBILITY
188 else
189 return Window::CreateAccessible();
190#else
192#endif
193}
194
196{
197 vcl::Window::DataChanged( rDCEvt );
198
199 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
200 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
201 {
203 }
204}
205
207{
208 bool bHelpHandled = false;
209 if( ( rHEvt.GetMode() & HelpEventMode::QUICK ) &&
211 {
212 Point aLogicHitPos = PixelToLogic( GetPointerPosPixel());
213 OUString aQuickHelpText;
214 awt::Rectangle aHelpRect;
215 bool bIsBalloonHelp( Help::IsBalloonHelpEnabled() );
216 bHelpHandled = m_pWindowController->requestQuickHelp( aLogicHitPos, bIsBalloonHelp, aQuickHelpText, aHelpRect );
217
218 if( bHelpHandled )
219 {
220 tools::Rectangle aPixelRect(LogicToPixel(lcl_AWTRectToVCLRect(aHelpRect)));
221 tools::Rectangle aScreenRect(OutputToScreenPixel(aPixelRect.TopLeft()),
222 OutputToScreenPixel(aPixelRect.BottomRight()));
223
224 if( bIsBalloonHelp )
225 Help::ShowBalloon(this, rHEvt.GetMousePosPixel(), aScreenRect, aQuickHelpText);
226 else
227 Help::ShowQuickHelp(this, aScreenRect, aQuickHelpText);
228 }
229 }
230
231 if( !bHelpHandled )
233}
234
236{
237 static const DrawModeFlags nContrastMode =
238 DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill |
239 DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient;
240
241 bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
242 GetOutDev()->SetDrawMode( bUseContrast ? nContrastMode : DrawModeFlags::Default );
243}
244
246{
248}
250{
251 if( m_bInPaint ) // #i101928# superfluous paint calls while entering and editing charts"
252 return;
253 vcl::Window::ImplInvalidate( rRegion, nFlags );
254}
255
257{
258 SfxViewShell* pCurrentShell = SfxViewShell::Current();
259 if ( nullptr == pCurrentShell )
260 return;
261 tools::Rectangle aResultRectangle;
262 if (!pRectangle)
263 {
264 // we have to invalidate the whole chart area not the whole document
265 aResultRectangle = GetBoundingBox();
266 }
267 else
268 {
269 tools::Rectangle aRectangle(*pRectangle);
270 // When dragging shapes the map mode is disabled.
271 if (IsMapModeEnabled())
272 {
273 if (GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
274 {
275 aRectangle = o3tl::convert(aRectangle, o3tl::Length::mm100, o3tl::Length::twip);
276 }
277 }
278 else
279 {
280 aRectangle = PixelToLogic(aRectangle, MapMode(MapUnit::MapTwip));
281 }
282
283 vcl::Window* pEditWin = GetParentEditWin();
284 if (pEditWin)
285 {
286 MapMode aCWMapMode = GetMapMode();
287 constexpr auto p = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip);
288 const auto& scaleX = aCWMapMode.GetScaleX();
289 const auto& scaleY = aCWMapMode.GetScaleY();
290 const auto nXNum = p.first * scaleX.GetDenominator();
291 const auto nXDen = p.second * scaleX.GetNumerator();
292 const auto nYNum = p.first * scaleY.GetDenominator();
293 const auto nYDen = p.second * scaleY.GetNumerator();
294
295 if (!IsMapModeEnabled())
296 {
297 aRectangle = aRectangle.scale(scaleX.GetDenominator(), scaleX.GetNumerator(),
298 scaleY.GetDenominator(), scaleY.GetNumerator());
299 }
300
301 Point aOffset = this->GetOffsetPixelFrom(*pEditWin).scale(nXNum, nXDen, nYNum, nYDen);
302
303 aRectangle = tools::Rectangle(aRectangle.TopLeft() + aOffset, aRectangle.GetSize());
304 }
305
306 aResultRectangle = aRectangle;
307 }
308 SfxLokHelper::notifyInvalidation(pCurrentShell, &aResultRectangle);
309}
310
312{
314}
315
317{
318 return m_pWindowController;
319}
320
322{
324 return m_pViewShellWindow.get();
325
326 // So, you are thinking, why do not invoke pCurrentShell->GetWindow() ?
327 // Because in Impress the parent edit win is not view shell window.
328 SfxViewShell* pCurrentShell = SfxViewShell::Current();
329 if( pCurrentShell )
330 {
331 SfxInPlaceClient* pIPClient = pCurrentShell->GetIPClient();
332 if (pIPClient)
333 {
334 vcl::Window* pRootWin = pIPClient->GetEditWin();
335 if(pRootWin && pRootWin->IsAncestorOf(*this))
336 {
337 m_pViewShellWindow = pRootWin;
338 return m_pViewShellWindow.get();
339 }
340 }
341 }
342 return nullptr;
343}
344
346{
347 tools::Rectangle aBBox;
348
349 vcl::Window* pRootWin = GetParentEditWin();
350 if (pRootWin)
351 {
352 // In all cases, the following code fragment
353 // returns the chart bounding box in twips.
354 MapMode aCWMapMode = GetMapMode();
355 constexpr auto p = o3tl::getConversionMulDiv(o3tl::Length::px, o3tl::Length::twip);
356 const auto& scaleX = aCWMapMode.GetScaleX();
357 const auto& scaleY = aCWMapMode.GetScaleY();
358 const auto nXNum = p.first * scaleX.GetDenominator();
359 const auto nXDen = p.second * scaleX.GetNumerator();
360 const auto nYNum = p.first * scaleY.GetDenominator();
361 const auto nYDen = p.second * scaleY.GetNumerator();
362
363 Point aOffset = GetOffsetPixelFrom(*pRootWin);
364 aOffset.setX( o3tl::convert(aOffset.X(), nXNum, nXDen) );
365 aOffset.setY( o3tl::convert(aOffset.Y(), nYNum, nYDen) );
366 Size aSize = GetSizePixel();
367 aSize.setWidth( o3tl::convert(aSize.Width(), nXNum, nXDen) );
368 aSize.setHeight( o3tl::convert(aSize.Height(), nYNum, nYDen) );
369 aBBox = tools::Rectangle(aOffset, aSize);
370 }
371 return aBBox;
372}
373
374} //namespace chart
375
376/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawModeFlags
const StyleSettings & GetStyleSettings() const
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:189
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
HelpEventMode GetMode() const
const Point & GetMousePosPixel() const
static bool IsBalloonHelpEnabled()
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
const Fraction & GetScaleX() const
const Fraction & GetScaleY() const
void SetAntialiasing(AntialiasingFlags nMode)
void SetDrawMode(DrawModeFlags nDrawMode)
virtual bool IsVirtual() const
constexpr tools::Long Y() const
void setX(tools::Long nX)
constexpr Point scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
void setY(tools::Long nY)
constexpr tools::Long X() const
vcl::Window * GetEditWin() const
static void notifyInvalidation(SfxViewShell const *pThisView, tools::Rectangle const *)
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
SfxInPlaceClient * GetIPClient() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
bool GetHighContrastMode() const
void clear()
reference_type * get() const
bool execute_KeyInput(const KeyEvent &rKEvt)
css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
void execute_MouseButtonUp(const MouseEvent &rMEvt)
bool requestQuickHelp(::Point aAtLogicPosition, bool bIsBalloonHelp, OUString &rOutQuickHelpText, css::awt::Rectangle &rOutEqualRect)
get help text to be shown in a quick help
void execute_MouseButtonDown(const MouseEvent &rMEvt)
void execute_Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
void execute_Command(const CommandEvent &rCEvt)
void execute_MouseMove(const MouseEvent &rMEvt)
ChartWindow(ChartController *pController, vcl::Window *pParent, WinBits nStyle)
Definition: ChartWindow.cxx:50
VclPtr< vcl::Window > m_pViewShellWindow
Definition: ChartWindow.hxx:77
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: ChartWindow.cxx:88
ChartController * GetController()
virtual void ImplInvalidate(const vcl::Region *rRegion, InvalidateFlags nFlags) override
virtual void Deactivate() override
virtual void Command(const CommandEvent &rCEvt) override
virtual FactoryFunction GetUITestFactory() const override
virtual void Activate() override
void adjustHighContrastMode()
virtual void Tracking(const TrackingEvent &rTEvt) override
virtual ~ChartWindow() override
Definition: ChartWindow.cxx:67
virtual void LoseFocus() override
virtual void MouseMove(const MouseEvent &rMEvt) override
virtual void PrePaint(vcl::RenderContext &rRenderContext) override
Definition: ChartWindow.cxx:79
virtual void GetFocus() override
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
ChartController * m_pWindowController
Definition: ChartWindow.hxx:75
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
tools::Rectangle GetBoundingBox()
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
virtual void dispose() override
Definition: ChartWindow.cxx:72
vcl::Window * GetParentEditWin()
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
virtual void Resize() override
virtual void LogicInvalidate(const tools::Rectangle *pRectangle) override
Notify the LOK client about an invalidated area.
virtual void KeyInput(const KeyEvent &rKEvt) override
virtual void RequestHelp(const HelpEvent &rHEvt) override
constexpr Point TopLeft() const
constexpr Size GetSize() const
constexpr Point BottomRight() const
constexpr tools::Rectangle scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const
Point OutputToScreenPixel(const Point &rPos) const
virtual void dispose() override
virtual void RequestHelp(const HelpEvent &rHEvt)
Point LogicToPixel(const Point &rLogicPt) const
Point GetOffsetPixelFrom(const vcl::Window &rWindow) const
void set_id(const OUString &rID)
virtual void EnableRTL(bool bEnable=true)
void SetMapMode()
bool IsMapModeEnabled() const
const AllSettings & GetSettings() const
const MapMode & GetMapMode() const
::OutputDevice const * GetOutDev() const
Point PixelToLogic(const Point &rDevicePt) const
virtual Size GetSizePixel() const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Point GetPointerPosPixel()
virtual void ImplInvalidate(const vcl::Region *pRegion, InvalidateFlags nFlags)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
bool IsAncestorOf(const vcl::Window &rWindow) const
void SetHelpId(const OUString &)
constexpr OUStringLiteral HID_SCH_WIN_DOCUMENT
Definition: helpids.h:24
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
void * p
MapUnit GetMapUnit()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
InvalidateFlags
sal_Int64 WinBits