1
// TextButton.cc for Fluxbox Window Manager
2
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
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.
22
// $Id: TextButton.cc 3961 2005-04-27 15:15:36Z simonb $
24
#include "TextButton.hh"
26
#include "GContext.hh"
30
TextButton::TextButton(const FbTk::FbWindow &parent,
31
const FbTk::Font &font,
32
const std::string &text):
33
FbTk::Button(parent, 0, 0, 10, 10),
36
m_justify(FbTk::LEFT), m_bevel(1),
43
void TextButton::resize(unsigned int width, unsigned int height) {
44
if (this->width() == width && height == this->height())
47
Button::resize(width, height);
50
void TextButton::moveResize(int x, int y,
51
unsigned int width, unsigned int height) {
52
if (this->width() == width && height == this->height() &&
53
x == this->x() && y == this->y())
56
Button::moveResize(x, y, width, height);
59
void TextButton::setJustify(FbTk::Justify just) {
63
void TextButton::setText(const std::string &text) {
66
updateBackground(false);
71
void TextButton::setFont(const FbTk::Font &font) {
72
// no need to set new font if it's the same
78
/// set bevel and redraw text
79
void TextButton::setBevel(int bevel) {
85
void TextButton::setTextPaddingLeft(unsigned int leftpadding) {
86
m_left_padding = leftpadding;
89
void TextButton::setTextPaddingRight(unsigned int rightpadding) {
90
m_right_padding = rightpadding;
93
void TextButton::setTextPadding(unsigned int padding) {
94
setTextPaddingLeft(padding/2);
95
setTextPaddingRight(padding/2);
98
/// clear window and redraw text
99
void TextButton::clear() {
100
TextButton::clearArea(0, 0,
104
void TextButton::clearArea(int x, int y,
105
unsigned int width, unsigned int height,
107
Button::clearArea(x, y, width, height, exposure);
108
if (backgroundPixmap() == ParentRelative)
109
drawText(0, 0, this);
112
unsigned int TextButton::textWidth() const {
113
return font().textWidth(text().c_str(), text().size());
116
void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) {
117
// (win should always be *this, no need to check)
118
drawText(0, 0, &drawable);
121
void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) {
122
unsigned int textlen = text().size();
125
int align_x = FbTk::doAlignment(width() - x_offset - m_left_padding - m_right_padding,
129
text().c_str(), text().size(),
130
textlen); // return new text lne
132
// center text by default
133
int center_pos = height()/2 + font().ascent()/2 - 1;
138
font().drawText(*drawable,
140
gc(), // graphic context
141
text().c_str(), textlen, // string and string size
142
align_x + x_offset + m_left_padding, center_pos + y_offset); // position
146
void TextButton::exposeEvent(XExposeEvent &event) {
147
clearArea(event.x, event.y, event.width, event.height, false);
150
}; // end namespace FbTk