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/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 <docsh.hxx>
36 #include <sfx2/docfile.hxx>
37 #include <svl/urihelper.hxx>
38 #include <avmedia/mediawindow.hxx>
39 
40 using namespace ::com::sun::star;
41 
42 void SwBaseShell::InsertURLButton(const OUString& rURL, const OUString& rTarget, const OUString& rText)
43 {
44  SwWrtShell& rSh = GetShell();
45 
46  if (!rSh.HasDrawView())
47  rSh.MakeDrawView();
48  SdrView *pSdrView = rSh.GetDrawView();
49 
50  // OBJ_FM_BUTTON
51  pSdrView->SetDesignMode();
52  pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
53  pSdrView->SetEditMode(false);
54 
55  Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
56 
57  rSh.StartAction();
59  if (rSh.BeginCreate(OBJ_FM_BUTTON, SdrInventor::FmForm, aStartPos))
60  {
61  pSdrView->SetOrtho(false);
62  Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
63  Point aEndPos(aSz.Width(), aSz.Height());
64 
65  rSh.MoveCreate(aStartPos + aEndPos);
66  rSh.EndCreate(SdrCreateCmd::ForceEnd);
67 
68  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
69  if (rMarkList.GetMark(0))
70  {
71  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
72  OSL_ENSURE( pUnoCtrl, "not an SdrUnoObj" );
73  if (!pUnoCtrl)
74  return;
75 
76  uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
77 
78  OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
79  if (!xControlModel.is())
80  return;
81 
82  uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
83 
84  uno::Any aTmp;
85 
86  aTmp <<= rText;
87  xPropSet->setPropertyValue( "Label", aTmp );
88 
89  SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
90  INetURLObject aAbs;
91  if( pMedium )
92  aAbs = pMedium->GetURLObject();
93 
94  aTmp <<= URIHelper::SmartRel2Abs(aAbs, rURL);
95  xPropSet->setPropertyValue( "TargetURL", aTmp );
96 
97  if( !rTarget.isEmpty() )
98  {
99  aTmp <<= rTarget;
100  xPropSet->setPropertyValue( "TargetFrame", aTmp );
101  }
102 
103  aTmp <<= form::FormButtonType_URL;
104  xPropSet->setPropertyValue( "ButtonType", aTmp );
105 
106 #if HAVE_FEATURE_AVMEDIA
107  if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
108  {
109  // #105638# OJ
110  aTmp <<= true;
111  xPropSet->setPropertyValue("DispatchURLInternal", aTmp );
112  }
113 #endif
114  }
115 
116  if (rSh.IsObjSelected())
117  {
118  rSh.UnSelectFrame();
119  }
120  }
122  rSh.EndAction();
123 }
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
SwView & GetView()
Definition: basesh.hxx:57
SdrView * GetDrawView()
Definition: vnew.cxx:375
void SetDesignMode(bool bOn=true)
long Height() const
SwWrtShell & GetShell()
Definition: basesh.cxx:2677
bool HasDrawView() const
Definition: vnew.cxx:360
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:90
const SwView & GetView() const
Definition: wrtsh.hxx:428
void InsertURLButton(const OUString &rURL, const OUString &rTarget, const OUString &rText)
Definition: textdrw.cxx:42
void SetEditMode(SdrViewEditMode eMode)
SdrObject * GetMarkedSdrObj() const
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:239
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
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
SwDocShell * GetDocShell()
Definition: view.cxx:1107
void StartAction()
Definition: crsrsh.cxx:222
void MoveCreate(const Point &rPos)
Definition: feshview.cxx:1722
void MakeDrawView()
Definition: vnew.cxx:365
void SetCurrentObj(sal_uInt16 nIdent, SdrInventor nInvent=SdrInventor::Default)
void SetOrtho(bool bOn)
const SwRect & GetCharRect() const
Definition: crsrsh.hxx:516
const INetURLObject & GetURLObject() const
size_t IsObjSelected() const
Definition: feshview.cxx:1150
void UnSelectFrame()
Definition: select.cxx:322
bool BeginCreate(sal_uInt16 eSdrObjectKind, const Point &rPos)
Process of creating draw objects.
Definition: feshview.cxx:1680
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
const sal_uInt16 OBJ_FM_BUTTON
bool EndCreate(SdrCreateCmd eSdrCreateCmd)
Definition: feshview.cxx:1733
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