news download themes documentation links










Text.cc

00001 // Text.cc for FbTk - text utils
00002 // Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 // DEALINGS IN THE SOFTWARE.
00021 
00022 // $Id: Text.cc,v 1.2 2003/08/11 14:59:57 fluxgen Exp $
00023 
00024 #include "Text.hh"
00025 
00026 #include "Font.hh"
00027 #include "Theme.hh"
00028 
00029 #include <strings.h>
00030 
00031 namespace FbTk {
00032 
00033 int doAlignment(int max_width, int bevel, FbTk::Justify justify, 
00034                 const FbTk::Font &font, const char * const text, 
00035                 unsigned int textlen, unsigned int &newlen) {
00036 
00037     if (text == 0 || textlen == 0)
00038         return 0;
00039 
00040     int l = font.textWidth(text, textlen) + bevel;
00041     size_t dlen = textlen;
00042     int dx = bevel;
00043     if (l > max_width) {
00044         for (; dlen > 0; dlen--) {
00045             l = font.textWidth(text, dlen) + bevel;
00046             if (l<=max_width)
00047                 break;
00048         }
00049     }
00050 
00051     newlen = dlen;
00052 
00053     switch (justify) {
00054     case FbTk::RIGHT:
00055         dx = max_width - l - bevel;
00056     break;
00057     case FbTk::CENTER:
00058         dx = (max_width - l)/2;
00059     break;
00060     case FbTk::LEFT:
00061     break;
00062     }
00063     
00064     return dx;
00065 }
00066 
00068 template <>
00069 void ThemeItem<FbTk::Justify>::setDefaultValue() {
00070     m_value = LEFT;
00071 }
00072 
00073 template <>
00074 void ThemeItem<FbTk::Justify>::setFromString(const char *value) {
00075     if (strcasecmp("center", value) == 0)
00076         m_value = FbTk::CENTER;
00077     else if (strcasecmp("right", value) == 0)
00078         m_value = FbTk::RIGHT;
00079     else // default
00080         setDefaultValue();
00081 }
00082 
00083 // do nothing
00084 template <>
00085 void ThemeItem<FbTk::Justify>::load() {
00086 }
00087 
00088 }; // end namespace FbTk

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA