diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-18 08:33:47 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-18 08:33:47 (GMT) |
commit | 1d4bea8a2db2c0ab1e14b8afd81c87b80a262d66 (patch) | |
tree | 21cc4e919cabe52ab8d355a7ceec980da6fb420a /src/FbTk/TextUtils.cc | |
parent | 3a5fd7342d6cfd00acafeec4c1f35948a550e4ab (diff) | |
parent | 8c2cee577a744870fd497f73a21c2d4e1c45c907 (diff) | |
download | fluxbox-1d4bea8a2db2c0ab1e14b8afd81c87b80a262d66.zip fluxbox-1d4bea8a2db2c0ab1e14b8afd81c87b80a262d66.tar.bz2 |
Merge branch 'master' of fluxbox@gitfbox:fluxbox
Diffstat (limited to 'src/FbTk/TextUtils.cc')
-rw-r--r-- | src/FbTk/TextUtils.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/FbTk/TextUtils.cc b/src/FbTk/TextUtils.cc new file mode 100644 index 0000000..2b47531 --- /dev/null +++ b/src/FbTk/TextUtils.cc | |||
@@ -0,0 +1,87 @@ | |||
1 | // Text.cc for FbTk - text utils | ||
2 | // Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #include "TextUtils.hh" | ||
23 | |||
24 | #include "Font.hh" | ||
25 | #include "Theme.hh" | ||
26 | |||
27 | #include <strings.h> | ||
28 | |||
29 | namespace FbTk { | ||
30 | |||
31 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | ||
32 | const FbTk::Font &font, const char * const text, | ||
33 | unsigned int textlen, unsigned int &newlen) { | ||
34 | |||
35 | if (text == 0 || textlen == 0) | ||
36 | return 0; | ||
37 | |||
38 | int l = font.textWidth(text, textlen) + bevel; | ||
39 | unsigned int dlen = textlen; | ||
40 | int dx = bevel; | ||
41 | if (l > max_width) { | ||
42 | for (; dlen > 0; dlen--) { | ||
43 | l = font.textWidth(text, dlen) + bevel; | ||
44 | if (l<=max_width) | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | newlen = dlen; | ||
50 | |||
51 | switch (justify) { | ||
52 | case FbTk::RIGHT: | ||
53 | dx = max_width - l - bevel; | ||
54 | break; | ||
55 | case FbTk::CENTER: | ||
56 | dx = (max_width - l)/2; | ||
57 | break; | ||
58 | case FbTk::LEFT: | ||
59 | break; | ||
60 | } | ||
61 | |||
62 | return dx; | ||
63 | } | ||
64 | |||
65 | |||
66 | /// specialization for Justify | ||
67 | template <> | ||
68 | void ThemeItem<FbTk::Justify>::setDefaultValue() { | ||
69 | m_value = LEFT; | ||
70 | } | ||
71 | |||
72 | template <> | ||
73 | void ThemeItem<FbTk::Justify>::setFromString(const char *value) { | ||
74 | if (strcasecmp("center", value) == 0) | ||
75 | m_value = FbTk::CENTER; | ||
76 | else if (strcasecmp("right", value) == 0) | ||
77 | m_value = FbTk::RIGHT; | ||
78 | else // default | ||
79 | setDefaultValue(); | ||
80 | } | ||
81 | |||
82 | // do nothing | ||
83 | template <> | ||
84 | void ThemeItem<FbTk::Justify>::load(const std::string *name, const std::string *altname) { | ||
85 | } | ||
86 | |||
87 | }; // end namespace FbTk | ||