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_sc.hxx"
26
27
28
29 // INCLUDE ---------------------------------------------------------------
30
31 //#define SI_VCDRAWOBJ
32
33 #include <tools/urlobj.hxx>
34 #include <svx/fmglob.hxx>
35 #include <svx/svdouno.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/docfile.hxx>
39
40 #include <com/sun/star/form/FormButtonType.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/awt/XControlModel.hpp>
43
44 using namespace com::sun::star;
45
46 #include "tabvwsh.hxx"
47 #include "document.hxx"
48 #include "drawview.hxx"
49 #include "globstr.hrc"
50 #include <avmedia/mediawindow.hxx>
51
52 //------------------------------------------------------------------------
53
InsertURLButton(const String & rName,const String & rURL,const String & rTarget,const Point * pInsPos)54 void ScTabViewShell::InsertURLButton( const String& rName, const String& rURL,
55 const String& rTarget,
56 const Point* pInsPos )
57 {
58 // Tabelle geschuetzt ?
59
60 ScViewData* pViewData = GetViewData();
61 ScDocument* pDoc = pViewData->GetDocument();
62 SCTAB nTab = pViewData->GetTabNo();
63 if ( pDoc->IsTabProtected(nTab) )
64 {
65 ErrorMessage(STR_PROTECTIONERR);
66 return;
67 }
68
69 MakeDrawLayer();
70
71 ScTabView* pView = pViewData->GetView();
72 // SdrView* pDrView = pView->GetSdrView();
73 ScDrawView* pDrView = pView->GetScDrawView();
74 SdrModel* pModel = pDrView->GetModel();
75
76 SdrObject* pObj = SdrObjFactory::MakeNewObject(FmFormInventor, OBJ_FM_BUTTON,
77 pDrView->GetSdrPageView()->GetPage(), pModel);
78 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObj);
79
80 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
81 DBG_ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
82 if( !xControlModel.is() )
83 return;
84
85 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
86 uno::Any aAny;
87
88 aAny <<= rtl::OUString(rName);
89 xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "Label" ), aAny );
90
91 ::rtl::OUString aTmp = INetURLObject::GetAbsURL( pDoc->GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
92 aAny <<= aTmp;
93 xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "TargetURL" ), aAny );
94
95 if( rTarget.Len() )
96 {
97 aAny <<= rtl::OUString(rTarget);
98 xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "TargetFrame" ), aAny );
99 }
100
101 form::FormButtonType eButtonType = form::FormButtonType_URL;
102 aAny <<= eButtonType;
103 xPropSet->setPropertyValue( rtl::OUString::createFromAscii( "ButtonType" ), aAny );
104
105 if ( ::avmedia::MediaWindow::isMediaURL( rURL ) )
106 {
107 // #105638# OJ
108 aAny <<= sal_True;
109 xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DispatchURLInternal" )), aAny );
110 }
111
112 Point aPos;
113 if (pInsPos)
114 aPos = *pInsPos;
115 else
116 aPos = GetInsertPos();
117
118 // Groesse wie in 3.1:
119 Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
120
121 if ( pDoc->IsNegativePage(nTab) )
122 aPos.X() -= aSize.Width();
123
124 pObj->SetLogicRect(Rectangle(aPos, aSize));
125 // pObj->Resize(Point(), Fraction(1, 1), Fraction(1, 1));
126
127 // am alten VC-Button musste die Position/Groesse nochmal explizit
128 // gesetzt werden - das scheint mit UnoControls nicht noetig zu sein
129
130 // nicht markieren wenn Ole
131 pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() );
132 }
133
134
135
136
137