1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmpage.cxx,v $
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>
43 #ifndef _SVX_FMOBJ_HXX
49 #ifndef _SVX_FMRESIDS_HRC
50 #include "fmresids.hrc"
53 #include <tools/shl.hxx>
54 #include <svx/dialmgr.hxx>
57 #ifndef _SVX_FMPGEIMP_HXX
58 #include "fmpgeimp.hxx"
63 #ifndef _SFX_OBJSH_HXX //autogen
64 #include <sfx2/objsh.hxx>
67 #include "svditer.hxx"
68 #include <svx/svdview.hxx>
69 #include <tools/urlobj.hxx>
70 #include <vcl/help.hxx>
74 #ifndef _SVX_FMGLOB_HXX
75 #include <svx/fmglob.hxx>
77 #ifndef _SVX_FMPROP_HRC
81 #include "fmtools.hxx"
82 using namespace ::svxform
;
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
)
98 ,m_pImpl( new FmFormPageImpl( *this ) )
104 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
107 //------------------------------------------------------------------
108 FmFormPage::FmFormPage(const FmFormPage
& rPage
)
111 ,m_pImpl(new FmFormPageImpl( *this, rPage
.GetImpl() ) )
117 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "svx", "Ocke.Janssen@sun.com", "FmFormPage::FmFormPage" );
118 m_sPageName
= rPage
.m_sPageName
;
121 //------------------------------------------------------------------
122 FmFormPage::~FmFormPage()
129 //------------------------------------------------------------------
130 void FmFormPage::SetModel(SdrModel
* pNewModel
)
132 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "svx", "Ocke.Janssen@sun.com", "FmFormPage::SetModel" );
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
);
142 if ( ( pOldModel
!= pNewModel
) && m_pImpl
)
146 Reference
< XNameContainer
> xForms( m_pImpl
->getForms( false ) );
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
);
154 FmFormModel
* pDrawModel
= (FmFormModel
*) GetModel();
155 SfxObjectShell
* pObjShell
= pDrawModel
->GetObjectShell();
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
);
183 if (GetModel() && (!pReason
|| pReason
->GetReason() != SDRREASON_STREAMING
))
184 ((FmFormModel
*)GetModel())->GetUndoEnv().Inserted(pObj
);
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" );
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?!" );
199 return pFormPage
->m_pImpl
->getForms( _bForceCreate
);
201 static ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> aRef
;
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" );
212 if( pView
->IsAction() )
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
) )
224 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pObj
);
229 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xSet( pFormObject
->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY
);
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
);
255 if ( aHelpText
.Len() != 0 )
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
);
269 Help::ShowQuickHelp( pWindow
, aItemRect
, aHelpText
);
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
);
281 if (pObj
&& GetModel())
282 ((FmFormModel
*)GetModel())->GetUndoEnv().Removed(pObj
);