return FALSE;
}
- if (!m_resourceTable.ParseResourceFile(WXSTRINGCAST str))
+ if (!m_resourceTable.ParseResourceFile(str))
{
wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION);
return FALSE;
bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows), bool force)
{
+ wxPropertyInfo::CloseWindow();
+
if (!force && Modified())
{
int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
m_resourceAssociations.Put((long)resource, win);
wxNode *node = resource->GetChildren().First();
- while (node)
+ wxNode* node2 = win->GetChildren().First();
+ while (node && node2)
{
wxItemResource *child = (wxItemResource *)node->Data();
+ wxWindow* childWindow = (wxWindow*) node2->Data();
+
+ if (child->GetId() != childWindow->GetId())
+ {
+ wxString msg;
+ msg.Printf("AssociateResource: error when associating child window %ld with resource %ld", child->GetId(), childWindow->GetId());
+ wxMessageBox(msg, "Dialog Editor problem", wxOK);
+ }
+ else if (childWindow->GetName() != child->GetName())
+ {
+ wxString msg;
+ msg.Printf("AssociateResource: error when associating child window with resource %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)");
+ wxMessageBox(msg, "Dialog Editor problem", wxOK);
+ }
+ else
+ {
+ AssociateResource(child, childWindow);
+ }
+
+ // New code to avoid the problem of duplicate ids and names. We simply
+ // traverse the child windows and child resources in parallel,
+ // checking for any mismatch.
+#if 0
wxWindow *childWindow = (wxWindow *)m_resourceAssociations.Get((long)child);
if (!childWindow)
- childWindow = win->FindWindow(child->GetName());
+ // childWindow = win->FindWindow(child->GetName());
+ childWindow = win->FindWindow(child->GetId());
if (childWindow)
AssociateResource(child, childWindow);
else
{
- char buf[200];
- sprintf(buf, "AssociateResource: cannot find child window %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)");
- wxMessageBox(buf, "Dialog Editor problem", wxOK);
+ wxString msg;
+ msg.Printf("AssociateResource: cannot find child window %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)");
+ wxMessageBox(msg, "Dialog Editor problem", wxOK);
}
-
+#endif
node = node->Next();
+ node2 = node2->Next();
}
}
bool wxResourceManager::Edit(wxItemResource *res)
{
+ wxPropertyInfo::CloseWindow();
+
ClearCurrentDialog();
wxString resType(res->GetType());
bool wxResourceManager::CreateNewPanel()
{
+ wxPropertyInfo::CloseWindow();
+
ClearCurrentDialog();
char buf[256];
{
item->SetSize(-1, -1, firstW, firstH);
+ int fw = firstW;
+ int fh = firstH;
+
wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
{
wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH));
- firstW = sz.x; firstH = sz.y;
+ fw = sz.x; fh = sz.y;
}
- resource->SetSize(resource->GetX(), resource->GetY(), firstW, firstH);
+ resource->SetSize(resource->GetX(), resource->GetY(), fw, fh);
}
}
m_selections.DeleteObject(win);
}
+void wxResourceManager::DeselectItemIfNecessary(wxWindow *win)
+{
+ if (win->IsKindOf(CLASSINFO(wxControl)) && (win->GetEventHandler() != win))
+ {
+ // Deselect and refresh window in case we leave selection
+ // handles behind
+ wxControl *item = (wxControl *)win;
+ wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
+ if (childHandler->IsSelected())
+ {
+ wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item);
+ childHandler->SelectItem(FALSE);
+#ifndef __WXGTK__
+ item->GetParent()->Refresh();
+#endif
+ }
+ }
+}
+
// Need to search through resource table removing this from
// any resource which has this as a parent.
bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res)
bool wxResourceManager::DeleteResource(wxWindow *win)
{
- if (win->IsKindOf(CLASSINFO(wxControl)))
- {
- // Deselect and refresh window in case we leave selection
- // handles behind
- wxControl *item = (wxControl *)win;
- wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
- if (childHandler->IsSelected())
- {
- RemoveSelection(item);
- childHandler->SelectItem(FALSE);
-#ifndef __WXGTK__
- item->GetParent()->Refresh();
-#endif
- }
- }
+ DeselectItemIfNecessary(win);
wxItemResource *res = FindResourceForWindow(win);
// 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.
-wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info)
+wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info, bool instantiateFirst)
{
wxItemResource *resource = FindResourceForWindow(win);
info = newInfo;
}
- info->InstantiateResource(resource);
+ // May not always want to copy values back from the resource
+ if (instantiateFirst)
+ info->InstantiateResource(resource);
wxWindow *newWin = NULL;
wxWindow *parent = win->GetParent();
void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event)
{
+ wxPropertyInfo::CloseWindow();
if (manager->Modified())
{
if (!manager->Clear(TRUE, FALSE))
}
case OBJECT_MENU_DELETE:
{
+ wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data);
+
wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);