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
44using namespace ::com::sun::star::uno;
45using namespace ::com::sun::star::drawing;
46using namespace ::com::sun::star::frame;
47
48SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage)
49: FmFormPage(rNewModel, bMasterPage),
50 m_pDoc(&rNewModel.GetDoc())
51{
52}
53
55{
56}
57
58void SwDPage::lateInit(const SwDPage& rSrcPage)
59{
60 FmFormPage::lateInit( rSrcPage );
61
62 if ( rSrcPage.m_pGridLst )
63 {
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
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
92static 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
145bool 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 bool bTooltip = false;
164 if (pDrawObj)
165 {
166 SwFlyFrame *pFly = pDrawObj->GetFlyFrame();
167
168 aPixRect = pWindow->LogicToPixel(pFly->getFrameArea().SVRect());
169
170 const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
171 if (!pFly->GetFormat()->GetObjTooltip().isEmpty())
172 {
173 // Tooltips have priority over URLs.
174 sText = pFly->GetFormat()->GetObjTooltip();
175 bTooltip = true;
176 }
177 else if( rURL.GetMap() )
178 {
179 IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly );
180 if( pTmpObj )
181 {
182 sText = pTmpObj->GetAltText();
183 if ( sText.isEmpty() )
184 sText = URIHelper::removePassword( pTmpObj->GetURL(),
187 }
188 }
189 else if ( !rURL.GetURL().isEmpty() )
190 {
191 sText = URIHelper::removePassword( rURL.GetURL(),
194
195 if( rURL.IsServerMap() )
196 {
197 // then append the relative pixel position!!
198 Point aPt( aPos );
199 aPt -= pFly->getFrameArea().Pos();
200 // without MapMode-Offset !!!!!
201 // without MapMode-Offset, without Offset, w ... !!!!!
202 aPt = pWindow->LogicToPixel(
203 aPt, MapMode( MapUnit::MapTwip ) );
204 sText += "?" + OUString::number( aPt.getX() )
205 + "," + OUString::number( aPt.getY() );
206 }
207 }
208 }
209 else
210 {
211 SdrViewEvent aVEvt;
212 MouseEvent aMEvt(pWindow->ScreenToOutputPixel(rEvt.GetMousePosPixel()), 1,
213 MouseEventModifiers::NONE, MOUSE_LEFT);
214 pView->PickAnything(aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
215 if (aVEvt.meEvent == SdrEventKind::ExecuteUrl && aVEvt.mpURLField)
216 {
217 sText = aVEvt.mpURLField->GetURL();
218 aPixRect = pWindow->LogicToPixel(aVEvt.mpObj->GetLogicRect());
219 }
220 }
221
222 if (!sText.isEmpty())
223 {
224 // #i80029#
225 bool bExecHyperlinks = m_pDoc->GetDocShell()->IsReadOnly();
226 if (!bExecHyperlinks && !bTooltip)
227 sText = SfxHelp::GetURLHelpText(sText);
228
229 // then display the help:
230 tools::Rectangle aScreenRect(pWindow->OutputToScreenPixel(aPixRect.TopLeft()),
231 pWindow->OutputToScreenPixel(aPixRect.BottomRight()));
232
233 if (rEvt.GetMode() & HelpEventMode::BALLOON)
234 Help::ShowBalloon(pWindow, rEvt.GetMousePosPixel(), aScreenRect, sText);
235 else
236 Help::ShowQuickHelp(pWindow, aScreenRect, sText);
237 bContinue = false;
238 }
239 }
240
241 if( bContinue )
242 bContinue = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
243
244 return bContinue;
245}
246
247Reference< XInterface > SwDPage::createUnoPage()
248{
249 assert( m_pDoc );
250
251 Reference < XInterface > xRet;
252 SwDocShell* pDocShell = m_pDoc->GetDocShell();
253 if ( pDocShell )
254 {
255 Reference<XModel> xModel = pDocShell->GetBaseModel();
256 Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
257 xRet = xPageSupp->getDrawPage();
258 }
259 return xRet;
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void lateInit(const FmFormPage &rPage)
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
HelpEventMode GetMode() const
const Point & GetMousePosPixel() const
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
const OUString & GetAltText() const
const OUString & GetURL() const
constexpr tools::Long getX() const
constexpr tools::Long getY() const
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
virtual rtl::Reference< SdrObject > ReplaceObject(SdrObject *pNewObj, size_t nObjNum)
SdrObject * GetObj(size_t nNum) const
virtual const tools::Rectangle & GetLogicRect() const
void Insert(const SdrPageGridFrame &rGF)
bool IsMasterPage() const
SdrModel & getSdrModelFromSdrPage() const
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
static OUString GetURLHelpText(std::u16string_view)
bool IsReadOnly() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
const OUString & GetURL() const
Base class for the following contact objects (frame + draw objects).
Definition: dcontact.hxx:67
SwDPage is Writer's draw page: derives from SdrPage, but has a reference to the Writer document via S...
Definition: dpage.hxx:34
virtual rtl::Reference< SdrObject > ReplaceObject(SdrObject *pNewObj, size_t nObjNum) override
Definition: dpage.cxx:81
void lateInit(const SwDPage &rSrcPage)
Definition: dpage.cxx:58
virtual ~SwDPage() override
Definition: dpage.cxx:54
SwDPage(const SwDPage &)=delete
std::unique_ptr< SdrPageGridFrameList > m_pGridLst
Definition: dpage.hxx:38
SwDoc * m_pDoc
Definition: dpage.hxx:39
virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override
Definition: dpage.cxx:247
virtual rtl::Reference< SdrPage > CloneSdrPage(SdrModel &rTargetModel) const override
Definition: dpage.cxx:70
virtual const SdrPageGridFrameList * GetGridFrameList(const SdrPageView *pPV, const tools::Rectangle *pRect) const override
Definition: dpage.cxx:101
bool RequestHelp(vcl::Window *pWindow, SdrView const *pView, const HelpEvent &rEvt)
Definition: dpage.cxx:145
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
ContactObject for connection of formats as representatives of draw objects in SwClient and the object...
Definition: dcontact.hxx:305
const OUString & GetObjTooltip() const
Definition: atrfrm.cxx:3203
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:3119
SfxPoolItem subclass that wraps a URL.
Definition: fmturl.hxx:33
const ImageMap * GetMap() const
Definition: fmturl.hxx:67
const OUString & GetURL() const
Definition: fmturl.hxx:65
bool IsServerMap() const
Definition: fmturl.hxx:66
const SwFormatURL & GetURL(bool=true) const
Definition: fmturl.hxx:77
const SwRect & getFrameArea() const
Definition: frame.hxx:179
const SwRect & getFramePrintArea() const
Definition: frame.hxx:180
IMapObject * GetIMapObject(const Point &rPoint, const SwFlyFrame *pFly=nullptr) const
Definition: atrfrm.cxx:3539
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwFrame * GetNext()
Definition: frame.hxx:682
const SwFrame * Lower() const
Definition: layfrm.hxx:101
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Pos(const Point &rNew)
Definition: swrect.hxx:171
bool Overlaps(const SwRect &rRect) const
Definition: swrect.hxx:374
tools::Rectangle SVRect() const
Definition: swrect.hxx:292
const SwPageFrame * GetFirstVisPage(OutputDevice const *pRenderContext) const
Management of the first visible Page.
Definition: viewimp.cxx:315
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:365
SwViewShellImp * Imp()
Definition: viewsh.hxx:211
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
const SwRect & VisArea() const
Definition: viewsh.cxx:642
SwFlyFrame * GetFlyFrame()
Definition: dflyobj.hxx:135
ring_container GetRingContainer()
Definition: ring.hxx:240
constexpr Point TopLeft() const
constexpr Point BottomRight() const
Point OutputToScreenPixel(const Point &rPos) const
Point LogicToPixel(const Point &rLogicPt) const
Point PixelToLogic(const Point &rDevicePt) const
Point ScreenToOutputPixel(const Point &rPos) const
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:172
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
static void InsertGridFrame(SdrPageGridFrameList *pLst, const SwFrame *pPg)
Definition: dpage.cxx:92
#define MOUSE_LEFT
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(165)
SVL_DLLPUBLIC OUString removePassword(OUString const &rURI, INetURLObject::EncodeMechanism eEncodeMechanism, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
int i
SdrObject * mpObj
const SvxURLField * mpURLField
SdrEventKind meEvent
Reference< XModel > xModel