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 <svx/fmpage.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 
23 #include <svx/fmmodel.hxx>
24 
25 #include <fmobj.hxx>
26 
27 #include <fmpgeimp.hxx>
28 
29 #include <svx/svdview.hxx>
30 #include <tools/urlobj.hxx>
31 #include <vcl/help.hxx>
32 
33 
34 #include <fmprop.hxx>
35 #include <fmundo.hxx>
36 using namespace ::svxform;
37 #include <comphelper/property.hxx>
38 #include <comphelper/types.hxx>
39 
41 using com::sun::star::uno::UNO_QUERY;
42 
43 
44 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
45 : SdrPage(rModel, bMasterPage)
46  ,m_pImpl( new FmFormPageImpl( *this ) )
47 {
48 }
49 
50 void FmFormPage::lateInit(const FmFormPage& rPage)
51 {
52  // call parent
53  SdrPage::lateInit( rPage );
54 
55  // copy local variables (former stuff from copy constructor)
56  m_pImpl->initFrom( rPage.GetImpl() );
57  m_sPageName = rPage.m_sPageName;
58 }
59 
60 
62 {
63 }
64 
66 {
67  FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
68  FmFormPage* pClonedFmFormPage(
69  new FmFormPage(
70  rFmFormModel,
71  IsMasterPage()));
72  pClonedFmFormPage->lateInit(*this);
73  return pClonedFmFormPage;
74 }
75 
76 
77 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
78 {
79  SdrPage::InsertObject( pObj, nPos );
80  static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
81 }
82 
83 
84 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
85 {
86  const SdrPage& rMasterPage( *this );
87  const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
88  OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
89  if ( !pFormPage )
90  pFormPage = this;
91 
92  return pFormPage->m_pImpl->getForms( _bForceCreate );
93 }
94 
95 
96 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
97  const HelpEvent& rEvt )
98 {
99  if( pView->IsAction() )
100  return false;
101 
102  Point aPos = rEvt.GetMousePosPixel();
103  aPos = pWindow->ScreenToOutputPixel( aPos );
104  aPos = pWindow->PixelToLogic( aPos );
105 
106  SdrPageView* pPV = nullptr;
107  SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
108  if (!pObj)
109  return false;
110 
111  FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
112  if ( !pFormObject )
113  return false;
114 
115  OUString aHelpText;
116  css::uno::Reference< css::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
117  if (xSet.is())
118  {
120  aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
121 
122  if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
123  {
124  OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
125  INetURLObject aUrl(aText);
126 
127  // test if it is a protocol type that I want to display
128  INetProtocol aProtocol = aUrl.GetProtocol();
129  static const INetProtocol s_aQuickHelpSupported[] =
130  { INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
131  INetProtocol::Https, INetProtocol::Javascript,
132  INetProtocol::Ldap
133  };
134  for (const INetProtocol& i : s_aQuickHelpSupported)
135  if (i == aProtocol)
136  {
137  aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
138  break;
139  }
140  }
141  }
142  if ( !aHelpText.isEmpty() )
143  {
144  // display the help
145  tools::Rectangle aItemRect = pObj->GetCurrentBoundRect();
146  aItemRect = pWindow->LogicToPixel( aItemRect );
147  Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
148  aItemRect.SetLeft( aPt.X() );
149  aItemRect.SetTop( aPt.Y() );
150  aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
151  aItemRect.SetRight( aPt.X() );
152  aItemRect.SetBottom( aPt.Y() );
153  if( rEvt.GetMode() == HelpEventMode::BALLOON )
154  Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
155  else
156  Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
157  }
158  return true;
159 }
160 
161 
163 {
164  SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
165  if (pObj)
166  static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
167  return pObj;
168 }
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:854
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
Definition: fmpage.cxx:77
virtual ~FmFormPage() override
Definition: fmpage.cxx:61
void lateInit(const FmFormPage &rPage)
Definition: fmpage.cxx:50
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:343
HelpEventMode GetMode() const
void SetRight(tools::Long v)
void SetLeft(tools::Long v)
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:2191
int i
OUString m_sPageName
Definition: fmpage.hxx:46
bool IsMasterPage() const
Definition: svdpage.hxx:450
void SetTop(tools::Long v)
void SetBottom(tools::Long v)
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
Definition: fmpage.cxx:96
Abstract DrawObject.
Definition: svdobj.hxx:260
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:421
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
void lateInit(const SdrPage &rSrcPage)
Definition: svdpage.cxx:1285
virtual bool IsAction() const override
Definition: svdcrtv.cxx:202
virtual SdrPage * CloneSdrPage(SdrModel &rTargetModel) const override
Definition: fmpage.cxx:65
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:390
#define FM_PROP_HELPTEXT
Definition: fmprop.hxx:98
FmFormPage(const FmFormPage &)=delete
friend class FmFormObj
Definition: fmpage.hxx:44
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
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:365
virtual SdrObject * RemoveObject(size_t nObjNum) override
Definition: fmpage.cxx:162
const css::uno::Reference< css::form::XForms > & GetForms(bool _bForceCreate=true) const
Definition: fmpage.cxx:84
::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
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)