Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / form / fmpage.cxx
blobabf3a57c54d513179df3f9a529bf810118bbcfc7
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 <tools/shl.hxx>
33 #include <svx/dialmgr.hxx>
35 #include "fmpgeimp.hxx"
37 #include <sfx2/objsh.hxx>
38 #include <svx/svditer.hxx>
39 #include <svx/svdview.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/help.hxx>
44 #include <svx/fmglob.hxx>
45 #include "fmprop.hrc"
46 #include "fmundo.hxx"
47 #include "svx/fmtools.hxx"
48 using namespace ::svxform;
49 #include <comphelper/property.hxx>
51 using com::sun::star::uno::Reference;
52 using com::sun::star::uno::UNO_QUERY;
53 using com::sun::star::container::XChild;
54 using com::sun::star::container::XNameContainer;
56 TYPEINIT1(FmFormPage, SdrPage);
59 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
60 :SdrPage(rModel, bMasterPage)
61 ,m_pImpl( new FmFormPageImpl( *this ) )
66 FmFormPage::FmFormPage(const FmFormPage& rPage)
67 :SdrPage(rPage)
68 ,m_pImpl(new FmFormPageImpl( *this ) )
70 m_pImpl->initFrom( rPage.GetImpl() );
71 m_sPageName = rPage.m_sPageName;
75 FmFormPage::~FmFormPage()
77 delete m_pImpl;
81 void FmFormPage::SetModel(SdrModel* pNewModel)
83 /* #35055# */
84 // we want to call the super's "SetModel" method even if the model is the
85 // same, in case code somewhere in the system depends on it. But our code
86 // doesn't, so get the old model to do a check.
87 SdrModel *pOldModel = GetModel();
89 SdrPage::SetModel( pNewModel );
91 /* #35055# */
92 if ( ( pOldModel != pNewModel ) && m_pImpl )
94 try
96 Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
97 if ( xForms.is() )
99 // we want to keep the current collection, just reset the model
100 // with which it's associated.
101 FmFormModel* pDrawModel = (FmFormModel*) GetModel();
102 SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
103 if ( pObjShell )
104 xForms->setParent( pObjShell->GetModel() );
107 catch( ::com::sun::star::uno::Exception const& )
109 OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
115 SdrPage* FmFormPage::Clone() const
117 return new FmFormPage(*this);
118 // hier fehlt noch ein kopieren der Objekte
122 void FmFormPage::InsertObject(SdrObject* pObj, sal_uLong nPos,
123 const SdrInsertReason* pReason)
125 SdrPage::InsertObject( pObj, nPos, pReason );
126 if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
127 ((FmFormModel*)GetModel())->GetUndoEnv().Inserted(pObj);
131 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
133 const SdrPage& rMasterPage( *this );
134 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
135 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
136 if ( !pFormPage )
137 pFormPage = this;
139 return pFormPage->m_pImpl->getForms( _bForceCreate );
143 bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView,
144 const HelpEvent& rEvt )
146 if( pView->IsAction() )
147 return false;
149 Point aPos = rEvt.GetMousePosPixel();
150 aPos = pWindow->ScreenToOutputPixel( aPos );
151 aPos = pWindow->PixelToLogic( aPos );
153 SdrObject* pObj = NULL;
154 SdrPageView* pPV = NULL;
155 if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
156 return false;
158 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
159 if ( !pFormObject )
160 return false;
162 OUString aHelpText;
163 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
164 if (xSet.is())
166 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
167 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
169 if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
171 OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
172 INetURLObject aUrl(aText);
174 // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
175 INetProtocol aProtocol = aUrl.GetProtocol();
176 static const INetProtocol s_aQuickHelpSupported[] =
177 { INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
178 INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
179 INET_PROT_VIM, INET_PROT_LDAP
181 for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
182 if (s_aQuickHelpSupported[i] == aProtocol)
184 aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
185 break;
189 if ( !aHelpText.isEmpty() )
191 // Hilfe anzeigen
192 Rectangle aItemRect = pObj->GetCurrentBoundRect();
193 aItemRect = pWindow->LogicToPixel( aItemRect );
194 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
195 aItemRect.Left() = aPt.X();
196 aItemRect.Top() = aPt.Y();
197 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
198 aItemRect.Right() = aPt.X();
199 aItemRect.Bottom() = aPt.Y();
200 if( rEvt.GetMode() == HELPMODE_BALLOON )
201 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
202 else
203 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
205 return true;
209 SdrObject* FmFormPage::RemoveObject(sal_uLong nObjNum)
211 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
212 if (pObj && GetModel())
213 ((FmFormModel*)GetModel())->GetUndoEnv().Removed(pObj);
214 return pObj;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */