Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / draw / dpage.cxx
blob93b5e42cbce1ec97d89db99e770f38b4a588ebd5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 #include <IDocumentLayoutAccess.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>
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing;
46 using namespace ::com::sun::star::frame;
48 SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage)
49 : FmFormPage(rNewModel, bMasterPage),
50 m_pDoc(&rNewModel.GetDoc())
54 SwDPage::~SwDPage()
58 void SwDPage::lateInit(const SwDPage& rSrcPage)
60 FmFormPage::lateInit( rSrcPage );
62 if ( rSrcPage.m_pGridLst )
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 ] );
70 rtl::Reference<SdrPage> SwDPage::CloneSdrPage(SdrModel& rTargetModel) const
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;
81 rtl::Reference<SdrObject> SwDPage::ReplaceObject( SdrObject* pNewObj, size_t nObjNum )
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 );
92 static void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrame *pPg )
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 ) );
101 const SdrPageGridFrameList* SwDPage::GetGridFrameList(
102 const SdrPageView* pPV, const tools::Rectangle *pRect ) const
104 SwViewShell* pSh = static_cast< SwDrawModel& >(getSdrModelFromSdrPage()).GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
105 if(pSh)
107 for(SwViewShell& rShell : pSh->GetRingContainer())
109 if(rShell.Imp()->GetPageView() == pPV)
111 pSh = &rShell;
112 break;
115 if ( m_pGridLst )
116 const_cast<SwDPage*>(this)->m_pGridLst->Clear();
117 else
118 const_cast<SwDPage*>(this)->m_pGridLst.reset( new SdrPageGridFrameList );
120 if ( pRect )
122 //The drawing demands all pages which overlap with the rest.
123 const SwRect aRect( *pRect );
124 const SwFrame *pPg = pSh->GetLayout()->Lower();
126 { if ( pPg->getFrameArea().Overlaps( aRect ) )
127 ::InsertGridFrame( const_cast<SwDPage*>(this)->m_pGridLst.get(), pPg );
128 pPg = pPg->GetNext();
129 } while ( pPg );
131 else
133 //The drawing demands all visible pages
134 const SwFrame *pPg = pSh->Imp()->GetFirstVisPage(pSh->GetOut());
135 if ( pPg )
137 { ::InsertGridFrame( const_cast<SwDPage*>(this)->m_pGridLst.get(), pPg );
138 pPg = pPg->GetNext();
139 } while ( pPg && pPg->getFrameArea().Overlaps( pSh->VisArea() ) );
142 return m_pGridLst.get();
145 bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
146 const HelpEvent& rEvt )
148 assert( m_pDoc );
150 bool bContinue = true;
152 if( rEvt.GetMode() & ( HelpEventMode::QUICK | HelpEventMode::BALLOON ))
154 Point aPos( rEvt.GetMousePosPixel() );
155 aPos = pWindow->ScreenToOutputPixel( aPos );
156 aPos = pWindow->PixelToLogic( aPos );
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)
166 SwFlyFrame *pFly = pDrawObj->GetFlyFrame();
168 aPixRect = pWindow->LogicToPixel(pFly->getFrameArea().SVRect());
170 const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
171 if (!pFly->GetFormat()->GetObjTooltip().isEmpty())
173 // Tooltips have priority over URLs.
174 sText = pFly->GetFormat()->GetObjTooltip();
175 bTooltip = true;
177 else if( rURL.GetMap() )
179 IMapObject *pTmpObj = pFly->GetFormat()->GetIMapObject( aPos, pFly );
180 if( pTmpObj )
182 sText = pTmpObj->GetAltText();
183 if ( sText.isEmpty() )
184 sText = URIHelper::removePassword( pTmpObj->GetURL(),
185 INetURLObject::EncodeMechanism::WasEncoded,
186 INetURLObject::DecodeMechanism::Unambiguous);
189 else if ( !rURL.GetURL().isEmpty() )
191 sText = URIHelper::removePassword( rURL.GetURL(),
192 INetURLObject::EncodeMechanism::WasEncoded,
193 INetURLObject::DecodeMechanism::Unambiguous);
195 if( rURL.IsServerMap() )
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() );
209 else
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)
217 sText = aVEvt.mpURLField->GetURL();
218 aPixRect = pWindow->LogicToPixel(aVEvt.mpObj->GetLogicRect());
222 if (!sText.isEmpty())
224 // #i80029#
225 bool bExecHyperlinks = m_pDoc->GetDocShell()->IsReadOnly();
226 if (!bExecHyperlinks && !bTooltip)
227 sText = SfxHelp::GetURLHelpText(sText);
229 // then display the help:
230 tools::Rectangle aScreenRect(pWindow->OutputToScreenPixel(aPixRect.TopLeft()),
231 pWindow->OutputToScreenPixel(aPixRect.BottomRight()));
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;
241 if( bContinue )
242 bContinue = !FmFormPage::RequestHelp( pWindow, pView, rEvt );
244 return bContinue;
247 Reference< XInterface > SwDPage::createUnoPage()
249 assert( m_pDoc );
251 Reference < XInterface > xRet;
252 SwDocShell* pDocShell = m_pDoc->GetDocShell();
253 if ( pDocShell )
255 Reference<XModel> xModel = pDocShell->GetBaseModel();
256 Reference<XDrawPageSupplier> xPageSupp(xModel, UNO_QUERY);
257 xRet = xPageSupp->getDrawPage();
259 return xRet;
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */