xref: /aoo41x/main/sw/source/ui/shells/textdrw.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <svx/svdview.hxx>
29 #include <tools/urlobj.hxx>
30 #include <svx/fmglob.hxx>
31 #include <svx/svdouno.hxx>
32 #include <com/sun/star/form/FormButtonType.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 
35 #include <view.hxx>
36 #include <wrtsh.hxx>
37 #include <edtwin.hxx>
38 #include <swundo.hxx>
39 #include <basesh.hxx>
40 
41 #ifndef _POOLFMT_HRC
42 #include <poolfmt.hrc>
43 #endif
44 
45 #include <docsh.hxx>
46 #include <sfx2/docfile.hxx>
47 #include <svl/urihelper.hxx>
48 #include <avmedia/mediawindow.hxx>
49 
50 #include <unomid.h>
51 
52 
53 using namespace ::com::sun::star;
54 using ::rtl::OUString;
55 /*---------------------------------------------------------------------------
56 	Beschreibung:
57  ----------------------------------------------------------------------------*/
58 
InsertURLButton(const String & rURL,const String & rTarget,const String & rTxt)59 void SwBaseShell::InsertURLButton(const String& rURL, const String& rTarget, const String& rTxt)
60 {
61 	SwWrtShell& rSh = GetShell();
62 
63 	if (!rSh.HasDrawView())
64 		rSh.MakeDrawView();
65 	SdrView *pSdrView = rSh.GetDrawView();
66 
67 	// OBJ_FM_BUTTON
68     pSdrView->SetDesignMode(sal_True);
69 	pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
70 	pSdrView->SetEditMode(sal_False);
71 
72 	Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
73 
74 	rSh.StartAction();
75     rSh.StartUndo( UNDO_UI_INSERT_URLBTN );
76 	if (rSh.BeginCreate(OBJ_FM_BUTTON, FmFormInventor, aStartPos))
77 	{
78 		pSdrView->SetOrtho(sal_False);
79 	 	Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
80 		Point aEndPos(aSz.Width(), aSz.Height());
81 
82 		rSh.MoveCreate(aStartPos + aEndPos);
83 		rSh.EndCreate(SDRCREATE_FORCEEND);
84 
85 		const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
86 		if (rMarkList.GetMark(0))
87 		{
88 			SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
89 			uno::Reference< awt::XControlModel >  xControlModel = pUnoCtrl->GetUnoControlModel();
90 
91 			ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
92 			if( !xControlModel.is() )
93 				return;
94 
95 			uno::Reference< beans::XPropertySet >  xPropSet(xControlModel, uno::UNO_QUERY);
96 
97 
98 			uno::Any aTmp;
99 
100 			aTmp <<= OUString(rTxt);
101 			xPropSet->setPropertyValue( C2U("Label"), aTmp );
102 
103             SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
104             INetURLObject aAbs;
105             if( pMedium )
106                 aAbs = pMedium->GetURLObject();
107 
108             aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rURL));
109 			xPropSet->setPropertyValue( C2U("TargetURL"), aTmp );
110 
111 			if( rTarget.Len() )
112 			{
113 				aTmp <<= OUString(rTarget);
114 				xPropSet->setPropertyValue( C2U("TargetFrame"), aTmp );
115 			}
116 
117 
118 			form::FormButtonType eButtonType = form::FormButtonType_URL;
119 			aTmp.setValue( &eButtonType, ::getCppuType((const form::FormButtonType*)0));
120 			xPropSet->setPropertyValue( C2U("ButtonType"), aTmp );
121 
122 			if ( ::avmedia::MediaWindow::isMediaURL( rURL ) )
123 			{
124 				// #105638# OJ
125 				aTmp <<= sal_True;
126 				xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aTmp );
127 			}
128 		}
129 
130 		if (rSh.IsObjSelected())
131 		{
132 			rSh.UnSelectFrm();
133 		}
134 	}
135     rSh.EndUndo( UNDO_UI_INSERT_URLBTN );
136 	rSh.EndAction();
137 }
138 
139 
140