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 #include <vcl/window.hxx>
33 #include <osl/diagnose.h>
34 
35 
36 #include <fmprop.hxx>
37 #include <fmundo.hxx>
38 using namespace ::svxform;
39 #include <comphelper/property.hxx>
40 #include <comphelper/types.hxx>
41 
43 using com::sun::star::uno::UNO_QUERY;
44 
45 
46 FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
47 : SdrPage(rModel, bMasterPage)
48  ,m_pImpl( new FmFormPageImpl( *this ) )
49 {
50 }
51 
52 void FmFormPage::lateInit(const FmFormPage& rPage)
53 {
54  // call parent
55  SdrPage::lateInit( rPage );
56 
57  // copy local variables (former stuff from copy constructor)
58  m_pImpl->initFrom( rPage.GetImpl() );
59  m_sPageName = rPage.m_sPageName;
60 }
61 
62 
64 {
65 }
66 
68 {
69  FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
70  rtl::Reference<FmFormPage> pClonedFmFormPage =
71  new FmFormPage(
72  rFmFormModel,
73  IsMasterPage());
74  pClonedFmFormPage->lateInit(*this);
75  return pClonedFmFormPage;
76 }
77 
78 
79 void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
80 {
81  SdrPage::InsertObject( pObj, nPos );
82  static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
83 }
84 
85 
86 const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
87 {
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?!" );
91  if ( !pFormPage )
92  pFormPage = this;
93 
94  return pFormPage->m_pImpl->getForms( _bForceCreate );
95 }
96 
97 
98 bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
99  const HelpEvent& rEvt )
100 {
101  if( pView->IsAction() )
102  return false;
103 
104  Point aPos = rEvt.GetMousePosPixel();
105  aPos = pWindow->ScreenToOutputPixel( aPos );
106  aPos = pWindow->PixelToLogic( aPos );
107 
108  SdrPageView* pPV = nullptr;
109  SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
110  if (!pObj)
111  return false;
112 
113  FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
114  if ( !pFormObject )
115  return false;
116 
117  OUString aHelpText;
118  css::uno::Reference< css::beans::XPropertySet > xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
119  if (xSet.is())
120  {
122  aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
123 
124  if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
125  {
126  OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
127  INetURLObject aUrl(aText);
128 
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,
134  INetProtocol::Ldap
135  };
136  for (const INetProtocol& i : s_aQuickHelpSupported)
137  if (i == aProtocol)
138  {
139  aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
140  break;
141  }
142  }
143  }
144  if ( !aHelpText.isEmpty() )
145  {
146  // display the help
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);
157  else
158  Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
159  }
160  return true;
161 }
162 
163 
165 {
166  SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
167  if (pObj)
168  static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
169  return pObj;
170 }
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:957
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
Definition: fmpage.cxx:79
virtual ~FmFormPage() override
Definition: fmpage.cxx:63
virtual rtl::Reference< SdrPage > CloneSdrPage(SdrModel &rTargetModel) const override
Definition: fmpage.cxx:67
void lateInit(const FmFormPage &rPage)
Definition: fmpage.cxx:52
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:334
HelpEventMode GetMode() const
INetProtocol
FmFormPageImpl & GetImpl() const
Definition: fmpage.hxx:62
constexpr void SetLeft(tools::Long v)
const Point & GetMousePosPixel() const
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
Definition: svdmrkv.cxx:2372
Point LogicToPixel(const Point &rLogicPt) const
int i
OUString m_sPageName
Definition: fmpage.hxx:46
bool IsMasterPage() const
Definition: svdpage.hxx:451
constexpr void SetRight(tools::Long v)
constexpr void SetBottom(tools::Long v)
Point PixelToLogic(const Point &rDevicePt) const
static bool RequestHelp(vcl::Window *pWin, SdrView const *pView, const HelpEvent &rEvt)
Definition: fmpage.cxx:98
Abstract DrawObject.
Definition: svdobj.hxx:259
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:412
constexpr void SetTop(tools::Long v)
constexpr Point Center() const
constexpr Point TopLeft() const
void lateInit(const SdrPage &rSrcPage)
Definition: svdpage.cxx:1345
virtual bool IsAction() const override
Definition: svdcrtv.cxx:202
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
constexpr Point BottomRight() const
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:164
const css::uno::Reference< css::form::XForms > & GetForms(bool _bForceCreate=true) const
Definition: fmpage.cxx:86
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
OUString getString(const Any &_rAny)
std::unique_ptr< FmFormPageImpl > m_pImpl
Definition: fmpage.hxx:45
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)