LibreOffice Module svx (master)  1
fmpage.cxx
Go to the documentation of this file.
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 
47 using com::sun::star::uno::UNO_QUERY;
48 
49 
50 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
51 : SdrPage(rModel, bMasterPage)
52  ,m_pImpl( new FmFormPageImpl( *this ) )
53 {
54 }
55 
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 
68 {
69 }
70 
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 
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 
90 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 
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  {
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 
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: */
Point TopLeft() const
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:881
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
Definition: fmpage.cxx:83
virtual ~FmFormPage() override
Definition: fmpage.cxx:67
void lateInit(const FmFormPage &rPage)
Definition: fmpage.cxx:56
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:358
HelpEventMode GetMode() const
INetProtocol
FmFormPageImpl & GetImpl() const
Definition: fmpage.hxx:62
const Point & GetMousePosPixel() const
Point BottomRight() const
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
Definition: svdmrkv.cxx:2156
void SetTop(long v)
OUString m_sPageName
Definition: fmpage.hxx:46
int i
void SetRight(long v)
bool IsMasterPage() const
Definition: svdpage.hxx:451
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
Definition: fmpage.cxx:102
Abstract DrawObject.
Definition: svdobj.hxx:312
Point ScreenToOutputPixel(const Point &rPos) const
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
#define FM_PROP_TARGET_URL
Definition: fmprop.hxx:52
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:436
long X() const
static SAL_DLLPRIVATE FmFormObj * GetFormObject(SdrObject *_pSdrObject)
returns the FmFormObj behind the given SdrObject
Definition: fmobj.cxx:582
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
void lateInit(const SdrPage &rSrcPage)
Definition: svdpage.cxx:1309
virtual bool IsAction() const override
Definition: svdcrtv.cxx:217
virtual SdrPage * CloneSdrPage(SdrModel &rTargetModel) const override
Definition: fmpage.cxx:71
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:391
void SetBottom(long v)
#define FM_PROP_HELPTEXT
Definition: fmprop.hxx:98
FmFormPage(const FmFormPage &)=delete
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
Definition: svdouno.hxx:91
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
void SetLeft(long v)
class FmSearchEngine - Impl class for FmSearchDialog
Point OutputToScreenPixel(const Point &rPos) const
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
virtual SdrObject * RemoveObject(size_t nObjNum) override
Definition: fmpage.cxx:168
const css::uno::Reference< css::form::XForms > & GetForms(bool _bForceCreate=true) const
Definition: fmpage.cxx:90
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
OUString getString(const Any &_rAny)
std::unique_ptr< FmFormPageImpl > m_pImpl
Definition: fmpage.hxx:45
Point Center() const
long Y() const
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)