]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/utils/convertrc/rc2xml.cpp
corrected typo in Darwin specific code
[wxWidgets.git] / contrib / utils / convertrc / rc2xml.cpp
index be22c23737bd50d33ac770a4bf60a20e70f6e689..ee909b0256b7b1a46a4efd82a9fc572c06b3a94d 100644 (file)
@@ -21,7 +21,7 @@ cross platform (wxGTK,etc)
 #endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
-#include <wx/wxprec.h>
+#include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 #pragma hdrstop
 
 #ifdef __BORLANDC__
 #pragma hdrstop
@@ -68,6 +68,16 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile)
     m_rc.Open(rcfile.c_str());
     m_filesize=m_rc.Length();
     
     m_rc.Open(rcfile.c_str());
     m_filesize=m_rc.Length();
     
+
+    m_workingpath=wxPathOnly(rcfile);
+
+    m_targetpath=wxPathOnly(xmlfile)+"\\";
+
+
+
+    wxSetWorkingDirectory(m_workingpath);
+
+
     bool result;
     result=m_xmlfile.Open(xmlfile.c_str(),"w+t");
     wxASSERT_MSG(result,"Couldn't create XML file");   
     bool result;
     result=m_xmlfile.Open(xmlfile.c_str(),"w+t");
     wxASSERT_MSG(result,"Couldn't create XML file");   
@@ -171,6 +181,12 @@ void rc2xml::ParseControls()
     token=GetToken();
     while ((token!="END")&(token!="}"))
         {
     token=GetToken();
     while ((token!="END")&(token!="}"))
         {
+        if (token=="AUTOCHECKBOX")
+            ParseCheckBox();
+        else
+        if (token=="AUTORADIOBUTTON")
+            ParseRadioButton();
+        else
         if (token=="LTEXT")
             ParseStaticText();
         else if (token=="EDITTEXT")
         if (token=="LTEXT")
             ParseStaticText();
         else if (token=="EDITTEXT")
@@ -220,11 +236,50 @@ void rc2xml::ParseTextCtrl()
     ReadRect(x,y,width,height);
 //TODO
 //style=GetToken();
     ReadRect(x,y,width,height);
 //TODO
 //style=GetToken();
-    m_xmlfile.Write("\t\t<object class\"wxTextCtrl\"");
+    m_xmlfile.Write("\t\t<object class=\"wxTextCtrl\"");
     WriteBasicInfo(x,y,width,height,varname);
     m_xmlfile.Write("\t\t</object>\n");
 
 }
     WriteBasicInfo(x,y,width,height,varname);
     m_xmlfile.Write("\t\t</object>\n");
 
 }
+//AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
+void rc2xml::ParseCheckBox()
+{
+    wxString token;
+    wxString phrase,varname;
+    phrase=GetQuoteField();
+    varname=GetToken();
+
+    int x,y,width,height;
+    ReadRect(x,y,width,height);
+
+    m_xmlfile.Write("\t\t<object class=\"wxCheckBox\"");
+    WriteBasicInfo(x,y,width,height,varname);
+    WriteLabel(phrase);
+    m_xmlfile.Write("\t\t</object>\n");
+
+}
+//AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
+void rc2xml::ParseRadioButton()
+{
+    wxString token,style;
+    wxString phrase,varname;
+    phrase=GetQuoteField();
+    varname=GetToken();
+
+    int x,y,width,height;
+    if (ReadRect(x,y,width,height))
+      ReadOrs(token);
+    if (token.Find("WS_GROUP") != -1)
+        style += "wxRB_GROUP";
+
+    m_xmlfile.Write("\t\t<object class=\"wxRadioButton\"");
+    WriteBasicInfo(x,y,width,height,varname);
+    WriteLabel(phrase);
+    WriteStyle(style);
+    m_xmlfile.Write("\t\t</object>\n");
+
+}
+
 //PUSHBUTTON      "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
 void rc2xml::ParsePushButton()
 {
 //PUSHBUTTON      "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
 void rc2xml::ParsePushButton()
 {
@@ -236,7 +291,7 @@ void rc2xml::ParsePushButton()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<object class\"wxButton\"");
+    m_xmlfile.Write("\t\t<object class=\"wxButton\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteLabel(phrase);
     m_xmlfile.Write("\t\t</object>\n");
     WriteBasicInfo(x,y,width,height,varname);
     WriteLabel(phrase);
     m_xmlfile.Write("\t\t</object>\n");
@@ -275,15 +330,18 @@ void rc2xml::ParseGroupBox()
     m_xmlfile.Write("\t\t</object>\n");
 }
 
     m_xmlfile.Write("\t\t</object>\n");
 }
 
-void rc2xml::ReadRect(int & x, int & y, int & width, int & height)
+bool rc2xml::ReadRect(int & x, int & y, int & width, int & height)
 {
     x=atoi(GetToken());
     y=atoi(GetToken());
     width=atoi(GetToken());
 {
     x=atoi(GetToken());
     y=atoi(GetToken());
     width=atoi(GetToken());
-    height=atoi(GetToken());
+    bool ret;
+    wxString tmp = GetToken(&ret);
+    height=atoi(tmp);
+    return ret; // check for more parameters
 }
 
 }
 
-wxString rc2xml::GetToken()
+wxString rc2xml::GetToken(bool *listseperator)
 {
     wxString token="";
 
 {
     wxString token="";
 
@@ -316,13 +374,15 @@ wxString rc2xml::GetToken()
 
     while (!Seperator(ch))
     {
 
     while (!Seperator(ch))
     {
-    token+=(char)ch;
+    token += (char)ch;
     ReadChar(ch);
     }
 
     ReadChar(ch);
     }
 
-    if (ch==EOF)
-        m_done=TRUE;
+    if (ch == EOF)
+        m_done = TRUE;
 
 
+    if (listseperator)
+      *listseperator = (ch == ',');
     return token;
 }
 
     return token;
 }
 
@@ -367,14 +427,21 @@ void rc2xml::ParseComboBox()
 {
 /* COMBOBOX        IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | 
                     WS_VSCROLL | WS_TABSTOP */
 {
 /* COMBOBOX        IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | 
                     WS_VSCROLL | WS_TABSTOP */
-    wxString token;
+    wxString token,style;
     wxString varname;
     varname=GetToken();
     int x,y,width,height;
     wxString varname;
     varname=GetToken();
     int x,y,width,height;
-    ReadRect(x,y,width,height);
+    if (ReadRect(x,y,width,height))
+      ReadOrs(token);
 
     m_xmlfile.Write("\t\t<object class=\"wxComboBox\"");
     WriteBasicInfo(x,y,width,height,varname);
 
     m_xmlfile.Write("\t\t<object class=\"wxComboBox\"");
     WriteBasicInfo(x,y,width,height,varname);
+    if (token.Find("CBS_SIMPLE") != -1)
+        WriteStyle("wxCB_SIMPLE");
+    if (token.Find("CBS_SORT") != -1)
+        WriteStyle("wxCB_SORT");
+    if (token.Find("CBS_DISABLENOSCROLL") != -1)
+        WriteStyle("wxLB_ALWAYS_SB");
     m_xmlfile.Write("\n\t\t</object>\n");
 
 }
     m_xmlfile.Write("\n\t\t</object>\n");
 
 }
@@ -610,6 +677,12 @@ name=LookUpId(name);
         name="wxID_COPY";
     else if (name=="ID_EDIT_PASTE")
         name="wxID_PASTE";
         name="wxID_COPY";
     else if (name=="ID_EDIT_PASTE")
         name="wxID_PASTE";
+    else if (name=="IDYES")
+        name="wxID_YES";
+    else if (name=="IDNO")
+        name="wxID_NO";
+    else if (name=="IDHELP")
+        name="wxID_HELP";
 
     m_xmlfile.Write(" name= \""+name+"\"");
 }
 
     m_xmlfile.Write(" name= \""+name+"\"");
 }
@@ -634,7 +707,7 @@ void rc2xml::WriteStyle(wxString style)
 {
     if (style.Length()==0)
         return;
 {
     if (style.Length()==0)
         return;
-    m_xmlfile.Write("\n\t\t<style>"+style+"</style>\n");
+    m_xmlfile.Write("\t\t\t<style>"+style+"</style>\n");
 }
 /*
     LISTBOX         IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | 
 }
 /*
     LISTBOX         IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | 
@@ -825,7 +898,7 @@ void rc2xml::WriteToolButton(wxString name,int index, int width, int height, wxB
     wxRect r(x,0,width,height);
     wxBitmap little;
     little=bitmap.GetSubBitmap(r);
     wxRect r(x,0,width,height);
     wxBitmap little;
     little=bitmap.GetSubBitmap(r);
-    little.SaveFile(name,wxBITMAP_TYPE_BMP);
+    little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP);
 }
 
 void rc2xml::ParseStringTable(wxString varname)
 }
 
 void rc2xml::ParseStringTable(wxString varname)
@@ -961,6 +1034,10 @@ wxString rc2xml::CleanName(wxString name)
     name.Replace("idr_","");
     name.Replace("idb_","");
     name.Replace("idc_","");
     name.Replace("idr_","");
     name.Replace("idb_","");
     name.Replace("idc_","");
+
+    name.Replace(".ico","");
+
+    name.Replace(".bmp","");
     return name;
 }
 // And the award for most messed up control goes to...
     return name;
 }
 // And the award for most messed up control goes to...
@@ -1114,6 +1191,8 @@ void rc2xml::WriteBitmap(wxString bitmapname)
     
     wxString *bitmappath;
     bitmappath=(wxString *)node->Data();
     
     wxString *bitmappath;
     bitmappath=(wxString *)node->Data();
+
+    bitmapname=wxFileNameFromPath(*bitmappath);
     wxBitmap bitmap;
     if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
         wxLogError("Unable to load bitmap:"+*bitmappath);
     wxBitmap bitmap;
     if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
         wxLogError("Unable to load bitmap:"+*bitmappath);
@@ -1122,7 +1201,7 @@ void rc2xml::WriteBitmap(wxString bitmapname)
     bitmapname=CleanName(bitmapname);
     bitmapname+=".bmp";
     m_xmlfile.Write("\t\t\t<bitmap>"+bitmapname+"</bitmap>\n");
     bitmapname=CleanName(bitmapname);
     bitmapname+=".bmp";
     m_xmlfile.Write("\t\t\t<bitmap>"+bitmapname+"</bitmap>\n");
-    bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP);
+    bitmap.SaveFile(m_targetpath+bitmapname,wxBITMAP_TYPE_BMP);
 }
 
 void rc2xml::WriteIcon(wxString iconname)
 }
 
 void rc2xml::WriteIcon(wxString iconname)
@@ -1144,12 +1223,12 @@ wxNode *node=m_iconlist->Find(iconname);
 #else
     bitmap = icon;
 #endif
 #else
     bitmap = icon;
 #endif
-
+    iconname=wxFileNameFromPath(*iconpath);
     //Make a bitmap file name
     iconname=CleanName(iconname);
     iconname+=".bmp";
     m_xmlfile.Write("\t\t\t<bitmap>"+iconname+"</bitmap>\n");
     //Make a bitmap file name
     iconname=CleanName(iconname);
     iconname+=".bmp";
     m_xmlfile.Write("\t\t\t<bitmap>"+iconname+"</bitmap>\n");
-    bitmap.SaveFile(iconname,wxBITMAP_TYPE_BMP);
+    bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP);
 
     
 }
 
     
 }