diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/llpanel.cpp | |
parent | README.txt (diff) | |
download | meta-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 'linden/indra/llui/llpanel.cpp')
-rw-r--r-- | linden/indra/llui/llpanel.cpp | 1049 |
1 files changed, 1049 insertions, 0 deletions
diff --git a/linden/indra/llui/llpanel.cpp b/linden/indra/llui/llpanel.cpp new file mode 100644 index 0000000..c2c29bb --- /dev/null +++ b/linden/indra/llui/llpanel.cpp | |||
@@ -0,0 +1,1049 @@ | |||
1 | /** | ||
2 | * @file llpanel.cpp | ||
3 | * @brief LLPanel base class | ||
4 | * | ||
5 | * Copyright (c) 2001-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 | // Opaque view with a background and a border. Can contain LLUICtrls. | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | |||
32 | #include "llpanel.h" | ||
33 | |||
34 | #include "llalertdialog.h" | ||
35 | #include "llfocusmgr.h" | ||
36 | #include "llfontgl.h" | ||
37 | #include "llrect.h" | ||
38 | #include "llerror.h" | ||
39 | #include "lltimer.h" | ||
40 | |||
41 | #include "llmenugl.h" | ||
42 | //#include "llstatusbar.h" | ||
43 | #include "llui.h" | ||
44 | #include "llkeyboard.h" | ||
45 | #include "lllineeditor.h" | ||
46 | #include "llcontrol.h" | ||
47 | #include "lltextbox.h" | ||
48 | #include "lluictrl.h" | ||
49 | #include "lluictrlfactory.h" | ||
50 | #include "llviewborder.h" | ||
51 | #include "llbutton.h" | ||
52 | |||
53 | LLPanel::panel_map_t LLPanel::sPanelMap; | ||
54 | LLPanel::alert_queue_t LLPanel::sAlertQueue; | ||
55 | |||
56 | void LLPanel::init() | ||
57 | { | ||
58 | // mRectControl | ||
59 | mBgColorAlpha = LLUI::sColorsGroup->getColor( "DefaultBackgroundColor" ); | ||
60 | mBgColorOpaque = LLUI::sColorsGroup->getColor( "FocusBackgroundColor" ); | ||
61 | mDefaultBtnHighlight = LLUI::sColorsGroup->getColor( "DefaultHighlightLight" ); | ||
62 | mBgVisible = FALSE; | ||
63 | mBgOpaque = FALSE; | ||
64 | mBorder = NULL; | ||
65 | mDefaultBtn = NULL; | ||
66 | setIsChrome(FALSE); //is this a decorator to a live window or a form? | ||
67 | mLastTabGroup = 0; | ||
68 | |||
69 | // add self to handle->panel map | ||
70 | sPanelMap[mViewHandle] = this; | ||
71 | setTabStop(FALSE); | ||
72 | } | ||
73 | |||
74 | LLPanel::LLPanel() | ||
75 | : mRectControl() | ||
76 | { | ||
77 | init(); | ||
78 | } | ||
79 | |||
80 | LLPanel::LLPanel(const LLString& name) | ||
81 | : LLUICtrl(name, LLRect(0, 0, 0, 0), TRUE, NULL, NULL), | ||
82 | mRectControl() | ||
83 | { | ||
84 | init(); | ||
85 | } | ||
86 | |||
87 | |||
88 | LLPanel::LLPanel(const LLString& name, const LLRect& rect, BOOL bordered) | ||
89 | : LLUICtrl(name, rect, TRUE, NULL, NULL), | ||
90 | mRectControl() | ||
91 | { | ||
92 | init(); | ||
93 | if (bordered) | ||
94 | { | ||
95 | addBorder(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
100 | LLPanel::LLPanel(const LLString& name, const LLString& rect_control, BOOL bordered) | ||
101 | : LLUICtrl(name, LLUI::sConfigGroup->getRect(rect_control), TRUE, NULL, NULL), | ||
102 | mRectControl( rect_control ) | ||
103 | { | ||
104 | init(); | ||
105 | if (bordered) | ||
106 | { | ||
107 | addBorder(); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void LLPanel::addBorder(LLViewBorder::EBevel border_bevel, | ||
112 | LLViewBorder::EStyle border_style, S32 border_thickness) | ||
113 | { | ||
114 | mBorder = new LLViewBorder( "panel border", | ||
115 | LLRect(0, mRect.getHeight(), mRect.getWidth(), 0), | ||
116 | border_bevel, border_style, border_thickness ); | ||
117 | mBorder->setSaveToXML(false); | ||
118 | addChild( mBorder ); | ||
119 | } | ||
120 | |||
121 | |||
122 | LLPanel::~LLPanel() | ||
123 | { | ||
124 | if( !mRectControl.empty() ) | ||
125 | { | ||
126 | LLUI::sConfigGroup->setRect( mRectControl, mRect ); | ||
127 | } | ||
128 | sPanelMap.erase(mViewHandle); | ||
129 | } | ||
130 | |||
131 | |||
132 | // virtual | ||
133 | EWidgetType LLPanel::getWidgetType() const | ||
134 | { | ||
135 | return WIDGET_TYPE_PANEL; | ||
136 | } | ||
137 | |||
138 | // virtual | ||
139 | LLString LLPanel::getWidgetTag() const | ||
140 | { | ||
141 | return LL_PANEL_TAG; | ||
142 | } | ||
143 | |||
144 | // virtual | ||
145 | BOOL LLPanel::isPanel() | ||
146 | { | ||
147 | return TRUE; | ||
148 | } | ||
149 | |||
150 | // virtual | ||
151 | BOOL LLPanel::postBuild() | ||
152 | { | ||
153 | return TRUE; | ||
154 | } | ||
155 | |||
156 | // virtual | ||
157 | void LLPanel::clearCtrls() | ||
158 | { | ||
159 | LLView::ctrl_list_t ctrls = getCtrlList(); | ||
160 | for (LLView::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it) | ||
161 | { | ||
162 | LLUICtrl* ctrl = *ctrl_it; | ||
163 | ctrl->setFocus( FALSE ); | ||
164 | ctrl->setEnabled( FALSE ); | ||
165 | ctrl->clear(); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | void LLPanel::setCtrlsEnabled( BOOL b ) | ||
170 | { | ||
171 | LLView::ctrl_list_t ctrls = getCtrlList(); | ||
172 | for (LLView::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it) | ||
173 | { | ||
174 | LLUICtrl* ctrl = *ctrl_it; | ||
175 | ctrl->setEnabled( b ); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | void LLPanel::draw() | ||
180 | { | ||
181 | if( getVisible() ) | ||
182 | { | ||
183 | // draw background | ||
184 | if( mBgVisible ) | ||
185 | { | ||
186 | S32 left = LLPANEL_BORDER_WIDTH; | ||
187 | S32 top = mRect.getHeight() - LLPANEL_BORDER_WIDTH; | ||
188 | S32 right = mRect.getWidth() - LLPANEL_BORDER_WIDTH; | ||
189 | S32 bottom = LLPANEL_BORDER_WIDTH; | ||
190 | |||
191 | if (mBgOpaque ) | ||
192 | { | ||
193 | gl_rect_2d( left, top, right, bottom, mBgColorOpaque ); | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | gl_rect_2d( left, top, right, bottom, mBgColorAlpha ); | ||
198 | } | ||
199 | } | ||
200 | |||
201 | if( mDefaultBtn) | ||
202 | { | ||
203 | if (gFocusMgr.childHasKeyboardFocus( this ) && mDefaultBtn->getEnabled()) | ||
204 | { | ||
205 | LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus(); | ||
206 | BOOL focus_is_child_button = focus_ctrl->getWidgetType() == WIDGET_TYPE_BUTTON && static_cast<LLButton *>(focus_ctrl)->getCommitOnReturn(); | ||
207 | // only enable default button when current focus is not a return-capturing button | ||
208 | mDefaultBtn->setBorderEnabled(!focus_is_child_button); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | mDefaultBtn->setBorderEnabled(FALSE); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | LLView::draw(); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | void LLPanel::refresh() | ||
221 | { | ||
222 | // do nothing by default | ||
223 | // but is automatically called in setFocus(TRUE) | ||
224 | } | ||
225 | |||
226 | void LLPanel::setDefaultBtn(LLButton* btn) | ||
227 | { | ||
228 | if (mDefaultBtn && mDefaultBtn->getEnabled()) | ||
229 | { | ||
230 | mDefaultBtn->setBorderEnabled(FALSE); | ||
231 | } | ||
232 | mDefaultBtn = btn; | ||
233 | if (mDefaultBtn) | ||
234 | { | ||
235 | mDefaultBtn->setBorderEnabled(TRUE); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | void LLPanel::setDefaultBtn(const LLString& id) | ||
240 | { | ||
241 | LLButton *button = LLUICtrlFactory::getButtonByName(this, id); | ||
242 | if (button) | ||
243 | { | ||
244 | setDefaultBtn(button); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | setDefaultBtn(NULL); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | BOOL LLPanel::handleKey(KEY key, MASK mask, BOOL called_from_parent) | ||
253 | { | ||
254 | BOOL handled = FALSE; | ||
255 | if (getVisible() && getEnabled()) | ||
256 | { | ||
257 | if( (mask == MASK_SHIFT) && (KEY_TAB == key)) | ||
258 | { | ||
259 | //SHIFT-TAB | ||
260 | LLView* cur_focus = gFocusMgr.getKeyboardFocus(); | ||
261 | if (cur_focus && gFocusMgr.childHasKeyboardFocus(this)) | ||
262 | { | ||
263 | LLView* focus_root = cur_focus; | ||
264 | while(cur_focus->getParent()) | ||
265 | { | ||
266 | cur_focus = cur_focus->getParent(); | ||
267 | if (cur_focus->isFocusRoot()) | ||
268 | { | ||
269 | // this is the root-most focus root found so far | ||
270 | focus_root = cur_focus; | ||
271 | } | ||
272 | } | ||
273 | handled = focus_root->focusPrevItem(FALSE); | ||
274 | } | ||
275 | else if (!cur_focus && mIsFocusRoot) | ||
276 | { | ||
277 | handled = focusLastItem(); | ||
278 | if (!handled) | ||
279 | { | ||
280 | setFocus(TRUE); | ||
281 | handled = TRUE; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | else | ||
286 | if( (mask == MASK_NONE ) && (KEY_TAB == key)) | ||
287 | { | ||
288 | //TAB | ||
289 | LLView* cur_focus = gFocusMgr.getKeyboardFocus(); | ||
290 | if (cur_focus && gFocusMgr.childHasKeyboardFocus(this)) | ||
291 | { | ||
292 | LLView* focus_root = cur_focus; | ||
293 | while(cur_focus->getParent()) | ||
294 | { | ||
295 | cur_focus = cur_focus->getParent(); | ||
296 | if (cur_focus->isFocusRoot()) | ||
297 | { | ||
298 | focus_root = cur_focus; | ||
299 | } | ||
300 | } | ||
301 | handled = focus_root->focusNextItem(FALSE); | ||
302 | } | ||
303 | else if (!cur_focus && mIsFocusRoot) | ||
304 | { | ||
305 | handled = focusFirstItem(); | ||
306 | if (!handled) | ||
307 | { | ||
308 | setFocus(TRUE); | ||
309 | handled = TRUE; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | |||
315 | if (!handled) | ||
316 | { | ||
317 | handled = LLView::handleKey(key, mask, called_from_parent); | ||
318 | } | ||
319 | |||
320 | return handled; | ||
321 | } | ||
322 | |||
323 | void LLPanel::addCtrl( LLUICtrl* ctrl, S32 tab_group) | ||
324 | { | ||
325 | mLastTabGroup = tab_group; | ||
326 | |||
327 | LLView::addCtrl(ctrl, tab_group); | ||
328 | // propagate chrome to children only if they have not been flagged as chrome | ||
329 | if (!ctrl->getIsChrome()) | ||
330 | { | ||
331 | ctrl->setIsChrome(getIsChrome()); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | void LLPanel::addCtrlAtEnd( LLUICtrl* ctrl, S32 tab_group) | ||
336 | { | ||
337 | mLastTabGroup = tab_group; | ||
338 | |||
339 | LLView::addCtrlAtEnd(ctrl, tab_group); | ||
340 | if (!ctrl->getIsChrome()) | ||
341 | { | ||
342 | ctrl->setIsChrome(getIsChrome()); | ||
343 | } | ||
344 | } | ||
345 | |||
346 | BOOL LLPanel::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ) | ||
347 | { | ||
348 | BOOL handled = FALSE; | ||
349 | |||
350 | if( getVisible() && getEnabled() && gFocusMgr.childHasKeyboardFocus(this) && KEY_ESCAPE == key ) | ||
351 | { | ||
352 | gFocusMgr.setKeyboardFocus(NULL, NULL); | ||
353 | return TRUE; | ||
354 | } | ||
355 | |||
356 | if( getVisible() && getEnabled() && | ||
357 | gFocusMgr.childHasKeyboardFocus(this) && !called_from_parent ) | ||
358 | { | ||
359 | LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); | ||
360 | if (key == KEY_RETURN && mask == MASK_NONE) | ||
361 | { | ||
362 | // set keyboard focus to self to trigger commitOnFocusLost behavior on current ctrl | ||
363 | if (cur_focus && cur_focus->acceptsTextInput()) | ||
364 | { | ||
365 | cur_focus->onCommit(); | ||
366 | handled = TRUE; | ||
367 | } | ||
368 | } | ||
369 | |||
370 | // If we have a default button, click it when | ||
371 | // return is pressed, unless current focus is a return-capturing button | ||
372 | // in which case *that* button will handle the return key | ||
373 | if (!(cur_focus->getWidgetType() == WIDGET_TYPE_BUTTON && static_cast<LLButton *>(cur_focus)->getCommitOnReturn())) | ||
374 | { | ||
375 | // RETURN key means hit default button in this case | ||
376 | if (key == KEY_RETURN && mask == MASK_NONE | ||
377 | && mDefaultBtn != NULL | ||
378 | && mDefaultBtn->getVisible() | ||
379 | && mDefaultBtn->getEnabled()) | ||
380 | { | ||
381 | mDefaultBtn->onCommit(); | ||
382 | handled = TRUE; | ||
383 | } | ||
384 | } | ||
385 | } | ||
386 | |||
387 | return handled; | ||
388 | } | ||
389 | |||
390 | void LLPanel::requires(LLString name, EWidgetType type) | ||
391 | { | ||
392 | mRequirements[name] = type; | ||
393 | } | ||
394 | |||
395 | BOOL LLPanel::checkRequirements() | ||
396 | { | ||
397 | BOOL retval = TRUE; | ||
398 | LLString message; | ||
399 | |||
400 | for (requirements_map_t::iterator i = mRequirements.begin(); i != mRequirements.end(); ++i) | ||
401 | { | ||
402 | if (!this->getCtrlByNameAndType(i->first, i->second)) | ||
403 | { | ||
404 | retval = FALSE; | ||
405 | message += i->first + " " + LLUICtrlFactory::getWidgetType(i->second) + "\n"; | ||
406 | } | ||
407 | } | ||
408 | |||
409 | if (!retval) | ||
410 | { | ||
411 | LLString::format_map_t args; | ||
412 | args["[COMPONENTS]"] = message; | ||
413 | args["[FLOATER]"] = getName(); | ||
414 | |||
415 | llwarns << getName() << " failed requirements check on: \n" | ||
416 | << message << llendl; | ||
417 | |||
418 | alertXml("FailedRequirementsCheck", args); | ||
419 | } | ||
420 | |||
421 | return retval; | ||
422 | } | ||
423 | |||
424 | //static | ||
425 | void LLPanel::alertXml(LLString label, LLString::format_map_t args) | ||
426 | { | ||
427 | sAlertQueue.push(LLAlertInfo(label,args)); | ||
428 | } | ||
429 | |||
430 | //static | ||
431 | BOOL LLPanel::nextAlert(LLAlertInfo &alert) | ||
432 | { | ||
433 | if (!sAlertQueue.empty()) | ||
434 | { | ||
435 | alert = sAlertQueue.front(); | ||
436 | sAlertQueue.pop(); | ||
437 | return TRUE; | ||
438 | } | ||
439 | |||
440 | return FALSE; | ||
441 | } | ||
442 | |||
443 | void LLPanel::setFocus(BOOL b) | ||
444 | { | ||
445 | if( b ) | ||
446 | { | ||
447 | if (!gFocusMgr.childHasKeyboardFocus(this)) | ||
448 | { | ||
449 | //refresh(); | ||
450 | if (!focusFirstItem()) | ||
451 | { | ||
452 | LLUICtrl::setFocus(TRUE); | ||
453 | } | ||
454 | onFocusReceived(); | ||
455 | } | ||
456 | } | ||
457 | else | ||
458 | { | ||
459 | if( this == gFocusMgr.getKeyboardFocus() ) | ||
460 | { | ||
461 | gFocusMgr.setKeyboardFocus( NULL, NULL ); | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | //RN: why is this here? | ||
466 | LLView::ctrl_list_t ctrls = getCtrlList(); | ||
467 | for (LLView::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it) | ||
468 | { | ||
469 | LLUICtrl* ctrl = *ctrl_it; | ||
470 | ctrl->setFocus( FALSE ); | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | } | ||
475 | |||
476 | void LLPanel::setBackgroundColor(const LLColor4& color) | ||
477 | { | ||
478 | mBgColorOpaque = color; | ||
479 | } | ||
480 | |||
481 | void LLPanel::setTransparentColor(const LLColor4& color) | ||
482 | { | ||
483 | mBgColorAlpha = color; | ||
484 | } | ||
485 | |||
486 | void LLPanel::setBorderVisible(BOOL b) | ||
487 | { | ||
488 | if (mBorder) | ||
489 | { | ||
490 | mBorder->setVisible( b ); | ||
491 | } | ||
492 | } | ||
493 | |||
494 | LLView* LLPanel::getCtrlByNameAndType(const LLString& name, EWidgetType type) | ||
495 | { | ||
496 | LLView* view = getChildByName(name, TRUE); | ||
497 | if (view) | ||
498 | { | ||
499 | if (type == WIDGET_TYPE_DONTCARE || view->getWidgetType() == type) | ||
500 | { | ||
501 | return view; | ||
502 | } | ||
503 | else | ||
504 | { | ||
505 | llwarns << "Widget " << name << " has improper type in panel " << mName << "\n" | ||
506 | << "Is: \t\t" << view->getWidgetType() << "\n" | ||
507 | << "Should be: \t" << type | ||
508 | << llendl; | ||
509 | } | ||
510 | } | ||
511 | else | ||
512 | { | ||
513 | childNotFound(name); | ||
514 | } | ||
515 | return NULL; | ||
516 | } | ||
517 | |||
518 | // static | ||
519 | LLPanel* LLPanel::getPanelByHandle(LLViewHandle handle) | ||
520 | { | ||
521 | if (!sPanelMap.count(handle)) | ||
522 | { | ||
523 | return NULL; | ||
524 | } | ||
525 | |||
526 | return sPanelMap[handle]; | ||
527 | } | ||
528 | |||
529 | // virtual | ||
530 | LLXMLNodePtr LLPanel::getXML(bool save_children) const | ||
531 | { | ||
532 | LLXMLNodePtr node = LLView::getXML(); | ||
533 | |||
534 | if (mBorder && mBorder->getVisible()) | ||
535 | { | ||
536 | node->createChild("border", TRUE)->setBoolValue(TRUE); | ||
537 | } | ||
538 | |||
539 | if (!mRectControl.empty()) | ||
540 | { | ||
541 | node->createChild("rect_control", TRUE)->setStringValue(mRectControl); | ||
542 | } | ||
543 | |||
544 | if (!mLabel.empty()) | ||
545 | { | ||
546 | node->createChild("label", TRUE)->setStringValue(mLabel); | ||
547 | } | ||
548 | |||
549 | if (save_children) | ||
550 | { | ||
551 | LLView::child_list_const_reverse_iter_t rit; | ||
552 | for (rit = getChildList()->rbegin(); rit != getChildList()->rend(); ++rit) | ||
553 | { | ||
554 | LLView* childp = *rit; | ||
555 | |||
556 | if (childp->getSaveToXML()) | ||
557 | { | ||
558 | LLXMLNodePtr xml_node = childp->getXML(); | ||
559 | |||
560 | node->addChild(xml_node); | ||
561 | } | ||
562 | } | ||
563 | } | ||
564 | |||
565 | return node; | ||
566 | } | ||
567 | |||
568 | LLView* LLPanel::fromXML(LLXMLNodePtr node, LLView* parentp, LLUICtrlFactory *factory) | ||
569 | { | ||
570 | LLString name("panel"); | ||
571 | node->getAttributeString("name", name); | ||
572 | |||
573 | LLPanel* panelp = factory->createFactoryPanel(name); | ||
574 | // Fall back on a default panel, if there was no special factory. | ||
575 | if (!panelp) | ||
576 | { | ||
577 | panelp = new LLPanel("tab panel"); | ||
578 | } | ||
579 | |||
580 | panelp->initPanelXML(node, parentp, factory); | ||
581 | |||
582 | return panelp; | ||
583 | } | ||
584 | |||
585 | void LLPanel::initPanelXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) | ||
586 | { | ||
587 | LLString name("panel"); | ||
588 | node->getAttributeString("name", name); | ||
589 | setName(name); | ||
590 | |||
591 | setPanelParameters(node, parent); | ||
592 | |||
593 | LLXMLNodePtr child; | ||
594 | for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) | ||
595 | { | ||
596 | factory->createWidget(this, child); | ||
597 | } | ||
598 | |||
599 | LLString xml_filename; | ||
600 | node->getAttributeString("filename", xml_filename); | ||
601 | if (!xml_filename.empty()) | ||
602 | { | ||
603 | factory->buildPanel(this, xml_filename, NULL); | ||
604 | } | ||
605 | |||
606 | postBuild(); | ||
607 | } | ||
608 | |||
609 | void LLPanel::setPanelParameters(LLXMLNodePtr node, LLView* parentp) | ||
610 | { | ||
611 | /////// Rect, follows, tool_tip, enabled, visible attributes /////// | ||
612 | initFromXML(node, parentp); | ||
613 | |||
614 | /////// Border attributes /////// | ||
615 | BOOL border = FALSE; | ||
616 | node->getAttributeBOOL("border", border); | ||
617 | if (border) | ||
618 | { | ||
619 | LLViewBorder::EBevel bevel_style = LLViewBorder::BEVEL_OUT; | ||
620 | LLViewBorder::getBevelFromAttribute(node, bevel_style); | ||
621 | |||
622 | LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE; | ||
623 | LLString border_string; | ||
624 | node->getAttributeString("border_style", border_string); | ||
625 | LLString::toLower(border_string); | ||
626 | |||
627 | if (border_string == "texture") | ||
628 | { | ||
629 | border_style = LLViewBorder::STYLE_TEXTURE; | ||
630 | } | ||
631 | |||
632 | S32 border_thickness = LLPANEL_BORDER_WIDTH; | ||
633 | node->getAttributeS32("border_thickness", border_thickness); | ||
634 | |||
635 | addBorder(bevel_style, border_style, border_thickness); | ||
636 | } | ||
637 | |||
638 | /////// Background attributes /////// | ||
639 | BOOL background_visible = FALSE; | ||
640 | node->getAttributeBOOL("background_visible", background_visible); | ||
641 | setBackgroundVisible(background_visible); | ||
642 | |||
643 | BOOL background_opaque = FALSE; | ||
644 | node->getAttributeBOOL("background_opaque", background_opaque); | ||
645 | setBackgroundOpaque(background_opaque); | ||
646 | |||
647 | LLColor4 color; | ||
648 | color = LLUI::sColorsGroup->getColor( "FocusBackgroundColor" ); | ||
649 | LLUICtrlFactory::getAttributeColor(node,"bg_opaque_color", color); | ||
650 | setBackgroundColor(color); | ||
651 | |||
652 | color = LLUI::sColorsGroup->getColor( "DefaultBackgroundColor" ); | ||
653 | LLUICtrlFactory::getAttributeColor(node,"bg_alpha_color", color); | ||
654 | setTransparentColor(color); | ||
655 | |||
656 | LLString label; | ||
657 | node->getAttributeString("label", label); | ||
658 | setLabel(label); | ||
659 | } | ||
660 | |||
661 | void LLPanel::childSetVisible(const LLString& id, bool visible) | ||
662 | { | ||
663 | LLView* child = getChildByName(id, true); | ||
664 | if (child) | ||
665 | { | ||
666 | child->setVisible(visible); | ||
667 | } | ||
668 | } | ||
669 | |||
670 | bool LLPanel::childIsVisible(const LLString& id) const | ||
671 | { | ||
672 | LLView* child = getChildByName(id, true); | ||
673 | if (child) | ||
674 | { | ||
675 | return (bool)child->getVisible(); | ||
676 | } | ||
677 | return false; | ||
678 | } | ||
679 | |||
680 | void LLPanel::childSetEnabled(const LLString& id, bool enabled) | ||
681 | { | ||
682 | LLView* child = getChildByName(id, true); | ||
683 | if (child) | ||
684 | { | ||
685 | child->setEnabled(enabled); | ||
686 | } | ||
687 | } | ||
688 | |||
689 | void LLPanel::childSetTentative(const LLString& id, bool tentative) | ||
690 | { | ||
691 | LLView* child = getChildByName(id, true); | ||
692 | if (child) | ||
693 | { | ||
694 | child->setTentative(tentative); | ||
695 | } | ||
696 | } | ||
697 | |||
698 | bool LLPanel::childIsEnabled(const LLString& id) const | ||
699 | { | ||
700 | LLView* child = getChildByName(id, true); | ||
701 | if (child) | ||
702 | { | ||
703 | return (bool)child->getEnabled(); | ||
704 | } | ||
705 | return false; | ||
706 | } | ||
707 | |||
708 | |||
709 | void LLPanel::childSetToolTip(const LLString& id, const LLString& msg) | ||
710 | { | ||
711 | LLView* child = getChildByName(id, true); | ||
712 | if (child) | ||
713 | { | ||
714 | child->setToolTip(msg); | ||
715 | } | ||
716 | } | ||
717 | |||
718 | void LLPanel::childSetRect(const LLString& id, const LLRect& rect) | ||
719 | { | ||
720 | LLView* child = getChildByName(id, true); | ||
721 | if (child) | ||
722 | { | ||
723 | child->setRect(rect); | ||
724 | } | ||
725 | } | ||
726 | |||
727 | bool LLPanel::childGetRect(const LLString& id, LLRect& rect) const | ||
728 | { | ||
729 | LLView* child = getChildByName(id, true); | ||
730 | if (child) | ||
731 | { | ||
732 | rect = child->getRect(); | ||
733 | return true; | ||
734 | } | ||
735 | return false; | ||
736 | } | ||
737 | |||
738 | void LLPanel::childSetFocus(const LLString& id, BOOL focus) | ||
739 | { | ||
740 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
741 | if (child) | ||
742 | { | ||
743 | child->setFocus(focus); | ||
744 | } | ||
745 | } | ||
746 | |||
747 | BOOL LLPanel::childHasFocus(const LLString& id) | ||
748 | { | ||
749 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
750 | if (child) | ||
751 | { | ||
752 | return child->hasFocus(); | ||
753 | } | ||
754 | else | ||
755 | { | ||
756 | childNotFound(id); | ||
757 | return FALSE; | ||
758 | } | ||
759 | } | ||
760 | |||
761 | |||
762 | void LLPanel::childSetFocusChangedCallback(const LLString& id, void (*cb)(LLUICtrl*, void*)) | ||
763 | { | ||
764 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
765 | if (child) | ||
766 | { | ||
767 | child->setFocusChangedCallback(cb); | ||
768 | } | ||
769 | } | ||
770 | |||
771 | void LLPanel::childSetCommitCallback(const LLString& id, void (*cb)(LLUICtrl*, void*), void *userdata ) | ||
772 | { | ||
773 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
774 | if (child) | ||
775 | { | ||
776 | child->setCommitCallback(cb); | ||
777 | child->setCallbackUserData(userdata); | ||
778 | } | ||
779 | } | ||
780 | |||
781 | void LLPanel::childSetDoubleClickCallback(const LLString& id, void (*cb)(void*), void *userdata ) | ||
782 | { | ||
783 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
784 | if (child) | ||
785 | { | ||
786 | child->setDoubleClickCallback(cb); | ||
787 | if (userdata) | ||
788 | { | ||
789 | child->setCallbackUserData(userdata); | ||
790 | } | ||
791 | } | ||
792 | } | ||
793 | |||
794 | void LLPanel::childSetValidate(const LLString& id, BOOL (*cb)(LLUICtrl*, void*)) | ||
795 | { | ||
796 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
797 | if (child) | ||
798 | { | ||
799 | child->setValidateBeforeCommit(cb); | ||
800 | } | ||
801 | } | ||
802 | |||
803 | void LLPanel::childSetUserData(const LLString& id, void* userdata) | ||
804 | { | ||
805 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
806 | if (child) | ||
807 | { | ||
808 | child->setCallbackUserData(userdata); | ||
809 | } | ||
810 | } | ||
811 | |||
812 | void LLPanel::childSetColor(const LLString& id, const LLColor4& color) | ||
813 | { | ||
814 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
815 | if (child) | ||
816 | { | ||
817 | child->setColor(color); | ||
818 | } | ||
819 | } | ||
820 | |||
821 | LLCtrlSelectionInterface* LLPanel::childGetSelectionInterface(const LLString& id) | ||
822 | { | ||
823 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
824 | if (child) | ||
825 | { | ||
826 | return child->getSelectionInterface(); | ||
827 | } | ||
828 | return NULL; | ||
829 | } | ||
830 | |||
831 | LLCtrlListInterface* LLPanel::childGetListInterface(const LLString& id) | ||
832 | { | ||
833 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
834 | if (child) | ||
835 | { | ||
836 | return child->getListInterface(); | ||
837 | } | ||
838 | return NULL; | ||
839 | } | ||
840 | |||
841 | LLCtrlScrollInterface* LLPanel::childGetScrollInterface(const LLString& id) | ||
842 | { | ||
843 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
844 | if (child) | ||
845 | { | ||
846 | return child->getScrollInterface(); | ||
847 | } | ||
848 | return NULL; | ||
849 | } | ||
850 | |||
851 | void LLPanel::childSetValue(const LLString& id, LLSD value) | ||
852 | { | ||
853 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
854 | if (child) | ||
855 | { | ||
856 | child->setValue(value); | ||
857 | } | ||
858 | } | ||
859 | |||
860 | LLSD LLPanel::childGetValue(const LLString& id) const | ||
861 | { | ||
862 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
863 | if (child) | ||
864 | { | ||
865 | return child->getValue(); | ||
866 | } | ||
867 | // Not found => return undefined | ||
868 | return LLSD(); | ||
869 | } | ||
870 | |||
871 | BOOL LLPanel::childSetTextArg(const LLString& id, const LLString& key, const LLString& text) | ||
872 | { | ||
873 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
874 | if (child) | ||
875 | { | ||
876 | return child->setTextArg(key, text); | ||
877 | } | ||
878 | return FALSE; | ||
879 | } | ||
880 | |||
881 | BOOL LLPanel::childSetLabelArg(const LLString& id, const LLString& key, const LLString& text) | ||
882 | { | ||
883 | LLView* child = getChildByName(id, true); | ||
884 | if (child) | ||
885 | { | ||
886 | return child->setLabelArg(key, text); | ||
887 | } | ||
888 | return FALSE; | ||
889 | } | ||
890 | |||
891 | void LLPanel::childSetMinValue(const LLString& id, LLSD min_value) | ||
892 | { | ||
893 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
894 | if (child) | ||
895 | { | ||
896 | child->setMinValue(min_value); | ||
897 | } | ||
898 | } | ||
899 | |||
900 | void LLPanel::childSetMaxValue(const LLString& id, LLSD max_value) | ||
901 | { | ||
902 | LLUICtrl* child = (LLUICtrl*)getChildByName(id, true); | ||
903 | if (child) | ||
904 | { | ||
905 | child->setMaxValue(max_value); | ||
906 | } | ||
907 | } | ||
908 | |||
909 | void LLPanel::childShowTab(const LLString& id, const LLString& tabname, bool visible) | ||
910 | { | ||
911 | LLTabContainerCommon* child = LLUICtrlFactory::getTabContainerByName(this, id); | ||
912 | if (child) | ||
913 | { | ||
914 | child->selectTabByName(tabname); | ||
915 | } | ||
916 | } | ||
917 | |||
918 | LLPanel *LLPanel::childGetVisibleTab(const LLString& id) | ||
919 | { | ||
920 | LLTabContainerCommon* child = LLUICtrlFactory::getTabContainerByName(this, id); | ||
921 | if (child) | ||
922 | { | ||
923 | return child->getCurrentPanel(); | ||
924 | } | ||
925 | return NULL; | ||
926 | } | ||
927 | |||
928 | void LLPanel::childSetTabChangeCallback(const LLString& id, const LLString& tabname, void (*on_tab_clicked)(void*, bool), void *userdata) | ||
929 | { | ||
930 | LLTabContainerCommon* child = LLUICtrlFactory::getTabContainerByName(this, id); | ||
931 | if (child) | ||
932 | { | ||
933 | LLPanel *panel = child->getPanelByName(tabname); | ||
934 | if (panel) | ||
935 | { | ||
936 | child->setTabChangeCallback(panel, on_tab_clicked); | ||
937 | child->setTabUserData(panel, userdata); | ||
938 | } | ||
939 | } | ||
940 | } | ||
941 | |||
942 | void LLPanel::childSetText(const LLString& id, const LLString& text) | ||
943 | { | ||
944 | childSetValue(id, LLSD(text)); | ||
945 | } | ||
946 | |||
947 | void LLPanel::childSetKeystrokeCallback(const LLString& id, void (*keystroke_callback)(LLLineEditor* caller, void* user_data), void *user_data) | ||
948 | { | ||
949 | LLLineEditor* child = LLUICtrlFactory::getLineEditorByName(this, id); | ||
950 | if (child) | ||
951 | { | ||
952 | child->setKeystrokeCallback(keystroke_callback); | ||
953 | if (user_data) | ||
954 | { | ||
955 | child->setCallbackUserData(user_data); | ||
956 | } | ||
957 | } | ||
958 | } | ||
959 | |||
960 | void LLPanel::childSetPrevalidate(const LLString& id, BOOL (*func)(const LLWString &) ) | ||
961 | { | ||
962 | LLLineEditor* child = LLUICtrlFactory::getLineEditorByName(this, id); | ||
963 | if (child) | ||
964 | { | ||
965 | child->setPrevalidate(func); | ||
966 | } | ||
967 | } | ||
968 | |||
969 | LLString LLPanel::childGetText(const LLString& id) | ||
970 | { | ||
971 | return childGetValue(id).asString(); | ||
972 | } | ||
973 | |||
974 | void LLPanel::childSetWrappedText(const LLString& id, const LLString& text, bool visible) | ||
975 | { | ||
976 | LLTextBox* child = (LLTextBox*)getCtrlByNameAndType(id, WIDGET_TYPE_TEXT_BOX); | ||
977 | if (child) | ||
978 | { | ||
979 | child->setVisible(visible); | ||
980 | child->setWrappedText(text); | ||
981 | } | ||
982 | } | ||
983 | |||
984 | void LLPanel::childSetAction(const LLString& id, void(*function)(void*), void* value) | ||
985 | { | ||
986 | LLButton* button = (LLButton*)getCtrlByNameAndType(id, WIDGET_TYPE_BUTTON); | ||
987 | if (button) | ||
988 | { | ||
989 | button->setClickedCallback(function, value); | ||
990 | } | ||
991 | } | ||
992 | |||
993 | void LLPanel::childSetActionTextbox(const LLString& id, void(*function)(void*)) | ||
994 | { | ||
995 | LLTextBox* textbox = (LLTextBox*)getCtrlByNameAndType(id, WIDGET_TYPE_TEXT_BOX); | ||
996 | if (textbox) | ||
997 | { | ||
998 | textbox->setClickedCallback(function); | ||
999 | } | ||
1000 | } | ||
1001 | |||
1002 | void LLPanel::childSetControlName(const LLString& id, const LLString& control_name) | ||
1003 | { | ||
1004 | LLView* view = getChildByName(id, TRUE); | ||
1005 | if (view) | ||
1006 | { | ||
1007 | view->setControlName(control_name, NULL); | ||
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | //virtual | ||
1012 | LLView* LLPanel::getChildByName(const LLString& name, BOOL recurse) const | ||
1013 | { | ||
1014 | LLView* view = LLUICtrl::getChildByName(name, recurse); | ||
1015 | if (!view) | ||
1016 | { | ||
1017 | childNotFound(name); | ||
1018 | } | ||
1019 | return view; | ||
1020 | } | ||
1021 | |||
1022 | void LLPanel::childNotFound(const LLString& id) const | ||
1023 | { | ||
1024 | if (mExpectedMembers.find(id) == mExpectedMembers.end()) | ||
1025 | { | ||
1026 | mNewExpectedMembers.insert(id); | ||
1027 | } | ||
1028 | } | ||
1029 | |||
1030 | void LLPanel::childDisplayNotFound() | ||
1031 | { | ||
1032 | if (mNewExpectedMembers.empty()) | ||
1033 | { | ||
1034 | return; | ||
1035 | } | ||
1036 | LLString msg; | ||
1037 | expected_members_list_t::iterator itor; | ||
1038 | for (itor=mNewExpectedMembers.begin(); itor!=mNewExpectedMembers.end(); ++itor) | ||
1039 | { | ||
1040 | msg.append(*itor); | ||
1041 | msg.append("\n"); | ||
1042 | mExpectedMembers.insert(*itor); | ||
1043 | } | ||
1044 | mNewExpectedMembers.clear(); | ||
1045 | LLString::format_map_t args; | ||
1046 | args["[CONTROLS]"] = msg; | ||
1047 | LLAlertDialog::showXml("FloaterNotFound", args); | ||
1048 | } | ||
1049 | |||