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 <editeng/flditem.hxx>
21 #include <vcl/imapobj.hxx>
22 #include <svl/urihelper.hxx>
23 #include <sfx2/sfxhelp.hxx>
24 #include <vcl/help.hxx>
25 #include <svx/svdview.hxx>
26 #include <fmturl.hxx>
27 #include <frmfmt.hxx>
28 #include <doc.hxx>
30 #include <viewimp.hxx>
31 #include <pagefrm.hxx>
32 #include <rootfrm.hxx>
33 #include <viewsh.hxx>
34 #include <drawdoc.hxx>
35 #include <dpage.hxx>
36 #include <dcontact.hxx>
37 #include <dflyobj.hxx>
38 #include <docsh.hxx>
39 #include <flyfrm.hxx>
40 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
41 
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::frame;
45 
46 SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage)
47 : FmFormPage(rNewModel, bMasterPage),
48  pDoc(&rNewModel.GetDoc())
49 {
50 }
51 
53 {
54 }
55 
56 void SwDPage::lateInit(const SwDPage& rSrcPage)
57 {
58  FmFormPage::lateInit( rSrcPage );
59 
60  if ( rSrcPage.pGridLst )
61  {
62  pGridLst.reset( new SdrPageGridFrameList );
63  for ( sal_uInt16 i = 0; i != rSrcPage.pGridLst->GetCount(); ++i )
64  pGridLst->Insert( ( *rSrcPage.pGridLst )[ i ] );
65  }
66 }
67 
68 SwDPage* SwDPage::CloneSdrPage(SdrModel& rTargetModel) const
69 {
70  SwDrawModel& rSwDrawModel(static_cast< SwDrawModel& >(rTargetModel));
71  SwDPage* pClonedSwDPage(
72  new SwDPage(
73  rSwDrawModel,
74  IsMasterPage()));
75  pClonedSwDPage->lateInit(*this);
76  return pClonedSwDPage;
77 }
78 
79 SdrObject* SwDPage::ReplaceObject( SdrObject* pNewObj, size_t nObjNum )
80 {
81  SdrObject *pOld = GetObj( nObjNum );
82  OSL_ENSURE( pOld, "Oups, Object not replaced" );
83  SdrObjUserCall* pContact;
84  if ( nullptr != ( pContact = GetUserCall(pOld) ) &&
85  RES_DRAWFRMFMT == static_cast<SwContact*>(pContact)->GetFormat()->Which())
86  static_cast<SwDrawContact*>(pContact)->ChangeMasterObject( pNewObj );
87  return FmFormPage::ReplaceObject( pNewObj, nObjNum );
88 }
89 
90 static void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrame *pPg )
91 {
92  SwRect aPrt( pPg->getFramePrintArea() );
93  aPrt += pPg->getFrameArea().Pos();
94  const tools::Rectangle aUser( aPrt.SVRect() );
95  const tools::Rectangle aPaper( pPg->getFrameArea().SVRect() );
96  pLst->Insert( SdrPageGridFrame( aPaper, aUser ) );
97 }
98 
100  const SdrPageView* pPV, const tools::Rectangle *pRect ) const
101 {
102  SwViewShell* pSh = static_cast< SwDrawModel& >(getSdrModelFromSdrPage()).GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
103  if(pSh)
104  {
105  for(SwViewShell& rShell : pSh->GetRingContainer())
106  {
107  if(rShell.Imp()->GetPageView() == pPV)
108  {
109  pSh = &rShell;
110  break;
111  }
112  }
113  if ( pGridLst )
114  const_cast<SwDPage*>(this)->pGridLst->Clear();
115  else
116  const_cast<SwDPage*>(this)->pGridLst.reset( new SdrPageGridFrameList );
117 
118  if ( pRect )
119  {
120  //The drawing demands all pages which overlap with the rest.
121  const SwRect aRect( *pRect );
122  const SwFrame *pPg = pSh->GetLayout()->Lower();
123  do
124  { if ( pPg->getFrameArea().IsOver( aRect ) )
125  ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst.get(), pPg );
126  pPg = pPg->GetNext();
127  } while ( pPg );
128  }
129  else
130  {
131  //The drawing demands all visible pages
132  const SwFrame *pPg = pSh->Imp()->GetFirstVisPage(pSh->GetOut());
133  if ( pPg )
134  do
135  { ::InsertGridFrame( const_cast<SwDPage*>(this)->pGridLst.get(), pPg );
136  pPg = pPg->GetNext();
137  } while ( pPg && pPg->getFrameArea().IsOver( pSh->VisArea() ) );
138  }
139  }
140  return pGridLst.get();
141 }
142 
143 bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
144  const HelpEvent& rEvt )
145 {
146  assert( pDoc );
147 
148  bool bContinue = true;
149 
150  if( rEvt.GetMode() & ( HelpEventMode::QUICK | HelpEventMode::BALLOON ))
151  {
152  Point aPos( rEvt.GetMousePosPixel() );
153  aPos = pWindow->ScreenToOutputPixel( aPos );
154  aPos = pWindow->PixelToLogic( aPos );
155 
156  SdrPageView* pPV;
157  SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::PICKMACRO);
158  SwVirtFlyDrawObj* pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
159  OUString sText;
160  tools::Rectangle aPixRect;
161  if (pDrawObj)
162  {
163  SwFlyFrame *pFly = pDrawObj->GetFlyFrame();
164 
165  aPixRect = pWindow->LogicToPixel(pFly->getFrameArea().SVRect());
166 
167  const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
168  if( rURL.GetMap() )
169  {
170  IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly );
171  if( pTmpObj )
172  {
173  sText = pTmpObj->GetAltText();
174  if ( sText.isEmpty() )
175  sText = URIHelper::removePassword( pTmpObj->GetURL(),
178  }
179  }
180  else if ( !rURL.GetURL().isEmpty() )
181  {
182  sText = URIHelper::removePassword( rURL.GetURL(),
185 
186  if( rURL.IsServerMap() )
187  {
188  // then append the relative pixel position!!
189  Point aPt( aPos );
190  aPt -= pFly->getFrameArea().Pos();
191  // without MapMode-Offset !!!!!
192  // without MapMode-Offset, without Offset, w ... !!!!!
193  aPt = pWindow->LogicToPixel(
194  aPt, MapMode( MapUnit::MapTwip ) );
195  sText += "?" + OUString::number( aPt.getX() )
196  + "," + OUString::number( aPt.getY() );
197  }
198  }
199  }
200  else
201  {
202  SdrViewEvent aVEvt;
203  MouseEvent aMEvt(pWindow->ScreenToOutputPixel(rEvt.GetMousePosPixel()), 1,
204  MouseEventModifiers::NONE, MOUSE_LEFT);
205  pView->PickAnything(aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
206  if (aVEvt.eEvent == SdrEventKind::ExecuteUrl)
207  {
208  sText = aVEvt.pURLField->GetURL();
209  aPixRect = pWindow->LogicToPixel(aVEvt.pObj->GetLogicRect());
210  }
211  }
212 
213  if (!sText.isEmpty())
214  {
215  // #i80029#
216  bool bExecHyperlinks = pDoc->GetDocShell()->IsReadOnly();
217  if (!bExecHyperlinks)
218  sText = SfxHelp::GetURLHelpText(sText);
219 
220  // then display the help:
221  tools::Rectangle aScreenRect(pWindow->OutputToScreenPixel(aPixRect.TopLeft()),
222  pWindow->OutputToScreenPixel(aPixRect.BottomRight()));
223 
224  if (rEvt.GetMode() & HelpEventMode::BALLOON)
225  Help::ShowBalloon(pWindow, rEvt.GetMousePosPixel(), aScreenRect, sText);
226  else
227  Help::ShowQuickHelp(pWindow, aScreenRect, sText);
228  bContinue = false;
229  }
230  }
231 
232  if( bContinue )
233  bContinue = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
234 
235  return bContinue;
236 }
237 
239 {
240  assert( pDoc );
241 
243  SwDocShell* pDocShell = pDoc->GetDocShell();
244  if ( pDocShell )
245  {
246  Reference<XModel> xModel = pDocShell->GetBaseModel();
247  Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
248  xRet = xPageSupp->getDrawPage();
249  }
250  return xRet;
251 }
252 
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:341
Point TopLeft() const
Base class of the Writer layout elements.
Definition: frame.hxx:295
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2814
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
SwDocShell * GetDocShell()
Definition: doc.hxx:1342
virtual const SdrPageGridFrameList * GetGridFrameList(const SdrPageView *pPV, const tools::Rectangle *pRect) const override
Definition: dpage.cxx:99
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:170
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:52
css::uno::Reference< css::frame::XModel > GetBaseModel() const
#define MOUSE_LEFT
const Point & GetMousePosPixel() const
long getY() const
long getX() const
Point BottomRight() 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:571
const OUString & GetAltText() const
std::unique_ptr< SdrPageGridFrameList > pGridLst
Definition: dpage.hxx:35
const SwFrame * Lower() const
Definition: layfrm.hxx:101
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:90
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:68
bool IsReadOnly() const
void lateInit(const SwDPage &rSrcPage)
Definition: dpage.cxx:56
const OUString & GetURL() const
IMapObject * GetIMapObject(const Point &rPoint, const SwFlyFrame *pFly=nullptr) const
Definition: atrfrm.cxx:3455
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:238
bool RequestHelp(vcl::Window *pWindow, SdrView const *pView, const HelpEvent &rEvt)
Definition: dpage.cxx:143
SdrModel & getSdrModelFromSdrPage() const
SwFlyFrame * GetFlyFrame()
Definition: dflyobj.hxx:130
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:279
SdrObject * pObj
Reference< XModel > xModel
virtual const tools::Rectangle & GetLogicRect() const
Point OutputToScreenPixel(const Point &rPos) const
bool IsOver(const SwRect &rRect) const
Definition: swrect.cxx:125
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
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:79
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