From 3e972e83bd2716f7e5941f4ef8edcb67f4f2a3b5 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 15 Oct 2002 17:17:00 +0000 Subject: using new font system for labelstyle, windowstyle --- src/IconBar.cc | 30 ++++++++++++----- src/Screen.cc | 39 +++++++++++++++++----- src/Theme.cc | 101 ++++++++++++++------------------------------------------- src/Theme.hh | 10 +++--- src/Window.cc | 50 +++++++++------------------- 5 files changed, 98 insertions(+), 132 deletions(-) diff --git a/src/IconBar.cc b/src/IconBar.cc index 3ed4f54..3d2919d 100644 --- a/src/IconBar.cc +++ b/src/IconBar.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconBar.cc,v 1.15 2002/08/04 15:23:24 fluxgen Exp $ +// $Id: IconBar.cc,v 1.16 2002/10/15 17:10:48 fluxgen Exp $ #include "IconBar.hh" #include "i18n.hh" @@ -261,9 +261,9 @@ void IconBar::draw(IconBarObj *obj, int width) { FluxboxWindow *fluxboxwin = obj->getFluxboxWin(); Window iconwin = obj->getIconWin(); unsigned int title_text_w; - + /* const int multibyte = I18n::instance()->multibyte(); - + if (multibyte) { XRectangle ink, logical; XmbTextExtents(m_screen->getWindowStyle()->font.set, @@ -273,14 +273,16 @@ void IconBar::draw(IconBarObj *obj, int width) { title_text_w = XTextWidth(m_screen->getWindowStyle()->font.fontstruct, fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size()); } - + */ + title_text_w = m_screen->getWindowStyle()->font.textWidth( + fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size()); int l = title_text_w; unsigned int dlen=fluxboxwin->getIconTitle().size(); unsigned int bevel_w = m_screen->getBevelWidth(); int dx=bevel_w*2; for (; dlen >= 0; dlen--) { - if (multibyte) { + /*if (multibyte) { XRectangle ink, logical; XmbTextExtents(m_screen->getWindowStyle()->tab.font.set, fluxboxwin->getIconTitle().c_str(), dlen, @@ -289,13 +291,16 @@ void IconBar::draw(IconBarObj *obj, int width) { } else l = XTextWidth(m_screen->getWindowStyle()->tab.font.fontstruct, fluxboxwin->getIconTitle().c_str(), dlen); - l += (bevel_w * 4); - + */ + l = m_screen->getWindowStyle()->tab.font.textWidth( + fluxboxwin->getIconTitle().c_str(), dlen); + l += (bevel_w * 4); + if (l < width) break; } - switch (m_screen->getWindowStyle()->tab.font.justify) { + switch (m_screen->getWindowStyle()->tab.justify) { case DrawUtil::Font::RIGHT: dx += width - l; break; @@ -309,7 +314,7 @@ void IconBar::draw(IconBarObj *obj, int width) { //Draw title to m_iconwin XClearWindow(m_display, iconwin); - + /* if (multibyte) { XmbDrawString(m_display, iconwin, m_screen->getWindowStyle()->tab.font.set, @@ -322,6 +327,13 @@ void IconBar::draw(IconBarObj *obj, int width) { m_screen->getWindowStyle()->tab.font.fontstruct->ascent + 1, fluxboxwin->getIconTitle().c_str(), dlen); } + */ + m_screen->getWindowStyle()->tab.font.drawText( + iconwin, + m_screen->getScreenNumber(), + m_screen->getWindowStyle()->tab.l_text_focus_gc, + fluxboxwin->getIconTitle().c_str(), dlen, + dx, m_screen->getWindowStyle()->tab.font.height()); } diff --git a/src/Screen.cc b/src/Screen.cc index f70e6e9..4159141 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Screen.cc,v 1.73 2002/10/15 13:05:55 fluxgen Exp $ +// $Id: Screen.cc,v 1.74 2002/10/15 17:12:23 fluxgen Exp $ //use GNU extensions #ifndef _GNU_SOURCE @@ -288,7 +288,7 @@ resource(rm, screenname, altscreenname) "0: 0000 x 0: 0000"); int l = strlen(s); - + /* if (i18n->multibyte()) { XRectangle ink, logical; XmbTextExtents(theme->getWindowStyle().font.set, s, l, &ink, &logical); @@ -301,7 +301,10 @@ resource(rm, screenname, altscreenname) geom_w = XTextWidth(theme->getWindowStyle().font.fontstruct, s, l); } - + */ + geom_h = theme->getWindowStyle().font.height(); + geom_w = theme->getWindowStyle().font.textWidth(s, l); + geom_w += getBevelWidth()*2; geom_h += getBevelWidth()*2; @@ -527,7 +530,7 @@ void BScreen::reconfigure() { FBNLS::ScreenSet, FBNLS::ScreenPositionLength, "0: 0000 x 0: 0000"); int l = strlen(s); - + /* if (i18n->multibyte()) { XRectangle ink, logical; XmbTextExtents(theme->getWindowStyle().font.set, s, l, &ink, &logical); @@ -540,7 +543,10 @@ void BScreen::reconfigure() { geom_h = theme->getWindowStyle().font.fontstruct->ascent + theme->getWindowStyle().font.fontstruct->descent; } - + */ + //TODO: repeat from somewhere else? + geom_h = theme->getWindowStyle().font.height(); + geom_w = theme->getWindowStyle().font.textWidth(s, l); geom_w += getBevelWidth()*2; geom_h += getBevelWidth()*2; @@ -1620,7 +1626,7 @@ void BScreen::showPosition(int x, int y) { "X: %4d x Y: %4d"), x, y); XClearWindow(getBaseDisplay()->getXDisplay(), geom_window); - + /* if (I18n::instance()->multibyte()) XmbDrawString(getBaseDisplay()->getXDisplay(), geom_window, theme->getWindowStyle().font.set, theme->getWindowStyle().l_text_focus_gc, @@ -1633,7 +1639,15 @@ void BScreen::showPosition(int x, int y) { theme->getBevelWidth(), theme->getWindowStyle().font.fontstruct->ascent + theme->getBevelWidth(), label, strlen(label)); - + */ + theme->getWindowStyle().font.drawText( + geom_window, + getScreenNumber(), + theme->getWindowStyle().l_text_focus_gc, + label, strlen(label), + theme->getBevelWidth(), theme->getBevelWidth() + + theme->getWindowStyle().font.height()); + } @@ -1664,7 +1678,7 @@ void BScreen::showGeometry(unsigned int gx, unsigned int gy) { "W: %4d x H: %4d"), gx, gy); XClearWindow(getBaseDisplay()->getXDisplay(), geom_window); - + /* if (I18n::instance()->multibyte()) XmbDrawString(getBaseDisplay()->getXDisplay(), geom_window, theme->getWindowStyle().font.set, theme->getWindowStyle().l_text_focus_gc, @@ -1677,6 +1691,15 @@ void BScreen::showGeometry(unsigned int gx, unsigned int gy) { theme->getBevelWidth(), theme->getWindowStyle().font.fontstruct->ascent + theme->getBevelWidth(), label, strlen(label)); + */ + //TODO: geom window again?! repeat + theme->getWindowStyle().font.drawText( + geom_window, + getScreenNumber(), + theme->getWindowStyle().l_text_focus_gc, + label, strlen(label), + theme->getBevelWidth(), theme->getBevelWidth() + + theme->getWindowStyle().font.height()); } diff --git a/src/Theme.cc b/src/Theme.cc index be660d6..a6ea86c 100644 --- a/src/Theme.cc +++ b/src/Theme.cc @@ -21,7 +21,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Theme.cc,v 1.30 2002/10/15 10:53:01 fluxgen Exp $ +// $Id: Theme.cc,v 1.31 2002/10/15 17:08:45 fluxgen Exp $ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -62,10 +62,8 @@ m_rootcommand(rootcommand==0 ? "" : rootcommand) //we dont want to send 0-pointe #endif //DEBUG //default settings - m_windowstyle.font.set = m_toolbarstyle.font.set = m_windowstyle.tab.font.set = 0; - - m_toolbarstyle.font.fontstruct = m_windowstyle.font.fontstruct = m_windowstyle.tab.font.fontstruct = 0; - m_windowstyle.tab.rot_font = 0; + m_toolbarstyle.font.set = 0; + m_toolbarstyle.font.fontstruct = 0; load(filename); //-------- create gc for the styles ------------ @@ -74,9 +72,6 @@ m_rootcommand(rootcommand==0 ? "" : rootcommand) //we dont want to send 0-pointe XGCValues gcv; unsigned long gc_value_mask = GCForeground; - if (! I18n::instance()->multibyte()) - gc_value_mask |= GCFont; - gcv.foreground = WhitePixel(m_display, screennum)^BlackPixel(m_display, screennum); gcv.function = GXxor; gcv.subwindow_mode = IncludeInferiors; @@ -84,24 +79,17 @@ m_rootcommand(rootcommand==0 ? "" : rootcommand) //we dont want to send 0-pointe GCForeground | GCFunction | GCSubwindowMode, &gcv); gcv.foreground = m_windowstyle.l_text_focus.pixel(); - if (m_windowstyle.font.fontstruct) - gcv.font = m_windowstyle.font.fontstruct->fid; - m_windowstyle.l_text_focus_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); gcv.foreground = m_windowstyle.l_text_unfocus.pixel(); - if (m_windowstyle.font.fontstruct) - gcv.font = m_windowstyle.font.fontstruct->fid; m_windowstyle.l_text_unfocus_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv); //---- Tab gcv.foreground = m_windowstyle.tab.l_text_focus.pixel(); - if (m_windowstyle.tab.font.fontstruct) - gcv.font = m_windowstyle.tab.font.fontstruct->fid; m_windowstyle.tab.l_text_focus_gc = XCreateGC(m_display, rootwindow, @@ -202,15 +190,8 @@ void Theme::freeMenuStyle() { //----- freeWindowStyle ----- // free memory allocated for m_windowstyle -// should only be called from ~Theme //-------------------- void Theme::freeWindowStyle() { - if (m_windowstyle.font.set) - XFreeFontSet(m_display, m_windowstyle.font.set); - - if (m_windowstyle.font.fontstruct) - XFreeFont(m_display, m_windowstyle.font.fontstruct); - XFreeGC(m_display, m_windowstyle.l_text_focus_gc); XFreeGC(m_display, m_windowstyle.l_text_unfocus_gc); XFreeGC(m_display, m_windowstyle.b_pic_focus_gc); @@ -219,20 +200,8 @@ void Theme::freeWindowStyle() { //----- freeTabStyle ----- // free memory allocated for m_windowstyle.tab -// should only be called from ~Theme //-------------------- void Theme::freeTabStyle() { - - if (m_windowstyle.tab.font.set) - XFreeFontSet(m_display, m_windowstyle.tab.font.set); - - if (m_windowstyle.tab.font.fontstruct) - XFreeFont(m_display, m_windowstyle.tab.font.fontstruct); - - if (m_windowstyle.tab.rot_font) - DrawUtil::XRotUnloadFont(m_display, m_windowstyle.tab.rot_font); - - XFreeGC(m_display, m_windowstyle.tab.l_text_focus_gc); XFreeGC(m_display, m_windowstyle.tab.l_text_unfocus_gc); } @@ -445,17 +414,7 @@ void Theme::loadWindowStyle() { WhitePixel(m_display, m_screennum)); //----- font - - if (I18n::instance()->multibyte()) { - readDatabaseFontSet("window.font", "Window.Font", - &m_windowstyle.font.set); - - m_windowstyle.font.set_extents = - XExtentsOfFontSet(m_windowstyle.font.set); - } else { - readDatabaseFont("window.font", "Window.Font", - &m_windowstyle.font.fontstruct); - } + loadFontFromDatabase(m_windowstyle.font, "window.font", "Window.Font"); XrmValue value; char *value_type; @@ -463,13 +422,13 @@ void Theme::loadWindowStyle() { if (XrmGetResource(m_database, "window.justify", "Window.Justify", &value_type, &value)) { if (strstr(value.addr, "right") || strstr(value.addr, "Right")) - m_windowstyle.font.justify = DrawUtil::Font::RIGHT; + m_windowstyle.justify = DrawUtil::Font::RIGHT; else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) - m_windowstyle.font.justify = DrawUtil::Font::CENTER; + m_windowstyle.justify = DrawUtil::Font::CENTER; else - m_windowstyle.font.justify = DrawUtil::Font::LEFT; + m_windowstyle.justify = DrawUtil::Font::LEFT; } else - m_windowstyle.font.justify = DrawUtil::Font::LEFT; + m_windowstyle.justify = DrawUtil::Font::LEFT; } @@ -523,38 +482,29 @@ void Theme::loadTabStyle() { m_windowstyle.tab.border_width_2x = m_windowstyle.tab.border_width*2; - //---------- font - - if (I18n::instance()->multibyte()) { - readDatabaseFontSet("window.tab.font", "Window.Tab.Font", - &m_windowstyle.tab.font.set); - - m_windowstyle.tab.font.set_extents = - XExtentsOfFontSet(m_windowstyle.tab.font.set); - } else { - readDatabaseFont("window.tab.font", "Window.Tab.Font", - &m_windowstyle.tab.font.fontstruct); - } + loadFontFromDatabase(m_windowstyle.tab.font, "window.tab.font", "Window.Tab.Font"); + //TODO: fix rotated font //--------- rotated font for left and right tabs // TODO: add extra checking - if (XrmGetResource(m_database, "window.tab.font", "Window.Tab.Font", + /*if (XrmGetResource(m_database, "window.tab.font", "Window.Tab.Font", &value_type, &value)) { if (! (m_windowstyle.tab.rot_font = DrawUtil::XRotLoadFont(m_display, value.addr, 90.0)) ) m_windowstyle.tab.rot_font = DrawUtil::XRotLoadFont(m_display, "fixed", 90); } else m_windowstyle.tab.rot_font = DrawUtil::XRotLoadFont(m_display, "fixed", 90); + */ if (XrmGetResource(m_database, "window.tab.justify", "Window.Tab.Justify", &value_type, &value)) { if (strstr(value.addr, "right") || strstr(value.addr, "Right")) - m_windowstyle.tab.font.justify = DrawUtil::Font::RIGHT; + m_windowstyle.tab.justify = DrawUtil::Font::RIGHT; else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) - m_windowstyle.tab.font.justify = DrawUtil::Font::CENTER; + m_windowstyle.tab.justify = DrawUtil::Font::CENTER; else - m_windowstyle.tab.font.justify = DrawUtil::Font::LEFT; + m_windowstyle.tab.justify = DrawUtil::Font::LEFT; } else - m_windowstyle.tab.font.justify = DrawUtil::Font::LEFT; + m_windowstyle.tab.justify = DrawUtil::Font::LEFT; } @@ -920,8 +870,6 @@ void Theme::reconfigure(bool antialias) { XGCValues gcv; unsigned long gc_value_mask = GCForeground; - if (! I18n::instance()->multibyte()) - gc_value_mask |= GCFont; XChangeGC(m_display, m_opgc, GCForeground | GCFunction | GCSubwindowMode, &gcv); @@ -933,8 +881,8 @@ void Theme::reconfigure(bool antialias) { GCForeground | GCFunction | GCSubwindowMode, &gcv); gcv.foreground = m_windowstyle.l_text_focus.pixel(); - if (m_windowstyle.font.fontstruct) - gcv.font = m_windowstyle.font.fontstruct->fid; + if (m_windowstyle.font.isAntialias() != antialias) + m_windowstyle.font.setAntialias(antialias); XChangeGC(m_display, m_windowstyle.l_text_focus_gc, gc_value_mask, &gcv); @@ -945,9 +893,8 @@ void Theme::reconfigure(bool antialias) { //---- Tab gcv.foreground = m_windowstyle.tab.l_text_focus.pixel(); - if (m_windowstyle.tab.font.fontstruct) - gcv.font = m_windowstyle.tab.font.fontstruct->fid; - + if (m_windowstyle.tab.font.isAntialias() != antialias) + m_windowstyle.tab.font.setAntialias(antialias); XChangeGC(m_display, m_windowstyle.tab.l_text_focus_gc, gc_value_mask, &gcv); @@ -970,7 +917,7 @@ void Theme::reconfigure(bool antialias) { m_menustyle.titlefont.setAntialias(antialias); XChangeGC(m_display, m_menustyle.t_text_gc, - gc_value_mask, &gcv); + gc_value_mask|GCForeground, &gcv); gcv.foreground = m_menustyle.f_text.pixel(); if (m_menustyle.framefont.isAntialias() != antialias) @@ -994,7 +941,8 @@ void Theme::reconfigure(bool antialias) { gcv.foreground = m_toolbarstyle.l_text.pixel(); if (m_toolbarstyle.font.fontstruct) gcv.font = m_toolbarstyle.font.fontstruct->fid; - + + gc_value_mask |= GCFont; XChangeGC(m_display, m_toolbarstyle.l_text_gc, gc_value_mask, &gcv); @@ -1138,7 +1086,8 @@ void Theme::loadFontFromDatabase(FbTk::Font &dest, const char *name, const char #ifdef DEBUG std::cerr<<__FILE__<<"("<<__LINE__<<"): Load font:"<getBorderWidth(); if (getTitle().size() > 0) { - if (I18n::instance()->multibyte()) { - XRectangle ink, logical; - XmbTextExtents(screen->getWindowStyle()->font.set, - getTitle().c_str(), getTitle().size(), &ink, &logical); - client.title_text_w = logical.width; - } else { - client.title_text_w = XTextWidth(screen->getWindowStyle()->font.fontstruct, - getTitle().c_str(), getTitle().size()); - } + client.title_text_w = screen->getWindowStyle()->font.textWidth(getTitle().c_str(), getTitle().size()); client.title_text_w += (frame.bevel_w * 4); } @@ -1121,17 +1113,8 @@ void FluxboxWindow::getWMName() { FBNLS::WindowSet, FBNLS::WindowUnnamed, "Unnamed"); } - - if (i18n->multibyte()) { - XRectangle ink, logical; - XmbTextExtents(screen->getWindowStyle()->font.set, - getTitle().c_str(), getTitle().size(), &ink, &logical); - client.title_text_w = logical.width; - } else { - client.title_text_w = XTextWidth(screen->getWindowStyle()->font.fontstruct, - getTitle().c_str(), getTitle().size()); - } - + //Note: repeated? + client.title_text_w = screen->getWindowStyle()->font.textWidth(getTitle().c_str(), getTitle().size()); client.title_text_w += (frame.bevel_w * 4); } @@ -2445,15 +2428,18 @@ void FluxboxWindow::redrawLabel() { XSetWindowBackground(display, frame.label, frame.ulabel_pixel); } + XClearWindow(display, frame.label); + //no need to draw the title if we don't have any - if (getTitle().size()!=0) { + if (getTitle().size() != 0) { GC gc = ((focused) ? screen->getWindowStyle()->l_text_focus_gc : screen->getWindowStyle()->l_text_unfocus_gc); - - DrawUtil::DrawString(display, frame.label, gc, - &screen->getWindowStyle()->font, - client.title_text_w, frame.label_w, - frame.bevel_w, getTitle().c_str()); + screen->getWindowStyle()->font.drawText( + frame.label, + screen->getScreenNumber(), + gc, + getTitle().c_str(), getTitle().size(), + frame.bevel_w, frame.bevel_w + screen->getWindowStyle()->font.height()); } } @@ -3633,14 +3619,8 @@ void FluxboxWindow::upsize() { frame.bevel_w = screen->getBevelWidth(); frame.mwm_border_w = screen->getFrameWidth() * decorations.border; - if (I18n::instance()->multibyte()) { - frame.title_h = (screen->getWindowStyle()->font.set_extents-> - max_ink_extent.height + - (frame.bevel_w * 2) + 2) * decorations.titlebar; - } else - frame.title_h = (screen->getWindowStyle()->font.fontstruct->ascent + - screen->getWindowStyle()->font.fontstruct->descent + - (frame.bevel_w * 2) + 2) * decorations.titlebar; + frame.title_h = screen->getWindowStyle()->font.height() + + (frame.bevel_w*2 + 2)*decorations.titlebar; frame.label_h = (frame.title_h - (frame.bevel_w * 2)) * decorations.titlebar; frame.button_w = frame.button_h = frame.label_h - 2; -- cgit v0.11.2