/src/libreoffice/sw/source/uibase/shells/drformsh.cxx
Line | Count | Source |
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 <svx/hlnkitem.hxx> |
21 | | #include <svx/svdview.hxx> |
22 | | #include <svl/whiter.hxx> |
23 | | #include <sfx2/request.hxx> |
24 | | #include <sfx2/objface.hxx> |
25 | | #include <sfx2/toolbarids.hxx> |
26 | | #include <sfx2/viewfrm.hxx> |
27 | | #include <sfx2/dispatch.hxx> |
28 | | #include <vcl/EnumContext.hxx> |
29 | | #include <svx/svdouno.hxx> |
30 | | #include <com/sun/star/form/FormButtonType.hpp> |
31 | | #include <com/sun/star/beans/XPropertySet.hpp> |
32 | | #include <com/sun/star/beans/XPropertySetInfo.hpp> |
33 | | #include <sfx2/htmlmode.hxx> |
34 | | #include <tools/urlobj.hxx> |
35 | | #include <osl/diagnose.h> |
36 | | |
37 | | #include <viewopt.hxx> |
38 | | #include <wrtsh.hxx> |
39 | | #include <cmdid.h> |
40 | | #include <drwbassh.hxx> |
41 | | #include <drformsh.hxx> |
42 | | #include <svl/urihelper.hxx> |
43 | | #include <view.hxx> |
44 | | #include <sfx2/docfile.hxx> |
45 | | #include <docsh.hxx> |
46 | | |
47 | | #define ShellClass_SwDrawFormShell |
48 | | #include <sfx2/msg.hxx> |
49 | | #include <swslots.hxx> |
50 | | |
51 | | using namespace ::com::sun::star; |
52 | | |
53 | | SFX_IMPL_INTERFACE(SwDrawFormShell, SwDrawBaseShell) |
54 | | |
55 | | void SwDrawFormShell::InitInterface_Impl() |
56 | 9 | { |
57 | 9 | GetStaticInterface()->RegisterPopupMenu(u"form"_ustr); |
58 | | |
59 | 9 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw); |
60 | 9 | } |
61 | | |
62 | | |
63 | | void SwDrawFormShell::Execute(SfxRequest const &rReq) |
64 | 0 | { |
65 | 0 | SwWrtShell &rSh = GetShell(); |
66 | 0 | const SfxPoolItem* pItem = nullptr; |
67 | 0 | const SfxItemSet *pArgs = rReq.GetArgs(); |
68 | |
|
69 | 0 | switch ( rReq.GetSlot() ) |
70 | 0 | { |
71 | 0 | case SID_HYPERLINK_SETLINK: |
72 | 0 | { |
73 | 0 | if(pArgs) |
74 | 0 | pArgs->GetItemState(SID_HYPERLINK_SETLINK, false, &pItem); |
75 | 0 | if(pItem) |
76 | 0 | { |
77 | 0 | SdrView *pSdrView = rSh.GetDrawView(); |
78 | 0 | const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem); |
79 | 0 | bool bConvertToText = rHLinkItem.GetInsertMode() == HLINK_DEFAULT || |
80 | 0 | rHLinkItem.GetInsertMode() == HLINK_FIELD; |
81 | 0 | const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); |
82 | 0 | if (rMarkList.GetMark(0)) |
83 | 0 | { |
84 | 0 | SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() ); |
85 | 0 | if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor()) |
86 | 0 | { |
87 | 0 | if(bConvertToText) |
88 | 0 | { |
89 | | //remove object -> results in destruction of this! |
90 | 0 | SwView& rTempView = GetView(); |
91 | 0 | rTempView.GetViewFrame().GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON ); |
92 | 0 | rTempView.StopShellTimer(); |
93 | | //issue a new command to insert the link |
94 | 0 | rTempView.GetViewFrame().GetDispatcher()->ExecuteList( |
95 | 0 | SID_HYPERLINK_SETLINK, SfxCallMode::ASYNCHRON, |
96 | 0 | { &rHLinkItem }); |
97 | 0 | } |
98 | 0 | else |
99 | 0 | { |
100 | 0 | const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel(); |
101 | |
|
102 | 0 | OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" ); |
103 | 0 | if( !xControlModel.is() ) |
104 | 0 | return; |
105 | | |
106 | 0 | uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY); |
107 | | |
108 | | // Can we set a URL to the object? |
109 | 0 | OUString sTargetURL( u"TargetURL"_ustr ); |
110 | 0 | uno::Reference< beans::XPropertySetInfo > xPropInfoSet = xPropSet->getPropertySetInfo(); |
111 | 0 | if( xPropInfoSet->hasPropertyByName( sTargetURL )) |
112 | 0 | { |
113 | 0 | beans::Property aProp = xPropInfoSet->getPropertyByName( sTargetURL ); |
114 | 0 | if( !aProp.Name.isEmpty() ) |
115 | 0 | { |
116 | 0 | uno::Any aTmp; |
117 | | // Yes! |
118 | 0 | OUString sLabel(u"Label"_ustr); |
119 | 0 | if( xPropInfoSet->hasPropertyByName(sLabel) ) |
120 | 0 | { |
121 | 0 | aTmp <<= rHLinkItem.GetName(); |
122 | 0 | xPropSet->setPropertyValue(sLabel, aTmp ); |
123 | 0 | } |
124 | |
|
125 | 0 | SfxMedium* pMedium = GetView().GetDocShell()->GetMedium(); |
126 | 0 | INetURLObject aAbs; |
127 | 0 | if( pMedium ) |
128 | 0 | aAbs = pMedium->GetURLObject(); |
129 | 0 | aTmp <<= URIHelper::SmartRel2Abs(aAbs, rHLinkItem.GetURL()); |
130 | 0 | xPropSet->setPropertyValue( sTargetURL, aTmp ); |
131 | |
|
132 | 0 | if( !rHLinkItem.GetTargetFrame().isEmpty() ) |
133 | 0 | { |
134 | 0 | aTmp <<= rHLinkItem.GetTargetFrame(); |
135 | 0 | xPropSet->setPropertyValue( u"TargetFrame"_ustr, aTmp ); |
136 | 0 | } |
137 | |
|
138 | 0 | aTmp <<= form::FormButtonType_URL; |
139 | 0 | xPropSet->setPropertyValue( u"ButtonType"_ustr, aTmp ); |
140 | 0 | } |
141 | 0 | } |
142 | 0 | } |
143 | 0 | } |
144 | 0 | } |
145 | 0 | } |
146 | 0 | } |
147 | 0 | break; |
148 | | |
149 | 0 | default: |
150 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
151 | 0 | return; |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | | void SwDrawFormShell::GetState(SfxItemSet& rSet) |
156 | 0 | { |
157 | 0 | SwWrtShell &rSh = GetShell(); |
158 | 0 | SfxWhichIter aIter( rSet ); |
159 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
160 | |
|
161 | 0 | while( nWhich ) |
162 | 0 | { |
163 | 0 | switch( nWhich ) |
164 | 0 | { |
165 | 0 | case SID_HYPERLINK_GETLINK: |
166 | 0 | { |
167 | 0 | SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList(); |
168 | 0 | const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); |
169 | 0 | SvxHyperlinkItem aHLinkItem; |
170 | 0 | if (rMarkList.GetMark(0)) |
171 | 0 | { |
172 | 0 | SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() ); |
173 | 0 | if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor()) |
174 | 0 | { |
175 | 0 | const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel(); |
176 | |
|
177 | 0 | OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" ); |
178 | 0 | if( !xControlModel.is() ) |
179 | 0 | return; |
180 | | |
181 | 0 | uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY); |
182 | |
|
183 | 0 | uno::Any aTmp; |
184 | 0 | uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo(); |
185 | 0 | if(xInfo->hasPropertyByName( u"ButtonType"_ustr )) |
186 | 0 | { |
187 | 0 | form::FormButtonType eButtonType = form::FormButtonType_URL; |
188 | 0 | aTmp = xPropSet->getPropertyValue( u"ButtonType"_ustr ); |
189 | 0 | if( aTmp >>= eButtonType ) |
190 | 0 | { |
191 | | // Label |
192 | 0 | if(xInfo->hasPropertyByName( u"Label"_ustr )) |
193 | 0 | { |
194 | 0 | aTmp = xPropSet->getPropertyValue( u"Label"_ustr ); |
195 | 0 | OUString sTmp; |
196 | 0 | if( (aTmp >>= sTmp) && !sTmp.isEmpty()) |
197 | 0 | { |
198 | 0 | aHLinkItem.SetName(sTmp); |
199 | 0 | } |
200 | 0 | } |
201 | | |
202 | | // URL |
203 | 0 | if(xInfo->hasPropertyByName( u"TargetURL"_ustr )) |
204 | 0 | { |
205 | 0 | aTmp = xPropSet->getPropertyValue( u"TargetURL"_ustr ); |
206 | 0 | OUString sTmp; |
207 | 0 | if( (aTmp >>= sTmp) && !sTmp.isEmpty()) |
208 | 0 | { |
209 | 0 | aHLinkItem.SetURL(sTmp); |
210 | 0 | } |
211 | 0 | } |
212 | | |
213 | | // Target |
214 | 0 | if(xInfo->hasPropertyByName( u"TargetFrame"_ustr )) |
215 | 0 | { |
216 | 0 | aTmp = xPropSet->getPropertyValue( u"TargetFrame"_ustr ); |
217 | 0 | OUString sTmp; |
218 | 0 | if( (aTmp >>= sTmp) && !sTmp.isEmpty()) |
219 | 0 | { |
220 | 0 | aHLinkItem.SetTargetFrame(sTmp); |
221 | 0 | } |
222 | 0 | } |
223 | 0 | aHLinkItem.SetInsertMode(HLINK_BUTTON); |
224 | 0 | } |
225 | 0 | } |
226 | 0 | } |
227 | 0 | } |
228 | 0 | sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell()); |
229 | 0 | aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() | |
230 | 0 | ((nHtmlMode & HTMLMODE_ON) != 0 ? HLINK_HTMLMODE : 0))); |
231 | |
|
232 | 0 | rSet.Put(aHLinkItem); |
233 | 0 | } |
234 | 0 | break; |
235 | 0 | } |
236 | 0 | nWhich = aIter.NextWhich(); |
237 | 0 | } |
238 | 0 | } |
239 | | |
240 | | SwDrawFormShell::SwDrawFormShell(SwView &_rView) : |
241 | 0 | SwDrawBaseShell(_rView) |
242 | 0 | { |
243 | 0 | GetShell().NoEdit(); |
244 | 0 | SetName(u"DrawForm"_ustr); |
245 | 0 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Form)); |
246 | 0 | } |
247 | | |
248 | | SwDrawFormShell::~SwDrawFormShell() |
249 | 0 | { |
250 | 0 | } |
251 | | |
252 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |