]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/utils/convertrc/rc2xml.cpp
give focus to show top level windows
[wxWidgets.git] / contrib / utils / convertrc / rc2xml.cpp
index 795f45a9eb92c4aaa536b7fbe78342fd9aed1fac..15f7ac44eeecb842bea8011267755317fa8f84e3 100644 (file)
@@ -68,6 +68,11 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile)
     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");   
@@ -123,7 +128,7 @@ microsoft reuses the keyword DIALOG for other things
     wxString title;
     wxString ptsize,face;
     
-    m_xmlfile.Write("\t<dialog");
+    m_xmlfile.Write("\t<object class=\"wxDialog\"");
     //Avoid duplicate names this way
     dlgname.Replace("IDD_","DLG_");
     WriteBasicInfo(x,y,width,height,dlgname);
@@ -152,10 +157,8 @@ microsoft reuses the keyword DIALOG for other things
     token=GetToken();
     }
 
-    m_xmlfile.Write("\t<children>\n");
     ParseControls();
-    m_xmlfile.Write("\t</children>\n");
-    m_xmlfile.Write("\t</dialog>\n");
+    m_xmlfile.Write("\t</object>\n");
 }
 
 /*
@@ -173,6 +176,12 @@ void rc2xml::ParseControls()
     token=GetToken();
     while ((token!="END")&(token!="}"))
         {
+        if (token=="AUTOCHECKBOX")
+            ParseCheckBox();
+        else
+        if (token=="AUTORADIOBUTTON")
+            ParseRadioButton();
+        else
         if (token=="LTEXT")
             ParseStaticText();
         else if (token=="EDITTEXT")
@@ -207,9 +216,9 @@ void rc2xml::ParseStaticText()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<statictext");
+    m_xmlfile.Write("\t\t<object class=\"wxStaticText\"");
     WriteBasicInfo(x,y,width,height,varname);WriteLabel(phrase);
-    m_xmlfile.Write("\t\t</statictext>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 //EDITTEXT        IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
@@ -222,11 +231,50 @@ void rc2xml::ParseTextCtrl()
     ReadRect(x,y,width,height);
 //TODO
 //style=GetToken();
-    m_xmlfile.Write("\t\t<textctrl");
+    m_xmlfile.Write("\t\t<object class=\"wxTextCtrl\"");
+    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);
-    m_xmlfile.Write("\t\t</textctrl>\n");
+    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()
 {
@@ -238,10 +286,10 @@ void rc2xml::ParsePushButton()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<button");
+    m_xmlfile.Write("\t\t<object class=\"wxButton\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteLabel(phrase);
-    m_xmlfile.Write("\t\t</button>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 
@@ -271,21 +319,24 @@ void rc2xml::ParseGroupBox()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<staticbox");
+    m_xmlfile.Write("\t\t<object class=\"wxStaticBox\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteLabel(phrase);
-    m_xmlfile.Write("\t\t</staticbox>\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());
-    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="";
 
@@ -318,13 +369,15 @@ wxString rc2xml::GetToken()
 
     while (!Seperator(ch))
     {
-    token+=(char)ch;
+    token += (char)ch;
     ReadChar(ch);
     }
 
-    if (ch==EOF)
-        m_done=TRUE;
+    if (ch == EOF)
+        m_done = TRUE;
 
+    if (listseperator)
+      *listseperator = (ch == ',');
     return token;
 }
 
@@ -369,15 +422,22 @@ void rc2xml::ParseComboBox()
 {
 /* 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;
-    ReadRect(x,y,width,height);
+    if (ReadRect(x,y,width,height))
+      ReadOrs(token);
 
-    m_xmlfile.Write("\t\t<combobox");
+    m_xmlfile.Write("\t\t<object class=\"wxComboBox\"");
     WriteBasicInfo(x,y,width,height,varname);
-    m_xmlfile.Write("\n\t\t</combobox>\n");
+    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");
 
 }
 
@@ -386,12 +446,11 @@ void rc2xml::ParseMenu(wxString varname)
     wxString token="";
 
     //Write menubar to xml file
-    m_xmlfile.Write("\t<menubar");
+    m_xmlfile.Write("\t<object class=\"wxMenuBar\"");
     //Avoid duplicate names this way
     varname.Replace("IDR_","MB_");
     WriteName(varname);
     m_xmlfile.Write(">\n");
-    m_xmlfile.Write("\t\t<children>\n");
 
     while ((token!="BEGIN")&(token!="{"))
         token=GetToken();
@@ -404,8 +463,7 @@ void rc2xml::ParseMenu(wxString varname)
         ParsePopupMenu();
         }
     }
-    m_xmlfile.Write("\t\t</children>\n");
-    m_xmlfile.Write("\t</menubar>\n");
+    m_xmlfile.Write("\t</object>\n");
 }
 
 void rc2xml::ParsePopupMenu()
@@ -423,11 +481,10 @@ void rc2xml::ParsePopupMenu()
 //Write Menu item
 //Generate a fake name since RC menus don't have one
     name<<"Menu_"<<menucount;
-    m_xmlfile.Write("\t\t<menu");
+    m_xmlfile.Write("\t\t<object class=\"wxMenu\"");
     WriteName(name);
     m_xmlfile.Write(">\n");
     WriteLabel(token);
-    m_xmlfile.Write("\t\t\t<children>\n");
 
     while ((token!="BEGIN")&(token!="{"))
         token=GetToken();
@@ -441,8 +498,7 @@ void rc2xml::ParsePopupMenu()
     if (token=="MENUITEM")
         ParseMenuItem();
     }
-    m_xmlfile.Write("\t\t\t</children>\n");
-    m_xmlfile.Write("\t\t\t</menu>\n");
+    m_xmlfile.Write("\t\t\t</object>\n");
 }
 
 wxString rc2xml::PeekToken()
@@ -484,10 +540,10 @@ void rc2xml::ParseSlider(wxString label, wxString varname)
 
     int x,y,width,height;
     ReadRect(x,y,width,height);
-    m_xmlfile.Write("\t\t<slider");
+    m_xmlfile.Write("\t\t<object class=\"wxSlider\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteStyle(style);
-    m_xmlfile.Write("\n\t\t</slider>\n");
+    m_xmlfile.Write("\n\t\t</object>\n");
 
 }
 /*    
@@ -503,10 +559,10 @@ void rc2xml::ParseProgressBar(wxString label, wxString varname)
     ReadRect(x,y,width,height);
 
 //Always horizontal in MFC
-    m_xmlfile.Write("\t\t<gauge");
+    m_xmlfile.Write("\t\t<object class=\"wxGauge\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteStyle(style);
-    m_xmlfile.Write("\t\t</gauge>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 }
 
 bool rc2xml::ReadOrs(wxString & orstring)
@@ -538,19 +594,19 @@ void rc2xml::ParseCtrlButton(wxString label, wxString varname)
     if (token.Find("BS_AUTOCHECKBOX")!=-1)
         {
         ReadRect(x,y,width,height);
-        m_xmlfile.Write("\t\t<checkbox");
+        m_xmlfile.Write("\t\t<object class=\"wxCheckBox\"");
         WriteBasicInfo(x,y,width,height,varname);
         WriteLabel(label);
-        m_xmlfile.Write("\t\t</checkbox>\n");
+        m_xmlfile.Write("\t\t</object>\n");
         }
 
     if (token.Find("BS_AUTORADIOBUTTON")!=-1)
         {
         ReadRect(x,y,width,height);
-        m_xmlfile.Write("\t\t<radiobutton");
+        m_xmlfile.Write("\t\t<object class=\"wxRadioButton\"");
         WriteBasicInfo(x,y,width,height,varname);
         WriteLabel(label);
-        m_xmlfile.Write("\t\t</radiobutton>\n");
+        m_xmlfile.Write("\t\t</object>\n");
         }
 
 }
@@ -616,6 +672,12 @@ name=LookUpId(name);
         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+"\"");
 }
@@ -640,7 +702,7 @@ void rc2xml::WriteStyle(wxString style)
 {
     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 | 
@@ -654,9 +716,9 @@ void rc2xml::ParseListBox()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<listbox");
+    m_xmlfile.Write("\t\t<object class=\"wxListBox\"");
     WriteBasicInfo(x,y,width,height,varname);
-    m_xmlfile.Write("\n\t\t</listbox>\n");
+    m_xmlfile.Write("\n\t\t</object>\n");
 
 }
 /*
@@ -673,10 +735,10 @@ void rc2xml::ParseRichEdit(wxString label, wxString varname)
     wxString style;
 //Make it a rich text control
     style+="wxTE_MULTILINE ";
-    m_xmlfile.Write("\t\t<textctrl");
+    m_xmlfile.Write("\t\t<object class=\"wxTextCtrl\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteStyle(style);
-    m_xmlfile.Write("\t\t</textctrl>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 /*
@@ -696,10 +758,10 @@ void rc2xml::ParseSpinCtrl(wxString label, wxString varname)
 
     int x,y,width,height;
     ReadRect(x,y,width,height);
-    m_xmlfile.Write("\t\t<spinbutton");
+    m_xmlfile.Write("\t\t<object class=\"wxSpinButton\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteStyle(style);
-    m_xmlfile.Write("\n\t\t</spinbutton>\n");
+    m_xmlfile.Write("\n\t\t</object>\n");
 
 }
 
@@ -770,7 +832,7 @@ void rc2xml::ParseToolBar(wxString varname)
         wxLogError("Unable to load bitmap:"+*bitmappath);
 
 //Write toolbar to xml file
-    m_xmlfile.Write("  <toolbar");
+    m_xmlfile.Write("  <object class=\"wxToolBar\"");
 //Avoid duplicate names this way
     varname.Replace("IDR_","TB_");
     WriteName(varname);
@@ -779,7 +841,6 @@ void rc2xml::ParseToolBar(wxString varname)
     style+="wxTB_FLAT";
     WriteStyle(style);
 
-    m_xmlfile.Write("\t\t<children>\n");
 
 //Grab width and height
     int width,height;
@@ -797,7 +858,7 @@ void rc2xml::ParseToolBar(wxString varname)
         if (token=="BUTTON")
             {
             buttonname=GetToken();
-            m_xmlfile.Write("\t\t\t<tool");
+            m_xmlfile.Write("\t\t\t<object class=\"tool\"");
             WriteName(buttonname);
             m_xmlfile.Write(">\n");
     //Write tool tip if any
@@ -812,17 +873,16 @@ void rc2xml::ParseToolBar(wxString varname)
             buttonname+=".bmp";
             m_xmlfile.Write("\t\t\t\t<bitmap>"+buttonname+"</bitmap>\n");
         WriteToolButton(buttonname,c,width,height,bitmap);
-        m_xmlfile.Write("\t\t\t</tool>\n");
+        m_xmlfile.Write("\t\t\t</object>\n");
         c++;
         }
     else if (token=="SEPARATOR")
     {
-    m_xmlfile.Write("\t\t\t<separator/>\n");
+    m_xmlfile.Write("\t\t\t<object class=\"separator\"/>\n");
     }
     token=GetToken();
     }
-    m_xmlfile.Write("\t</children>\n");
-    m_xmlfile.Write("\t</toolbar>\n");
+    m_xmlfile.Write("\t</object>\n");
 }
 
 //Extract bitmaps from larger toolbar bitmap
@@ -833,7 +893,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);
-    little.SaveFile(name,wxBITMAP_TYPE_BMP);
+    little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP);
 }
 
 void rc2xml::ParseStringTable(wxString varname)
@@ -890,7 +950,7 @@ void rc2xml::ParseMenuItem()
 //int spot;
     if (PeekToken()=="SEPARATOR")
         {
-        m_xmlfile.Write("\t\t\t<separator/>\n");
+        m_xmlfile.Write("\t\t\t<object class=\"separator\"/>\n");
         return;
         }
 
@@ -899,7 +959,7 @@ void rc2xml::ParseMenuItem()
 //Remove \t because it causes problems
 //spot=token.First("\\t");
 //token=token.Left(spot);
-    m_xmlfile.Write("\t\t\t<menuitem");
+    m_xmlfile.Write("\t\t\t<object class=\"wxMenuItem\"");
     WriteName(name);
     m_xmlfile.Write(">\n");
     WriteLabel(token);
@@ -926,7 +986,7 @@ void rc2xml::ParseMenuItem()
         
         ptoken=PeekToken();
         }
-    m_xmlfile.Write("\t\t\t</menuitem>\n"); 
+    m_xmlfile.Write("\t\t\t</object>\n"); 
 
 }
 
@@ -942,11 +1002,11 @@ void rc2xml::ParseIconStatic()
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<staticbitmap");
+    m_xmlfile.Write("\t\t<object class=\"wxStaticBitmap\"");
     WriteBasicInfo(x,y,width,height,varname);
 //Save icon as a bitmap
     WriteIcon(iconname);
-    m_xmlfile.Write("\t\t</staticbitmap>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 //IDR_MAINFRAME           ICON    DISCARDABLE     "res\\mfcexample.ico"
@@ -969,6 +1029,8 @@ wxString rc2xml::CleanName(wxString name)
     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...
@@ -984,10 +1046,10 @@ void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname)
     int x,y,width,height;
     ReadRect(x,y,width,height);
 
-    m_xmlfile.Write("\t\t<staticbitmap");
+    m_xmlfile.Write("\t\t<object class=\"wxStaticBitmap\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteBitmap(bitmapname);
-    m_xmlfile.Write("\t\t</staticbitmap>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 
@@ -1058,10 +1120,10 @@ if (token.Find("SBS_VERT")!=-1)
     else
         style=_T("wxSB_HORIZONTAL");
 
-    m_xmlfile.Write("\t\t<scrollbar");
+    m_xmlfile.Write("\t\t<object class=\"wxScrollBar\"");
     WriteBasicInfo(x,y,width,height,varname);
     WriteStyle(style);
-    m_xmlfile.Write("\n\t\t</scrollbar>\n");
+    m_xmlfile.Write("\n\t\t</object>\n");
 
 }
 //    CONTROL         "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
@@ -1074,9 +1136,9 @@ void rc2xml::ParseTreeCtrl(wxString label, wxString varname)
     ReadOrs(token);
     int x,y,width,height;
     ReadRect(x,y,width,height);
-    m_xmlfile.Write("\t\t<treectrl");
+    m_xmlfile.Write("\t\t<object class=\"wxTreeCtrl\"");
     WriteBasicInfo(x,y,width,height,varname);
-    m_xmlfile.Write("\t\t</treectrl>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 //    CONTROL         "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
@@ -1089,9 +1151,9 @@ void rc2xml::ParseCalendar(wxString label, wxString varname)
     ReadOrs(token);
     int x,y,width,height;
     ReadRect(x,y,width,height);
-    m_xmlfile.Write("\t\t<calendarctrl");
+    m_xmlfile.Write("\t\t<object class=\"wxCalendarCtrl\"");
     WriteBasicInfo(x,y,width,height,varname);
-    m_xmlfile.Write("\t\t</calendarctrl>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 }
 //    CONTROL         "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
   //                  7,89,68,71
@@ -1103,9 +1165,9 @@ void rc2xml::ParseListCtrl(wxString label, wxString varname)
     ReadOrs(token);
     int x,y,width,height;
     ReadRect(x,y,width,height);
-    m_xmlfile.Write("\t\t<listctrl");
+    m_xmlfile.Write("\t\t<object class=\"wxListCtrl\"");
     WriteBasicInfo(x,y,width,height,varname);
-    m_xmlfile.Write("\t\t</listctrl>\n");
+    m_xmlfile.Write("\t\t</object>\n");
 
 }
 
@@ -1122,6 +1184,7 @@ void rc2xml::WriteBitmap(wxString bitmapname)
     
     wxString *bitmappath;
     bitmappath=(wxString *)node->Data();
+    bitmapname=wxFileNameFromPath(*bitmappath);
     wxBitmap bitmap;
     if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
         wxLogError("Unable to load bitmap:"+*bitmappath);
@@ -1130,7 +1193,7 @@ void rc2xml::WriteBitmap(wxString bitmapname)
     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)
@@ -1152,12 +1215,12 @@ wxNode *node=m_iconlist->Find(iconname);
 #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");
-    bitmap.SaveFile(iconname,wxBITMAP_TYPE_BMP);
+    bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP);
 
     
 }