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