LibreOffice Module svx (master)  1
hlnkitem.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 <svx/svxids.hrc>
21 #include <sfx2/event.hxx>
22 #include <svx/hlnkitem.hxx>
23 
24 
26 
28  SfxPoolItem(rHyperlinkItem)
29 {
30  sName = rHyperlinkItem.sName;
31  sURL = rHyperlinkItem.sURL;
32  sTarget = rHyperlinkItem.sTarget;
33  eType = rHyperlinkItem.eType;
34  sIntName = rHyperlinkItem.sIntName;
35  nMacroEvents = rHyperlinkItem.nMacroEvents;
36 
37  if( rHyperlinkItem.GetMacroTable() )
38  pMacroTable.reset( new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTable() ) );
39 
40 };
41 
42 SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich, const OUString& rName, const OUString& rURL,
43  const OUString& rTarget, const OUString& rIntName, SvxLinkInsertMode eTyp,
44  HyperDialogEvent nEvents, SvxMacroTableDtor const *pMacroTbl ):
45  SfxPoolItem (_nWhich),
46  sName (rName),
47  sURL (rURL),
48  sTarget (rTarget),
49  eType (eTyp),
50  sIntName (rIntName),
51  nMacroEvents (nEvents)
52 {
53  if (pMacroTbl)
54  pMacroTable.reset( new SvxMacroTableDtor ( *pMacroTbl ) );
55 }
56 
58 {
59  return new SvxHyperlinkItem( *this );
60 }
61 
62 bool SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const
63 {
64  assert(SfxPoolItem::operator==(rAttr));
65 
66  const SvxHyperlinkItem& rItem = static_cast<const SvxHyperlinkItem&>(rAttr);
67 
68  bool bRet = ( sName == rItem.sName &&
69  sURL == rItem.sURL &&
70  sTarget == rItem.sTarget &&
71  eType == rItem.eType &&
72  sIntName == rItem.sIntName &&
73  nMacroEvents == rItem.nMacroEvents);
74  if (!bRet)
75  return false;
76 
77  const SvxMacroTableDtor* pOther = static_cast<const SvxHyperlinkItem&>(rAttr).pMacroTable.get();
78  if( !pMacroTable )
79  return ( !pOther || pOther->empty() );
80  if( !pOther )
81  return pMacroTable->empty();
82 
83  const SvxMacroTableDtor& rOwn = *pMacroTable;
84  const SvxMacroTableDtor& rOther = *pOther;
85 
86  return rOwn == rOther;
87 }
88 
90 {
91  SvMacroItemId nSfxEvent = SvMacroItemId::NONE;
92  switch( nEvent )
93  {
95  nSfxEvent = SvMacroItemId::OnMouseOver;
96  break;
98  nSfxEvent = SvMacroItemId::OnClick;
99  break;
101  nSfxEvent = SvMacroItemId::OnMouseOut;
102  break;
103  default: break;
104  }
105 
106  if( !pMacroTable )
107  pMacroTable.reset( new SvxMacroTableDtor );
108 
109  pMacroTable->Insert( nSfxEvent, rMacro);
110 }
111 
113 {
114  pMacroTable.reset( new SvxMacroTableDtor ( rTbl ) );
115 }
116 
117 bool SvxHyperlinkItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
118 {
119 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
120  nMemberId &= ~CONVERT_TWIPS;
121  switch(nMemberId)
122  {
123  case MID_HLINK_NAME :
124  rVal <<= sIntName;
125  break;
126  case MID_HLINK_TEXT :
127  rVal <<= sName;
128  break;
129  case MID_HLINK_URL:
130  rVal <<= sURL;
131  break;
132  case MID_HLINK_TARGET:
133  rVal <<= sTarget;
134  break;
135  case MID_HLINK_TYPE:
136  rVal <<= static_cast<sal_Int32>(eType);
137  break;
138  default:
139  return false;
140  }
141 
142  return true;
143 }
144 
145 bool SvxHyperlinkItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
146 {
147  nMemberId &= ~CONVERT_TWIPS;
148  OUString aStr;
149  sal_Int32 nVal = 0;
150  switch(nMemberId)
151  {
152  case MID_HLINK_NAME :
153  if(!(rVal >>= aStr))
154  return false;
155  sIntName = aStr;
156  break;
157  case MID_HLINK_TEXT :
158  if(!(rVal >>= aStr))
159  return false;
160  sName = aStr;
161  break;
162  case MID_HLINK_URL:
163  if(!(rVal >>= aStr))
164  return false;
165  sURL = aStr;
166  break;
167  case MID_HLINK_TARGET:
168  if(!(rVal >>= aStr))
169  return false;
170  sTarget = aStr;
171  break;
172  case MID_HLINK_TYPE:
173  if(!(rVal >>= nVal))
174  return false;
175  eType = static_cast<SvxLinkInsertMode>(static_cast<sal_uInt16>(nVal));
176  break;
177  default:
178  return false;
179  }
180 
181  return true;
182 }
183 
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMacro(HyperDialogEvent nEvent, const SvxMacro &rMacro)
Definition: hlnkitem.cxx:89
HyperDialogEvent
Definition: hlnkitem.hxx:30
virtual SvxHyperlinkItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: hlnkitem.cxx:57
std::unique_ptr< SvxMacroTableDtor > pMacroTable
Definition: hlnkitem.hxx:56
OUString sTarget
Definition: hlnkitem.hxx:52
OUString sIntName
Definition: hlnkitem.hxx:55
SvMacroItemId
OUString sURL
Definition: hlnkitem.hxx:51
void SetMacroTable(const SvxMacroTableDtor &rTbl)
Definition: hlnkitem.cxx:112
const SvxMacroTableDtor * GetMacroTable() const
Definition: hlnkitem.hxx:95
OUString sName
Definition: hlnkitem.hxx:50
DocumentType eType
bool empty() const
static SfxPoolItem * CreateDefault()
Definition: hlnkitem.cxx:25
OUString sName
SvxLinkInsertMode
Definition: hlnkitem.hxx:40
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: hlnkitem.cxx:117
SvxHyperlinkItem(sal_uInt16 _nWhich=SID_HYPERLINK_GETLINK)
Definition: hlnkitem.hxx:63
SvxLinkInsertMode eType
Definition: hlnkitem.hxx:53
unsigned char sal_uInt8
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: hlnkitem.cxx:145
aStr
HyperDialogEvent nMacroEvents
Definition: hlnkitem.hxx:58
virtual bool operator==(const SfxPoolItem &) const override
Definition: hlnkitem.cxx:62
#define CONVERT_TWIPS