Line data Source code
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 <sfx2/printer.hxx>
25 : #include <unotools/pathoptions.hxx>
26 : #include <svl/itempool.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <vcl/settings.hxx>
29 :
30 : #include "notemark.hxx"
31 : #include "document.hxx"
32 : #include "postit.hxx"
33 :
34 : #define SC_NOTEMARK_TIME 800
35 : #define SC_NOTEMARK_SHORT 70
36 :
37 0 : 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 ) :
40 : pWindow( pWin ),
41 : pRightWin( pRight ),
42 : pBottomWin( pBottom ),
43 : pDiagWin( pDiagonal ),
44 : pDoc( pD ),
45 : aDocPos( aPos ),
46 : aUserText( rUser ),
47 : aMapMode( rMap ),
48 : bLeft( bLeftEdge ),
49 : bByKeyboard( bKeyboard ),
50 : pModel( NULL ),
51 : pObject( NULL ),
52 0 : bVisible( false )
53 : {
54 0 : Size aSizePixel = pWindow->GetOutputSizePixel();
55 0 : if( pRightWin )
56 0 : aSizePixel.Width() += pRightWin->GetOutputSizePixel().Width();
57 0 : if( pBottomWin )
58 0 : aSizePixel.Height() += pBottomWin->GetOutputSizePixel().Height();
59 0 : Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
60 0 : aVisRect = pWindow->PixelToLogic( aVisPixel, aMapMode );
61 :
62 0 : aTimer.SetTimeoutHdl( LINK( this, ScNoteMarker, TimeHdl ) );
63 0 : aTimer.SetTimeout( bForce ? SC_NOTEMARK_SHORT : SC_NOTEMARK_TIME );
64 0 : aTimer.Start();
65 0 : }
66 :
67 0 : ScNoteMarker::~ScNoteMarker()
68 : {
69 0 : InvalidateWin();
70 :
71 0 : delete pModel;
72 0 : }
73 :
74 0 : IMPL_LINK_NOARG_TYPED(ScNoteMarker, TimeHdl, Timer *, void)
75 : {
76 0 : if (!bVisible)
77 : {
78 0 : SvtPathOptions aPathOpt;
79 0 : OUString aPath = aPathOpt.GetPalettePath();
80 0 : pModel = new SdrModel(aPath, NULL, NULL, false, false);
81 0 : pModel->SetScaleUnit(MAP_100TH_MM);
82 0 : SfxItemPool& rPool = pModel->GetItemPool();
83 0 : rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
84 0 : rPool.FreezeIdRanges();
85 :
86 0 : OutputDevice* pPrinter = pDoc->GetRefDevice();
87 0 : if (pPrinter)
88 : {
89 : // Am Outliner des Draw-Model ist auch der Drucker als RefDevice gesetzt,
90 : // und es soll einheitlich aussehen.
91 0 : Outliner& rOutliner = pModel->GetDrawOutliner();
92 0 : rOutliner.SetRefDevice(pPrinter);
93 : }
94 :
95 0 : if( SdrPage* pPage = pModel->AllocPage( false ) )
96 : {
97 0 : pObject = ScNoteUtil::CreateTempCaption( *pDoc, aDocPos, *pPage, aUserText, aVisRect, bLeft );
98 0 : if( pObject )
99 : {
100 0 : pObject->SetGridOffset( aGridOff );
101 0 : aRect = pObject->GetCurrentBoundRect();
102 : }
103 :
104 : // Page einfuegen damit das Model sie kennt und auch deleted
105 0 : pModel->InsertPage( pPage );
106 :
107 : }
108 0 : bVisible = true;
109 : }
110 :
111 0 : Draw();
112 0 : }
113 :
114 0 : static void lcl_DrawWin( SdrObject* pObject, vcl::RenderContext* pWindow, const MapMode& rMap )
115 : {
116 0 : MapMode aOld = pWindow->GetMapMode();
117 0 : pWindow->SetMapMode( rMap );
118 :
119 0 : DrawModeFlags nOldDrawMode = pWindow->GetDrawMode();
120 0 : if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
121 : {
122 : pWindow->SetDrawMode( nOldDrawMode | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill |
123 0 : DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
124 : }
125 :
126 0 : pObject->SingleObjectPainter( *pWindow ); // #110094#-17
127 :
128 0 : pWindow->SetDrawMode( nOldDrawMode );
129 0 : pWindow->SetMapMode( aOld );
130 0 : }
131 :
132 0 : static MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
133 : {
134 0 : MapMode aNew = rMap;
135 0 : Point aOrigin = aNew.GetOrigin();
136 0 : aOrigin.X() -= rMove.Width();
137 0 : aOrigin.Y() -= rMove.Height();
138 0 : aNew.SetOrigin(aOrigin);
139 0 : return aNew;
140 : }
141 :
142 0 : void ScNoteMarker::Draw()
143 : {
144 0 : if ( pObject && bVisible )
145 : {
146 0 : lcl_DrawWin( pObject, pWindow, aMapMode );
147 :
148 0 : if ( pRightWin || pBottomWin )
149 : {
150 0 : Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
151 0 : if ( pRightWin )
152 : lcl_DrawWin( pObject, pRightWin,
153 0 : lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ) );
154 0 : if ( pBottomWin )
155 : lcl_DrawWin( pObject, pBottomWin,
156 0 : lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ) );
157 0 : if ( pDiagWin )
158 0 : lcl_DrawWin( pObject, pDiagWin, lcl_MoveMapMode( aMapMode, aWinSize ) );
159 : }
160 : }
161 0 : }
162 :
163 0 : void ScNoteMarker::InvalidateWin()
164 : {
165 0 : if (bVisible)
166 : {
167 0 : pWindow->Invalidate( OutputDevice::LogicToLogic(aRect, aMapMode, pWindow->GetMapMode()) );
168 :
169 0 : if ( pRightWin || pBottomWin )
170 : {
171 0 : Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
172 0 : if ( pRightWin )
173 0 : pRightWin->Invalidate( OutputDevice::LogicToLogic(aRect,
174 0 : lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ),
175 0 : pRightWin->GetMapMode()) );
176 0 : if ( pBottomWin )
177 0 : pBottomWin->Invalidate( OutputDevice::LogicToLogic(aRect,
178 0 : lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ),
179 0 : pBottomWin->GetMapMode()) );
180 0 : if ( pDiagWin )
181 0 : pDiagWin->Invalidate( OutputDevice::LogicToLogic(aRect,
182 : lcl_MoveMapMode( aMapMode, aWinSize ),
183 0 : pDiagWin->GetMapMode()) );
184 : }
185 : }
186 156 : }
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|