X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ae8351fc61c11718b80630465967408d13fc226a..2224580a415da12d7c453943c4ae4a1b58ecd369:/utils/dialoged/src/reseditr.cpp diff --git a/utils/dialoged/src/reseditr.cpp b/utils/dialoged/src/reseditr.cpp index 4193ebde82..14166498d4 100644 --- a/utils/dialoged/src/reseditr.cpp +++ b/utils/dialoged/src/reseditr.cpp @@ -32,52 +32,50 @@ #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" +#include "wx/config.h" #include #include #include #include -#if defined(__WINDOWS__) && !defined(__GNUWIN32__) -#include -#else -#include -#endif - -#ifdef __WINDOWS__ -#include -#endif - +#ifdef __WXMSW__ #include "wx/help.h" +#endif #include "reseditr.h" #include "winprop.h" -#include "editrpal.h" #include "dlghndlr.h" #include "edtree.h" #include "edlist.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" -#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__) +#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/dialog.xpm" +#include "bitmaps/folder1.xpm" +#include "bitmaps/folder2.xpm" +#include "bitmaps/buttonsm.xpm" #endif /* @@ -93,15 +91,16 @@ wxResourceManager::wxResourceManager(): m_popupMenu = NULL; m_editorResourceTree = NULL; m_editorControlList = NULL; - m_editorPalette = NULL; m_nameCounter = 1; + m_symbolIdCounter = 99; m_modified = FALSE; m_currentFilename = ""; + m_symbolFilename = ""; m_editorToolBar = NULL; // Default window positions - m_resourceEditorWindowSize.width = 470; - m_resourceEditorWindowSize.height = 300; + m_resourceEditorWindowSize.width = 500; + m_resourceEditorWindowSize.height = 450; m_resourceEditorWindowSize.x = 0; m_resourceEditorWindowSize.y = 0; @@ -109,7 +108,9 @@ wxResourceManager::wxResourceManager(): m_propertyWindowSize.width = 300; m_propertyWindowSize.height = 300; +#ifdef __WXMSW__ m_helpController = NULL; +#endif m_bitmapImage = NULL; m_rootDialogItem = 0; @@ -120,12 +121,15 @@ wxResourceManager::~wxResourceManager() 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; } @@ -133,57 +137,77 @@ wxResourceManager::~wxResourceManager() bool wxResourceManager::Initialize() { // Set up the resource filename for each platform. -#ifdef __WINDOWS__ + // TODO: This shold be replaced by wxConfig usage. +#ifdef __WXMSW__ // dialoged.ini in the Windows directory - char buf[256]; - GetWindowsDirectory(buf, 256); - strcat(buf, "\\dialoged.ini"); - m_optionsResourceFilename = buf; -#elif defined(__X__) - char buf[500]; - ()wxGetHomeDir(buf); - strcat(buf, "/.dialogedrc"); - m_optionsResourceFilename = buf; + wxString windowsDir = wxGetOSDirectory(); + windowsDir += "\\dialoged.ini" ; + + m_optionsResourceFilename = windowsDir; +#elif defined(__WXGTK__) || defined(__WXMOTIF__) + wxGetHomeDir( &m_optionsResourceFilename ); + m_optionsResourceFilename += "/.dialogedrc"; #else #error "Unsupported platform." #endif LoadOptions(); +#ifdef __WXMSW__ m_helpController = new wxHelpController; m_helpController->Initialize("dialoged"); +#endif - m_popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc); + m_popupMenu = new wxMenu; m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties"); m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object"); if (!m_bitmapImage) { -#ifdef __WINDOWS__ +#ifdef __WXMSW__ m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE); #endif -#ifdef __X__ - m_bitmapImage = new wxBitmap(wxwin_bits, wxwin_width, wxwin_height); +#if defined(__WXGTK__) || defined(__WXMOTIF__) + m_bitmapImage = new wxBitmap( wxwin_xpm ); #endif } // Initialize the image list icons -#ifdef __WINDOWS__ +#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); +#else + wxIcon icon1( dialog_xpm ); + wxIcon icon2( folder1_xpm ); + wxIcon icon3( folder2_xpm ); + wxIcon icon4( buttonsm_xpm ); +#endif m_imageList.Add(icon1); m_imageList.Add(icon2); m_imageList.Add(icon3); m_imageList.Add(icon4); -#endif + + m_symbolTable.AddStandardSymbols(); return TRUE; } bool wxResourceManager::LoadOptions() { + 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); + + /* 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()); @@ -192,11 +216,23 @@ bool wxResourceManager::LoadOptions() 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; } bool wxResourceManager::SaveOptions() { + 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); + /* 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()); @@ -206,13 +242,14 @@ bool wxResourceManager::SaveOptions() 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; } // 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) { @@ -228,7 +265,6 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const ch m_editorFrame->SetMenuBar(menuBar); m_editorToolBar = (EditorToolBar *)OnCreateToolBar(m_editorFrame); -// m_editorPalette = OnCreatePalette(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); @@ -245,17 +281,7 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const ch c->width.Unconstrained(); c->height.Absolute(28); m_editorToolBar->SetConstraints(c); -/* - // Constraints for palette - c = new wxLayoutConstraints; - c->left.SameAs (m_editorFrame, wxLeft, 0); - c->top.SameAs (m_editorToolBar, wxBottom, 0); - c->right.SameAs (m_editorFrame, wxRight, 0); - c->bottom.Unconstrained(); - c->width.Unconstrained(); - c->height.Absolute(34); - m_editorPalette->SetConstraints(c); -*/ + // Constraints for listbox c = new wxLayoutConstraints; c->left.SameAs (m_editorFrame, wxLeft, 0); @@ -282,7 +308,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(); +#if defined(__WXGTK__) || defined(__WXMOTIF__) + c->height.Absolute(120); +#else c->height.Absolute(60); +#endif + m_editorControlList->SetConstraints(c); m_editorFrame->SetAutoLayout(TRUE); @@ -294,11 +325,8 @@ bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *parent, const ch } else { - wxFrame *fr = m_editorFrame; - if (m_editorFrame->OnClose()) + if (m_editorFrame->Close()) { - fr->Show(FALSE); - delete fr; m_editorFrame = NULL; m_editorPanel = NULL; } @@ -338,6 +366,7 @@ bool wxResourceManager::Save(const wxString& filename) InstantiateAllResourcesFromWindows(); if (m_resourceTable.Save(filename)) { + m_symbolTable.WriteIncludeFile(m_symbolFilename); Modify(FALSE); return TRUE; } @@ -348,12 +377,21 @@ bool wxResourceManager::Save(const wxString& filename) bool wxResourceManager::SaveAs() { wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename), - "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT)); + "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow())); if (s.IsNull() || s == "") return FALSE; 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; } @@ -375,19 +413,21 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename) if (!Clear(TRUE, FALSE)) return FALSE; + m_symbolTable.AddStandardSymbols(); + if (loadFromFile) { wxString str = filename; if (str == wxString("")) { - wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, NULL)); + wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow())); if (!f.IsNull() && f != "") str = f; else return FALSE; } - if (!m_resourceTable.ParseResourceFile(WXSTRINGCAST str)) + if (!m_resourceTable.ParseResourceFile(str)) { wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION); return FALSE; @@ -397,6 +437,42 @@ bool wxResourceManager::New(bool loadFromFile, const wxString& filename) 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; } else { @@ -408,8 +484,10 @@ 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) { + wxPropertyInfo::CloseWindow(); + if (!force && Modified()) { int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL); @@ -425,6 +503,7 @@ bool wxResourceManager::Clear(bool deleteWindows, bool force) ClearCurrentDialog(); DisassociateWindows(); + m_symbolTable.Clear(); m_resourceTable.ClearTable(); UpdateResourceList(); @@ -435,7 +514,7 @@ bool wxResourceManager::DisassociateWindows() { m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); DisassociateResource(res); @@ -450,22 +529,48 @@ void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *wi m_resourceAssociations.Put((long)resource, win); wxNode *node = resource->GetChildren().First(); - while (node) + wxNode* node2 = win->GetChildren().First(); + while (node && node2) { wxItemResource *child = (wxItemResource *)node->Data(); + wxWindow* childWindow = (wxWindow*) node2->Data(); + + if (child->GetId() != childWindow->GetId()) + { + wxString msg; + msg.Printf("AssociateResource: error when associating child window %ld with resource %ld", child->GetId(), childWindow->GetId()); + wxMessageBox(msg, "Dialog Editor problem", wxOK); + } + else if (childWindow->GetName() != child->GetName()) + { + wxString msg; + msg.Printf("AssociateResource: error when associating child window with resource %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)"); + wxMessageBox(msg, "Dialog Editor problem", wxOK); + } + else + { + AssociateResource(child, childWindow); + } + + // New code to avoid the problem of duplicate ids and names. We simply + // traverse the child windows and child resources in parallel, + // checking for any mismatch. +#if 0 wxWindow *childWindow = (wxWindow *)m_resourceAssociations.Get((long)child); if (!childWindow) - childWindow = win->FindWindow(child->GetName()); + // childWindow = win->FindWindow(child->GetName()); + childWindow = win->FindWindow(child->GetId()); if (childWindow) AssociateResource(child, childWindow); else { - char buf[200]; - sprintf(buf, "AssociateResource: cannot find child window %s", child->GetName() ? child->GetName() : "(unnamed)"); - wxMessageBox(buf, "Dialog Editor problem", wxOK); + wxString msg; + msg.Printf("AssociateResource: cannot find child window %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)"); + wxMessageBox(msg, "Dialog Editor problem", wxOK); } - +#endif node = node->Next(); + node2 = node2->Next(); } } @@ -476,18 +581,15 @@ bool wxResourceManager::DisassociateResource(wxItemResource *resource) return FALSE; // Disassociate children of window - if (win->GetChildren()) + wxNode *node = win->GetChildren().First(); + while (node) { - wxNode *node = win->GetChildren()->First(); - 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; @@ -515,7 +617,7 @@ bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win) win->PopEventHandler(); // Now reset all child event handlers - wxNode *node = win->GetChildren()->First(); + wxNode *node = win->GetChildren().First(); while ( node ) { wxWindow *child = (wxWindow *)node->Data(); @@ -545,10 +647,18 @@ bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win) // variable. bool wxResourceManager::DeleteWindow(wxWindow* win) { + bool clearDisplay = FALSE; if (m_editorPanel->m_childWindow == win) + { m_editorPanel->m_childWindow = NULL; + clearDisplay = TRUE; + } win->Destroy(); + + if (clearDisplay) + m_editorPanel->Clear(); + return TRUE; } @@ -556,12 +666,12 @@ wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win) { m_resourceAssociations.BeginFind(); wxNode *node; - while (node = m_resourceAssociations.Next()) + while ((node = m_resourceAssociations.Next())) { wxWindow *w = (wxWindow *)node->Data(); if (w == win) { - return (wxItemResource *)node->key.integer; + return (wxItemResource *)node->GetKeyInteger(); } } return NULL; @@ -587,8 +697,10 @@ void wxResourceManager::MakeUniqueName(char *prefix, char *buf) 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), @@ -598,14 +710,13 @@ wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title) frame->CreateStatusBar(1); frame->SetAutoLayout(TRUE); -#ifdef __WINDOWS__ - wxIcon *icon = new wxIcon("DIALOGEDICON"); - frame->SetIcon(icon); +#ifdef __WXMSW__ + frame->SetIcon(wxIcon("DIALOGEDICON")); #endif return frame; } -wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *parent) +wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *WXUNUSED(parent)) { wxMenuBar *menuBar = new wxMenuBar; @@ -641,17 +752,21 @@ wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame * { wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize, // wxSUNKEN_BORDER|wxCLIP_CHILDREN); +#ifdef __WXMOTIF__ + wxBORDER); +#else wxSUNKEN_BORDER); +#endif panel->SetScrollbars(10, 10, 100, 100); return panel; } -wxToolBarBase *wxResourceManager::OnCreateToolBar(wxFrame *parent) +wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent) { // Load palette bitmaps -#ifdef __WINDOWS__ +#ifdef __WXMSW__ wxBitmap ToolbarLoadBitmap("LOADTOOL"); wxBitmap ToolbarSaveBitmap("SAVETOOL"); wxBitmap ToolbarNewBitmap("NEWTOOL"); @@ -666,88 +781,84 @@ 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); - 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__) + 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 ); #endif // Create the toolbar - EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER, - wxVERTICAL, 1); + EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER|wxTB_HORIZONTAL); toolbar->SetMargins(2, 2); -// toolbar->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH); -#ifdef __WINDOWS__ +#ifdef __WXMSW__ int width = 24; int dx = 2; int gap = 6; #else - int width = ToolbarLoadBitmap->GetWidth(); + int width = 24; // ToolbarLoadBitmap->GetWidth(); ??? int dx = 2; int gap = 6; #endif int currentX = gap; toolbar->AddSeparator(); - toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "New dialog"); + toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "New dialog"); currentX += width + dx; - toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Load"); + toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "Load"); currentX += width + dx; - toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Save"); + toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, wxNullBitmap, + FALSE, 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"); + toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, wxNullBitmap, + FALSE, 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"); + 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, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Bottom align"); + toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "Bottom align"); currentX += width + dx; - toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Vertical align"); + toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, wxNullBitmap, + FALSE, 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"); + 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, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Right align"); + toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "Right align"); currentX += width + dx; - toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Copy size"); + toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, wxNullBitmap, + FALSE, 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"); + toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "To front"); currentX += width + dx; - toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "To back"); + toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "To back"); currentX += width + dx + gap; toolbar->AddSeparator(); - toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, (wxBitmap *)NULL, - FALSE, (float)currentX, -1, NULL, "Help"); + toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, wxNullBitmap, + FALSE, currentX, -1, NULL, "Help"); currentX += width + dx; - toolbar->CreateTools(); + toolbar->Realize(); return toolbar; - -// parent->OnSize(-1, -1); } void wxResourceManager::UpdateResourceList() @@ -758,15 +869,11 @@ void wxResourceManager::UpdateResourceList() m_editorResourceTree->SetInvalid(TRUE); m_editorResourceTree->DeleteAllItems(); - long id = m_editorResourceTree->InsertItem(0, "Dialogs" -#ifdef __WINDOWS__ - , 1, 2 -#endif - ); + long id = m_editorResourceTree->AddRoot("Dialogs", 1, 2); m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); wxString resType(res->GetType()); @@ -775,7 +882,7 @@ void wxResourceManager::UpdateResourceList() AddItemsRecursively(id, res); } } - m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); + m_editorResourceTree->Expand(id); m_editorResourceTree->SetInvalid(FALSE); } @@ -791,13 +898,9 @@ void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resourc else imageId = 3; - long id = m_editorResourceTree->InsertItem(parent, theString -#ifdef __WINDOWS__ - , imageId -#endif - ); + long id = m_editorResourceTree->AppendItem(parent, theString, imageId ); - m_editorResourceTree->SetItemData(id, (long) resource); + m_editorResourceTree->SetItemData(id, new wxResourceTreeData(resource)); if (strcmp(resource->GetType(), "wxBitmap") != 0) { @@ -809,15 +912,16 @@ void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resourc node = node->Next(); } } - m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); +// m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); } bool wxResourceManager::EditSelectedResource() { int sel = m_editorResourceTree->GetSelection(); - if (sel > -1) + if (sel != 0) { - wxItemResource *res = (wxItemResource *)m_editorResourceTree->GetItemData(sel); + wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); + wxItemResource *res = data->GetResource(); return Edit(res); } return FALSE; @@ -825,6 +929,8 @@ bool wxResourceManager::EditSelectedResource() bool wxResourceManager::Edit(wxItemResource *res) { + wxPropertyInfo::CloseWindow(); + ClearCurrentDialog(); wxString resType(res->GetType()); @@ -837,8 +943,8 @@ bool wxResourceManager::Edit(wxItemResource *res) } else { - long style = res->GetStyle(); - res->SetStyle(style|wxRAISED_BORDER); +// long style = res->GetStyle(); +// res->SetStyle(style|wxRAISED_BORDER); panel = new wxPanel; wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(), this); @@ -847,7 +953,7 @@ bool wxResourceManager::Edit(wxItemResource *res) panel->PushEventHandler(handler); - res->SetStyle(style); +// res->SetStyle(style); handler->AddChildHandlers(); // Add event handlers for all controls AssociateResource(res, panel); @@ -864,25 +970,42 @@ bool wxResourceManager::Edit(wxItemResource *res) bool wxResourceManager::CreateNewPanel() { + wxPropertyInfo::CloseWindow(); + 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); + 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()), - wxSize(400, 300), wxRAISED_BORDER, buf); + size, wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf); m_editorPanel->m_childWindow = panel; - resource->SetStyle(0); // panel->GetWindowStyleFlag()); - resource->SetSize(10, 10, 400, 300); + 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. @@ -916,88 +1039,125 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel * wxItemResource *res = new wxItemResource; wxControl *newItem = NULL; - res->SetSize(x, y, -1, -1); + + if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) + { + wxPoint pt = panel->ConvertPixelsToDialog(wxPoint(x, y)); + res->SetSize(pt.x, pt.y, -1, -1); + } + else res->SetSize(x, y, -1, -1); + res->SetType(iType); + + wxString prefix; wxString itemType(iType); if (itemType == "wxButton") { + prefix = "ID_BUTTON"; MakeUniqueName("button", buf); res->SetName(buf); if (isBitmap) - newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); + 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); } if (itemType == "wxBitmapButton") { + prefix = "ID_BITMAPBUTTON"; MakeUniqueName("button", buf); res->SetName(buf); - newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); + newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); } else if (itemType == "wxMessage" || itemType == "wxStaticText") { - MakeUniqueName("message", 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); + 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") { - MakeUniqueName("message", 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); + newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf); } else if (itemType == "wxCheckBox") { + 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 == "wxListBox") { + 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 == "wxRadioBox") { + 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(new wxStringList("One", "Two", NULL)); + res->SetStringValues(wxStringList("One", "Two", NULL)); + } + else if (itemType == "wxRadioButton") + { + 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 == "wxChoice") { + 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 == "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") { - MakeUniqueName("group", buf); + prefix = "ID_STATICBOX"; + 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") { + 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 == "wxSlider") { + 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 == "wxText" || itemType == "wxTextCtrl (single-line)") { + prefix = "ID_TEXTCTRL"; MakeUniqueName("textctrl", buf); res->SetName(buf); res->SetType("wxTextCtrl"); @@ -1005,6 +1165,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel * } else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)") { + prefix = "ID_TEXTCTRL"; MakeUniqueName("textctrl", buf); res->SetName(buf); res->SetType("wxTextCtrl"); @@ -1012,6 +1173,7 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel * } 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); @@ -1019,6 +1181,23 @@ bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel * 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()); @@ -1042,19 +1221,43 @@ void wxResourceManager::ClearCurrentDialog() } } +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; + bool success = FALSE; + if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable)) + { + dialog->Centre(); + dialog->ShowModal(); + success = TRUE; + } + return success; + } + return FALSE; +} + // 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()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); wxWindow *win = FindWindowForResource(res); if (win) { - wxNode *node1 = win->GetChildren()->First(); + wxNode *node1 = win->GetChildren().First(); while (node1) { wxControl *item = (wxControl *)node1->Data(); @@ -1090,7 +1293,7 @@ void wxResourceManager::AlignItems(int flag) int centreX = (int)(firstX + (firstW / 2)); int centreY = (int)(firstY + (firstH / 2)); - while (node = node->Next()) + while ((node = node->Next())) { wxControl *item = (wxControl *)node->Data(); if (item->GetParent() == win) @@ -1144,7 +1347,22 @@ void wxResourceManager::AlignItems(int flag) 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); } } win->Refresh(); @@ -1169,14 +1387,31 @@ void wxResourceManager::CopySize() 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()) + while ((node = node->Next())) { wxControl *item = (wxControl *)node->Data(); if (item->GetParent() == win) + { item->SetSize(-1, -1, firstW, firstH); + + int fw = firstW; + int fh = firstH; + + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); + + // 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 sz = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH)); + fw = sz.x; fh = sz.y; + } + resource->SetSize(resource->GetX(), resource->GetY(), fw, fh); + + } } win->Refresh(); } @@ -1195,18 +1430,18 @@ void wxResourceManager::ToBackOrFront(bool toBack) wxItemResource *itemResource = FindResourceForWindow(item); if (item->GetParent() == win) { - win->GetChildren()->DeleteObject(item); + win->GetChildren().DeleteObject(item); if (winResource) winResource->GetChildren().DeleteObject(itemResource); if (toBack) { - win->GetChildren()->Insert(item); + win->GetChildren().Insert(item); if (winResource) winResource->GetChildren().Insert(itemResource); } else { - win->GetChildren()->Append(item); + win->GetChildren().Append(item); if (winResource) winResource->GetChildren().Append(itemResource); } @@ -1227,13 +1462,32 @@ void wxResourceManager::RemoveSelection(wxWindow *win) m_selections.DeleteObject(win); } +void wxResourceManager::DeselectItemIfNecessary(wxWindow *win) +{ + if (win->IsKindOf(CLASSINFO(wxControl)) && (win->GetEventHandler() != win)) + { + // Deselect and refresh window in case we leave selection + // handles behind + wxControl *item = (wxControl *)win; + wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); + if (childHandler->IsSelected()) + { + wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item); + childHandler->SelectItem(FALSE); +#ifndef __WXGTK__ + item->GetParent()->Refresh(); +#endif + } + } +} + // Need to search through resource table removing this from // any resource which has this as a parent. bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res) { m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *thisRes = (wxItemResource *)node->Data(); if (thisRes->GetChildren().Member(res)) @@ -1264,11 +1518,19 @@ bool wxResourceManager::DeleteResource(wxItemResource *res) // 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; @@ -1278,19 +1540,7 @@ bool wxResourceManager::DeleteResource(wxItemResource *res) bool wxResourceManager::DeleteResource(wxWindow *win) { - if (win->IsKindOf(CLASSINFO(wxControl))) - { - // Deselect and refresh window in case we leave selection - // handles behind - wxControl *item = (wxControl *)win; - wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); - if (childHandler->IsSelected()) - { - RemoveSelection(item); - childHandler->SelectItem(FALSE); - item->GetParent()->Refresh(); - } - } + DeselectItemIfNecessary(win); wxItemResource *res = FindResourceForWindow(win); @@ -1303,7 +1553,7 @@ bool wxResourceManager::DeleteResource(wxWindow *win) // Will eventually have bitmap type information, for different // kinds of bitmap. -char *wxResourceManager::AddBitmapResource(char *filename) +wxString wxResourceManager::AddBitmapResource(const wxString& filename) { wxItemResource *resource = FindBitmapResourceByFilename(filename); if (!resource) @@ -1332,11 +1582,11 @@ char *wxResourceManager::AddBitmapResource(char *filename) if (resource) return resource->GetName(); else - return NULL; + return wxEmptyString; } // Delete the bitmap resource if it isn't being used by another resource. -void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName) +void wxResourceManager::PossiblyDeleteBitmapResource(const wxString& resourceName) { if (!IsBitmapResourceUsed(resourceName)) { @@ -1346,11 +1596,11 @@ void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName) } } -bool wxResourceManager::IsBitmapResourceUsed(char *resourceName) +bool wxResourceManager::IsBitmapResourceUsed(const wxString& resourceName) { m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); wxString resType(res->GetType()); @@ -1374,13 +1624,13 @@ bool wxResourceManager::IsBitmapResourceUsed(char *resourceName) } // Given a wxButton or wxMessage, find the corresponding bitmap filename. -char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) +wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) { - if (!resource || !resource->GetValue4()) - return NULL; + if (!resource || (resource->GetValue4() == "")) + return wxEmptyString; wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4()); if (!bitmapResource) - return NULL; + return wxEmptyString; wxNode *node = bitmapResource->GetChildren().First(); while (node) @@ -1391,16 +1641,16 @@ char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) wxItemResource *child = (wxItemResource *)node->Data(); return child->GetName(); - node = node->Next(); + //node = node->Next(); } - return NULL; + return wxEmptyString; } -wxItemResource *wxResourceManager::FindBitmapResourceByFilename(char *filename) +wxItemResource *wxResourceManager::FindBitmapResourceByFilename(const wxString& filename) { m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); wxString resType(res->GetType()); @@ -1419,10 +1669,149 @@ wxItemResource *wxResourceManager::FindBitmapResourceByFilename(char *filename) 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") + { + 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(); + } + } + } + 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") + { + 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(); + } + } + } +} + +// 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. -wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info) +wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info, bool instantiateFirst) { wxItemResource *resource = FindResourceForWindow(win); @@ -1435,10 +1824,15 @@ wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowP info = newInfo; } - info->InstantiateResource(resource); + // May not always want to copy values back from the resource + if (instantiateFirst) + info->InstantiateResource(resource); wxWindow *newWin = NULL; wxWindow *parent = win->GetParent(); + wxItemResource* parentResource = NULL; + if (parent) + parentResource = FindResourceForWindow(parent); if (win->IsKindOf(CLASSINFO(wxPanel))) { @@ -1448,8 +1842,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 = m_resourceTable.CreateItem((wxPanel *)parent, resource, parentResource); + newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin)); AssociateResource(resource, newWin); UpdateResourceList(); } @@ -1467,9 +1865,10 @@ wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowP bool wxResourceManager::DeleteSelection() { int sel = m_editorResourceTree->GetSelection(); - if (sel > -1) + if (sel != 0) { - wxItemResource *res = (wxItemResource *)m_editorResourceTree->GetItemData(sel); + wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); + wxItemResource *res = data->GetResource(); wxWindow *win = FindWindowForResource(res); if (win) { @@ -1504,7 +1903,7 @@ bool wxResourceManager::RecreateSelection() return TRUE; } -bool wxResourceManager::EditDialog(wxDialog *dialog, wxWindow *parent) +bool wxResourceManager::EditDialog(wxDialog *WXUNUSED(dialog), wxWindow *WXUNUSED(parent)) { return FALSE; } @@ -1515,7 +1914,7 @@ bool wxResourceManager::InstantiateAllResourcesFromWindows() { m_resourceTable.BeginFind(); wxNode *node; - while (node = m_resourceTable.Next()) + while ((node = m_resourceTable.Next())) { wxItemResource *res = (wxItemResource *)node->Data(); wxString resType(res->GetType()); @@ -1554,7 +1953,7 @@ bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, if (!childWindow) { char buf[200]; - sprintf(buf, "Could not find window %s", child->GetName()); + sprintf(buf, "Could not find window %s", (const char*) child->GetName()); wxMessageBox(buf, "Dialog Editor problem", wxOK); } else @@ -1598,26 +1997,34 @@ wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *w { info = new wxRadioBoxPropertyInfo(win); } - else if (win->IsKindOf(CLASSINFO(wxChoice))) + else if (win->IsKindOf(CLASSINFO(wxRadioButton))) { - info = new wxChoicePropertyInfo(win); + info = new wxRadioButtonPropertyInfo(win); } - else if (win->IsKindOf(CLASSINFO(wxButton))) + else if (win->IsKindOf(CLASSINFO(wxComboBox))) { - info = new wxButtonPropertyInfo(win); + 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(wxStaticText))) + else if (win->IsKindOf(CLASSINFO(wxButton))) { - info = new wxStaticTextPropertyInfo(win); + 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); @@ -1651,6 +2058,29 @@ void wxResourceManager::EditWindow(wxWindow *win) } } +// 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 @@ -1671,6 +2101,7 @@ BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame) EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection) EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection) EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest) + EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow) END_EVENT_TABLE() wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title, @@ -1684,81 +2115,87 @@ 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(); + manager->Clear(TRUE, FALSE) ; + this->Destroy(); } -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); + sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart \nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION); wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE); } -void wxResourceEditorFrame::OnTest(wxCommandEvent& event) +void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event)) { - // TODO should show the current dialog + manager->TestCurrentDialog(this); } -void wxResourceEditorFrame::OnContents(wxCommandEvent& event) +void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event)) { +#ifdef __WXMSW__ 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(); } -bool wxResourceEditorFrame::OnClose() +void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event) { + wxPropertyInfo::CloseWindow(); if (manager->Modified()) { - if (!manager->Clear(TRUE, FALSE)) - return FALSE; + if (!manager->Clear(TRUE, FALSE)) + { + event.Veto(); + return; + } } - if (!Iconized()) + if (!IsIconized()) { int w, h; GetSize(&w, &h); @@ -1773,9 +2210,8 @@ bool wxResourceEditorFrame::OnClose() } manager->SetEditorFrame(NULL); manager->SetEditorToolBar(NULL); - manager->SetEditorPalette(NULL); - return TRUE; + this->Destroy(); } /* @@ -1783,7 +2219,6 @@ bool wxResourceEditorFrame::OnClose() */ BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow) - EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll) EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint) END_EVENT_TABLE() @@ -1794,24 +2229,15 @@ wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, m_marginX = 10; m_marginY = 40; m_childWindow = NULL; + + SetBackgroundColour(* wxWHITE); } 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); @@ -1843,9 +2269,9 @@ void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc) } // Popup menu callback -void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) +void ObjectMenuProc(wxMenu *menu, wxCommandEvent& event) { - wxWindow *data = (wxWindow *)menu.GetClientData(); + wxWindow *data = (wxWindow *)menu->GetClientData(); if (!data) return; @@ -1858,6 +2284,8 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) } case OBJECT_MENU_DELETE: { + wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data); + wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data); wxResourceManager::GetCurrentResourceManager()->DeleteResource(data); wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data); @@ -1874,16 +2302,16 @@ void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) */ 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, - long style, int direction, int RowsOrColumns): - wxToolBar(frame, -1, pos, size, style, direction, RowsOrColumns) + 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(); @@ -1906,10 +2334,12 @@ bool EditorToolBar::OnLeftClick(int toolIndex, bool toggled) } case TOOLBAR_HELP: { +#ifdef __WXMSW__ wxBeginBusyCursor(); manager->GetHelpController()->LoadFile(); manager->GetHelpController()->DisplayContents(); wxEndBusyCursor(); +#endif break; } case TOOLBAR_FORMAT_HORIZ: @@ -2019,16 +2449,3 @@ void EditorToolBar::OnMouseEnter(int toolIndex) else frame->SetStatusText(""); } -void EditorToolBar::OnPaint(wxPaintEvent& event) -{ - wxToolBar::OnPaint(event); - - 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); -} - -