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>
23 #include <uiobject.hxx>
25 #include <vcl/help.hxx>
26 #include <vcl/settings.hxx>
28 #include <sfx2/ipclient.hxx>
29 #include <sfx2/viewsh.hxx>
30 #include <sfx2/lokhelper.hxx>
31 #include <comphelper/lok.hxx>
33 #define TWIPS_PER_PIXEL 15
35 using namespace ::com::sun::star
;
39 ::tools::Rectangle
lcl_AWTRectToVCLRect( const css::awt::Rectangle
& rAWTRect
)
41 ::tools::Rectangle aResult
;
42 aResult
.setX( rAWTRect
.X
);
43 aResult
.setY( rAWTRect
.Y
);
44 aResult
.setWidth( rAWTRect
.Width
);
45 aResult
.setHeight( rAWTRect
.Height
);
48 } // anonymous namespace
53 ChartWindow::ChartWindow( ChartController
* pController
, vcl::Window
* pParent
, WinBits nStyle
)
54 : Window(pParent
, nStyle
)
55 , m_pWindowController( pController
)
57 , m_pViewShellWindow( nullptr )
59 set_id("chart_window");
60 SetHelpId( HID_SCH_WIN_DOCUMENT
);
61 SetMapMode( MapMode(MapUnit::Map100thMM
) );
62 adjustHighContrastMode();
63 // chart does not depend on exact pixel painting => enable antialiased drawing
64 SetAntialiasing( AntialiasingFlags::EnableB2dDraw
| GetAntialiasing() );
67 pParent
->EnableRTL( false );// #i96215# necessary for a correct position of the context menu in rtl mode
70 ChartWindow::~ChartWindow()
75 void ChartWindow::dispose()
77 m_pViewShellWindow
.clear();
78 vcl::Window::dispose();
81 void ChartWindow::PrePaint(vcl::RenderContext
& )
83 // forward VCLs PrePaint window event to DrawingLayer
84 if (m_pWindowController
)
86 m_pWindowController
->PrePaint();
90 void ChartWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
92 if (comphelper::LibreOfficeKit::isActive() && !rRenderContext
.IsVirtual())
96 if (m_pWindowController
)
98 m_pWindowController
->execute_Paint(rRenderContext
, rRect
);
102 Window::Paint(rRenderContext
, rRect
);
107 void ChartWindow::MouseButtonDown(const MouseEvent
& rMEvt
)
109 if( m_pWindowController
)
110 m_pWindowController
->execute_MouseButtonDown(rMEvt
);
112 Window::MouseButtonDown(rMEvt
);
115 void ChartWindow::MouseMove( const MouseEvent
& rMEvt
)
117 if( m_pWindowController
)
118 m_pWindowController
->execute_MouseMove( rMEvt
);
120 Window::MouseMove( rMEvt
);
123 void ChartWindow::Tracking( const TrackingEvent
& rTEvt
)
125 if( !m_pWindowController
)
126 Window::Tracking( rTEvt
);
129 void ChartWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
131 if( m_pWindowController
)
132 m_pWindowController
->execute_MouseButtonUp( rMEvt
);
134 Window::MouseButtonUp( rMEvt
);
137 void ChartWindow::Resize()
139 if( m_pWindowController
)
140 m_pWindowController
->execute_Resize();
145 void ChartWindow::Activate()
147 if( !m_pWindowController
)
150 void ChartWindow::Deactivate()
152 if( !m_pWindowController
)
153 Window::Deactivate();
155 void ChartWindow::GetFocus()
157 if( !m_pWindowController
)
160 void ChartWindow::LoseFocus()
162 if( !m_pWindowController
)
166 void ChartWindow::Command( const CommandEvent
& rCEvt
)
168 if( m_pWindowController
)
169 m_pWindowController
->execute_Command( rCEvt
);
171 Window::Command( rCEvt
);
174 void ChartWindow::KeyInput( const KeyEvent
& rKEvt
)
176 if( m_pWindowController
)
178 if( !m_pWindowController
->execute_KeyInput(rKEvt
) )
179 Window::KeyInput(rKEvt
);
182 Window::KeyInput( rKEvt
);
185 uno::Reference
< css::accessibility::XAccessible
> ChartWindow::CreateAccessible()
187 if( m_pWindowController
)
188 return m_pWindowController
->CreateAccessible();
190 return Window::CreateAccessible();
193 void ChartWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
195 vcl::Window::DataChanged( rDCEvt
);
197 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
198 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
200 adjustHighContrastMode();
204 void ChartWindow::RequestHelp( const HelpEvent
& rHEvt
)
206 bool bHelpHandled
= false;
207 if( ( rHEvt
.GetMode() & HelpEventMode::QUICK
) &&
208 m_pWindowController
)
210 // Point aLogicHitPos = PixelToLogic( rHEvt.GetMousePosPixel()); // old chart: GetPointerPosPixel()
211 Point aLogicHitPos
= PixelToLogic( GetPointerPosPixel());
212 OUString aQuickHelpText
;
213 awt::Rectangle aHelpRect
;
214 bool bIsBalloonHelp( Help::IsBalloonHelpEnabled() );
215 bHelpHandled
= m_pWindowController
->requestQuickHelp( aLogicHitPos
, bIsBalloonHelp
, aQuickHelpText
, aHelpRect
);
221 this, rHEvt
.GetMousePosPixel(), lcl_AWTRectToVCLRect( aHelpRect
), aQuickHelpText
);
224 this, lcl_AWTRectToVCLRect( aHelpRect
), aQuickHelpText
);
229 vcl::Window::RequestHelp( rHEvt
);
232 void ChartWindow::LogicMouseButtonDown(const MouseEvent
& rEvent
)
234 MouseButtonDown(rEvent
);
237 void ChartWindow::LogicMouseButtonUp(const MouseEvent
& rEvent
)
239 MouseButtonUp(rEvent
);
242 void ChartWindow::LogicMouseMove(const MouseEvent
& rEvent
)
247 void ChartWindow::adjustHighContrastMode()
249 static const DrawModeFlags nContrastMode
=
250 DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
|
251 DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
;
253 bool bUseContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
254 SetDrawMode( bUseContrast
? nContrastMode
: DrawModeFlags::Default
);
257 void ChartWindow::ForceInvalidate()
259 vcl::Window::Invalidate();
261 void ChartWindow::Invalidate( InvalidateFlags nFlags
)
263 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
265 vcl::Window::Invalidate( nFlags
);
267 void ChartWindow::Invalidate( const tools::Rectangle
& rRect
, InvalidateFlags nFlags
)
269 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
271 vcl::Window::Invalidate( rRect
, nFlags
);
273 void ChartWindow::Invalidate( const vcl::Region
& rRegion
, InvalidateFlags nFlags
)
275 if( m_bInPaint
) // #i101928# superfluous paint calls while entering and editing charts"
277 vcl::Window::Invalidate( rRegion
, nFlags
);
280 void ChartWindow::LogicInvalidate(const tools::Rectangle
* pRectangle
)
282 SfxViewShell
* pCurrentShell
= SfxViewShell::Current();
283 if ( nullptr == pCurrentShell
)
288 // we have to invalidate the whole chart area not the whole document
289 sRectangle
= GetBoundingBox().toString();
293 tools::Rectangle
aRectangle(*pRectangle
);
294 // When dragging shapes the map mode is disabled.
295 if (IsMapModeEnabled())
297 if (GetMapMode().GetMapUnit() == MapUnit::Map100thMM
)
298 aRectangle
= OutputDevice::LogicToLogic(aRectangle
, MapMode(MapUnit::Map100thMM
), MapMode(MapUnit::MapTwip
));
302 aRectangle
= PixelToLogic(aRectangle
, MapMode(MapUnit::MapTwip
));
305 vcl::Window
* pEditWin
= GetParentEditWin();
308 MapMode aCWMapMode
= GetMapMode();
309 double fXScale( aCWMapMode
.GetScaleX() );
310 double fYScale( aCWMapMode
.GetScaleY() );
312 if (!IsMapModeEnabled())
314 aRectangle
.SetLeft( aRectangle
.Left() / fXScale
);
315 aRectangle
.SetRight( aRectangle
.Right() / fXScale
);
316 aRectangle
.SetTop( aRectangle
.Top() / fYScale
);
317 aRectangle
.SetBottom( aRectangle
.Bottom() / fYScale
);
320 Point aOffset
= this->GetOffsetPixelFrom(*pEditWin
);
321 aOffset
.setX( aOffset
.X() * (TWIPS_PER_PIXEL
/ fXScale
) );
322 aOffset
.setY( aOffset
.Y() * (TWIPS_PER_PIXEL
/ fYScale
) );
324 aRectangle
= tools::Rectangle(aRectangle
.TopLeft() + aOffset
, aRectangle
.GetSize());
327 sRectangle
= aRectangle
.toString();
329 SfxLokHelper::notifyInvalidation(pCurrentShell
, sRectangle
);
332 FactoryFunction
ChartWindow::GetUITestFactory() const
334 return ChartWindowUIObject::create
;
337 ChartController
* ChartWindow::GetController()
339 return m_pWindowController
;
342 vcl::Window
* ChartWindow::GetParentEditWin()
344 if (m_pViewShellWindow
)
345 return m_pViewShellWindow
.get();
347 // So, you are thinking, why do not invoke pCurrentShell->GetWindow() ?
348 // Because in Impress the parent edit win is not view shell window.
349 SfxViewShell
* pCurrentShell
= SfxViewShell::Current();
352 SfxInPlaceClient
* pIPClient
= pCurrentShell
->GetIPClient();
355 vcl::Window
* pRootWin
= pIPClient
->GetEditWin();
356 if(pRootWin
&& pRootWin
->IsAncestorOf(*this))
358 m_pViewShellWindow
= pRootWin
;
359 return m_pViewShellWindow
.get();
366 tools::Rectangle
ChartWindow::GetBoundingBox()
368 tools::Rectangle aBBox
;
370 vcl::Window
* pRootWin
= GetParentEditWin();
373 // In all cases, the following code fragment
374 // returns the chart bounding box in twips.
375 MapMode aCWMapMode
= GetMapMode();
376 double fXScale( aCWMapMode
.GetScaleX() );
377 double fYScale( aCWMapMode
.GetScaleY() );
378 Point aOffset
= GetOffsetPixelFrom(*pRootWin
);
379 aOffset
.setX( aOffset
.X() * (TWIPS_PER_PIXEL
/ fXScale
) );
380 aOffset
.setY( aOffset
.Y() * (TWIPS_PER_PIXEL
/ fYScale
) );
381 Size aSize
= GetSizePixel();
382 aSize
.setWidth( aSize
.Width() * (TWIPS_PER_PIXEL
/ fXScale
) );
383 aSize
.setHeight( aSize
.Height() * (TWIPS_PER_PIXEL
/ fYScale
) );
384 aBBox
= tools::Rectangle(aOffset
, aSize
);
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */