]> Dogcows Code - chaz/openbox/commitdiff
more conversion to ustring. added more members
authorDana Jansens <danakj@orodu.net>
Mon, 13 Jan 2003 03:51:48 +0000 (03:51 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 13 Jan 2003 03:51:48 +0000 (03:51 +0000)
otk/font.cc
otk/property.cc
otk/property.hh
otk/ustring.cc
otk/ustring.hh
src/openbox_wrap.cc

index b9cc7075ce9c4c8f87a52f856635071c7fa01b5d..6fbdb0957f1d7dddf9622028aeb8afc2edde4e00 100644 (file)
@@ -94,9 +94,14 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
     c.color.alpha = _tint | _tint << 8; // transparent shadow
     c.pixel = BlackPixel(Display::display, _screen_num);
 
-    XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
-                      _xftfont->ascent + y + _offset,
-                      (FcChar8*)string.c_str(), string.size());
+    if (string.utf8())
+      XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
+                        _xftfont->ascent + y + _offset,
+                        (FcChar8*)string.c_str(), string.size());
+    else
+      XftDrawString8(d, &c, _xftfont, x + _offset,
+                     _xftfont->ascent + y + _offset,
+                     (FcChar8*)string.c_str(), string.size());
   }
     
   XftColor c;
@@ -106,8 +111,12 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
   c.pixel = color.pixel();
   c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
 
-  XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
-                    (FcChar8*)string.c_str(), string.size());
+  if (string.utf8())
+    XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
+                      (FcChar8*)string.c_str(), string.size());
+  else
+    XftDrawString8(d, &c, _xftfont, x, _xftfont->ascent + y,
+                   (FcChar8*)string.c_str(), string.size());
 
   return;
 }
@@ -117,8 +126,12 @@ unsigned int Font::measureString(const ustring &string) const
 {
   XGlyphInfo info;
 
-  XftTextExtentsUtf8(Display::display, _xftfont,
-                     (FcChar8*)string.c_str(), string.size(), &info);
+  if (string.utf8())
+    XftTextExtentsUtf8(Display::display, _xftfont,
+                       (FcChar8*)string.c_str(), string.size(), &info);
+  else
+    XftTextExtents8(Display::display, _xftfont,
+                    (FcChar8*)string.c_str(), string.size(), &info);
 
   return info.xOff + (_shadow ? _offset : 0);
 }
index ad9eacc90736ce6a7ec1cb96c2f6676f5f79562e..232803cdd053b8e824ac8d8ca32ec5f6c860ab28 100644 (file)
@@ -217,17 +217,18 @@ void Property::set(Window win, Atoms atom, Atoms type,
  * Set an string property value on a window.
  */
 void Property::set(Window win, Atoms atom, StringType type,
-                          const std::string &value) const
+                          const ustring &value) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
   
   Atom t;
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
+  case ascii: t = _atoms[Atom_String]; assert(!value.utf8()); break;
+  case utf8:  t = _atoms[Atom_Utf8]; assert(value.utf8()); break;
   default: assert(False); return; // unhandled StringType
   }
+  
   set(win, _atoms[atom], t,
       reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
       8, value.size() + 1, False); // add 1 to the size to include the null
@@ -244,18 +245,22 @@ void Property::set(Window win, Atoms atom, StringType type,
   assert(type >= 0 && type < NUM_STRING_TYPE);
 
   Atom t;
+  bool u; // utf8 encoded?
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
+  case ascii: t = _atoms[Atom_String]; u = false; break;
+  case utf8:  t = _atoms[Atom_Utf8];   u = true;  break;
   default: assert(False); return; // unhandled StringType
   }
 
-  std::string value;
+  ustring value;
 
   StringVect::const_iterator it = strings.begin();
   const StringVect::const_iterator end = strings.end();
-  for (; it != end; ++it)
-      value += *it + '\0';
+  for (; it != end; ++it) {
+    assert(it->utf8() == u); // the ustring is encoded correctly?
+    value += *it;
+    value += '\0';
+  }
 
   set(win, _atoms[atom], t,
       reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
@@ -363,10 +368,11 @@ bool Property::get(Window win, Atoms atom, Atoms type,
  * Gets an string property's value from a window.
  */
 bool Property::get(Window win, Atoms atom, StringType type,
-                     std::string *value) const
+                   ustring *value) const
 {
   unsigned long n = 1;
   StringVect s;
+
   if (get(win, atom, type, &n, &s)) {
     *value = s[0];
     return True;
@@ -384,9 +390,10 @@ bool Property::get(Window win, Atoms atom, StringType type,
   assert(*nelements > 0);
 
   Atom t;
+  bool u; // utf8 encoded?
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
+  case ascii: t = _atoms[Atom_String]; u = false; break;
+  case utf8:  t = _atoms[Atom_Utf8];   u = true;  break;
   default: assert(False); return False; // unhandled StringType
   }
   
@@ -404,6 +411,7 @@ bool Property::get(Window win, Atoms atom, StringType type,
     std::string::const_iterator tmp = it; // current string.begin()
     it = std::find(tmp, end, '\0');       // look for null between tmp and end
     strings->push_back(std::string(tmp, it));   // s[tmp:it)
+    if (!u) strings->back().setUtf8(false);
     ++num;
     if (it == end) break;
     ++it;
index 7f4ae266f9691b2834ccc01d331d1d00297e17bf..9681b9c311be125c2568c6a16a7175c95ce03d8e 100644 (file)
@@ -6,6 +6,9 @@
   @brief Provides access to window properties
 */
 
+#include "ustring.hh"
+#include "screeninfo.hh"
+
 extern "C" {
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -14,9 +17,6 @@ extern "C" {
 }
 
 #include <vector>
-#include <string>
-
-#include "screeninfo.hh"
 
 namespace otk {
 
@@ -176,7 +176,7 @@ private:
 
 public:
   //! A list of strings
-  typedef std::vector<std::string> StringVect;
+  typedef std::vector<ustring> StringVect;
 
   //! Constructs a new Atom object
   /*!
@@ -220,7 +220,7 @@ public:
     @param value The string to set the property to
   */
   void set(Window win, Atoms atom, StringType type,
-           const std::string &value) const;
+           const ustring &value) const;
   //! Sets a string-array property on a window to a new value
   /*!
     @param win The window id of the window on which to set the property's value
@@ -284,7 +284,7 @@ public:
     @return true if retrieval of the specified property with the specified
             type was successful; otherwise, false
   */
-  bool get(Window win, Atoms atom, StringType type, std::string *value) const;
+  bool get(Window win, Atoms atom, StringType type, ustring *value) const;
   //! Gets strings from the value of a property on a window
   /*!
     @param win The window id of the window to get the property value from
index be16bb1702a202bf0c0f654a34828770f47e6c37..a04c08cff69496e91c5f547cd6423372d03649e7 100644 (file)
@@ -21,27 +21,47 @@ ustring::~ustring()
 }
 
 ustring::ustring(const ustring& other)
-  : _string(other._string)
+  : _string(other._string), _utf8(other._utf8)
 {
 }
 
 ustring& ustring::operator=(const ustring& other)
 {
   _string = other._string;
+  _utf8 = other._utf8;
   return *this;
 }
 
 ustring::ustring(const std::string& src)
-  : _string(src)
+  : _string(src), _utf8(true)
 {
 }
 
 ustring::ustring(const char* src)
-  : _string(src)
+  : _string(src), _utf8(true)
 {
 }
 
-static ustring::size_type find_offset(const char *str, const char *pos)
+ustring& ustring::operator+=(const ustring& src)
+{
+  assert(_utf8 == src._utf8);
+  _string += src._string;
+  return *this;
+}
+
+ustring& ustring::operator+=(const char* src)
+{
+  _string += src;
+  return *this;
+}
+
+ustring& ustring::operator+=(char c)
+{
+  _string += c;
+  return *this;
+}
+
+static ustring::size_type find_utf8_offset(const char *str, const char *pos)
 {
   ustring::size_type offset = 0;
 
@@ -55,14 +75,11 @@ static ustring::size_type find_offset(const char *str, const char *pos)
 
 ustring::size_type ustring::size() const
 {
-  const char *const pdata = _string.data();
-  return find_offset(pdata, pdata + _string.size());
-}
-
-ustring::size_type ustring::length() const
-{
-  const char *const pdata = _string.data();
-  return find_offset(pdata, pdata + _string.size());
+  if (_utf8) {
+    const char *const pdata = _string.data();
+    return find_utf8_offset(pdata, pdata + _string.size());
+  } else
+    return _string.size();
 }
 
 ustring::size_type ustring::bytes() const
@@ -91,4 +108,14 @@ const char* ustring::c_str() const
   return _string.c_str();
 }
 
+bool ustring::utf8() const
+{
+  return _utf8;
+}
+
+void ustring::setUtf8(bool utf8)
+{
+  _utf8 = utf8;
+}
+
 }
index 03f893d309333ea34b69203cbff93a9ae7d0c701..02111a3379e89dde26e1a90b444226d6a6435cda 100644 (file)
@@ -106,8 +106,9 @@ private:
 
 #endif // DOXYGEN_IGNORE
 
-//! This class provides a simple wrapper to a std::string that is encoded as
-//! UTF-8.
+//! This class provides a simple wrapper to a std::string that can be encoded
+//! as UTF-8. The ustring::utf() member specifies if the given string is UTF-8
+//! encoded. ustrings default to specifying UTF-8 encoding.
 /*!
   This class does <b>not</b> handle extended 8-bit ASCII charsets like
   ISO-8859-1.
@@ -120,7 +121,8 @@ private:
 */
 class ustring {
   std::string _string;
-
+  bool _utf8;
+  
 public:
   typedef std::string::size_type                        size_type;
   typedef std::string::difference_type                  difference_type;
@@ -144,10 +146,15 @@ public:
   ustring(const std::string& src);
   ustring::ustring(const char* src);
 
+  // append to the string
+
+  ustring& operator+=(const ustring& src);
+  ustring& operator+=(const char* src);
+  ustring& operator+=(char c);
+
   // sizes
   
   ustring::size_type size() const;
-  ustring::size_type length() const;
   ustring::size_type bytes() const;
   ustring::size_type capacity() const;
   ustring::size_type max_size() const;
@@ -156,7 +163,11 @@ public:
 
   const char* data()  const;
   const char* c_str() const;
+
+  // encoding
   
+  bool utf8() const;
+  void setUtf8(bool utf8);
 };
 
 }
index 548cebbc95e552422b437ade24518a84bbc176b0..533b0046959ab1e72c19e87541360ef230112ff6 100644 (file)
@@ -677,36 +677,37 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
 #define  SWIGTYPE_p_XCirculateEvent swig_types[29] 
 #define  SWIGTYPE_p_XRectangle swig_types[30] 
 #define  SWIGTYPE_p_std__string swig_types[31] 
-#define  SWIGTYPE_p_XCrossingEvent swig_types[32] 
-#define  SWIGTYPE_p_Display swig_types[33] 
-#define  SWIGTYPE_p_otk__Display swig_types[34] 
-#define  SWIGTYPE_p_XMappingEvent swig_types[35] 
-#define  SWIGTYPE_p_otk__Style swig_types[36] 
-#define  SWIGTYPE_p_otk__EventHandler swig_types[37] 
-#define  SWIGTYPE_p_XReparentEvent swig_types[38] 
-#define  SWIGTYPE_p_otk__EventDispatcher swig_types[39] 
-#define  SWIGTYPE_p_otk__GCCache swig_types[40] 
-#define  SWIGTYPE_p_ob__Bindings swig_types[41] 
-#define  SWIGTYPE_p_ob__Openbox swig_types[42] 
-#define  SWIGTYPE_p_ob__Actions swig_types[43] 
-#define  SWIGTYPE_p_XEvent swig_types[44] 
-#define  SWIGTYPE_p_otk__Property swig_types[45] 
-#define  SWIGTYPE_p_PyObject swig_types[46] 
-#define  SWIGTYPE_p_otk__ScreenInfo swig_types[47] 
-#define  SWIGTYPE_p_ob__EventData swig_types[48] 
-#define  SWIGTYPE_p_XCreateWindowEvent swig_types[49] 
-#define  SWIGTYPE_p_XDestroyWindowEvent swig_types[50] 
-#define  SWIGTYPE_p_otk__Property__StringVect swig_types[51] 
-#define  SWIGTYPE_p_ob__WidgetBase swig_types[52] 
-#define  SWIGTYPE_p_XKeyEvent swig_types[53] 
-#define  SWIGTYPE_p_otk__Strut swig_types[54] 
-#define  SWIGTYPE_p_unsigned_long swig_types[55] 
-#define  SWIGTYPE_p_p_unsigned_long swig_types[56] 
-#define  SWIGTYPE_p_XMotionEvent swig_types[57] 
-#define  SWIGTYPE_p_XButtonEvent swig_types[58] 
-#define  SWIGTYPE_p_XSelectionEvent swig_types[59] 
-#define  SWIGTYPE_p_otk__TimerQueueManager swig_types[60] 
-static swig_type_info *swig_types[62];
+#define  SWIGTYPE_p_ustring swig_types[32] 
+#define  SWIGTYPE_p_XCrossingEvent swig_types[33] 
+#define  SWIGTYPE_p_Display swig_types[34] 
+#define  SWIGTYPE_p_otk__Display swig_types[35] 
+#define  SWIGTYPE_p_XMappingEvent swig_types[36] 
+#define  SWIGTYPE_p_otk__Style swig_types[37] 
+#define  SWIGTYPE_p_otk__EventHandler swig_types[38] 
+#define  SWIGTYPE_p_XReparentEvent swig_types[39] 
+#define  SWIGTYPE_p_otk__EventDispatcher swig_types[40] 
+#define  SWIGTYPE_p_otk__GCCache swig_types[41] 
+#define  SWIGTYPE_p_ob__Bindings swig_types[42] 
+#define  SWIGTYPE_p_ob__Openbox swig_types[43] 
+#define  SWIGTYPE_p_ob__Actions swig_types[44] 
+#define  SWIGTYPE_p_XEvent swig_types[45] 
+#define  SWIGTYPE_p_otk__Property swig_types[46] 
+#define  SWIGTYPE_p_PyObject swig_types[47] 
+#define  SWIGTYPE_p_otk__ScreenInfo swig_types[48] 
+#define  SWIGTYPE_p_ob__EventData swig_types[49] 
+#define  SWIGTYPE_p_XCreateWindowEvent swig_types[50] 
+#define  SWIGTYPE_p_XDestroyWindowEvent swig_types[51] 
+#define  SWIGTYPE_p_otk__Property__StringVect swig_types[52] 
+#define  SWIGTYPE_p_ob__WidgetBase swig_types[53] 
+#define  SWIGTYPE_p_XKeyEvent swig_types[54] 
+#define  SWIGTYPE_p_otk__Strut swig_types[55] 
+#define  SWIGTYPE_p_unsigned_long swig_types[56] 
+#define  SWIGTYPE_p_p_unsigned_long swig_types[57] 
+#define  SWIGTYPE_p_XMotionEvent swig_types[58] 
+#define  SWIGTYPE_p_XButtonEvent swig_types[59] 
+#define  SWIGTYPE_p_XSelectionEvent swig_types[60] 
+#define  SWIGTYPE_p_otk__TimerQueueManager swig_types[61] 
+static swig_type_info *swig_types[63];
 
 /* -------- TYPES TABLE (END) -------- */
 
@@ -1505,8 +1506,7 @@ static PyObject *_wrap_Property_set__SWIG_2(PyObject *self, PyObject *args) {
     Window arg2 ;
     int arg3 ;
     int arg4 ;
-    std::string *arg5 = 0 ;
-    std::string temp5 ;
+    ustring *arg5 = 0 ;
     PyObject * obj0  = 0 ;
     PyObject * obj1  = 0 ;
     PyObject * obj4  = 0 ;
@@ -1515,15 +1515,11 @@ static PyObject *_wrap_Property_set__SWIG_2(PyObject *self, PyObject *args) {
     if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Property,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
     arg2 = (Window) PyInt_AsLong(obj1);
     if (PyErr_Occurred()) SWIG_fail;
-    {
-        if (PyString_Check(obj4)) {
-            temp5 = std::string(PyString_AsString(obj4));
-            arg5 = &temp5;
-        }else {
-            SWIG_exception(SWIG_TypeError, "string expected");
-        }
+    if ((SWIG_ConvertPtr(obj4,(void **) &arg5, SWIGTYPE_p_ustring,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
+    if (arg5 == NULL) {
+        PyErr_SetString(PyExc_TypeError,"null reference"); SWIG_fail; 
     }
-    ((otk::Property const *)arg1)->set(arg2,(otk::Property::Atoms )arg3,(otk::Property::StringType )arg4,(std::string const &)*arg5);
+    ((otk::Property const *)arg1)->set(arg2,(otk::Property::Atoms )arg3,(otk::Property::StringType )arg4,(ustring const &)*arg5);
     
     Py_INCREF(Py_None); resultobj = Py_None;
     return resultobj;
@@ -1595,7 +1591,7 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) {
                     if (_v) {
                         {
                             void *ptr;
-                            if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_otk__Property__StringVect, 0) == -1) {
+                            if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_ustring, 0) == -1) {
                                 _v = 0;
                                 PyErr_Clear();
                             }else {
@@ -1603,7 +1599,7 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) {
                             }
                         }
                         if (_v) {
-                            return _wrap_Property_set__SWIG_3(self,args);
+                            return _wrap_Property_set__SWIG_2(self,args);
                         }
                     }
                 }
@@ -1635,10 +1631,16 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) {
                     }
                     if (_v) {
                         {
-                            _v = (PyInt_Check(argv[4]) || PyLong_Check(argv[4])) ? 1 : 0;
+                            void *ptr;
+                            if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_otk__Property__StringVect, 0) == -1) {
+                                _v = 0;
+                                PyErr_Clear();
+                            }else {
+                                _v = 1;
+                            }
                         }
                         if (_v) {
-                            return _wrap_Property_set__SWIG_0(self,args);
+                            return _wrap_Property_set__SWIG_3(self,args);
                         }
                     }
                 }
@@ -1670,10 +1672,10 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) {
                     }
                     if (_v) {
                         {
-                            _v = PyString_Check(argv[4]) ? 1 : 0;
+                            _v = (PyInt_Check(argv[4]) || PyLong_Check(argv[4])) ? 1 : 0;
                         }
                         if (_v) {
-                            return _wrap_Property_set__SWIG_2(self,args);
+                            return _wrap_Property_set__SWIG_0(self,args);
                         }
                     }
                 }
@@ -8251,6 +8253,7 @@ static swig_type_info _swigt__p_XConfigureEvent[] = {{"_p_XConfigureEvent", 0, "
 static swig_type_info _swigt__p_XCirculateEvent[] = {{"_p_XCirculateEvent", 0, "XCirculateEvent *", 0},{"_p_XCirculateEvent"},{0}};
 static swig_type_info _swigt__p_XRectangle[] = {{"_p_XRectangle", 0, "XRectangle *", 0},{"_p_XRectangle"},{0}};
 static swig_type_info _swigt__p_std__string[] = {{"_p_std__string", 0, "std::string *", 0},{"_p_std__string"},{0}};
+static swig_type_info _swigt__p_ustring[] = {{"_p_ustring", 0, "ustring *", 0},{"_p_ustring"},{0}};
 static swig_type_info _swigt__p_XCrossingEvent[] = {{"_p_XCrossingEvent", 0, "XCrossingEvent *", 0},{"_p_XCrossingEvent"},{0}};
 static swig_type_info _swigt__p_Display[] = {{"_p_Display", 0, "Display *", 0},{"_p_Display"},{0}};
 static swig_type_info _swigt__p_otk__Display[] = {{"_p_otk__Display", 0, "otk::Display *", 0},{"_p_otk__Display"},{0}};
@@ -8314,6 +8317,7 @@ _swigt__p_XConfigureEvent,
 _swigt__p_XCirculateEvent, 
 _swigt__p_XRectangle, 
 _swigt__p_std__string, 
+_swigt__p_ustring, 
 _swigt__p_XCrossingEvent, 
 _swigt__p_Display, 
 _swigt__p_otk__Display, 
This page took 0.042777 seconds and 4 git commands to generate.