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