1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxResourceSymbolTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "symbtabl.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
34 wxResourceSymbolTable::wxResourceSymbolTable():
35 m_hashTable(wxKEY_STRING
)
39 wxResourceSymbolTable::~wxResourceSymbolTable()
46 bool wxResourceSymbolTable::ReadIncludeFile(const wxString
& filename
)
49 if (!wxFileExists(filename
))
52 if (!file
.Open(filename
, wxFile::read
))
55 off_t len
= file
.Length();
63 char* p
= str
.GetWriteBuf(len
+ 1);
65 if (file
.Read(p
, len
) == wxFile::fd_invalid
)
72 // Look for #define occurrences
73 size_t pos
= str
.Find("#define");
76 size_t len
= str
.Length();
80 // Eat whitespace until symbol
81 while ((str
[i
] == ' ' || str
[i
] == '\t') && (i
< len
))
87 while (str
[i
] != ' ' && str
[i
] != '\t' && (i
< len
))
91 wxString
symbol(str
.Mid(start
, (end
- start
+ 1)));
93 // Eat whitespace until number
94 while ((str
[i
] == ' ' || str
[i
] == '\t') && (i
< len
))
100 while (str
[i
] != ' ' && str
[i
] != '\t' && str
[i
] != '\n' && (i
< len
))
105 wxString
numStr(str
.Mid(startNum
, (endNum
- startNum
+ 1)));
107 int id
= atol(numStr
);
109 AddSymbol(symbol
, id
);
111 str
= str
.Right(len
- i
);
112 pos
= str
.Find("#define");
118 bool wxResourceSymbolTable::WriteIncludeFile(const wxString
& filename
)
121 if (!file
.Open(filename
, wxFile::write
))
124 wxString
fileOnly(wxFileNameFromPath(filename
));
126 line
.Printf("/*\n * %s\n * Window identifiers file written by Dialog Editor\n */\n\n",
127 (const char*) fileOnly
);
129 file
.Write(line
, line
.Length());
131 m_hashTable
.BeginFind();
133 wxNode
* node
= m_hashTable
.Next();
136 char* str
= node
->key
.string
;
137 int id
= (int) node
->Data() ;
139 if (!IsStandardSymbol(str
))
142 line
.Printf("#define %s %ld\n", str
, id
);
144 file
.Write(line
, line
.Length());
147 node
= m_hashTable
.Next();
152 void wxResourceSymbolTable::Clear()
157 bool wxResourceSymbolTable::AddSymbol(const wxString
& symbol
, int id
)
159 m_hashTable
.Put(symbol
, (wxObject
*) id
);
163 bool wxResourceSymbolTable::RemoveSymbol(const wxString
& symbol
)
165 m_hashTable
.Delete(symbol
);
169 bool wxResourceSymbolTable::RemoveSymbol(int id
)
171 wxString
symbol(GetSymbolForId(id
));
172 m_hashTable
.Delete(symbol
);
177 wxString
wxResourceSymbolTable::GetSymbolForId(int id
)
179 m_hashTable
.BeginFind();
181 wxNode
* node
= m_hashTable
.Next();
184 char* str
= node
->key
.string
;
185 if (str
&& ( ((int) node
->Data()) == id
) )
186 return wxString(str
);
188 node
= m_hashTable
.Next();
193 int wxResourceSymbolTable::GetIdForSymbol(const wxString
& symbol
)
195 return (int) m_hashTable
.Get(symbol
);
198 bool wxResourceSymbolTable::SymbolExists(const wxString
& symbol
) const
200 return (m_hashTable
.Get(symbol
) != NULL
);
203 bool wxResourceSymbolTable::IdExists(int id
)
205 m_hashTable
.BeginFind();
207 wxNode
* node
= m_hashTable
.Next();
210 if ( (((int) node
->Data()) == id
) )
213 node
= m_hashTable
.Next();
218 int wxResourceSymbolTable::FindHighestId()
222 m_hashTable
.BeginFind();
224 wxNode
* node
= m_hashTable
.Next();
227 int id
= ((int) node
->Data());
231 node
= m_hashTable
.Next();
237 * A table of the standard identifiers
240 struct wxStandardSymbolStruct
246 static wxStandardSymbolStruct sg_StandardSymbols
[] =
248 { "wxID_OK", wxID_OK
},
249 { "wxID_CANCEL", wxID_CANCEL
},
250 { "wxID_APPLY", wxID_APPLY
},
251 // { "wxID_STATIC", wxID_STATIC },
252 { "wxID_YES", wxID_YES
},
253 { "wxID_NO", wxID_NO
}
256 static int sg_StandardSymbolSize
= (sizeof(sg_StandardSymbols
)/sizeof(wxStandardSymbolStruct
));
258 void wxResourceSymbolTable::AddStandardSymbols()
261 for (i
= 0; i
< sg_StandardSymbolSize
; i
++)
263 AddSymbol(sg_StandardSymbols
[i
].m_name
, sg_StandardSymbols
[i
].m_id
);
267 bool wxResourceSymbolTable::IsStandardSymbol(const wxString
& symbol
) const
270 for (i
= 0; i
< sg_StandardSymbolSize
; i
++)
272 if (symbol
== sg_StandardSymbols
[i
].m_name
)
278 bool wxResourceSymbolTable::FillComboBox(wxComboBox
* comboBox
)
280 m_hashTable
.BeginFind();
282 wxNode
* node
= m_hashTable
.Next();
285 char* str
= node
->key
.string
;
287 comboBox
->Append(str
);
288 node
= m_hashTable
.Next();