]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reseditr.cpp
added missing const
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
index 80f9f0c84540fb6f37bb7b3c7710427bd05102d3..f4d2e4d600bbb27208ae23110e2563f8b5bfc706 100644 (file)
 #include "wx/gauge.h"
 #include "wx/slider.h"
 #include "wx/textctrl.h"
 #include "wx/gauge.h"
 #include "wx/slider.h"
 #include "wx/textctrl.h"
+#include "wx/menu.h"
+#include "wx/toolbar.h"
 #endif
 
 #include "wx/scrolbar.h"
 #endif
 
 #include "wx/scrolbar.h"
+#include "wx/config.h"
+#include "wx/dir.h"
+#include "wx/progdlg.h"
 
 #include <ctype.h>
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
 
 
 #include <ctype.h>
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
 
-#if defined(__WXMSW__) && !defined(__GNUWIN32__)
-#include <strstrea.h>
-#else
-#include <strstream.h>
-#endif
-
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-#include <windows.h>
-#endif
-
 #include "wx/help.h"
 #include "wx/help.h"
+#endif
 
 #include "reseditr.h"
 #include "winprop.h"
 
 #include "reseditr.h"
 #include "winprop.h"
 #include "edtree.h"
 #include "edlist.h"
 
 #include "edtree.h"
 #include "edlist.h"
 
-static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event);
 wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 
 wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 
-#ifdef __X__
-#include "bitmaps/load.xbm"
-#include "bitmaps/save.xbm"
-#include "bitmaps/new.xbm"
-#include "bitmaps/vert.xbm"
-#include "bitmaps/alignt.xbm"
-#include "bitmaps/alignb.xbm"
-#include "bitmaps/horiz.xbm"
-#include "bitmaps/alignl.xbm"
-#include "bitmaps/alignr.xbm"
-#include "bitmaps/copysize.xbm"
-#include "bitmaps/tofront.xbm"
-#include "bitmaps/toback.xbm"
-#include "bitmaps/help.xbm"
-#include "bitmaps/wxwin.xbm"
+#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
+#include "bitmaps/load.xpm"
+#include "bitmaps/save.xpm"
+#include "bitmaps/new.xpm"
+#include "bitmaps/vert.xpm"
+#include "bitmaps/alignt.xpm"
+#include "bitmaps/alignb.xpm"
+#include "bitmaps/horiz.xpm"
+#include "bitmaps/alignl.xpm"
+#include "bitmaps/alignr.xpm"
+#include "bitmaps/copysize.xpm"
+#include "bitmaps/tofront.xpm"
+#include "bitmaps/toback.xpm"
+#include "bitmaps/help.xpm"
+#include "bitmaps/wxwin.xpm"
+#include "bitmaps/distvert.xpm"
+#include "bitmaps/disthor.xpm"
+#include "bitmaps/copywdth.xpm"
+#include "bitmaps/copyhght.xpm"
+
+#include "bitmaps/dialog.xpm"
+#include "bitmaps/folder1.xpm"
+#include "bitmaps/folder2.xpm"
+#include "bitmaps/buttonsm.xpm"
 #endif
 
 /*
 #endif
 
 /*
- * Resource manager
- */
+* Resource manager
+*/
 
 wxResourceManager::wxResourceManager():
 
 wxResourceManager::wxResourceManager():
-  m_imageList(16, 16, TRUE)
-{
-  sm_currentResourceManager = this;
-  m_editorFrame = NULL;
-  m_editorPanel = NULL;
-  m_popupMenu = NULL;
-  m_editorResourceTree = NULL;
-  m_editorControlList = NULL;
-  m_nameCounter = 1;
-  m_modified = FALSE;
-  m_currentFilename = "";
-  m_symbolFilename = "";
-  m_editorToolBar = NULL;
-
-  // Default window positions
-  m_resourceEditorWindowSize.width = 470;
-  m_resourceEditorWindowSize.height = 300;
-
-  m_resourceEditorWindowSize.x = 0;
-  m_resourceEditorWindowSize.y = 0;
-
-  m_propertyWindowSize.width = 300;
-  m_propertyWindowSize.height = 300;
-
-  m_helpController = NULL;
-
-  m_bitmapImage = NULL;
-  m_rootDialogItem = 0;
+m_imageList(16, 16, TRUE)
+{
+    sm_currentResourceManager = this;
+    m_editorFrame = NULL;
+    m_editorPanel = NULL;
+    m_popupMenu = NULL;
+    m_editorResourceTree = NULL;
+    m_editorControlList = NULL;
+    m_nameCounter = 1;
+    m_symbolIdCounter = 99;
+    m_modified = FALSE;
+    m_currentFilename = "";
+    m_symbolFilename = "";
+    m_editorToolBar = NULL;
+    
+    // Default window positions
+    m_resourceEditorWindowSize.width = 500;
+    m_resourceEditorWindowSize.height = 450;
+    
+    m_resourceEditorWindowSize.x = 0;
+    m_resourceEditorWindowSize.y = 0;
+    
+    m_propertyWindowSize.width = 300;
+    m_propertyWindowSize.height = 300;
+    
+#ifdef __WXMSW__
+    m_helpController = NULL;
+#endif
+    
+    m_bitmapImage = NULL;
+    m_rootDialogItem = 0;
 }
 
 wxResourceManager::~wxResourceManager()
 {
 }
 
 wxResourceManager::~wxResourceManager()
 {
-  sm_currentResourceManager = NULL;
-  SaveOptions();
-
-  if (m_helpController)
-  {
-    m_helpController->Quit();
-    delete m_helpController;
-    m_helpController = NULL;
-  }
-  delete m_bitmapImage;
-  delete m_popupMenu;
+    sm_currentResourceManager = NULL;
+    SaveOptions();
+    
+#ifdef __WXMSW__
+    if (m_helpController)
+    {
+        m_helpController->Quit();
+        delete m_helpController;
+        m_helpController = NULL;
+    }
+#endif  
+    
+    delete m_bitmapImage;
+    delete m_popupMenu;
 }
 
 bool wxResourceManager::Initialize()
 {
 }
 
 bool wxResourceManager::Initialize()
 {
-  // Set up the resource filename for each platform.
+    // Set up the resource filename for each platform.
+    // TODO: This shold be replaced by wxConfig usage.
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-  // dialoged.ini in the Windows directory
-  char buf[256];
-  GetWindowsDirectory(buf, 256);
-  strcat(buf, "\\dialoged.ini");
-  m_optionsResourceFilename = buf;
-#elif defined(__X__)
-  char buf[500];
-  ()wxGetHomeDir(buf);
-  strcat(buf, "/.dialogedrc");
-  m_optionsResourceFilename = buf;
+    // dialoged.ini in the Windows directory
+    wxString windowsDir = wxGetOSDirectory();
+    windowsDir += "\\dialoged.ini" ;
+    
+    m_optionsResourceFilename = windowsDir;
+#elif defined(__WXGTK__) || defined(__WXMOTIF__) || (defined(__WXMAC__) && defined(__DARWIN__))
+    wxGetHomeDir( &m_optionsResourceFilename );
+    m_optionsResourceFilename += "/.dialogedrc";
 #else
 #error "Unsupported platform."
 #endif
 #else
 #error "Unsupported platform."
 #endif
-
-  LoadOptions();
-
-  m_helpController = new wxHelpController;
-  m_helpController->Initialize("dialoged");
-
-  m_popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc);
-  m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties");
-  m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object");
-
-  if (!m_bitmapImage)
-  {
+    
+    LoadOptions();
+    
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-    m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE);
+    m_helpController = new wxHelpController;
+    m_helpController->Initialize("dialoged");
 #endif
 #endif
-#ifdef __X__
-    m_bitmapImage = new wxBitmap(wxwin_bits, wxwin_width, wxwin_height);
+    
+    m_popupMenu = new wxMenu;
+    m_popupMenu->Append(OBJECT_MENU_TITLE, "WIDGET TYPE");
+    m_popupMenu->AppendSeparator();
+    m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties");
+    m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object");
+    
+    if (!m_bitmapImage)
+    {
+#ifdef __WXMSW__
+        m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE);
 #endif
 #endif
-  }
-
-  // Initialize the image list icons
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+        m_bitmapImage = new wxBitmap( wxwin_xpm );
+#endif
+    }
+    
+    // Initialize the image list icons
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-  wxIcon icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
-  wxIcon icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
-  wxIcon icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
-  wxIcon icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
-  m_imageList.Add(icon1);
-  m_imageList.Add(icon2);
-  m_imageList.Add(icon3);
-  m_imageList.Add(icon4);
+    wxIcon icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
+    wxIcon icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
+    wxIcon icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
+    wxIcon icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
+#else
+    wxIcon icon1( dialog_xpm );    
+    wxIcon icon2( folder1_xpm );    
+    wxIcon icon3( folder2_xpm );    
+    wxIcon icon4( buttonsm_xpm );    
 #endif
 #endif
-
-  return TRUE;
+    m_imageList.Add(icon1);
+    m_imageList.Add(icon2);
+    m_imageList.Add(icon3);
+    m_imageList.Add(icon4);
+    
+    m_symbolTable.AddStandardSymbols();
+    
+    return TRUE;
 }
 
 bool wxResourceManager::LoadOptions()
 {
 }
 
 bool wxResourceManager::LoadOptions()
 {
-  wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
-  wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
-  return TRUE;
+    wxConfig config("DialogEd", "wxWindows");
+    
+    config.Read("editorWindowX", &m_resourceEditorWindowSize.x);
+    config.Read("editorWindowY", &m_resourceEditorWindowSize.y);
+    config.Read("editorWindowWidth", &m_resourceEditorWindowSize.width);
+    config.Read("editorWindowHeight", &m_resourceEditorWindowSize.height);
+    config.Read("propertyWindowX", &m_propertyWindowSize.x);
+    config.Read("propertyWindowY", &m_propertyWindowSize.y);
+    config.Read("propertyWindowWidth", &m_propertyWindowSize.width);
+    config.Read("propertyWindowHeight", &m_propertyWindowSize.height);
+
+    return TRUE;
 }
 
 bool wxResourceManager::SaveOptions()
 {
 }
 
 bool wxResourceManager::SaveOptions()
 {
-  wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
-
-  wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
-  wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
-
-  return TRUE;
+    wxConfig config("DialogEd", "wxWindows");
+    
+    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);
+    
+    return TRUE;
 }
 
 // Show or hide the resource editor frame, which displays a list
 // of resources with ability to edit them.
 }
 
 // Show or hide the resource editor frame, which displays a list
 // of resources with ability to edit them.
-bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const char *title)
+bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent), const char *title)
 {
 {
-  if (show)
-  {
-    if (m_editorFrame)
+    if (show)
     {
     {
-      m_editorFrame->Iconize(FALSE);
-      m_editorFrame->Show(TRUE);
-      return TRUE;
-    }
-    m_editorFrame = OnCreateEditorFrame(title);
-    SetFrameTitle("");
-    wxMenuBar *menuBar = OnCreateEditorMenuBar(m_editorFrame);
-    m_editorFrame->SetMenuBar(menuBar);
-
-    m_editorToolBar = (EditorToolBar *)OnCreateToolBar(m_editorFrame);
-    m_editorControlList = new wxResourceEditorControlList(m_editorFrame, IDC_LISTCTRL, wxPoint(0, 0), wxSize(-1, -1));
-    m_editorResourceTree = new wxResourceEditorProjectTree(m_editorFrame, IDC_TREECTRL, wxPoint(0, 0), wxSize(-1, -1),
-      wxTR_HAS_BUTTONS);
-    m_editorPanel = OnCreateEditorPanel(m_editorFrame);
-
-    m_editorResourceTree->SetImageList(& m_imageList);
-
-    // Constraints for toolbar
-    wxLayoutConstraints *c = new wxLayoutConstraints;
-    c->left.SameAs       (m_editorFrame, wxLeft, 0);
-    c->top.SameAs        (m_editorFrame, wxTop, 0);
-    c->right.SameAs      (m_editorFrame, wxRight, 0);
-    c->bottom.Unconstrained();
-    c->width.Unconstrained();
-    c->height.Absolute(28);
-    m_editorToolBar->SetConstraints(c);
-
-    // Constraints for listbox
-    c = new wxLayoutConstraints;
-    c->left.SameAs       (m_editorFrame, wxLeft, 0);
-    c->top.SameAs        (m_editorToolBar, wxBottom, 0);
-    c->right.Absolute    (150);
-    c->bottom.SameAs     (m_editorControlList, wxTop, 0);
-    c->width.Unconstrained();
-    c->height.Unconstrained();
-    m_editorResourceTree->SetConstraints(c);
-
-    // Constraints for panel
-    c = new wxLayoutConstraints;
-    c->left.SameAs       (m_editorResourceTree, wxRight, 0);
-    c->top.SameAs        (m_editorToolBar, wxBottom, 0);
-    c->right.SameAs      (m_editorFrame, wxRight, 0);
-    c->bottom.SameAs     (m_editorControlList, wxTop, 0);
-    c->width.Unconstrained();
-    c->height.Unconstrained();
-    m_editorPanel->SetConstraints(c);
-
-    // Constraints for control list (bottom window)
-    c = new wxLayoutConstraints;
-    c->left.SameAs       (m_editorFrame, wxLeft, 0);
-    c->right.SameAs      (m_editorFrame, wxRight, 0);
-    c->bottom.SameAs     (m_editorFrame, wxBottom, 0);
-    c->width.Unconstrained();
-    c->height.Absolute(60);
-    m_editorControlList->SetConstraints(c);
-
-    m_editorFrame->SetAutoLayout(TRUE);
-
-    UpdateResourceList();
-
-    m_editorFrame->Show(TRUE);
-    return TRUE;
-  }
-  else
-  {
-    wxFrame *fr = m_editorFrame;
-    if (m_editorFrame->OnClose())
+        if (m_editorFrame)
+        {
+            m_editorFrame->Iconize(FALSE);
+            m_editorFrame->Show(TRUE);
+            return TRUE;
+        }
+        m_editorFrame = OnCreateEditorFrame(title);
+        SetFrameTitle("");
+        wxMenuBar *menuBar = OnCreateEditorMenuBar(m_editorFrame);
+        m_editorFrame->SetMenuBar(menuBar);
+        
+        m_editorToolBar = (EditorToolBar *)OnCreateToolBar(m_editorFrame);
+        m_editorControlList = new wxResourceEditorControlList(m_editorFrame, IDC_LISTCTRL, wxPoint(0, 0), wxSize(-1, -1));
+        m_editorResourceTree = new wxResourceEditorProjectTree(m_editorFrame, IDC_TREECTRL, wxPoint(0, 0), wxSize(-1, -1),
+            wxTR_HAS_BUTTONS);
+        m_editorPanel = OnCreateEditorPanel(m_editorFrame);
+        
+        m_editorResourceTree->SetImageList(& m_imageList);
+        
+        // Constraints for toolbar
+        wxLayoutConstraints *c = new wxLayoutConstraints;
+        c->left.SameAs       (m_editorFrame, wxLeft, 0);
+        c->top.SameAs        (m_editorFrame, wxTop, 0);
+        c->right.SameAs      (m_editorFrame, wxRight, 0);
+        c->bottom.Unconstrained();
+        c->width.Unconstrained();
+        c->height.Absolute(28);
+        m_editorToolBar->SetConstraints(c);
+        
+        // Constraints for listbox
+        c = new wxLayoutConstraints;
+        c->left.SameAs       (m_editorFrame, wxLeft, 0);
+        c->top.SameAs        (m_editorToolBar, wxBottom, 0);
+        c->right.Absolute    (150);
+        c->bottom.SameAs     (m_editorControlList, wxTop, 0);
+        c->width.Unconstrained();
+        c->height.Unconstrained();
+        m_editorResourceTree->SetConstraints(c);
+        
+        // Constraints for panel
+        c = new wxLayoutConstraints;
+        c->left.SameAs       (m_editorResourceTree, wxRight, 0);
+        c->top.SameAs        (m_editorToolBar, wxBottom, 0);
+        c->right.SameAs      (m_editorFrame, wxRight, 0);
+        c->bottom.SameAs     (m_editorControlList, wxTop, 0);
+        c->width.Unconstrained();
+        c->height.Unconstrained();
+        m_editorPanel->SetConstraints(c);
+        
+        // Constraints for control list (bottom window)
+        c = new wxLayoutConstraints;
+        c->left.SameAs       (m_editorFrame, wxLeft, 0);
+        c->right.SameAs      (m_editorFrame, wxRight, 0);
+        c->bottom.SameAs     (m_editorFrame, wxBottom, 0);
+        c->width.Unconstrained();
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+        c->height.Absolute(120);
+#else
+        c->height.Absolute(60);
+#endif
+        
+        m_editorControlList->SetConstraints(c);
+        
+        m_editorFrame->SetAutoLayout(TRUE);
+        
+        UpdateResourceList();
+        
+        m_editorFrame->Show(TRUE);
+        return TRUE;
+    }
+    else
     {
     {
-      fr->Show(FALSE);
-      delete fr;
-      m_editorFrame = NULL;
-      m_editorPanel = NULL;
+        if (m_editorFrame->Close())
+        {
+            m_editorFrame = NULL;
+            m_editorPanel = NULL;
+        }
     }
     }
-  }
-  return TRUE;
+    return TRUE;
 }
 
 void wxResourceManager::SetFrameTitle(const wxString& filename)
 {
 }
 
 void wxResourceManager::SetFrameTitle(const wxString& filename)
 {
-  if (m_editorFrame)
-  {
-    if (filename == wxString(""))
-      m_editorFrame->SetTitle("wxWindows Dialog Editor - untitled");
-    else
+    if (m_editorFrame)
     {
     {
-      wxString str("wxWindows Dialog Editor - ");
-      wxString str2(wxFileNameFromPath(WXSTRINGCAST filename));
-      str += str2;
-      m_editorFrame->SetTitle(str);
+        if (filename == wxString(""))
+            m_editorFrame->SetTitle("wxWindows Dialog Editor - untitled");
+        else
+        {
+            wxString str("wxWindows Dialog Editor - ");
+            wxString str2(wxFileNameFromPath(WXSTRINGCAST filename));
+            str += str2;
+            m_editorFrame->SetTitle(str);
+        }
     }
     }
-  }
 }
 
 bool wxResourceManager::Save()
 {
 }
 
 bool wxResourceManager::Save()
 {
-  if (m_currentFilename == wxString(""))
-    return SaveAs();
-  else
-    return Save(m_currentFilename);
+    if (m_currentFilename == wxString(""))
+        return SaveAs();
+    else
+        return Save(m_currentFilename);
 }
 
 bool wxResourceManager::Save(const wxString& filename)
 {
 }
 
 bool wxResourceManager::Save(const wxString& filename)
 {
-  // Ensure all visible windows are saved to their resources
-  m_currentFilename = filename;
-  SetFrameTitle(m_currentFilename);
-  InstantiateAllResourcesFromWindows();
-  if (m_resourceTable.Save(filename))
-  {
-    Modify(FALSE);
-    return TRUE;
-  }
-  else
-    return FALSE;
+    // Ensure all visible windows are saved to their resources
+    m_currentFilename = filename;
+    SetFrameTitle(m_currentFilename);
+    InstantiateAllResourcesFromWindows();
+    if (m_resourceTable.Save(filename))
+    {
+        m_symbolTable.WriteIncludeFile(m_symbolFilename);
+        Modify(FALSE);
+        return TRUE;
+    }
+    else
+        return FALSE;
 }
 
 bool wxResourceManager::SaveAs()
 {
 }
 
 bool wxResourceManager::SaveAs()
 {
-  wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename),
-    "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT));
+    wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename),
+        "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow()));
     
     
-  if (s.IsNull() || s == "")
-    return FALSE;
+    if (s.IsNull() || s == "")
+        return FALSE;
+    
+    m_currentFilename = s;
+    wxStripExtension(m_currentFilename);
+    m_currentFilename += ".wxr";
+    
+    // Construct include filename from this file
+    m_symbolFilename = m_currentFilename;
+    
+    wxStripExtension(m_symbolFilename);
+    m_symbolFilename += ".h";
     
     
-  m_currentFilename = s;
-  Save(m_currentFilename);
-  return TRUE;
+    Save(m_currentFilename);
+    return TRUE;
 }
 
 bool wxResourceManager::SaveIfModified()
 {
 }
 
 bool wxResourceManager::SaveIfModified()
 {
-  if (Modified())
-    return Save();
-  else return TRUE;
+    if (Modified())
+        return Save();
+    else return TRUE;
 }
 
 bool wxResourceManager::Load(const wxString& filename)
 {
 }
 
 bool wxResourceManager::Load(const wxString& filename)
 {
-  return New(TRUE, filename);
+    return New(TRUE, filename);
 }
 
 bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
 {
 }
 
 bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
 {
-  if (!Clear(TRUE, FALSE))
-    return FALSE;
-    
-  if (loadFromFile)
-  {
-    wxString str = filename;
-    if (str == wxString(""))
-    {
-      wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, NULL));
-      if (!f.IsNull() && f != "")
-        str = f;
-      else
+    if (!Clear(TRUE, FALSE))
         return FALSE;
         return FALSE;
-    }
     
     
-    if (!m_resourceTable.ParseResourceFile(WXSTRINGCAST str))
+    m_symbolTable.AddStandardSymbols();
+    
+    if (loadFromFile)
     {
     {
-      wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION);
-      return FALSE;
+        wxString str = filename;
+        if (str == wxString(""))
+        {
+            wxString f(wxFileSelector("Open resource file", wxGetCwd(), wxEmptyString, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow()));
+            if (!f.IsNull() && f != "")
+                str = f;
+            else
+                return FALSE;
+        }
+        
+        if (!m_resourceTable.ParseResourceFile(str))
+        {
+            wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION);
+            return FALSE;
+        }
+        m_currentFilename = str;
+        
+        SetFrameTitle(m_currentFilename);
+        
+        UpdateResourceList();
+        
+        // Construct include filename from this file
+        m_symbolFilename = m_currentFilename;
+        
+        wxStripExtension(m_symbolFilename);
+        m_symbolFilename += ".h";
+        
+        if (!m_symbolTable.ReadIncludeFile(m_symbolFilename))
+        {
+            wxString str("Could not find include file ");
+            str += m_symbolFilename;
+            str += ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
+            str += "The next time this .wxr file is saved, a header file will be saved also.";
+            wxMessageBox(str, "Dialog Editor Warning", wxOK );
+            
+            m_symbolIdCounter = 99;
+        }
+        else
+        {
+            // Set the id counter to the last known id
+            m_symbolIdCounter = m_symbolTable.FindHighestId();
+        }
+        
+        // Now check in case some (or all) resources don't have resource ids, or they
+        // don't match the .h file, or something of that nature.
+        bool altered = RepairResourceIds();
+        if (altered)
+        {
+            wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.", 
+                "Dialog Editor Warning", wxOK );
+            Modify(TRUE);
+        }
+        else
+            Modify(FALSE);
+        
+        return TRUE;
     }
     }
-    m_currentFilename = str;
-
-    SetFrameTitle(m_currentFilename);
-
-    UpdateResourceList();
-
-    // 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);
-    m_symbolFilename += ".h";
-
-    if (!m_symbolTable.ReadIncludeFile(m_symbolFilename))
+    else
     {
     {
-        wxString str("Could not find include file ");
-        str += m_symbolFilename;
-        wxMessageBox(str, "Dialog Editor Warning", MB_OK);
+        SetFrameTitle("");
+        m_currentFilename = "";
     }
     }
-  }
-  else
-  {
-    SetFrameTitle("");
-    m_currentFilename = "";
-  }
-  Modify(FALSE);
-  
-  return TRUE;
+    Modify(FALSE);
+    
+    return TRUE;
 }
 
 }
 
-bool wxResourceManager::Clear(bool deleteWindows, bool force)
+bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows), bool force)
 {
 {
-  if (!force && Modified())
-  {
-    int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
-    if (ans == wxCANCEL)
-      return FALSE;
-    if (ans == wxYES)
-      if (!SaveIfModified())
-        return FALSE;
-    if (ans == wxNO)
-        Modify(FALSE);
-  }
-  
-  ClearCurrentDialog();
-  DisassociateWindows();
-
-  m_symbolTable.Clear();
-  m_resourceTable.ClearTable();
-  UpdateResourceList();
-
-  return TRUE;
+    wxPropertyInfo::CloseWindow();
+    
+    if (!force && Modified())
+    {
+        int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
+        if (ans == wxCANCEL)
+            return FALSE;
+        if (ans == wxYES)
+            if (!SaveIfModified())
+                return FALSE;
+            if (ans == wxNO)
+                Modify(FALSE);
+    }
+    
+    ClearCurrentDialog();
+    DisassociateWindows();
+    
+    m_symbolTable.Clear();
+    m_resourceTable.ClearTable();
+    UpdateResourceList();
+    
+    return TRUE;
 }
 
 bool wxResourceManager::DisassociateWindows()
 {
 }
 
 bool wxResourceManager::DisassociateWindows()
 {
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    DisassociateResource(res);
-  }
-  
-  return TRUE;
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
+    {
+        wxItemResource *res = (wxItemResource *)node->Data();
+        DisassociateResource(res);
+    }
+    
+    return TRUE;
 }
 
 void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *win)
 {
 }
 
 void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *win)
 {
-  if (!m_resourceAssociations.Get((long)resource))
-    m_resourceAssociations.Put((long)resource, win);
-
-  wxNode *node = resource->GetChildren().First();
-  while (node)
-  {
-    wxItemResource *child = (wxItemResource *)node->Data();
-    wxWindow *childWindow = (wxWindow *)m_resourceAssociations.Get((long)child);
-    if (!childWindow)
-      childWindow = win->FindWindow(child->GetName());
-    if (childWindow)
-      AssociateResource(child, childWindow);
-    else
+    if (!m_resourceAssociations.Get((long)resource))
+        m_resourceAssociations.Put((long)resource, win);
+    
+    wxNode *node = resource->GetChildren().First();
+    wxNode* node2 = win->GetChildren().First();
+    while (node && node2)
     {
     {
-      char buf[200];
-      sprintf(buf, "AssociateResource: cannot find child window %s", child->GetName() ? child->GetName() : "(unnamed)");
-      wxMessageBox(buf, "Dialog Editor problem", wxOK);
+        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->GetId());
+        if (childWindow)
+            AssociateResource(child, childWindow);
+        else
+        {
+            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();
     }
     }
-
-    node = node->Next();
-  }
 }
 
 bool wxResourceManager::DisassociateResource(wxItemResource *resource)
 {
 }
 
 bool wxResourceManager::DisassociateResource(wxItemResource *resource)
 {
-  wxWindow *win = FindWindowForResource(resource);
-  if (!win)
-    return FALSE;
-
-  // Disassociate children of window
-  if (win->GetChildren())
-  {
-    wxNode *node = win->GetChildren()->First();
+    wxWindow *win = FindWindowForResource(resource);
+    if (!win)
+        return FALSE;
+    
+    // Disassociate children of window
+    wxNode *node = win->GetChildren().First();
     while (node)
     {
     while (node)
     {
-      wxWindow *child = (wxWindow *)node->Data();
-      if (child->IsKindOf(CLASSINFO(wxControl)))
-       DisassociateResource(child);
-      node = node->Next();
+        wxWindow *child = (wxWindow *)node->Data();
+        if (child->IsKindOf(CLASSINFO(wxControl)))
+            DisassociateResource(child);
+        node = node->Next();
     }
     }
-  }
-  
-  RemoveSelection(win);
-  m_resourceAssociations.Delete((long)resource);
-  return TRUE;
+    
+    RemoveSelection(win);
+    m_resourceAssociations.Delete((long)resource);
+    return TRUE;
 }
 
 bool wxResourceManager::DisassociateResource(wxWindow *win)
 {
 }
 
 bool wxResourceManager::DisassociateResource(wxWindow *win)
 {
-  wxItemResource *res = FindResourceForWindow(win);
-  if (res)
-    return DisassociateResource(res);
-  else
-    return FALSE;
+    wxItemResource *res = FindResourceForWindow(win);
+    if (res)
+        return DisassociateResource(res);
+    else
+        return FALSE;
 }
 
 // Saves the window info into the resource, and deletes the
 }
 
 // Saves the window info into the resource, and deletes the
@@ -549,23 +597,23 @@ bool wxResourceManager::DisassociateResource(wxWindow *win)
 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win)
 {
     wxItemResource *res = FindResourceForWindow(win);
 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win)
 {
     wxItemResource *res = FindResourceForWindow(win);
-
+    
     if (win->IsKindOf(CLASSINFO(wxPanel)))
     {
         wxResourceEditorDialogHandler* handler = (wxResourceEditorDialogHandler*) win->GetEventHandler();
         win->PopEventHandler();
     if (win->IsKindOf(CLASSINFO(wxPanel)))
     {
         wxResourceEditorDialogHandler* handler = (wxResourceEditorDialogHandler*) win->GetEventHandler();
         win->PopEventHandler();
-
+        
         // Now reset all child event handlers
         // Now reset all child event handlers
-        wxNode *node = win->GetChildren()->First();
+        wxNode *node = win->GetChildren().First();
         while ( node )
         {
         while ( node )
         {
-               wxWindow *child = (wxWindow *)node->Data();
-               wxEvtHandler *childHandler = child->GetEventHandler();
-               if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler != child )
-               {
-                       child->PopEventHandler(TRUE);
-               }
-               node = node->Next();
+            wxWindow *child = (wxWindow *)node->Data();
+            wxEvtHandler *childHandler = child->GetEventHandler();
+            if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler != child )
+            {
+                child->PopEventHandler(TRUE);
+            }
+            node = node->Next();
         }
         delete handler;
     }
         }
         delete handler;
     }
@@ -573,12 +621,12 @@ bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win)
     {
         win->PopEventHandler(TRUE);
     }
     {
         win->PopEventHandler(TRUE);
     }
-  
+    
     // Save the information
     InstantiateResourceFromWindow(res, win, TRUE);
     // Save the information
     InstantiateResourceFromWindow(res, win, TRUE);
-  
-//  DisassociateResource(win);
-
+    
+    //  DisassociateResource(win);
+    
     return TRUE;
 }
 
     return TRUE;
 }
 
@@ -592,1312 +640,1736 @@ bool wxResourceManager::DeleteWindow(wxWindow* win)
         m_editorPanel->m_childWindow = NULL;
         clearDisplay = TRUE;
     }
         m_editorPanel->m_childWindow = NULL;
         clearDisplay = TRUE;
     }
-
+    
     win->Destroy();
     win->Destroy();
-
+    
     if (clearDisplay)
         m_editorPanel->Clear();
     if (clearDisplay)
         m_editorPanel->Clear();
-
+    
     return TRUE;
 }
 
 wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win)
 {
     return TRUE;
 }
 
 wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win)
 {
-  m_resourceAssociations.BeginFind();
-  wxNode *node;
-  while (node = m_resourceAssociations.Next())
-  {
-    wxWindow *w = (wxWindow *)node->Data();
-    if (w == win)
+    m_resourceAssociations.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceAssociations.Next()))
     {
     {
-      return (wxItemResource *)node->key.integer;
+        wxWindow *w = (wxWindow *)node->Data();
+        if (w == win)
+        {
+            return (wxItemResource *)node->GetKeyInteger();
+        }
     }
     }
-  }
-  return NULL;
+    return NULL;
 }
 
 wxWindow *wxResourceManager::FindWindowForResource(wxItemResource *resource)
 {
 }
 
 wxWindow *wxResourceManager::FindWindowForResource(wxItemResource *resource)
 {
-  return (wxWindow *)m_resourceAssociations.Get((long)resource);
+    return (wxWindow *)m_resourceAssociations.Get((long)resource);
 }
 
 
 void wxResourceManager::MakeUniqueName(char *prefix, char *buf)
 {
 }
 
 
 void wxResourceManager::MakeUniqueName(char *prefix, char *buf)
 {
-  while (TRUE)
-  {
-    sprintf(buf, "%s%d", prefix, m_nameCounter);
-    m_nameCounter ++;
-
-    if (!m_resourceTable.FindResource(buf))
-      return;
-  }
+    while (TRUE)
+    {
+        sprintf(buf, "%s%d", prefix, m_nameCounter);
+        m_nameCounter ++;
+        
+        if (!m_resourceTable.FindResource(buf))
+            return;
+    }
 }
 
 wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title)
 {
 }
 
 wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title)
 {
-  int frameWidth = 420;
-  int frameHeight = 300;
-  
-  wxResourceEditorFrame *frame = new wxResourceEditorFrame(this, NULL, title,
-    wxPoint(m_resourceEditorWindowSize.x, m_resourceEditorWindowSize.y),
-    wxSize(m_resourceEditorWindowSize.width, m_resourceEditorWindowSize.height),
-    wxDEFAULT_FRAME_STYLE);
-
-  frame->CreateStatusBar(1);
-
-  frame->SetAutoLayout(TRUE);
+    wxResourceEditorFrame *frame = new wxResourceEditorFrame(this, NULL, title,
+        wxPoint(m_resourceEditorWindowSize.x, m_resourceEditorWindowSize.y),
+        wxSize(m_resourceEditorWindowSize.width, m_resourceEditorWindowSize.height),
+        wxDEFAULT_FRAME_STYLE);
+    
+    frame->CreateStatusBar(1);
+    
+    frame->SetAutoLayout(TRUE);
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-  wxIcon *icon = new wxIcon("DIALOGEDICON");
-  frame->SetIcon(icon);
+    frame->SetIcon(wxIcon("DIALOGEDICON"));
 #endif
 #endif
-  return frame;
+    return frame;
 }
 
 }
 
-wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *parent)
+wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *WXUNUSED(parent))
 {
 {
-  wxMenuBar *menuBar = new wxMenuBar;
-
-  wxMenu *fileMenu = new wxMenu;
-  fileMenu->Append(RESED_NEW_DIALOG, "New &dialog", "Create a new dialog");
-  fileMenu->AppendSeparator();
-  fileMenu->Append(wxID_NEW, "&New project",           "Clear the current project");
-  fileMenu->Append(wxID_OPEN, "&Open...",         "Load a resource file");
-  fileMenu->Append(wxID_SAVE, "&Save",            "Save a resource file");
-  fileMenu->Append(wxID_SAVEAS, "Save &As...",   "Save a resource file as...");
-  fileMenu->Append(RESED_CLEAR, "&Clear",   "Clear current resources");
-  fileMenu->AppendSeparator();
-  fileMenu->Append(wxID_EXIT, "E&xit",            "Exit resource editor");
-
-  wxMenu *editMenu = new wxMenu;
-  editMenu->Append(RESED_TEST, "&Test Dialog",  "Test dialog");
-  editMenu->Append(RESED_RECREATE, "&Recreate",  "Recreate the selected resource(s)");
-  editMenu->Append(RESED_DELETE, "&Delete",  "Delete the selected resource(s)");
-
-  wxMenu *helpMenu = new wxMenu;
-  helpMenu->Append(RESED_CONTENTS, "&Help topics",          "Invokes the on-line help");
-  helpMenu->AppendSeparator();
-  helpMenu->Append(wxID_ABOUT, "&About",          "About wxWindows Dialog Editor");
-
-  menuBar->Append(fileMenu, "&File");
-  menuBar->Append(editMenu, "&Edit");
-  menuBar->Append(helpMenu, "&Help");
-
-  return menuBar;
+    wxMenuBar *menuBar = new wxMenuBar;
+    
+    wxMenu *fileMenu = new wxMenu;
+    fileMenu->Append(RESED_NEW_DIALOG, "New &Dialog", "Create a new dialog");
+    fileMenu->AppendSeparator();
+    fileMenu->Append(wxID_NEW, "&New Project",           "Clear the current project");
+    fileMenu->Append(wxID_OPEN, "&Open...",         "Load a resource file");
+    fileMenu->Append(wxID_SAVE, "&Save",            "Save a resource file");
+    fileMenu->Append(wxID_SAVEAS, "Save &As...",   "Save a resource file as...");
+    fileMenu->Append(RESED_CLEAR, "&Clear",   "Clear current resources");
+    fileMenu->AppendSeparator();
+    fileMenu->Append(RESED_CONVERT_WXRS, "Convert Old &Resources...", "Convert old resources to new");
+    fileMenu->AppendSeparator();
+    fileMenu->Append(wxID_EXIT, "E&xit",            "Exit resource editor");
+    
+    wxMenu *editMenu = new wxMenu;
+    editMenu->Append(RESED_TEST, "&Test Dialog",  "Test dialog");
+    editMenu->Append(RESED_RECREATE, "&Recreate",  "Recreate the selected resource(s)");
+    editMenu->Append(RESED_DELETE, "&Delete",  "Delete the selected resource(s)");
+    
+    wxMenu *helpMenu = new wxMenu;
+    helpMenu->Append(RESED_CONTENTS, "&Help Topics",          "Invokes the on-line help");
+    helpMenu->AppendSeparator();
+    helpMenu->Append(wxID_ABOUT, "&About",          "About wxWindows Dialog Editor");
+    
+    menuBar->Append(fileMenu, "&File");
+    menuBar->Append(editMenu, "&Edit");
+    menuBar->Append(helpMenu, "&Help");
+    
+    return menuBar;
 }
 
 wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *parent)
 {
 }
 
 wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *parent)
 {
-  wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize,
-//    wxSUNKEN_BORDER|wxCLIP_CHILDREN);
+    wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize,
+        //    wxSUNKEN_BORDER|wxCLIP_CHILDREN);
+#ifdef __WXMOTIF__
+        wxBORDER);
+#else
     wxSUNKEN_BORDER);
     wxSUNKEN_BORDER);
-
-  panel->SetScrollbars(10, 10, 100, 100);
-
-  return panel;
+#endif
+    
+    panel->SetScrollbars(10, 10, 100, 100);
+    
+    return panel;
 }
 
 }
 
-wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent)
+wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent)
 {
 {
-  // Load palette bitmaps
+    // Load palette bitmaps
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-  wxBitmap ToolbarLoadBitmap("LOADTOOL");
-  wxBitmap ToolbarSaveBitmap("SAVETOOL");
-  wxBitmap ToolbarNewBitmap("NEWTOOL");
-  wxBitmap ToolbarVertBitmap("VERTTOOL");
-  wxBitmap ToolbarAlignTBitmap("ALIGNTTOOL");
-  wxBitmap ToolbarAlignBBitmap("ALIGNBTOOL");
-  wxBitmap ToolbarHorizBitmap("HORIZTOOL");
-  wxBitmap ToolbarAlignLBitmap("ALIGNLTOOL");
-  wxBitmap ToolbarAlignRBitmap("ALIGNRTOOL");
-  wxBitmap ToolbarCopySizeBitmap("COPYSIZETOOL");
-  wxBitmap ToolbarToBackBitmap("TOBACKTOOL");
-  wxBitmap ToolbarToFrontBitmap("TOFRONTTOOL");
-  wxBitmap ToolbarHelpBitmap("HELPTOOL");
+    wxBitmap ToolbarLoadBitmap("LOADTOOL");
+    wxBitmap ToolbarSaveBitmap("SAVETOOL");
+    wxBitmap ToolbarNewBitmap("NEWTOOL");
+    wxBitmap ToolbarVertBitmap("VERTTOOL");
+    wxBitmap ToolbarAlignTBitmap("ALIGNTTOOL");
+    wxBitmap ToolbarAlignBBitmap("ALIGNBTOOL");
+    wxBitmap ToolbarHorizBitmap("HORIZTOOL");
+    wxBitmap ToolbarAlignLBitmap("ALIGNLTOOL");
+    wxBitmap ToolbarAlignRBitmap("ALIGNRTOOL");
+    wxBitmap ToolbarCopySizeBitmap("COPYSIZETOOL");
+    wxBitmap ToolbarToBackBitmap("TOBACKTOOL");
+    wxBitmap ToolbarToFrontBitmap("TOFRONTTOOL");
+    wxBitmap ToolbarHelpBitmap("HELPTOOL");
+    wxBitmap ToolbarCopyWidthBitmap("COPYWIDTHTOOL");
+    wxBitmap ToolbarCopyHeightBitmap("COPYHEIGHTTOOL");
+    wxBitmap ToolbarDistributeHorizBitmap("DISTHORIZTOOL");
+    wxBitmap ToolbarDistributeVertBitmap("DISTVERTTOOL");
 #endif
 #endif
-#ifdef __X__
-  wxBitmap ToolbarLoadBitmap(load_bits, load_width, load_height);
-  wxBitmap ToolbarSaveBitmap(save_bits, save_width, save_height);
-  wxBitmap ToolbarNewBitmap(new_bits, save_width, save_height);
-  wxBitmap ToolbarVertBitmap(vert_bits, vert_width, vert_height);
-  wxBitmap ToolbarAlignTBitmap(alignt_bits, alignt_width, alignt_height);
-  wxBitmap ToolbarAlignBBitmap(alignb_bits, alignb_width, alignb_height);
-  wxBitmap ToolbarHorizBitmap(horiz_bits, horiz_width, horiz_height);
-  wxBitmap ToolbarAlignLBitmap(alignl_bits, alignl_width, alignl_height);
-  wxBitmap ToolbarAlignRBitmap(alignr_bits, alignr_width, alignr_height);
-  wxBitmap ToolbarCopySizeBitmap(copysize_bits, copysize_width, copysize_height);
-  wxBitmap ToolbarToBackBitmap(toback_bits, toback_width, toback_height);
-  wxBitmap ToolbarToFrontBitmap(tofront_bits, tofront_width, tofront_height);
-  wxBitmap ToolbarHelpBitmap(help_bits, help_width, help_height);
+#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
+    wxBitmap ToolbarLoadBitmap( load_xpm );
+    wxBitmap ToolbarSaveBitmap( save_xpm);
+    wxBitmap ToolbarNewBitmap( new_xpm );
+    wxBitmap ToolbarVertBitmap( vert_xpm );
+    wxBitmap ToolbarAlignTBitmap( alignt_xpm );
+    wxBitmap ToolbarAlignBBitmap( alignb_xpm );
+    wxBitmap ToolbarHorizBitmap( horiz_xpm );
+    wxBitmap ToolbarAlignLBitmap( alignl_xpm );
+    wxBitmap ToolbarAlignRBitmap( alignr_xpm );
+    wxBitmap ToolbarCopySizeBitmap( copysize_xpm );
+    wxBitmap ToolbarToBackBitmap( toback_xpm );
+    wxBitmap ToolbarToFrontBitmap( tofront_xpm );
+    wxBitmap ToolbarHelpBitmap( help_xpm );
+    wxBitmap ToolbarCopyWidthBitmap(copywdth_xpm);
+    wxBitmap ToolbarCopyHeightBitmap(copyhght_xpm);
+    wxBitmap ToolbarDistributeHorizBitmap(disthor_xpm);
+    wxBitmap ToolbarDistributeVertBitmap(distvert_xpm);
 #endif
 #endif
-
-  // Create the toolbar
-  EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER|wxTB_HORIZONTAL);
-  toolbar->SetMargins(2, 2);
-
+    
+    // Create the toolbar
+    EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT);
+    toolbar->SetMargins(2, 2);
+    
 #ifdef __WXMSW__
 #ifdef __WXMSW__
-  int width = 24;
-  int dx = 2;
-  int gap = 6;
+    int width = 24;
+    int dx = 2;
+    int gap = 6;
 #else
 #else
-  int width = ToolbarLoadBitmap->GetWidth();
-  int dx = 2;
-  int gap = 6;
+    int width = 24; // ToolbarLoadBitmap->GetWidth();  ???
+    int dx = 2;
+    int gap = 6;
 #endif
 #endif
-  int currentX = gap;
-  toolbar->AddSeparator();
-  toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "New dialog");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Load");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Save");
-  currentX += width + dx + gap;
-  toolbar->AddSeparator();
-  toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Horizontal align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Top align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Bottom align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Vertical align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Left align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Right align");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Copy size");
-  currentX += width + dx + gap;
-  toolbar->AddSeparator();
-  toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "To front");
-  currentX += width + dx;
-  toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "To back");
-  currentX += width + dx + gap;
-
-  toolbar->AddSeparator();
-  toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, (wxBitmap *)NULL,
-                   FALSE, (float)currentX, -1, NULL, "Help");
-  currentX += width + dx;
-  
-  toolbar->Realize();
-
-  return toolbar;
+    int currentX = gap;
+    //toolbar->AddSeparator();
+    toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "New dialog");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Load");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Save");
+    currentX += width + dx + gap;
+    toolbar->AddSeparator();
+    toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Horizontal align");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Top align");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Bottom align");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Vertical align");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Left align");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Right align");
+    currentX += width + dx + gap;
+    toolbar->AddSeparator();
+    toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Copy size");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_COPY_WIDTH, ToolbarCopyWidthBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Copy width");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_COPY_HEIGHT, ToolbarCopyHeightBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Copy height");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_DISTRIBUTE_HORIZ, ToolbarDistributeHorizBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Distribute horizontally");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_DISTRIBUTE_VERT, ToolbarDistributeVertBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Distribute vertically");
+    currentX += width + dx + gap;
+    toolbar->AddSeparator();
+    toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "To front");
+    currentX += width + dx;
+    toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "To back");
+    currentX += width + dx + gap;
+    
+    toolbar->AddSeparator();
+    toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, wxNullBitmap,
+        FALSE, currentX, -1, NULL, "Help");
+    currentX += width + dx;
+    
+    toolbar->Realize();
+    
+    return toolbar;
 }
 
 void wxResourceManager::UpdateResourceList()
 {
 }
 
 void wxResourceManager::UpdateResourceList()
 {
-  if (!m_editorResourceTree)
-      return;
-
-  m_editorResourceTree->SetInvalid(TRUE);
-  m_editorResourceTree->DeleteAllItems();
-
-  long id = m_editorResourceTree->InsertItem(0, "Dialogs"
-#ifdef __WXMSW__
-     , 1, 2
-#endif
-   );
-
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    wxString resType(res->GetType());
-    if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel" || resType == "wxBitmap")
+    if (!m_editorResourceTree)
+        return;
+    
+    m_editorResourceTree->SetInvalid(TRUE);
+    m_editorResourceTree->DeleteAllItems();
+    
+    long id = m_editorResourceTree->AddRoot("Dialogs", 1, 2);
+    
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
     {
     {
-      AddItemsRecursively(id, res);
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxString resType(res->GetType());
+        if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel" || resType == "wxBitmap")
+        {
+            AddItemsRecursively(id, res);
+        }
     }
     }
-  }
-  m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
-  m_editorResourceTree->SetInvalid(FALSE);
+    m_editorResourceTree->Expand(id);
+    m_editorResourceTree->SetInvalid(FALSE);
 }
 
 void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resource)
 {
 }
 
 void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resource)
 {
-  wxString theString("");
-  theString = resource->GetName();
-
-  int imageId = 0;
-  wxString resType(resource->GetType());
-  if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
-    imageId = 0;
-  else
-    imageId = 3;
-  
-  long id = m_editorResourceTree->InsertItem(parent, theString
-#ifdef __WXMSW__
-     , imageId
-#endif
-   );
-
-  m_editorResourceTree->SetItemData(id, (long) resource);
-
-  if (strcmp(resource->GetType(), "wxBitmap") != 0)
-  {
-    wxNode *node = resource->GetChildren().First();
-    while (node)
+    wxString theString("");
+    theString = resource->GetName();
+    
+    int imageId = 0;
+    wxString resType(resource->GetType());
+    if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
+        imageId = 0;
+    else
+        imageId = 3;
+    
+    long id = m_editorResourceTree->AppendItem(parent, theString, imageId );
+    
+    m_editorResourceTree->SetItemData(id, new wxResourceTreeData(resource));
+    
+    if (strcmp(resource->GetType(), "wxBitmap") != 0)
     {
     {
-      wxItemResource *res = (wxItemResource *)node->Data();
-      AddItemsRecursively(id, res);
-      node = node->Next();
+        wxNode *node = resource->GetChildren().First();
+        while (node)
+        {
+            wxItemResource *res = (wxItemResource *)node->Data();
+            AddItemsRecursively(id, res);
+            node = node->Next();
+        }
     }
     }
-  }
-  m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
+    //  m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
 }
 
 bool wxResourceManager::EditSelectedResource()
 {
 }
 
 bool wxResourceManager::EditSelectedResource()
 {
-  int sel = m_editorResourceTree->GetSelection();
-  if (sel != 0)
-  {
-    wxItemResource *res = (wxItemResource *)m_editorResourceTree->GetItemData(sel);
-    return Edit(res);
-  }
-  return FALSE;
+    int sel = m_editorResourceTree->GetSelection();
+    if (sel != 0)
+    {
+        wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel);
+        wxItemResource *res = data->GetResource();
+        return Edit(res);
+    }
+    return FALSE;
 }
 
 bool wxResourceManager::Edit(wxItemResource *res)
 {
 }
 
 bool wxResourceManager::Edit(wxItemResource *res)
 {
-  ClearCurrentDialog();
-
-  wxString resType(res->GetType());
-  wxPanel *panel = (wxPanel *)FindWindowForResource(res);
-
-  if (panel)
-  {
-    wxMessageBox("Should not find panel in wxResourceManager::Edit");
-    return FALSE;
-  }
-  else
-  {
-        long style = res->GetStyle();
-        res->SetStyle(style|wxRAISED_BORDER);
+    wxPropertyInfo::CloseWindow();
+    
+    ClearCurrentDialog();
+    
+    wxString resType(res->GetType());
+    wxPanel *panel = (wxPanel *)FindWindowForResource(res);
+    
+    if (panel)
+    {
+        wxMessageBox("Should not find panel in wxResourceManager::Edit");
+        return FALSE;
+    }
+    else
+    {
+        //        long style = res->GetStyle();
+        //        res->SetStyle(style|wxRAISED_BORDER);
         panel = new wxPanel;
         wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(),
         panel = new wxPanel;
         wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(),
-           this);
-
+            this);
+        
         panel->LoadFromResource(m_editorPanel, res->GetName(), &m_resourceTable);
         panel->LoadFromResource(m_editorPanel, res->GetName(), &m_resourceTable);
-
+        
         panel->PushEventHandler(handler);
         panel->PushEventHandler(handler);
-
-        res->SetStyle(style);
-               handler->AddChildHandlers(); // Add event handlers for all controls
+        
+        //        res->SetStyle(style);
+        handler->AddChildHandlers(); // Add event handlers for all controls
         AssociateResource(res, panel);
         AssociateResource(res, panel);
-
+        
         m_editorPanel->m_childWindow = panel;
         panel->Move(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY());
         panel->Show(TRUE);
         panel->Refresh();
         m_editorPanel->m_childWindow = panel;
         panel->Move(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY());
         panel->Show(TRUE);
         panel->Refresh();
-
+        
         wxClientDC dc(m_editorPanel);
         m_editorPanel->DrawTitle(dc);
         wxClientDC dc(m_editorPanel);
         m_editorPanel->DrawTitle(dc);
-  }
-  return FALSE;
+    }
+    return FALSE;
 }
 
 bool wxResourceManager::CreateNewPanel()
 {
 }
 
 bool wxResourceManager::CreateNewPanel()
 {
-  ClearCurrentDialog();
-
-  char buf[256];
-  MakeUniqueName("panel", buf);
-  
-  wxItemResource *resource = new wxItemResource;
-//  resource->SetType(wxTYPE_PANEL);
-  resource->SetType("wxPanel");
-  resource->SetName(buf);
-  resource->SetTitle(buf);
-  m_resourceTable.AddResource(resource);
-
-  wxPanel *panel = new wxPanel(m_editorPanel, -1,
-     wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()),
-     wxSize(400, 300), wxRAISED_BORDER, buf);
-  m_editorPanel->m_childWindow = panel;
-
-  resource->SetStyle(0); // panel->GetWindowStyleFlag());
-  resource->SetSize(10, 10, 400, 300);
-
-  // For editing in situ we will need to use the hash table to ensure
-  // we don't dereference invalid pointers.
-//  resourceWindowTable.Put((long)resource, panel);
-
-  wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(),
-   this);
-  panel->PushEventHandler(handler);
-  
-  AssociateResource(resource, panel);
-  UpdateResourceList();
-  
-  Modify(TRUE);
-  m_editorPanel->m_childWindow->Refresh();
-
-//  panel->Refresh();
-
-  wxClientDC dc(m_editorPanel);
-  m_editorPanel->DrawTitle(dc);
-
-  return TRUE;
+    wxPropertyInfo::CloseWindow();
+    
+    ClearCurrentDialog();
+    
+    char buf[256];
+    MakeUniqueName("dialog", buf);
+    
+    wxItemResource *resource = new wxItemResource;
+    resource->SetType("wxDialog");
+    resource->SetName(buf);
+    resource->SetTitle(buf);
+    resource->SetResourceStyle(wxRESOURCE_USE_DEFAULTS);
+    resource->SetResourceStyle(wxRESOURCE_DIALOG_UNITS);
+    
+    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);
+    
+    wxSize size(400, 300);
+    
+    wxPanel *panel = new wxPanel(m_editorPanel, -1,
+        wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()),
+        size, wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf);
+    m_editorPanel->m_childWindow = panel;
+    
+    resource->SetStyle(panel->GetWindowStyleFlag());
+    
+    // Store dialog units in resource
+    size = panel->ConvertPixelsToDialog(size);
+    
+    resource->SetSize(10, 10, size.x, size.y);
+    
+    // For editing in situ we will need to use the hash table to ensure
+    // we don't dereference invalid pointers.
+    //  resourceWindowTable.Put((long)resource, panel);
+    
+    wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(),
+        this);
+    panel->PushEventHandler(handler);
+    
+    AssociateResource(resource, panel);
+    UpdateResourceList();
+    
+    Modify(TRUE);
+    m_editorPanel->m_childWindow->Refresh();
+    
+    //  panel->Refresh();
+    
+    wxClientDC dc(m_editorPanel);
+    m_editorPanel->DrawTitle(dc);
+    
+    return TRUE;
 }
 
 bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap)
 {
 }
 
 bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap)
 {
-  char buf[256];
-  if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog)))
-    return FALSE;
-
-  Modify(TRUE);
-  
-  wxItemResource *res = new wxItemResource;
-  wxControl *newItem = NULL;
-  res->SetSize(x, y, -1, -1);
-  res->SetType(iType);
-  
-  wxString itemType(iType);
-
-  if (itemType == "wxButton")
+    char buf[256];
+    if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog)))
+        return FALSE;
+    
+    Modify(TRUE);
+    
+    wxItemResource *res = new wxItemResource;
+    wxControl *newItem = NULL;
+    
+    if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
     {
     {
-      MakeUniqueName("button", buf);
-      res->SetName(buf);
-      if (isBitmap)
-        newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
-      else
-        newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
+        wxPoint pt = panel->ConvertPixelsToDialog(wxPoint(x, y));
+        res->SetSize(pt.x, pt.y, -1, -1);
     }
     }
-  if (itemType == "wxBitmapButton")
+    else res->SetSize(x, y, -1, -1);
+    
+    res->SetType(iType);
+    
+    wxString prefix;
+    
+    wxString itemType(iType);
+    
+    if (itemType == "wxButton")
     {
     {
-      MakeUniqueName("button", buf);
-      res->SetName(buf);
-      newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
+        prefix = "ID_BUTTON";
+        MakeUniqueName("button", buf);
+        res->SetName(buf);
+        if (isBitmap)
+            newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), wxBU_AUTODRAW, wxDefaultValidator, buf);
+        else
+            newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
     }
     }
-  else if (itemType == "wxMessage" || itemType == "wxStaticText")
+    if (itemType == "wxBitmapButton")
     {
     {
-      MakeUniqueName("message", buf);
-      res->SetName(buf);
-      if (isBitmap)
-        newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(0, 0), 0, buf);
-      else
-        newItem = new wxStaticText(panel, -1, "Message", wxPoint(x, y), wxSize(-1, -1), 0, buf);
+        prefix = "ID_BITMAPBUTTON";
+        MakeUniqueName("button", buf);
+        res->SetName(buf);
+        newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), wxBU_AUTODRAW, wxDefaultValidator, buf);
     }
     }
-  else if (itemType == "wxStaticBitmap")
+    else if (itemType == "wxMessage" || itemType == "wxStaticText")
     {
     {
-      MakeUniqueName("message", buf);
-      res->SetName(buf);
-      newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf);
+        prefix = "ID_STATIC";
+        MakeUniqueName("statictext", buf);
+        res->SetName(buf);
+        if (isBitmap)
+            newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(0, 0), 0, buf);
+        else
+            newItem = new wxStaticText(panel, -1, "Static", wxPoint(x, y), wxSize(-1, -1), 0, buf);
     }
     }
-  else if (itemType == "wxCheckBox")
+    else if (itemType == "wxStaticBitmap")
     {
     {
-      MakeUniqueName("checkbox", buf);
-      res->SetName(buf);
-      newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf);
+        prefix = "ID_STATICBITMAP";
+        MakeUniqueName("static", buf);
+        res->SetName(buf);
+        newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf);
     }
     }
-  else if (itemType == "wxListBox")
+    else if (itemType == "wxCheckBox")
     {
     {
-      MakeUniqueName("listbox", buf);
-      res->SetName(buf);
-      newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
+        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 == "wxRadioBox")
+    else if (itemType == "wxListBox")
     {
     {
-      MakeUniqueName("radiobox", buf);
-      res->SetName(buf);
-      wxString names[] = { "One", "Two" };
-      newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2,
-            wxHORIZONTAL, wxDefaultValidator, buf);
-      res->SetStringValues(new wxStringList("One", "Two", NULL));
+        prefix = "ID_LISTBOX";
+        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 == "wxRadioButton")
+    else if (itemType == "wxRadioBox")
     {
     {
-      MakeUniqueName("radiobutton", buf);
-      res->SetName(buf);
-      wxString names[] = { "One", "Two" };
-      newItem = new wxRadioButton(panel, -1, "Radiobutton", wxPoint(x, y), wxSize(-1, -1),
-            0, wxDefaultValidator, buf);
+        prefix = "ID_RADIOBOX";
+        MakeUniqueName("radiobox", buf);
+        res->SetName(buf);
+        wxString names[] = { "One", "Two" };
+        newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2,
+            wxHORIZONTAL, wxDefaultValidator, buf);
+        res->SetStringValues(wxStringList("One", "Two", NULL));
     }
     }
-  else if (itemType == "wxChoice")
+    else if (itemType == "wxRadioButton")
     {
     {
-      MakeUniqueName("choice", buf);
-      res->SetName(buf);
-      newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
+        prefix = "ID_RADIOBUTTON";
+        MakeUniqueName("radiobutton", buf);
+        res->SetName(buf);
+        wxString names[] = { "One", "Two" };
+        newItem = new wxRadioButton(panel, -1, "Radiobutton", wxPoint(x, y), wxSize(-1, -1),
+            0, wxDefaultValidator, buf);
     }
     }
-  else if (itemType == "wxGroupBox" || itemType == "wxStaticBox")
+    else if (itemType == "wxChoice")
     {
     {
-      MakeUniqueName("group", buf);
-      res->SetName(buf);
-      newItem = new wxStaticBox(panel, -1, "Groupbox", wxPoint(x, y), wxSize(200, 200), 0, buf);
+        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 == "wxGauge")
+    else if (itemType == "wxComboBox")
     {
     {
-      MakeUniqueName("gauge", buf);
-      res->SetName(buf);
-      newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf);
+        prefix = "ID_COMBOBOX";
+        MakeUniqueName("combobox", buf);
+        res->SetName(buf);
+        newItem = new wxComboBox(panel, -1, "", wxPoint(x, y), wxSize(-1, -1), 0, NULL, wxCB_DROPDOWN, wxDefaultValidator, buf);
     }
     }
-  else if (itemType == "wxSlider")
+    else if (itemType == "wxGroupBox" || itemType == "wxStaticBox")
     {
     {
-      MakeUniqueName("slider", buf);
-      res->SetName(buf);
-      newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf);
+        prefix = "ID_STATICBOX";
+        MakeUniqueName("staticbox", buf);
+        res->SetName(buf);
+        newItem = new wxStaticBox(panel, -1, "Static", wxPoint(x, y), wxSize(200, 200), 0, buf);
     }
     }
-  else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)")
+    else if (itemType == "wxGauge")
     {
     {
-      MakeUniqueName("textctrl", buf);
-      res->SetName(buf);
-      res->SetType("wxTextCtrl");
-      newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf);
+        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 == "wxMultiText" || itemType == "wxTextCtrl (multi-line)")
+    else if (itemType == "wxSlider")
     {
     {
-      MakeUniqueName("textctrl", buf);
-      res->SetName(buf);
-      res->SetType("wxTextCtrl");
-      newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, 100), wxTE_MULTILINE, wxDefaultValidator, buf);
+        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 == "wxScrollBar")
+    else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)")
     {
     {
-      MakeUniqueName("scrollbar", buf);
-      res->SetName(buf);
-      newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf);
+        prefix = "ID_TEXTCTRL";
+        MakeUniqueName("textctrl", buf);
+        res->SetName(buf);
+        res->SetType("wxTextCtrl");
+        newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf);
     }
     }
-  if (!newItem)
-    return FALSE;
-
-  newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem));
-
-  res->SetStyle(newItem->GetWindowStyleFlag());
-  AssociateResource(res, newItem);
-  panelResource->GetChildren().Append(res);
-
-  UpdateResourceList();
-  
-  return TRUE;
+    else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)")
+    {
+        prefix = "ID_TEXTCTRL";
+        MakeUniqueName("textctrl", buf);
+        res->SetName(buf);
+        res->SetType("wxTextCtrl");
+        newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, 100), wxTE_MULTILINE, wxDefaultValidator, buf);
+    }
+    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);
+    }
+    if (!newItem)
+        return FALSE;
+    
+    int actualW, actualH;
+    newItem->GetSize(&actualW, &actualH);
+    wxSize actualSize(actualW, actualH);
+    
+    if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
+    {
+        actualSize = panel->ConvertPixelsToDialog(actualSize);
+    }
+    res->SetSize(res->GetX(), res->GetY(), actualSize.x, actualSize.y);
+    
+    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());
+    AssociateResource(res, newItem);
+    panelResource->GetChildren().Append(res);
+    
+    UpdateResourceList();
+    
+    return TRUE;
 }
 
 void wxResourceManager::ClearCurrentDialog()
 {
 }
 
 void wxResourceManager::ClearCurrentDialog()
 {
-  if (m_editorPanel->m_childWindow)
-  {
-    SaveInfoAndDeleteHandler(m_editorPanel->m_childWindow);
-    DisassociateResource(m_editorPanel->m_childWindow);
-    DeleteWindow(m_editorPanel->m_childWindow);
-    m_editorPanel->m_childWindow = NULL;
-    m_editorPanel->Clear();
-  }
+    if (m_editorPanel->m_childWindow)
+    {
+        SaveInfoAndDeleteHandler(m_editorPanel->m_childWindow);
+        DisassociateResource(m_editorPanel->m_childWindow);
+        DeleteWindow(m_editorPanel->m_childWindow);
+        m_editorPanel->m_childWindow = NULL;
+        m_editorPanel->Clear();
+    }
 }
 
 bool wxResourceManager::TestCurrentDialog(wxWindow* parent)
 {
 }
 
 bool wxResourceManager::TestCurrentDialog(wxWindow* parent)
 {
-  if (m_editorPanel->m_childWindow)
-  {
-    wxItemResource* item = FindResourceForWindow(m_editorPanel->m_childWindow);
-    if (!item)
-        return FALSE;
-
-    // Make sure the resources are up-to-date w.r.t. the window
-    InstantiateResourceFromWindow(item, m_editorPanel->m_childWindow, TRUE);
-
-    wxDialog* dialog = new wxDialog;
-    long oldStyle = item->GetStyle();
-    bool success = FALSE;
-    item->SetStyle(wxDEFAULT_DIALOG_STYLE);
-    if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable))
+    if (m_editorPanel->m_childWindow)
     {
     {
-        dialog->Centre();
-        dialog->ShowModal();
-        success = TRUE;
+        wxItemResource* item = FindResourceForWindow(m_editorPanel->m_childWindow);
+        if (!item)
+            return FALSE;
+        
+        // Make sure the resources are up-to-date w.r.t. the window
+        InstantiateResourceFromWindow(item, m_editorPanel->m_childWindow, TRUE);
+        
+        ResourceEditorDialogTester* dialog = new ResourceEditorDialogTester;
+        bool success = FALSE;
+        if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable))
+        {
+            dialog->Centre();
+            dialog->ShowModal();
+            success = TRUE;
+        }
+        return success;
     }
     }
-    item->SetStyle(oldStyle);
-    return success;
-  }
-  return FALSE;
+    return FALSE;
 }
 
 // Find the first dialog or panel for which
 // there is a selected panel item.
 wxWindow *wxResourceManager::FindParentOfSelection()
 {
 }
 
 // Find the first dialog or panel for which
 // there is a selected panel item.
 wxWindow *wxResourceManager::FindParentOfSelection()
 {
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    wxWindow *win = FindWindowForResource(res);
-    if (win)
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
     {
     {
-      wxNode *node1 = win->GetChildren()->First();
-      while (node1)
-      {
-        wxControl *item = (wxControl *)node1->Data();
-           wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
-        if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
-          return win;
-        node1 = node1->Next();
-      }
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxWindow *win = FindWindowForResource(res);
+        if (win)
+        {
+            wxNode *node1 = win->GetChildren().First();
+            while (node1)
+            {
+                wxControl *item = (wxControl *)node1->Data();
+                wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
+                if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected())
+                    return win;
+                node1 = node1->Next();
+            }
+        }
     }
     }
-  }
-  return NULL;
+    return NULL;
 }
 
 // Format the panel items according to 'flag'
 void wxResourceManager::AlignItems(int flag)
 {
 }
 
 // Format the panel items according to 'flag'
 void wxResourceManager::AlignItems(int flag)
 {
-  wxWindow *win = FindParentOfSelection();
-  if (!win)
-    return;
-
-  wxNode *node = GetSelections().First();
-  if (!node)
-    return;
+    wxWindow *win = FindParentOfSelection();
+    if (!win)
+        return;
     
     
-  wxControl *firstSelection = (wxControl *)node->Data();
-  if (firstSelection->GetParent() != win)
-    return;
+    wxNode *node = GetSelections().First();
+    if (!node)
+        return;
     
     
-  int firstX, firstY;
-  int firstW, firstH;
-  firstSelection->GetPosition(&firstX, &firstY);
-  firstSelection->GetSize(&firstW, &firstH);
-  int centreX = (int)(firstX + (firstW / 2));
-  int centreY = (int)(firstY + (firstH / 2));
-
-  while (node = node->Next())
-  {
-    wxControl *item = (wxControl *)node->Data();
-    if (item->GetParent() == win)
+    wxControl *firstSelection = (wxControl *)node->Data();
+    if (firstSelection->GetParent() != win)
+        return;
+    
+    int firstX, firstY;
+    int firstW, firstH;
+    firstSelection->GetPosition(&firstX, &firstY);
+    firstSelection->GetSize(&firstW, &firstH);
+    int centreX = (int)(firstX + (firstW / 2));
+    int centreY = (int)(firstY + (firstH / 2));
+    
+    while ((node = node->Next()))
     {
     {
-      int x, y, w, h;
-      item->GetPosition(&x, &y);
-      item->GetSize(&w, &h);
-
-      int newX, newY;
-
-      switch (flag)
-      {
-        case TOOLBAR_FORMAT_HORIZ:
-        {
-          newX = x;
-          newY = (int)(centreY - (h/2.0));
-          break;
-        }
-        case TOOLBAR_FORMAT_VERT:
-        {
-          newX = (int)(centreX - (w/2.0));
-          newY = y;
-          break;
-        }
-        case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
-        {
-          newX = firstX;
-          newY = y;
-          break;
-        }
-        case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
+        wxControl *item = (wxControl *)node->Data();
+        if (item->GetParent() == win)
         {
         {
-          newX = x;
-          newY = firstY;
-          break;
+            int x, y, w, h;
+            item->GetPosition(&x, &y);
+            item->GetSize(&w, &h);
+            
+            int newX, newY;
+            
+            switch (flag)
+            {
+            case TOOLBAR_FORMAT_HORIZ:
+                {
+                    newX = x;
+                    newY = (int)(centreY - (h/2.0));
+                    break;
+                }
+            case TOOLBAR_FORMAT_VERT:
+                {
+                    newX = (int)(centreX - (w/2.0));
+                    newY = y;
+                    break;
+                }
+            case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
+                {
+                    newX = firstX;
+                    newY = y;
+                    break;
+                }
+            case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
+                {
+                    newX = x;
+                    newY = firstY;
+                    break;
+                }
+            case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
+                {
+                    newX = firstX + firstW - w;
+                    newY = y;
+                    break;
+                }
+            case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
+                {
+                    newX = x;
+                    newY = firstY + firstH - h;
+                    break;
+                }
+            default:
+                newX = x; newY = y;
+                break;
+            }
+            
+            wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+            wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
+            
+            item->SetSize(newX, newY, w, h);
+            
+            // Also update the associated resource
+            // We need to convert to dialog units if this is not a dialog or panel, but
+            // the parent resource specifies dialog units.
+            if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+            {
+                wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY));
+                newX = pt.x; newY = pt.y;
+                wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(w, h));
+                w = sz.x; h = sz.y;
+            }
+            resource->SetSize(newX, newY, w, h);
         }
         }
-        case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
-        {
-          newX = firstX + firstW - w;
-          newY = y;
-          break;
-        }
-        case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
-        {
-          newX = x;
-          newY = firstY + firstH - h;
-          break;
-        }
-        default:
-          newX = x; newY = y;
-          break;
-      }
-
-      item->SetSize(newX, newY, w, h);
     }
     }
-  }
-  win->Refresh();
+    win->Refresh();
 }
 
 // Copy the first image's size to subsequent images
 }
 
 // Copy the first image's size to subsequent images
-void wxResourceManager::CopySize()
+void wxResourceManager::CopySize(int command)
 {
 {
-  wxWindow *win = FindParentOfSelection();
-  if (!win)
-    return;
-
-  wxNode *node = GetSelections().First();
-  if (!node)
-    return;
+    bool copyWidth = (command == TOOLBAR_COPY_SIZE || command == TOOLBAR_COPY_WIDTH) ;
+    bool copyHeight = (command == TOOLBAR_COPY_SIZE || command == TOOLBAR_COPY_HEIGHT) ;
     
     
-  wxControl *firstSelection = (wxControl *)node->Data();
-  if (firstSelection->GetParent() != win)
-    return;
+    wxWindow *win = FindParentOfSelection();
+    if (!win)
+        return;
     
     
-  int firstX, firstY;
-  int firstW, firstH;
-  firstSelection->GetPosition(&firstX, &firstY);
-  firstSelection->GetSize(&firstW, &firstH);
-  int centreX = (int)(firstX + (firstW / 2));
-  int centreY = (int)(firstY + (firstH / 2));
-
-  while (node = node->Next())
-  {
-    wxControl *item = (wxControl *)node->Data();
-    if (item->GetParent() == win)
-      item->SetSize(-1, -1, firstW, firstH);
-  }
-  win->Refresh();
+    wxNode *node = GetSelections().First();
+    if (!node)
+        return;
+    
+    wxControl *firstSelection = (wxControl *)node->Data();
+    if (firstSelection->GetParent() != win)
+        return;
+    
+    int firstX, firstY;
+    int firstW, firstH;
+    firstSelection->GetPosition(&firstX, &firstY);
+    firstSelection->GetSize(&firstW, &firstH);
+    
+    while ((node = node->Next()))
+    {
+        wxControl *item = (wxControl *)node->Data();
+        if (item->GetParent() == win)
+        {
+            wxSize sz = item->GetSize();
+            int widthToSet = (copyWidth ? firstW : sz.x);
+            int heightToSet = (copyHeight ? firstH : sz.y);
+            
+            item->SetSize(-1, -1, widthToSet, heightToSet);
+            
+            wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+            wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
+            
+            widthToSet = resource->GetWidth();
+            heightToSet = resource->GetHeight();
+            
+            // Also update the associated resource
+            // We need to convert to dialog units if this is not a dialog or panel, but
+            // the parent resource specifies dialog units.
+            if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+            {
+                wxSize convertedSize = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH));
+                if (copyWidth)
+                    widthToSet = convertedSize.x;
+                if (copyHeight)
+                    heightToSet = convertedSize.y;
+            }
+            resource->SetSize(resource->GetX(), resource->GetY(), widthToSet, heightToSet);
+        }
+    }
+    win->Refresh();
 }
 
 void wxResourceManager::ToBackOrFront(bool toBack)
 {
 }
 
 void wxResourceManager::ToBackOrFront(bool toBack)
 {
-  wxWindow *win = FindParentOfSelection();
-  if (!win)
-    return;
-  wxItemResource *winResource = FindResourceForWindow(win);
-
-  wxNode *node = GetSelections().First();
-  while (node)
-  {
-    wxControl *item = (wxControl *)node->Data();
-    wxItemResource *itemResource = FindResourceForWindow(item);
-    if (item->GetParent() == win)
-    {
-      win->GetChildren()->DeleteObject(item);
-      if (winResource)
-        winResource->GetChildren().DeleteObject(itemResource);
-      if (toBack)
-      {
-        win->GetChildren()->Insert(item);
-        if (winResource)
-          winResource->GetChildren().Insert(itemResource);
-      }
-      else
-      {
-        win->GetChildren()->Append(item);
-        if (winResource)
-          winResource->GetChildren().Append(itemResource);
-      }
-    }
-    node = node->Next();
-  }
-//  win->Refresh();
-}
-
-void wxResourceManager::AddSelection(wxWindow *win)
-{
-  if (!m_selections.Member(win))
-    m_selections.Append(win);
+    wxWindow *win = FindParentOfSelection();
+    if (!win)
+        return;
+    wxItemResource *winResource = FindResourceForWindow(win);
+    
+    wxNode *node = GetSelections().First();
+    while (node)
+    {
+        wxControl *item = (wxControl *)node->Data();
+        wxItemResource *itemResource = FindResourceForWindow(item);
+        if (item->GetParent() == win)
+        {
+            win->GetChildren().DeleteObject(item);
+            if (winResource)
+                winResource->GetChildren().DeleteObject(itemResource);
+            if (toBack)
+            {
+                win->GetChildren().Insert(item);
+                if (winResource)
+                    winResource->GetChildren().Insert(itemResource);
+            }
+            else
+            {
+                win->GetChildren().Append(item);
+                if (winResource)
+                    winResource->GetChildren().Append(itemResource);
+            }
+        }
+        node = node->Next();
+    }
+    //  win->Refresh();
 }
 
 }
 
-void wxResourceManager::RemoveSelection(wxWindow *win)
+// Distribute controls evenly between first and last
+void wxResourceManager::DistributePositions(int command)
 {
 {
-  m_selections.DeleteObject(win);
-}
+    bool horizontal = (command == TOOLBAR_DISTRIBUTE_HORIZ) ;
 
 
-// Need to search through resource table removing this from
-// any resource which has this as a parent.
-bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res)
-{
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *thisRes = (wxItemResource *)node->Data();
-    if (thisRes->GetChildren().Member(res))
+    wxWindow *win = FindParentOfSelection();
+    if (!win)
+        return;
+    
+    if (GetSelections().Number() < 3)
     {
     {
-      thisRes->GetChildren().DeleteObject(res);
-      return TRUE;
+        wxMessageBox(wxT("Sorry, distributing less than three controls does not make sense."));
+        return;
     }
     }
-  }
-  return FALSE;
-}
+    
+    wxControl *firstSelection = (wxControl*) GetSelections().First()->Data();
+    wxControl *lastSelection = (wxControl*) GetSelections().Last()->Data();
 
 
-bool wxResourceManager::DeleteResource(wxItemResource *res)
-{
-  if (!res)
-    return FALSE;
+    // For now, assume the ordering is correct (the user selected the controls in order).
+    // TODO: explicitly order the selections in terms of increading x or y position.
 
 
-  RemoveResourceFromParent(res);
+    // Find the total amount of space between all controls
+    int totalControlSpace = 0; // How much space the controls take up
 
 
-  wxNode *node = res->GetChildren().First();
-  while (node)
-  {
-    wxNode *next = node->Next();
-    wxItemResource *child = (wxItemResource *)node->Data();
-    DeleteResource(child);
-    node = next;
-  }
-  
-  // If this is a button or message resource, delete the
-  // associate bitmap resource if not being used.
-  wxString resType(res->GetType());
-  
-  if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
-  {
-    PossiblyDeleteBitmapResource(res->GetValue4());
-  }
+    wxNode* node = GetSelections().First();
+    while (node)
+    {
+        wxControl* control = (wxControl*) node->Data();
 
 
-  m_resourceTable.Delete(res->GetName());
-  delete res;
-  Modify(TRUE);
-  return TRUE;
-}
+        int x, y;
+        int w, h;
+        control->GetPosition(&x, &y);
+        control->GetSize(&w, &h);
 
 
-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);
-      item->GetParent()->Refresh();
-    }
-  }
-  
-  wxItemResource *res = FindResourceForWindow(win);
-  
-  DisassociateResource(res);
-  DeleteResource(res);
-  UpdateResourceList();
+        // Don't include the space taken up by the first and last controls.
+        if (control != firstSelection && control != lastSelection)
+        {
+            if (horizontal)
+                totalControlSpace += w;
+            else
+                totalControlSpace += h;
+        }
 
 
-  return TRUE;
-}
+        node = node->Next();
+    }
 
 
-// Will eventually have bitmap type information, for different
-// kinds of bitmap.
-char *wxResourceManager::AddBitmapResource(char *filename)
-{
-  wxItemResource *resource = FindBitmapResourceByFilename(filename);
-  if (!resource)
-  {
-    char buf[256];
-    MakeUniqueName("bitmap", buf);
-    resource = new wxItemResource;
-    resource->SetType("wxBitmap");
-    resource->SetName(buf);
     
     
-    // A bitmap resource has one or more children, specifying
-    // alternative bitmaps.
-    wxItemResource *child = new wxItemResource;
-    child->SetType("wxBitmap");
-    child->SetName(filename);
-    child->SetValue1(wxBITMAP_TYPE_BMP);
-    child->SetValue2(RESOURCE_PLATFORM_ANY);
-    child->SetValue3(0); // Depth
-    child->SetSize(0,0,0,0);
-    resource->GetChildren().Append(child);
+    int firstX, firstY, lastX, lastY;
+    int firstW, firstH, lastW, lastH;
+    firstSelection->GetPosition(&firstX, &firstY);
+    firstSelection->GetSize(&firstW, &firstH);
 
 
-    m_resourceTable.AddResource(resource);
+    lastSelection->GetPosition(&lastX, &lastY);
+    lastSelection->GetSize(&lastW, &lastH);
 
 
-    UpdateResourceList();
-  }
-  if (resource)
-    return resource->GetName();
-  else
-    return NULL;
-}
+    /*
 
 
- // Delete the bitmap resource if it isn't being used by another resource.
-void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName)
-{
-  if (!IsBitmapResourceUsed(resourceName))
-  {
-    wxItemResource *res = m_resourceTable.FindResource(resourceName);
-    DeleteResource(res);
-    UpdateResourceList();
-  }
-}
+  firstX                  lastX
+    |===| |====| |======| |==|
 
 
-bool wxResourceManager::IsBitmapResourceUsed(char *resourceName)
-{
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    wxString resType(res->GetType());
-    if (resType == "wxDialog")
+    */
+
+    int spacing, currentPos;
+    if (horizontal)
+    {
+        spacing = ((lastX - (firstX + firstW)) - totalControlSpace) / (GetSelections().Number() - 1);
+        currentPos = firstX + firstW + spacing;
+    }
+    else
+    {
+        spacing = ((lastY - (firstY + firstH)) - totalControlSpace) / (GetSelections().Number() - 1);
+        currentPos = firstY + firstH + spacing;
+    }
+
+    node = GetSelections().First();
+
+    while ((node = node->Next()))
     {
     {
-      wxNode *node1 = res->GetChildren().First();
-      while (node1)
-      {
-        wxItemResource *child = (wxItemResource *)node1->Data();
-        wxString childResType(child->GetType());
+        wxControl *item = (wxControl *)node->Data();
+        wxSize sz = item->GetSize();
+        wxPoint pos = item->GetPosition();
+        wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item);
+        wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent());
+        
+        int controlX = (horizontal ? currentPos : pos.x);
+        int controlY = (horizontal ? pos.y : currentPos);
+        
+        item->Move(controlX, controlY);
         
         
-        if ((childResType == "wxMessage" || childResType == "wxButton") &&
-             child->GetValue4() &&
-            (strcmp(child->GetValue4(), resourceName) == 0))
-          return TRUE;
-        node1 = node1->Next();
-      }
+        int resX = controlX;
+        int resY = controlY;
+        
+        // Also update the associated resource
+        // We need to convert to dialog units if this is not a dialog or panel, but
+        // the parent resource specifies dialog units.
+        if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS)
+        {
+            wxPoint convertedPos = item->GetParent()->ConvertPixelsToDialog(wxPoint(resX, resY));
+            resX = convertedPos.x;
+            resY = convertedPos.y;
+        }
+        resource->SetSize(resX, resY, resource->GetWidth(), resource->GetHeight());
+        
+        currentPos += (horizontal ? (sz.x + spacing) : (sz.y + spacing));
     }
     }
-  }
-  return FALSE;
+    win->Refresh();
 }
 
 }
 
-// Given a wxButton or wxMessage, find the corresponding bitmap filename.
-char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource)
+void wxResourceManager::AddSelection(wxWindow *win)
 {
 {
-  if (!resource || !resource->GetValue4())
-    return NULL;
-  wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4());
-  if (!bitmapResource)
-    return NULL;
-
-  wxNode *node = bitmapResource->GetChildren().First();
-  while (node)
-  {
-    // Eventually augment this to return a bitmap of the right kind or something...
-    // Maybe the root of the filename remains the same, so it doesn't matter which we
-    // pick up. Otherwise how do we specify multiple filenames... too boring...
-    wxItemResource *child = (wxItemResource *)node->Data();
-    return child->GetName();
-    
-    node = node->Next();
-  }
-  return NULL;
+    if (!m_selections.Member(win))
+        m_selections.Append(win);
 }
 
 }
 
-wxItemResource *wxResourceManager::FindBitmapResourceByFilename(char *filename)
+void wxResourceManager::RemoveSelection(wxWindow *win)
 {
 {
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    wxString resType(res->GetType());
-    if (resType == "wxBitmap")
-    {
-      wxNode *node1 = res->GetChildren().First();
-      while (node1)
-      {
-        wxItemResource *child = (wxItemResource *)node1->Data();
-        if (child->GetName() && (strcmp(child->GetName(), filename) == 0))
-          return res;
-        node1 = node1->Next();
-      }
-    }
-  }
-  return NULL;
+    m_selections.DeleteObject(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)
+void wxResourceManager::DeselectItemIfNecessary(wxWindow *win)
 {
 {
-  wxItemResource *resource = FindResourceForWindow(win);
-
-  // Put the current window properties into the wxItemResource object
-  
-  wxWindowPropertyInfo *newInfo = NULL;
-  if (!info)
-  {
-    newInfo = CreatePropertyInfoForWindow(win);
-    info = newInfo;
-  }
-
-  info->InstantiateResource(resource);
-
-  wxWindow *newWin = NULL;
-  wxWindow *parent = win->GetParent();
-  
-  if (win->IsKindOf(CLASSINFO(wxPanel)))
-  {
-    Edit(resource);
-    newWin = FindWindowForResource(resource);
-  }
-  else
-  {
-    DisassociateResource(resource);
-    DeleteWindow(win);
-    newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource);
-    AssociateResource(resource, newWin);
-    UpdateResourceList();
-  }
-
-  if (info)
-    info->SetPropertyWindow(newWin);
-    
-  if (newInfo)
-    delete newInfo;
-  
-  return newWin;
+    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
+        }
+    } 
 }
 
 }
 
-// Delete resource highlighted in the listbox
-bool wxResourceManager::DeleteSelection()
+// Need to search through resource table removing this from
+// any resource which has this as a parent.
+bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res)
 {
 {
-  int sel = m_editorResourceTree->GetSelection();
-  if (sel != 0)
-  {
-    wxItemResource *res = (wxItemResource *)m_editorResourceTree->GetItemData(sel);
-    wxWindow *win = FindWindowForResource(res);
-    if (win)
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
     {
     {
-        DeleteResource(win);
-        DeleteWindow(win);
-        UpdateResourceList();
-        Modify(TRUE);
+        wxItemResource *thisRes = (wxItemResource *)node->Data();
+        if (thisRes->GetChildren().Member(res))
+        {
+            thisRes->GetChildren().DeleteObject(res);
+            return TRUE;
+        }
     }
     }
-    return TRUE;
-  }
-
-  return FALSE;
+    return FALSE;
 }
 
 }
 
-// Delete resource highlighted in the listbox
-bool wxResourceManager::RecreateSelection()
+bool wxResourceManager::DeleteResource(wxItemResource *res)
 {
 {
-  wxNode *node = GetSelections().First();
-  while (node)
-  {
-    wxControl *item = (wxControl *)node->Data();
-    wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
-    wxNode *next = node->Next();
-    childHandler->SelectItem(FALSE);
+    if (!res)
+        return FALSE;
+    
+    RemoveResourceFromParent(res);
+    
+    wxNode *node = res->GetChildren().First();
+    while (node)
+    {
+        wxNode *next = node->Next();
+        wxItemResource *child = (wxItemResource *)node->Data();
+        DeleteResource(child);
+        node = next;
+    }
+    
+    // If this is a button or message resource, delete the
+    // associate bitmap resource if not being used.
+    wxString resType(res->GetType());
+    
+    /* shouldn't have to do this now bitmaps are ref-counted
+    if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
+    {
+    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);
+    return TRUE;
+}
 
 
-    RemoveSelection(item);
+bool wxResourceManager::DeleteResource(wxWindow *win)
+{
+    DeselectItemIfNecessary(win);
     
     
-    RecreateWindowFromResource(item);
+    wxItemResource *res = FindResourceForWindow(win);
     
     
-    node = next;
-  }
-  return TRUE;
+    DisassociateResource(res);
+    DeleteResource(res);
+    UpdateResourceList();
+    
+    return TRUE;
 }
 
 }
 
-bool wxResourceManager::EditDialog(wxDialog *dialog, wxWindow *parent)
+// Will eventually have bitmap type information, for different
+// kinds of bitmap.
+wxString wxResourceManager::AddBitmapResource(const wxString& filename)
 {
 {
-  return FALSE;
+    wxItemResource *resource = FindBitmapResourceByFilename(filename);
+    if (!resource)
+    {
+        char buf[256];
+        MakeUniqueName("bitmap", buf);
+        resource = new wxItemResource;
+        resource->SetType("wxBitmap");
+        resource->SetName(buf);
+        
+        // A bitmap resource has one or more children, specifying
+        // alternative bitmaps.
+        wxItemResource *child = new wxItemResource;
+        child->SetType("wxBitmap");
+        child->SetName(filename);
+        child->SetValue1(wxBITMAP_TYPE_BMP);
+        child->SetValue2(RESOURCE_PLATFORM_ANY);
+        child->SetValue3(0); // Depth
+        child->SetSize(0,0,0,0);
+        resource->GetChildren().Append(child);
+        
+        m_resourceTable.AddResource(resource);
+        
+        UpdateResourceList();
+    }
+    if (resource)
+        return resource->GetName();
+    else
+        return wxEmptyString;
 }
 
 }
 
-// Ensures that all currently shown windows are saved to resources,
-// e.g. just before writing to a .wxr file.
-bool wxResourceManager::InstantiateAllResourcesFromWindows()
+// Delete the bitmap resource if it isn't being used by another resource.
+void wxResourceManager::PossiblyDeleteBitmapResource(const wxString& resourceName)
 {
 {
-  m_resourceTable.BeginFind();
-  wxNode *node;
-  while (node = m_resourceTable.Next())
-  {
-    wxItemResource *res = (wxItemResource *)node->Data();
-    wxString resType(res->GetType());
-    
-    if (resType == "wxDialog")
+    if (!IsBitmapResourceUsed(resourceName))
     {
     {
-      wxWindow *win = (wxWindow *)FindWindowForResource(res);
-      if (win)
-        InstantiateResourceFromWindow(res, win, TRUE);
+        wxItemResource *res = m_resourceTable.FindResource(resourceName);
+        DeleteResource(res);
+        UpdateResourceList();
     }
     }
-    else if (resType == "wxPanel")
+}
+
+bool wxResourceManager::IsBitmapResourceUsed(const wxString& resourceName)
+{
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
     {
     {
-      wxWindow *win = (wxWindow *)FindWindowForResource(res);
-      if (win)
-        InstantiateResourceFromWindow(res, win, TRUE);
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxString resType(res->GetType());
+        if (resType == "wxDialog")
+        {
+            wxNode *node1 = res->GetChildren().First();
+            while (node1)
+            {
+                wxItemResource *child = (wxItemResource *)node1->Data();
+                wxString childResType(child->GetType());
+                
+                if ((childResType == "wxMessage" || childResType == "wxButton") &&
+                    child->GetValue4() &&
+                    (strcmp(child->GetValue4(), resourceName) == 0))
+                    return TRUE;
+                node1 = node1->Next();
+            }
+        }
     }
     }
-  }
-  return TRUE;  
+    return FALSE;
 }
 
 }
 
-bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse)
+// Given a wxButton or wxMessage, find the corresponding bitmap filename.
+wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource)
 {
 {
-  wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(window);
-  info->SetResource(resource);
-  info->InstantiateResource(resource);
-  delete info;
-  
-  if (recurse)
-  {
-    wxNode *node = resource->GetChildren().First();
+    if (!resource || (resource->GetValue4() == ""))
+        return wxEmptyString;
+    wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4());
+    if (!bitmapResource)
+        return wxEmptyString;
+    
+    wxNode *node = bitmapResource->GetChildren().First();
     while (node)
     {
     while (node)
     {
-      wxItemResource *child = (wxItemResource *)node->Data();
-      wxWindow *childWindow = FindWindowForResource(child);
-      
-      if (!childWindow)
-      {
-        char buf[200];
-        sprintf(buf, "Could not find window %s", child->GetName());
-        wxMessageBox(buf, "Dialog Editor problem", wxOK);
-      }
-      else
-        InstantiateResourceFromWindow(child, childWindow, recurse);
-      node = node->Next();
-    }
-  }
-  
-  return TRUE;
+        // Eventually augment this to return a bitmap of the right kind or something...
+        // Maybe the root of the filename remains the same, so it doesn't matter which we
+        // pick up. Otherwise how do we specify multiple filenames... too boring...
+        wxItemResource *child = (wxItemResource *)node->Data();
+        return child->GetName();
+        
+        //node = node->Next();
+    }
+    return wxEmptyString;
 }
 
 }
 
-// Create a window information object for the give window
-wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *win)
+wxItemResource *wxResourceManager::FindBitmapResourceByFilename(const wxString& filename)
 {
 {
-  wxWindowPropertyInfo *info = NULL;
-  if (win->IsKindOf(CLASSINFO(wxScrollBar)))
-        {
-          info = new wxScrollBarPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxStaticBox)))
-        {
-          info = new wxGroupBoxPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxCheckBox)))
-        {
-          info = new wxCheckBoxPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxSlider)))
-        {
-          info = new wxSliderPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxGauge)))
-        {
-          info = new wxGaugePropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxListBox)))
-        {
-          info = new wxListBoxPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxRadioBox)))
-        {
-          info = new wxRadioBoxPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxRadioButton)))
-        {
-          info = new wxRadioButtonPropertyInfo(win);
-        }
-  else if (win->IsKindOf(CLASSINFO(wxChoice)))
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
+    {
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxString resType(res->GetType());
+        if (resType == "wxBitmap")
         {
         {
-          info = new wxChoicePropertyInfo(win);
+            wxNode *node1 = res->GetChildren().First();
+            while (node1)
+            {
+                wxItemResource *child = (wxItemResource *)node1->Data();
+                if (child->GetName() && (strcmp(child->GetName(), filename) == 0))
+                    return res;
+                node1 = node1->Next();
+            }
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxButton)))
+    }
+    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();
+        
+        wxString resType(res->GetType());
+        if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
         {
         {
-          info = new wxButtonPropertyInfo(win);
+            if ((res != thisResource) && (res->GetId() == id))
+                return TRUE;
+            
+            wxNode *node1 = res->GetChildren().First();
+            while (node1)
+            {
+                wxItemResource *child = (wxItemResource *)node1->Data();
+                if ((child != thisResource) && (child->GetId() == id))
+                    return TRUE;
+                node1 = node1->Next();
+            }
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxBitmapButton)))
+    }
+    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();
+        
+        wxString resType(res->GetType());
+        if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
         {
         {
-          info = new wxBitmapButtonPropertyInfo(win);
+            if (res->GetId() == oldId)
+                res->SetId(newId);
+            
+            wxNode *node1 = res->GetChildren().First();
+            while (node1)
+            {
+                wxItemResource *child = (wxItemResource *)node1->Data();
+                if (child->GetId() == oldId)
+                    child->SetId(newId);
+                
+                node1 = node1->Next();
+            }
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxStaticText)))
+    }
+}
+
+// If any resource ids were missing (or their symbol was missing),
+// repair them i.e. give them new ids. Returns TRUE if any resource
+// needed repairing.
+bool wxResourceManager::RepairResourceIds()
+{
+    bool repaired = FALSE;
+    
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
+    {
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxString resType(res->GetType());
+        if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
         {
         {
-          info = new wxStaticTextPropertyInfo(win);
+            
+            if ( (res->GetId() == 0) || ((res->GetId() > 0) && !m_symbolTable.IdExists(res->GetId())) )
+            {
+                wxString newSymbolName;
+                int newId = GenerateWindowId("ID_DIALOG", newSymbolName) ;
+                
+                if (res->GetId() == 0)
+                {
+                    res->SetId(newId);
+                    m_symbolTable.AddSymbol(newSymbolName, newId);
+                }
+                else
+                {
+                    m_symbolTable.AddSymbol(newSymbolName, res->GetId());
+                }
+                
+                repaired = TRUE;
+            }
+            
+            wxNode *node1 = res->GetChildren().First();
+            while (node1)
+            {
+                wxItemResource *child = (wxItemResource *)node1->Data();
+                
+                if ( (child->GetId() == 0) || ((child->GetId() > 0) && !m_symbolTable.IdExists(child->GetId())) )
+                {
+                    wxString newSymbolName;
+                    int newId = GenerateWindowId("ID_CONTROL", newSymbolName) ;
+                    
+                    if (child->GetId() == 0)
+                    {
+                        child->SetId(newId);
+                        m_symbolTable.AddSymbol(newSymbolName, newId);
+                    }
+                    else
+                    {
+                        m_symbolTable.AddSymbol(newSymbolName, child->GetId());
+                    }
+                    
+                    repaired = TRUE;
+                }
+                
+                node1 = node1->Next();
+            }
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxStaticBitmap)))
+    }
+    return repaired;
+}
+
+
+// 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, bool instantiateFirst)
+{
+    wxItemResource *resource = FindResourceForWindow(win);
+    
+    // Put the current window properties into the wxItemResource object
+    
+    wxWindowPropertyInfo *newInfo = NULL;
+    if (!info)
+    {
+        newInfo = CreatePropertyInfoForWindow(win);
+        info = newInfo;
+    }
+    
+    // May not always want to copy values back from the resource
+    if (instantiateFirst)
+        info->InstantiateResource(resource);
+    
+    wxWindow *newWin = NULL;
+    wxWindow *parent = win->GetParent();
+    wxItemResource* parentResource = NULL;
+    if (parent)
+        parentResource = FindResourceForWindow(parent);
+    
+    if (win->IsKindOf(CLASSINFO(wxPanel)))
+    {
+        Edit(resource);
+        newWin = FindWindowForResource(resource);
+    }
+    else
+    {
+        DisassociateResource(resource);
+        if (win->GetEventHandler() != win)
+            win->PopEventHandler(TRUE);
+        
+        DeleteWindow(win);
+        newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource, parentResource);
+        newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin));
+        AssociateResource(resource, newWin);
+        UpdateResourceList();
+    }
+    
+    if (info)
+        info->SetPropertyWindow(newWin);
+    
+    if (newInfo)
+        delete newInfo;
+    
+    return newWin;
+}
+
+// Delete resource highlighted in the listbox
+bool wxResourceManager::DeleteSelection()
+{
+    int sel = m_editorResourceTree->GetSelection();
+    if (sel != 0)
+    {
+        wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel);
+        wxItemResource *res = data->GetResource();
+        wxWindow *win = FindWindowForResource(res);
+        if (win)
         {
         {
-          info = new wxStaticBitmapPropertyInfo(win);
+            DeleteResource(win);
+            DeleteWindow(win);
+            UpdateResourceList();
+            Modify(TRUE);
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxTextCtrl)))
+        return TRUE;
+    }
+    
+    return FALSE;
+}
+
+// Delete resource highlighted in the listbox
+bool wxResourceManager::RecreateSelection()
+{
+    wxNode *node = GetSelections().First();
+    while (node)
+    {
+        wxControl *item = (wxControl *)node->Data();
+        wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler();
+        wxNode *next = node->Next();
+        childHandler->SelectItem(FALSE);
+        
+        RemoveSelection(item);
+        
+        RecreateWindowFromResource(item);
+        
+        node = next;
+    }
+    return TRUE;
+}
+
+bool wxResourceManager::EditDialog(wxDialog *WXUNUSED(dialog), wxWindow *WXUNUSED(parent))
+{
+    return FALSE;
+}
+
+// Ensures that all currently shown windows are saved to resources,
+// e.g. just before writing to a .wxr file.
+bool wxResourceManager::InstantiateAllResourcesFromWindows()
+{
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
+    {
+        wxItemResource *res = (wxItemResource *)node->Data();
+        wxString resType(res->GetType());
+        
+        if (resType == "wxDialog")
         {
         {
-          info = new wxTextPropertyInfo(win);
+            wxWindow *win = (wxWindow *)FindWindowForResource(res);
+            if (win)
+                InstantiateResourceFromWindow(res, win, TRUE);
         }
         }
-  else if (win->IsKindOf(CLASSINFO(wxPanel)))
+        else if (resType == "wxPanel")
         {
         {
-          info = new wxPanelPropertyInfo(win);
+            wxWindow *win = (wxWindow *)FindWindowForResource(res);
+            if (win)
+                InstantiateResourceFromWindow(res, win, TRUE);
         }
         }
-  else
+    }
+    return TRUE;  
+}
+
+bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse)
+{
+    wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(window);
+    info->SetResource(resource);
+    info->InstantiateResource(resource);
+    delete info;
+    
+    if (recurse)
+    {
+        wxNode *node = resource->GetChildren().First();
+        while (node)
         {
         {
-          info = new wxWindowPropertyInfo(win);
+            wxItemResource *child = (wxItemResource *)node->Data();
+            wxWindow *childWindow = FindWindowForResource(child);
+            
+            if (!childWindow)
+            {
+                char buf[200];
+                sprintf(buf, "Could not find window %s", (const char*) child->GetName());
+                wxMessageBox(buf, "Dialog Editor problem", wxOK);
+            }
+            else
+                InstantiateResourceFromWindow(child, childWindow, recurse);
+            node = node->Next();
         }
         }
-  return info;
+    }
+    
+    return TRUE;
+}
+
+// Create a window information object for the give window
+wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *win)
+{
+    wxWindowPropertyInfo *info = NULL;
+    if (win->IsKindOf(CLASSINFO(wxScrollBar)))
+    {
+        info = new wxScrollBarPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxStaticBox)))
+    {
+        info = new wxGroupBoxPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxCheckBox)))
+    {
+        info = new wxCheckBoxPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxSlider)))
+    {
+        info = new wxSliderPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxGauge)))
+    {
+        info = new wxGaugePropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxListBox)))
+    {
+        info = new wxListBoxPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxRadioBox)))
+    {
+        info = new wxRadioBoxPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxRadioButton)))
+    {
+        info = new wxRadioButtonPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxComboBox)))
+    {
+        info = new wxComboBoxPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxChoice)))
+    {
+        info = new wxChoicePropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxBitmapButton)))
+    {
+        info = new wxBitmapButtonPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxButton)))
+    {
+        info = new wxButtonPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxStaticBitmap)))
+    {
+        info = new wxStaticBitmapPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxStaticText)))
+    {
+        info = new wxStaticTextPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxTextCtrl)))
+    {
+        info = new wxTextPropertyInfo(win);
+    }
+    else if (win->IsKindOf(CLASSINFO(wxPanel)))
+    {
+        info = new wxPanelPropertyInfo(win);
+    }
+    else
+    {
+        info = new wxWindowPropertyInfo(win);
+    }
+    return info;
 }
 
 // Edit the given window
 void wxResourceManager::EditWindow(wxWindow *win)
 {
 }
 
 // Edit the given window
 void wxResourceManager::EditWindow(wxWindow *win)
 {
-  wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(win);
-  if (info)
-  {
-    info->SetResource(FindResourceForWindow(win));
-    wxString str("Editing ");
-    str += win->GetClassInfo()->GetClassName();
-    str += ": ";
-    if (win->GetName() != "")
-        str += win->GetName();
-    else
-        str += "properties";
-    info->Edit(NULL, str);
-  }
+    wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(win);
+    if (info)
+    {
+        info->SetResource(FindResourceForWindow(win));
+        wxString str("Editing ");
+        str += win->GetClassInfo()->GetClassName();
+        str += ": ";
+        if (win->GetName() != "")
+            str += win->GetName();
+        else
+            str += "properties";
+        info->Edit(NULL, str);
+    }
+}
+
+// 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
- */
+* Resource editor frame
+*/
 
 IMPLEMENT_CLASS(wxResourceEditorFrame, wxFrame)
 
 BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame)
 
 IMPLEMENT_CLASS(wxResourceEditorFrame, wxFrame)
 
 BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame)
-    EVT_MENU(wxID_NEW, wxResourceEditorFrame::OnNew)
-    EVT_MENU(RESED_NEW_DIALOG, wxResourceEditorFrame::OnNewDialog)
-    EVT_MENU(wxID_OPEN, wxResourceEditorFrame::OnOpen)
-    EVT_MENU(RESED_CLEAR, wxResourceEditorFrame::OnClear)
-    EVT_MENU(wxID_SAVE, wxResourceEditorFrame::OnSave)
-    EVT_MENU(wxID_SAVEAS, wxResourceEditorFrame::OnSaveAs)
-    EVT_MENU(wxID_EXIT, wxResourceEditorFrame::OnExit)
-    EVT_MENU(wxID_ABOUT, wxResourceEditorFrame::OnAbout)
-    EVT_MENU(RESED_CONTENTS, wxResourceEditorFrame::OnContents)
-    EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection)
-    EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection)
-    EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest)
+EVT_MENU(wxID_NEW, wxResourceEditorFrame::OnNew)
+EVT_MENU(RESED_NEW_DIALOG, wxResourceEditorFrame::OnNewDialog)
+EVT_MENU(wxID_OPEN, wxResourceEditorFrame::OnOpen)
+EVT_MENU(RESED_CLEAR, wxResourceEditorFrame::OnClear)
+EVT_MENU(wxID_SAVE, wxResourceEditorFrame::OnSave)
+EVT_MENU(wxID_SAVEAS, wxResourceEditorFrame::OnSaveAs)
+EVT_MENU(wxID_EXIT, wxResourceEditorFrame::OnExit)
+EVT_MENU(wxID_ABOUT, wxResourceEditorFrame::OnAbout)
+EVT_MENU(RESED_CONTENTS, wxResourceEditorFrame::OnContents)
+EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection)
+EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection)
+EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest)
+EVT_MENU(RESED_CONVERT_WXRS, wxResourceEditorFrame::OnConvertWXRs)
+EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow)
 END_EVENT_TABLE()
 
 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
 END_EVENT_TABLE()
 
 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
-    const wxPoint& pos, const wxSize& size, long style, const wxString& name):
-  wxFrame(parent, -1, title, pos, size, style, name)
+                                             const wxPoint& pos, const wxSize& size, long style, const wxString& name):
+wxFrame(parent, -1, title, pos, size, style, name)
 {
 {
-  manager = resMan;
+    manager = resMan;
 }
 
 wxResourceEditorFrame::~wxResourceEditorFrame()
 {
 }
 
 }
 
 wxResourceEditorFrame::~wxResourceEditorFrame()
 {
 }
 
-void wxResourceEditorFrame::OnNew(wxCommandEvent& event)
+void wxResourceEditorFrame::OnConvertWXRs(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->New(FALSE);
+      manager->ConvertWXRs();
 }
 
 }
 
-void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& event)
+void wxResourceEditorFrame::OnNew(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->CreateNewPanel();
+    manager->New(FALSE);
 }
 
 }
 
-void wxResourceEditorFrame::OnOpen(wxCommandEvent& event)
+void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->New(TRUE);
+    manager->CreateNewPanel();
 }
 
 }
 
-void wxResourceEditorFrame::OnClear(wxCommandEvent& event)
+void wxResourceEditorFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->Clear(TRUE, FALSE);
+    manager->New(TRUE);
 }
 
 }
 
-void wxResourceEditorFrame::OnSave(wxCommandEvent& event)
+void wxResourceEditorFrame::OnClear(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->Save();
+    manager->Clear(TRUE, FALSE);
 }
 
 }
 
-void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& event)
+void wxResourceEditorFrame::OnSave(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->SaveAs();
+    manager->Save();
 }
 
 }
 
-void wxResourceEditorFrame::OnExit(wxCommandEvent& event)
+void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event))
 {
 {
-         manager->Clear(TRUE, FALSE) ;
-      this->Close();
+    manager->SaveAs();
 }
 
 }
 
-void wxResourceEditorFrame::OnAbout(wxCommandEvent& event)
+void wxResourceEditorFrame::OnExit(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);
-      wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE);
+    manager->Clear(TRUE, FALSE) ;
+    this->Destroy();
 }
 
 }
 
-void wxResourceEditorFrame::OnTest(wxCommandEvent& event)
+void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
+{
+    char buf[300];
+    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);
+}
+
+void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event))
 {
     manager->TestCurrentDialog(this);
 }
 
 {
     manager->TestCurrentDialog(this);
 }
 
-void wxResourceEditorFrame::OnContents(wxCommandEvent& event)
+void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event))
 {
 {
-      wxBeginBusyCursor();
-      manager->GetHelpController()->LoadFile();
-      manager->GetHelpController()->DisplayContents();
-      wxEndBusyCursor();
+#ifdef __WXMSW__
+    wxBeginBusyCursor();
+    manager->GetHelpController()->LoadFile();
+    manager->GetHelpController()->DisplayContents();
+    wxEndBusyCursor();
+#endif
 }
 
 }
 
-void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& event)
+void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->DeleteSelection();
+    manager->DeleteSelection();
 }
 
 }
 
-void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& event)
+void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event))
 {
 {
-      manager->RecreateSelection();
+    manager->RecreateSelection();
 }
 
 }
 
-bool wxResourceEditorFrame::OnClose()
+void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event)
 {
 {
-  if (manager->Modified())
-  {
-  if (!manager->Clear(TRUE, FALSE))
-     return FALSE;
-  }
+    wxPropertyInfo::CloseWindow();
+    manager->ClearCurrentDialog();
+    if (manager->Modified())
+    {
+        if (!manager->Clear(TRUE, FALSE))
+        {
+            event.Veto();
+            return;
+        }
+    }
     
     
-  if (!Iconized())
-  {
-    int w, h;
-    GetSize(&w, &h);
-    manager->m_resourceEditorWindowSize.width = w;
-    manager->m_resourceEditorWindowSize.height = h;
-
-    int x, y;
-    GetPosition(&x, &y);
-
-    manager->m_resourceEditorWindowSize.x = x;
-    manager->m_resourceEditorWindowSize.y = y;
-  }
-  manager->SetEditorFrame(NULL);
-  manager->SetEditorToolBar(NULL);
-
-  return TRUE;
+    if (!IsIconized())
+    {
+        int w, h;
+        GetSize(&w, &h);
+        manager->m_resourceEditorWindowSize.width = w;
+        manager->m_resourceEditorWindowSize.height = h;
+        
+        int x, y;
+        GetPosition(&x, &y);
+        
+        manager->m_resourceEditorWindowSize.x = x;
+        manager->m_resourceEditorWindowSize.y = y;
+    }
+    manager->SetEditorFrame(NULL);
+    manager->SetEditorToolBar(NULL);
+    
+    this->Destroy();
 }
 
 /*
 }
 
 /*
- * Resource editor window that contains the dialog/panel being edited
- */
+* Resource editor window that contains the dialog/panel being edited
+*/
 
 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow)
 
 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow)
-    EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll)
-    EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint)
+EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint)
 END_EVENT_TABLE()
 
 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos, const wxSize& size,
 END_EVENT_TABLE()
 
 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos, const wxSize& size,
-    long style):
-  wxScrolledWindow(parent, -1, pos, size, style)
+                                                               long style):
+wxScrolledWindow(parent, -1, pos, size, style)
 {
     m_marginX = 10;
     m_marginY = 40;
     m_childWindow = NULL;
 {
     m_marginX = 10;
     m_marginY = 40;
     m_childWindow = NULL;
+    
+    SetBackgroundColour(* wxWHITE);
 }
 
 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
 {
 }
 
 }
 
 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& event)
+void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
     wxPaintDC dc(this);
 {
     wxPaintDC dc(this);
-
+    
     DrawTitle(dc);
 }
 
     DrawTitle(dc);
 }
 
@@ -1910,208 +2382,591 @@ void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc)
         {
             wxString str(res->GetTitle());
             int x, y;
         {
             wxString str(res->GetTitle());
             int x, y;
-            ViewStart(& x, & y);
-
+            GetViewStart(& x, & y);
+            
             wxFont font(10, wxSWISS, wxNORMAL, wxBOLD);
             dc.SetFont(font);
             dc.SetBackgroundMode(wxTRANSPARENT);
             dc.SetTextForeground(wxColour(0, 0, 0));
             wxFont font(10, wxSWISS, wxNORMAL, wxBOLD);
             dc.SetFont(font);
             dc.SetBackgroundMode(wxTRANSPARENT);
             dc.SetTextForeground(wxColour(0, 0, 0));
-
+            
             long w, h;
             dc.GetTextExtent(str, & w, & h);
             long w, h;
             dc.GetTextExtent(str, & w, & h);
-
+            
             dc.DrawText(str, m_marginX + (- x * 10), m_marginY + (- y * 10) - h - 5);
         }
     }
 }
 
 // Popup menu callback
             dc.DrawText(str, m_marginX + (- x * 10), m_marginY + (- y * 10) - h - 5);
         }
     }
 }
 
 // Popup menu callback
-void ObjectMenuProc(wxMenumenu, wxCommandEvent& event)
+void ObjectMenuProc(wxMenu *menu, wxCommandEvent& event)
 {
 {
-  wxWindow *data = (wxWindow *)menu.GetClientData();
-  if (!data)
-    return;
-
-  switch (event.GetInt())
-  {
-    case OBJECT_MENU_EDIT:
+    wxWindow *data = (wxWindow *)menu->GetClientData();
+    if (!data)
+        return;
+    
+    switch (event.GetId())
     {
     {
-      wxResourceManager::GetCurrentResourceManager()->EditWindow(data);
-      break;
-    }
+    case OBJECT_MENU_TITLE:
+        {
+            event.Skip();
+            break;
+        }
+    case OBJECT_MENU_EDIT:
+        {
+            wxResourceManager::GetCurrentResourceManager()->EditWindow(data);
+            break;
+        }
     case OBJECT_MENU_DELETE:
     case OBJECT_MENU_DELETE:
-    {
-      wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
-      wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
-      wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);
-      break;
-    }
+        {
+            // Before deleting a dialog, give the user a last chance
+            // change their mind, in case they accidentally right
+            // clicked the dialog rather than the widget they were
+            // aiming for.
+            if (data->IsKindOf(CLASSINFO(wxPanel)))
+            {
+                wxString str(wxT("Deleting dialog : "));
+                str += data->GetName();
+                if (wxMessageBox(wxT("Are you sure?"), str, wxYES_NO | wxCENTRE) == wxNO)
+                    return;
+            }
+
+            wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data);
+
+            wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data);
+            wxResourceManager::GetCurrentResourceManager()->DeleteResource(data);
+            wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data);
+            break;
+        }
     default:
     default:
-      break;
-  }
+        break;
+    }
 }
 
 /*
 }
 
 /*
- * Main toolbar
- *
- */
+* Main toolbar
+*
+*/
 
 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
 
 BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar)
-       EVT_PAINT(EditorToolBar::OnPaint)
+//     EVT_PAINT(EditorToolBar::OnPaint)
 END_EVENT_TABLE()
 
 EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size,
 END_EVENT_TABLE()
 
 EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size,
-            long style):
-  wxToolBar(frame, -1, pos, size, style)
+                             long style):
+wxToolBar(frame, -1, pos, size, style)
 {
 }
 
 {
 }
 
-bool EditorToolBar::OnLeftClick(int toolIndex, bool toggled)
+bool EditorToolBar::OnLeftClick(int toolIndex, bool WXUNUSED(toggled))
 {
 {
-  wxResourceManager *manager = wxResourceManager::GetCurrentResourceManager();
-
-  switch (toolIndex)
-  {
-    case TOOLBAR_LOAD_FILE:
+    wxResourceManager *manager = wxResourceManager::GetCurrentResourceManager();
+    
+    switch (toolIndex)
     {
     {
-      manager->New(TRUE);
-      break;
-    }
+    case TOOLBAR_LOAD_FILE:
+        {
+            manager->New(TRUE);
+            break;
+        }
     case TOOLBAR_NEW:
     case TOOLBAR_NEW:
-    {
-      manager->CreateNewPanel();
-      break;
-    }
+        {
+            manager->CreateNewPanel();
+            break;
+        }
     case TOOLBAR_SAVE_FILE:
     case TOOLBAR_SAVE_FILE:
-    {
-      manager->Save();
-      break;
-    }
+        {
+            manager->Save();
+            break;
+        }
     case TOOLBAR_HELP:
     case TOOLBAR_HELP:
-    {
-      wxBeginBusyCursor();
-      manager->GetHelpController()->LoadFile();
-      manager->GetHelpController()->DisplayContents();
-      wxEndBusyCursor();
-      break;
-    }
+        {
+#ifdef __WXMSW__
+            wxBeginBusyCursor();
+            manager->GetHelpController()->DisplayContents();
+            wxEndBusyCursor();
+#endif
+            break;
+        }
     case TOOLBAR_FORMAT_HORIZ:
     case TOOLBAR_FORMAT_HORIZ:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_HORIZ);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_HORIZ);
+            break;
+        }
     case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
     case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN);
+            break;
+        }
     case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
     case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN);
+            break;
+        }
     case TOOLBAR_FORMAT_VERT:
     case TOOLBAR_FORMAT_VERT:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_VERT);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_VERT);
+            break;
+        }
     case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
     case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN);
+            break;
+        }
     case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
     case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
-    {
-      manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN);
-      break;
-    }
+        {
+            manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN);
+            break;
+        }
     case TOOLBAR_COPY_SIZE:
     case TOOLBAR_COPY_SIZE:
-    {
-      manager->CopySize();
-      break;
-    }
+        {
+            manager->CopySize(TOOLBAR_COPY_SIZE);
+            break;
+        }
+    case TOOLBAR_COPY_WIDTH:
+        {
+            manager->CopySize(TOOLBAR_COPY_WIDTH);
+            break;
+        }
+    case TOOLBAR_COPY_HEIGHT:
+        {
+            manager->CopySize(TOOLBAR_COPY_HEIGHT);
+            break;
+        }
+    case TOOLBAR_DISTRIBUTE_HORIZ:
+        {
+            manager->DistributePositions(TOOLBAR_DISTRIBUTE_HORIZ);
+            break;
+        }
+    case TOOLBAR_DISTRIBUTE_VERT:
+        {
+            manager->DistributePositions(TOOLBAR_DISTRIBUTE_VERT);
+            break;
+        }
     case TOOLBAR_TO_BACK:
     case TOOLBAR_TO_BACK:
-    {
-      manager->ToBackOrFront(TRUE);
-      break;
-    }
+        {
+            manager->ToBackOrFront(TRUE);
+            break;
+        }
     case TOOLBAR_TO_FRONT:
     case TOOLBAR_TO_FRONT:
-    {
-      manager->ToBackOrFront(FALSE);
-      break;
-    }
+        {
+            manager->ToBackOrFront(FALSE);
+            break;
+        }
     default:
     default:
-      break;
-  }
-  return TRUE;
+        break;
+    }
+    return TRUE;
 }
 
 void EditorToolBar::OnMouseEnter(int toolIndex)
 {
 }
 
 void EditorToolBar::OnMouseEnter(int toolIndex)
 {
-  wxFrame *frame = (wxFrame *)GetParent();
-  
-  if (!frame) return;
-  
-  if (toolIndex > -1)
-  {
-      switch (toolIndex)
-      {
+    wxFrame *frame = (wxFrame *)GetParent();
+    
+    if (!frame) return;
+    
+    if (toolIndex > -1)
+    {
+        switch (toolIndex)
+        {
         case TOOLBAR_LOAD_FILE:
         case TOOLBAR_LOAD_FILE:
-          frame->SetStatusText("Load project file");
-          break;
+            frame->SetStatusText("Load project file");
+            break;
         case TOOLBAR_SAVE_FILE:
         case TOOLBAR_SAVE_FILE:
-          frame->SetStatusText("Save project file");
-          break;
+            frame->SetStatusText("Save project file");
+            break;
         case TOOLBAR_NEW:
         case TOOLBAR_NEW:
-          frame->SetStatusText("Create a new resource");
-          break;
+            frame->SetStatusText("Create a new resource");
+            break;
         case TOOLBAR_FORMAT_HORIZ:
         case TOOLBAR_FORMAT_HORIZ:
-          frame->SetStatusText("Align items horizontally");
-          break;
+            frame->SetStatusText("Align items horizontally");
+            break;
         case TOOLBAR_FORMAT_VERT:
         case TOOLBAR_FORMAT_VERT:
-          frame->SetStatusText("Align items vertically");
-          break;
+            frame->SetStatusText("Align items vertically");
+            break;
         case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
         case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN:
-          frame->SetStatusText("Left-align items");
-          break;
+            frame->SetStatusText("Left-align items");
+            break;
         case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
         case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN:
-          frame->SetStatusText("Right-align items");
-          break;
+            frame->SetStatusText("Right-align items");
+            break;
         case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
         case TOOLBAR_FORMAT_VERT_TOP_ALIGN:
-          frame->SetStatusText("Top-align items");
-          break;
+            frame->SetStatusText("Top-align items");
+            break;
         case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
         case TOOLBAR_FORMAT_VERT_BOT_ALIGN:
-          frame->SetStatusText("Bottom-align items");
-          break;
+            frame->SetStatusText("Bottom-align items");
+            break;
         case TOOLBAR_COPY_SIZE:
         case TOOLBAR_COPY_SIZE:
-          frame->SetStatusText("Copy size from first selection");
-          break;
+            frame->SetStatusText("Copy size from first selection");
+            break;
         case TOOLBAR_TO_FRONT:
         case TOOLBAR_TO_FRONT:
-          frame->SetStatusText("Put image to front");
-          break;
+            frame->SetStatusText("Put image to front");
+            break;
         case TOOLBAR_TO_BACK:
         case TOOLBAR_TO_BACK:
-          frame->SetStatusText("Put image to back");
-          break;
+            frame->SetStatusText("Put image to back");
+            break;
         case TOOLBAR_HELP:
         case TOOLBAR_HELP:
-          frame->SetStatusText("Display help contents");
-          break;
+            frame->SetStatusText("Display help contents");
+            break;
         default:
         default:
-          break;
-      }
-  }
-  else frame->SetStatusText("");
+            break;
+        }
+    }
+    else frame->SetStatusText("");
 }
 
 }
 
-void EditorToolBar::OnPaint(wxPaintEvent& event)
+bool ResourceEditorDialogTester::ProcessEvent(wxEvent& event)
 {
 {
-  wxToolBar::OnPaint(event);
+    if (event.IsCommandEvent() && event.GetId() != wxID_OK && event.GetId() != wxID_CANCEL)
+    {
+        // Do nothing
+        return TRUE;
+    }
+    else
+        return wxDialog::ProcessEvent(event);
+}
+
+static int gs_LabelInsertionCount = 0;
+
+// Convert old WXRs to new
+bool wxResourceManager::ConvertWXRs()
+{
+    gs_LabelInsertionCount = 0;
+    m_symbolIdCounter = 20000;
+
+    wxString currentPath = wxGetCwd();
+    wxString oldWXRPath, newWXRPath;
+
+    wxDirDialog dialog(NULL, wxT("Choose directory for old WXRs"), currentPath);
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        oldWXRPath = dialog.GetPath();
+    }
+    else
+        return FALSE;
+
+    wxDirDialog dialog2(NULL, wxT("Choose directory for new WXRs"), oldWXRPath);
+
+    if (dialog2.ShowModal() == wxID_OK)
+    {
+        newWXRPath = dialog2.GetPath();
+    }
+    else
+        return FALSE;
+
+    if (newWXRPath == oldWXRPath)
+    {
+        wxMessageBox(wxT("Sorry, the directories must be different."));
+        return FALSE;
+    }
+
+    wxDir dir(oldWXRPath);
+    if (!dir.IsOpened())
+        return FALSE;
+
+    wxArrayString stringArray;
+
+    wxString filename;
+    bool ok = dir.GetFirst(& filename, wxT("*.wxr"));
+    while (ok)
+    {
+        stringArray.Add(filename);
+
+        ok = dir.GetNext(& filename);
+    }
 
 
-  wxPaintDC dc(this);
-  int w, h;
-  GetSize(&w, &h);
-  dc.SetPen(wxBLACK_PEN);
-  dc.SetBrush(wxTRANSPARENT_BRUSH);
-  dc.DrawLine(0, h-1, w, h-1);
+    // Pop up a progress dialog
+    wxProgressDialog progressDialog(wxT("Converting WXR files"), wxT("Converting files..."));
+
+    size_t i;
+    for (i = 0; i < stringArray.Count(); i++)
+    {
+        progressDialog.Update((int) (100.0 * ((double) i / (double) stringArray.Count())));
+
+        filename = stringArray[i];
+        wxString oldPath = oldWXRPath + wxString(wxFILE_SEP_PATH) + filename;
+        wxString newPath = newWXRPath + wxString(wxFILE_SEP_PATH) + filename;
+
+        DoConvertWXR(oldPath, newPath);
+    }
+
+    wxString msg;
+    msg.Printf(wxT("Dialog Editor inserted %d labels."), gs_LabelInsertionCount);
+    wxMessageBox(msg);
+
+    return TRUE;
 }
 
 }
 
+bool wxResourceManager::DoConvertWXR(const wxString& oldPath, const wxString& newPath)
+{
+
+    if (!Clear(TRUE, FALSE))
+        return FALSE;
+    
+    m_symbolTable.AddStandardSymbols();
+
+    if (!m_resourceTable.ParseResourceFile(oldPath))
+    {
+        wxString msg;
+        msg.Printf(wxT("Could not read file %s"), (const char*) oldPath);
+        wxMessageBox(msg, "Resource file load error", wxOK | wxICON_EXCLAMATION);
+        return FALSE;
+    }
+    m_currentFilename = oldPath;
+
+    //SetFrameTitle(m_currentFilename);
+
+    //UpdateResourceList();
+
+    // Construct include filename from this file
+    m_symbolFilename = m_currentFilename;
+
+    wxStripExtension(m_symbolFilename);
+    m_symbolFilename += wxT(".h");
+
+    if (!m_symbolTable.ReadIncludeFile(m_symbolFilename))
+    {
+    }
+    else
+    {
+        // Set the id counter to the last known id
+        m_symbolIdCounter = m_symbolTable.FindHighestId();
+    }
+
+    // Now check in case some (or all) resources don't have resource ids, or they
+    // don't match the .h file, or something of that nature.
+    bool altered = RepairResourceIds();
 
 
+    // Do any necessary changes to the resources
+    m_resourceTable.BeginFind();
+    wxNode *node;
+    while ((node = m_resourceTable.Next()))
+    {
+        wxItemResource *res = (wxItemResource *)node->Data();
+        ChangeOldToNewResource(NULL, res);
+    }
+
+    // Change the filename before saving
+
+    m_currentFilename = newPath;
+    m_symbolFilename = m_currentFilename;
+    wxStripExtension(m_symbolFilename);
+    m_symbolFilename += wxT(".h");
+
+    Modify(TRUE);
+
+    Save();
+
+    Clear(TRUE, TRUE);
+
+    return TRUE;
+
+}
+
+bool wxResourceManager::ChangeOldToNewResource(wxItemResource* parent, wxItemResource* res)
+{
+    // Change these according to your needs
+
+    // Change all fonts to use system defaults for fonts, colours etc.
+    static bool s_useSystemDefaultsAlways = FALSE; // TRUE;
+
+    // Increase dialog height by this amount (wxWin 2 uses dialog client size now)
+    static int s_increaseDialogSize = -18;
+
+    // How many points to decrease the font sizes by, since
+    // wxWin 2 fonts are larger in Windows
+    static int s_decreaseFontSize = 3;
+
+    wxString itemType(res->GetType());
+
+    wxFont font = res->GetFont();
+
+    if ((s_decreaseFontSize) > 0 && font.Ok())
+    {
+        wxFont newFont = wxFont(font.GetPointSize() - s_decreaseFontSize,
+                        font.GetFamily(), font.GetStyle(), font.GetWeight(),
+                        font.GetUnderlined(), font.GetFaceName());
+        res->SetFont(newFont);
+    }
+  
+    if (itemType == wxT("wxDialogBox") || itemType == wxT("wxDialog") || itemType == wxT("wxPanel"))
+    {
+        if (itemType == wxT("wxDialogBox"))
+            res->SetType(wxT("wxDialog"));
+
+        if (itemType == wxT("wxDialogBox") || itemType == wxT("wxDialog"))
+        {
+            // Only change the height if it has a caption, i.e. it's going to be
+            // used as a proper dialog and not a panel
+            if (res->GetStyle() & wxCAPTION)
+                res->SetSize(res->GetX(), res->GetY(), res->GetWidth(), res->GetHeight() + s_increaseDialogSize );
+        }
+
+        if (s_useSystemDefaultsAlways)
+            res->SetResourceStyle(res->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS);
+
+        if (res->GetValue1())
+            res->SetStyle(res->GetStyle() | wxDIALOG_MODAL);
+
+        wxNode *node = res->GetChildren().First();
+        while (node)
+        {
+            wxItemResource *child = (wxItemResource *)node->Data();
+        
+            ChangeOldToNewResource(res, child);
+            node = node->Next();
+        }
+    }
+    else if (itemType == wxT("wxMessage"))
+    {
+        // Figure out if this is a bitmap or text message
+        if (res->GetValue4().IsEmpty())
+            res->SetType(wxT("wxStaticText"));
+        else
+            res->SetType(wxT("wxStaticBitmap"));
+    }
+    else if (itemType == wxT("wxButton"))
+    {
+        // Figure out if this is a bitmap or text message
+        if (res->GetValue4().IsEmpty())
+        {
+        }
+        else
+            res->SetType(wxT("wxBitmapButton"));
+    }
+    else if (itemType == wxT("wxGroupBox"))
+    {
+        res->SetType(wxT("wxStaticBox"));
+    }
+    else if (itemType == wxT("wxText"))
+    {
+        res->SetType(wxT("wxTextCtrl"));
+    }
+    else if (itemType == wxT("wxMultiText"))
+    {
+        res->SetType(wxT("wxTextCtrl"));
+        res->SetStyle(res->GetStyle() | wxTE_MULTILINE);
+    }
+
+    itemType = res->GetType();
+
+    if (!res->GetTitle().IsEmpty() &&
+        (itemType == wxT("wxTextCtrl") || itemType == wxT("wxChoice") ||
+         itemType == wxT("wxComboBox") || itemType == wxT("wxGauge") ||
+         itemType == wxT("wxListBox")))
+    {
+        // Insert a label control resource, adjusting the size of this
+        // resource accordingly.
+        InsertLabelResource(parent, res);
+    }
+
+    return TRUE;
+}
+
+// Insert a label control resource, adjusting the size of this
+// resource accordingly.
+bool wxResourceManager::InsertLabelResource(wxItemResource* parent, wxItemResource* res)
+{
+    gs_LabelInsertionCount ++;
+
+    bool isHorizontal = TRUE;
+
+    // Determine panel orientation
+    if (parent->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL)
+    {
+        isHorizontal = FALSE;
+    }
+    else if (parent->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL)
+    {
+        isHorizontal = TRUE;
+    }
+
+    // Now override
+    if (res->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL)
+    {
+        isHorizontal = FALSE;
+    }
+    else if (res->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL)
+    {
+        isHorizontal = TRUE;
+    }
+
+    int x = res->GetX();
+    int y = res->GetY();
+    int width = res->GetWidth();
+    int height = res->GetHeight();
+
+    // Find the font specified
+    wxFont font;
+    if (res->GetFont().Ok())
+        font = res->GetFont();
+    else
+        font = parent->GetFont();
+
+    if (!font.Ok() || (parent->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS))
+        font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+
+    int labelX, labelY;
+    wxCoord labelWidth, labelHeight;
+    wxScreenDC dc;
+    dc.SetFont(font);
+    dc.GetTextExtent(res->GetTitle(), & labelWidth, & labelHeight);
+
+    // Vert/horizontal margin between controls
+    int margin = 3;
+
+    labelX = x;
+    labelY = y;
+    //labelWidth += 1;
+    //labelHeight += 1;
+
+    if (isHorizontal)
+    {
+        x += labelWidth + margin;
+        width -= (labelWidth + margin);
+    }
+    else
+    {
+        y += labelHeight + margin;
+        height -= (labelHeight + margin);
+
+        // Fudge factors
+        if (res->GetType() == wxT("wxTextCtrl"))
+        {
+            height += 3;
+        }
+        else if (res->GetType() == wxT("wxChoice") || res->GetType() == wxT("wxComboBox"))
+        {
+            height -= 4;
+        }
+    }
+
+    res->SetSize(x, y, width, height);
+
+    wxItemResource* staticItem = new wxItemResource;
+    staticItem->SetSize(labelX, labelY, labelWidth, labelHeight);
+    staticItem->SetTitle(res->GetTitle());
+    staticItem->SetFont(font);
+    staticItem->SetStyle(0);
+    staticItem->SetType(wxT("wxStaticText"));
+
+    wxString newSymbolName;
+    int newId = GenerateWindowId(wxT("ID_STATICTEXT"), newSymbolName) ;
+    staticItem->SetId(newId);
+
+    newSymbolName = res->GetName() + wxT("_Label");
+    staticItem->SetName(newSymbolName);
+    m_symbolTable.AddSymbol(newSymbolName, newId);
+
+    wxNode* node = parent->GetChildren().Member(res);
+
+    wxASSERT( (node != NULL) );
+
+    parent->GetChildren().Insert(node, staticItem);
+
+    // Remove the title from this resource since we've replaced it
+    // with a static text control
+    res->SetTitle(wxEmptyString);
+
+    return TRUE;
+}