bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / form / fmpage.cxx
blobcc32c6dad91ab174529924473c2875175d0513b5
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>
24 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <svx/fmmodel.hxx>
29 #include "fmobj.hxx"
31 #include <svx/fmresids.hrc>
32 #include <svx/dialmgr.hxx>
34 #include "fmpgeimp.hxx"
36 #include <sfx2/objsh.hxx>
37 #include <svx/svditer.hxx>
38 #include <svx/svdview.hxx>
39 #include <tools/urlobj.hxx>
40 #include <vcl/help.hxx>
43 #include <svx/fmglob.hxx>
44 #include "fmprop.hrc"
45 #include "fmundo.hxx"
46 #include "svx/fmtools.hxx"
47 using namespace ::svxform;
48 #include <comphelper/property.hxx>
50 using com::sun::star::uno::Reference;
51 using com::sun::star::uno::UNO_QUERY;
52 using com::sun::star::container::XChild;
53 using com::sun::star::container::XNameContainer;
55 TYPEINIT1(FmFormPage, SdrPage);
58 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
59 :SdrPage(rModel, bMasterPage)
60 ,m_pImpl( new FmFormPageImpl( *this ) )
65 FmFormPage::FmFormPage(const FmFormPage& rPage)
66 :SdrPage(rPage)
67 ,m_pImpl(new FmFormPageImpl( *this ) )
71 void FmFormPage::lateInit(const FmFormPage& rPage, FmFormModel* const pNewModel)
73 SdrPage::lateInit( rPage, pNewModel );
75 m_pImpl->initFrom( rPage.GetImpl() );
76 m_sPageName = rPage.m_sPageName;
80 FmFormPage::~FmFormPage()
82 delete m_pImpl;
86 void FmFormPage::SetModel(SdrModel* pNewModel)
88 /* #35055# */
89 // we want to call the super's "SetModel" method even if the model is the
90 // same, in case code somewhere in the system depends on it. But our code
91 // doesn't, so get the old model to do a check.
92 SdrModel *pOldModel = GetModel();
94 SdrPage::SetModel( pNewModel );
96 /* #35055# */
97 if ( ( pOldModel != pNewModel ) && m_pImpl )
99 try
101 Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
102 if ( xForms.is() )
104 // we want to keep the current collection, just reset the model
105 // with which it's associated.
106 FmFormModel* pDrawModel = static_cast<FmFormModel*>( GetModel() );
107 SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
108 if ( pObjShell )
109 xForms->setParent( pObjShell->GetModel() );
112 catch( ::com::sun::star::uno::Exception const& )
114 OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
120 SdrPage* FmFormPage::Clone() const
122 return Clone(0);
125 SdrPage* FmFormPage::Clone(SdrModel* const pNewModel) const
127 FmFormPage* const pNewPage = new FmFormPage(*this);
128 FmFormModel* pFormModel = 0;
129 if (pNewModel)
131 pFormModel = dynamic_cast<FmFormModel*>(pNewModel);
132 assert(pFormModel);
134 pNewPage->lateInit(*this, pFormModel);
135 return pNewPage;
139 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos,
140 const SdrInsertReason* pReason)
142 SdrPage::InsertObject( pObj, nPos, pReason );
143 if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
144 static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Inserted(pObj);
148 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
150 const SdrPage& rMasterPage( *this );
151 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
152 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
153 if ( !pFormPage )
154 pFormPage = this;
156 return pFormPage->m_pImpl->getForms( _bForceCreate );
160 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView* pView,
161 const HelpEvent& rEvt )
163 if( pView->IsAction() )
164 return false;
166 Point aPos = rEvt.GetMousePosPixel();
167 aPos = pWindow->ScreenToOutputPixel( aPos );
168 aPos = pWindow->PixelToLogic( aPos );
170 SdrObject* pObj = NULL;
171 SdrPageView* pPV = NULL;
172 if ( !pView->PickObj( aPos, 0, pObj, pPV, SdrSearchOptions::DEEP ) )
173 return false;
175 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
176 if ( !pFormObject )
177 return false;
179 OUString aHelpText;
180 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
181 if (xSet.is())
183 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
184 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
186 if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
188 OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
189 INetURLObject aUrl(aText);
191 // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
192 INetProtocol aProtocol = aUrl.GetProtocol();
193 static const INetProtocol s_aQuickHelpSupported[] =
194 { INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
195 INetProtocol::Https, INetProtocol::Javascript,
196 INetProtocol::Ldap
198 for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
199 if (s_aQuickHelpSupported[i] == aProtocol)
201 aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), INetURLObject::DECODE_UNAMBIGUOUS);
202 break;
206 if ( !aHelpText.isEmpty() )
208 // Hilfe anzeigen
209 Rectangle aItemRect = pObj->GetCurrentBoundRect();
210 aItemRect = pWindow->LogicToPixel( aItemRect );
211 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
212 aItemRect.Left() = aPt.X();
213 aItemRect.Top() = aPt.Y();
214 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
215 aItemRect.Right() = aPt.X();
216 aItemRect.Bottom() = aPt.Y();
217 if( rEvt.GetMode() == HelpEventMode::BALLOON )
218 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
219 else
220 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
222 return true;
226 SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
228 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
229 if (pObj && GetModel())
230 static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Removed(pObj);
231 return pObj;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */