diff options
Diffstat (limited to 'linden/indra/llui/llmenugl.cpp')
-rw-r--r-- | linden/indra/llui/llmenugl.cpp | 219 |
1 files changed, 208 insertions, 11 deletions
diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index 91bb581..d5e1186 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp | |||
@@ -149,6 +149,18 @@ LLMenuItemGL::LLMenuItemGL( const std::string& name, const std::string& label, K | |||
149 | setLabel( label ); | 149 | setLabel( label ); |
150 | } | 150 | } |
151 | 151 | ||
152 | LLMenuItemGL::~LLMenuItemGL() { | ||
153 | |||
154 | // Delete all the entries in the mFutureCallbackRequests vector | ||
155 | for(std::vector<LLCallbackInformation*>::iterator iter= mFutureCallbackRequests.begin(); | ||
156 | iter!=mFutureCallbackRequests.end(); | ||
157 | ++iter) { | ||
158 | delete (*iter); | ||
159 | } | ||
160 | |||
161 | } | ||
162 | |||
163 | |||
152 | // virtual | 164 | // virtual |
153 | LLXMLNodePtr LLMenuItemGL::getXML(bool save_children) const | 165 | LLXMLNodePtr LLMenuItemGL::getXML(bool save_children) const |
154 | { | 166 | { |
@@ -517,6 +529,18 @@ BOOL LLMenuItemGL::setLabelArg( const std::string& key, const LLStringExplicit& | |||
517 | return TRUE; | 529 | return TRUE; |
518 | } | 530 | } |
519 | 531 | ||
532 | |||
533 | void LLMenuItemGL::addCallbackType(U8 theType, | ||
534 | const std::string& name, | ||
535 | const std::string& userdata) { | ||
536 | |||
537 | // Add the new callback information to the list of callbacks that are being tracked. | ||
538 | mFutureCallbackRequests.push_back(new LLCallbackInformation(theType,name,userdata)); | ||
539 | |||
540 | } | ||
541 | |||
542 | |||
543 | |||
520 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 544 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
521 | // Class LLMenuItemSeparatorGL | 545 | // Class LLMenuItemSeparatorGL |
522 | // | 546 | // |
@@ -541,6 +565,12 @@ public: | |||
541 | virtual BOOL handleHover(S32 x, S32 y, MASK mask); | 565 | virtual BOOL handleHover(S32 x, S32 y, MASK mask); |
542 | 566 | ||
543 | virtual U32 getNominalHeight( void ) const { return SEPARATOR_HEIGHT_PIXELS; } | 567 | virtual U32 getNominalHeight( void ) const { return SEPARATOR_HEIGHT_PIXELS; } |
568 | |||
569 | virtual BOOL setCtrlResponse(U8 llMenuItemCallType, | ||
570 | const std::string& name, | ||
571 | void* user_data, | ||
572 | void *callback_fcn) { return FALSE; } ; | ||
573 | |||
544 | }; | 574 | }; |
545 | 575 | ||
546 | LLMenuItemSeparatorGL::LLMenuItemSeparatorGL( const std::string &name ) : | 576 | LLMenuItemSeparatorGL::LLMenuItemSeparatorGL( const std::string &name ) : |
@@ -726,6 +756,11 @@ public: | |||
726 | } | 756 | } |
727 | virtual void doIt( void ) {} | 757 | virtual void doIt( void ) {} |
728 | virtual void draw( void ) {} | 758 | virtual void draw( void ) {} |
759 | virtual BOOL setCtrlResponse(U8 llMenuItemCallType, | ||
760 | const std::string& name, | ||
761 | void* user_data, | ||
762 | void *callback_fcn) { return FALSE; } ; | ||
763 | |||
729 | }; | 764 | }; |
730 | 765 | ||
731 | 766 | ||
@@ -805,6 +840,8 @@ LLMenuItemCallGL::LLMenuItemCallGL(const std::string& name, | |||
805 | if(!enabled) setEnabled(FALSE); | 840 | if(!enabled) setEnabled(FALSE); |
806 | } | 841 | } |
807 | 842 | ||
843 | |||
844 | |||
808 | void LLMenuItemCallGL::setEnabledControl(std::string enabled_control, LLView *context) | 845 | void LLMenuItemCallGL::setEnabledControl(std::string enabled_control, LLView *context) |
809 | { | 846 | { |
810 | // Register new listener | 847 | // Register new listener |
@@ -921,6 +958,53 @@ BOOL LLMenuItemCallGL::handleAcceleratorKey( KEY key, MASK mask ) | |||
921 | return LLMenuItemGL::handleAcceleratorKey(key, mask); | 958 | return LLMenuItemGL::handleAcceleratorKey(key, mask); |
922 | } | 959 | } |
923 | 960 | ||
961 | |||
962 | |||
963 | // Method to add a callback function for the given type and name. | ||
964 | BOOL LLMenuItemCallGL::setCtrlResponse(U8 llMenuItemCallType, | ||
965 | const std::string& name, | ||
966 | void* user_data, | ||
967 | void *callback_fcn) { | ||
968 | |||
969 | // Loop through all of the menu items and check to see which ones | ||
970 | // match the name and callback type given. | ||
971 | BOOL result = FALSE; | ||
972 | std::vector<LLCallbackInformation*>::iterator item_iter; | ||
973 | for (item_iter = mFutureCallbackRequests.begin(); | ||
974 | item_iter != mFutureCallbackRequests.end(); | ||
975 | ++item_iter) | ||
976 | { | ||
977 | if( ((*item_iter)->getTypeOfCallback()==llMenuItemCallType) && | ||
978 | ((*item_iter)->getCallbackName()==name)) { | ||
979 | |||
980 | // Found a match. Set the user data and then determine what type it is. | ||
981 | setUserData(user_data); | ||
982 | |||
983 | if(llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK) | ||
984 | { | ||
985 | setMenuCallback((menu_callback)callback_fcn,user_data); | ||
986 | } | ||
987 | |||
988 | else if (llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE) | ||
989 | { | ||
990 | setEnabledCallback((enabled_callback)callback_fcn); | ||
991 | } | ||
992 | |||
993 | else if (llMenuItemCallType == LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE) { | ||
994 | setName((*item_iter)->getCallbackUserData()); | ||
995 | setMenuCallback((menu_callback)callback_fcn,user_data); | ||
996 | } | ||
997 | |||
998 | } | ||
999 | } | ||
1000 | |||
1001 | |||
1002 | return result; | ||
1003 | |||
1004 | } | ||
1005 | |||
1006 | |||
1007 | |||
924 | ///============================================================================ | 1008 | ///============================================================================ |
925 | /// Class LLMenuItemCheckGL | 1009 | /// Class LLMenuItemCheckGL |
926 | ///============================================================================ | 1010 | ///============================================================================ |
@@ -1379,6 +1463,17 @@ void LLMenuItemBranchGL::openMenu() | |||
1379 | } | 1463 | } |
1380 | 1464 | ||
1381 | 1465 | ||
1466 | BOOL LLMenuItemBranchGL::setCtrlResponse(U8 llMenuItemCallType, | ||
1467 | const std::string& name, | ||
1468 | void* user_data, | ||
1469 | void *callback_fcn) { | ||
1470 | |||
1471 | // Get the menu branch and set the callback functions on all its children. | ||
1472 | return(getBranch()->setCtrlResponse(llMenuItemCallType,name,user_data,callback_fcn)); | ||
1473 | |||
1474 | } | ||
1475 | |||
1476 | |||
1382 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 1477 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1383 | // Class LLMenuItemBranchDownGL | 1478 | // Class LLMenuItemBranchDownGL |
1384 | // | 1479 | // |
@@ -1982,13 +2077,31 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory | |||
1982 | 2077 | ||
1983 | LLSimpleListener* callback = parent->getListenerByName(callback_name); | 2078 | LLSimpleListener* callback = parent->getListenerByName(callback_name); |
1984 | 2079 | ||
1985 | if (!callback) | 2080 | if (callback) |
1986 | { | 2081 | { |
1987 | lldebugs << "Ignoring \"on_click\" \"" << item_name << "\" because \"" << callback_name << "\" is not registered" << llendl; | 2082 | new_item->addListener(callback, "on_click", callback_data); |
1988 | continue; | 2083 | } |
2084 | else { | ||
2085 | |||
2086 | // A callback for this item has not yet been | ||
2087 | // specified. Add it to the list of options | ||
2088 | // that do not yet have callbacks. | ||
2089 | if (call_child->hasAttribute("translate")) | ||
2090 | { | ||
2091 | new_item->addCallbackType | ||
2092 | (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_TRANSLATE, | ||
2093 | item_name, | ||
2094 | callback_data); | ||
2095 | } | ||
2096 | |||
2097 | else | ||
2098 | { | ||
2099 | new_item->addCallbackType | ||
2100 | (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_CLICK, | ||
2101 | item_name, | ||
2102 | callback_data); | ||
2103 | } | ||
1989 | } | 2104 | } |
1990 | |||
1991 | new_item->addListener(callback, "on_click", callback_data); | ||
1992 | } | 2105 | } |
1993 | if (call_child->hasName("on_enable")) | 2106 | if (call_child->hasName("on_enable")) |
1994 | { | 2107 | { |
@@ -2016,13 +2129,22 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory | |||
2016 | 2129 | ||
2017 | LLSimpleListener* callback = parent->getListenerByName(callback_name); | 2130 | LLSimpleListener* callback = parent->getListenerByName(callback_name); |
2018 | 2131 | ||
2019 | if (!callback) | 2132 | if (callback) |
2020 | { | 2133 | { |
2021 | lldebugs << "Ignoring \"on_enable\" \"" << item_name << "\" because \"" << callback_name << "\" is not registered" << llendl; | 2134 | new_item->addListener(callback, "on_build", userdata); |
2022 | continue; | 2135 | } else { |
2136 | |||
2137 | // A callback for this item has not yet been | ||
2138 | // specified. Add it to the list of options | ||
2139 | // that do not yet have callbacks. | ||
2140 | |||
2141 | new_item->addCallbackType | ||
2142 | (LLCallbackInformation::LL_MENU_ITEM_CALL_GL_ON_ENABLE, | ||
2143 | item_name, | ||
2144 | callback_data); | ||
2023 | } | 2145 | } |
2024 | 2146 | ||
2025 | new_item->addListener(callback, "on_build", userdata); | 2147 | |
2026 | } | 2148 | } |
2027 | else if (call_child->hasAttribute("control")) | 2149 | else if (call_child->hasAttribute("control")) |
2028 | { | 2150 | { |
@@ -2188,7 +2310,7 @@ LLView* LLMenuGL::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa | |||
2188 | LLColor4 color(0,0,0,1); | 2310 | LLColor4 color(0,0,0,1); |
2189 | if (opaque && LLUICtrlFactory::getAttributeColor(node,"color", color)) | 2311 | if (opaque && LLUICtrlFactory::getAttributeColor(node,"color", color)) |
2190 | { | 2312 | { |
2191 | menu->setBackgroundColor(color); | 2313 | menu->setBackgroundColor(color); |
2192 | } | 2314 | } |
2193 | 2315 | ||
2194 | BOOL create_jump_keys = FALSE; | 2316 | BOOL create_jump_keys = FALSE; |
@@ -2977,7 +3099,8 @@ void LLMenuGL::draw( void ) | |||
2977 | 3099 | ||
2978 | if( mBgVisible ) | 3100 | if( mBgVisible ) |
2979 | { | 3101 | { |
2980 | gl_rect_2d( 0, getRect().getHeight(), getRect().getWidth(), 0, mBackgroundColor ); | 3102 | gl_rect_2d( -1, getRect().getHeight()+2, getRect().getWidth()+2, -2, mBorderColor,FALSE); |
3103 | gl_rect_2d( 0, getRect().getHeight(), getRect().getWidth(), 0, mBackgroundColor ); | ||
2981 | } | 3104 | } |
2982 | LLView::draw(); | 3105 | LLView::draw(); |
2983 | } | 3106 | } |
@@ -3033,6 +3156,41 @@ LLMenuGL* LLMenuGL::getChildMenuByName(const std::string& name, BOOL recurse) co | |||
3033 | return NULL; | 3156 | return NULL; |
3034 | } | 3157 | } |
3035 | 3158 | ||
3159 | |||
3160 | void LLMenuGL::setBackgroundColor( const LLColor4& color ) { | ||
3161 | |||
3162 | mBackgroundColor = color; | ||
3163 | item_list_t::iterator item_iter; | ||
3164 | for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) | ||
3165 | { | ||
3166 | if((*item_iter)->getType()=="menu") | ||
3167 | { | ||
3168 | LLMenuItemBranchGL *menuBranchItem = (LLMenuItemBranchGL*)(*item_iter); | ||
3169 | menuBranchItem->getBranch()->setBackgroundColor(color); | ||
3170 | } | ||
3171 | } | ||
3172 | |||
3173 | |||
3174 | } | ||
3175 | |||
3176 | |||
3177 | void LLMenuGL::setBorderColor( const LLColor4& color ) { | ||
3178 | |||
3179 | mBorderColor = color; | ||
3180 | item_list_t::iterator item_iter; | ||
3181 | for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) | ||
3182 | { | ||
3183 | if((*item_iter)->getType()=="menu") | ||
3184 | { | ||
3185 | LLMenuItemBranchGL *menuBranchItem = (LLMenuItemBranchGL*)(*item_iter); | ||
3186 | menuBranchItem->getBranch()->setBorderColor(color); | ||
3187 | } | ||
3188 | } | ||
3189 | |||
3190 | |||
3191 | } | ||
3192 | |||
3193 | |||
3036 | BOOL LLMenuGL::clearHoverItem() | 3194 | BOOL LLMenuGL::clearHoverItem() |
3037 | { | 3195 | { |
3038 | for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) | 3196 | for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) |
@@ -3098,6 +3256,26 @@ void LLMenuGL::showPopup(LLView* spawning_view, LLMenuGL* menu, S32 x, S32 y) | |||
3098 | menu->getParent()->sendChildToFront(menu); | 3256 | menu->getParent()->sendChildToFront(menu); |
3099 | } | 3257 | } |
3100 | 3258 | ||
3259 | |||
3260 | BOOL LLMenuGL::setCtrlResponse(U8 llMenuItemCallType, | ||
3261 | const std::string& name, | ||
3262 | void* user_data, | ||
3263 | void *callback_fcn) | ||
3264 | { | ||
3265 | |||
3266 | // Go through all of the children on this menu and set the callback function. | ||
3267 | BOOL result = FALSE; | ||
3268 | item_list_t::iterator item_iter; | ||
3269 | for (item_iter = mItems.begin(); item_iter != mItems.end(); ++item_iter) | ||
3270 | { | ||
3271 | result |= (*item_iter)->setCtrlResponse(llMenuItemCallType,name,user_data,callback_fcn); | ||
3272 | } | ||
3273 | |||
3274 | return result; | ||
3275 | } | ||
3276 | |||
3277 | |||
3278 | |||
3101 | //----------------------------------------------------------------------------- | 3279 | //----------------------------------------------------------------------------- |
3102 | // class LLPieMenuBranch | 3280 | // class LLPieMenuBranch |
3103 | // A branch to another pie menu | 3281 | // A branch to another pie menu |
@@ -3117,6 +3295,12 @@ public: | |||
3117 | 3295 | ||
3118 | LLPieMenu* getBranch() { return mBranch; } | 3296 | LLPieMenu* getBranch() { return mBranch; } |
3119 | 3297 | ||
3298 | virtual BOOL setCtrlResponse(U8 llMenuItemCallType, | ||
3299 | const std::string& name, | ||
3300 | void* user_data, | ||
3301 | void *callback_fcn) { return FALSE; } ; | ||
3302 | |||
3303 | |||
3120 | protected: | 3304 | protected: |
3121 | LLPieMenu* mBranch; | 3305 | LLPieMenu* mBranch; |
3122 | }; | 3306 | }; |
@@ -4581,3 +4765,16 @@ void LLTearOffMenu::onClose(bool app_quitting) | |||
4581 | destroy(); | 4765 | destroy(); |
4582 | } | 4766 | } |
4583 | 4767 | ||
4768 | |||
4769 | ///============================================================================ | ||
4770 | /// Class LLCallbackInformation | ||
4771 | ///============================================================================ | ||
4772 | |||
4773 | LLCallbackInformation::LLCallbackInformation(U8 theType, | ||
4774 | const std::string& theName, | ||
4775 | const std::string& userData) | ||
4776 | : callbackName(theName), | ||
4777 | callbackUserData(userData) | ||
4778 | { | ||
4779 | setTypeOfCallback(theType); | ||
4780 | } | ||