From cd17687f01420952712a500107e0f93e7ab8d5f8 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:34 -0500 Subject: Second Life viewer sources 1.19.1.0 --- linden/indra/llui/lluictrl.cpp | 203 +++++++++++++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 29 deletions(-) (limited to 'linden/indra/llui/lluictrl.cpp') diff --git a/linden/indra/llui/lluictrl.cpp b/linden/indra/llui/lluictrl.cpp index 63db1cc..0e6c155 100644 --- a/linden/indra/llui/lluictrl.cpp +++ b/linden/indra/llui/lluictrl.cpp @@ -32,20 +32,9 @@ //#include "llviewerprecompiledheaders.h" #include "linden_common.h" - #include "lluictrl.h" - -#include "llgl.h" -#include "llui.h" -#include "lluiconstants.h" #include "llfocusmgr.h" -#include "v3color.h" - -#include "llstring.h" -#include "llfontgl.h" -#include "llkeyboard.h" -const U32 MAX_STRING_LENGTH = 10; LLFocusableElement::LLFocusableElement() : mFocusLostCallback(NULL), @@ -55,6 +44,11 @@ LLFocusableElement::LLFocusableElement() { } +//virtual +LLFocusableElement::~LLFocusableElement() +{ +} + void LLFocusableElement::onFocusReceived() { if( mFocusReceivedCallback ) @@ -138,6 +132,18 @@ void LLUICtrl::onCommit() } } +//virtual +BOOL LLUICtrl::isCtrl() const +{ + return TRUE; +} + +//virtual +LLSD LLUICtrl::getValue() const +{ + return LLSD(); +} + // virtual BOOL LLUICtrl::setTextArg( const LLString& key, const LLStringExplicit& text ) { @@ -176,7 +182,7 @@ BOOL LLUICtrl::hasFocus() const void LLUICtrl::setFocus(BOOL b) { // focus NEVER goes to ui ctrls that are disabled! - if (!mEnabled) + if (!getEnabled()) { return; } @@ -266,6 +272,17 @@ BOOL LLUICtrl::acceptsTextInput() const return FALSE; } +//virtual +BOOL LLUICtrl::isDirty() const +{ + return FALSE; +}; + +//virtual +void LLUICtrl::resetDirty() +{ +} + // virtual void LLUICtrl::onTabInto() { @@ -285,8 +302,6 @@ void LLUICtrl::setIsChrome(BOOL is_chrome) // virtual BOOL LLUICtrl::getIsChrome() const { - // am I or any of my ancestors flagged as "chrome"? - if (mIsChrome) return TRUE; LLView* parent_ctrl = getParent(); while(parent_ctrl) @@ -300,11 +315,12 @@ BOOL LLUICtrl::getIsChrome() const if(parent_ctrl) { - // recurse into parent_ctrl and ask if it is in a chrome subtree - return ((LLUICtrl*)parent_ctrl)->getIsChrome(); + return mIsChrome || ((LLUICtrl*)parent_ctrl)->getIsChrome(); + } + else + { + return mIsChrome ; } - - return FALSE; } // this comparator uses the crazy disambiguating logic of LLCompareByTabOrder, @@ -316,7 +332,7 @@ public: CompareByDefaultTabGroup(LLView::child_tab_order_t order, S32 default_tab_group): LLCompareByTabOrder(order), mDefaultTabGroup(default_tab_group) {} -protected: +private: /*virtual*/ bool compareTabOrders(const LLView::tab_order_t & a, const LLView::tab_order_t & b) const { S32 ag = a.first; // tab group for a @@ -330,8 +346,10 @@ protected: S32 mDefaultTabGroup; }; -// sorter for plugging into the query -class DefaultTabGroupFirstSorter : public LLQuerySorter, public LLSingleton + +// Sorter for plugging into the query. +// I'd have defined it local to the one method that uses it but that broke the VS 05 compiler. -MG +class LLUICtrl::DefaultTabGroupFirstSorter : public LLQuerySorter, public LLSingleton { public: /*virtual*/ void operator() (LLView * parent, viewList_t &children) const @@ -340,14 +358,47 @@ public: } }; - -BOOL LLUICtrl::focusFirstItem(BOOL prefer_text_fields) +BOOL LLUICtrl::focusFirstItem(BOOL prefer_text_fields, BOOL focus_flash) { // try to select default tab group child - LLCtrlQuery query = LLView::getTabOrderQuery(); + LLCtrlQuery query = getTabOrderQuery(); // sort things such that the default tab group is at the front query.setSorter(DefaultTabGroupFirstSorter::getInstance()); - LLView::child_list_t result = query(this); + child_list_t result = query(this); + if(result.size() > 0) + { + LLUICtrl * ctrl = static_cast(result.front()); + if(!ctrl->hasFocus()) + { + ctrl->setFocus(TRUE); + ctrl->onTabInto(); + if(focus_flash) + { + gFocusMgr.triggerFocusFlash(); + } + } + return TRUE; + } + // search for text field first + if(prefer_text_fields) + { + LLCtrlQuery query = getTabOrderQuery(); + query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); + child_list_t result = query(this); + if(result.size() > 0) + { + LLUICtrl * ctrl = static_cast(result.front()); + if(!ctrl->hasFocus()) + { + ctrl->setFocus(TRUE); + ctrl->onTabInto(); + gFocusMgr.triggerFocusFlash(); + } + return TRUE; + } + } + // no text field found, or we don't care about text fields + result = getTabOrderQuery().run(this); if(result.size() > 0) { LLUICtrl * ctrl = static_cast(result.front()); @@ -359,10 +410,85 @@ BOOL LLUICtrl::focusFirstItem(BOOL prefer_text_fields) } return TRUE; } - // fall back on default behavior if we didn't find anything - return LLView::focusFirstItem(prefer_text_fields); + return FALSE; } +BOOL LLUICtrl::focusLastItem(BOOL prefer_text_fields) +{ + // search for text field first + if(prefer_text_fields) + { + LLCtrlQuery query = getTabOrderQuery(); + query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); + child_list_t result = query(this); + if(result.size() > 0) + { + LLUICtrl * ctrl = static_cast(result.back()); + if(!ctrl->hasFocus()) + { + ctrl->setFocus(TRUE); + ctrl->onTabInto(); + gFocusMgr.triggerFocusFlash(); + } + return TRUE; + } + } + // no text field found, or we don't care about text fields + child_list_t result = getTabOrderQuery().run(this); + if(result.size() > 0) + { + LLUICtrl * ctrl = static_cast(result.back()); + if(!ctrl->hasFocus()) + { + ctrl->setFocus(TRUE); + ctrl->onTabInto(); + gFocusMgr.triggerFocusFlash(); + } + return TRUE; + } + return FALSE; +} + +BOOL LLUICtrl::focusNextItem(BOOL text_fields_only) +{ + // this assumes that this method is called on the focus root. + LLCtrlQuery query = getTabOrderQuery(); + if(text_fields_only || LLUI::sConfigGroup->getBOOL("TabToTextFieldsOnly")) + { + query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); + } + child_list_t result = query(this); + return focusNext(result); +} + +BOOL LLUICtrl::focusPrevItem(BOOL text_fields_only) +{ + // this assumes that this method is called on the focus root. + LLCtrlQuery query = getTabOrderQuery(); + if(text_fields_only || LLUI::sConfigGroup->getBOOL("TabToTextFieldsOnly")) + { + query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); + } + child_list_t result = query(this); + return focusPrev(result); +} + +const LLUICtrl* LLUICtrl::findRootMostFocusRoot() const +{ + const LLUICtrl* focus_root = NULL; + const LLUICtrl* next_view = this; + while(next_view) + { + if (next_view->isFocusRoot()) + { + focus_root = next_view; + } + next_view = next_view->getParentUICtrl(); + } + return focus_root; +} + + /* // Don't let the children handle the tool tip. Handle it here instead. BOOL LLUICtrl::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect_screen) @@ -379,7 +505,7 @@ BOOL LLUICtrl::handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect_sc 0, 0, &(sticky_rect_screen->mLeft), &(sticky_rect_screen->mBottom) ); localPointToScreen( - mRect.getWidth(), mRect.getHeight(), + getRect().getWidth(), getRect().getHeight(), &(sticky_rect_screen->mRight), &(sticky_rect_screen->mTop) ); handled = TRUE; @@ -423,7 +549,26 @@ LLPanel* LLUICtrl::getParentPanel() const { parent = parent->getParent(); } - return reinterpret_cast(parent); + return (LLPanel*)(parent); +} + +// Skip over any parents that are not LLUICtrl's +// Used in focus logic since only LLUICtrl elements can have focus +LLUICtrl* LLUICtrl::getParentUICtrl() const +{ + LLView* parent = getParent(); + while (parent) + { + if (parent->isCtrl()) + { + return (LLUICtrl*)(parent); + } + else + { + parent = parent->getParent(); + } + } + return NULL; } // virtual -- cgit v1.1