~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/wxsstyle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-2007  Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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/>.
 
17
*
 
18
* $Revision: 4850 $
 
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 $
 
21
*/
 
22
 
 
23
#include "wxsstyle.h"
 
24
#include <wx/tokenzr.h>
 
25
#include <logmanager.h>
 
26
 
 
27
wxsStyleSet::wxsStyleSet(const wxChar* DefaultStyle): DefaultStr(DefaultStyle)
 
28
{
 
29
}
 
30
 
 
31
wxsStyleSet::~wxsStyleSet()
 
32
{
 
33
}
 
34
 
 
35
void wxsStyleSet::AddStyle(const wxChar* Name,long Value,long Flags)
 
36
{
 
37
    if ( Value == ((long)-1) )
 
38
    {
 
39
        // Skipping style as it declares new category, not yet supported
 
40
        return;
 
41
    }
 
42
 
 
43
    if ( Flags & wxsSFExt )
 
44
    {
 
45
        // Extra style
 
46
        ExStyleNames.Add(Name);
 
47
        ExStyleBits.Add(1L<<ExStyleBits.Count());
 
48
        ExStyleValues.Add(Value);
 
49
        ExStyleFlags.Add(Flags);
 
50
    }
 
51
    else
 
52
    {
 
53
        // Normal style
 
54
        StyleNames.Add(Name);
 
55
        StyleBits.Add(1L<<StyleBits.Count());
 
56
        StyleValues.Add(Value);
 
57
        StyleFlags.Add(Flags);
 
58
    }
 
59
}
 
60
 
 
61
void wxsStyleSet::EndStyle()
 
62
{
 
63
    StyleNames.Shrink();
 
64
    StyleBits.Shrink();
 
65
    StyleValues.Shrink();
 
66
    StyleFlags.Shrink();
 
67
    ExStyleNames.Shrink();
 
68
    ExStyleBits.Shrink();
 
69
    ExStyleValues.Shrink();
 
70
    ExStyleFlags.Shrink();
 
71
 
 
72
    Default = GetBits(DefaultStr,false);
 
73
}
 
74
 
 
75
long wxsStyleSet::GetBits(const wxString& String,bool IsExtra) const
 
76
{
 
77
    long Result = 0;
 
78
    wxStringTokenizer Tkn(String, wxT("| \t\n"), wxTOKEN_STRTOK);
 
79
    const wxArrayString& NamesArray = IsExtra ? ExStyleNames : StyleNames;
 
80
    const wxArrayLong& BitsArray = IsExtra ? ExStyleBits : StyleBits;
 
81
 
 
82
    while ( Tkn.HasMoreTokens() )
 
83
    {
 
84
        int Index = NamesArray.Index(Tkn.GetNextToken());
 
85
        if ( Index != wxNOT_FOUND )
 
86
        {
 
87
            Result |= BitsArray[Index];
 
88
        }
 
89
    }
 
90
    return Result;
 
91
}
 
92
 
 
93
wxString wxsStyleSet::GetString(long Bits,bool IsExtra,wxsCodingLang Language) const
 
94
{
 
95
    switch ( Language )
 
96
    {
 
97
        case wxsCPP:
 
98
        {
 
99
            wxString Result;
 
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++ )
 
104
            {
 
105
                if ( Bits & BitsArray[i] )
 
106
                {
 
107
                    Result.Append(NamesArray[i]);
 
108
                    Result.Append(_T('|'));
 
109
                }
 
110
            }
 
111
 
 
112
            if ( Result.empty() )
 
113
            {
 
114
                return _T("0");
 
115
            }
 
116
 
 
117
            Result.RemoveLast();
 
118
            return Result;
 
119
        }
 
120
 
 
121
        default:
 
122
        {
 
123
            wxsCodeMarks::Unknown(_T("wxsStyleSet::BitsToString"),Language);
 
124
        }
 
125
    }
 
126
    return wxEmptyString;
 
127
}
 
128
 
 
129
long wxsStyleSet::GetWxStyle(long Bits,bool IsExtra) const
 
130
{
 
131
    long Result = 0L;
 
132
    const wxArrayLong& BitsArray = IsExtra ? ExStyleBits : StyleBits;
 
133
    const wxArrayLong& ValuesArray = IsExtra ? ExStyleValues : StyleValues;
 
134
 
 
135
    for ( size_t i = BitsArray.Count(); i-->0; )
 
136
    {
 
137
        if ( BitsArray[i] & Bits )
 
138
        {
 
139
            Result |= ValuesArray[i];
 
140
        }
 
141
    }
 
142
 
 
143
    return Result;
 
144
}
 
145