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