From 81717b48cdb23df13c3ca31bd2c5b881ec39e8f4 Mon Sep 17 00:00:00 2001 From: Erwan Tulou Date: Sat, 11 Dec 2010 11:56:14 +0100 Subject: [PATCH] skins2: implement a new 'focus' attribute for text control Up to now, text control could but be focusable, and this focus was used to scroll text, should it be too long for full display. From a user viewpoint, this behavior is often counterintuitive : - Most of the time, the control is designed to fit the text anyway, and scrolling is not expected. - On the other hand, an underlying control may be used to move the window (for instance, the title bar), and a text control is expected not to interact in this endeavor. Same goes for popupmenu, that is expected to work if one happens to right-click on a text control. This patch adds a 'focus' attribute to the text control, and leave it to the skins developper to decide which behavior is most desirable on a per-control basis. focus still defaults to true to maintain skins current behavior. --- doc/skins/skins2-howto.xml | 5 +++++ modules/gui/skins2/controls/ctrl_text.cpp | 9 ++++++--- modules/gui/skins2/controls/ctrl_text.hpp | 6 ++++-- modules/gui/skins2/parser/builder.cpp | 5 +++-- modules/gui/skins2/parser/builder_data.def | 2 +- modules/gui/skins2/parser/builder_data.hpp | 5 +++-- modules/gui/skins2/parser/skin_parser.cpp | 4 +++- share/skins2/skin.dtd | 1 + 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/skins/skins2-howto.xml b/doc/skins/skins2-howto.xml index 20d05f4145..cacdffd5d6 100644 --- a/doc/skins/skins2-howto.xml +++ b/doc/skins/skins2-howto.xml @@ -642,6 +642,11 @@ difficulty to understand how VLC skins work. Alignment of the text inside the control. Possible values are 'left', 'center' and 'right'. The 'width' and 'center' alignments are computed using the width of the control (as given by the width attribute). Available since VLC 0.8.5. Default value: left + + focus + indicates if the control is eligible for mouse focus or not. If focus is set to false, it is as though the control did not exist when it comes to mouse focus. This allows for instance displaying a dynamic text in the title bar, yet opting for being able to move the window rather than manage scrolling of lengthy text. Available in VLC 1.2.0. + Default value: true + scrolling Scrolling behaviour of the text (only when it doesn't fit in the width of the control). Possible values are 'auto', 'manual' and 'none'. If this attribute is set to 'auto', the text automatically starts scrolling. The user can drag the text, and click on it to start/stop the scrolling. If this attribute is set to 'manual', the text only scrolls when dragged by the user. If this attribute is set to 'none', no scrolling is possible at all. Available since VLC 0.8.5. diff --git a/modules/gui/skins2/controls/ctrl_text.cpp b/modules/gui/skins2/controls/ctrl_text.cpp index 513028fe7c..4a0859029a 100644 --- a/modules/gui/skins2/controls/ctrl_text.cpp +++ b/modules/gui/skins2/controls/ctrl_text.cpp @@ -42,9 +42,9 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable, const GenericFont &rFont, const UString &rHelp, - uint32_t color, VarBool *pVisible, Scrolling_t scrollMode, - Align_t alignment ): - CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), + uint32_t color, VarBool *pVisible, VarBool *pFocus, + Scrolling_t scrollMode, Align_t alignment ): + CtrlGeneric( pIntf, rHelp, pVisible ), m_pFocus( pFocus), m_fsm( pIntf ), m_rVariable( rVariable ), m_cmdToManual( this ), m_cmdManualMoving( this ), m_cmdManualStill( this ), m_cmdMove( this ), m_pEvt( NULL ), m_rFont( rFont ), @@ -121,6 +121,9 @@ void CtrlText::handleEvent( EvtGeneric &rEvent ) bool CtrlText::mouseOver( int x, int y ) const { + if( !m_pFocus->get() ) + return false; + if( m_pCurrImg ) { // We have 3 different ways of deciding when to return true here: diff --git a/modules/gui/skins2/controls/ctrl_text.hpp b/modules/gui/skins2/controls/ctrl_text.hpp index c0a35bb619..828cb2a9a2 100644 --- a/modules/gui/skins2/controls/ctrl_text.hpp +++ b/modules/gui/skins2/controls/ctrl_text.hpp @@ -63,8 +63,8 @@ public: /// Create a text control with the optional given color CtrlText( intf_thread_t *pIntf, VarText &rVariable, const GenericFont &rFont, const UString &rHelp, - uint32_t color, VarBool *pVisible, Scrolling_t scrollMode, - Align_t alignment); + uint32_t color, VarBool *pVisible, VarBool *pFocus, + Scrolling_t scrollMode, Align_t alignment); virtual ~CtrlText(); /// Handle an event @@ -103,6 +103,8 @@ private: Scrolling_t m_scrollMode; /// Type of alignment Align_t m_alignment; + /// indicate if control is focusable + VarBool *m_pFocus; /// Image of the text GenericBitmap *m_pImg; /// Image of the text, repeated twice and with some blank between; diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index ab4ba9c777..d41f6b15e6 100644 --- a/modules/gui/skins2/parser/builder.cpp +++ b/modules/gui/skins2/parser/builder.cpp @@ -739,10 +739,11 @@ void Builder::addText( const BuilderData::Text &rData ) // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); + VarBool *pFocus = pInterpreter->getVarBool( rData.m_focus, m_pTheme ); CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont, - UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible, - scrolling, alignment ); + UString( getIntf(), rData.m_help.c_str() ), rData.m_color, + pVisible, pFocus, scrolling, alignment ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText ); int height = pFont->getSize(); diff --git a/modules/gui/skins2/parser/builder_data.def b/modules/gui/skins2/parser/builder_data.def index 3571a32f99..08939c85e8 100644 --- a/modules/gui/skins2/parser/builder_data.def +++ b/modules/gui/skins2/parser/builder_data.def @@ -14,7 +14,7 @@ Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRati Image id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool visible:string bmpId:string actionId:string action2Id:string resize:string help:string art:bool layer:int windowId:string layoutId:string panelId:string IniFile id:string file:string Panel id:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool width:int height:int layer:int windowId:string layoutId:string panelId:string -Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool color:uint32_t scrolling:string alignment:string help:string layer:int windowId:string layoutId:string panelId:string +Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool color:uint32_t scrolling:string alignment:string focus:string help:string layer:int windowId:string layoutId:string panelId:string RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool sequence:string nbImages:int minAngle:float maxAngle:float value:string tooltip:string help:string layer:int windowId:string layoutId:string panelId:string Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool upId:string downId:string overId:string points:string thickness:int value:string imageId:string nbHoriz:int nbVert:int padHoriz:int padVert:int tooltip:string help:string layer:int windowId:string layoutId:string panelId:string List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool fontId:string var:string bgImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string panelId:string diff --git a/modules/gui/skins2/parser/builder_data.hpp b/modules/gui/skins2/parser/builder_data.hpp index e9243bc283..a14bdf52cd 100644 --- a/modules/gui/skins2/parser/builder_data.hpp +++ b/modules/gui/skins2/parser/builder_data.hpp @@ -337,8 +337,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( /// Type definition struct Text { - Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, uint32_t color, const string & scrolling, const string & alignment, const string & help, int layer, const string & windowId, const string & layoutId, const string & panelId ): -m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_color( color ), m_scrolling( scrolling ), m_alignment( alignment ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ), m_panelId( panelId ) {} + Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, uint32_t color, const string & scrolling, const string & alignment, const string & focus, const string & help, int layer, const string & windowId, const string & layoutId, const string & panelId ): +m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_color( color ), m_scrolling( scrolling ), m_alignment( alignment ), m_focus( focus ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ), m_panelId( panelId ) {} string m_id; int m_xPos; @@ -354,6 +354,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( font uint32_t m_color; string m_scrolling; string m_alignment; + string m_focus; string m_help; int m_layer; string m_windowId; diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index 3e18e6083b..7be0cd9d51 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -625,6 +625,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) DefaultAttr( attr, "color", "#000000" ); DefaultAttr( attr, "scrolling", "auto" ); DefaultAttr( attr, "alignment", "left" ); + DefaultAttr( attr, "focus", "true" ); DefaultAttr( attr, "width", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); @@ -649,7 +650,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) convertBoolean( attr["ykeepratio"] ), convertColor( attr["color"] ), attr["scrolling"], attr["alignment"], - attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, + attr["focus"], attr["help"], + m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listText.push_back( textData ); diff --git a/share/skins2/skin.dtd b/share/skins2/skin.dtd index de0227eff0..f1c05f77f4 100644 --- a/share/skins2/skin.dtd +++ b/share/skins2/skin.dtd @@ -257,6 +257,7 @@ color CDATA "#000000" scrolling CDATA "auto" alignment CDATA "left" + focus CDATA "true" help CDATA "" >