Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sw / source / core / view / vdraw.cxx
blob3c331cc15cb1114714730f8449bb8db44d577dc9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svdmodel.hxx>
21 #include <svx/svdpage.hxx>
22 #include <tools/shl.hxx>
23 #include <swmodule.hxx>
24 #include <svtools/accessibilityoptions.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <fmtanchr.hxx>
27 #include <frmfmt.hxx>
29 #include <svx/svdoutl.hxx>
31 #include "fesh.hxx"
32 #include "pagefrm.hxx"
33 #include "rootfrm.hxx"
34 #include "viewimp.hxx"
35 #include "dflyobj.hxx"
36 #include "viewopt.hxx"
37 #include "printdata.hxx"
38 #include "dcontact.hxx"
39 #include "dview.hxx"
40 #include "flyfrm.hxx"
41 #include <vcl/svapp.hxx>
43 #include <IDocumentDrawModelAccess.hxx>
46 void SwViewImp::StartAction()
48 if ( HasDrawView() )
50 SET_CURR_SHELL( GetShell() );
51 if ( pSh->ISA(SwFEShell) )
52 ((SwFEShell*)pSh)->HideChainMarker(); // might have changed
57 void SwViewImp::EndAction()
59 if ( HasDrawView() )
61 SET_CURR_SHELL( GetShell() );
62 if ( pSh->ISA(SwFEShell) )
63 ((SwFEShell*)pSh)->SetChainMarker(); // might have changed
68 void SwViewImp::LockPaint()
70 if ( HasDrawView() )
72 bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
73 GetDrawView()->hideMarkHandles();
75 else
77 bResetHdlHiddenPaint = sal_False;
82 void SwViewImp::UnlockPaint()
84 if ( bResetHdlHiddenPaint )
85 GetDrawView()->showMarkHandles();
89 void SwViewImp::PaintLayer( const SdrLayerID _nLayerID,
90 SwPrintData const*const pPrintData,
91 const SwRect& aPaintRect,
92 const Color* _pPageBackgrdColor,
93 const bool _bIsPageRightToLeft,
94 sdr::contact::ViewObjectContactRedirector* pRedirector ) const
96 if ( HasDrawView() )
98 //change the draw mode in high contrast mode
99 OutputDevice* pOutDev = GetShell()->GetOut();
100 sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
101 if( GetShell()->GetWin() &&
102 Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
103 (!GetShell()->IsPreView()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
105 pOutDev->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
106 DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
109 // For correct handling of accessibility, high contrast, the
110 // page background color is set as the background color at the
111 // outliner of the draw view. Only necessary for the layers
112 // hell and heaven
113 Color aOldOutlinerBackgrdColor;
114 // set default horizontal text direction on painting <hell> or
115 // <heaven>.
116 EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
117 const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
118 if ( (_nLayerID == pIDDMA->GetHellId()) ||
119 (_nLayerID == pIDDMA->GetHeavenId()) )
121 OSL_ENSURE( _pPageBackgrdColor,
122 "incorrect usage of SwViewImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
123 if ( _pPageBackgrdColor )
125 aOldOutlinerBackgrdColor =
126 GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
127 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
130 aOldEEHoriTextDir =
131 GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
132 EEHorizontalTextDirection aEEHoriTextDirOfPage =
133 _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
134 GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
137 pOutDev->Push( PUSH_LINECOLOR ); // #114231#
138 if (pPrintData)
140 // hide drawings but not form controls (form controls are handled elsewhere)
141 SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
142 rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
144 GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector, aPaintRect.SVRect() );
145 pOutDev->Pop();
147 // reset background color of the outliner & default horiz. text dir.
148 if ( (_nLayerID == pIDDMA->GetHellId()) ||
149 (_nLayerID == pIDDMA->GetHeavenId()) )
151 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
152 GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
155 pOutDev->SetDrawMode( nOldDrawMode );
160 #define WIEDUWILLST 400
162 sal_Bool SwViewImp::IsDragPossible( const Point &rPoint )
164 if ( !HasDrawView() )
165 return sal_False;
167 const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
169 if( !rMrkList.GetMarkCount() )
170 return sal_False;
172 SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
174 SwRect aRect;
175 if( pO && ::CalcClipRect( pO, aRect, sal_False ) )
177 SwRect aTmp;
178 ::CalcClipRect( pO, aTmp, sal_True );
179 aRect.Union( aTmp );
181 else
182 aRect = GetShell()->GetLayout()->Frm();
184 aRect.Top( aRect.Top() - WIEDUWILLST );
185 aRect.Bottom( aRect.Bottom() + WIEDUWILLST );
186 aRect.Left( aRect.Left() - WIEDUWILLST );
187 aRect.Right( aRect.Right() + WIEDUWILLST );
188 return aRect.IsInside( rPoint );
192 void SwViewImp::NotifySizeChg( const Size &rNewSz )
194 if ( !HasDrawView() )
195 return;
197 if ( GetPageView() )
198 GetPageView()->GetPage()->SetSize( rNewSz );
200 // Limitation of the work area
201 const Rectangle aRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
202 const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
203 sal_Bool bCheckDrawObjs = sal_False;
204 if ( aRect != rOldWork )
206 if ( rOldWork.Bottom() > aRect.Bottom() || rOldWork.Right() > aRect.Right())
207 bCheckDrawObjs = sal_True;
208 GetDrawView()->SetWorkArea( aRect );
210 if ( !bCheckDrawObjs )
211 return;
213 OSL_ENSURE( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
214 SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
215 const sal_uLong nObjs = pPage->GetObjCount();
216 for( sal_uLong nObj = 0; nObj < nObjs; ++nObj )
218 SdrObject *pObj = pPage->GetObj( nObj );
219 if( !pObj->ISA(SwVirtFlyDrawObj) )
221 // Objects not anchored to the frame, do not need to be adjusted
222 const SwContact *pCont = (SwContact*)GetUserCall(pObj);
223 // this function might be called by the InsertDocument, when
224 // a PageDesc-Attribute is set on a node. Then the SdrObject
225 // must not have an UserCall.
226 if( !pCont || !pCont->ISA(SwDrawContact) )
227 continue;
229 const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
230 if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
231 !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
232 (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
234 continue;
237 // no move for drawing objects in header/footer
238 if ( pAnchor->FindFooterOrHeader() )
240 continue;
243 const Rectangle aBound( pObj->GetCurrentBoundRect() );
244 if ( !aRect.IsInside( aBound ) )
246 Size aSz;
247 if ( aBound.Left() > aRect.Right() )
248 aSz.Width() = (aRect.Right() - aBound.Left()) - MINFLY;
249 if ( aBound.Top() > aRect.Bottom() )
250 aSz.Height() = (aRect.Bottom() - aBound.Top()) - MINFLY;
251 if ( aSz.Width() || aSz.Height() )
252 pObj->Move( aSz );
254 // Don't let large objects dissappear to the top
255 aSz.Width() = aSz.Height() = 0;
256 if ( aBound.Bottom() < aRect.Top() )
257 aSz.Width() = (aBound.Bottom() - aRect.Top()) - MINFLY;
258 if ( aBound.Right() < aRect.Left() )
259 aSz.Height() = (aBound.Right() - aRect.Left()) - MINFLY;
260 if ( aSz.Width() || aSz.Height() )
261 pObj->Move( aSz );
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */