summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
Diffstat (limited to 'otk')
-rw-r--r--otk/eventdispatcher.cc68
-rw-r--r--otk/eventdispatcher.hh3
-rw-r--r--otk/focuslabel.cc6
-rw-r--r--otk/focuswidget.cc21
-rw-r--r--otk/label.cc6
-rw-r--r--otk/otk_wrap.cc43
-rw-r--r--otk/style.hh3
-rw-r--r--otk/widget.cc21
8 files changed, 72 insertions, 99 deletions
diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc
index 33d8ba2d..73c329e8 100644
--- a/otk/eventdispatcher.cc
+++ b/otk/eventdispatcher.cc
@@ -11,8 +11,10 @@
namespace otk {
OtkEventDispatcher::OtkEventDispatcher()
- : _fallback(0), _master(0)
+ : _fallback(0), _master(0), _focus(None)
{
+ _focus_e.xfocus.mode = NotifyNormal;
+ _focus_e.xfocus.detail = NotifyNonlinear;
}
OtkEventDispatcher::~OtkEventDispatcher()
@@ -36,9 +38,10 @@ void OtkEventDispatcher::clearHandler(Window id)
void OtkEventDispatcher::dispatchEvents(void)
{
- XEvent e;
- OtkEventHandler *handler;
OtkEventMap::iterator it;
+ XEvent e;
+ Window focus = _focus;
+ Window unfocus = None;
while (XPending(OBDisplay::display)) {
XNextEvent(OBDisplay::display, &e);
@@ -70,23 +73,58 @@ void OtkEventDispatcher::dispatchEvents(void)
XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
e.xconfigurerequest.value_mask, &xwc);
}
+ // madly compress all focus events
+ } else if (e.type == FocusIn) {
+ // any other types are not ones we're interested in
+ if (e.xfocus.detail == NotifyNonlinear) {
+ if (e.xfocus.window != focus) {
+ unfocus = focus;
+ focus = e.xfocus.window;
+ }
+ }
+ } else if (e.type == FocusOut) {
+ // any other types are not ones we're interested in
+ if (e.xfocus.detail == NotifyNonlinear) {
+ if (e.xfocus.window == focus) {
+ unfocus = focus;
+ focus = None;
+ }
+ }
} else {
// normal events
-
- it = _map.find(e.xany.window);
-
- if (it != _map.end())
- handler = it->second;
- else
- handler = _fallback;
-
- if (handler)
- handler->handle(e);
+ dispatch(e);
}
+ }
- if (_master)
- _master->handle(e);
+ if (focus != _focus) {
+ _focus_e.xfocus.type = FocusIn;
+ _focus_e.xfocus.window = focus;
+ dispatch(_focus_e);
+ _focus = focus;
}
+ if (unfocus != None) {
+ _focus_e.xfocus.type = FocusOut;
+ _focus_e.xfocus.window = unfocus;
+ dispatch(_focus_e);
+ }
+}
+
+void OtkEventDispatcher::dispatch(const XEvent &e) {
+ OtkEventHandler *handler;
+ OtkEventMap::iterator it;
+
+ it = _map.find(e.xany.window);
+
+ if (it != _map.end())
+ handler = it->second;
+ else
+ handler = _fallback;
+
+ if (handler)
+ handler->handle(e);
+
+ if (master)
+ master->handle(e);
}
OtkEventHandler *OtkEventDispatcher::findHandler(Window win)
diff --git a/otk/eventdispatcher.hh b/otk/eventdispatcher.hh
index a9b5af7b..716a8118 100644
--- a/otk/eventdispatcher.hh
+++ b/otk/eventdispatcher.hh
@@ -36,9 +36,12 @@ private:
OtkEventMap _map;
OtkEventHandler *_fallback;
OtkEventHandler *_master;
+ XEvent _focus_e;
//! The time at which the last XEvent with a time was received
Time _lasttime; // XXX: store this! also provide an accessor!
+
+ void dispatch(const XEvent &e);
};
}
diff --git a/otk/focuslabel.cc b/otk/focuslabel.cc
index 136eb742..a5c85127 100644
--- a/otk/focuslabel.cc
+++ b/otk/focuslabel.cc
@@ -36,7 +36,7 @@ void OtkFocusLabel::setStyle(Style *style)
void OtkFocusLabel::update(void)
{
if (_dirty) {
- const BFont &ft = style()->getFont();
+ const BFont *ft = style()->getFont();
BColor *text_color = (isFocused() ? style()->getTextFocus()
: style()->getTextUnfocus());
unsigned int sidemargin = style()->getBevelWidth() * 2;
@@ -54,7 +54,7 @@ void OtkFocusLabel::update(void)
do {
t.resize(text_len);
- length = ft.measureString(t);
+ length = ft->measureString(t);
} while (length > max_length && text_len-- > 0);
// justify the text
@@ -72,7 +72,7 @@ void OtkFocusLabel::update(void)
OtkFocusWidget::update();
- ft.drawString(_xftdraw, x, 0, *text_color, t);
+ ft->drawString(_xftdraw, x, 0, *text_color, t);
} else
OtkFocusWidget::update();
}
diff --git a/otk/focuswidget.cc b/otk/focuswidget.cc
index a5d2696d..e2eef1ee 100644
--- a/otk/focuswidget.cc
+++ b/otk/focuswidget.cc
@@ -23,43 +23,30 @@ OtkFocusWidget::~OtkFocusWidget()
#include <stdio.h>
void OtkFocusWidget::focus(void)
{
- if (!isVisible() || _focused)
+ if (_focused)
return;
- printf("FOCUS\n");
OtkWidget::focus();
if (_focus_bcolor)
OtkWidget::setBorderColor(_focus_bcolor);
OtkWidget::setTexture(_focus_texture);
- OtkWidget::update();
+ update();
}
void OtkFocusWidget::unfocus(void)
{
- if (!isVisible() || !_focused)
+ if (!_focused)
return;
- printf("UNFOCUS\n");
OtkWidget::unfocus();
if (_unfocus_bcolor)
OtkWidget::setBorderColor(_unfocus_bcolor);
OtkWidget::setTexture(_unfocus_texture);
- OtkWidget::update();
-
- OtkWidget::OtkWidgetList children = OtkWidget::children();
-
- OtkWidget::OtkWidgetList::iterator it = children.begin(),
- end = children.end();
-
- OtkFocusWidget *tmp = 0;
- for (; it != end; ++it) {
- tmp = dynamic_cast<OtkFocusWidget*>(*it);
- if (tmp) tmp->unfocus();
- }
+ update();
}
void OtkFocusWidget::setTexture(BTexture *texture)
diff --git a/otk/label.cc b/otk/label.cc
index cc67a316..4a61efd0 100644
--- a/otk/label.cc
+++ b/otk/label.cc
@@ -32,7 +32,7 @@ void OtkLabel::setStyle(Style *style)
void OtkLabel::update(void)
{
if (_dirty) {
- const BFont &ft = style()->getFont();
+ const BFont *ft = style()->getFont();
unsigned int sidemargin = style()->getBevelWidth() * 2;
std::string t = _text; // the actual text to draw
@@ -48,7 +48,7 @@ void OtkLabel::update(void)
do {
t.resize(text_len);
- length = ft.measureString(t);
+ length = ft->measureString(t);
} while (length > max_length && text_len-- > 0);
// justify the text
@@ -66,7 +66,7 @@ void OtkLabel::update(void)
OtkWidget::update();
- ft.drawString(_xftdraw, x, 0, *style()->getTextUnfocus(), t);
+ ft->drawString(_xftdraw, x, 0, *style()->getTextUnfocus(), t);
} else
OtkWidget::update();
}
diff --git a/otk/otk_wrap.cc b/otk/otk_wrap.cc
index 73f9bea6..08451e98 100644
--- a/otk/otk_wrap.cc
+++ b/otk/otk_wrap.cc
@@ -1001,42 +1001,6 @@ static PyObject *_wrap_OtkEventDispatcher_getFallbackHandler(PyObject *self, PyO
}
-static PyObject *_wrap_OtkEventDispatcher_setMasterHandler(PyObject *self, PyObject *args) {
- PyObject *resultobj;
- otk::OtkEventDispatcher *arg1 = (otk::OtkEventDispatcher *) 0 ;
- otk::OtkEventHandler *arg2 = (otk::OtkEventHandler *) 0 ;
- PyObject * obj0 = 0 ;
- PyObject * obj1 = 0 ;
-
- if(!PyArg_ParseTuple(args,(char *)"OO:OtkEventDispatcher_setMasterHandler",&obj0,&obj1)) goto fail;
- if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__OtkEventDispatcher,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
- if ((SWIG_ConvertPtr(obj1,(void **) &arg2, SWIGTYPE_p_otk__OtkEventHandler,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
- (arg1)->setMasterHandler(arg2);
-
- Py_INCREF(Py_None); resultobj = Py_None;
- return resultobj;
- fail:
- return NULL;
-}
-
-
-static PyObject *_wrap_OtkEventDispatcher_getMasterHandler(PyObject *self, PyObject *args) {
- PyObject *resultobj;
- otk::OtkEventDispatcher *arg1 = (otk::OtkEventDispatcher *) 0 ;
- otk::OtkEventHandler *result;
- PyObject * obj0 = 0 ;
-
- if(!PyArg_ParseTuple(args,(char *)"O:OtkEventDispatcher_getMasterHandler",&obj0)) goto fail;
- if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__OtkEventDispatcher,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
- result = (otk::OtkEventHandler *)((otk::OtkEventDispatcher const *)arg1)->getMasterHandler();
-
- resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__OtkEventHandler, 0);
- return resultobj;
- fail:
- return NULL;
-}
-
-
static PyObject *_wrap_OtkEventDispatcher_findHandler(PyObject *self, PyObject *args) {
PyObject *resultobj;
otk::OtkEventDispatcher *arg1 = (otk::OtkEventDispatcher *) 0 ;
@@ -11327,10 +11291,7 @@ static PyObject *_wrap_Style_getFont(PyObject *self, PyObject *args) {
if(!PyArg_ParseTuple(args,(char *)"O:Style_getFont",&obj0)) goto fail;
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__Style,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
- {
- otk::BFont const &_result_ref = ((otk::Style const *)arg1)->getFont();
- result = (otk::BFont *) &_result_ref;
- }
+ result = (otk::BFont *)((otk::Style const *)arg1)->getFont();
resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_otk__BFont, 0);
return resultobj;
@@ -12745,8 +12706,6 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"OtkEventDispatcher_dispatchEvents", _wrap_OtkEventDispatcher_dispatchEvents, METH_VARARGS },
{ (char *)"OtkEventDispatcher_setFallbackHandler", _wrap_OtkEventDispatcher_setFallbackHandler, METH_VARARGS },
{ (char *)"OtkEventDispatcher_getFallbackHandler", _wrap_OtkEventDispatcher_getFallbackHandler, METH_VARARGS },
- { (char *)"OtkEventDispatcher_setMasterHandler", _wrap_OtkEventDispatcher_setMasterHandler, METH_VARARGS },
- { (char *)"OtkEventDispatcher_getMasterHandler", _wrap_OtkEventDispatcher_getMasterHandler, METH_VARARGS },
{ (char *)"OtkEventDispatcher_findHandler", _wrap_OtkEventDispatcher_findHandler, METH_VARARGS },
{ (char *)"OtkEventDispatcher_swigregister", OtkEventDispatcher_swigregister, METH_VARARGS },
{ (char *)"OtkEventHandler_handle", _wrap_OtkEventHandler_handle, METH_VARARGS },
diff --git a/otk/style.hh b/otk/style.hh
index f7584c3e..95f9b487 100644
--- a/otk/style.hh
+++ b/otk/style.hh
@@ -16,6 +16,7 @@ namespace otk {
struct PixmapMask {
Pixmap mask;
unsigned int w, h;
+ PixmapMask() { mask = None; w = h = 0; }
};
class Style {
@@ -114,7 +115,7 @@ public:
inline unsigned int getFrameWidth(void) const { return frame_width; }
inline unsigned int getBorderWidth(void) const { return border_width; }
- inline const BFont &getFont() const { return *font; }
+ inline const BFont *getFont() const { return font; }
inline void setShadowFonts(bool fonts) { shadow_fonts = fonts; }
inline bool hasShadowFonts(void) const { return shadow_fonts; }
diff --git a/otk/widget.cc b/otk/widget.cc
index 07122bc6..e085bc9f 100644
--- a/otk/widget.cc
+++ b/otk/widget.cc
@@ -187,12 +187,6 @@ void OtkWidget::hide(bool recursive)
void OtkWidget::focus(void)
{
-/* if (! _visible)
- return;
-
- XSetInputFocus(otk::OBDisplay::display, _window, RevertToPointerRoot,
- CurrentTime);*/
-
_focused = true;
OtkWidget::OtkWidgetList::iterator it = _children.begin(),
@@ -253,7 +247,7 @@ void OtkWidget::ungrabKeyboard(void)
void OtkWidget::render(void)
{
if (!_texture) return;
-
+
_bg_pixmap = _texture->render(_rect.width(), _rect.height(), _bg_pixmap);
if (_bg_pixmap)
@@ -392,8 +386,8 @@ void OtkWidget::adjustVert(void)
void OtkWidget::update(void)
{
if (_dirty) {
- if (! _unmanaged)
- adjust();
+ if (!_unmanaged)
+ adjust();
render();
XClearWindow(OBDisplay::display, _window);
}
@@ -445,15 +439,6 @@ void OtkWidget::setStyle(Style *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);