bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / form / fmpage.cxx
blob507e2294712f76230773345d08306d6e40594d81
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>
50 #include <rtl/logfile.hxx>
52 using com::sun::star::uno::Reference;
53 using com::sun::star::uno::UNO_QUERY;
54 using com::sun::star::container::XChild;
55 using com::sun::star::container::XNameContainer;
57 TYPEINIT1(FmFormPage, SdrPage);
59 //------------------------------------------------------------------
60 FmFormPage::FmFormPage(FmFormModel& rModel, StarBASIC* _pBasic, bool bMasterPage)
61 :SdrPage(rModel, bMasterPage)
62 ,m_pImpl( new FmFormPageImpl( *this ) )
63 ,m_pBasic(_pBasic)
65 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
68 //------------------------------------------------------------------
69 FmFormPage::FmFormPage(const FmFormPage& rPage)
70 :SdrPage(rPage)
71 ,m_pImpl(new FmFormPageImpl( *this ) )
72 ,m_pBasic(0)
74 m_pImpl->initFrom( rPage.GetImpl() );
75 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
76 m_sPageName = rPage.m_sPageName;
79 //------------------------------------------------------------------
80 FmFormPage::~FmFormPage()
82 delete m_pImpl;
85 //------------------------------------------------------------------
86 void FmFormPage::SetModel(SdrModel* pNewModel)
88 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::SetModel" );
89 /* #35055# */
90 // we want to call the super's "SetModel" method even if the model is the
91 // same, in case code somewhere in the system depends on it. But our code
92 // doesn't, so get the old model to do a check.
93 SdrModel *pOldModel = GetModel();
95 SdrPage::SetModel( pNewModel );
97 /* #35055# */
98 if ( ( pOldModel != pNewModel ) && m_pImpl )
102 Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
103 if ( xForms.is() )
105 // we want to keep the current collection, just reset the model
106 // with which it's associated.
107 FmFormModel* pDrawModel = (FmFormModel*) GetModel();
108 SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
109 if ( pObjShell )
110 xForms->setParent( pObjShell->GetModel() );
113 catch( ::com::sun::star::uno::Exception const& )
115 OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
120 //------------------------------------------------------------------
121 SdrPage* FmFormPage::Clone() const
123 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::Clone" );
124 return new FmFormPage(*this);
125 // hier fehlt noch ein kopieren der Objekte
128 //------------------------------------------------------------------
129 void FmFormPage::InsertObject(SdrObject* pObj, sal_uLong nPos,
130 const SdrInsertReason* pReason)
132 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::InsertObject" );
133 SdrPage::InsertObject( pObj, nPos, pReason );
134 if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
135 ((FmFormModel*)GetModel())->GetUndoEnv().Inserted(pObj);
138 //------------------------------------------------------------------
139 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
141 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::GetForms" );
142 const SdrPage& rMasterPage( *this );
143 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
144 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
145 if ( !pFormPage )
146 pFormPage = this;
148 return pFormPage->m_pImpl->getForms( _bForceCreate );
151 //------------------------------------------------------------------
152 sal_Bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView,
153 const HelpEvent& rEvt )
155 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RequestHelp" );
156 if( pView->IsAction() )
157 return sal_False;
159 Point aPos = rEvt.GetMousePosPixel();
160 aPos = pWindow->ScreenToOutputPixel( aPos );
161 aPos = pWindow->PixelToLogic( aPos );
163 SdrObject* pObj = NULL;
164 SdrPageView* pPV = NULL;
165 if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
166 return sal_False;
168 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
169 if ( !pFormObject )
170 return sal_False;
172 OUString aHelpText;
173 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
174 if (xSet.is())
176 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
177 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
179 if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
181 OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
182 INetURLObject aUrl(aText);
184 // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
185 INetProtocol aProtocol = aUrl.GetProtocol();
186 static const INetProtocol s_aQuickHelpSupported[] =
187 { INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
188 INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
189 INET_PROT_VIM, INET_PROT_LDAP
191 for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
192 if (s_aQuickHelpSupported[i] == aProtocol)
194 aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
195 break;
199 if ( !aHelpText.isEmpty() )
201 // Hilfe anzeigen
202 Rectangle aItemRect = pObj->GetCurrentBoundRect();
203 aItemRect = pWindow->LogicToPixel( aItemRect );
204 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
205 aItemRect.Left() = aPt.X();
206 aItemRect.Top() = aPt.Y();
207 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
208 aItemRect.Right() = aPt.X();
209 aItemRect.Bottom() = aPt.Y();
210 if( rEvt.GetMode() == HELPMODE_BALLOON )
211 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
212 else
213 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
215 return sal_True;
218 //------------------------------------------------------------------
219 SdrObject* FmFormPage::RemoveObject(sal_uLong nObjNum)
221 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RemoveObject" );
222 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
223 if (pObj && GetModel())
224 ((FmFormModel*)GetModel())->GetUndoEnv().Removed(pObj);
225 return pObj;
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */