use "userstring" for all user viewable strings
This commit is contained in:
parent
c03068ee3a
commit
74061b4e2d
9 changed files with 156 additions and 72 deletions
|
@ -41,7 +41,7 @@ void FocusLabel::update(void)
|
||||||
: style()->getTextUnfocus());
|
: style()->getTextUnfocus());
|
||||||
unsigned int sidemargin = style()->getBevelWidth() * 2;
|
unsigned int sidemargin = style()->getBevelWidth() * 2;
|
||||||
|
|
||||||
std::string t = _text; // the actual text to draw
|
userstring t = _text; // the actual text to draw
|
||||||
int x = sidemargin; // x coord for the text
|
int x = sidemargin; // x coord for the text
|
||||||
|
|
||||||
// find a string that will fit inside the area for text
|
// find a string that will fit inside the area for text
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "focuswidget.hh"
|
#include "focuswidget.hh"
|
||||||
#include "font.hh"
|
#include "font.hh"
|
||||||
|
#include "userstring.hh"
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -14,8 +15,8 @@ public:
|
||||||
FocusLabel(Widget *parent);
|
FocusLabel(Widget *parent);
|
||||||
~FocusLabel();
|
~FocusLabel();
|
||||||
|
|
||||||
inline const std::string &getText(void) const { return _text; }
|
inline const userstring &getText(void) const { return _text; }
|
||||||
void setText(const std::string &text) { _text = text; _dirty = true; }
|
void setText(const userstring &text) { _text = text; _dirty = true; }
|
||||||
|
|
||||||
void update(void);
|
void update(void);
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ private:
|
||||||
//! Object used by Xft to render to the drawable
|
//! Object used by Xft to render to the drawable
|
||||||
XftDraw *_xftdraw;
|
XftDraw *_xftdraw;
|
||||||
//! Text displayed in the label
|
//! Text displayed in the label
|
||||||
std::string _text;
|
userstring _text;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
22
otk/font.cc
22
otk/font.cc
|
@ -10,15 +10,7 @@ extern "C" {
|
||||||
#endif // HAVE_STDLIB_H
|
#endif // HAVE_STDLIB_H
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::cerr;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
#include "font.hh"
|
#include "font.hh"
|
||||||
#include "util.hh"
|
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
#include "color.hh"
|
#include "color.hh"
|
||||||
#include "screeninfo.hh"
|
#include "screeninfo.hh"
|
||||||
|
@ -34,10 +26,10 @@ extern "C" {
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
string Font::_fallback_font = "fixed";
|
std::string Font::_fallback_font = "fixed";
|
||||||
bool Font::_xft_init = false;
|
bool Font::_xft_init = false;
|
||||||
|
|
||||||
Font::Font(int screen_num, const string &fontstring,
|
Font::Font(int screen_num, const std::string &fontstring,
|
||||||
bool shadow, unsigned char offset, unsigned char tint)
|
bool shadow, unsigned char offset, unsigned char tint)
|
||||||
: _screen_num(screen_num),
|
: _screen_num(screen_num),
|
||||||
_fontstring(fontstring),
|
_fontstring(fontstring),
|
||||||
|
@ -86,7 +78,7 @@ Font::~Font(void)
|
||||||
|
|
||||||
|
|
||||||
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
const string &string, bool utf8) const
|
const userstring &string) const
|
||||||
{
|
{
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
|
@ -98,7 +90,7 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
c.color.alpha = _tint | _tint << 8; // transparent shadow
|
c.color.alpha = _tint | _tint << 8; // transparent shadow
|
||||||
c.pixel = BlackPixel(Display::display, _screen_num);
|
c.pixel = BlackPixel(Display::display, _screen_num);
|
||||||
|
|
||||||
if (utf8)
|
if (string.utf8())
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
|
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
|
||||||
_xftfont->ascent + y + _offset,
|
_xftfont->ascent + y + _offset,
|
||||||
(FcChar8*)string.c_str(), string.size());
|
(FcChar8*)string.c_str(), string.size());
|
||||||
|
@ -115,7 +107,7 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
c.pixel = color.pixel();
|
c.pixel = color.pixel();
|
||||||
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
||||||
|
|
||||||
if (utf8)
|
if (string.utf8())
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
||||||
(FcChar8*)string.c_str(), string.size());
|
(FcChar8*)string.c_str(), string.size());
|
||||||
else
|
else
|
||||||
|
@ -126,11 +118,11 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int Font::measureString(const string &string, bool utf8) const
|
unsigned int Font::measureString(const userstring &string) const
|
||||||
{
|
{
|
||||||
XGlyphInfo info;
|
XGlyphInfo info;
|
||||||
|
|
||||||
if (utf8)
|
if (string.utf8())
|
||||||
XftTextExtentsUtf8(Display::display, _xftfont,
|
XftTextExtentsUtf8(Display::display, _xftfont,
|
||||||
(FcChar8*)string.c_str(), string.size(), &info);
|
(FcChar8*)string.c_str(), string.size(), &info);
|
||||||
else
|
else
|
||||||
|
|
17
otk/font.hh
17
otk/font.hh
|
@ -2,6 +2,8 @@
|
||||||
#ifndef __font_hh
|
#ifndef __font_hh
|
||||||
#define __font_hh
|
#define __font_hh
|
||||||
|
|
||||||
|
#include "userstring.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
||||||
|
@ -9,6 +11,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
@ -57,16 +60,24 @@ public:
|
||||||
unsigned int height() const;
|
unsigned int height() const;
|
||||||
unsigned int maxCharWidth() const;
|
unsigned int maxCharWidth() const;
|
||||||
|
|
||||||
unsigned int measureString(const std::string &string,
|
//! Measures the length of a string
|
||||||
bool utf8 = false) const;
|
/*!
|
||||||
|
@param string The string to measure, it should be UTF8 encoded.
|
||||||
|
*/
|
||||||
|
unsigned int measureString(const userstring &string) const;
|
||||||
|
|
||||||
//! Draws a string into an XftDraw object
|
//! Draws a string into an XftDraw object
|
||||||
/*!
|
/*!
|
||||||
Be Warned: If you use an XftDraw object and a color, or a font from
|
Be Warned: If you use an XftDraw object and a color, or a font from
|
||||||
different screens, you WILL have unpredictable results! :)
|
different screens, you WILL have unpredictable results! :)
|
||||||
|
@param d The drawable to render into.
|
||||||
|
@param x The X offset onto the drawable at which to start drawing.
|
||||||
|
@param x The Y offset onto the drawable at which to start drawing.
|
||||||
|
@param color The color to use for drawing the text.
|
||||||
|
@param string The string to draw, it should be UTF8 encoded.
|
||||||
*/
|
*/
|
||||||
void drawString(XftDraw *d, int x, int y, const Color &color,
|
void drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
const std::string &string, bool utf8 = false) const;
|
const userstring &string) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ void Label::update(void)
|
||||||
const Font *ft = style()->getFont();
|
const Font *ft = style()->getFont();
|
||||||
unsigned int sidemargin = style()->getBevelWidth() * 2;
|
unsigned int sidemargin = style()->getBevelWidth() * 2;
|
||||||
|
|
||||||
std::string t = _text; // the actual text to draw
|
userstring t = _text; // the actual text to draw
|
||||||
int x = sidemargin; // x coord for the text
|
int x = sidemargin; // x coord for the text
|
||||||
|
|
||||||
// find a string that will fit inside the area for text
|
// find a string that will fit inside the area for text
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "widget.hh"
|
#include "widget.hh"
|
||||||
#include "font.hh"
|
#include "font.hh"
|
||||||
|
#include "userstring.hh"
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -14,8 +15,8 @@ public:
|
||||||
Label(Widget *parent);
|
Label(Widget *parent);
|
||||||
~Label();
|
~Label();
|
||||||
|
|
||||||
inline const std::string &getText(void) const { return _text; }
|
inline const userstring &getText(void) const { return _text; }
|
||||||
void setText(const std::string &text) { _text = text; _dirty = true; }
|
void setText(const userstring &text) { _text = text; _dirty = true; }
|
||||||
|
|
||||||
void update(void);
|
void update(void);
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ private:
|
||||||
//! Object used by Xft to render to the drawable
|
//! Object used by Xft to render to the drawable
|
||||||
XftDraw *_xftdraw;
|
XftDraw *_xftdraw;
|
||||||
//! Text displayed in the label
|
//! Text displayed in the label
|
||||||
std::string _text;
|
userstring _text;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ Property::~Property()
|
||||||
*/
|
*/
|
||||||
Atom Property::create(const char *name) const
|
Atom Property::create(const char *name) const
|
||||||
{
|
{
|
||||||
Atom a = XInternAtom(Display::display, name, False);
|
Atom a = XInternAtom(Display::display, name, false);
|
||||||
assert(a);
|
assert(a);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ void Property::set(Window win, Atoms atom, Atoms type,
|
||||||
assert(atom >= 0 && atom < NUM_ATOMS);
|
assert(atom >= 0 && atom < NUM_ATOMS);
|
||||||
assert(type >= 0 && type < NUM_ATOMS);
|
assert(type >= 0 && type < NUM_ATOMS);
|
||||||
set(win, _atoms[atom], _atoms[type],
|
set(win, _atoms[atom], _atoms[type],
|
||||||
reinterpret_cast<unsigned char*>(&value), 32, 1, False);
|
reinterpret_cast<unsigned char*>(&value), 32, 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ void Property::set(Window win, Atoms atom, Atoms type,
|
||||||
assert(atom >= 0 && atom < NUM_ATOMS);
|
assert(atom >= 0 && atom < NUM_ATOMS);
|
||||||
assert(type >= 0 && type < NUM_ATOMS);
|
assert(type >= 0 && type < NUM_ATOMS);
|
||||||
set(win, _atoms[atom], _atoms[type],
|
set(win, _atoms[atom], _atoms[type],
|
||||||
reinterpret_cast<unsigned char*>(value), 32, elements, False);
|
reinterpret_cast<unsigned char*>(value), 32, elements, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ void Property::set(Window win, Atoms atom, Atoms type,
|
||||||
* Set an string property value on a window.
|
* Set an string property value on a window.
|
||||||
*/
|
*/
|
||||||
void Property::set(Window win, Atoms atom, StringType type,
|
void Property::set(Window win, Atoms atom, StringType type,
|
||||||
const std::string &value) const
|
const userstring &value) const
|
||||||
{
|
{
|
||||||
assert(atom >= 0 && atom < NUM_ATOMS);
|
assert(atom >= 0 && atom < NUM_ATOMS);
|
||||||
assert(type >= 0 && type < NUM_STRING_TYPE);
|
assert(type >= 0 && type < NUM_STRING_TYPE);
|
||||||
|
@ -226,11 +226,11 @@ void Property::set(Window win, Atoms atom, StringType type,
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ascii: t = _atoms[Atom_String]; break;
|
case ascii: t = _atoms[Atom_String]; break;
|
||||||
case utf8: t = _atoms[Atom_Utf8]; 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,
|
set(win, _atoms[atom], t,
|
||||||
reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void Property::set(Window win, Atoms atom, StringType type,
|
||||||
* Set an array of string property values on a window.
|
* Set an array of string property values on a window.
|
||||||
*/
|
*/
|
||||||
void Property::set(Window win, Atoms atom, StringType type,
|
void Property::set(Window win, Atoms atom, StringType type,
|
||||||
const StringVect &strings) const
|
const userstring::vector &strings) const
|
||||||
{
|
{
|
||||||
assert(atom >= 0 && atom < NUM_ATOMS);
|
assert(atom >= 0 && atom < NUM_ATOMS);
|
||||||
assert(type >= 0 && type < NUM_STRING_TYPE);
|
assert(type >= 0 && type < NUM_STRING_TYPE);
|
||||||
|
@ -247,26 +247,26 @@ void Property::set(Window win, Atoms atom, StringType type,
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ascii: t = _atoms[Atom_String]; break;
|
case ascii: t = _atoms[Atom_String]; break;
|
||||||
case utf8: t = _atoms[Atom_Utf8]; break;
|
case utf8: t = _atoms[Atom_Utf8]; break;
|
||||||
default: assert(False); return; // unhandled StringType
|
default: assert(false); return; // unhandled StringType
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
StringVect::const_iterator it = strings.begin();
|
userstring::vector::const_iterator it = strings.begin();
|
||||||
const StringVect::const_iterator end = strings.end();
|
const userstring::vector::const_iterator end = strings.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
value += *it + '\0';
|
value += *it + '\0';
|
||||||
|
|
||||||
set(win, _atoms[atom], t,
|
set(win, _atoms[atom], t,
|
||||||
reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
|
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.
|
* Internal get function used by all of the typed get functions.
|
||||||
* Gets an property's value from a window.
|
* 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
|
* property did not exist on the window, or has a different type/size format
|
||||||
* than the user tried to retrieve.
|
* than the user tried to retrieve.
|
||||||
*/
|
*/
|
||||||
|
@ -283,11 +283,11 @@ bool Property::get(Window win, Atom atom, Atom type,
|
||||||
unsigned long ret_bytes;
|
unsigned long ret_bytes;
|
||||||
int result;
|
int result;
|
||||||
unsigned long maxread = *nelements;
|
unsigned long maxread = *nelements;
|
||||||
bool ret = False;
|
bool ret = false;
|
||||||
|
|
||||||
// try get the first element
|
// try get the first element
|
||||||
result = XGetWindowProperty(Display::display, win, atom, 0l, 1l,
|
result = XGetWindowProperty(Display::display, win, atom, 0l, 1l,
|
||||||
False, AnyPropertyType, &ret_type, &ret_size,
|
false, AnyPropertyType, &ret_type, &ret_size,
|
||||||
nelements, &ret_bytes, &c_val);
|
nelements, &ret_bytes, &c_val);
|
||||||
ret = (result == Success && ret_type == type && ret_size == size &&
|
ret = (result == Success && ret_type == type && ret_size == size &&
|
||||||
*nelements > 0);
|
*nelements > 0);
|
||||||
|
@ -305,7 +305,7 @@ bool Property::get(Window win, Atom atom, Atom type,
|
||||||
if (remain > size/8 * (signed)maxread) // dont get more than the max
|
if (remain > size/8 * (signed)maxread) // dont get more than the max
|
||||||
remain = size/8 * (signed)maxread;
|
remain = size/8 * (signed)maxread;
|
||||||
result = XGetWindowProperty(Display::display, win, atom, 0l,
|
result = XGetWindowProperty(Display::display, win, atom, 0l,
|
||||||
remain, False, type, &ret_type, &ret_size,
|
remain, false, type, &ret_type, &ret_size,
|
||||||
nelements, &ret_bytes, &c_val);
|
nelements, &ret_bytes, &c_val);
|
||||||
ret = (result == Success && ret_type == type && ret_size == size &&
|
ret = (result == Success && ret_type == type && ret_size == size &&
|
||||||
ret_bytes == 0);
|
ret_bytes == 0);
|
||||||
|
@ -352,10 +352,10 @@ bool Property::get(Window win, Atoms atom, Atoms type,
|
||||||
unsigned long num = 1;
|
unsigned long num = 1;
|
||||||
if (! get(win, _atoms[atom], _atoms[type], &num,
|
if (! get(win, _atoms[atom], _atoms[type], &num,
|
||||||
reinterpret_cast<unsigned char **>(&temp), 32))
|
reinterpret_cast<unsigned char **>(&temp), 32))
|
||||||
return False;
|
return false;
|
||||||
*value = temp[0];
|
*value = temp[0];
|
||||||
delete [] temp;
|
delete [] temp;
|
||||||
return True;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -363,20 +363,25 @@ bool Property::get(Window win, Atoms atom, Atoms type,
|
||||||
* Gets an string property's value from a window.
|
* Gets an string property's value from a window.
|
||||||
*/
|
*/
|
||||||
bool Property::get(Window win, Atoms atom, StringType type,
|
bool Property::get(Window win, Atoms atom, StringType type,
|
||||||
std::string *value) const
|
userstring *value) const
|
||||||
{
|
{
|
||||||
unsigned long n = 1;
|
unsigned long n = 1;
|
||||||
StringVect s;
|
userstring::vector s;
|
||||||
if (get(win, atom, type, &n, &s)) {
|
if (get(win, atom, type, &n, &s)) {
|
||||||
*value = s[0];
|
*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 Property::get(Window win, Atoms atom, StringType type,
|
bool Property::get(Window win, Atoms atom, StringType type,
|
||||||
unsigned long *nelements, StringVect *strings) const
|
unsigned long *nelements, userstring::vector *strings) const
|
||||||
{
|
{
|
||||||
assert(atom >= 0 && atom < NUM_ATOMS);
|
assert(atom >= 0 && atom < NUM_ATOMS);
|
||||||
assert(type >= 0 && type < NUM_STRING_TYPE);
|
assert(type >= 0 && type < NUM_STRING_TYPE);
|
||||||
|
@ -384,26 +389,27 @@ bool Property::get(Window win, Atoms atom, StringType type,
|
||||||
assert(*nelements > 0);
|
assert(*nelements > 0);
|
||||||
|
|
||||||
Atom t;
|
Atom t;
|
||||||
|
bool isutf8;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ascii: t = _atoms[Atom_String]; break;
|
case ascii: t = _atoms[Atom_String]; isutf8 = false; break;
|
||||||
case utf8: t = _atoms[Atom_Utf8]; break;
|
case utf8: t = _atoms[Atom_Utf8]; isutf8 = true; break;
|
||||||
default: assert(False); return False; // unhandled StringType
|
default: assert(false); return false; // unhandled StringType
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *value;
|
unsigned char *value;
|
||||||
unsigned long elements = (unsigned) -1;
|
unsigned long elements = (unsigned) -1;
|
||||||
if (!get(win, _atoms[atom], t, &elements, &value, 8) || elements < 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;
|
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;
|
unsigned long num = 0;
|
||||||
while(num < *nelements) {
|
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
|
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;
|
++num;
|
||||||
if (it == end) break;
|
if (it == end) break;
|
||||||
++it;
|
++it;
|
||||||
|
@ -412,7 +418,7 @@ bool Property::get(Window win, Atoms atom, StringType type,
|
||||||
|
|
||||||
*nelements = num;
|
*nelements = num;
|
||||||
|
|
||||||
return True;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
#include "userstring.hh"
|
||||||
#include "screeninfo.hh"
|
#include "screeninfo.hh"
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
@ -175,9 +175,6 @@ private:
|
||||||
int size) const;
|
int size) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! A list of strings
|
|
||||||
typedef std::vector<std::string> StringVect;
|
|
||||||
|
|
||||||
//! Constructs a new Atom object
|
//! Constructs a new Atom object
|
||||||
/*!
|
/*!
|
||||||
CAUTION: This constructor uses Display::display, so ensure that it is
|
CAUTION: This constructor uses Display::display, so ensure that it is
|
||||||
|
@ -220,7 +217,7 @@ public:
|
||||||
@param value The string to set the property to
|
@param value The string to set the property to
|
||||||
*/
|
*/
|
||||||
void set(Window win, Atoms atom, StringType type,
|
void set(Window win, Atoms atom, StringType type,
|
||||||
const std::string &value) const;
|
const userstring &value) const;
|
||||||
//! Sets a string-array property on a window to a new value
|
//! 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
|
@param win The window id of the window on which to set the property's value
|
||||||
|
@ -231,7 +228,7 @@ public:
|
||||||
@param strings A list of strings to set the property to
|
@param strings A list of strings to set the property to
|
||||||
*/
|
*/
|
||||||
void set(Window win, Atoms atom, StringType type,
|
void set(Window win, Atoms atom, StringType type,
|
||||||
const StringVect &strings) const;
|
const userstring::vector &strings) const;
|
||||||
|
|
||||||
//! Gets the value of a property on a window
|
//! Gets the value of a property on a window
|
||||||
/*!
|
/*!
|
||||||
|
@ -284,7 +281,7 @@ public:
|
||||||
@return true if retrieval of the specified property with the specified
|
@return true if retrieval of the specified property with the specified
|
||||||
type was successful; otherwise, false
|
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, userstring *value) const;
|
||||||
//! Gets strings from the value of a property on a window
|
//! 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
|
@param win The window id of the window to get the property value from
|
||||||
|
@ -303,7 +300,7 @@ public:
|
||||||
type was successful; otherwise, false
|
type was successful; otherwise, false
|
||||||
*/
|
*/
|
||||||
bool get(Window win, Atoms atom, StringType type,
|
bool get(Window win, Atoms atom, StringType type,
|
||||||
unsigned long *nelements, StringVect *strings) const;
|
unsigned long *nelements, userstring::vector *strings) const;
|
||||||
|
|
||||||
//! Removes a property from a window
|
//! Removes a property from a window
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -3,26 +3,102 @@
|
||||||
#define __userstring_hh
|
#define __userstring_hh
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <assert.h>
|
||||||
|
}
|
||||||
|
|
||||||
//! userstring is a std::string with an extra flag specifying if the string is
|
//! userstring is a std::string with an extra flag specifying if the string is
|
||||||
//! UTF-8 encoded.
|
//! UTF-8 encoded.
|
||||||
class userstring : public std::string
|
class userstring : public std::string
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
//! A vector of userstrings
|
||||||
|
typedef std::vector<userstring> vector;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _utf8;
|
bool _utf8;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
userstring(bool utf8) : std::string(), _utf8(utf8) {}
|
userstring(bool utf8) : std::string(), _utf8(utf8) {}
|
||||||
userstring(const userstring& s, bool utf8, size_type pos = 0,
|
userstring(const userstring& s, size_type pos = 0,
|
||||||
size_type n = npos) : std::string(s, pos, n), _utf8(utf8) {}
|
size_type n = npos) : std::string(s, pos, n), _utf8(s._utf8) {}
|
||||||
userstring(const charT *s, bool utf8) : std::string(s), _utf8(utf8) {}
|
userstring(const char *s, bool utf8) : std::string(s), _utf8(utf8) {}
|
||||||
userstring(const charT* s, size_type n, bool utf8) : std::string(s, n),
|
userstring(const char *s, size_type n, bool utf8) : std::string(s, n),
|
||||||
_utf8(utf8) {}
|
_utf8(utf8) {}
|
||||||
userstring(size_type n, charT c, bool utf8) : std::string(n, c),
|
userstring(size_type n, char c, bool utf8) : std::string(n, c),
|
||||||
_utf8(utf8) {}
|
_utf8(utf8) {}
|
||||||
|
userstring(const_iterator first, const_iterator last, bool utf8) :
|
||||||
|
std::string(first, last), _utf8(utf8) {}
|
||||||
|
|
||||||
//! Returns if the string is encoded in UTF-8 or not
|
//! Returns if the string is encoded in UTF-8 or not
|
||||||
inline bool utf8() const { return _utf8; }
|
inline bool utf8() const { return _utf8; }
|
||||||
|
|
||||||
|
inline void setUtf8(bool u) { _utf8 = u; }
|
||||||
|
|
||||||
|
inline userstring& insert(size_type pos, const userstring& s) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::insert(pos, s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& insert(size_type pos,
|
||||||
|
const userstring& s,
|
||||||
|
size_type pos1, size_type n) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::insert(pos, s, pos1, n);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& append(const userstring& s) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::append(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& append(const userstring& s,
|
||||||
|
size_type pos, size_type n) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::append(s, pos, n);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& assign(const userstring& s) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::assign(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& assign(const userstring& s,
|
||||||
|
size_type pos, size_type n) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::assign(s, pos, n);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& replace(size_type pos, size_type n,
|
||||||
|
const userstring& s) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::replace(pos, n, s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& replace(size_type pos, size_type n,
|
||||||
|
const userstring& s,
|
||||||
|
size_type pos1, size_type n1) {
|
||||||
|
assert(s._utf8 == _utf8);
|
||||||
|
std::string::replace(pos, n, s, pos1, n1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& operator=(const userstring& s) {
|
||||||
|
return assign(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline userstring& operator+=(const userstring& s) {
|
||||||
|
return append(s);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __userstring_hh
|
#endif // __userstring_hh
|
||||||
|
|
Loading…
Reference in a new issue