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