Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / notemark.cxx
blob2735a251a90ed181edb5d28d465730a1b8cc7278
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>
30 #include "notemark.hxx"
31 #include "document.hxx"
32 #include "postit.hxx"
34 #define SC_NOTEMARK_TIME 800
35 #define SC_NOTEMARK_SHORT 70
37 // -----------------------------------------------------------------------
39 ScNoteMarker::ScNoteMarker( Window* pWin, Window* pRight, Window* pBottom, Window* pDiagonal,
40 ScDocument* pD, ScAddress aPos, const String& rUser,
41 const MapMode& rMap, sal_Bool bLeftEdge, sal_Bool bForce, sal_Bool bKeyboard ) :
42 pWindow( pWin ),
43 pRightWin( pRight ),
44 pBottomWin( pBottom ),
45 pDiagWin( pDiagonal ),
46 pDoc( pD ),
47 aDocPos( aPos ),
48 aUserText( rUser ),
49 aMapMode( rMap ),
50 bLeft( bLeftEdge ),
51 bByKeyboard( bKeyboard ),
52 pModel( NULL ),
53 pObject( NULL ),
54 bVisible( false )
56 Size aSizePixel = pWindow->GetOutputSizePixel();
57 if( pRightWin )
58 aSizePixel.Width() += pRightWin->GetOutputSizePixel().Width();
59 if( pBottomWin )
60 aSizePixel.Height() += pBottomWin->GetOutputSizePixel().Height();
61 Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
62 aVisRect = pWindow->PixelToLogic( aVisPixel, aMapMode );
64 aTimer.SetTimeoutHdl( LINK( this, ScNoteMarker, TimeHdl ) );
65 aTimer.SetTimeout( bForce ? SC_NOTEMARK_SHORT : SC_NOTEMARK_TIME );
66 aTimer.Start();
69 ScNoteMarker::~ScNoteMarker()
71 InvalidateWin();
73 delete pModel;
76 IMPL_LINK_NOARG(ScNoteMarker, TimeHdl)
78 if (!bVisible)
80 SvtPathOptions aPathOpt;
81 String aPath = aPathOpt.GetPalettePath();
82 pModel = new SdrModel(aPath);
83 pModel->SetScaleUnit(MAP_100TH_MM);
84 SfxItemPool& rPool = pModel->GetItemPool();
85 rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
86 rPool.FreezeIdRanges();
88 OutputDevice* pPrinter = pDoc->GetRefDevice();
89 if (pPrinter)
91 // Am Outliner des Draw-Model ist auch der Drucker als RefDevice gesetzt,
92 // und es soll einheitlich aussehen.
93 Outliner& rOutliner = pModel->GetDrawOutliner();
94 rOutliner.SetRefDevice(pPrinter);
97 if( SdrPage* pPage = pModel->AllocPage( false ) )
99 pObject = ScNoteUtil::CreateTempCaption( *pDoc, aDocPos, *pPage, aUserText, aVisRect, bLeft );
100 if( pObject )
102 pObject->SetGridOffset( aGridOff );
103 aRect = pObject->GetCurrentBoundRect();
106 // Page einfuegen damit das Model sie kennt und auch deleted
107 pModel->InsertPage( pPage );
110 bVisible = true;
113 Draw();
114 return 0;
117 static void lcl_DrawWin( SdrObject* pObject, Window* pWindow, const MapMode& rMap )
119 MapMode aOld = pWindow->GetMapMode();
120 pWindow->SetMapMode( rMap );
122 sal_uLong nOldDrawMode = pWindow->GetDrawMode();
123 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
125 pWindow->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
126 DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
129 pObject->SingleObjectPainter( *pWindow ); // #110094#-17
131 pWindow->SetDrawMode( nOldDrawMode );
132 pWindow->SetMapMode( aOld );
135 static MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
137 MapMode aNew = rMap;
138 Point aOrigin = aNew.GetOrigin();
139 aOrigin.X() -= rMove.Width();
140 aOrigin.Y() -= rMove.Height();
141 aNew.SetOrigin(aOrigin);
142 return aNew;
145 void ScNoteMarker::Draw()
147 if ( pObject && bVisible )
149 lcl_DrawWin( pObject, pWindow, aMapMode );
151 if ( pRightWin || pBottomWin )
153 Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
154 if ( pRightWin )
155 lcl_DrawWin( pObject, pRightWin,
156 lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ) );
157 if ( pBottomWin )
158 lcl_DrawWin( pObject, pBottomWin,
159 lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ) );
160 if ( pDiagWin )
161 lcl_DrawWin( pObject, pDiagWin, lcl_MoveMapMode( aMapMode, aWinSize ) );
166 void ScNoteMarker::InvalidateWin()
168 if (bVisible)
170 pWindow->Invalidate( pWindow->LogicToLogic(aRect, aMapMode, pWindow->GetMapMode()) );
172 if ( pRightWin || pBottomWin )
174 Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
175 if ( pRightWin )
176 pRightWin->Invalidate( pRightWin->LogicToLogic(aRect,
177 lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ),
178 pRightWin->GetMapMode()) );
179 if ( pBottomWin )
180 pBottomWin->Invalidate( pBottomWin->LogicToLogic(aRect,
181 lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ),
182 pBottomWin->GetMapMode()) );
183 if ( pDiagWin )
184 pDiagWin->Invalidate( pDiagWin->LogicToLogic(aRect,
185 lcl_MoveMapMode( aMapMode, aWinSize ),
186 pDiagWin->GetMapMode()) );
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */