PageRenderTime 30ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/sw/source/core/view/vdraw.cxx

https://github.com/jonasfj/libreoffice-writer
C++ | 378 lines | 198 code | 50 blank | 130 comment | 45 complexity | 12d720903fef468ed69a0e65734cb884 MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * Copyright 2000, 2010 Oracle and/or its affiliates.
  6. *
  7. * OpenOffice.org - a multi-platform office productivity suite
  8. *
  9. * This file is part of OpenOffice.org.
  10. *
  11. * OpenOffice.org is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License version 3
  13. * only, as published by the Free Software Foundation.
  14. *
  15. * OpenOffice.org is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License version 3 for more details
  19. * (a copy is included in the LICENSE file that accompanied this code).
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with OpenOffice.org. If not, see
  23. * <http://www.openoffice.org/license.html>
  24. * for a copy of the LGPLv3 License.
  25. *
  26. ************************************************************************/
  27. // MARKER(update_precomp.py): autogen include statement, do not remove
  28. #include "precompiled_sw.hxx"
  29. #include <svx/svdmodel.hxx>
  30. #include <svx/svdpage.hxx>
  31. #include <tools/shl.hxx>
  32. #include <swmodule.hxx>
  33. #include <svtools/accessibilityoptions.hxx>
  34. #include <svx/svdpagv.hxx>
  35. #include <fmtanchr.hxx>
  36. #include <frmfmt.hxx>
  37. /// OD 29.08.2002 #102450#
  38. /// include <svx/svdoutl.hxx>
  39. #include <svx/svdoutl.hxx>
  40. #ifdef DBG_UTIL
  41. #include <svx/fmglob.hxx>
  42. #endif
  43. #include "fesh.hxx"
  44. #include "pagefrm.hxx"
  45. #include "rootfrm.hxx"
  46. #include "viewimp.hxx"
  47. #include "dflyobj.hxx"
  48. #include "viewopt.hxx"
  49. #include "swprtopt.hxx"
  50. #include "dcontact.hxx"
  51. #include "dview.hxx"
  52. #include "flyfrm.hxx"
  53. #include <vcl/svapp.hxx>
  54. #include <IDocumentDrawModelAccess.hxx>
  55. /*************************************************************************
  56. |*
  57. |* SwSaveHdl
  58. |*
  59. |* Ersterstellung MA 14. Feb. 95
  60. |* Letzte Aenderung MA 02. Jun. 98
  61. |*
  62. |*************************************************************************/
  63. //SwSaveHdl::SwSaveHdl( SwViewImp *pI ) :
  64. // pImp( pI ),
  65. // bXorVis( FALSE )
  66. //{
  67. //if ( pImp->HasDrawView() )
  68. //{
  69. // bXorVis = pImp->GetDrawView()->IsShownXorVisible( pImp->GetShell()->GetOut());
  70. // if ( bXorVis )
  71. // pImp->GetDrawView()->HideShownXor( pImp->GetShell()->GetOut() );
  72. //}
  73. //}
  74. //SwSaveHdl::~SwSaveHdl()
  75. //{
  76. //if ( bXorVis )
  77. // pImp->GetDrawView()->ShowShownXor( pImp->GetShell()->GetOut() );
  78. //}
  79. /*************************************************************************
  80. |*
  81. |* SwViewImp::StartAction(), EndAction()
  82. |*
  83. |* Ersterstellung MA 14. Feb. 95
  84. |* Letzte Aenderung MA 14. Sep. 98
  85. |*
  86. |*************************************************************************/
  87. void SwViewImp::StartAction()
  88. {
  89. if ( HasDrawView() )
  90. {
  91. SET_CURR_SHELL( GetShell() );
  92. if ( pSh->ISA(SwFEShell) )
  93. ((SwFEShell*)pSh)->HideChainMarker(); //Kann sich geaendert haben
  94. //bResetXorVisibility = GetDrawView()->IsShownXorVisible( GetShell()->GetOut());
  95. //GetDrawView()->HideShownXor( GetShell()->GetOut() );
  96. }
  97. }
  98. void SwViewImp::EndAction()
  99. {
  100. if ( HasDrawView() )
  101. {
  102. SET_CURR_SHELL( GetShell() );
  103. //if ( bResetXorVisibility )
  104. // GetDrawView()->ShowShownXor( GetShell()->GetOut() );
  105. if ( pSh->ISA(SwFEShell) )
  106. ((SwFEShell*)pSh)->SetChainMarker(); //Kann sich geaendert haben
  107. }
  108. }
  109. /*************************************************************************
  110. |*
  111. |* SwViewImp::LockPaint(), UnlockPaint()
  112. |*
  113. |* Ersterstellung MA 11. Jun. 96
  114. |* Letzte Aenderung MA 11. Jun. 96
  115. |*
  116. |*************************************************************************/
  117. void SwViewImp::LockPaint()
  118. {
  119. if ( HasDrawView() )
  120. {
  121. //HMHbShowHdlPaint = GetDrawView()->IsMarkHdlShown();
  122. //HMHif ( bShowHdlPaint )
  123. //HMH GetDrawView()->HideMarkHdl();
  124. bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
  125. GetDrawView()->hideMarkHandles();
  126. }
  127. else
  128. {
  129. //HMHbShowHdlPaint = FALSE;
  130. bResetHdlHiddenPaint = FALSE;
  131. }
  132. }
  133. void SwViewImp::UnlockPaint()
  134. {
  135. if ( bResetHdlHiddenPaint )
  136. GetDrawView()->showMarkHandles();
  137. //HMHif ( bShowHdlPaint )
  138. //HMH GetDrawView()->ShowMarkHdl();
  139. }
  140. /*************************************************************************
  141. |*
  142. |* SwViewImp::PaintLayer(), PaintDispatcher()
  143. |*
  144. |* Ersterstellung MA 20. Dec. 94
  145. |* Letzte Aenderung AMA 04. Jun. 98
  146. |*
  147. |*************************************************************************/
  148. // OD 29.08.2002 #102450#
  149. // add 3rd paramter <const Color* pPageBackgrdColor> for setting this
  150. // color as the background color at the outliner of the draw view.
  151. // OD 09.12.2002 #103045# - add 4th parameter for the horizontal text direction
  152. // of the page in order to set the default horizontal text direction at the
  153. // outliner of the draw view for painting layers <hell> and <heaven>.
  154. // OD 25.06.2003 #108784# - correct type of 1st parameter
  155. void SwViewImp::PaintLayer( const SdrLayerID _nLayerID,
  156. const SwPrtOptions * _pPrintData,
  157. const SwRect& ,
  158. const Color* _pPageBackgrdColor,
  159. const bool _bIsPageRightToLeft ) const
  160. {
  161. if ( HasDrawView() )
  162. {
  163. //change the draw mode in high contrast mode
  164. OutputDevice* pOutDev = GetShell()->GetOut();
  165. ULONG nOldDrawMode = pOutDev->GetDrawMode();
  166. if( GetShell()->GetWin() &&
  167. Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
  168. (!GetShell()->IsPreView()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
  169. {
  170. pOutDev->SetDrawMode( nOldDrawMode | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL |
  171. DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
  172. }
  173. // OD 29.08.2002 #102450#
  174. // For correct handling of accessibility, high contrast, the page background
  175. // color is set as the background color at the outliner of the draw view.
  176. // Only necessary for the layers hell and heaven
  177. Color aOldOutlinerBackgrdColor;
  178. // OD 09.12.2002 #103045# - set default horizontal text direction on
  179. // painting <hell> or <heaven>.
  180. EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
  181. const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
  182. if ( (_nLayerID == pIDDMA->GetHellId()) ||
  183. (_nLayerID == pIDDMA->GetHeavenId()) )
  184. {
  185. ASSERT( _pPageBackgrdColor,
  186. "incorrect usage of SwViewImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
  187. if ( _pPageBackgrdColor )
  188. {
  189. aOldOutlinerBackgrdColor =
  190. GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
  191. GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
  192. }
  193. aOldEEHoriTextDir =
  194. GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
  195. EEHorizontalTextDirection aEEHoriTextDirOfPage =
  196. _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
  197. GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
  198. }
  199. pOutDev->Push( PUSH_LINECOLOR ); // #114231#
  200. if (_pPrintData)
  201. {
  202. // hide drawings but not form controls (form controls are handled elsewhere)
  203. SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
  204. rSdrView.setHideDraw( !_pPrintData->IsPrintDraw() );
  205. }
  206. GetPageView()->DrawLayer(_nLayerID, pOutDev);
  207. pOutDev->Pop();
  208. // OD 29.08.2002 #102450#
  209. // reset background color of the outliner
  210. // OD 09.12.2002 #103045# - reset default horizontal text direction
  211. if ( (_nLayerID == pIDDMA->GetHellId()) ||
  212. (_nLayerID == pIDDMA->GetHeavenId()) )
  213. {
  214. GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
  215. GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
  216. }
  217. pOutDev->SetDrawMode( nOldDrawMode );
  218. }
  219. }
  220. /*************************************************************************
  221. |*
  222. |* SwViewImp::IsDragPossible()
  223. |*
  224. |* Ersterstellung MA 19. Jan. 93
  225. |* Letzte Aenderung MA 16. Jan. 95
  226. |*
  227. |*************************************************************************/
  228. #define WIEDUWILLST 400
  229. BOOL SwViewImp::IsDragPossible( const Point &rPoint )
  230. {
  231. if ( !HasDrawView() )
  232. return FALSE;
  233. const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
  234. if( !rMrkList.GetMarkCount() )
  235. return FALSE;
  236. SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
  237. SwRect aRect;
  238. if( ::CalcClipRect( pO, aRect, FALSE ) )
  239. {
  240. SwRect aTmp;
  241. ::CalcClipRect( pO, aTmp, TRUE );
  242. aRect.Union( aTmp );
  243. }
  244. else
  245. aRect = GetShell()->GetLayout()->Frm();
  246. aRect.Top( aRect.Top() - WIEDUWILLST );
  247. aRect.Bottom( aRect.Bottom() + WIEDUWILLST );
  248. aRect.Left( aRect.Left() - WIEDUWILLST );
  249. aRect.Right( aRect.Right() + WIEDUWILLST );
  250. return aRect.IsInside( rPoint );
  251. }
  252. /*************************************************************************
  253. |*
  254. |* SwViewImp::NotifySizeChg()
  255. |*
  256. |* Ersterstellung MA 23. Jun. 93
  257. |* Letzte Aenderung MA 05. Oct. 98
  258. |*
  259. |*************************************************************************/
  260. void SwViewImp::NotifySizeChg( const Size &rNewSz )
  261. {
  262. if ( !HasDrawView() )
  263. return;
  264. if ( GetPageView() )
  265. GetPageView()->GetPage()->SetSize( rNewSz );
  266. //Begrenzung des Arbeitsbereiches.
  267. const Rectangle aRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
  268. const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
  269. BOOL bCheckDrawObjs = FALSE;
  270. if ( aRect != rOldWork )
  271. {
  272. if ( rOldWork.Bottom() > aRect.Bottom() || rOldWork.Right() > aRect.Right())
  273. bCheckDrawObjs = TRUE;
  274. GetDrawView()->SetWorkArea( aRect );
  275. }
  276. if ( !bCheckDrawObjs )
  277. return;
  278. ASSERT( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
  279. SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
  280. const ULONG nObjs = pPage->GetObjCount();
  281. for( ULONG nObj = 0; nObj < nObjs; ++nObj )
  282. {
  283. SdrObject *pObj = pPage->GetObj( nObj );
  284. if( !pObj->ISA(SwVirtFlyDrawObj) )
  285. {
  286. //Teilfix(26793): Objekte, die in Rahmen verankert sind, brauchen
  287. //nicht angepasst werden.
  288. const SwContact *pCont = (SwContact*)GetUserCall(pObj);
  289. //JP - 16.3.00 Bug 73920: this function might be called by the
  290. // InsertDocument, when a PageDesc-Attribute is
  291. // set on a node. Then the SdrObject must not have
  292. // an UserCall.
  293. if( !pCont || !pCont->ISA(SwDrawContact) )
  294. continue;
  295. const SwFrm *pAnchor = ((SwDrawContact*)pCont)->GetAnchorFrm();
  296. if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
  297. !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
  298. (FLY_AS_CHAR == pCont->GetFmt()->GetAnchor().GetAnchorId()) )
  299. {
  300. continue;
  301. }
  302. // OD 19.06.2003 #108784# - no move for drawing objects in header/footer
  303. if ( pAnchor->FindFooterOrHeader() )
  304. {
  305. continue;
  306. }
  307. const Rectangle aBound( pObj->GetCurrentBoundRect() );
  308. if ( !aRect.IsInside( aBound ) )
  309. {
  310. Size aSz;
  311. if ( aBound.Left() > aRect.Right() )
  312. aSz.Width() = (aRect.Right() - aBound.Left()) - MINFLY;
  313. if ( aBound.Top() > aRect.Bottom() )
  314. aSz.Height() = (aRect.Bottom() - aBound.Top()) - MINFLY;
  315. if ( aSz.Width() || aSz.Height() )
  316. pObj->Move( aSz );
  317. //Notanker: Grosse Objekte nicht nach oben verschwinden lassen.
  318. aSz.Width() = aSz.Height() = 0;
  319. if ( aBound.Bottom() < aRect.Top() )
  320. aSz.Width() = (aBound.Bottom() - aRect.Top()) - MINFLY;
  321. if ( aBound.Right() < aRect.Left() )
  322. aSz.Height() = (aBound.Right() - aRect.Left()) - MINFLY;
  323. if ( aSz.Width() || aSz.Height() )
  324. pObj->Move( aSz );
  325. }
  326. }
  327. }
  328. }