aboutsummaryrefslogtreecommitdiff
path: root/src/WorkspaceNameTool.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-11 14:32:39 (GMT)
committerfluxgen <fluxgen>2003-08-11 14:32:39 (GMT)
commitd45b3ad764f2854f323254a6616c93466df5445d (patch)
tree002939ca9daafa14eda54507b87bf37f6536c0c9 /src/WorkspaceNameTool.cc
parent4f51fab7afc2b7fa48e28d182336df84ffe284d2 (diff)
downloadfluxbox-d45b3ad764f2854f323254a6616c93466df5445d.zip
fluxbox-d45b3ad764f2854f323254a6616c93466df5445d.tar.bz2
basic tools for toolbar
Diffstat (limited to 'src/WorkspaceNameTool.cc')
-rw-r--r--src/WorkspaceNameTool.cc115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc
new file mode 100644
index 0000000..bc493fa
--- /dev/null
+++ b/src/WorkspaceNameTool.cc
@@ -0,0 +1,115 @@
1// WorkspaceNameTool.cc
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: WorkspaceNameTool.cc,v 1.1 2003/08/11 14:32:39 fluxgen Exp $
24
25#include "WorkspaceNameTool.hh"
26
27#include "ToolTheme.hh"
28#include "Screen.hh"
29#include "Workspace.hh"
30
31#include "FbTk/ImageControl.hh"
32
33WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent,
34 ToolTheme &theme, BScreen &screen):
35 ToolbarItem(ToolbarItem::FIXED),
36 m_button(parent, theme.font(), "a workspace name"),
37 m_theme(theme),
38 m_screen(screen),
39 m_pixmap(0) {
40 // set text
41 m_button.setText(m_screen.currentWorkspace()->name());
42 // setup signals
43 screen.currentWorkspaceSig().attach(this);
44 theme.reconfigSig().attach(this);
45}
46
47WorkspaceNameTool::~WorkspaceNameTool() {
48 if (m_pixmap)
49 m_screen.imageControl().removeImage(m_pixmap);
50}
51
52void WorkspaceNameTool::move(int x, int y) {
53 m_button.move(x, y);
54}
55
56void WorkspaceNameTool::resize(unsigned int width, unsigned int height) {
57 m_button.resize(width, height);
58}
59
60
61void WorkspaceNameTool::moveResize(int x, int y,
62 unsigned int width, unsigned int height) {
63 m_button.moveResize(x, y, width, height);
64}
65
66void WorkspaceNameTool::update(FbTk::Subject *subj) {
67 m_button.setText(m_screen.currentWorkspace()->name());
68 renderTheme();
69}
70
71unsigned int WorkspaceNameTool::width() const {
72 // calculate largest size
73 int max_size = 0;
74 const int num_workspaces = m_screen.getNumberOfWorkspaces();
75 for (int workspace = 0; workspace < num_workspaces; ++workspace) {
76 const std::string &name = m_screen.getWorkspace(workspace)->name().c_str();
77 int size = m_theme.font().textWidth(name.c_str(), name.size());
78 if (size > max_size)
79 max_size = size;
80 }
81 // so align text dont cut the last character
82 max_size += 2;
83
84 return max_size;
85}
86
87unsigned int WorkspaceNameTool::height() const {
88 return m_button.height();
89}
90
91
92void WorkspaceNameTool::show() {
93 m_button.show();
94}
95
96void WorkspaceNameTool::hide() {
97 m_button.hide();
98}
99
100void WorkspaceNameTool::renderTheme() {
101 Pixmap tmp = m_pixmap;
102 if (m_theme.texture().type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
103 m_pixmap = 0;
104 m_button.setBackgroundColor(m_theme.texture().color());
105 } else {
106 m_pixmap = m_screen.imageControl().renderImage(width(), height(),
107 m_theme.texture());
108 }
109 if (tmp)
110 m_screen.imageControl().removeImage(tmp);
111
112 m_button.setFont(m_theme.font());
113 m_button.setJustify(m_theme.justify());
114 m_button.clear();
115}