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 int 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 const char* str
= node
->GetKeyString();
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 const char* str
= node
->GetKeyString();
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();
234 // Make sure we don't clash with future standard wxWindows ids
235 if (highest
<= wxID_HIGHEST
)
236 highest
= wxID_HIGHEST
+ 1;
241 * A table of the standard identifiers
244 struct wxStandardSymbolStruct
250 static wxStandardSymbolStruct sg_StandardSymbols
[] =
252 { "wxID_OK", wxID_OK
},
253 { "wxID_CANCEL", wxID_CANCEL
},
254 { "wxID_APPLY", wxID_APPLY
},
255 { "wxID_HELP", wxID_HELP
},
256 { "wxID_STATIC", wxID_STATIC
},
257 { "wxID_YES", wxID_YES
},
258 { "wxID_NO", wxID_NO
},
260 { "wxID_OPEN", wxID_OPEN
},
261 { "wxID_CLOSE", wxID_CLOSE
},
262 { "wxID_NEW", wxID_NEW
},
263 { "wxID_SAVE", wxID_SAVE
},
264 { "wxID_SAVEAS", wxID_SAVEAS
},
265 { "wxID_REVERT", wxID_REVERT
},
266 { "wxID_EXIT", wxID_EXIT
},
267 { "wxID_UNDO", wxID_UNDO
},
268 { "wxID_REDO", wxID_REDO
},
269 { "wxID_PRINT", wxID_PRINT
},
270 { "wxID_PRINT_SETUP", wxID_PRINT_SETUP
},
271 { "wxID_PREVIEW", wxID_PREVIEW
},
272 { "wxID_ABOUT", wxID_ABOUT
},
273 { "wxID_HELP_CONTENTS", wxID_HELP_CONTENTS
},
274 { "wxID_HELP_COMMANDS", wxID_HELP_COMMANDS
},
275 { "wxID_HELP_PROCEDURES", wxID_HELP_PROCEDURES
},
276 { "wxID_HELP_CONTEXT", wxID_HELP_CONTEXT
},
278 { "wxID_CUT", wxID_CUT
},
279 { "wxID_COPY", wxID_COPY
},
280 { "wxID_PASTE", wxID_PASTE
},
281 { "wxID_CLEAR", wxID_CLEAR
},
282 { "wxID_FIND", wxID_FIND
},
283 { "wxID_DUPLICATE", wxID_DUPLICATE
},
285 { "wxID_FILE1", wxID_FILE1
},
286 { "wxID_FILE2", wxID_FILE2
},
287 { "wxID_FILE3", wxID_FILE3
},
288 { "wxID_FILE4", wxID_FILE4
},
289 { "wxID_FILE5", wxID_FILE5
},
290 { "wxID_FILE6", wxID_FILE6
},
291 { "wxID_FILE7", wxID_FILE7
},
292 { "wxID_FILE8", wxID_FILE8
},
293 { "wxID_FILE9", wxID_FILE9
}
297 static int sg_StandardSymbolSize
= (sizeof(sg_StandardSymbols
)/sizeof(wxStandardSymbolStruct
));
299 void wxResourceSymbolTable::AddStandardSymbols()
302 for (i
= 0; i
< sg_StandardSymbolSize
; i
++)
304 AddSymbol(sg_StandardSymbols
[i
].m_name
, sg_StandardSymbols
[i
].m_id
);
308 bool wxResourceSymbolTable::IsStandardSymbol(const wxString
& symbol
) const
311 for (i
= 0; i
< sg_StandardSymbolSize
; i
++)
313 if (symbol
== sg_StandardSymbols
[i
].m_name
)
319 bool wxResourceSymbolTable::FillComboBox(wxComboBox
* comboBox
)
321 m_hashTable
.BeginFind();
323 wxNode
* node
= m_hashTable
.Next();
326 const char* str
= node
->GetKeyString();
328 comboBox
->Append(str
);
329 node
= m_hashTable
.Next();