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