bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / drformsh.cxx
blob255aed0a97b5e08430f129105a9f49df00922aac
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 <hintids.hxx>
21 #include <svx/hlnkitem.hxx>
22 #include <svx/svdview.hxx>
23 #include <svl/whiter.hxx>
24 #include <sfx2/request.hxx>
25 #include <sfx2/objface.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/sidebar/EnumContext.hxx>
30 #include <svl/srchitem.hxx>
31 #include <svx/fmglob.hxx>
32 #include <svx/svdouno.hxx>
33 #include <com/sun/star/form/FormButtonType.hpp>
34 #include <sfx2/htmlmode.hxx>
35 #include <tools/urlobj.hxx>
37 #include "viewopt.hxx"
38 #include "swmodule.hxx"
39 #include "wrtsh.hxx"
40 #include "cmdid.h"
41 #include "globals.hrc"
42 #include "helpid.h"
43 #include "popup.hrc"
44 #include "shells.hrc"
45 #include "drwbassh.hxx"
46 #include "drformsh.hxx"
47 #include <svl/urihelper.hxx>
48 #include <view.hxx>
49 #include <sfx2/docfile.hxx>
50 #include <docsh.hxx>
52 #define SwDrawFormShell
53 #include <sfx2/msg.hxx>
54 #include "swslots.hxx"
56 #include <unomid.h>
59 using namespace ::com::sun::star;
61 SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
63 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAWFORM_POPUPMENU));
64 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
68 TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
71 void SwDrawFormShell::Execute(SfxRequest &rReq)
73 SwWrtShell &rSh = GetShell();
74 const SfxPoolItem* pItem = 0;
75 const SfxItemSet *pArgs = rReq.GetArgs();
77 switch ( rReq.GetSlot() )
79 case SID_HYPERLINK_SETLINK:
81 if(pArgs)
82 pArgs->GetItemState(SID_HYPERLINK_SETLINK, sal_False, &pItem);
83 if(pItem)
85 SdrView *pSdrView = rSh.GetDrawView();
86 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
87 bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
88 rHLinkItem.GetInsertMode() == HLINK_FIELD;
89 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
90 if (rMarkList.GetMark(0))
92 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
93 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
95 if(bConvertToText)
97 //remove object -> results in destruction of this!
98 SwView& rTempView = GetView();
99 rTempView.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SFX_CALLMODE_SYNCHRON );
100 rTempView.StopShellTimer();
101 //issue a new command to insert the link
102 rTempView.GetViewFrame()->GetDispatcher()->Execute(
103 SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON, &rHLinkItem, 0);
105 else
107 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
109 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
110 if( !xControlModel.is() )
111 return;
113 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
115 // Can we set an URL to the object?
116 OUString sTargetURL( "TargetURL" );
117 uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
118 if( xPropInfoSet->hasPropertyByName( sTargetURL ))
120 beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
121 if( !aProp.Name.isEmpty() )
123 uno::Any aTmp;
124 // Yes!
125 OUString sLabel("Label");
126 if( xPropInfoSet->hasPropertyByName(sLabel) )
128 aTmp <<= OUString(rHLinkItem.GetName());
129 xPropSet->setPropertyValue(sLabel, aTmp );
132 SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
133 INetURLObject aAbs;
134 if( pMedium )
135 aAbs = pMedium->GetURLObject();
136 aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()));
137 xPropSet->setPropertyValue( sTargetURL, aTmp );
139 if( rHLinkItem.GetTargetFrame().Len() )
141 aTmp <<= OUString(rHLinkItem.GetTargetFrame());
142 xPropSet->setPropertyValue( "TargetFrame", aTmp );
146 form::FormButtonType eButtonType = form::FormButtonType_URL;
147 aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
148 xPropSet->setPropertyValue( "ButtonType", aTmp );
156 break;
158 default:
159 OSL_ENSURE(!this, "wrong dispatcher");
160 return;
164 void SwDrawFormShell::GetState(SfxItemSet& rSet)
166 SwWrtShell &rSh = GetShell();
167 SfxWhichIter aIter( rSet );
168 sal_uInt16 nWhich = aIter.FirstWhich();
170 while( nWhich )
172 switch( nWhich )
174 case SID_HYPERLINK_GETLINK:
176 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
177 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
178 SvxHyperlinkItem aHLinkItem;
179 if (rMarkList.GetMark(0))
181 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
182 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
184 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
186 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
187 if( !xControlModel.is() )
188 return;
190 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
192 uno::Any aTmp;
193 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
194 if(xInfo->hasPropertyByName( "ButtonType" ))
196 form::FormButtonType eButtonType = form::FormButtonType_URL;
197 aTmp = xPropSet->getPropertyValue( "ButtonType" );
198 if( aTmp >>= eButtonType )
200 // Label
201 if(xInfo->hasPropertyByName( "Label" ))
203 aTmp = xPropSet->getPropertyValue( "Label" );
204 OUString sTmp;
205 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
207 aHLinkItem.SetName(sTmp);
211 // URL
212 if(xInfo->hasPropertyByName( "TargetURL" ))
214 aTmp = xPropSet->getPropertyValue( "TargetURL" );
215 OUString sTmp;
216 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
218 aHLinkItem.SetURL(sTmp);
222 // Target
223 if(xInfo->hasPropertyByName( "TargetFrame" ))
225 aTmp = xPropSet->getPropertyValue( "TargetFrame" );
226 OUString sTmp;
227 if( (aTmp >>= sTmp) && !sTmp.isEmpty())
229 aHLinkItem.SetTargetFrame(sTmp);
232 aHLinkItem.SetInsertMode(HLINK_BUTTON);
237 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
238 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
239 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
241 rSet.Put(aHLinkItem);
243 break;
245 nWhich = aIter.NextWhich();
249 SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
250 SwDrawBaseShell(_rView)
252 SetHelpId(SW_DRAWFORMSHELL);
253 GetShell().NoEdit(true);
254 SetName(OUString("DrawForm"));
255 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Form));
258 SwDrawFormShell::~SwDrawFormShell()
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */