setCommitOnReturn moved to from llbutton to lluictrl, cleanup some focus/key handling, avoid needless reshape calls.

This commit is contained in:
Shyotl
2013-10-26 18:12:56 -05:00
parent 30c5b9514e
commit edf75a7174
5 changed files with 52 additions and 53 deletions

View File

@@ -207,9 +207,6 @@ public:
void setImageFlash(LLPointer<LLUIImage> image);
void setImagePressed(LLPointer<LLUIImage> image);
void setCommitOnReturn(BOOL commit) { mCommitOnReturn = commit; }
BOOL getCommitOnReturn() const { return mCommitOnReturn; }
static void onHeldDown(void *userdata); // to be called by gIdleCallbacks
void setHelpURLCallback(const std::string &help_url);
const std::string& getHelpURL() const { return mHelpURL; }

View File

@@ -159,8 +159,12 @@ void LLPanel::addBorder(LLViewBorder::EBevel border_bevel,
void LLPanel::removeBorder()
{
delete mBorder;
mBorder = NULL;
if (mBorder)
{
removeChild(mBorder);
delete mBorder;
mBorder = NULL;
}
}
@@ -277,7 +281,7 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask )
// handle user hitting ESC to defocus
if (key == KEY_ESCAPE && mask == MASK_NONE)
{
gFocusMgr.setKeyboardFocus(NULL);
setFocus(FALSE);
return TRUE;
}
else if( (mask == MASK_SHIFT) && (KEY_TAB == key))
@@ -304,29 +308,25 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask )
}
}
}
// 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<LLButton*>(cur_focus);
if (cur_focus && !(focused_button && focused_button->getCommitOnReturn()))
// If RETURN was pressed and something has focus, call onCommit()
if (!handled && cur_focus && key == KEY_RETURN && mask == MASK_NONE)
{
// RETURN key means hit default button in this case
if (key == KEY_RETURN && mask == MASK_NONE
&& mDefaultBtn != NULL
&& mDefaultBtn->getVisible()
&& mDefaultBtn->getEnabled())
if (cur_focus->getCommitOnReturn())
{
// current focus is a return-capturing element,
// let *that* element handle the return key
handled = FALSE;
}
else if (mDefaultBtn && mDefaultBtn->getVisible() && mDefaultBtn->getEnabled())
{
// If we have a default button, click it when return is pressed
mDefaultBtn->onCommit();
handled = TRUE;
}
}
if (key == KEY_RETURN && mask == MASK_NONE)
{
// set keyboard focus to self to trigger commitOnFocusLost behavior on current ctrl
if (cur_focus && cur_focus->acceptsTextInput())
else if (cur_focus->acceptsTextInput())
{
// call onCommit for text input handling control
cur_focus->onCommit();
handled = TRUE;
}
@@ -363,34 +363,16 @@ void LLPanel::handleVisibilityChange ( BOOL new_visibility )
void LLPanel::setFocus(BOOL b)
{
if( b )
if( b && !hasFocus())
{
if (!gFocusMgr.childHasKeyboardFocus(this))
{
//refresh();
if (!focusFirstItem())
{
LLUICtrl::setFocus(TRUE);
}
onFocusReceived();
}
// give ourselves focus preemptively, to avoid infinite loop
LLUICtrl::setFocus(TRUE);
// then try to pass to first valid child
focusFirstItem();
}
else
{
if( this == gFocusMgr.getKeyboardFocus() )
{
gFocusMgr.setKeyboardFocus( NULL );
}
else
{
//RN: why is this here?
LLView::ctrl_list_t ctrls = getCtrlList();
for (LLView::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it)
{
LLUICtrl* ctrl = *ctrl_it;
ctrl->setFocus( FALSE );
}
}
LLUICtrl::setFocus(b);
}
}

View File

@@ -56,7 +56,8 @@ LLUICtrl::LLUICtrl() :
mDoubleClickSignal(NULL),
mTentative(FALSE),
mTabStop(TRUE),
mIsChrome(FALSE)
mIsChrome(FALSE),
mCommitOnReturn(FALSE)
{
}
@@ -78,7 +79,8 @@ LLUICtrl::LLUICtrl(const std::string& name, const LLRect rect, BOOL mouse_opaque
mDoubleClickSignal(NULL),
mTentative( FALSE ),
mTabStop( TRUE ),
mIsChrome(FALSE)
mIsChrome(FALSE),
mCommitOnReturn(FALSE)
{
if(commit_callback)
setCommitCallback(commit_callback);
@@ -178,6 +180,13 @@ BOOL LLUICtrl::handleDoubleClick(S32 x, S32 y, MASK mask)
return handled;
}
// can't tab to children of a non-tab-stop widget
BOOL LLUICtrl::canFocusChildren() const
{
return TRUE;//hasTabStop();
}
void LLUICtrl::onCommit()
{
if (mCommitSignal)
@@ -528,7 +537,8 @@ 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"))
static LLUICachedControl<bool> tab_to_text_fields_only ("TabToTextFieldsOnly", false);
if(text_fields_only || tab_to_text_fields_only)
{
query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance());
}
@@ -540,7 +550,8 @@ 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"))
static LLUICachedControl<bool> tab_to_text_fields_only ("TabToTextFieldsOnly", false);
if(text_fields_only || tab_to_text_fields_only)
{
query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance());
}
@@ -552,7 +563,7 @@ LLUICtrl* LLUICtrl::findRootMostFocusRoot()
{
LLUICtrl* focus_root = NULL;
LLUICtrl* next_view = this;
while(next_view)
while(next_view/* && next_view->hasTabStop()*/)
{
if (next_view->isFocusRoot())
{

View File

@@ -70,6 +70,7 @@ public:
/*virtual*/ BOOL isCtrl() const;
/*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask);
/*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
/*virtual*/ BOOL canFocusChildren() const;
/*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
/*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
/*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
@@ -132,6 +133,9 @@ public:
LLUICtrl* getParentUICtrl() const;
void setCommitOnReturn(BOOL commit) { mCommitOnReturn = commit; }
BOOL getCommitOnReturn() const { return mCommitOnReturn; }
//Start using these!
boost::signals2::connection setCommitCallback( const commit_signal_t::slot_type& cb );
boost::signals2::connection setValidateCallback( const enable_signal_t::slot_type& cb );
@@ -198,6 +202,8 @@ private:
BOOL mIsChrome;
BOOL mTentative;
bool mCommitOnReturn;
class DefaultTabGroupFirstSorter;
};

View File

@@ -1377,7 +1377,10 @@ void LLView::reshape(S32 width, S32 height, BOOL called_from_parent)
S32 delta_x = child_rect.mLeft - viewp->getRect().mLeft;
S32 delta_y = child_rect.mBottom - viewp->getRect().mBottom;
viewp->translate( delta_x, delta_y );
viewp->reshape(child_rect.getWidth(), child_rect.getHeight());
if (child_rect.getWidth() != viewp->getRect().getWidth() || child_rect.getHeight() != viewp->getRect().getHeight())
{
viewp->reshape(child_rect.getWidth(), child_rect.getHeight());
}
}
}