diff options
author | richard <none@none> | 2009-11-23 11:42:32 -0800 |
---|---|---|
committer | richard <none@none> | 2009-11-23 11:42:32 -0800 |
commit | 7fd1488c6218ddbd82de0eea86297e65f2561bc7 (patch) | |
tree | a7a29812c0ed94c6a07c396f5e516dcf0950c99f /indra/llui | |
parent | e0a364b7bf836191f25604ef9c3783be46c1ce55 (diff) |
convert signals to allocate on demand in order to speed up widget construction
reviewed by James
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llbutton.cpp | 51 | ||||
-rw-r--r-- | indra/llui/llbutton.h | 8 | ||||
-rw-r--r-- | indra/llui/llfloater.cpp | 8 | ||||
-rw-r--r-- | indra/llui/llfocusmgr.cpp | 43 | ||||
-rw-r--r-- | indra/llui/llfocusmgr.h | 16 | ||||
-rw-r--r-- | indra/llui/lllineeditor.cpp | 6 | ||||
-rw-r--r-- | indra/llui/llmenugl.cpp | 17 | ||||
-rw-r--r-- | indra/llui/llmultislider.cpp | 37 | ||||
-rw-r--r-- | indra/llui/llmultislider.h | 9 | ||||
-rw-r--r-- | indra/llui/llmultisliderctrl.cpp | 4 | ||||
-rw-r--r-- | indra/llui/llpanel.cpp | 25 | ||||
-rw-r--r-- | indra/llui/llpanel.h | 6 | ||||
-rw-r--r-- | indra/llui/llslider.cpp | 36 | ||||
-rw-r--r-- | indra/llui/llslider.h | 9 | ||||
-rw-r--r-- | indra/llui/llsliderctrl.cpp | 4 | ||||
-rw-r--r-- | indra/llui/llspinctrl.cpp | 6 | ||||
-rw-r--r-- | indra/llui/lltabcontainer.cpp | 6 | ||||
-rw-r--r-- | indra/llui/lluictrl.cpp | 179 | ||||
-rw-r--r-- | indra/llui/lluictrl.h | 42 |
19 files changed, 390 insertions, 122 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp index b65f248db2..8930e32055 100644 --- a/indra/llui/llbutton.cpp +++ b/indra/llui/llbutton.cpp @@ -147,7 +147,11 @@ LLButton::LLButton(const LLButton::Params& p) mCommitOnReturn(p.commit_on_return), mFadeWhenDisabled(FALSE), mForcePressedState(false), - mLastDrawCharsCount(0) + mLastDrawCharsCount(0), + mMouseDownSignal(NULL), + mMouseUpSignal(NULL), + mHeldDownSignal(NULL) + { static LLUICachedControl<S32> llbutton_orig_h_pad ("UIButtonOrigHPad", 0); static Params default_params(LLUICtrlFactory::getDefaultParams<LLButton>()); @@ -215,13 +219,28 @@ LLButton::LLButton(const LLButton::Params& p) } if (p.click_callback.isProvided()) - initCommitCallback(p.click_callback, mCommitSignal); // alias -> commit_callback + { + setCommitCallback(initCommitCallback(p.click_callback)); // alias -> commit_callback + } if (p.mouse_down_callback.isProvided()) - initCommitCallback(p.mouse_down_callback, mMouseDownSignal); + { + setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); + } if (p.mouse_up_callback.isProvided()) - initCommitCallback(p.mouse_up_callback, mMouseUpSignal); + { + setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); + } if (p.mouse_held_callback.isProvided()) - initCommitCallback(p.mouse_held_callback, mHeldDownSignal); + { + setHeldDownCallback(initCommitCallback(p.mouse_held_callback)); + } +} + +LLButton::~LLButton() +{ + delete mMouseDownSignal; + delete mMouseUpSignal; + delete mHeldDownSignal; } // HACK: Committing a button is the same as instantly clicking it. @@ -232,9 +251,9 @@ void LLButton::onCommit() // panel containing it. Therefore we need to call LLUICtrl::onCommit() // LAST, otherwise this becomes deleted memory. - mMouseDownSignal(this, LLSD()); + if (mMouseDownSignal) (*mMouseDownSignal)(this, LLSD()); - mMouseUpSignal(this, LLSD()); + if (mMouseUpSignal) (*mMouseUpSignal)(this, LLSD()); if (getSoundFlags() & MOUSE_DOWN) { @@ -257,19 +276,23 @@ void LLButton::onCommit() boost::signals2::connection LLButton::setClickedCallback( const commit_signal_t::slot_type& cb ) { - return mCommitSignal.connect(cb); + if (!mCommitSignal) mCommitSignal = new commit_signal_t(); + return mCommitSignal->connect(cb); } boost::signals2::connection LLButton::setMouseDownCallback( const commit_signal_t::slot_type& cb ) { - return mMouseDownSignal.connect(cb); + if (!mMouseDownSignal) mMouseDownSignal = new commit_signal_t(); + return mMouseDownSignal->connect(cb); } boost::signals2::connection LLButton::setMouseUpCallback( const commit_signal_t::slot_type& cb ) { - return mMouseUpSignal.connect(cb); + if (!mMouseUpSignal) mMouseUpSignal = new commit_signal_t(); + return mMouseUpSignal->connect(cb); } boost::signals2::connection LLButton::setHeldDownCallback( const commit_signal_t::slot_type& cb ) { - return mHeldDownSignal.connect(cb); + if (!mHeldDownSignal) mHeldDownSignal = new commit_signal_t(); + return mHeldDownSignal->connect(cb); } @@ -351,7 +374,7 @@ BOOL LLButton::handleMouseDown(S32 x, S32 y, MASK mask) */ LLUICtrl::handleMouseDown(x, y, mask); - mMouseDownSignal(this, LLSD()); + if(mMouseDownSignal) (*mMouseDownSignal)(this, LLSD()); mMouseDownTimer.start(); mMouseDownFrame = (S32) LLFrameTimer::getFrameCount(); @@ -383,7 +406,7 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) LLUICtrl::handleMouseUp(x, y, mask); // Regardless of where mouseup occurs, handle callback - mMouseUpSignal(this, LLSD()); + if(mMouseUpSignal) (*mMouseUpSignal)(this, LLSD()); resetMouseDownTimer(); @@ -493,7 +516,7 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) { LLSD param; param["count"] = mMouseHeldDownCount++; - mHeldDownSignal(this, param); + if (mHeldDownSignal) (*mHeldDownSignal)(this, param); } } diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h index 3c1b57c4be..8c3b4bd859 100644 --- a/indra/llui/llbutton.h +++ b/indra/llui/llbutton.h @@ -128,6 +128,8 @@ protected: LLButton(const Params&); public: + + ~LLButton(); // For backward compatability only typedef boost::function<void(void*)> button_callback_t; @@ -251,9 +253,9 @@ private: void resetMouseDownTimer(); private: - commit_signal_t mMouseDownSignal; - commit_signal_t mMouseUpSignal; - commit_signal_t mHeldDownSignal; + commit_signal_t* mMouseDownSignal; + commit_signal_t* mMouseUpSignal; + commit_signal_t* mHeldDownSignal; const LLFontGL* mGLFont; diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp index bf965e8e28..262afbe661 100644 --- a/indra/llui/llfloater.cpp +++ b/indra/llui/llfloater.cpp @@ -2642,10 +2642,14 @@ void LLFloater::initFromParams(const LLFloater::Params& p) // open callback if (p.open_callback.isProvided()) - initCommitCallback(p.open_callback, mOpenSignal); + { + mOpenSignal.connect(initCommitCallback(p.open_callback)); + } // close callback if (p.close_callback.isProvided()) - initCommitCallback(p.close_callback, mCloseSignal); + { + mCloseSignal.connect(initCommitCallback(p.close_callback)); + } } LLFastTimer::DeclareTimer POST_BUILD("Floater Post Build"); diff --git a/indra/llui/llfocusmgr.cpp b/indra/llui/llfocusmgr.cpp index 00a80478cf..35fbc7b0a8 100644 --- a/indra/llui/llfocusmgr.cpp +++ b/indra/llui/llfocusmgr.cpp @@ -41,6 +41,10 @@ const F32 FOCUS_FADE_TIME = 0.3f; // NOTE: the LLFocusableElement implementation has been moved here from lluictrl.cpp. LLFocusableElement::LLFocusableElement() +: mFocusLostCallback(NULL), + mFocusReceivedCallback(NULL), + mFocusChangedCallback(NULL), + mTopLostCallback(NULL) { } @@ -59,23 +63,27 @@ BOOL LLFocusableElement::handleUnicodeChar(llwchar uni_char, BOOL called_from_pa // virtual LLFocusableElement::~LLFocusableElement() { + delete mFocusLostCallback; + delete mFocusReceivedCallback; + delete mFocusChangedCallback; + delete mTopLostCallback; } void LLFocusableElement::onFocusReceived() { - mFocusReceivedCallback(this); - mFocusChangedCallback(this); + if (mFocusReceivedCallback) (*mFocusReceivedCallback)(this); + if (mFocusChangedCallback) (*mFocusChangedCallback)(this); } void LLFocusableElement::onFocusLost() { - mFocusLostCallback(this); - mFocusChangedCallback(this); + if (mFocusLostCallback) (*mFocusLostCallback)(this); + if (mFocusChangedCallback) (*mFocusChangedCallback)(this); } void LLFocusableElement::onTopLost() { - mTopLostCallback(this); + if (mTopLostCallback) (*mTopLostCallback)(this); } BOOL LLFocusableElement::hasFocus() const @@ -87,6 +95,31 @@ void LLFocusableElement::setFocus(BOOL b) { } +boost::signals2::connection LLFocusableElement::setFocusLostCallback( const focus_signal_t::slot_type& cb) +{ + if (!mFocusLostCallback) mFocusLostCallback = new focus_signal_t(); + return mFocusLostCallback->connect(cb); +} + +boost::signals2::connection LLFocusableElement::setFocusReceivedCallback(const focus_signal_t::slot_type& cb) +{ + if (!mFocusReceivedCallback) mFocusReceivedCallback = new focus_signal_t(); + return mFocusReceivedCallback->connect(cb); +} + +boost::signals2::connection LLFocusableElement::setFocusChangedCallback(const focus_signal_t::slot_type& cb) +{ + if (!mFocusChangedCallback) mFocusChangedCallback = new focus_signal_t(); + return mFocusChangedCallback->connect(cb); +} + +boost::signals2::connection LLFocusableElement::setTopLostCallback(const focus_signal_t::slot_type& cb) +{ + if (!mTopLostCallback) mTopLostCallback = new focus_signal_t(); + return mTopLostCallback->connect(cb); +} + + LLFocusMgr gFocusMgr; diff --git a/indra/llui/llfocusmgr.h b/indra/llui/llfocusmgr.h index 2fa4e124fb..83ecd1d301 100644 --- a/indra/llui/llfocusmgr.h +++ b/indra/llui/llfocusmgr.h @@ -56,10 +56,10 @@ public: typedef boost::signals2::signal<void(LLFocusableElement*)> focus_signal_t; - boost::signals2::connection setFocusLostCallback( const focus_signal_t::slot_type& cb) { return mFocusLostCallback.connect(cb);} - boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb) { return mFocusReceivedCallback.connect(cb);} - boost::signals2::connection setFocusChangedCallback(const focus_signal_t::slot_type& cb) { return mFocusChangedCallback.connect(cb);} - void setTopLostCallback(const focus_signal_t::slot_type& cb) { mTopLostCallback.connect(cb);} + boost::signals2::connection setFocusLostCallback( const focus_signal_t::slot_type& cb); + boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb); + boost::signals2::connection setFocusChangedCallback(const focus_signal_t::slot_type& cb); + boost::signals2::connection setTopLostCallback(const focus_signal_t::slot_type& cb); // These were brought up the hierarchy from LLView so that we don't have to use dynamic_cast when dealing with keyboard focus. virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); @@ -69,10 +69,10 @@ protected: virtual void onFocusReceived(); virtual void onFocusLost(); virtual void onTopLost(); // called when registered as top ctrl and user clicks elsewhere - focus_signal_t mFocusLostCallback; - focus_signal_t mFocusReceivedCallback; - focus_signal_t mFocusChangedCallback; - focus_signal_t mTopLostCallback; + focus_signal_t* mFocusLostCallback; + focus_signal_t* mFocusReceivedCallback; + focus_signal_t* mFocusChangedCallback; + focus_signal_t* mTopLostCallback; }; diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index c2f91ff7e0..406c77a365 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -626,7 +626,8 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) // delay cursor flashing mKeystrokeTimer.reset(); - mMouseDownSignal(this,x,y,mask); + if (mMouseDownSignal) + (*mMouseDownSignal)(this,x,y,mask); return TRUE; } @@ -742,7 +743,8 @@ BOOL LLLineEditor::handleMouseUp(S32 x, S32 y, MASK mask) } // We won't call LLUICtrl::handleMouseUp to avoid double calls of childrenHandleMouseUp().Just invoke the signal manually. - mMouseUpSignal(this,x,y, mask); + if (mMouseUpSignal) + (*mMouseUpSignal)(this,x,y, mask); return handled; } diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp index de9a854f63..f8935d03ac 100644 --- a/indra/llui/llmenugl.cpp +++ b/indra/llui/llmenugl.cpp @@ -760,21 +760,25 @@ void LLMenuItemCallGL::initFromParams(const Params& p) { if (p.on_visible.isProvided()) { - initVisibleCallback(p.on_visible, mVisibleSignal); + mVisibleSignal.connect(initVisibleCallback(p.on_visible)); } if (p.on_enable.isProvided()) { - initEnableCallback(p.on_enable, mEnableSignal); + setEnableCallback(initEnableCallback(p.on_enable)); // Set the enabled control variable (for backwards compatability) if (p.on_enable.control_name.isProvided() && !p.on_enable.control_name().empty()) { LLControlVariable* control = findControl(p.on_enable.control_name()); if (control) + { setEnabledControlVariable(control); + } } } if (p.on_click.isProvided()) - initCommitCallback(p.on_click, mCommitSignal); + { + setCommitCallback(initCommitCallback(p.on_click)); + } LLUICtrl::initFromParams(p); } @@ -795,7 +799,10 @@ void LLMenuItemCallGL::updateEnabled( void ) if (mEnabledControlVariable) { if (!enabled) - mEnabledControlVariable->set(false); // callback overrides control variable; this will call setEnabled() + { + // callback overrides control variable; this will call setEnabled() + mEnabledControlVariable->set(false); + } } else { @@ -854,7 +861,7 @@ void LLMenuItemCheckGL::initFromParams(const Params& p) { if (p.on_check.isProvided()) { - initEnableCallback(p.on_check, mCheckSignal); + setCheckCallback(initEnableCallback(p.on_check)); // Set the control name (for backwards compatability) if (p.on_check.control_name.isProvided() && !p.on_check.control_name().empty()) { diff --git a/indra/llui/llmultislider.cpp b/indra/llui/llmultislider.cpp index 68e496aed1..1891bca36c 100644 --- a/indra/llui/llmultislider.cpp +++ b/indra/llui/llmultislider.cpp @@ -84,17 +84,30 @@ LLMultiSlider::LLMultiSlider(const LLMultiSlider::Params& p) mThumbCenterSelectedColor(p.thumb_center_selected_color()), mDisabledThumbColor(p.thumb_disabled_color()), mTriangleColor(p.triangle_color()), - mThumbWidth(p.thumb_width) + mThumbWidth(p.thumb_width), + mMouseDownSignal(NULL), + mMouseUpSignal(NULL) { mValue.emptyMap(); mCurSlider = LLStringUtil::null; if (p.mouse_down_callback.isProvided()) - initCommitCallback(p.mouse_down_callback, mMouseDownSignal); + { + setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); + } if (p.mouse_up_callback.isProvided()) - initCommitCallback(p.mouse_up_callback, mMouseUpSignal); + { + setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); + } +} + +LLMultiSlider::~LLMultiSlider() +{ + delete mMouseDownSignal; + delete mMouseUpSignal; } + void LLMultiSlider::setSliderValue(const std::string& name, F32 value, BOOL from_event) { // exit if not there @@ -325,7 +338,8 @@ BOOL LLMultiSlider::handleMouseUp(S32 x, S32 y, MASK mask) { gFocusMgr.setMouseCapture( NULL ); - mMouseUpSignal( this, LLSD() ); + if (mMouseUpSignal) + (*mMouseUpSignal)( this, LLSD() ); handled = TRUE; make_ui_sound("UISndClickRelease"); @@ -345,7 +359,8 @@ BOOL LLMultiSlider::handleMouseDown(S32 x, S32 y, MASK mask) { setFocus(TRUE); } - mMouseDownSignal( this, LLSD() ); + if (mMouseDownSignal) + (*mMouseDownSignal)( this, LLSD() ); if (MASK_CONTROL & mask) // if CTRL is modifying { @@ -557,3 +572,15 @@ void LLMultiSlider::draw() LLF32UICtrl::draw(); } + +boost::signals2::connection LLMultiSlider::setMouseDownCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseDownSignal) mMouseDownSignal = new commit_signal_t(); + return mMouseDownSignal->connect(cb); +} + +boost::signals2::connection LLMultiSlider::setMouseUpCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseUpSignal) mMouseUpSignal = new commit_signal_t(); + return mMouseUpSignal->connect(cb); +} diff --git a/indra/llui/llmultislider.h b/indra/llui/llmultislider.h index da633cc1cd..f8e43a0470 100644 --- a/indra/llui/llmultislider.h +++ b/indra/llui/llmultislider.h @@ -67,6 +67,7 @@ protected: LLMultiSlider(const Params&); friend class LLUICtrlFactory; public: + virtual ~LLMultiSlider(); void setSliderValue(const std::string& name, F32 value, BOOL from_event = FALSE); F32 getSliderValue(const std::string& name) const; @@ -78,8 +79,8 @@ public: /*virtual*/ void setValue(const LLSD& value); /*virtual*/ LLSD getValue() const { return mValue; } - boost::signals2::connection setMouseDownCallback( const commit_signal_t::slot_type& cb ) { return mMouseDownSignal.connect(cb); } - boost::signals2::connection setMouseUpCallback( const commit_signal_t::slot_type& cb ) { return mMouseUpSignal.connect(cb); } + boost::signals2::connection setMouseDownCallback( const commit_signal_t::slot_type& cb ); + boost::signals2::connection setMouseUpCallback( const commit_signal_t::slot_type& cb ); bool findUnusedValue(F32& initVal); const std::string& addSlider(); @@ -116,8 +117,8 @@ protected: LLUIColor mDisabledThumbColor; LLUIColor mTriangleColor; - commit_signal_t mMouseDownSignal; - commit_signal_t mMouseUpSignal; + commit_signal_t* mMouseDownSignal; + commit_signal_t* mMouseUpSignal; }; #endif // LL_MULTI_SLIDER_H diff --git a/indra/llui/llmultisliderctrl.cpp b/indra/llui/llmultisliderctrl.cpp index a9f462173d..87938c19d4 100644 --- a/indra/llui/llmultisliderctrl.cpp +++ b/indra/llui/llmultisliderctrl.cpp @@ -344,7 +344,7 @@ void LLMultiSliderCtrl::onEditorCommit( LLUICtrl* ctrl, const LLSD& userdata) if( self->mMultiSlider->getMinValue() <= val && val <= self->mMultiSlider->getMaxValue() ) { self->setCurSliderValue( val ); // set the value temporarily so that the callback can retrieve it. - if( self->mValidateSignal( self, val ) ) + if( !self->mValidateSignal || (*(self->mValidateSignal))( self, val ) ) { success = TRUE; } @@ -378,7 +378,7 @@ void LLMultiSliderCtrl::onSliderCommit(LLUICtrl* ctrl, const LLSD& userdata) F32 new_val = self->mMultiSlider->getCurSliderValue(); self->mCurValue = new_val; // set the value temporarily so that the callback can retrieve it. - if( self->mValidateSignal( self, new_val ) ) + if( !self->mValidateSignal || (*(self->mValidateSignal))( self, new_val ) ) { success = TRUE; } diff --git a/indra/llui/llpanel.cpp b/indra/llui/llpanel.cpp index 89c4656297..063822dd56 100644 --- a/indra/llui/llpanel.cpp +++ b/indra/llui/llpanel.cpp @@ -106,7 +106,8 @@ LLPanel::LLPanel(const LLPanel::Params& p) mHelpTopic(p.help_topic), mCommitCallbackRegistrar(false), mEnableCallbackRegistrar(false), - mXMLFilename(p.filename) + mXMLFilename(p.filename), + mVisibleSignal(NULL) // *NOTE: Be sure to also change LLPanel::initFromParams(). We have too // many classes derived from LLPanel to retrofit them all to pass in params. { @@ -118,6 +119,11 @@ LLPanel::LLPanel(const LLPanel::Params& p) mPanelHandle.bind(this); } +LLPanel::~LLPanel() +{ + delete mVisibleSignal; +} + // virtual BOOL LLPanel::isPanel() const { @@ -332,7 +338,8 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask ) void LLPanel::handleVisibilityChange ( BOOL new_visibility ) { LLUICtrl::handleVisibilityChange ( new_visibility ); - mVisibleSignal(this, LLSD(new_visibility) ); // Pass BOOL as LLSD + if (mVisibleSignal) + (*mVisibleSignal)(this, LLSD(new_visibility) ); // Pass BOOL as LLSD } void LLPanel::setFocus(BOOL b) @@ -424,7 +431,9 @@ void LLPanel::initFromParams(const LLPanel::Params& p) // visible callback if (p.visible_callback.isProvided()) - initCommitCallback(p.visible_callback, mVisibleSignal); + { + setVisibleCallback(initCommitCallback(p.visible_callback)); + } for (LLInitParam::ParamIterator<LocalizedString>::const_iterator it = p.strings().begin(); it != p.strings().end(); @@ -907,3 +916,13 @@ void LLPanel::childSetControlName(const std::string& id, const std::string& cont view->setControlName(control_name, NULL); } } + +boost::signals2::connection LLPanel::setVisibleCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mVisibleSignal) + { + mVisibleSignal = new commit_signal_t(); + } + + return mVisibleSignal->connect(cb); +} diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h index c213809d68..0a0fed82fb 100644 --- a/indra/llui/llpanel.h +++ b/indra/llui/llpanel.h @@ -109,7 +109,7 @@ protected: public: // LLPanel(const std::string& name, const LLRect& rect = LLRect(), BOOL bordered = TRUE); - /*virtual*/ ~LLPanel() {} + /*virtual*/ ~LLPanel(); // LLView interface /*virtual*/ BOOL isPanel() const; @@ -241,6 +241,8 @@ public: void setXMLFilename(std::string filename) { mXMLFilename = filename; }; std::string getXMLFilename() { return mXMLFilename; }; + boost::signals2::connection setVisibleCallback( const commit_signal_t::slot_type& cb ); + protected: // Override to set not found list LLButton* getDefaultButton() { return mDefaultBtn; } @@ -249,7 +251,7 @@ protected: EnableCallbackRegistry::ScopedRegistrar mEnableCallbackRegistrar; VisibleCallbackRegistry::ScopedRegistrar mVisibleCallbackRegistrar; - commit_signal_t mVisibleSignal; // Called when visibility changes, passes new visibility as LLSD() + commit_signal_t* mVisibleSignal; // Called when visibility changes, passes new visibility as LLSD() std::string mHelpTopic; // the name of this panel's help topic to display in the Help Viewer diff --git a/indra/llui/llslider.cpp b/indra/llui/llslider.cpp index da2fc7c68b..a6f729b396 100644 --- a/indra/llui/llslider.cpp +++ b/indra/llui/llslider.cpp @@ -77,7 +77,9 @@ LLSlider::LLSlider(const LLSlider::Params& p) mTrackImageHorizontal(p.track_image_horizontal), mTrackImageVertical(p.track_image_vertical), mTrackHighlightHorizontalImage(p.track_highlight_horizontal_image), - mTrackHighlightVerticalImage(p.track_highlight_vertical_image) + mTrackHighlightVerticalImage(p.track_highlight_vertical_image), + mMouseDownSignal(NULL), + mMouseUpSignal(NULL) { mViewModel->setValue(p.initial_value); updateThumbRect(); @@ -86,9 +88,19 @@ LLSlider::LLSlider(const LLSlider::Params& p) setValue(getValueF32()); if (p.mouse_down_callback.isProvided()) - initCommitCallback(p.mouse_down_callback, mMouseDownSignal); + { + setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); + } if (p.mouse_up_callback.isProvided()) - initCommitCallback(p.mouse_up_callback, mMouseUpSignal); + { + setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); + } +} + +LLSlider::~LLSlider() +{ + delete mMouseDownSignal; + delete mMouseUpSignal; } void LLSlider::setValue(F32 value, BOOL from_event) @@ -202,7 +214,8 @@ BOOL LLSlider::handleMouseUp(S32 x, S32 y, MASK mask) { gFocusMgr.setMouseCapture( NULL ); - mMouseUpSignal( this, getValueF32() ); + if (mMouseUpSignal) + (*mMouseUpSignal)( this, getValueF32() ); handled = TRUE; make_ui_sound("UISndClickRelease"); @@ -222,7 +235,8 @@ BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask) { setFocus(TRUE); } - mMouseDownSignal( this, getValueF32() ); + if (mMouseDownSignal) + (*mMouseDownSignal)( this, getValueF32() ); if (MASK_CONTROL & mask) // if CTRL is modifying { @@ -364,3 +378,15 @@ void LLSlider::draw() LLUICtrl::draw(); } + +boost::signals2::connection LLSlider::setMouseDownCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseDownSignal) mMouseDownSignal = new commit_signal_t(); + return mMouseDownSignal->connect(cb); +} + +boost::signals2::connection LLSlider::setMouseUpCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseUpSignal) mMouseUpSignal = new commit_signal_t(); + return mMouseUpSignal->connect(cb); +} diff --git a/indra/llui/llslider.h b/indra/llui/llslider.h index 6ab0ed7922..45f8f81e40 100644 --- a/indra/llui/llslider.h +++ b/indra/llui/llslider.h @@ -67,6 +67,7 @@ protected: LLSlider(const Params&); friend class LLUICtrlFactory; public: + virtual ~LLSlider(); void setValue( F32 value, BOOL from_event = FALSE ); // overrides for LLF32UICtrl methods virtual void setValue(const LLSD& value ) { setValue((F32)value.asReal(), TRUE); } @@ -76,8 +77,8 @@ public: virtual void setMinValue(F32 min_value) { LLF32UICtrl::setMinValue(min_value); updateThumbRect(); } virtual void setMaxValue(F32 max_value) { LLF32UICtrl::setMaxValue(max_value); updateThumbRect(); } - boost::signals2::connection setMouseDownCallback( const commit_signal_t::slot_type& cb ) { return mMouseDownSignal.connect(cb); } - boost::signals2::connection setMouseUpCallback( const commit_signal_t::slot_type& cb ) { return mMouseUpSignal.connect(cb); } + boost::signals2::connection setMouseDownCallback( const commit_signal_t::slot_type& cb ); + boost::signals2::connection setMouseUpCallback( const commit_signal_t::slot_type& cb ); virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); @@ -109,8 +110,8 @@ private: LLUIColor mThumbOutlineColor; LLUIColor mThumbCenterColor; - commit_signal_t mMouseDownSignal; - commit_signal_t mMouseUpSignal; + commit_signal_t* mMouseDownSignal; + commit_signal_t* mMouseUpSignal; }; #endif // LL_LLSLIDER_H diff --git a/indra/llui/llsliderctrl.cpp b/indra/llui/llsliderctrl.cpp index ed22c0a47f..a4f89ae1d3 100644 --- a/indra/llui/llsliderctrl.cpp +++ b/indra/llui/llsliderctrl.cpp @@ -260,7 +260,7 @@ void LLSliderCtrl::onEditorCommit( LLUICtrl* ctrl, const LLSD& userdata ) if( self->mSlider->getMinValue() <= val && val <= self->mSlider->getMaxValue() ) { self->setValue( val ); // set the value temporarily so that the callback can retrieve it. - if( self->mValidateSignal( self, val ) ) + if( !self->mValidateSignal || (*(self->mValidateSignal))( self, val ) ) { success = TRUE; } @@ -294,7 +294,7 @@ void LLSliderCtrl::onSliderCommit( LLUICtrl* ctrl, const LLSD& userdata ) F32 new_val = self->mSlider->getValueF32(); self->mValue = new_val; // set the value temporarily so that the callback can retrieve it. - if( self->mValidateSignal( self, new_val ) ) + if( !self->mValidateSignal || (*(self->mValidateSignal))( self, new_val ) ) { success = TRUE; } diff --git a/indra/llui/llspinctrl.cpp b/indra/llui/llspinctrl.cpp index bedf16a397..d6d46654d5 100644 --- a/indra/llui/llspinctrl.cpp +++ b/indra/llui/llspinctrl.cpp @@ -190,7 +190,7 @@ void LLSpinCtrl::onUpBtn( const LLSD& data ) F32 saved_val = (F32)getValue().asReal(); setValue(val); - if( !mValidateSignal( this, val ) ) + if( mValidateSignal && !(*mValidateSignal)( this, val ) ) { setValue( saved_val ); reportInvalidData(); @@ -224,7 +224,7 @@ void LLSpinCtrl::onDownBtn( const LLSD& data ) F32 saved_val = (F32)getValue().asReal(); setValue(val); - if( !mValidateSignal( this, val ) ) + if( mValidateSignal && !(*mValidateSignal)( this, val ) ) { setValue( saved_val ); reportInvalidData(); @@ -316,7 +316,7 @@ void LLSpinCtrl::onEditorCommit( const LLSD& data ) F32 saved_val = getValueF32(); setValue(val); - if( mValidateSignal( this, val ) ) + if( !mValidateSignal || (*mValidateSignal)( this, val ) ) { success = TRUE; onCommit(); diff --git a/indra/llui/lltabcontainer.cpp b/indra/llui/lltabcontainer.cpp index f5d8174820..d7d61cf6cb 100644 --- a/indra/llui/lltabcontainer.cpp +++ b/indra/llui/lltabcontainer.cpp @@ -1339,12 +1339,12 @@ BOOL LLTabContainer::selectTab(S32 which) cbdata = selected_tuple->mTabPanel->getName(); BOOL res = FALSE; - if( mValidateSignal( this, cbdata ) ) + if( !mValidateSignal || (*mValidateSignal)( this, cbdata ) ) { res = setTab(which); - if (res) + if (res && mCommitSignal) { - mCommitSignal(this, cbdata); + (*mCommitSignal)(this, cbdata); } } diff --git a/indra/llui/lluictrl.cpp b/indra/llui/lluictrl.cpp index 08fc8fb784..a30d5b4651 100644 --- a/indra/llui/lluictrl.cpp +++ b/indra/llui/lluictrl.cpp @@ -78,7 +78,16 @@ LLUICtrl::LLUICtrl(const LLUICtrl::Params& p, const LLViewModelPtr& viewmodel) mEnabledControlVariable(NULL), mDisabledControlVariable(NULL), mMakeVisibleControlVariable(NULL), - mMakeInvisibleControlVariable(NULL) + mMakeInvisibleControlVariable(NULL), + mCommitSignal(NULL), + mValidateSignal(NULL), + mMouseEnterSignal(NULL), + mMouseLeaveSignal(NULL), + mMouseDownSignal(NULL), + mMouseUpSignal(NULL), + mRightMouseDownSignal(NULL), + mRightMouseUpSignal(NULL), + mDoubleClickSignal(NULL) { mUICtrlHandle.bind(this); } @@ -129,10 +138,14 @@ void LLUICtrl::initFromParams(const Params& p) } if (p.commit_callback.isProvided()) - initCommitCallback(p.commit_callback, mCommitSignal); + { + setCommitCallback(initCommitCallback(p.commit_callback)); + } if (p.validate_callback.isProvided()) - initEnableCallback(p.validate_callback, mValidateSignal); + { + setValidateCallback(initEnableCallback(p.validate_callback)); + } if (p.init_callback.isProvided()) { @@ -151,10 +164,14 @@ void LLUICtrl::initFromParams(const Params& p) } if(p.mouseenter_callback.isProvided()) - initCommitCallback(p.mouseenter_callback, mMouseEnterSignal); + { + setMouseEnterCallback(initCommitCallback(p.mouseenter_callback)); + } if(p.mouseleave_callback.isProvided()) - initCommitCallback(p.mouseleave_callback, mMouseLeaveSignal); + { + setMouseLeaveCallback(initCommitCallback(p.mouseleave_callback)); + } } @@ -167,16 +184,40 @@ LLUICtrl::~LLUICtrl() llwarns << "UI Control holding top ctrl deleted: " << getName() << ". Top view removed." << llendl; gFocusMgr.removeTopCtrlWithoutCallback( this ); } + + delete mCommitSignal; + delete mValidateSignal; + delete mMouseEnterSignal; + delete mMouseLeaveSignal; + delete mMouseDownSignal; + delete mMouseUpSignal; + delete mRightMouseDownSignal; + delete mRightMouseUpSignal; + delete mDoubleClickSignal; } -void LLUICtrl::initCommitCallback(const CommitCallbackParam& cb, commit_signal_t& sig) +void default_commit_handler(LLUICtrl* ctrl, const LLSD& param) +{} + +bool default_enable_handler(LLUICtrl* ctrl, const LLSD& param) +{ + return true; +} + +bool default_visible_handler(LLUICtrl* ctrl, const LLSD& param) +{ + return true; +} + + +LLUICtrl::commit_signal_t::slot_type LLUICtrl::initCommitCallback(const CommitCallbackParam& cb) { if (cb.function.isProvided()) { if (cb.parameter.isProvided()) - sig.connect(boost::bind(cb.function(), _1, cb.parameter)); + return boost::bind(cb.function(), _1, cb.parameter); else - sig.connect(cb.function()); + return cb.function(); } else { @@ -185,26 +226,27 @@ void LLUICtrl::initCommitCallback(const CommitCallbackParam& cb, commit_signal_t if (func) { if (cb.parameter.isProvided()) - sig.connect(boost::bind((*func), _1, cb.parameter)); + return boost::bind((*func), _1, cb.parameter); else - sig.connect(*func); + return commit_signal_t::slot_type(*func); } else if (!function_name.empty()) { llwarns << "No callback found for: '" << function_name << "' in control: " << getName() << llendl; } } + return default_commit_handler; } -void LLUICtrl::initEnableCallback(const EnableCallbackParam& cb, enable_signal_t& sig) +LLUICtrl::enable_signal_t::slot_type LLUICtrl::initEnableCallback(const EnableCallbackParam& cb) { // Set the callback function if (cb.function.isProvided()) { if (cb.parameter.isProvided()) - sig.connect(boost::bind(cb.function(), this, cb.parameter)); + return boost::bind(cb.function(), this, cb.parameter); else - sig.connect(cb.function()); + return cb.function(); } else { @@ -212,22 +254,23 @@ void LLUICtrl::initEnableCallback(const EnableCallbackParam& cb, enable_signal_t if (func) { if (cb.parameter.isProvided()) - sig.connect(boost::bind((*func), this, cb.parameter)); + return boost::bind((*func), this, cb.parameter); else - sig.connect(*func); + return enable_signal_t::slot_type(*func); } } + return default_enable_handler; } -void LLUICtrl::initVisibleCallback(const VisibleCallbackParam& cb, visible_signal_t& sig) +LLUICtrl::visible_signal_t::slot_type LLUICtrl::initVisibleCallback(const VisibleCallbackParam& cb) { // Set the callback function if (cb.function.isProvided()) { if (cb.parameter.isProvided()) - sig.connect(boost::bind(cb.function(), this, cb.parameter)); + return boost::bind(cb.function(), this, cb.parameter); else - sig.connect(cb.function()); + return cb.function(); } else { @@ -235,30 +278,40 @@ void LLUICtrl::initVisibleCallback(const VisibleCallbackParam& cb, visible_signa if (func) { if (cb.parameter.isProvided()) - sig.connect(boost::bind((*func), this, cb.parameter)); + return boost::bind((*func), this, cb.parameter); else - sig.connect(*func); + return visible_signal_t::slot_type(*func); } } + return default_visible_handler; } // virtual void LLUICtrl::onMouseEnter(S32 x, S32 y, MASK mask) { - mMouseEnterSignal(this, getValue()); + if (mMouseEnterSignal) + { + (*mMouseEnterSignal)(this, getValue()); + } } // virtual void LLUICtrl::onMouseLeave(S32 x, S32 y, MASK mask) { - mMouseLeaveSignal(this, getValue()); + if(mMouseLeaveSignal) + { + (*mMouseLeaveSignal)(this, getValue()); + } } //virtual BOOL LLUICtrl::handleMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = LLView::handleMouseDown(x,y,mask); - mMouseDownSignal(this,x,y,mask); + if (mMouseDownSignal) + { + (*mMouseDownSignal)(this,x,y,mask); + } return handled; } @@ -266,7 +319,10 @@ BOOL LLUICtrl::handleMouseDown(S32 x, S32 y, MASK mask) BOOL LLUICtrl::handleMouseUp(S32 x, S32 y, MASK mask) { BOOL handled = LLView::handleMouseUp(x,y,mask); - mMouseUpSignal(this,x,y,mask); + if (mMouseUpSignal) + { + (*mMouseUpSignal)(this,x,y,mask); + } return handled; } @@ -274,7 +330,10 @@ BOOL LLUICtrl::handleMouseUp(S32 x, S32 y, MASK mask) BOOL LLUICtrl::handleRightMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = LLView::handleRightMouseDown(x,y,mask); - mRightMouseDownSignal(this,x,y,mask); + if (mRightMouseDownSignal) + { + (*mRightMouseDownSignal)(this,x,y,mask); + } return handled; } @@ -282,14 +341,20 @@ BOOL LLUICtrl::handleRightMouseDown(S32 x, S32 y, MASK mask) BOOL LLUICtrl::handleRightMouseUp(S32 x, S32 y, MASK mask) { BOOL handled = LLView::handleRightMouseUp(x,y,mask); - mRightMouseUpSignal(this,x,y,mask); + if(mRightMouseUpSignal) + { + (*mRightMouseUpSignal)(this,x,y,mask); + } return handled; } BOOL LLUICtrl::handleDoubleClick(S32 x, S32 y, MASK mask) { BOOL handled = LLView::handleDoubleClick(x, y, mask); - mDoubleClickSignal(this, x, y, mask); + if (mDoubleClickSignal) + { + (*mDoubleClickSignal)(this, x, y, mask); + } return handled; } @@ -302,7 +367,8 @@ BOOL LLUICtrl::canFocusChildren() const void LLUICtrl::onCommit() { - mCommitSignal(this, getValue()); + if (mCommitSignal) + (*mCommitSignal)(this, getValue()); } //virtual @@ -832,7 +898,8 @@ boost::signals2::connection LLUICtrl::setCommitCallback( boost::function<void (L } boost::signals2::connection LLUICtrl::setValidateBeforeCommit( boost::function<bool (const LLSD& data)> cb ) { - return mValidateSignal.connect(boost::bind(cb, _2)); + if (!mValidateSignal) mValidateSignal = new enable_signal_t(); + return mValidateSignal->connect(boost::bind(cb, _2)); } // virtual @@ -850,3 +917,57 @@ BOOL LLUICtrl::getTentative() const // virtual void LLUICtrl::setColor(const LLColor4& color) { } + +boost::signals2::connection LLUICtrl::setCommitCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mCommitSignal) mCommitSignal = new commit_signal_t(); + return mCommitSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setValidateCallback( const enable_signal_t::slot_type& cb ) +{ + if (!mValidateSignal) mValidateSignal = new enable_signal_t(); + return mValidateSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setMouseEnterCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseEnterSignal) mMouseEnterSignal = new commit_signal_t(); + return mMouseEnterSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setMouseLeaveCallback( const commit_signal_t::slot_type& cb ) +{ + if (!mMouseLeaveSignal) mMouseLeaveSignal = new commit_signal_t(); + return mMouseLeaveSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setMouseDownCallback( const mouse_signal_t::slot_type& cb ) +{ + if (!mMouseDownSignal) mMouseDownSignal = new mouse_signal_t(); + return mMouseDownSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setMouseUpCallback( const mouse_signal_t::slot_type& cb ) +{ + if (!mMouseUpSignal) mMouseUpSignal = new mouse_signal_t(); + return mMouseUpSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setRightMouseDownCallback( const mouse_signal_t::slot_type& cb ) +{ + if (!mRightMouseDownSignal) mRightMouseDownSignal = new mouse_signal_t(); + return mRightMouseDownSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setRightMouseUpCallback( const mouse_signal_t::slot_type& cb ) +{ + if (!mRightMouseUpSignal) mRightMouseUpSignal = new mouse_signal_t(); + return mRightMouseUpSignal->connect(cb); +} + +boost::signals2::connection LLUICtrl::setDoubleClickCallback( const mouse_signal_t::slot_type& cb ) +{ + if (!mDoubleClickSignal) mDoubleClickSignal = new mouse_signal_t(); + return mDoubleClickSignal->connect(cb); +} diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h index dd22851100..aef1bcd519 100644 --- a/indra/llui/lluictrl.h +++ b/indra/llui/lluictrl.h @@ -162,9 +162,9 @@ protected: LLUICtrl(const Params& p = getDefaultParams(), const LLViewModelPtr& viewmodel=LLViewModelPtr(new LLViewModel)); - void initCommitCallback(const CommitCallbackParam& cb, commit_signal_t& sig); - void initEnableCallback(const EnableCallbackParam& cb, enable_signal_t& sig); - void initVisibleCallback(const VisibleCallbackParam& cb, visible_signal_t& sig); + commit_signal_t::slot_type initCommitCallback(const CommitCallbackParam& cb); + enable_signal_t::slot_type initEnableCallback(const EnableCallbackParam& cb); + visible_signal_t::slot_type initVisibleCallback(const VisibleCallbackParam& cb); // We need this virtual so we can override it with derived versions virtual LLViewModel* getViewModel() const; @@ -254,18 +254,18 @@ public: // topic then put in help_topic_out bool findHelpTopic(std::string& help_topic_out); - boost::signals2::connection setCommitCallback( const commit_signal_t::slot_type& cb ) { return mCommitSignal.connect(cb); } - boost::signals2::connection setValidateCallback( const enable_signal_t::slot_type& cb ) { return mValidateSignal.connect(cb); } + boost::signals2::connection setCommitCallback( const commit_signal_t::slot_type& cb ); + boost::signals2::connection setValidateCallback( const enable_signal_t::slot_type& cb ); - boost::signals2::connection setMouseEnterCallback( const commit_signal_t::slot_type& cb ) { return mMouseEnterSignal.connect(cb); } - boost::signals2::connection setMouseLeaveCallback( const commit_signal_t::slot_type& cb ) { return mMouseLeaveSignal.connect(cb); } + boost::signals2::connection setMouseEnterCallback( const commit_signal_t::slot_type& cb ); + boost::signals2::connection setMouseLeaveCallback( const commit_signal_t::slot_type& cb ); - boost::signals2::connection setMouseDownCallback( const mouse_signal_t::slot_type& cb ) { return mMouseDownSignal.connect(cb); } - boost::signals2::connection setMouseUpCallback( const mouse_signal_t::slot_type& cb ) { return mMouseUpSignal.connect(cb); } - boost::signals2::connection setRightMouseDownCallback( const mouse_signal_t::slot_type& cb ) { return mRightMouseDownSignal.connect(cb); } - boost::signals2::connection setRightMouseUpCallback( const mouse_signal_t::slot_type& cb ) { return mRightMouseUpSignal.connect(cb); } + boost::signals2::connection setMouseDownCallback( const mouse_signal_t::slot_type& cb ); + boost::signals2::connection setMouseUpCallback( const mouse_signal_t::slot_type& cb ); + boost::signals2::connection setRightMouseDownCallback( const mouse_signal_t::slot_type& cb ); + boost::signals2::connection setRightMouseUpCallback( const mouse_signal_t::slot_type& cb ); - boost::signals2::connection setDoubleClickCallback( const mouse_signal_t::slot_type& cb ) { return mDoubleClickSignal.connect(cb); } + boost::signals2::connection setDoubleClickCallback( const mouse_signal_t::slot_type& cb ); // *TODO: Deprecate; for backwards compatability only: boost::signals2::connection setCommitCallback( boost::function<void (LLUICtrl*,void*)> cb, void* data); @@ -293,18 +293,18 @@ protected: static bool controlListener(const LLSD& newvalue, LLHandle<LLUICtrl> handle, std::string type); - commit_signal_t mCommitSignal; - enable_signal_t mValidateSignal; + commit_signal_t* mCommitSignal; + enable_signal_t* mValidateSignal; - commit_signal_t mMouseEnterSignal; - commit_signal_t mMouseLeaveSignal; + commit_signal_t* mMouseEnterSignal; + commit_signal_t* mMouseLeaveSignal; - mouse_signal_t mMouseDownSignal; - mouse_signal_t mMouseUpSignal; - mouse_signal_t mRightMouseDownSignal; - mouse_signal_t mRightMouseUpSignal; + mouse_signal_t* mMouseDownSignal; + mouse_signal_t* mMouseUpSignal; + mouse_signal_t* mRightMouseDownSignal; + mouse_signal_t* mRightMouseUpSignal; - mouse_signal_t mDoubleClickSignal; + mouse_signal_t* mDoubleClickSignal; LLViewModelPtr mViewModel; |