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 <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>
36 :
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>
51 :
52 : #define SwDrawFormShell
53 : #include <sfx2/msg.hxx>
54 : #include "swslots.hxx"
55 :
56 : #include <unomid.h>
57 :
58 : using namespace ::com::sun::star;
59 :
60 222 : SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
61 : {
62 37 : SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAWFORM_POPUPMENU));
63 37 : SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
64 37 : }
65 :
66 0 : TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
67 :
68 0 : void SwDrawFormShell::Execute(SfxRequest &rReq)
69 : {
70 0 : SwWrtShell &rSh = GetShell();
71 0 : const SfxPoolItem* pItem = 0;
72 0 : const SfxItemSet *pArgs = rReq.GetArgs();
73 :
74 0 : switch ( rReq.GetSlot() )
75 : {
76 : case SID_HYPERLINK_SETLINK:
77 : {
78 0 : if(pArgs)
79 0 : pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem);
80 0 : if(pItem)
81 : {
82 0 : SdrView *pSdrView = rSh.GetDrawView();
83 0 : const SvxHyperlinkItem& rHLinkItem = *(const SvxHyperlinkItem *)pItem;
84 0 : bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT ||
85 0 : rHLinkItem.GetInsertMode() == HLINK_FIELD;
86 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
87 0 : if (rMarkList.GetMark(0))
88 : {
89 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
90 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
91 : {
92 0 : if(bConvertToText)
93 : {
94 : //remove object -> results in destruction of this!
95 0 : SwView& rTempView = GetView();
96 0 : rTempView.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SFX_CALLMODE_SYNCHRON );
97 0 : rTempView.StopShellTimer();
98 : //issue a new command to insert the link
99 : rTempView.GetViewFrame()->GetDispatcher()->Execute(
100 0 : SID_HYPERLINK_SETLINK, SFX_CALLMODE_ASYNCHRON, &rHLinkItem, 0);
101 : }
102 : else
103 : {
104 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
105 :
106 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
107 0 : if( !xControlModel.is() )
108 0 : return;
109 :
110 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
111 :
112 : // Can we set an URL to the object?
113 0 : OUString sTargetURL( "TargetURL" );
114 0 : uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo();
115 0 : if( xPropInfoSet->hasPropertyByName( sTargetURL ))
116 : {
117 0 : beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL );
118 0 : if( !aProp.Name.isEmpty() )
119 : {
120 0 : uno::Any aTmp;
121 : // Yes!
122 0 : OUString sLabel("Label");
123 0 : if( xPropInfoSet->hasPropertyByName(sLabel) )
124 : {
125 0 : aTmp <<= OUString(rHLinkItem.GetName());
126 0 : xPropSet->setPropertyValue(sLabel, aTmp );
127 : }
128 :
129 0 : SfxMedium* pMedium = GetView().GetDocShell()->GetMedium();
130 0 : INetURLObject aAbs;
131 0 : if( pMedium )
132 0 : aAbs = pMedium->GetURLObject();
133 0 : aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()));
134 0 : xPropSet->setPropertyValue( sTargetURL, aTmp );
135 :
136 0 : if( !rHLinkItem.GetTargetFrame().isEmpty() )
137 : {
138 0 : aTmp <<= rHLinkItem.GetTargetFrame();
139 0 : xPropSet->setPropertyValue( "TargetFrame", aTmp );
140 : }
141 :
142 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
143 0 : aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
144 0 : xPropSet->setPropertyValue( "ButtonType", aTmp );
145 0 : }
146 0 : }
147 : }
148 : }
149 : }
150 : }
151 : }
152 0 : break;
153 :
154 : default:
155 : OSL_ENSURE(!this, "wrong dispatcher");
156 0 : return;
157 : }
158 : }
159 :
160 0 : void SwDrawFormShell::GetState(SfxItemSet& rSet)
161 : {
162 0 : SwWrtShell &rSh = GetShell();
163 0 : SfxWhichIter aIter( rSet );
164 0 : sal_uInt16 nWhich = aIter.FirstWhich();
165 :
166 0 : while( nWhich )
167 : {
168 0 : switch( nWhich )
169 : {
170 : case SID_HYPERLINK_GETLINK:
171 : {
172 0 : SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
173 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
174 0 : SvxHyperlinkItem aHLinkItem;
175 0 : if (rMarkList.GetMark(0))
176 : {
177 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
178 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
179 : {
180 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
181 :
182 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
183 0 : if( !xControlModel.is() )
184 0 : return;
185 :
186 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
187 :
188 0 : uno::Any aTmp;
189 0 : uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
190 0 : if(xInfo->hasPropertyByName( "ButtonType" ))
191 : {
192 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
193 0 : aTmp = xPropSet->getPropertyValue( "ButtonType" );
194 0 : if( aTmp >>= eButtonType )
195 : {
196 : // Label
197 0 : if(xInfo->hasPropertyByName( "Label" ))
198 : {
199 0 : aTmp = xPropSet->getPropertyValue( "Label" );
200 0 : OUString sTmp;
201 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
202 : {
203 0 : aHLinkItem.SetName(sTmp);
204 0 : }
205 : }
206 :
207 : // URL
208 0 : if(xInfo->hasPropertyByName( "TargetURL" ))
209 : {
210 0 : aTmp = xPropSet->getPropertyValue( "TargetURL" );
211 0 : OUString sTmp;
212 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
213 : {
214 0 : aHLinkItem.SetURL(sTmp);
215 0 : }
216 : }
217 :
218 : // Target
219 0 : if(xInfo->hasPropertyByName( "TargetFrame" ))
220 : {
221 0 : aTmp = xPropSet->getPropertyValue( "TargetFrame" );
222 0 : OUString sTmp;
223 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
224 : {
225 0 : aHLinkItem.SetTargetFrame(sTmp);
226 0 : }
227 : }
228 0 : aHLinkItem.SetInsertMode(HLINK_BUTTON);
229 : }
230 0 : }
231 : }
232 : }
233 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
234 0 : aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
235 0 : ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
236 :
237 0 : rSet.Put(aHLinkItem);
238 : }
239 0 : break;
240 : }
241 0 : nWhich = aIter.NextWhich();
242 0 : }
243 : }
244 :
245 0 : SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
246 0 : SwDrawBaseShell(_rView)
247 : {
248 0 : SetHelpId(SW_DRAWFORMSHELL);
249 0 : GetShell().NoEdit(true);
250 0 : SetName(OUString("DrawForm"));
251 0 : SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Form));
252 0 : }
253 :
254 0 : SwDrawFormShell::~SwDrawFormShell()
255 : {
256 0 : }
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|