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 <svx/svdoutl.hxx>
21 #include <svx/svdmodel.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/svdocapt.hxx>
24 #include <sfx2/printer.hxx>
25 #include <unotools/pathoptions.hxx>
26 #include <svl/itempool.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 #include "notemark.hxx"
31 #include "document.hxx"
34 #define SC_NOTEMARK_TIME 800
35 #define SC_NOTEMARK_SHORT 70
37 ScNoteMarker::ScNoteMarker( vcl::Window
* pWin
, vcl::Window
* pRight
, vcl::Window
* pBottom
, vcl::Window
* pDiagonal
,
38 ScDocument
* pD
, ScAddress aPos
, const OUString
& rUser
,
39 const MapMode
& rMap
, bool bLeftEdge
, bool bForce
, bool bKeyboard
) :
42 pBottomWin( pBottom
),
43 pDiagWin( pDiagonal
),
49 bByKeyboard( bKeyboard
),
54 Size aSizePixel
= pWindow
->GetOutputSizePixel();
56 aSizePixel
.Width() += pRightWin
->GetOutputSizePixel().Width();
58 aSizePixel
.Height() += pBottomWin
->GetOutputSizePixel().Height();
59 Rectangle
aVisPixel( Point( 0, 0 ), aSizePixel
);
60 aVisRect
= pWindow
->PixelToLogic( aVisPixel
, aMapMode
);
62 aTimer
.SetTimeoutHdl( LINK( this, ScNoteMarker
, TimeHdl
) );
63 aTimer
.SetTimeout( bForce
? SC_NOTEMARK_SHORT
: SC_NOTEMARK_TIME
);
67 ScNoteMarker::~ScNoteMarker()
74 IMPL_LINK_NOARG_TYPED(ScNoteMarker
, TimeHdl
, Timer
*, void)
78 SvtPathOptions aPathOpt
;
79 OUString aPath
= aPathOpt
.GetPalettePath();
80 pModel
= new SdrModel(aPath
, nullptr, nullptr, false);
81 pModel
->SetScaleUnit(MAP_100TH_MM
);
82 SfxItemPool
& rPool
= pModel
->GetItemPool();
83 rPool
.SetDefaultMetric(SFX_MAPUNIT_100TH_MM
);
84 rPool
.FreezeIdRanges();
86 OutputDevice
* pPrinter
= pDoc
->GetRefDevice();
89 // On the outliner of the draw model also the printer is set as RefDevice,
90 // and it should look uniform.
91 Outliner
& rOutliner
= pModel
->GetDrawOutliner();
92 rOutliner
.SetRefDevice(pPrinter
);
95 if( SdrPage
* pPage
= pModel
->AllocPage( false ) )
97 pObject
= ScNoteUtil::CreateTempCaption( *pDoc
, aDocPos
, *pPage
, aUserText
, aVisRect
, bLeft
);
100 pObject
->SetGridOffset( aGridOff
);
101 aRect
= pObject
->GetCurrentBoundRect();
104 // Insert page so that the model recognise it and also deleted
105 pModel
->InsertPage( pPage
);
114 static void lcl_DrawWin( SdrObject
* pObject
, vcl::RenderContext
* pWindow
, const MapMode
& rMap
)
116 MapMode aOld
= pWindow
->GetMapMode();
117 pWindow
->SetMapMode( rMap
);
119 DrawModeFlags nOldDrawMode
= pWindow
->GetDrawMode();
120 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
122 pWindow
->SetDrawMode( nOldDrawMode
| DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
|
123 DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
);
126 pObject
->SingleObjectPainter( *pWindow
); // #110094#-17
128 pWindow
->SetDrawMode( nOldDrawMode
);
129 pWindow
->SetMapMode( aOld
);
132 static MapMode
lcl_MoveMapMode( const MapMode
& rMap
, const Size
& rMove
)
135 Point aOrigin
= aNew
.GetOrigin();
136 aOrigin
.X() -= rMove
.Width();
137 aOrigin
.Y() -= rMove
.Height();
138 aNew
.SetOrigin(aOrigin
);
142 void ScNoteMarker::Draw()
144 if ( pObject
&& bVisible
)
146 lcl_DrawWin( pObject
, pWindow
, aMapMode
);
148 if ( pRightWin
|| pBottomWin
)
150 Size aWinSize
= pWindow
->PixelToLogic( pWindow
->GetOutputSizePixel(), aMapMode
);
152 lcl_DrawWin( pObject
, pRightWin
,
153 lcl_MoveMapMode( aMapMode
, Size( aWinSize
.Width(), 0 ) ) );
155 lcl_DrawWin( pObject
, pBottomWin
,
156 lcl_MoveMapMode( aMapMode
, Size( 0, aWinSize
.Height() ) ) );
158 lcl_DrawWin( pObject
, pDiagWin
, lcl_MoveMapMode( aMapMode
, aWinSize
) );
163 void ScNoteMarker::InvalidateWin()
167 pWindow
->Invalidate( OutputDevice::LogicToLogic(aRect
, aMapMode
, pWindow
->GetMapMode()) );
169 if ( pRightWin
|| pBottomWin
)
171 Size aWinSize
= pWindow
->PixelToLogic( pWindow
->GetOutputSizePixel(), aMapMode
);
173 pRightWin
->Invalidate( OutputDevice::LogicToLogic(aRect
,
174 lcl_MoveMapMode( aMapMode
, Size( aWinSize
.Width(), 0 ) ),
175 pRightWin
->GetMapMode()) );
177 pBottomWin
->Invalidate( OutputDevice::LogicToLogic(aRect
,
178 lcl_MoveMapMode( aMapMode
, Size( 0, aWinSize
.Height() ) ),
179 pBottomWin
->GetMapMode()) );
181 pDiagWin
->Invalidate( OutputDevice::LogicToLogic(aRect
,
182 lcl_MoveMapMode( aMapMode
, aWinSize
),
183 pDiagWin
->GetMapMode()) );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */