Line data Source code
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/clipfmtitem.hxx>
21 : #include <com/sun/star/frame/status/ClipboardFormats.hpp>
22 :
23 : #include <boost/ptr_container/ptr_vector.hpp>
24 :
25 0 : struct SvxClipboardFmtItem_Impl
26 : {
27 : boost::ptr_vector< boost::nullable<OUString> > aFmtNms;
28 : std::vector<sal_uIntPtr> aFmtIds;
29 :
30 0 : SvxClipboardFmtItem_Impl() {}
31 : SvxClipboardFmtItem_Impl( const SvxClipboardFmtItem_Impl& );
32 : };
33 :
34 0 : TYPEINIT1_FACTORY( SvxClipboardFmtItem, SfxPoolItem , new SvxClipboardFmtItem(0));
35 :
36 0 : SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl(
37 : const SvxClipboardFmtItem_Impl& rCpy )
38 : : aFmtNms(rCpy.aFmtNms)
39 0 : , aFmtIds(rCpy.aFmtIds)
40 : {
41 0 : }
42 :
43 0 : SvxClipboardFmtItem::SvxClipboardFmtItem( sal_uInt16 nId )
44 0 : : SfxPoolItem( nId ), pImpl( new SvxClipboardFmtItem_Impl )
45 : {
46 0 : }
47 :
48 0 : SvxClipboardFmtItem::SvxClipboardFmtItem( const SvxClipboardFmtItem& rCpy )
49 0 : : SfxPoolItem( rCpy.Which() ),
50 0 : pImpl( new SvxClipboardFmtItem_Impl( *rCpy.pImpl ) )
51 : {
52 0 : }
53 :
54 0 : SvxClipboardFmtItem::~SvxClipboardFmtItem()
55 : {
56 0 : delete pImpl;
57 0 : }
58 :
59 0 : bool SvxClipboardFmtItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
60 : {
61 0 : sal_uInt16 nCount = Count();
62 :
63 0 : ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
64 :
65 0 : aClipFormats.Identifiers.realloc( nCount );
66 0 : aClipFormats.Names.realloc( nCount );
67 0 : for ( sal_uInt16 n=0; n < nCount; n++ )
68 : {
69 0 : aClipFormats.Identifiers[n] = (sal_Int64)GetClipbrdFormatId( n );
70 0 : aClipFormats.Names[n] = GetClipbrdFormatName( n );
71 : }
72 :
73 0 : rVal <<= aClipFormats;
74 0 : return true;
75 : }
76 :
77 0 : bool SvxClipboardFmtItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
78 : {
79 0 : ::com::sun::star::frame::status::ClipboardFormats aClipFormats;
80 0 : if ( rVal >>= aClipFormats )
81 : {
82 0 : sal_uInt16 nCount = sal_uInt16( aClipFormats.Identifiers.getLength() );
83 :
84 0 : pImpl->aFmtIds.clear();
85 0 : pImpl->aFmtNms.clear();
86 0 : for ( sal_uInt16 n=0; n < nCount; ++n )
87 0 : AddClipbrdFormat( sal_uIntPtr( aClipFormats.Identifiers[n] ), aClipFormats.Names[n], n );
88 :
89 0 : return true;
90 : }
91 :
92 0 : return false;
93 : }
94 :
95 0 : bool SvxClipboardFmtItem::operator==( const SfxPoolItem& rComp ) const
96 : {
97 0 : const SvxClipboardFmtItem& rCmp = (SvxClipboardFmtItem&)rComp;
98 0 : if(rCmp.pImpl->aFmtNms.size() != pImpl->aFmtNms.size())
99 0 : return false;
100 :
101 0 : int nRet = 1;
102 0 : for( sal_uInt16 n = 0, nEnd = rCmp.pImpl->aFmtNms.size(); n < nEnd; ++n )
103 : {
104 0 : if( pImpl->aFmtIds[ n ] != rCmp.pImpl->aFmtIds[ n ] ||
105 0 : ( pImpl->aFmtNms.is_null(n) != rCmp.pImpl->aFmtNms.is_null(n) ) ||
106 0 : ( !pImpl->aFmtNms.is_null(n) && pImpl->aFmtNms[n] != rCmp.pImpl->aFmtNms[n] ) )
107 : {
108 0 : nRet = 0;
109 0 : break;
110 : }
111 : }
112 :
113 0 : return nRet;
114 : }
115 :
116 0 : SfxPoolItem* SvxClipboardFmtItem::Clone( SfxItemPool * /*pPool*/ ) const
117 : {
118 0 : return new SvxClipboardFmtItem( *this );
119 : }
120 :
121 0 : void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, sal_uInt16 nPos )
122 : {
123 0 : if( nPos > pImpl->aFmtNms.size() )
124 0 : nPos = pImpl->aFmtNms.size();
125 :
126 0 : pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, 0);
127 0 : pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
128 0 : }
129 :
130 0 : void SvxClipboardFmtItem::AddClipbrdFormat( sal_uIntPtr nId, const OUString& rName,
131 : sal_uInt16 nPos )
132 : {
133 0 : if( nPos > pImpl->aFmtNms.size() )
134 0 : nPos = pImpl->aFmtNms.size();
135 :
136 0 : pImpl->aFmtNms.insert(pImpl->aFmtNms.begin() + nPos, new OUString(rName));
137 0 : pImpl->aFmtIds.insert( pImpl->aFmtIds.begin()+nPos, nId );
138 0 : }
139 :
140 0 : sal_uInt16 SvxClipboardFmtItem::Count() const
141 : {
142 0 : return pImpl->aFmtIds.size();
143 : }
144 :
145 0 : sal_uIntPtr SvxClipboardFmtItem::GetClipbrdFormatId( sal_uInt16 nPos ) const
146 : {
147 0 : return pImpl->aFmtIds[ nPos ];
148 : }
149 :
150 0 : const OUString SvxClipboardFmtItem::GetClipbrdFormatName( sal_uInt16 nPos ) const
151 : {
152 0 : return pImpl->aFmtNms.is_null(nPos) ? OUString() : pImpl->aFmtNms[nPos];
153 : }
154 :
155 :
156 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|