1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir //#define SI_VCDRAWOBJ
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <tools/urlobj.hxx>
34cdf0e10cSrcweir #include <svx/fmglob.hxx>
35cdf0e10cSrcweir #include <svx/svdouno.hxx>
36cdf0e10cSrcweir #include <svx/svdpagv.hxx>
37cdf0e10cSrcweir #include <sfx2/objsh.hxx>
38cdf0e10cSrcweir #include <sfx2/docfile.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp>
41cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace com::sun::star;
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include "tabvwsh.hxx"
47cdf0e10cSrcweir #include "document.hxx"
48cdf0e10cSrcweir #include "drawview.hxx"
49cdf0e10cSrcweir #include "globstr.hrc"
50cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
51cdf0e10cSrcweir
52cdf0e10cSrcweir //------------------------------------------------------------------------
53cdf0e10cSrcweir
InsertURLButton(const String & rName,const String & rURL,const String & rTarget,const Point * pInsPos)54cdf0e10cSrcweir void ScTabViewShell::InsertURLButton( const String& rName, const String& rURL,
55cdf0e10cSrcweir const String& rTarget,
56cdf0e10cSrcweir const Point* pInsPos )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir // Tabelle geschuetzt ?
59cdf0e10cSrcweir
60cdf0e10cSrcweir ScViewData* pViewData = GetViewData();
61cdf0e10cSrcweir ScDocument* pDoc = pViewData->GetDocument();
62cdf0e10cSrcweir SCTAB nTab = pViewData->GetTabNo();
63cdf0e10cSrcweir if ( pDoc->IsTabProtected(nTab) )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir ErrorMessage(STR_PROTECTIONERR);
66cdf0e10cSrcweir return;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir MakeDrawLayer();
70cdf0e10cSrcweir
71cdf0e10cSrcweir ScTabView* pView = pViewData->GetView();
72cdf0e10cSrcweir // SdrView* pDrView = pView->GetSdrView();
73cdf0e10cSrcweir ScDrawView* pDrView = pView->GetScDrawView();
74cdf0e10cSrcweir SdrModel* pModel = pDrView->GetModel();
75cdf0e10cSrcweir
76cdf0e10cSrcweir SdrObject* pObj = SdrObjFactory::MakeNewObject(FmFormInventor, OBJ_FM_BUTTON,
77cdf0e10cSrcweir pDrView->GetSdrPageView()->GetPage(), pModel);
78cdf0e10cSrcweir SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObj);
79cdf0e10cSrcweir
80cdf0e10cSrcweir uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
81cdf0e10cSrcweir DBG_ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
82cdf0e10cSrcweir if( !xControlModel.is() )
83cdf0e10cSrcweir return;
84cdf0e10cSrcweir
85cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
86cdf0e10cSrcweir uno::Any aAny;
87cdf0e10cSrcweir
88cdf0e10cSrcweir aAny <<= rtl::OUString(rName);
89cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "Label" ), aAny );
90cdf0e10cSrcweir
91cdf0e10cSrcweir ::rtl::OUString aTmp = INetURLObject::GetAbsURL( pDoc->GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
92cdf0e10cSrcweir aAny <<= aTmp;
93cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "TargetURL" ), aAny );
94cdf0e10cSrcweir
95cdf0e10cSrcweir if( rTarget.Len() )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir aAny <<= rtl::OUString(rTarget);
98cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "TargetFrame" ), aAny );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir form::FormButtonType eButtonType = form::FormButtonType_URL;
102cdf0e10cSrcweir aAny <<= eButtonType;
103cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "ButtonType" ), aAny );
104cdf0e10cSrcweir
105cdf0e10cSrcweir if ( ::avmedia::MediaWindow::isMediaURL( rURL ) )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir // #105638# OJ
108cdf0e10cSrcweir aAny <<= sal_True;
109cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aAny );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112cdf0e10cSrcweir Point aPos;
113cdf0e10cSrcweir if (pInsPos)
114cdf0e10cSrcweir aPos = *pInsPos;
115cdf0e10cSrcweir else
116cdf0e10cSrcweir aPos = GetInsertPos();
117cdf0e10cSrcweir
118cdf0e10cSrcweir // Groesse wie in 3.1:
119cdf0e10cSrcweir Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
120cdf0e10cSrcweir
121cdf0e10cSrcweir if ( pDoc->IsNegativePage(nTab) )
122cdf0e10cSrcweir aPos.X() -= aSize.Width();
123cdf0e10cSrcweir
124cdf0e10cSrcweir pObj->SetLogicRect(Rectangle(aPos, aSize));
125cdf0e10cSrcweir // pObj->Resize(Point(), Fraction(1, 1), Fraction(1, 1));
126cdf0e10cSrcweir
127cdf0e10cSrcweir // am alten VC-Button musste die Position/Groesse nochmal explizit
128cdf0e10cSrcweir // gesetzt werden - das scheint mit UnoControls nicht noetig zu sein
129cdf0e10cSrcweir
130cdf0e10cSrcweir // nicht markieren wenn Ole
131cdf0e10cSrcweir pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir
136cdf0e10cSrcweir
137