Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / drformsh.cxx
blobfcf2eab803d18c389fbed8e9442ba92777fb5a5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
46 #define ShellClass_SwDrawFormShell
47 #include <sfx2/msg.hxx>
48 #include <swslots.hxx>
50 using namespace ::com::sun::star;
52 SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell)
54 void SwDrawFormShell::InitInterface_Impl()
56 GetStaticInterface()->RegisterPopupMenu("form");
58 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw);
62 void SwDrawFormShell::Execute(SfxRequest const &rReq)
64 SwWrtShell &rSh = GetShell();
65 const SfxPoolItem* pItem = nullptr;
66 const SfxItemSet *pArgs = rReq.GetArgs();
68 switch ( rReq.GetSlot() )
70 case SID_HYPERLINK_SETLINK:
72 if(pArgs)
73 pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem);
74 if(pItem)
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))
83 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
84 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
86 if(bConvertToText)
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
93 rTempView.GetViewFrame().GetDispatcher()->ExecuteList(
94 SID_HYPERLINK_SETLINK, SfxCallMode::ASYNCHRON,
95 { &rHLinkItem });
97 else
99 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
101 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
102 if( !xControlModel.is() )
103 return;
105 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
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 ))
112 beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
113 if( !aProp.Name.isEmpty() )
115 uno::Any aTmp;
116 // Yes!
117 OUString sLabel("Label");
118 if( xPropInfoSet->hasPropertyByName(sLabel) )
120 aTmp <<= rHLinkItem.GetName();
121 xPropSet->setPropertyValue(sLabel, aTmp );
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 );
131 if( !rHLinkItem.GetTargetFrame().isEmpty() )
133 aTmp <<= rHLinkItem.GetTargetFrame();
134 xPropSet->setPropertyValue( "TargetFrame", aTmp );
137 aTmp <<= form::FormButtonType_URL;
138 xPropSet->setPropertyValue( "ButtonType", aTmp );
146 break;
148 default:
149 OSL_ENSURE(false, "wrong dispatcher");
150 return;
154 void SwDrawFormShell::GetState(SfxItemSet& rSet)
156 SwWrtShell &rSh = GetShell();
157 SfxWhichIter aIter( rSet );
158 sal_uInt16 nWhich = aIter.FirstWhich();
160 while( nWhich )
162 switch( nWhich )
164 case SID_HYPERLINK_GETLINK:
166 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
167 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
168 SvxHyperlinkItem aHLinkItem;
169 if (rMarkList.GetMark(0))
171 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
172 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
174 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
176 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
177 if( !xControlModel.is() )
178 return;
180 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
182 uno::Any aTmp;
183 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
184 if(xInfo->hasPropertyByName( "ButtonType" ))
186 form::FormButtonType eButtonType = form::FormButtonType_URL;
187 aTmp = xPropSet->getPropertyValue( "ButtonType" );
188 if( aTmp >>= eButtonType )
190 // Label
191 if(xInfo->hasPropertyByName( "Label" ))
193 aTmp = xPropSet->getPropertyValue( "Label" );
194 OUString sTmp;
195 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
197 aHLinkItem.SetName(sTmp);
201 // URL
202 if(xInfo->hasPropertyByName( "TargetURL" ))
204 aTmp = xPropSet->getPropertyValue( "TargetURL" );
205 OUString sTmp;
206 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
208 aHLinkItem.SetURL(sTmp);
212 // Target
213 if(xInfo->hasPropertyByName( "TargetFrame" ))
215 aTmp = xPropSet->getPropertyValue( "TargetFrame" );
216 OUString sTmp;
217 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
219 aHLinkItem.SetTargetFrame(sTmp);
222 aHLinkItem.SetInsertMode(HLINK_BUTTON);
227 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
228 aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() |
229 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
231 rSet.Put(aHLinkItem);
233 break;
235 nWhich = aIter.NextWhich();
239 SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
240 SwDrawBaseShell(_rView)
242 GetShell().NoEdit();
243 SetName("DrawForm");
244 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Form));
247 SwDrawFormShell::~SwDrawFormShell()
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */