1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/macros.h>
21 
22 #include <svx/fmpage.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 
25 #include <svx/fmmodel.hxx>
26 
27 #include <fmobj.hxx>
28 
29 #include <fmpgeimp.hxx>
30 
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>
36 
37 
38 #include <svx/fmglob.hxx>
39 #include <fmprop.hxx>
40 #include <fmundo.hxx>
41 #include <svx/fmtools.hxx>
42 using namespace ::svxform;
43 #include <comphelper/property.hxx>
44 #include <comphelper/types.hxx>
45 
46 using com::sun::star::uno::Reference;
47 using com::sun::star::uno::UNO_QUERY;
48 
49 
FmFormPage(FmFormModel & rModel,bool bMasterPage)50 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
51 :   SdrPage(rModel, bMasterPage)
52     ,m_pImpl( new FmFormPageImpl( *this ) )
53 {
54 }
55 
lateInit(const FmFormPage & rPage)56 void FmFormPage::lateInit(const FmFormPage& rPage)
57 {
58     // call parent
59     SdrPage::lateInit( rPage );
60 
61     // copy local variables (former stuff from copy constructor)
62     m_pImpl->initFrom( rPage.GetImpl() );
63     m_sPageName = rPage.m_sPageName;
64 }
65 
66 
~FmFormPage()67 FmFormPage::~FmFormPage()
68 {
69 }
70 
CloneSdrPage(SdrModel & rTargetModel) const71 SdrPage* FmFormPage::CloneSdrPage(SdrModel& rTargetModel) const
72 {
73     FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
74     FmFormPage* pClonedFmFormPage(
75         new FmFormPage(
76             rFmFormModel,
77             IsMasterPage()));
78     pClonedFmFormPage->lateInit(*this);
79     return pClonedFmFormPage;
80 }
81 
82 
InsertObject(SdrObject * pObj,size_t nPos)83 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
84 {
85     SdrPage::InsertObject( pObj, nPos );
86     static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
87 }
88 
89 
GetForms(bool _bForceCreate) const90 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
91 {
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?!" );
95     if ( !pFormPage )
96         pFormPage = this;
97 
98     return pFormPage->m_pImpl->getForms( _bForceCreate );
99 }
100 
101 
RequestHelp(vcl::Window * pWindow,SdrView const * pView,const HelpEvent & rEvt)102 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
103                               const HelpEvent& rEvt )
104 {
105     if( pView->IsAction() )
106         return false;
107 
108     Point aPos = rEvt.GetMousePosPixel();
109     aPos = pWindow->ScreenToOutputPixel( aPos );
110     aPos = pWindow->PixelToLogic( aPos );
111 
112     SdrPageView* pPV = nullptr;
113     SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
114     if (!pObj)
115         return false;
116 
117     FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
118     if ( !pFormObject )
119         return false;
120 
121     OUString aHelpText;
122     css::uno::Reference< css::beans::XPropertySet >  xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
123     if (xSet.is())
124     {
125         if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
126             aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
127 
128         if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
129         {
130             OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
131             INetURLObject aUrl(aText);
132 
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,
138                     INetProtocol::Ldap
139                 };
140             for (const INetProtocol& i : s_aQuickHelpSupported)
141                 if (i == aProtocol)
142                 {
143                     aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
144                     break;
145                 }
146         }
147     }
148     if ( !aHelpText.isEmpty() )
149     {
150         // display the help
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);
161         else
162             Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
163     }
164     return true;
165 }
166 
167 
RemoveObject(size_t nObjNum)168 SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
169 {
170     SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
171     if (pObj)
172         static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
173     return pObj;
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
177