LibreOffice Module sw (master)  1
dpage.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <basic/basmgr.hxx>
21 #include <editeng/flditem.hxx>
22 #include <vcl/imapobj.hxx>
23 #include <svl/urihelper.hxx>
24 #include <sfx2/sfxhelp.hxx>
26 #include <vcl/help.hxx>
27 #include <vcl/svapp.hxx>
28 #include <svx/svdview.hxx>
29 #include <fmturl.hxx>
30 #include <frmfmt.hxx>
31 #include <doc.hxx>
33 #include <shellres.hxx>
34 #include <viewimp.hxx>
35 #include <pagefrm.hxx>
36 #include <cntfrm.hxx>
37 #include <rootfrm.hxx>
38 #include <frmatr.hxx>
39 #include <viewsh.hxx>
40 #include <drawdoc.hxx>
41 #include <dpage.hxx>
42 #include <dcontact.hxx>
43 #include <dflyobj.hxx>
44 #include <docsh.hxx>
45 #include <usrfld.hxx>
46 #include <flyfrm.hxx>
47 #include <ndnotxt.hxx>
48 #include <grfatr.hxx>
49 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
50 
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::drawing;
53 using namespace ::com::sun::star::frame;
54 
55 SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage)
56 : FmFormPage(rNewModel, bMasterPage),
57  pDoc(&rNewModel.GetDoc())
58 {
59 }
60 
62 {
63 }
64 
65 void SwDPage::lateInit(const SwDPage& rSrcPage)
66 {
67  FmFormPage::lateInit( rSrcPage );
68 
69  if ( rSrcPage.pGridLst )
70  {
71  pGridLst.reset( new SdrPageGridFrameList );
72  for ( sal_uInt16 i = 0; i != rSrcPage.pGridLst->GetCount(); ++i )
73  pGridLst->Insert( ( *rSrcPage.pGridLst )[ i ] );
74  }
75 }
76 
77 SwDPage* SwDPage::CloneSdrPage(SdrModel& rTargetModel) const
78 {
79  SwDrawModel& rSwDrawModel(static_cast< SwDrawModel& >(rTargetModel));
80  SwDPage* pClonedSwDPage(
81  new SwDPage(
82  rSwDrawModel,
83  IsMasterPage()));
84  pClonedSwDPage->lateInit(*this);
85  return pClonedSwDPage;
86 }
87 
88 SdrObject* SwDPage::ReplaceObject( SdrObject* pNewObj, size_t nObjNum )
89 {
90  SdrObject *pOld = GetObj( nObjNum );
91  OSL_ENSURE( pOld, "Oups, Object not replaced" );
92  SdrObjUserCall* pContact;
93  if ( nullptr != ( pContact = GetUserCall(pOld) ) &&
94  RES_DRAWFRMFMT == static_cast<SwContact*>(pContact)->GetFormat()->Which())
95  static_cast<SwDrawContact*>(pContact)->ChangeMasterObject( pNewObj );
96  return FmFormPage::ReplaceObject( pNewObj, nObjNum );
97 }
98 
99 static void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrame *pPg )
100 {
101  SwRect aPrt( pPg->getFramePrintArea() );
102  aPrt += pPg->getFrameArea().Pos();
103  const tools::Rectangle aUser( aPrt.SVRect() );
104  const tools::Rectangle aPaper( pPg->getFrameArea().SVRect() );
105  pLst->Insert( SdrPageGridFrame( aPaper, aUser ) );
106 }
107 
109  const SdrPageView* pPV, const tools::Rectangle *pRect ) const
110 {
111  SwViewShell* pSh = static_cast< SwDrawModel& >(getSdrModelFromSdrPage()).GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
112  if(pSh)
113  {
114  for(SwViewShell& rShell : pSh->GetRingContainer())
115  {
116  if(rShell.Imp()->GetPageView() == pPV)
117  {
118  pSh = &rShell;
119  break;
120  }
121  }
122  if ( pGridLst )
123  const_cast<SwDPage*>(this)->pGridLst->Clear();
124  else
125  const_cast<SwDPage*>(this)->pGridLst.reset( new SdrPageGridFrameList );
126 
127  if ( pRect )
128  {
129  //The drawing demands all pages which overlap with the rest.
130  const SwRect aRect( *pRect );
131  const SwFrame *pPg = pSh->GetLayout()->Lower();
132  do
133  { if ( pPg->getFrameArea().IsOver( aRect ) )
134  ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst.get(), pPg );
135  pPg = pPg->GetNext();
136  } while ( pPg );
137  }
138  else
139  {
140  //The drawing demands all visible pages
141  const SwFrame *pPg = pSh->Imp()->GetFirstVisPage(pSh->GetOut());
142  if ( pPg )
143  do
144  { ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst.get(), pPg );
145  pPg = pPg->GetNext();
146  } while ( pPg && pPg->getFrameArea().IsOver( pSh->VisArea() ) );
147  }
148  }
149  return pGridLst.get();
150 }
151 
152 bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
153  const HelpEvent& rEvt )
154 {
155  assert( pDoc );
156 
157  bool bContinue = true;
158 
159  if( rEvt.GetMode() & ( HelpEventMode::QUICK | HelpEventMode::BALLOON ))
160  {
161  Point aPos( rEvt.GetMousePosPixel() );
162  aPos = pWindow->ScreenToOutputPixel( aPos );
163  aPos = pWindow->PixelToLogic( aPos );
164 
165  SdrPageView* pPV;
166  SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::PICKMACRO);
167  SwVirtFlyDrawObj* pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
168  OUString sText;
169  if (pDrawObj)
170  {
171  SwFlyFrame *pFly = pDrawObj->GetFlyFrame();
172  const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
173  if( rURL.GetMap() )
174  {
175  IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly );
176  if( pTmpObj )
177  {
178  sText = pTmpObj->GetAltText();
179  if ( sText.isEmpty() )
180  sText = URIHelper::removePassword( pTmpObj->GetURL(),
183  }
184  }
185  else if ( !rURL.GetURL().isEmpty() )
186  {
187  sText = URIHelper::removePassword( rURL.GetURL(),
190 
191  if( rURL.IsServerMap() )
192  {
193  // then append the relative pixel position!!
194  Point aPt( aPos );
195  aPt -= pFly->getFrameArea().Pos();
196  // without MapMode-Offset !!!!!
197  // without MapMode-Offset, without Offset, w ... !!!!!
198  aPt = pWindow->LogicToPixel(
199  aPt, MapMode( MapUnit::MapTwip ) );
200  sText += "?" + OUString::number( aPt.getX() )
201  + "," + OUString::number( aPt.getY() );
202  }
203  }
204  }
205  else
206  {
207  SdrViewEvent aVEvt;
208  MouseEvent aMEvt(pWindow->ScreenToOutputPixel(rEvt.GetMousePosPixel()), 1,
209  MouseEventModifiers::NONE, MOUSE_LEFT);
210  pView->PickAnything(aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
211  if (aVEvt.eEvent == SdrEventKind::ExecuteUrl)
212  {
213  sText = aVEvt.pURLField->GetURL();
214  }
215  }
216 
217  if (!sText.isEmpty())
218  {
219  // #i80029#
220  bool bExecHyperlinks = pDoc->GetDocShell()->IsReadOnly();
221  if (!bExecHyperlinks)
222  sText = SfxHelp::GetURLHelpText(sText);
223 
224  // then display the help:
225  tools::Rectangle aRect(rEvt.GetMousePosPixel(), Size(1, 1));
226  if (rEvt.GetMode() & HelpEventMode::BALLOON)
227  Help::ShowBalloon(pWindow, rEvt.GetMousePosPixel(), aRect, sText);
228  else
229  Help::ShowQuickHelp(pWindow, aRect, sText);
230  bContinue = false;
231  }
232  }
233 
234  if( bContinue )
235  bContinue = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
236 
237  return bContinue;
238 }
239 
241 {
242  assert( pDoc );
243 
245  SwDocShell* pDocShell = pDoc->GetDocShell();
246  if ( pDocShell )
247  {
248  Reference<XModel> xModel = pDocShell->GetBaseModel();
249  Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
250  xRet = xPageSupp->getDrawPage();
251  }
252  return xRet;
253 }
254 
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:341
Base class of the Writer layout elements.
Definition: frame.hxx:295
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2816
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
SwDocShell * GetDocShell()
Definition: doc.hxx:1341
virtual const SdrPageGridFrameList * GetGridFrameList(const SdrPageView *pPV, const tools::Rectangle *pRect) const override
Definition: dpage.cxx:108
const SwRect & getFramePrintArea() const
Definition: frame.hxx:176
SdrObject * GetObj(size_t nNum) const
SVL_DLLPUBLIC OUString removePassword(OUString const &rURI, INetURLObject::EncodeMechanism eEncodeMechanism, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void Pos(const Point &rNew)
Definition: swrect.hxx:167
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
SwDPage(const SwDPage &)=delete
void lateInit(const FmFormPage &rPage)
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:176
HelpEventMode GetMode() const
const SwPageFrame * GetFirstVisPage(OutputDevice const *pRenderContext) const
Management of the first visible Page.
Definition: viewimp.cxx:277
const SwRect & getFrameArea() const
Definition: frame.hxx:175
const SvxURLField * pURLField
virtual ~SwDPage() override
Definition: dpage.cxx:61
css::uno::Reference< css::frame::XModel > GetBaseModel() const
#define MOUSE_LEFT
const Point & GetMousePosPixel() const
long getY() const
long getX() const
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
void Insert(const SdrPageGridFrame &rGF)
const SwRect & VisArea() const
Definition: viewsh.cxx:569
const OUString & GetAltText() const
std::unique_ptr< SdrPageGridFrameList > pGridLst
Definition: dpage.hxx:35
const SwFrame * Lower() const
Definition: layfrm.hxx:100
int i
SdrEventKind eEvent
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:78
bool IsMasterPage() const
ring_container GetRingContainer()
Definition: ring.hxx:240
static void InsertGridFrame(SdrPageGridFrameList *pLst, const SwFrame *pPg)
Definition: dpage.cxx:99
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
Point ScreenToOutputPixel(const Point &rPos) const
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
virtual SwDPage * CloneSdrPage(SdrModel &rTargetModel) const override
Definition: dpage.cxx:77
bool IsReadOnly() const
void lateInit(const SwDPage &rSrcPage)
Definition: dpage.cxx:65
const OUString & GetURL() const
IMapObject * GetIMapObject(const Point &rPoint, const SwFlyFrame *pFly=nullptr) const
Definition: atrfrm.cxx:3433
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
const ImageMap * GetMap() const
Definition: fmturl.hxx:68
virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override
Definition: dpage.cxx:240
bool RequestHelp(vcl::Window *pWindow, SdrView const *pView, const HelpEvent &rEvt)
Definition: dpage.cxx:152
SdrModel & getSdrModelFromSdrPage() const
SwFlyFrame * GetFlyFrame()
Definition: dflyobj.hxx:127
tools::Rectangle SVRect() const
Definition: swrect.hxx:282
virtual SdrObject * ReplaceObject(SdrObject *pNewObj, size_t nObjNum)
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
#define RES_DRAWFRMFMT
Definition: hintids.hxx:277
Reference< XModel > xModel
bool IsOver(const SwRect &rRect) const
Definition: swrect.cxx:125
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
bool IsServerMap() const
Definition: fmturl.hxx:67
static OUString GetURLHelpText(const OUString &)
SwDoc * pDoc
Definition: dpage.hxx:36
const OUString & GetURL() const
virtual SdrObject * ReplaceObject(SdrObject *pNewObj, size_t nObjNum) override
Definition: dpage.cxx:88
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
const OUString & GetURL() const
Definition: fmturl.hxx:66
SwFrame * GetNext()
Definition: frame.hxx:654