Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / tabvwshg.cxx
blob4fafbe90f0112cf49bbe883a7534b0a703adf02c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/urlobj.hxx>
21 #include <svx/fmglob.hxx>
22 #include <svx/svdouno.hxx>
23 #include <svx/svdpagv.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/docfile.hxx>
27 #include <com/sun/star/form/FormButtonType.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/awt/XControlModel.hpp>
31 using namespace com::sun::star;
33 #include "tabvwsh.hxx"
34 #include "document.hxx"
35 #include "drawview.hxx"
36 #include "globstr.hrc"
37 #include <avmedia/mediawindow.hxx>
39 //------------------------------------------------------------------------
41 void ScTabViewShell::InsertURLButton( const String& rName, const String& rURL,
42 const String& rTarget,
43 const Point* pInsPos )
45 // Tabelle geschuetzt ?
47 ScViewData* pViewData = GetViewData();
48 ScDocument* pDoc = pViewData->GetDocument();
49 SCTAB nTab = pViewData->GetTabNo();
50 if ( pDoc->IsTabProtected(nTab) )
52 ErrorMessage(STR_PROTECTIONERR);
53 return;
56 MakeDrawLayer();
58 ScTabView* pView = pViewData->GetView();
59 ScDrawView* pDrView = pView->GetScDrawView();
60 SdrModel* pModel = pDrView->GetModel();
62 SdrObject* pObj = SdrObjFactory::MakeNewObject(FmFormInventor, OBJ_FM_BUTTON,
63 pDrView->GetSdrPageView()->GetPage(), pModel);
64 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObj);
66 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
67 OSL_ENSURE( xControlModel.is(), "UNO-Control ohne Model" );
68 if( !xControlModel.is() )
69 return;
71 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
72 uno::Any aAny;
74 aAny <<= rtl::OUString(rName);
75 xPropSet->setPropertyValue( rtl::OUString( "Label" ), aAny );
77 ::rtl::OUString aTmp = INetURLObject::GetAbsURL( pDoc->GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
78 aAny <<= aTmp;
79 xPropSet->setPropertyValue( rtl::OUString( "TargetURL" ), aAny );
81 if( rTarget.Len() )
83 aAny <<= rtl::OUString(rTarget);
84 xPropSet->setPropertyValue( rtl::OUString( "TargetFrame" ), aAny );
87 form::FormButtonType eButtonType = form::FormButtonType_URL;
88 aAny <<= eButtonType;
89 xPropSet->setPropertyValue( rtl::OUString( "ButtonType" ), aAny );
91 if ( ::avmedia::MediaWindow::isMediaURL( rURL ) )
93 aAny <<= sal_True;
94 xPropSet->setPropertyValue( rtl::OUString( "DispatchURLInternal" ), aAny );
97 Point aPos;
98 if (pInsPos)
99 aPos = *pInsPos;
100 else
101 aPos = GetInsertPos();
103 // Groesse wie in 3.1:
104 Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
106 if ( pDoc->IsNegativePage(nTab) )
107 aPos.X() -= aSize.Width();
109 pObj->SetLogicRect(Rectangle(aPos, aSize));
111 // am alten VC-Button musste die Position/Groesse nochmal explizit
112 // gesetzt werden - das scheint mit UnoControls nicht noetig zu sein
114 // nicht markieren wenn Ole
115 pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() );
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */