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 #include <unomid.h>
41 
42 using namespace ::com::sun::star;
43 
44 void SwBaseShell::InsertURLButton(const OUString& rURL, const OUString& rTarget, const OUString& rText)
45 {
46  SwWrtShell& rSh = GetShell();
47 
48  if (!rSh.HasDrawView())
49  rSh.MakeDrawView();
50  SdrView *pSdrView = rSh.GetDrawView();
51 
52  // OBJ_FM_BUTTON
53  pSdrView->SetDesignMode();
54  pSdrView->SetCurrentObj(OBJ_FM_BUTTON);
55  pSdrView->SetEditMode(false);
56 
57  Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
58 
59  rSh.StartAction();
61  if (rSh.BeginCreate(OBJ_FM_BUTTON, SdrInventor::FmForm, aStartPos))
62  {
63  pSdrView->SetOrtho(false);
64  Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
65  Point aEndPos(aSz.Width(), aSz.Height());
66 
67  rSh.MoveCreate(aStartPos + aEndPos);
68  rSh.EndCreate(SdrCreateCmd::ForceEnd);
69 
70  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
71  if (rMarkList.GetMark(0))
72  {
73  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
74  OSL_ENSURE( pUnoCtrl, "not an SdrUnoObj" );
75  if (!pUnoCtrl)
76  return;
77 
78  uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
79 
80  OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
81  if (!xControlModel.is())
82  return;
83 
84  uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
85 
86  uno::Any aTmp;
87 
88  aTmp <<= rText;
89  xPropSet->setPropertyValue( "Label", aTmp );
90 
91  SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
92  INetURLObject aAbs;
93  if( pMedium )
94  aAbs = pMedium->GetURLObject();
95 
96  aTmp <<= URIHelper::SmartRel2Abs(aAbs, rURL);
97  xPropSet->setPropertyValue( "TargetURL", aTmp );
98 
99  if( !rTarget.isEmpty() )
100  {
101  aTmp <<= rTarget;
102  xPropSet->setPropertyValue( "TargetFrame", aTmp );
103  }
104 
105  aTmp <<= form::FormButtonType_URL;
106  xPropSet->setPropertyValue( "ButtonType", aTmp );
107 
108 #if HAVE_FEATURE_AVMEDIA
109  if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
110  {
111  // #105638# OJ
112  aTmp <<= true;
113  xPropSet->setPropertyValue("DispatchURLInternal", aTmp );
114  }
115 #endif
116  }
117 
118  if (rSh.IsObjSelected())
119  {
120  rSh.UnSelectFrame();
121  }
122  }
124  rSh.EndAction();
125 }
126 
127 /* 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:2651
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:233
SdrMark * GetMark(size_t nNum) const
void Pos(const Point &rNew)
Definition: swrect.hxx:167
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:44
void SetEditMode(SdrViewEditMode eMode)
SdrObject * GetMarkedSdrObj() const
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:228
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:222
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
SwDocShell * GetDocShell()
Definition: view.cxx:1127
void StartAction()
Definition: crsrsh.cxx:211
void MoveCreate(const Point &rPos)
Definition: feshview.cxx:1739
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:520
const INetURLObject & GetURLObject() const
size_t IsObjSelected() const
Definition: feshview.cxx:1167
void UnSelectFrame()
Definition: select.cxx:327
bool BeginCreate(sal_uInt16 eSdrObjectKind, const Point &rPos)
Process of creating draw objects.
Definition: feshview.cxx:1697
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
const sal_uInt16 OBJ_FM_BUTTON
bool EndCreate(SdrCreateCmd eSdrCreateCmd)
Definition: feshview.cxx:1750
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