]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/dialoged/src/reswrite.cpp
bug fixes
[wxWidgets.git] / utils / dialoged / src / reswrite.cpp
index 41766cacd1205913322f7c107034f7ba47d7e028..ba22dfe8853ebf3ce13c5ad029a065724180580e 100644 (file)
 #include <math.h>
 #include <string.h>
 
-#if wxUSE_IOSTREAMH
-#if defined(__WXMSW__) && !defined(__GNUWIN32__)
-#include <strstrea.h>
-#else
-#include <strstream.h>
-#include <fstream.h>
-#endif
-#else
-#include <strstream>
-#include <fstream>
-#endif
-
-
 #include "wx/scrolbar.h"
 #include "wx/string.h"
+#include "wx/wfstream.h"
+#include "wx/txtstrm.h"
 
 #include "reseditr.h"
 
@@ -60,7 +49,7 @@ wxControl *wxResourceTableWithSaving::CreateItem(wxPanel *panel, const wxItemRes
   return item;
 }
 
-void wxResourceTableWithSaving::OutputFont(ostream& stream, const wxFont& font)
+void wxResourceTableWithSaving::OutputFont(wxTextOutputStream& stream, const wxFont& font)
 {
   stream << "[" << font.GetPointSize() << ", '";
   stream << font.GetFamilyString() << "', '";
@@ -78,10 +67,12 @@ void wxResourceTableWithSaving::OutputFont(ostream& stream, const wxFont& font)
  
 bool wxResourceTableWithSaving::Save(const wxString& filename)
 {
-  ofstream stream(((wxString &) filename).GetData());
-  if (stream.bad())
+  wxFileOutputStream file_output( filename.fn_str() );
+  if (file_output.LastError())
     return FALSE;
     
+  wxTextOutputStream stream( file_output );
+    
   BeginFind();
   wxNode *node = NULL;
   while ((node = Next()))
@@ -98,7 +89,7 @@ bool wxResourceTableWithSaving::Save(const wxString& filename)
   return TRUE;
 }
 
-bool wxResourceTableWithSaving::SaveResource(ostream& stream, wxItemResource* item, wxItemResource* parentItem)
+bool wxResourceTableWithSaving::SaveResource(wxTextOutputStream& stream, wxItemResource* item, wxItemResource* parentItem)
 {
   char styleBuf[400];
   wxString itemType(item->GetType());
@@ -117,7 +108,7 @@ bool wxResourceTableWithSaving::SaveResource(ostream& stream, wxItemResource* it
       }
 
       stream << "  style = '" << styleBuf << "',\\\n";
-      stream << "  title = '" << item->GetTitle() << "',\\\n";
+      stream << "  title = " << SafeWord(item->GetTitle()) << ",\\\n";
       stream << "  id = " << item->GetId() << ",\\\n";
       stream << "  x = " << item->GetX() << ", y = " << item->GetY();
       stream << ", width = " << item->GetWidth() << ", height = " << item->GetHeight();
@@ -310,7 +301,9 @@ bool wxResourceTableWithSaving::SaveResource(ostream& stream, wxItemResource* it
           node = node->Next();
         }
       }
-      stream << "], ";
+      stream << "]";
+/* Styles are now in the window style, not in a separate arg
+      stream << ", ";
       switch (item->GetValue1())
       {
         case wxLB_MULTIPLE:
@@ -330,6 +323,8 @@ bool wxResourceTableWithSaving::SaveResource(ostream& stream, wxItemResource* it
           break;
         }
       }
+ */
+
       if (item->GetFont().Ok())
       {
         stream << ",\\\n      ";
@@ -581,17 +576,35 @@ char *SafeString(const wxString& s)
   }
 }
 
-// Returns quoted string or ''
+// Returns quoted string or '' : convert " to \"
 char *SafeWord(const wxString& s)
 {
-  if (s == "")
-    return "''";
-  else
-  {
-    strcpy(wxBuffer, "'");
-    strcat(wxBuffer, (const char*) s);
-    strcat(wxBuffer, "'");
-    return wxBuffer;
-  }
+       const char *cp;
+       char *dp;
+
+       if (s == "")
+               return "''";
+       else
+       {
+               dp = wxBuffer;
+               cp = s.c_str();
+               *dp++ = '\'';
+               while(*cp != 0) {
+                       if(*cp == '"') {
+                               *dp++ = '\\';
+                               *dp++ = '"';
+                       } else if(*cp == '\'') {
+                               *dp++ = '\\';
+                               *dp++ = '\'';
+                       } else
+                               *dp++ = *cp;
+
+                       cp++;
+               }
+               *dp++ = '\'';
+               *dp++ = 0;
+
+               return wxBuffer;
+       }
 }