1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <hintids.hxx>
30cdf0e10cSrcweir #include <svx/hlnkitem.hxx>
31cdf0e10cSrcweir #include <svx/svdview.hxx>
32cdf0e10cSrcweir #include <svl/whiter.hxx>
33cdf0e10cSrcweir #include <sfx2/request.hxx>
34cdf0e10cSrcweir #include <sfx2/objface.hxx>
35cdf0e10cSrcweir #include <sfx2/app.hxx>
36cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
37cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
38*f120fe41SAndre Fischer #include <sfx2/sidebar/EnumContext.hxx>
39cdf0e10cSrcweir #include <svl/srchitem.hxx>
40cdf0e10cSrcweir #include <svx/fmglob.hxx>
41cdf0e10cSrcweir #include <svx/svdouno.hxx>
42cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp>
43cdf0e10cSrcweir #include <svx/htmlmode.hxx>
44cdf0e10cSrcweir #include <tools/urlobj.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include "viewopt.hxx"
47cdf0e10cSrcweir #include "swmodule.hxx"
48cdf0e10cSrcweir #include "wrtsh.hxx"
49cdf0e10cSrcweir #include "cmdid.h"
50cdf0e10cSrcweir #include "globals.hrc"
51cdf0e10cSrcweir #include "helpid.h"
52cdf0e10cSrcweir #include "popup.hrc"
53cdf0e10cSrcweir #include "shells.hrc"
54cdf0e10cSrcweir #include "drwbassh.hxx"
55cdf0e10cSrcweir #include "drformsh.hxx"
56cdf0e10cSrcweir #include <svl/urihelper.hxx>
57cdf0e10cSrcweir #include <view.hxx>
58cdf0e10cSrcweir #include <sfx2/docfile.hxx>
59cdf0e10cSrcweir #include <docsh.hxx>
60cdf0e10cSrcweir
61cdf0e10cSrcweir #define SwDrawFormShell
62cdf0e10cSrcweir #include <sfx2/msg.hxx>
63cdf0e10cSrcweir #include "swslots.hxx"
64cdf0e10cSrcweir
65cdf0e10cSrcweir #include <unomid.h>
66cdf0e10cSrcweir
67cdf0e10cSrcweir
68cdf0e10cSrcweir using namespace ::com::sun::star;
69cdf0e10cSrcweir using ::rtl::OUString;
70cdf0e10cSrcweir
SFX_IMPL_INTERFACE(SwDrawFormShell,SwDrawBaseShell,SW_RES (STR_SHELLNAME_DRAWFORM))71cdf0e10cSrcweir SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
72cdf0e10cSrcweir {
73cdf0e10cSrcweir SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAWFORM_POPUPMENU));
74cdf0e10cSrcweir SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir
TYPEINIT1(SwDrawFormShell,SwDrawBaseShell)78cdf0e10cSrcweir TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
79cdf0e10cSrcweir
80cdf0e10cSrcweir
81cdf0e10cSrcweir void SwDrawFormShell::Execute(SfxRequest &rReq)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir SwWrtShell &rSh = GetShell();
84cdf0e10cSrcweir const SfxPoolItem* pItem = 0;
85cdf0e10cSrcweir const SfxItemSet *pArgs = rReq.GetArgs();
86cdf0e10cSrcweir
87cdf0e10cSrcweir switch ( rReq.GetSlot() )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir case SID_HYPERLINK_SETLINK:
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if(pArgs)
92cdf0e10cSrcweir pArgs->GetItemState(SID_HYPERLINK_SETLINK, sal_False, &pItem);
93cdf0e10cSrcweir if(pItem)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir SdrView *pSdrView = rSh.GetDrawView();
96cdf0e10cSrcweir const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
97cdf0e10cSrcweir bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
98cdf0e10cSrcweir rHLinkItem.GetInsertMode() == HLINK_FIELD;
99cdf0e10cSrcweir const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
100cdf0e10cSrcweir if (rMarkList.GetMark(0))
101cdf0e10cSrcweir {
102cdf0e10cSrcweir SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
103cdf0e10cSrcweir if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if(bConvertToText)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir //remove object -> results in destruction of this!
108cdf0e10cSrcweir SwView& rTempView = GetView();
109cdf0e10cSrcweir rTempView.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SFX_CALLMODE_SYNCHRON );
110cdf0e10cSrcweir rTempView.StopShellTimer();
111cdf0e10cSrcweir //issue a new command to insert the link
112cdf0e10cSrcweir rTempView.GetViewFrame()->GetDispatcher()->Execute(
113cdf0e10cSrcweir SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON, &rHLinkItem, 0);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir else
116cdf0e10cSrcweir {
117cdf0e10cSrcweir uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
118cdf0e10cSrcweir
119cdf0e10cSrcweir ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
120cdf0e10cSrcweir if( !xControlModel.is() )
121cdf0e10cSrcweir return;
122cdf0e10cSrcweir
123cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
124cdf0e10cSrcweir
125cdf0e10cSrcweir // Darf man eine URL an dem Objekt setzen?
126cdf0e10cSrcweir OUString sTargetURL( C2U( "TargetURL" ));
127cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
128cdf0e10cSrcweir if( xPropInfoSet->hasPropertyByName( sTargetURL ))
129cdf0e10cSrcweir {
130cdf0e10cSrcweir beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
131cdf0e10cSrcweir if( aProp.Name.getLength() )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir uno::Any aTmp;
134cdf0e10cSrcweir // Ja!
135cdf0e10cSrcweir ::rtl::OUString sLabel(C2U("Label"));
136cdf0e10cSrcweir if( xPropInfoSet->hasPropertyByName(sLabel) )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir aTmp <<= OUString(rHLinkItem.GetName());
139cdf0e10cSrcweir xPropSet->setPropertyValue(sLabel, aTmp );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
143cdf0e10cSrcweir INetURLObject aAbs;
144cdf0e10cSrcweir if( pMedium )
145cdf0e10cSrcweir aAbs = pMedium->GetURLObject();
146cdf0e10cSrcweir aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()));
147cdf0e10cSrcweir xPropSet->setPropertyValue( sTargetURL, aTmp );
148cdf0e10cSrcweir
149cdf0e10cSrcweir if( rHLinkItem.GetTargetFrame().Len() )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir aTmp <<= OUString(rHLinkItem.GetTargetFrame());
152cdf0e10cSrcweir xPropSet->setPropertyValue( C2U("TargetFrame"), aTmp );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir
156cdf0e10cSrcweir form::FormButtonType eButtonType = form::FormButtonType_URL;
157cdf0e10cSrcweir aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
158cdf0e10cSrcweir xPropSet->setPropertyValue( C2U("ButtonType"), aTmp );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir break;
167cdf0e10cSrcweir
168cdf0e10cSrcweir default:
169cdf0e10cSrcweir DBG_ASSERT(!this, "falscher Dispatcher");
170cdf0e10cSrcweir return;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
GetState(SfxItemSet & rSet)174cdf0e10cSrcweir void SwDrawFormShell::GetState(SfxItemSet& rSet)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir SwWrtShell &rSh = GetShell();
177cdf0e10cSrcweir SfxWhichIter aIter( rSet );
178cdf0e10cSrcweir sal_uInt16 nWhich = aIter.FirstWhich();
179cdf0e10cSrcweir
180cdf0e10cSrcweir while( nWhich )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir switch( nWhich )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir case SID_HYPERLINK_GETLINK:
185cdf0e10cSrcweir {
186cdf0e10cSrcweir SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
187cdf0e10cSrcweir const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
188cdf0e10cSrcweir SvxHyperlinkItem aHLinkItem;
189cdf0e10cSrcweir if (rMarkList.GetMark(0))
190cdf0e10cSrcweir {
191cdf0e10cSrcweir SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
192cdf0e10cSrcweir if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
193cdf0e10cSrcweir {
194cdf0e10cSrcweir uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
195cdf0e10cSrcweir
196cdf0e10cSrcweir ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
197cdf0e10cSrcweir if( !xControlModel.is() )
198cdf0e10cSrcweir return;
199cdf0e10cSrcweir
200cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
201cdf0e10cSrcweir
202cdf0e10cSrcweir uno::Any aTmp;
203cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
204cdf0e10cSrcweir if(xInfo->hasPropertyByName(C2U("ButtonType" )))
205cdf0e10cSrcweir {
206cdf0e10cSrcweir form::FormButtonType eButtonType = form::FormButtonType_URL;
207cdf0e10cSrcweir aTmp = xPropSet->getPropertyValue( C2U("ButtonType") );
208cdf0e10cSrcweir if( aTmp >>= eButtonType )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir // Label
211cdf0e10cSrcweir if(xInfo->hasPropertyByName( C2U("Label") ))
212cdf0e10cSrcweir {
213cdf0e10cSrcweir aTmp = xPropSet->getPropertyValue( C2U("Label") );
214cdf0e10cSrcweir OUString sTmp;
215cdf0e10cSrcweir if( (aTmp >>= sTmp) && sTmp.getLength())
216cdf0e10cSrcweir {
217cdf0e10cSrcweir aHLinkItem.SetName(sTmp);
218cdf0e10cSrcweir }
219cdf0e10cSrcweir }
220cdf0e10cSrcweir
221cdf0e10cSrcweir // URL
222cdf0e10cSrcweir if(xInfo->hasPropertyByName( C2U("TargetURL" )))
223cdf0e10cSrcweir {
224cdf0e10cSrcweir aTmp = xPropSet->getPropertyValue( C2U("TargetURL") );
225cdf0e10cSrcweir OUString sTmp;
226cdf0e10cSrcweir if( (aTmp >>= sTmp) && sTmp.getLength())
227cdf0e10cSrcweir {
228cdf0e10cSrcweir aHLinkItem.SetURL(sTmp);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir // Target
233cdf0e10cSrcweir if(xInfo->hasPropertyByName( C2U("TargetFrame") ))
234cdf0e10cSrcweir {
235cdf0e10cSrcweir aTmp = xPropSet->getPropertyValue( C2U("TargetFrame") );
236cdf0e10cSrcweir OUString sTmp;
237cdf0e10cSrcweir if( (aTmp >>= sTmp) && sTmp.getLength())
238cdf0e10cSrcweir {
239cdf0e10cSrcweir aHLinkItem.SetTargetFrame(sTmp);
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir aHLinkItem.SetInsertMode(HLINK_BUTTON);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir }
247cdf0e10cSrcweir sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
248cdf0e10cSrcweir aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
249cdf0e10cSrcweir ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
250cdf0e10cSrcweir
251cdf0e10cSrcweir rSet.Put(aHLinkItem);
252cdf0e10cSrcweir }
253cdf0e10cSrcweir break;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir nWhich = aIter.NextWhich();
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir
SwDrawFormShell(SwView & _rView)260cdf0e10cSrcweir SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
261cdf0e10cSrcweir SwDrawBaseShell(_rView)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir SetHelpId(SW_DRAWFORMSHELL);
264cdf0e10cSrcweir GetShell().NoEdit(sal_True);
265cdf0e10cSrcweir SetName(String::CreateFromAscii("DrawForm"));
266*f120fe41SAndre Fischer SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Form));
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
~SwDrawFormShell()269cdf0e10cSrcweir SwDrawFormShell::~SwDrawFormShell()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir }
272