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