+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;
+}