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;
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;
}
{
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);
}
* 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
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())),
* 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;
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
}
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;
@brief Provides access to window properties
*/
+#include "ustring.hh"
+#include "screeninfo.hh"
+
extern "C" {
#include <X11/Xlib.h>
#include <X11/Xatom.h>
}
#include <vector>
-#include <string>
-
-#include "screeninfo.hh"
namespace otk {
public:
//! A list of strings
- typedef std::vector<std::string> StringVect;
+ typedef std::vector<ustring> StringVect;
//! Constructs a new Atom object
/*!
@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
@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
}
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;
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
return _string.c_str();
}
+bool ustring::utf8() const
+{
+ return _utf8;
+}
+
+void ustring::setUtf8(bool utf8)
+{
+ _utf8 = utf8;
+}
+
}
#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.
*/
class ustring {
std::string _string;
-
+ bool _utf8;
+
public:
typedef std::string::size_type size_type;
typedef std::string::difference_type difference_type;
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;
const char* data() const;
const char* c_str() const;
+
+ // encoding
+ bool utf8() const;
+ void setUtf8(bool utf8);
};
}
#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) -------- */
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 ;
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;
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 {
}
}
if (_v) {
- return _wrap_Property_set__SWIG_3(self,args);
+ return _wrap_Property_set__SWIG_2(self,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);
}
}
}
}
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);
}
}
}
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}};
_swigt__p_XCirculateEvent,
_swigt__p_XRectangle,
_swigt__p_std__string,
+_swigt__p_ustring,
_swigt__p_XCrossingEvent,
_swigt__p_Display,
_swigt__p_otk__Display,