]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reseditr.cpp
1. configre/makefiles changes
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
index 6ec0f160a3889e3d2022190f00a91555a102c5ce..14166498d43d6b92155859a374513cfa0c4433cc 100644 (file)
@@ -427,7 +427,7 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
         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;
@@ -486,6 +486,8 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
 
 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);
@@ -527,22 +529,48 @@ void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *wi
     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();
   }
 }
 
@@ -901,6 +929,8 @@ bool wxResourceManager::EditSelectedResource()
 
 bool wxResourceManager::Edit(wxItemResource *res)
 {
+  wxPropertyInfo::CloseWindow();
+
   ClearCurrentDialog();
 
   wxString resType(res->GetType());
@@ -940,6 +970,8 @@ bool wxResourceManager::Edit(wxItemResource *res)
 
 bool wxResourceManager::CreateNewPanel()
 {
+  wxPropertyInfo::CloseWindow();
+
   ClearCurrentDialog();
 
   char buf[256];
@@ -1363,6 +1395,9 @@ void wxResourceManager::CopySize()
        {
       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());
 
@@ -1372,9 +1407,9 @@ void wxResourceManager::CopySize()
          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);
 
        }
   }
@@ -1427,6 +1462,25 @@ void wxResourceManager::RemoveSelection(wxWindow *win)
   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)
@@ -1486,21 +1540,7 @@ bool wxResourceManager::DeleteResource(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);
   
@@ -1771,7 +1811,7 @@ bool wxResourceManager::RepairResourceIds()
  // 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);
 
@@ -1784,7 +1824,9 @@ wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowP
     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();
@@ -2143,6 +2185,7 @@ void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event))
 
 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event)
 {
+  wxPropertyInfo::CloseWindow();
   if (manager->Modified())
   {
      if (!manager->Clear(TRUE, FALSE))
@@ -2241,6 +2284,8 @@ void ObjectMenuProc(wxMenu *menu, wxCommandEvent& event)
     }
     case OBJECT_MENU_DELETE:
     {
+      wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data);
+
       wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
       wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
       wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);