summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2002-12-18 02:28:44 +0000
committerDana Jansens <danakj@orodu.net>2002-12-18 02:28:44 +0000
commit70eb03ad50e1a71fd64c8cb1ebabbff311850553 (patch)
tree0cef2e44f7e97c0d00281df8746e7fb7f2c15f5f /otk
parent6bf858e4f4fc19914a36d51546278e6464ec00e0 (diff)
add an OBBackgroundWidget and use it for setting colors so far.
Diffstat (limited to 'otk')
-rw-r--r--otk/button.cc1
-rw-r--r--otk/focuslabel.cc1
-rw-r--r--otk/focuswidget.cc40
-rw-r--r--otk/focuswidget.hh11
-rw-r--r--otk/label.cc2
-rw-r--r--otk/label.hh2
-rw-r--r--otk/widget.cc53
-rw-r--r--otk/widget.hh24
8 files changed, 94 insertions, 40 deletions
diff --git a/otk/button.cc b/otk/button.cc
index fd23a569..2b174582 100644
--- a/otk/button.cc
+++ b/otk/button.cc
@@ -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()
diff --git a/otk/focuslabel.cc b/otk/focuslabel.cc
index 007c7957..c4f124e6 100644
--- a/otk/focuslabel.cc
+++ b/otk/focuslabel.cc
@@ -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()
diff --git a/otk/focuswidget.cc b/otk/focuswidget.cc
index 22a6100b..f5b176bf 100644
--- a/otk/focuswidget.cc
+++ b/otk/focuswidget.cc
@@ -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;
+}
+
}
diff --git a/otk/focuswidget.hh b/otk/focuswidget.hh
index d33d2abf..2a97c6aa 100644
--- a/otk/focuswidget.hh
+++ b/otk/focuswidget.hh
@@ -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;
};
}
diff --git a/otk/label.cc b/otk/label.cc
index fa12a0fa..ceb6a49c 100644
--- a/otk/label.cc
+++ b/otk/label.cc
@@ -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()
diff --git a/otk/label.hh b/otk/label.hh
index 0dd81442..f80f76c7 100644
--- a/otk/label.hh
+++ b/otk/label.hh
@@ -19,7 +19,7 @@ public:
void update(void);
virtual void setStyle(Style *style);
-
+
private:
//! Object used by Xft to render to the drawable
XftDraw *_xftdraw;
diff --git a/otk/widget.cc b/otk/widget.cc
index 6423a7af..2c3c6058 100644
--- a/otk/widget.cc
+++ b/otk/widget.cc
@@ -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);
diff --git a/otk/widget.hh b/otk/widget.hh
index 249a4e28..5f1553c3 100644
--- a/otk/widget.hh
+++ b/otk/widget.hh
@@ -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);
@@ -76,7 +77,19 @@ public:
inline BTexture *getTexture(void) const { return _texture; }
virtual void setTexture(BTexture *texture)
- { _texture = texture; _dirty = true; }
+ { _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;
};
}