ooo33gsl12: #i115107# do not call getNativeControlRegion during paint on gtk
[LibreOffice.git] / vcl / source / helper / smartid.cxx
blobc367aeb2bce53261ba43a900393c8b7d4bb5e76b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include <vcl/smartid.hxx>
32 struct ImplSmartIdData
34 String aUId;
35 ULONG nUId;
36 BOOL bHasStringId;
37 BOOL bHasNumericId;
41 ImplSmartIdData* SmartId::GetSmartIdData()
43 if ( !mpData )
45 mpData = new ImplSmartIdData;
46 // mpData->aUId = "";
47 mpData->nUId = 0;
48 mpData->bHasStringId = FALSE;
49 mpData->bHasNumericId = FALSE;
51 return mpData;
55 SmartId::SmartId( const String& rId )
56 : mpData( NULL )
58 GetSmartIdData()->aUId = rId;
59 GetSmartIdData()->bHasStringId = TRUE;
62 SmartId::SmartId( ULONG nId )
63 : mpData( NULL )
65 GetSmartIdData()->nUId = nId;
66 GetSmartIdData()->bHasNumericId = TRUE;
69 SmartId::SmartId( const String& rId, ULONG nId )
70 : mpData( NULL )
72 GetSmartIdData()->aUId = rId;
73 GetSmartIdData()->bHasStringId = TRUE;
74 GetSmartIdData()->nUId = nId;
75 GetSmartIdData()->bHasNumericId = TRUE;
78 SmartId::SmartId()
79 : mpData( NULL )
82 SmartId::SmartId( const SmartId& rId )
83 : mpData( NULL )
85 if ( rId.mpData )
87 GetSmartIdData();
88 mpData->aUId = rId.mpData->aUId;
89 mpData->bHasStringId = rId.mpData->bHasStringId;
90 mpData->nUId = rId.mpData->nUId;
91 mpData->bHasNumericId = rId.mpData->bHasNumericId;
95 SmartId& SmartId::operator = ( const SmartId& rId )
97 if ( rId.mpData )
98 GetSmartIdData();
99 else
101 delete mpData;
102 mpData = NULL;
104 if ( mpData && rId.mpData )
106 mpData->aUId = rId.mpData->aUId;
107 mpData->bHasStringId = rId.mpData->bHasStringId;
108 mpData->nUId = rId.mpData->nUId;
109 mpData->bHasNumericId = rId.mpData->bHasNumericId;
111 return *this;
114 SmartId::~SmartId()
116 if ( mpData )
117 delete mpData;
118 #ifdef DBG_UTIL
119 if ( mpData )
120 mpData = (ImplSmartIdData*)0xDeadBeef;
121 #endif
124 void SmartId::UpdateId( const SmartId& rId, SmartIdUpdateMode aMode )
126 // Check if ImplData is needed
127 if ( aMode != SMART_SET_SMART || ( rId.HasString() || rId.HasNumeric() ) )
128 GetSmartIdData();
130 if ( aMode == SMART_SET_STR || aMode == SMART_SET_ALL || ( aMode == SMART_SET_SMART && rId.HasString() ) )
132 GetSmartIdData()->aUId = rId.GetStr();
133 GetSmartIdData()->bHasStringId = rId.HasString();
135 if ( aMode == SMART_SET_NUM || aMode == SMART_SET_ALL || ( aMode == SMART_SET_SMART && rId.HasNumeric() ) )
137 GetSmartIdData()->nUId = rId.GetNum();
138 GetSmartIdData()->bHasNumericId = rId.HasNumeric();
141 // remove ImplData when no IDs are set. This is Important because Implementation of Equals() Matches and HasAny relies on it
142 if ( mpData && !mpData->bHasStringId && !mpData->bHasNumericId )
144 delete mpData;
145 mpData = NULL;
149 BOOL SmartId::HasNumeric() const
151 if ( !mpData )
152 return FALSE;
153 else
154 return mpData->bHasNumericId;
157 BOOL SmartId::HasString() const
159 if ( !mpData )
160 return FALSE;
161 else
162 return mpData->bHasStringId;
165 BOOL SmartId::HasAny() const
167 return mpData != NULL;
170 ULONG SmartId::GetNum() const
172 if ( !mpData )
173 return 0;
174 else
175 return mpData->nUId;
178 String SmartId::GetStr() const
180 if ( !mpData )
181 return String();
182 else
183 return mpData->aUId;
187 String SmartId::GetText() const // return String for UI usage
189 String aRes;
190 if ( HasNumeric() )
191 aRes = String::CreateFromInt64( GetNum() );
192 if ( HasString() )
194 if ( HasNumeric() )
195 aRes.AppendAscii( "/" );
196 aRes.Append( GetStr() );
198 return aRes;
201 BOOL SmartId::Matches( const String &rId )const
203 if ( HasString() )
204 return GetStr().EqualsIgnoreCaseAscii( rId );
205 else
206 return FALSE;
209 BOOL SmartId::Matches( const ULONG nId ) const
211 if ( HasNumeric() )
212 return GetNum() == nId;
213 else
214 return FALSE;
217 /******************************************************************************
218 If Both Ids have nither Strings nor Numbers they don't match
219 If both Ids have Strings the result of Matching these is returned.
220 Numbers are then Ignored.
221 Else Matching Numbers is attempted.
222 ******************************************************************************/
223 BOOL SmartId::Matches( const SmartId &rId ) const
225 if ( !mpData || !rId.mpData )
226 return FALSE;
227 else if ( HasString() && rId.HasString() )
228 return Matches( rId.GetStr() );
229 else
230 return rId.HasNumeric() && Matches( rId.GetNum() );
233 BOOL SmartId::Equals( const SmartId &rId ) const
235 if ( mpData && rId.mpData )
236 return mpData->aUId.EqualsIgnoreCaseAscii( rId.mpData->aUId )
237 && mpData->bHasStringId == rId.mpData->bHasStringId
238 && mpData->nUId == rId.mpData->nUId
239 && mpData->bHasNumericId == rId.mpData->bHasNumericId;
240 else if ( !mpData && !rId.mpData )
241 return TRUE;
242 else
243 return FALSE;
246 BOOL SmartId::operator == ( const SmartId& rRight ) const
248 return Equals( rRight );
251 BOOL SmartId::operator < ( const SmartId& rRight ) const
253 if ( HasString() && rRight.HasString() && GetStr() != rRight.GetStr() )
254 return GetStr() < rRight.GetStr();
255 else if ( HasNumeric() && rRight.HasNumeric() && GetNum() != rRight.GetNum() )
256 return GetNum() < rRight.GetNum();
257 else
258 { // Sort Strings to Front
259 if ( HasString() )
260 return rRight.HasString() && rRight.HasNumeric();
261 else
262 return rRight.HasString() || (!HasNumeric() && rRight.HasNumeric());