LibreOffice Module sw (master) 1
drformsh.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/hlnkitem.hxx>
21#include <svx/svdview.hxx>
22#include <svl/whiter.hxx>
23#include <sfx2/request.hxx>
24#include <sfx2/objface.hxx>
25#include <sfx2/viewfrm.hxx>
26#include <sfx2/dispatch.hxx>
27#include <vcl/EnumContext.hxx>
28#include <svx/svdouno.hxx>
29#include <com/sun/star/form/FormButtonType.hpp>
30#include <com/sun/star/beans/XPropertySet.hpp>
31#include <com/sun/star/beans/XPropertySetInfo.hpp>
32#include <sfx2/htmlmode.hxx>
33#include <tools/urlobj.hxx>
34#include <osl/diagnose.h>
35
36#include <viewopt.hxx>
37#include <wrtsh.hxx>
38#include <cmdid.h>
39#include <drwbassh.hxx>
40#include <drformsh.hxx>
41#include <svl/urihelper.hxx>
42#include <view.hxx>
43#include <sfx2/docfile.hxx>
44#include <docsh.hxx>
45
46#define ShellClass_SwDrawFormShell
47#include <sfx2/msg.hxx>
48#include <swslots.hxx>
49
50using namespace ::com::sun::star;
51
53
54void SwDrawFormShell::InitInterface_Impl()
55{
56 GetStaticInterface()->RegisterPopupMenu("form");
57
58 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
59}
60
61
63{
64 SwWrtShell &rSh = GetShell();
65 const SfxPoolItem* pItem = nullptr;
66 const SfxItemSet *pArgs = rReq.GetArgs();
67
68 switch ( rReq.GetSlot() )
69 {
70 case SID_HYPERLINK_SETLINK:
71 {
72 if(pArgs)
73 pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem);
74 if(pItem)
75 {
76 SdrView *pSdrView = rSh.GetDrawView();
77 const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem);
78 bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
79 rHLinkItem.GetInsertMode() == HLINK_FIELD;
80 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
81 if (rMarkList.GetMark(0))
82 {
83 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
84 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
85 {
86 if(bConvertToText)
87 {
88 //remove object -> results in destruction of this!
89 SwView& rTempView = GetView();
90 rTempView.GetViewFrame().GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON );
91 rTempView.StopShellTimer();
92 //issue a new command to insert the link
94 SID_HYPERLINK_SETLINK, SfxCallMode::ASYNCHRON,
95 { &rHLinkItem });
96 }
97 else
98 {
99 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
100
101 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
102 if( !xControlModel.is() )
103 return;
104
105 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
106
107 // Can we set a URL to the object?
108 OUString sTargetURL( "TargetURL" );
109 uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
110 if( xPropInfoSet->hasPropertyByName( sTargetURL ))
111 {
112 beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
113 if( !aProp.Name.isEmpty() )
114 {
115 uno::Any aTmp;
116 // Yes!
117 OUString sLabel("Label");
118 if( xPropInfoSet->hasPropertyByName(sLabel) )
119 {
120 aTmp <<= rHLinkItem.GetName();
121 xPropSet->setPropertyValue(sLabel, aTmp );
122 }
123
124 SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
125 INetURLObject aAbs;
126 if( pMedium )
127 aAbs = pMedium->GetURLObject();
128 aTmp <<= URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL());
129 xPropSet->setPropertyValue( sTargetURL, aTmp );
130
131 if( !rHLinkItem.GetTargetFrame().isEmpty() )
132 {
133 aTmp <<= rHLinkItem.GetTargetFrame();
134 xPropSet->setPropertyValue( "TargetFrame", aTmp );
135 }
136
137 aTmp <<= form::FormButtonType_URL;
138 xPropSet->setPropertyValue( "ButtonType", aTmp );
139 }
140 }
141 }
142 }
143 }
144 }
145 }
146 break;
147
148 default:
149 OSL_ENSURE(false, "wrong dispatcher");
150 return;
151 }
152}
153
155{
156 SwWrtShell &rSh = GetShell();
157 SfxWhichIter aIter( rSet );
158 sal_uInt16 nWhich = aIter.FirstWhich();
159
160 while( nWhich )
161 {
162 switch( nWhich )
163 {
164 case SID_HYPERLINK_GETLINK:
165 {
166 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
167 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
168 SvxHyperlinkItem aHLinkItem;
169 if (rMarkList.GetMark(0))
170 {
171 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
172 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
173 {
174 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
175
176 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
177 if( !xControlModel.is() )
178 return;
179
180 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
181
182 uno::Any aTmp;
183 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
184 if(xInfo->hasPropertyByName( "ButtonType" ))
185 {
186 form::FormButtonType eButtonType = form::FormButtonType_URL;
187 aTmp = xPropSet->getPropertyValue( "ButtonType" );
188 if( aTmp >>= eButtonType )
189 {
190 // Label
191 if(xInfo->hasPropertyByName( "Label" ))
192 {
193 aTmp = xPropSet->getPropertyValue( "Label" );
194 OUString sTmp;
195 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
196 {
197 aHLinkItem.SetName(sTmp);
198 }
199 }
200
201 // URL
202 if(xInfo->hasPropertyByName( "TargetURL" ))
203 {
204 aTmp = xPropSet->getPropertyValue( "TargetURL" );
205 OUString sTmp;
206 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
207 {
208 aHLinkItem.SetURL(sTmp);
209 }
210 }
211
212 // Target
213 if(xInfo->hasPropertyByName( "TargetFrame" ))
214 {
215 aTmp = xPropSet->getPropertyValue( "TargetFrame" );
216 OUString sTmp;
217 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
218 {
219 aHLinkItem.SetTargetFrame(sTmp);
220 }
221 }
222 aHLinkItem.SetInsertMode(HLINK_BUTTON);
223 }
224 }
225 }
226 }
227 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
228 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
229 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
230
231 rSet.Put(aHLinkItem);
232 }
233 break;
234 }
235 nWhich = aIter.NextWhich();
236 }
237}
238
240 SwDrawBaseShell(_rView)
241{
242 GetShell().NoEdit();
243 SetName("DrawForm");
245}
246
248{
249}
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
virtual SdrInventor GetObjInventor() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const INetURLObject & GetURLObject() const
SfxMedium * GetMedium() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
void SetContextName(const OUString &rsContextName)
void SetName(const OUString &rName)
SfxDispatcher * GetDispatcher()
SfxViewFrame & GetViewFrame() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
SvxLinkInsertMode GetInsertMode() const
const OUString & GetName() const
const OUString & GetURL() const
void SetName(const OUString &rName)
void SetInsertMode(SvxLinkInsertMode eNew)
void SetURL(const OUString &rURL)
const OUString & GetTargetFrame() const
void SetTargetFrame(const OUString &rTarget)
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
SwView & GetView()
Definition: basesh.hxx:59
void GetState(SfxItemSet &)
Definition: drformsh.cxx:154
void Execute(SfxRequest const &)
Definition: drformsh.cxx:62
virtual ~SwDrawFormShell() override
Definition: drformsh.cxx:247
SwDrawFormShell(SwView &rView)
Definition: drformsh.cxx:239
SdrView * GetDrawViewWithValidMarkList()
Definition: vnew.cxx:391
SdrView * GetDrawView()
Definition: vnew.cxx:386
Definition: view.hxx:146
void StopShellTimer()
Definition: view.cxx:1836
SwDocShell * GetDocShell()
Definition: view.cxx:1193
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void NoEdit(bool bHideCursor=true)
Definition: wrtsh1.cxx:182
static const OUString & GetContextName(const Context eContext)
SvxLinkInsertMode
HLINK_FIELD
HLINK_DEFAULT
HLINK_HTMLMODE
HLINK_BUTTON
HTMLMODE_ON
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
#define SFX_OBJECTBAR_OBJECT
static SfxItemSet & rSet
#define SFX_IMPL_INTERFACE(Class, SuperClass)
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415