From 82ac933efe4ce3b88ec32ee8f64b1c3dcc0528b1 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Mon, 13 Oct 2003 23:35:54 +0000
Subject: helper class for simple tools

---
 src/GenericTool.cc | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/GenericTool.hh | 69 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 151 insertions(+)
 create mode 100644 src/GenericTool.cc
 create mode 100644 src/GenericTool.hh

diff --git a/src/GenericTool.cc b/src/GenericTool.cc
new file mode 100644
index 0000000..aaea626
--- /dev/null
+++ b/src/GenericTool.cc
@@ -0,0 +1,82 @@
+// GenericTool.cc for Fluxbox
+// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
+//
+// 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.
+
+// $Id: GenericTool.cc,v 1.1 2003/10/13 23:35:54 fluxgen Exp $
+
+#include "GenericTool.hh"
+#include "FbTk/FbWindow.hh"
+
+#include <string>
+
+GenericTool::GenericTool(FbTk::FbWindow *new_window, ToolbarItem::Type type,
+                         ToolTheme &theme):
+    ToolbarItem(type),
+    m_window(new_window),
+    m_theme(theme) {
+
+    theme.reconfigSig().attach(this);
+
+    if (new_window == 0)
+        throw std::string("GenericTool: Error! Tried to create a tool with window = 0");
+}
+
+void GenericTool::move(int x, int y) {
+    m_window->move(x, y);
+}
+
+void GenericTool::resize(unsigned int width, unsigned int height) {
+    m_window->resize(width, height);
+}
+
+void GenericTool::moveResize(int x, int y,
+                             unsigned int width, unsigned int height) {
+    m_window->moveResize(x, y, width, height);
+}
+
+void GenericTool::show() {
+    m_window->show();
+}
+
+void GenericTool::hide() {
+    m_window->hide();
+}
+
+unsigned int GenericTool::width() const {
+    return m_window->width();
+}
+
+unsigned int GenericTool::height() const {
+    return m_window->height();
+
+}
+
+unsigned int GenericTool::borderWidth() const {
+    return m_window->borderWidth();
+}
+
+
+void GenericTool::renderTheme() {
+    m_window->clear();
+}
+
+void GenericTool::update(FbTk::Subject *subj) {
+    renderTheme();
+}
diff --git a/src/GenericTool.hh b/src/GenericTool.hh
new file mode 100644
index 0000000..5ad429c
--- /dev/null
+++ b/src/GenericTool.hh
@@ -0,0 +1,69 @@
+// GenericTool.hh for Fluxbox
+// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
+//
+// 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.
+
+// $Id: GenericTool.hh,v 1.1 2003/10/13 23:35:53 fluxgen Exp $
+
+#ifndef GENERICTOOL_HH
+#define GENERICTOOL_HH
+
+#include "ToolbarItem.hh"
+#include "ToolTheme.hh"
+
+#include "FbTk/NotCopyable.hh"
+#include "FbTk/Observer.hh"
+
+#include <memory>
+
+namespace FbTk {
+class FbWindow;
+}
+
+/// helper class for simple tools, i.e buttons etc
+class GenericTool: public ToolbarItem, public FbTk::Observer, private FbTk::NotCopyable {
+public:
+    GenericTool(FbTk::FbWindow *new_window, ToolbarItem::Type type, ToolTheme &theme);
+    virtual ~GenericTool() { }
+    void move(int x, int y);
+    void resize(unsigned int x, unsigned int y);
+    void moveResize(int x, int y,
+                    unsigned int width, unsigned int height);
+    void show();
+    void hide();
+
+    unsigned int width() const;
+    unsigned int height() const;
+    unsigned int borderWidth() const;
+
+    const ToolTheme &theme() const { return m_theme; }
+    FbTk::FbWindow &window() { return *m_window; }
+    const FbTk::FbWindow &window() const { return *m_window; }
+
+protected:
+    virtual void renderTheme();
+
+private:
+    void update(FbTk::Subject *subj);
+    
+    std::auto_ptr<FbTk::FbWindow> m_window;
+    ToolTheme &m_theme;
+};
+
+#endif // GENERICTOOL_HH
-- 
cgit v0.11.2