display window titles using utf if appropriate, and in the toolbar
authorDana Jansens <danakj@orodu.net>
Sat, 11 Jan 2003 20:37:50 +0000 (20:37 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 11 Jan 2003 20:37:50 +0000 (20:37 +0000)
src/Basemenu.cc
src/Font.cc
src/Font.hh
src/Screen.cc
src/Screen.hh
src/Toolbar.cc
src/Window.cc
src/Window.hh

index 01ca387b6670dea414c2d65d0eec50e8279f7658..3f3db62e554c6678fab3a6e1353db9eb01903729 100644 (file)
@@ -257,7 +257,8 @@ void Basemenu::update(void) {
   menu.title_h = style->t_font->height() + menu.bevel_w * 2;
 
   if (title_vis) {
-    menu.item_w = screen->getMenuStyle()->t_font->measureString(menu.label) +
+    menu.item_w = screen->getMenuStyle()->t_font->measureString(menu.label,
+                                                                false) +
       menu.bevel_w * 2;
   }  else {
     menu.item_w = 1;
@@ -266,7 +267,7 @@ void Basemenu::update(void) {
   unsigned int ii = 0;
   MenuItems::iterator it = menuitems.begin(), end = menuitems.end();
   for (; it != end; ++it) {
-    ii = screen->getMenuStyle()->f_font->measureString((*it)->l) +
+    ii = screen->getMenuStyle()->f_font->measureString((*it)->l, false) +
       (menu.bevel_w * 2) + (menu.item_h * 2);
 
     menu.item_w = ((menu.item_w < ii) ? ii : menu.item_w);
@@ -436,7 +437,7 @@ void Basemenu::redrawTitle(void) {
   unsigned int l;
   const MenuStyle* const style = screen->getMenuStyle();
 
-  l = style->t_font->measureString(text) + menu.bevel_w * 2;
+  l = style->t_font->measureString(text, false) + menu.bevel_w * 2;
 
   switch (screen->getMenuStyle()->t_justify) {
   case RightJustify:
@@ -454,7 +455,7 @@ void Basemenu::redrawTitle(void) {
 
   XClearWindow(display, menu.title);
   style->t_font->drawString(menu.title, dx, menu.bevel_w,
-                            style->t_text, text);
+                            style->t_text, text, false);
 }
 
 void Basemenu::drawSubmenu(int index) {
@@ -541,7 +542,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     text_h = 0;
 
   if (text) {
-    text_w = screen->getMenuStyle()->f_font->measureString(text);
+    text_w = screen->getMenuStyle()->f_font->measureString(text, false);
     text_y = item_y + menu.bevel_w / 2;
 
     switch(screen->getMenuStyle()->f_justify) {
@@ -677,7 +678,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
                               (highlight ? style->h_text :
                                (item->isEnabled() ? style->f_text :
                                 style->d_text)),
-                              text);
+                              text, false);
   }
 
   if (dosel && item->submenu()) {
index 149e75faf96b18a7053d3d1a109b9c71360407ee..773dc279f79afa17d867ee600b9c381762b01e2b 100644 (file)
@@ -253,7 +253,7 @@ bool BFont::parseXlfd(const string &xlfd) {
 
 
 void BFont::drawString(Drawable d, int x, int y, const BColor &color,
-                       const string &string) const {
+                       const string &string, bool utf) const {
   assert(_valid);
 
 #ifdef    XFT
@@ -278,15 +278,18 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color,
         c.pixel = WhitePixel(_display, _screen->getScreenNumber());
       }
 
-#ifdef XFT_UTF8
-      XftDrawStringUtf8(
-#else
-      XftDrawString8(
-#endif
-                     draw, &c, _xftfont, x + _offset, 
-                     _xftfont->ascent + y + _offset,
-                     (XftChar8 *) string.c_str(), 
-                     string.size());
+//#ifdef XFT_UTF8
+      if (utf)
+        XftDrawStringUtf8(draw, &c, _xftfont, x + _offset, 
+                          _xftfont->ascent + y + _offset,
+                          (XftChar8 *) string.c_str(), 
+                          string.size());
+      else
+//#endif
+        XftDrawString8(draw, &c, _xftfont, x + _offset, 
+                       _xftfont->ascent + y + _offset,
+                       (XftChar8 *) string.c_str(), 
+                       string.size());
     }
     
     XftColor c;
@@ -296,13 +299,14 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color,
     c.pixel = color.pixel();
     c.color.alpha = 0xff | 0xff << 8; // no transparency in BColor yet
 
-#ifdef XFT_UTF8
-    XftDrawStringUtf8(
-#else
-    XftDrawString8(
-#endif
-                   draw, &c, _xftfont, x, _xftfont->ascent + y,
-                   (XftChar8 *) string.c_str(), string.size());
+//#ifdef XFT_UTF8
+    if (utf)
+      XftDrawStringUtf8(draw, &c, _xftfont, x, _xftfont->ascent + y,
+                        (XftChar8 *) string.c_str(), string.size());
+    else
+//#endif
+      XftDrawString8(draw, &c, _xftfont, x, _xftfont->ascent + y,
+                     (XftChar8 *) string.c_str(), string.size());
 
     XftDrawDestroy(draw);
     return;
@@ -322,20 +326,21 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color,
 }
 
 
-unsigned int BFont::measureString(const string &string) const {
+unsigned int BFont::measureString(const string &string, bool utf) const {
   assert(_valid);
 
 #ifdef    XFT
   if (_xftfont) {
     XGlyphInfo info;
 
-#ifdef XFT_UTF8
-    XftTextExtentsUtf8(
-#else
-    XftTextExtents8(
-#endif
-                    _display, _xftfont, (XftChar8 *) string.c_str(),
-                    string.size(), &info);
+//#ifdef XFT_UTF8
+    if (utf)
+      XftTextExtentsUtf8(_display, _xftfont, (XftChar8 *) string.c_str(),
+                         string.size(), &info);
+    else
+//#endif
+      XftTextExtents8(_display, _xftfont, (XftChar8 *) string.c_str(),
+                      string.size(), &info);
 
     return info.xOff + (_shadow ? std::abs(_offset) : 0);
   }
index 6f6431ef276af8d83723a0f677f79c6a34678600..9a84357a71318b3d4e79bb14c9c3db1a6b67f458 100644 (file)
@@ -115,10 +115,10 @@ public:
   unsigned int height(void) const;
   unsigned int maxCharWidth(void) const;
 
-  unsigned int measureString(const std::string &string) const;
+  unsigned int measureString(const std::string &string, bool utf) const;
 
   void drawString(Drawable d, int x, int y, const BColor &color,
-                  const std::string &string) const;
+                  const std::string &string, bool utf) const;
 };
 
 #endif // __Font_hh
index c4534904623d615794854580cfef979e71a3a414..18ecd5a629372b633f4e5dec821779604cfe9aa3 100644 (file)
@@ -181,7 +181,8 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
 
   const char *s =  i18n(ScreenSet, ScreenPositionLength,
                         "0: 0000 x 0: 0000");
-  geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
+  geom_w = resource.wstyle.font->measureString(s, false) +
+    resource.bevel_width * 2;
   geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
 
   XSetWindowAttributes attrib;
@@ -939,7 +940,8 @@ void BScreen::reconfigure(void) {
   const char *s = i18n(ScreenSet, ScreenPositionLength,
                        "0: 0000 x 0: 0000");
 
-  geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
+  geom_w = resource.wstyle.font->measureString(s, false) +
+    resource.bevel_width * 2;
   geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
 
   BTexture* texture = &(resource.wstyle.l_focus);
@@ -2433,7 +2435,7 @@ void BScreen::showPosition(int x, int y) {
   resource.wstyle.font->drawString(geom_window,
                                    resource.bevel_width, resource.bevel_width,
                                    resource.wstyle.l_text_focus,
-                                   label);
+                                   label, false);
 }
 
 
@@ -2458,7 +2460,7 @@ void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
   resource.wstyle.font->drawString(geom_window,
                                    resource.bevel_width, resource.bevel_width,
                                    resource.wstyle.l_text_focus,
-                                   label);
+                                   label, false);
 }
 
 
index ca19b2cd44e6f3295ec017b7fecfa9b6ff984895..01a08b4c5b6396910a25294ce05b1c8eb5739fa3 100644 (file)
@@ -83,7 +83,8 @@ struct WindowStyle {
   TextJustify justify;
 
   void doJustify(const std::string &text, int &start_pos,
-                 unsigned int max_length, unsigned int modifier) const;
+                 unsigned int max_length, unsigned int modifier,
+                 bool utf) const;
 };
 
 struct ToolbarStyle {
@@ -99,7 +100,8 @@ struct ToolbarStyle {
   TextJustify justify;
 
   void doJustify(const std::string &text, int &start_pos,
-                 unsigned int max_length, unsigned int modifier) const;
+                 unsigned int max_length, unsigned int modifier,
+                 bool utf) const;
 };
 
 struct MenuStyle {
index 14d347efba9d7a048e98582651690972a832096e..6d3d370545df920129881b737c26b7fd621022ed 100644 (file)
@@ -363,7 +363,7 @@ void Toolbar::reconfigure(void) {
       // find the length of the rendered string and add room for two extra
       // characters to it.  This allows for variable width output of the fonts
       BFont *font = screen->getToolbarStyle()->font;
-      frame.clock_w = font->measureString(t) + font->maxCharWidth() * 2;
+      frame.clock_w = font->measureString(t, false) + font->maxCharWidth() * 2;
     }
   }
 #else // !HAVE_STRFTIME
@@ -377,7 +377,8 @@ void Toolbar::reconfigure(void) {
 
   for (unsigned int i = 0; i < screen->getWorkspaceCount(); i++) {
     const string& workspace_name = screen->getWorkspace(i)->getName();
-    width = screen->getToolbarStyle()->font->measureString(workspace_name);
+    width = screen->getToolbarStyle()->font->measureString(workspace_name,
+                                                           false);
     if (width > frame.workspace_label_w) frame.workspace_label_w = width;
   }
 
@@ -580,13 +581,13 @@ void Toolbar::checkClock(bool redraw, bool date) {
     ToolbarStyle *style = screen->getToolbarStyle();
 
     int pos = frame.bevel_w * 2; // this is modified by doJustify()
-    style->doJustify(t, pos, frame.clock_w, frame.bevel_w * 4);
+    style->doJustify(t, pos, frame.clock_w, frame.bevel_w * 4, false);
 
 #ifdef    XFT
     XClearWindow(display, frame.clock);
 #endif // XFT
 
-    style->font->drawString(frame.clock, pos, 1, style->c_text, t);
+    style->font->drawString(frame.clock, pos, 1, style->c_text, t, false);
   }
 }
 
@@ -608,11 +609,13 @@ void Toolbar::redrawWindowLabel(bool redraw) {
   if (foc->getScreen() != screen) return;
 
   const char *title = foc->getTitle();
+  bool utf = foc->getTitleUtf();
   ToolbarStyle *style = screen->getToolbarStyle();
 
   int pos = frame.bevel_w * 2; // modified by doJustify()
-  style->doJustify(title, pos, frame.window_label_w, frame.bevel_w * 4);
-  style->font->drawString(frame.window_label, pos, 1, style->w_text, title);
+  style->doJustify(title, pos, frame.window_label_w, frame.bevel_w * 4, utf);
+  style->font->drawString(frame.window_label, pos, 1, style->w_text, title,
+                          utf);
 }
 
 
@@ -630,8 +633,9 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) {
 
   int pos = frame.bevel_w * 2;
   style->doJustify(name.c_str(), pos, frame.workspace_label_w,
-                   frame.bevel_w * 4);
-  style->font->drawString(frame.workspace_label, pos, 1, style->l_text, name);
+                   frame.bevel_w * 4, false);
+  style->font->drawString(frame.workspace_label, pos, 1, style->l_text, name,
+                          false);
 }
 
 
@@ -1012,14 +1016,15 @@ void Toolbar::keyPressEvent(const XKeyEvent *ke) {
       XClearWindow(display, frame.workspace_label);
       unsigned int tw, x;
 
-      tw = screen->getToolbarStyle()->font->measureString(new_workspace_name);
+      tw = screen->getToolbarStyle()->font->measureString(new_workspace_name,
+                                                          false);
       x = (frame.workspace_label_w - tw) / 2;
 
       if (x < frame.bevel_w) x = frame.bevel_w;
 
       ToolbarStyle *style = screen->getToolbarStyle();
       style->font->drawString(frame.workspace_label, x, 1, style->l_text,
-                              new_workspace_name);
+                              new_workspace_name, false);
       BPen pen(style->l_text);
       XDrawRectangle(display, frame.workspace_label, pen.gc(), x + tw, 0, 1,
                      frame.label_h - 1);
@@ -1212,12 +1217,13 @@ void Toolbarmenu::Placementmenu::itemSelected(int button, unsigned int index) {
 
 void ToolbarStyle::doJustify(const std::string &text, int &start_pos,
                              unsigned int max_length,
-                             unsigned int modifier) const {
+                             unsigned int modifier, bool utf) const {
   size_t text_len = text.size();
   unsigned int length;
 
   do {
-    length = font->measureString(string(text, 0, text_len)) + modifier;
+    length = font->measureString(string(text, 0, text_len), utf) +
+      modifier;
   } while (length > max_length && text_len-- > 0);
 
   switch (justify) {
index 7b971eda0c18b98215d11f904d9d0ad78abbb07a..50431428c1d1b3e84a229b3366d179941713c0ea 100644 (file)
@@ -1158,18 +1158,21 @@ void BlackboxWindow::getWMName(void) {
                       XAtom::utf8, client.title) &&
       !client.title.empty()) {
     xatom->eraseValue(client.window, XAtom::net_wm_visible_name);
+    client.title_utf = true;
     return;
   }
   //fall through to using WM_NAME
   if (xatom->getValue(client.window, XAtom::wm_name, XAtom::ansi, client.title)
       && !client.title.empty()) {
     xatom->eraseValue(client.window, XAtom::net_wm_visible_name);
+    client.title_utf = false;
     return;
   }
   // fall back to an internal default
   client.title = i18n(WindowSet, WindowUnnamed, "Unnamed");
   xatom->setValue(client.window, XAtom::net_wm_visible_name, XAtom::utf8,
                   client.title);
+  client.title_utf = false;
 
 #ifdef DEBUG_WITH_ID
   // the 16 is the 8 chars of the debug text plus the number
@@ -1186,6 +1189,7 @@ void BlackboxWindow::getWMIconName(void) {
                       XAtom::utf8, client.icon_title) && 
       !client.icon_title.empty()) {
     xatom->eraseValue(client.window, XAtom::net_wm_visible_icon_name);
+    client.icon_title_utf = true;
     return;
   }
   //fall through to using WM_ICON_NAME
@@ -1193,12 +1197,14 @@ void BlackboxWindow::getWMIconName(void) {
                       client.icon_title) && 
       !client.icon_title.empty()) {
     xatom->eraseValue(client.window, XAtom::net_wm_visible_icon_name);
+    client.icon_title_utf = false;
     return;
   }
   // fall back to using the main name
   client.icon_title = client.title;
   xatom->setValue(client.window, XAtom::net_wm_visible_icon_name, XAtom::utf8,
                   client.icon_title);
+  client.icon_title_utf = client.title_utf;
 }
 
 
@@ -2613,11 +2619,12 @@ void BlackboxWindow::redrawLabel(void) const {
   WindowStyle *style = screen->getWindowStyle();
 
   int pos = frame.bevel_w * 2;
-  style->doJustify(client.title.c_str(), pos, frame.label_w, frame.bevel_w * 4);
+  style->doJustify(client.title.c_str(), pos, frame.label_w, frame.bevel_w * 4,
+                   client.title_utf);
   style->font->drawString(frame.label, pos, 1,
                           (flags.focused ? style->l_text_focus :
                            style->l_text_unfocus),
-                          client.title);
+                          client.title, client.title_utf);
 }
 
 
@@ -4292,12 +4299,12 @@ void BlackboxWindow::constrain(Corner anchor,
 
 void WindowStyle::doJustify(const std::string &text, int &start_pos,
                             unsigned int max_length,
-                            unsigned int modifier) const {
+                            unsigned int modifier, bool utf) const {
   size_t text_len = text.size();
   unsigned int length;
 
   do {
-    length = font->measureString(string(text, 0, text_len)) + modifier;
+    length = font->measureString(string(text, 0, text_len), utf) + modifier;
   } while (length > max_length && text_len-- > 0);
 
   switch (justify) {
index b923c4bfe14f8a597ab87cee2246142eb18d0778..126d9cbbc0653cf3ba86dc7ed7bd7a0c86d25260 100644 (file)
@@ -167,6 +167,7 @@ private:
     BlackboxWindowList transientList; // which windows are our transients?
 
     std::string title, icon_title;
+    bool title_utf, icon_title_utf;
 
     Rect rect;
     Strut strut;
@@ -355,10 +356,11 @@ public:
 
   inline Windowmenu * getWindowmenu(void) const { return windowmenu; }
 
-  inline const char *getTitle(void) const
-  { return client.title.c_str(); }
+  inline const char *getTitle(void) const { return client.title.c_str(); }
+  inline bool getTitleUtf(void) const { return client.title_utf; }
   inline const char *getIconTitle(void) const
-  { return client.icon_title.c_str(); }
+    { return client.icon_title.c_str(); }
+  inline bool getIconTitleUtf(void) const { return client.icon_title_utf; }
 
   inline unsigned int getWorkspaceNumber(void) const
   { return blackbox_attrib.workspace; }