]> Dogcows Code - chaz/openbox/blobdiff - otk/property.cc
default to drawing as utf8
[chaz/openbox] / otk / property.cc
index 5ebb2f0f154b05cdcbaa2a23c0fb00e9d17de8ef..77bdfb0382fefff651a8d5e7ff644174982b54db 100644 (file)
@@ -15,9 +15,9 @@ extern "C" {
 
 namespace otk {
 
-OBProperty::OBProperty()
+Property::Property()
 {
-  assert(OBDisplay::display);
+  assert(Display::display);
 
   // make sure asserts fire if there is a problem
   memset(_atoms, 0, sizeof(_atoms));
@@ -40,6 +40,7 @@ OBProperty::OBProperty()
   _atoms[wm_name] = create("WM_NAME");
   _atoms[wm_icon_name] = create("WM_ICON_NAME");
   _atoms[wm_class] = create("WM_CLASS");
+  _atoms[wm_window_role] = create("WM_WINDOW_ROLE");
   _atoms[motif_wm_hints] = create("_MOTIF_WM_HINTS");
   _atoms[blackbox_hints] = create("_BLACKBOX_HINTS");
   _atoms[blackbox_attributes] = create("_BLACKBOX_ATTRIBUTES");
@@ -152,7 +153,7 @@ OBProperty::OBProperty()
 /*
  * clean up the class' members
  */
-OBProperty::~OBProperty()
+Property::~Property()
 {
 }
 
@@ -160,9 +161,9 @@ OBProperty::~OBProperty()
 /*
  * Returns an atom from the Xserver, creating it if necessary.
  */
-Atom OBProperty::create(const char *name) const
+Atom Property::create(const char *name) const
 {
-  Atom a = XInternAtom(OBDisplay::display, name, False);
+  Atom a = XInternAtom(Display::display, name, false);
   assert(a);
   return a;
 }
@@ -173,14 +174,14 @@ Atom OBProperty::create(const char *name) const
  * Sets a window property on a window, optionally appending to the existing
  * value.
  */
-void OBProperty::set(Window win, Atom atom, Atom type,
+void Property::set(Window win, Atom atom, Atom type,
                           unsigned char* data, int size, int nelements,
                           bool append) const
 {
   assert(win != None); assert(atom != None); assert(type != None);
   assert(nelements == 0 || (nelements > 0 && data != (unsigned char *) 0));
   assert(size == 8 || size == 16 || size == 32);
-  XChangeProperty(OBDisplay::display, win, atom, type, size,
+  XChangeProperty(Display::display, win, atom, type, size,
                   (append ? PropModeAppend : PropModeReplace),
                   data, nelements);
 }
@@ -189,34 +190,34 @@ void OBProperty::set(Window win, Atom atom, Atom type,
 /*
  * Set a 32-bit property value on a window.
  */
-void OBProperty::set(Window win, Atoms atom, Atoms type,
+void Property::set(Window win, Atoms atom, Atoms type,
                           unsigned long value) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   set(win, _atoms[atom], _atoms[type],
-           reinterpret_cast<unsigned char*>(&value), 32, 1, False);
+           reinterpret_cast<unsigned char*>(&value), 32, 1, false);
 }
 
 
 /*
  * Set an array of 32-bit properties value on a window.
  */
-void OBProperty::set(Window win, Atoms atom, Atoms type,
+void Property::set(Window win, Atoms atom, Atoms type,
                           unsigned long value[], int elements) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   set(win, _atoms[atom], _atoms[type],
-      reinterpret_cast<unsigned char*>(value), 32, elements, False);
+      reinterpret_cast<unsigned char*>(value), 32, elements, false);
 }
 
 
 /*
  * Set an string property value on a window.
  */
-void OBProperty::set(Window win, Atoms atom, StringType type,
-                          const std::string &value) const
+void Property::set(Window win, Atoms atom, StringType type,
+                          const userstring &value) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
@@ -225,19 +226,19 @@ void OBProperty::set(Window win, Atoms atom, StringType type,
   switch (type) {
   case ascii: t = _atoms[Atom_String]; break;
   case utf8:  t = _atoms[Atom_Utf8]; break;
-  default: assert(False); return; // unhandled StringType
+  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
+      8, value.size() + 1, false); // add 1 to the size to include the null
 }
 
 
 /*
  * Set an array of string property values on a window.
  */
-void OBProperty::set(Window win, Atoms atom, StringType type,
-                     const StringVect &strings) const
+void Property::set(Window win, Atoms atom, StringType type,
+                     const userstring::vector &strings) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
@@ -246,30 +247,30 @@ void OBProperty::set(Window win, Atoms atom, StringType type,
   switch (type) {
   case ascii: t = _atoms[Atom_String]; break;
   case utf8:  t = _atoms[Atom_Utf8]; break;
-  default: assert(False); return; // unhandled StringType
+  default: assert(false); return; // unhandled StringType
   }
 
   std::string value;
 
-  StringVect::const_iterator it = strings.begin();
-  const StringVect::const_iterator end = strings.end();
+  userstring::vector::const_iterator it = strings.begin();
+  const userstring::vector::const_iterator end = strings.end();
   for (; it != end; ++it)
       value += *it + '\0';
 
   set(win, _atoms[atom], t,
       reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
-      8, value.size(), False);
+      8, value.size(), false);
 }
 
 
 /*
  * Internal get function used by all of the typed get functions.
  * Gets an property's value from a window.
- * Returns True if the property was successfully retrieved; False if the
+ * Returns true if the property was successfully retrieved; false if the
  * property did not exist on the window, or has a different type/size format
  * than the user tried to retrieve.
  */
-bool OBProperty::get(Window win, Atom atom, Atom type,
+bool Property::get(Window win, Atom atom, Atom type,
                           unsigned long *nelements, unsigned char **value,
                           int size) const
 {
@@ -282,11 +283,11 @@ bool OBProperty::get(Window win, Atom atom, Atom type,
   unsigned long ret_bytes;
   int result;
   unsigned long maxread = *nelements;
-  bool ret = False;
+  bool ret = false;
 
   // try get the first element
-  result = XGetWindowProperty(OBDisplay::display, win, atom, 0l, 1l,
-                              False, AnyPropertyType, &ret_type, &ret_size,
+  result = XGetWindowProperty(Display::display, win, atom, 0l, 1l,
+                              false, AnyPropertyType, &ret_type, &ret_size,
                               nelements, &ret_bytes, &c_val);
   ret = (result == Success && ret_type == type && ret_size == size &&
          *nelements > 0);
@@ -303,8 +304,8 @@ bool OBProperty::get(Window win, Atom atom, Atom type,
       int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
       if (remain > size/8 * (signed)maxread) // dont get more than the max
         remain = size/8 * (signed)maxread;
-      result = XGetWindowProperty(OBDisplay::display, win, atom, 0l,
-                                  remain, False, type, &ret_type, &ret_size,
+      result = XGetWindowProperty(Display::display, win, atom, 0l,
+                                  remain, false, type, &ret_type, &ret_size,
                                   nelements, &ret_bytes, &c_val);
       ret = (result == Success && ret_type == type && ret_size == size &&
              ret_bytes == 0);
@@ -328,7 +329,7 @@ bool OBProperty::get(Window win, Atom atom, Atom type,
 /*
  * Gets a 32-bit property's value from a window.
  */
-bool OBProperty::get(Window win, Atoms atom, Atoms type,
+bool Property::get(Window win, Atoms atom, Atoms type,
                           unsigned long *nelements,
                           unsigned long **value) const
 {
@@ -342,7 +343,7 @@ bool OBProperty::get(Window win, Atoms atom, Atoms type,
 /*
  * Gets a single 32-bit property's value from a window.
  */
-bool OBProperty::get(Window win, Atoms atom, Atoms type,
+bool Property::get(Window win, Atoms atom, Atoms type,
                      unsigned long *value) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
@@ -351,31 +352,36 @@ bool OBProperty::get(Window win, Atoms atom, Atoms type,
   unsigned long num = 1;
   if (! get(win, _atoms[atom], _atoms[type], &num,
                  reinterpret_cast<unsigned char **>(&temp), 32))
-    return False;
+    return false;
   *value = temp[0];
   delete [] temp;
-  return True;
+  return true;
 }
 
 
 /*
  * Gets an string property's value from a window.
  */
-bool OBProperty::get(Window win, Atoms atom, StringType type,
-                     std::string *value) const
+bool Property::get(Window win, Atoms atom, StringType type,
+                     userstring *value) const
 {
   unsigned long n = 1;
-  StringVect s;
+  userstring::vector s;
   if (get(win, atom, type, &n, &s)) {
     *value = s[0];
-    return True;
+    switch (type) {
+    case ascii: value->setUtf8(false); break;
+    case utf8:  value->setUtf8(true); break;
+    default: assert(false); return false; // unhandled StringType
+    }
+    return true;
   }
-  return False;
+  return false;
 }
 
 
-bool OBProperty::get(Window win, Atoms atom, StringType type,
-                     unsigned long *nelements, StringVect *strings) const
+bool Property::get(Window win, Atoms atom, StringType type,
+                   unsigned long *nelements, userstring::vector *strings) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
@@ -383,26 +389,27 @@ bool OBProperty::get(Window win, Atoms atom, StringType type,
   assert(*nelements > 0);
 
   Atom t;
+  bool isutf8;
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
-  default: assert(False); return False; // unhandled StringType
+  case ascii: t = _atoms[Atom_String]; isutf8 = false; break;
+  case utf8:  t = _atoms[Atom_Utf8];   isutf8 = true; break;
+  default: assert(false); return false; // unhandled StringType
   }
   
   unsigned char *value;
   unsigned long elements = (unsigned) -1;
   if (!get(win, _atoms[atom], t, &elements, &value, 8) || elements < 1)
-    return False;
+    return false;
 
-  std::string s(reinterpret_cast<char *>(value), elements);
+  userstring s(reinterpret_cast<char *>(value), elements, isutf8);
   delete [] value;
 
-  std::string::const_iterator it = s.begin(), end = s.end();
+  userstring::const_iterator it = s.begin(), end = s.end();
   unsigned long num = 0;
   while(num < *nelements) {
-    std::string::const_iterator tmp = it; // current string.begin()
+    userstring::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)
+    strings->push_back(userstring(tmp, it, isutf8));   // s[tmp:it)
     ++num;
     if (it == end) break;
     ++it;
@@ -411,17 +418,17 @@ bool OBProperty::get(Window win, Atoms atom, StringType type,
 
   *nelements = num;
 
-  return True;
+  return true;
 }
 
 
 /*
  * Removes a property entirely from a window.
  */
-void OBProperty::erase(Window win, Atoms atom) const
+void Property::erase(Window win, Atoms atom) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
-  XDeleteProperty(OBDisplay::display, win, _atoms[atom]);
+  XDeleteProperty(Display::display, win, _atoms[atom]);
 }
 
 }
This page took 0.033762 seconds and 4 git commands to generate.