Bump version to 6.4-15
[LibreOffice.git] / svx / source / form / fmpage.cxx
blob5fc8df9195c8a3d2ed3228f8735430cab3909b3b
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 <sal/macros.h>
22 #include <svx/fmpage.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <svx/fmmodel.hxx>
27 #include <fmobj.hxx>
29 #include <fmpgeimp.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <svx/svditer.hxx>
33 #include <svx/svdview.hxx>
34 #include <tools/urlobj.hxx>
35 #include <vcl/help.hxx>
38 #include <svx/fmglob.hxx>
39 #include <fmprop.hxx>
40 #include <fmundo.hxx>
41 #include <svx/fmtools.hxx>
42 using namespace ::svxform;
43 #include <comphelper/property.hxx>
44 #include <comphelper/types.hxx>
46 using com::sun::star::uno::Reference;
47 using com::sun::star::uno::UNO_QUERY;
50 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
51 : SdrPage(rModel, bMasterPage)
52 ,m_pImpl( new FmFormPageImpl( *this ) )
56 void FmFormPage::lateInit(const FmFormPage& rPage)
58 // call parent
59 SdrPage::lateInit( rPage );
61 // copy local variables (former stuff from copy constructor)
62 m_pImpl->initFrom( rPage.GetImpl() );
63 m_sPageName = rPage.m_sPageName;
67 FmFormPage::~FmFormPage()
71 SdrPage* FmFormPage::CloneSdrPage(SdrModel& rTargetModel) const
73 FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
74 FmFormPage* pClonedFmFormPage(
75 new FmFormPage(
76 rFmFormModel,
77 IsMasterPage()));
78 pClonedFmFormPage->lateInit(*this);
79 return pClonedFmFormPage;
83 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
85 SdrPage::InsertObject( pObj, nPos );
86 static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
90 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
92 const SdrPage& rMasterPage( *this );
93 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
94 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
95 if ( !pFormPage )
96 pFormPage = this;
98 return pFormPage->m_pImpl->getForms( _bForceCreate );
102 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
103 const HelpEvent& rEvt )
105 if( pView->IsAction() )
106 return false;
108 Point aPos = rEvt.GetMousePosPixel();
109 aPos = pWindow->ScreenToOutputPixel( aPos );
110 aPos = pWindow->PixelToLogic( aPos );
112 SdrPageView* pPV = nullptr;
113 SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
114 if (!pObj)
115 return false;
117 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
118 if ( !pFormObject )
119 return false;
121 OUString aHelpText;
122 css::uno::Reference< css::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
123 if (xSet.is())
125 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
126 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
128 if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
130 OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
131 INetURLObject aUrl(aText);
133 // test if it is a protocol type that I want to display
134 INetProtocol aProtocol = aUrl.GetProtocol();
135 static const INetProtocol s_aQuickHelpSupported[] =
136 { INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
137 INetProtocol::Https, INetProtocol::Javascript,
138 INetProtocol::Ldap
140 for (const INetProtocol& i : s_aQuickHelpSupported)
141 if (i == aProtocol)
143 aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
144 break;
148 if ( !aHelpText.isEmpty() )
150 // display the help
151 tools::Rectangle aItemRect = pObj->GetCurrentBoundRect();
152 aItemRect = pWindow->LogicToPixel( aItemRect );
153 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
154 aItemRect.SetLeft( aPt.X() );
155 aItemRect.SetTop( aPt.Y() );
156 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
157 aItemRect.SetRight( aPt.X() );
158 aItemRect.SetBottom( aPt.Y() );
159 if( rEvt.GetMode() == HelpEventMode::BALLOON )
160 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
161 else
162 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
164 return true;
168 SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
170 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
171 if (pObj)
172 static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
173 return pObj;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */