From ef02a0c8ae65f169157c90064a335303e964a4c1 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 13 Jan 2003 05:54:40 +0000 Subject: [PATCH] almost done the ustring conversion --- otk/otk.hh | 1 + otk/otk.i | 1 + otk/property.cc | 2 +- otk/ustring.cc | 5 ++++ otk/ustring.hh | 3 +- src/client.cc | 6 ++-- src/client.hh | 9 +++--- src/frame.cc | 4 +-- src/frame.hh | 3 +- src/labelwidget.cc | 4 +-- src/labelwidget.hh | 7 +++-- src/openbox.i | 2 ++ src/openbox_wrap.cc | 72 +++++++++++++++++++++++---------------------- src/python.cc | 4 +-- src/python.hh | 5 ++-- src/screen.cc | 8 ++--- src/screen.hh | 3 +- 17 files changed, 78 insertions(+), 61 deletions(-) diff --git a/otk/otk.hh b/otk/otk.hh index b6e24a75..b06afcbf 100644 --- a/otk/otk.hh +++ b/otk/otk.hh @@ -29,6 +29,7 @@ #include "timerqueue.hh" #include "timerqueuemanager.hh" #include "util.hh" +#include "ustring.hh" #include "widget.hh" #endif // __otk_hh diff --git a/otk/otk.i b/otk/otk.i index 148ff0c2..d0e4331d 100644 --- a/otk/otk.i +++ b/otk/otk.i @@ -12,6 +12,7 @@ %include "stl.i" //%include std_list.i +%include "ustring.i" %ignore otk::OBDisplay::display; %inline %{ diff --git a/otk/property.cc b/otk/property.cc index 232803cd..ab99cd89 100644 --- a/otk/property.cc +++ b/otk/property.cc @@ -382,7 +382,7 @@ 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, StringVect *strings) const { assert(atom >= 0 && atom < NUM_ATOMS); assert(type >= 0 && type < NUM_STRING_TYPE); diff --git a/otk/ustring.cc b/otk/ustring.cc index 8f3cdfc4..c15effb0 100644 --- a/otk/ustring.cc +++ b/otk/ustring.cc @@ -142,6 +142,11 @@ ustring::size_type ustring::max_size() const return _string.max_size(); } +bool ustring::empty() const +{ + return _string.empty(); +} + void ustring::clear() { _string.erase(); diff --git a/otk/ustring.hh b/otk/ustring.hh index ef94440c..647bee86 100644 --- a/otk/ustring.hh +++ b/otk/ustring.hh @@ -152,7 +152,7 @@ public: ustring(const ustring& other); ustring& operator=(const ustring& other); ustring(const std::string& src); - ustring::ustring(const char* src); + ustring(const char* src); // append to the string @@ -166,6 +166,7 @@ public: ustring::size_type bytes() const; ustring::size_type capacity() const; ustring::size_type max_size() const; + bool empty() const; // erase substrings diff --git a/src/client.cc b/src/client.cc index 0fc485c8..cdef1f94 100644 --- a/src/client.cc +++ b/src/client.cc @@ -531,15 +531,15 @@ void Client::updateClass() if (property->get(_window, otk::Property::wm_class, otk::Property::ascii, &num, &v)) { - if (num > 0) _app_name = v[0]; - if (num > 1) _app_class = v[1]; + if (num > 0) _app_name = v[0].c_str(); + if (num > 1) _app_class = v[1].c_str(); } v.clear(); num = 1; if (property->get(_window, otk::Property::wm_window_role, otk::Property::ascii, &num, &v)) { - if (num > 0) _role = v[0]; + if (num > 0) _role = v[0].c_str(); } } diff --git a/src/client.hh b/src/client.hh index 14b5a45e..9bac56f5 100644 --- a/src/client.hh +++ b/src/client.hh @@ -12,6 +12,7 @@ #include "otk/strut.hh" #include "otk/rect.hh" #include "otk/eventhandler.hh" +#include "otk/ustring.hh" extern "C" { #include @@ -182,9 +183,9 @@ private: long _desktop; //! Normal window title - std::string _title; // XXX: Have to keep track if this string is Utf8 or not + otk::ustring _title; //! Window title when iconifiged - std::string _icon_title; + otk::ustring _icon_title; //! The application that created the window std::string _app_name; @@ -412,9 +413,9 @@ BB @param window The window id that the Client class should handle */ inline long desktop() const { return _desktop; } //! Returns the window's title - inline const std::string &title() const { return _title; } + inline const otk::ustring &title() const { return _title; } //! Returns the window's title when it is iconified - inline const std::string &iconTitle() const { return _title; } + inline const otk::ustring &iconTitle() const { return _title; } //! Returns the application's name to whom the window belongs inline const std::string &appName() const { return _app_name; } //! Returns the class of the window diff --git a/src/frame.cc b/src/frame.cc index 12a42ec2..a2a6cc07 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -64,7 +64,7 @@ Frame::~Frame() } -void Frame::setTitle(const std::string &text) +void Frame::setTitle(const otk::ustring &text) { _label.setText(text); _label.update(); @@ -172,7 +172,7 @@ void Frame::adjustSize() // separation between titlebar elements const int sep = bevel + 1; - std::string layout; + otk::ustring layout; if (!python_get_string("titlebar_layout", &layout)) layout = "ILMC"; diff --git a/src/frame.hh b/src/frame.hh index 0a22cbaa..7831284e 100644 --- a/src/frame.hh +++ b/src/frame.hh @@ -18,6 +18,7 @@ extern "C" { #include "otk/screeninfo.hh" #include "otk/style.hh" #include "otk/widget.hh" +#include "otk/ustring.hh" #include @@ -88,7 +89,7 @@ public: //! Displays unfocused decorations virtual void unfocus(); - void setTitle(const std::string &text); + void setTitle(const otk::ustring &text); //! Reparents the client window from the root window onto the frame void grabClient(); diff --git a/src/labelwidget.cc b/src/labelwidget.cc index 445ae260..16c8eae2 100644 --- a/src/labelwidget.cc +++ b/src/labelwidget.cc @@ -26,7 +26,7 @@ LabelWidget::~LabelWidget() } -void LabelWidget::setText(const std::string &text) +void LabelWidget::setText(const otk::ustring &text) { _text = text; _dirty = true; @@ -77,7 +77,7 @@ void LabelWidget::update() otk::Widget::update(); if (draw) { - std::string t = _text; + otk::ustring t = _text; int x = _sidemargin; // x coord for the text // find a string that will fit inside the area for text diff --git a/src/labelwidget.hh b/src/labelwidget.hh index 92c35c3c..094cf868 100644 --- a/src/labelwidget.hh +++ b/src/labelwidget.hh @@ -6,6 +6,7 @@ #include "otk/widget.hh" #include "otk/font.hh" #include "otk/style.hh" +#include "otk/ustring.hh" namespace ob { @@ -17,7 +18,7 @@ private: otk::Color *_text_color; int _sidemargin; otk::Style::TextJustify _justify; - std::string _text; + otk::ustring _text; //! Object used by Xft to render to the drawable XftDraw *_xftdraw; @@ -34,8 +35,8 @@ public: virtual void update(); - inline const std::string &text() const { return _text; } - void setText(const std::string &text); + inline const otk::ustring &text() const { return _text; } + void setText(const otk::ustring &text); }; } diff --git a/src/openbox.i b/src/openbox.i index edc29ae8..6f768502 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -112,6 +112,8 @@ void python_callback(PyObject *func, KeyData *data) Display *Display_display() { return otk::Display::display; } %}; +%include "../otk/ustring.i" + %include "../otk/display.hh" %include "../otk/point.hh" %include "../otk/property.hh" diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 533b0046..e26d59e1 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -676,8 +676,8 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) { #define SWIGTYPE_p_XConfigureEvent swig_types[28] #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_ustring swig_types[32] +#define SWIGTYPE_p_otk__ustring swig_types[31] +#define SWIGTYPE_p_std__string 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] @@ -885,6 +885,9 @@ void python_callback(PyObject *func, KeyData *data) Display *Display_display() { return otk::Display::display; } + +#include "ustring.hh" + ob::Client *ob_Screen_client(ob::Screen *self,int i){ if (i >= (int)self->clients.size()) return NULL; @@ -1506,7 +1509,8 @@ static PyObject *_wrap_Property_set__SWIG_2(PyObject *self, PyObject *args) { Window arg2 ; int arg3 ; int arg4 ; - ustring *arg5 = 0 ; + otk::ustring *arg5 = 0 ; + otk::ustring temp5 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj4 = 0 ; @@ -1515,11 +1519,15 @@ 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 ((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; + { + if (PyString_Check(obj4)) { + temp5 = otk::ustring(PyString_AsString(obj4)); + arg5 = &temp5; + }else { + SWIG_exception(SWIG_TypeError, "ustring expected"); + } } - ((otk::Property const *)arg1)->set(arg2,(otk::Property::Atoms )arg3,(otk::Property::StringType )arg4,(ustring const &)*arg5); + ((otk::Property const *)arg1)->set(arg2,(otk::Property::Atoms )arg3,(otk::Property::StringType )arg4,(otk::ustring const &)*arg5); Py_INCREF(Py_None); resultobj = Py_None; return resultobj; @@ -1591,7 +1599,7 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) { if (_v) { { void *ptr; - if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_ustring, 0) == -1) { + if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_otk__Property__StringVect, 0) == -1) { _v = 0; PyErr_Clear(); }else { @@ -1599,7 +1607,7 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) { } } if (_v) { - return _wrap_Property_set__SWIG_2(self,args); + return _wrap_Property_set__SWIG_3(self,args); } } } @@ -1631,16 +1639,10 @@ 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) { - _v = 0; - PyErr_Clear(); - }else { - _v = 1; - } + _v = (PyInt_Check(argv[4]) || PyLong_Check(argv[4])) ? 1 : 0; } if (_v) { - return _wrap_Property_set__SWIG_3(self,args); + return _wrap_Property_set__SWIG_0(self,args); } } } @@ -1672,10 +1674,10 @@ static PyObject *_wrap_Property_set(PyObject *self, PyObject *args) { } if (_v) { { - _v = (PyInt_Check(argv[4]) || PyLong_Check(argv[4])) ? 1 : 0; + _v = PyString_Check(argv[4]) ? 1 : 0; } if (_v) { - return _wrap_Property_set__SWIG_0(self,args); + return _wrap_Property_set__SWIG_2(self,args); } } } @@ -1795,7 +1797,7 @@ static PyObject *_wrap_Property_get__SWIG_2(PyObject *self, PyObject *args) { Window arg2 ; int arg3 ; int arg4 ; - std::string *arg5 = (std::string *) 0 ; + otk::ustring *arg5 = (otk::ustring *) 0 ; bool result; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; @@ -1805,7 +1807,7 @@ static PyObject *_wrap_Property_get__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 ((SWIG_ConvertPtr(obj4,(void **) &arg5, SWIGTYPE_p_std__string,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + if ((SWIG_ConvertPtr(obj4,(void **) &arg5, SWIGTYPE_p_otk__ustring,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; result = (bool)((otk::Property const *)arg1)->get(arg2,(otk::Property::Atoms )arg3,(otk::Property::StringType )arg4,arg5); resultobj = PyInt_FromLong((long)result); @@ -1920,7 +1922,7 @@ static PyObject *_wrap_Property_get(PyObject *self, PyObject *args) { if (_v) { { void *ptr; - if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_std__string, 0) == -1) { + if (SWIG_ConvertPtr(argv[4], (void **) &ptr, SWIGTYPE_p_otk__ustring, 0) == -1) { _v = 0; PyErr_Clear(); }else { @@ -5596,8 +5598,8 @@ static PyObject *_wrap_Screen_setDesktopName(PyObject *self, PyObject *args) { PyObject *resultobj; ob::Screen *arg1 = (ob::Screen *) 0 ; long arg2 ; - std::string *arg3 = 0 ; - std::string temp3 ; + otk::ustring *arg3 = 0 ; + otk::ustring temp3 ; PyObject * obj0 = 0 ; PyObject * obj2 = 0 ; @@ -5605,13 +5607,13 @@ static PyObject *_wrap_Screen_setDesktopName(PyObject *self, PyObject *args) { if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Screen,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; { if (PyString_Check(obj2)) { - temp3 = std::string(PyString_AsString(obj2)); + temp3 = otk::ustring(PyString_AsString(obj2)); arg3 = &temp3; }else { - SWIG_exception(SWIG_TypeError, "string expected"); + SWIG_exception(SWIG_TypeError, "ustring expected"); } } - (arg1)->setDesktopName(arg2,(std::string const &)*arg3); + (arg1)->setDesktopName(arg2,(otk::ustring const &)*arg3); Py_INCREF(Py_None); resultobj = Py_None; return resultobj; @@ -5969,14 +5971,14 @@ static PyObject *_wrap_Client_desktop(PyObject *self, PyObject *args) { static PyObject *_wrap_Client_title(PyObject *self, PyObject *args) { PyObject *resultobj; ob::Client *arg1 = (ob::Client *) 0 ; - std::string *result; + otk::ustring *result; PyObject * obj0 = 0 ; if(!PyArg_ParseTuple(args,(char *)"O:Client_title",&obj0)) goto fail; if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Client,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; { - std::string const &_result_ref = ((ob::Client const *)arg1)->title(); - result = (std::string *) &_result_ref; + otk::ustring const &_result_ref = ((ob::Client const *)arg1)->title(); + result = (otk::ustring *) &_result_ref; } { @@ -5991,14 +5993,14 @@ static PyObject *_wrap_Client_title(PyObject *self, PyObject *args) { static PyObject *_wrap_Client_iconTitle(PyObject *self, PyObject *args) { PyObject *resultobj; ob::Client *arg1 = (ob::Client *) 0 ; - std::string *result; + otk::ustring *result; PyObject * obj0 = 0 ; if(!PyArg_ParseTuple(args,(char *)"O:Client_iconTitle",&obj0)) goto fail; if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Client,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; { - std::string const &_result_ref = ((ob::Client const *)arg1)->iconTitle(); - result = (std::string *) &_result_ref; + otk::ustring const &_result_ref = ((ob::Client const *)arg1)->iconTitle(); + result = (otk::ustring *) &_result_ref; } { @@ -8252,8 +8254,8 @@ static swig_type_info _swigt__p_ob__KeyData[] = {{"_p_ob__KeyData", 0, "ob::KeyD static swig_type_info _swigt__p_XConfigureEvent[] = {{"_p_XConfigureEvent", 0, "XConfigureEvent *", 0},{"_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_otk__ustring[] = {{"_p_otk__ustring", 0, "otk::ustring *", 0},{"_p_otk__ustring"},{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}}; @@ -8316,8 +8318,8 @@ _swigt__p_ob__KeyData, _swigt__p_XConfigureEvent, _swigt__p_XCirculateEvent, _swigt__p_XRectangle, +_swigt__p_otk__ustring, _swigt__p_std__string, -_swigt__p_ustring, _swigt__p_XCrossingEvent, _swigt__p_Display, _swigt__p_otk__Display, diff --git a/src/python.cc b/src/python.cc index a9a457f8..f6ed7a7e 100644 --- a/src/python.cc +++ b/src/python.cc @@ -66,7 +66,7 @@ bool python_get_long(const char *name, long *value) return true; } -bool python_get_string(const char *name, std::string *value) +bool python_get_string(const char *name, otk::ustring *value) { PyObject *val = PyDict_GetItemString(obdict, const_cast(name)); if (!(val && PyString_Check(val))) return false; @@ -75,7 +75,7 @@ bool python_get_string(const char *name, std::string *value) return true; } -bool python_get_stringlist(const char *name, std::vector *value) +bool python_get_stringlist(const char *name, std::vector *value) { PyObject *val = PyDict_GetItemString(obdict, const_cast(name)); if (!(val && PyList_Check(val))) return false; diff --git a/src/python.hh b/src/python.hh index 8b41f00b..c346f928 100644 --- a/src/python.hh +++ b/src/python.hh @@ -10,6 +10,7 @@ #include "otk/rect.hh" #include "otk/property.hh" #include "otk/display.hh" +#include "otk/ustring.hh" extern "C" { #include @@ -165,8 +166,8 @@ void python_destroy(); bool python_exec(const std::string &path); bool python_get_long(const char *name, long *value); -bool python_get_string(const char *name, std::string *value); -bool python_get_stringlist(const char *name, std::vector *value); +bool python_get_string(const char *name, otk::ustring *value); +bool python_get_stringlist(const char *name, std::vector *value); /*********************************************** * These are found in openbox.i, not python.cc * diff --git a/src/screen.cc b/src/screen.cc index 763931f8..c211df12 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -82,10 +82,10 @@ Screen::Screen(int screen) // initialize the screen's style _style.setImageControl(_image_control); - std::string stylepath; + otk::ustring stylepath; python_get_string("theme", &stylepath); otk::Configuration sconfig(false); - sconfig.setFile(otk::expandTilde(stylepath)); + sconfig.setFile(otk::expandTilde(stylepath.c_str())); if (!sconfig.load()) { sconfig.setFile(otk::expandTilde(DEFAULTSTYLE)); if (!sconfig.load()) { @@ -107,7 +107,7 @@ Screen::Screen(int screen) geometry, 2); // Set the net_desktop_names property - std::vector names; + std::vector names; python_get_stringlist("desktop_names", &names); Openbox::instance->property()->set(_info->rootWindow(), otk::Property::net_desktop_names, @@ -710,7 +710,7 @@ void Screen::updateDesktopNames() } -void Screen::setDesktopName(long i, const std::string &name) +void Screen::setDesktopName(long i, const otk::ustring &name) { assert(i >= 0); diff --git a/src/screen.hh b/src/screen.hh index 8904c2a7..c3af7b6c 100644 --- a/src/screen.hh +++ b/src/screen.hh @@ -19,6 +19,7 @@ extern "C" { #include "otk/screeninfo.hh" #include "otk/eventhandler.hh" #include "otk/property.hh" +#include "otk/ustring.hh" #include #include @@ -191,7 +192,7 @@ public: @param name The name to set for the desktop If the index is too large, it is simply ignored. */ - void setDesktopName(long i, const std::string &name); + void setDesktopName(long i, const otk::ustring &name); virtual void propertyHandler(const XPropertyEvent &e); virtual void clientMessageHandler(const XClientMessageEvent &e); -- 2.44.0