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 <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
27 #include <vcl/window.hxx>
28 
29 #include <notemark.hxx>
30 #include <document.hxx>
31 #include <postit.hxx>
32 
33 #define SC_NOTEMARK_TIME 800
34 #define SC_NOTEMARK_SHORT 70
35 
37  ScDocument* pD, const ScAddress& aPos, const OUString& rUser,
38  const MapMode& rMap, bool bLeftEdge, bool bForce, bool bKeyboard) :
39  m_pWindow( pWin ),
40  m_pRightWin( pRight ),
41  m_pBottomWin( pBottom ),
42  m_pDiagWin( pDiagonal ),
43  m_pDoc( pD ),
44  m_aDocPos( aPos ),
45  m_aUserText( rUser ),
46  m_aTimer("ScNoteMarker m_aTimer"),
47  m_aMapMode( rMap ),
48  m_bLeft( bLeftEdge ),
49  m_bByKeyboard( bKeyboard ),
50  m_bVisible( false )
51 {
52  Size aSizePixel = m_pWindow->GetOutputSizePixel();
53  if( m_pRightWin )
55  if( m_pBottomWin )
57  tools::Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
59 
60  m_aTimer.SetInvokeHandler( LINK( this, ScNoteMarker, TimeHdl ) );
62  m_aTimer.Start();
63 }
64 
66 {
67  if (m_pModel)
68  m_xObject.release(); // deleting pModel also deletes the SdrCaptionObj
69 
70  InvalidateWin();
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 
120 static 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 
138 static 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 
154 
155  if ( m_pRightWin || m_pBottomWin )
156  {
158  if ( m_pRightWin )
160  lcl_MoveMapMode( m_aMapMode, Size( aWinSize.Width(), 0 ) ) );
161  if ( m_pBottomWin )
163  lcl_MoveMapMode( m_aMapMode, Size( 0, aWinSize.Height() ) ) );
164  if ( m_pDiagWin )
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.
176  tools::Rectangle aRect(m_aRect);
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 
184 
185  if ( !(m_pRightWin || m_pBottomWin) )
186  return;
187 
189  if ( m_pRightWin )
191  lcl_MoveMapMode( m_aMapMode, Size( aWinSize.Width(), 0 ) ),
192  m_pRightWin->GetMapMode()) );
193  if ( m_pBottomWin )
195  lcl_MoveMapMode( m_aMapMode, Size( 0, aWinSize.Height() ) ),
196  m_pBottomWin->GetMapMode()) );
197  if ( m_pDiagWin )
199  lcl_MoveMapMode( m_aMapMode, aWinSize ),
200  m_pDiagWin->GetMapMode()) );
201 }
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ScCaptionPtr 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:1163
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
ScCaptionPtr m_xObject
Definition: notemark.hxx:52
ScNoteMarker(vcl::Window *pWin, vcl::Window *pRight, vcl::Window *pBottom, vcl::Window *pDiagonal, ScDocument *pD, const ScAddress &aPos, const OUString &rUser, const MapMode &rMap, bool bLeftEdge, bool bForce, bool bKeyboard)
Definition: notemark.cxx:36
VclPtr< vcl::Window > m_pDiagWin
Definition: notemark.hxx:40
static const AllSettings & GetSettings()
static void lcl_DrawWin(const SdrObject *pObject, vcl::RenderContext *pWindow, const MapMode &rMap)
Definition: notemark.cxx:120
#define SC_NOTEMARK_SHORT
Definition: notemark.cxx:34
const MapMode & GetMapMode() const
std::unique_ptr< SdrModel > m_pModel
Definition: notemark.hxx:51
tools::Rectangle m_aRect
Definition: notemark.hxx:50
void FreezeIdRanges()
void SetMapMode()
void SetDrawMode(DrawModeFlags nDrawMode)
IMPL_LINK_NOARG(ScNoteMarker, TimeHdl, Timer *, void)
Definition: notemark.cxx:75
constexpr tools::Long Width() const
static MapMode lcl_MoveMapMode(const MapMode &rMap, const Size &rMove)
Definition: notemark.cxx:138
MapMode m_aMapMode
Definition: notemark.hxx:46
constexpr tools::Long getHeight() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
bool m_bVisible
Definition: notemark.hxx:53
void SingleObjectPainter(OutputDevice &rOut) const
const MapMode & GetMapMode() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetOrigin(const Point &rOrigin)
virtual void Start(bool bStartTimer=true) override
void Draw()
Definition: notemark.cxx:148
Point PixelToLogic(const Point &rDevicePt) const
DrawModeFlags GetDrawMode() const
void SetTimeout(sal_uInt64 nTimeoutMs)
tools::Long AdjustTop(tools::Long nVertMoveDelta)
Timer m_aTimer
Definition: notemark.hxx:45
#define SC_NOTEMARK_TIME
Definition: notemark.cxx:33
void InvalidateWin()
Definition: notemark.cxx:169
VclPtr< vcl::Window > m_pRightWin
Definition: notemark.hxx:38
void SetDefaultMetric(MapUnit eNewMetric)
constexpr tools::Long Height() const
const SdrCaptionObj * get() const
Definition: postit.hxx:54
VclPtr< vcl::Window > m_pWindow
Definition: notemark.hxx:37
::OutputDevice const * GetOutDev() const
tools::Long AdjustWidth(tools::Long n)
SdrCaptionObj * release()
Release all management of the SdrCaptionObj* in all instances of this list and dissolve.
Definition: postit.cxx:783
void SetRefDevice(OutputDevice *pRefDev)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
const Point & GetOrigin() const
tools::Long AdjustHeight(tools::Long n)
Size GetOutputSizePixel() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long getWidth() const
VclPtr< vcl::Window > m_pBottomWin
Definition: notemark.hxx:39
tools::Rectangle m_aVisRect
Definition: notemark.hxx:44
DrawModeFlags
bool m_bDetectedRangeSegmentation false