Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 <svl/srchitem.hxx>
30 : #include <svx/fmglob.hxx>
31 : #include <svx/svdouno.hxx>
32 : #include <com/sun/star/form/FormButtonType.hpp>
33 : #include <svx/htmlmode.hxx>
34 : #include <tools/urlobj.hxx>
35 :
36 : #include "viewopt.hxx"
37 : #include "swmodule.hxx"
38 : #include "wrtsh.hxx"
39 : #include "cmdid.h"
40 : #include "globals.hrc"
41 : #include "helpid.h"
42 : #include "popup.hrc"
43 : #include "shells.hrc"
44 : #include "drwbassh.hxx"
45 : #include "drformsh.hxx"
46 : #include <svl/urihelper.hxx>
47 : #include <view.hxx>
48 : #include <sfx2/docfile.hxx>
49 : #include <docsh.hxx>
50 :
51 : #define SwDrawFormShell
52 : #include <sfx2/msg.hxx>
53 : #include "swslots.hxx"
54 :
55 : #include <unomid.h>
56 :
57 :
58 : using namespace ::com::sun::star;
59 : using ::rtl::OUString;
60 :
61 60 : SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
62 : {
63 10 : SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAWFORM_POPUPMENU));
64 10 : SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
65 10 : }
66 :
67 :
68 0 : TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
69 :
70 :
71 0 : void SwDrawFormShell::Execute(SfxRequest &rReq)
72 : {
73 0 : SwWrtShell &rSh = GetShell();
74 0 : const SfxPoolItem* pItem = 0;
75 0 : const SfxItemSet *pArgs = rReq.GetArgs();
76 :
77 0 : switch ( rReq.GetSlot() )
78 : {
79 : case SID_HYPERLINK_SETLINK:
80 : {
81 0 : if(pArgs)
82 0 : pArgs->GetItemState(SID_HYPERLINK_SETLINK, sal_False, &pItem);
83 0 : if(pItem)
84 : {
85 0 : SdrView *pSdrView = rSh.GetDrawView();
86 0 : const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
87 0 : bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
88 0 : rHLinkItem.GetInsertMode() == HLINK_FIELD;
89 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
90 0 : if (rMarkList.GetMark(0))
91 : {
92 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
93 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
94 : {
95 0 : if(bConvertToText)
96 : {
97 : //remove object -> results in destruction of this!
98 0 : SwView& rTempView = GetView();
99 0 : rTempView.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SFX_CALLMODE_SYNCHRON );
100 0 : rTempView.StopShellTimer();
101 : //issue a new command to insert the link
102 : rTempView.GetViewFrame()->GetDispatcher()->Execute(
103 0 : SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON, &rHLinkItem, 0);
104 : }
105 : else
106 : {
107 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
108 :
109 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
110 0 : if( !xControlModel.is() )
111 : return;
112 :
113 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
114 :
115 : // Darf man eine URL an dem Objekt setzen?
116 0 : OUString sTargetURL( "TargetURL" );
117 0 : uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
118 0 : if( xPropInfoSet->hasPropertyByName( sTargetURL ))
119 : {
120 0 : beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
121 0 : if( !aProp.Name.isEmpty() )
122 : {
123 0 : uno::Any aTmp;
124 : // Ja!
125 0 : ::rtl::OUString sLabel("Label");
126 0 : if( xPropInfoSet->hasPropertyByName(sLabel) )
127 : {
128 0 : aTmp <<= OUString(rHLinkItem.GetName());
129 0 : xPropSet->setPropertyValue(sLabel, aTmp );
130 : }
131 :
132 0 : SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
133 0 : INetURLObject aAbs;
134 0 : if( pMedium )
135 0 : aAbs = pMedium->GetURLObject();
136 0 : aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()));
137 0 : xPropSet->setPropertyValue( sTargetURL, aTmp );
138 :
139 0 : if( rHLinkItem.GetTargetFrame().Len() )
140 : {
141 0 : aTmp <<= OUString(rHLinkItem.GetTargetFrame());
142 0 : xPropSet->setPropertyValue( "TargetFrame", aTmp );
143 : }
144 :
145 :
146 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
147 0 : aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
148 0 : xPropSet->setPropertyValue( "ButtonType", aTmp );
149 0 : }
150 0 : }
151 : }
152 : }
153 : }
154 : }
155 : }
156 0 : break;
157 :
158 : default:
159 : OSL_ENSURE(!this, "wrong dispatcher");
160 : return;
161 : }
162 : }
163 :
164 0 : void SwDrawFormShell::GetState(SfxItemSet& rSet)
165 : {
166 0 : SwWrtShell &rSh = GetShell();
167 0 : SfxWhichIter aIter( rSet );
168 0 : sal_uInt16 nWhich = aIter.FirstWhich();
169 :
170 0 : while( nWhich )
171 : {
172 0 : switch( nWhich )
173 : {
174 : case SID_HYPERLINK_GETLINK:
175 : {
176 0 : SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
177 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
178 0 : SvxHyperlinkItem aHLinkItem;
179 0 : if (rMarkList.GetMark(0))
180 : {
181 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
182 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
183 : {
184 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
185 :
186 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
187 0 : if( !xControlModel.is() )
188 0 : return;
189 :
190 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
191 :
192 0 : uno::Any aTmp;
193 0 : uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
194 0 : if(xInfo->hasPropertyByName( "ButtonType" ))
195 : {
196 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
197 0 : aTmp = xPropSet->getPropertyValue( "ButtonType" );
198 0 : if( aTmp >>= eButtonType )
199 : {
200 : // Label
201 0 : if(xInfo->hasPropertyByName( "Label" ))
202 : {
203 0 : aTmp = xPropSet->getPropertyValue( "Label" );
204 0 : OUString sTmp;
205 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
206 : {
207 0 : aHLinkItem.SetName(sTmp);
208 0 : }
209 : }
210 :
211 : // URL
212 0 : if(xInfo->hasPropertyByName( "TargetURL" ))
213 : {
214 0 : aTmp = xPropSet->getPropertyValue( "TargetURL" );
215 0 : OUString sTmp;
216 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
217 : {
218 0 : aHLinkItem.SetURL(sTmp);
219 0 : }
220 : }
221 :
222 : // Target
223 0 : if(xInfo->hasPropertyByName( "TargetFrame" ))
224 : {
225 0 : aTmp = xPropSet->getPropertyValue( "TargetFrame" );
226 0 : OUString sTmp;
227 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
228 : {
229 0 : aHLinkItem.SetTargetFrame(sTmp);
230 0 : }
231 : }
232 0 : aHLinkItem.SetInsertMode(HLINK_BUTTON);
233 : }
234 0 : }
235 : }
236 : }
237 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
238 0 : aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
239 0 : ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
240 :
241 0 : rSet.Put(aHLinkItem);
242 : }
243 0 : break;
244 : }
245 0 : nWhich = aIter.NextWhich();
246 0 : }
247 : }
248 :
249 :
250 0 : SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
251 0 : SwDrawBaseShell(_rView)
252 : {
253 0 : SetHelpId(SW_DRAWFORMSHELL);
254 0 : GetShell().NoEdit(sal_True);
255 0 : SetName(rtl::OUString("DrawForm"));
256 0 : }
257 :
258 0 : SwDrawFormShell::~SwDrawFormShell()
259 : {
260 0 : }
261 :
262 :
263 :
264 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|