From f6c292a406f183a12b2e327716aad5de4c0abcca Mon Sep 17 00:00:00 2001
From: Mathias Gumz <akira at fluxbox dot org>
Date: Tue, 15 Jan 2008 08:45:57 +0100
Subject: split Text.hh into Orientation.hh and TextUtils.{cc,hh}

---
 src/ClockTool.cc          |   1 +
 src/FbTk/Button.hh        |   2 +-
 src/FbTk/Container.cc     |  32 +----------
 src/FbTk/Container.hh     |   5 +-
 src/FbTk/FbPixmap.cc      |   1 +
 src/FbTk/FbPixmap.hh      |   2 +-
 src/FbTk/Font.hh          |   2 +-
 src/FbTk/FontImp.hh       |   2 +-
 src/FbTk/ImageControl.hh  |   2 +-
 src/FbTk/Makefile.am      |   2 +-
 src/FbTk/MenuTheme.hh     |   1 -
 src/FbTk/Orientation.hh   |  34 ++++++++++++
 src/FbTk/Text.cc          |  87 ------------------------------
 src/FbTk/Text.hh          | 135 ----------------------------------------------
 src/FbTk/TextButton.cc    |   1 +
 src/FbTk/TextButton.hh    |   1 -
 src/FbTk/TextTheme.hh     |   2 +-
 src/FbTk/TextUtils.cc     |  87 ++++++++++++++++++++++++++++++
 src/FbTk/TextUtils.hh     | 133 +++++++++++++++++++++++++++++++++++++++++++++
 src/FbTk/TextureRender.cc |   1 +
 src/FbTk/TextureRender.hh |   2 +-
 src/FbTk/XmbFontImp.cc    |   1 +
 src/FbWinFrame.cc         |   1 +
 src/IconButton.cc         |   1 +
 src/SystemTray.cc         |   1 +
 src/Toolbar.cc            |   1 +
 src/ToolbarItem.hh        |   2 +-
 27 files changed, 274 insertions(+), 268 deletions(-)
 create mode 100644 src/FbTk/Orientation.hh
 delete mode 100644 src/FbTk/Text.cc
 delete mode 100644 src/FbTk/Text.hh
 create mode 100644 src/FbTk/TextUtils.cc
 create mode 100644 src/FbTk/TextUtils.hh

diff --git a/src/ClockTool.cc b/src/ClockTool.cc
index ae78266..1dd07cd 100644
--- a/src/ClockTool.cc
+++ b/src/ClockTool.cc
@@ -30,6 +30,7 @@
 
 #include "FbTk/SimpleCommand.hh"
 #include "FbTk/ImageControl.hh"
+#include "FbTk/TextUtils.hh"
 #include "FbTk/Menu.hh"
 #include "FbTk/MenuItem.hh"
 #include "FbTk/I18n.hh"
diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh
index bcf909b..99d8ee9 100644
--- a/src/FbTk/Button.hh
+++ b/src/FbTk/Button.hh
@@ -28,7 +28,7 @@
 #include "FbWindow.hh"
 #include "Command.hh"
 #include "Color.hh"
-#include "Text.hh"
+#include "Orientation.hh"
 
 namespace FbTk {
 
diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc
index 9da25c6..0c9b6ac 100644
--- a/src/FbTk/Container.cc
+++ b/src/FbTk/Container.cc
@@ -23,6 +23,7 @@
 #include "Container.hh"
 
 #include "Button.hh"
+#include "TextUtils.hh"
 #include "EventManager.hh"
 #include "CompareEqual.hh"
 
@@ -62,37 +63,6 @@ void Container::moveResize(int x, int y,
     repositionItems();
 }
 
-#ifdef NOT_USED
-void Container::insertItems(ItemList &item_list, int pos) {
-
-    // make sure all items have parent == this
-    ItemList::iterator it = m_item_list.begin();
-    ItemList::iterator it_end = m_item_list.end();
-    for (; it != it_end; ++it) {
-        if ((*it)->parent() != this)
-            return;
-    }
-
-    if (pos > size() || pos < 0) {
-        // insert last
-        m_item_list.splice(m_item_list.end(), item_list);
-    } else if (pos == 0) {
-        // insert first
-        m_item_list.splice(m_item_list.begin(), item_list);
-    } else {
-        // find insert point
-        for (it = m_item_list.begin(); pos != 0; ++it, --pos)
-            continue;
-        m_item_list.splice(it, item_list);
-    }
-
-    m_item_list.unique();
-
-    // update position
-    repositionItems();
-}
-#endif
-
 void Container::insertItem(Item item, int pos) {
     if (find(item) != -1)
         return;
diff --git a/src/FbTk/Container.hh b/src/FbTk/Container.hh
index 954f929..d2b826c 100644
--- a/src/FbTk/Container.hh
+++ b/src/FbTk/Container.hh
@@ -26,7 +26,7 @@
 #include "FbWindow.hh"
 #include "EventHandler.hh"
 #include "NotCopyable.hh"
-#include "Text.hh" // for Orientation
+#include "Orientation.hh"
 
 #include <list>
 
@@ -52,9 +52,6 @@ public:
     void moveResize(int x, int y,
                     unsigned int width, unsigned int height);
 
-#ifdef NOT_USED
-    void insertItems(ItemList &list, int position=-1);
-#endif
     void insertItem(Item item, int pos = -1);
     bool removeItem(int item); // return true if something was removed
     bool removeItem(Item item); // return true if something was removed
diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc
index 9d90c5a..7c1d674 100644
--- a/src/FbTk/FbPixmap.cc
+++ b/src/FbTk/FbPixmap.cc
@@ -24,6 +24,7 @@
 #include "GContext.hh"
 #include "Transparent.hh"
 #include "FbWindow.hh"
+#include "TextUtils.hh"
 
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
diff --git a/src/FbTk/FbPixmap.hh b/src/FbTk/FbPixmap.hh
index 5c2e2b8..256f6b6 100644
--- a/src/FbTk/FbPixmap.hh
+++ b/src/FbTk/FbPixmap.hh
@@ -23,7 +23,7 @@
 #define FBTK_FBPIXMAP_HH
 
 #include "FbDrawable.hh"
-#include "Text.hh" // for Orientation
+#include "Orientation.hh"
 
 namespace FbTk {
 
diff --git a/src/FbTk/Font.hh b/src/FbTk/Font.hh
index 8fb493e..28bbf22 100644
--- a/src/FbTk/Font.hh
+++ b/src/FbTk/Font.hh
@@ -30,7 +30,7 @@
 
 #include "FbString.hh"
 #include "Color.hh"
-#include "Text.hh"
+#include "Orientation.hh"
 
 namespace FbTk {
 
diff --git a/src/FbTk/FontImp.hh b/src/FbTk/FontImp.hh
index bdbab48..d903a4e 100644
--- a/src/FbTk/FontImp.hh
+++ b/src/FbTk/FontImp.hh
@@ -22,7 +22,7 @@
 #ifndef FBTK_FONTIMP_HH
 #define FBTK_FONTIMP_HH
 
-#include "Text.hh"
+#include "Orientation.hh"
 #include "FbString.hh"
 
 #include <X11/Xlib.h>
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh
index 3c3cbb1..a8e18b7 100644
--- a/src/FbTk/ImageControl.hh
+++ b/src/FbTk/ImageControl.hh
@@ -25,7 +25,7 @@
 #ifndef FBTK_IMAGECONTROL_HH
 #define FBTK_IMAGECONTROL_HH
 
-#include "Text.hh" // actually, Text is rather tool like, that's where orientation comes from
+#include "Orientation.hh"
 #include "Timer.hh"
 #include "NotCopyable.hh"
 
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 0fdb155..6fa874a 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -30,7 +30,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
 	MenuTheme.hh MenuTheme.cc NotCopyable.hh \
 	BorderTheme.hh BorderTheme.cc TextTheme.hh TextTheme.cc \
 	RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \
-	Text.hh Text.cc \
+	TextUtils.hh TextUtils.cc Orientation.hh \
 	Texture.cc Texture.hh TextureRender.hh TextureRender.cc \
 	Shape.hh Shape.cc \
 	Theme.hh Theme.cc ThemeItems.cc Timer.hh Timer.cc \
diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh
index 273104c..70fc9b8 100644
--- a/src/FbTk/MenuTheme.hh
+++ b/src/FbTk/MenuTheme.hh
@@ -27,7 +27,6 @@
 #include "Font.hh"
 #include "Shape.hh"
 #include "Texture.hh"
-#include "Text.hh"
 #include "PixmapWithMask.hh"
 #include "GContext.hh"
 
diff --git a/src/FbTk/Orientation.hh b/src/FbTk/Orientation.hh
new file mode 100644
index 0000000..bf6bd69
--- /dev/null
+++ b/src/FbTk/Orientation.hh
@@ -0,0 +1,34 @@
+// Orientation.hh for FbTk
+// Copyright (c) 2008 Henrik Kinnunen (fluxgen at fluxbox dot org)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef FBTK_ORIENTATION_HH
+#define FBTK_ORIENTATION_HH
+
+namespace FbTk {
+
+enum Justify {LEFT, RIGHT, CENTER};
+
+// clockwise
+enum Orientation { ROT0=0, ROT90, ROT180, ROT270 };
+
+} // end namespace FbTk
+
+#endif // FBTK_ORIENTATION_HH
diff --git a/src/FbTk/Text.cc b/src/FbTk/Text.cc
deleted file mode 100644
index 710b48a..0000000
--- a/src/FbTk/Text.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-// Text.cc for FbTk - text utils
-// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-
-#include "Text.hh"
-
-#include "Font.hh"
-#include "Theme.hh"
-
-#include <strings.h>
-
-namespace FbTk {
-
-int doAlignment(int max_width, int bevel, FbTk::Justify justify,
-                const FbTk::Font &font, const char * const text,
-                unsigned int textlen, unsigned int &newlen) {
-
-    if (text == 0 || textlen == 0)
-        return 0;
-
-    int l = font.textWidth(text, textlen) + bevel;
-    unsigned int dlen = textlen;
-    int dx = bevel;
-    if (l > max_width) {
-        for (; dlen > 0; dlen--) {
-            l = font.textWidth(text, dlen) + bevel;
-            if (l<=max_width)
-                break;
-        }
-    }
-
-    newlen = dlen;
-
-    switch (justify) {
-    case FbTk::RIGHT:
-        dx = max_width - l - bevel;
-    break;
-    case FbTk::CENTER:
-        dx = (max_width - l)/2;
-    break;
-    case FbTk::LEFT:
-    break;
-    }
-
-    return dx;
-}
-
-
-/// specialization for Justify
-template <>
-void ThemeItem<FbTk::Justify>::setDefaultValue() {
-    m_value = LEFT;
-}
-
-template <>
-void ThemeItem<FbTk::Justify>::setFromString(const char *value) {
-    if (strcasecmp("center", value) == 0)
-        m_value = FbTk::CENTER;
-    else if (strcasecmp("right", value) == 0)
-        m_value = FbTk::RIGHT;
-    else // default
-        setDefaultValue();
-}
-
-// do nothing
-template <>
-void ThemeItem<FbTk::Justify>::load(const std::string *name, const std::string *altname) {
-}
-
-}; // end namespace FbTk
diff --git a/src/FbTk/Text.hh b/src/FbTk/Text.hh
deleted file mode 100644
index 494d365..0000000
--- a/src/FbTk/Text.hh
+++ /dev/null
@@ -1,135 +0,0 @@
-// Text.hh for FbTk - text utils
-// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-
-#ifndef FBTK_TEXT_HH
-#define FBTK_TEXT_HH
-
-namespace FbTk {
-
-class Font;
-
-enum Justify {LEFT, RIGHT, CENTER};
-// clockwise
-enum Orientation { ROT0=0, ROT90, ROT180, ROT270 };
-
-/**
-   Aligns the text after max width and bevel
- */
-int doAlignment(int max_width, int bevel, FbTk::Justify justify, 
-                const FbTk::Font &font, const char * const text, 
-                unsigned int textlen, unsigned int &newlen);
-
-/**
-   There are 3 interesting translations:
-   1) Coords = simple rotation of coordinates
-   2) Position = adjusting (x,y) coordinates to use to position a box with X coords
-   3) Size = swapping of width and height if necessary
- */
-
-
-// translate coordinates from ROT0 into different orientations
-// coords are relative to rot0 0,0 position
-// Need width and height of the area being rotated (in ROT0 coords)
-
-inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w, unsigned int h) {
-
-    int orig_x = x;
-    int orig_y = y;
-
-    switch(orient) {
-    case ROT0:
-        break;
-    case ROT90:
-        x = h - orig_y;
-        y = orig_x;
-        break;
-    case ROT180:
-        x = w - orig_x;
-        y = h - orig_y;
-        break;
-    case ROT270:
-        x = orig_y;
-        y = w - orig_x;
-        break;
-    }
-
-}
-
-// still require w and h in ROT0 coords
-inline void untranslateCoords(Orientation orient, int orig_x, int orig_y, unsigned int w, unsigned int h) {
-
-    int x = orig_x;
-    int y = orig_y;
-
-    switch(orient) {
-    case ROT0:
-        break;
-    case ROT90:
-        orig_y = h - x;
-        orig_x = y;
-        break;
-    case ROT180:
-        orig_x = w - x;
-        orig_y = h - y;
-        break;
-    case ROT270:
-        orig_y = x;
-        orig_x = w - y;
-        break;
-    }
-
-}
-
-// When positioning an X11 box inside another area, we need to
-// relocate the x,y coordinates
-inline void translatePosition(Orientation orient, int x, int y, unsigned int w, unsigned int h, unsigned int bw) {
-
-    switch(orient) {
-    case ROT0:
-        break;
-    case ROT90:
-        x -= h + 2*bw;
-        break;
-    case ROT180:
-        x -= w + 2*bw;
-        y -= h + 2*bw;
-        break;
-    case ROT270:
-        y -= w + 2*bw;
-        break;
-    }
-
-}
-
-inline void translateSize(Orientation orient, unsigned int w, unsigned int h) {
-    if (orient == ROT0 || orient == ROT180)
-        return;
-
-    unsigned int tmp;
-    tmp = w;
-    w = h;
-    h = tmp;
-
-}
-
-} // end namespace FbTk
-
-#endif // FBTK_TEXT_HH
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc
index 85ac5c8..5a7afa6 100644
--- a/src/FbTk/TextButton.cc
+++ b/src/FbTk/TextButton.cc
@@ -20,6 +20,7 @@
 // DEALINGS IN THE SOFTWARE.
 
 #include "TextButton.hh"
+#include "TextUtils.hh"
 #include "Font.hh"
 #include "GContext.hh"
 
diff --git a/src/FbTk/TextButton.hh b/src/FbTk/TextButton.hh
index 50d509b..eb48e61 100644
--- a/src/FbTk/TextButton.hh
+++ b/src/FbTk/TextButton.hh
@@ -23,7 +23,6 @@
 #define FBTK_TEXTBUTTON_HH
 
 #include "Button.hh"
-#include "Text.hh"
 
 #include <string>
 
diff --git a/src/FbTk/TextTheme.hh b/src/FbTk/TextTheme.hh
index 9a83788..02adf92 100644
--- a/src/FbTk/TextTheme.hh
+++ b/src/FbTk/TextTheme.hh
@@ -26,7 +26,7 @@
 #include "Theme.hh"
 #include "Font.hh"
 #include "Color.hh"
-#include "Text.hh"
+#include "Orientation.hh"
 #include "GContext.hh"
 
 namespace FbTk {
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 @@
+// Text.cc for FbTk - text utils
+// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#include "TextUtils.hh"
+
+#include "Font.hh"
+#include "Theme.hh"
+
+#include <strings.h>
+
+namespace FbTk {
+
+int doAlignment(int max_width, int bevel, FbTk::Justify justify,
+                const FbTk::Font &font, const char * const text,
+                unsigned int textlen, unsigned int &newlen) {
+
+    if (text == 0 || textlen == 0)
+        return 0;
+
+    int l = font.textWidth(text, textlen) + bevel;
+    unsigned int dlen = textlen;
+    int dx = bevel;
+    if (l > max_width) {
+        for (; dlen > 0; dlen--) {
+            l = font.textWidth(text, dlen) + bevel;
+            if (l<=max_width)
+                break;
+        }
+    }
+
+    newlen = dlen;
+
+    switch (justify) {
+    case FbTk::RIGHT:
+        dx = max_width - l - bevel;
+    break;
+    case FbTk::CENTER:
+        dx = (max_width - l)/2;
+    break;
+    case FbTk::LEFT:
+    break;
+    }
+
+    return dx;
+}
+
+
+/// specialization for Justify
+template <>
+void ThemeItem<FbTk::Justify>::setDefaultValue() {
+    m_value = LEFT;
+}
+
+template <>
+void ThemeItem<FbTk::Justify>::setFromString(const char *value) {
+    if (strcasecmp("center", value) == 0)
+        m_value = FbTk::CENTER;
+    else if (strcasecmp("right", value) == 0)
+        m_value = FbTk::RIGHT;
+    else // default
+        setDefaultValue();
+}
+
+// do nothing
+template <>
+void ThemeItem<FbTk::Justify>::load(const std::string *name, const std::string *altname) {
+}
+
+}; // end namespace FbTk
diff --git a/src/FbTk/TextUtils.hh b/src/FbTk/TextUtils.hh
new file mode 100644
index 0000000..efb6020
--- /dev/null
+++ b/src/FbTk/TextUtils.hh
@@ -0,0 +1,133 @@
+// TextUtils.hh for FbTk - text utils
+// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef FBTK_TEXTUTILS_HH
+#define FBTK_TEXTUTILS_HH
+
+#include "Orientation.hh"
+
+namespace FbTk {
+
+class Font;
+
+/**
+   Aligns the text after max width and bevel
+ */
+int doAlignment(int max_width, int bevel, FbTk::Justify justify, 
+                const FbTk::Font &font, const char * const text, 
+                unsigned int textlen, unsigned int &newlen);
+
+/**
+   There are 3 interesting translations:
+   1) Coords = simple rotation of coordinates
+   2) Position = adjusting (x,y) coordinates to use to position a box with X coords
+   3) Size = swapping of width and height if necessary
+ */
+
+
+// translate coordinates from ROT0 into different orientations
+// coords are relative to rot0 0,0 position
+// Need width and height of the area being rotated (in ROT0 coords)
+
+inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w, unsigned int h) {
+
+    int orig_x = x;
+    int orig_y = y;
+
+    switch(orient) {
+    case ROT0:
+        break;
+    case ROT90:
+        x = h - orig_y;
+        y = orig_x;
+        break;
+    case ROT180:
+        x = w - orig_x;
+        y = h - orig_y;
+        break;
+    case ROT270:
+        x = orig_y;
+        y = w - orig_x;
+        break;
+    }
+
+}
+
+// still require w and h in ROT0 coords
+inline void untranslateCoords(Orientation orient, int orig_x, int orig_y, unsigned int w, unsigned int h) {
+
+    int x = orig_x;
+    int y = orig_y;
+
+    switch(orient) {
+    case ROT0:
+        break;
+    case ROT90:
+        orig_y = h - x;
+        orig_x = y;
+        break;
+    case ROT180:
+        orig_x = w - x;
+        orig_y = h - y;
+        break;
+    case ROT270:
+        orig_y = x;
+        orig_x = w - y;
+        break;
+    }
+
+}
+
+// When positioning an X11 box inside another area, we need to
+// relocate the x,y coordinates
+inline void translatePosition(Orientation orient, int x, int y, unsigned int w, unsigned int h, unsigned int bw) {
+
+    switch(orient) {
+    case ROT0:
+        break;
+    case ROT90:
+        x -= h + 2*bw;
+        break;
+    case ROT180:
+        x -= w + 2*bw;
+        y -= h + 2*bw;
+        break;
+    case ROT270:
+        y -= w + 2*bw;
+        break;
+    }
+
+}
+
+inline void translateSize(Orientation orient, unsigned int w, unsigned int h) {
+    if (orient == ROT0 || orient == ROT180)
+        return;
+
+    unsigned int tmp;
+    tmp = w;
+    w = h;
+    h = tmp;
+
+}
+
+} // end namespace FbTk
+
+#endif // FBTK_TEXTUTILS_HH
diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc
index c7c29c1..a4bb50c 100644
--- a/src/FbTk/TextureRender.cc
+++ b/src/FbTk/TextureRender.cc
@@ -25,6 +25,7 @@
 #include "TextureRender.hh"
 
 #include "ImageControl.hh"
+#include "TextUtils.hh"
 #include "Texture.hh"
 #include "App.hh"
 #include "FbPixmap.hh"
diff --git a/src/FbTk/TextureRender.hh b/src/FbTk/TextureRender.hh
index ab03252..cfedba5 100644
--- a/src/FbTk/TextureRender.hh
+++ b/src/FbTk/TextureRender.hh
@@ -25,7 +25,7 @@
 #ifndef FBTK_TEXTURRENDER_HH
 #define FBTK_TEXTURRENDER_HH
 
-#include "Text.hh"
+#include "Orientation.hh"
 
 #include <X11/Xlib.h>
 
diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc
index 8ef0fbc..e05609c 100644
--- a/src/FbTk/XmbFontImp.cc
+++ b/src/FbTk/XmbFontImp.cc
@@ -22,6 +22,7 @@
 #include "XmbFontImp.hh"
 
 #include "App.hh"
+#include "TextUtils.hh"
 #include "StringUtil.hh"
 #include "FbPixmap.hh"
 #include "GContext.hh"
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index ea1236a..234364e 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -28,6 +28,7 @@
 #include "FbTk/Compose.hh"
 #include "FbTk/Transparent.hh"
 #include "FbTk/CompareEqual.hh"
+#include "FbTk/TextUtils.hh"
 
 #include "FbWinFrameTheme.hh"
 #include "Screen.hh"
diff --git a/src/IconButton.cc b/src/IconButton.cc
index 2df741a..09791c8 100644
--- a/src/IconButton.cc
+++ b/src/IconButton.cc
@@ -30,6 +30,7 @@
 #include "FbTk/Command.hh"
 #include "FbTk/EventManager.hh"
 #include "FbTk/ImageControl.hh"
+#include "FbTk/TextUtils.hh"
 #include "FbTk/MacroCommand.hh"
 #include "FbTk/Menu.hh"
 #include "FbTk/RefCount.hh"
diff --git a/src/SystemTray.cc b/src/SystemTray.cc
index 5ba89c3..5aa7323 100644
--- a/src/SystemTray.cc
+++ b/src/SystemTray.cc
@@ -23,6 +23,7 @@
 
 #include "FbTk/EventManager.hh"
 #include "FbTk/ImageControl.hh"
+#include "FbTk/TextUtils.hh"
 
 #include "AtomHandler.hh"
 #include "fluxbox.hh"
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 18f07fc..89ec898 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -45,6 +45,7 @@
 
 #include "FbTk/I18n.hh"
 #include "FbTk/ImageControl.hh"
+#include "FbTk/TextUtils.hh"
 #include "FbTk/MacroCommand.hh"
 #include "FbTk/EventManager.hh"
 #include "FbTk/SimpleCommand.hh"
diff --git a/src/ToolbarItem.hh b/src/ToolbarItem.hh
index c4327b2..4a92c97 100644
--- a/src/ToolbarItem.hh
+++ b/src/ToolbarItem.hh
@@ -24,7 +24,7 @@
 #define TOOLBARITEM_HH
 
 #include "FbTk/Subject.hh"
-#include "FbTk/Text.hh" // orientation
+#include "FbTk/Orientation.hh"
 
 /// An item in the toolbar that has either fixed or relative size to the toolbar
 class ToolbarItem {
-- 
cgit v0.11.2