From ce28e056c20bf2723f565bbf464b87781ec248a2 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:42 -0500 Subject: Second Life viewer sources 1.20.2 --- linden/indra/llui/llalertdialog.cpp | 58 +-- linden/indra/llui/llalertdialog.h | 7 +- linden/indra/llui/llbutton.cpp | 578 ++++++++++++++--------------- linden/indra/llui/llbutton.h | 8 +- linden/indra/llui/llcheckboxctrl.cpp | 3 +- linden/indra/llui/llcheckboxctrl.h | 3 +- linden/indra/llui/llcombobox.cpp | 75 ++-- linden/indra/llui/llcombobox.h | 15 +- linden/indra/llui/lldraghandle.cpp | 26 +- linden/indra/llui/lldraghandle.h | 6 - linden/indra/llui/llfloater.cpp | 265 +++++++------ linden/indra/llui/llfloater.h | 14 +- linden/indra/llui/llfocusmgr.cpp | 5 +- linden/indra/llui/llfocusmgr.h | 7 +- linden/indra/llui/llhtmlhelp.h | 3 +- linden/indra/llui/lliconctrl.cpp | 59 +-- linden/indra/llui/lliconctrl.h | 6 +- linden/indra/llui/lllineeditor.cpp | 216 +++++++---- linden/indra/llui/lllineeditor.h | 40 +- linden/indra/llui/llmenugl.cpp | 279 +++++--------- linden/indra/llui/llmenugl.h | 50 +-- linden/indra/llui/llmodaldialog.cpp | 49 ++- linden/indra/llui/llmodaldialog.h | 2 +- linden/indra/llui/llmultislider.cpp | 308 +++++++-------- linden/indra/llui/llmultislider.h | 4 +- linden/indra/llui/llmultisliderctrl.cpp | 2 + linden/indra/llui/llmultisliderctrl.h | 2 - linden/indra/llui/llpanel.cpp | 320 +++++++--------- linden/indra/llui/llpanel.h | 40 +- linden/indra/llui/llradiogroup.cpp | 5 +- linden/indra/llui/llradiogroup.h | 4 +- linden/indra/llui/llresizebar.cpp | 15 +- linden/indra/llui/llresizebar.h | 3 - linden/indra/llui/llresizehandle.cpp | 27 +- linden/indra/llui/llresizehandle.h | 5 +- linden/indra/llui/llresmgr.cpp | 2 - linden/indra/llui/llresmgr.h | 66 +--- linden/indra/llui/llrootview.h | 3 - linden/indra/llui/llscrollbar.cpp | 191 ++++------ linden/indra/llui/llscrollbar.h | 5 +- linden/indra/llui/llscrollcontainer.cpp | 176 ++++----- linden/indra/llui/llscrollcontainer.h | 4 +- linden/indra/llui/llscrollingpanellist.cpp | 9 +- linden/indra/llui/llscrollingpanellist.h | 2 - linden/indra/llui/llscrolllistctrl.cpp | 288 +++++++------- linden/indra/llui/llscrolllistctrl.h | 35 +- linden/indra/llui/llslider.cpp | 134 +++---- linden/indra/llui/llslider.h | 10 +- linden/indra/llui/llsliderctrl.cpp | 1 + linden/indra/llui/llsliderctrl.h | 3 +- linden/indra/llui/llspinctrl.cpp | 22 +- linden/indra/llui/llspinctrl.h | 5 +- linden/indra/llui/llstyle.cpp | 32 +- linden/indra/llui/llstyle.h | 17 +- linden/indra/llui/lltabcontainer.cpp | 213 +++++------ linden/indra/llui/lltabcontainer.h | 10 +- linden/indra/llui/lltextbox.cpp | 95 +++-- linden/indra/llui/lltextbox.h | 3 +- linden/indra/llui/lltexteditor.cpp | 166 ++++----- linden/indra/llui/lltexteditor.h | 7 +- linden/indra/llui/llui.cpp | 175 +++++---- linden/indra/llui/llui.h | 127 ++----- linden/indra/llui/lluictrl.cpp | 22 +- linden/indra/llui/lluictrl.h | 4 +- linden/indra/llui/lluictrlfactory.cpp | 301 +-------------- linden/indra/llui/lluictrlfactory.h | 64 +--- linden/indra/llui/llview.cpp | 215 +++++++---- linden/indra/llui/llview.h | 177 +++++++-- linden/indra/llui/llviewborder.cpp | 81 ++-- linden/indra/llui/llviewborder.h | 4 +- linden/indra/llui/llviewquery.cpp | 5 - linden/indra/llui/llviewquery.h | 10 +- 72 files changed, 2311 insertions(+), 2882 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llalertdialog.cpp b/linden/indra/llui/llalertdialog.cpp index e60ef42..4ca9dc8 100644 --- a/linden/indra/llui/llalertdialog.cpp +++ b/linden/indra/llui/llalertdialog.cpp @@ -186,7 +186,7 @@ bool LLAlertDialog::show() { mOptionChosen = mDefaultOption; llinfos << "Alert: " << mLabel << llendl; - delete this; + close(); return false; } } @@ -208,7 +208,7 @@ bool LLAlertDialog::show() case IGNORE_SHOW_AGAIN: break; } - delete this; + close(); return false; } } @@ -231,7 +231,7 @@ bool LLAlertDialog::show() { gFloaterView->bringToFront(iter->second); mUnique = FALSE; // don't remove entry from map on destruction - delete this; + close(); return false; } sUniqueActiveMap[mLabel] = this; @@ -270,7 +270,7 @@ void LLAlertDialog::createDialog(const std::vector* optionsp, S32 defa setBackgroundVisible(TRUE); setBackgroundOpaque(TRUE); - const LLFontGL* font = gResMgr->getRes( font_name ); + const LLFontGL* font = LLResMgr::getInstance()->getRes( font_name ); const S32 LINE_HEIGHT = llfloor(font->getLineHeight() + 0.99f); const S32 EDITOR_HEIGHT = 20; @@ -399,7 +399,7 @@ void LLAlertDialog::createDialog(const std::vector* optionsp, S32 defa bool LLAlertDialog::setCheckBox( const LLString& check_title, const LLString& check_control ) { - const LLFontGL* font = gResMgr->getRes( font_name ); + const LLFontGL* font = LLResMgr::getInstance()->getRes( font_name ); const S32 LINE_HEIGHT = llfloor(font->getLineHeight() + 0.99f); // Extend dialog for "check next time" @@ -444,8 +444,23 @@ void LLAlertDialog::setVisible( BOOL visible ) } } +void LLAlertDialog::onClose(bool app_quitting) +{ + LLModalDialog::onClose(app_quitting); + handleCallbacks(); +} + LLAlertDialog::~LLAlertDialog() { + delete[] mButtonData; + if (mUnique) + { + sUniqueActiveMap.erase(mLabel); + } +} + +void LLAlertDialog::handleCallbacks() +{ if (mOptionChosen >= 0) { if (mTextCallback && mLineEditor) @@ -465,7 +480,7 @@ LLAlertDialog::~LLAlertDialog() sURLLoader->load(mURL); } } - + // Only change warn state if we actually warned. if (mCheck && sSettings->getWarning(mIgnoreLabel)) @@ -490,13 +505,7 @@ LLAlertDialog::~LLAlertDialog() } } } - delete[] mButtonData; - if (mUnique) - { - sUniqueActiveMap.erase(mLabel); - } } - BOOL LLAlertDialog::hasTitleBar() const { return (getTitle() != "" && getTitle() != " ") // has title @@ -504,16 +513,11 @@ BOOL LLAlertDialog::hasTitleBar() const || isCloseable(); } -BOOL LLAlertDialog::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLAlertDialog::handleKeyHere(KEY key, MASK mask ) { if( KEY_RETURN == key && mask == MASK_NONE ) { - // Warning: handleKeyHere may result in the default button - // being committed, which will destroy this object. - // Everything works, but the call stack will pass through - // the very end of functions that belong to deleted objects. - // Should find a less fragile way to do this. - LLModalDialog::handleKeyHere( key, mask , called_from_parent ); + LLModalDialog::handleKeyHere( key, mask ); return TRUE; } else if (KEY_RIGHT == key) @@ -538,7 +542,7 @@ BOOL LLAlertDialog::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) } else { - return LLModalDialog::handleKeyHere( key, mask , called_from_parent ); + return LLModalDialog::handleKeyHere( key, mask ); } } @@ -551,16 +555,14 @@ void LLAlertDialog::draw() mDefaultBtnTimer.stop(); // prevent this block from being run more than once setDefaultBtn(mButtonData[mDefaultOption].mButton); } - if (getVisible()) - { - LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); - S32 shadow_lines = LLUI::sConfigGroup->getS32("DropShadowFloater"); - gl_drop_shadow( 0, getRect().getHeight(), getRect().getWidth(), 0, - shadow_color, shadow_lines); + LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); + S32 shadow_lines = LLUI::sConfigGroup->getS32("DropShadowFloater"); - LLModalDialog::draw(); - } + gl_drop_shadow( 0, getRect().getHeight(), getRect().getWidth(), 0, + shadow_color, shadow_lines); + + LLModalDialog::draw(); } void LLAlertDialog::setOptionEnabled( S32 option, BOOL enable ) diff --git a/linden/indra/llui/llalertdialog.h b/linden/indra/llui/llalertdialog.h index 4978d71..8633164 100644 --- a/linden/indra/llui/llalertdialog.h +++ b/linden/indra/llui/llalertdialog.h @@ -68,10 +68,11 @@ public: LLAlertDialog( const LLAlertDialogTemplate* xml_template, const LLString::format_map_t& args, alert_callback_t callback = NULL, void *user_data = NULL); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ); + virtual BOOL handleKeyHere(KEY key, MASK mask ); virtual void draw(); virtual void setVisible( BOOL visible ); + virtual void onClose(bool app_quitting); bool setCheckBox( const LLString&, const LLString& ); void setOptionEnabled( S32 option, BOOL enable ); @@ -126,7 +127,9 @@ private: const LLString& msg, const LLString::format_map_t& args, const LLString& edit_text); - virtual ~LLAlertDialog(); // No you can't kill it. It can only kill itself. + virtual ~LLAlertDialog(); + void handleCallbacks(); + // No you can't kill it. It can only kill itself. // Does it have a readable title label, or minimize or close buttons? BOOL hasTitleBar() const; diff --git a/linden/indra/llui/llbutton.cpp b/linden/indra/llui/llbutton.cpp index 4af40ff..3ada389 100644 --- a/linden/indra/llui/llbutton.cpp +++ b/linden/indra/llui/llbutton.cpp @@ -50,6 +50,8 @@ #include "llwindow.h" #include "llglimmediate.h" +static LLRegisterWidget r("button"); + // globals loaded from settings.xml S32 LLBUTTON_ORIG_H_PAD = 6; // Pre-zoomable UI S32 LLBUTTON_H_PAD = 0; @@ -222,18 +224,6 @@ LLButton::~LLButton() } } -// virtual -EWidgetType LLButton::getWidgetType() const -{ - return WIDGET_TYPE_BUTTON; -} - -// virtual -LLString LLButton::getWidgetTag() const -{ - return LL_BUTTON_TAG; -} - // HACK: Committing a button is the same as instantly clicking it. // virtual void LLButton::onCommit() @@ -277,10 +267,11 @@ void LLButton::onCommit() -BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) +BOOL LLButton::handleUnicodeCharHere(llwchar uni_char) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) + if(' ' == uni_char + && !gKeyboard->getKeyRepeated(' ')) { if (mIsToggle) { @@ -296,24 +287,21 @@ BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) return handled; } -BOOL LLButton::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLButton::handleKeyHere(KEY key, MASK mask ) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && !called_from_parent ) + if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) { - if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) + if (mIsToggle) { - if (mIsToggle) - { - toggleState(); - } + toggleState(); + } - handled = TRUE; + handled = TRUE; - if (mClickedCallback) - { - (*mClickedCallback)( mCallbackUserData ); - } + if (mClickedCallback) + { + (*mClickedCallback)( mCallbackUserData ); } } return handled; @@ -391,8 +379,6 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) { - BOOL handled = FALSE; - LLMouseHandler* other_captor = gFocusMgr.getMouseCapture(); mNeedsHighlight = other_captor == NULL || other_captor == this || @@ -409,358 +395,333 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) } // We only handle the click if the click both started and ended within us - if( hasMouseCapture() ) - { - handled = TRUE; - } - else if( getVisible() ) - { - // Opaque - handled = TRUE; - } + getWindow()->setCursor(UI_CURSOR_ARROW); + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << llendl; - if( handled ) - { - getWindow()->setCursor(UI_CURSOR_ARROW); - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << llendl; - } - - return handled; + return TRUE; } // virtual void LLButton::draw() { - if( getVisible() ) + BOOL flash = FALSE; + if( mFlashing ) { - BOOL flash = FALSE; - if( mFlashing ) - { - F32 elapsed = mFlashingTimer.getElapsedTimeF32(); - S32 flash_count = S32(elapsed * LLUI::sConfigGroup->getF32("ButtonFlashRate") * 2.f); - // flash on or off? - flash = (flash_count % 2 == 0) || flash_count > (F32)LLUI::sConfigGroup->getS32("ButtonFlashCount"); - } + F32 elapsed = mFlashingTimer.getElapsedTimeF32(); + S32 flash_count = S32(elapsed * LLUI::sConfigGroup->getF32("ButtonFlashRate") * 2.f); + // flash on or off? + flash = (flash_count % 2 == 0) || flash_count > S32((F32)LLUI::sConfigGroup->getS32("ButtonFlashCount") * 2.f); + } - BOOL pressed_by_keyboard = FALSE; - if (hasFocus()) - { - pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mCommitOnReturn && gKeyboard->getKeyDown(KEY_RETURN)); - } + BOOL pressed_by_keyboard = FALSE; + if (hasFocus()) + { + pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mCommitOnReturn && gKeyboard->getKeyDown(KEY_RETURN)); + } - // Unselected image assignments - S32 local_mouse_x; - S32 local_mouse_y; - LLCoordWindow cursor_pos_window; - getWindow()->getCursorPosition(&cursor_pos_window); - LLCoordGL cursor_pos_gl; - getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); - cursor_pos_gl.mX = llround((F32)cursor_pos_gl.mX / LLUI::sGLScaleFactor.mV[VX]); - cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); - screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); - - BOOL pressed = pressed_by_keyboard - || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)) - || mToggleState; - - BOOL use_glow_effect = FALSE; - if ( mNeedsHighlight || flash ) + // Unselected image assignments + S32 local_mouse_x; + S32 local_mouse_y; + LLCoordWindow cursor_pos_window; + getWindow()->getCursorPosition(&cursor_pos_window); + LLCoordGL cursor_pos_gl; + getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); + cursor_pos_gl.mX = llround((F32)cursor_pos_gl.mX / LLUI::sGLScaleFactor.mV[VX]); + cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); + screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); + + BOOL pressed = pressed_by_keyboard + || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)) + || mToggleState; + + BOOL use_glow_effect = FALSE; + if ( mNeedsHighlight || flash ) + { + if (pressed) { - if (pressed) + if (mImageHoverSelected) { - if (mImageHoverSelected) - { - mImagep = mImageHoverSelected; - } - else - { - mImagep = mImageSelected; - use_glow_effect = TRUE; - } + mImagep = mImageHoverSelected; } else { - if (mImageHoverUnselected) - { - mImagep = mImageHoverUnselected; - } - else - { - mImagep = mImageUnselected; - use_glow_effect = TRUE; - } + mImagep = mImageSelected; + use_glow_effect = TRUE; } } - else if ( pressed ) - { - mImagep = mImageSelected; - } else { - mImagep = mImageUnselected; + if (mImageHoverUnselected) + { + mImagep = mImageHoverUnselected; + } + else + { + mImagep = mImageUnselected; + use_glow_effect = TRUE; + } } + } + else if ( pressed ) + { + mImagep = mImageSelected; + } + else + { + mImagep = mImageUnselected; + } - // Override if more data is available - // HACK: Use gray checked state to mean either: - // enabled and tentative - // or - // disabled but checked - if (!mImageDisabledSelected.isNull() && ( (getEnabled() && getTentative()) || (!getEnabled() && pressed ) ) ) - { - mImagep = mImageDisabledSelected; - } - else if (!mImageDisabled.isNull() && !getEnabled() && !pressed) - { - mImagep = mImageDisabled; - } + // Override if more data is available + // HACK: Use gray checked state to mean either: + // enabled and tentative + // or + // disabled but checked + if (!mImageDisabledSelected.isNull() + && + ( (getEnabled() && getTentative()) + || (!getEnabled() && pressed ) ) ) + { + mImagep = mImageDisabledSelected; + } + else if (!mImageDisabled.isNull() + && !getEnabled() + && !pressed) + { + mImagep = mImageDisabled; + } - if (mNeedsHighlight && !mImagep) - { - use_glow_effect = TRUE; - } + if (mNeedsHighlight && !mImagep) + { + use_glow_effect = TRUE; + } - // Figure out appropriate color for the text - LLColor4 label_color; + // Figure out appropriate color for the text + LLColor4 label_color; - // label changes when button state changes, not when pressed - if ( getEnabled() ) + // label changes when button state changes, not when pressed + if ( getEnabled() ) + { + if ( mToggleState ) { - if ( mToggleState ) - { - label_color = mSelectedLabelColor; - } - else - { - label_color = mUnselectedLabelColor; - } + label_color = mSelectedLabelColor; } else { - if ( mToggleState ) - { - label_color = mDisabledSelectedLabelColor; - } - else - { - label_color = mDisabledLabelColor; - } + label_color = mUnselectedLabelColor; } - - // Unselected label assignments - LLWString label; - - if( mToggleState ) + } + else + { + if ( mToggleState ) { - if( getEnabled() || mDisabledSelectedLabel.empty() ) - { - label = mSelectedLabel; - } - else - { - label = mDisabledSelectedLabel; - } + label_color = mDisabledSelectedLabelColor; } else { - if( getEnabled() || mDisabledLabel.empty() ) - { - label = mUnselectedLabel; - } - else - { - label = mDisabledLabel; - } + label_color = mDisabledLabelColor; } - - // draw default button border - if (getEnabled() && mBorderEnabled && gFocusMgr.getAppHasFocus()) // because we're the default button in a panel + } + + // Unselected label assignments + LLWString label; + + if( mToggleState ) + { + if( getEnabled() || mDisabledSelectedLabel.empty() ) { - drawBorder(LLUI::sColorsGroup->getColor( "ButtonBorderColor" ), BORDER_SIZE); + label = mSelectedLabel; } - - // overlay with keyboard focus border - if (hasFocus()) + else { - F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); - drawBorder(gFocusMgr.getFocusColor(), llround(lerp(1.f, 3.f, lerp_amt))); + label = mDisabledSelectedLabel; } - - if (use_glow_effect) + } + else + { + if( getEnabled() || mDisabledLabel.empty() ) { - mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); + label = mUnselectedLabel; } else { - mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); + label = mDisabledLabel; } + } - // Draw button image, if available. - // Otherwise draw basic rectangular button. - if( mImagep.notNull() && !mScaleImage) + // overlay with keyboard focus border + if (hasFocus()) + { + F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); + drawBorder(gFocusMgr.getFocusColor(), llround(lerp(1.f, 3.f, lerp_amt))); + } + + if (use_glow_effect) + { + mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); + } + else + { + mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); + } + + // Draw button image, if available. + // Otherwise draw basic rectangular button. + if (mImagep.notNull()) + { + if ( mScaleImage) { - mImagep->draw(0, 0, getEnabled() ? mImageColor : mDisabledImageColor ); + mImagep->draw(getLocalRect(), getEnabled() ? mImageColor : mDisabledImageColor ); if (mCurGlowStrength > 0.01f) { - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE); - mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + mImagep->drawSolid(0, 0, getRect().getWidth(), getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } else - if ( mImagep.notNull() && mScaleImage) { - mImagep->draw(0, 0, getRect().getWidth(), getRect().getHeight(), getEnabled() ? mImageColor : mDisabledImageColor ); + mImagep->draw(0, 0, getEnabled() ? mImageColor : mDisabledImageColor ); if (mCurGlowStrength > 0.01f) { - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE); - mImagep->drawSolid(0, 0, getRect().getWidth(), getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } - else - { - // no image - llwarns << "No image for button " << getName() << llendl; - // draw it in pink so we can find it - gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1, FALSE); - } - - // let overlay image and text play well together - S32 text_left = mLeftHPad; - S32 text_right = getRect().getWidth() - mRightHPad; - S32 text_width = getRect().getWidth() - mLeftHPad - mRightHPad; - - // draw overlay image - if (mImageOverlay.notNull()) - { - // get max width and height (discard level 0) - S32 overlay_width = mImageOverlay->getWidth(); - S32 overlay_height = mImageOverlay->getHeight(); + } + else + { + // no image + llwarns << "No image for button " << getName() << llendl; + // draw it in pink so we can find it + gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1, FALSE); + } - F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f); - overlay_width = llround((F32)overlay_width * scale_factor); - overlay_height = llround((F32)overlay_height * scale_factor); + // let overlay image and text play well together + S32 text_left = mLeftHPad; + S32 text_right = getRect().getWidth() - mRightHPad; + S32 text_width = getRect().getWidth() - mLeftHPad - mRightHPad; - S32 center_x = getLocalRect().getCenterX(); - S32 center_y = getLocalRect().getCenterY(); + // draw overlay image + if (mImageOverlay.notNull()) + { + // get max width and height (discard level 0) + S32 overlay_width = mImageOverlay->getWidth(); + S32 overlay_height = mImageOverlay->getHeight(); - //FUGLY HACK FOR "DEPRESSED" BUTTONS - if (pressed) - { - center_y--; - center_x++; - } + F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f); + overlay_width = llround((F32)overlay_width * scale_factor); + overlay_height = llround((F32)overlay_height * scale_factor); - // fade out overlay images on disabled buttons - LLColor4 overlay_color = mImageOverlayColor; - if (!getEnabled()) - { - overlay_color.mV[VALPHA] = 0.5f; - } + S32 center_x = getLocalRect().getCenterX(); + S32 center_y = getLocalRect().getCenterY(); - switch(mImageOverlayAlignment) - { - case LLFontGL::LEFT: - text_left += overlay_width + 1; - text_width -= overlay_width + 1; - mImageOverlay->draw( - mLeftHPad, - center_y - (overlay_height / 2), - overlay_width, - overlay_height, - overlay_color); - break; - case LLFontGL::HCENTER: - mImageOverlay->draw( - center_x - (overlay_width / 2), - center_y - (overlay_height / 2), - overlay_width, - overlay_height, - overlay_color); - break; - case LLFontGL::RIGHT: - text_right -= overlay_width + 1; - text_width -= overlay_width + 1; - mImageOverlay->draw( - getRect().getWidth() - mRightHPad - overlay_width, - center_y - (overlay_height / 2), - overlay_width, - overlay_height, - overlay_color); - break; - default: - // draw nothing - break; - } + //FUGLY HACK FOR "DEPRESSED" BUTTONS + if (pressed) + { + center_y--; + center_x++; } - // Draw label - if( !label.empty() ) + // fade out overlay images on disabled buttons + LLColor4 overlay_color = mImageOverlayColor; + if (!getEnabled()) { - LLWString::trim(label); + overlay_color.mV[VALPHA] = 0.5f; + } - S32 x; - switch( mHAlign ) - { - case LLFontGL::RIGHT: - x = text_right; - break; - case LLFontGL::HCENTER: - x = getRect().getWidth() / 2; - break; - case LLFontGL::LEFT: - default: - x = text_left; - break; - } + switch(mImageOverlayAlignment) + { + case LLFontGL::LEFT: + text_left += overlay_width + 1; + text_width -= overlay_width + 1; + mImageOverlay->draw( + mLeftHPad, + center_y - (overlay_height / 2), + overlay_width, + overlay_height, + overlay_color); + break; + case LLFontGL::HCENTER: + mImageOverlay->draw( + center_x - (overlay_width / 2), + center_y - (overlay_height / 2), + overlay_width, + overlay_height, + overlay_color); + break; + case LLFontGL::RIGHT: + text_right -= overlay_width + 1; + text_width -= overlay_width + 1; + mImageOverlay->draw( + getRect().getWidth() - mRightHPad - overlay_width, + center_y - (overlay_height / 2), + overlay_width, + overlay_height, + overlay_color); + break; + default: + // draw nothing + break; + } + } - S32 y_offset = 2 + (getRect().getHeight() - 20)/2; - - if (pressed) - { - y_offset--; - x++; - } + // Draw label + if( !label.empty() ) + { + LLWString::trim(label); - mGLFont->render(label, 0, (F32)x, (F32)(LLBUTTON_V_PAD + y_offset), - label_color, - mHAlign, LLFontGL::BOTTOM, - mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, - U32_MAX, text_width, - NULL, FALSE, FALSE); + S32 x; + switch( mHAlign ) + { + case LLFontGL::RIGHT: + x = text_right; + break; + case LLFontGL::HCENTER: + x = getRect().getWidth() / 2; + break; + case LLFontGL::LEFT: + default: + x = text_left; + break; } - if (sDebugRects - || (LLView::sEditingUI && this == LLView::sEditingUIView)) + S32 y_offset = 2 + (getRect().getHeight() - 20)/2; + + if (pressed) { - drawDebugRect(); + y_offset--; + x++; } + + mGLFont->render(label, 0, (F32)x, (F32)(LLBUTTON_V_PAD + y_offset), + label_color, + mHAlign, LLFontGL::BOTTOM, + mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, + U32_MAX, text_width, + NULL, FALSE, FALSE); } + + if (sDebugRects + || (LLView::sEditingUI && this == LLView::sEditingUIView)) + { + drawDebugRect(); + } + // reset hover status for next frame mNeedsHighlight = FALSE; } void LLButton::drawBorder(const LLColor4& color, S32 size) { - S32 left = -size; - S32 top = getRect().getHeight() + size; - S32 right = getRect().getWidth() + size; - S32 bottom = -size; - - if (mImagep.isNull()) - { - gl_rect_2d(left, top, right, bottom, color, FALSE); - return; - } - if (mScaleImage) { - mImagep->drawSolid(left, bottom, right-left, top-bottom, color); + mImagep->drawBorder(getLocalRect(), color, size); } else { - mImagep->drawSolid(left, bottom, mImagep->getWidth() + size * 2, mImagep->getHeight() + size * 2, color); + mImagep->drawBorder(0, 0, color, size); } } @@ -778,9 +739,8 @@ void LLButton::setToggleState(BOOL b) { if( b != mToggleState ) { - mToggleState = b; - LLValueChangedEvent *evt = new LLValueChangedEvent(this, mToggleState); - fireEvent(evt, ""); + setControlValue(b); // will fire LLControlVariable callbacks (if any) + mToggleState = b; // may or may not be redundant } } @@ -924,7 +884,7 @@ void LLButton::setImageOverlay(const LLString &image_name, LLFontGL::HAlign alig } else { - mImageOverlay = LLUI::getUIImageByName(image_name); + mImageOverlay = LLUI::getUIImage(image_name); mImageOverlayAlignment = alignment; mImageOverlayColor = color; } @@ -957,37 +917,37 @@ S32 round_up(S32 grid, S32 value) void LLButton::setImageUnselected(const LLString &image_name) { - setImageUnselected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageUnselected(LLUI::getUIImage(image_name)); mImageUnselectedName = image_name; } void LLButton::setImageSelected(const LLString &image_name) { - setImageSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageSelected(LLUI::getUIImage(image_name)); mImageSelectedName = image_name; } void LLButton::setImageHoverSelected(const LLString &image_name) { - setImageHoverSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageHoverSelected(LLUI::getUIImage(image_name)); mImageHoverSelectedName = image_name; } void LLButton::setImageHoverUnselected(const LLString &image_name) { - setImageHoverUnselected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageHoverUnselected(LLUI::getUIImage(image_name)); mImageHoverUnselectedName = image_name; } void LLButton::setImageDisabled(const LLString &image_name) { - setImageDisabled(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageDisabled(LLUI::getUIImage(image_name)); mImageDisabledName = image_name; } void LLButton::setImageDisabledSelected(const LLString &image_name) { - setImageDisabledSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); + setImageDisabledSelected(LLUI::getUIImage(image_name)); mImageDisabledSelectedName = image_name; } @@ -1038,7 +998,7 @@ void clicked_help(void* data) return; } - LLUI::sHtmlHelp->show(self->getHelpURL(), ""); + LLUI::sHtmlHelp->show(self->getHelpURL()); } // static diff --git a/linden/indra/llui/llbutton.h b/linden/indra/llui/llbutton.h index 18f4e07..a101a3c 100644 --- a/linden/indra/llui/llbutton.h +++ b/linden/indra/llui/llbutton.h @@ -87,16 +87,15 @@ public: virtual ~LLButton(); void init(void (*click_callback)(void*), void *callback_data, const LLFontGL* font, const LLString& control_name); - virtual EWidgetType getWidgetType() const; - virtual LLString getWidgetTag() const; + void addImageAttributeToXML(LLXMLNodePtr node, const LLString& imageName, const LLUUID& imageID,const LLString& xmlTagName) const; virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); - virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleUnicodeCharHere(llwchar uni_char); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleHover(S32 x, S32 y, MASK mask); @@ -104,7 +103,6 @@ public: virtual void onMouseCaptureLost(); - // HACK: "committing" a button is the same as clicking on it. virtual void onCommit(); void setUnselectedLabelColor( const LLColor4& c ) { mUnselectedLabelColor = c; } diff --git a/linden/indra/llui/llcheckboxctrl.cpp b/linden/indra/llui/llcheckboxctrl.cpp index ecb6342..33de4da 100644 --- a/linden/indra/llui/llcheckboxctrl.cpp +++ b/linden/indra/llui/llcheckboxctrl.cpp @@ -45,10 +45,11 @@ #include "llfontgl.h" #include "lltextbox.h" #include "llkeyboard.h" -#include "llviewborder.h" const U32 MAX_STRING_LENGTH = 10; +static LLRegisterWidget r("check_box"); + LLCheckBoxCtrl::LLCheckBoxCtrl(const LLString& name, const LLRect& rect, const LLString& label, diff --git a/linden/indra/llui/llcheckboxctrl.h b/linden/indra/llui/llcheckboxctrl.h index 6df0e77..6518272 100644 --- a/linden/indra/llui/llcheckboxctrl.h +++ b/linden/indra/llui/llcheckboxctrl.h @@ -75,8 +75,7 @@ public: virtual ~LLCheckBoxCtrl(); // LLView interface - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_CHECKBOX; } - virtual LLString getWidgetTag() const { return LL_CHECK_BOX_CTRL_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); diff --git a/linden/indra/llui/llcombobox.cpp b/linden/indra/llui/llcombobox.cpp index c486042..0523a11 100644 --- a/linden/indra/llui/llcombobox.cpp +++ b/linden/indra/llui/llcombobox.cpp @@ -57,6 +57,8 @@ S32 LLCOMBOBOX_HEIGHT = 0; S32 LLCOMBOBOX_WIDTH = 0; S32 MAX_COMBO_WIDTH = 500; +static LLRegisterWidget r1("combo_box"); + LLComboBox::LLComboBox( const LLString& name, const LLRect &rect, const LLString& label, void (*commit_callback)(LLUICtrl*,void*), void *callback_userdata @@ -74,9 +76,10 @@ LLComboBox::LLComboBox( const LLString& name, const LLRect &rect, const LLString { // Always use text box // Text label button - mButton = new LLButton("comboxbox button", - LLRect(), label, NULL, LLString::null, - NULL, this); + mButton = new LLButton(label, + LLRect(), + LLString::null, + NULL, this); mButton->setImageUnselected("square_btn_32x128.tga"); mButton->setImageSelected("square_btn_selected_32x128.tga"); mButton->setImageDisabled("square_btn_32x128.tga"); @@ -99,13 +102,7 @@ LLComboBox::LLComboBox( const LLString& name, const LLRect &rect, const LLString mList->setCommitOnKeyboardMovement(FALSE); addChild(mList); - LLRect border_rect(0, getRect().getHeight(), getRect().getWidth(), 0); - mBorder = new LLViewBorder( "combo border", border_rect ); - addChild( mBorder ); - mBorder->setFollowsAll(); - - LLUUID arrow_image_id( LLUI::sAssetsGroup->getString("combobox_arrow.tga") ); - mArrowImage = LLUI::sImageProvider->getImageByID(arrow_image_id); + mArrowImage = LLUI::sImageProvider->getUIImage("combobox_arrow.tga"); mButton->setImageOverlay("combobox_arrow.tga", LLFontGL::RIGHT); updateLayout(); @@ -447,7 +444,7 @@ void LLComboBox::setButtonVisible(BOOL visible) LLRect text_entry_rect(0, getRect().getHeight(), getRect().getWidth(), 0); if (visible) { - text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth(0)) + 2 * LLUI::sConfigGroup->getS32("DropShadowButton"); + text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth()) + 2 * LLUI::sConfigGroup->getS32("DropShadowButton"); } //mTextEntry->setRect(text_entry_rect); mTextEntry->reshape(text_entry_rect.getWidth(), text_entry_rect.getHeight(), TRUE); @@ -456,15 +453,10 @@ void LLComboBox::setButtonVisible(BOOL visible) void LLComboBox::draw() { - if( getVisible() ) - { - mBorder->setKeyboardFocusHighlight(hasFocus()); - - mButton->setEnabled(getEnabled() /*&& !mList->isEmpty()*/); + mButton->setEnabled(getEnabled() /*&& !mList->isEmpty()*/); - // Draw children normally - LLUICtrl::draw(); - } + // Draw children normally + LLUICtrl::draw(); } BOOL LLComboBox::setCurrentByIndex( S32 index ) @@ -494,14 +486,14 @@ void LLComboBox::updateLayout() if (mAllowTextEntry) { S32 shadow_size = LLUI::sConfigGroup->getS32("DropShadowButton"); - mButton->setRect(LLRect( getRect().getWidth() - llmax(8,mArrowImage->getWidth(0)) - 2 * shadow_size, + mButton->setRect(LLRect( getRect().getWidth() - llmax(8,mArrowImage->getWidth()) - 2 * shadow_size, rect.mTop, rect.mRight, rect.mBottom)); mButton->setTabStop(FALSE); if (!mTextEntry) { LLRect text_entry_rect(0, getRect().getHeight(), getRect().getWidth(), 0); - text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth(0)) + 2 * LLUI::sConfigGroup->getS32("DropShadowButton"); + text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth()) + 2 * LLUI::sConfigGroup->getS32("DropShadowButton"); // clear label on button LLString cur_label = mButton->getLabelSelected(); mTextEntry = new LLLineEditor("combo_text_entry", @@ -512,11 +504,7 @@ void LLComboBox::updateLayout() onTextCommit, onTextEntry, NULL, - this, - NULL, // prevalidate func - LLViewBorder::BEVEL_NONE, - LLViewBorder::STYLE_LINE, - 0); // no border + this); mTextEntry->setSelectAllonFocusReceived(TRUE); mTextEntry->setHandleEditKeysDirectly(TRUE); mTextEntry->setCommitOnFocusLost(FALSE); @@ -761,7 +749,7 @@ BOOL LLComboBox::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect_ tool_tip = getToolTip(); if (tool_tip.empty()) { - tool_tip = getValue().asString(); + tool_tip = getSelectedItemLabel(); } } @@ -780,10 +768,10 @@ BOOL LLComboBox::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect_ return TRUE; } -BOOL LLComboBox::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLComboBox::handleKeyHere(KEY key, MASK mask) { BOOL result = FALSE; - if (gFocusMgr.childHasKeyboardFocus(this)) + if (hasFocus()) { //give list a chance to pop up and handle key LLScrollListItem* last_selected_item = mList->getLastSelectedItem(); @@ -792,7 +780,7 @@ BOOL LLComboBox::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) // highlight the original selection before potentially selecting a new item mList->highlightNthItem(mList->getItemIndex(last_selected_item)); } - result = mList->handleKeyHere(key, mask, FALSE); + result = mList->handleKeyHere(key, mask); // if selection has changed, pop open list if (mList->getLastSelectedItem() != last_selected_item) { @@ -802,7 +790,7 @@ BOOL LLComboBox::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) return result; } -BOOL LLComboBox::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) +BOOL LLComboBox::handleUnicodeCharHere(llwchar uni_char) { BOOL result = FALSE; if (gFocusMgr.childHasKeyboardFocus(this)) @@ -816,7 +804,7 @@ BOOL LLComboBox::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent // highlight the original selection before potentially selecting a new item mList->highlightNthItem(mList->getItemIndex(last_selected_item)); } - result = mList->handleUnicodeCharHere(uni_char, called_from_parent); + result = mList->handleUnicodeCharHere(uni_char); if (mList->getLastSelectedItem() != last_selected_item) { showList(); @@ -1095,6 +1083,8 @@ BOOL LLComboBox::selectItemRange( S32 first, S32 last ) // LLFlyoutButton // +static LLRegisterWidget r2("flyout_button"); + const S32 FLYOUT_BUTTON_ARROW_WIDTH = 24; LLFlyoutButton::LLFlyoutButton( @@ -1109,9 +1099,8 @@ LLFlyoutButton::LLFlyoutButton( { // Always use text box // Text label button - mActionButton = new LLButton("flyout_button_main", - LLRect(), label, NULL, LLString::null, - NULL, this); + mActionButton = new LLButton(label, + LLRect(), LLString::null, NULL, this); mActionButton->setScaleImage(TRUE); mActionButton->setClickedCallback(onActionButtonClick); @@ -1120,24 +1109,24 @@ LLFlyoutButton::LLFlyoutButton( mActionButton->setLabel(label); addChild(mActionButton); - mActionButtonImage = LLUI::getUIImageByName("flyout_btn_left.tga"); - mExpanderButtonImage = LLUI::getUIImageByName("flyout_btn_right.tga"); - mActionButtonImageSelected = LLUI::getUIImageByName("flyout_btn_left_selected.tga"); - mExpanderButtonImageSelected = LLUI::getUIImageByName("flyout_btn_right_selected.tga"); + mActionButtonImage = LLUI::getUIImage("flyout_btn_left.tga"); + mExpanderButtonImage = LLUI::getUIImage("flyout_btn_right.tga"); + mActionButtonImageSelected = LLUI::getUIImage("flyout_btn_left_selected.tga"); + mExpanderButtonImageSelected = LLUI::getUIImage("flyout_btn_right_selected.tga"); + mActionButtonImageDisabled = LLUI::getUIImage("flyout_btn_left_disabled.tga"); + mExpanderButtonImageDisabled = LLUI::getUIImage("flyout_btn_right_disabled.tga"); mActionButton->setImageSelected(mActionButtonImageSelected); mActionButton->setImageUnselected(mActionButtonImage); - mActionButton->setImageDisabled(LLPointer(NULL)); + mActionButton->setImageDisabled(mActionButtonImageDisabled); mActionButton->setImageDisabledSelected(LLPointer(NULL)); mButton->setImageSelected(mExpanderButtonImageSelected); mButton->setImageUnselected(mExpanderButtonImage); - mButton->setImageDisabled(LLPointer(NULL)); + mButton->setImageDisabled(mExpanderButtonImageDisabled); mButton->setImageDisabledSelected(LLPointer(NULL)); mButton->setRightHPad(6); - mBorder->setVisible(FALSE); - updateLayout(); } diff --git a/linden/indra/llui/llcombobox.h b/linden/indra/llui/llcombobox.h index f9ca4d2..b35d078 100644 --- a/linden/indra/llui/llcombobox.h +++ b/linden/indra/llui/llcombobox.h @@ -73,8 +73,7 @@ public: virtual ~LLComboBox(); // LLView interface - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_COMBO_BOX; } - virtual LLString getWidgetTag() const { return LL_COMBO_BOX_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); @@ -85,8 +84,8 @@ public: virtual void setEnabled(BOOL enabled); virtual BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); - virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); + virtual BOOL handleUnicodeCharHere(llwchar uni_char); // LLUICtrl interface virtual void clear(); // select nothing @@ -187,9 +186,8 @@ public: protected: LLButton* mButton; LLScrollListCtrl* mList; - LLViewBorder* mBorder; EPreferredPosition mListPosition; - LLPointer mArrowImage; + LLPointer mArrowImage; private: S32 mButtonPadding; @@ -211,9 +209,6 @@ public: void (*commit_callback)(LLUICtrl*, void*) = NULL, void *callback_userdata = NULL); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_FLYOUT_BUTTON; } - virtual LLString getWidgetTag() const { return LL_FLYOUT_BUTTON_TAG; } - virtual void updateLayout(); virtual void draw(); virtual void setEnabled(BOOL enabled); @@ -230,6 +225,8 @@ protected: LLPointer mExpanderButtonImage; LLPointer mActionButtonImageSelected; LLPointer mExpanderButtonImageSelected; + LLPointer mActionButtonImageDisabled; + LLPointer mExpanderButtonImageDisabled; BOOL mToggleState; }; diff --git a/linden/indra/llui/lldraghandle.cpp b/linden/indra/llui/lldraghandle.cpp index 516afc6..f033371 100644 --- a/linden/indra/llui/lldraghandle.cpp +++ b/linden/indra/llui/lldraghandle.cpp @@ -101,16 +101,6 @@ LLDragHandleTop::LLDragHandleTop(const LLString& name, const LLRect &rect, const setTitle( title ); } -EWidgetType LLDragHandleTop::getWidgetType() const -{ - return WIDGET_TYPE_DRAG_HANDLE_TOP; -} - -LLString LLDragHandleTop::getWidgetTag() const -{ - return LL_DRAG_HANDLE_TOP_TAG; -} - LLDragHandleLeft::LLDragHandleLeft(const LLString& name, const LLRect &rect, const LLString& title) : LLDragHandle(name, rect, title) { @@ -118,22 +108,12 @@ LLDragHandleLeft::LLDragHandleLeft(const LLString& name, const LLRect &rect, con setTitle( title ); } -EWidgetType LLDragHandleLeft::getWidgetType() const -{ - return WIDGET_TYPE_DRAG_HANDLE_LEFT; -} - -LLString LLDragHandleLeft::getWidgetTag() const -{ - return LL_DRAG_HANDLE_LEFT_TAG; -} - void LLDragHandleTop::setTitle(const LLString& title) { LLString trimmed_title = title; LLString::trim(trimmed_title); - const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF ); + const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); LLTextBox* titlebox = new LLTextBox( "Drag Handle Title", getRect(), trimmed_title, font ); titlebox->setFollows(FOLLOWS_TOP | FOLLOWS_LEFT | FOLLOWS_RIGHT); titlebox->setFontStyle(LLFontGL::DROP_SHADOW_SOFT); @@ -262,7 +242,7 @@ void LLDragHandleTop::reshapeTitleBox() { return; } - const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF ); + const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); S32 title_width = font->getWidth( getTitleBox()->getText() ) + TITLE_PAD; if (getMaxTitleWidth() > 0) title_width = llmin(title_width, getMaxTitleWidth()); @@ -372,7 +352,7 @@ BOOL LLDragHandle::handleHover(S32 x, S32 y, MASK mask) lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" <setCursor(UI_CURSOR_ARROW); lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; diff --git a/linden/indra/llui/lldraghandle.h b/linden/indra/llui/lldraghandle.h index 88e16dc..fc10639 100644 --- a/linden/indra/llui/lldraghandle.h +++ b/linden/indra/llui/lldraghandle.h @@ -90,9 +90,6 @@ class LLDragHandleTop public: LLDragHandleTop(const LLString& name, const LLRect& rect, const LLString& title ); - virtual EWidgetType getWidgetType() const; - virtual LLString getWidgetTag() const; - virtual void setTitle( const LLString& title ); virtual const LLString& getTitle() const; virtual void draw(); @@ -110,9 +107,6 @@ class LLDragHandleLeft public: LLDragHandleLeft(const LLString& name, const LLRect& rect, const LLString& title ); - virtual EWidgetType getWidgetType() const; - virtual LLString getWidgetTag() const; - virtual void setTitle( const LLString& title ); virtual const LLString& getTitle() const; virtual void draw(); diff --git a/linden/indra/llui/llfloater.cpp b/linden/indra/llui/llfloater.cpp index 1e825d3..5142bf4 100644 --- a/linden/indra/llui/llfloater.cpp +++ b/linden/indra/llui/llfloater.cpp @@ -50,7 +50,6 @@ #include "lltextbox.h" #include "llresmgr.h" #include "llui.h" -#include "llviewborder.h" #include "llwindow.h" #include "llstl.h" #include "llcontrol.h" @@ -131,8 +130,9 @@ LLFloaterView* gFloaterView = NULL; LLFloater::LLFloater() : //FIXME: we should initialize *all* member variables here mResizable(FALSE), - mDragOnLeft(FALSE) - + mDragOnLeft(FALSE), + mMinWidth(0), + mMinHeight(0) { // automatically take focus when opened mAutoFocus = TRUE; @@ -656,7 +656,8 @@ void LLFloater::setTitle( const LLString& title ) { return; } - mDragHandle->setTitle( title ); + if (mDragHandle) + mDragHandle->setTitle( title ); } const LLString& LLFloater::getTitle() const @@ -802,24 +803,10 @@ void LLFloater::setMinimized(BOOL minimize) mButtonsEnabled[BUTTON_RESTORE] = TRUE; } - mMinimizedHiddenChildren.clear(); - // hide all children - for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) - { - LLView* viewp = *child_it; - if (!viewp->getVisible()) - { - mMinimizedHiddenChildren.push_back(viewp->getHandle()); - } - viewp->setVisible(FALSE); - } - - // except the special controls if (mDragHandle) { mDragHandle->setVisible(TRUE); } - setBorderVisible(TRUE); for(handle_set_iter_t dependent_it = mDependents.begin(); @@ -843,6 +830,12 @@ void LLFloater::setMinimized(BOOL minimize) // Lose keyboard focus when minimized releaseFocus(); + for (S32 i = 0; i < 4; i++) + { + if (mResizeBar[i]) mResizeBar[i]->setEnabled(FALSE); + if (mResizeHandle[i]) mResizeHandle[i]->setEnabled(FALSE); + } + mMinimized = TRUE; // Reshape *after* setting mMinimized @@ -867,24 +860,6 @@ void LLFloater::setMinimized(BOOL minimize) mButtonsEnabled[BUTTON_RESTORE] = FALSE; } - // show all children - for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) - { - LLView* viewp = *child_it; - viewp->setVisible(TRUE); - } - - std::vector >::iterator itor = mMinimizedHiddenChildren.begin(); - for ( ; itor != mMinimizedHiddenChildren.end(); ++itor) - { - LLView* viewp = itor->get(); - if(viewp) - { - viewp->setVisible(FALSE); - } - } - mMinimizedHiddenChildren.clear(); - // show dependent floater for(handle_set_iter_t dependent_it = mDependents.begin(); dependent_it != mDependents.end(); @@ -898,6 +873,12 @@ void LLFloater::setMinimized(BOOL minimize) } } + for (S32 i = 0; i < 4; i++) + { + if (mResizeBar[i]) mResizeBar[i]->setEnabled(isResizable()); + if (mResizeHandle[i]) mResizeHandle[i]->setEnabled(isResizable()); + } + mMinimized = FALSE; // Reshape *after* setting mMinimized @@ -954,7 +935,8 @@ void LLFloater::setIsChrome(BOOL is_chrome) } // no titles displayed on "chrome" floaters - mDragHandle->setTitleVisible(!is_chrome); + if (mDragHandle) + mDragHandle->setTitleVisible(!is_chrome); LLPanel::setIsChrome(is_chrome); } @@ -965,7 +947,8 @@ void LLFloater::setForeground(BOOL front) if (front != mForeground) { mForeground = front; - mDragHandle->setForeground( front ); + if (mDragHandle) + mDragHandle->setForeground( front ); if (!front) { @@ -1310,49 +1293,72 @@ void LLFloater::onClickClose( void* userdata ) // virtual void LLFloater::draw() { - if( getVisible() ) + // draw background + if( isBackgroundVisible() ) { - // draw background - if( isBackgroundVisible() ) - { - S32 left = LLPANEL_BORDER_WIDTH; - S32 top = getRect().getHeight() - LLPANEL_BORDER_WIDTH; - S32 right = getRect().getWidth() - LLPANEL_BORDER_WIDTH; - S32 bottom = LLPANEL_BORDER_WIDTH; + S32 left = LLPANEL_BORDER_WIDTH; + S32 top = getRect().getHeight() - LLPANEL_BORDER_WIDTH; + S32 right = getRect().getWidth() - LLPANEL_BORDER_WIDTH; + S32 bottom = LLPANEL_BORDER_WIDTH; - LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); - F32 shadow_offset = (F32)LLUI::sConfigGroup->getS32("DropShadowFloater"); - if (!isBackgroundOpaque()) - { - shadow_offset *= 0.2f; - shadow_color.mV[VALPHA] *= 0.5f; - } - gl_drop_shadow(left, top, right, bottom, - shadow_color, - llround(shadow_offset)); + LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); + F32 shadow_offset = (F32)LLUI::sConfigGroup->getS32("DropShadowFloater"); + if (!isBackgroundOpaque()) + { + shadow_offset *= 0.2f; + shadow_color.mV[VALPHA] *= 0.5f; + } + gl_drop_shadow(left, top, right, bottom, + shadow_color, + llround(shadow_offset)); - // No transparent windows in simple UI - if (isBackgroundOpaque()) - { - gl_rect_2d( left, top, right, bottom, getBackgroundColor() ); - } - else - { - gl_rect_2d( left, top, right, bottom, getTransparentColor() ); - } + // No transparent windows in simple UI + if (isBackgroundOpaque()) + { + gl_rect_2d( left, top, right, bottom, getBackgroundColor() ); + } + else + { + gl_rect_2d( left, top, right, bottom, getTransparentColor() ); + } - if(gFocusMgr.childHasKeyboardFocus(this) && !getIsChrome() && !getTitle().empty()) - { - // draw highlight on title bar to indicate focus. RDW - const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF ); - LLRect r = getRect(); - gl_rect_2d_offset_local(0, r.getHeight(), r.getWidth(), r.getHeight() - (S32)font->getLineHeight() - 1, - LLUI::sColorsGroup->getColor("TitleBarFocusColor"), 0, TRUE); - } + if(gFocusMgr.childHasKeyboardFocus(this) && !getIsChrome() && !getTitle().empty()) + { + // draw highlight on title bar to indicate focus. RDW + const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); + LLRect r = getRect(); + gl_rect_2d_offset_local(0, r.getHeight(), r.getWidth(), r.getHeight() - (S32)font->getLineHeight() - 1, + LLUI::sColorsGroup->getColor("TitleBarFocusColor"), 0, TRUE); } + } - LLPanel::updateDefaultBtn(); + LLPanel::updateDefaultBtn(); + if( getDefaultButton() ) + { + if (hasFocus() && getDefaultButton()->getEnabled()) + { + LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus(); + // is this button a direct descendent and not a nested widget (e.g. checkbox)? + BOOL focus_is_child_button = dynamic_cast(focus_ctrl) != NULL && focus_ctrl->getParent() == this; + // only enable default button when current focus is not a button + getDefaultButton()->setBorderEnabled(!focus_is_child_button); + } + else + { + getDefaultButton()->setBorderEnabled(FALSE); + } + } + if (isMinimized()) + { + for (S32 i = 0; i < BUTTON_COUNT; i++) + { + drawChild(mButtons[i]); + } + drawChild(mDragHandle); + } + else + { // draw children LLView* focused_child = gFocusMgr.getKeyboardFocus(); BOOL focused_child_visible = FALSE; @@ -1365,36 +1371,35 @@ void LLFloater::draw() // don't call LLPanel::draw() since we've implemented custom background rendering LLView::draw(); - if( isBackgroundVisible() ) - { - // add in a border to improve spacialized visual aclarity ;) - // use lines instead of gl_rect_2d so we can round the edges as per james' recommendation - LLUI::setLineWidth(1.5f); - LLColor4 outlineColor = gFocusMgr.childHasKeyboardFocus(this) ? LLUI::sColorsGroup->getColor("FloaterFocusBorderColor") : LLUI::sColorsGroup->getColor("FloaterUnfocusBorderColor"); - gl_rect_2d_offset_local(0, getRect().getHeight() + 1, getRect().getWidth() + 1, 0, outlineColor, -LLPANEL_BORDER_WIDTH, FALSE); - LLUI::setLineWidth(1.f); - } - if (focused_child_visible) { focused_child->setVisible(TRUE); } drawChild(focused_child); + } - // update tearoff button for torn off floaters - // when last host goes away - if (mCanTearOff && !getHost()) + if( isBackgroundVisible() ) + { + // add in a border to improve spacialized visual aclarity ;) + // use lines instead of gl_rect_2d so we can round the edges as per james' recommendation + LLUI::setLineWidth(1.5f); + LLColor4 outlineColor = gFocusMgr.childHasKeyboardFocus(this) ? LLUI::sColorsGroup->getColor("FloaterFocusBorderColor") : LLUI::sColorsGroup->getColor("FloaterUnfocusBorderColor"); + gl_rect_2d_offset_local(0, getRect().getHeight() + 1, getRect().getWidth() + 1, 0, outlineColor, -LLPANEL_BORDER_WIDTH, FALSE); + LLUI::setLineWidth(1.f); + } + + // update tearoff button for torn off floaters + // when last host goes away + if (mCanTearOff && !getHost()) + { + LLFloater* old_host = mLastHostHandle.get(); + if (!old_host) { - LLFloater* old_host = mLastHostHandle.get(); - if (!old_host) - { - setCanTearOff(FALSE); - } + setCanTearOff(FALSE); } } } - void LLFloater::setCanMinimize(BOOL can_minimize) { // removing minimize/restore button programmatically, @@ -1540,7 +1545,13 @@ void LLFloater::updateButtons() S32 button_count = 0; for (S32 i = 0; i < BUTTON_COUNT; i++) { - if (mButtonsEnabled[i]) + mButtons[i]->setEnabled(mButtonsEnabled[i]); + + if (mButtonsEnabled[i] + //*HACK: always render close button for hosted floaters + // so that users don't accidentally hit the button when closing multiple windows + // in the chatterbox + || (i == BUTTON_CLOSE && mButtonScale != 1.f)) { button_count++; @@ -1564,18 +1575,16 @@ void LLFloater::updateButtons() mButtons[i]->setRect(btn_rect); mButtons[i]->setVisible(TRUE); - mButtons[i]->setEnabled(TRUE); // the restore button should have a tab stop so that it takes action when you Ctrl-Tab to a minimized floater mButtons[i]->setTabStop(i == BUTTON_RESTORE); } else if (mButtons[i]) { mButtons[i]->setVisible(FALSE); - mButtons[i]->setEnabled(FALSE); } } - - mDragHandle->setMaxTitleWidth(getRect().getWidth() - (button_count * (LLFLOATER_CLOSE_BOX_SIZE + 1))); + if (mDragHandle) + mDragHandle->setMaxTitleWidth(getRect().getWidth() - (button_count * (LLFLOATER_CLOSE_BOX_SIZE + 1))); } void LLFloater::buildButtons() @@ -2076,7 +2085,7 @@ void LLFloaterView::closeAllChildren(bool app_quitting) // Attempt to close floater. This will cause the "do you want to save" // dialogs to appear. - if (floaterp->canClose()) + if (floaterp->canClose() && !floaterp->isDead()) { floaterp->close(app_quitting); } @@ -2093,7 +2102,7 @@ BOOL LLFloaterView::allChildrenClosed() LLView* viewp = *it; LLFloater* floaterp = (LLFloater*)viewp; - if (floaterp->getVisible() && floaterp->canClose()) + if (floaterp->getVisible() && !floaterp->isDead() && floaterp->canClose()) { return false; } @@ -2332,7 +2341,9 @@ void LLFloaterView::popVisibleAll(const skip_list_t& skip_list) LLMultiFloater::LLMultiFloater() : mTabContainer(NULL), mTabPos(LLTabContainer::TOP), - mAutoResize(TRUE) + mAutoResize(TRUE), + mOrigMinWidth(0), + mOrigMinHeight(0) { } @@ -2340,7 +2351,9 @@ LLMultiFloater::LLMultiFloater() : LLMultiFloater::LLMultiFloater(LLTabContainer::TabPosition tab_pos) : mTabContainer(NULL), mTabPos(tab_pos), - mAutoResize(TRUE) + mAutoResize(TRUE), + mOrigMinWidth(0), + mOrigMinHeight(0) { } @@ -2349,7 +2362,9 @@ LLMultiFloater::LLMultiFloater(const LLString &name) : LLFloater(name), mTabContainer(NULL), mTabPos(LLTabContainer::TOP), - mAutoResize(FALSE) + mAutoResize(FALSE), + mOrigMinWidth(0), + mOrigMinHeight(0) { } @@ -2361,7 +2376,9 @@ LLMultiFloater::LLMultiFloater( LLFloater(name, rect, name), mTabContainer(NULL), mTabPos(LLTabContainer::TOP), - mAutoResize(auto_resize) + mAutoResize(auto_resize), + mOrigMinWidth(0), + mOrigMinHeight(0) { mTabContainer = new LLTabContainer("Preview Tabs", LLRect(LLPANEL_BORDER_WIDTH, getRect().getHeight() - LLFLOATER_HEADER_SIZE, getRect().getWidth() - LLPANEL_BORDER_WIDTH, 0), @@ -2385,7 +2402,9 @@ LLMultiFloater::LLMultiFloater( LLFloater(name, rect_control, name), mTabContainer(NULL), mTabPos(tab_pos), - mAutoResize(auto_resize) + mAutoResize(auto_resize), + mOrigMinWidth(0), + mOrigMinHeight(0) { mTabContainer = new LLTabContainer("Preview Tabs", LLRect(LLPANEL_BORDER_WIDTH, getRect().getHeight() - LLFLOATER_HEADER_SIZE, getRect().getWidth() - LLPANEL_BORDER_WIDTH, 0), @@ -2678,24 +2697,20 @@ void LLMultiFloater::setVisible(BOOL visible) } } -BOOL LLMultiFloater::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLMultiFloater::handleKeyHere(KEY key, MASK mask) { - if (getEnabled() - && mask == MASK_CONTROL) + if (key == 'W' && mask == MASK_CONTROL) { - if (key == 'W') + LLFloater* floater = getActiveFloater(); + // is user closeable and is system closeable + if (floater && floater->canClose() && floater->isCloseable()) { - LLFloater* floater = getActiveFloater(); - // is user closeable and is system closeable - if (floater && floater->canClose() && floater->isCloseable()) - { - floater->close(); - } - return TRUE; + floater->close(); } + return TRUE; } - return LLFloater::handleKeyHere(key, mask, called_from_parent); + return LLFloater::handleKeyHere(key, mask); } LLFloater* LLMultiFloater::getActiveFloater() @@ -2763,15 +2778,18 @@ void LLMultiFloater::setCanResize(BOOL can_resize) BOOL LLMultiFloater::postBuild() { + // remember any original xml minimum size + getResizeLimits(&mOrigMinWidth, &mOrigMinHeight); + if (mTabContainer) { return TRUE; } - requires("Preview Tabs", WIDGET_TYPE_TAB_CONTAINER); + requires("Preview Tabs"); if (checkRequirements()) { - mTabContainer = LLUICtrlFactory::getTabContainerByName(this, "Preview Tabs"); + mTabContainer = getChild("Preview Tabs"); return TRUE; } @@ -2780,10 +2798,11 @@ BOOL LLMultiFloater::postBuild() void LLMultiFloater::updateResizeLimits() { - S32 new_min_width = 0; - S32 new_min_height = 0; - S32 tab_idx; - for (tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx) + // initialize minimum size constraint to the original xml values. + S32 new_min_width = mOrigMinWidth; + S32 new_min_height = mOrigMinHeight; + // possibly increase minimum size constraint due to children's minimums. + for (S32 tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx) { LLFloater* floaterp = (LLFloater*)mTabContainer->getPanelByIndex(tab_idx); if (floaterp) diff --git a/linden/indra/llui/llfloater.h b/linden/indra/llui/llfloater.h index f0bbcaf..8068741 100644 --- a/linden/indra/llui/llfloater.h +++ b/linden/indra/llui/llfloater.h @@ -50,7 +50,7 @@ class LLMultiFloater; const S32 LLFLOATER_VPAD = 6; const S32 LLFLOATER_HPAD = 6; const S32 LLFLOATER_CLOSE_BOX_SIZE = 16; -const S32 LLFLOATER_HEADER_SIZE = 16; +const S32 LLFLOATER_HEADER_SIZE = 18; const BOOL RESIZE_YES = TRUE; const BOOL RESIZE_NO = FALSE; @@ -122,8 +122,6 @@ public: virtual void initFloater(const LLString& title, BOOL resizable, S32 min_width, S32 min_height, BOOL drag_on_left, BOOL minimizable, BOOL close_btn); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_FLOATER; } - virtual LLString getWidgetTag() const { return LL_FLOATER_TAG; }; virtual void open(); /* Flawfinder: ignore */ @@ -187,6 +185,8 @@ public: // Defaults to destroy(). virtual void onClose(bool app_quitting) { destroy(); } + // This cannot be "const" until all derived floater canClose() + // methods are const as well. JC virtual BOOL canClose() { return TRUE; } virtual void setVisible(BOOL visible); @@ -302,9 +302,6 @@ class LLFloaterView : public LLUICtrl public: LLFloaterView( const LLString& name, const LLRect& rect ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_FLOATER_VIEW; } - virtual LLString getWidgetTag() const { return LL_FLOATER_VIEW_TAG; } - /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); void reshapeFloater(S32 width, S32 height, BOOL called_from_parent, BOOL adjust_vertical); @@ -373,9 +370,7 @@ public: /*virtual*/ void onClose(bool app_quitting); /*virtual*/ void draw(); /*virtual*/ void setVisible(BOOL visible); - /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); - /*virtual*/ EWidgetType getWidgetType() const { return WIDGET_TYPE_MULTI_FLOATER; } - /*virtual*/ LLString getWidgetTag() const { return LL_MULTI_FLOATER_TAG; }; + /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask); virtual void setCanResize(BOOL can_resize); virtual void growToFit(S32 content_width, S32 content_height); @@ -418,6 +413,7 @@ protected: LLTabContainer::TabPosition mTabPos; BOOL mAutoResize; + S32 mOrigMinWidth, mOrigMinHeight; // logically const but initialized late }; // visibility policy specialized for floaters diff --git a/linden/indra/llui/llfocusmgr.cpp b/linden/indra/llui/llfocusmgr.cpp index 0634513..e2d1f46 100644 --- a/linden/indra/llui/llfocusmgr.cpp +++ b/linden/indra/llui/llfocusmgr.cpp @@ -46,6 +46,7 @@ LLFocusMgr::LLFocusMgr() mKeyboardFocus( NULL ), mLastKeyboardFocus( NULL ), mDefaultKeyboardFocus( NULL ), + mKeystrokesOnly(FALSE), mTopCtrl( NULL ), mFocusWeight(0.f), mAppHasFocus(TRUE) // Macs don't seem to notify us that we've gotten focus, so default to true @@ -85,7 +86,7 @@ void LLFocusMgr::releaseFocusIfNeeded( const LLView* view ) } -void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock) +void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock, BOOL keystrokes_only) { if (mLockedView && (new_focus == NULL || @@ -98,6 +99,8 @@ void LLFocusMgr::setKeyboardFocus(LLUICtrl* new_focus, BOOL lock) //llinfos << "Keyboard focus handled by " << (new_focus ? new_focus->getName() : "nothing") << llendl; + mKeystrokesOnly = keystrokes_only; + if( new_focus != mKeyboardFocus ) { mLastKeyboardFocus = mKeyboardFocus; diff --git a/linden/indra/llui/llfocusmgr.h b/linden/indra/llui/llfocusmgr.h index 842c874..49aba93 100644 --- a/linden/indra/llui/llfocusmgr.h +++ b/linden/indra/llui/llfocusmgr.h @@ -54,13 +54,17 @@ public: BOOL childHasMouseCapture( const LLView* parent ) const; // Keyboard Focus - void setKeyboardFocus(LLUICtrl* new_focus, BOOL lock = FALSE); // new_focus = NULL to release the focus. + void setKeyboardFocus(LLUICtrl* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE); // new_focus = NULL to release the focus. LLUICtrl* getKeyboardFocus() const { return mKeyboardFocus; } LLUICtrl* getLastKeyboardFocus() const { return mLastKeyboardFocus; } BOOL childHasKeyboardFocus( const LLView* parent ) const; void removeKeyboardFocusWithoutCallback( const LLView* focus ); + BOOL getKeystrokesOnly() { return mKeystrokesOnly; } + void setKeystrokesOnly(BOOL keystrokes_only) { mKeystrokesOnly = keystrokes_only; } + F32 getFocusTime() const { return mFocusTimer.getElapsedTimeF32(); } F32 getFocusFlashAmt() const; + S32 getFocusFlashWidth() const { return llround(lerp(1.f, 3.f, getFocusFlashAmt())); } LLColor4 getFocusColor() const; void triggerFocusFlash(); BOOL getAppHasFocus() const { return mAppHasFocus; } @@ -96,6 +100,7 @@ private: LLUICtrl* mKeyboardFocus; // Keyboard events are preemptively routed to this object LLUICtrl* mLastKeyboardFocus; // who last had focus LLUICtrl* mDefaultKeyboardFocus; + BOOL mKeystrokesOnly; // Top View LLUICtrl* mTopCtrl; diff --git a/linden/indra/llui/llhtmlhelp.h b/linden/indra/llui/llhtmlhelp.h index d4ec9e3..254faa2 100644 --- a/linden/indra/llui/llhtmlhelp.h +++ b/linden/indra/llui/llhtmlhelp.h @@ -36,7 +36,8 @@ class LLHtmlHelp { public: virtual ~LLHtmlHelp() {} - virtual void show(std::string start_url, std::string title) = 0; + virtual void show() = 0; + virtual void show(std::string help_url) = 0; }; #endif // LL_LLFLOATERHTMLHELP_H diff --git a/linden/indra/llui/lliconctrl.cpp b/linden/indra/llui/lliconctrl.cpp index 6a1d77c..f35de85 100644 --- a/linden/indra/llui/lliconctrl.cpp +++ b/linden/indra/llui/lliconctrl.cpp @@ -42,14 +42,15 @@ const F32 RESOLUTION_BUMP = 1.f; +static LLRegisterWidget r("icon"); + LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLUUID &image_id) : LLUICtrl(name, rect, FALSE, // mouse opaque NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP), - mColor( LLColor4::white ), - mImageName("") + mColor( LLColor4::white ) { setImage( image_id ); setTabStop(FALSE); @@ -64,9 +65,7 @@ LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLString mColor( LLColor4::white ), mImageName(image_name) { - LLUUID image_id; - image_id.set(LLUI::sAssetsGroup->getString( image_name )); - setImage( image_id ); + setImage( image_name ); setTabStop(FALSE); } @@ -77,32 +76,52 @@ LLIconCtrl::~LLIconCtrl() } -void LLIconCtrl::setImage(const LLUUID &image_id) +void LLIconCtrl::setImage(const LLString& image_name) { - mImageID = image_id; + //RN: support UUIDs masquerading as strings + if (LLUUID::validate(image_name)) + { + mImageID = LLUUID(image_name); + + setImage(mImageID); + } + else + { + mImageName = image_name; + mImagep = LLUI::sImageProvider->getUIImage(image_name); + mImageID.setNull(); + } +} + +void LLIconCtrl::setImage(const LLUUID& image_id) +{ + mImageName.clear(); mImagep = LLUI::sImageProvider->getUIImageByID(image_id); + mImageID = image_id; } void LLIconCtrl::draw() { - if( getVisible() ) + if( mImagep.notNull() ) { - if( mImagep.notNull() ) - { - mImagep->draw(0, 0, - getRect().getWidth(), getRect().getHeight(), - mColor ); - } - - LLUICtrl::draw(); + mImagep->draw(getLocalRect(), mColor ); } + + LLUICtrl::draw(); } // virtual void LLIconCtrl::setValue(const LLSD& value ) { - setImage(value.asUUID()); + if (value.isUUID()) + { + setImage(value.asUUID()); + } + else + { + setImage(value.asString()); + } } // virtual @@ -135,18 +154,16 @@ LLView* LLIconCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory * LLRect rect; createRect(node, rect, parent, LLRect()); - LLUUID image_id; + LLString image_name; if (node->hasAttribute("image_name")) { - LLString image_name; node->getAttributeString("image_name", image_name); - image_id.set(LLUI::sAssetsGroup->getString( image_name )); } LLColor4 color(LLColor4::white); LLUICtrlFactory::getAttributeColor(node,"color", color); - LLIconCtrl* icon = new LLIconCtrl(name, rect, image_id); + LLIconCtrl* icon = new LLIconCtrl(name, rect, image_name); icon->setColor(color); diff --git a/linden/indra/llui/lliconctrl.h b/linden/indra/llui/lliconctrl.h index b0c191f..055b504 100644 --- a/linden/indra/llui/lliconctrl.h +++ b/linden/indra/llui/lliconctrl.h @@ -51,14 +51,14 @@ public: LLIconCtrl(const LLString& name, const LLRect &rect, const LLUUID &image_id); LLIconCtrl(const LLString& name, const LLRect &rect, const LLString &image_name); virtual ~LLIconCtrl(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_ICON; } - virtual LLString getWidgetTag() const { return LL_ICON_CTRL_TAG; } // llview overrides virtual void draw(); - void setImage(const LLUUID &image_id); + void setImage(const LLString& image_name); + void setImage(const LLUUID& image_name); const LLUUID &getImage() const { return mImageID; } + LLString getImageName() const { return mImageName; } // Takes a UUID, wraps get/setImage virtual void setValue(const LLSD& value ); diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 1c96bc4..aeb906c 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -70,7 +70,6 @@ const F32 CURSOR_FLASH_DELAY = 1.0f; // in seconds const S32 SCROLL_INCREMENT_ADD = 0; // make space for typing const S32 SCROLL_INCREMENT_DEL = 4; // make space for baskspacing const F32 AUTO_SCROLL_TIME = 0.05f; -const F32 LABEL_HPAD = 5.f; const F32 PREEDIT_MARKER_BRIGHTNESS = 0.4f; const S32 PREEDIT_MARKER_GAP = 1; @@ -81,6 +80,10 @@ const S32 PREEDIT_STANDOUT_GAP = 1; const S32 PREEDIT_STANDOUT_POSITION = 2; const S32 PREEDIT_STANDOUT_THICKNESS = 2; +static LLRegisterWidget r1("line_editor"); + +/* static */ LLPointer LLLineEditor::sImage; + // // Member functions // @@ -101,8 +104,8 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, mMaxLengthBytes(max_length_bytes), mCursorPos( 0 ), mScrollHPos( 0 ), - mBorderLeft(0), - mBorderRight(0), + mTextPadLeft(0), + mTextPadRight(0), mCommitOnFocusLost( TRUE ), mRevertOnEsc( TRUE ), mKeystrokeCallback( keystroke_callback ), @@ -128,7 +131,8 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, mHandleEditKeysDirectly( FALSE ), mSelectAllonFocusReceived( FALSE ), mPassDelete(FALSE), - mReadOnly(FALSE) + mReadOnly(FALSE), + mImage( sImage ) { llassert( max_length_bytes > 0 ); @@ -151,8 +155,7 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, setFocusLostCallback(focus_lost_callback); - mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft; - mMaxHPixels = getRect().getWidth() - mMinHPixels - mBorderThickness - mBorderRight; + setTextPadding(0, 0); mScrollTimer.reset(); @@ -166,6 +169,12 @@ LLLineEditor::LLLineEditor(const LLString& name, const LLRect& rect, mBorder = new LLViewBorder( "line ed border", border_rect, border_bevel, border_style, mBorderThickness ); addChild( mBorder ); mBorder->setFollows(FOLLOWS_LEFT|FOLLOWS_RIGHT|FOLLOWS_TOP|FOLLOWS_BOTTOM); + + if( ! sImage) + { + sImage = LLUI::getUIImage("sm_rounded_corners_simple.tga"); + } + mImage = sImage; } @@ -243,9 +252,9 @@ void LLLineEditor::updateHistory() void LLLineEditor::reshape(S32 width, S32 height, BOOL called_from_parent) { - LLUICtrl::reshape(width, height, called_from_parent ); - - mMaxHPixels = getRect().getWidth() - 2 * (mBorderThickness + UI_LINEEDITOR_H_PAD) + 1 - mBorderRight; + LLUICtrl::reshape(width, height, called_from_parent); + setTextPadding(mTextPadLeft, mTextPadRight); // For clamping side-effect. + setCursor(mCursorPos); // For clamping side-effect. } void LLLineEditor::setEnabled(BOOL enabled) @@ -262,12 +271,12 @@ void LLLineEditor::setMaxTextLength(S32 max_text_length) mMaxLengthBytes = max_len; } -void LLLineEditor::setBorderWidth(S32 left, S32 right) +void LLLineEditor::setTextPadding(S32 left, S32 right) { - mBorderLeft = llclamp(left, 0, getRect().getWidth()); - mBorderRight = llclamp(right, 0, getRect().getWidth()); - mMinHPixels = mBorderThickness + UI_LINEEDITOR_H_PAD + mBorderLeft; - mMaxHPixels = getRect().getWidth() - mMinHPixels - mBorderThickness - mBorderRight; + mTextPadLeft = llclamp(left, 0, getRect().getWidth()); + mTextPadRight = llclamp(right, 0, getRect().getWidth()); + mMinHPixels = UI_LINEEDITOR_H_PAD + mTextPadLeft; + mMaxHPixels = getRect().getWidth() - mMinHPixels - mTextPadRight; } @@ -483,9 +492,10 @@ BOOL LLLineEditor::handleDoubleClick(S32 x, S32 y, MASK mask) BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) { - if (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight)) + // Check first whether the "clear search" button wants to deal with this. + if(childrenHandleMouseDown(x, y, mask) != NULL) { - return LLUICtrl::handleMouseDown(x, y, mask); + return TRUE; } if (mSelectAllonFocusReceived && gFocusMgr.getKeyboardFocus() != this) @@ -563,61 +573,62 @@ BOOL LLLineEditor::handleMouseDown(S32 x, S32 y, MASK mask) BOOL LLLineEditor::handleHover(S32 x, S32 y, MASK mask) { BOOL handled = FALSE; - if (!hasMouseCapture() && (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight))) + // Check first whether the "clear search" button wants to deal with this. + if(!hasMouseCapture()) { - return LLUICtrl::handleHover(x, y, mask); + if(childrenHandleHover(x, y, mask) != NULL) + { + return TRUE; + } } - if( getVisible() ) + if( (hasMouseCapture()) && mIsSelecting ) { - if( (hasMouseCapture()) && mIsSelecting ) + if (x != mLastSelectionX || y != mLastSelectionY) { - if (x != mLastSelectionX || y != mLastSelectionY) + mLastSelectionX = x; + mLastSelectionY = y; + } + // Scroll if mouse cursor outside of bounds + if (mScrollTimer.hasExpired()) + { + S32 increment = llround(mScrollTimer.getElapsedTimeF32() / AUTO_SCROLL_TIME); + mScrollTimer.reset(); + mScrollTimer.setTimerExpirySec(AUTO_SCROLL_TIME); + if( (x < mMinHPixels) && (mScrollHPos > 0 ) ) { - mLastSelectionX = x; - mLastSelectionY = y; + // Scroll to the left + mScrollHPos = llclamp(mScrollHPos - increment, 0, mText.length()); } - // Scroll if mouse cursor outside of bounds - if (mScrollTimer.hasExpired()) + else + if( (x > mMaxHPixels) && (mCursorPos < (S32)mText.length()) ) { - S32 increment = llround(mScrollTimer.getElapsedTimeF32() / AUTO_SCROLL_TIME); - mScrollTimer.reset(); - mScrollTimer.setTimerExpirySec(AUTO_SCROLL_TIME); - if( (x < mMinHPixels) && (mScrollHPos > 0 ) ) - { - // Scroll to the left - mScrollHPos = llclamp(mScrollHPos - increment, 0, mText.length()); - } - else - if( (x > mMaxHPixels) && (mCursorPos < (S32)mText.length()) ) + // If scrolling one pixel would make a difference... + S32 pixels_after_scrolling_one_char = findPixelNearestPos(1); + if( pixels_after_scrolling_one_char >= mMaxHPixels ) { - // If scrolling one pixel would make a difference... - S32 pixels_after_scrolling_one_char = findPixelNearestPos(1); - if( pixels_after_scrolling_one_char >= mMaxHPixels ) - { - // ...scroll to the right - mScrollHPos = llclamp(mScrollHPos + increment, 0, mText.length()); - } + // ...scroll to the right + mScrollHPos = llclamp(mScrollHPos + increment, 0, mText.length()); } } + } - setCursorAtLocalPos( x ); - mSelectionEnd = getCursor(); + setCursorAtLocalPos( x ); + mSelectionEnd = getCursor(); - // delay cursor flashing - mKeystrokeTimer.reset(); + // delay cursor flashing + mKeystrokeTimer.reset(); - getWindow()->setCursor(UI_CURSOR_IBEAM); - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; - handled = TRUE; - } + getWindow()->setCursor(UI_CURSOR_IBEAM); + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; + handled = TRUE; + } - if( !handled ) - { - getWindow()->setCursor(UI_CURSOR_IBEAM); - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; - handled = TRUE; - } + if( !handled ) + { + getWindow()->setCursor(UI_CURSOR_IBEAM); + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; + handled = TRUE; } return handled; @@ -634,9 +645,10 @@ BOOL LLLineEditor::handleMouseUp(S32 x, S32 y, MASK mask) handled = TRUE; } - if (!handled && (x < mBorderLeft || x > (getRect().getWidth() - mBorderRight))) + // Check first whether the "clear search" button wants to deal with this. + if(!handled && childrenHandleMouseUp(x, y, mask) != NULL) { - return LLUICtrl::handleMouseUp(x, y, mask); + return TRUE; } if( mIsSelecting ) @@ -1223,12 +1235,12 @@ BOOL LLLineEditor::handleSpecialKey(KEY key, MASK mask) } -BOOL LLLineEditor::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLLineEditor::handleKeyHere(KEY key, MASK mask ) { BOOL handled = FALSE; BOOL selection_modified = FALSE; - if ( (gFocusMgr.getKeyboardFocus() == this) && getVisible()) + if ( gFocusMgr.getKeyboardFocus() == this ) { LLLineEditorRollback rollback( this ); @@ -1291,7 +1303,7 @@ BOOL LLLineEditor::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) } -BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) +BOOL LLLineEditor::handleUnicodeCharHere(llwchar uni_char) { if ((uni_char < 0x20) || (uni_char == 0x7F)) // Control character or DEL { @@ -1381,11 +1393,6 @@ void LLLineEditor::doDelete() void LLLineEditor::draw() { - if( !getVisible() ) - { - return; - } - S32 text_len = mText.length(); LLString saved_text; @@ -1406,6 +1413,13 @@ void LLLineEditor::draw() LLColor4 bg_color = mReadOnlyBgColor; +#if 0 // for when we're ready for image art. + if( hasFocus()) + { + mImage->drawBorder(0, 0, getRect().getWidth(), getRect().getHeight(), gFocusMgr.getFocusColor(), gFocusMgr.getFocusFlashWidth()); + } + mImage->draw(getLocalRect(), mReadOnly ? mReadOnlyBgColor : mWriteableBgColor ); +#else // the old programmer art. // drawing solids requires texturing be disabled { LLGLSNoTexture no_texture; @@ -1423,6 +1437,7 @@ void LLLineEditor::draw() } gl_rect_2d(background, bg_color); } +#endif // draw text @@ -1560,10 +1575,14 @@ void LLLineEditor::draw() mMaxHPixels - llround(rendered_pixels_right), &rendered_pixels_right); } +#if 0 // for when we're ready for image art. + mBorder->setVisible(FALSE); // no more programmatic art. +#endif // If we're editing... if( gFocusMgr.getKeyboardFocus() == this) { + //mBorder->setVisible(TRUE); // ok, programmer art just this once. // (Flash the cursor every half second) if (gShowTextEditCursor && !mReadOnly) { @@ -1616,7 +1635,7 @@ void LLLineEditor::draw() if (0 == mText.length()) { mGLFont->render(mLabel.getWString(), 0, - LABEL_HPAD, (F32)text_bottom, + mMinHPixels, (F32)text_bottom, label_color, LLFontGL::LEFT, LLFontGL::BOTTOM, LLFontGL::NORMAL, @@ -1757,7 +1776,7 @@ BOOL LLLineEditor::prevalidateFloat(const LLWString &str) if( 0 < len ) { // May be a comma or period, depending on the locale - llwchar decimal_point = (llwchar)gResMgr->getDecimalPoint(); + llwchar decimal_point = (llwchar)LLResMgr::getInstance()->getDecimalPoint(); S32 i = 0; @@ -1806,7 +1825,7 @@ BOOL LLLineEditor::postvalidateFloat(const LLString &str) } // May be a comma or period, depending on the locale - llwchar decimal_point = (llwchar)gResMgr->getDecimalPoint(); + llwchar decimal_point = (llwchar)LLResMgr::getInstance()->getDecimalPoint(); for( ; i < len; i++ ) { @@ -2244,8 +2263,27 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory return line_editor; } +//static +void LLLineEditor::cleanupClass() +{ + sImage = NULL; +} + +/* static */ +LLPointer LLLineEditor::parseImage(LLString name, LLXMLNodePtr from, LLPointer def) +{ + LLString xml_name; + if (from->hasAttribute(name)) from->getAttributeString(name, xml_name); + if (xml_name == LLString::null) return def; + LLPointer image = LLUI::getUIImage(xml_name); + return image.isNull() ? def : image; +} + void LLLineEditor::setColorParameters(LLXMLNodePtr node) { + // overrides default image if supplied. + mImage = parseImage("image", node, mImage); + LLColor4 color; if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) { @@ -2510,6 +2548,9 @@ S32 LLLineEditor::getPreeditFontSize() const } +static LLRegisterWidget r2("search_editor"); + + LLSearchEditor::LLSearchEditor(const LLString& name, const LLRect& rect, S32 max_length_bytes, @@ -2539,7 +2580,7 @@ LLSearchEditor::LLSearchEditor(const LLString& name, LLRect clear_btn_rect(rect.getWidth() - btn_width, rect.getHeight(), rect.getWidth(), 0); mClearSearchButton = new LLButton("clear search", clear_btn_rect, - "closebox.tga", + "icn_clear_lineeditor.tga", "UIImgBtnCloseInactiveUUID", LLString::null, onClearSearch, @@ -2552,9 +2593,42 @@ LLSearchEditor::LLSearchEditor(const LLString& name, mClearSearchButton->setTabStop(FALSE); mSearchEdit->addChild(mClearSearchButton); - mSearchEdit->setBorderWidth(0, btn_width); + mSearchEdit->setTextPadding(0, btn_width); +} + + +//virtual +void LLSearchEditor::setValue(const LLSD& value ) +{ + mSearchEdit->setValue(value); +} + +//virtual +LLSD LLSearchEditor::getValue() const +{ + return mSearchEdit->getValue(); } +//virtual +BOOL LLSearchEditor::setTextArg( const LLString& key, const LLStringExplicit& text ) +{ + return mSearchEdit->setTextArg(key, text); +} + +//virtual +BOOL LLSearchEditor::setLabelArg( const LLString& key, const LLStringExplicit& text ) +{ + return mSearchEdit->setLabelArg(key, text); +} + +//virtual +void LLSearchEditor::clear() +{ + if (mSearchEdit) + { + mSearchEdit->clear(); + } +} void LLSearchEditor::draw() { diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index ba3c697..bf0dcb5 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -78,19 +78,19 @@ public: S32 border_thickness = 1); virtual ~LLLineEditor(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_LINE_EDITOR; } - virtual LLString getWidgetTag() const { return LL_LINE_EDITOR_TAG; }; + virtual LLXMLNodePtr getXML(bool save_children = true) const; void setColorParameters(LLXMLNodePtr node); static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); + static void cleanupClass(); // mousehandler overrides /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleDoubleClick(S32 x,S32 y,MASK mask); - /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ); - /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); + /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask ); + /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char); /*virtual*/ void onMouseCaptureLost(); // LLEditMenuHandler overrides @@ -189,8 +189,8 @@ public: void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data)); - void setMaxTextLength(S32 max_text_length); - void setBorderWidth(S32 left, S32 right); + void setMaxTextLength(S32 max_text_length); + void setTextPadding(S32 left, S32 right); // Used to specify room for children before or after text. static BOOL isPartOfWord(llwchar c); // Prevalidation controls which keystrokes can affect the editor @@ -212,7 +212,7 @@ public: void updateHistory(); // stores current line in history private: - // private helper classes + // private helper methods void removeChar(); void addChar(const llwchar c); void setCursorAtLocalPos(S32 local_mouse_x); @@ -254,10 +254,10 @@ protected: S32 mCursorPos; // I-beam is just after the mCursorPos-th character. S32 mScrollHPos; // Horizontal offset from the start of mText. Used for scrolling. LLFrameTimer mScrollTimer; + S32 mTextPadLeft; // Used to reserve space before the beginning of the text for children. + S32 mTextPadRight; // Used to reserve space after the end of the text for children. S32 mMinHPixels; S32 mMaxHPixels; - S32 mBorderLeft; - S32 mBorderRight; BOOL mCommitOnFocusLost; BOOL mRevertOnEsc; @@ -302,6 +302,15 @@ protected: std::vector mPreeditPositions; LLPreeditor::standouts_t mPreeditStandouts; +private: + // Utility on top of LLUI::getUIImage, looks up a named image in a given XML node and returns it if possible + // or returns a given default image if anything in the process fails. + static LLPointer parseImage(LLString name, LLXMLNodePtr from, LLPointer def); + // Global instance used as default for member instance below. + static LLPointer sImage; + // Instances that by default point to the statics but can be overidden in XML. + LLPointer mImage; + // private helper class class LLLineEditorRollback { @@ -359,8 +368,6 @@ public: /*virtual*/ void draw(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SEARCH_EDITOR; } - virtual LLString getWidgetTag() const { return LL_SEARCH_EDITOR_TAG; } static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); void setText(const LLStringExplicit &new_text) { mSearchEdit->setText(new_text); } @@ -368,12 +375,11 @@ public: void setSearchCallback(void (*search_callback)(const LLString& search_string, void* user_data), void* data) { mSearchCallback = search_callback; mCallbackUserData = data; } // LLUICtrl interface - virtual void setValue(const LLSD& value ) { mSearchEdit->setValue(value); } - virtual LLSD getValue() const { return mSearchEdit->getValue(); } - virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text ) { return mSearchEdit->setTextArg( key, text); } - virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text ) { return mSearchEdit->setLabelArg(key, text); } - virtual void clear() { if (mSearchEdit) mSearchEdit->clear(); } - + virtual void setValue(const LLSD& value ); + virtual LLSD getValue() const; + virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text ); + virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text ); + virtual void clear(); private: static void onSearchEdit(LLLineEditor* caller, void* user_data ); diff --git a/linden/indra/llui/llmenugl.cpp b/linden/indra/llui/llmenugl.cpp index cb54476..f2486f1 100644 --- a/linden/indra/llui/llmenugl.cpp +++ b/linden/indra/llui/llmenugl.cpp @@ -188,31 +188,6 @@ LLXMLNodePtr LLMenuItemGL::getXML(bool save_children) const return node; } -BOOL LLMenuItemGL::handleKey(KEY key, MASK mask, BOOL called_from_parent) -{ - // modified from LLView::handleKey - // ignore visibility, as keyboard accelerators should still trigger menu items - // even when they are not visible - // also, ignore enabled flag for self, as that can change based on menu callbacks - BOOL handled = FALSE; - - if( called_from_parent ) - { - // Downward traversal - if (getEnabled()) - { - handled = childrenHandleKey( key, mask ) != NULL; - } - } - - if( !handled ) - { - handled = handleKeyHere( key, mask, called_from_parent ); - } - - return handled; -} - BOOL LLMenuItemGL::handleAcceleratorKey(KEY key, MASK mask) { if( getEnabled() && (!gKeyboard->getKeyRepeated(key) || mAllowKeyRepeat) && (key == mAcceleratorKey) && (mask == (mAcceleratorMask & MASK_NORMALKEYS)) ) @@ -400,7 +375,7 @@ void LLMenuItemGL::doIt( void ) } -BOOL LLMenuItemGL::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLMenuItemGL::handleKeyHere( KEY key, MASK mask ) { if (getHighlight() && getMenu()->isOpen()) @@ -436,29 +411,21 @@ BOOL LLMenuItemGL::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ) BOOL LLMenuItemGL::handleMouseUp( S32 x, S32 y, MASK ) { - if (getEnabled()) - { - // switch to mouse navigation mode - LLMenuGL::setKeyboardMode(FALSE); + // switch to mouse navigation mode + LLMenuGL::setKeyboardMode(FALSE); - doIt(); - make_ui_sound("UISndClickRelease"); - return TRUE; - } - return FALSE; + doIt(); + make_ui_sound("UISndClickRelease"); + return TRUE; } BOOL LLMenuItemGL::handleMouseDown( S32 x, S32 y, MASK ) { - if (getEnabled()) - { - // switch to mouse navigation mode - LLMenuGL::setKeyboardMode(FALSE); + // switch to mouse navigation mode + LLMenuGL::setKeyboardMode(FALSE); - setHighlight(TRUE); - return TRUE; - } - return FALSE; + setHighlight(TRUE); + return TRUE; } @@ -560,9 +527,6 @@ public: virtual LLString getType() const { return "separator"; } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_SEPARATOR; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_SEPARATOR_GL_TAG; } - // doIt() - do the primary funcationality of the menu item. virtual void doIt( void ) {} @@ -641,9 +605,6 @@ class LLMenuItemVerticalSeparatorGL public: LLMenuItemVerticalSeparatorGL( void ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_SEPARATOR_VERTICAL; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_VERTICAL_SEPARATOR_GL_TAG; } - virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask) { return FALSE; } }; @@ -739,8 +700,6 @@ public: { setEnabled(FALSE); } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_BLANK; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_BLANK_GL_TAG; } virtual void doIt( void ) {} virtual void draw( void ) {} }; @@ -827,57 +786,33 @@ void LLMenuItemCallGL::setEnabledControl(LLString enabled_control, LLView *conte // Register new listener if (!enabled_control.empty()) { - LLControlBase *control = context->findControl(enabled_control); - if (control) - { - LLSD state = control->registerListener(this, "ENABLED"); - setEnabled(state); - } - else + LLControlVariable *control = context->findControl(enabled_control); + if (!control) { context->addBoolControl(enabled_control, getEnabled()); control = context->findControl(enabled_control); - control->registerListener(this, "ENABLED"); + llassert_always(control); } + control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("enabled"))); + setEnabled(control->getValue()); } } -void LLMenuItemCallGL::setVisibleControl(LLString enabled_control, LLView *context) +void LLMenuItemCallGL::setVisibleControl(LLString visible_control, LLView *context) { // Register new listener - if (!enabled_control.empty()) + if (!visible_control.empty()) { - LLControlBase *control = context->findControl(enabled_control); - if (control) + LLControlVariable *control = context->findControl(visible_control); + if (!control) { - LLSD state = control->registerListener(this, "VISIBLE"); - setVisible(state); + context->addBoolControl(visible_control, getVisible()); + control = context->findControl(visible_control); + llassert_always(control); } - else - { - context->addBoolControl(enabled_control, getEnabled()); - control = context->findControl(enabled_control); - control->registerListener(this, "VISIBLE"); - } - } -} - -// virtual -bool LLMenuItemCallGL::handleEvent(LLPointer event, const LLSD& userdata) -{ - if (userdata.asString() == "ENABLED" && event->desc() == "value_changed") - { - LLSD state = event->getValue(); - setEnabled(state); - return TRUE; + control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("visible"))); + setVisible(control->getValue()); } - if (userdata.asString() == "VISIBLE" && event->desc() == "value_changed") - { - LLSD state = event->getValue(); - setVisible(state); - return TRUE; - } - return LLMenuItemGL::handleEvent(event, userdata); } // virtual @@ -1000,44 +935,35 @@ LLMenuItemCheckGL::LLMenuItemCheckGL ( const LLString& name, setControlName(control_name, context); } -void LLMenuItemCheckGL::setCheckedControl(LLString checked_control, LLView *context) +//virtual +void LLMenuItemCheckGL::setValue(const LLSD& value) { - // Register new listener - if (!checked_control.empty()) + mChecked = value.asBoolean(); + if(mChecked) { - LLControlBase *control = context->findControl(checked_control); - if (control) - { - LLSD state = control->registerListener(this, "CHECKED"); - mChecked = state; - } - else - { - context->addBoolControl(checked_control, mChecked); - control = context->findControl(checked_control); - control->registerListener(this, "CHECKED"); - } + mDrawBoolLabel = BOOLEAN_TRUE_PREFIX; + } + else + { + mDrawBoolLabel.clear(); } } -// virtual -bool LLMenuItemCheckGL::handleEvent(LLPointer event, const LLSD& userdata) +void LLMenuItemCheckGL::setCheckedControl(LLString checked_control, LLView *context) { - if (userdata.asString() == "CHECKED" && event->desc() == "value_changed") + // Register new listener + if (!checked_control.empty()) { - LLSD state = event->getValue(); - mChecked = state; - if(mChecked) - { - mDrawBoolLabel = BOOLEAN_TRUE_PREFIX; - } - else + LLControlVariable *control = context->findControl(checked_control); + if (!control) { - mDrawBoolLabel.clear(); + context->addBoolControl(checked_control, mChecked); + control = context->findControl(checked_control); + llassert_always(control); } - return TRUE; + control->getSignal()->connect(boost::bind(&LLView::controlListener, _1, getHandle(), std::string("value"))); + mChecked = control->getValue(); } - return LLMenuItemCallGL::handleEvent(event, userdata); } // virtual @@ -1119,29 +1045,31 @@ LLMenuItemBranchGL::LLMenuItemBranchGL( const LLString& name, const LLString& la } // virtual -LLView* LLMenuItemBranchGL::getChildByName(const LLString& name, BOOL recurse) const +LLView* LLMenuItemBranchGL::getChildView(const LLString& name, BOOL recurse, BOOL create_if_missing) const { + // richard: this is redundant with parent, remove if (mBranch->getName() == name) { return mBranch; } // Always recurse on branches - return mBranch->getChild(name, recurse); + LLView* child = mBranch->getChildView(name, recurse, FALSE); + if (!child) + { + child = LLView::getChildView(name, recurse, create_if_missing); + } + return child; } // virtual BOOL LLMenuItemBranchGL::handleMouseUp(S32 x, S32 y, MASK mask) { - if (getEnabled()) - { - // switch to mouse navigation mode - LLMenuGL::setKeyboardMode(FALSE); + // switch to mouse navigation mode + LLMenuGL::setKeyboardMode(FALSE); - doIt(); - make_ui_sound("UISndClickRelease"); - return TRUE; - } - return FALSE; + doIt(); + make_ui_sound("UISndClickRelease"); + return TRUE; } BOOL LLMenuItemBranchGL::handleAcceleratorKey(KEY key, MASK mask) @@ -1299,7 +1227,7 @@ void LLMenuItemBranchGL::onVisibilityChange( BOOL new_visibility ) LLMenuItemGL::onVisibilityChange(new_visibility); } -BOOL LLMenuItemBranchGL::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLMenuItemBranchGL::handleKeyHere( KEY key, MASK mask ) { if (getMenu()->getVisible() && mBranch->getVisible() && key == KEY_LEFT) { @@ -1318,8 +1246,7 @@ BOOL LLMenuItemBranchGL::handleKeyHere( KEY key, MASK mask, BOOL called_from_par return handled; } - if (getEnabled() && - getHighlight() && + if (getHighlight() && getMenu()->isOpen() && key == KEY_RIGHT && !mBranch->getHighlightedItem()) { @@ -1333,7 +1260,7 @@ BOOL LLMenuItemBranchGL::handleKeyHere( KEY key, MASK mask, BOOL called_from_par } } - return LLMenuItemGL::handleKeyHere(key, mask, called_from_parent); + return LLMenuItemGL::handleKeyHere(key, mask); } void LLMenuItemBranchGL::openMenu() @@ -1403,9 +1330,6 @@ public: LLMenuItemBranchDownGL( const LLString& name, const LLString& label, LLMenuGL* branch, KEY key = KEY_NONE, MASK mask = MASK_NONE ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_BRANCH_DOWN_GL_TAG; } - virtual LLString getType() const { return "menu"; } // returns the normal width of this control in pixels - this is @@ -1429,7 +1353,7 @@ public: virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask ); virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask ); virtual void draw( void ); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleAcceleratorKey(KEY key, MASK mask); }; @@ -1566,7 +1490,7 @@ BOOL LLMenuItemBranchDownGL::handleAcceleratorKey(KEY key, MASK mask) return handled; } -BOOL LLMenuItemBranchDownGL::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLMenuItemBranchDownGL::handleKeyHere(KEY key, MASK mask) { BOOL menu_open = getBranch()->getVisible(); // don't do keyboard navigation of top-level menus unless in keyboard mode, or menu expanded @@ -1605,7 +1529,7 @@ BOOL LLMenuItemBranchDownGL::handleKeyHere(KEY key, MASK mask, BOOL called_from_ // switch to keyboard navigation mode LLMenuGL::setKeyboardMode(TRUE); - if (getEnabled() && !isActive()) + if (!isActive()) { doIt(); } @@ -1617,7 +1541,7 @@ BOOL LLMenuItemBranchDownGL::handleKeyHere(KEY key, MASK mask, BOOL called_from_ // switch to keyboard navigation mode LLMenuGL::setKeyboardMode(TRUE); - if (getEnabled() && !isActive()) + if (!isActive()) { doIt(); } @@ -1690,6 +1614,8 @@ void LLMenuItemBranchDownGL::draw( void ) /// Class LLMenuGL ///============================================================================ +static LLRegisterWidget r1("menu"); + // Default constructor LLMenuGL::LLMenuGL( const LLString& name, const LLString& label, LLHandle parent_floater_handle ) : LLUICtrl( name, LLRect(), FALSE, NULL, NULL ), @@ -1946,7 +1872,7 @@ void LLMenuGL::parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory { continue; } - LLControlBase *control = parent->findControl(control_name); + LLControlVariable *control = parent->findControl(control_name); if (!control) { parent->addBoolControl(control_name, FALSE); @@ -2685,8 +2611,8 @@ LLMenuItemGL* LLMenuGL::highlightNextItem(LLMenuItemGL* cur_item, BOOL skip_disa while(1) { - // skip separators and disabled items - if ((*next_item_iter)->getEnabled() && (*next_item_iter)->getType() != SEPARATOR_NAME) + // skip separators and disabled/invisible items + if ((*next_item_iter)->getEnabled() && (*next_item_iter)->getVisible() && (*next_item_iter)->getType() != SEPARATOR_NAME) { if (cur_item) { @@ -2751,8 +2677,8 @@ LLMenuItemGL* LLMenuGL::highlightPrevItem(LLMenuItemGL* cur_item, BOOL skip_disa while(1) { - // skip separators and disabled items - if ((*prev_item_iter)->getEnabled() && (*prev_item_iter)->getName() != SEPARATOR_NAME) + // skip separators and disabled/invisible items + if ((*prev_item_iter)->getEnabled() && (*prev_item_iter)->getVisible() && (*prev_item_iter)->getName() != SEPARATOR_NAME) { (*prev_item_iter)->setHighlight(TRUE); return (*prev_item_iter); @@ -2801,37 +2727,6 @@ void LLMenuGL::updateParent(LLView* parentp) } } -// LLView functionality -BOOL LLMenuGL::handleKey( KEY key, MASK mask, BOOL called_from_parent ) -{ - BOOL handled = FALSE; - - // Pass down even if not visible - if( getEnabled() && called_from_parent ) - { - for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) - { - LLView* viewp = *child_it; - if (viewp->handleKey(key, mask, TRUE)) - { - handled = TRUE; - break; - } - } - } - - if( !handled ) - { - handled = handleKeyHere( key, mask, called_from_parent ); - if (handled && LLView::sDebugKeys) - { - llinfos << "Key handled by " << getName() << llendl; - } - } - - return handled; -} - BOOL LLMenuGL::handleAcceleratorKey(KEY key, MASK mask) { // don't handle if not enabled @@ -2854,7 +2749,7 @@ BOOL LLMenuGL::handleAcceleratorKey(KEY key, MASK mask) return FALSE; } -BOOL LLMenuGL::handleUnicodeCharHere( llwchar uni_char, BOOL called_from_parent ) +BOOL LLMenuGL::handleUnicodeCharHere( llwchar uni_char ) { if (jumpKeysActive()) { @@ -2980,17 +2875,19 @@ void LLMenuGL::setVisible(BOOL visible) LLMenuGL* LLMenuGL::getChildMenuByName(const LLString& name, BOOL recurse) const { - LLView* view = getChildByName(name, recurse); + LLView* view = getChildView(name, recurse, FALSE); if (view) { - if (view->getWidgetType() == WIDGET_TYPE_MENU_ITEM_BRANCH) + LLMenuItemBranchGL* branch = dynamic_cast(view); + if (branch) { - LLMenuItemBranchGL *branch = (LLMenuItemBranchGL *)view; return branch->getBranch(); } - if (view->getWidgetType() == WIDGET_TYPE_MENU || view->getWidgetType() == WIDGET_TYPE_PIE_MENU) + + LLMenuGL* menup = dynamic_cast(view); + if (menup) { - return (LLMenuGL*)view; + return menup; } } llwarns << "Child Menu " << name << " not found in menu " << getName() << llendl; @@ -3070,9 +2967,6 @@ class LLPieMenuBranch : public LLMenuItemGL public: LLPieMenuBranch(const LLString& name, const LLString& label, LLPieMenu* branch); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_PIE_MENU_BRANCH; } - virtual LLString getWidgetTag() const { return LL_PIE_MENU_BRANCH_TAG; } - // called to rebuild the draw label virtual void buildDrawLabel( void ); @@ -3842,6 +3736,8 @@ void LLPieMenu::hide(BOOL item_selected) /// Class LLMenuBarGL ///============================================================================ +static LLRegisterWidget r2("menu_bar"); + // Default constructor LLMenuBarGL::LLMenuBarGL( const LLString& name ) : LLMenuGL ( name, name ) { @@ -3897,9 +3793,10 @@ LLView* LLMenuBarGL::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory LLMenuBarGL *menubar = new LLMenuBarGL(name); LLHandle parent_handle; - if (parent->getWidgetType() == WIDGET_TYPE_FLOATER) + LLFloater* parent_floater = dynamic_cast(parent); + if (parent_floater) { - parent_handle = ((LLFloater*)parent)->getHandle(); + parent_handle = parent_floater->getHandle(); } // We need to have the rect early so that it's around when building @@ -3991,7 +3888,7 @@ BOOL LLMenuBarGL::handleAcceleratorKey(KEY key, MASK mask) return result; } -BOOL LLMenuBarGL::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLMenuBarGL::handleKeyHere(KEY key, MASK mask) { if(key == KEY_ALT && !gKeyboard->getKeyRepeated(key) && LLUI::sConfigGroup->getBOOL("UseAltKeyForMenus")) { @@ -4005,7 +3902,7 @@ BOOL LLMenuBarGL::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) // before processing any other key, check to see if ALT key has triggered menu access checkMenuTrigger(); - return LLMenuGL::handleKeyHere(key, mask, called_from_parent); + return LLMenuGL::handleKeyHere(key, mask); } BOOL LLMenuBarGL::handleJumpKey(KEY key) @@ -4295,7 +4192,7 @@ BOOL LLMenuHolderGL::hasVisibleMenu() const for ( child_list_const_iter_t child_it = getChildList()->begin(); child_it != getChildList()->end(); ++child_it) { LLView* viewp = *child_it; - if (viewp->getVisible() && viewp->getWidgetType() != WIDGET_TYPE_MENU_BAR) + if (viewp->getVisible() && dynamic_cast(viewp) == NULL) { return TRUE; } @@ -4319,7 +4216,7 @@ BOOL LLMenuHolderGL::hideMenus() { LLView* viewp = *child_it; // clicks off of menu do not hide menu bar - if (viewp->getWidgetType() != WIDGET_TYPE_MENU_BAR && viewp->getVisible()) + if (dynamic_cast(viewp) == NULL && viewp->getVisible()) { viewp->setVisible(FALSE); } @@ -4429,7 +4326,7 @@ BOOL LLTearOffMenu::handleUnicodeChar(llwchar uni_char, BOOL called_from_parent) return mMenu->handleUnicodeChar(uni_char, TRUE); } -BOOL LLTearOffMenu::handleKey(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLTearOffMenu::handleKeyHere(KEY key, MASK mask) { if (!mMenu->getHighlightedItem()) { diff --git a/linden/indra/llui/llmenugl.h b/linden/indra/llui/llmenugl.h index cd39006..e7b009a 100644 --- a/linden/indra/llui/llmenugl.h +++ b/linden/indra/llui/llmenugl.h @@ -91,14 +91,11 @@ public: LLMenuItemGL( const LLString& name, const LLString& label, KEY key = KEY_NONE, MASK = MASK_NONE ); virtual void setValue(const LLSD& value) { setLabel(value.asString()); } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_TAG; } virtual LLXMLNodePtr getXML(bool save_children = true) const; virtual LLString getType() const { return "item"; } - virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleAcceleratorKey(KEY key, MASK mask); @@ -165,7 +162,7 @@ public: virtual void setEnabledSubMenus(BOOL enable){}; // LLView Functionality - virtual BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ); + virtual BOOL handleKeyHere( KEY key, MASK mask ); virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask ); virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask ); virtual void draw( void ); @@ -225,7 +222,7 @@ private: // calls a user defined callback. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class LLMenuItemCallGL : public LLMenuItemGL +class LLMenuItemCallGL : public LLMenuItemGL, public LLObservable { public: // normal constructor @@ -267,8 +264,6 @@ public: virtual LLString getType() const { return "call"; } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_CALL; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_CALL_GL_TAG; } void setEnabledControl(LLString enabled_control, LLView *context); void setVisibleControl(LLString enabled_control, LLView *context); @@ -291,7 +286,6 @@ public: //virtual void draw(); - virtual bool handleEvent(LLPointer event, const LLSD& userdata); private: menu_callback mCallback; @@ -341,17 +335,13 @@ public: void setCheckedControl(LLString checked_control, LLView *context); - virtual void setValue(const LLSD& value) { mChecked = value.asBoolean(); } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_CHECK; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_CHECK_GL_TAG; } + virtual void setValue(const LLSD& value); virtual LLString getType() const { return "check"; } // called to rebuild the draw label virtual void buildDrawLabel( void ); - virtual bool handleEvent(LLPointer event, const LLSD& userdata); - private: check_callback mCheckCallback; BOOL mChecked; @@ -408,6 +398,8 @@ class LLMenuGL // TODO: The menu and menu item classes share a great deal of functionality and perhaps should be united. // I think it may make the most sense to make LLMenuGL be a subclass of LLMenuItemGL. -MG { + // let branching menu items use my protected traversal methods + friend class LLMenuItemBranchGL; public: LLMenuGL( const LLString& name, const LLString& label, LLHandle parent_floater = LLHandle()); LLMenuGL( const LLString& label, LLHandle parent_floater = LLHandle() ); @@ -417,13 +409,9 @@ public: void parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory *factory); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU; } - virtual LLString getWidgetTag() const { return LL_MENU_GL_TAG; } // LLView Functionality - virtual BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent ); - //virtual BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ); - virtual BOOL handleUnicodeCharHere( llwchar uni_char, BOOL called_from_parent ); + virtual BOOL handleUnicodeCharHere( llwchar uni_char ); virtual BOOL handleHover( S32 x, S32 y, MASK mask ); virtual void draw( void ); virtual void drawBackground(LLMenuItemGL* itemp, LLColor4& color); @@ -579,9 +567,6 @@ public: virtual LLString getType() const { return "menu"; } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM_BRANCH; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_BRANCH_GL_TAG; } - virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleAcceleratorKey(KEY key, MASK mask); @@ -602,7 +587,7 @@ public: // active. This is used for behavior transfer. virtual void setHighlight( BOOL highlight ); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL isActive() const { return isOpen() && mBranch->getHighlightedItem(); } @@ -621,8 +606,7 @@ public: virtual void openMenu(); -protected: - virtual LLView* getChildByName(const LLString& name, BOOL recurse) const; + virtual LLView* getChildView(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; private: LLMenuGL* mBranch; @@ -643,16 +627,12 @@ public: LLPieMenu(const LLString& name); virtual ~LLPieMenu() {} - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_PIE_MENU; } - virtual LLString getWidgetTag() const { return LL_PIE_MENU_TAG; } - void initXML(LLXMLNodePtr node, LLView *context, LLUICtrlFactory *factory); // LLView Functionality // can't set visibility directly, must call show or hide virtual void setVisible(BOOL visible); - //virtual BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent ); virtual BOOL handleHover( S32 x, S32 y, MASK mask ); virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask ); virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); @@ -672,7 +652,6 @@ public: void show(S32 x, S32 y, BOOL mouse_down); void hide(BOOL item_selected); - private: LLMenuItemGL *pieItemFromXY(S32 x, S32 y); S32 pieItemIndexFromXY(S32 x, S32 y); @@ -708,11 +687,8 @@ public: virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_BAR; } - virtual LLString getWidgetTag() const { return LL_MENU_BAR_GL_TAG; } - virtual BOOL handleAcceleratorKey(KEY key, MASK mask); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleJumpKey(KEY key); // rearrange the child rects so they fit the shape of the menu @@ -754,9 +730,6 @@ public: LLMenuHolderGL(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows = FOLLOWS_NONE); virtual ~LLMenuHolderGL() {} - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_HOLDER; } - virtual LLString getWidgetTag() const { return LL_MENU_HOLDER_GL_TAG; } - virtual BOOL hideMenus(); void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); void setCanHide(BOOL can_hide) { mCanHide = can_hide; } @@ -794,7 +767,7 @@ public: virtual void onFocusReceived(); virtual void onFocusLost(); virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent); - virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual void translate(S32 x, S32 y); private: @@ -816,9 +789,6 @@ class LLMenuItemTearOffGL : public LLMenuItemGL public: LLMenuItemTearOffGL( LLHandle parent_floater_handle = LLHandle()); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_TEAROFF_MENU; } - virtual LLString getWidgetTag() const { return LL_MENU_ITEM_TEAR_OFF_GL_TAG; } - virtual LLString getType() const { return "tearoff_menu"; } virtual void doIt(void); diff --git a/linden/indra/llui/llmodaldialog.cpp b/linden/indra/llui/llmodaldialog.cpp index 392c122..160495d 100644 --- a/linden/indra/llui/llmodaldialog.cpp +++ b/linden/indra/llui/llmodaldialog.cpp @@ -211,11 +211,9 @@ BOOL LLModalDialog::handleRightMouseDown(S32 x, S32 y, MASK mask) } -BOOL LLModalDialog::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLModalDialog::handleKeyHere(KEY key, MASK mask ) { - childrenHandleKey(key, mask); - - LLFloater::handleKeyHere(key, mask, called_from_parent ); + LLFloater::handleKeyHere(key, mask ); if (mModal) { @@ -246,33 +244,30 @@ void LLModalDialog::onClose(bool app_quitting) // virtual void LLModalDialog::draw() { - if (getVisible()) - { - LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); - S32 shadow_lines = LLUI::sConfigGroup->getS32("DropShadowFloater"); + LLColor4 shadow_color = LLUI::sColorsGroup->getColor("ColorDropShadow"); + S32 shadow_lines = LLUI::sConfigGroup->getS32("DropShadowFloater"); + + gl_drop_shadow( 0, getRect().getHeight(), getRect().getWidth(), 0, + shadow_color, shadow_lines); - gl_drop_shadow( 0, getRect().getHeight(), getRect().getWidth(), 0, - shadow_color, shadow_lines); + LLFloater::draw(); + + if (mModal) + { + // If we've lost focus to a non-child, get it back ASAP. + if( gFocusMgr.getTopCtrl() != this ) + { + gFocusMgr.setTopCtrl( this ); + } - LLFloater::draw(); + if( !gFocusMgr.childHasKeyboardFocus( this ) ) + { + setFocus(TRUE); + } - if (mModal) + if( !gFocusMgr.childHasMouseCapture( this ) ) { - // If we've lost focus to a non-child, get it back ASAP. - if( gFocusMgr.getTopCtrl() != this ) - { - gFocusMgr.setTopCtrl( this ); - } - - if( !gFocusMgr.childHasKeyboardFocus( this ) ) - { - setFocus(TRUE); - } - - if( !gFocusMgr.childHasMouseCapture( this ) ) - { - gFocusMgr.setMouseCapture( this ); - } + gFocusMgr.setMouseCapture( this ); } } } diff --git a/linden/indra/llui/llmodaldialog.h b/linden/indra/llui/llmodaldialog.h index 0199498..77bd9db 100644 --- a/linden/indra/llui/llmodaldialog.h +++ b/linden/indra/llui/llmodaldialog.h @@ -60,7 +60,7 @@ public: /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); - /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ); + /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask ); /*virtual*/ void onClose(bool app_quitting); diff --git a/linden/indra/llui/llmultislider.cpp b/linden/indra/llui/llmultislider.cpp index d0c9002..dfa36fa 100644 --- a/linden/indra/llui/llmultislider.cpp +++ b/linden/indra/llui/llmultislider.cpp @@ -43,6 +43,8 @@ #include +static LLRegisterWidget r("multi_slider_bar"); + const S32 MULTI_THUMB_WIDTH = 8; const S32 MULTI_TRACK_HEIGHT = 6; const F32 FLOAT_THRESHOLD = 0.00001f; @@ -98,16 +100,6 @@ LLMultiSlider::LLMultiSlider( setValue(getValue()); } -EWidgetType LLMultiSlider::getWidgetType() const -{ - return WIDGET_TYPE_MULTI_SLIDER_BAR; -} - -LLString LLMultiSlider::getWidgetTag() const -{ - return LL_MULTI_SLIDER_TAG; -} - void LLMultiSlider::setSliderValue(const LLString& name, F32 value, BOOL from_event) { // exit if not there @@ -403,31 +395,28 @@ BOOL LLMultiSlider::handleMouseDown(S32 x, S32 y, MASK mask) return TRUE; } -BOOL LLMultiSlider::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLMultiSlider::handleKeyHere(KEY key, MASK mask) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && !called_from_parent ) + switch(key) { - switch(key) - { - case KEY_UP: - case KEY_DOWN: - // eat up and down keys to be consistent - handled = TRUE; - break; - case KEY_LEFT: - setCurSliderValue(getCurSliderValue() - getIncrement()); - onCommit(); - handled = TRUE; - break; - case KEY_RIGHT: - setCurSliderValue(getCurSliderValue() + getIncrement()); - onCommit(); - handled = TRUE; - break; - default: - break; - } + case KEY_UP: + case KEY_DOWN: + // eat up and down keys to be consistent + handled = TRUE; + break; + case KEY_LEFT: + setCurSliderValue(getCurSliderValue() - getIncrement()); + onCommit(); + handled = TRUE; + break; + case KEY_RIGHT: + setCurSliderValue(getCurSliderValue() + getIncrement()); + onCommit(); + handled = TRUE; + break; + default: + break; } return handled; } @@ -438,177 +427,142 @@ void LLMultiSlider::draw() std::map::iterator mIt; std::map::iterator curSldrIt; - if( getVisible() ) - { - // Draw background and thumb. - // drawing solids requires texturing be disabled - LLGLSNoTexture no_texture; + // Draw background and thumb. - LLRect rect(mDragStartThumbRect); + // drawing solids requires texturing be disabled + LLGLSNoTexture no_texture; - F32 opacity = getEnabled() ? 1.f : 0.3f; + LLRect rect(mDragStartThumbRect); - // Track - LLUUID thumb_image_id; - thumb_image_id.set(LLUI::sAssetsGroup->getString("rounded_square.tga")); - LLPointer thumb_imagep(LLUI::sImageProvider->getUIImageByID(thumb_image_id)->getImage()); + F32 opacity = getEnabled() ? 1.f : 0.3f; - S32 height_offset = (getRect().getHeight() - MULTI_TRACK_HEIGHT) / 2; - LLRect track_rect(0, getRect().getHeight() - height_offset, getRect().getWidth(), height_offset ); + // Track + LLUIImagePtr thumb_imagep = LLUI::sImageProvider->getUIImage("rounded_square.tga"); + S32 height_offset = (getRect().getHeight() - MULTI_TRACK_HEIGHT) / 2; + LLRect track_rect(0, getRect().getHeight() - height_offset, getRect().getWidth(), height_offset ); - if(mDrawTrack) - { - track_rect.stretch(-1); - gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 16, 16, track_rect.getWidth(), track_rect.getHeight(), - thumb_imagep, mTrackColor % opacity); - } - // if we're supposed to use a drawn triangle - // simple gl call for the triangle - if(mUseTriangle) { + if(mDrawTrack) + { + track_rect.stretch(-1); + thumb_imagep->draw(track_rect, mTrackColor % opacity); + } - for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { + // if we're supposed to use a drawn triangle + // simple gl call for the triangle + if(mUseTriangle) { - gl_triangle_2d( - mIt->second.mLeft - EXTRA_TRIANGLE_WIDTH, - mIt->second.mTop + EXTRA_TRIANGLE_HEIGHT, - mIt->second.mRight + EXTRA_TRIANGLE_WIDTH, - mIt->second.mTop + EXTRA_TRIANGLE_HEIGHT, - mIt->second.mLeft + mIt->second.getWidth() / 2, - mIt->second.mBottom - EXTRA_TRIANGLE_HEIGHT, - mTriangleColor, TRUE); - } + for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { + + gl_triangle_2d( + mIt->second.mLeft - EXTRA_TRIANGLE_WIDTH, + mIt->second.mTop + EXTRA_TRIANGLE_HEIGHT, + mIt->second.mRight + EXTRA_TRIANGLE_WIDTH, + mIt->second.mTop + EXTRA_TRIANGLE_HEIGHT, + mIt->second.mLeft + mIt->second.getWidth() / 2, + mIt->second.mBottom - EXTRA_TRIANGLE_HEIGHT, + mTriangleColor, TRUE); } - else if (!thumb_imagep) - { - // draw all the thumbs - curSldrIt = mThumbRects.end(); - for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { + } + else if (!thumb_imagep) + { + // draw all the thumbs + curSldrIt = mThumbRects.end(); + for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { + + // choose the color + curThumbColor = mThumbCenterColor; + if(mIt->first == mCurSlider) { - // choose the color - curThumbColor = mThumbCenterColor; - if(mIt->first == mCurSlider) { - - curSldrIt = mIt; - continue; - //curThumbColor = mThumbCenterSelectedColor; - } - - // the draw command - gl_rect_2d(mIt->second, curThumbColor, TRUE); + curSldrIt = mIt; + continue; + //curThumbColor = mThumbCenterSelectedColor; } - // now draw the current slider - if(curSldrIt != mThumbRects.end()) { - gl_rect_2d(curSldrIt->second, mThumbCenterSelectedColor, TRUE); - } + // the draw command + gl_rect_2d(mIt->second, curThumbColor, TRUE); + } - // and draw the drag start - if (gFocusMgr.getMouseCapture() == this) - { - gl_rect_2d(mDragStartThumbRect, mThumbCenterColor % opacity, FALSE); - } + // now draw the current slider + if(curSldrIt != mThumbRects.end()) { + gl_rect_2d(curSldrIt->second, mThumbCenterSelectedColor, TRUE); } - else if( gFocusMgr.getMouseCapture() == this ) + + // and draw the drag start + if (gFocusMgr.getMouseCapture() == this) { - // draw drag start - gl_draw_scaled_image_with_border(mDragStartThumbRect.mLeft, - mDragStartThumbRect.mBottom, 16, 16, - mDragStartThumbRect.getWidth(), - mDragStartThumbRect.getHeight(), - thumb_imagep, mThumbCenterColor % 0.3f, TRUE); - - // draw the highlight - if (hasFocus()) + gl_rect_2d(mDragStartThumbRect, mThumbCenterColor % opacity, FALSE); + } + } + else if( gFocusMgr.getMouseCapture() == this ) + { + // draw drag start + thumb_imagep->drawSolid(mDragStartThumbRect, mThumbCenterColor % 0.3f); + + // draw the highlight + if (hasFocus()) + { + thumb_imagep->drawBorder(mThumbRects[mCurSlider], gFocusMgr.getFocusColor(), gFocusMgr.getFocusFlashWidth()); + } + + // draw the thumbs + curSldrIt = mThumbRects.end(); + for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) + { + // choose the color + curThumbColor = mThumbCenterColor; + if(mIt->first == mCurSlider) { - F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); - LLRect highlight_rect = mThumbRects[mCurSlider]; - highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); - gl_draw_scaled_image_with_border(highlight_rect.mLeft, - highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), - highlight_rect.getHeight(), - thumb_imagep, gFocusMgr.getFocusColor()); + // don't draw now, draw last + curSldrIt = mIt; + continue; } + + // the draw command + thumb_imagep->drawSolid(mIt->second, curThumbColor); + } + + // draw cur slider last + if(curSldrIt != mThumbRects.end()) + { + thumb_imagep->drawSolid(curSldrIt->second, mThumbCenterSelectedColor); + } + + } + else + { + // draw highlight + if (hasFocus()) + { + thumb_imagep->drawBorder(mThumbRects[mCurSlider], gFocusMgr.getFocusColor(), gFocusMgr.getFocusFlashWidth()); + } - // draw the thumbs - curSldrIt = mThumbRects.end(); - for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { - - // choose the color - curThumbColor = mThumbCenterColor; - if(mIt->first == mCurSlider) { - // don't draw now, draw last - curSldrIt = mIt; - continue; - } - - // the draw command - gl_draw_scaled_image_with_border( - mIt->second.mLeft, - mIt->second.mBottom, 16, 16, - mIt->second.getWidth(), - mIt->second.getHeight(), thumb_imagep, - curThumbColor, TRUE); - } + // draw thumbs + curSldrIt = mThumbRects.end(); + for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) + { - // draw cur slider last - if(curSldrIt != mThumbRects.end()) { - gl_draw_scaled_image_with_border( - curSldrIt->second.mLeft, - curSldrIt->second.mBottom, 16, 16, - curSldrIt->second.getWidth(), - curSldrIt->second.getHeight(), thumb_imagep, - mThumbCenterSelectedColor, TRUE); - } + // choose the color + curThumbColor = mThumbCenterColor; + if(mIt->first == mCurSlider) + { + curSldrIt = mIt; + continue; + //curThumbColor = mThumbCenterSelectedColor; + } + thumb_imagep->drawSolid(mIt->second, curThumbColor % opacity); } - else - { - // draw highlight - if (hasFocus()) - { - F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); - LLRect highlight_rect = mThumbRects[mCurSlider]; - highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); - gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), - thumb_imagep, gFocusMgr.getFocusColor()); - } - // draw thumbs - curSldrIt = mThumbRects.end(); - for(mIt = mThumbRects.begin(); mIt != mThumbRects.end(); mIt++) { - - // choose the color - curThumbColor = mThumbCenterColor; - if(mIt->first == mCurSlider) { - curSldrIt = mIt; - continue; - //curThumbColor = mThumbCenterSelectedColor; - } - - // the draw command - gl_draw_scaled_image_with_border( - mIt->second.mLeft, - mIt->second.mBottom, 16, 16, - mIt->second.getWidth(), - mIt->second.getHeight(), thumb_imagep, - curThumbColor % opacity, TRUE); - } - - if(curSldrIt != mThumbRects.end()) { - gl_draw_scaled_image_with_border( - curSldrIt->second.mLeft, - curSldrIt->second.mBottom, 16, 16, - curSldrIt->second.getWidth(), - curSldrIt->second.getHeight(), thumb_imagep, - mThumbCenterSelectedColor % opacity, TRUE); - } + if(curSldrIt != mThumbRects.end()) + { + thumb_imagep->drawSolid(curSldrIt->second, mThumbCenterSelectedColor % opacity); } - - LLUICtrl::draw(); } + + LLUICtrl::draw(); } // virtual diff --git a/linden/indra/llui/llmultislider.h b/linden/indra/llui/llmultislider.h index 7cd5061..df6153a 100644 --- a/linden/indra/llui/llmultislider.h +++ b/linden/indra/llui/llmultislider.h @@ -55,8 +55,6 @@ public: BOOL use_triangle, const LLString& control_name = LLString::null ); - virtual EWidgetType getWidgetType() const; - virtual LLString getWidgetTag() const; virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); @@ -94,7 +92,7 @@ public: virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual void draw(); protected: diff --git a/linden/indra/llui/llmultisliderctrl.cpp b/linden/indra/llui/llmultisliderctrl.cpp index 47e21d8..c242d18 100644 --- a/linden/indra/llui/llmultisliderctrl.cpp +++ b/linden/indra/llui/llmultisliderctrl.cpp @@ -50,6 +50,8 @@ #include "llfocusmgr.h" #include "llresmgr.h" +static LLRegisterWidget r("multi_slider"); + const U32 MAX_STRING_LENGTH = 10; diff --git a/linden/indra/llui/llmultisliderctrl.h b/linden/indra/llui/llmultisliderctrl.h index 5e2d13c..6a298c8 100644 --- a/linden/indra/llui/llmultisliderctrl.h +++ b/linden/indra/llui/llmultisliderctrl.h @@ -71,8 +71,6 @@ public: const LLString& control_which = LLString::null ); virtual ~LLMultiSliderCtrl(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MULTI_SLIDER; } - virtual LLString getWidgetTag() const { return LL_MULTI_SLIDER_CTRL_TAG; } virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); diff --git a/linden/indra/llui/llpanel.cpp b/linden/indra/llui/llpanel.cpp index 567d29e..7db3725 100644 --- a/linden/indra/llui/llpanel.cpp +++ b/linden/indra/llui/llpanel.cpp @@ -65,6 +65,8 @@ LLPanel::alert_queue_t LLPanel::sAlertQueue; const S32 RESIZE_BAR_OVERLAP = 1; const S32 RESIZE_BAR_HEIGHT = 3; +static LLRegisterWidget r1("panel"); + void LLPanel::init() { // mRectControl @@ -126,18 +128,6 @@ LLPanel::~LLPanel() } // virtual -EWidgetType LLPanel::getWidgetType() const -{ - return WIDGET_TYPE_PANEL; -} - -// virtual -LLString LLPanel::getWidgetTag() const -{ - return LL_PANEL_TAG; -} - -// virtual BOOL LLPanel::isPanel() const { return TRUE; @@ -227,7 +217,8 @@ void LLPanel::updateDefaultBtn() if (gFocusMgr.childHasKeyboardFocus( this ) && mDefaultBtn->getEnabled()) { LLUICtrl* focus_ctrl = gFocusMgr.getKeyboardFocus(); - BOOL focus_is_child_button = focus_ctrl->getWidgetType() == WIDGET_TYPE_BUTTON && static_cast(focus_ctrl)->getCommitOnReturn(); + LLButton* buttonp = dynamic_cast(focus_ctrl); + 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); } @@ -259,7 +250,7 @@ void LLPanel::setDefaultBtn(LLButton* btn) void LLPanel::setDefaultBtn(const LLString& id) { - LLButton *button = LLUICtrlFactory::getButtonByName(this, id); + LLButton *button = getChild(id); if (button) { setDefaultBtn(button); @@ -270,77 +261,6 @@ void LLPanel::setDefaultBtn(const LLString& id) } } -BOOL LLPanel::handleKey(KEY key, MASK mask, BOOL called_from_parent) -{ - BOOL handled = FALSE; - if (getVisible() && getEnabled()) - { - if( (mask == MASK_SHIFT) && (KEY_TAB == key)) - { - //SHIFT-TAB - LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); - if (cur_focus && gFocusMgr.childHasKeyboardFocus(this)) - { - LLUICtrl* focus_root = cur_focus; - while(cur_focus->getParentUICtrl()) - { - cur_focus = cur_focus->getParentUICtrl(); - if (cur_focus->isFocusRoot()) - { - // this is the root-most focus root found so far - focus_root = cur_focus; - } - } - handled = focus_root->focusPrevItem(FALSE); - } - else if (!cur_focus && isFocusRoot()) - { - handled = focusLastItem(); - if (!handled) - { - setFocus(TRUE); - handled = TRUE; - } - } - } - else - if( (mask == MASK_NONE ) && (KEY_TAB == key)) - { - //TAB - LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); - if (cur_focus && gFocusMgr.childHasKeyboardFocus(this)) - { - LLUICtrl* focus_root = cur_focus; - while(cur_focus->getParentUICtrl()) - { - cur_focus = cur_focus->getParentUICtrl(); - if (cur_focus->isFocusRoot()) - { - focus_root = cur_focus; - } - } - handled = focus_root->focusNextItem(FALSE); - } - else if (!cur_focus && isFocusRoot()) - { - handled = focusFirstItem(); - if (!handled) - { - setFocus(TRUE); - handled = TRUE; - } - } - } - } - - if (!handled) - { - handled = LLView::handleKey(key, mask, called_from_parent); - } - - return handled; -} - void LLPanel::addCtrl( LLUICtrl* ctrl, S32 tab_group) { mLastTabGroup = tab_group; @@ -355,83 +275,90 @@ void LLPanel::addCtrlAtEnd( LLUICtrl* ctrl, S32 tab_group) LLView::addCtrlAtEnd(ctrl, tab_group); } -BOOL LLPanel::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLPanel::handleKeyHere( KEY key, MASK mask ) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && - gFocusMgr.childHasKeyboardFocus(this) && !called_from_parent ) - { - // handle user hitting ESC to defocus - if (key == KEY_ESCAPE) - { - gFocusMgr.setKeyboardFocus(NULL); - return TRUE; - } + LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); - LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus(); - // If we have a default button, click it when - // return is pressed, unless current focus is a return-capturing button - // in which case *that* button will handle the return key - if (cur_focus && !(cur_focus->getWidgetType() == WIDGET_TYPE_BUTTON && static_cast(cur_focus)->getCommitOnReturn())) + // handle user hitting ESC to defocus + if (key == KEY_ESCAPE) + { + gFocusMgr.setKeyboardFocus(NULL); + return TRUE; + } + else if( (mask == MASK_SHIFT) && (KEY_TAB == key)) + { + //SHIFT-TAB + if (cur_focus) { - // RETURN key means hit default button in this case - if (key == KEY_RETURN && mask == MASK_NONE - && mDefaultBtn != NULL - && mDefaultBtn->getVisible() - && mDefaultBtn->getEnabled()) + LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot(); + if (focus_root) { - mDefaultBtn->onCommit(); - handled = TRUE; + handled = focus_root->focusPrevItem(FALSE); } } - - if (key == KEY_RETURN && mask == MASK_NONE) + } + else if( (mask == MASK_NONE ) && (KEY_TAB == key)) + { + //TAB + if (cur_focus) { - // set keyboard focus to self to trigger commitOnFocusLost behavior on current ctrl - if (cur_focus && cur_focus->acceptsTextInput()) + LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot(); + if (focus_root) { - cur_focus->onCommit(); - handled = TRUE; + handled = focus_root->focusNextItem(FALSE); } } } - return handled; -} - -void LLPanel::requires(LLString name, EWidgetType type) -{ - mRequirements[name] = type; -} - -BOOL LLPanel::checkRequirements() const -{ - BOOL retval = TRUE; - LLString message; + // If we have a default button, click it when + // return is pressed, unless current focus is a return-capturing button + // in which case *that* button will handle the return key + LLButton* focused_button = dynamic_cast(cur_focus); + if (cur_focus && !(focused_button && focused_button->getCommitOnReturn())) + { + // RETURN key means hit default button in this case + if (key == KEY_RETURN && mask == MASK_NONE + && mDefaultBtn != NULL + && mDefaultBtn->getVisible() + && mDefaultBtn->getEnabled()) + { + mDefaultBtn->onCommit(); + handled = TRUE; + } + } - for (requirements_map_t::const_iterator i = mRequirements.begin(); i != mRequirements.end(); ++i) + if (key == KEY_RETURN && mask == MASK_NONE) { - if (!this->getCtrlByNameAndType(i->first, i->second)) + // set keyboard focus to self to trigger commitOnFocusLost behavior on current ctrl + if (cur_focus && cur_focus->acceptsTextInput()) { - retval = FALSE; - message += i->first + " " + LLUICtrlFactory::getWidgetType(i->second) + "\n"; + cur_focus->onCommit(); + handled = TRUE; } } - if (!retval) + return handled; +} + +BOOL LLPanel::checkRequirements() +{ + if (!mRequirementsError.empty()) { LLString::format_map_t args; - args["[COMPONENTS]"] = message; + args["[COMPONENTS]"] = mRequirementsError; args["[FLOATER]"] = getName(); llwarns << getName() << " failed requirements check on: \n" - << message << llendl; + << mRequirementsError << llendl; alertXml("FailedRequirementsCheck", args); + mRequirementsError.clear(); + return FALSE; } - return retval; + return TRUE; } //static @@ -494,30 +421,6 @@ void LLPanel::setBorderVisible(BOOL b) } } -LLUICtrl* LLPanel::getCtrlByNameAndType(const LLString& name, EWidgetType type) const -{ - LLView* view = getChildByName(name, TRUE); - if (view && view->isCtrl()) - { - if (type == WIDGET_TYPE_DONTCARE || view->getWidgetType() == type) - { - return (LLUICtrl*)view; - } - else - { - llwarns << "Widget " << name << " has improper type in panel " << getName() << "\n" - << "Is: \t\t" << view->getWidgetType() << "\n" - << "Should be: \t" << type - << llendl; - } - } - else - { - childNotFound(name); - } - return NULL; -} - // virtual LLXMLNodePtr LLPanel::getXML(bool save_children) const { @@ -973,7 +876,7 @@ BOOL LLPanel::childSetLabelArg(const LLString& id, const LLString& key, const LL BOOL LLPanel::childSetToolTipArg(const LLString& id, const LLString& key, const LLStringExplicit& text) { - LLView* child = getChildByName(id, true); + LLView* child = getChildView(id, true, FALSE); if (child) { return child->setToolTipArg(key, text); @@ -1001,7 +904,7 @@ void LLPanel::childSetMaxValue(const LLString& id, LLSD max_value) void LLPanel::childShowTab(const LLString& id, const LLString& tabname, bool visible) { - LLTabContainer* child = LLUICtrlFactory::getTabContainerByName(this, id); + LLTabContainer* child = getChild(id); if (child) { child->selectTabByName(tabname); @@ -1010,7 +913,7 @@ void LLPanel::childShowTab(const LLString& id, const LLString& tabname, bool vis LLPanel *LLPanel::childGetVisibleTab(const LLString& id) const { - LLTabContainer* child = LLUICtrlFactory::getTabContainerByName(this, id); + LLTabContainer* child = getChild(id); if (child) { return child->getCurrentPanel(); @@ -1020,7 +923,7 @@ LLPanel *LLPanel::childGetVisibleTab(const LLString& id) const void LLPanel::childSetTabChangeCallback(const LLString& id, const LLString& tabname, void (*on_tab_clicked)(void*, bool), void *userdata) { - LLTabContainer* child = LLUICtrlFactory::getTabContainerByName(this, id); + LLTabContainer* child = getChild(id); if (child) { LLPanel *panel = child->getPanelByName(tabname); @@ -1034,7 +937,7 @@ void LLPanel::childSetTabChangeCallback(const LLString& id, const LLString& tabn void LLPanel::childSetKeystrokeCallback(const LLString& id, void (*keystroke_callback)(LLLineEditor* caller, void* user_data), void *user_data) { - LLLineEditor* child = LLUICtrlFactory::getLineEditorByName(this, id); + LLLineEditor* child = getChild(id); if (child) { child->setKeystrokeCallback(keystroke_callback); @@ -1047,7 +950,7 @@ void LLPanel::childSetKeystrokeCallback(const LLString& id, void (*keystroke_cal void LLPanel::childSetPrevalidate(const LLString& id, BOOL (*func)(const LLWString &) ) { - LLLineEditor* child = LLUICtrlFactory::getLineEditorByName(this, id); + LLLineEditor* child = getChild(id); if (child) { child->setPrevalidate(func); @@ -1056,7 +959,7 @@ void LLPanel::childSetPrevalidate(const LLString& id, BOOL (*func)(const LLWStri void LLPanel::childSetWrappedText(const LLString& id, const LLString& text, bool visible) { - LLTextBox* child = (LLTextBox*)getCtrlByNameAndType(id, WIDGET_TYPE_TEXT_BOX); + LLTextBox* child = getChild(id); if (child) { child->setVisible(visible); @@ -1066,7 +969,7 @@ void LLPanel::childSetWrappedText(const LLString& id, const LLString& text, bool void LLPanel::childSetAction(const LLString& id, void(*function)(void*), void* value) { - LLButton* button = (LLButton*)getCtrlByNameAndType(id, WIDGET_TYPE_BUTTON); + LLButton* button = getChild(id); if (button) { button->setClickedCallback(function, value); @@ -1075,7 +978,7 @@ void LLPanel::childSetAction(const LLString& id, void(*function)(void*), void* v void LLPanel::childSetActionTextbox(const LLString& id, void(*function)(void*)) { - LLTextBox* textbox = (LLTextBox*)getCtrlByNameAndType(id, WIDGET_TYPE_TEXT_BOX); + LLTextBox* textbox = getChild(id); if (textbox) { textbox->setClickedCallback(function); @@ -1092,13 +995,18 @@ void LLPanel::childSetControlName(const LLString& id, const LLString& control_na } //virtual -LLView* LLPanel::getChildByName(const LLString& name, BOOL recurse) const +LLView* LLPanel::getChildView(const LLString& name, BOOL recurse, BOOL create_if_missing) const { - LLView* view = LLUICtrl::getChildByName(name, recurse); + // just get child, don't try to create a dummy one + LLView* view = LLUICtrl::getChildView(name, recurse, FALSE); if (!view && !recurse) { childNotFound(name); } + if (!view && create_if_missing) + { + view = createDummyWidget(name); + } return view; } @@ -1191,6 +1099,8 @@ struct LLLayoutStack::LLEmbeddedPanel F32 mVisibleAmt; }; +static LLRegisterWidget r2("layout_stack"); + LLLayoutStack::LLLayoutStack(eLayoutOrientation orientation) : mOrientation(orientation), mMinWidth(0), @@ -1204,19 +1114,6 @@ LLLayoutStack::~LLLayoutStack() std::for_each(mPanels.begin(), mPanels.end(), DeletePointer()); } -// virtual -EWidgetType LLLayoutStack::getWidgetType() const -{ - return WIDGET_TYPE_LAYOUT_STACK; -} - -// virtual -LLString LLLayoutStack::getWidgetTag() const -{ - return LL_LAYOUT_STACK_TAG; -} - - void LLLayoutStack::draw() { updateLayout(); @@ -1304,18 +1201,18 @@ LLView* LLLayoutStack::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactor LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { + S32 min_width = 0; + S32 min_height = 0; + BOOL auto_resize = TRUE; + + child->getAttributeS32("min_width", min_width); + child->getAttributeS32("min_height", min_height); + child->getAttributeBOOL("auto_resize", auto_resize); + if (child->hasName("layout_panel")) { - S32 min_width = 0; - S32 min_height = 0; - BOOL auto_resize = TRUE; BOOL user_resize = TRUE; - - child->getAttributeS32("min_width", min_width); - child->getAttributeS32("min_height", min_height); - child->getAttributeBOOL("auto_resize", auto_resize); child->getAttributeBOOL("user_resize", user_resize); - LLPanel* panelp = (LLPanel*)LLPanel::fromXML(child, layout_stackp, factory); if (panelp) { @@ -1323,6 +1220,26 @@ LLView* LLLayoutStack::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactor layout_stackp->addPanel(panelp, min_width, min_height, auto_resize, user_resize); } } + else + { + BOOL user_resize = FALSE; + child->getAttributeBOOL("user_resize", user_resize); + + LLPanel* panelp = new LLPanel("auto_panel"); + LLView* new_child = factory->createWidget(panelp, child); + if (new_child) + { + // put child in new embedded panel + layout_stackp->addPanel(panelp, min_width, min_height, auto_resize, user_resize); + // resize panel to contain widget and move widget to be contained in panel + panelp->setRect(new_child->getRect()); + new_child->setOrigin(0, 0); + } + else + { + panelp->die(); + } + } } layout_stackp->updateLayout(); @@ -1411,6 +1328,11 @@ void LLLayoutStack::updateLayout(BOOL force_resize) if (mOrientation == HORIZONTAL) { + // enforce minimize size constraint by default + if (panelp->getRect().getWidth() < (*panel_it)->mMinWidth) + { + panelp->reshape((*panel_it)->mMinWidth, panelp->getRect().getHeight()); + } total_width += llround(panelp->getRect().getWidth() * (*panel_it)->mVisibleAmt); // want n-1 panel gaps for n panels if (panel_it != mPanels.begin()) @@ -1420,6 +1342,11 @@ void LLLayoutStack::updateLayout(BOOL force_resize) } else //VERTICAL { + // enforce minimize size constraint by default + if (panelp->getRect().getHeight() < (*panel_it)->mMinHeight) + { + panelp->reshape(panelp->getRect().getWidth(), (*panel_it)->mMinHeight); + } total_height += llround(panelp->getRect().getHeight() * (*panel_it)->mVisibleAmt); if (panel_it != mPanels.begin()) { @@ -1438,6 +1365,7 @@ void LLLayoutStack::updateLayout(BOOL force_resize) { continue; } + // if currently resizing a panel or the panel is flagged as not automatically resizing // only track total available headroom, but don't use it for automatic resize logic if ((*panel_it)->mResizeBar->hasMouseCapture() @@ -1469,6 +1397,7 @@ void LLLayoutStack::updateLayout(BOOL force_resize) } } + // calculate how many pixels need to be distributed among layout panels // positive means panels need to grow, negative means shrink S32 pixels_to_distribute; if (mOrientation == HORIZONTAL) @@ -1480,6 +1409,7 @@ void LLLayoutStack::updateLayout(BOOL force_resize) pixels_to_distribute = getRect().getHeight() - total_height; } + // now we distribute the pixels... S32 cur_x = 0; S32 cur_y = getRect().getHeight(); @@ -1505,13 +1435,17 @@ void LLLayoutStack::updateLayout(BOOL force_resize) if (pixels_to_distribute < 0) { // shrink proportionally to amount over minimum - delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * (F32)(cur_width - (*panel_it)->mMinWidth) / (F32)shrink_headroom_available) : 0; + // so we can do this in one pass + delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_width - (*panel_it)->mMinWidth) / (F32)shrink_headroom_available)) : 0; + shrink_headroom_available -= (cur_width - (*panel_it)->mMinWidth); } else { // grow all elements equally delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels); + num_resizable_panels--; } + pixels_to_distribute -= delta_size; new_width = llmax((*panel_it)->mMinWidth, cur_width + delta_size); } else @@ -1524,12 +1458,16 @@ void LLLayoutStack::updateLayout(BOOL force_resize) if (pixels_to_distribute < 0) { // shrink proportionally to amount over minimum - delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * (F32)(cur_height - (*panel_it)->mMinHeight) / (F32)shrink_headroom_available) : 0; + // so we can do this in one pass + delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_height - (*panel_it)->mMinHeight) / (F32)shrink_headroom_available)) : 0; + shrink_headroom_available -= (cur_height - (*panel_it)->mMinHeight); } else { delta_size = llround((F32)pixels_to_distribute / (F32)num_resizable_panels); + num_resizable_panels--; } + pixels_to_distribute -= delta_size; new_height = llmax((*panel_it)->mMinHeight, cur_height + delta_size); } else diff --git a/linden/indra/llui/llpanel.h b/linden/indra/llui/llpanel.h index e0f48ca..c7627ff 100644 --- a/linden/indra/llui/llpanel.h +++ b/linden/indra/llui/llpanel.h @@ -82,13 +82,12 @@ public: /*virtual*/ ~LLPanel(); // LLView interface - /*virtual*/ EWidgetType getWidgetType() const; - /*virtual*/ LLString getWidgetTag() const; /*virtual*/ BOOL isPanel() const; /*virtual*/ void draw(); - /*virtual*/ BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent ); - /*virtual*/ BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent ); + /*virtual*/ BOOL handleKeyHere( KEY key, MASK mask ); /*virtual*/ LLXMLNodePtr getXML(bool save_children = true) const; + // Override to set not found list: + virtual LLView* getChildView(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; // From LLFocusableElement /*virtual*/ void setFocus( BOOL b ); @@ -106,8 +105,21 @@ public: BOOL hasBorder() const { return mBorder != NULL; } void setBorderVisible( BOOL b ); - void requires(LLString name, EWidgetType type = WIDGET_TYPE_DONTCARE); - BOOL checkRequirements() const; + template void requires(LLString name) + { + // check for widget with matching type and name + if (LLView::getChild(name) == NULL) + { + mRequirementsError += name + "\n"; + } + } + + // requires LLView by default + void requires(LLString name) + { + requires(name); + } + BOOL checkRequirements(); void setBackgroundColor( const LLColor4& color ) { mBgColorOpaque = color; } const LLColor4& getBackgroundColor() const { return mBgColorOpaque; } @@ -133,8 +145,6 @@ public: S32 getLastTabGroup() const { return mLastTabGroup; } - LLUICtrl* getCtrlByNameAndType(const LLString& name, EWidgetType type) const; - const LLCallbackMap::map_t& getFactoryMap() const { return mFactoryMap; } BOOL initPanelXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); @@ -226,9 +236,6 @@ protected: LLButton* getDefaultButton() { return mDefaultBtn; } LLCallbackMap::map_t mFactoryMap; - // Override to set not found list: - virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const; - private: // common construction logic void init(); @@ -257,8 +264,7 @@ private: typedef std::map ui_string_map_t; ui_string_map_t mUIStrings; - typedef std::map requirements_map_t; - requirements_map_t mRequirements; + LLString mRequirementsError; typedef std::queue alert_queue_t; static alert_queue_t sAlertQueue; @@ -281,9 +287,6 @@ public: /*virtual*/ LLXMLNodePtr getXML(bool save_children = true) const; /*virtual*/ void removeCtrl(LLUICtrl* ctrl); - virtual EWidgetType getWidgetType() const; - virtual LLString getWidgetTag() const; - static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); S32 getMinWidth() const { return mMinWidth; } @@ -291,16 +294,17 @@ public: void addPanel(LLPanel* panel, S32 min_width, S32 min_height, BOOL auto_resize, BOOL user_resize, S32 index = S32_MAX); void removePanel(LLPanel* panel); - void updateLayout(BOOL force_resize = FALSE); private: + struct LLEmbeddedPanel; + + void updateLayout(BOOL force_resize = FALSE); void calcMinExtents(); S32 getDefaultHeight(S32 cur_height); S32 getDefaultWidth(S32 cur_width); const eLayoutOrientation mOrientation; - struct LLEmbeddedPanel; typedef std::vector e_panel_list_t; e_panel_list_t mPanels; LLEmbeddedPanel* findEmbeddedPanel(LLPanel* panelp) const; diff --git a/linden/indra/llui/llradiogroup.cpp b/linden/indra/llui/llradiogroup.cpp index 039fe81..d7373f1 100644 --- a/linden/indra/llui/llradiogroup.cpp +++ b/linden/indra/llui/llradiogroup.cpp @@ -42,6 +42,7 @@ #include "llui.h" #include "llfocusmgr.h" +static LLRegisterWidget r("radio_group"); LLRadioGroup::LLRadioGroup(const LLString& name, const LLRect& rect, const LLString& control_name, @@ -161,11 +162,11 @@ BOOL LLRadioGroup::setSelectedIndex(S32 index, BOOL from_event) return TRUE; } -BOOL LLRadioGroup::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLRadioGroup::handleKeyHere(KEY key, MASK mask) { BOOL handled = FALSE; // do any of the tab buttons have keyboard focus? - if (getEnabled() && !called_from_parent && mask == MASK_NONE) + if (mask == MASK_NONE) { switch(key) { diff --git a/linden/indra/llui/llradiogroup.h b/linden/indra/llui/llradiogroup.h index 87591a4..e208b79 100644 --- a/linden/indra/llui/llradiogroup.h +++ b/linden/indra/llui/llradiogroup.h @@ -82,10 +82,8 @@ public: BOOL border = TRUE); virtual ~LLRadioGroup(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_RADIO_GROUP; } - virtual LLString getWidgetTag() const { return LL_RADIO_GROUP_TAG; } - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual void setEnabled(BOOL enabled); virtual LLXMLNodePtr getXML(bool save_children = true) const; diff --git a/linden/indra/llui/llresizebar.cpp b/linden/indra/llui/llresizebar.cpp index b4933bd..e89bfee 100644 --- a/linden/indra/llui/llresizebar.cpp +++ b/linden/indra/llui/llresizebar.cpp @@ -85,16 +85,13 @@ LLResizeBar::LLResizeBar( const LLString& name, LLView* resizing_view, const LLR BOOL LLResizeBar::handleMouseDown(S32 x, S32 y, MASK mask) { - if( getEnabled() ) - { - // Route future Mouse messages here preemptively. (Release on mouse up.) - // No handler needed for focus lost since this clas has no state that depends on it. - gFocusMgr.setMouseCapture( this ); + // Route future Mouse messages here preemptively. (Release on mouse up.) + // No handler needed for focus lost since this clas has no state that depends on it. + gFocusMgr.setMouseCapture( this ); - localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY); - mLastMouseScreenX = mDragLastScreenX; - mLastMouseScreenY = mDragLastScreenY; - } + localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY); + mLastMouseScreenX = mDragLastScreenX; + mLastMouseScreenY = mDragLastScreenY; return TRUE; } diff --git a/linden/indra/llui/llresizebar.h b/linden/indra/llui/llresizebar.h index 5446811..d03dafa 100644 --- a/linden/indra/llui/llresizebar.h +++ b/linden/indra/llui/llresizebar.h @@ -42,9 +42,6 @@ public: LLResizeBar(const LLString& name, LLView* resizing_view, const LLRect& rect, S32 min_size, S32 max_size, Side side ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_RESIZE_BAR; } - virtual LLString getWidgetTag() const { return LL_RESIZE_BAR_TAG; } - // virtual void draw(); No appearance virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); diff --git a/linden/indra/llui/llresizehandle.cpp b/linden/indra/llui/llresizehandle.cpp index d3e066b..3aa968f 100644 --- a/linden/indra/llui/llresizehandle.cpp +++ b/linden/indra/llui/llresizehandle.cpp @@ -59,8 +59,7 @@ LLResizeHandle::LLResizeHandle( const LLString& name, const LLRect& rect, S32 mi if( RIGHT_BOTTOM == mCorner) { - LLUUID image_id(LLUI::sConfigGroup->getString("UIImgResizeBottomRightUUID")); - mImage = LLUI::sImageProvider->getImageByID(image_id); + mImage = LLUI::sImageProvider->getUIImage("UIImgResizeBottomRightUUID"); } switch( mCorner ) @@ -78,19 +77,16 @@ LLResizeHandle::LLResizeHandle( const LLString& name, const LLRect& rect, S32 mi BOOL LLResizeHandle::handleMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = FALSE; - if( getVisible() && pointInHandle(x, y) ) + if( pointInHandle(x, y) ) { handled = TRUE; - if( getEnabled() ) - { - // Route future Mouse messages here preemptively. (Release on mouse up.) - // No handler needed for focus lost since this clas has no state that depends on it. - gFocusMgr.setMouseCapture( this ); + // Route future Mouse messages here preemptively. (Release on mouse up.) + // No handler needed for focus lost since this clas has no state that depends on it. + gFocusMgr.setMouseCapture( this ); - localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY); - mLastMouseScreenX = mDragLastScreenX; - mLastMouseScreenY = mDragLastScreenY; - } + localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY); + mLastMouseScreenX = mDragLastScreenX; + mLastMouseScreenY = mDragLastScreenY; } return handled; @@ -107,8 +103,7 @@ BOOL LLResizeHandle::handleMouseUp(S32 x, S32 y, MASK mask) gFocusMgr.setMouseCapture( NULL ); handled = TRUE; } - else - if( getVisible() && pointInHandle(x, y) ) + else if( pointInHandle(x, y) ) { handled = TRUE; } @@ -284,7 +279,7 @@ BOOL LLResizeHandle::handleHover(S32 x, S32 y, MASK mask) } else // don't have mouse capture { - if( getVisible() && pointInHandle( x, y ) ) + if( pointInHandle( x, y ) ) { handled = TRUE; } @@ -314,7 +309,7 @@ void LLResizeHandle::draw() { if( mImage.notNull() && getVisible() && (RIGHT_BOTTOM == mCorner) ) { - gl_draw_image( 0, 0, mImage ); + mImage->draw(0, 0); } } diff --git a/linden/indra/llui/llresizehandle.h b/linden/indra/llui/llresizehandle.h index 77ebcb9..5302612 100644 --- a/linden/indra/llui/llresizehandle.h +++ b/linden/indra/llui/llresizehandle.h @@ -46,9 +46,6 @@ public: LLResizeHandle(const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, ECorner corner = RIGHT_BOTTOM ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_RESIZE_HANDLE; } - virtual LLString getWidgetTag() const { return LL_RESIZE_HANDLE_TAG; } - virtual void draw(); virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); @@ -64,7 +61,7 @@ private: S32 mLastMouseScreenX; S32 mLastMouseScreenY; LLCoordGL mLastMouseDir; - LLPointer mImage; + LLPointer mImage; S32 mMinWidth; S32 mMinHeight; const ECorner mCorner; diff --git a/linden/indra/llui/llresmgr.cpp b/linden/indra/llui/llresmgr.cpp index 83ad440..b5b9174 100644 --- a/linden/indra/llui/llresmgr.cpp +++ b/linden/indra/llui/llresmgr.cpp @@ -39,8 +39,6 @@ #include "llerror.h" #include "llstring.h" -// Global singleton -LLResMgr* gResMgr = NULL; LLResMgr::LLResMgr() { diff --git a/linden/indra/llui/llresmgr.h b/linden/indra/llui/llresmgr.h index 810d386..f9ec115 100644 --- a/linden/indra/llui/llresmgr.h +++ b/linden/indra/llui/llresmgr.h @@ -36,6 +36,7 @@ #include "locale.h" #include "stdtypes.h" #include "llstring.h" +#include "llmemory.h" enum LLLOCALE_ID { @@ -44,67 +45,6 @@ enum LLLOCALE_ID LLLOCALE_COUNT // Number of values in this enum. Keep at end. }; -/* -enum LLSTR_ID -{ - LLSTR_HELLO, - LLSTR_GOODBYE, - LLSTR_CHAT_LABEL, - LLSTR_STATUS_LABEL, - LLSTR_X, - LLSTR_Y, - LLSTR_Z, - LLSTR_POSITION, - LLSTR_SCALE, - LLSTR_ROTATION, - LLSTR_HAS_PHYSICS, - LLSTR_SCRIPT, - LLSTR_HELP, - LLSTR_REMOVE, - LLSTR_CLEAR, - LLSTR_APPLY, - LLSTR_CANCEL, - LLSTR_MATERIAL, - LLSTR_FACE, - LLSTR_TEXTURE, - LLSTR_TEXTURE_SIZE, - LLSTR_TEXTURE_OFFSET, - LLSTR_TEXTURE_ROTATION, - LLSTR_U, - LLSTR_V, - LLSTR_OWNERSHIP, - LLSTR_PUBLIC, - LLSTR_PRIVATE, - LLSTR_REVERT, - LLSTR_INSERT_SAMPLE, - LLSTR_SET_TEXTURE, - LLSTR_EDIT_SCRIPT, - LLSTR_MOUSELOOK_INSTRUCTIONS, - LLSTR_EDIT_FACE_INSTRUCTIONS, - LLSTR_CLOSE, - LLSTR_MOVE, - LLSTR_ROTATE, - LLSTR_RESIZE, - LLSTR_PLACE_BOX, - LLSTR_PLACE_PRISM, - LLSTR_PLACE_PYRAMID, - LLSTR_PLACE_TETRAHEDRON, - LLSTR_PLACE_CYLINDER, - LLSTR_PLACE_HALF_CYLINDER, - LLSTR_PLACE_CONE, - LLSTR_PLACE_HALF_CONE, - LLSTR_PLACE_SPHERE, - LLSTR_PLACE_HALF_SPHERE, - LLSTR_PLACE_BIRD, - LLSTR_PLACE_SNAKE, - LLSTR_PLACE_ROCK, - LLSTR_PLACE_TREE, - LLSTR_PLACE_GRASS, - LLSTR_MODIFY_LAND, - LLSTR_COUNT // Number of values in this enum. Keep at end. -}; -*/ - enum LLFONT_ID { LLFONT_OCRA, @@ -117,7 +57,7 @@ enum LLFONT_ID class LLFontGL; -class LLResMgr +class LLResMgr : public LLSingleton { public: LLResMgr(); @@ -162,6 +102,4 @@ private: LLString mPrevLocaleString; }; -extern LLResMgr* gResMgr; - #endif // LL_RESMGR_ diff --git a/linden/indra/llui/llrootview.h b/linden/indra/llui/llrootview.h index 5f130b9..f4c047c 100644 --- a/linden/indra/llui/llrootview.h +++ b/linden/indra/llui/llrootview.h @@ -38,9 +38,6 @@ class LLRootView : public LLView { public: LLRootView(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows=FOLLOWS_NONE); - - /*virtual*/ EWidgetType getWidgetType() const { return WIDGET_TYPE_ROOT_VIEW; } - /*virtual*/ LLString getWidgetTag() const { return LL_ROOT_VIEW_TAG; } }; #endif diff --git a/linden/indra/llui/llscrollbar.cpp b/linden/indra/llui/llscrollbar.cpp index cf64742..cdabda0 100644 --- a/linden/indra/llui/llscrollbar.cpp +++ b/linden/indra/llui/llscrollbar.cpp @@ -414,17 +414,8 @@ BOOL LLScrollbar::handleHover(S32 x, S32 y, MASK mask) BOOL LLScrollbar::handleScrollWheel(S32 x, S32 y, S32 clicks) { - BOOL handled = FALSE; - if( getVisible() && getRect().localPointInRect( x, y ) ) - { - if( getEnabled() ) - { - changeLine( clicks * mStepSize, TRUE ); - } - handled = TRUE; - } - - return handled; + changeLine( clicks * mStepSize, TRUE ); + return TRUE; } BOOL LLScrollbar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, @@ -475,85 +466,68 @@ void LLScrollbar::reshape(S32 width, S32 height, BOOL called_from_parent) void LLScrollbar::draw() { - if( getVisible() ) + S32 local_mouse_x; + S32 local_mouse_y; + LLCoordWindow cursor_pos_window; + getWindow()->getCursorPosition(&cursor_pos_window); + LLCoordGL cursor_pos_gl; + getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); + + screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); + BOOL other_captor = gFocusMgr.getMouseCapture() && gFocusMgr.getMouseCapture() != this; + BOOL hovered = getEnabled() && !other_captor && (hasMouseCapture() || mThumbRect.pointInRect(local_mouse_x, local_mouse_y)); + if (hovered) { - S32 local_mouse_x; - S32 local_mouse_y; - LLCoordWindow cursor_pos_window; - getWindow()->getCursorPosition(&cursor_pos_window); - LLCoordGL cursor_pos_gl; - getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); - - screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); - BOOL other_captor = gFocusMgr.getMouseCapture() && gFocusMgr.getMouseCapture() != this; - BOOL hovered = getEnabled() && !other_captor && (hasMouseCapture() || mThumbRect.pointInRect(local_mouse_x, local_mouse_y)); - if (hovered) - { - mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); - } - else - { - mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); - } + mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); + } + else + { + mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); + } - // Draw background and thumb. - LLUUID rounded_rect_image_id; - rounded_rect_image_id.set(LLUI::sAssetsGroup->getString("rounded_square.tga")); - LLImageGL* rounded_rect_imagep = LLUI::sImageProvider->getImageByID(rounded_rect_image_id); + // Draw background and thumb. + LLUIImage* rounded_rect_imagep = LLUI::sImageProvider->getUIImage("rounded_square.tga"); - if (!rounded_rect_imagep) - { - gl_rect_2d(mOrientation == HORIZONTAL ? SCROLLBAR_SIZE : 0, - mOrientation == VERTICAL ? getRect().getHeight() - 2 * SCROLLBAR_SIZE : getRect().getHeight(), - mOrientation == HORIZONTAL ? getRect().getWidth() - 2 * SCROLLBAR_SIZE : getRect().getWidth(), - mOrientation == VERTICAL ? SCROLLBAR_SIZE : 0, mTrackColor, TRUE); + if (!rounded_rect_imagep) + { + gl_rect_2d(mOrientation == HORIZONTAL ? SCROLLBAR_SIZE : 0, + mOrientation == VERTICAL ? getRect().getHeight() - 2 * SCROLLBAR_SIZE : getRect().getHeight(), + mOrientation == HORIZONTAL ? getRect().getWidth() - 2 * SCROLLBAR_SIZE : getRect().getWidth(), + mOrientation == VERTICAL ? SCROLLBAR_SIZE : 0, mTrackColor, TRUE); - gl_rect_2d(mThumbRect, mThumbColor, TRUE); + gl_rect_2d(mThumbRect, mThumbColor, TRUE); - } - else - { - // Background - gl_draw_scaled_image_with_border(mOrientation == HORIZONTAL ? SCROLLBAR_SIZE : 0, - mOrientation == VERTICAL ? SCROLLBAR_SIZE : 0, - 16, - 16, - mOrientation == HORIZONTAL ? getRect().getWidth() - 2 * SCROLLBAR_SIZE : getRect().getWidth(), - mOrientation == VERTICAL ? getRect().getHeight() - 2 * SCROLLBAR_SIZE : getRect().getHeight(), - rounded_rect_imagep, - mTrackColor, - TRUE); - - // Thumb - LLRect outline_rect = mThumbRect; - outline_rect.stretch(2); - - if (gFocusMgr.getKeyboardFocus() == this) - { - gl_draw_scaled_image_with_border(outline_rect.mLeft, outline_rect.mBottom, 16, 16, outline_rect.getWidth(), outline_rect.getHeight(), - rounded_rect_imagep, gFocusMgr.getFocusColor() ); - } + } + else + { + // Thumb + LLRect outline_rect = mThumbRect; + outline_rect.stretch(2); - gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), - rounded_rect_imagep, mThumbColor ); - if (mCurGlowStrength > 0.01f) - { - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE); - gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), - rounded_rect_imagep, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength), TRUE); - gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + if (gFocusMgr.getKeyboardFocus() == this) + { + rounded_rect_imagep->draw(outline_rect, gFocusMgr.getFocusColor()); } - BOOL was_scrolled_to_bottom = (getDocPos() == getDocPosMax()); - if (mOnScrollEndCallback && was_scrolled_to_bottom) + rounded_rect_imagep->draw(mThumbRect, mThumbColor); + if (mCurGlowStrength > 0.01f) { - mOnScrollEndCallback(mOnScrollEndData); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + rounded_rect_imagep->drawSolid(mThumbRect, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - // Draw children - LLView::draw(); + } + + BOOL was_scrolled_to_bottom = (getDocPos() == getDocPosMax()); + if (mOnScrollEndCallback && was_scrolled_to_bottom) + { + mOnScrollEndCallback(mOnScrollEndData); + } + + // Draw children + LLView::draw(); } // end draw @@ -582,42 +556,39 @@ void LLScrollbar::setValue(const LLSD& value) } -BOOL LLScrollbar::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLScrollbar::handleKeyHere(KEY key, MASK mask) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && !called_from_parent ) + switch( key ) { - switch( key ) - { - case KEY_HOME: - changeLine( -mDocPos, TRUE ); - handled = TRUE; - break; - - case KEY_END: - changeLine( getDocPosMax() - mDocPos, TRUE ); - handled = TRUE; - break; - - case KEY_DOWN: - changeLine( mStepSize, TRUE ); - handled = TRUE; - break; - - case KEY_UP: - changeLine( - mStepSize, TRUE ); - handled = TRUE; - break; - - case KEY_PAGE_DOWN: - pageDown(1); - break; - - case KEY_PAGE_UP: - pageUp(1); - break; - } + case KEY_HOME: + changeLine( -mDocPos, TRUE ); + handled = TRUE; + break; + + case KEY_END: + changeLine( getDocPosMax() - mDocPos, TRUE ); + handled = TRUE; + break; + + case KEY_DOWN: + changeLine( mStepSize, TRUE ); + handled = TRUE; + break; + + case KEY_UP: + changeLine( - mStepSize, TRUE ); + handled = TRUE; + break; + + case KEY_PAGE_DOWN: + pageDown(1); + break; + + case KEY_PAGE_UP: + pageUp(1); + break; } return handled; diff --git a/linden/indra/llui/llscrollbar.h b/linden/indra/llui/llscrollbar.h index b4586c3..52f19d1 100644 --- a/linden/indra/llui/llscrollbar.h +++ b/linden/indra/llui/llscrollbar.h @@ -62,11 +62,8 @@ public: virtual void setValue(const LLSD& value); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SCROLLBAR; } - virtual LLString getWidgetTag() const { return LL_SCROLLBAR_TAG; } - // Overrides from LLView - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleHover(S32 x, S32 y, MASK mask); diff --git a/linden/indra/llui/llscrollcontainer.cpp b/linden/indra/llui/llscrollcontainer.cpp index 15b59d4..a6c1c6d 100644 --- a/linden/indra/llui/llscrollcontainer.cpp +++ b/linden/indra/llui/llscrollcontainer.cpp @@ -61,6 +61,8 @@ static const F32 AUTO_SCROLL_RATE_ACCEL = 120.f; /// Class LLScrollableContainerView ///---------------------------------------------------------------------------- +static LLRegisterWidget r("scroll_container"); + // Default constructor LLScrollableContainerView::LLScrollableContainerView( const LLString& name, const LLRect& rect, @@ -210,63 +212,33 @@ void LLScrollableContainerView::reshape(S32 width, S32 height, } } -BOOL LLScrollableContainerView::handleKey( KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLScrollableContainerView::handleKeyHere(KEY key, MASK mask) { - if( getVisible() && getEnabled() ) + for( S32 i = 0; i < SCROLLBAR_COUNT; i++ ) { - if( called_from_parent ) - { - // Downward traversal - - // Don't pass keys to scrollbars on downward. - - // Handle 'child' view. - if( mScrolledView && mScrolledView->handleKey(key, mask, TRUE) ) - { - return TRUE; - } - } - else + if( mScrollbar[i]->handleKeyHere(key, mask) ) { - // Upward traversal - - for( S32 i = 0; i < SCROLLBAR_COUNT; i++ ) - { - // Note: the scrollbar _is_ actually being called from it's parent. Here - // we're delgating LLScrollableContainerView's upward traversal to the scrollbars - if( mScrollbar[i]->handleKey(key, mask, TRUE) ) - { - return TRUE; - } - } - - if (getParent()) - { - return getParent()->handleKey( key, mask, FALSE ); - } + return TRUE; } - } + } return FALSE; } BOOL LLScrollableContainerView::handleScrollWheel( S32 x, S32 y, S32 clicks ) { - if( getEnabled() ) + for( S32 i = 0; i < SCROLLBAR_COUNT; i++ ) { - for( S32 i = 0; i < SCROLLBAR_COUNT; i++ ) - { - // Note: tries vertical and then horizontal + // Note: tries vertical and then horizontal - // Pretend the mouse is over the scrollbar - if( mScrollbar[i]->handleScrollWheel( 0, 0, clicks ) ) - { - return TRUE; - } + // Pretend the mouse is over the scrollbar + if( mScrollbar[i]->handleScrollWheel( 0, 0, clicks ) ) + { + return TRUE; } } - // Opaque + // Eat scroll wheel event (to avoid scrolling nested containers?) return TRUE; } @@ -446,80 +418,78 @@ void LLScrollableContainerView::draw() // clear this flag to be set on next call to handleDragAndDrop mAutoScrolling = FALSE; - if( getVisible() ) + // auto-focus when scrollbar active + // this allows us to capture user intent (i.e. stop automatically scrolling the view/etc) + if (!gFocusMgr.childHasKeyboardFocus(this) && + (mScrollbar[VERTICAL]->hasMouseCapture() || mScrollbar[HORIZONTAL]->hasMouseCapture())) { - // auto-focus when scrollbar active - // this allows us to capture user intent (i.e. stop automatically scrolling the view/etc) - if (!gFocusMgr.childHasKeyboardFocus(this) && - (mScrollbar[VERTICAL]->hasMouseCapture() || mScrollbar[HORIZONTAL]->hasMouseCapture())) - { - focusFirstItem(); - } + focusFirstItem(); + } - // Draw background - if( mIsOpaque ) + // Draw background + if( mIsOpaque ) + { + LLGLSNoTexture no_texture; + glColor4fv( mBackgroundColor.mV ); + gl_rect_2d( mInnerRect ); + } + + // Draw mScrolledViews and update scroll bars. + // get a scissor region ready, and draw the scrolling view. The + // scissor region ensures that we don't draw outside of the bounds + // of the rectangle. + if( mScrolledView ) + { + updateScroll(); + + // Draw the scrolled area. { - LLGLSNoTexture no_texture; - gGL.color4fv( mBackgroundColor.mV ); - gl_rect_2d( mInnerRect ); + S32 visible_width = 0; + S32 visible_height = 0; + BOOL show_v_scrollbar = FALSE; + BOOL show_h_scrollbar = FALSE; + calcVisibleSize( mScrolledView->getRect(), &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar ); + + LLLocalClipRect clip(LLRect(mInnerRect.mLeft, + mInnerRect.mBottom + (show_h_scrollbar ? SCROLLBAR_SIZE : 0) + visible_height, + visible_width, + mInnerRect.mBottom + (show_h_scrollbar ? SCROLLBAR_SIZE : 0) + )); + drawChild(mScrolledView); } - - // Draw mScrolledViews and update scroll bars. - // get a scissor region ready, and draw the scrolling view. The - // scissor region ensures that we don't draw outside of the bounds - // of the rectangle. - if( mScrolledView ) - { - updateScroll(); + } - // Draw the scrolled area. - { - S32 visible_width = 0; - S32 visible_height = 0; - BOOL show_v_scrollbar = FALSE; - BOOL show_h_scrollbar = FALSE; - calcVisibleSize( mScrolledView->getRect(), &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar ); - - LLLocalClipRect clip(LLRect(mInnerRect.mLeft, - mInnerRect.mBottom + (show_h_scrollbar ? SCROLLBAR_SIZE : 0) + visible_height, - visible_width, - mInnerRect.mBottom + (show_h_scrollbar ? SCROLLBAR_SIZE : 0) - )); - drawChild(mScrolledView); - } - } + // Highlight border if a child of this container has keyboard focus + if( mBorder->getVisible() ) + { + mBorder->setKeyboardFocusHighlight( gFocusMgr.childHasKeyboardFocus(this) ); + } - // Highlight border if a child of this container has keyboard focus - if( mBorder->getVisible() ) + // Draw all children except mScrolledView + // Note: scrollbars have been adjusted by above drawing code + for (child_list_const_reverse_iter_t child_iter = getChildList()->rbegin(); + child_iter != getChildList()->rend(); ++child_iter) + { + LLView *viewp = *child_iter; + if( sDebugRects ) { - mBorder->setKeyboardFocusHighlight( gFocusMgr.childHasKeyboardFocus(this) ); + sDepth++; } - - // Draw all children except mScrolledView - // Note: scrollbars have been adjusted by above drawing code - for (child_list_const_reverse_iter_t child_iter = getChildList()->rbegin(); - child_iter != getChildList()->rend(); ++child_iter) + if( (viewp != mScrolledView) && viewp->getVisible() ) { - LLView *viewp = *child_iter; - if( sDebugRects ) - { - sDepth++; - } - if( (viewp != mScrolledView) && viewp->getVisible() ) - { - drawChild(viewp); - } - if( sDebugRects ) - { - sDepth--; - } + drawChild(viewp); } - - if (sDebugRects) + if( sDebugRects ) { - drawDebugRect(); + sDepth--; } } + + if (sDebugRects) + { + drawDebugRect(); + } + } // end draw void LLScrollableContainerView::updateScroll() diff --git a/linden/indra/llui/llscrollcontainer.h b/linden/indra/llui/llscrollcontainer.h index 51b1527..b6999e6 100644 --- a/linden/indra/llui/llscrollcontainer.h +++ b/linden/indra/llui/llscrollcontainer.h @@ -70,8 +70,6 @@ public: void setScrolledView(LLView* view) { mScrolledView = view; } virtual void setValue(const LLSD& value) { mInnerRect.setValue(value); } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SCROLL_CONTAINER; } - virtual LLString getWidgetTag() const { return LL_SCROLLABLE_CONTAINER_VIEW_TAG; } void calcVisibleSize( S32 *visible_width, S32 *visible_height, BOOL* show_h_scrollbar, BOOL* show_v_scrollbar ) const; void calcVisibleSize( const LLRect& doc_rect, S32 *visible_width, S32 *visible_height, BOOL* show_h_scrollbar, BOOL* show_v_scrollbar ) const; @@ -90,7 +88,7 @@ public: // LLView functionality virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); - virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks ); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, diff --git a/linden/indra/llui/llscrollingpanellist.cpp b/linden/indra/llui/llscrollingpanellist.cpp index 8f85bc8..c9cdf3f 100644 --- a/linden/indra/llui/llscrollingpanellist.cpp +++ b/linden/indra/llui/llscrollingpanellist.cpp @@ -34,6 +34,9 @@ #include "llscrollingpanellist.h" +static LLRegisterWidget r("scrolling_panel_list"); + + ///////////////////////////////////////////////////////////////////// // LLScrollingPanelList @@ -129,10 +132,8 @@ void LLScrollingPanelList::updatePanelVisiblilty() void LLScrollingPanelList::draw() { - if( getVisible() ) - { - updatePanelVisiblilty(); - } + updatePanelVisiblilty(); + LLUICtrl::draw(); } diff --git a/linden/indra/llui/llscrollingpanellist.h b/linden/indra/llui/llscrollingpanellist.h index 6fe35cd..7729250 100644 --- a/linden/indra/llui/llscrollingpanellist.h +++ b/linden/indra/llui/llscrollingpanellist.h @@ -56,8 +56,6 @@ public: : LLUICtrl(name, rect, TRUE, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_BOTTOM ) {} virtual void setValue(const LLSD& value) {}; - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SCROLLING_PANEL_LIST; } - virtual LLString getWidgetTag() const { return LL_SCROLLING_PANEL_LIST_TAG; } virtual LLXMLNodePtr getXML(bool save_children) const { return LLUICtrl::getXML(); } diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp index 01c37d9..2066819 100644 --- a/linden/indra/llui/llscrolllistctrl.cpp +++ b/linden/indra/llui/llscrolllistctrl.cpp @@ -55,10 +55,11 @@ #include "llkeyboard.h" #include "llresizebar.h" -const S32 LIST_BORDER_PAD = 0; // white space inside the border and to the left of the scrollbar const S32 MIN_COLUMN_WIDTH = 20; const S32 LIST_SNAP_PADDING = 5; +static LLRegisterWidget r("scroll_list"); + // local structures & classes. struct SortScrollListItem { @@ -68,37 +69,26 @@ struct SortScrollListItem bool operator()(const LLScrollListItem* i1, const LLScrollListItem* i2) { - if ( mSortOrders.empty() ) return true; - - const LLScrollListCell *cell1 = NULL; - const LLScrollListCell *cell2 = NULL; - - sort_order_t::const_reverse_iterator end_it = mSortOrders.rend(); - sort_order_t::const_reverse_iterator it; + if ( mSortOrders.empty() ) + return i1 < i2; // sort over all columns in order specified by mSortOrders S32 sort_result = 0; - for (it = mSortOrders.rbegin(); it != end_it; ++it) + for (sort_order_t::const_reverse_iterator it = mSortOrders.rbegin(); + it != mSortOrders.rend(); ++it) { S32 col_idx = it->first; BOOL sort_ascending = it->second; - cell1 = i1->getColumn(col_idx); - cell2 = i2->getColumn(col_idx); - // ascending or descending sort for this column? - S32 order = 1; - if (!sort_ascending) - { - order = -1; - } - + const LLScrollListCell *cell1 = i1->getColumn(col_idx); + const LLScrollListCell *cell2 = i2->getColumn(col_idx); + S32 order = sort_ascending ? 1 : -1; // ascending or descending sort for this column? if (cell1 && cell2) { - sort_result = (order * LLString::compareDict(cell1->getValue().asString(), cell2->getValue().asString())); + sort_result = order * LLString::compareDict(cell1->getValue().asString(), cell2->getValue().asString()); if (sort_result != 0) { - // we have a sort order! - break; + break; // we have a sort order! } } } @@ -114,24 +104,49 @@ struct SortScrollListItem // // LLScrollListIcon // -LLScrollListIcon::LLScrollListIcon(const LLUUID& icon_id, S32 width) +LLScrollListIcon::LLScrollListIcon(LLUIImagePtr icon, S32 width) + : LLScrollListCell(width), + mIcon(icon), + mColor(LLColor4::white) +{ +} + +LLScrollListIcon::LLScrollListIcon(const LLSD& value, S32 width) : LLScrollListCell(width), - mColor(LLColor4::white), - mImageUUID(icon_id) + mColor(LLColor4::white) { - // don't use default image specified by LLUUID::null, use no image in that case - mIcon = icon_id.isNull() ? NULL : LLUI::sImageProvider->getImageByID(icon_id); + setValue(value); } + LLScrollListIcon::~LLScrollListIcon() { } void LLScrollListIcon::setValue(const LLSD& value) { - mImageUUID = value.asUUID(); - // don't use default image specified by LLUUID::null, use no image in that case - mIcon = mImageUUID.isNull() ? NULL : LLUI::sImageProvider->getImageByID(mImageUUID); + if (value.isUUID()) + { + // don't use default image specified by LLUUID::null, use no image in that case + LLUUID image_id = value.asUUID(); + mIcon = image_id.notNull() ? LLUI::sImageProvider->getUIImageByID(image_id) : LLUIImagePtr(NULL); + } + else + { + LLString value_string = value.asString(); + if (LLUUID::validate(value_string)) + { + setValue(LLUUID(value_string)); + } + else if (!value_string.empty()) + { + mIcon = LLUI::getUIImage(value.asString()); + } + else + { + mIcon = NULL; + } + } } @@ -143,7 +158,7 @@ void LLScrollListIcon::setColor(const LLColor4& color) S32 LLScrollListIcon::getWidth() const { // if no specified fix width, use width of icon - if (LLScrollListCell::getWidth() == 0) + if (LLScrollListCell::getWidth() == 0 && mIcon.notNull()) { return mIcon->getWidth(); } @@ -151,11 +166,11 @@ S32 LLScrollListIcon::getWidth() const } -void LLScrollListIcon::draw(const LLColor4& color, const LLColor4& highlight_color) const +void LLScrollListIcon::draw(const LLColor4& color, const LLColor4& highlight_color) const { if (mIcon) { - gl_draw_image(0, 0, mIcon, mColor); + mIcon->draw(0, 0, mColor); } } @@ -206,6 +221,13 @@ LLScrollListSeparator::LLScrollListSeparator(S32 width) : LLScrollListCell(width { } +//virtual +S32 LLScrollListSeparator::getHeight() const +{ + return 5; +} + + void LLScrollListSeparator::draw(const LLColor4& color, const LLColor4& highlight_color) const { //*FIXME: use dynamic item heights and make separators narrow, and inactive @@ -234,9 +256,34 @@ LLScrollListText::LLScrollListText( const LLString& text, const LLFontGL* font, // initialize rounded rect image if (!mRoundedRectImage) { - mRoundedRectImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("rounded_square.tga"))); + mRoundedRectImage = LLUI::sImageProvider->getUIImage("rounded_square.tga"); } } +//virtual +void LLScrollListText::highlightText(S32 offset, S32 num_chars) +{ + mHighlightOffset = offset; + mHighlightCount = num_chars; +} + +//virtual +BOOL LLScrollListText::isText() const +{ + return TRUE; +} + +//virtual +BOOL LLScrollListText::getVisible() const +{ + return mVisible; +} + +//virtual +S32 LLScrollListText::getHeight() const +{ + return llround(mFont->getLineHeight()); +} + LLScrollListText::~LLScrollListText() { @@ -266,6 +313,13 @@ void LLScrollListText::setValue(const LLSD& text) setText(text.asString()); } +//virtual +const LLSD LLScrollListText::getValue() const +{ + return LLSD(mText.getString()); +} + + void LLScrollListText::draw(const LLColor4& color, const LLColor4& highlight_color) const { LLColor4 display_color; @@ -280,8 +334,6 @@ void LLScrollListText::draw(const LLColor4& color, const LLColor4& highlight_col if (mHighlightCount > 0) { - mRoundedRectImage->bind(); - gGL.color4fv(highlight_color.mV); S32 left = 0; switch(mFontAlignment) { @@ -295,13 +347,11 @@ void LLScrollListText::draw(const LLColor4& color, const LLColor4& highlight_col left = (getWidth() - mFont->getWidth(mText.getString())) / 2; break; } - gl_segmented_rect_2d_tex(left - 2, + LLRect highlight_rect(left - 2, llround(mFont->getLineHeight()) + 1, left + mFont->getWidth(mText.getString(), mHighlightOffset, mHighlightCount) + 1, - 1, - mRoundedRectImage->getWidth(), - mRoundedRectImage->getHeight(), - 16); + 1); + mRoundedRectImage->draw(highlight_rect, highlight_color); } // Try to draw the entire string @@ -389,8 +439,6 @@ void LLScrollListItem::draw(const LLRect& rect, const LLColor4& fg_color, const { // draw background rect LLRect bg_rect = rect; - // pad background rectangle to separate it from contents - bg_rect.stretch(LIST_BORDER_PAD, 0); { LLGLSNoTexture no_texture; gGL.color4fv(bg_color.mV); @@ -432,7 +480,7 @@ LLScrollListItemComment::LLScrollListItemComment(const LLString& comment_string, : LLScrollListItem(FALSE), mColor(color) { - addColumn( comment_string, gResMgr->getRes( LLFONT_SANSSERIF_SMALL ) ); + addColumn( comment_string, LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ) ); } void LLScrollListItemComment::draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding) @@ -541,10 +589,10 @@ LLScrollListCtrl::LLScrollListCtrl(const LLString& name, const LLRect& rect, mDrewSelected(FALSE) { mItemListRect.setOriginAndSize( - mBorderThickness + LIST_BORDER_PAD, - mBorderThickness + LIST_BORDER_PAD, - getRect().getWidth() - 2*( mBorderThickness + LIST_BORDER_PAD ), - getRect().getHeight() - 2*( mBorderThickness + LIST_BORDER_PAD ) ); + mBorderThickness, + mBorderThickness, + getRect().getWidth() - 2 * mBorderThickness, + getRect().getHeight() - 2 * mBorderThickness ); updateLineHeight(); @@ -738,10 +786,10 @@ void LLScrollListCtrl::updateLayout() // reserve room for column headers, if needed S32 heading_size = (mDisplayColumnHeaders ? mHeadingHeight : 0); mItemListRect.setOriginAndSize( - mBorderThickness + LIST_BORDER_PAD, - mBorderThickness + LIST_BORDER_PAD, - getRect().getWidth() - 2*( mBorderThickness + LIST_BORDER_PAD ), - getRect().getHeight() - 2*( mBorderThickness + LIST_BORDER_PAD ) - heading_size ); + mBorderThickness, + mBorderThickness, + getRect().getWidth() - 2 * mBorderThickness, + getRect().getHeight() - (2 * mBorderThickness ) - heading_size ); // how many lines of content in a single "page" mPageLines = mLineHeight? mItemListRect.getHeight() / mLineHeight : 0; @@ -749,7 +797,7 @@ void LLScrollListCtrl::updateLayout() if (scrollbar_visible) { // provide space on the right for scrollbar - mItemListRect.mRight = getRect().getWidth() - ( mBorderThickness + LIST_BORDER_PAD ) - SCROLLBAR_SIZE; + mItemListRect.mRight = getRect().getWidth() - mBorderThickness - SCROLLBAR_SIZE; } mScrollbar->reshape(SCROLLBAR_SIZE, mItemListRect.getHeight() + (mDisplayColumnHeaders ? mHeadingHeight : 0)); @@ -775,7 +823,7 @@ LLRect LLScrollListCtrl::getRequiredRect() { S32 heading_size = (mDisplayColumnHeaders ? mHeadingHeight : 0); S32 height = (mLineHeight * getItemCount()) - + (2 * ( mBorderThickness + LIST_BORDER_PAD )) + + (2 * mBorderThickness ) + heading_size; S32 width = getRect().getWidth(); @@ -1357,7 +1405,6 @@ LLScrollListItem* LLScrollListCtrl::addCommentText(const LLString& comment_text, LLScrollListItem* item = NULL; if (getItemCount() < mMaxItemCount) { - // simple items have their LLSD data set to their label // always draw comment text with "enabled" color item = new LLScrollListItemComment( comment_text, mFgUnselectedColor ); addItem( item, pos, FALSE ); @@ -1525,7 +1572,7 @@ LLScrollListItem* LLScrollListCtrl::addStringUUIDItem(const LLString& item_text, if (getItemCount() < mMaxItemCount) { item = new LLScrollListItem( enabled, NULL, id ); - item->addColumn(item_text, gResMgr->getRes(LLFONT_SANSSERIF_SMALL), column_width); + item->addColumn(item_text, LLResMgr::getInstance()->getRes(LLFONT_SANSSERIF_SMALL), column_width); addItem( item, pos ); } return item; @@ -1664,7 +1711,6 @@ void LLScrollListCtrl::drawItems() fg_color = (item->getEnabled() ? mFgUnselectedColor : mFgDisabledColor); if( item->getSelected() && mCanSelect) { - // Draw background of selected item bg_color = mBgSelectedColor; fg_color = (item->getEnabled() ? mFgSelectedColor : mFgDisabledColor); } @@ -1697,43 +1743,40 @@ void LLScrollListCtrl::drawItems() void LLScrollListCtrl::draw() { - if( getVisible() ) + // if user specifies sort, make sure it is maintained + if (needsSorting() && !isSorted()) { - // if user specifies sort, make sure it is maintained - if (needsSorting() && !isSorted()) - { - sortItems(); - } - - if (mNeedsScroll) - { - scrollToShowSelected(); - mNeedsScroll = FALSE; - } - LLRect background(0, getRect().getHeight(), getRect().getWidth(), 0); - // Draw background - if (mBackgroundVisible) - { - LLGLSNoTexture no_texture; - gGL.color4fv( getEnabled() ? mBgWriteableColor.mV : mBgReadOnlyColor.mV ); - gl_rect_2d(background); - } + sortItems(); + } - if (mColumnsDirty) - { - updateColumns(); - mColumnsDirty = FALSE; - } + if (mNeedsScroll) + { + scrollToShowSelected(); + mNeedsScroll = FALSE; + } + LLRect background(0, getRect().getHeight(), getRect().getWidth(), 0); + // Draw background + if (mBackgroundVisible) + { + LLGLSNoTexture no_texture; + glColor4fv( getEnabled() ? mBgWriteableColor.mV : mBgReadOnlyColor.mV ); + gl_rect_2d(background); + } - drawItems(); + if (mColumnsDirty) + { + updateColumns(); + mColumnsDirty = FALSE; + } - if (mBorder) - { - mBorder->setKeyboardFocusHighlight(gFocusMgr.getKeyboardFocus() == this); - } + drawItems(); - LLUICtrl::draw(); + if (mBorder) + { + mBorder->setKeyboardFocusHighlight(gFocusMgr.getKeyboardFocus() == this); } + + LLUICtrl::draw(); } void LLScrollListCtrl::setEnabled(BOOL enabled) @@ -1950,23 +1993,21 @@ BOOL LLScrollListCtrl::handleMouseUp(S32 x, S32 y, MASK mask) BOOL LLScrollListCtrl::handleDoubleClick(S32 x, S32 y, MASK mask) { //BOOL handled = FALSE; - if(getVisible()) - { - BOOL handled = handleClick(x, y, mask); + BOOL handled = handleClick(x, y, mask); - if (!handled) + if (!handled) + { + // Offer the click to the children, even if we aren't enabled + // so the scroll bars will work. + if (NULL == LLView::childrenHandleDoubleClick(x, y, mask)) { - // Offer the click to the children, even if we aren't enabled - // so the scroll bars will work. - if (NULL == LLView::childrenHandleDoubleClick(x, y, mask)) + if( mCanSelect && mOnDoubleClickCallback ) { - if( mCanSelect && mOnDoubleClickCallback ) - { - mOnDoubleClickCallback( mCallbackUserData ); - } + mOnDoubleClickCallback( mCallbackUserData ); } } } + return TRUE; } @@ -2146,12 +2187,12 @@ BOOL LLScrollListCtrl::handleHover(S32 x,S32 y,MASK mask) } -BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask, BOOL called_from_parent ) +BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask ) { BOOL handled = FALSE; // not called from parent means we have keyboard focus or a child does - if (mCanSelect && !called_from_parent) + if (mCanSelect) { // Ignore capslock mask = mask; @@ -2234,7 +2275,7 @@ BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask, BOOL called_from_parent // JC - Special case: Only claim to have handled it // if we're the special non-commit-on-move // type. AND we are visible - if (!mCommitOnKeyboardMovement && mask == MASK_NONE && getVisible()) + if (!mCommitOnKeyboardMovement && mask == MASK_NONE) { onCommit(); mSearchString.clear(); @@ -2281,7 +2322,7 @@ BOOL LLScrollListCtrl::handleKeyHere(KEY key,MASK mask, BOOL called_from_parent return handled; } -BOOL LLScrollListCtrl::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) +BOOL LLScrollListCtrl::handleUnicodeCharHere(llwchar uni_char) { if ((uni_char < 0x20) || (uni_char == 0x7F)) // Control character or DEL { @@ -3207,17 +3248,16 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p LLColor4 color = ((*itor)["color"]); BOOL enabled = !(*itor).has("enabled") || (*itor)["enabled"].asBoolean() == true; - const LLFontGL *font = gResMgr->getRes(fontname); + const LLFontGL *font = LLResMgr::getInstance()->getRes(fontname); if (!font) { - font = gResMgr->getRes( LLFONT_SANSSERIF_SMALL ); + font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); } U8 font_style = LLFontGL::getStyleFromString(fontstyle); if (type == "icon") { - LLUUID image_id = value.asUUID(); - LLScrollListIcon* cell = new LLScrollListIcon(value.asUUID(), width); + LLScrollListIcon* cell = new LLScrollListIcon(value, width); if (has_color) { cell->setColor(color); @@ -3270,7 +3310,7 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p if (new_item->getColumn(column_idx) == NULL) { LLScrollListColumn* column_ptr = &column_it->second; - new_item->setColumn(column_idx, new LLScrollListText("", gResMgr->getRes( LLFONT_SANSSERIF_SMALL ), column_ptr->mWidth, LLFontGL::NORMAL)); + new_item->setColumn(column_idx, new LLScrollListText("", LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ), column_ptr->mWidth, LLFontGL::NORMAL)); } } @@ -3290,7 +3330,7 @@ LLScrollListItem* LLScrollListCtrl::addSimpleElement(const LLString& value, EAdd LLScrollListItem *new_item = new LLScrollListItem(entry_id); - const LLFontGL *font = gResMgr->getRes( LLFONT_SANSSERIF_SMALL ); + const LLFontGL *font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); new_item->addColumn(value, font, getRect().getWidth()); @@ -3438,29 +3478,25 @@ LLColumnHeader::~LLColumnHeader() void LLColumnHeader::draw() { - if( getVisible() ) - { - BOOL draw_arrow = !mColumn->mLabel.empty() && mColumn->mParentCtrl->isSorted() && mColumn->mParentCtrl->getSortColumnName() == mColumn->mSortingColumn; + BOOL draw_arrow = !mColumn->mLabel.empty() && mColumn->mParentCtrl->isSorted() && mColumn->mParentCtrl->getSortColumnName() == mColumn->mSortingColumn; - BOOL is_ascending = mColumn->mParentCtrl->getSortAscending(); - mButton->setImageOverlay(is_ascending ? "up_arrow.tga" : "down_arrow.tga", LLFontGL::RIGHT, draw_arrow ? LLColor4::white : LLColor4::transparent); - mArrowImage = mButton->getImageOverlay()->getImage(); + BOOL is_ascending = mColumn->mParentCtrl->getSortAscending(); + mButton->setImageOverlay(is_ascending ? "up_arrow.tga" : "down_arrow.tga", LLFontGL::RIGHT, draw_arrow ? LLColor4::white : LLColor4::transparent); + mArrowImage = mButton->getImageOverlay(); - //BOOL clip = getRect().mRight > mColumn->mParentCtrl->getItemListRect().getWidth(); - //LLGLEnable scissor_test(clip ? GL_SCISSOR_TEST : GL_FALSE); + //BOOL clip = getRect().mRight > mColumn->mParentCtrl->getItemListRect().getWidth(); + //LLGLEnable scissor_test(clip ? GL_SCISSOR_TEST : GL_FALSE); - //LLRect column_header_local_rect(-getRect().mLeft, getRect().getHeight(), mColumn->mParentCtrl->getItemListRect().getWidth() - getRect().mLeft, 0); - //LLUI::setScissorRegionLocal(column_header_local_rect); + //LLRect column_header_local_rect(-getRect().mLeft, getRect().getHeight(), mColumn->mParentCtrl->getItemListRect().getWidth() - getRect().mLeft, 0); + //LLUI::setScissorRegionLocal(column_header_local_rect); - // Draw children - LLComboBox::draw(); - - if (mList->getVisible()) - { - // sync sort order with list selection every frame - mColumn->mParentCtrl->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0); - } + // Draw children + LLComboBox::draw(); + if (mList->getVisible()) + { + // sync sort order with list selection every frame + mColumn->mParentCtrl->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0); } } diff --git a/linden/indra/llui/llscrolllistctrl.h b/linden/indra/llui/llscrolllistctrl.h index 716d18a..8a31154 100644 --- a/linden/indra/llui/llscrolllistctrl.h +++ b/linden/indra/llui/llscrolllistctrl.h @@ -90,7 +90,7 @@ public: LLScrollListSeparator(S32 width); virtual ~LLScrollListSeparator() {}; virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const; // truncate to given width, if possible - virtual S32 getHeight() const { return 5; }; + virtual S32 getHeight() const; virtual BOOL isText() const { return FALSE; } }; @@ -105,14 +105,14 @@ public: virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const; virtual S32 getContentWidth() const; - virtual S32 getHeight() const { return llround(mFont->getLineHeight()); } + virtual S32 getHeight() const; virtual void setValue(const LLSD& value); - virtual const LLSD getValue() const { return LLSD(mText.getString()); } - virtual BOOL getVisible() const { return mVisible; } - virtual void highlightText(S32 offset, S32 num_chars) {mHighlightOffset = offset; mHighlightCount = num_chars;} + virtual const LLSD getValue() const; + virtual BOOL getVisible() const; + virtual void highlightText(S32 offset, S32 num_chars); virtual void setColor(const LLColor4&); - virtual BOOL isText() const { return TRUE; } + virtual BOOL isText() const; void setText(const LLStringExplicit& text); void setFontStyle(const U8 font_style) { mFontStyle = font_style; } @@ -128,7 +128,7 @@ private: S32 mHighlightCount; S32 mHighlightOffset; - LLPointer mRoundedRectImage; + LLPointer mRoundedRectImage; static U32 sCount; }; @@ -139,20 +139,19 @@ private: class LLScrollListIcon : public LLScrollListCell { public: - LLScrollListIcon( const LLUUID& icon_id, S32 width = 0); + LLScrollListIcon( LLUIImagePtr icon, S32 width = 0); + LLScrollListIcon(const LLSD& value, S32 width = 0); /*virtual*/ ~LLScrollListIcon(); virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const; virtual S32 getWidth() const; virtual S32 getHeight() const { return mIcon ? mIcon->getHeight() : 0; } - // used as sort criterion - virtual const LLSD getValue() const { return LLSD(mImageUUID); } + virtual const LLSD getValue() const { return mIcon.isNull() ? LLString::null : mIcon->getName(); } virtual void setColor(const LLColor4&); virtual BOOL isText()const { return FALSE; } virtual void setValue(const LLSD& value); private: - LLPointer mIcon; - LLUUID mImageUUID; + LLUIImagePtr mIcon; LLColor4 mColor; }; @@ -342,8 +341,8 @@ public: void addColumn( const LLString& text, const LLFontGL* font, S32 width = 0 , U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, BOOL visible = TRUE) { mColumns.push_back( new LLScrollListText(text, font, width, font_style, font_alignment, LLColor4::black, FALSE, visible) ); } - void addColumn( const LLUUID& icon_id, S32 width = 0 ) - { mColumns.push_back( new LLScrollListIcon(icon_id, width) ); } + void addColumn( LLUIImagePtr icon, S32 width = 0 ) + { mColumns.push_back( new LLScrollListIcon(icon, width) ); } void addColumn( LLCheckBoxCtrl* check, S32 width = 0 ) { mColumns.push_back( new LLScrollListCheck(check,width) ); } @@ -404,8 +403,7 @@ public: BOOL draw_border = TRUE); virtual ~LLScrollListCtrl(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SCROLL_LIST; } - virtual LLString getWidgetTag() const { return LL_SCROLL_LIST_CTRL_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; void setScrollListParameters(LLXMLNodePtr node); static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); @@ -562,8 +560,8 @@ public: /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask); - /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); - /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); + /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask); + /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char); /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); /*virtual*/ BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect); /*virtual*/ void setEnabled(BOOL enabled); @@ -618,6 +616,7 @@ public: S32 selectMultiple( LLDynamicArray ids ); void sortItems(); + // manually call this whenever editing list items in place to flag need for resorting void setSorted(BOOL sorted) { mSorted = sorted; } void dirtyColumns(); // some operation has potentially affected column layout or ordering diff --git a/linden/indra/llui/llslider.cpp b/linden/indra/llui/llslider.cpp index 02841ee..12d794c 100644 --- a/linden/indra/llui/llslider.cpp +++ b/linden/indra/llui/llslider.cpp @@ -41,6 +41,10 @@ #include "llcontrol.h" #include "llimagegl.h" +static LLRegisterWidget r1("slider_bar"); +static LLRegisterWidget r2("volume_slider"); + + LLSlider::LLSlider( const LLString& name, const LLRect& rect, @@ -68,9 +72,9 @@ LLSlider::LLSlider( mMouseDownCallback( NULL ), mMouseUpCallback( NULL ) { - mThumbImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-thumb_dark.tga"))); - mTrackImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-groove_dark.tga"))); - mTrackHighlightImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-highlight.tga"))); + mThumbImage = LLUI::sImageProvider->getUIImage("icn_slide-thumb_dark.tga"); + mTrackImage = LLUI::sImageProvider->getUIImage("icn_slide-groove_dark.tga"); + mTrackHighlightImage = LLUI::sImageProvider->getUIImage("icn_slide-highlight.tga"); // properly handle setting the starting thumb rect // do it this way to handle both the operating-on-settings @@ -217,98 +221,68 @@ BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask) return TRUE; } -BOOL LLSlider::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLSlider::handleKeyHere(KEY key, MASK mask) { BOOL handled = FALSE; - if( getVisible() && getEnabled() && !called_from_parent ) + switch(key) { - switch(key) - { - case KEY_UP: - case KEY_DOWN: - // eat up and down keys to be consistent - handled = TRUE; - break; - case KEY_LEFT: - setValueAndCommit(getValueF32() - getIncrement()); - handled = TRUE; - break; - case KEY_RIGHT: - setValueAndCommit(getValueF32() + getIncrement()); - handled = TRUE; - break; - default: - break; - } + case KEY_UP: + case KEY_DOWN: + // eat up and down keys to be consistent + handled = TRUE; + break; + case KEY_LEFT: + setValueAndCommit(getValueF32() - getIncrement()); + handled = TRUE; + break; + case KEY_RIGHT: + setValueAndCommit(getValueF32() + getIncrement()); + handled = TRUE; + break; + default: + break; } return handled; } void LLSlider::draw() { - if( getVisible() ) - { - // since thumb image might still be decoding, need thumb to accomodate image size - updateThumbRect(); - - // Draw background and thumb. - - // drawing solids requires texturing be disabled - LLGLSNoTexture no_texture; - - LLRect rect(mDragStartThumbRect); - - F32 opacity = getEnabled() ? 1.f : 0.3f; - LLColor4 center_color = (mThumbCenterColor % opacity); - LLColor4 track_color = (mTrackColor % opacity); - - // Track - LLRect track_rect(mThumbImage->getWidth() / 2, - getLocalRect().getCenterY() + (mTrackImage->getHeight() / 2), - getRect().getWidth() - mThumbImage->getWidth() / 2, - getLocalRect().getCenterY() - (mTrackImage->getHeight() / 2) ); - - gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 3, 3, track_rect.getWidth(), track_rect.getHeight(), - mTrackImage, track_color); - gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 3, 3, mThumbRect.mLeft, track_rect.getHeight(), - mTrackHighlightImage, track_color); + // since thumb image might still be decoding, need thumb to accomodate image size + updateThumbRect(); + // Draw background and thumb. - // Thumb - if( hasMouseCapture() ) - { - gl_draw_scaled_image(mDragStartThumbRect.mLeft, mDragStartThumbRect.mBottom, mDragStartThumbRect.getWidth(), mDragStartThumbRect.getHeight(), - mThumbImage, mThumbCenterColor % 0.3f); + // drawing solids requires texturing be disabled + LLGLSNoTexture no_texture; - if (hasFocus()) - { - F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); - LLRect highlight_rect = mThumbRect; - highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); - gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 0, 0, highlight_rect.getWidth(), highlight_rect.getHeight(), - mThumbImage, gFocusMgr.getFocusColor(), TRUE); - } + F32 opacity = getEnabled() ? 1.f : 0.3f; + LLColor4 center_color = (mThumbCenterColor % opacity); + LLColor4 track_color = (mTrackColor % opacity); - gl_draw_scaled_image(mThumbRect.mLeft, mThumbRect.mBottom, mThumbRect.getWidth(), mThumbRect.getHeight(), - mThumbImage, mThumbOutlineColor); + // Track + LLRect track_rect(mThumbImage->getWidth() / 2, + getLocalRect().getCenterY() + (mTrackImage->getHeight() / 2), + getRect().getWidth() - mThumbImage->getWidth() / 2, + getLocalRect().getCenterY() - (mTrackImage->getHeight() / 2) ); + LLRect highlight_rect(track_rect.mLeft, track_rect.mTop, mThumbRect.getCenterX(), track_rect.mBottom); + mTrackImage->draw(track_rect); + mTrackHighlightImage->draw(highlight_rect); - } - else - { - if (hasFocus()) - { - F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); - LLRect highlight_rect = mThumbRect; - highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); - gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 0, 0, highlight_rect.getWidth(), highlight_rect.getHeight(), - mThumbImage, gFocusMgr.getFocusColor(), TRUE); - } - - gl_draw_scaled_image(mThumbRect.mLeft, mThumbRect.mBottom, mThumbRect.getWidth(), mThumbRect.getHeight(), - mThumbImage, center_color); - } - LLUICtrl::draw(); + // Thumb + if( hasMouseCapture() ) + { + // Show ghost where thumb was before dragging began. + mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor % 0.3f); } + if (hasFocus()) + { + // Draw focus highlighting. + mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor(), gFocusMgr.getFocusFlashWidth()); + } + // Fill in the thumb. + mThumbImage->draw(mThumbRect, hasMouseCapture() ? mThumbOutlineColor : center_color); + + LLUICtrl::draw(); } // virtual diff --git a/linden/indra/llui/llslider.h b/linden/indra/llui/llslider.h index 506a6bd..1c9d5e1 100644 --- a/linden/indra/llui/llslider.h +++ b/linden/indra/llui/llslider.h @@ -52,8 +52,6 @@ public: BOOL volume, //TODO: create a "volume" slider sub-class or just use image art, no? -MG const LLString& control_name = LLString::null ); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SLIDER_BAR; } - virtual LLString getWidgetTag() const { return LL_SLIDER_TAG; } virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory); @@ -79,7 +77,7 @@ public: virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual void draw(); private: @@ -96,9 +94,9 @@ private: S32 mMouseOffset; LLRect mDragStartThumbRect; - LLImageGL* mThumbImage; - LLImageGL* mTrackImage; - LLImageGL* mTrackHighlightImage; + LLUIImage* mThumbImage; + LLUIImage* mTrackImage; + LLUIImage* mTrackHighlightImage; LLRect mThumbRect; LLColor4 mTrackColor; diff --git a/linden/indra/llui/llsliderctrl.cpp b/linden/indra/llui/llsliderctrl.cpp index 58ab4ae..d3dc35f 100644 --- a/linden/indra/llui/llsliderctrl.cpp +++ b/linden/indra/llui/llsliderctrl.cpp @@ -52,6 +52,7 @@ const U32 MAX_STRING_LENGTH = 10; +static LLRegisterWidget r("slider"); LLSliderCtrl::LLSliderCtrl(const LLString& name, const LLRect& rect, const LLString& label, diff --git a/linden/indra/llui/llsliderctrl.h b/linden/indra/llui/llsliderctrl.h index 705fa5c..0c8a8b6 100644 --- a/linden/indra/llui/llsliderctrl.h +++ b/linden/indra/llui/llsliderctrl.h @@ -63,8 +63,7 @@ public: const LLString& control_which = LLString::null ); virtual ~LLSliderCtrl() {} // Children all cleaned up by default view destructor. - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SLIDER; } - virtual LLString getWidgetTag() const { return LL_SLIDER_CTRL_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); diff --git a/linden/indra/llui/llspinctrl.cpp b/linden/indra/llui/llspinctrl.cpp index 98cdae1..9e85b20 100644 --- a/linden/indra/llui/llspinctrl.cpp +++ b/linden/indra/llui/llspinctrl.cpp @@ -52,6 +52,7 @@ const U32 MAX_STRING_LENGTH = 32; +static LLRegisterWidget r2("spinner"); LLSpinCtrl::LLSpinCtrl( const LLString& name, const LLRect& rect, const LLString& label, const LLFontGL* font, void (*commit_callback)(LLUICtrl*, void*), @@ -409,26 +410,23 @@ void LLSpinCtrl::draw() BOOL LLSpinCtrl::handleScrollWheel(S32 x, S32 y, S32 clicks) { - if( getEnabled() ) + if( clicks > 0 ) { - if( clicks > 0 ) + while( clicks-- ) { - while( clicks-- ) - { - LLSpinCtrl::onDownBtn(this); - } - } - else - while( clicks++ ) - { - LLSpinCtrl::onUpBtn(this); + LLSpinCtrl::onDownBtn(this); } } + else + while( clicks++ ) + { + LLSpinCtrl::onUpBtn(this); + } return TRUE; } -BOOL LLSpinCtrl::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLSpinCtrl::handleKeyHere(KEY key, MASK mask) { if (mEditor->hasFocus()) { diff --git a/linden/indra/llui/llspinctrl.h b/linden/indra/llui/llspinctrl.h index f1f971e..790e216 100644 --- a/linden/indra/llui/llspinctrl.h +++ b/linden/indra/llui/llspinctrl.h @@ -62,8 +62,7 @@ public: S32 label_width = SPINCTRL_DEFAULT_LABEL_WIDTH ); virtual ~LLSpinCtrl() {} // Children all cleaned up by default view destructor. - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SPINNER; } - virtual LLString getWidgetTag() const { return LL_SPIN_CTRL_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory); @@ -101,7 +100,7 @@ public: void forceEditorCommit(); // for commit on external button virtual BOOL handleScrollWheel(S32 x,S32 y,S32 clicks); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask); virtual void draw(); diff --git a/linden/indra/llui/llstyle.cpp b/linden/indra/llui/llstyle.cpp index cdf87d3..7c46114 100644 --- a/linden/indra/llui/llstyle.cpp +++ b/linden/indra/llui/llstyle.cpp @@ -138,12 +138,34 @@ void LLStyle::setFontName(const LLString& fontname) } -void LLStyle::setImage(const LLString& src) +void LLStyle::setLinkHREF(const LLString& href) { - if (src.size() >= UUID_STR_LENGTH - 1) - { - mImagep = LLUI::sImageProvider->getImageByID(LLUUID(src)); - } + mLink = href; +} + +BOOL LLStyle::isLink() const +{ + return mLink.size(); +} + +BOOL LLStyle::isVisible() const +{ + return mVisible; +} + +void LLStyle::setVisible(BOOL is_visible) +{ + mVisible = is_visible; +} + +LLUIImagePtr LLStyle::getImage() const +{ + return mImagep; +} + +void LLStyle::setImage(const LLUUID& src) +{ + mImagep = LLUI::sImageProvider->getUIImageByID(src); } diff --git a/linden/indra/llui/llstyle.h b/linden/indra/llui/llstyle.h index d6ae900..6f0099c 100644 --- a/linden/indra/llui/llstyle.h +++ b/linden/indra/llui/llstyle.h @@ -35,7 +35,7 @@ #include "v4color.h" #include "llresmgr.h" #include "llfont.h" -#include "llimagegl.h" +#include "llui.h" class LLStyle { @@ -53,19 +53,20 @@ public: virtual const LLColor4& getColor() const { return mColor; } virtual void setColor(const LLColor4 &color) { mColor = color; } - virtual BOOL isVisible() const { return mVisible; } - virtual void setVisible(BOOL is_visible) { mVisible = is_visible; } + virtual BOOL isVisible() const; + virtual void setVisible(BOOL is_visible); virtual const LLString& getFontString() const { return mFontName; } virtual void setFontName(const LLString& fontname); virtual LLFONT_ID getFontID() const { return mFontID; } virtual const LLString& getLinkHREF() const { return mLink; } - virtual void setLinkHREF(const LLString& href) { mLink = href; } - virtual BOOL isLink() const { return mLink.size(); } + virtual void setLinkHREF(const LLString& href); + virtual BOOL isLink() const; + + virtual LLUIImagePtr getImage() const; + virtual void setImage(const LLUUID& src); - virtual LLImageGL *getImage() const { return mImagep; } - virtual void setImage(const LLString& src); virtual BOOL isImage() const { return ((mImageWidth != 0) && (mImageHeight != 0)); } virtual void setImageSize(S32 width, S32 height); @@ -106,7 +107,7 @@ private: LLString mFontName; LLFONT_ID mFontID; LLString mLink; - LLPointer mImagep; + LLUIImagePtr mImagep; BOOL mIsEmbeddedItem; }; diff --git a/linden/indra/llui/lltabcontainer.cpp b/linden/indra/llui/lltabcontainer.cpp index e632cf1..7f581dc 100644 --- a/linden/indra/llui/lltabcontainer.cpp +++ b/linden/indra/llui/lltabcontainer.cpp @@ -64,7 +64,7 @@ const S32 TABCNTRV_HEADER_HEIGHT = LLPANEL_BORDER_WIDTH + TABCNTRV_CLOSE_BTN_SIZ const S32 TABCNTRV_ARROW_BTN_SIZE = 16; const S32 TABCNTRV_PAD = 0; - +static LLRegisterWidget r("tab_container"); LLTabContainer::LLTabContainer(const LLString& name, const LLRect& rect, TabPosition pos, BOOL bordered, BOOL is_vertical ) @@ -115,18 +115,6 @@ void LLTabContainer::setValue(const LLSD& value) } //virtual -EWidgetType LLTabContainer::getWidgetType() const -{ - return WIDGET_TYPE_TAB_CONTAINER; -} - -//virtual -LLString LLTabContainer::getWidgetTag() const -{ - return LL_TAB_CONTAINER_COMMON_TAG; -} - -//virtual void LLTabContainer::reshape(S32 width, S32 height, BOOL called_from_parent) { LLPanel::reshape( width, height, called_from_parent ); @@ -134,7 +122,7 @@ void LLTabContainer::reshape(S32 width, S32 height, BOOL called_from_parent) } //virtual -LLView* LLTabContainer::getChildByName(const LLString& name, BOOL recurse) const +LLView* LLTabContainer::getChildView(const LLString& name, BOOL recurse, BOOL create_if_missing) const { tuple_list_t::const_iterator itor; for (itor = mTabList.begin(); itor != mTabList.end(); ++itor) @@ -145,19 +133,20 @@ LLView* LLTabContainer::getChildByName(const LLString& name, BOOL recurse) const return panel; } } + if (recurse) { for (itor = mTabList.begin(); itor != mTabList.end(); ++itor) { LLPanel *panel = (*itor)->mTabPanel; - LLView *child = panel->getChild(name, recurse); + LLView *child = panel->getChildView(name, recurse, FALSE); if (child) { return child; } } } - return LLView::getChildByName(name, recurse); + return LLView::getChildView(name, recurse, create_if_missing); } // virtual @@ -185,124 +174,122 @@ void LLTabContainer::draw() } setScrollPosPixels((S32)lerp((F32)getScrollPosPixels(), (F32)target_pixel_scroll, LLCriticalDamp::getInterpolant(0.08f))); - if( getVisible() ) + + BOOL has_scroll_arrows = (mMaxScrollPos > 0) || (mScrollPosPixels > 0); + if (!mIsVertical) { - BOOL has_scroll_arrows = (mMaxScrollPos > 0) || (mScrollPosPixels > 0); - if (!mIsVertical) - { - mJumpPrevArrowBtn->setVisible( has_scroll_arrows ); - mJumpNextArrowBtn->setVisible( has_scroll_arrows ); - } - mPrevArrowBtn->setVisible( has_scroll_arrows ); - mNextArrowBtn->setVisible( has_scroll_arrows ); + mJumpPrevArrowBtn->setVisible( has_scroll_arrows ); + mJumpNextArrowBtn->setVisible( has_scroll_arrows ); + } + mPrevArrowBtn->setVisible( has_scroll_arrows ); + mNextArrowBtn->setVisible( has_scroll_arrows ); - S32 left = 0, top = 0; - if (mIsVertical) - { - top = getRect().getHeight() - getTopBorderHeight() - LLPANEL_BORDER_WIDTH - 1 - (has_scroll_arrows ? TABCNTRV_ARROW_BTN_SIZE : 0); - top += getScrollPosPixels(); - } - else - { - // Set the leftmost position of the tab buttons. - left = LLPANEL_BORDER_WIDTH + (has_scroll_arrows ? (TABCNTR_ARROW_BTN_SIZE * 2) : TABCNTR_TAB_H_PAD); - left -= getScrollPosPixels(); - } - - // Hide all the buttons + S32 left = 0, top = 0; + if (mIsVertical) + { + top = getRect().getHeight() - getTopBorderHeight() - LLPANEL_BORDER_WIDTH - 1 - (has_scroll_arrows ? TABCNTRV_ARROW_BTN_SIZE : 0); + top += getScrollPosPixels(); + } + else + { + // Set the leftmost position of the tab buttons. + left = LLPANEL_BORDER_WIDTH + (has_scroll_arrows ? (TABCNTR_ARROW_BTN_SIZE * 2) : TABCNTR_TAB_H_PAD); + left -= getScrollPosPixels(); + } + + // Hide all the buttons + for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter) + { + LLTabTuple* tuple = *iter; + tuple->mButton->setVisible( FALSE ); + } + + LLPanel::draw(); + + // if tabs are hidden, don't draw them and leave them in the invisible state + if (!getTabsHidden()) + { + // Show all the buttons for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter) { LLTabTuple* tuple = *iter; - tuple->mButton->setVisible( FALSE ); + tuple->mButton->setVisible( TRUE ); } - LLPanel::draw(); - - // if tabs are hidden, don't draw them and leave them in the invisible state - if (!getTabsHidden()) + // Draw some of the buttons... + LLRect clip_rect = getLocalRect(); + if (has_scroll_arrows) { - // Show all the buttons - for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter) + // ...but clip them. + if (mIsVertical) { - LLTabTuple* tuple = *iter; - tuple->mButton->setVisible( TRUE ); + clip_rect.mBottom = mNextArrowBtn->getRect().mTop + 3*TABCNTRV_PAD; + clip_rect.mTop = mPrevArrowBtn->getRect().mBottom - 3*TABCNTRV_PAD; } - - // Draw some of the buttons... - LLRect clip_rect = getLocalRect(); - if (has_scroll_arrows) + else { - // ...but clip them. - if (mIsVertical) - { - clip_rect.mBottom = mNextArrowBtn->getRect().mTop + 3*TABCNTRV_PAD; - clip_rect.mTop = mPrevArrowBtn->getRect().mBottom - 3*TABCNTRV_PAD; - } - else - { - clip_rect.mLeft = mPrevArrowBtn->getRect().mRight; - clip_rect.mRight = mNextArrowBtn->getRect().mLeft; - } + clip_rect.mLeft = mPrevArrowBtn->getRect().mRight; + clip_rect.mRight = mNextArrowBtn->getRect().mLeft; } - LLLocalClipRect clip(clip_rect); + } + LLLocalClipRect clip(clip_rect); - S32 max_scroll_visible = getTabCount() - getMaxScrollPos() + getScrollPos(); - S32 idx = 0; - for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter) - { - LLTabTuple* tuple = *iter; + S32 max_scroll_visible = getTabCount() - getMaxScrollPos() + getScrollPos(); + S32 idx = 0; + for(tuple_list_t::iterator iter = mTabList.begin(); iter != mTabList.end(); ++iter) + { + LLTabTuple* tuple = *iter; - tuple->mButton->translate( left ? left - tuple->mButton->getRect().mLeft : 0, - top ? top - tuple->mButton->getRect().mTop : 0 ); - if (top) top -= BTN_HEIGHT + TABCNTRV_PAD; - if (left) left += tuple->mButton->getRect().getWidth(); + tuple->mButton->translate( left ? left - tuple->mButton->getRect().mLeft : 0, + top ? top - tuple->mButton->getRect().mTop : 0 ); + if (top) top -= BTN_HEIGHT + TABCNTRV_PAD; + if (left) left += tuple->mButton->getRect().getWidth(); - if (!mIsVertical) + if (!mIsVertical) + { + if( idx < getScrollPos() ) { - if( idx < getScrollPos() ) - { - if( tuple->mButton->getFlashing() ) - { - mPrevArrowBtn->setFlashing( TRUE ); - } - } - else if( max_scroll_visible < idx ) + if( tuple->mButton->getFlashing() ) { - if( tuple->mButton->getFlashing() ) - { - mNextArrowBtn->setFlashing( TRUE ); - } + mPrevArrowBtn->setFlashing( TRUE ); } } - LLUI::pushMatrix(); + else if( max_scroll_visible < idx ) { - LLUI::translate((F32)tuple->mButton->getRect().mLeft, (F32)tuple->mButton->getRect().mBottom, 0.f); - tuple->mButton->draw(); + if( tuple->mButton->getFlashing() ) + { + mNextArrowBtn->setFlashing( TRUE ); + } } - LLUI::popMatrix(); - - idx++; } - - - if( mIsVertical && has_scroll_arrows ) + LLUI::pushMatrix(); { - // Redraw the arrows so that they appears on top. - gGL.pushMatrix(); - gGL.translatef((F32)mPrevArrowBtn->getRect().mLeft, (F32)mPrevArrowBtn->getRect().mBottom, 0.f); - mPrevArrowBtn->draw(); - gGL.popMatrix(); - - gGL.pushMatrix(); - gGL.translatef((F32)mNextArrowBtn->getRect().mLeft, (F32)mNextArrowBtn->getRect().mBottom, 0.f); - mNextArrowBtn->draw(); - gGL.popMatrix(); + LLUI::translate((F32)tuple->mButton->getRect().mLeft, (F32)tuple->mButton->getRect().mBottom, 0.f); + tuple->mButton->draw(); } + LLUI::popMatrix(); + + idx++; } - mPrevArrowBtn->setFlashing(FALSE); - mNextArrowBtn->setFlashing(FALSE); + + if( mIsVertical && has_scroll_arrows ) + { + // Redraw the arrows so that they appears on top. + gGL.pushMatrix(); + gGL.translatef((F32)mPrevArrowBtn->getRect().mLeft, (F32)mPrevArrowBtn->getRect().mBottom, 0.f); + mPrevArrowBtn->draw(); + gGL.popMatrix(); + + gGL.pushMatrix(); + gGL.translatef((F32)mNextArrowBtn->getRect().mLeft, (F32)mNextArrowBtn->getRect().mBottom, 0.f); + mNextArrowBtn->draw(); + gGL.popMatrix(); + } } + + mPrevArrowBtn->setFlashing(FALSE); + mNextArrowBtn->setFlashing(FALSE); } @@ -524,12 +511,8 @@ BOOL LLTabContainer::handleToolTip( S32 x, S32 y, LLString& msg, LLRect* sticky_ } // virtual -BOOL LLTabContainer::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLTabContainer::handleKeyHere(KEY key, MASK mask) { - if (!getEnabled()) return FALSE; - - if (!gFocusMgr.childHasKeyboardFocus(this)) return FALSE; - BOOL handled = FALSE; if (key == KEY_LEFT && mask == MASK_ALT) { @@ -687,7 +670,7 @@ void LLTabContainer::addTabPanel(LLPanel* child, // already a child of mine return; } - const LLFontGL* font = gResMgr->getRes( mIsVertical ? LLFONT_SANSSERIF : LLFONT_SANSSERIF_SMALL ); + const LLFontGL* font = LLResMgr::getInstance()->getRes( mIsVertical ? LLFONT_SANSSERIF : LLFONT_SANSSERIF_SMALL ); // Store the original label for possible xml export. child->setLabel(label); @@ -1272,7 +1255,7 @@ void LLTabContainer::setTabImage(LLPanel* child, std::string image_name, const L if (!mIsVertical) { - const LLFontGL* fontp = gResMgr->getRes( LLFONT_SANSSERIF_SMALL ); + const LLFontGL* fontp = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); // remove current width from total tab strip width mTotalTabWidth -= tuple->mButton->getRect().getWidth(); @@ -1353,7 +1336,7 @@ void LLTabContainer::setPanelTitle(S32 index, const LLString& title) { LLTabTuple* tuple = getTab(index); LLButton* tab_button = tuple->mButton; - const LLFontGL* fontp = gResMgr->getRes( LLFONT_SANSSERIF_SMALL ); + const LLFontGL* fontp = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); mTotalTabWidth -= tab_button->getRect().getWidth(); tab_button->reshape(llclamp(fontp->getWidth(title) + TAB_PADDING + tuple->mPadding, mMinTabWidth, mMaxTabWidth), tab_button->getRect().getHeight()); mTotalTabWidth += tab_button->getRect().getWidth(); diff --git a/linden/indra/llui/lltabcontainer.h b/linden/indra/llui/lltabcontainer.h index 152bd05..16f8be5 100644 --- a/linden/indra/llui/lltabcontainer.h +++ b/linden/indra/llui/lltabcontainer.h @@ -62,19 +62,19 @@ public: // from LLView /*virtual*/ void setValue(const LLSD& value); - /*virtual*/ EWidgetType getWidgetType() const; - /*virtual*/ LLString getWidgetTag() const; + /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); /*virtual*/ void draw(); /*virtual*/ BOOL handleMouseDown( S32 x, S32 y, MASK mask ); /*virtual*/ BOOL handleHover( S32 x, S32 y, MASK mask ); /*virtual*/ BOOL handleMouseUp( S32 x, S32 y, MASK mask ); /*virtual*/ BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect ); - /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); + /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask); /*virtual*/ BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType type, void* cargo_data, EAcceptance* accept, LLString& tooltip); /*virtual*/ LLXMLNodePtr getXML(bool save_children = true) const; + /*virtual*/ LLView* getChildView(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; void addTabPanel(LLPanel* child, const LLString& label, @@ -142,10 +142,6 @@ public: static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); -protected: - /*virtual*/ LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const; - - private: // Structure used to map tab buttons to and from tab panels struct LLTabTuple diff --git a/linden/indra/llui/lltextbox.cpp b/linden/indra/llui/lltextbox.cpp index 9ad7849..0f411b8 100644 --- a/linden/indra/llui/lltextbox.cpp +++ b/linden/indra/llui/lltextbox.cpp @@ -34,6 +34,8 @@ #include "lluictrlfactory.h" #include "llfocusmgr.h" +static LLRegisterWidget r("text"); + LLTextBox::LLTextBox(const LLString& name, const LLRect& rect, const LLString& text, const LLFontGL* font, BOOL mouse_opaque) : LLUICtrl(name, rect, mouse_opaque, NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP ), @@ -212,7 +214,7 @@ void LLTextBox::setLineLengths() LLString::size_type cur = 0; LLString::size_type len = mText.getWString().size(); - while (cur < len) + while (cur < len) { LLString::size_type end = mText.getWString().find('\n', cur); LLString::size_type runLen; @@ -323,63 +325,60 @@ BOOL LLTextBox::setTextArg( const LLString& key, const LLStringExplicit& text ) void LLTextBox::draw() { - if( getVisible() ) + if (mBorderVisible) { - if (mBorderVisible) - { - gl_rect_2d_offset_local(getLocalRect(), 2, FALSE); - } + gl_rect_2d_offset_local(getLocalRect(), 2, FALSE); + } - if( mBorderDropShadowVisible ) - { - static LLColor4 color_drop_shadow = LLUI::sColorsGroup->getColor("ColorDropShadow"); - static S32 drop_shadow_tooltip = LLUI::sConfigGroup->getS32("DropShadowTooltip"); - gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0, - color_drop_shadow, drop_shadow_tooltip); - } - - if (mBackgroundVisible) - { - LLRect r( 0, getRect().getHeight(), getRect().getWidth(), 0 ); - gl_rect_2d( r, mBackgroundColor ); - } + if( mBorderDropShadowVisible ) + { + static LLColor4 color_drop_shadow = LLUI::sColorsGroup->getColor("ColorDropShadow"); + static S32 drop_shadow_tooltip = LLUI::sConfigGroup->getS32("DropShadowTooltip"); + gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0, + color_drop_shadow, drop_shadow_tooltip); + } - S32 text_x = 0; - switch( mHAlign ) - { - case LLFontGL::LEFT: - text_x = mHPad; - break; - case LLFontGL::HCENTER: - text_x = getRect().getWidth() / 2; - break; - case LLFontGL::RIGHT: - text_x = getRect().getWidth() - mHPad; - break; - } + if (mBackgroundVisible) + { + LLRect r( 0, getRect().getHeight(), getRect().getWidth(), 0 ); + gl_rect_2d( r, mBackgroundColor ); + } - S32 text_y = getRect().getHeight() - mVPad; + S32 text_x = 0; + switch( mHAlign ) + { + case LLFontGL::LEFT: + text_x = mHPad; + break; + case LLFontGL::HCENTER: + text_x = getRect().getWidth() / 2; + break; + case LLFontGL::RIGHT: + text_x = getRect().getWidth() - mHPad; + break; + } - if ( getEnabled() ) + S32 text_y = getRect().getHeight() - mVPad; + + if ( getEnabled() ) + { + if(mHasHover) { - if(mHasHover) - { - drawText( text_x, text_y, mHoverColor ); - } - else - { - drawText( text_x, text_y, mTextColor ); - } + drawText( text_x, text_y, mHoverColor ); } else { - drawText( text_x, text_y, mDisabledColor ); - } + drawText( text_x, text_y, mTextColor ); + } + } + else + { + drawText( text_x, text_y, mDisabledColor ); + } - if (sDebugRects) - { - drawDebugRect(); - } + if (sDebugRects) + { + drawDebugRect(); } mHasHover = FALSE; // This is reset every frame. diff --git a/linden/indra/llui/lltextbox.h b/linden/indra/llui/lltextbox.h index 7bea722..ffe6f4c 100644 --- a/linden/indra/llui/lltextbox.h +++ b/linden/indra/llui/lltextbox.h @@ -57,8 +57,7 @@ public: LLTextBox(const LLString& name_and_label); virtual ~LLTextBox() {} - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_TEXT_BOX; } - virtual LLString getWidgetTag() const { return LL_TEXT_BOX_TAG; } + virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory); diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 545fddb..4ed936f 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -64,6 +64,8 @@ // // Globals // +static LLRegisterWidget r("simple_text_editor"); + BOOL gDebugTextEditorTips = FALSE; // @@ -304,10 +306,10 @@ LLTextEditor::LLTextEditor( // Init the scrollbar LLRect scroll_rect; scroll_rect.setOriginAndSize( - getRect().getWidth() - UI_TEXTEDITOR_BORDER - SCROLLBAR_SIZE, - UI_TEXTEDITOR_BORDER, + getRect().getWidth() - SCROLLBAR_SIZE, + 1, SCROLLBAR_SIZE, - getRect().getHeight() - 2 * UI_TEXTEDITOR_BORDER ); + getRect().getHeight() - 1); S32 lines_in_doc = getLineCount(); mScrollbar = new LLScrollbar( "Scrollbar", scroll_rect, LLScrollbar::VERTICAL, @@ -1102,14 +1104,7 @@ BOOL LLTextEditor::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rec BOOL LLTextEditor::handleScrollWheel(S32 x, S32 y, S32 clicks) { // Pretend the mouse is over the scrollbar - if (getVisible()) - { - return mScrollbar->handleScrollWheel( 0, 0, clicks ); - } - else - { - return FALSE; - } + return mScrollbar->handleScrollWheel( 0, 0, clicks ); } BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) @@ -1197,91 +1192,88 @@ BOOL LLTextEditor::handleHover(S32 x, S32 y, MASK mask) BOOL handled = FALSE; mHoverSegment = NULL; - if( getVisible() ) + if(hasMouseCapture() ) { - if(hasMouseCapture() ) + if( mIsSelecting ) { - if( mIsSelecting ) + if (x != mLastSelectionX || y != mLastSelectionY) { - if (x != mLastSelectionX || y != mLastSelectionY) - { - mLastSelectionX = x; - mLastSelectionY = y; - } + mLastSelectionX = x; + mLastSelectionY = y; + } - if( y > mTextRect.mTop ) + if( y > mTextRect.mTop ) + { + mScrollbar->setDocPos( mScrollbar->getDocPos() - 1 ); + } + else + if( y < mTextRect.mBottom ) + { + mScrollbar->setDocPos( mScrollbar->getDocPos() + 1 ); + } + + setCursorAtLocalPos( x, y, TRUE ); + mSelectionEnd = mCursorPos; + + updateScrollFromCursor(); + } + + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; + getWindow()->setCursor(UI_CURSOR_IBEAM); + handled = TRUE; + } + + if( !handled ) + { + // Pass to children + handled = LLView::childrenHandleHover(x, y, mask) != NULL; + } + + if( handled ) + { + // Delay cursor flashing + resetKeystrokeTimer(); + } + + // Opaque + if( !handled && mTakesNonScrollClicks) + { + // Check to see if we're over an HTML-style link + if( !mSegments.empty() ) + { + const LLTextSegment* cur_segment = getSegmentAtLocalPos( x, y ); + if( cur_segment ) + { + if(cur_segment->getStyle().isLink()) { - mScrollbar->setDocPos( mScrollbar->getDocPos() - 1 ); + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (over link, inactive)" << llendl; + getWindow()->setCursor(UI_CURSOR_HAND); + handled = TRUE; } else - if( y < mTextRect.mBottom ) + if(cur_segment->getStyle().getIsEmbeddedItem()) { - mScrollbar->setDocPos( mScrollbar->getDocPos() + 1 ); + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (over embedded item, inactive)" << llendl; + getWindow()->setCursor(UI_CURSOR_HAND); + //getWindow()->setCursor(UI_CURSOR_ARROW); + handled = TRUE; } - - setCursorAtLocalPos( x, y, TRUE ); - mSelectionEnd = mCursorPos; - - updateScrollFromCursor(); + mHoverSegment = cur_segment; } - - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; - getWindow()->setCursor(UI_CURSOR_IBEAM); - handled = TRUE; } if( !handled ) { - // Pass to children - handled = LLView::childrenHandleHover(x, y, mask) != NULL; - } - - if( handled ) - { - // Delay cursor flashing - resetKeystrokeTimer(); - } - - // Opaque - if( !handled && mTakesNonScrollClicks) - { - // Check to see if we're over an HTML-style link - if( !mSegments.empty() ) + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; + if (!mScrollbar->getVisible() || x < getRect().getWidth() - SCROLLBAR_SIZE) { - const LLTextSegment* cur_segment = getSegmentAtLocalPos( x, y ); - if( cur_segment ) - { - if(cur_segment->getStyle().isLink()) - { - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (over link, inactive)" << llendl; - getWindow()->setCursor(UI_CURSOR_HAND); - handled = TRUE; - } - else - if(cur_segment->getStyle().getIsEmbeddedItem()) - { - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (over embedded item, inactive)" << llendl; - getWindow()->setCursor(UI_CURSOR_HAND); - //getWindow()->setCursor(UI_CURSOR_ARROW); - handled = TRUE; - } - mHoverSegment = cur_segment; - } + getWindow()->setCursor(UI_CURSOR_IBEAM); } - - if( !handled ) + else { - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; - if (!mScrollbar->getVisible() || x < getRect().getWidth() - SCROLLBAR_SIZE) - { - getWindow()->setCursor(UI_CURSOR_IBEAM); - } - else - { - getWindow()->setCursor(UI_CURSOR_ARROW); - } - handled = TRUE; + getWindow()->setCursor(UI_CURSOR_ARROW); } + handled = TRUE; } } @@ -2154,14 +2146,14 @@ void LLTextEditor::unindentLineBeforeCloseBrace() } -BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) +BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask ) { BOOL handled = FALSE; BOOL selection_modified = FALSE; BOOL return_key_hit = FALSE; BOOL text_may_have_changed = TRUE; - if ( (gFocusMgr.getKeyboardFocus() == this) && getVisible()) + if ( gFocusMgr.getKeyboardFocus() == this ) { // Special case for TAB. If want to move to next field, report // not handled and let the parent take care of field movement. @@ -2245,7 +2237,7 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) } -BOOL LLTextEditor::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) +BOOL LLTextEditor::handleUnicodeCharHere(llwchar uni_char) { if ((uni_char < 0x20) || (uni_char == 0x7F)) // Control character or DEL { @@ -2254,7 +2246,7 @@ BOOL LLTextEditor::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_pare BOOL handled = FALSE; - if ( (gFocusMgr.getKeyboardFocus() == this) && getVisible()) + if ( gFocusMgr.getKeyboardFocus() == this ) { // Handle most keys only if the text editor is writeable. if( !mReadOnly ) @@ -2939,8 +2931,8 @@ void LLTextEditor::drawText() LLStyle style = cur_segment->getStyle(); if ( style.isImage() && (cur_segment->getStart() >= seg_start) && (cur_segment->getStart() <= clipped_end)) { - LLImageGL *image = style.getImage(); - gl_draw_scaled_image( llround(text_x), llround(text_y)+line_height-style.mImageHeight, style.mImageWidth, style.mImageHeight, image, LLColor4::white ); + LLUIImagePtr image = style.getImage(); + image->draw(llround(text_x), llround(text_y)+line_height-style.mImageHeight, style.mImageWidth, style.mImageHeight); } if (cur_segment == mHoverSegment && style.getIsEmbeddedItem()) @@ -2984,7 +2976,7 @@ void LLTextEditor::drawClippedSegment(const LLWString &text, S32 seg_start, S32 if ( style.getFontString()[0] ) { - font = gResMgr->getRes(style.getFontID()); + font = LLResMgr::getInstance()->getRes(style.getFontID()); } U8 font_flags = LLFontGL::NORMAL; @@ -3051,10 +3043,6 @@ void LLTextEditor::drawClippedSegment(const LLWString &text, S32 seg_start, S32 void LLTextEditor::draw() { - if( !getVisible() ) - { - return; - } { LLLocalClipRect clip(LLRect(0, getRect().getHeight(), getRect().getWidth() - (mScrollbar->getVisible() ? SCROLLBAR_SIZE : 0), 0)); diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 7943129..54a34cc 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -71,9 +71,6 @@ public: virtual ~LLTextEditor(); - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_TEXT_EDITOR; } - virtual LLString getWidgetTag() const { return LL_TEXT_EDITOR_TAG; } - virtual LLXMLNodePtr getXML(bool save_children = true) const; static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory); void setTextEditorParameters(LLXMLNodePtr node); @@ -85,8 +82,8 @@ public: virtual BOOL handleHover(S32 x, S32 y, MASK mask); virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask ); - virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ); - virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); + virtual BOOL handleKeyHere(KEY key, MASK mask ); + virtual BOOL handleUnicodeCharHere(llwchar uni_char); virtual BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, diff --git a/linden/indra/llui/llui.cpp b/linden/indra/llui/llui.cpp index ec8c94e..aafd3af 100644 --- a/linden/indra/llui/llui.cpp +++ b/linden/indra/llui/llui.cpp @@ -55,6 +55,7 @@ //#include "llstartup.h" #include "llui.h" #include "llview.h" +#include "lllineeditor.h" #include "llwindow.h" #include "llglheaders.h" @@ -73,7 +74,6 @@ std::list gUntranslated; LLControlGroup* LLUI::sConfigGroup = NULL; LLControlGroup* LLUI::sColorsGroup = NULL; -LLControlGroup* LLUI::sAssetsGroup = NULL; LLImageProviderInterface* LLUI::sImageProvider = NULL; LLUIAudioCallback LLUI::sAudioCallback = NULL; LLVector2 LLUI::sGLScaleFactor(1.f, 1.f); @@ -321,7 +321,7 @@ void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &st void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2 ) { // Work around bug in ATI driver: vertical lines are offset by (-1,-1) - if( gGLManager.mATIOffsetVerticalLines && (x1 == x2) ) + if( (x1 == x2) && gGLManager.mATIOffsetVerticalLines ) { x1++; x2++; @@ -340,7 +340,7 @@ void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2 ) void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color ) { // Work around bug in ATI driver: vertical lines are offset by (-1,-1) - if( gGLManager.mATIOffsetVerticalLines && (x1 == x2) ) + if( (x1 == x2) && gGLManager.mATIOffsetVerticalLines ) { x1++; x2++; @@ -458,24 +458,30 @@ void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLIma return; } - // scale screen size of borders down - LLRectf clipped_scale_rect = uv_rect; - clipped_scale_rect.intersectWith(scale_rect); + // shrink scaling region to be proportional to clipped image region + LLRectf scale_rect_uv( + uv_rect.mLeft + (scale_rect.mLeft * uv_rect.getWidth()), + uv_rect.mBottom + (scale_rect.mTop * uv_rect.getHeight()), + uv_rect.mLeft + (scale_rect.mRight * uv_rect.getWidth()), + uv_rect.mBottom + (scale_rect.mBottom * uv_rect.getHeight())); + + S32 image_natural_width = llround((F32)image->getWidth(0) * uv_rect.getWidth()); + S32 image_natural_height = llround((F32)image->getHeight(0) * uv_rect.getHeight()); LLRect draw_rect(0, height, width, 0); - LLRect draw_scale_rect(llround((F32)image->getWidth() * scale_rect.mLeft), - llround((F32)image->getHeight() * scale_rect.mTop), - llround((F32)image->getWidth() * scale_rect.mRight), - llround((F32)image->getHeight() * scale_rect.mBottom)); - // scale fixed region of image up with drawn region - draw_scale_rect.mRight += width - image->getWidth(); - draw_scale_rect.mTop += height - image->getHeight(); + LLRect draw_scale_rect(llround(scale_rect_uv.mLeft * (F32)image->getWidth(0)), + llround(scale_rect_uv.mTop * (F32)image->getHeight(0)), + llround(scale_rect_uv.mRight * (F32)image->getWidth(0)), + llround(scale_rect_uv.mBottom * (F32)image->getHeight(0))); + // scale fixed region of image to drawn region + draw_scale_rect.mRight += width - image_natural_width; + draw_scale_rect.mTop += height - image_natural_height; S32 border_shrink_width = llmax(0, draw_scale_rect.mLeft - draw_scale_rect.mRight); S32 border_shrink_height = llmax(0, draw_scale_rect.mBottom - draw_scale_rect.mTop); - F32 shrink_width_ratio = scale_rect.getWidth() == 1.f ? 0.f : border_shrink_width / ((F32)image->getWidth() * (1.f - scale_rect.getWidth())); - F32 shrink_height_ratio = scale_rect.getHeight() == 1.f ? 0.f : border_shrink_height / ((F32)image->getHeight() * (1.f - scale_rect.getHeight())); + F32 shrink_width_ratio = scale_rect.getWidth() == 1.f ? 0.f : border_shrink_width / ((F32)image_natural_width * (1.f - scale_rect.getWidth())); + F32 shrink_height_ratio = scale_rect.getHeight() == 1.f ? 0.f : border_shrink_height / ((F32)image_natural_height * (1.f - scale_rect.getHeight())); F32 shrink_scale = 1.f - llmax(shrink_width_ratio, shrink_height_ratio); draw_scale_rect.mLeft = llround((F32)draw_scale_rect.mLeft * shrink_scale); @@ -515,117 +521,117 @@ void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLIma gGL.texCoord2f(uv_rect.mLeft, uv_rect.mBottom); gGL.vertex2i(0, 0); - gGL.texCoord2f(clipped_scale_rect.mLeft, uv_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, 0); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom); - gGL.texCoord2f(uv_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(0, draw_scale_rect.mBottom); // draw bottom middle - gGL.texCoord2f(clipped_scale_rect.mLeft, uv_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, 0); - gGL.texCoord2f(clipped_scale_rect.mRight, uv_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mBottom); gGL.vertex2i(draw_scale_rect.mRight, 0); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom); // draw bottom right - gGL.texCoord2f(clipped_scale_rect.mRight, uv_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mBottom); gGL.vertex2i(draw_scale_rect.mRight, 0); gGL.texCoord2f(uv_rect.mRight, uv_rect.mBottom); gGL.vertex2i(width, 0); - gGL.texCoord2f(uv_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mBottom); gGL.vertex2i(width, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom); // draw left - gGL.texCoord2f(uv_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(0, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop); - gGL.texCoord2f(uv_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mTop); gGL.vertex2i(0, draw_scale_rect.mTop); // draw middle - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop); // draw right - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom); - gGL.texCoord2f(uv_rect.mRight, clipped_scale_rect.mBottom); + gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mBottom); gGL.vertex2i(width, draw_scale_rect.mBottom); - gGL.texCoord2f(uv_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mTop); gGL.vertex2i(width, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop); // draw top left - gGL.texCoord2f(uv_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mTop); gGL.vertex2i(0, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mLeft, uv_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mTop); gGL.vertex2i(draw_scale_rect.mLeft, height); gGL.texCoord2f(uv_rect.mLeft, uv_rect.mTop); gGL.vertex2i(0, height); // draw top middle - gGL.texCoord2f(clipped_scale_rect.mLeft, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop); - gGL.texCoord2f(clipped_scale_rect.mRight, uv_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mTop); gGL.vertex2i(draw_scale_rect.mRight, height); - gGL.texCoord2f(clipped_scale_rect.mLeft, uv_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mTop); gGL.vertex2i(draw_scale_rect.mLeft, height); // draw top right - gGL.texCoord2f(clipped_scale_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop); gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop); - gGL.texCoord2f(uv_rect.mRight, clipped_scale_rect.mTop); + gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mTop); gGL.vertex2i(width, draw_scale_rect.mTop); gGL.texCoord2f(uv_rect.mRight, uv_rect.mTop); gGL.vertex2i(width, height); - gGL.texCoord2f(clipped_scale_rect.mRight, uv_rect.mTop); + gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mTop); gGL.vertex2i(draw_scale_rect.mRight, height); } gGL.end(); @@ -1556,20 +1562,14 @@ void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale, const LLVector3 gl_segmented_rect_3d_tex(border_scale, border_width, border_height, width_vec, height_vec, ROUNDED_RECT_TOP); } -class LLShowXUINamesListener: public LLSimpleListener +bool handleShowXUINamesChanged(const LLSD& newvalue) { - bool handleEvent(LLPointer event, const LLSD& userdata) - { - LLUI::sShowXUINames = (BOOL) event->getValue().asBoolean(); - return true; - } -}; -static LLShowXUINamesListener show_xui_names_listener; - + LLUI::sShowXUINames = newvalue.asBoolean(); + return true; +} void LLUI::initClass(LLControlGroup* config, LLControlGroup* colors, - LLControlGroup* assets, LLImageProviderInterface* image_provider, LLUIAudioCallback audio_callback, const LLVector2* scale_factor, @@ -1577,7 +1577,6 @@ void LLUI::initClass(LLControlGroup* config, { sConfigGroup = config; sColorsGroup = colors; - sAssetsGroup = assets; sImageProvider = image_provider; sAudioCallback = audio_callback; sGLScaleFactor = (scale_factor == NULL) ? LLVector2(1.f, 1.f) : *scale_factor; @@ -1585,11 +1584,13 @@ void LLUI::initClass(LLControlGroup* config, LLFontGL::sShadowColor = colors->getColor("ColorDropShadow"); LLUI::sShowXUINames = LLUI::sConfigGroup->getBOOL("ShowXUINames"); - LLUI::sConfigGroup->getControl("ShowXUINames")->addListener(&show_xui_names_listener); + LLUI::sConfigGroup->getControl("ShowXUINames")->getSignal()->connect(boost::bind(&handleShowXUINamesChanged, _1)); } void LLUI::cleanupClass() { + sImageProvider->cleanUp(); + LLLineEditor::cleanupClass(); } @@ -1732,28 +1733,15 @@ void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen) glPointToScreen(gl.mRight, gl.mBottom, &screen->mRight, &screen->mBottom); } -//static -LLUUID LLUI::findAssetUUIDByName(const LLString &asset_name) -{ - if(asset_name == LLString::null) return LLUUID::null; - LLString foundValue = LLUI::sConfigGroup->findString(asset_name); - if(foundValue==LLString::null) - { - foundValue = LLUI::sAssetsGroup->findString(asset_name); - } - if(foundValue == LLString::null){ - return LLUUID::null; - } - return LLUUID( foundValue ); -} - //static -LLUIImage* LLUI::getUIImageByName(const LLString& name) +LLUIImage* LLUI::getUIImage(const LLString& name) { - return sImageProvider->getUIImageByID(findAssetUUIDByName(name)); + if (!name.empty()) + return sImageProvider->getUIImage(name); + else + return NULL; } - // static void LLUI::setHtmlHelp(LLHtmlHelp* html_help) { @@ -1834,7 +1822,8 @@ LLLocalClipRect::LLLocalClipRect(const LLRect &rect, BOOL enabled) // LLUIImage // -LLUIImage::LLUIImage(LLPointer image) : +LLUIImage::LLUIImage(const LLString& name, LLPointer image) : + mName(name), mImage(image), mScaleRegion(0.f, 1.f, 1.f, 0.f), mClipRegion(0.f, 1.f, 1.f, 0.f), @@ -1898,24 +1887,32 @@ void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& c mScaleRegion); } -void LLUIImage::drawSolid(S32 x, S32 y, const LLColor4& color) const +void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const { - gl_draw_scaled_image_with_border( - x, y, - getWidth(), getHeight(), - mImage, - color, - TRUE, - mClipRegion, - mScaleRegion); + LLRect border_rect; + border_rect.setOriginAndSize(x, y, width, height); + border_rect.stretch(border_width, border_width); + drawSolid(border_rect, color); } S32 LLUIImage::getWidth() const { - return mImage->getWidth(0); + // return clipped dimensions of actual image area + return llround((F32)mImage->getWidth(0) * mClipRegion.getWidth()); } S32 LLUIImage::getHeight() const { - return mImage->getHeight(0); + // return clipped dimensions of actual image area + return llround((F32)mImage->getHeight(0) * mClipRegion.getHeight()); +} + +S32 LLUIImage::getTextureWidth() const +{ + return mImage->getWidth(0); +} + +S32 LLUIImage::getTextureHeight() const +{ + return mImage->getHeight(0); } diff --git a/linden/indra/llui/llui.h b/linden/indra/llui/llui.h index 9e275a5..0b06913 100644 --- a/linden/indra/llui/llui.h +++ b/linden/indra/llui/llui.h @@ -161,7 +161,6 @@ public: // static void initClass(LLControlGroup* config, LLControlGroup* colors, - LLControlGroup* assets, LLImageProviderInterface* image_provider, LLUIAudioCallback audio_callback = NULL, const LLVector2 *scale_factor = NULL, @@ -179,8 +178,7 @@ public: static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y); static void setScaleFactor(const LLVector2& scale_factor); static void setLineWidth(F32 width); - static LLUUID findAssetUUIDByName(const LLString& name); - static LLUIImage* getUIImageByName(const LLString& name); + static LLUIImage* getUIImage(const LLString& name); static LLVector2 getWindowSize(); static void screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y); static void glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y); @@ -193,7 +191,6 @@ public: // static LLControlGroup* sConfigGroup; static LLControlGroup* sColorsGroup; - static LLControlGroup* sAssetsGroup; static LLImageProviderInterface* sImageProvider; static LLUIAudioCallback sAudioCallback; static LLVector2 sGLScaleFactor; @@ -209,101 +206,6 @@ public: }; -// UI widgets -// This MUST match UICtrlNames in lluictrlfactory.cpp -typedef enum e_widget_type -{ - WIDGET_TYPE_VIEW = 0, - WIDGET_TYPE_ROOT_VIEW, - WIDGET_TYPE_FLOATER_VIEW, - WIDGET_TYPE_BUTTON, - WIDGET_TYPE_JOYSTICK_TURN, - WIDGET_TYPE_JOYSTICK_SLIDE, - WIDGET_TYPE_CHECKBOX, - WIDGET_TYPE_COLOR_SWATCH, - WIDGET_TYPE_COMBO_BOX, - WIDGET_TYPE_LINE_EDITOR, - WIDGET_TYPE_SEARCH_EDITOR, - WIDGET_TYPE_SCROLL_LIST, - WIDGET_TYPE_NAME_LIST, - WIDGET_TYPE_WEBBROWSER, - WIDGET_TYPE_SLIDER, // actually LLSliderCtrl - WIDGET_TYPE_SLIDER_BAR, // actually LLSlider - WIDGET_TYPE_VOLUME_SLIDER,//actually LLVolumeSliderCtrl - WIDGET_TYPE_MULTI_SLIDER, // actually LLMultiSliderCtrl - WIDGET_TYPE_MULTI_SLIDER_BAR, // actually LLMultiSlider - WIDGET_TYPE_SPINNER, - WIDGET_TYPE_TEXT_EDITOR, - WIDGET_TYPE_TEXTURE_PICKER, - WIDGET_TYPE_TEXT_BOX, - WIDGET_TYPE_PAD, // used in XML for positioning, not a real widget - WIDGET_TYPE_RADIO_GROUP, - WIDGET_TYPE_ICON, - WIDGET_TYPE_LANDMARK_PICKER, - WIDGET_TYPE_LOCATE, // used in XML for positioning, not a real widget - WIDGET_TYPE_VIEW_BORDER, // decorative border - WIDGET_TYPE_PANEL, - WIDGET_TYPE_MENU, - WIDGET_TYPE_PIE_MENU, - WIDGET_TYPE_PIE_MENU_BRANCH, - WIDGET_TYPE_MENU_ITEM, - WIDGET_TYPE_MENU_ITEM_SEPARATOR, - WIDGET_TYPE_MENU_SEPARATOR_VERTICAL, - WIDGET_TYPE_MENU_ITEM_CALL, - WIDGET_TYPE_MENU_ITEM_CHECK, - WIDGET_TYPE_MENU_ITEM_BRANCH, - WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN, - WIDGET_TYPE_MENU_ITEM_BLANK, - WIDGET_TYPE_TEAROFF_MENU, - WIDGET_TYPE_MENU_BAR, - WIDGET_TYPE_TAB_CONTAINER, - WIDGET_TYPE_SCROLL_CONTAINER, // LLScrollableContainerView - WIDGET_TYPE_SCROLLBAR, - WIDGET_TYPE_INVENTORY_PANEL, // LLInventoryPanel - WIDGET_TYPE_FLOATER, - WIDGET_TYPE_DRAG_HANDLE_TOP, - WIDGET_TYPE_DRAG_HANDLE_LEFT, - WIDGET_TYPE_RESIZE_HANDLE, - WIDGET_TYPE_RESIZE_BAR, - WIDGET_TYPE_NAME_EDITOR, - WIDGET_TYPE_MULTI_FLOATER, - WIDGET_TYPE_MEDIA_REMOTE, - WIDGET_TYPE_FOLDER_VIEW, - WIDGET_TYPE_FOLDER_ITEM, - WIDGET_TYPE_FOLDER, - WIDGET_TYPE_STAT_GRAPH, - WIDGET_TYPE_STAT_VIEW, - WIDGET_TYPE_STAT_BAR, - WIDGET_TYPE_DROP_TARGET, - WIDGET_TYPE_TEXTURE_BAR, - WIDGET_TYPE_TEX_MEM_BAR, - WIDGET_TYPE_SNAPSHOT_LIVE_PREVIEW, - WIDGET_TYPE_STATUS_BAR, - WIDGET_TYPE_PROGRESS_VIEW, - WIDGET_TYPE_TALK_VIEW, - WIDGET_TYPE_OVERLAY_BAR, - WIDGET_TYPE_HUD_VIEW, - WIDGET_TYPE_HOVER_VIEW, - WIDGET_TYPE_MORPH_VIEW, - WIDGET_TYPE_NET_MAP, - WIDGET_TYPE_PERMISSIONS_VIEW, - WIDGET_TYPE_MENU_HOLDER, - WIDGET_TYPE_DEBUG_VIEW, - WIDGET_TYPE_SCROLLING_PANEL_LIST, - WIDGET_TYPE_AUDIO_STATUS, - WIDGET_TYPE_CONTAINER_VIEW, - WIDGET_TYPE_CONSOLE, - WIDGET_TYPE_FAST_TIMER_VIEW, - WIDGET_TYPE_VELOCITY_BAR, - WIDGET_TYPE_TEXTURE_VIEW, - WIDGET_TYPE_MEMORY_VIEW, - WIDGET_TYPE_FRAME_STAT_VIEW, - WIDGET_TYPE_LAYOUT_STACK, - WIDGET_TYPE_FLYOUT_BUTTON, - WIDGET_TYPE_DONTCARE, - WIDGET_TYPE_COUNT -} EWidgetType; - // FactoryPolicy is a static class that controls the creation and lookup of UI elements, // such as floaters. // The key parameter is used to provide a unique identifier and/or associated construction @@ -509,7 +411,7 @@ public: class LLUIImage : public LLRefCount { public: - LLUIImage(LLPointer image); + LLUIImage(const LLString& name, LLPointer image); void setClipRegion(const LLRectf& region); void setScaleRegion(const LLRectf& region); @@ -517,15 +419,29 @@ public: LLPointer getImage() { return mImage; } const LLPointer& getImage() const { return mImage; } - void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const; void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const; + void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const; + void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } + void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const; - void drawSolid(S32 x, S32 y, const LLColor4& color) const; + void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } + void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, mImage->getWidth(0), mImage->getHeight(0), color); } + + void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const; + void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); } + void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, mImage->getWidth(0), mImage->getHeight(0), color, border_width); } + + const LLString& getName() const { return mName; } S32 getWidth() const; S32 getHeight() const; + // returns dimensions of underlying textures, which might not be equal to ui image portion + S32 getTextureWidth() const; + S32 getTextureHeight() const; + protected: + LLString mName; LLRectf mScaleRegion; LLRectf mClipRegion; LLPointer mImage; @@ -533,6 +449,7 @@ protected: BOOL mNoClip; }; +typedef LLPointer LLUIImagePtr; template class LLTombStone : public LLRefCount @@ -667,6 +584,7 @@ private: LLRootHandle mHandle; }; + //RN: maybe this needs to moved elsewhere? class LLImageProviderInterface { @@ -674,8 +592,9 @@ public: LLImageProviderInterface() {}; virtual ~LLImageProviderInterface() {}; - virtual LLUIImage* getUIImageByID(const LLUUID& id, BOOL clamped = TRUE) = 0; - virtual LLImageGL* getImageByID(const LLUUID& id, BOOL clamped = TRUE) = 0; + virtual LLUIImagePtr getUIImage(const LLString& name) = 0; + virtual LLUIImagePtr getUIImageByID(const LLUUID& id) = 0; + virtual void cleanUp() = 0; }; #endif diff --git a/linden/indra/llui/lluictrl.cpp b/linden/indra/llui/lluictrl.cpp index 0e6c155..66504b7 100644 --- a/linden/indra/llui/lluictrl.cpp +++ b/linden/indra/llui/lluictrl.cpp @@ -34,7 +34,9 @@ #include "linden_common.h" #include "lluictrl.h" #include "llfocusmgr.h" +#include "llpanel.h" +static LLRegisterWidget r("ui_ctrl"); LLFocusableElement::LLFocusableElement() : mFocusLostCallback(NULL), @@ -473,7 +475,7 @@ BOOL LLUICtrl::focusPrevItem(BOOL text_fields_only) return focusPrev(result); } -const LLUICtrl* LLUICtrl::findRootMostFocusRoot() const +LLUICtrl* LLUICtrl::findRootMostFocusRoot() const { const LLUICtrl* focus_root = NULL; const LLUICtrl* next_view = this; @@ -485,7 +487,9 @@ const LLUICtrl* LLUICtrl::findRootMostFocusRoot() const } next_view = next_view->getParentUICtrl(); } - return focus_root; + // since focus_root could be this, need to cast away const to return + // a non-const result + return const_cast(focus_root); } @@ -538,14 +542,22 @@ LLXMLNodePtr LLUICtrl::getXML(bool save_children) const return node; } +//static +LLView* LLUICtrl::fromXML(LLXMLNodePtr node, LLView* parent, class LLUICtrlFactory* factory) +{ + LLUICtrl* ctrl = new LLUICtrl(); + ctrl->initFromXML(node, parent); + return ctrl; +} + + // *NOTE: If other classes derive from LLPanel, they will need to be // added to this function. LLPanel* LLUICtrl::getParentPanel() const { LLView* parent = getParent(); - while (parent - && parent->getWidgetType() != WIDGET_TYPE_PANEL - && parent->getWidgetType() != WIDGET_TYPE_FLOATER) + LLPanel* parent_panel = dynamic_cast(parent); + while (!parent_panel) { parent = parent->getParent(); } diff --git a/linden/indra/llui/lluictrl.h b/linden/indra/llui/lluictrl.h index 0c43297..7bc5eeb 100644 --- a/linden/indra/llui/lluictrl.h +++ b/linden/indra/llui/lluictrl.h @@ -141,7 +141,9 @@ public: void setValidateBeforeCommit( BOOL(*cb)(LLUICtrl*, void*) ) { mValidateCallback = cb; } void setLostTopCallback( void (*cb)(LLUICtrl*, void*) ) { mLostTopCallback = cb; } - const LLUICtrl* findRootMostFocusRoot() const; + static LLView* fromXML(LLXMLNodePtr node, LLView* parent, class LLUICtrlFactory* factory); + + LLUICtrl* findRootMostFocusRoot() const; class LLTextInputFilter : public LLQueryFilter, public LLSingleton { diff --git a/linden/indra/llui/lluictrlfactory.cpp b/linden/indra/llui/lluictrlfactory.cpp index cfee76a..cc8135c 100644 --- a/linden/indra/llui/lluictrlfactory.cpp +++ b/linden/indra/llui/lluictrlfactory.cpp @@ -71,100 +71,6 @@ const char XML_HEADER[] = "\n"; -// *NOTE: If you add a new class derived from LLPanel, add a check for its -// widget type to LLUICtrl::getParentPanel(). -// *NOTE: This MUST match EWidgetType in llui.h -//static -const LLString LLUICtrlFactory::sUICtrlNames[WIDGET_TYPE_COUNT] = -{ - LLString("view"), //WIDGET_TYPE_VIEW - LLString("root_view"), //WIDGET_TYPE_ROOT_VIEW - LLString("floater_view"), //WIDGET_TYPE_FLOATER_VIEW - LLString("button"), //WIDGET_TYPE_BUTTON - LLString("joystick_turn"), //WIDGET_TYPE_JOYSTICK_TURN - LLString("joystick_slide"), //WIDGET_TYPE_JOYSTICK_SLIDE - LLString("check_box"), //WIDGET_TYPE_CHECKBOX - LLString("color_swatch"), //WIDGET_TYPE_COLOR_SWATCH - LLString("combo_box"), //WIDGET_TYPE_COMBO_BOX - LLString("line_editor"), //WIDGET_TYPE_LINE_EDITOR - LLString("search_editor"), //WIDGET_TYPE_SEARCH_EDITOR - LLString("scroll_list"), //WIDGET_TYPE_SCROLL_LIST - LLString("name_list"), //WIDGET_TYPE_NAME_LIST - LLString("web_browser"), //WIDGET_TYPE_WEBBROWSER - LLString("slider"), //WIDGET_TYPE_SLIDER, actually LLSliderCtrl - LLString("slider_bar"), //WIDGET_TYPE_SLIDER_BAR, actually LLSlider - LLString("volume_slider"), //WIDGET_TYPE_VOLUME_SLIDER, actually LLSlider + "volume" param - LLString("multi_slider"), //WIDGET_TYPE_MULTI_SLIDER, actually LLMultiSliderCtrl - LLString("multi_slider_bar"), //WIDGET_TYPE_MULTI_SLIDER_BAR, actually LLMultiSlider - LLString("spinner"), //WIDGET_TYPE_SPINNER, actually LLSpinCtrl - LLString("text_editor"), //WIDGET_TYPE_TEXT_EDITOR - LLString("texture_picker"),//WIDGET_TYPE_TEXTURE_PICKER - LLString("text"), //WIDGET_TYPE_TEXT_BOX - LLString("pad"), //WIDGET_TYPE_PAD - LLString("radio_group"), //WIDGET_TYPE_RADIO_GROUP - LLString("icon"), //WIDGET_TYPE_ICON - LLString("locate"), //WIDGET_TYPE_LOCATE - LLString("view_border"), //WIDGET_TYPE_VIEW_BORDER - LLString("panel"), //WIDGET_TYPE_PANEL - LLString("menu"), //WIDGET_TYPE_MENU - LLString("pie_menu"), //WIDGET_TYPE_PIE_MENU - LLString("pie_menu_branch"), //WIDGET_TYPE_PIE_MENU_BRANCH - LLString("menu_item"), //WIDGET_TYPE_MENU_ITEM - LLString("menu_item_separator"), //WIDGET_TYPE_MENU_ITEM_SEPARATOR - LLString("menu_separator_vertical"), // WIDGET_TYPE_MENU_SEPARATOR_VERTICAL - LLString("menu_item_call"), // WIDGET_TYPE_MENU_ITEM_CALL - LLString("menu_item_check"),// WIDGET_TYPE_MENU_ITEM_CHECK - LLString("menu_item_branch"), // WIDGET_TYPE_MENU_ITEM_BRANCH - LLString("menu_item_branch_down"), //WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN, - LLString("menu_item_blank"), //WIDGET_TYPE_MENU_ITEM_BLANK, - LLString("tearoff_menu"), //WIDGET_TYPE_TEAROFF_MENU - LLString("menu_bar"), //WIDGET_TYPE_MENU_BAR - LLString("tab_container"),//WIDGET_TYPE_TAB_CONTAINER - LLString("scroll_container"),//WIDGET_TYPE_SCROLL_CONTAINER - LLString("scrollbar"), //WIDGET_TYPE_SCROLLBAR - LLString("inventory_panel"), //WIDGET_TYPE_INVENTORY_PANEL - LLString("floater"), //WIDGET_TYPE_FLOATER - LLString("drag_handle_top"), //WIDGET_TYPE_DRAG_HANDLE_TOP - LLString("drag_handle_left"), //WIDGET_TYPE_DRAG_HANDLE_LEFT - LLString("resize_handle"), //WIDGET_TYPE_RESIZE_HANDLE - LLString("resize_bar"), //WIDGET_TYPE_RESIZE_BAR - LLString("name_editor"), //WIDGET_TYPE_NAME_EDITOR - LLString("multi_floater"), //WIDGET_TYPE_MULTI_FLOATER - LLString("media_remote"), //WIDGET_TYPE_MEDIA_REMOTE - LLString("folder_view"), //WIDGET_TYPE_FOLDER_VIEW - LLString("folder_item"), //WIDGET_TYPE_FOLDER_ITEM - LLString("folder"), //WIDGET_TYPE_FOLDER - LLString("stat_graph"), //WIDGET_TYPE_STAT_GRAPH - LLString("stat_view"), //WIDGET_TYPE_STAT_VIEW - LLString("stat_bar"), //WIDGET_TYPE_STAT_BAR - LLString("drop_target"), //WIDGET_TYPE_DROP_TARGET - LLString("texture_bar"), //WIDGET_TYPE_TEXTURE_BAR - LLString("tex_mem_bar"), //WIDGET_TYPE_TEX_MEM_BAR - LLString("snapshot_live_preview"), //WIDGET_TYPE_SNAPSHOT_LIVE_PREVIEW - LLString("status_bar"), //WIDGET_TYPE_STATUS_BAR - LLString("progress_view"), //WIDGET_TYPE_PROGRESS_VIEW - LLString("talk_view"), //WIDGET_TYPE_TALK_VIEW - LLString("overlay_bar"), //WIDGET_TYPE_OVERLAY_BAR - LLString("hud_view"), //WIDGET_TYPE_HUD_VIEW - LLString("hover_view"), //WIDGET_TYPE_HOVER_VIEW - LLString("morph_view"), //WIDGET_TYPE_MORPH_VIEW - LLString("net_map"), //WIDGET_TYPE_NET_MAP - LLString("permissions_view"), //WIDGET_TYPE_PERMISSIONS_VIEW - LLString("menu_holder"), //WIDGET_TYPE_MENU_HOLDER - LLString("debug_view"), //WIDGET_TYPE_DEBUG_VIEW - LLString("scrolling_panel_list"), //WIDGET_TYPE_SCROLLING_PANEL_LIST - LLString("audio_status"), //WIDGET_TYPE_AUDIO_STATUS - LLString("container_view"), //WIDGET_TYPE_CONTAINER_VIEW - LLString("console"), //WIDGET_TYPE_CONSOLE - LLString("fast_timer_view"), //WIDGET_TYPE_FAST_TIMER_VIEW - LLString("velocity_bar"), //WIDGET_TYPE_VELOCITY_BAR - LLString("texture_view"), //WIDGET_TYPE_TEXTURE_VIEW - LLString("memory_view"), //WIDGET_TYPE_MEMORY_VIEW - LLString("frame_stat_view"), //WIDGET_TYPE_FRAME_STAT_VIEW - LLString("layout_stack"), //WIDGET_TYPE_LAYOUT_STACK - LLString("DONT_CARE"), //WIDGET_TYPE_DONTCARE -}; - const S32 HPAD = 4; const S32 VPAD = 4; const S32 FLOATER_H_MARGIN = 15; @@ -179,9 +85,6 @@ public: LLUICtrlLocate() : LLUICtrl("locate", LLRect(0,0,0,0), FALSE, NULL, NULL) { setTabStop(FALSE); } virtual void draw() { } - virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_LOCATE; } - virtual LLString getWidgetTag() const { return LL_UI_CTRL_LOCATE_TAG; } - static LLView *fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { LLString name("pad"); @@ -194,39 +97,14 @@ public: } }; +static LLRegisterWidget r1("locate"); +static LLRegisterWidget r2("pad"); + //----------------------------------------------------------------------------- // LLUICtrlFactory() //----------------------------------------------------------------------------- LLUICtrlFactory::LLUICtrlFactory() { - // Register controls - LLUICtrlCreator::registerCreator(LL_BUTTON_TAG, this); - LLUICtrlCreator::registerCreator(LL_CHECK_BOX_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_COMBO_BOX_TAG, this); - LLUICtrlCreator::registerCreator(LL_FLYOUT_BUTTON_TAG, this); - LLUICtrlCreator::registerCreator(LL_LINE_EDITOR_TAG, this); - LLUICtrlCreator::registerCreator(LL_SEARCH_EDITOR_TAG, this); - LLUICtrlCreator::registerCreator(LL_SCROLL_LIST_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_SLIDER_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_SLIDER_TAG, this); - LLUICtrlCreator::registerCreator(LL_VOLUME_SLIDER_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_MULTI_SLIDER_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_MULTI_SLIDER_TAG, this); - LLUICtrlCreator::registerCreator(LL_SPIN_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_TEXT_BOX_TAG, this); - LLUICtrlCreator::registerCreator(LL_RADIO_GROUP_TAG, this); - LLUICtrlCreator::registerCreator(LL_ICON_CTRL_TAG, this); - LLUICtrlCreator::registerCreator(LL_UI_CTRL_LOCATE_TAG, this); - LLUICtrlCreator::registerCreator(LL_PAD_TAG, this); - LLUICtrlCreator::registerCreator(LL_VIEW_BORDER_TAG, this); - LLUICtrlCreator::registerCreator(LL_TAB_CONTAINER_COMMON_TAG, this); - LLUICtrlCreator::registerCreator(LL_SCROLLABLE_CONTAINER_VIEW_TAG, this); - LLUICtrlCreator::registerCreator(LL_PANEL_TAG, this); - LLUICtrlCreator::registerCreator(LL_MENU_GL_TAG, this); - LLUICtrlCreator::registerCreator(LL_MENU_BAR_GL_TAG, this); - LLUICtrlCreator::registerCreator(LL_SCROLLING_PANEL_LIST_TAG, this); - LLUICtrlCreator::registerCreator(LL_LAYOUT_STACK_TAG, this); - setupPaths(); } @@ -548,43 +426,33 @@ void LLUICtrlFactory::rebuild() //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -// static -EWidgetType LLUICtrlFactory::getWidgetType(const LLString& ctrl_type) -{ - U32 ctrl_id; - for (ctrl_id = 0; ctrl_id < WIDGET_TYPE_COUNT; ctrl_id++) - { - if (sUICtrlNames[ctrl_id] == ctrl_type) - { - break; - } - } - return (EWidgetType) ctrl_id; -} - -LLString LLUICtrlFactory::getWidgetType(EWidgetType ctrl_type) -{ - return sUICtrlNames[ctrl_type]; -} - LLView *LLUICtrlFactory::createCtrlWidget(LLPanel *parent, LLXMLNodePtr node) { + // panel for holding dummy widgets, so they have a parent for layout purposes, etc. + // does not manage lifetime of child widgets + static LLPanel dummy_panel; + LLString ctrl_type = node->getName()->mString; LLString::toLower(ctrl_type); - creator_list_t::const_iterator it = mCreatorFunctions.find(ctrl_type); - if (it == mCreatorFunctions.end()) + LLWidgetClassRegistry::factory_func_t func = LLWidgetClassRegistry::getInstance()->getCreatorFunc(ctrl_type); + + if (func == NULL) { llwarns << "Unknown control type " << ctrl_type << llendl; return NULL; } - LLView *ctrl = (*it->second)(node, parent, this); + if (parent == NULL) + { + parent = &dummy_panel; + } + LLView *ctrl = func(node, parent, this); return ctrl; } -void LLUICtrlFactory::createWidget(LLPanel *parent, LLXMLNodePtr node) +LLView* LLUICtrlFactory::createWidget(LLPanel *parent, LLXMLNodePtr node) { LLView* view = createCtrlWidget(parent, node); @@ -595,6 +463,8 @@ void LLUICtrlFactory::createWidget(LLPanel *parent, LLXMLNodePtr node) { parent->addChild(view, tab_group); } + + return view; } //----------------------------------------------------------------------------- @@ -648,138 +518,3 @@ BOOL LLUICtrlFactory::getAttributeColor(LLXMLNodePtr node, const LLString& name, return res; } -//============================================================================ - -LLButton* LLUICtrlFactory::getButtonByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLCheckBoxCtrl* LLUICtrlFactory::getCheckBoxByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLComboBox* LLUICtrlFactory::getComboBoxByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLIconCtrl* LLUICtrlFactory::getIconByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLLineEditor* LLUICtrlFactory::getLineEditorByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLRadioGroup* LLUICtrlFactory::getRadioGroupByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLScrollListCtrl* LLUICtrlFactory::getScrollListByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLSliderCtrl* LLUICtrlFactory::getSliderByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLSlider* LLUICtrlFactory::getSliderBarByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLSpinCtrl* LLUICtrlFactory::getSpinnerByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLTextBox* LLUICtrlFactory::getTextBoxByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLTextEditor* LLUICtrlFactory::getTextEditorByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLTabContainer* LLUICtrlFactory::getTabContainerByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLScrollableContainerView* LLUICtrlFactory::getScrollableContainerByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLPanel* LLUICtrlFactory::getPanelByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLMenuItemCallGL* LLUICtrlFactory::getMenuItemCallByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLScrollingPanelList* LLUICtrlFactory::getScrollingPanelList(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLMultiSliderCtrl* LLUICtrlFactory::getMultiSliderByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - -LLMultiSlider* LLUICtrlFactory::getMultiSliderBarByName(const LLPanel* panelp, const LLString& name) -{ - return panelp->getChild(name); -} - - -LLCtrlListInterface* LLUICtrlFactory::getListInterfaceByName(const LLPanel* panelp, const LLString& name) -{ - LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE); - if (viewp && viewp->isCtrl()) - { - return ((LLUICtrl*)viewp)->getListInterface(); - } - return NULL; -} - -LLCtrlSelectionInterface* LLUICtrlFactory::getSelectionInterfaceByName(const LLPanel* panelp, const LLString& name) -{ - LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE); - if (viewp && viewp->isCtrl()) - { - return ((LLUICtrl*)viewp)->getSelectionInterface(); - } - return NULL; -} - -LLCtrlScrollInterface* LLUICtrlFactory::getScrollInterfaceByName(const LLPanel* panelp, const LLString& name) -{ - LLView* viewp = panelp->getCtrlByNameAndType(name, WIDGET_TYPE_DONTCARE); - if (viewp && viewp->isCtrl()) - { - return ((LLUICtrl*)viewp)->getScrollInterface(); - } - return NULL; -} - -void LLUICtrlFactory::registerCreator(LLString ctrlname, creator_function_t function) -{ - LLString::toLower(ctrlname); - mCreatorFunctions[ctrlname] = function; -} - - diff --git a/linden/indra/llui/lluictrlfactory.h b/linden/indra/llui/lluictrlfactory.h index e6a2cd3..b9325a0 100644 --- a/linden/indra/llui/lluictrlfactory.h +++ b/linden/indra/llui/lluictrlfactory.h @@ -41,7 +41,7 @@ class LLView; class LLPanel; -class LLUICtrlFactory +class LLUICtrlFactory : public LLSingleton { public: LLUICtrlFactory(); @@ -49,7 +49,7 @@ public: virtual ~LLUICtrlFactory() {} void setupPaths(); - + void buildFloater(LLFloater* floaterp, const LLString &filename, const LLCallbackMap::map_t* factory_map = NULL, BOOL open = TRUE); BOOL buildPanel(LLPanel* panelp, const LLString &filename, @@ -65,84 +65,28 @@ public: // Returns 0 on success S32 saveToXML(LLView* viewp, const LLString& filename); - // Rebuilds all currently built panels. void rebuild(); - static EWidgetType getWidgetType(const LLString& ctrl_type); - static LLString getWidgetType(EWidgetType ctrl_type); static BOOL getAttributeColor(LLXMLNodePtr node, const LLString& name, LLColor4& color); - // specific typed getters - static class LLButton* getButtonByName( const LLPanel* panelp, const LLString& name); - static class LLCheckBoxCtrl* getCheckBoxByName( const LLPanel* panelp, const LLString& name); - static class LLComboBox* getComboBoxByName( const LLPanel* panelp, const LLString& name); - static class LLIconCtrl* getIconByName( const LLPanel* panelp, const LLString& name); - static class LLLineEditor* getLineEditorByName( const LLPanel* panelp, const LLString& name); - static class LLRadioGroup* getRadioGroupByName( const LLPanel* panelp, const LLString& name); - static class LLScrollListCtrl* getScrollListByName( const LLPanel* panelp, const LLString& name); - static class LLSliderCtrl* getSliderByName( const LLPanel* panelp, const LLString& name); - static class LLSlider* getSliderBarByName( const LLPanel* panelp, const LLString& name); - static class LLSpinCtrl* getSpinnerByName( const LLPanel* panelp, const LLString& name); - static class LLTextBox* getTextBoxByName( const LLPanel* panelp, const LLString& name); - static class LLTextEditor* getTextEditorByName( const LLPanel* panelp, const LLString& name); - static class LLTabContainer* getTabContainerByName( const LLPanel* panelp, const LLString& name); - static class LLScrollableContainerView* getScrollableContainerByName(const LLPanel* panelp, const LLString& name); - static class LLPanel* getPanelByName( const LLPanel* panelp, const LLString& name); - static class LLMenuItemCallGL* getMenuItemCallByName( const LLPanel* panelp, const LLString& name); - static class LLScrollingPanelList* getScrollingPanelList( const LLPanel* panelp, const LLString& name); - static class LLMultiSliderCtrl* getMultiSliderByName( const LLPanel* panelp, const LLString& name); - static class LLMultiSlider* getMultiSliderBarByName(const LLPanel* panelp, const LLString& name); - - // interface getters - static LLCtrlListInterface* getListInterfaceByName( const LLPanel* panelp, const LLString& name); - static LLCtrlSelectionInterface* getSelectionInterfaceByName(const LLPanel* panelp, const LLString& name); - static LLCtrlScrollInterface* getScrollInterfaceByName(const LLPanel* panelp, const LLString& name); - LLPanel* createFactoryPanel(LLString name); virtual LLView* createCtrlWidget(LLPanel *parent, LLXMLNodePtr node); - virtual void createWidget(LLPanel *parent, LLXMLNodePtr node); - - template T* createDummyWidget(const LLString& name) - { - return NULL; - //static LLPanel dummy_panel; - //LLXMLNodePtr new_node_ptr = new LLXMLNode(T::getWidgetTag(), FALSE); - //return createWidget(&dummy_panel, new_node_ptr); - } - - // Creator library - typedef LLView* (*creator_function_t)(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); - void registerCreator(LLString ctrlname, creator_function_t function); + virtual LLView* createWidget(LLPanel *parent, LLXMLNodePtr node); static bool getLayeredXMLNode(const LLString &filename, LLXMLNodePtr& root); -protected: - - template - class LLUICtrlCreator - { - public: - static void registerCreator(LLString name, LLUICtrlFactory *factory) - { - factory->registerCreator(name, T::fromXML); - } - }; - private: typedef std::map, LLString> built_panel_t; built_panel_t mBuiltPanels; + typedef std::map, LLString> built_floater_t; built_floater_t mBuiltFloaters; std::deque mFactoryStack; - static const LLString sUICtrlNames[]; - - typedef std::map creator_list_t; - creator_list_t mCreatorFunctions; static std::vector mXUIPaths; }; diff --git a/linden/indra/llui/llview.cpp b/linden/indra/llui/llview.cpp index e5415f8..c9828dd 100644 --- a/linden/indra/llui/llview.cpp +++ b/linden/indra/llui/llview.cpp @@ -49,7 +49,16 @@ #include "lluictrl.h" #include "llwindow.h" #include "v3color.h" +#include "lluictrlfactory.h" +// for ui edit hack +#include "llbutton.h" +#include "lllineeditor.h" +#include "lltexteditor.h" +#include "lltextbox.h" + +//HACK: this allows you to instantiate LLView from xml with "" which we don't want +static LLRegisterWidget r("view"); BOOL LLView::sDebugRects = FALSE; BOOL LLView::sDebugKeys = FALSE; @@ -153,6 +162,8 @@ LLView::~LLView() std::for_each(mFloaterControls.begin(), mFloaterControls.end(), DeletePairedPointer()); + std::for_each(mDummyWidgets.begin(), mDummyWidgets.end(), + DeletePairedPointer()); } // virtual @@ -716,7 +727,7 @@ BOOL LLView::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect_scre tool_tip = getShowNamesToolTip(); } - BOOL showNamesTextBox = LLUI::sShowXUINames && (getWidgetType() == WIDGET_TYPE_TEXT_BOX); + BOOL showNamesTextBox = LLUI::sShowXUINames && dynamic_cast(this) != NULL; if( !handled && (blockMouseEvent(x, y) || showNamesTextBox) && !tool_tip.empty()) { @@ -741,23 +752,21 @@ BOOL LLView::handleKey(KEY key, MASK mask, BOOL called_from_parent) { BOOL handled = FALSE; - if( called_from_parent ) + if (getVisible() && getEnabled()) { - // Downward traversal - if (getVisible() && getEnabled()) + if( called_from_parent ) { + // Downward traversal handled = childrenHandleKey( key, mask ) != NULL; } - } - // JC: Must pass to disabled views, since they could have - // keyboard focus, which requires the escape key to exit. - if (!handled && getVisible()) - { - handled = handleKeyHere( key, mask, called_from_parent ); - if (handled && LLView::sDebugKeys) + if (!handled) { - llinfos << "Key handled by " << getName() << llendl; + handled = handleKeyHere( key, mask ); + if (handled && LLView::sDebugKeys) + { + llinfos << "Key handled by " << getName() << llendl; + } } } @@ -771,7 +780,7 @@ BOOL LLView::handleKey(KEY key, MASK mask, BOOL called_from_parent) // Called from handleKey() // Handles key in this object. Checking parents and children happens in handleKey() -BOOL LLView::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) +BOOL LLView::handleKeyHere(KEY key, MASK mask) { return FALSE; } @@ -780,25 +789,24 @@ BOOL LLView::handleUnicodeChar(llwchar uni_char, BOOL called_from_parent) { BOOL handled = FALSE; - if( called_from_parent ) + if (getVisible() && getEnabled()) { - // Downward traversal - if (getVisible() && getEnabled()) + if( called_from_parent ) { + // Downward traversal handled = childrenHandleUnicodeChar( uni_char ) != NULL; } - } - if (!handled && getVisible()) - { - handled = handleUnicodeCharHere(uni_char, called_from_parent); - if (handled && LLView::sDebugKeys) + if (!handled) { - llinfos << "Unicode key handled by " << getName() << llendl; + handled = handleUnicodeCharHere(uni_char); + if (handled && LLView::sDebugKeys) + { + llinfos << "Unicode key handled by " << getName() << llendl; + } } } - if (!handled && !called_from_parent && mParentView) { // Upward traversal @@ -809,7 +817,7 @@ BOOL LLView::handleUnicodeChar(llwchar uni_char, BOOL called_from_parent) } -BOOL LLView::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent ) +BOOL LLView::handleUnicodeCharHere(llwchar uni_char ) { return FALSE; } @@ -903,11 +911,14 @@ BOOL LLView::handleMouseDown(S32 x, S32 y, MASK mask) if (sEditingUI && handled_view) { // need to find leaf views, big hack - EWidgetType type = handled_view->getWidgetType(); - if (type == WIDGET_TYPE_BUTTON - || type == WIDGET_TYPE_LINE_EDITOR - || type == WIDGET_TYPE_TEXT_EDITOR - || type == WIDGET_TYPE_TEXT_BOX) + LLButton* buttonp = dynamic_cast(handled_view); + LLLineEditor* line_editorp = dynamic_cast(handled_view); + LLTextEditor* text_editorp = dynamic_cast(handled_view); + LLTextBox* text_boxp = dynamic_cast(handled_view); + if (buttonp + || line_editorp + || text_editorp + || text_boxp) { sEditingUIView = handled_view; } @@ -971,8 +982,10 @@ LLView* LLView::childrenHandleScrollWheel(S32 x, S32 y, S32 clicks) LLView* viewp = *child_it; S32 local_x = x - viewp->getRect().mLeft; S32 local_y = y - viewp->getRect().mBottom; - if (viewp->pointInView(local_x, local_y) && - viewp->handleScrollWheel( local_x, local_y, clicks )) + if (viewp->pointInView(local_x, local_y) + && viewp->getVisible() + && viewp->getEnabled() + && viewp->handleScrollWheel( local_x, local_y, clicks )) { if (sDebugMouseHandling) { @@ -1528,7 +1541,7 @@ BOOL LLView::hasAncestor(const LLView* parentp) const BOOL LLView::childHasKeyboardFocus( const LLString& childname ) const { - LLView *child = getChildByName(childname); + LLView *child = getChildView(childname, TRUE, FALSE); if (child) { return gFocusMgr.childHasKeyboardFocus(child); @@ -1543,16 +1556,17 @@ BOOL LLView::childHasKeyboardFocus( const LLString& childname ) const BOOL LLView::hasChild(const LLString& childname, BOOL recurse) const { - return getChildByName(childname, recurse) != NULL; + return getChildView(childname, recurse, FALSE) != NULL; } //----------------------------------------------------------------------------- -// getChildByName() +// getChildView() //----------------------------------------------------------------------------- -LLView* LLView::getChildByName(const LLString& name, BOOL recurse) const +LLView* LLView::getChildView(const LLString& name, BOOL recurse, BOOL create_if_missing) const { - if(name.empty()) - return NULL; + //richard: should we allow empty names? + //if(name.empty()) + // return NULL; child_list_const_iter_t child_it; // Look for direct children *first* for ( child_it = mChildList.begin(); child_it != mChildList.end(); ++child_it) @@ -1569,13 +1583,18 @@ LLView* LLView::getChildByName(const LLString& name, BOOL recurse) const for ( child_it = mChildList.begin(); child_it != mChildList.end(); ++child_it) { LLView* childp = *child_it; - LLView* viewp = childp->getChildByName(name, recurse); + LLView* viewp = childp->getChildView(name, recurse, FALSE); if ( viewp ) { return viewp; } } } + + if (create_if_missing) + { + return createDummyWidget(name); + } return NULL; } @@ -1692,7 +1711,6 @@ BOOL LLView::translateIntoRect(const LLRect& constraint, BOOL allow_partial_outs if( getRect().mLeft + KEEP_ONSCREEN_PIXELS > constraint.mRight ) { delta_x = constraint.mRight - (getRect().mLeft + KEEP_ONSCREEN_PIXELS); - delta_x += llmax( 0, getRect().getWidth() - constraint.getWidth() ); } if( getRect().mTop > constraint.mTop ) @@ -1703,7 +1721,6 @@ BOOL LLView::translateIntoRect(const LLRect& constraint, BOOL allow_partial_outs if( getRect().mTop - KEEP_ONSCREEN_PIXELS < constraint.mBottom ) { delta_y = constraint.mBottom - (getRect().mTop - KEEP_ONSCREEN_PIXELS); - delta_y -= llmax( 0, getRect().getHeight() - constraint.getHeight() ); } } else @@ -1716,6 +1733,7 @@ BOOL LLView::translateIntoRect(const LLRect& constraint, BOOL allow_partial_outs if( getRect().mRight > constraint.mRight ) { delta_x = constraint.mRight - getRect().mRight; + // compensate for left edge possible going off screen delta_x += llmax( 0, getRect().getWidth() - constraint.getWidth() ); } @@ -1727,6 +1745,7 @@ BOOL LLView::translateIntoRect(const LLRect& constraint, BOOL allow_partial_outs if( getRect().mBottom < constraint.mBottom ) { delta_y = constraint.mBottom - getRect().mBottom; + // compensate for top edge possible going off screen delta_y -= llmax( 0, getRect().getHeight() - constraint.getHeight() ); } } @@ -1832,9 +1851,8 @@ BOOL LLView::localRectToOtherView( const LLRect& local, LLRect* other, LLView* o // virtual LLXMLNodePtr LLView::getXML(bool save_children) const { - const LLString& type_name = getWidgetTag(); - - LLXMLNodePtr node = new LLXMLNode(type_name, FALSE); + //FIXME: need to provide actual derived type tag, probably outside this method + LLXMLNodePtr node = new LLXMLNode("view", FALSE); node->createChild("name", TRUE)->setStringValue(getName()); node->createChild("width", TRUE)->setIntValue(getRect().getWidth()); @@ -1897,6 +1915,14 @@ LLXMLNodePtr LLView::getXML(bool save_children) const return node; } +//static +LLView* LLView::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) +{ + LLView* viewp = new LLView(); + viewp->initFromXML(node, parent); + return viewp; +} + // static void LLView::addColorXML(LLXMLNodePtr node, const LLColor4& color, const LLString& xml_name, const LLString& control_name) @@ -2426,16 +2452,7 @@ LLSimpleListener* LLView::getListenerByName(const LLString& callback_name) return callback; } -void LLView::addListenerToControl(LLEventDispatcher *dispatcher, const LLString& name, LLSD filter, LLSD userdata) -{ - LLSimpleListener* listener = getListenerByName(name); - if (listener) - { - dispatcher->addListener(listener, filter, userdata); - } -} - -LLControlBase *LLView::findControl(LLString name) +LLControlVariable *LLView::findControl(LLString name) { control_map_t::iterator itor = mFloaterControls.find(name); if (itor != mFloaterControls.end()) @@ -2791,9 +2808,15 @@ LLFontGL::StyleFlags LLView::selectFontStyle(LLXMLNodePtr node) return gl_font_style; } -void LLView::setControlValue(const LLSD& value) +bool LLView::setControlValue(const LLSD& value) { - LLUI::sConfigGroup->setValue(getControlName(), value); + LLString ctrlname = getControlName(); + if (!ctrlname.empty()) + { + LLUI::sConfigGroup->setValue(ctrlname, value); + return true; + } + return false; } //virtual @@ -2804,43 +2827,57 @@ void LLView::setControlName(const LLString& control_name, LLView *context) context = this; } - // Unregister from existing listeners if (!mControlName.empty()) { - clearDispatchers(); + llwarns << "setControlName called twice on same control!" << llendl; + mControlConnection.disconnect(); // disconnect current signal + mControlName.clear(); } - + // Register new listener if (!control_name.empty()) { - LLControlBase *control = context->findControl(control_name); + LLControlVariable *control = context->findControl(control_name); if (control) { mControlName = control_name; - LLSD state = control->registerListener(this, "DEFAULT"); - setValue(state); + mControlConnection = control->getSignal()->connect(boost::bind(&controlListener, _1, getHandle(), std::string("value"))); + setValue(control->getValue()); } } } -// virtual -bool LLView::handleEvent(LLPointer event, const LLSD& userdata) +// static +bool LLView::controlListener(const LLSD& newvalue, LLHandle handle, std::string type) { - if (userdata.asString() == "DEFAULT" && event->desc() == "value_changed") + LLView* view = handle.get(); + if (view) { - LLSD state = event->getValue(); - setValue(state); - return TRUE; + if (type == "value") + { + view->setValue(newvalue); + return true; + } + else if (type == "enabled") + { + view->setEnabled(newvalue.asBoolean()); + return true; + } + else if (type == "visible") + { + view->setVisible(newvalue.asBoolean()); + return true; + } } - return FALSE; + return false; } void LLView::addBoolControl(LLString name, bool initial_value) { - mFloaterControls[name] = new LLControl(name, TYPE_BOOLEAN, initial_value, "Internal floater control"); + mFloaterControls[name] = new LLControlVariable(name, TYPE_BOOLEAN, initial_value, "Internal floater control"); } -LLControlBase *LLView::getControl(LLString name) +LLControlVariable *LLView::getControl(LLString name) { control_map_t::iterator itor = mFloaterControls.find(name); if (itor != mFloaterControls.end()) @@ -2860,3 +2897,41 @@ LLSD LLView::getValue() const { return LLSD(); } + +LLView* LLView::createWidget(LLXMLNodePtr xml_node) const +{ + // forward requests to ui ctrl factory + return LLUICtrlFactory::getInstance()->createCtrlWidget(NULL, xml_node); +} + +// +// LLWidgetClassRegistry +// + +LLWidgetClassRegistry::LLWidgetClassRegistry() +{ +} + +void LLWidgetClassRegistry::registerCtrl(const LLString& tag, LLWidgetClassRegistry::factory_func_t function) +{ + LLString lower_case_tag = tag; + LLString::toLower(lower_case_tag); + + mCreatorFunctions[lower_case_tag] = function; +} + +BOOL LLWidgetClassRegistry::isTagRegistered(const LLString &tag) +{ + return mCreatorFunctions.find(tag) != mCreatorFunctions.end(); +} + +LLWidgetClassRegistry::factory_func_t LLWidgetClassRegistry::getCreatorFunc(const LLString& ctrl_type) +{ + factory_map_t::const_iterator found_it = mCreatorFunctions.find(ctrl_type); + if (found_it == mCreatorFunctions.end()) + { + return NULL; + } + return found_it->second; +} + diff --git a/linden/indra/llui/llview.h b/linden/indra/llui/llview.h index 51c314a..9a04ed7 100644 --- a/linden/indra/llui/llview.h +++ b/linden/indra/llui/llview.h @@ -52,7 +52,6 @@ #include "stdenums.h" #include "lluistring.h" - const U32 FOLLOWS_NONE = 0x00; const U32 FOLLOWS_LEFT = 0x01; const U32 FOLLOWS_RIGHT = 0x02; @@ -65,7 +64,6 @@ const BOOL NOT_MOUSE_OPAQUE = FALSE; const U32 GL_NAME_UI_RESERVED = 2; - /* // virtual functions defined in LLView: @@ -120,9 +118,7 @@ virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,EDragAndDropTy * virtual void draw(); * -virtual EWidgetType getWidgetType() const = 0; - * -virtual LLString getWidgetTag() const = 0; + * virtual LLXMLNodePtr getXML(bool save_children = true) const; * @@ -132,7 +128,7 @@ virtual void onFocusLost() {} LLUICtrl, LLScrollListCtrl, LLMenuGL, LLLineEditor, LLComboBox virtual void onFocusReceived() {} LLUICtrl, LLTextEditor, LLScrollListVtrl, LLMenuGL, LLLineEditor -virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const; +virtual LLView* getChildView(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; LLTabContainer, LLPanel, LLMenuGL virtual void setControlName(const LLString& control, LLView *context); LLSliderCtrl, LLCheckBoxCtrl @@ -144,13 +140,72 @@ virtual void setValue(const LLSD& value); * protected: -virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent); +virtual BOOL handleKeyHere(KEY key, MASK mask); * -virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent); +virtual BOOL handleUnicodeCharHere(llwchar uni_char); * */ -class LLView : public LLMouseHandler, public LLMortician, public LLSimpleListenerObservable +class LLUICtrlFactory; + +// maps xml strings to widget classes +class LLWidgetClassRegistry : public LLSingleton +{ + friend class LLSingleton; +public: + typedef LLView* (*factory_func_t)(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); + typedef std::map factory_map_t; + + void registerCtrl(const LLString& xml_tag, factory_func_t function); + BOOL isTagRegistered(const LLString& xml_tag); + factory_func_t getCreatorFunc(const LLString& xml_tag); + + // get (first) xml tag for a given class + template std::string getTag() + { + factory_map_t::iterator it; + for(it = mCreatorFunctions.begin(); it != mCreatorFunctions.end(); ++it) + { + if (it->second == T::fromXML) + { + return it->first; + } + } + + return ""; + } + +private: + LLWidgetClassRegistry(); + virtual ~LLWidgetClassRegistry() {}; + + typedef std::set ctrl_name_set_t; + ctrl_name_set_t mUICtrlNames; + + // map of xml tags to widget creator functions + factory_map_t mCreatorFunctions; +}; + +template +class LLRegisterWidget +{ +public: + LLRegisterWidget(const std::string& tag) + { + LLWidgetClassRegistry* registry = LLWidgetClassRegistry::getInstance(); + if (registry->isTagRegistered(tag)) + { + //error! + llerrs << "Widget named " << tag << " already registered!" << llendl; + } + else + { + registry->registerCtrl(tag, T::fromXML); + } + } +}; + +class LLView : public LLMouseHandler, public LLMortician { public: @@ -294,7 +349,6 @@ public: LLHandle getHandle() { mHandle.bind(this); return mHandle; } - U32 getFollows() const { return mReshapeFlags; } BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; } BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; } @@ -355,10 +409,9 @@ public: virtual void draw(); - virtual EWidgetType getWidgetType() const = 0; - virtual LLString getWidgetTag() const = 0; virtual LLXMLNodePtr getXML(bool save_children = true) const; - + //FIXME: make LLView non-instantiable from XML + static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory); virtual void initFromXML(LLXMLNodePtr node, LLView* parent); void parseFollowsFlags(LLXMLNodePtr node); @@ -393,13 +446,13 @@ public: void addListenerToControl(LLEventDispatcher *observer, const LLString& name, LLSD filter, LLSD userdata); void addBoolControl(LLString name, bool initial_value); - LLControlBase *getControl(LLString name); - LLControlBase *findControl(LLString name); + LLControlVariable *getControl(LLString name); + LLControlVariable *findControl(LLString name); - void setControlValue(const LLSD& value); + bool setControlValue(const LLSD& value); virtual void setControlName(const LLString& control, LLView *context); virtual LLString getControlName() const { return mControlName; } - virtual bool handleEvent(LLPointer event, const LLSD& userdata); +// virtual bool handleEvent(LLPointer event, const LLSD& userdata); virtual void setValue(const LLSD& value); virtual LLSD getValue() const; @@ -422,17 +475,74 @@ public: /*virtual*/ void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const; /*virtual*/ void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const; - template T* getChild(const LLString& name, BOOL recurse = TRUE) const + template T* getChild(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const { - T* result = dynamic_cast(getChildByName(name, TRUE)); - //if (!result) - //{ - // // create dummy widget instance here - // result = gUICtrlFactory->createDummyWidget(name); - //} + LLView* child = getChildView(name, recurse, FALSE); + T* result = dynamic_cast(child); + if (!result) + { + // did we find *something* with that name? + if (child) + { + llwarns << "Found child named " << name << " but of wrong type" << llendl; + } + if (create_if_missing) + { + // create dummy widget instance here + result = createDummyWidget(name); + } + } return result; } + virtual LLView* getChildView(const LLString& name, BOOL recurse = TRUE, BOOL create_if_missing = TRUE) const; + + template T* createDummyWidget(const LLString& name) const + { + T* widget = getDummyWidget(name); + if (!widget) + { + // get xml tag name corresponding to requested widget type (e.g. "button") + LLString xml_tag = LLWidgetClassRegistry::getInstance()->getTag(); + if (xml_tag.empty()) + { + llwarns << "No xml tag registered for this class " << llendl; + return NULL; + } + // create dummy xml node (