lluictrlfactory.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "lluictrlfactory.h"
00035 
00036 #include <fstream>
00037 #include <boost/tokenizer.hpp>
00038 
00039 // other library includes
00040 #include "llcontrol.h"
00041 #include "lldir.h"
00042 #include "v4color.h"
00043 
00044 // this library includes
00045 #include "llbutton.h"
00046 #include "llcheckboxctrl.h"
00047 //#include "llcolorswatch.h"
00048 #include "llcombobox.h"
00049 #include "llcontrol.h"
00050 #include "lldir.h"
00051 #include "llevent.h"
00052 #include "llfloater.h"
00053 #include "lliconctrl.h"
00054 #include "lllineeditor.h"
00055 #include "llmenugl.h"
00056 #include "llradiogroup.h"
00057 #include "llscrollcontainer.h"
00058 #include "llscrollingpanellist.h"
00059 #include "llscrolllistctrl.h"
00060 #include "llslider.h"
00061 #include "llsliderctrl.h"
00062 #include "llspinctrl.h"
00063 #include "lltabcontainer.h"
00064 #include "lltabcontainervertical.h"
00065 #include "lltextbox.h"
00066 #include "lltexteditor.h"
00067 #include "llui.h"
00068 #include "llviewborder.h"
00069 
00070 
00071 const char XML_HEADER[] = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n";
00072 
00073 // *NOTE: If you add a new class derived from LLPanel, add a check for its
00074 // widget type to LLUICtrl::getParentPanel().
00075 // *NOTE: This MUST match EWidgetType in llui.h
00076 //static
00077 const LLString LLUICtrlFactory::sUICtrlNames[WIDGET_TYPE_COUNT] = 
00078 {
00079         LLString("view"),                       //WIDGET_TYPE_VIEW
00080         LLString("root_view"),          //WIDGET_TYPE_ROOT_VIEW
00081         LLString("floater_view"),       //WIDGET_TYPE_FLOATER_VIEW
00082         LLString("button"),             //WIDGET_TYPE_BUTTON
00083         LLString("joystick_turn"),      //WIDGET_TYPE_JOYSTICK_TURN
00084         LLString("joystick_slide"),     //WIDGET_TYPE_JOYSTICK_SLIDE
00085         LLString("check_box"),  //WIDGET_TYPE_CHECKBOX
00086         LLString("color_swatch"),       //WIDGET_TYPE_COLOR_SWATCH
00087         LLString("combo_box"),  //WIDGET_TYPE_COMBO_BOX
00088         LLString("line_editor"),        //WIDGET_TYPE_LINE_EDITOR
00089         LLString("search_editor"),      //WIDGET_TYPE_SEARCH_EDITOR
00090         LLString("scroll_list"),        //WIDGET_TYPE_SCROLL_LIST
00091         LLString("name_list"),  //WIDGET_TYPE_NAME_LIST
00092         LLString("web_browser"),        //WIDGET_TYPE_WEBBROWSER
00093         LLString("slider"),             //WIDGET_TYPE_SLIDER, actually LLSliderCtrl
00094         LLString("slider_bar"), //WIDGET_TYPE_SLIDER_BAR, actually LLSlider
00095         LLString("volume_slider"),      //WIDGET_TYPE_VOLUME_SLIDER, actually LLSlider + "volume" param
00096         LLString("spinner"),            //WIDGET_TYPE_SPINNER, actually LLSpinCtrl
00097         LLString("text_editor"),        //WIDGET_TYPE_TEXT_EDITOR
00098         LLString("texture_picker"),//WIDGET_TYPE_TEXTURE_PICKER
00099         LLString("text"),                       //WIDGET_TYPE_TEXT_BOX
00100         LLString("pad"),                        //WIDGET_TYPE_PAD
00101         LLString("radio_group"),        //WIDGET_TYPE_RADIO_GROUP
00102         LLString("icon"),                       //WIDGET_TYPE_ICON
00103         LLString("locate"),             //WIDGET_TYPE_LOCATE
00104         LLString("view_border"),        //WIDGET_TYPE_VIEW_BORDER
00105         LLString("panel"),              //WIDGET_TYPE_PANEL
00106         LLString("menu"),               //WIDGET_TYPE_MENU
00107         LLString("pie_menu"),   //WIDGET_TYPE_PIE_MENU
00108         LLString("pie_menu_branch"), //WIDGET_TYPE_PIE_MENU_BRANCH
00109         LLString("menu_item"), //WIDGET_TYPE_MENU_ITEM
00110         LLString("menu_item_separator"), //WIDGET_TYPE_MENU_ITEM_SEPARATOR
00111         LLString("menu_separator_vertical"), // WIDGET_TYPE_MENU_SEPARATOR_VERTICAL
00112         LLString("menu_item_call"), // WIDGET_TYPE_MENU_ITEM_CALL
00113         LLString("menu_item_check"),// WIDGET_TYPE_MENU_ITEM_CHECK
00114         LLString("menu_item_branch"), // WIDGET_TYPE_MENU_ITEM_BRANCH
00115         LLString("menu_item_branch_down"), //WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN,
00116         LLString("menu_item_blank"), //WIDGET_TYPE_MENU_ITEM_BLANK,
00117         LLString("tearoff_menu"), //WIDGET_TYPE_TEAROFF_MENU
00118         LLString("menu_bar"),   //WIDGET_TYPE_MENU_BAR
00119         LLString("tab_container"),//WIDGET_TYPE_TAB_CONTAINER
00120         LLString("scroll_container"),//WIDGET_TYPE_SCROLL_CONTAINER
00121         LLString("scrollbar"),  //WIDGET_TYPE_SCROLLBAR
00122         LLString("inventory_panel"), //WIDGET_TYPE_INVENTORY_PANEL
00123         LLString("floater"),            //WIDGET_TYPE_FLOATER
00124         LLString("drag_handle_top"), //WIDGET_TYPE_DRAG_HANDLE_TOP
00125         LLString("drag_handle_left"), //WIDGET_TYPE_DRAG_HANDLE_LEFT
00126         LLString("resize_handle"), //WIDGET_TYPE_RESIZE_HANDLE
00127         LLString("resize_bar"), //WIDGET_TYPE_RESIZE_BAR
00128         LLString("name_editor"),        //WIDGET_TYPE_NAME_EDITOR
00129         LLString("multi_floater"),      //WIDGET_TYPE_MULTI_FLOATER
00130         LLString("media_remote"), //WIDGET_TYPE_MEDIA_REMOTE
00131         LLString("folder_view"), //WIDGET_TYPE_FOLDER_VIEW
00132         LLString("folder_item"), //WIDGET_TYPE_FOLDER_ITEM
00133         LLString("folder"), //WIDGET_TYPE_FOLDER
00134         LLString("stat_graph"), //WIDGET_TYPE_STAT_GRAPH
00135         LLString("stat_view"), //WIDGET_TYPE_STAT_VIEW
00136         LLString("stat_bar"), //WIDGET_TYPE_STAT_BAR
00137         LLString("drop_target"), //WIDGET_TYPE_DROP_TARGET
00138         LLString("texture_bar"), //WIDGET_TYPE_TEXTURE_BAR
00139         LLString("tex_mem_bar"), //WIDGET_TYPE_TEX_MEM_BAR
00140         LLString("snapshot_live_preview"), //WIDGET_TYPE_SNAPSHOT_LIVE_PREVIEW
00141         LLString("status_bar"), //WIDGET_TYPE_STATUS_BAR
00142         LLString("progress_view"), //WIDGET_TYPE_PROGRESS_VIEW
00143         LLString("talk_view"), //WIDGET_TYPE_TALK_VIEW
00144         LLString("overlay_bar"), //WIDGET_TYPE_OVERLAY_BAR
00145         LLString("hud_view"), //WIDGET_TYPE_HUD_VIEW
00146         LLString("hover_view"), //WIDGET_TYPE_HOVER_VIEW
00147         LLString("morph_view"), //WIDGET_TYPE_MORPH_VIEW
00148         LLString("net_map"), //WIDGET_TYPE_NET_MAP
00149         LLString("permissions_view"), //WIDGET_TYPE_PERMISSIONS_VIEW
00150         LLString("menu_holder"), //WIDGET_TYPE_MENU_HOLDER
00151         LLString("debug_view"), //WIDGET_TYPE_DEBUG_VIEW
00152         LLString("scrolling_panel_list"), //WIDGET_TYPE_SCROLLING_PANEL_LIST
00153         LLString("audio_status"), //WIDGET_TYPE_AUDIO_STATUS
00154         LLString("container_view"), //WIDGET_TYPE_CONTAINER_VIEW
00155         LLString("console"), //WIDGET_TYPE_CONSOLE
00156         LLString("fast_timer_view"), //WIDGET_TYPE_FAST_TIMER_VIEW
00157         LLString("velocity_bar"), //WIDGET_TYPE_VELOCITY_BAR
00158         LLString("texture_view"), //WIDGET_TYPE_TEXTURE_VIEW
00159         LLString("memory_view"), //WIDGET_TYPE_MEMORY_VIEW
00160         LLString("frame_stat_view"), //WIDGET_TYPE_FRAME_STAT_VIEW
00161         LLString("layout_stack"), //WIDGET_TYPE_LAYOUT_STACK
00162         LLString("DONT_CARE"),  //WIDGET_TYPE_DONTCARE
00163 };
00164 
00165 const S32 HPAD = 4;
00166 const S32 VPAD = 4;
00167 const S32 FLOATER_H_MARGIN = 15;
00168 const S32 MIN_WIDGET_HEIGHT = 10;
00169 
00170 std::vector<LLString> LLUICtrlFactory::mXUIPaths;
00171 
00172 // UI Ctrl class for padding
00173 class LLUICtrlLocate : public LLUICtrl
00174 {
00175 public:
00176         LLUICtrlLocate() : LLUICtrl("locate", LLRect(0,0,0,0), FALSE, NULL, NULL) {}
00177         virtual void draw() { }
00178 
00179         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_LOCATE; }
00180         virtual LLString getWidgetTag() const { return LL_UI_CTRL_LOCATE_TAG; }
00181 
00182         static LLView *fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00183         {
00184                 LLUICtrlLocate *new_ctrl = new LLUICtrlLocate();
00185                 new_ctrl->initFromXML(node, parent);
00186                 return new_ctrl;
00187         }
00188 };
00189 
00190 //-----------------------------------------------------------------------------
00191 // LLUICtrlFactory()
00192 //-----------------------------------------------------------------------------
00193 LLUICtrlFactory::LLUICtrlFactory()
00194 {
00195         // Register controls
00196         LLUICtrlCreator<LLButton>::registerCreator(LL_BUTTON_TAG, this);
00197         LLUICtrlCreator<LLCheckBoxCtrl>::registerCreator(LL_CHECK_BOX_CTRL_TAG, this);
00198         LLUICtrlCreator<LLComboBox>::registerCreator(LL_COMBO_BOX_TAG, this);
00199         LLUICtrlCreator<LLLineEditor>::registerCreator(LL_LINE_EDITOR_TAG, this);
00200         LLUICtrlCreator<LLSearchEditor>::registerCreator(LL_SEARCH_EDITOR_TAG, this);
00201         LLUICtrlCreator<LLScrollListCtrl>::registerCreator(LL_SCROLL_LIST_CTRL_TAG, this);
00202         LLUICtrlCreator<LLSliderCtrl>::registerCreator(LL_SLIDER_CTRL_TAG, this);
00203         LLUICtrlCreator<LLSlider>::registerCreator(LL_SLIDER_TAG, this);
00204         LLUICtrlCreator<LLSlider>::registerCreator(LL_VOLUME_SLIDER_CTRL_TAG, this);
00205         LLUICtrlCreator<LLSpinCtrl>::registerCreator(LL_SPIN_CTRL_TAG, this);
00206         LLUICtrlCreator<LLTextBox>::registerCreator(LL_TEXT_BOX_TAG, this);
00207         LLUICtrlCreator<LLRadioGroup>::registerCreator(LL_RADIO_GROUP_TAG, this);
00208         LLUICtrlCreator<LLIconCtrl>::registerCreator(LL_ICON_CTRL_TAG, this);
00209         LLUICtrlCreator<LLUICtrlLocate>::registerCreator(LL_UI_CTRL_LOCATE_TAG, this);
00210         LLUICtrlCreator<LLUICtrlLocate>::registerCreator(LL_PAD_TAG, this);
00211         LLUICtrlCreator<LLViewBorder>::registerCreator(LL_VIEW_BORDER_TAG, this);
00212         LLUICtrlCreator<LLTabContainerCommon>::registerCreator(LL_TAB_CONTAINER_COMMON_TAG, this);
00213         LLUICtrlCreator<LLScrollableContainerView>::registerCreator(LL_SCROLLABLE_CONTAINER_VIEW_TAG, this);
00214         LLUICtrlCreator<LLPanel>::registerCreator(LL_PANEL_TAG, this);
00215         LLUICtrlCreator<LLMenuGL>::registerCreator(LL_MENU_GL_TAG, this);
00216         LLUICtrlCreator<LLMenuBarGL>::registerCreator(LL_MENU_BAR_GL_TAG, this);
00217         LLUICtrlCreator<LLScrollingPanelList>::registerCreator(LL_SCROLLING_PANEL_LIST_TAG, this);
00218         LLUICtrlCreator<LLLayoutStack>::registerCreator(LL_LAYOUT_STACK_TAG, this);
00219 
00220         setupPaths();
00221 
00222 }
00223 
00224 void LLUICtrlFactory::setupPaths()
00225 {
00226         LLString filename = gDirUtilp->getExpandedFilename(LL_PATH_SKINS, "paths.xml");
00227 
00228         LLXMLNodePtr root;
00229         BOOL success  = LLXMLNode::parseFile(filename, root, NULL);
00230         mXUIPaths.clear();
00231         
00232         if (!success)
00233         {
00234                 LLString slash = gDirUtilp->getDirDelimiter();
00235                 LLString dir = gDirUtilp->getAppRODataDir() + slash + "skins" + slash + "xui" + slash + "en-us" + slash;
00236                 llwarns << "XUI::config file unable to open." << llendl;
00237                 mXUIPaths.push_back(dir);
00238         }
00239         else
00240         {
00241                 LLXMLNodePtr path;
00242                 LLString app_dir = gDirUtilp->getAppRODataDir();
00243         
00244                 for (path = root->getFirstChild(); path.notNull(); path = path->getNextSibling())
00245                 {
00246                         LLUIString path_val_ui(path->getValue());
00247                         LLString language = "en-us";
00248                         if (LLUI::sConfigGroup)
00249                         {
00250                                 language = LLUI::sConfigGroup->getString("Language");
00251                                 if(language == "default")
00252                                 {
00253                                         language = LLUI::sConfigGroup->getString("SystemLanguage");
00254                                 }
00255                         }
00256                         path_val_ui.setArg("[Language]", language);
00257                         LLString fullpath = app_dir + path_val_ui.getString();
00258 
00259                         if (std::find(mXUIPaths.begin(), mXUIPaths.end(), fullpath) == mXUIPaths.end())
00260                         {
00261                                 mXUIPaths.push_back(app_dir + path_val_ui.getString());
00262                         }
00263                 }
00264         }
00265 
00266 
00267 }
00268 
00269 //-----------------------------------------------------------------------------
00270 // ~LLUICtrlFactory()
00271 //-----------------------------------------------------------------------------
00272 LLUICtrlFactory::~LLUICtrlFactory()
00273 {
00274 }
00275 
00276 
00277 //-----------------------------------------------------------------------------
00278 // getLayeredXMLNode()
00279 //-----------------------------------------------------------------------------
00280 bool LLUICtrlFactory::getLayeredXMLNode(const LLString &filename, LLXMLNodePtr& root)
00281 {
00282         
00283         if (!LLXMLNode::parseFile(mXUIPaths.front() + filename, root, NULL))
00284         {       
00285                 llwarns << "Problem reading UI description file: " << mXUIPaths.front() + filename << llendl;
00286                 return FALSE;
00287         }
00288 
00289         LLXMLNodePtr updateRoot;
00290 
00291         std::vector<LLString>::const_iterator itor;
00292 
00293         for (itor = mXUIPaths.begin(), ++itor; itor != mXUIPaths.end(); ++itor)
00294         {
00295                 LLString nodeName;
00296                 LLString updateName;
00297 
00298                 LLXMLNode::parseFile((*itor) + filename, updateRoot, NULL);
00299         
00300                 updateRoot->getAttributeString("name", updateName);
00301                 root->getAttributeString("name", nodeName);
00302 
00303                 if (updateName == nodeName)
00304                 {
00305                         LLXMLNode::updateNode(root, updateRoot);
00306                 }
00307         }
00308 
00309         return TRUE;
00310 }
00311 
00312 
00313 //-----------------------------------------------------------------------------
00314 // buildFloater()
00315 //-----------------------------------------------------------------------------
00316 void LLUICtrlFactory::buildFloater(LLFloater* floaterp, const LLString &filename, 
00317                                                                         const LLCallbackMap::map_t* factory_map, BOOL open) /* Flawfinder: ignore */
00318 {
00319         LLXMLNodePtr root;
00320 
00321         if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
00322         {
00323                 return;
00324         }
00325         
00326         // root must be called floater
00327         if( !(root->hasName("floater") || root->hasName("multi_floater") ) )
00328         {
00329                 llwarns << "Root node should be named floater in: " << filename << llendl;
00330                 return;
00331         }
00332 
00333         if (factory_map)
00334         {
00335                 mFactoryStack.push_front(factory_map);
00336         }
00337 
00338         floaterp->initFloaterXML(root, NULL, this, open);       /* Flawfinder: ignore */
00339 
00340         if (LLUI::sShowXUINames)
00341         {
00342                 floaterp->mToolTipMsg = filename;
00343         }
00344 
00345         if (factory_map)
00346         {
00347                 mFactoryStack.pop_front();
00348         }
00349 
00350         LLViewHandle handle = floaterp->getHandle();
00351         mBuiltFloaters[handle] = filename;
00352 }
00353 
00354 //-----------------------------------------------------------------------------
00355 // saveToXML()
00356 //-----------------------------------------------------------------------------
00357 S32 LLUICtrlFactory::saveToXML(LLView* viewp, const LLString& filename)
00358 {
00359         llofstream out(filename.c_str());
00360         if (!out.good())
00361         {
00362                 llwarns << "Unable to open " << filename << " for output." << llendl;
00363                 return 1;
00364         }
00365 
00366         out << XML_HEADER;
00367 
00368         LLXMLNodePtr xml_node = viewp->getXML();
00369 
00370         xml_node->writeToOstream(out);
00371 
00372         out.close();
00373         return 0;
00374 }
00375 
00376 //-----------------------------------------------------------------------------
00377 // buildPanel()
00378 //-----------------------------------------------------------------------------
00379 BOOL LLUICtrlFactory::buildPanel(LLPanel* panelp, const LLString &filename,
00380                                                                         const LLCallbackMap::map_t* factory_map)
00381 {
00382         BOOL didPost = FALSE;
00383         LLXMLNodePtr root;
00384 
00385         if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
00386         {
00387                 return didPost;
00388         }
00389 
00390         // root must be called panel
00391         if( !root->hasName("panel" ) )
00392         {
00393                 llwarns << "Root node should be named panel in : " << filename << llendl;
00394                 return didPost;
00395         }
00396 
00397         if (factory_map)
00398         {
00399                 mFactoryStack.push_front(factory_map);
00400         }
00401 
00402         didPost = panelp->initPanelXML(root, NULL, this);
00403         
00404         if (LLUI::sShowXUINames)
00405         {
00406                 panelp->mToolTipMsg = filename;
00407         }
00408 
00409         LLViewHandle handle = panelp->getHandle();
00410         mBuiltPanels[handle] = filename;
00411 
00412         if (factory_map)
00413         {
00414                 mFactoryStack.pop_front();
00415         }
00416 
00417         return didPost;
00418 }
00419 
00420 //-----------------------------------------------------------------------------
00421 // buildMenu()
00422 //-----------------------------------------------------------------------------
00423 LLMenuGL *LLUICtrlFactory::buildMenu(const LLString &filename, LLView* parentp)
00424 {
00425         // TomY TODO: Break this function into buildMenu and buildMenuBar
00426         LLXMLNodePtr root;
00427         LLMenuGL*    menu;
00428 
00429         if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
00430         {
00431                 return NULL;
00432         }
00433 
00434         // root must be called panel
00435         if( !root->hasName( "menu_bar" ) && !root->hasName( "menu" ))
00436         {
00437                 llwarns << "Root node should be named menu bar or menu in : " << filename << llendl;
00438                 return NULL;
00439         }
00440 
00441         
00442 
00443         if (root->hasName("menu"))
00444         {
00445                 menu = (LLMenuGL*)LLMenuGL::fromXML(root, parentp, this);
00446         }
00447         else
00448         {
00449                 menu = (LLMenuGL*)LLMenuBarGL::fromXML(root, parentp, this);
00450         }
00451         
00452         if (LLUI::sShowXUINames)
00453         {
00454                 menu->mToolTipMsg = filename;
00455         }
00456 
00457     return menu;
00458 }
00459 
00460 //-----------------------------------------------------------------------------
00461 // buildMenu()
00462 //-----------------------------------------------------------------------------
00463 LLPieMenu *LLUICtrlFactory::buildPieMenu(const LLString &filename, LLView* parentp)
00464 {
00465 
00466         LLXMLNodePtr root;
00467 
00468         if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
00469         {
00470                 return NULL;
00471         }
00472 
00473         // root must be called panel
00474         if( !root->hasName( LL_PIE_MENU_TAG ))
00475         {
00476                 llwarns << "Root node should be named " << LL_PIE_MENU_TAG << " in : " << filename << llendl;
00477                 return NULL;
00478         }
00479 
00480         LLString name("menu");
00481         root->getAttributeString("name", name);
00482 
00483         LLPieMenu *menu = new LLPieMenu(name);
00484         parentp->addChild(menu);
00485         menu->initXML(root, parentp, this);
00486 
00487         if (LLUI::sShowXUINames)
00488         {
00489                 menu->mToolTipMsg = filename;
00490         }
00491 
00492         return menu;
00493 }
00494 
00495 //-----------------------------------------------------------------------------
00496 // removePanel()
00497 //-----------------------------------------------------------------------------
00498 void LLUICtrlFactory::removePanel(LLPanel* panelp)
00499 {
00500         mBuiltPanels.erase(panelp->getHandle());
00501 }
00502 
00503 //-----------------------------------------------------------------------------
00504 // removeFloater()
00505 //-----------------------------------------------------------------------------
00506 void LLUICtrlFactory::removeFloater(LLFloater* floaterp)
00507 {
00508         mBuiltFloaters.erase(floaterp->getHandle());
00509 }
00510 
00511 //-----------------------------------------------------------------------------
00512 // rebuild()
00513 //-----------------------------------------------------------------------------
00514 void LLUICtrlFactory::rebuild()
00515 {
00516         built_panel_t::iterator built_panel_it;
00517         for (built_panel_it = mBuiltPanels.begin();
00518                 built_panel_it != mBuiltPanels.end();
00519                 ++built_panel_it)
00520                 {
00521                         LLString filename = built_panel_it->second;
00522                         LLPanel* panelp = LLPanel::getPanelByHandle(built_panel_it->first);
00523                         if (!panelp)
00524                         {
00525                                 continue;
00526                         }
00527                         llinfos << "Rebuilding UI panel " << panelp->getName() 
00528                                 << " from " << filename
00529                                 << llendl;
00530                         BOOL visible = panelp->getVisible();
00531                         panelp->setVisible(FALSE);
00532                         panelp->setFocus(FALSE);
00533                         panelp->deleteAllChildren();
00534 
00535                         buildPanel(panelp, filename.c_str(), &panelp->getFactoryMap());
00536                         panelp->setVisible(visible);
00537                 }
00538 
00539         built_floater_t::iterator built_floater_it;
00540         for (built_floater_it = mBuiltFloaters.begin();
00541                 built_floater_it != mBuiltFloaters.end();
00542                 ++built_floater_it)
00543                 {
00544                         LLFloater* floaterp = LLFloater::getFloaterByHandle(built_floater_it->first);
00545                         if (!floaterp)
00546                         {
00547                                 continue;
00548                         }
00549                         LLString filename = built_floater_it->second;
00550                         llinfos << "Rebuilding UI floater " << floaterp->getName()
00551                                 << " from " << filename
00552                                 << llendl;
00553                         BOOL visible = floaterp->getVisible();
00554                         floaterp->setVisible(FALSE);
00555                         floaterp->setFocus(FALSE);
00556                         floaterp->deleteAllChildren();
00557 
00558                         gFloaterView->removeChild(floaterp);
00559                         buildFloater(floaterp, filename, &floaterp->getFactoryMap());
00560                         floaterp->setVisible(visible);
00561                 }
00562 }
00563 
00564 //-----------------------------------------------------------------------------
00565 //-----------------------------------------------------------------------------
00566 
00567 // static
00568 EWidgetType LLUICtrlFactory::getWidgetType(const LLString& ctrl_type)
00569 {
00570         U32 ctrl_id;
00571         for (ctrl_id = 0; ctrl_id < WIDGET_TYPE_COUNT; ctrl_id++)
00572         {
00573                 if (sUICtrlNames[ctrl_id] == ctrl_type)
00574                 {
00575                         break;
00576                 }
00577         }
00578         return (EWidgetType) ctrl_id;
00579 }
00580 
00581 LLString LLUICtrlFactory::getWidgetType(EWidgetType ctrl_type)
00582 {
00583         return sUICtrlNames[ctrl_type];
00584 }
00585 
00586 LLView *LLUICtrlFactory::createCtrlWidget(LLPanel *parent, LLXMLNodePtr node)
00587 {
00588         LLString ctrl_type = node->getName()->mString;
00589         LLString::toLower(ctrl_type);
00590         
00591         creator_list_t::const_iterator it = mCreatorFunctions.find(ctrl_type);
00592         if (it == mCreatorFunctions.end())
00593         {
00594                 llwarns << "Unknown control type " << ctrl_type << llendl;
00595                 return NULL;
00596         }
00597 
00598         LLView *ctrl = (*it->second)(node, parent, this);
00599 
00600         return ctrl;
00601 }
00602 
00603 void LLUICtrlFactory::createWidget(LLPanel *parent, LLXMLNodePtr node)
00604 {
00605         LLView* view = createCtrlWidget(parent, node);
00606 
00607         S32 tab_group = parent->getLastTabGroup();
00608         node->getAttributeS32("tab_group", tab_group);
00609 
00610         if (view)
00611         {
00612                 parent->addChild(view, tab_group);
00613         }
00614 }
00615 
00616 //-----------------------------------------------------------------------------
00617 // createFactoryPanel()
00618 //-----------------------------------------------------------------------------
00619 LLPanel* LLUICtrlFactory::createFactoryPanel(LLString name)
00620 {
00621         std::deque<const LLCallbackMap::map_t*>::iterator itor;
00622         for (itor = mFactoryStack.begin(); itor != mFactoryStack.end(); ++itor)
00623         {
00624                 const LLCallbackMap::map_t* factory_map = *itor;
00625 
00626                 // Look up this panel's name in the map.
00627                 LLCallbackMap::map_const_iter_t iter = factory_map->find( name );
00628                 if (iter != factory_map->end())
00629                 {
00630                         // Use the factory to create the panel, instead of using a default LLPanel.
00631                         LLPanel *ret = (LLPanel*) iter->second.mCallback( iter->second.mData );
00632                         return ret;
00633                 }
00634         }
00635         return NULL;
00636 }
00637 
00638 //-----------------------------------------------------------------------------
00639 
00640 //static
00641 BOOL LLUICtrlFactory::getAttributeColor(LLXMLNodePtr node, const LLString& name, LLColor4& color)
00642 {
00643         LLString colorstring;
00644         BOOL res = node->getAttributeString(name, colorstring);
00645         if (res && LLUI::sColorsGroup)
00646         {
00647                 if (LLUI::sColorsGroup->controlExists(colorstring))
00648                 {
00649                         color.setVec(LLUI::sColorsGroup->getColor(colorstring));
00650                 }
00651                 else
00652                 {
00653                         res = FALSE;
00654                 }
00655         }
00656         if (!res)
00657         {
00658                 res = LLColor4::parseColor(colorstring.c_str(), &color);
00659         }       
00660         if (!res)
00661         {
00662                 res = node->getAttributeColor(name, color);
00663         }
00664         return res;
00665 }
00666 
00667 //============================================================================
00668 
00669 LLButton*       LLUICtrlFactory::getButtonByName(LLPanel* panelp, const LLString& name)
00670 { 
00671         return (LLButton*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_BUTTON); 
00672 }
00673 
00674 LLCheckBoxCtrl*         LLUICtrlFactory::getCheckBoxByName(LLPanel* panelp, const LLString& name)               
00675 { 
00676         return (LLCheckBoxCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_CHECKBOX); 
00677 }
00678 
00679 LLComboBox*                     LLUICtrlFactory::getComboBoxByName(LLPanel* panelp, const LLString& name)               
00680 { 
00681         return (LLComboBox*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_COMBO_BOX); 
00682 }
00683 
00684 LLIconCtrl*                     LLUICtrlFactory::getIconByName(LLPanel* panelp, const LLString& name)                   
00685 { 
00686         return (LLIconCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_ICON); 
00687 }
00688 
00689 LLLineEditor*           LLUICtrlFactory::getLineEditorByName(LLPanel* panelp, const LLString& name)     
00690 { 
00691         return (LLLineEditor*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_LINE_EDITOR); 
00692 }
00693 
00694 LLNameListCtrl* LLUICtrlFactory::getNameListByName(LLPanel* panelp, const LLString& name)       
00695 { 
00696         return (LLNameListCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_NAME_LIST); 
00697 }
00698 
00699 LLRadioGroup*           LLUICtrlFactory::getRadioGroupByName(LLPanel* panelp, const LLString& name)     
00700 { 
00701         return (LLRadioGroup*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_RADIO_GROUP); 
00702 }
00703 
00704 LLScrollListCtrl*       LLUICtrlFactory::getScrollListByName(LLPanel* panelp, const LLString& name)     
00705 { 
00706         return (LLScrollListCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLL_LIST); 
00707 }
00708 
00709 LLSliderCtrl*           LLUICtrlFactory::getSliderByName(LLPanel* panelp, const LLString& name)         
00710 { 
00711         return (LLSliderCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SLIDER); 
00712 }
00713 
00714 LLSlider*                       LLUICtrlFactory::getSliderBarByName(LLPanel* panelp, const LLString& name)              
00715 { 
00716         return (LLSlider*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SLIDER_BAR); 
00717 }
00718 
00719 LLSpinCtrl*                     LLUICtrlFactory::getSpinnerByName(LLPanel* panelp, const LLString& name)                
00720 { 
00721         return (LLSpinCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SPINNER); 
00722 }
00723 
00724 LLTextBox*                      LLUICtrlFactory::getTextBoxByName(LLPanel* panelp, const LLString& name)                
00725 { 
00726         return (LLTextBox*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXT_BOX);
00727 }
00728 
00729 LLTextEditor*           LLUICtrlFactory::getTextEditorByName(LLPanel* panelp, const LLString& name)     
00730 { 
00731         return (LLTextEditor*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXT_EDITOR); 
00732 }
00733 
00734 LLTabContainerCommon* LLUICtrlFactory::getTabContainerByName(LLPanel* panelp, const LLString& name)     
00735 { 
00736         return (LLTabContainerCommon*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TAB_CONTAINER); 
00737 }
00738 
00739 LLScrollableContainerView* LLUICtrlFactory::getScrollableContainerByName(LLPanel* panelp, const LLString& name)
00740 {
00741         return (LLScrollableContainerView*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLL_CONTAINER); 
00742 }
00743 
00744 LLTextureCtrl* LLUICtrlFactory::getTexturePickerByName(LLPanel* panelp, const LLString& name)
00745 {
00746         return (LLTextureCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXTURE_PICKER);
00747 }
00748 
00749 LLPanel* LLUICtrlFactory::getPanelByName(LLPanel* panelp, const LLString& name) 
00750 { 
00751         return (LLPanel*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_PANEL); 
00752 }
00753 
00754 LLColorSwatchCtrl* LLUICtrlFactory::getColorSwatchByName(LLPanel* panelp, const LLString& name)
00755 { 
00756         return (LLColorSwatchCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_COLOR_SWATCH); 
00757 }
00758 
00759 LLWebBrowserCtrl* LLUICtrlFactory::getWebBrowserCtrlByName(LLPanel* panelp, const LLString& name)
00760 { 
00761         return (LLWebBrowserCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_WEBBROWSER); 
00762 }
00763 
00764 LLMenuItemCallGL* LLUICtrlFactory::getMenuItemCallByName(LLPanel* panelp, const LLString& name)
00765 { 
00766         return (LLMenuItemCallGL*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_MENU_ITEM_CALL); 
00767 }
00768 
00769 LLScrollingPanelList* LLUICtrlFactory::getScrollingPanelList(LLPanel* panelp, const LLString& name)
00770 { 
00771         return (LLScrollingPanelList*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLLING_PANEL_LIST); 
00772 }
00773 
00774 
00775 LLCtrlListInterface* LLUICtrlFactory::getListInterfaceByName(LLPanel* panelp, const LLString& name)
00776 {
00777         LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE);
00778         if (viewp && viewp->isCtrl())
00779         {
00780                 return ((LLUICtrl*)viewp)->getListInterface();
00781         }
00782         return NULL;
00783 }
00784 
00785 LLCtrlSelectionInterface* LLUICtrlFactory::getSelectionInterfaceByName(LLPanel* panelp, const LLString& name)
00786 {
00787         LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE);
00788         if (viewp && viewp->isCtrl())
00789         {
00790                 return ((LLUICtrl*)viewp)->getSelectionInterface();
00791         }
00792         return NULL;
00793 }
00794 
00795 LLCtrlScrollInterface* LLUICtrlFactory::getScrollInterfaceByName(LLPanel* panelp, const LLString& name)
00796 {
00797         LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE);
00798         if (viewp && viewp->isCtrl())
00799         {
00800                 return ((LLUICtrl*)viewp)->getScrollInterface();
00801         }
00802         return NULL;
00803 }
00804 
00805 void LLUICtrlFactory::registerCreator(LLString ctrlname, creator_function_t function)
00806 {
00807         LLString::toLower(ctrlname);
00808         mCreatorFunctions[ctrlname] = function;
00809 }
00810 
00811 

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7