1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textdrw.cxx,v $
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>
53 #include <poolfmt.hrc>
59 #include <sfx2/docfile.hxx>
60 #include <svtools/urihelper.hxx>
61 #include <avmedia/mediawindow.hxx>
66 using namespace ::com::sun::star
;
67 using ::rtl::OUString
;
68 /*---------------------------------------------------------------------------
70 ----------------------------------------------------------------------------*/
72 void SwBaseShell::InsertURLButton(const String
& rURL
, const String
& rTarget
, const String
& rTxt
)
74 SwWrtShell
& rSh
= GetShell();
76 if (!rSh
.HasDrawView())
78 SdrView
*pSdrView
= rSh
.GetDrawView();
81 pSdrView
->SetDesignMode(TRUE
);
82 pSdrView
->SetCurrentObj(OBJ_FM_BUTTON
);
83 pSdrView
->SetEditMode(sal_False
);
85 Point
aStartPos(rSh
.GetCharRect().Pos() + Point(0, 1));
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() )
108 uno::Reference
< beans::XPropertySet
> xPropSet(xControlModel
, uno::UNO_QUERY
);
113 aTmp
<<= OUString(rTxt
);
114 xPropSet
->setPropertyValue( C2U("Label"), aTmp
);
116 SfxMedium
* pMedium
= rSh
.GetView().GetDocShell()->GetMedium();
119 aAbs
= pMedium
->GetURLObject();
121 aTmp
<<= OUString(URIHelper::SmartRel2Abs(aAbs
, rURL
));
122 xPropSet
->setPropertyValue( C2U("TargetURL"), aTmp
);
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
) )
139 xPropSet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aTmp
);
143 if (rSh
.IsObjSelected())
145 // rSh.ChgAnchor(FLY_AT_CNTNT);
149 rSh
.EndUndo( UNDO_UI_INSERT_URLBTN
);