update dev300-m58
[ooovba.git] / sw / source / ui / shells / drformsh.cxx
blob59586c2a538bfc263c315325b6d483533d41d035
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drformsh.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <hintids.hxx>
37 #include <svx/hlnkitem.hxx>
38 #include <svx/svdview.hxx>
39 #include <svtools/whiter.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/objface.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <svx/srchitem.hxx>
46 #include <svx/fmglob.hxx>
47 #include <svx/svdouno.hxx>
48 #include <com/sun/star/form/FormButtonType.hpp>
49 #include <svx/htmlmode.hxx>
50 #include <tools/urlobj.hxx>
52 #include "viewopt.hxx"
53 #include "swmodule.hxx"
54 #include "wrtsh.hxx"
55 #include "cmdid.h"
56 #include "globals.hrc"
57 #include "helpid.h"
58 #include "popup.hrc"
59 #include "shells.hrc"
60 #include "drwbassh.hxx"
61 #include "drformsh.hxx"
62 #include <svtools/urihelper.hxx>
63 #include <view.hxx>
64 #include <sfx2/docfile.hxx>
65 #include <docsh.hxx>
67 #define SwDrawFormShell
68 #include <sfx2/msg.hxx>
69 #include "swslots.hxx"
71 #include <unomid.h>
74 using namespace ::com::sun::star;
75 using ::rtl::OUString;
77 SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
79 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAWFORM_POPUPMENU));
80 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
84 TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
87 void SwDrawFormShell::Execute(SfxRequest &rReq)
89 SwWrtShell &rSh = GetShell();
90 const SfxPoolItem* pItem = 0;
91 const SfxItemSet *pArgs = rReq.GetArgs();
93 switch ( rReq.GetSlot() )
95 case SID_HYPERLINK_SETLINK:
97 if(pArgs)
98 pArgs->GetItemState(SID_HYPERLINK_SETLINK, sal_False, &pItem);
99 if(pItem)
101 SdrView *pSdrView = rSh.GetDrawView();
102 const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
103 bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
104 rHLinkItem.GetInsertMode() == HLINK_FIELD;
105 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
106 if (rMarkList.GetMark(0))
108 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
109 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
111 if(bConvertToText)
113 //remove object -> results in destruction of this!
114 SwView& rTempView = GetView();
115 rTempView.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SFX_CALLMODE_SYNCHRON );
116 rTempView.StopShellTimer();
117 //issue a new command to insert the link
118 rTempView.GetViewFrame()->GetDispatcher()->Execute(
119 SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON, &rHLinkItem, 0);
121 else
123 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
125 ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
126 if( !xControlModel.is() )
127 return;
129 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
131 // Darf man eine URL an dem Objekt setzen?
132 OUString sTargetURL( C2U( "TargetURL" ));
133 uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
134 if( xPropInfoSet->hasPropertyByName( sTargetURL ))
136 beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
137 if( aProp.Name.getLength() )
139 uno::Any aTmp;
140 // Ja!
141 ::rtl::OUString sLabel(C2U("Label"));
142 if( xPropInfoSet->hasPropertyByName(sLabel) )
144 aTmp <<= OUString(rHLinkItem.GetName());
145 xPropSet->setPropertyValue(sLabel, aTmp );
148 SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
149 INetURLObject aAbs;
150 if( pMedium )
151 aAbs = pMedium->GetURLObject();
152 aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()));
153 xPropSet->setPropertyValue( sTargetURL, aTmp );
155 if( rHLinkItem.GetTargetFrame().Len() )
157 aTmp <<= OUString(rHLinkItem.GetTargetFrame());
158 xPropSet->setPropertyValue( C2U("TargetFrame"), aTmp );
162 form::FormButtonType eButtonType = form::FormButtonType_URL;
163 aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
164 xPropSet->setPropertyValue( C2U("ButtonType"), aTmp );
172 break;
174 default:
175 DBG_ASSERT(!this, "falscher Dispatcher");
176 return;
180 void SwDrawFormShell::GetState(SfxItemSet& rSet)
182 SwWrtShell &rSh = GetShell();
183 SfxWhichIter aIter( rSet );
184 sal_uInt16 nWhich = aIter.FirstWhich();
186 while( nWhich )
188 switch( nWhich )
190 case SID_HYPERLINK_GETLINK:
192 SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
193 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
194 SvxHyperlinkItem aHLinkItem;
195 if (rMarkList.GetMark(0))
197 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
198 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
200 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
202 ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
203 if( !xControlModel.is() )
204 return;
206 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
208 uno::Any aTmp;
209 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
210 if(xInfo->hasPropertyByName(C2U("ButtonType" )))
212 form::FormButtonType eButtonType = form::FormButtonType_URL;
213 aTmp = xPropSet->getPropertyValue( C2U("ButtonType") );
214 if( aTmp >>= eButtonType )
216 // Label
217 if(xInfo->hasPropertyByName( C2U("Label") ))
219 aTmp = xPropSet->getPropertyValue( C2U("Label") );
220 OUString sTmp;
221 if( (aTmp >>= sTmp) && sTmp.getLength())
223 aHLinkItem.SetName(sTmp);
227 // URL
228 if(xInfo->hasPropertyByName( C2U("TargetURL" )))
230 aTmp = xPropSet->getPropertyValue( C2U("TargetURL") );
231 OUString sTmp;
232 if( (aTmp >>= sTmp) && sTmp.getLength())
234 aHLinkItem.SetURL(sTmp);
238 // Target
239 if(xInfo->hasPropertyByName( C2U("TargetFrame") ))
241 aTmp = xPropSet->getPropertyValue( C2U("TargetFrame") );
242 OUString sTmp;
243 if( (aTmp >>= sTmp) && sTmp.getLength())
245 aHLinkItem.SetTargetFrame(sTmp);
248 aHLinkItem.SetInsertMode(HLINK_BUTTON);
253 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
254 aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
255 ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
257 rSet.Put(aHLinkItem);
259 break;
261 nWhich = aIter.NextWhich();
266 SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
267 SwDrawBaseShell(_rView)
269 SetHelpId(SW_DRAWFORMSHELL);
270 GetShell().NoEdit(sal_True);
271 SetName(String::CreateFromAscii("DrawForm"));
274 SwDrawFormShell::~SwDrawFormShell()