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 #include <svx/svdview.hxx> 33 #include <tools/urlobj.hxx> 34 #include <svx/fmglob.hxx> 35 #include <svx/svdouno.hxx> 36 #include <com/sun/star/form/FormButtonType.hpp> 37 #include <com/sun/star/beans/XPropertySet.hpp> 38 39 #include <view.hxx> 40 #include <wrtsh.hxx> 41 #include <edtwin.hxx> 42 #include <swundo.hxx> 43 #include <basesh.hxx> 44 45 #ifndef _POOLFMT_HRC 46 #include <poolfmt.hrc> 47 #endif 48 49 #include <docsh.hxx> 50 #include <sfx2/docfile.hxx> 51 #include <svl/urihelper.hxx> 52 #include <avmedia/mediawindow.hxx> 53 54 #include <unomid.h> 55 56 57 using namespace ::com::sun::star; 58 using ::rtl::OUString; 59 /*--------------------------------------------------------------------------- 60 Beschreibung: 61 ----------------------------------------------------------------------------*/ 62 63 void SwBaseShell::InsertURLButton(const String& rURL, const String& rTarget, const String& rTxt) 64 { 65 SwWrtShell& rSh = GetShell(); 66 67 if (!rSh.HasDrawView()) 68 rSh.MakeDrawView(); 69 SdrView *pSdrView = rSh.GetDrawView(); 70 71 // OBJ_FM_BUTTON 72 pSdrView->SetDesignMode(sal_True); 73 pSdrView->SetCurrentObj(OBJ_FM_BUTTON); 74 pSdrView->SetEditMode(sal_False); 75 76 Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1)); 77 78 rSh.StartAction(); 79 rSh.StartUndo( UNDO_UI_INSERT_URLBTN ); 80 if (rSh.BeginCreate(OBJ_FM_BUTTON, FmFormInventor, aStartPos)) 81 { 82 pSdrView->SetOrtho(sal_False); 83 Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20))); 84 Point aEndPos(aSz.Width(), aSz.Height()); 85 86 rSh.MoveCreate(aStartPos + aEndPos); 87 rSh.EndCreate(SDRCREATE_FORCEEND); 88 89 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); 90 if (rMarkList.GetMark(0)) 91 { 92 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj()); 93 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel(); 94 95 ASSERT( xControlModel.is(), "UNO-Control ohne Model" ); 96 if( !xControlModel.is() ) 97 return; 98 99 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY); 100 101 102 uno::Any aTmp; 103 104 aTmp <<= OUString(rTxt); 105 xPropSet->setPropertyValue( C2U("Label"), aTmp ); 106 107 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium(); 108 INetURLObject aAbs; 109 if( pMedium ) 110 aAbs = pMedium->GetURLObject(); 111 112 aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rURL)); 113 xPropSet->setPropertyValue( C2U("TargetURL"), aTmp ); 114 115 if( rTarget.Len() ) 116 { 117 aTmp <<= OUString(rTarget); 118 xPropSet->setPropertyValue( C2U("TargetFrame"), aTmp ); 119 } 120 121 122 form::FormButtonType eButtonType = form::FormButtonType_URL; 123 aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0)); 124 xPropSet->setPropertyValue( C2U("ButtonType"), aTmp ); 125 126 if ( ::avmedia::MediaWindow::isMediaURL( rURL ) ) 127 { 128 // #105638# OJ 129 aTmp <<= sal_True; 130 xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aTmp ); 131 } 132 } 133 134 if (rSh.IsObjSelected()) 135 { 136 rSh.UnSelectFrm(); 137 } 138 } 139 rSh.EndUndo( UNDO_UI_INSERT_URLBTN ); 140 rSh.EndAction(); 141 } 142 143 144