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