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