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