2003-08-11 14:32:39 +00:00
|
|
|
// WorkspaceNameTool.cc
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2003-08-11 14:32:39 +00:00
|
|
|
// and Simon Bowden (rathnor 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.
|
|
|
|
|
|
|
|
#include "WorkspaceNameTool.hh"
|
|
|
|
|
|
|
|
#include "ToolTheme.hh"
|
|
|
|
#include "Screen.hh"
|
|
|
|
#include "Workspace.hh"
|
|
|
|
|
|
|
|
#include "FbTk/ImageControl.hh"
|
2008-09-21 11:44:48 +00:00
|
|
|
#include "FbTk/MemFun.hh"
|
2003-08-11 14:32:39 +00:00
|
|
|
|
2005-04-27 09:52:30 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2003-08-11 14:32:39 +00:00
|
|
|
WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent,
|
2008-01-05 01:39:19 +00:00
|
|
|
FbTk::ThemeProxy<ToolTheme> &theme, BScreen &screen):
|
2003-08-11 14:32:39 +00:00
|
|
|
ToolbarItem(ToolbarItem::FIXED),
|
2010-09-08 18:17:21 +00:00
|
|
|
m_button(parent, theme->font(), FbTk::BiDiString("a workspace name")),
|
2003-08-11 14:32:39 +00:00
|
|
|
m_theme(theme),
|
|
|
|
m_screen(screen),
|
|
|
|
m_pixmap(0) {
|
|
|
|
// set text
|
2008-01-05 01:39:19 +00:00
|
|
|
m_button.setGC(m_theme->textGC());
|
2003-08-11 14:32:39 +00:00
|
|
|
m_button.setText(m_screen.currentWorkspace()->name());
|
2003-08-11 20:39:05 +00:00
|
|
|
|
2003-08-11 14:32:39 +00:00
|
|
|
// setup signals
|
2008-09-21 11:44:48 +00:00
|
|
|
join(screen.currentWorkspaceSig(),
|
2011-04-29 08:52:28 +00:00
|
|
|
FbTk::MemFunIgnoreArgs(*this, &WorkspaceNameTool::update));
|
2008-09-21 13:25:47 +00:00
|
|
|
join(screen.workspaceNamesSig(),
|
2011-04-29 08:52:28 +00:00
|
|
|
FbTk::MemFunIgnoreArgs(*this, &WorkspaceNameTool::update));
|
2008-09-21 11:44:48 +00:00
|
|
|
|
2011-04-29 08:52:28 +00:00
|
|
|
join(theme.reconfigSig(), FbTk::MemFun(*this, &WorkspaceNameTool::update));
|
2003-08-11 14:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceNameTool::~WorkspaceNameTool() {
|
|
|
|
if (m_pixmap)
|
|
|
|
m_screen.imageControl().removeImage(m_pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkspaceNameTool::move(int x, int y) {
|
|
|
|
m_button.move(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkspaceNameTool::resize(unsigned int width, unsigned int height) {
|
|
|
|
m_button.resize(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorkspaceNameTool::moveResize(int x, int y,
|
|
|
|
unsigned int width, unsigned int height) {
|
|
|
|
m_button.moveResize(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2011-04-29 08:52:28 +00:00
|
|
|
void WorkspaceNameTool::update() {
|
|
|
|
m_button.setText(m_screen.currentWorkspace()->name());
|
2004-08-25 17:16:40 +00:00
|
|
|
if (m_button.width() != width()) {
|
2003-08-26 23:20:07 +00:00
|
|
|
resize(width(), height());
|
2011-05-07 20:41:59 +00:00
|
|
|
resizeSig().emit();
|
2004-08-25 17:16:40 +00:00
|
|
|
}
|
2004-09-12 14:56:20 +00:00
|
|
|
reRender();
|
|
|
|
m_button.clear();
|
2003-08-11 14:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int WorkspaceNameTool::width() const {
|
|
|
|
// calculate largest size
|
2006-04-15 16:41:11 +00:00
|
|
|
if (orientation() == FbTk::ROT90 || orientation() == FbTk::ROT270)
|
|
|
|
return m_button.width();
|
2005-04-27 09:52:30 +00:00
|
|
|
unsigned int max_size = 0;
|
2006-04-15 16:41:11 +00:00
|
|
|
|
2005-04-27 09:52:30 +00:00
|
|
|
const BScreen::Workspaces& workspaces = m_screen.getWorkspacesList();
|
|
|
|
BScreen::Workspaces::const_iterator it;
|
2011-11-02 17:33:38 +00:00
|
|
|
for (it = workspaces.begin(); it != workspaces.end(); ++it) {
|
2010-09-08 18:17:21 +00:00
|
|
|
max_size = std::max(m_theme->font().textWidth((*it)->name()), max_size);
|
2003-08-11 14:32:39 +00:00
|
|
|
}
|
|
|
|
// so align text dont cut the last character
|
|
|
|
max_size += 2;
|
|
|
|
|
|
|
|
return max_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int WorkspaceNameTool::height() const {
|
2006-04-15 16:41:11 +00:00
|
|
|
if (orientation() == FbTk::ROT0 || orientation() == FbTk::ROT180)
|
|
|
|
return m_button.height();
|
|
|
|
|
|
|
|
unsigned int max_size = 0;
|
|
|
|
const BScreen::Workspaces& workspaces = m_screen.getWorkspacesList();
|
|
|
|
BScreen::Workspaces::const_iterator it;
|
2011-11-02 17:33:38 +00:00
|
|
|
for (it = workspaces.begin(); it != workspaces.end(); ++it) {
|
2010-09-08 18:17:21 +00:00
|
|
|
max_size = std::max(m_theme->font().textWidth((*it)->name()), max_size);
|
2006-04-15 16:41:11 +00:00
|
|
|
}
|
|
|
|
// so align text dont cut the last character
|
|
|
|
max_size += 2;
|
|
|
|
|
|
|
|
return max_size;
|
2003-08-11 14:32:39 +00:00
|
|
|
}
|
|
|
|
|
2003-08-13 10:19:57 +00:00
|
|
|
unsigned int WorkspaceNameTool::borderWidth() const {
|
|
|
|
return m_button.borderWidth();
|
|
|
|
}
|
2003-08-11 14:32:39 +00:00
|
|
|
|
|
|
|
void WorkspaceNameTool::show() {
|
|
|
|
m_button.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkspaceNameTool::hide() {
|
|
|
|
m_button.hide();
|
|
|
|
}
|
|
|
|
|
2004-08-29 08:33:13 +00:00
|
|
|
void WorkspaceNameTool::updateSizing() {
|
2008-01-05 01:39:19 +00:00
|
|
|
m_button.setBorderWidth(m_theme->border().width());
|
2004-08-29 08:33:13 +00:00
|
|
|
}
|
|
|
|
|
2004-09-12 14:56:20 +00:00
|
|
|
void WorkspaceNameTool::reRender() {
|
2008-01-13 01:42:52 +00:00
|
|
|
if (m_pixmap)
|
|
|
|
m_screen.imageControl().removeImage(m_pixmap);
|
|
|
|
|
2008-01-05 01:39:19 +00:00
|
|
|
if (m_theme->texture().usePixmap()) {
|
2004-09-12 14:56:20 +00:00
|
|
|
m_pixmap = m_screen.imageControl().renderImage(width(), height(),
|
2008-01-05 01:39:19 +00:00
|
|
|
m_theme->texture(), orientation());
|
2004-09-12 14:56:20 +00:00
|
|
|
m_button.setBackgroundPixmap(m_pixmap);
|
2008-01-13 01:42:52 +00:00
|
|
|
} else {
|
|
|
|
m_pixmap = 0;
|
|
|
|
m_button.setBackgroundColor(m_theme->texture().color());
|
2004-09-12 14:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-22 21:07:39 +00:00
|
|
|
void WorkspaceNameTool::renderTheme(int alpha) {
|
2005-06-07 09:01:29 +00:00
|
|
|
|
2008-01-05 01:39:19 +00:00
|
|
|
m_button.setJustify(m_theme->justify());
|
|
|
|
m_button.setBorderWidth(m_theme->border().width());
|
|
|
|
m_button.setBorderColor(m_theme->border().color());
|
2005-06-07 09:01:29 +00:00
|
|
|
m_button.setAlpha(alpha);
|
|
|
|
|
2008-01-13 01:42:52 +00:00
|
|
|
reRender();
|
2003-08-11 14:32:39 +00:00
|
|
|
m_button.clear();
|
|
|
|
}
|
2006-04-15 16:41:11 +00:00
|
|
|
|
|
|
|
void WorkspaceNameTool::setOrientation(FbTk::Orientation orient) {
|
|
|
|
m_button.setOrientation(orient);
|
|
|
|
ToolbarItem::setOrientation(orient);
|
|
|
|
}
|