]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reseditr.cpp
DialogEd now compiles, links and runs under wxGTK
[wxWidgets.git] / utils / dialoged / src / reseditr.cpp
index 6e98372ef5edc7c5f49af58f94477f1bea640c1d..ebdfdc6a8aa73d70999b63f893f7658c80e07a7d 100644 (file)
@@ -32,6 +32,8 @@
 #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"
@@ -51,7 +53,9 @@
 #include <windows.h>
 #endif
 
+#ifndef __WXGTK__
 #include "wx/help.h"
+#endif
 
 #include "reseditr.h"
 #include "winprop.h"
 static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event);
 wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL;
 
-#ifdef __X__
-#include "bitmaps/load.xbm"
-#include "bitmaps/save.xbm"
-#include "bitmaps/new.xbm"
+#ifdef __WXGTK__
+#include "bitmaps/load.xpm"
+#include "bitmaps/save.xpm"
+#include "bitmaps/new.xpm"
 #include "bitmaps/vert.xbm"
 #include "bitmaps/alignt.xbm"
 #include "bitmaps/alignb.xbm"
@@ -109,7 +113,9 @@ wxResourceManager::wxResourceManager():
   m_propertyWindowSize.width = 300;
   m_propertyWindowSize.height = 300;
 
+#ifndef __WXGTK__
   m_helpController = NULL;
+#endif
 
   m_bitmapImage = NULL;
   m_rootDialogItem = 0;
@@ -120,12 +126,15 @@ wxResourceManager::~wxResourceManager()
   sm_currentResourceManager = NULL;
   SaveOptions();
 
+#ifndef __WXGTK__
   if (m_helpController)
   {
     m_helpController->Quit();
     delete m_helpController;
     m_helpController = NULL;
   }
+#endif  
+  
   delete m_bitmapImage;
   delete m_popupMenu;
 }
@@ -139,9 +148,9 @@ bool wxResourceManager::Initialize()
   GetWindowsDirectory(buf, 256);
   strcat(buf, "\\dialoged.ini");
   m_optionsResourceFilename = buf;
-#elif defined(__X__)
+#elif defined(__WXGTK__)
   char buf[500];
-  ()wxGetHomeDir(buf);
+  wxGetHomeDir(buf);
   strcat(buf, "/.dialogedrc");
   m_optionsResourceFilename = buf;
 #else
@@ -150,8 +159,10 @@ bool wxResourceManager::Initialize()
 
   LoadOptions();
 
+#ifndef __WXGTK__
   m_helpController = new wxHelpController;
   m_helpController->Initialize("dialoged");
+#endif
 
   m_popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc);
   m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties");
@@ -162,7 +173,7 @@ bool wxResourceManager::Initialize()
 #ifdef __WXMSW__
     m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE);
 #endif
-#ifdef __X__
+#ifdef __WXGTK__
     m_bitmapImage = new wxBitmap(wxwin_bits, wxwin_width, wxwin_height);
 #endif
   }
@@ -214,7 +225,7 @@ bool wxResourceManager::SaveOptions()
 
 // 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)
   {
@@ -273,7 +284,12 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const ch
     c->right.SameAs      (m_editorFrame, wxRight, 0);
     c->bottom.SameAs     (m_editorFrame, wxBottom, 0);
     c->width.Unconstrained();
+#ifdef __WXGTK__
+    c->height.Absolute(70);
+#else
     c->height.Absolute(60);
+#endif
+
     m_editorControlList->SetConstraints(c);
 
     m_editorFrame->SetAutoLayout(TRUE);
@@ -329,6 +345,7 @@ bool wxResourceManager::Save(const wxString& filename)
   InstantiateAllResourcesFromWindows();
   if (m_resourceTable.Save(filename))
   {
+    m_symbolTable.WriteIncludeFile(m_symbolFilename);
     Modify(FALSE);
     return TRUE;
   }
@@ -345,6 +362,15 @@ bool wxResourceManager::SaveAs()
     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";
+
   Save(m_currentFilename);
   return TRUE;
 }
@@ -401,7 +427,9 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
     {
         wxString str("Could not find include file ");
         str += m_symbolFilename;
-        wxMessageBox(str, "Dialog Editor Warning", MB_OK);
+        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;
     }
@@ -410,6 +438,20 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
         // 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;
   }
   else
   {
@@ -421,7 +463,7 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename)
   return TRUE;
 }
 
-bool wxResourceManager::Clear(bool deleteWindows, bool force)
+bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows), bool force)
 {
   if (!force && Modified())
   {
@@ -627,7 +669,7 @@ wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title)
   return frame;
 }
 
-wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *parent)
+wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *WXUNUSED(parent))
 {
   wxMenuBar *menuBar = new wxMenuBar;
 
@@ -670,7 +712,7 @@ wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *
   return panel;
 }
 
-wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent)
+wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent)
 {
   // Load palette bitmaps
 #ifdef __WXMSW__
@@ -688,10 +730,10 @@ wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent)
   wxBitmap ToolbarToFrontBitmap("TOFRONTTOOL");
   wxBitmap ToolbarHelpBitmap("HELPTOOL");
 #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);
+#ifdef __WXGTK__
+  wxBitmap ToolbarLoadBitmap( load_xpm );
+  wxBitmap ToolbarSaveBitmap( save_xpm);
+  wxBitmap ToolbarNewBitmap( new_xpm );
   wxBitmap ToolbarVertBitmap(vert_bits, vert_width, vert_height);
   wxBitmap ToolbarAlignTBitmap(alignt_bits, alignt_width, alignt_height);
   wxBitmap ToolbarAlignBBitmap(alignb_bits, alignb_width, alignb_height);
@@ -713,7 +755,7 @@ wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent)
   int dx = 2;
   int gap = 6;
 #else
-  int width = ToolbarLoadBitmap->GetWidth();
+  int width = 24; // ToolbarLoadBitmap->GetWidth();  ???
   int dx = 2;
   int gap = 6;
 #endif
@@ -885,11 +927,10 @@ bool wxResourceManager::CreateNewPanel()
   ClearCurrentDialog();
 
   char buf[256];
-  MakeUniqueName("panel", buf);
+  MakeUniqueName("dialog", buf);
   
   wxItemResource *resource = new wxItemResource;
-//  resource->SetType(wxTYPE_PANEL);
-  resource->SetType("wxPanel");
+  resource->SetType("wxDialog");
   resource->SetName(buf);
   resource->SetTitle(buf);
 
@@ -904,10 +945,10 @@ bool wxResourceManager::CreateNewPanel()
 
   wxPanel *panel = new wxPanel(m_editorPanel, -1,
      wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()),
-     wxSize(400, 300), wxRAISED_BORDER, buf);
+     wxSize(400, 300), wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf);
   m_editorPanel->m_childWindow = panel;
 
-  resource->SetStyle(0); // panel->GetWindowStyleFlag());
+  resource->SetStyle(panel->GetWindowStyleFlag());
   resource->SetSize(10, 10, 400, 300);
 
   // For editing in situ we will need to use the hash table to ensure
@@ -969,17 +1010,17 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
   else if (itemType == "wxMessage" || itemType == "wxStaticText")
     {
       prefix = "ID_STATIC";
-      MakeUniqueName("message", buf);
+      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, "Message", wxPoint(x, y), wxSize(-1, -1), 0, buf);
+        newItem = new wxStaticText(panel, -1, "Static", wxPoint(x, y), wxSize(-1, -1), 0, buf);
     }
   else if (itemType == "wxStaticBitmap")
     {
       prefix = "ID_STATICBITMAP";
-      MakeUniqueName("message", buf);
+      MakeUniqueName("static", buf);
       res->SetName(buf);
       newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf);
     }
@@ -992,7 +1033,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
     }
   else if (itemType == "wxListBox")
     {
-      prefix = "ID_LISTBIX";
+      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);
@@ -1023,12 +1064,19 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *
       res->SetName(buf);
       newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf);
     }
+  else if (itemType == "wxComboBox")
+    {
+      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 == "wxGroupBox" || itemType == "wxStaticBox")
     {
       prefix = "ID_STATICBOX";
-      MakeUniqueName("group", buf);
+      MakeUniqueName("staticbox", buf);
       res->SetName(buf);
-      newItem = new wxStaticBox(panel, -1, "Groupbox", wxPoint(x, y), wxSize(200, 200), 0, buf);
+      newItem = new wxStaticBox(panel, -1, "Static", wxPoint(x, y), wxSize(200, 200), 0, buf);
     }
   else if (itemType == "wxGauge")
     {
@@ -1114,14 +1162,14 @@ bool wxResourceManager::TestCurrentDialog(wxWindow* parent)
     wxDialog* dialog = new wxDialog;
     long oldStyle = item->GetStyle();
     bool success = FALSE;
-    item->SetStyle(wxDEFAULT_DIALOG_STYLE);
+//    item->SetStyle(wxDEFAULT_DIALOG_STYLE);
     if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable))
     {
         dialog->Centre();
         dialog->ShowModal();
         success = TRUE;
     }
-    item->SetStyle(oldStyle);
+//    item->SetStyle(oldStyle);
     return success;
   }
   return FALSE;
@@ -1521,12 +1569,13 @@ bool wxResourceManager::IsSymbolUsed(wxItemResource* thisResource, wxWindowID id
   while (node = m_resourceTable.Next())
   {
     wxItemResource *res = (wxItemResource *)node->Data();
-    if ((res != thisResource) && (res->GetId() == id))
-        return TRUE;
 
     wxString resType(res->GetType());
     if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
     {
+      if ((res != thisResource) && (res->GetId() == id))
+          return TRUE;
+
       wxNode *node1 = res->GetChildren().First();
       while (node1)
       {
@@ -1563,12 +1612,13 @@ void wxResourceManager::ChangeIds(int oldId, int newId)
   while (node = m_resourceTable.Next())
   {
     wxItemResource *res = (wxItemResource *)node->Data();
-    if (res->GetId() == oldId)
-        res->SetId(newId);
 
     wxString resType(res->GetType());
     if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel")
     {
+      if (res->GetId() == oldId)
+          res->SetId(newId);
+
       wxNode *node1 = res->GetChildren().First();
       while (node1)
       {
@@ -1582,6 +1632,71 @@ void wxResourceManager::ChangeIds(int oldId, int newId)
   }
 }
 
+// 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")
+    {
+
+      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();
+      }
+    }
+  }
+  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.
@@ -1611,8 +1726,12 @@ wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowP
   else
   {
     DisassociateResource(resource);
+    if (win->GetEventHandler() != win)
+        win->PopEventHandler(TRUE);
+
     DeleteWindow(win);
     newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource);
+    newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin));
     AssociateResource(resource, newWin);
     UpdateResourceList();
   }
@@ -1769,6 +1888,10 @@ wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *w
         {
           info = new wxChoicePropertyInfo(win);
         }
+  else if (win->IsKindOf(CLASSINFO(wxComboBox)))
+        {
+          info = new wxComboBoxPropertyInfo(win);
+        }
   else if (win->IsKindOf(CLASSINFO(wxButton)))
         {
           info = new wxButtonPropertyInfo(win);
@@ -1874,68 +1997,70 @@ wxResourceEditorFrame::~wxResourceEditorFrame()
 {
 }
 
-void wxResourceEditorFrame::OnNew(wxCommandEvent& event)
+void wxResourceEditorFrame::OnNew(wxCommandEvent& WXUNUSED(event))
 {
       manager->New(FALSE);
 }
 
-void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& event)
+void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& WXUNUSED(event))
 {
       manager->CreateNewPanel();
 }
 
-void wxResourceEditorFrame::OnOpen(wxCommandEvent& event)
+void wxResourceEditorFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
 {
       manager->New(TRUE);
 }
 
-void wxResourceEditorFrame::OnClear(wxCommandEvent& event)
+void wxResourceEditorFrame::OnClear(wxCommandEvent& WXUNUSED(event))
 {
       manager->Clear(TRUE, FALSE);
 }
 
-void wxResourceEditorFrame::OnSave(wxCommandEvent& event)
+void wxResourceEditorFrame::OnSave(wxCommandEvent& WXUNUSED(event))
 {
       manager->Save();
 }
 
-void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& event)
+void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event))
 {
       manager->SaveAs();
 }
 
-void wxResourceEditorFrame::OnExit(wxCommandEvent& event)
+void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event))
 {
          manager->Clear(TRUE, FALSE) ;
       this->Close();
 }
 
-void wxResourceEditorFrame::OnAbout(wxCommandEvent& event)
+void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
       char buf[300];
       sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION);
       wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE);
 }
 
-void wxResourceEditorFrame::OnTest(wxCommandEvent& event)
+void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event))
 {
     manager->TestCurrentDialog(this);
 }
 
-void wxResourceEditorFrame::OnContents(wxCommandEvent& event)
+void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event))
 {
+#ifndef __WXGTK__
       wxBeginBusyCursor();
       manager->GetHelpController()->LoadFile();
       manager->GetHelpController()->DisplayContents();
       wxEndBusyCursor();
+#endif
 }
 
-void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& event)
+void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(event))
 {
       manager->DeleteSelection();
 }
 
-void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& event)
+void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event))
 {
       manager->RecreateSelection();
 }
@@ -2000,7 +2125,7 @@ void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent& event)
         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);
 
@@ -2095,10 +2220,12 @@ bool EditorToolBar::OnLeftClick(int toolIndex, bool toggled)
     }
     case TOOLBAR_HELP:
     {
+#ifndef __WXGTK__
       wxBeginBusyCursor();
       manager->GetHelpController()->LoadFile();
       manager->GetHelpController()->DisplayContents();
       wxEndBusyCursor();
+#endif
       break;
     }
     case TOOLBAR_FORMAT_HORIZ:
@@ -2210,6 +2337,7 @@ void EditorToolBar::OnMouseEnter(int toolIndex)
 
 void EditorToolBar::OnPaint(wxPaintEvent& event)
 {
+#ifndef __WXGTK__
   wxToolBar::OnPaint(event);
 
   wxPaintDC dc(this);
@@ -2218,6 +2346,7 @@ void EditorToolBar::OnPaint(wxPaintEvent& event)
   dc.SetPen(wxBLACK_PEN);
   dc.SetBrush(wxTRANSPARENT_BRUSH);
   dc.DrawLine(0, h-1, w, h-1);
+#endif
 }