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 450 : SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAWFORM))
61 :
62 90 : void SwDrawFormShell::InitInterface_Impl()
63 : {
64 90 : GetStaticInterface()->RegisterPopupMenu(SW_RES(MN_DRAWFORM_POPUPMENU));
65 :
66 90 : GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SW_RES(RID_TEXT_TOOLBOX));
67 90 : }
68 :
69 0 : TYPEINIT1(SwDrawFormShell, SwDrawBaseShell)
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, 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, SfxCallMode::SYNCHRON );
100 0 : rTempView.StopShellTimer();
101 : //issue a new command to insert the link
102 : rTempView.GetViewFrame()->GetDispatcher()->Execute(
103 0 : SID_HYPERLINK_SETLINK, SfxCallMode::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 0 : return;
112 :
113 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
114 :
115 : // Can we set an URL to the object?
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 : // Yes!
125 0 : 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().isEmpty() )
140 : {
141 0 : aTmp <<= rHLinkItem.GetTargetFrame();
142 0 : xPropSet->setPropertyValue( "TargetFrame", aTmp );
143 : }
144 :
145 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
146 0 : aTmp.setValue( &eButtonType, ::cppu::UnoType<form::FormButtonType>::get());
147 0 : xPropSet->setPropertyValue( "ButtonType", aTmp );
148 0 : }
149 0 : }
150 : }
151 : }
152 : }
153 : }
154 : }
155 0 : break;
156 :
157 : default:
158 : OSL_ENSURE(false, "wrong dispatcher");
159 0 : return;
160 : }
161 : }
162 :
163 0 : void SwDrawFormShell::GetState(SfxItemSet& rSet)
164 : {
165 0 : SwWrtShell &rSh = GetShell();
166 0 : SfxWhichIter aIter( rSet );
167 0 : sal_uInt16 nWhich = aIter.FirstWhich();
168 :
169 0 : while( nWhich )
170 : {
171 0 : switch( nWhich )
172 : {
173 : case SID_HYPERLINK_GETLINK:
174 : {
175 0 : SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList();
176 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
177 0 : SvxHyperlinkItem aHLinkItem;
178 0 : if (rMarkList.GetMark(0))
179 : {
180 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
181 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
182 : {
183 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
184 :
185 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
186 0 : if( !xControlModel.is() )
187 0 : return;
188 :
189 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
190 :
191 0 : uno::Any aTmp;
192 0 : uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
193 0 : if(xInfo->hasPropertyByName( "ButtonType" ))
194 : {
195 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
196 0 : aTmp = xPropSet->getPropertyValue( "ButtonType" );
197 0 : if( aTmp >>= eButtonType )
198 : {
199 : // Label
200 0 : if(xInfo->hasPropertyByName( "Label" ))
201 : {
202 0 : aTmp = xPropSet->getPropertyValue( "Label" );
203 0 : OUString sTmp;
204 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
205 : {
206 0 : aHLinkItem.SetName(sTmp);
207 0 : }
208 : }
209 :
210 : // URL
211 0 : if(xInfo->hasPropertyByName( "TargetURL" ))
212 : {
213 0 : aTmp = xPropSet->getPropertyValue( "TargetURL" );
214 0 : OUString sTmp;
215 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
216 : {
217 0 : aHLinkItem.SetURL(sTmp);
218 0 : }
219 : }
220 :
221 : // Target
222 0 : if(xInfo->hasPropertyByName( "TargetFrame" ))
223 : {
224 0 : aTmp = xPropSet->getPropertyValue( "TargetFrame" );
225 0 : OUString sTmp;
226 0 : if( (aTmp >>= sTmp) && !sTmp.isEmpty())
227 : {
228 0 : aHLinkItem.SetTargetFrame(sTmp);
229 0 : }
230 : }
231 0 : aHLinkItem.SetInsertMode(HLINK_BUTTON);
232 : }
233 0 : }
234 : }
235 : }
236 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
237 0 : aHLinkItem.SetInsertMode((SvxLinkInsertMode)(aHLinkItem.GetInsertMode() |
238 0 : ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0)));
239 :
240 0 : rSet.Put(aHLinkItem);
241 : }
242 0 : break;
243 : }
244 0 : nWhich = aIter.NextWhich();
245 0 : }
246 : }
247 :
248 0 : SwDrawFormShell::SwDrawFormShell(SwView &_rView) :
249 0 : SwDrawBaseShell(_rView)
250 : {
251 0 : SetHelpId(SW_DRAWFORMSHELL);
252 0 : GetShell().NoEdit(true);
253 0 : SetName(OUString("DrawForm"));
254 0 : SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Form));
255 0 : }
256 :
257 0 : SwDrawFormShell::~SwDrawFormShell()
258 : {
259 270 : }
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|