LibreOffice Module sc (master)  1
tabvwshg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <tools/urlobj.hxx>
23 #include <svx/fmglob.hxx>
24 #include <svx/svdouno.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <sfx2/docfile.hxx>
27 
28 #include <com/sun/star/form/FormButtonType.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/awt/XControlModel.hpp>
31 
32 using namespace com::sun::star;
33 
34 #include <tabvwsh.hxx>
35 #include <document.hxx>
36 #include <drawview.hxx>
37 #include <globstr.hrc>
38 #include <gridwin.hxx>
39 #include <avmedia/mediawindow.hxx>
40 
41 void ScTabViewShell::InsertURLButton( const OUString& rName, const OUString& rURL,
42  const OUString& rTarget,
43  const Point* pInsPos )
44 {
45  // protected sheet ?
46 
47  ScViewData& rViewData = GetViewData();
48  ScDocument& rDoc = rViewData.GetDocument();
49  SCTAB nTab = rViewData.GetTabNo();
50  if ( rDoc.IsTabProtected(nTab) )
51  {
52  ErrorMessage(STR_PROTECTIONERR);
53  return;
54  }
55 
56  MakeDrawLayer();
57 
58  ScTabView* pView = rViewData.GetView();
59  ScDrawView* pDrView = pView->GetScDrawView();
60  SdrModel* pModel = pDrView->GetModel();
61 
63  *pModel,
64  SdrInventor::FmForm,
66 
67  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObj );
68  OSL_ENSURE( pUnoCtrl, "no SdrUnoObj");
69  if( !pUnoCtrl )
70  return;
71 
72  uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
73  OSL_ENSURE( xControlModel.is(), "UNO control without model" );
74  if( !xControlModel.is() )
75  return;
76 
77  uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
78 
79  xPropSet->setPropertyValue("Label", uno::Any(rName) );
80 
81  OUString aTmp = INetURLObject::GetAbsURL( rDoc.GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
82  xPropSet->setPropertyValue("TargetURL", uno::Any(aTmp) );
83 
84  if( !rTarget.isEmpty() )
85  {
86  xPropSet->setPropertyValue("TargetFrame", uno::Any(rTarget) );
87  }
88 
89  xPropSet->setPropertyValue("ButtonType", uno::Any(form::FormButtonType_URL) );
90 
91 #if HAVE_FEATURE_AVMEDIA
92  if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
93  {
94  xPropSet->setPropertyValue("DispatchURLInternal", uno::Any(true) );
95  }
96 #endif
97 
98  Point aPos;
99  if (pInsPos)
100  aPos = *pInsPos;
101  else
102  aPos = GetInsertPos();
103 
104  // Size as in 3.1:
105  Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
106 
107  if ( rDoc.IsNegativePage(nTab) )
108  aPos.AdjustX( -(aSize.Width()) );
109 
110  pObj->SetLogicRect(tools::Rectangle(aPos, aSize));
111 
112  // for the old VC-Button the position/size had to be set explicitly once more
113  // that seems not to be needed with UnoControls
114 
115  // do not mark when Ole
116  pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() );
117 }
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1890
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1002
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
static OUString GetAbsURL(OUString const &rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
tools::Long Width() const
OUString GetBaseURL(bool bForSaving=false)
virtual void SetLogicRect(const tools::Rectangle &rRect)
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
bool InsertObjectSafe(SdrObject *pObj, SdrPageView &rPV)
Definition: drawview.cxx:802
ScDrawView * GetScDrawView()
Definition: tabview.hxx:340
SdrPageView * GetSdrPageView() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1058
void InsertURLButton(const OUString &rName, const OUString &rURL, const OUString &rTarget, const Point *pInsPos)
Definition: tabvwshg.cxx:41
SdrModel * GetModel() const
const sal_uInt16 OBJ_FM_BUTTON
sal_Int16 SCTAB
Definition: types.hxx:23
SfxMedium * GetMedium() const