bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / form / fmpage.cxx
blobc4f0bcad55f5b978b2e9e8a7f68519fc76bcaff7
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 <svx/fmpage.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <svx/fmmodel.hxx>
25 #include <fmobj.hxx>
27 #include <fmpgeimp.hxx>
29 #include <svx/svdview.hxx>
30 #include <tools/urlobj.hxx>
31 #include <vcl/help.hxx>
32 #include <vcl/window.hxx>
33 #include <osl/diagnose.h>
36 #include <fmprop.hxx>
37 #include <fmundo.hxx>
38 using namespace ::svxform;
39 #include <comphelper/property.hxx>
40 #include <comphelper/types.hxx>
42 using com::sun::star::uno::Reference;
43 using com::sun::star::uno::UNO_QUERY;
46 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
47 : SdrPage(rModel, bMasterPage)
48 ,m_pImpl( new FmFormPageImpl( *this ) )
52 void FmFormPage::lateInit(const FmFormPage& rPage)
54 // call parent
55 SdrPage::lateInit( rPage );
57 // copy local variables (former stuff from copy constructor)
58 m_pImpl->initFrom( rPage.GetImpl() );
59 m_sPageName = rPage.m_sPageName;
63 FmFormPage::~FmFormPage()
67 rtl::Reference<SdrPage> FmFormPage::CloneSdrPage(SdrModel& rTargetModel) const
69 FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
70 rtl::Reference<FmFormPage> pClonedFmFormPage =
71 new FmFormPage(
72 rFmFormModel,
73 IsMasterPage());
74 pClonedFmFormPage->lateInit(*this);
75 return pClonedFmFormPage;
79 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
81 SdrPage::InsertObject( pObj, nPos );
82 static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
86 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
88 const SdrPage& rMasterPage( *this );
89 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
90 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
91 if ( !pFormPage )
92 pFormPage = this;
94 return pFormPage->m_pImpl->getForms( _bForceCreate );
98 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
99 const HelpEvent& rEvt )
101 if( pView->IsAction() )
102 return false;
104 Point aPos = rEvt.GetMousePosPixel();
105 aPos = pWindow->ScreenToOutputPixel( aPos );
106 aPos = pWindow->PixelToLogic( aPos );
108 SdrPageView* pPV = nullptr;
109 SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
110 if (!pObj)
111 return false;
113 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
114 if ( !pFormObject )
115 return false;
117 OUString aHelpText;
118 css::uno::Reference< css::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
119 if (xSet.is())
121 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
122 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
124 if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
126 OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
127 INetURLObject aUrl(aText);
129 // test if it is a protocol type that I want to display
130 INetProtocol aProtocol = aUrl.GetProtocol();
131 static const INetProtocol s_aQuickHelpSupported[] =
132 { INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
133 INetProtocol::Https, INetProtocol::Javascript,
134 INetProtocol::Ldap
136 for (const INetProtocol& i : s_aQuickHelpSupported)
137 if (i == aProtocol)
139 aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
140 break;
144 if ( !aHelpText.isEmpty() )
146 // display the help
147 tools::Rectangle aItemRect = pObj->GetCurrentBoundRect();
148 aItemRect = pWindow->LogicToPixel( aItemRect );
149 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
150 aItemRect.SetLeft( aPt.X() );
151 aItemRect.SetTop( aPt.Y() );
152 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
153 aItemRect.SetRight( aPt.X() );
154 aItemRect.SetBottom( aPt.Y() );
155 if( rEvt.GetMode() == HelpEventMode::BALLOON )
156 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
157 else
158 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
160 return true;
164 SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
166 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
167 if (pObj)
168 static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
169 return pObj;
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */