1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: userlist.cxx,v $
10 * $Revision: 1.11.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include <unotools/charclass.hxx>
42 #include "userlist.hxx"
43 #include <unotools/localedatawrapper.hxx>
44 #include <unotools/calendarwrapper.hxx>
45 #include <unotools/transliterationwrapper.hxx>
47 // STATIC DATA -----------------------------------------------------------
50 //------------------------------------------------------------------------
52 void ScUserListData::InitTokens()
54 sal_Unicode cSep
= ScGlobal::cListDelimiter
;
55 nTokenCount
= (USHORT
) aStr
.GetTokenCount(cSep
);
58 pSubStrings
= new String
[nTokenCount
];
59 pUpperSub
= new String
[nTokenCount
];
60 for (USHORT i
=0; i
<nTokenCount
; i
++)
62 pUpperSub
[i
] = pSubStrings
[i
] = aStr
.GetToken((xub_StrLen
)i
,cSep
);
63 ScGlobal::pCharClass
->toUpper(pUpperSub
[i
]);
67 pSubStrings
= pUpperSub
= NULL
;
70 ScUserListData::ScUserListData(const String
& rStr
) :
76 ScUserListData::ScUserListData(const ScUserListData
& rData
) :
83 __EXPORT
ScUserListData::~ScUserListData()
89 void ScUserListData::SetString( const String
& rStr
)
98 USHORT
ScUserListData::GetSubCount() const
103 BOOL
ScUserListData::GetSubIndex(const String
& rSubStr
, USHORT
& rIndex
) const
106 for (i
=0; i
<nTokenCount
; i
++)
107 if (rSubStr
== pSubStrings
[i
])
113 String aUpStr
= rSubStr
;
114 ScGlobal::pCharClass
->toUpper(aUpStr
);
115 for (i
=0; i
<nTokenCount
; i
++)
116 if (aUpStr
== pUpperSub
[i
])
125 String
ScUserListData::GetSubStr(USHORT nIndex
) const
127 if (nIndex
< nTokenCount
)
128 return pSubStrings
[nIndex
];
133 StringCompare
ScUserListData::Compare(const String
& rSubStr1
, const String
& rSubStr2
) const
137 BOOL bFound1
= GetSubIndex(rSubStr1
, nIndex1
);
138 BOOL bFound2
= GetSubIndex(rSubStr2
, nIndex2
);
143 if (nIndex1
< nIndex2
)
145 else if (nIndex1
> nIndex2
)
146 return COMPARE_GREATER
;
148 return COMPARE_EQUAL
;
154 return COMPARE_GREATER
;
156 return (StringCompare
) ScGlobal::GetCaseTransliteration()->compareString( rSubStr1
, rSubStr2
);
159 StringCompare
ScUserListData::ICompare(const String
& rSubStr1
, const String
& rSubStr2
) const
163 BOOL bFound1
= GetSubIndex(rSubStr1
, nIndex1
);
164 BOOL bFound2
= GetSubIndex(rSubStr2
, nIndex2
);
169 if (nIndex1
< nIndex2
)
171 else if (nIndex1
> nIndex2
)
172 return COMPARE_GREATER
;
174 return COMPARE_EQUAL
;
180 return COMPARE_GREATER
;
182 return (StringCompare
) ScGlobal::GetpTransliteration()->compareString( rSubStr1
, rSubStr2
);
185 ScUserList::ScUserList(USHORT nLim
, USHORT nDel
) :
186 ScCollection ( nLim
, nDel
)
188 using namespace ::com::sun::star
;
190 sal_Unicode cDelimiter
= ScGlobal::cListDelimiter
;
191 uno::Sequence
< i18n::CalendarItem
> xCal
;
193 uno::Sequence
< i18n::Calendar
> xCalendars(
194 ScGlobal::pLocaleData
->getAllCalendars() );
196 for ( sal_Int32 j
= 0; j
< xCalendars
.getLength(); ++j
)
198 xCal
= xCalendars
[j
].Days
;
199 if ( xCal
.getLength() )
201 String sDayShort
, sDayLong
;
203 sal_Int32 nLen
= xCal
.getLength();
204 rtl::OUString sStart
= xCalendars
[j
].StartOfWeek
;
205 sal_Int16 nStart
= sal::static_int_cast
<sal_Int16
>(nLen
);
208 if (xCal
[--nStart
].ID
== sStart
)
211 sal_Int16 nLast
= sal::static_int_cast
<sal_Int16
>( (nStart
+ nLen
- 1) % nLen
);
212 for (i
= nStart
; i
!= nLast
; i
= (i
+1) % nLen
)
214 sDayShort
+= String( xCal
[i
].AbbrevName
);
215 sDayShort
+= cDelimiter
;
216 sDayLong
+= String( xCal
[i
].FullName
);
217 sDayLong
+= cDelimiter
;
219 sDayShort
+= String( xCal
[i
].AbbrevName
);
220 sDayLong
+= String( xCal
[i
].FullName
);
222 if ( !HasEntry( sDayShort
) )
223 Insert( new ScUserListData( sDayShort
));
224 if ( !HasEntry( sDayLong
) )
225 Insert( new ScUserListData( sDayLong
));
228 xCal
= xCalendars
[j
].Months
;
229 if ( xCal
.getLength() )
231 String sMonthShort
, sMonthLong
;
233 sal_Int32 nLen
= xCal
.getLength() - 1;
234 for (i
= 0; i
< nLen
; i
++)
236 sMonthShort
+= String( xCal
[i
].AbbrevName
);
237 sMonthShort
+= cDelimiter
;
238 sMonthLong
+= String( xCal
[i
].FullName
);
239 sMonthLong
+= cDelimiter
;
241 sMonthShort
+= String( xCal
[i
].AbbrevName
);
242 sMonthLong
+= String( xCal
[i
].FullName
);
244 if ( !HasEntry( sMonthShort
) )
245 Insert( new ScUserListData( sMonthShort
));
246 if ( !HasEntry( sMonthLong
) )
247 Insert( new ScUserListData( sMonthLong
));
252 ScDataObject
* ScUserList::Clone() const
254 return ( new ScUserList( *this ) );
257 ScUserListData
* ScUserList::GetData(const String
& rSubStr
) const
261 for (i
=0; i
< nCount
; i
++)
262 if (((ScUserListData
*)pItems
[i
])->GetSubIndex(rSubStr
, nIndex
))
263 return (ScUserListData
*)pItems
[i
];
267 BOOL
ScUserList::operator==( const ScUserList
& r
) const
269 BOOL bEqual
= (nCount
== r
.nCount
);
273 ScUserListData
* pMyData
= NULL
;
274 ScUserListData
* pOtherData
= NULL
;
276 for ( USHORT i
=0; i
<nCount
&& bEqual
; i
++)
278 pMyData
= (ScUserListData
*)At(i
);
279 pOtherData
= (ScUserListData
*)r
.At(i
);
281 bEqual
=( (pMyData
->nTokenCount
== pOtherData
->nTokenCount
)
282 && (pMyData
->aStr
== pOtherData
->aStr
) );
290 BOOL
ScUserList::HasEntry( const String
& rStr
) const
292 for ( USHORT i
=0; i
<nCount
; i
++)
294 const ScUserListData
* pMyData
= (ScUserListData
*) At(i
);
295 if ( pMyData
->aStr
== rStr
)