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