]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reseditr.cpp
Some things added
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
index a5f3709768539b682e17dcf9cfee418dbf35fa3a..e6a647f698aadb287baee1ffd0db5a6b943aad69 100644 (file)
 #include <math.h>
 #include <string.h>
 
-#if wxUSE_IOSTREAMH
-#if defined(__WXMSW__) && !defined(__GNUWIN32__)
-#include <strstrea.h>
-#else
-#include <strstream.h>
-#endif
-#else
-#include <strstream>
-#endif
-
-#ifdef __WXMSW__
-#include <windows.h>
-#endif
-
 #ifdef __WXMSW__
 #include "wx/help.h"
 #endif
@@ -68,7 +54,6 @@
 #include "edtree.h"
 #include "edlist.h"
 
-static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event);
 wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 
 #if defined(__WXGTK__) || defined(__WXMOTIF__)
@@ -152,12 +137,13 @@ wxResourceManager::~wxResourceManager()
 bool wxResourceManager::Initialize()
 {
   // Set up the resource filename for each platform.
+  // TODO: This shold be replaced by wxConfig usage.
 #ifdef __WXMSW__
   // dialoged.ini in the Windows directory
-  char buf[256];
-  GetWindowsDirectory(buf, 256);
-  strcat(buf, "\\dialoged.ini");
-  m_optionsResourceFilename = buf;
+  wxString windowsDir = wxGetOSDirectory();
+  windowsDir += "\\dialoged.ini" ;
+
+  m_optionsResourceFilename = windowsDir;
 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
   wxGetHomeDir( &m_optionsResourceFilename );
   m_optionsResourceFilename += "/.dialogedrc";
@@ -172,7 +158,7 @@ bool wxResourceManager::Initialize()
   m_helpController->Initialize("dialoged");
 #endif
 
-  m_popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc);
+  m_popupMenu = new wxMenu;
   m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties");
   m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object");
 
@@ -238,14 +224,14 @@ bool wxResourceManager::SaveOptions()
 {
   wxConfig config("DialogEd", "wxWindows");
 
-  config.Write("editorWindowX", m_resourceEditorWindowSize.x);
-  config.Write("editorWindowY", m_resourceEditorWindowSize.y);
-  config.Write("editorWindowWidth", m_resourceEditorWindowSize.width);
-  config.Write("editorWindowHeight", m_resourceEditorWindowSize.height);
-  config.Write("propertyWindowX", m_propertyWindowSize.x);
-  config.Write("propertyWindowY", m_propertyWindowSize.y);
-  config.Write("propertyWindowWidth", m_propertyWindowSize.width);
-  config.Write("propertyWindowHeight", m_propertyWindowSize.height);
+  config.Write("editorWindowX", (long) m_resourceEditorWindowSize.x);
+  config.Write("editorWindowY", (long) m_resourceEditorWindowSize.y);
+  config.Write("editorWindowWidth", (long) m_resourceEditorWindowSize.width);
+  config.Write("editorWindowHeight", (long) m_resourceEditorWindowSize.height);
+  config.Write("propertyWindowX", (long) m_propertyWindowSize.x);
+  config.Write("propertyWindowY", (long) m_propertyWindowSize.y);
+  config.Write("propertyWindowWidth", (long) m_propertyWindowSize.width);
+  config.Write("propertyWindowHeight", (long) m_propertyWindowSize.height);
   /*
   wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
   wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
@@ -323,7 +309,7 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent)
     c->bottom.SameAs     (m_editorFrame, wxBottom, 0);
     c->width.Unconstrained();
 #if defined(__WXGTK__) || defined(__WXMOTIF__)
-    c->height.Absolute(105);
+    c->height.Absolute(120);
 #else
     c->height.Absolute(60);
 #endif
@@ -339,11 +325,8 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent)
   }
   else
   {
-    wxFrame *fr = m_editorFrame;
-    if (m_editorFrame->OnClose())
+    if (m_editorFrame->Close())
     {
-      fr->Show(FALSE);
-      delete fr;
       m_editorFrame = NULL;
       m_editorPanel = NULL;
     }
@@ -394,7 +377,7 @@ bool wxResourceManager::Save(const wxString& filename)
 bool wxResourceManager::SaveAs()
 {
   wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename),
-    "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT));
+    "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow()));
     
   if (s.IsNull() || s == "")
     return FALSE;
@@ -437,14 +420,14 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
     wxString str = filename;
     if (str == wxString(""))
     {
-      wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, NULL));
+      wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow()));
       if (!f.IsNull() && f != "")
         str = f;
       else
         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;
@@ -544,22 +527,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();
   }
 }
 
@@ -1380,6 +1389,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());
 
@@ -1389,9 +1401,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);
 
        }
   }
@@ -1503,12 +1515,15 @@ bool wxResourceManager::DeleteResource(wxItemResource *res)
 
 bool wxResourceManager::DeleteResource(wxWindow *win)
 {
-  if (win->IsKindOf(CLASSINFO(wxControl)))
+  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();
+
+    wxASSERT_MSG( win->GetEventHandler()->IsKindOf(CLASSINFO(wxResourceEditorControlHandler)), "Wrong kind of handler in DeleteResource" );
+
     if (childHandler->IsSelected())
     {
       RemoveSelection(item);
@@ -1618,7 +1633,7 @@ wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resour
     wxItemResource *child = (wxItemResource *)node->Data();
     return child->GetName();
     
-    node = node->Next();
+    //node = node->Next();
   }
   return wxEmptyString;
 }
@@ -2076,6 +2091,7 @@ BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame)
     EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection)
     EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection)
     EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest)
+    EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow)
 END_EVENT_TABLE()
 
 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
@@ -2128,7 +2144,7 @@ void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event))
 void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
       char buf[300];
-      sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION);
+      sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION);
       wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE);
 }
 
@@ -2157,15 +2173,18 @@ void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event))
       manager->RecreateSelection();
 }
 
-bool wxResourceEditorFrame::OnClose()
+void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event)
 {
   if (manager->Modified())
   {
-  if (!manager->Clear(TRUE, FALSE))
-     return FALSE;
+     if (!manager->Clear(TRUE, FALSE))
+     {
+       event.Veto();
+       return;
+    }
   }
     
-  if (!Iconized())
+  if (!IsIconized())
   {
     int w, h;
     GetSize(&w, &h);
@@ -2181,7 +2200,7 @@ bool wxResourceEditorFrame::OnClose()
   manager->SetEditorFrame(NULL);
   manager->SetEditorToolBar(NULL);
 
-  return TRUE;
+  this->Destroy();
 }
 
 /*
@@ -2189,7 +2208,6 @@ bool wxResourceEditorFrame::OnClose()
  */
 
 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow)
-    EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll)
     EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint)
 END_EVENT_TABLE()
 
@@ -2208,17 +2226,6 @@ wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
 {
 }
 
-void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent& event)
-{
-    wxScrolledWindow::OnScroll(event);
-
-    int x, y;
-    ViewStart(& x, & y);
-
-    if (m_childWindow)
-        m_childWindow->Move(m_marginX + (- x * 10), m_marginY + (- y * 10));
-}
-
 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
     wxPaintDC dc(this);
@@ -2251,9 +2258,9 @@ void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc)
 }
 
 // Popup menu callback
-void ObjectMenuProc(wxMenumenu, wxCommandEvent& event)
+void ObjectMenuProc(wxMenu *menu, wxCommandEvent& event)
 {
-  wxWindow *data = (wxWindow *)menu.GetClientData();
+  wxWindow *data = (wxWindow *)menu->GetClientData();
   if (!data)
     return;
 
@@ -2266,6 +2273,22 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event)
     }
     case OBJECT_MENU_DELETE:
     {
+      if (data->IsKindOf(CLASSINFO(wxControl)) && (data->GetEventHandler() != data))
+      {
+         // Deselect and refresh window in case we leave selection
+         // handles behind
+         wxControl *item = (wxControl *)data;
+         wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
+         if (childHandler->IsSelected())
+         {
+            wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item);
+            childHandler->SelectItem(FALSE);
+#ifndef __WXGTK__
+            item->GetParent()->Refresh();
+#endif
+         }
+      } 
+
       wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
       wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
       wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);
@@ -2281,19 +2304,10 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event)
  *
  */
 
-#if defined(__WXGTK__) || defined(__WXMOTIF__)   // I don't dare to delete it...
 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
+//     EVT_PAINT(EditorToolBar::OnPaint)
 END_EVENT_TABLE()
 
-#else
-
-BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
-       EVT_PAINT(EditorToolBar::OnPaint)
-END_EVENT_TABLE()
-
-#endif
-
 EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size,
             long style):
   wxToolBar(frame, -1, pos, size, style)