update dev300-m58
[ooovba.git] / svx / source / form / fmpage.cxx
blob6062e99859e43968054255c1f115a8afeb07662f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmpage.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define ENABLE_BYTESTRING_STREAM_OPERATORS
35 #include <svx/fmpage.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <svx/fmmodel.hxx>
42 #ifndef SVX_LIGHT
43 #ifndef _SVX_FMOBJ_HXX
44 #include "fmobj.hxx"
45 #endif
46 #endif
48 #ifndef SVX_LIGHT
49 #ifndef _SVX_FMRESIDS_HRC
50 #include "fmresids.hrc"
51 #endif
52 #endif
53 #include <tools/shl.hxx>
54 #include <svx/dialmgr.hxx>
56 #ifndef SVX_LIGHT
57 #ifndef _SVX_FMPGEIMP_HXX
58 #include "fmpgeimp.hxx"
59 #endif
60 #endif
62 #ifndef SVX_LIGHT
63 #ifndef _SFX_OBJSH_HXX //autogen
64 #include <sfx2/objsh.hxx>
65 #endif
66 #endif
67 #include "svditer.hxx"
68 #include <svx/svdview.hxx>
69 #include <tools/urlobj.hxx>
70 #include <vcl/help.hxx>
73 #ifndef SVX_LIGHT
74 #ifndef _SVX_FMGLOB_HXX
75 #include <svx/fmglob.hxx>
76 #endif
77 #ifndef _SVX_FMPROP_HRC
78 #include "fmprop.hrc"
79 #endif
80 #include "fmundo.hxx"
81 #include "fmtools.hxx"
82 using namespace ::svxform;
83 #endif
84 #include <comphelper/property.hxx>
85 #include <rtl/logfile.hxx>
87 using com::sun::star::uno::Reference;
88 using com::sun::star::uno::UNO_QUERY;
89 using com::sun::star::container::XChild;
90 using com::sun::star::container::XNameContainer;
92 TYPEINIT1(FmFormPage, SdrPage);
94 //------------------------------------------------------------------
95 FmFormPage::FmFormPage(FmFormModel& rModel, StarBASIC* _pBasic, FASTBOOL bMasterPage)
96 :SdrPage(rModel, bMasterPage)
97 #ifndef SVX_LIGHT
98 ,m_pImpl( new FmFormPageImpl( *this ) )
99 #else
100 ,m_pImpl(NULL)
101 #endif
102 ,m_pBasic(_pBasic)
104 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
107 //------------------------------------------------------------------
108 FmFormPage::FmFormPage(const FmFormPage& rPage)
109 :SdrPage(rPage)
110 #ifndef SVX_LIGHT
111 ,m_pImpl(new FmFormPageImpl( *this, rPage.GetImpl() ) )
112 #else
113 ,m_pImpl(NULL)
114 #endif
115 ,m_pBasic(0)
117 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
118 m_sPageName = rPage.m_sPageName;
121 //------------------------------------------------------------------
122 FmFormPage::~FmFormPage()
124 #ifndef SVX_LIGHT
125 delete m_pImpl;
126 #endif
129 //------------------------------------------------------------------
130 void FmFormPage::SetModel(SdrModel* pNewModel)
132 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::SetModel" );
133 /* #35055# */
134 // we want to call the super's "SetModel" method even if the model is the
135 // same, in case code somewhere in the system depends on it. But our code
136 // doesn't, so get the old model to do a check.
137 SdrModel *pOldModel = GetModel();
139 SdrPage::SetModel( pNewModel );
141 /* #35055# */
142 if ( ( pOldModel != pNewModel ) && m_pImpl )
146 Reference< XNameContainer > xForms( m_pImpl->getForms( false ) );
147 if ( xForms.is() )
149 // we want to keep the current collection, just reset the model
150 // with which it's associated.
151 Reference< XChild > xAsChild( xForms, UNO_QUERY );
152 if ( xAsChild.is() )
154 FmFormModel* pDrawModel = (FmFormModel*) GetModel();
155 SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
156 if ( pObjShell )
157 xAsChild->setParent( pObjShell->GetModel() );
161 catch( ::com::sun::star::uno::Exception ex )
163 OSL_ENSURE( sal_False, "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
168 //------------------------------------------------------------------
169 SdrPage* FmFormPage::Clone() const
171 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::Clone" );
172 return new FmFormPage(*this);
173 // hier fehlt noch ein kopieren der Objekte
176 //------------------------------------------------------------------
177 void FmFormPage::InsertObject(SdrObject* pObj, ULONG nPos,
178 const SdrInsertReason* pReason)
180 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::InsertObject" );
181 SdrPage::InsertObject( pObj, nPos, pReason );
182 #ifndef SVX_LIGHT
183 if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
184 ((FmFormModel*)GetModel())->GetUndoEnv().Inserted(pObj);
185 #endif
188 //------------------------------------------------------------------
189 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > & FmFormPage::GetForms( bool _bForceCreate ) const
191 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::GetForms" );
192 #ifndef SVX_LIGHT
193 const SdrPage& rMasterPage( *this );
194 const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
195 OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
196 if ( !pFormPage )
197 pFormPage = this;
199 return pFormPage->m_pImpl->getForms( _bForceCreate );
200 #else
201 static ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > aRef;
202 return aRef;
203 #endif
206 //------------------------------------------------------------------
207 sal_Bool FmFormPage::RequestHelp( Window* pWindow, SdrView* pView,
208 const HelpEvent& rEvt )
210 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RequestHelp" );
211 #ifndef SVX_LIGHT
212 if( pView->IsAction() )
213 return sal_False;
215 Point aPos = rEvt.GetMousePosPixel();
216 aPos = pWindow->ScreenToOutputPixel( aPos );
217 aPos = pWindow->PixelToLogic( aPos );
219 SdrObject* pObj = NULL;
220 SdrPageView* pPV = NULL;
221 if ( !pView->PickObj( aPos, 0, pObj, pPV, SDRSEARCH_DEEP ) )
222 return sal_False;
224 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
225 if ( !pFormObject )
226 return sal_False;
228 UniString aHelpText;
229 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
230 if (xSet.is())
232 if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
233 aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
235 if (!aHelpText.Len() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
237 ::rtl::OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
238 INetURLObject aUrl(aText);
240 // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
241 INetProtocol aProtocol = aUrl.GetProtocol();
242 static const INetProtocol s_aQuickHelpSupported[] =
243 { INET_PROT_FTP, INET_PROT_HTTP, INET_PROT_FILE, INET_PROT_MAILTO, INET_PROT_NEWS,
244 INET_PROT_HTTPS, INET_PROT_JAVASCRIPT, INET_PROT_IMAP, INET_PROT_POP3,
245 INET_PROT_VIM, INET_PROT_LDAP
247 for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
248 if (s_aQuickHelpSupported[i] == aProtocol)
250 aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
251 break;
255 if ( aHelpText.Len() != 0 )
257 // Hilfe anzeigen
258 Rectangle aItemRect = pObj->GetCurrentBoundRect();
259 aItemRect = pWindow->LogicToPixel( aItemRect );
260 Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
261 aItemRect.Left() = aPt.X();
262 aItemRect.Top() = aPt.Y();
263 aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
264 aItemRect.Right() = aPt.X();
265 aItemRect.Bottom() = aPt.Y();
266 if( rEvt.GetMode() == HELPMODE_BALLOON )
267 Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
268 else
269 Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
271 #endif
272 return sal_True;
275 //------------------------------------------------------------------
276 SdrObject* FmFormPage::RemoveObject(ULONG nObjNum)
278 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPage::RemoveObject" );
279 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
280 #ifndef SVX_LIGHT
281 if (pObj && GetModel())
282 ((FmFormModel*)GetModel())->GetUndoEnv().Removed(pObj);
283 #endif
284 return pObj;