LibreOffice Module sw (master)  1
textdrw.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 <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 {
45  SwWrtShell& rSh = GetShell();
46 
47  if (!rSh.HasDrawView())
48  rSh.MakeDrawView();
49  SdrView *pSdrView = rSh.GetDrawView();
50 
51  // OBJ_FM_BUTTON
52  pSdrView->SetDesignMode();
53  pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
54  pSdrView->SetEditMode(false);
55 
56  Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
57 
58  rSh.StartAction();
60  if (rSh.BeginCreate(OBJ_FM_BUTTON, SdrInventor::FmForm, aStartPos))
61  {
62  pSdrView->SetOrtho(false);
63  Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
64  Point aEndPos(aSz.Width(), aSz.Height());
65 
66  rSh.MoveCreate(aStartPos + aEndPos);
67  rSh.EndCreate(SdrCreateCmd::ForceEnd);
68 
69  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
70  if (rMarkList.GetMark(0))
71  {
72  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
73  OSL_ENSURE( pUnoCtrl, "not an SdrUnoObj" );
74  if (!pUnoCtrl)
75  return;
76 
77  uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
78 
79  OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
80  if (!xControlModel.is())
81  return;
82 
83  uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
84 
85  uno::Any aTmp;
86 
87  aTmp <<= rText;
88  xPropSet->setPropertyValue( "Label", aTmp );
89 
90  SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
91  INetURLObject aAbs;
92  if( pMedium )
93  aAbs = pMedium->GetURLObject();
94 
95  aTmp <<= URIHelper::SmartRel2Abs(aAbs, rURL);
96  xPropSet->setPropertyValue( "TargetURL", aTmp );
97 
98  if( !rTarget.isEmpty() )
99  {
100  aTmp <<= rTarget;
101  xPropSet->setPropertyValue( "TargetFrame", aTmp );
102  }
103 
104  aTmp <<= form::FormButtonType_URL;
105  xPropSet->setPropertyValue( "ButtonType", aTmp );
106 
107 #if HAVE_FEATURE_AVMEDIA
108  if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
109  {
110  // #105638# OJ
111  aTmp <<= true;
112  xPropSet->setPropertyValue("DispatchURLInternal", aTmp );
113  }
114 #endif
115  }
116 
117  if (rSh.IsObjSelected())
118  {
119  rSh.UnSelectFrame();
120  }
121  }
123  rSh.EndAction();
124 }
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwView & GetView()
Definition: basesh.hxx:59
SdrView * GetDrawView()
Definition: vnew.cxx:376
void SetDesignMode(bool bOn=true)
OBJ_FM_BUTTON
SwWrtShell & GetShell()
Definition: basesh.cxx:2760
bool HasDrawView() const
Definition: vnew.cxx:361
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
SdrMark * GetMark(size_t nNum) const
void Pos(const Point &rNew)
Definition: swrect.hxx:169
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
constexpr tools::Long Width() const
const SwView & GetView() const
Definition: wrtsh.hxx:431
void InsertURLButton(const OUString &rURL, const OUString &rTarget, const OUString &rText)
Definition: textdrw.cxx:43
void SetEditMode(SdrViewEditMode eMode)
bool BeginCreate(SdrObjKind eSdrObjectKind, const Point &rPos)
Process of creating draw objects.
Definition: feshview.cxx:1770
SdrObject * GetMarkedSdrObj() const
const SdrMarkList & GetMarkedObjectList() const
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
SwDocShell * GetDocShell()
Definition: view.cxx:1122
void StartAction()
Definition: crsrsh.cxx:226
void MoveCreate(const Point &rPos)
Definition: feshview.cxx:1812
void MakeDrawView()
Definition: vnew.cxx:366
constexpr tools::Long Height() const
void SetOrtho(bool bOn)
const SwRect & GetCharRect() const
Definition: crsrsh.hxx:516
const INetURLObject & GetURLObject() const
size_t IsObjSelected() const
Definition: feshview.cxx:1240
void UnSelectFrame()
Definition: select.cxx:323
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
bool EndCreate(SdrCreateCmd eSdrCreateCmd)
Definition: feshview.cxx:1823
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
SfxMedium * GetMedium() const