xref: /trunk/main/sw/source/core/view/vdraw.cxx (revision d8dff77764cb74143fabc617dc8ee25d946bae78)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include <svx/svdmodel.hxx>
26 #include <svx/svdpage.hxx>
27 #include <tools/shl.hxx>
28 #include <swmodule.hxx>
29 #include <svtools/accessibilityoptions.hxx>
30 #include <svx/svdpagv.hxx>
31 #include <fmtanchr.hxx>
32 #include <frmfmt.hxx>
33 #include <svx/svdoutl.hxx>
34 #ifdef DBG_UTIL
35 #include <svx/fmglob.hxx>
36 #endif
37 #include "fesh.hxx"
38 #include "pagefrm.hxx"
39 #include "rootfrm.hxx"
40 #include "viewimp.hxx"
41 #include "dflyobj.hxx"
42 #include "viewopt.hxx"
43 #include "printdata.hxx"
44 #include "dcontact.hxx"
45 #include "dview.hxx"
46 #include "flyfrm.hxx"
47 #include <vcl/svapp.hxx>
48 #include <IDocumentDrawModelAccess.hxx>
49 #include <drawdoc.hxx>
50 
51 /*************************************************************************
52 |*  SwSaveHdl
53 |*
54 |*  Ersterstellung      MA 14. Feb. 95
55 |*  Letzte Aenderung    MA 02. Jun. 98
56 **************************************************************************/
57 //SwSaveHdl::SwSaveHdl( SwViewImp *pI ) :
58 //  pImp( pI ),
59 //  bXorVis( sal_False )
60 //{
61     //if ( pImp->HasDrawView() )
62     //{
63     //  bXorVis = pImp->GetDrawView()->IsShownXorVisible( pImp->GetShell()->GetOut());
64     //  if ( bXorVis )
65     //      pImp->GetDrawView()->HideShownXor( pImp->GetShell()->GetOut() );
66     //}
67 //}
68 
69 
70 //SwSaveHdl::~SwSaveHdl()
71 //{
72     //if ( bXorVis )
73     //  pImp->GetDrawView()->ShowShownXor( pImp->GetShell()->GetOut() );
74 //}
75 
76 
77 /*************************************************************************
78 |*  SwViewImp::StartAction(), EndAction()
79 |*
80 |*  Ersterstellung      MA 14. Feb. 95
81 |*  Letzte Aenderung    MA 14. Sep. 98
82 **************************************************************************/
83 
84 
85 void SwViewImp::StartAction()
86 {
87     if ( HasDrawView() )
88     {
89         SET_CURR_SHELL( GetShell() );
90         if ( pSh->ISA(SwFEShell) )
91             ((SwFEShell*)pSh)->HideChainMarker();   //Kann sich geaendert haben
92         //bResetXorVisibility = GetDrawView()->IsShownXorVisible( GetShell()->GetOut());
93         //GetDrawView()->HideShownXor( GetShell()->GetOut() );
94     }
95 }
96 
97 
98 
99 void SwViewImp::EndAction()
100 {
101     if ( HasDrawView() )
102     {
103         SET_CURR_SHELL( GetShell() );
104         //if ( bResetXorVisibility )
105         //  GetDrawView()->ShowShownXor( GetShell()->GetOut() );
106         if ( pSh->ISA(SwFEShell) )
107             ((SwFEShell*)pSh)->SetChainMarker();    //Kann sich geaendert haben
108     }
109 }
110 
111 /*************************************************************************
112 |*  SwViewImp::LockPaint(), UnlockPaint()
113 |*
114 |*  Ersterstellung      MA 11. Jun. 96
115 |*  Letzte Aenderung    MA 11. Jun. 96
116 **************************************************************************/
117 
118 
119 void SwViewImp::LockPaint()
120 {
121     if ( HasDrawView() )
122     {
123         //HMHbShowHdlPaint = GetDrawView()->IsMarkHdlShown();
124         //HMHif ( bShowHdlPaint )
125         //HMH   GetDrawView()->HideMarkHdl();
126         bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
127         GetDrawView()->hideMarkHandles();
128     }
129     else
130     {
131         //HMHbShowHdlPaint = sal_False;
132         bResetHdlHiddenPaint = sal_False;
133     }
134 }
135 
136 
137 
138 void SwViewImp::UnlockPaint()
139 {
140     if ( bResetHdlHiddenPaint )
141         GetDrawView()->showMarkHandles();
142     //HMHif ( bShowHdlPaint )
143     //HMH   GetDrawView()->ShowMarkHdl();
144 }
145 
146 
147 /*************************************************************************
148 |*  SwViewImp::PaintLayer(), PaintDispatcher()
149 |*
150 |*  Ersterstellung      MA 20. Dec. 94
151 |*  Letzte Aenderung    AMA 04. Jun. 98
152 **************************************************************************/
153 // OD 29.08.2002 #102450#
154 // add 3rd parameter <const Color* pPageBackgrdColor> for setting this
155 // color as the background color at the outliner of the draw view.
156 // OD 09.12.2002 #103045# - add 4th parameter for the horizontal text direction
157 // of the page in order to set the default horizontal text direction at the
158 // outliner of the draw view for painting layers <hell> and <heaven>.
159 // OD 25.06.2003 #108784# - correct type of 1st parameter
160 void SwViewImp::PaintLayer( const SdrLayerID _nLayerID,
161                             SwPrintData const*const pPrintData,
162                             const SwRect& ,
163                             const Color* _pPageBackgrdColor,
164                             const bool _bIsPageRightToLeft,
165                             sdr::contact::ViewObjectContactRedirector* pRedirector ) const
166 {
167     if ( HasDrawView() )
168     {
169         // change the draw mode in high contrast mode
170         OutputDevice* pOutDev = GetShell()->GetOut();
171         sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
172         if( GetShell()->GetWin() &&
173             Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
174             (!GetShell()->IsPreView()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
175         {
176             pOutDev->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
177                                   DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
178         }
179 
180         // OD 29.08.2002 #102450#
181         // For correct handling of accessibility, high contrast, the page background
182         // color is set as the background color at the outliner of the draw view.
183         // Only necessary for the layers hell and heaven
184         Color aOldOutlinerBackgrdColor;
185         // OD 09.12.2002 #103045# - set default horizontal text direction on
186         // painting <hell> or <heaven>.
187         EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
188         const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
189         if ( (_nLayerID == pIDDMA->GetHellId()) ||
190              (_nLayerID == pIDDMA->GetHeavenId()) )
191         {
192             ASSERT( _pPageBackgrdColor,
193                     "incorrect usage of SwViewImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
194             if ( _pPageBackgrdColor )
195             {
196                 aOldOutlinerBackgrdColor =
197                         GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
198                 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
199             }
200 
201             aOldEEHoriTextDir =
202                 GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
203             EEHorizontalTextDirection aEEHoriTextDirOfPage =
204                 _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
205             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
206         }
207 
208         pOutDev->Push( PUSH_LINECOLOR ); // #114231#
209         if (pPrintData)
210         {
211             // hide drawings but not form controls (form controls are handled elsewhere)
212             SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
213             rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
214         }
215         GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector );
216         pOutDev->Pop();
217 
218         // OD 29.08.2002 #102450#
219         // reset background color of the outliner
220         // OD 09.12.2002 #103045# - reset default horizontal text direction
221         if ( (_nLayerID == pIDDMA->GetHellId()) ||
222              (_nLayerID == pIDDMA->GetHeavenId()) )
223         {
224             GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
225             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
226         }
227 
228         pOutDev->SetDrawMode( nOldDrawMode );
229     }
230 }
231 
232 /*************************************************************************
233 |*  SwViewImp::IsDragPossible()
234 |*
235 |*  Ersterstellung      MA 19. Jan. 93
236 |*  Letzte Aenderung    MA 16. Jan. 95
237 **************************************************************************/
238 #define WIEDUWILLST 400
239 
240 sal_Bool SwViewImp::IsDragPossible( const Point &rPoint )
241 {
242     if ( !HasDrawView() )
243         return sal_False;
244 
245     const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
246 
247     if( !rMrkList.GetMarkCount() )
248         return sal_False;
249 
250     SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
251 
252     SwRect aRect;
253     if( pO && ::CalcClipRect( pO, aRect, sal_False ) )
254     {
255         SwRect aTmp;
256         ::CalcClipRect( pO, aTmp, sal_True );
257         aRect.Union( aTmp );
258     }
259     else
260         aRect = GetShell()->GetLayout()->Frm();
261 
262     aRect.Top(    aRect.Top()    - WIEDUWILLST );
263     aRect.Bottom( aRect.Bottom() + WIEDUWILLST );
264     aRect.Left(   aRect.Left()   - WIEDUWILLST );
265     aRect.Right(  aRect.Right()  + WIEDUWILLST );
266     return aRect.IsInside( rPoint );
267 }
268 
269 /*************************************************************************
270 |*  SwViewImp::NotifySizeChg()
271 |*
272 |*  Ersterstellung      MA 23. Jun. 93
273 |*  Letzte Aenderung    MA 05. Oct. 98
274 **************************************************************************/
275 
276 void SwViewImp::NotifySizeChg( const Size &rNewSz )
277 {
278     if ( !HasDrawView() )
279         return;
280 
281     if ( GetPageView() )
282         GetPageView()->GetPage()->SetSize( rNewSz );
283 
284     //Begrenzung des Arbeitsbereiches.
285     const Rectangle aRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
286     const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
287     sal_Bool bCheckDrawObjs = sal_False;
288     if ( aRect != rOldWork )
289     {
290         if ( rOldWork.Bottom() > aRect.Bottom() || rOldWork.Right() > aRect.Right())
291             bCheckDrawObjs = sal_True;
292         GetDrawView()->SetWorkArea( aRect );
293     }
294     if ( !bCheckDrawObjs )
295         return;
296 
297     ASSERT( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
298     SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
299     const sal_uLong nObjs = pPage->GetObjCount();
300     for( sal_uLong nObj = 0; nObj < nObjs; ++nObj )
301     {
302         SdrObject *pObj = pPage->GetObj( nObj );
303         if( !pObj->ISA(SwVirtFlyDrawObj) )
304         {
305             //Teilfix(26793): Objekte, die in Rahmen verankert sind, brauchen
306             //nicht angepasst werden.
307             const SwContact *pCont = (SwContact*)GetUserCall(pObj);
308             //JP - 16.3.00 Bug 73920: this function might be called by the
309             //              InsertDocument, when a PageDesc-Attribute is
310             //              set on a node. Then the SdrObject must not have
311             //              an UserCall.
312             if( !pCont || !pCont->ISA(SwDrawContact) )
313                 continue;
314 
315             const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
316             if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
317                  !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
318                  (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
319             {
320                 continue;
321             }
322 
323             // OD 19.06.2003 #108784# - no move for drawing objects in header/footer
324             if ( pAnchor->FindFooterOrHeader() )
325             {
326                 continue;
327             }
328 
329             const Rectangle aBound( pObj->GetCurrentBoundRect() );
330             if ( !aRect.IsInside( aBound ) )
331             {
332                 Size aSz;
333                 if ( aBound.Left() > aRect.Right() )
334                     aSz.Width() = (aRect.Right() - aBound.Left()) - MINFLY;
335                 if ( aBound.Top() > aRect.Bottom() )
336                     aSz.Height() = (aRect.Bottom() - aBound.Top()) - MINFLY;
337                 if ( aSz.Width() || aSz.Height() )
338                     pObj->Move( aSz );
339 
340                 // Notanker: Grosse Objekte nicht nach oben verschwinden lassen.
341                 aSz.Width() = aSz.Height() = 0;
342                 if ( aBound.Bottom() < aRect.Top() )
343                     aSz.Width() = (aBound.Bottom() - aRect.Top()) - MINFLY;
344                 if ( aBound.Right() < aRect.Left() )
345                     aSz.Height() = (aBound.Right() - aRect.Left()) - MINFLY;
346                 if ( aSz.Width() || aSz.Height() )
347                     pObj->Move( aSz );
348             }
349         }
350     }
351 }
352 
353 /* vim: set noet sw=4 ts=4: */
354