summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llbutton.cpp5
-rw-r--r--indra/llui/llmenugl.cpp101
-rw-r--r--indra/llui/llmenugl.h7
-rw-r--r--indra/llui/llui.cpp15
-rw-r--r--indra/llui/llview.cpp65
-rw-r--r--indra/llui/llview.h22
6 files changed, 91 insertions, 124 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp
index 2bcc89b59f..8ae6dd2ea5 100644
--- a/indra/llui/llbutton.cpp
+++ b/indra/llui/llbutton.cpp
@@ -778,9 +778,8 @@ void LLButton::setToggleState(BOOL b)
{
if( b != mToggleState )
{
- mToggleState = b;
- LLValueChangedEvent *evt = new LLValueChangedEvent(this, mToggleState);
- fireEvent(evt, "");
+ setControlValue(b); // will fire LLControlVariable callbacks (if any)
+ mToggleState = b; // may or may not be redundant
}
}
diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp
index 00b4c37bb0..8c62a10f2b 100644
--- a/indra/llui/llmenugl.cpp
+++ b/indra/llui/llmenugl.cpp
@@ -827,57 +827,33 @@ void LLMenuItemCallGL::setEnabledControl(LLString enabled_control, LLView *conte
// Register new listener
if (!enabled_control.empty())
{
- LLControlBase *control = context->findControl(enabled_control);
- if (control)
- {
- LLSD state = control->registerListener(this, "ENABLED");
- setEnabled(state);
- }
- else
+ LLControlVariable *control = context->findControl(enabled_control);
+ if (!control)
{
context->addBoolControl(enabled_control, getEnabled());
control = context->findControl(enabled_control);
- control->registerListener(this, "ENABLED");
+ llassert_always(control);
}
+ control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("enabled")));
+ setEnabled(control->getValue());
}
}
-void LLMenuItemCallGL::setVisibleControl(LLString enabled_control, LLView *context)
+void LLMenuItemCallGL::setVisibleControl(LLString visible_control, LLView *context)
{
// Register new listener
- if (!enabled_control.empty())
+ if (!visible_control.empty())
{
- LLControlBase *control = context->findControl(enabled_control);
- if (control)
+ LLControlVariable *control = context->findControl(visible_control);
+ if (!control)
{
- LLSD state = control->registerListener(this, "VISIBLE");
- setVisible(state);
+ context->addBoolControl(visible_control, getVisible());
+ control = context->findControl(visible_control);
+ llassert_always(control);
}
- else
- {
- context->addBoolControl(enabled_control, getEnabled());
- control = context->findControl(enabled_control);
- control->registerListener(this, "VISIBLE");
- }
- }
-}
-
-// virtual
-bool LLMenuItemCallGL::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
-{
- if (userdata.asString() == "ENABLED" && event->desc() == "value_changed")
- {
- LLSD state = event->getValue();
- setEnabled(state);
- return TRUE;
+ control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("visible")));
+ setVisible(control->getValue());
}
- if (userdata.asString() == "VISIBLE" && event->desc() == "value_changed")
- {
- LLSD state = event->getValue();
- setVisible(state);
- return TRUE;
- }
- return LLMenuItemGL::handleEvent(event, userdata);
}
// virtual
@@ -1000,44 +976,35 @@ LLMenuItemCheckGL::LLMenuItemCheckGL ( const LLString& name,
setControlName(control_name, context);
}
-void LLMenuItemCheckGL::setCheckedControl(LLString checked_control, LLView *context)
+//virtual
+void LLMenuItemCheckGL::setValue(const LLSD& value)
{
- // Register new listener
- if (!checked_control.empty())
+ mChecked = value.asBoolean();
+ if(mChecked)
{
- LLControlBase *control = context->findControl(checked_control);
- if (control)
- {
- LLSD state = control->registerListener(this, "CHECKED");
- mChecked = state;
- }
- else
- {
- context->addBoolControl(checked_control, mChecked);
- control = context->findControl(checked_control);
- control->registerListener(this, "CHECKED");
- }
+ mDrawBoolLabel = BOOLEAN_TRUE_PREFIX;
+ }
+ else
+ {
+ mDrawBoolLabel.clear();
}
}
-// virtual
-bool LLMenuItemCheckGL::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
+void LLMenuItemCheckGL::setCheckedControl(LLString checked_control, LLView *context)
{
- if (userdata.asString() == "CHECKED" && event->desc() == "value_changed")
+ // Register new listener
+ if (!checked_control.empty())
{
- LLSD state = event->getValue();
- mChecked = state;
- if(mChecked)
+ LLControlVariable *control = context->findControl(checked_control);
+ if (!control)
{
- mDrawBoolLabel = BOOLEAN_TRUE_PREFIX;
- }
- else
- {
- mDrawBoolLabel.clear();
+ context->addBoolControl(checked_control, mChecked);
+ control = context->findControl(checked_control);
+ llassert_always(control);
}
- return TRUE;
+ control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("value")));
+ mChecked = control->getValue();
}
- return LLMenuItemCallGL::handleEvent(event, userdata);
}
// virtual
@@ -1946,7 +1913,7 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory
{
continue;
}
- LLControlBase *control = parent->findControl(control_name);
+ LLControlVariable *control = parent->findControl(control_name);
if (!control)
{
parent->addBoolControl(control_name, FALSE);
diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h
index e9b80e562b..33b226fd99 100644
--- a/indra/llui/llmenugl.h
+++ b/indra/llui/llmenugl.h
@@ -225,7 +225,7 @@ private:
// calls a user defined callback.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-class LLMenuItemCallGL : public LLMenuItemGL
+class LLMenuItemCallGL : public LLMenuItemGL, public LLObservable
{
public:
// normal constructor
@@ -291,7 +291,6 @@ public:
//virtual void draw();
- virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
private:
menu_callback mCallback;
@@ -341,7 +340,7 @@ public:
void setCheckedControl(LLString checked_control, LLView *context);
- virtual void setValue(const LLSD& value) { mChecked = value.asBoolean(); }
+ virtual void setValue(const LLSD& value);
virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_CHECK; }
virtual LLString getWidgetTag() const { return LL_MENU_ITEM_CHECK_GL_TAG; }
@@ -350,8 +349,6 @@ public:
// called to rebuild the draw label
virtual void buildDrawLabel( void );
- virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
-
private:
check_callback mCheckCallback;
BOOL mChecked;
diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp
index aed7893df7..1e9442805f 100644
--- a/indra/llui/llui.cpp
+++ b/indra/llui/llui.cpp
@@ -1555,16 +1555,11 @@ void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale, const LLVector3
gl_segmented_rect_3d_tex(border_scale, border_width, border_height, width_vec, height_vec, ROUNDED_RECT_TOP);
}
-class LLShowXUINamesListener: public LLSimpleListener
+bool handleShowXUINamesChanged(const LLSD& newvalue)
{
- bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
- {
- LLUI::sShowXUINames = (BOOL) event->getValue().asBoolean();
- return true;
- }
-};
-static LLShowXUINamesListener show_xui_names_listener;
-
+ LLUI::sShowXUINames = newvalue.asBoolean();
+ return true;
+}
void LLUI::initClass(LLControlGroup* config,
LLControlGroup* colors,
@@ -1584,7 +1579,7 @@ void LLUI::initClass(LLControlGroup* config,
LLFontGL::sShadowColor = colors->getColor("ColorDropShadow");
LLUI::sShowXUINames = LLUI::sConfigGroup->getBOOL("ShowXUINames");
- LLUI::sConfigGroup->getControl("ShowXUINames")->addListener(&show_xui_names_listener);
+ LLUI::sConfigGroup->getControl("ShowXUINames")->getSignal()->connect(boost::bind(&handleShowXUINamesChanged, _1));
}
void LLUI::cleanupClass()
diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp
index 0a37c03ac5..269796e5de 100644
--- a/indra/llui/llview.cpp
+++ b/indra/llui/llview.cpp
@@ -2426,16 +2426,7 @@ LLSimpleListener* LLView::getListenerByName(const LLString& callback_name)
return callback;
}
-void LLView::addListenerToControl(LLEventDispatcher *dispatcher, const LLString& name, LLSD filter, LLSD userdata)
-{
- LLSimpleListener* listener = getListenerByName(name);
- if (listener)
- {
- dispatcher->addListener(listener, filter, userdata);
- }
-}
-
-LLControlBase *LLView::findControl(LLString name)
+LLControlVariable *LLView::findControl(LLString name)
{
control_map_t::iterator itor = mFloaterControls.find(name);
if (itor != mFloaterControls.end())
@@ -2791,9 +2782,15 @@ LLFontGL::StyleFlags LLView::selectFontStyle(LLXMLNodePtr node)
return gl_font_style;
}
-void LLView::setControlValue(const LLSD& value)
+bool LLView::setControlValue(const LLSD& value)
{
- LLUI::sConfigGroup->setValue(getControlName(), value);
+ LLString ctrlname = getControlName();
+ if (!ctrlname.empty())
+ {
+ LLUI::sConfigGroup->setValue(ctrlname, value);
+ return true;
+ }
+ return false;
}
//virtual
@@ -2804,43 +2801,57 @@ void LLView::setControlName(const LLString& control_name, LLView *context)
context = this;
}
- // Unregister from existing listeners
if (!mControlName.empty())
{
- clearDispatchers();
+ llwarns << "setControlName called twice on same control!" << llendl;
+ mControlConnection.disconnect(); // disconnect current signal
+ mControlName.clear();
}
-
+
// Register new listener
if (!control_name.empty())
{
- LLControlBase *control = context->findControl(control_name);
+ LLControlVariable *control = context->findControl(control_name);
if (control)
{
mControlName = control_name;
- LLSD state = control->registerListener(this, "DEFAULT");
- setValue(state);
+ mControlConnection = control->getSignal()->connect(boost::bind(&controlListener, _1, getHandle(), std::string("value")));
+ setValue(control->getValue());
}
}
}
-// virtual
-bool LLView::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
+// static
+bool LLView::controlListener(const LLSD& newvalue, LLHandle<LLView> handle, std::string type)
{
- if (userdata.asString() == "DEFAULT" && event->desc() == "value_changed")
+ LLView* view = handle.get();
+ if (view)
{
- LLSD state = event->getValue();
- setValue(state);
- return TRUE;
+ if (type == "value")
+ {
+ view->setValue(newvalue);
+ return true;
+ }
+ else if (type == "enabled")
+ {
+ view->setEnabled(newvalue.asBoolean());
+ return true;
+ }
+ else if (type == "visible")
+ {
+ view->setVisible(newvalue.asBoolean());
+ return true;
+ }
}
- return FALSE;
+ return false;
}
void LLView::addBoolControl(LLString name, bool initial_value)
{
- mFloaterControls[name] = new LLControl(name, TYPE_BOOLEAN, initial_value, "Internal floater control");
+ mFloaterControls[name] = new LLControlVariable(name, TYPE_BOOLEAN, initial_value, "Internal floater control");
}
-LLControlBase *LLView::getControl(LLString name)
+LLControlVariable *LLView::getControl(LLString name)
{
control_map_t::iterator itor = mFloaterControls.find(name);
if (itor != mFloaterControls.end())
diff --git a/indra/llui/llview.h b/indra/llui/llview.h
index c8556c7edc..24a5eb4f89 100644
--- a/indra/llui/llview.h
+++ b/indra/llui/llview.h
@@ -65,7 +65,6 @@ const BOOL NOT_MOUSE_OPAQUE = FALSE;
const U32 GL_NAME_UI_RESERVED = 2;
-
/*
// virtual functions defined in LLView:
@@ -150,7 +149,7 @@ virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
*
*/
-class LLView : public LLMouseHandler, public LLMortician, public LLSimpleListenerObservable
+class LLView : public LLMouseHandler, public LLMortician
{
public:
@@ -294,7 +293,6 @@ public:
LLHandle<LLView> getHandle() { mHandle.bind(this); return mHandle; }
-
U32 getFollows() const { return mReshapeFlags; }
BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; }
BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; }
@@ -393,13 +391,13 @@ public:
void addListenerToControl(LLEventDispatcher *observer, const LLString& name, LLSD filter, LLSD userdata);
void addBoolControl(LLString name, bool initial_value);
- LLControlBase *getControl(LLString name);
- LLControlBase *findControl(LLString name);
+ LLControlVariable *getControl(LLString name);
+ LLControlVariable *findControl(LLString name);
- void setControlValue(const LLSD& value);
+ bool setControlValue(const LLSD& value);
virtual void setControlName(const LLString& control, LLView *context);
virtual LLString getControlName() const { return mControlName; }
- virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
+// virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
virtual void setValue(const LLSD& value);
virtual LLSD getValue() const;
@@ -494,11 +492,12 @@ protected:
LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask);
LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask);
- typedef std::map<LLString, LLControlBase*> control_map_t;
+ static bool controlListener(const LLSD& newvalue, LLHandle<LLView> handle, std::string type);
+
+ typedef std::map<LLString, LLControlVariable*> control_map_t;
control_map_t mFloaterControls;
virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const;
-
private:
LLView* mParentView;
child_list_t mChildList;
@@ -537,9 +536,8 @@ private:
dispatch_list_t mDispatchList;
LLString mControlName;
-
-
-// Just debugging stuff? We should try to hide anything that's not. -MG
+ boost::signals::connection mControlConnection;
+
public:
static BOOL sDebugRects; // Draw debug rects behind everything.
static BOOL sDebugKeys;