1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <gridwin.hxx>
38 #include <avmedia/mediawindow.hxx>
40 void ScTabViewShell::InsertURLButton( const OUString
& rName
, const OUString
& rURL
,
41 const OUString
& rTarget
,
42 const Point
* pInsPos
)
44 // Tabelle geschuetzt ?
46 ScViewData
& rViewData
= GetViewData();
47 ScDocument
* pDoc
= rViewData
.GetDocument();
48 SCTAB nTab
= rViewData
.GetTabNo();
49 if ( pDoc
->IsTabProtected(nTab
) )
51 ErrorMessage(STR_PROTECTIONERR
);
57 ScTabView
* pView
= rViewData
.GetView();
58 ScDrawView
* pDrView
= pView
->GetScDrawView();
59 SdrModel
* pModel
= pDrView
->GetModel();
61 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(FmFormInventor
, OBJ_FM_BUTTON
,
62 pDrView
->GetSdrPageView()->GetPage(), pModel
);
63 SdrUnoObj
* pUnoCtrl
= PTR_CAST(SdrUnoObj
, pObj
);
64 OSL_ENSURE( pUnoCtrl
, "no SdrUnoObj");
68 uno::Reference
<awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
69 OSL_ENSURE( xControlModel
.is(), "UNO-Control ohne Model" );
70 if( !xControlModel
.is() )
73 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
76 aAny
<<= OUString(rName
);
77 xPropSet
->setPropertyValue("Label", aAny
);
79 OUString aTmp
= INetURLObject::GetAbsURL( pDoc
->GetDocumentShell()->GetMedium()->GetBaseURL(), rURL
);
81 xPropSet
->setPropertyValue("TargetURL", aAny
);
83 if( !rTarget
.isEmpty() )
86 xPropSet
->setPropertyValue("TargetFrame", aAny
);
89 form::FormButtonType eButtonType
= form::FormButtonType_URL
;
91 xPropSet
->setPropertyValue("ButtonType", aAny
);
93 if ( ::avmedia::MediaWindow::isMediaURL( rURL
, ""/*TODO?*/ ) )
96 xPropSet
->setPropertyValue("DispatchURLInternal", aAny
);
103 aPos
= GetInsertPos();
105 // Groesse wie in 3.1:
106 Size aSize
= GetActiveWin()->PixelToLogic(Size(140, 20));
108 if ( pDoc
->IsNegativePage(nTab
) )
109 aPos
.X() -= aSize
.Width();
111 pObj
->SetLogicRect(Rectangle(aPos
, aSize
));
113 // am alten VC-Button musste die Position/Groesse nochmal explizit
114 // gesetzt werden - das scheint mit UnoControls nicht noetig zu sein
116 // nicht markieren wenn Ole
117 pDrView
->InsertObjectSafe( pObj
, *pDrView
->GetSdrPageView() );
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */