OGL fixes; documentation fixes; dialog editor updates
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@447 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -93,6 +93,7 @@ wxResourceManager::wxResourceManager():
|
||||
m_editorResourceTree = NULL;
|
||||
m_editorControlList = NULL;
|
||||
m_nameCounter = 1;
|
||||
m_symbolIdCounter = 99;
|
||||
m_modified = FALSE;
|
||||
m_currentFilename = "";
|
||||
m_symbolFilename = "";
|
||||
@@ -178,6 +179,8 @@ bool wxResourceManager::Initialize()
|
||||
m_imageList.Add(icon4);
|
||||
#endif
|
||||
|
||||
m_symbolTable.AddStandardSymbols();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -363,6 +366,8 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
|
||||
if (!Clear(TRUE, FALSE))
|
||||
return FALSE;
|
||||
|
||||
m_symbolTable.AddStandardSymbols();
|
||||
|
||||
if (loadFromFile)
|
||||
{
|
||||
wxString str = filename;
|
||||
@@ -389,46 +394,7 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
|
||||
// Construct include filename from this file
|
||||
m_symbolFilename = m_currentFilename;
|
||||
|
||||
if (m_symbolFilename[0] == 'c')
|
||||
{
|
||||
}
|
||||
|
||||
wxString stringA("123456.45");
|
||||
wxString stringB("");
|
||||
stringB = str;
|
||||
|
||||
size_t i = 0;
|
||||
char c = stringB[i];
|
||||
#if 0
|
||||
size_t len = stringB.Length();
|
||||
size_t i = len-1;
|
||||
while (i > 0)
|
||||
{
|
||||
// if (buffer.GetChar(i) == '.')
|
||||
if (stringB[i] == '.')
|
||||
{
|
||||
stringB = stringB.Left(i);
|
||||
break;
|
||||
}
|
||||
i --;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
size_t len = m_symbolFilename.Length();
|
||||
size_t i = len-1;
|
||||
while (i > 0)
|
||||
{
|
||||
// if (buffer.GetChar(i) == '.')
|
||||
if (m_symbolFilename[i] == '.')
|
||||
{
|
||||
m_symbolFilename = m_symbolFilename.Left(i);
|
||||
break;
|
||||
}
|
||||
i --;
|
||||
}
|
||||
#endif
|
||||
// wxStripExtension(m_symbolFilename);
|
||||
wxStripExtension(m_symbolFilename);
|
||||
m_symbolFilename += ".h";
|
||||
|
||||
if (!m_symbolTable.ReadIncludeFile(m_symbolFilename))
|
||||
@@ -436,6 +402,13 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
|
||||
wxString str("Could not find include file ");
|
||||
str += m_symbolFilename;
|
||||
wxMessageBox(str, "Dialog Editor Warning", MB_OK);
|
||||
|
||||
m_symbolIdCounter = 99;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the id counter to the last known id
|
||||
m_symbolIdCounter = m_symbolTable.FindHighestId();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -919,6 +892,14 @@ bool wxResourceManager::CreateNewPanel()
|
||||
resource->SetType("wxPanel");
|
||||
resource->SetName(buf);
|
||||
resource->SetTitle(buf);
|
||||
|
||||
wxString newIdName;
|
||||
int id = GenerateWindowId("ID_DIALOG", newIdName);
|
||||
resource->SetId(id);
|
||||
|
||||
// This is now guaranteed to be unique, so just add to symbol table
|
||||
m_symbolTable.AddSymbol(newIdName, id);
|
||||
|
||||
m_resourceTable.AddResource(resource);
|
||||
|
||||
wxPanel *panel = new wxPanel(m_editorPanel, -1,
|
||||
@@ -963,11 +944,14 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
wxControl *newItem = NULL;
|
||||
res->SetSize(x, y, -1, -1);
|
||||
res->SetType(iType);
|
||||
|
||||
wxString prefix;
|
||||
|
||||
wxString itemType(iType);
|
||||
|
||||
if (itemType == "wxButton")
|
||||
{
|
||||
prefix = "ID_BUTTON";
|
||||
MakeUniqueName("button", buf);
|
||||
res->SetName(buf);
|
||||
if (isBitmap)
|
||||
@@ -977,12 +961,14 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
if (itemType == "wxBitmapButton")
|
||||
{
|
||||
prefix = "ID_BITMAPBUTTON";
|
||||
MakeUniqueName("button", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxMessage" || itemType == "wxStaticText")
|
||||
{
|
||||
prefix = "ID_STATIC";
|
||||
MakeUniqueName("message", buf);
|
||||
res->SetName(buf);
|
||||
if (isBitmap)
|
||||
@@ -992,24 +978,28 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
else if (itemType == "wxStaticBitmap")
|
||||
{
|
||||
prefix = "ID_STATICBITMAP";
|
||||
MakeUniqueName("message", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf);
|
||||
}
|
||||
else if (itemType == "wxCheckBox")
|
||||
{
|
||||
prefix = "ID_CHECKBOX";
|
||||
MakeUniqueName("checkbox", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxListBox")
|
||||
{
|
||||
prefix = "ID_LISTBIX";
|
||||
MakeUniqueName("listbox", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxRadioBox")
|
||||
{
|
||||
prefix = "ID_RADIOBOX";
|
||||
MakeUniqueName("radiobox", buf);
|
||||
res->SetName(buf);
|
||||
wxString names[] = { "One", "Two" };
|
||||
@@ -1019,6 +1009,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
else if (itemType == "wxRadioButton")
|
||||
{
|
||||
prefix = "ID_RADIOBUTTON";
|
||||
MakeUniqueName("radiobutton", buf);
|
||||
res->SetName(buf);
|
||||
wxString names[] = { "One", "Two" };
|
||||
@@ -1027,30 +1018,35 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
else if (itemType == "wxChoice")
|
||||
{
|
||||
prefix = "ID_CHOICE";
|
||||
MakeUniqueName("choice", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxGroupBox" || itemType == "wxStaticBox")
|
||||
{
|
||||
prefix = "ID_STATICBOX";
|
||||
MakeUniqueName("group", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxStaticBox(panel, -1, "Groupbox", wxPoint(x, y), wxSize(200, 200), 0, buf);
|
||||
}
|
||||
else if (itemType == "wxGauge")
|
||||
{
|
||||
prefix = "ID_GAUGE";
|
||||
MakeUniqueName("gauge", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxSlider")
|
||||
{
|
||||
prefix = "ID_SLIDER";
|
||||
MakeUniqueName("slider", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf);
|
||||
}
|
||||
else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)")
|
||||
{
|
||||
prefix = "ID_TEXTCTRL";
|
||||
MakeUniqueName("textctrl", buf);
|
||||
res->SetName(buf);
|
||||
res->SetType("wxTextCtrl");
|
||||
@@ -1058,6 +1054,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)")
|
||||
{
|
||||
prefix = "ID_TEXTCTRL";
|
||||
MakeUniqueName("textctrl", buf);
|
||||
res->SetName(buf);
|
||||
res->SetType("wxTextCtrl");
|
||||
@@ -1065,6 +1062,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
}
|
||||
else if (itemType == "wxScrollBar")
|
||||
{
|
||||
prefix = "ID_SCROLLBAR";
|
||||
MakeUniqueName("scrollbar", buf);
|
||||
res->SetName(buf);
|
||||
newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf);
|
||||
@@ -1072,6 +1070,13 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
|
||||
if (!newItem)
|
||||
return FALSE;
|
||||
|
||||
wxString newIdName;
|
||||
int id = GenerateWindowId(prefix, newIdName);
|
||||
res->SetId(id);
|
||||
|
||||
// This is now guaranteed to be unique, so just add to symbol table
|
||||
m_symbolTable.AddSymbol(newIdName, id);
|
||||
|
||||
newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem));
|
||||
|
||||
res->SetStyle(newItem->GetWindowStyleFlag());
|
||||
@@ -1350,6 +1355,12 @@ bool wxResourceManager::DeleteResource(wxItemResource *res)
|
||||
PossiblyDeleteBitmapResource(res->GetValue4());
|
||||
}
|
||||
|
||||
// Remove symbol from table if appropriate
|
||||
if (!IsSymbolUsed(res, res->GetId()))
|
||||
{
|
||||
m_symbolTable.RemoveSymbol(res->GetId());
|
||||
}
|
||||
|
||||
m_resourceTable.Delete(res->GetName());
|
||||
delete res;
|
||||
Modify(TRUE);
|
||||
@@ -1499,6 +1510,78 @@ wxItemResource *wxResourceManager::FindBitmapResourceByFilename(char *filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Is this window identifier symbol in use?
|
||||
// Let's assume that we can't have 2 names for the same integer id.
|
||||
// Therefore we can tell by the integer id whether the symbol is
|
||||
// in use.
|
||||
bool wxResourceManager::IsSymbolUsed(wxItemResource* thisResource, wxWindowID id)
|
||||
{
|
||||
m_resourceTable.BeginFind();
|
||||
wxNode *node;
|
||||
while (node = m_resourceTable.Next())
|
||||
{
|
||||
wxItemResource *res = (wxItemResource *)node->Data();
|
||||
if ((res != thisResource) && (res->GetId() == id))
|
||||
return TRUE;
|
||||
|
||||
wxString resType(res->GetType());
|
||||
if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
|
||||
{
|
||||
wxNode *node1 = res->GetChildren().First();
|
||||
while (node1)
|
||||
{
|
||||
wxItemResource *child = (wxItemResource *)node1->Data();
|
||||
if ((child != thisResource) && (child->GetId() == id))
|
||||
return TRUE;
|
||||
node1 = node1->Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is this window identifier compatible with the given name? (i.e.
|
||||
// does it already exist under a different name)
|
||||
bool wxResourceManager::IsIdentifierOK(const wxString& name, wxWindowID id)
|
||||
{
|
||||
if (m_symbolTable.SymbolExists(name))
|
||||
{
|
||||
int foundId = m_symbolTable.GetIdForSymbol(name);
|
||||
if (foundId != id)
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Change all integer ids that match oldId, to newId.
|
||||
// This is necessary if an id is changed for one resource - all resources
|
||||
// must be changed.
|
||||
void wxResourceManager::ChangeIds(int oldId, int newId)
|
||||
{
|
||||
m_resourceTable.BeginFind();
|
||||
wxNode *node;
|
||||
while (node = m_resourceTable.Next())
|
||||
{
|
||||
wxItemResource *res = (wxItemResource *)node->Data();
|
||||
if (res->GetId() == oldId)
|
||||
res->SetId(newId);
|
||||
|
||||
wxString resType(res->GetType());
|
||||
if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
|
||||
{
|
||||
wxNode *node1 = res->GetChildren().First();
|
||||
while (node1)
|
||||
{
|
||||
wxItemResource *child = (wxItemResource *)node1->Data();
|
||||
if (child->GetId() == oldId)
|
||||
child->SetId(newId);
|
||||
|
||||
node1 = node1->Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deletes 'win' and creates a new window from the resource that
|
||||
// was associated with it. E.g. if you can't change properties on the
|
||||
// fly, you'll need to delete the window and create it again.
|
||||
@@ -1735,6 +1818,29 @@ void wxResourceManager::EditWindow(wxWindow *win)
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a window id and a first stab at a name
|
||||
int wxResourceManager::GenerateWindowId(const wxString& prefix, wxString& idName)
|
||||
{
|
||||
m_symbolIdCounter ++;
|
||||
while (m_symbolTable.IdExists(m_symbolIdCounter))
|
||||
m_symbolIdCounter ++;
|
||||
|
||||
int nameId = m_symbolIdCounter;
|
||||
|
||||
wxString str;
|
||||
str.Printf("%d", nameId);
|
||||
idName = prefix + str;
|
||||
|
||||
while (m_symbolTable.SymbolExists(idName))
|
||||
{
|
||||
nameId ++;
|
||||
str.Printf("%d", nameId);
|
||||
idName = prefix + str;
|
||||
}
|
||||
|
||||
return m_symbolIdCounter;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Resource editor frame
|
||||
|
@@ -220,6 +220,18 @@ public:
|
||||
|
||||
char *FindBitmapFilenameForResource(wxItemResource *resource);
|
||||
|
||||
// Is this window identifier in use?
|
||||
bool IsSymbolUsed(wxItemResource* thisResource, wxWindowID id) ;
|
||||
|
||||
// Is this window identifier compatible with the given name? (i.e.
|
||||
// does it already exist under a different name)
|
||||
bool IsIdentifierOK(const wxString& name, wxWindowID id);
|
||||
|
||||
// Change all integer ids that match oldId, to newId.
|
||||
// This is necessary if an id is changed for one resource - all resources
|
||||
// must be changed.
|
||||
void ChangeIds(int oldId, int newId);
|
||||
|
||||
// Deletes 'win' and creates a new window from the resource that
|
||||
// was associated with it. E.g. if you can't change properties on the
|
||||
// fly, you'll need to delete the window and create it again.
|
||||
@@ -275,6 +287,11 @@ public:
|
||||
inline wxRect& GetPropertyWindowSize() { return m_propertyWindowSize; }
|
||||
inline wxRect& GetResourceEditorWindowSize() { return m_resourceEditorWindowSize; }
|
||||
|
||||
wxResourceSymbolTable& GetSymbolTable() { return m_symbolTable; }
|
||||
|
||||
// Generate a window id and a first stab at a name
|
||||
int GenerateWindowId(const wxString& prefix, wxString& idName) ;
|
||||
|
||||
// Member variables
|
||||
protected:
|
||||
wxHelpController* m_helpController;
|
||||
@@ -286,6 +303,7 @@ public:
|
||||
wxResourceEditorControlList* m_editorControlList;
|
||||
EditorToolBar* m_editorToolBar;
|
||||
int m_nameCounter;
|
||||
int m_symbolIdCounter; // For generating window ids
|
||||
bool m_modified;
|
||||
wxHashTable m_resourceAssociations;
|
||||
wxList m_selections;
|
||||
|
@@ -46,6 +46,9 @@ wxResourceSymbolTable::~wxResourceSymbolTable()
|
||||
bool wxResourceSymbolTable::ReadIncludeFile(const wxString& filename)
|
||||
{
|
||||
wxFile file;
|
||||
if (!wxFileExists(filename))
|
||||
return FALSE;
|
||||
|
||||
if (!file.Open(filename, wxFile::read))
|
||||
return FALSE;
|
||||
|
||||
@@ -53,10 +56,13 @@ bool wxResourceSymbolTable::ReadIncludeFile(const wxString& filename)
|
||||
if (len == -1)
|
||||
return FALSE;
|
||||
|
||||
Clear();
|
||||
AddStandardSymbols();
|
||||
|
||||
wxString str;
|
||||
char* p = str.GetWriteBuf(len + 1);
|
||||
|
||||
if (file.Read(p, len) == ofsInvalid)
|
||||
if (file.Read(p, len) == wxFile::fd_invalid)
|
||||
{
|
||||
str.UngetWriteBuf();
|
||||
return FALSE;
|
||||
@@ -98,7 +104,7 @@ bool wxResourceSymbolTable::ReadIncludeFile(const wxString& filename)
|
||||
|
||||
wxString numStr(str.Mid(startNum, (endNum - startNum + 1)));
|
||||
|
||||
long id = atol(numStr);
|
||||
int id = atol(numStr);
|
||||
|
||||
AddSymbol(symbol, id);
|
||||
|
||||
@@ -121,12 +127,15 @@ bool wxResourceSymbolTable::WriteIncludeFile(const wxString& filename)
|
||||
while (node)
|
||||
{
|
||||
char* str = node->key.string;
|
||||
long id = (long) node->Data() ;
|
||||
int id = (int) node->Data() ;
|
||||
|
||||
wxString line;
|
||||
line.Printf("#define %s %ld\n", str, id);
|
||||
if (!IsStandardSymbol(str))
|
||||
{
|
||||
wxString line;
|
||||
line.Printf("#define %s %ld\n", str, id);
|
||||
|
||||
file.Write(line, line.Length());
|
||||
file.Write(line, line.Length());
|
||||
}
|
||||
|
||||
node = m_hashTable.Next();
|
||||
}
|
||||
@@ -138,14 +147,27 @@ void wxResourceSymbolTable::Clear()
|
||||
m_hashTable.Clear();
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::AddSymbol(const wxString& symbol, long id)
|
||||
bool wxResourceSymbolTable::AddSymbol(const wxString& symbol, int id)
|
||||
{
|
||||
m_hashTable.Put(symbol, (wxObject*) id);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::RemoveSymbol(const wxString& symbol)
|
||||
{
|
||||
m_hashTable.Delete(symbol);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::RemoveSymbol(int id)
|
||||
{
|
||||
wxString symbol(GetSymbolForId(id));
|
||||
m_hashTable.Delete(symbol);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
wxString wxResourceSymbolTable::GetSymbolForId(long id)
|
||||
wxString wxResourceSymbolTable::GetSymbolForId(int id)
|
||||
{
|
||||
m_hashTable.BeginFind();
|
||||
|
||||
@@ -153,7 +175,7 @@ wxString wxResourceSymbolTable::GetSymbolForId(long id)
|
||||
while (node)
|
||||
{
|
||||
char* str = node->key.string;
|
||||
if (str && ( ((long) node->Data()) == id) )
|
||||
if (str && ( ((int) node->Data()) == id) )
|
||||
return wxString(str);
|
||||
|
||||
node = m_hashTable.Next();
|
||||
@@ -161,9 +183,9 @@ wxString wxResourceSymbolTable::GetSymbolForId(long id)
|
||||
return wxString("");
|
||||
}
|
||||
|
||||
long wxResourceSymbolTable::GetIdForSymbol(const wxString& symbol)
|
||||
int wxResourceSymbolTable::GetIdForSymbol(const wxString& symbol)
|
||||
{
|
||||
return (long) m_hashTable.Get(symbol);
|
||||
return (int) m_hashTable.Get(symbol);
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::SymbolExists(const wxString& symbol) const
|
||||
@@ -171,3 +193,93 @@ bool wxResourceSymbolTable::SymbolExists(const wxString& symbol) const
|
||||
return (m_hashTable.Get(symbol) != NULL);
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::IdExists(int id)
|
||||
{
|
||||
m_hashTable.BeginFind();
|
||||
|
||||
wxNode* node = m_hashTable.Next();
|
||||
while (node)
|
||||
{
|
||||
if ( (((int) node->Data()) == id) )
|
||||
return TRUE;
|
||||
|
||||
node = m_hashTable.Next();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int wxResourceSymbolTable::FindHighestId()
|
||||
{
|
||||
int highest = 0;
|
||||
|
||||
m_hashTable.BeginFind();
|
||||
|
||||
wxNode* node = m_hashTable.Next();
|
||||
while (node)
|
||||
{
|
||||
int id = ((int) node->Data());
|
||||
if (id > highest)
|
||||
highest = id;
|
||||
|
||||
node = m_hashTable.Next();
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
|
||||
/*
|
||||
* A table of the standard identifiers
|
||||
*/
|
||||
|
||||
struct wxStandardSymbolStruct
|
||||
{
|
||||
char* m_name;
|
||||
int m_id;
|
||||
};
|
||||
|
||||
static wxStandardSymbolStruct sg_StandardSymbols[] =
|
||||
{
|
||||
{ "wxID_OK", wxID_OK },
|
||||
{ "wxID_CANCEL", wxID_CANCEL },
|
||||
{ "wxID_APPLY", wxID_APPLY },
|
||||
// { "wxID_STATIC", wxID_STATIC },
|
||||
{ "wxID_YES", wxID_YES },
|
||||
{ "wxID_NO", wxID_NO }
|
||||
};
|
||||
|
||||
static int sg_StandardSymbolSize = (sizeof(sg_StandardSymbols)/sizeof(wxStandardSymbolStruct));
|
||||
|
||||
void wxResourceSymbolTable::AddStandardSymbols()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sg_StandardSymbolSize; i++)
|
||||
{
|
||||
AddSymbol(sg_StandardSymbols[i].m_name, sg_StandardSymbols[i].m_id);
|
||||
}
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::IsStandardSymbol(const wxString& symbol) const
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sg_StandardSymbolSize; i++)
|
||||
{
|
||||
if (symbol == sg_StandardSymbols[i].m_name)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxResourceSymbolTable::FillComboBox(wxComboBox* comboBox)
|
||||
{
|
||||
m_hashTable.BeginFind();
|
||||
|
||||
wxNode* node = m_hashTable.Next();
|
||||
while (node)
|
||||
{
|
||||
char* str = node->key.string;
|
||||
|
||||
comboBox->Append(str);
|
||||
node = m_hashTable.Next();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -26,12 +26,19 @@ public:
|
||||
bool ReadIncludeFile(const wxString& filename);
|
||||
bool WriteIncludeFile(const wxString& filename);
|
||||
void Clear();
|
||||
bool AddSymbol(const wxString& symbol, long id);
|
||||
bool AddSymbol(const wxString& symbol, int id);
|
||||
bool RemoveSymbol(const wxString& symbol);
|
||||
bool RemoveSymbol(int id);
|
||||
void AddStandardSymbols();
|
||||
bool FillComboBox(wxComboBox* comboBox);
|
||||
|
||||
// Accessors
|
||||
wxString GetSymbolForId(long id);
|
||||
long GetIdForSymbol(const wxString& symbol);
|
||||
wxString GetSymbolForId(int id);
|
||||
int GetIdForSymbol(const wxString& symbol);
|
||||
bool SymbolExists(const wxString& symbol) const;
|
||||
bool IdExists(int id) ;
|
||||
bool IsStandardSymbol(const wxString& symbol) const;
|
||||
int FindHighestId() ;
|
||||
|
||||
// Implementation
|
||||
|
||||
|
@@ -292,8 +292,20 @@ wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name)
|
||||
}
|
||||
else if (name == "id")
|
||||
{
|
||||
wxString symbolName("TODO");
|
||||
return new wxProperty("id", symbolName, "window_id");
|
||||
wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
|
||||
if (resource)
|
||||
{
|
||||
int id = resource->GetId();
|
||||
wxString idStr;
|
||||
idStr.Printf("%d", id);
|
||||
wxString symbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id);
|
||||
symbolName += "=";
|
||||
symbolName += idStr;
|
||||
// symbolName is now e.g. "ID_PANEL21=105"
|
||||
return new wxProperty("id", symbolName, "window_id");
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
@@ -389,8 +401,77 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property)
|
||||
}
|
||||
else if (name == "id")
|
||||
{
|
||||
// TODO
|
||||
return TRUE;
|
||||
wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
|
||||
if (resource)
|
||||
{
|
||||
wxString value = property->GetValue().StringValue();
|
||||
|
||||
wxString strName = value.Before('=');
|
||||
wxString strId = value.After('=');
|
||||
int id = atoi(strId);
|
||||
|
||||
wxString oldSymbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource->GetId());
|
||||
int oldSymbolId = resource->GetId();
|
||||
|
||||
if (strName != "")
|
||||
{
|
||||
// If we change the id for an existing symbol, we need to:
|
||||
// 1) Check if there are any other resources currently using the original id.
|
||||
// If so, will need to change their id to the new id.
|
||||
// 2) Remove the old symbol, add the new symbol.
|
||||
// In this check, we don't have to do this, but we need to do it in SetProperty.
|
||||
|
||||
if (strName == oldSymbolName && id != oldSymbolId)
|
||||
{
|
||||
wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
|
||||
|
||||
// It's OK to change just the id. But we'll need to change all matching ids in all resources,
|
||||
// because ids are unique and changing one resource's id must change all identical ones.
|
||||
wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId, id);
|
||||
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
|
||||
}
|
||||
|
||||
// If we change the name but not the id, we'll just need to remove and
|
||||
// re-add the symbol/id pair.
|
||||
if (strName != oldSymbolName && id == oldSymbolId)
|
||||
{
|
||||
wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
|
||||
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
|
||||
|
||||
if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
|
||||
{
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
|
||||
}
|
||||
}
|
||||
|
||||
// What if we're changing both the name and the id?
|
||||
// - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
|
||||
// - if there is a symbol of that name, if id matches, do nothing. If not, veto.
|
||||
|
||||
if (strName != oldSymbolName && id != oldSymbolId)
|
||||
{
|
||||
// Remove old symbol if it's not being used
|
||||
if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource, oldSymbolId) &&
|
||||
!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName))
|
||||
{
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
|
||||
}
|
||||
|
||||
if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
|
||||
{
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
|
||||
}
|
||||
}
|
||||
resource->SetId(id);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
@@ -1778,21 +1859,26 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView
|
||||
|
||||
wxResourceSymbolDialog* dialog = new wxResourceSymbolDialog(parentWindow, -1, "Edit Symbol");
|
||||
|
||||
dialog->SetSymbol(property->GetValue().StringValue());
|
||||
// Split name/id pair e.g. "IDC_TEXT=123"
|
||||
wxString value(property->GetValue().StringValue());
|
||||
|
||||
// TODO: split name/id pair e.g. "IDC_TEXT=123" or get from symbol table - which?
|
||||
dialog->SetId(1234);
|
||||
wxString strName = value.Before('=');
|
||||
wxString strId = value.After('=');
|
||||
|
||||
dialog->SetSymbol(strName);
|
||||
dialog->SetId(atoi(strId));
|
||||
|
||||
dialog->Init();
|
||||
|
||||
if (dialog->ShowModal())
|
||||
if (dialog->ShowModal() == wxID_OK)
|
||||
{
|
||||
wxString symbolName(dialog->GetSymbol());
|
||||
long id = dialog->GetId();
|
||||
dialog->Destroy();
|
||||
|
||||
// TODO: set id somewhere
|
||||
property->GetValue() = wxString(symbolName);
|
||||
wxString str;
|
||||
str.Printf("%d", id);
|
||||
property->GetValue() = symbolName + wxString("=") + str;
|
||||
|
||||
view->DisplayProperty(property);
|
||||
view->UpdatePropertyDisplayInList(property);
|
||||
@@ -1820,6 +1906,8 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView
|
||||
|
||||
BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog)
|
||||
EVT_BUTTON(wxID_OK, wxResourceSymbolDialog::OnOK)
|
||||
EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnComboBoxSelect)
|
||||
EVT_TEXT(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnSymbolNameUpdate)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos,
|
||||
@@ -1848,10 +1936,10 @@ wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowI
|
||||
|
||||
y += 30;
|
||||
x = 5;
|
||||
(void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(90, -1));
|
||||
(void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(80, -1));
|
||||
|
||||
x += 120;
|
||||
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(90, -1));
|
||||
x += 100;
|
||||
(void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(80, -1));
|
||||
|
||||
Fit();
|
||||
Centre();
|
||||
@@ -1864,6 +1952,8 @@ void wxResourceSymbolDialog::Init()
|
||||
|
||||
m_nameCtrl->SetValue(m_symbolName);
|
||||
m_idCtrl->SetValue(defaultId);
|
||||
|
||||
wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl);
|
||||
}
|
||||
|
||||
void wxResourceSymbolDialog::OnOK(wxCommandEvent& event)
|
||||
@@ -1876,6 +1966,124 @@ void wxResourceSymbolDialog::OnOK(wxCommandEvent& event)
|
||||
|
||||
bool wxResourceSymbolDialog::CheckValues()
|
||||
{
|
||||
wxString nameStr(m_nameCtrl->GetValue());
|
||||
wxString idStr(m_idCtrl->GetValue());
|
||||
int id = atoi(idStr);
|
||||
|
||||
if (id <= 0 )
|
||||
{
|
||||
wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
if (nameStr == "")
|
||||
{
|
||||
wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
if (nameStr.Contains(" "))
|
||||
{
|
||||
wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
if (nameStr.Contains("="))
|
||||
{
|
||||
wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
if (nameStr.IsNumber())
|
||||
{
|
||||
wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
// TODO: other checks on the name syntax.
|
||||
|
||||
if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr))
|
||||
{
|
||||
// If we change the id for an existing symbol, we need to:
|
||||
// 1) Check if there are any other resources currently using the original id.
|
||||
// If so, will need to change their id to the new id, in SetProperty.
|
||||
// 2) Remove the old symbol, add the new symbol.
|
||||
// In this check, we don't have to do this, but we need to do it in SetProperty.
|
||||
|
||||
if (nameStr == GetSymbol() && id != GetId())
|
||||
{
|
||||
// It's OK to change the id. But we'll need to change all matching ids in all resources,
|
||||
// in SetProperty.
|
||||
}
|
||||
|
||||
// If we change the name but not the id... we'll just need to remove and
|
||||
// re-add the symbol/id pair, in SetProperty.
|
||||
if (nameStr != GetSymbol() && id == GetId())
|
||||
{
|
||||
}
|
||||
|
||||
// What if we're changing both the name and the id?
|
||||
// - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
|
||||
// - if there is a symbol of that name, if id matches, do nothing. If not, veto.
|
||||
|
||||
if (nameStr != GetSymbol() && id != GetId())
|
||||
{
|
||||
if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr, id))
|
||||
{
|
||||
wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
|
||||
"Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SetSymbol(nameStr);
|
||||
SetId(id);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent& event)
|
||||
{
|
||||
wxString str(m_nameCtrl->GetValue());
|
||||
if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
|
||||
{
|
||||
int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
|
||||
wxString str2;
|
||||
str2.Printf("%d", id);
|
||||
m_idCtrl->SetValue(str2);
|
||||
m_idCtrl->Enable(FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
|
||||
{
|
||||
int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
|
||||
wxString str2;
|
||||
str2.Printf("%d", id);
|
||||
m_idCtrl->SetValue(str2);
|
||||
}
|
||||
m_idCtrl->Enable(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent& event)
|
||||
{
|
||||
wxString str(m_nameCtrl->GetValue());
|
||||
if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
|
||||
{
|
||||
int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
|
||||
wxString str2;
|
||||
str2.Printf("%d", id);
|
||||
m_idCtrl->SetValue(str2);
|
||||
m_idCtrl->Enable(FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
|
||||
{
|
||||
int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
|
||||
wxString str2;
|
||||
str2.Printf("%d", id);
|
||||
m_idCtrl->SetValue(str2);
|
||||
}
|
||||
m_idCtrl->Enable(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -367,7 +367,7 @@ class wxResourceSymbolDialog: public wxDialog
|
||||
public:
|
||||
wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE);
|
||||
const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
|
||||
|
||||
void Init();
|
||||
|
||||
@@ -379,6 +379,8 @@ public:
|
||||
|
||||
bool CheckValues();
|
||||
void OnOK(wxCommandEvent& event);
|
||||
void OnComboBoxSelect(wxCommandEvent& event);
|
||||
void OnSymbolNameUpdate(wxCommandEvent& event);
|
||||
|
||||
protected:
|
||||
wxString m_symbolName;
|
||||
|
Reference in New Issue
Block a user