xref: /aoo42x/main/sc/source/ui/view/notemark.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include <svx/svdoutl.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svx/svdocapt.hxx>
31 #include <sfx2/printer.hxx>
32 #include <unotools/pathoptions.hxx>
33 #include <svl/itempool.hxx>
34 #include <vcl/svapp.hxx>
35 
36 #include "notemark.hxx"
37 #include "document.hxx"
38 #include "postit.hxx"
39 
40 #define SC_NOTEMARK_TIME	800
41 #define SC_NOTEMARK_SHORT	70
42 
43 // -----------------------------------------------------------------------
44 
ScNoteMarker(Window * pWin,Window * pRight,Window * pBottom,Window * pDiagonal,ScDocument * pD,ScAddress aPos,const String & rUser,const MapMode & rMap,sal_Bool bLeftEdge,sal_Bool bForce,sal_Bool bKeyboard)45 ScNoteMarker::ScNoteMarker( Window* pWin, Window* pRight, Window* pBottom, Window* pDiagonal,
46 							ScDocument* pD, ScAddress aPos, const String& rUser,
47 							const MapMode& rMap, sal_Bool bLeftEdge, sal_Bool bForce, sal_Bool bKeyboard ) :
48 	pWindow( pWin ),
49 	pRightWin( pRight ),
50 	pBottomWin( pBottom ),
51 	pDiagWin( pDiagonal ),
52 	pDoc( pD ),
53 	aDocPos( aPos ),
54 	aUserText( rUser ),
55 	aMapMode( rMap ),
56 	bLeft( bLeftEdge ),
57 	bByKeyboard( bKeyboard ),
58 	pModel( NULL ),
59 	pObject( NULL ),
60 	bVisible( sal_False )
61 {
62     Size aSizePixel = pWindow->GetOutputSizePixel();
63     if( pRightWin )
64         aSizePixel.Width() += pRightWin->GetOutputSizePixel().Width();
65     if( pBottomWin )
66         aSizePixel.Height() += pBottomWin->GetOutputSizePixel().Height();
67     Rectangle aVisPixel( Point( 0, 0 ), aSizePixel );
68     aVisRect = pWindow->PixelToLogic( aVisPixel, aMapMode );
69 
70 	aTimer.SetTimeoutHdl( LINK( this, ScNoteMarker, TimeHdl ) );
71 	aTimer.SetTimeout( bForce ? SC_NOTEMARK_SHORT : SC_NOTEMARK_TIME );
72 	aTimer.Start();
73 }
74 
~ScNoteMarker()75 ScNoteMarker::~ScNoteMarker()
76 {
77 	InvalidateWin();
78 
79 	delete pModel;
80 }
81 
IMPL_LINK(ScNoteMarker,TimeHdl,Timer *,EMPTYARG)82 IMPL_LINK( ScNoteMarker, TimeHdl, Timer*, EMPTYARG )
83 {
84 	if (!bVisible)
85 	{
86 		SvtPathOptions aPathOpt;
87 		String aPath = aPathOpt.GetPalettePath();
88 		pModel = new SdrModel(aPath);
89 		pModel->SetScaleUnit(MAP_100TH_MM);
90 		SfxItemPool& rPool = pModel->GetItemPool();
91 		rPool.SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
92 		rPool.FreezeIdRanges();
93 
94         OutputDevice* pPrinter = pDoc->GetRefDevice();
95 		if (pPrinter)
96 		{
97 			//	Am Outliner des Draw-Model ist auch der Drucker als RefDevice gesetzt,
98 			//	und es soll einheitlich aussehen.
99 			Outliner& rOutliner = pModel->GetDrawOutliner();
100 			rOutliner.SetRefDevice(pPrinter);
101 		}
102 
103 		if( SdrPage* pPage = pModel->AllocPage( sal_False ) )
104         {
105             pObject = ScNoteUtil::CreateTempCaption( *pDoc, aDocPos, *pPage, aUserText, aVisRect, bLeft );
106             if( pObject )
107                 aRect = pObject->GetCurrentBoundRect();
108 
109             // #39351# Page einfuegen damit das Model sie kennt und auch deleted
110             pModel->InsertPage( pPage );
111 
112         }
113         bVisible = sal_True;
114 	}
115 
116 	Draw();
117 	return 0;
118 }
119 
lcl_DrawWin(SdrObject * pObject,Window * pWindow,const MapMode & rMap)120 void lcl_DrawWin( SdrObject* pObject, Window* pWindow, const MapMode& rMap )
121 {
122 	MapMode aOld = pWindow->GetMapMode();
123 	pWindow->SetMapMode( rMap );
124 
125 	sal_uLong nOldDrawMode = pWindow->GetDrawMode();
126 	if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
127 	{
128 		pWindow->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
129 							DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
130 	}
131 
132 	pObject->SingleObjectPainter( *pWindow ); // #110094#-17
133 
134 	pWindow->SetDrawMode( nOldDrawMode );
135 	pWindow->SetMapMode( aOld );
136 }
137 
lcl_MoveMapMode(const MapMode & rMap,const Size & rMove)138 MapMode lcl_MoveMapMode( const MapMode& rMap, const Size& rMove )
139 {
140 	MapMode aNew = rMap;
141 	Point aOrigin = aNew.GetOrigin();
142 	aOrigin.X() -= rMove.Width();
143 	aOrigin.Y() -= rMove.Height();
144 	aNew.SetOrigin(aOrigin);
145 	return aNew;
146 }
147 
Draw()148 void ScNoteMarker::Draw()
149 {
150 	if ( pObject && bVisible )
151 	{
152 		lcl_DrawWin( pObject, pWindow, aMapMode );
153 
154 		if ( pRightWin || pBottomWin )
155 		{
156 			Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
157 			if ( pRightWin )
158 				lcl_DrawWin( pObject, pRightWin,
159 								lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ) );
160 			if ( pBottomWin )
161 				lcl_DrawWin( pObject, pBottomWin,
162 								lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ) );
163 			if ( pDiagWin )
164 				lcl_DrawWin( pObject, pDiagWin, lcl_MoveMapMode( aMapMode, aWinSize ) );
165 		}
166 	}
167 }
168 
InvalidateWin()169 void ScNoteMarker::InvalidateWin()
170 {
171 	if (bVisible)
172 	{
173 		pWindow->Invalidate( pWindow->LogicToLogic(aRect, aMapMode, pWindow->GetMapMode()) );
174 
175 		if ( pRightWin || pBottomWin )
176 		{
177 			Size aWinSize = pWindow->PixelToLogic( pWindow->GetOutputSizePixel(), aMapMode );
178 			if ( pRightWin )
179 				pRightWin->Invalidate( pRightWin->LogicToLogic(aRect,
180 										lcl_MoveMapMode( aMapMode, Size( aWinSize.Width(), 0 ) ),
181 										pRightWin->GetMapMode()) );
182 			if ( pBottomWin )
183 				pBottomWin->Invalidate( pBottomWin->LogicToLogic(aRect,
184 										lcl_MoveMapMode( aMapMode, Size( 0, aWinSize.Height() ) ),
185 										pBottomWin->GetMapMode()) );
186 			if ( pDiagWin )
187 				pDiagWin->Invalidate( pDiagWin->LogicToLogic(aRect,
188 										lcl_MoveMapMode( aMapMode, aWinSize ),
189 										pDiagWin->GetMapMode()) );
190 		}
191 	}
192 }
193 
194 
195 
196 
197