Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / notemark.cxx
blobb0071fad92a838d6832831d70ec5e1c64785e44d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <svx/svdoutl.hxx>
22 #include <svx/svdmodel.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/svdocapt.hxx>
25 #include <sfx2/printer.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <svl/itempool.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/settings.hxx>
31 #include "notemark.hxx"
32 #include "document.hxx"
33 #include "postit.hxx"
35 #define SC_NOTEMARK_TIME 800
36 #define SC_NOTEMARK_SHORT 70
38 ScNoteMarker::ScNoteMarker( Window* pWin, Window* pRight, Window* pBottom, Window* pDiagonal,
39 ScDocument* pD, ScAddress aPos, const OUString& rUser,
40 const MapMode& rMap, bool bLeftEdge, bool bForce, bool bKeyboard ) :
41 pWindow( pWin ),
42 pRightWin( pRight ),
43 pBottomWin( pBottom ),
44 pDiagWin( pDiagonal ),
45 pDoc( pD ),
46 aDocPos( aPos ),
47 aUserText( rUser ),
48 aMapMode( rMap ),
49 bLeft( bLeftEdge ),
50 bByKeyboard( bKeyboard ),
51 pModel( NULL ),
52 pObject( NULL ),
53 bVisible( false )
55 Size aSizePixel = pWindow->GetOutputSizePixel();
56 if( pRightWin )
57 aSizePixel.Width() += pRightWin->GetOutputSizePixel().Width();
58 if( pBottomWin )
59 aSizePixel.Height() += pBottomWin->GetOutputSizePixel().Height();
60 Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
61 aVisRect = pWindow->PixelToLogic( aVisPixel, aMapMode );
63 aTimer.SetTimeoutHdl( LINK( this, ScNoteMarker, TimeHdl ) );
64 aTimer.SetTimeout( bForce ? SC_NOTEMARK_SHORT : SC_NOTEMARK_TIME );
65 aTimer.Start();
68 ScNoteMarker::~ScNoteMarker()
70 InvalidateWin();
72 delete pModel;
75 IMPL_LINK_NOARG(ScNoteMarker, TimeHdl)
77 if (!bVisible)
79 SvtPathOptions aPathOpt;
80 OUString aPath = aPathOpt.GetPalettePath();
81 pModel = new SdrModel(aPath, NULL, NULL, false, false);
82 pModel->SetScaleUnit(MAP_100TH_MM);
83 SfxItemPool& rPool = pModel->GetItemPool();
84 rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
85 rPool.FreezeIdRanges();
87 OutputDevice* pPrinter = pDoc->GetRefDevice();
88 if (pPrinter)
90 // Am Outliner des Draw-Model ist auch der Drucker als RefDevice gesetzt,
91 // und es soll einheitlich aussehen.
92 Outliner& rOutliner = pModel->GetDrawOutliner();
93 rOutliner.SetRefDevice(pPrinter);
96 if( SdrPage* pPage = pModel->AllocPage( false ) )
98 pObject = ScNoteUtil::CreateTempCaption( *pDoc, aDocPos, *pPage, aUserText, aVisRect, bLeft );
99 if( pObject )
101 pObject->SetGridOffset( aGridOff );
102 aRect = pObject->GetCurrentBoundRect();
105 // Page einfuegen damit das Model sie kennt und auch deleted
106 pModel->InsertPage( pPage );
109 bVisible = true;
112 Draw();
113 return 0;
116 static void lcl_DrawWin( SdrObject* pObject, Window* pWindow, const MapMode& rMap )
118 MapMode aOld = pWindow->GetMapMode();
119 pWindow->SetMapMode( rMap );
121 sal_uLong nOldDrawMode = pWindow->GetDrawMode();
122 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
124 pWindow->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
125 DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
128 pObject->SingleObjectPainter( *pWindow ); // #110094#-17
130 pWindow->SetDrawMode( nOldDrawMode );
131 pWindow->SetMapMode( aOld );
134 static MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
136 MapMode aNew = rMap;
137 Point aOrigin = aNew.GetOrigin();
138 aOrigin.X() -= rMove.Width();
139 aOrigin.Y() -= rMove.Height();
140 aNew.SetOrigin(aOrigin);
141 return aNew;
144 void ScNoteMarker::Draw()
146 if ( pObject && bVisible )
148 lcl_DrawWin( pObject, pWindow, aMapMode );
150 if ( pRightWin || pBottomWin )
152 Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
153 if ( pRightWin )
154 lcl_DrawWin( pObject, pRightWin,
155 lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ) );
156 if ( pBottomWin )
157 lcl_DrawWin( pObject, pBottomWin,
158 lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ) );
159 if ( pDiagWin )
160 lcl_DrawWin( pObject, pDiagWin, lcl_MoveMapMode( aMapMode, aWinSize ) );
165 void ScNoteMarker::InvalidateWin()
167 if (bVisible)
169 pWindow->Invalidate( pWindow->LogicToLogic(aRect, aMapMode, pWindow->GetMapMode()) );
171 if ( pRightWin || pBottomWin )
173 Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
174 if ( pRightWin )
175 pRightWin->Invalidate( pRightWin->LogicToLogic(aRect,
176 lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ),
177 pRightWin->GetMapMode()) );
178 if ( pBottomWin )
179 pBottomWin->Invalidate( pBottomWin->LogicToLogic(aRect,
180 lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ),
181 pBottomWin->GetMapMode()) );
182 if ( pDiagWin )
183 pDiagWin->Invalidate( pDiagWin->LogicToLogic(aRect,
184 lcl_MoveMapMode( aMapMode, aWinSize ),
185 pDiagWin->GetMapMode()) );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */