lok: calc: fix needed when position caching is disabled
[LibreOffice.git] / sc / source / ui / view / tabvwshg.cxx
blob538ac000aed47a77818852ca3cd8e2419cb589bb
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 <config_features.h>
22 #include <tools/urlobj.hxx>
23 #include <svx/fmglob.hxx>
24 #include <svx/svdouno.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <sfx2/docfile.hxx>
29 #include <com/sun/star/form/FormButtonType.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/awt/XControlModel.hpp>
33 using namespace com::sun::star;
35 #include <tabvwsh.hxx>
36 #include <document.hxx>
37 #include <drawview.hxx>
38 #include <globstr.hrc>
39 #include <gridwin.hxx>
40 #include <avmedia/mediawindow.hxx>
42 void ScTabViewShell::InsertURLButton( const OUString& rName, const OUString& rURL,
43 const OUString& rTarget,
44 const Point* pInsPos )
46 // protected sheet ?
48 ScViewData& rViewData = GetViewData();
49 ScDocument* pDoc = rViewData.GetDocument();
50 SCTAB nTab = rViewData.GetTabNo();
51 if ( pDoc->IsTabProtected(nTab) )
53 ErrorMessage(STR_PROTECTIONERR);
54 return;
57 MakeDrawLayer();
59 ScTabView* pView = rViewData.GetView();
60 ScDrawView* pDrView = pView->GetScDrawView();
61 SdrModel* pModel = pDrView->GetModel();
63 SdrObject* pObj = SdrObjFactory::MakeNewObject(SdrInventor::FmForm, OBJ_FM_BUTTON,
64 pDrView->GetSdrPageView()->GetPage(), pModel);
65 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObj );
66 OSL_ENSURE( pUnoCtrl, "no SdrUnoObj");
67 if( !pUnoCtrl )
68 return;
70 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
71 OSL_ENSURE( xControlModel.is(), "UNO control without model" );
72 if( !xControlModel.is() )
73 return;
75 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
77 xPropSet->setPropertyValue("Label", uno::Any(rName) );
79 OUString aTmp = INetURLObject::GetAbsURL( pDoc->GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
80 xPropSet->setPropertyValue("TargetURL", uno::Any(aTmp) );
82 if( !rTarget.isEmpty() )
84 xPropSet->setPropertyValue("TargetFrame", uno::Any(rTarget) );
87 xPropSet->setPropertyValue("ButtonType", uno::Any(form::FormButtonType_URL) );
89 #if HAVE_FEATURE_AVMEDIA
90 if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
92 xPropSet->setPropertyValue("DispatchURLInternal", uno::Any(true) );
94 #endif
96 Point aPos;
97 if (pInsPos)
98 aPos = *pInsPos;
99 else
100 aPos = GetInsertPos();
102 // Size as in 3.1:
103 Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
105 if ( pDoc->IsNegativePage(nTab) )
106 aPos.X() -= aSize.Width();
108 pObj->SetLogicRect(tools::Rectangle(aPos, aSize));
110 // for the old VC-Button the position/size had to be set explicitly once more
111 // that seems not to be needed with UnoControls
113 // do not mark when Ole
114 pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() );
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */