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