LibreOffice Module sc (master) 1
notemark.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 <svx/svdoutl.hxx>
21#include <svx/svdmodel.hxx>
22#include <svx/svdpage.hxx>
23#include <svx/svdocapt.hxx>
24#include <svl/itempool.hxx>
25#include <utility>
26#include <vcl/svapp.hxx>
27#include <vcl/settings.hxx>
28#include <vcl/window.hxx>
29
30#include <notemark.hxx>
31#include <document.hxx>
32#include <postit.hxx>
33
34#define SC_NOTEMARK_TIME 800
35#define SC_NOTEMARK_SHORT 70
36
38 ScDocument* pD, const ScAddress& aPos, OUString aUser,
39 const MapMode& rMap, bool bLeftEdge, bool bForce, bool bKeyboard) :
40 m_pWindow( pWin ),
41 m_pRightWin( pRight ),
42 m_pBottomWin( pBottom ),
43 m_pDiagWin( pDiagonal ),
44 m_pDoc( pD ),
45 m_aDocPos( aPos ),
46 m_aUserText(std::move( aUser )),
47 m_aTimer("ScNoteMarker m_aTimer"),
48 m_aMapMode( rMap ),
49 m_bLeft( bLeftEdge ),
50 m_bByKeyboard( bKeyboard ),
51 m_bVisible( false )
52{
53 Size aSizePixel = m_pWindow->GetOutputSizePixel();
54 if( m_pRightWin )
55 aSizePixel.AdjustWidth(m_pRightWin->GetOutputSizePixel().Width() );
56 if( m_pBottomWin )
57 aSizePixel.AdjustHeight(m_pBottomWin->GetOutputSizePixel().Height() );
58 tools::Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
59 m_aVisRect = m_pWindow->PixelToLogic( aVisPixel, m_aMapMode );
60
61 m_aTimer.SetInvokeHandler( LINK( this, ScNoteMarker, TimeHdl ) );
64}
65
67{
68 m_xObject.clear();
69
71
72 m_pModel.reset();
73}
74
76{
77 if (!m_bVisible)
78 {
79 m_pModel.reset( new SdrModel() );
80 m_pModel->SetScaleUnit(MapUnit::Map100thMM);
81 SfxItemPool& rPool = m_pModel->GetItemPool();
82 rPool.SetDefaultMetric(MapUnit::Map100thMM);
83 rPool.FreezeIdRanges();
84
85 OutputDevice* pPrinter = m_pDoc->GetRefDevice();
86 if (pPrinter)
87 {
88 // On the outliner of the draw model also the printer is set as RefDevice,
89 // and it should look uniform.
90 Outliner& rOutliner = m_pModel->GetDrawOutliner();
91 rOutliner.SetRefDevice(pPrinter);
92 }
93
94 if( rtl::Reference<SdrPage> pPage = m_pModel->AllocPage( false ) )
95
96 {
97 m_xObject = ScNoteUtil::CreateTempCaption( *m_pDoc, m_aDocPos, *pPage, m_aUserText, m_aVisRect, m_bLeft );
98 if( m_xObject )
99 {
100 // Here, SyncForGrid and GetGridOffset was used with the comment:
101 // // Need to include grid offset: GetCurrentBoundRect is removing it
102 // // but we need to know actual rect position
103 // This is no longer true - SdrObject::RecalcBoundRect() uses the
104 // GetViewContact().getViewIndependentPrimitive2DContainer()) call
105 // that now by default adds the eventually needed GridOffset. Thus
106 // I have removed that adaptation stuff.
107 m_aRect = m_xObject->GetCurrentBoundRect();
108 }
109
110 // Insert page so that the model recognise it and also deleted
111 m_pModel->InsertPage( pPage.get() );
112
113 }
114 m_bVisible = true;
115 }
116
117 Draw();
118}
119
120static void lcl_DrawWin( const SdrObject* pObject, vcl::RenderContext* pWindow, const MapMode& rMap )
121{
122 MapMode aOld = pWindow->GetMapMode();
123 pWindow->SetMapMode( rMap );
124
125 DrawModeFlags nOldDrawMode = pWindow->GetDrawMode();
126 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
127 {
128 pWindow->SetDrawMode( nOldDrawMode | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill |
129 DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
130 }
131
132 pObject->SingleObjectPainter( *pWindow ); // #110094#-17
133
134 pWindow->SetDrawMode( nOldDrawMode );
135 pWindow->SetMapMode( aOld );
136}
137
138static MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
139{
140 MapMode aNew = rMap;
141 Point aOrigin = aNew.GetOrigin();
142 aOrigin.AdjustX( -(rMove.Width()) );
143 aOrigin.AdjustY( -rMove.Height() );
144 aNew.SetOrigin(aOrigin);
145 return aNew;
146}
147
149{
150 if ( !(m_xObject && m_bVisible) )
151 return;
152
153 lcl_DrawWin( m_xObject.get(), m_pWindow->GetOutDev(), m_aMapMode );
154
155 if ( m_pRightWin || m_pBottomWin )
156 {
157 Size aWinSize = m_pWindow->PixelToLogic( m_pWindow->GetOutputSizePixel(), m_aMapMode );
158 if ( m_pRightWin )
159 lcl_DrawWin( m_xObject.get(), m_pRightWin->GetOutDev(),
160 lcl_MoveMapMode( m_aMapMode, Size( aWinSize.Width(), 0 ) ) );
161 if ( m_pBottomWin )
162 lcl_DrawWin( m_xObject.get(), m_pBottomWin->GetOutDev(),
163 lcl_MoveMapMode( m_aMapMode, Size( 0, aWinSize.Height() ) ) );
164 if ( m_pDiagWin )
165 lcl_DrawWin( m_xObject.get(), m_pDiagWin->GetOutDev(), lcl_MoveMapMode( m_aMapMode, aWinSize ) );
166 }
167}
168
170{
171 if (!m_bVisible)
172 return;
173
174 // Extend the invalidated rectangle by 1 pixel in each direction in case AA would slightly
175 // paint outside the nominal area.
177 const Size aPixelSize = m_pWindow->PixelToLogic(Size(1, 1));
178 aRect.AdjustLeft(-aPixelSize.getWidth());
179 aRect.AdjustTop(-aPixelSize.getHeight());
180 aRect.AdjustRight(aPixelSize.getWidth());
181 aRect.AdjustBottom(aPixelSize.getHeight());
182
183 m_pWindow->Invalidate( OutputDevice::LogicToLogic(aRect, m_aMapMode, m_pWindow->GetMapMode()) );
184
185 if ( !(m_pRightWin || m_pBottomWin) )
186 return;
187
188 Size aWinSize = m_pWindow->PixelToLogic( m_pWindow->GetOutputSizePixel(), m_aMapMode );
189 if ( m_pRightWin )
190 m_pRightWin->Invalidate( OutputDevice::LogicToLogic(aRect,
191 lcl_MoveMapMode( m_aMapMode, Size( aWinSize.Width(), 0 ) ),
192 m_pRightWin->GetMapMode()) );
193 if ( m_pBottomWin )
194 m_pBottomWin->Invalidate( OutputDevice::LogicToLogic(aRect,
195 lcl_MoveMapMode( m_aMapMode, Size( 0, aWinSize.Height() ) ),
196 m_pBottomWin->GetMapMode()) );
197 if ( m_pDiagWin )
198 m_pDiagWin->Invalidate( OutputDevice::LogicToLogic(aRect,
199 lcl_MoveMapMode( m_aMapMode, aWinSize ),
200 m_pDiagWin->GetMapMode()) );
201}
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawModeFlags
static const AllSettings & GetSettings()
void SetOrigin(const Point &rOrigin)
const Point & GetOrigin() const
void SetRefDevice(OutputDevice *pRefDev)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetMapMode()
const MapMode & GetMapMode() const
void SetDrawMode(DrawModeFlags nDrawMode)
DrawModeFlags GetDrawMode() const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
tools::Rectangle m_aRect
Definition: notemark.hxx:50
ScNoteMarker(vcl::Window *pWin, vcl::Window *pRight, vcl::Window *pBottom, vcl::Window *pDiagonal, ScDocument *pD, const ScAddress &aPos, OUString aUser, const MapMode &rMap, bool bLeftEdge, bool bForce, bool bKeyboard)
Definition: notemark.cxx:37
bool m_bVisible
Definition: notemark.hxx:53
VclPtr< vcl::Window > m_pRightWin
Definition: notemark.hxx:38
tools::Rectangle m_aVisRect
Definition: notemark.hxx:44
Timer m_aTimer
Definition: notemark.hxx:45
VclPtr< vcl::Window > m_pDiagWin
Definition: notemark.hxx:40
std::unique_ptr< SdrModel > m_pModel
Definition: notemark.hxx:51
MapMode m_aMapMode
Definition: notemark.hxx:46
VclPtr< vcl::Window > m_pWindow
Definition: notemark.hxx:37
VclPtr< vcl::Window > m_pBottomWin
Definition: notemark.hxx:39
rtl::Reference< SdrCaptionObj > m_xObject
Definition: notemark.hxx:52
void Draw()
Definition: notemark.cxx:148
void InvalidateWin()
Definition: notemark.cxx:169
static rtl::Reference< SdrCaptionObj > CreateTempCaption(ScDocument &rDoc, const ScAddress &rPos, SdrPage &rDrawPage, std::u16string_view rUserText, const tools::Rectangle &rVisRect, bool bTailFront)
Creates and returns a caption object for a temporary caption.
Definition: postit.cxx:832
void FreezeIdRanges()
void SetDefaultMetric(MapUnit eNewMetric)
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
constexpr tools::Long getWidth() const
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
EmbeddedObjectRef * pObject
#define SC_NOTEMARK_TIME
Definition: notemark.cxx:34
static MapMode lcl_MoveMapMode(const MapMode &rMap, const Size &rMove)
Definition: notemark.cxx:138
IMPL_LINK_NOARG(ScNoteMarker, TimeHdl, Timer *, void)
Definition: notemark.cxx:75
static void lcl_DrawWin(const SdrObject *pObject, vcl::RenderContext *pWindow, const MapMode &rMap)
Definition: notemark.cxx:120
#define SC_NOTEMARK_SHORT
Definition: notemark.cxx:35