1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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
)
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()
86 void FmFormPage::SetModel(SdrModel
* pNewModel
)
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
);
97 if ( ( pOldModel
!= pNewModel
) && m_pImpl
)
101 Reference
< css::form::XForms
> xForms( m_pImpl
->getForms( false ) );
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();
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
125 SdrPage
* FmFormPage::Clone(SdrModel
* const pNewModel
) const
127 FmFormPage
* const pNewPage
= new FmFormPage(*this);
128 FmFormModel
* pFormModel
= 0;
131 pFormModel
= dynamic_cast<FmFormModel
*>(pNewModel
);
134 pNewPage
->lateInit(*this, pFormModel
);
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?!" );
156 return pFormPage
->m_pImpl
->getForms( _bForceCreate
);
160 bool FmFormPage::RequestHelp( vcl::Window
* pWindow
, SdrView
* pView
,
161 const HelpEvent
& rEvt
)
163 if( pView
->IsAction() )
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
) )
175 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pObj
);
180 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xSet( pFormObject
->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY
);
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
,
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
);
206 if ( !aHelpText
.isEmpty() )
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
);
220 Help::ShowQuickHelp( pWindow
, aItemRect
, aHelpText
);
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
);
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */