update dev300-m58
[ooovba.git] / sw / source / ui / shells / textdrw.cxx
blob8031028cad1b08ba688278f003fdc9e831c76ee4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textdrw.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <svx/svdview.hxx>
36 #include <tools/urlobj.hxx>
37 #include <svx/fmglob.hxx>
38 #include <svx/svdouno.hxx>
39 #include <com/sun/star/form/FormButtonType.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
42 #ifndef _VIEW_HXX
43 #include <view.hxx>
44 #endif
45 #include <wrtsh.hxx>
46 #include <edtwin.hxx>
47 #include <swundo.hxx>
48 #ifndef _BASESH_HXX
49 #include <basesh.hxx>
50 #endif
52 #ifndef _POOLFMT_HRC
53 #include <poolfmt.hrc>
54 #endif
56 #ifndef _DOCSH_HXX
57 #include <docsh.hxx>
58 #endif
59 #include <sfx2/docfile.hxx>
60 #include <svtools/urihelper.hxx>
61 #include <avmedia/mediawindow.hxx>
63 #include <unomid.h>
66 using namespace ::com::sun::star;
67 using ::rtl::OUString;
68 /*---------------------------------------------------------------------------
69 Beschreibung:
70 ----------------------------------------------------------------------------*/
72 void SwBaseShell::InsertURLButton(const String& rURL, const String& rTarget, const String& rTxt)
74 SwWrtShell& rSh = GetShell();
76 if (!rSh.HasDrawView())
77 rSh.MakeDrawView();
78 SdrView *pSdrView = rSh.GetDrawView();
80 // OBJ_FM_BUTTON
81 pSdrView->SetDesignMode(TRUE);
82 pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
83 pSdrView->SetEditMode(sal_False);
85 Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
87 rSh.StartAction();
88 rSh.StartUndo( UNDO_UI_INSERT_URLBTN );
89 if (rSh.BeginCreate(OBJ_FM_BUTTON, FmFormInventor, aStartPos))
91 pSdrView->SetOrtho(sal_False);
92 Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
93 Point aEndPos(aSz.Width(), aSz.Height());
95 rSh.MoveCreate(aStartPos + aEndPos);
96 rSh.EndCreate(SDRCREATE_FORCEEND);
98 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
99 if (rMarkList.GetMark(0))
101 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
102 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
104 ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
105 if( !xControlModel.is() )
106 return;
108 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
111 uno::Any aTmp;
113 aTmp <<= OUString(rTxt);
114 xPropSet->setPropertyValue( C2U("Label"), aTmp );
116 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
117 INetURLObject aAbs;
118 if( pMedium )
119 aAbs = pMedium->GetURLObject();
121 aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rURL));
122 xPropSet->setPropertyValue( C2U("TargetURL"), aTmp );
124 if( rTarget.Len() )
126 aTmp <<= OUString(rTarget);
127 xPropSet->setPropertyValue( C2U("TargetFrame"), aTmp );
131 form::FormButtonType eButtonType = form::FormButtonType_URL;
132 aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
133 xPropSet->setPropertyValue( C2U("ButtonType"), aTmp );
135 if ( ::avmedia::MediaWindow::isMediaURL( rURL ) )
137 // #105638# OJ
138 aTmp <<= sal_True;
139 xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aTmp );
143 if (rSh.IsObjSelected())
145 // rSh.ChgAnchor(FLY_AT_CNTNT);
146 rSh.UnSelectFrm();
149 rSh.EndUndo( UNDO_UI_INSERT_URLBTN );
150 rSh.EndAction();