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