xref: /trunk/main/sc/source/ui/view/notemark.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <svx/svdoutl.hxx>
32 #include <svx/svdmodel.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdocapt.hxx>
35 #include <sfx2/printer.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <svl/itempool.hxx>
38 #include <vcl/svapp.hxx>
39 
40 #include "notemark.hxx"
41 #include "document.hxx"
42 #include "postit.hxx"
43 
44 #define SC_NOTEMARK_TIME	800
45 #define SC_NOTEMARK_SHORT	70
46 
47 // -----------------------------------------------------------------------
48 
49 ScNoteMarker::ScNoteMarker( Window* pWin, Window* pRight, Window* pBottom, Window* pDiagonal,
50 							ScDocument* pD, ScAddress aPos, const String& rUser,
51 							const MapMode& rMap, sal_Bool bLeftEdge, sal_Bool bForce, sal_Bool bKeyboard ) :
52 	pWindow( pWin ),
53 	pRightWin( pRight ),
54 	pBottomWin( pBottom ),
55 	pDiagWin( pDiagonal ),
56 	pDoc( pD ),
57 	aDocPos( aPos ),
58 	aUserText( rUser ),
59 	aMapMode( rMap ),
60 	bLeft( bLeftEdge ),
61 	bByKeyboard( bKeyboard ),
62 	pModel( NULL ),
63 	pObject( NULL ),
64 	bVisible( sal_False )
65 {
66     Size aSizePixel = pWindow->GetOutputSizePixel();
67     if( pRightWin )
68         aSizePixel.Width() += pRightWin->GetOutputSizePixel().Width();
69     if( pBottomWin )
70         aSizePixel.Height() += pBottomWin->GetOutputSizePixel().Height();
71     Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
72     aVisRect = pWindow->PixelToLogic( aVisPixel, aMapMode );
73 
74 	aTimer.SetTimeoutHdl( LINK( this, ScNoteMarker, TimeHdl ) );
75 	aTimer.SetTimeout( bForce ? SC_NOTEMARK_SHORT : SC_NOTEMARK_TIME );
76 	aTimer.Start();
77 }
78 
79 ScNoteMarker::~ScNoteMarker()
80 {
81 	InvalidateWin();
82 
83 	delete pModel;
84 }
85 
86 IMPL_LINK( ScNoteMarker, TimeHdl, Timer*, EMPTYARG )
87 {
88 	if (!bVisible)
89 	{
90 		SvtPathOptions aPathOpt;
91 		String aPath = aPathOpt.GetPalettePath();
92 		pModel = new SdrModel(aPath);
93 		pModel->SetScaleUnit(MAP_100TH_MM);
94 		SfxItemPool& rPool = pModel->GetItemPool();
95 		rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
96 		rPool.FreezeIdRanges();
97 
98         OutputDevice* pPrinter = pDoc->GetRefDevice();
99 		if (pPrinter)
100 		{
101 			//	Am Outliner des Draw-Model ist auch der Drucker als RefDevice gesetzt,
102 			//	und es soll einheitlich aussehen.
103 			Outliner& rOutliner = pModel->GetDrawOutliner();
104 			rOutliner.SetRefDevice(pPrinter);
105 		}
106 
107 		if( SdrPage* pPage = pModel->AllocPage( sal_False ) )
108         {
109             pObject = ScNoteUtil::CreateTempCaption( *pDoc, aDocPos, *pPage, aUserText, aVisRect, bLeft );
110             if( pObject )
111                 aRect = pObject->GetCurrentBoundRect();
112 
113             // #39351# Page einfuegen damit das Model sie kennt und auch deleted
114             pModel->InsertPage( pPage );
115 
116         }
117         bVisible = sal_True;
118 	}
119 
120 	Draw();
121 	return 0;
122 }
123 
124 void lcl_DrawWin( SdrObject* pObject, Window* pWindow, const MapMode& rMap )
125 {
126 	MapMode aOld = pWindow->GetMapMode();
127 	pWindow->SetMapMode( rMap );
128 
129 	sal_uLong nOldDrawMode = pWindow->GetDrawMode();
130 	if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
131 	{
132 		pWindow->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
133 							DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
134 	}
135 
136 	pObject->SingleObjectPainter( *pWindow ); // #110094#-17
137 
138 	pWindow->SetDrawMode( nOldDrawMode );
139 	pWindow->SetMapMode( aOld );
140 }
141 
142 MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
143 {
144 	MapMode aNew = rMap;
145 	Point aOrigin = aNew.GetOrigin();
146 	aOrigin.X() -= rMove.Width();
147 	aOrigin.Y() -= rMove.Height();
148 	aNew.SetOrigin(aOrigin);
149 	return aNew;
150 }
151 
152 void ScNoteMarker::Draw()
153 {
154 	if ( pObject && bVisible )
155 	{
156 		lcl_DrawWin( pObject, pWindow, aMapMode );
157 
158 		if ( pRightWin || pBottomWin )
159 		{
160 			Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
161 			if ( pRightWin )
162 				lcl_DrawWin( pObject, pRightWin,
163 								lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ) );
164 			if ( pBottomWin )
165 				lcl_DrawWin( pObject, pBottomWin,
166 								lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ) );
167 			if ( pDiagWin )
168 				lcl_DrawWin( pObject, pDiagWin, lcl_MoveMapMode( aMapMode, aWinSize ) );
169 		}
170 	}
171 }
172 
173 void ScNoteMarker::InvalidateWin()
174 {
175 	if (bVisible)
176 	{
177 		pWindow->Invalidate( pWindow->LogicToLogic(aRect, aMapMode, pWindow->GetMapMode()) );
178 
179 		if ( pRightWin || pBottomWin )
180 		{
181 			Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
182 			if ( pRightWin )
183 				pRightWin->Invalidate( pRightWin->LogicToLogic(aRect,
184 										lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ),
185 										pRightWin->GetMapMode()) );
186 			if ( pBottomWin )
187 				pBottomWin->Invalidate( pBottomWin->LogicToLogic(aRect,
188 										lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ),
189 										pBottomWin->GetMapMode()) );
190 			if ( pDiagWin )
191 				pDiagWin->Invalidate( pDiagWin->LogicToLogic(aRect,
192 										lcl_MoveMapMode( aMapMode, aWinSize ),
193 										pDiagWin->GetMapMode()) );
194 		}
195 	}
196 }
197 
198 
199 
200 
201