Line data Source code
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 <svx/svdview.hxx>
23 : #include <tools/urlobj.hxx>
24 : #include <svx/fmglob.hxx>
25 : #include <svx/svdouno.hxx>
26 : #include <com/sun/star/form/FormButtonType.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 :
29 : #include <view.hxx>
30 : #include <wrtsh.hxx>
31 : #include <edtwin.hxx>
32 : #include <swundo.hxx>
33 : #include <basesh.hxx>
34 :
35 : #include <poolfmt.hrc>
36 :
37 : #include <docsh.hxx>
38 : #include <sfx2/docfile.hxx>
39 : #include <svl/urihelper.hxx>
40 : #include <avmedia/mediawindow.hxx>
41 :
42 : #include <unomid.h>
43 :
44 : using namespace ::com::sun::star;
45 :
46 0 : void SwBaseShell::InsertURLButton(const OUString& rURL, const OUString& rTarget, const OUString& rText)
47 : {
48 0 : SwWrtShell& rSh = GetShell();
49 :
50 0 : if (!rSh.HasDrawView())
51 0 : rSh.MakeDrawView();
52 0 : SdrView *pSdrView = rSh.GetDrawView();
53 :
54 : // OBJ_FM_BUTTON
55 0 : pSdrView->SetDesignMode(true);
56 0 : pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
57 0 : pSdrView->SetEditMode(false);
58 :
59 0 : Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
60 :
61 0 : rSh.StartAction();
62 0 : rSh.StartUndo( UNDO_UI_INSERT_URLBTN );
63 0 : if (rSh.BeginCreate(OBJ_FM_BUTTON, FmFormInventor, aStartPos))
64 : {
65 0 : pSdrView->SetOrtho(false);
66 0 : Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
67 0 : Point aEndPos(aSz.Width(), aSz.Height());
68 :
69 0 : rSh.MoveCreate(aStartPos + aEndPos);
70 0 : rSh.EndCreate(SDRCREATE_FORCEEND);
71 :
72 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
73 0 : if (rMarkList.GetMark(0))
74 : {
75 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
76 : OSL_ENSURE( pUnoCtrl, "not an SdrUnoObj" );
77 0 : if (!pUnoCtrl)
78 0 : return;
79 :
80 0 : uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
81 :
82 : OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
83 0 : if (!xControlModel.is())
84 0 : return;
85 :
86 0 : uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
87 :
88 0 : uno::Any aTmp;
89 :
90 0 : aTmp <<= OUString(rText);
91 0 : xPropSet->setPropertyValue( "Label", aTmp );
92 :
93 0 : SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
94 0 : INetURLObject aAbs;
95 0 : if( pMedium )
96 0 : aAbs = pMedium->GetURLObject();
97 :
98 0 : aTmp <<= OUString(URIHelper::SmartRel2Abs(aAbs, rURL));
99 0 : xPropSet->setPropertyValue( "TargetURL", aTmp );
100 :
101 0 : if( !rTarget.isEmpty() )
102 : {
103 0 : aTmp <<= rTarget;
104 0 : xPropSet->setPropertyValue( "TargetFrame", aTmp );
105 : }
106 :
107 0 : form::FormButtonType eButtonType = form::FormButtonType_URL;
108 0 : aTmp.setValue( &eButtonType, ::cppu::UnoType<form::FormButtonType>::get());
109 0 : xPropSet->setPropertyValue( "ButtonType", aTmp );
110 :
111 : #if HAVE_FEATURE_AVMEDIA
112 0 : if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
113 : {
114 : // #105638# OJ
115 0 : aTmp <<= sal_True;
116 0 : xPropSet->setPropertyValue("DispatchURLInternal", aTmp );
117 0 : }
118 : #endif
119 : }
120 :
121 0 : if (rSh.IsObjSelected())
122 : {
123 0 : rSh.UnSelectFrm();
124 : }
125 : }
126 0 : rSh.EndUndo( UNDO_UI_INSERT_URLBTN );
127 0 : rSh.EndAction();
128 177 : }
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|