diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2008-01-15 07:45:57 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2008-01-15 07:45:57 (GMT) |
commit | f6c292a406f183a12b2e327716aad5de4c0abcca (patch) | |
tree | a90b80a7a1ec95ce7ab0b66447b7528f64e03eae /src/FbTk/TextUtils.cc | |
parent | e1db89e2d7d56afca5335550ee1c9ff87fd54ba4 (diff) | |
download | fluxbox_lack-f6c292a406f183a12b2e327716aad5de4c0abcca.zip fluxbox_lack-f6c292a406f183a12b2e327716aad5de4c0abcca.tar.bz2 |
split Text.hh into Orientation.hh and TextUtils.{cc,hh}
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 | ||