add an OBBackgroundWidget and use it for setting colors so far.

This commit is contained in:
Dana Jansens 2002-12-18 02:28:44 +00:00
parent 6bf858e4f4
commit 70eb03ad50
14 changed files with 222 additions and 72 deletions

View file

@ -12,7 +12,6 @@ OtkButton::OtkButton(OtkWidget *parent)
: OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
_pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
{
setStyle(getStyle());
}
OtkButton::~OtkButton()

View file

@ -16,7 +16,6 @@ OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
_xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
info->getColormap());
setStyle(getStyle());
}
OtkFocusLabel::~OtkFocusLabel()

View file

@ -9,44 +9,44 @@
namespace otk {
OtkFocusWidget::OtkFocusWidget(OtkWidget *parent, Direction direction)
: OtkWidget(parent, direction), _unfocus_texture(0), _focused(true)
: OtkWidget(parent, direction), _unfocus_texture(0), _unfocus_bcolor(0)
{
_focused = true;
_focus_texture = parent->getTexture();
_focus_bcolor = parent->getBorderColor();
}
OtkFocusWidget::~OtkFocusWidget()
{
}
#include <stdio.h>
void OtkFocusWidget::focus(void)
{
if (_focused)
if (!isVisible() || _focused)
return;
// XXX: what about OtkWidget::focus()
printf("FOCUS\n");
OtkWidget::focus();
if (_focus_bcolor)
OtkWidget::setBorderColor(_focus_bcolor);
assert(_focus_texture);
OtkWidget::setTexture(_focus_texture);
OtkWidget::update();
OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
OtkWidget::OtkWidgetList::iterator it = children.begin(),
end = children.end();
OtkFocusWidget *tmp = 0;
for (; it != end; ++it) {
tmp = dynamic_cast<OtkFocusWidget*>(*it);
if (tmp) tmp->focus();
}
}
void OtkFocusWidget::unfocus(void)
{
if (! _focused)
if (!isVisible() || !_focused)
return;
assert(_unfocus_texture);
printf("UNFOCUS\n");
OtkWidget::unfocus();
if (_unfocus_bcolor)
OtkWidget::setBorderColor(_unfocus_bcolor);
OtkWidget::setTexture(_unfocus_texture);
OtkWidget::update();
@ -68,4 +68,10 @@ void OtkFocusWidget::setTexture(BTexture *texture)
_focus_texture = texture;
}
void OtkFocusWidget::setBorderColor(const BColor *color)
{
OtkWidget::setBorderColor(color);
_focus_bcolor = color;
}
}

View file

@ -16,13 +16,19 @@ public:
virtual void focus(void);
virtual void unfocus(void);
void setTexture(BTexture *texture);
virtual void setTexture(BTexture *texture);
virtual void setBorderColor(const BColor *color);
inline void setUnfocusTexture(BTexture *texture)
{ _unfocus_texture = texture; }
inline BTexture *getUnfocusTexture(void) const
{ return _unfocus_texture; }
inline void setUnfocusBorderColor(const BColor *color)
{ _unfocus_bcolor = color; }
inline const BColor *getUnfocusBorderColor(void) const
{ return _unfocus_bcolor; }
inline bool isFocused(void) const { return _focused; }
inline bool isUnfocused(void) const { return !_focused; }
@ -31,7 +37,8 @@ private:
BTexture *_unfocus_texture;
BTexture *_focus_texture;
bool _focused;
const BColor *_unfocus_bcolor;
const BColor *_focus_bcolor;
};
}

View file

@ -14,8 +14,6 @@ OtkLabel::OtkLabel(OtkWidget *parent)
const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
_xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
info->getColormap());
setStyle(getStyle());
}
OtkLabel::~OtkLabel()

View file

@ -16,38 +16,40 @@ namespace otk {
OtkWidget::OtkWidget(OtkWidget *parent, Direction direction)
: OtkEventHandler(),
_dirty(false),
_dirty(false), _focused(false),
_parent(parent), _style(parent->getStyle()), _direction(direction),
_cursor(parent->getCursor()), _bevel_width(parent->getBevelWidth()),
_ignore_config(0),
_visible(false), _focused(false), _grabbed_mouse(false),
_visible(false), _grabbed_mouse(false),
_grabbed_keyboard(false), _stretchable_vert(false),
_stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
_screen(parent->getScreen()), _fixed_width(false), _fixed_height(false),
_event_dispatcher(parent->getEventDispatcher()), _application(0)
_bcolor(0), _bwidth(0), _screen(parent->getScreen()), _fixed_width(false),
_fixed_height(false), _event_dispatcher(parent->getEventDispatcher())
{
assert(parent);
parent->addChild(this);
create();
_event_dispatcher->registerHandler(_window, this);
setStyle(_style); // let the widget initialize stuff
}
OtkWidget::OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style,
Direction direction, Cursor cursor, int bevel_width)
: OtkEventHandler(),
_dirty(false),
_dirty(false),_focused(false),
_parent(0), _style(style), _direction(direction), _cursor(cursor),
_bevel_width(bevel_width), _ignore_config(0), _visible(false),
_focused(false), _grabbed_mouse(false), _grabbed_keyboard(false),
_grabbed_mouse(false), _grabbed_keyboard(false),
_stretchable_vert(false), _stretchable_horz(false), _texture(0),
_bg_pixmap(0), _bg_pixel(0), _screen(style->getScreen()),
_fixed_width(false), _fixed_height(false),
_event_dispatcher(event_dispatcher), _application(0)
_bg_pixmap(0), _bg_pixel(0), _bcolor(0), _bwidth(0),
_screen(style->getScreen()), _fixed_width(false), _fixed_height(false),
_event_dispatcher(event_dispatcher)
{
assert(event_dispatcher);
assert(style);
create();
_event_dispatcher->registerHandler(_window, this);
setStyle(_style); // let the widget initialize stuff
}
OtkWidget::~OtkWidget()
@ -185,11 +187,28 @@ void OtkWidget::hide(bool recursive)
void OtkWidget::focus(void)
{
if (! _visible)
/* if (! _visible)
return;
XSetInputFocus(otk::OBDisplay::display, _window, RevertToPointerRoot,
CurrentTime);
CurrentTime);*/
_focused = true;
OtkWidget::OtkWidgetList::iterator it = _children.begin(),
end = _children.end();
for (; it != end; ++it)
(*it)->focus();
}
void OtkWidget::unfocus(void)
{
_focused = false;
OtkWidget::OtkWidgetList::iterator it = _children.begin(),
end = _children.end();
for (; it != end; ++it)
(*it)->unfocus();
}
bool OtkWidget::grabMouse(void)
@ -419,12 +438,22 @@ void OtkWidget::removeChild(OtkWidget *child)
if (it != _children.end())
_children.erase(it);
}
#include <stdio.h>
void OtkWidget::setStyle(Style *style)
{
assert(style);
_style = style;
_dirty = true;
// reset textures/colors
if (_focused) {
unfocus();
focus();
} else {
focus();
unfocus();
}
OtkWidgetList::iterator it, end = _children.end();
for (it = _children.begin(); it != end; ++it)
(*it)->setStyle(style);

View file

@ -65,6 +65,7 @@ public:
inline bool isFocused(void) const { return _focused; };
virtual void focus(void);
virtual void unfocus(void);
inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
bool grabMouse(void);
@ -78,6 +79,18 @@ public:
virtual void setTexture(BTexture *texture)
{ _texture = texture; _dirty = true; }
inline const BColor *getBorderColor(void) const { return _bcolor; }
virtual void setBorderColor(const BColor *color) {
assert(color); _bcolor = color;
XSetWindowBorder(OBDisplay::display, _window, color->pixel());
}
inline int getBorderWidth(void) const { return _bwidth; }
void setBorderWidth(int width) {
_bwidth = width;
XSetWindowBorderWidth(OBDisplay::display, _window, width);
}
virtual void addChild(OtkWidget *child, bool front = false);
virtual void removeChild(OtkWidget *child);
@ -112,11 +125,13 @@ public:
protected:
bool _dirty;
bool _focused;
virtual void adjust(void);
private:
void create(void);
void adjust(void);
void adjustHorz(void);
void adjustVert(void);
void internalResize(int width, int height);
@ -134,7 +149,6 @@ private:
int _ignore_config;
bool _visible;
bool _focused;
bool _grabbed_mouse;
bool _grabbed_keyboard;
@ -146,6 +160,9 @@ private:
Pixmap _bg_pixmap;
unsigned int _bg_pixel;
const BColor *_bcolor;
unsigned int _bwidth;
Rect _rect;
unsigned int _screen;
@ -155,7 +172,6 @@ private:
bool _unmanaged;
OtkEventDispatcher *_event_dispatcher;
OtkApplication *_application;
};
}

View file

@ -16,7 +16,7 @@ bin_PROGRAMS= openbox3
openbox3_LDADD=../otk/libotk.a @LIBINTL@
openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \
main.cc rootwindow.cc
main.cc rootwindow.cc backgroundwidget.cc
MAINTAINERCLEANFILES= Makefile.in

57
src/backgroundwidget.cc Normal file
View file

@ -0,0 +1,57 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
#include "backgroundwidget.hh"
namespace ob {
OBBackgroundWidget::OBBackgroundWidget(otk::OtkWidget *parent,
OBWidget::WidgetType type)
: otk::OtkFocusWidget(parent),
OBWidget(type)
{
}
OBBackgroundWidget::~OBBackgroundWidget()
{
}
void OBBackgroundWidget::setStyle(otk::Style *style)
{
switch (type()) {
case Type_Titlebar:
setTexture(style->getTitleFocus());
setUnfocusTexture(style->getTitleUnfocus());
setBorderColor(style->getBorderColor());
break;
case Type_Handle:
setTexture(style->getHandleFocus());
setUnfocusTexture(style->getHandleUnfocus());
setBorderColor(style->getBorderColor());
break;
case Type_Plate:
setBorderColor(&style->getFrameFocus()->color());
setUnfocusBorderColor(&style->getFrameUnfocus()->color());
break;
default:
assert(false); // there's no other background widgets!
}
otk::OtkFocusWidget::setStyle(style);
}
void OBBackgroundWidget::adjust()
{
otk::OtkFocusWidget::adjust();
// XXX: adjust shit
}
}

25
src/backgroundwidget.hh Normal file
View file

@ -0,0 +1,25 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __obbackgroundwidget_hh
#define __obbackgroundwidget_hh
#include "otk/focuswidget.hh"
#include "widget.hh"
namespace ob {
class OBBackgroundWidget : public otk::OtkFocusWidget, public OBWidget
{
private:
public:
OBBackgroundWidget(otk::OtkWidget *parent, OBWidget::WidgetType type);
virtual ~OBBackgroundWidget();
virtual void setStyle(otk::Style *style);
virtual void adjust();
};
}
#endif // __obbackgroundwidget_hh

View file

@ -25,14 +25,14 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
: otk::OtkWidget(Openbox::instance, style),
_client(client),
_screen(otk::OBDisplay::screenInfo(client->screen())),
_plate(this),
_titlebar(this),
_plate(this, OBWidget::Type_Plate),
_titlebar(this, OBWidget::Type_Titlebar),
_button_close(&_titlebar),
_button_iconify(&_titlebar),
_button_max(&_titlebar),
_button_stick(&_titlebar),
_label(&_titlebar),
_handle(this),
_handle(this, OBWidget::Type_Handle),
_grip_left(&_handle),
_grip_right(&_handle),
_decorations(client->decorations())
@ -57,8 +57,6 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
_grip_left.setCursor(Openbox::instance->cursors().ll_angle);
_grip_right.setCursor(Openbox::instance->cursors().lr_angle);
_plate.show();
_button_close.setText("X");
_button_iconify.setText("I");
_button_max.setText("M");
@ -68,6 +66,10 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
_style = 0;
setStyle(style);
//XXX: uncomment me unfocus(); // stuff starts out focused in otk
_plate.show(); // the other stuff is shown based on decor settings
grabClient();
}
@ -93,11 +95,6 @@ void OBFrame::setStyle(otk::Style *style)
_grip_right.setPressedFocusTexture(style->getGripFocus());
_grip_right.setPressedUnfocusTexture(style->getGripUnfocus());
_titlebar.setTexture(style->getTitleFocus());
_titlebar.setUnfocusTexture(style->getTitleUnfocus());
_handle.setTexture(style->getHandleFocus());
_handle.setUnfocusTexture(style->getHandleUnfocus());
// if a style was previously set, then 'replace' is true, cause we're
// replacing a style
bool replace = (_style);
@ -109,19 +106,12 @@ void OBFrame::setStyle(otk::Style *style)
_style = style;
// XXX: change when focus changes!
XSetWindowBorder(otk::OBDisplay::display, _plate.getWindow(),
_style->getFrameFocus()->color().pixel());
XSetWindowBorder(otk::OBDisplay::display, getWindow(),
_style->getBorderColor()->pixel());
XSetWindowBorder(otk::OBDisplay::display, _titlebar.getWindow(),
_style->getBorderColor()->pixel());
XSetWindowBorder(otk::OBDisplay::display, _grip_left.getWindow(),
_style->getBorderColor()->pixel());
XSetWindowBorder(otk::OBDisplay::display, _grip_right.getWindow(),
_style->getBorderColor()->pixel());
XSetWindowBorder(otk::OBDisplay::display, _handle.getWindow(),
_style->getBorderColor()->pixel());
// if !replace, then adjust() will get called after the client is grabbed!
if (replace) {
@ -151,16 +141,13 @@ void OBFrame::adjustSize()
cbwidth;
width = _client->area().width() + cbwidth * 2;
XSetWindowBorderWidth(otk::OBDisplay::display, _plate.getWindow(), cbwidth);
_plate.setBorderWidth(cbwidth);
XSetWindowBorderWidth(otk::OBDisplay::display, getWindow(), bwidth);
XSetWindowBorderWidth(otk::OBDisplay::display, _titlebar.getWindow(),
bwidth);
XSetWindowBorderWidth(otk::OBDisplay::display, _grip_left.getWindow(),
bwidth);
XSetWindowBorderWidth(otk::OBDisplay::display, _grip_right.getWindow(),
bwidth);
XSetWindowBorderWidth(otk::OBDisplay::display, _handle.getWindow(), bwidth);
setBorderWidth(bwidth);
_titlebar.setBorderWidth(bwidth);
_grip_left.setBorderWidth(bwidth);
_grip_right.setBorderWidth(bwidth);
_handle.setBorderWidth(bwidth);
if (_decorations & OBClient::Decor_Titlebar) {
// set the titlebar size

View file

@ -10,6 +10,7 @@ extern "C" {
}
#include "client.hh"
#include "backgroundwidget.hh"
#include "otk/strut.hh"
#include "otk/rect.hh"
#include "otk/screeninfo.hh"
@ -49,14 +50,14 @@ private:
otk::Strut _innersize;
// decoration windows
otk::OtkFocusWidget _plate; // sits entirely under the client window
otk::OtkFocusWidget _titlebar;
OBBackgroundWidget _plate; // sits entirely under the client window
OBBackgroundWidget _titlebar;
otk::OtkButton _button_close;
otk::OtkButton _button_iconify;
otk::OtkButton _button_max;
otk::OtkButton _button_stick;
otk::OtkFocusLabel _label;
otk::OtkFocusWidget _handle;
OBBackgroundWidget _handle;
otk::OtkButton _grip_left;
otk::OtkButton _grip_right;

26
src/widget.hh Normal file
View file

@ -0,0 +1,26 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __obwidget_hh
#define __obwidget_hh
namespace ob {
class OBWidget {
public:
enum WidgetType {
Type_Titlebar,
Type_Handle,
Type_Plate
};
private:
WidgetType _type;
public:
OBWidget(WidgetType type) : _type(type) {}
inline WidgetType type() const { return _type; }
};
}
#endif // __obwidget_hh