2
* This file is part of wxSmith plugin for Code::Blocks Studio
3
* Copyright (C) 2006-2007 Bartlomiej Swiecki
5
* wxSmith is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* wxSmith is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: wxsstyle.cpp 4850 2008-01-29 21:45:49Z byo $
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/wxsstyle.cpp $
24
#include <wx/tokenzr.h>
25
#include <logmanager.h>
27
wxsStyleSet::wxsStyleSet(const wxChar* DefaultStyle): DefaultStr(DefaultStyle)
31
wxsStyleSet::~wxsStyleSet()
35
void wxsStyleSet::AddStyle(const wxChar* Name,long Value,long Flags)
37
if ( Value == ((long)-1) )
39
// Skipping style as it declares new category, not yet supported
43
if ( Flags & wxsSFExt )
46
ExStyleNames.Add(Name);
47
ExStyleBits.Add(1L<<ExStyleBits.Count());
48
ExStyleValues.Add(Value);
49
ExStyleFlags.Add(Flags);
55
StyleBits.Add(1L<<StyleBits.Count());
56
StyleValues.Add(Value);
57
StyleFlags.Add(Flags);
61
void wxsStyleSet::EndStyle()
67
ExStyleNames.Shrink();
69
ExStyleValues.Shrink();
70
ExStyleFlags.Shrink();
72
Default = GetBits(DefaultStr,false);
75
long wxsStyleSet::GetBits(const wxString& String,bool IsExtra) const
78
wxStringTokenizer Tkn(String, wxT("| \t\n"), wxTOKEN_STRTOK);
79
const wxArrayString& NamesArray = IsExtra ? ExStyleNames : StyleNames;
80
const wxArrayLong& BitsArray = IsExtra ? ExStyleBits : StyleBits;
82
while ( Tkn.HasMoreTokens() )
84
int Index = NamesArray.Index(Tkn.GetNextToken());
85
if ( Index != wxNOT_FOUND )
87
Result |= BitsArray[Index];
93
wxString wxsStyleSet::GetString(long Bits,bool IsExtra,wxsCodingLang Language) const
100
const wxArrayString& NamesArray = IsExtra ? ExStyleNames : StyleNames;
101
const wxArrayLong& BitsArray = IsExtra ? ExStyleBits : StyleBits;
102
size_t Cnt = BitsArray.Count();
103
for ( size_t i=0; i<Cnt; i++ )
105
if ( Bits & BitsArray[i] )
107
Result.Append(NamesArray[i]);
108
Result.Append(_T('|'));
112
if ( Result.empty() )
123
wxsCodeMarks::Unknown(_T("wxsStyleSet::BitsToString"),Language);
126
return wxEmptyString;
129
long wxsStyleSet::GetWxStyle(long Bits,bool IsExtra) const
132
const wxArrayLong& BitsArray = IsExtra ? ExStyleBits : StyleBits;
133
const wxArrayLong& ValuesArray = IsExtra ? ExStyleValues : StyleValues;
135
for ( size_t i = BitsArray.Count(); i-->0; )
137
if ( BitsArray[i] & Bits )
139
Result |= ValuesArray[i];