replaced LinkedList with stl container and fixed multibyte

This commit is contained in:
fluxgen 2002-02-04 22:43:15 +00:00
parent cdc6210bfe
commit 936e16583d
2 changed files with 60 additions and 59 deletions

View file

@ -19,16 +19,18 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: IconBar.cc,v 1.8 2002/01/20 02:10:37 fluxgen Exp $ // $Id: IconBar.cc,v 1.9 2002/02/04 22:43:15 fluxgen Exp $
#include "IconBar.hh" #include "IconBar.hh"
#include "i18n.hh" #include "i18n.hh"
#include "Screen.hh" #include "Screen.hh"
#include <algorithm>
IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin)
{ {
m_fluxboxwin = fluxboxwin; m_fluxboxwin = fluxboxwin;
m_iconwin = iconwin; m_iconwin = iconwin;
} }
IconBarObj::~IconBarObj() { IconBarObj::~IconBarObj() {
@ -39,12 +41,10 @@ IconBar::IconBar(BScreen *scrn, Window parent):
m_screen(scrn), m_screen(scrn),
m_parent(parent) m_parent(parent)
{ {
m_iconlist = new IconList;
m_display = scrn->getBaseDisplay()->getXDisplay(); m_display = scrn->getBaseDisplay()->getXDisplay();
} }
IconBar::~IconBar() { IconBar::~IconBar() {
delete m_iconlist;
} }
//------------ addIcon ----------------------- //------------ addIcon -----------------------
@ -57,7 +57,7 @@ Window IconBar::addIcon(FluxboxWindow *fluxboxwin) {
Window iconwin = createIconWindow(fluxboxwin, m_parent); Window iconwin = createIconWindow(fluxboxwin, m_parent);
decorate(iconwin); decorate(iconwin);
//add window object to list //add window object to list
m_iconlist->insert(new IconBarObj(fluxboxwin, iconwin)); m_iconlist.push_back(new IconBarObj(fluxboxwin, iconwin));
//reposition all icons to fit windowbar //reposition all icons to fit windowbar
repositionIcons(); repositionIcons();
@ -77,12 +77,16 @@ Window IconBar::delIcon(FluxboxWindow *fluxboxwin) {
Window retwin = None; Window retwin = None;
IconBarObj *obj = findIcon(fluxboxwin); IconBarObj *obj = findIcon(fluxboxwin);
if (obj) { if (obj) {
m_iconlist->remove(obj); IconList::iterator it =
std::find(m_iconlist.begin(), m_iconlist.end(), obj);
if (it != m_iconlist.end()) {
m_iconlist.erase(it);
retwin = obj->getIconWin(); retwin = obj->getIconWin();
delete obj; delete obj;
XDestroyWindow(m_display, retwin); XDestroyWindow(m_display, retwin);
repositionIcons(); repositionIcons();
} }
}
return retwin; return retwin;
} }
@ -95,25 +99,19 @@ void IconBar::loadTheme(unsigned int width, unsigned int height) {
Pixmap tmp = m_focus_pm; Pixmap tmp = m_focus_pm;
BTexture *texture = &(m_screen->getWindowStyle()->tab.l_focus); BTexture *texture = &(m_screen->getWindowStyle()->tab.l_focus);
//If we are working on a PARENTRELATIVE, change to right focus value
if (texture->getTexture() & BImage::PARENTRELATIVE ) { if (texture->getTexture() & BImage::PARENTRELATIVE ) {
texture = &(m_screen->getWindowStyle()->tab.t_focus);
BTexture *pt = &(m_screen->getWindowStyle()->tab.t_focus); }
if (pt->getTexture() == (BImage::FLAT | BImage::SOLID)) {
m_focus_pm = None;
m_focus_pixel = pt->getColor()->getPixel();
} else
m_focus_pm =
image_ctrl->renderImage(width, height, pt);
} else {
if (texture->getTexture() == (BImage::FLAT | BImage::SOLID)) { if (texture->getTexture() == (BImage::FLAT | BImage::SOLID)) {
m_focus_pm = None; m_focus_pm = None;
m_focus_pixel = texture->getColor()->getPixel(); m_focus_pixel = texture->getColor()->getPixel();
} else } else {
m_focus_pm = m_focus_pm =
image_ctrl->renderImage(width, height, texture); image_ctrl->renderImage(width, height, texture);
} }
if (tmp) image_ctrl->removeImage(tmp); if (tmp) image_ctrl->removeImage(tmp);
} }
@ -146,10 +144,11 @@ void IconBar::reconfigure() {
//---------------------------------------- //----------------------------------------
void IconBar::exposeEvent(XExposeEvent *ee) { void IconBar::exposeEvent(XExposeEvent *ee) {
IconBarObj *obj=0; IconBarObj *obj=0;
IconListIterator it(m_iconlist); IconList::iterator it = m_iconlist.begin();
for (; it.current(); it++) { IconList::iterator it_end = m_iconlist.end();
if (it.current()->getIconWin() == ee->window) { for (; it != it_end; ++it) {
obj = it.current(); if ((*it)->getIconWin() == ee->window) {
obj = (*it);
break; break;
} }
} }
@ -164,7 +163,7 @@ void IconBar::exposeEvent(XExposeEvent *ee) {
&border_width, &depth); &border_width, &depth);
//max width on every icon //max width on every icon
unsigned int icon_width = width / m_iconlist->count(); unsigned int icon_width = width / m_iconlist.size();
//load right size of theme //load right size of theme
loadTheme(icon_width, height); loadTheme(icon_width, height);
@ -178,7 +177,7 @@ void IconBar::exposeEvent(XExposeEvent *ee) {
// Calculates and moves/resizes the icons // Calculates and moves/resizes the icons
//----------------------------------------- //-----------------------------------------
void IconBar::repositionIcons(void) { void IconBar::repositionIcons(void) {
if (!m_iconlist->count()) if (m_iconlist.size() == 0)
return; return;
Window root; Window root;
@ -189,19 +188,19 @@ void IconBar::repositionIcons(void) {
&border_width, &depth); &border_width, &depth);
//max width on every icon //max width on every icon
unsigned int icon_width = width / m_iconlist->count(); unsigned int icon_width = width / m_iconlist.size();
//load right size of theme //load right size of theme
loadTheme(icon_width, height); loadTheme(icon_width, height);
IconListIterator it(m_iconlist); IconList::iterator it = m_iconlist.begin();
IconList::iterator it_end = m_iconlist.end();
for (x = 0; it.current(); it++, x+=icon_width) { for (x = 0; it != it_end; ++it, x += icon_width) {
Window iconwin = it.current()->getIconWin(); Window iconwin = (*it)->getIconWin();
XMoveResizeWindow(m_display, iconwin, XMoveResizeWindow(m_display, iconwin,
x, 0, x, 0,
icon_width, height); icon_width, height);
draw(it.current(), icon_width); draw((*it), icon_width);
decorate(iconwin); decorate(iconwin);
} }
@ -244,7 +243,9 @@ void IconBar::draw(IconBarObj *obj, int width) {
unsigned int title_len = strlen(title); unsigned int title_len = strlen(title);
unsigned int title_text_w; unsigned int title_text_w;
if (I18n::instance()->multibyte()) { const int multibyte = I18n::instance()->multibyte();
if (multibyte) {
XRectangle ink, logical; XRectangle ink, logical;
XmbTextExtents(m_screen->getWindowStyle()->font.set, XmbTextExtents(m_screen->getWindowStyle()->font.set,
title, title_len, &ink, &logical); title, title_len, &ink, &logical);
@ -260,7 +261,7 @@ void IconBar::draw(IconBarObj *obj, int width) {
int dx=bevel_w*2; int dx=bevel_w*2;
for (; dlen >= 0; dlen--) { for (; dlen >= 0; dlen--) {
if (I18n::instance()->multibyte()) { if (multibyte) {
XRectangle ink, logical; XRectangle ink, logical;
XmbTextExtents(m_screen->getWindowStyle()->tab.font.set, XmbTextExtents(m_screen->getWindowStyle()->tab.font.set,
title, dlen, title, dlen,
@ -290,7 +291,7 @@ void IconBar::draw(IconBarObj *obj, int width) {
XClearWindow(m_display, iconwin); XClearWindow(m_display, iconwin);
if (I18n::instance()->multibyte()) { if (multibyte) {
XmbDrawString(m_display, iconwin, XmbDrawString(m_display, iconwin,
m_screen->getWindowStyle()->tab.font.set, m_screen->getWindowStyle()->tab.font.set,
m_screen->getWindowStyle()->tab.l_text_focus_gc, dx, m_screen->getWindowStyle()->tab.l_text_focus_gc, dx,
@ -313,10 +314,10 @@ void IconBar::draw(IconBarObj *obj, int width) {
//---------------------------------- //----------------------------------
FluxboxWindow *IconBar::findWindow(Window w) { FluxboxWindow *IconBar::findWindow(Window w) {
IconListIterator it(m_iconlist); IconList::iterator it = m_iconlist.begin();
IconList::iterator it_end = m_iconlist.end();
for (; it.current(); it++) { for (; it != it_end; ++it) {
IconBarObj *tmp = it.current(); IconBarObj *tmp = (*it);
if (tmp) if (tmp)
if (tmp->getIconWin() == w) if (tmp->getIconWin() == w)
return tmp->getFluxboxWin(); return tmp->getFluxboxWin();
@ -333,10 +334,10 @@ FluxboxWindow *IconBar::findWindow(Window w) {
IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) {
IconListIterator it(m_iconlist); IconList::iterator it = m_iconlist.begin();
IconList::iterator it_end = m_iconlist.end();
for (; it.current(); it++) { for (; it != it_end; ++it) {
IconBarObj *tmp = it.current(); IconBarObj *tmp = (*it);
if (tmp) if (tmp)
if (tmp->getFluxboxWin() == fluxboxwin) if (tmp->getFluxboxWin() == fluxboxwin)
return tmp; return tmp;

View file

@ -19,14 +19,15 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: IconBar.hh,v 1.4 2002/01/09 14:11:20 fluxgen Exp $ // $Id: IconBar.hh,v 1.5 2002/02/04 22:43:15 fluxgen Exp $
#ifndef _ICONBAR_HH_ #ifndef _ICONBAR_HH_
#define _ICONBAR_HH_ #define _ICONBAR_HH_
#include <vector> #include <vector>
#include "Window.hh" #include "Window.hh"
#include "LinkedList.hh"
#include <list>
class IconBarObj class IconBarObj
{ {
@ -57,8 +58,7 @@ public:
void draw(IconBarObj *obj, int width); void draw(IconBarObj *obj, int width);
private: private:
typedef LinkedList<IconBarObj> IconList; typedef std::list<IconBarObj *> IconList;
typedef LinkedListIterator<IconBarObj> IconListIterator;
// void draw(IconBarObj *obj, int width); // void draw(IconBarObj *obj, int width);
void loadTheme(unsigned int width, unsigned int height); void loadTheme(unsigned int width, unsigned int height);
@ -69,7 +69,7 @@ private:
BScreen *m_screen; BScreen *m_screen;
Display *m_display; Display *m_display;
Window m_parent; Window m_parent;
IconList *m_iconlist; IconList m_iconlist;
Pixmap m_focus_pm; Pixmap m_focus_pm;
unsigned long m_focus_pixel; unsigned long m_focus_pixel;
}; };