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