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 <svx/fmpage.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <svx/fmmodel.hxx>
27 #include <fmpgeimp.hxx>
29 #include <svx/svdview.hxx>
30 #include <tools/urlobj.hxx>
31 #include <vcl/help.hxx>
32 #include <vcl/window.hxx>
33 #include <osl/diagnose.h>
38 using namespace ::svxform
;
39 #include <comphelper/property.hxx>
40 #include <comphelper/types.hxx>
42 using com::sun::star::uno::Reference
;
43 using com::sun::star::uno::UNO_QUERY
;
46 FmFormPage::FmFormPage(FmFormModel
& rModel
, bool bMasterPage
)
47 : SdrPage(rModel
, bMasterPage
)
48 ,m_pImpl( new FmFormPageImpl( *this ) )
52 void FmFormPage::lateInit(const FmFormPage
& rPage
)
55 SdrPage::lateInit( rPage
);
57 // copy local variables (former stuff from copy constructor)
58 m_pImpl
->initFrom( rPage
.GetImpl() );
59 m_sPageName
= rPage
.m_sPageName
;
63 FmFormPage::~FmFormPage()
67 rtl::Reference
<SdrPage
> FmFormPage::CloneSdrPage(SdrModel
& rTargetModel
) const
69 FmFormModel
& rFmFormModel(static_cast< FmFormModel
& >(rTargetModel
));
70 rtl::Reference
<FmFormPage
> pClonedFmFormPage
=
74 pClonedFmFormPage
->lateInit(*this);
75 return pClonedFmFormPage
;
79 void FmFormPage::InsertObject(SdrObject
* pObj
, size_t nPos
)
81 SdrPage::InsertObject( pObj
, nPos
);
82 static_cast< FmFormModel
& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj
);
86 const Reference
< css::form::XForms
> & FmFormPage::GetForms( bool _bForceCreate
) const
88 const SdrPage
& rMasterPage( *this );
89 const FmFormPage
* pFormPage
= dynamic_cast< const FmFormPage
* >( &rMasterPage
);
90 OSL_ENSURE( pFormPage
, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
94 return pFormPage
->m_pImpl
->getForms( _bForceCreate
);
98 bool FmFormPage::RequestHelp( vcl::Window
* pWindow
, SdrView
const * pView
,
99 const HelpEvent
& rEvt
)
101 if( pView
->IsAction() )
104 Point aPos
= rEvt
.GetMousePosPixel();
105 aPos
= pWindow
->ScreenToOutputPixel( aPos
);
106 aPos
= pWindow
->PixelToLogic( aPos
);
108 SdrPageView
* pPV
= nullptr;
109 SdrObject
* pObj
= pView
->PickObj(aPos
, 0, pPV
, SdrSearchOptions::DEEP
);
113 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( pObj
);
118 css::uno::Reference
< css::beans::XPropertySet
> xSet( pFormObject
->GetUnoControlModel(), css::uno::UNO_QUERY
);
121 if (::comphelper::hasProperty(FM_PROP_HELPTEXT
, xSet
))
122 aHelpText
= ::comphelper::getString(xSet
->getPropertyValue(FM_PROP_HELPTEXT
));
124 if (aHelpText
.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL
, xSet
))
126 OUString aText
= ::comphelper::getString(xSet
->getPropertyValue(FM_PROP_TARGET_URL
));
127 INetURLObject
aUrl(aText
);
129 // test if it is a protocol type that I want to display
130 INetProtocol aProtocol
= aUrl
.GetProtocol();
131 static const INetProtocol s_aQuickHelpSupported
[] =
132 { INetProtocol::Ftp
, INetProtocol::Http
, INetProtocol::File
, INetProtocol::Mailto
,
133 INetProtocol::Https
, INetProtocol::Javascript
,
136 for (const INetProtocol
& i
: s_aQuickHelpSupported
)
139 aHelpText
= aUrl
.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous
);
144 if ( !aHelpText
.isEmpty() )
147 tools::Rectangle aItemRect
= pObj
->GetCurrentBoundRect();
148 aItemRect
= pWindow
->LogicToPixel( aItemRect
);
149 Point aPt
= pWindow
->OutputToScreenPixel( aItemRect
.TopLeft() );
150 aItemRect
.SetLeft( aPt
.X() );
151 aItemRect
.SetTop( aPt
.Y() );
152 aPt
= pWindow
->OutputToScreenPixel( aItemRect
.BottomRight() );
153 aItemRect
.SetRight( aPt
.X() );
154 aItemRect
.SetBottom( aPt
.Y() );
155 if( rEvt
.GetMode() == HelpEventMode::BALLOON
)
156 Help::ShowBalloon( pWindow
, aItemRect
.Center(), aItemRect
, aHelpText
);
158 Help::ShowQuickHelp( pWindow
, aItemRect
, aHelpText
);
164 SdrObject
* FmFormPage::RemoveObject(size_t nObjNum
)
166 SdrObject
* pObj
= SdrPage::RemoveObject(nObjNum
);
168 static_cast< FmFormModel
& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj
);
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */