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