| 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 |
|
| 34 |
using namespace ::com::sun::star; |
| 35 |
|
| 36 |
namespace |
| 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 |
|
| 47 |
namespace chart |
| 48 |
{ |
| 49 |
|
| 50 |
ChartWindow::ChartWindow( ChartController* pController, vcl::Window* pParent, WinBits nStyle ) |
| 51 |
: Window(pParent, nStyle) |
| 52 |
, m_pWindowController( pController ) |
| 53 |
, m_bInPaint(false) |
| 54 |
, m_pViewShellWindow( nullptr ) |
| 55 |
{ |
| 56 |
set_id(u"chart_window"_ustr); |
| 57 |
SetHelpId( HID_SCH_WIN_DOCUMENT ); |
| 58 |
SetMapMode( MapMode(MapUnit::Map100thMM) ); |
| 59 |
adjustHighContrastMode(); |
| 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 |
|
| 67 |
ChartWindow::~ChartWindow() |
| 68 |
{ |
| 69 |
disposeOnce(); |
| 70 |
} |
| 71 |
|
| 72 |
void ChartWindow::dispose() |
| 73 |
{ |
| 74 |
m_pWindowController = nullptr; |
| 75 |
m_pViewShellWindow.reset(); |
| 76 |
vcl::Window::dispose(); |
| 77 |
} |
| 78 |
|
| 79 |
void ChartWindow::PrePaint(vcl::RenderContext& ) |
| 80 |
{ |
| 81 |
// forward VCLs PrePaint window event to DrawingLayer |
| 82 |
if (m_pWindowController) |
| 83 |
{ |
| 84 |
m_pWindowController->PrePaint(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
void ChartWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) |
| 89 |
{ |
| 90 |
if (comphelper::LibreOfficeKit::isActive() && !rRenderContext.IsVirtual()) |
| 91 |
return; |
| 92 |
|
| 93 |
m_bInPaint = true; |
| 94 |
if (m_pWindowController) |
| 95 |
{ |
| 96 |
m_pWindowController->execute_Paint(rRenderContext, rRect); |
| 97 |
} |
| 98 |
else |
| 99 |
{ |
| 100 |
Window::Paint(rRenderContext, rRect); |
| 101 |
} |
| 102 |
m_bInPaint = false; |
| 103 |
} |
| 104 |
|
| 105 |
void ChartWindow::MouseButtonDown(const MouseEvent& rMEvt) |
| 106 |
{ |
| 107 |
if( m_pWindowController ) |
| 108 |
m_pWindowController->execute_MouseButtonDown(rMEvt); |
| 109 |
else |
| 110 |
Window::MouseButtonDown(rMEvt); |
| 111 |
} |
| 112 |
|
| 113 |
void ChartWindow::MouseMove( const MouseEvent& rMEvt ) |
| 114 |
{ |
| 115 |
if( m_pWindowController ) |
| 116 |
m_pWindowController->execute_MouseMove( rMEvt ); |
| 117 |
else |
| 118 |
Window::MouseMove( rMEvt ); |
| 119 |
} |
| 120 |
|
| 121 |
void ChartWindow::Tracking( const TrackingEvent& rTEvt ) |
| 122 |
{ |
| 123 |
if( !m_pWindowController ) |
| 124 |
Window::Tracking( rTEvt ); |
| 125 |
} |
| 126 |
|
| 127 |
void ChartWindow::MouseButtonUp( const MouseEvent& rMEvt ) |
| 128 |
{ |
| 129 |
if( m_pWindowController ) |
| 130 |
m_pWindowController->execute_MouseButtonUp( rMEvt ); |
| 131 |
else |
| 132 |
Window::MouseButtonUp( rMEvt ); |
| 133 |
} |
| 134 |
|
| 135 |
void ChartWindow::Resize() |
| 136 |
{ |
| 137 |
if( m_pWindowController ) |
| 138 |
m_pWindowController->execute_Resize(); |
| 139 |
else |
| 140 |
Window::Resize(); |
| 141 |
} |
| 142 |
|
| 143 |
void ChartWindow::Activate() |
| 144 |
{ |
| 145 |
if( !m_pWindowController ) |
| 146 |
Window::Activate(); |
| 147 |
} |
| 148 |
void ChartWindow::Deactivate() |
| 149 |
{ |
| 150 |
if( !m_pWindowController ) |
| 151 |
Window::Deactivate(); |
| 152 |
} |
| 153 |
void ChartWindow::GetFocus() |
| 154 |
{ |
| 155 |
if( !m_pWindowController ) |
| 156 |
Window::GetFocus(); |
| 157 |
} |
| 158 |
void ChartWindow::LoseFocus() |
| 159 |
{ |
| 160 |
if( !m_pWindowController ) |
| 161 |
Window::LoseFocus(); |
| 162 |
} |
| 163 |
|
| 164 |
void ChartWindow::Command( const CommandEvent& rCEvt ) |
| 165 |
{ |
| 166 |
if( m_pWindowController ) |
| 167 |
m_pWindowController->execute_Command( rCEvt ); |
| 168 |
else |
| 169 |
Window::Command( rCEvt ); |
| 170 |
} |
| 171 |
|
| 172 |
void ChartWindow::KeyInput( const KeyEvent& rKEvt ) |
| 173 |
{ |
| 174 |
if( m_pWindowController ) |
| 175 |
{ |
| 176 |
if( !m_pWindowController->execute_KeyInput(rKEvt) ) |
| 177 |
Window::KeyInput(rKEvt); |
| 178 |
} |
| 179 |
else |
| 180 |
Window::KeyInput( rKEvt ); |
| 181 |
} |
| 182 |
|
| 183 |
rtl::Reference<comphelper::OAccessible> ChartWindow::CreateAccessible() |
| 184 |
{ |
| 185 |
#if !ENABLE_WASM_STRIP_ACCESSIBILITY |
| 186 |
if( m_pWindowController ) |
| 187 |
return m_pWindowController->CreateAccessible(); |
| 188 |
else |
| 189 |
return Window::CreateAccessible(); |
| 190 |
#else |
| 191 |
return {}; |
| 192 |
#endif |
| 193 |
} |
| 194 |
|
| 195 |
void ChartWindow::DataChanged( const DataChangedEvent& rDCEvt ) |
| 196 |
{ |
| 197 |
vcl::Window::DataChanged( rDCEvt ); |
| 198 |
|
| 199 |
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && |
| 200 |
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) |
| 201 |
{ |
| 202 |
adjustHighContrastMode(); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
void ChartWindow::RequestHelp( const HelpEvent& rHEvt ) |
| 207 |
{ |
| 208 |
bool bHelpHandled = false; |
| 209 |
if( ( rHEvt.GetMode() & HelpEventMode::QUICK ) && |
| 210 |
m_pWindowController ) |
| 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 ) |
| 232 |
vcl::Window::RequestHelp( rHEvt ); |
| 233 |
} |
| 234 |
|
| 235 |
void ChartWindow::adjustHighContrastMode() |
| 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 |
|
| 245 |
void ChartWindow::ForceInvalidate() |
| 246 |
{ |
| 247 |
vcl::Window::Invalidate(); |
| 248 |
} |
| 249 |
void ChartWindow::ImplInvalidate( const vcl::Region* rRegion, InvalidateFlags nFlags ) |
| 250 |
{ |
| 251 |
if( m_bInPaint ) // #i101928# superfluous paint calls while entering and editing charts" |
| 252 |
return; |
| 253 |
vcl::Window::ImplInvalidate( rRegion, nFlags ); |
| 254 |
} |
| 255 |
|
| 256 |
void ChartWindow::LogicInvalidate(const tools::Rectangle* pRectangle) |
| 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 |
|
| 311 |
FactoryFunction ChartWindow::GetUITestFactory() const |
| 312 |
{ |
| 313 |
return ChartWindowUIObject::create; |
| 314 |
} |
| 315 |
|
| 316 |
ChartController* ChartWindow::GetController() |
| 317 |
{ |
| 318 |
return m_pWindowController; |
| 319 |
} |
| 320 |
|
| 321 |
vcl::Window* ChartWindow::GetParentEditWin() |
| 322 |
{ |
| 323 |
if (m_pViewShellWindow) |
| 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 |
|
| 345 |
tools::Rectangle ChartWindow::GetBoundingBox() |
| 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: */ |