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>
25 #include <svx/fmmodel.hxx>
29 #include <fmpgeimp.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <svx/svditer.hxx>
33 #include <svx/svdview.hxx>
34 #include <tools/urlobj.hxx>
35 #include <vcl/help.hxx>
38 #include <svx/fmglob.hxx>
41 #include <svx/fmtools.hxx>
42 using namespace ::svxform
;
43 #include <comphelper/property.hxx>
44 #include <comphelper/types.hxx>
46 using com::sun::star::uno::Reference
;
47 using com::sun::star::uno::UNO_QUERY
;
50 FmFormPage::FmFormPage(FmFormModel
& rModel
, bool bMasterPage
)
51 : SdrPage(rModel
, bMasterPage
)
52 ,m_pImpl( new FmFormPageImpl( *this ) )
56 void FmFormPage::lateInit(const FmFormPage
& rPage
)
59 SdrPage::lateInit( rPage
);
61 // copy local variables (former stuff from copy constructor)
62 m_pImpl
->initFrom( rPage
.GetImpl() );
63 m_sPageName
= rPage
.m_sPageName
;
67 FmFormPage::~FmFormPage()
71 SdrPage
* FmFormPage::CloneSdrPage(SdrModel
& rTargetModel
) const
73 FmFormModel
& rFmFormModel(static_cast< FmFormModel
& >(rTargetModel
));
74 FmFormPage
* pClonedFmFormPage(
78 pClonedFmFormPage
->lateInit(*this);
79 return pClonedFmFormPage
;
83 void FmFormPage::InsertObject(SdrObject
* pObj
, size_t nPos
)
85 SdrPage::InsertObject( pObj
, nPos
);
86 static_cast< FmFormModel
& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj
);
90 const Reference
< css::form::XForms
> & FmFormPage::GetForms( bool _bForceCreate
) const
92 const SdrPage
& rMasterPage( *this );
93 const FmFormPage
* pFormPage
= dynamic_cast< const FmFormPage
* >( &rMasterPage
);
94 OSL_ENSURE( pFormPage
, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
98 return pFormPage
->m_pImpl
->getForms( _bForceCreate
);
102 bool FmFormPage::RequestHelp( vcl::Window
* pWindow
, SdrView
const * pView
,
103 const HelpEvent
& rEvt
)
105 if( pView
->IsAction() )
108 Point aPos
= rEvt
.GetMousePosPixel();
109 aPos
= pWindow
->ScreenToOutputPixel( aPos
);
110 aPos
= pWindow
->PixelToLogic( aPos
);
112 SdrPageView
* pPV
= nullptr;
113 SdrObject
* pObj
= pView
->PickObj(aPos
, 0, pPV
, SdrSearchOptions::DEEP
);
117 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pObj
);
122 css::uno::Reference
< css::beans::XPropertySet
> xSet( pFormObject
->GetUnoControlModel(), css::uno::UNO_QUERY
);
125 if (::comphelper::hasProperty(FM_PROP_HELPTEXT
, xSet
))
126 aHelpText
= ::comphelper::getString(xSet
->getPropertyValue(FM_PROP_HELPTEXT
));
128 if (aHelpText
.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL
, xSet
))
130 OUString aText
= ::comphelper::getString(xSet
->getPropertyValue(FM_PROP_TARGET_URL
));
131 INetURLObject
aUrl(aText
);
133 // test if it is a protocol type that I want to display
134 INetProtocol aProtocol
= aUrl
.GetProtocol();
135 static const INetProtocol s_aQuickHelpSupported
[] =
136 { INetProtocol::Ftp
, INetProtocol::Http
, INetProtocol::File
, INetProtocol::Mailto
,
137 INetProtocol::Https
, INetProtocol::Javascript
,
140 for (const INetProtocol
& i
: s_aQuickHelpSupported
)
143 aHelpText
= aUrl
.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous
);
148 if ( !aHelpText
.isEmpty() )
151 tools::Rectangle aItemRect
= pObj
->GetCurrentBoundRect();
152 aItemRect
= pWindow
->LogicToPixel( aItemRect
);
153 Point aPt
= pWindow
->OutputToScreenPixel( aItemRect
.TopLeft() );
154 aItemRect
.SetLeft( aPt
.X() );
155 aItemRect
.SetTop( aPt
.Y() );
156 aPt
= pWindow
->OutputToScreenPixel( aItemRect
.BottomRight() );
157 aItemRect
.SetRight( aPt
.X() );
158 aItemRect
.SetBottom( aPt
.Y() );
159 if( rEvt
.GetMode() == HelpEventMode::BALLOON
)
160 Help::ShowBalloon( pWindow
, aItemRect
.Center(), aItemRect
, aHelpText
);
162 Help::ShowQuickHelp( pWindow
, aItemRect
, aHelpText
);
168 SdrObject
* FmFormPage::RemoveObject(size_t nObjNum
)
170 SdrObject
* pObj
= SdrPage::RemoveObject(nObjNum
);
172 static_cast< FmFormModel
& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */