Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / hlnkitem.cxx
blob93ef9f6d6da54b1ba06b2b595cc3213305e6a24e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svxids.hrc>
21 #include <sfx2/event.hxx>
22 #include <svx/hlnkitem.hxx>
23 #include <utility>
26 SfxPoolItem* SvxHyperlinkItem::CreateDefault() { return new SvxHyperlinkItem(TypedWhichId<SvxHyperlinkItem>(0));}
28 SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& rHyperlinkItem ):
29 SfxPoolItem(rHyperlinkItem)
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;
39 if( rHyperlinkItem.GetMacroTable() )
40 pMacroTable.reset( new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTable() ) );
44 SvxHyperlinkItem::SvxHyperlinkItem( TypedWhichId<SvxHyperlinkItem> _nWhich, OUString aName, OUString aURL,
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)
56 if (pMacroTbl)
57 pMacroTable.reset( new SvxMacroTableDtor ( *pMacroTbl ) );
60 SvxHyperlinkItem* SvxHyperlinkItem::Clone( SfxItemPool* ) const
62 return new SvxHyperlinkItem( *this );
65 bool SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const
67 assert(SfxPoolItem::operator==(rAttr));
69 const SvxHyperlinkItem& rItem = static_cast<const SvxHyperlinkItem&>(rAttr);
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 &&
77 sReplacementText == rItem.sReplacementText);
78 if (!bRet)
79 return false;
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();
87 const SvxMacroTableDtor& rOwn = *pMacroTable;
88 const SvxMacroTableDtor& rOther = *pOther;
90 return rOwn == rOther;
93 void SvxHyperlinkItem::SetMacro( HyperDialogEvent nEvent, const SvxMacro& rMacro )
95 SvMacroItemId nSfxEvent = SvMacroItemId::NONE;
96 switch( nEvent )
98 case HyperDialogEvent::MouseOverObject:
99 nSfxEvent = SvMacroItemId::OnMouseOver;
100 break;
101 case HyperDialogEvent::MouseClickObject:
102 nSfxEvent = SvMacroItemId::OnClick;
103 break;
104 case HyperDialogEvent::MouseOutObject:
105 nSfxEvent = SvMacroItemId::OnMouseOut;
106 break;
107 default: break;
110 if( !pMacroTable )
111 pMacroTable.reset( new SvxMacroTableDtor );
113 pMacroTable->Insert( nSfxEvent, rMacro);
116 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
118 pMacroTable.reset( new SvxMacroTableDtor ( rTbl ) );
121 bool SvxHyperlinkItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
123 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
124 nMemberId &= ~CONVERT_TWIPS;
125 switch(nMemberId)
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;
149 return true;
152 bool SvxHyperlinkItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
154 nMemberId &= ~CONVERT_TWIPS;
155 OUString aStr;
156 sal_Int32 nVal = 0;
157 switch(nMemberId)
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;
187 sReplacementText = aStr;
188 break;
189 default:
190 return false;
193 return true;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */