aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lluictrlfactory.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/lluictrlfactory.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/lluictrlfactory.cpp759
1 files changed, 759 insertions, 0 deletions
diff --git a/linden/indra/llui/lluictrlfactory.cpp b/linden/indra/llui/lluictrlfactory.cpp
new file mode 100644
index 0000000..5a35783
--- /dev/null
+++ b/linden/indra/llui/lluictrlfactory.cpp
@@ -0,0 +1,759 @@
1/**
2 * @file lluictrlfactory.cpp
3 * @brief Factory class for creating UI controls
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29
30#include "lluictrlfactory.h"
31
32#include <fstream>
33#include <boost/tokenizer.hpp>
34
35// other library includes
36#include "llcontrol.h"
37#include "lldir.h"
38#include "v4color.h"
39
40// this library includes
41#include "llbutton.h"
42#include "llcheckboxctrl.h"
43//#include "llcolorswatch.h"
44#include "llcombobox.h"
45#include "llcontrol.h"
46#include "lldir.h"
47#include "llevent.h"
48#include "llfloater.h"
49#include "lliconctrl.h"
50#include "lllineeditor.h"
51#include "llmenugl.h"
52#include "llradiogroup.h"
53#include "llscrollcontainer.h"
54#include "llscrollingpanellist.h"
55#include "llscrolllistctrl.h"
56#include "llslider.h"
57#include "llsliderctrl.h"
58#include "llspinctrl.h"
59#include "lltabcontainer.h"
60#include "lltabcontainervertical.h"
61#include "lltextbox.h"
62#include "lltexteditor.h"
63#include "llui.h"
64#include "llviewborder.h"
65
66
67const char XML_HEADER[] = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n";
68
69// *NOTE: If you add a new class derived from LLPanel, add a check for its
70// widget type to LLUICtrl::getParentPanel().
71// *NOTE: This MUST match EWidgetType in llui.h
72//static
73const LLString LLUICtrlFactory::sUICtrlNames[WIDGET_TYPE_COUNT] =
74{
75 LLString("view"), //WIDGET_TYPE_VIEW
76 LLString("root_view"), //WIDGET_TYPE_ROOT_VIEW
77 LLString("floater_view"), //WIDGET_TYPE_FLOATER_VIEW
78 LLString("button"), //WIDGET_TYPE_BUTTON
79 LLString("joystick_turn"), //WIDGET_TYPE_JOYSTICK_TURN
80 LLString("joystick_slide"), //WIDGET_TYPE_JOYSTICK_SLIDE
81 LLString("check_box"), //WIDGET_TYPE_CHECKBOX
82 LLString("color_swatch"), //WIDGET_TYPE_COLOR_SWATCH
83 LLString("combo_box"), //WIDGET_TYPE_COMBO_BOX
84 LLString("line_editor"), //WIDGET_TYPE_LINE_EDITOR
85 LLString("search_editor"), //WIDGET_TYPE_SEARCH_EDITOR
86 LLString("scroll_list"), //WIDGET_TYPE_SCROLL_LIST
87 LLString("name_list"), //WIDGET_TYPE_NAME_LIST
88 LLString("web_browser"), //WIDGET_TYPE_WEBBROWSER
89 LLString("slider"), //WIDGET_TYPE_SLIDER, actually LLSliderCtrl
90 LLString("slider_bar"), //WIDGET_TYPE_SLIDER_BAR, actually LLSlider
91 LLString("volume_slider"), //WIDGET_TYPE_VOLUME_SLIDER, actually LLVolumeSliderCtrl
92 LLString("spinner"), //WIDGET_TYPE_SPINNER, actually LLSpinCtrl
93 LLString("text_editor"), //WIDGET_TYPE_TEXT_EDITOR
94 LLString("texture_picker"),//WIDGET_TYPE_TEXTURE_PICKER
95 LLString("text"), //WIDGET_TYPE_TEXT_BOX
96 LLString("pad"), //WIDGET_TYPE_PAD
97 LLString("radio_group"), //WIDGET_TYPE_RADIO_GROUP
98 LLString("icon"), //WIDGET_TYPE_ICON
99 LLString("locate"), //WIDGET_TYPE_LOCATE
100 LLString("view_border"), //WIDGET_TYPE_VIEW_BORDER
101 LLString("panel"), //WIDGET_TYPE_PANEL
102 LLString("menu"), //WIDGET_TYPE_MENU
103 LLString("pie_menu"), //WIDGET_TYPE_PIE_MENU
104 LLString("pie_menu_branch"), //WIDGET_TYPE_PIE_MENU_BRANCH
105 LLString("menu_item"), //WIDGET_TYPE_MENU_ITEM
106 LLString("menu_item_separator"), //WIDGET_TYPE_MENU_ITEM_SEPARATOR
107 LLString("menu_separator_vertical"), // WIDGET_TYPE_MENU_SEPARATOR_VERTICAL
108 LLString("menu_item_call"), // WIDGET_TYPE_MENU_ITEM_CALL
109 LLString("menu_item_check"),// WIDGET_TYPE_MENU_ITEM_CHECK
110 LLString("menu_item_branch"), // WIDGET_TYPE_MENU_ITEM_BRANCH
111 LLString("menu_item_branch_down"), //WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN,
112 LLString("menu_item_blank"), //WIDGET_TYPE_MENU_ITEM_BLANK,
113 LLString("tearoff_menu"), //WIDGET_TYPE_TEAROFF_MENU
114 LLString("menu_bar"), //WIDGET_TYPE_MENU_BAR
115 LLString("tab_container"),//WIDGET_TYPE_TAB_CONTAINER
116 LLString("scroll_container"),//WIDGET_TYPE_SCROLL_CONTAINER
117 LLString("scrollbar"), //WIDGET_TYPE_SCROLLBAR
118 LLString("inventory_panel"), //WIDGET_TYPE_INVENTORY_PANEL
119 LLString("floater"), //WIDGET_TYPE_FLOATER
120 LLString("drag_handle_top"), //WIDGET_TYPE_DRAG_HANDLE_TOP
121 LLString("drag_handle_left"), //WIDGET_TYPE_DRAG_HANDLE_LEFT
122 LLString("resize_handle"), //WIDGET_TYPE_RESIZE_HANDLE
123 LLString("resize_bar"), //WIDGET_TYPE_RESIZE_BAR
124 LLString("name_editor"), //WIDGET_TYPE_NAME_EDITOR
125 LLString("multi_floater"), //WIDGET_TYPE_MULTI_FLOATER
126 LLString("media_remote"), //WIDGET_TYPE_MEDIA_REMOTE
127 LLString("folder_view"), //WIDGET_TYPE_FOLDER_VIEW
128 LLString("folder_item"), //WIDGET_TYPE_FOLDER_ITEM
129 LLString("folder"), //WIDGET_TYPE_FOLDER
130 LLString("stat_graph"), //WIDGET_TYPE_STAT_GRAPH
131 LLString("stat_view"), //WIDGET_TYPE_STAT_VIEW
132 LLString("stat_bar"), //WIDGET_TYPE_STAT_BAR
133 LLString("drop_target"), //WIDGET_TYPE_DROP_TARGET
134 LLString("texture_bar"), //WIDGET_TYPE_TEXTURE_BAR
135 LLString("tex_mem_bar"), //WIDGET_TYPE_TEX_MEM_BAR
136 LLString("snapshot_live_preview"), //WIDGET_TYPE_SNAPSHOT_LIVE_PREVIEW
137 LLString("status_bar"), //WIDGET_TYPE_STATUS_BAR
138 LLString("progress_view"), //WIDGET_TYPE_PROGRESS_VIEW
139 LLString("talk_view"), //WIDGET_TYPE_TALK_VIEW
140 LLString("overlay_bar"), //WIDGET_TYPE_OVERLAY_BAR
141 LLString("hud_view"), //WIDGET_TYPE_HUD_VIEW
142 LLString("hover_view"), //WIDGET_TYPE_HOVER_VIEW
143 LLString("morph_view"), //WIDGET_TYPE_MORPH_VIEW
144 LLString("net_map"), //WIDGET_TYPE_NET_MAP
145 LLString("permissions_view"), //WIDGET_TYPE_PERMISSIONS_VIEW
146 LLString("menu_holder"), //WIDGET_TYPE_MENU_HOLDER
147 LLString("debug_view"), //WIDGET_TYPE_DEBUG_VIEW
148 LLString("scrolling_panel_list"), //WIDGET_TYPE_SCROLLING_PANEL_LIST
149 LLString("audio_status"), //WIDGET_TYPE_AUDIO_STATUS
150 LLString("container_view"), //WIDGET_TYPE_CONTAINER_VIEW
151 LLString("console"), //WIDGET_TYPE_CONSOLE
152 LLString("fast_timer_view"), //WIDGET_TYPE_FAST_TIMER_VIEW
153 LLString("velocity_bar"), //WIDGET_TYPE_VELOCITY_BAR
154 LLString("texture_view"), //WIDGET_TYPE_TEXTURE_VIEW
155 LLString("memory_view"), //WIDGET_TYPE_MEMORY_VIEW
156 LLString("frame_stat_view"), //WIDGET_TYPE_FRAME_STAT_VIEW
157 LLString("DONT_CARE"), //WIDGET_TYPE_DONTCARE
158};
159
160const S32 HPAD = 4;
161const S32 VPAD = 4;
162const S32 FLOATER_H_MARGIN = 15;
163const S32 MIN_WIDGET_HEIGHT = 10;
164
165std::vector<LLString> LLUICtrlFactory::mXUIPaths;
166
167// UI Ctrl class for padding
168class LLUICtrlLocate : public LLUICtrl
169{
170public:
171 LLUICtrlLocate() : LLUICtrl("locate", LLRect(0,0,0,0), FALSE, NULL, NULL) {}
172 virtual void draw() { }
173
174 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_LOCATE; }
175 virtual LLString getWidgetTag() const { return LL_UI_CTRL_LOCATE_TAG; }
176
177 static LLView *fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
178 {
179 LLUICtrlLocate *new_ctrl = new LLUICtrlLocate();
180 new_ctrl->initFromXML(node, parent);
181 return new_ctrl;
182 }
183};
184
185//-----------------------------------------------------------------------------
186// LLUICtrlFactory()
187//-----------------------------------------------------------------------------
188LLUICtrlFactory::LLUICtrlFactory()
189{
190 // Register controls
191 LLUICtrlCreator<LLButton>::registerCreator(LL_BUTTON_TAG, this);
192 LLUICtrlCreator<LLCheckBoxCtrl>::registerCreator(LL_CHECK_BOX_CTRL_TAG, this);
193 LLUICtrlCreator<LLComboBox>::registerCreator(LL_COMBO_BOX_TAG, this);
194 LLUICtrlCreator<LLLineEditor>::registerCreator(LL_LINE_EDITOR_TAG, this);
195 LLUICtrlCreator<LLSearchEditor>::registerCreator(LL_SEARCH_EDITOR_TAG, this);
196 LLUICtrlCreator<LLScrollListCtrl>::registerCreator(LL_SCROLL_LIST_CTRL_TAG, this);
197 LLUICtrlCreator<LLSliderCtrl>::registerCreator(LL_SLIDER_CTRL_TAG, this);
198 LLUICtrlCreator<LLSlider>::registerCreator(LL_SLIDER_TAG, this);
199 LLUICtrlCreator<LLSpinCtrl>::registerCreator(LL_SPIN_CTRL_TAG, this);
200 LLUICtrlCreator<LLTextBox>::registerCreator(LL_TEXT_BOX_TAG, this);
201 LLUICtrlCreator<LLRadioGroup>::registerCreator(LL_RADIO_GROUP_TAG, this);
202 LLUICtrlCreator<LLIconCtrl>::registerCreator(LL_ICON_CTRL_TAG, this);
203 LLUICtrlCreator<LLUICtrlLocate>::registerCreator(LL_UI_CTRL_LOCATE_TAG, this);
204 LLUICtrlCreator<LLUICtrlLocate>::registerCreator(LL_PAD_TAG, this);
205 LLUICtrlCreator<LLViewBorder>::registerCreator(LL_VIEW_BORDER_TAG, this);
206 LLUICtrlCreator<LLTabContainerCommon>::registerCreator(LL_TAB_CONTAINER_COMMON_TAG, this);
207 LLUICtrlCreator<LLScrollableContainerView>::registerCreator(LL_SCROLLABLE_CONTAINER_VIEW_TAG, this);
208 LLUICtrlCreator<LLPanel>::registerCreator(LL_PANEL_TAG, this);
209 LLUICtrlCreator<LLMenuGL>::registerCreator(LL_MENU_GL_TAG, this);
210 LLUICtrlCreator<LLMenuBarGL>::registerCreator(LL_MENU_BAR_GL_TAG, this);
211 LLUICtrlCreator<LLScrollingPanelList>::registerCreator(LL_SCROLLING_PANEL_LIST_TAG, this);
212
213
214 LLString filename = gDirUtilp->getExpandedFilename(LL_PATH_SKINS, "paths.xml");
215
216 LLXMLNodePtr root;
217 BOOL success = LLXMLNode::parseFile(filename, root, NULL);
218
219 if (!success)
220 {
221 LLString slash = gDirUtilp->getDirDelimiter();
222 LLString dir = gDirUtilp->getAppRODataDir() + slash + "skins" + slash + "xui" + slash + "en-us" + slash;
223 llwarns << "XUI::config file unable to open." << llendl;
224 mXUIPaths.push_back(dir);
225 }
226 else
227 {
228 LLXMLNodePtr path;
229 LLString app_dir = gDirUtilp->getAppRODataDir();
230
231 for (path = root->getFirstChild(); path.notNull(); path = path->getNextSibling())
232 {
233 LLUIString path_val_ui(path->getValue());
234 LLString language = "en-us";
235 if (LLUI::sConfigGroup)
236 {
237 language = LLUI::sConfigGroup->getString("Language");
238 }
239 path_val_ui.setArg("[Language]", language);
240 LLString fullpath = app_dir + path_val_ui.getString();
241
242 if (mXUIPaths.empty() || (find(mXUIPaths.begin(), mXUIPaths.end(), fullpath) == mXUIPaths.end()) )
243 {
244 mXUIPaths.push_back(app_dir + path_val_ui.getString());
245 }
246 }
247 }
248
249
250}
251
252//-----------------------------------------------------------------------------
253// ~LLUICtrlFactory()
254//-----------------------------------------------------------------------------
255LLUICtrlFactory::~LLUICtrlFactory()
256{
257}
258
259
260//-----------------------------------------------------------------------------
261// getLayeredXMLNode()
262//-----------------------------------------------------------------------------
263bool LLUICtrlFactory::getLayeredXMLNode(const LLString &filename, LLXMLNodePtr& root)
264{
265
266 if (!LLXMLNode::parseFile(mXUIPaths.front() + filename, root, NULL))
267 {
268 llwarns << "Problem reading UI description file: " << mXUIPaths.front() + filename << llendl;
269 return FALSE;
270 }
271
272 LLXMLNodePtr updateRoot;
273
274 std::vector<LLString>::const_iterator itor;
275
276 for (itor = mXUIPaths.begin(), ++itor; itor != mXUIPaths.end(); ++itor)
277 {
278 LLString nodeName;
279 LLString updateName;
280
281 LLXMLNode::parseFile((*itor) + filename, updateRoot, NULL);
282
283 updateRoot->getAttributeString("name", updateName);
284 root->getAttributeString("name", nodeName);
285
286 if (updateName == nodeName)
287 {
288 LLXMLNode::updateNode(root, updateRoot);
289 }
290 }
291
292 return TRUE;
293}
294
295
296//-----------------------------------------------------------------------------
297// buildFloater()
298//-----------------------------------------------------------------------------
299void LLUICtrlFactory::buildFloater(LLFloater* floaterp, const LLString &filename,
300 const LLCallbackMap::map_t* factory_map, BOOL open)
301{
302 LLXMLNodePtr root;
303
304 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
305 {
306 return;
307 }
308
309 // root must be called floater
310 if( !(root->hasName("floater") || root->hasName("multi_floater") ) )
311 {
312 llwarns << "Root node should be named floater in: " << filename << llendl;
313 return;
314 }
315
316 if (factory_map)
317 {
318 mFactoryStack.push_front(factory_map);
319 }
320
321 floaterp->initFloaterXML(root, NULL, this, open);
322
323 if (LLUI::sShowXUINames)
324 {
325 floaterp->mToolTipMsg = filename;
326 }
327
328 if (factory_map)
329 {
330 mFactoryStack.pop_front();
331 }
332
333 LLViewHandle handle = floaterp->getHandle();
334 mBuiltFloaters[handle] = filename;
335}
336
337//-----------------------------------------------------------------------------
338// saveToXML()
339//-----------------------------------------------------------------------------
340S32 LLUICtrlFactory::saveToXML(LLView* viewp, const LLString& filename)
341{
342 llofstream out(filename.c_str());
343 if (!out.good())
344 {
345 llwarns << "Unable to open " << filename << " for output." << llendl;
346 return 1;
347 }
348
349 out << XML_HEADER;
350
351 LLXMLNodePtr xml_node = viewp->getXML();
352
353 xml_node->writeToOstream(out);
354
355 out.close();
356 return 0;
357}
358
359//-----------------------------------------------------------------------------
360// buildPanel()
361//-----------------------------------------------------------------------------
362void LLUICtrlFactory::buildPanel(LLPanel* panelp, const LLString &filename,
363 const LLCallbackMap::map_t* factory_map)
364{
365 LLXMLNodePtr root;
366
367 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
368 {
369 return;
370 }
371
372 // root must be called panel
373 if( !root->hasName("panel" ) )
374 {
375 llwarns << "Root node should be named panel in : " << filename << llendl;
376 return;
377 }
378
379 if (factory_map)
380 {
381 mFactoryStack.push_front(factory_map);
382 }
383
384 panelp->initPanelXML(root, NULL, this);
385
386 if (LLUI::sShowXUINames)
387 {
388 panelp->mToolTipMsg = filename;
389 }
390
391 LLViewHandle handle = panelp->getHandle();
392 mBuiltPanels[handle] = filename;
393
394 if (factory_map)
395 {
396 mFactoryStack.pop_front();
397 }
398}
399
400//-----------------------------------------------------------------------------
401// buildMenu()
402//-----------------------------------------------------------------------------
403LLMenuGL *LLUICtrlFactory::buildMenu(const LLString &filename, LLView* parentp)
404{
405 // TomY TODO: Break this function into buildMenu and buildMenuBar
406 LLXMLNodePtr root;
407 LLMenuGL* menu;
408
409 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
410 {
411 return NULL;
412 }
413
414 // root must be called panel
415 if( !root->hasName( "menu_bar" ) && !root->hasName( "menu" ))
416 {
417 llwarns << "Root node should be named menu bar or menu in : " << filename << llendl;
418 return NULL;
419 }
420
421
422
423 if (root->hasName("menu"))
424 {
425 menu = (LLMenuGL*)LLMenuGL::fromXML(root, parentp, this);
426 }
427 else
428 {
429 menu = (LLMenuGL*)LLMenuBarGL::fromXML(root, parentp, this);
430 }
431
432 if (LLUI::sShowXUINames)
433 {
434 menu->mToolTipMsg = filename;
435 }
436
437 return menu;
438}
439
440//-----------------------------------------------------------------------------
441// buildMenu()
442//-----------------------------------------------------------------------------
443LLPieMenu *LLUICtrlFactory::buildPieMenu(const LLString &filename, LLView* parentp)
444{
445
446 LLXMLNodePtr root;
447
448 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
449 {
450 return NULL;
451 }
452
453 // root must be called panel
454 if( !root->hasName( LL_PIE_MENU_TAG ))
455 {
456 llwarns << "Root node should be named " LL_PIE_MENU_TAG " in : " << filename << llendl;
457 return NULL;
458 }
459
460 LLString name("menu");
461 root->getAttributeString("name", name);
462
463 LLPieMenu *menu = new LLPieMenu(name);
464 parentp->addChild(menu);
465 menu->initXML(root, parentp, this);
466
467 if (LLUI::sShowXUINames)
468 {
469 menu->mToolTipMsg = filename;
470 }
471
472 return menu;
473}
474
475//-----------------------------------------------------------------------------
476// removePanel()
477//-----------------------------------------------------------------------------
478void LLUICtrlFactory::removePanel(LLPanel* panelp)
479{
480 mBuiltPanels.erase(panelp->getHandle());
481}
482
483//-----------------------------------------------------------------------------
484// removeFloater()
485//-----------------------------------------------------------------------------
486void LLUICtrlFactory::removeFloater(LLFloater* floaterp)
487{
488 mBuiltFloaters.erase(floaterp->getHandle());
489}
490
491//-----------------------------------------------------------------------------
492// rebuild()
493//-----------------------------------------------------------------------------
494void LLUICtrlFactory::rebuild()
495{
496 built_panel_t::iterator built_panel_it;
497 for (built_panel_it = mBuiltPanels.begin();
498 built_panel_it != mBuiltPanels.end();
499 ++built_panel_it)
500 {
501 LLString filename = built_panel_it->second;
502 LLPanel* panelp = LLPanel::getPanelByHandle(built_panel_it->first);
503 if (!panelp)
504 {
505 continue;
506 }
507 llinfos << "Rebuilding UI panel " << panelp->getName()
508 << " from " << filename
509 << llendl;
510 BOOL visible = panelp->getVisible();
511 panelp->setVisible(FALSE);
512 panelp->setFocus(FALSE);
513 panelp->deleteAllChildren();
514
515 buildPanel(panelp, filename.c_str(), &panelp->getFactoryMap());
516 panelp->setVisible(visible);
517 }
518
519 built_floater_t::iterator built_floater_it;
520 for (built_floater_it = mBuiltFloaters.begin();
521 built_floater_it != mBuiltFloaters.end();
522 ++built_floater_it)
523 {
524 LLFloater* floaterp = LLFloater::getFloaterByHandle(built_floater_it->first);
525 if (!floaterp)
526 {
527 continue;
528 }
529 LLString filename = built_floater_it->second;
530 llinfos << "Rebuilding UI floater " << floaterp->getName()
531 << " from " << filename
532 << llendl;
533 BOOL visible = floaterp->getVisible();
534 floaterp->setVisible(FALSE);
535 floaterp->setFocus(FALSE);
536 floaterp->deleteAllChildren();
537
538 gFloaterView->removeChild(floaterp);
539 buildFloater(floaterp, filename, &floaterp->getFactoryMap());
540 floaterp->setVisible(visible);
541 }
542}
543
544//-----------------------------------------------------------------------------
545//-----------------------------------------------------------------------------
546
547// static
548EWidgetType LLUICtrlFactory::getWidgetType(const LLString& ctrl_type)
549{
550 U32 ctrl_id;
551 for (ctrl_id = 0; ctrl_id < WIDGET_TYPE_COUNT; ctrl_id++)
552 {
553 if (sUICtrlNames[ctrl_id] == ctrl_type)
554 {
555 break;
556 }
557 }
558 return (EWidgetType) ctrl_id;
559}
560
561LLString LLUICtrlFactory::getWidgetType(EWidgetType ctrl_type)
562{
563 return sUICtrlNames[ctrl_type];
564}
565
566LLView *LLUICtrlFactory::createCtrlWidget(LLPanel *parent, LLXMLNodePtr node)
567{
568 LLString ctrl_type = node->getName()->mString;
569 LLString::toLower(ctrl_type);
570
571 creator_list_t::const_iterator it = mCreatorFunctions.find(ctrl_type);
572 if (it == mCreatorFunctions.end())
573 {
574 llwarns << "Unknown control type " << ctrl_type << llendl;
575 return NULL;
576 }
577
578 LLView *ctrl = (*it->second)(node, parent, this);
579
580 return ctrl;
581}
582
583void LLUICtrlFactory::createWidget(LLPanel *parent, LLXMLNodePtr node)
584{
585 LLView* view = createCtrlWidget(parent, node);
586
587 S32 tab_group = parent->getLastTabGroup();
588 node->getAttributeS32("tab_group", tab_group);
589
590 if (view)
591 {
592 parent->addChild(view, tab_group);
593 }
594}
595
596//-----------------------------------------------------------------------------
597// createFactoryPanel()
598//-----------------------------------------------------------------------------
599LLPanel* LLUICtrlFactory::createFactoryPanel(LLString name)
600{
601 std::deque<const LLCallbackMap::map_t*>::iterator itor;
602 for (itor = mFactoryStack.begin(); itor != mFactoryStack.end(); ++itor)
603 {
604 const LLCallbackMap::map_t* factory_map = *itor;
605
606 // Look up this panel's name in the map.
607 LLCallbackMap::map_const_iter_t iter = factory_map->find( name );
608 if (iter != factory_map->end())
609 {
610 // Use the factory to create the panel, instead of using a default LLPanel.
611 LLPanel *ret = (LLPanel*) iter->second.mCallback( iter->second.mData );
612 return ret;
613 }
614 }
615 return NULL;
616}
617
618//-----------------------------------------------------------------------------
619
620//static
621BOOL LLUICtrlFactory::getAttributeColor(LLXMLNodePtr node, const LLString& name, LLColor4& color)
622{
623 LLString colorstring;
624 BOOL res = node->getAttributeString(name, colorstring);
625 if (res && LLUI::sColorsGroup)
626 {
627 if (LLUI::sColorsGroup->controlExists(colorstring))
628 {
629 color.setVec(LLUI::sColorsGroup->getColor(colorstring));
630 }
631 else
632 {
633 res = FALSE;
634 }
635 }
636 if (!res)
637 {
638 res = LLColor4::parseColor(colorstring.c_str(), &color);
639 }
640 if (!res)
641 {
642 res = node->getAttributeColor(name, color);
643 }
644 return res;
645}
646
647//============================================================================
648
649LLButton* LLUICtrlFactory::getButtonByName(LLPanel* panelp, const LLString& name)
650{
651 return (LLButton*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_BUTTON);
652}
653
654LLCheckBoxCtrl* LLUICtrlFactory::getCheckBoxByName(LLPanel* panelp, const LLString& name)
655{
656 return (LLCheckBoxCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_CHECKBOX);
657}
658
659LLComboBox* LLUICtrlFactory::getComboBoxByName(LLPanel* panelp, const LLString& name)
660{
661 return (LLComboBox*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_COMBO_BOX);
662}
663
664LLIconCtrl* LLUICtrlFactory::getIconByName(LLPanel* panelp, const LLString& name)
665{
666 return (LLIconCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_ICON);
667}
668
669LLLineEditor* LLUICtrlFactory::getLineEditorByName(LLPanel* panelp, const LLString& name)
670{
671 return (LLLineEditor*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_LINE_EDITOR);
672}
673
674LLNameListCtrl* LLUICtrlFactory::getNameListByName(LLPanel* panelp, const LLString& name)
675{
676 return (LLNameListCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_NAME_LIST);
677}
678
679LLRadioGroup* LLUICtrlFactory::getRadioGroupByName(LLPanel* panelp, const LLString& name)
680{
681 return (LLRadioGroup*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_RADIO_GROUP);
682}
683
684LLScrollListCtrl* LLUICtrlFactory::getScrollListByName(LLPanel* panelp, const LLString& name)
685{
686 return (LLScrollListCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLL_LIST);
687}
688
689LLSliderCtrl* LLUICtrlFactory::getSliderByName(LLPanel* panelp, const LLString& name)
690{
691 return (LLSliderCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SLIDER);
692}
693
694LLSlider* LLUICtrlFactory::getSliderBarByName(LLPanel* panelp, const LLString& name)
695{
696 return (LLSlider*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SLIDER_BAR);
697}
698
699LLSpinCtrl* LLUICtrlFactory::getSpinnerByName(LLPanel* panelp, const LLString& name)
700{
701 return (LLSpinCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SPINNER);
702}
703
704LLTextBox* LLUICtrlFactory::getTextBoxByName(LLPanel* panelp, const LLString& name)
705{
706 return (LLTextBox*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXT_BOX);
707}
708
709LLTextEditor* LLUICtrlFactory::getTextEditorByName(LLPanel* panelp, const LLString& name)
710{
711 return (LLTextEditor*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXT_EDITOR);
712}
713
714LLTabContainerCommon* LLUICtrlFactory::getTabContainerByName(LLPanel* panelp, const LLString& name)
715{
716 return (LLTabContainerCommon*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TAB_CONTAINER);
717}
718
719LLScrollableContainerView* LLUICtrlFactory::getScrollableContainerByName(LLPanel* panelp, const LLString& name)
720{
721 return (LLScrollableContainerView*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLL_CONTAINER);
722}
723
724LLTextureCtrl* LLUICtrlFactory::getTexturePickerByName(LLPanel* panelp, const LLString& name)
725{
726 return (LLTextureCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_TEXTURE_PICKER);
727}
728
729LLPanel* LLUICtrlFactory::getPanelByName(LLPanel* panelp, const LLString& name)
730{
731 return (LLPanel*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_PANEL);
732}
733
734LLColorSwatchCtrl* LLUICtrlFactory::getColorSwatchByName(LLPanel* panelp, const LLString& name)
735{
736 return (LLColorSwatchCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_COLOR_SWATCH);
737}
738
739LLWebBrowserCtrl* LLUICtrlFactory::getWebBrowserCtrlByName(LLPanel* panelp, const LLString& name)
740{
741 return (LLWebBrowserCtrl*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_WEBBROWSER);
742}
743
744LLMenuItemCallGL* LLUICtrlFactory::getMenuItemCallByName(LLPanel* panelp, const LLString& name)
745{
746 return (LLMenuItemCallGL*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_MENU_ITEM_CALL);
747}
748
749LLScrollingPanelList* LLUICtrlFactory::getScrollingPanelList(LLPanel* panelp, const LLString& name)
750{
751 return (LLScrollingPanelList*)panelp->getCtrlByNameAndType(name, WIDGET_TYPE_SCROLLING_PANEL_LIST);
752}
753
754void LLUICtrlFactory::registerCreator(LLString ctrlname, creator_function_t function)
755{
756 LLString::toLower(ctrlname);
757 mCreatorFunctions[ctrlname] = function;
758}
759