summaryrefslogtreecommitdiff
path: root/indra/llui/llpanel.cpp
blob: d580566b13d5525333e685f5c9d859de8a618f3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
/**
 * @file llpanel.cpp
 * @brief LLPanel base class
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

// Opaque view with a background and a border.  Can contain LLUICtrls.

#include "linden_common.h"

#define LLPANEL_CPP
#include "llpanel.h"

#include "llfocusmgr.h"
#include "llfontgl.h"
#include "llrect.h"
#include "llerror.h"
#include "lldir.h"
#include "lltimer.h"

#include "llbutton.h"
#include "llmenugl.h"
#include "llui.h"
#include "llkeyboard.h"
#include "lllineeditor.h"
#include "llcontrol.h"
#include "lltextbox.h"
#include "lluictrl.h"
#include "lluictrlfactory.h"
#include "llviewborder.h"

static LLDefaultChildRegistry::Register<LLPanel> r1("panel", &LLPanel::fromXML);
LLPanel::factory_stack_t    LLPanel::sFactoryStack;


// Compiler optimization, generate extern template
template class LLPanel* LLView::getChild<class LLPanel>(
    const std::string& name, BOOL recurse) const;

LLPanel::LocalizedString::LocalizedString()
:   name("name"),
    value("value")
{}

const LLPanel::Params& LLPanel::getDefaultParams()
{
    return LLUICtrlFactory::getDefaultParams<LLPanel>();
}

LLPanel::Params::Params()
:   has_border("border", false),
    border(""),
    background_visible("background_visible", false),
    background_opaque("background_opaque", false),
    bg_opaque_color("bg_opaque_color"),
    bg_alpha_color("bg_alpha_color"),
    bg_opaque_image_overlay("bg_opaque_image_overlay"),
    bg_alpha_image_overlay("bg_alpha_image_overlay"),
    bg_opaque_image("bg_opaque_image"),
    bg_alpha_image("bg_alpha_image"),
    min_width("min_width", 100),
    min_height("min_height", 100),
    strings("string"),
    filename("filename"),
    class_name("class"),
    help_topic("help_topic"),
    visible_callback("visible_callback"),
    accepts_badge("accepts_badge")
{
    addSynonym(background_visible, "bg_visible");
    addSynonym(has_border, "border_visible");
    addSynonym(label, "title");
}


LLPanel::LLPanel(const LLPanel::Params& p)
:   LLUICtrl(p),
    LLBadgeHolder(p.accepts_badge),
    mBgVisible(p.background_visible),
    mBgOpaque(p.background_opaque),
    mBgOpaqueColor(p.bg_opaque_color()),
    mBgAlphaColor(p.bg_alpha_color()),
    mBgOpaqueImageOverlay(p.bg_opaque_image_overlay),
    mBgAlphaImageOverlay(p.bg_alpha_image_overlay),
    mBgOpaqueImage(p.bg_opaque_image()),
    mBgAlphaImage(p.bg_alpha_image()),
    mDefaultBtn(NULL),
    mBorder(NULL),
    mLabel(p.label),
    mHelpTopic(p.help_topic),
    mCommitCallbackRegistrar(false),
    mEnableCallbackRegistrar(false),
    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.
{
    if (p.has_border)
    {
        addBorder(p.border);
    }
}

LLPanel::~LLPanel()
{
    delete mVisibleSignal;
}

// virtual
BOOL LLPanel::isPanel() const
{
    return TRUE;
}

void LLPanel::addBorder(LLViewBorder::Params p)
{
    removeBorder();
    p.rect = getLocalRect();

    mBorder = LLUICtrlFactory::create<LLViewBorder>(p);
    addChild( mBorder );
}

void LLPanel::addBorder()
{
    LLViewBorder::Params p;
    p.border_thickness(LLPANEL_BORDER_WIDTH);
    addBorder(p);
}


void LLPanel::removeBorder()
{
    if (mBorder)
    {
        removeChild(mBorder);
        delete mBorder;
        mBorder = NULL;
    }
}


// virtual
void LLPanel::clearCtrls()
{
    LLPanel::ctrl_list_t ctrls = getCtrlList();
    for (LLPanel::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it)
    {
        LLUICtrl* ctrl = *ctrl_it;
        ctrl->setFocus( FALSE );
        ctrl->setEnabled( FALSE );
        ctrl->clear();
    }
}

void LLPanel::setCtrlsEnabled( BOOL b )
{
    LLPanel::ctrl_list_t ctrls = getCtrlList();
    for (LLPanel::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it)
    {
        LLUICtrl* ctrl = *ctrl_it;
        ctrl->setEnabled( b );
    }
}

LLPanel::ctrl_list_t LLPanel::getCtrlList() const
{
    ctrl_list_t controls;
    for(child_list_t::const_iterator it = getChildList()->begin(), end_it = getChildList()->end(); it != end_it; ++it)
    {
        LLView* viewp = *it;
        if(viewp->isCtrl())
        {
            controls.push_back(static_cast<LLUICtrl*>(viewp));
        }
    }
    return controls;
}


void LLPanel::draw()
{
    F32 alpha = getDrawContext().mAlpha;

    // draw background
    if( mBgVisible )
    {
        alpha = getCurrentTransparency();

        LLRect local_rect = getLocalRect();
        if (mBgOpaque )
        {
            // opaque, in-front look
            if (mBgOpaqueImage.notNull())
            {
                mBgOpaqueImage->draw( local_rect, mBgOpaqueImageOverlay % alpha );
            }
            else
            {
                // fallback to flat colors when there are no images
                gl_rect_2d( local_rect, mBgOpaqueColor.get() % alpha);
            }
        }
        else
        {
            // transparent, in-back look
            if (mBgAlphaImage.notNull())
            {
                mBgAlphaImage->draw( local_rect, mBgAlphaImageOverlay % alpha );
            }
            else
            {
                gl_rect_2d( local_rect, mBgAlphaColor.get() % alpha );
            }
        }
    }

    updateDefaultBtn();

    LLView::draw();
}

void LLPanel::updateDefaultBtn()
{
    if( mDefaultBtn)
    {
        if (gFocusMgr.childHasKeyboardFocus( this ) && mDefaultBtn->getEnabled())
        {
            LLButton* buttonp = dynamic_cast<LLButton*>(gFocusMgr.getKeyboardFocus());
            BOOL focus_is_child_button = buttonp && buttonp->getCommitOnReturn();
            // only enable default button when current focus is not a return-capturing button
            mDefaultBtn->setBorderEnabled(!focus_is_child_button);
        }
        else
        {
            mDefaultBtn->setBorderEnabled(FALSE);
        }
    }
}

void LLPanel::refresh()
{
    // do nothing by default
    // but is automatically called in setFocus(TRUE)
}

void LLPanel::setDefaultBtn(LLButton* btn)
{
    if (mDefaultBtn && mDefaultBtn->getEnabled())
    {
        mDefaultBtn->setBorderEnabled(FALSE);
    }
    mDefaultBtn = btn;
    if (mDefaultBtn)
    {
        mDefaultBtn->setBorderEnabled(TRUE);
    }
}

void LLPanel::setDefaultBtn(const std::string& id)
{
    LLButton *button = getChild<LLButton>(id);
    if (button)
    {
        setDefaultBtn(button);
    }
    else
    {
        setDefaultBtn(NULL);
    }
}

BOOL LLPanel::handleKeyHere( KEY key, MASK mask )
{
    BOOL handled = FALSE;

    LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());

    // handle user hitting ESC to defocus
    if (key == KEY_ESCAPE)
    {
        setFocus(FALSE);
        return TRUE;
    }
    else if( (mask == MASK_SHIFT) && (KEY_TAB == key))
    {
        //SHIFT-TAB
        if (cur_focus)
        {
            LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot();
            if (focus_root)
            {
                handled = focus_root->focusPrevItem(FALSE);
            }
        }
    }
    else if( (mask == MASK_NONE ) && (KEY_TAB == key))
    {
        //TAB
        if (cur_focus)
        {
            LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot();
            if (focus_root)
            {
                handled = focus_root->focusNextItem(FALSE);
            }
        }
    }

    // If RETURN was pressed and something has focus, call onCommit()
    if (!handled && cur_focus && key == KEY_RETURN && mask == MASK_NONE)
    {
        LLButton* focused_button = dynamic_cast<LLButton*>(cur_focus);
        if (focused_button && focused_button->getCommitOnReturn())
        {
            // current focus is a return-capturing button,
            // let *that* button handle the return key
            handled = FALSE;
        }
        else if (mDefaultBtn && mDefaultBtn->getVisible() && mDefaultBtn->getEnabled())
        {
            // If we have a default button, click it when return is pressed
            mDefaultBtn->onCommit();
            handled = TRUE;
        }
        else if (cur_focus->acceptsTextInput())
        {
            // call onCommit for text input handling control
            cur_focus->onCommit();
            handled = TRUE;
        }
    }

    return handled;
}

void LLPanel::onVisibilityChange ( BOOL new_visibility )
{
    LLUICtrl::onVisibilityChange ( new_visibility );
    if (mVisibleSignal)
        (*mVisibleSignal)(this, LLSD(new_visibility) ); // Pass BOOL as LLSD
}

void LLPanel::setFocus(BOOL b)
{
    if( b && !hasFocus())
    {
        // give ourselves focus preemptively, to avoid infinite loop
        LLUICtrl::setFocus(TRUE);
        // then try to pass to first valid child
        focusFirstItem();
    }
    else
    {
        LLUICtrl::setFocus(b);
    }
}

void LLPanel::setBorderVisible(BOOL b)
{
    if (mBorder)
    {
        mBorder->setVisible( b );
    }
}

LLTrace::BlockTimerStatHandle FTM_PANEL_CONSTRUCTION("Panel Construction");

LLView* LLPanel::fromXML(LLXMLNodePtr node, LLView* parent, LLXMLNodePtr output_node)
{
    std::string name("panel");
    node->getAttributeString("name", name);

    std::string class_attr;
    node->getAttributeString("class", class_attr);

    LLPanel* panelp = NULL;

    {   LL_RECORD_BLOCK_TIME(FTM_PANEL_CONSTRUCTION);

        if(!class_attr.empty())
        {
            panelp = LLRegisterPanelClass::instance().createPanelClass(class_attr);
            if (!panelp)
            {
                LL_WARNS() << "Panel class \"" << class_attr << "\" not registered." << LL_ENDL;
            }
        }

        if (!panelp)
        {
            panelp = createFactoryPanel(name);
            llassert(panelp);

            if (!panelp)
            {
                return NULL; // :(
            }
        }

    }
    // factory panels may have registered their own factory maps
    if (!panelp->getFactoryMap().empty())
    {
        sFactoryStack.push_back(&panelp->getFactoryMap());
    }
    // for local registry callbacks; define in constructor, referenced in XUI or postBuild
    panelp->mCommitCallbackRegistrar.pushScope();
    panelp->mEnableCallbackRegistrar.pushScope();

    panelp->initPanelXML(node, parent, output_node, LLUICtrlFactory::getDefaultParams<LLPanel>());

    panelp->mCommitCallbackRegistrar.popScope();
    panelp->mEnableCallbackRegistrar.popScope();

    if (!panelp->getFactoryMap().empty())
    {
        sFactoryStack.pop_back();
    }

    return panelp;
}

void LLPanel::initFromParams(const LLPanel::Params& p)
{
    //setting these here since panel constructor not called with params
    //and LLView::initFromParams will use them to set visible and enabled
    setVisible(p.visible);
    setEnabled(p.enabled);
    setFocusRoot(p.focus_root);
    setSoundFlags(p.sound_flags);

     // control_name, tab_stop, focus_lost_callback, initial_value, rect, enabled, visible
    LLUICtrl::initFromParams(p);

    // visible callback
    if (p.visible_callback.isProvided())
    {
        setVisibleCallback(initCommitCallback(p.visible_callback));
    }

    for (LLInitParam::ParamIterator<LocalizedString>::const_iterator it = p.strings.begin();
        it != p.strings.end();
        ++it)
    {
        mUIStrings[it->name] = it->value;
    }

    setLabel(p.label());
    setHelpTopic(p.help_topic);
    setShape(p.rect);
    parseFollowsFlags(p);

    setToolTip(p.tool_tip());
    setFromXUI(p.from_xui);

    mHoverCursor = getCursorFromString(p.hover_cursor);

    if (p.has_border)
    {
        addBorder(p.border);
    }
    // let constructors set this value if not provided
    if (p.use_bounding_rect.isProvided())
    {
        setUseBoundingRect(p.use_bounding_rect);
    }
    setDefaultTabGroup(p.default_tab_group);
    setMouseOpaque(p.mouse_opaque);

    setBackgroundVisible(p.background_visible);
    setBackgroundOpaque(p.background_opaque);
    setBackgroundColor(p.bg_opaque_color().get());
    setTransparentColor(p.bg_alpha_color().get());
    mBgOpaqueImage = p.bg_opaque_image();
    mBgAlphaImage = p.bg_alpha_image();
    mBgOpaqueImageOverlay = p.bg_opaque_image_overlay;
    mBgAlphaImageOverlay = p.bg_alpha_image_overlay;

    setAcceptsBadge(p.accepts_badge);
}

static LLTrace::BlockTimerStatHandle FTM_PANEL_SETUP("Panel Setup");
static LLTrace::BlockTimerStatHandle FTM_EXTERNAL_PANEL_LOAD("Load Extern Panel Reference");
static LLTrace::BlockTimerStatHandle FTM_PANEL_POSTBUILD("Panel PostBuild");

BOOL LLPanel::initPanelXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node, const LLPanel::Params& default_params)
{
    Params params(default_params);
    {
        LL_RECORD_BLOCK_TIME(FTM_PANEL_SETUP);

        LLXMLNodePtr referenced_xml;
        std::string xml_filename = mXMLFilename;

        // if the panel didn't provide a filename, check the node
        if (xml_filename.empty())
        {
            node->getAttributeString("filename", xml_filename);
            setXMLFilename(xml_filename);
        }

        LLXUIParser parser;

        if (!xml_filename.empty())
        {
            if (output_node)
            {
                //if we are exporting, we want to export the current xml
                //not the referenced xml
                parser.readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
                Params output_params(params);
                setupParamsForExport(output_params, parent);
                output_node->setName(node->getName()->mString);
                parser.writeXUI(output_node, output_params, LLInitParam::default_parse_rules(), &default_params);
                return TRUE;
            }

            LLUICtrlFactory::instance().pushFileName(xml_filename);

            LL_RECORD_BLOCK_TIME(FTM_EXTERNAL_PANEL_LOAD);
            if (!LLUICtrlFactory::getLayeredXMLNode(xml_filename, referenced_xml))
            {
                LL_WARNS() << "Couldn't parse panel from: " << xml_filename << LL_ENDL;

                return FALSE;
            }

            parser.readXUI(referenced_xml, params, LLUICtrlFactory::getInstance()->getCurFileName());

            // add children using dimensions from referenced xml for consistent layout
            setShape(params.rect);
            LLUICtrlFactory::createChildren(this, referenced_xml, child_registry_t::instance());

            LLUICtrlFactory::instance().popFileName();
        }

        // ask LLUICtrlFactory for filename, since xml_filename might be empty
        parser.readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());

        if (output_node)
        {
            Params output_params(params);
            setupParamsForExport(output_params, parent);
            output_node->setName(node->getName()->mString);
            parser.writeXUI(output_node, output_params, LLInitParam::default_parse_rules(), &default_params);
        }

        params.from_xui = true;
        applyXUILayout(params, parent);
        {
            LL_RECORD_BLOCK_TIME(FTM_PANEL_CONSTRUCTION);
            initFromParams(params);
        }

        // add children
        LLUICtrlFactory::createChildren(this, node, child_registry_t::instance(), output_node);

        // Connect to parent after children are built, because tab containers
        // do a reshape() on their child panels, which requires that the children
        // be built/added. JC
        if (parent)
        {
            S32 tab_group = params.tab_group.isProvided() ? params.tab_group() : parent->getLastTabGroup();
            parent->addChild(this, tab_group);
        }

        {
            LL_RECORD_BLOCK_TIME(FTM_PANEL_POSTBUILD);
            postBuild();
        }
    }
    return TRUE;
}

bool LLPanel::hasString(const std::string& name)
{
    return mUIStrings.find(name) != mUIStrings.end();
}

std::string LLPanel::getString(const std::string& name, const LLStringUtil::format_map_t& args) const
{
    ui_string_map_t::const_iterator found_it = mUIStrings.find(name);
    if (found_it != mUIStrings.end())
    {
        // make a copy as format works in place
        LLUIString formatted_string = LLUIString(found_it->second);
        formatted_string.setArgList(args);
        return formatted_string.getString();
    }
    std::string err_str("Failed to find string " + name + " in panel " + getName()); //*TODO: Translate
    if(LLUI::getInstance()->mSettingGroups["config"]->getBOOL("QAMode"))
    {
        LL_ERRS() << err_str << LL_ENDL;
    }
    else
    {
        LL_WARNS() << err_str << LL_ENDL;
    }
    return LLStringUtil::null;
}

std::string LLPanel::getString(const std::string& name) const
{
    ui_string_map_t::const_iterator found_it = mUIStrings.find(name);
    if (found_it != mUIStrings.end())
    {
        return found_it->second;
    }
    std::string err_str("Failed to find string " + name + " in panel " + getName()); //*TODO: Translate
    if(LLUI::getInstance()->mSettingGroups["config"]->getBOOL("QAMode"))
    {
        LL_ERRS() << err_str << LL_ENDL;
    }
    else
    {
        LL_WARNS() << err_str << LL_ENDL;
    }
    return LLStringUtil::null;
}


void LLPanel::childSetVisible(const std::string& id, bool visible)
{
    LLView* child = findChild<LLView>(id);
    if (child)
    {
        child->setVisible(visible);
    }
}

void LLPanel::childSetEnabled(const std::string& id, bool enabled)
{
    LLView* child = findChild<LLView>(id);
    if (child)
    {
        child->setEnabled(enabled);
    }
}

void LLPanel::childSetFocus(const std::string& id, BOOL focus)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        child->setFocus(focus);
    }
}

BOOL LLPanel::childHasFocus(const std::string& id)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->hasFocus();
    }
    else
    {
        return FALSE;
    }
}

// *TODO: Deprecate; for backwards compatability only:
// Prefer getChild<LLUICtrl>("foo")->setCommitCallback(boost:bind(...)),
// which takes a generic slot.  Or use mCommitCallbackRegistrar.add() with
// a named callback and reference it in XML.
void LLPanel::childSetCommitCallback(const std::string& id, boost::function<void (LLUICtrl*,void*)> cb, void* data)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        child->setCommitCallback(boost::bind(cb, child, data));
    }
}

void LLPanel::childSetColor(const std::string& id, const LLColor4& color)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        child->setColor(color);
    }
}

LLCtrlSelectionInterface* LLPanel::childGetSelectionInterface(const std::string& id) const
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->getSelectionInterface();
    }
    return NULL;
}

LLCtrlListInterface* LLPanel::childGetListInterface(const std::string& id) const
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->getListInterface();
    }
    return NULL;
}

LLCtrlScrollInterface* LLPanel::childGetScrollInterface(const std::string& id) const
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->getScrollInterface();
    }
    return NULL;
}

void LLPanel::childSetValue(const std::string& id, LLSD value)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        child->setValue(value);
    }
}

LLSD LLPanel::childGetValue(const std::string& id) const
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->getValue();
    }
    // Not found => return undefined
    return LLSD();
}

BOOL LLPanel::childSetTextArg(const std::string& id, const std::string& key, const LLStringExplicit& text)
{
    LLUICtrl* child = findChild<LLUICtrl>(id);
    if (child)
    {
        return child->setTextArg(key, text);
    }
    return FALSE;
}

BOOL LLPanel::childSetLabelArg(const std::string& id, const std::string& key, const LLStringExplicit& text)
{
    LLView* child = findChild<LLView>(id);
    if (child)
    {
        return child->setLabelArg(key, text);
    }
    return FALSE;
}

void LLPanel::childSetAction(const std::string& id, const commit_signal_t::slot_type& function)
{
    LLButton* button = findChild<LLButton>(id);
    if (button)
    {
        button->setClickedCallback(function);
    }
}

void LLPanel::childSetAction(const std::string& id, boost::function<void(void*)> function, void* value)
{
    LLButton* button = findChild<LLButton>(id);
    if (button)
    {
        button->setClickedCallback(boost::bind(function, value));
    }
}

boost::signals2::connection LLPanel::setVisibleCallback( const commit_signal_t::slot_type& cb )
{
    if (!mVisibleSignal)
    {
        mVisibleSignal = new commit_signal_t();
    }

    return mVisibleSignal->connect(cb);
}

//-----------------------------------------------------------------------------
// buildPanel()
//-----------------------------------------------------------------------------
BOOL LLPanel::buildFromFile(const std::string& filename, const LLPanel::Params& default_params)
{
    LL_PROFILE_ZONE_SCOPED;
    BOOL didPost = FALSE;
    LLXMLNodePtr root;

    if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
    {
        LL_WARNS() << "Couldn't parse panel from: " << filename << LL_ENDL;
        return didPost;
    }

    // root must be called panel
    if( !root->hasName("panel" ) )
    {
        LL_WARNS() << "Root node should be named panel in : " << filename << LL_ENDL;
        return didPost;
    }

    LL_DEBUGS() << "Building panel " << filename << LL_ENDL;

    LLUICtrlFactory::instance().pushFileName(filename);
    {
        if (!getFactoryMap().empty())
        {
            sFactoryStack.push_back(&getFactoryMap());
        }

         // for local registry callbacks; define in constructor, referenced in XUI or postBuild
        getCommitCallbackRegistrar().pushScope();
        getEnableCallbackRegistrar().pushScope();

        didPost = initPanelXML(root, NULL, NULL, default_params);

        getCommitCallbackRegistrar().popScope();
        getEnableCallbackRegistrar().popScope();

        setXMLFilename(filename);

        if (!getFactoryMap().empty())
        {
            sFactoryStack.pop_back();
        }
    }
    LLUICtrlFactory::instance().popFileName();
    return didPost;
}

//-----------------------------------------------------------------------------
// createFactoryPanel()
//-----------------------------------------------------------------------------
LLPanel* LLPanel::createFactoryPanel(const std::string& name)
{
    std::deque<const LLCallbackMap::map_t*>::iterator itor;
    for (itor = sFactoryStack.begin(); itor != sFactoryStack.end(); ++itor)
    {
        const LLCallbackMap::map_t* factory_map = *itor;

        // Look up this panel's name in the map.
        LLCallbackMap::map_const_iter_t iter = factory_map->find( name );
        if (iter != factory_map->end())
        {
            // Use the factory to create the panel, instead of using a default LLPanel.
            LLPanel *ret = (LLPanel*) iter->second.mCallback( iter->second.mData );
            return ret;
        }
    }
    LLPanel::Params panel_p;
    return LLUICtrlFactory::create<LLPanel>(panel_p);
}