CHANGED: #1471 Implemented property querying for CCtrlBase and CInterfaceGroup.

This commit is contained in:
dfighter1985 2012-07-28 00:17:41 +02:00
parent f245e69063
commit 307129e1bf
10 changed files with 374 additions and 15 deletions

View file

@ -30,7 +30,7 @@ namespace NLGUI
public: public:
// Tooltip mode // Tooltip mode
enum TToolTipParentType enum TToolTipParentType
{ {
TTMouse= 0, // The tooltip is displayed relatively to the mouse when it appears TTMouse= 0, // The tooltip is displayed relatively to the mouse when it appears
TTCtrl= 1, // The tooltip is displayed relatively to the ctrl it comes from when it apeears TTCtrl= 1, // The tooltip is displayed relatively to the ctrl it comes from when it apeears
@ -56,6 +56,8 @@ namespace NLGUI
/// Destructor /// Destructor
virtual ~CCtrlBase(); virtual ~CCtrlBase();
static std::string tooltipParentToString( TToolTipParentType type );
// special parse // special parse
virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup);

View file

@ -341,6 +341,7 @@ namespace NLGUI
// set sizeref as a string, like "wh", "wh5" .... // set sizeref as a string, like "wh", "wh5" ....
void setSizeRef(const std::string &sizeref); void setSizeRef(const std::string &sizeref);
std::string getSizeRefAsString() const; std::string getSizeRefAsString() const;
std::string getSizeRefAsString( const sint32 &sizeRef, const sint32 &sizeDivW, const sint32 &sizeDivH ) const;
// export some properties // export some properties
REFLECT_EXPORT_START(CInterfaceElement, CReflectable) REFLECT_EXPORT_START(CInterfaceElement, CReflectable)

View file

@ -168,6 +168,7 @@ namespace NLGUI
/// LUA Class Association builder : associate a lua script to a group (called for each group after every document parsed) /// LUA Class Association builder : associate a lua script to a group (called for each group after every document parsed)
void addLuaClassAssociation(CInterfaceGroup *group, const std::string &luaScript); void addLuaClassAssociation(CInterfaceGroup *group, const std::string &luaScript);
std::string getLuaClassAssociation( CInterfaceGroup *group ) const;
/** /**
* Accessors * Accessors

View file

@ -48,6 +48,7 @@ namespace NLGUI
virtual std::string getParentPosAssociation( CInterfaceElement *element ) const = 0; virtual std::string getParentPosAssociation( CInterfaceElement *element ) const = 0;
virtual std::string getParentSizeAssociation( CInterfaceElement *element ) const = 0; virtual std::string getParentSizeAssociation( CInterfaceElement *element ) const = 0;
virtual std::string getParentSizeMaxAssociation( CInterfaceElement *element ) const = 0; virtual std::string getParentSizeMaxAssociation( CInterfaceElement *element ) const = 0;
virtual std::string getLuaClassAssociation( CInterfaceGroup *group ) const = 0;
virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, const std::pair< std::string, std::string > *templateParams, uint numParams, bool updateLinks = true ) = 0; virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, const std::pair< std::string, std::string > *templateParams, uint numParams, bool updateLinks = true ) = 0;
virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, std::vector< std::pair< std::string, std::string > > &templateParams, bool updateLinks = true ) = 0; virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, std::vector< std::pair< std::string, std::string > > &templateParams, bool updateLinks = true ) = 0;
virtual bool parseGroupChildren( xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload ) = 0; virtual bool parseGroupChildren( xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload ) = 0;

View file

@ -60,6 +60,26 @@ namespace NLGUI
return false; return false;
} }
std::string CCtrlBase::tooltipParentToString( TToolTipParentType type )
{
switch( type )
{
case TTMouse:
return "mouse";
break;
case TTWindow:
return "win";
break;
case TTSpecialWindow:
return "special";
break;
}
return "";
}
// *************************************************************************** // ***************************************************************************
bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) bool CCtrlBase::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
{ {
@ -76,7 +96,7 @@ namespace NLGUI
_ContextHelp = ucstring(propPtr); _ContextHelp = ucstring(propPtr);
if (strlen(propPtr) > 2) if( !editorMode && ( strlen(propPtr) > 2 ) )
{ {
if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) if ((propPtr[0] == 'u') && (propPtr[1] == 'i'))
_ContextHelp = CI18N::get ((const char *) prop); _ContextHelp = CI18N::get ((const char *) prop);
@ -86,7 +106,10 @@ namespace NLGUI
prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" );
if ((bool)prop && strlen((const char*)prop)>0) if ((bool)prop && strlen((const char*)prop)>0)
{ {
_ContextHelp = CI18N::get ((const char *) prop); if( !editorMode )
_ContextHelp = CI18N::get ((const char *) prop);
else
_ContextHelp = (const char*)prop;
} }
// get dynamic toolTip ActionHandler // get dynamic toolTip ActionHandler
@ -147,6 +170,16 @@ namespace NLGUI
std::string CCtrlBase::getProperty( const std::string &name ) const std::string CCtrlBase::getProperty( const std::string &name ) const
{ {
if( name == "tooltip" )
{
return _ContextHelp.toString();
}
else
if( name == "tooltip_i18n" )
{
return _ContextHelp.toString();
}
else
if( name == "on_tooltip" ) if( name == "on_tooltip" )
{ {
return _OnContextHelp.toString(); return _OnContextHelp.toString();
@ -156,8 +189,49 @@ namespace NLGUI
{ {
return _OnContextHelpParams.toString(); return _OnContextHelpParams.toString();
} }
else
return CInterfaceElement::getProperty( name ); if( name == "tooltip_parent" )
{
return tooltipParentToString( _ToolTipParent );
}
else
if( name == "tooltip_special_parent" )
{
return _ToolTipSpecialParent.toString();
}
else
if( name == "tooltip_posref" )
{
std::string s;
if( ( _ToolTipParentPosRef == Hotspot_TTAuto ) && ( _ToolTipPosRef == Hotspot_TTAuto ) )
return "auto";
else{
s = CInterfaceElement::HotSpotToString( _ToolTipParentPosRef );
s += " ";
s += CInterfaceElement::HotSpotToString( _ToolTipPosRef );
return s;
}
}
else
if( name == "tooltip_posref_alt" )
{
std::string s;
if( ( _ToolTipParentPosRef == Hotspot_TTAuto ) && ( _ToolTipPosRef == Hotspot_TTAuto ) )
return "auto";
else{
s = CInterfaceElement::HotSpotToString( _ToolTipParentPosRef );
s += " ";
s += CInterfaceElement::HotSpotToString( _ToolTipPosRef );
return s;
}
}
else
if( name == "instant_help" )
{
return toString( _ToolTipInstant );
}
else
return CInterfaceElement::getProperty( name );
} }
// *************************************************************************** // ***************************************************************************

View file

@ -261,7 +261,7 @@ namespace NLGUI
else else
if( name == "sizeref" ) if( name == "sizeref" )
{ {
return getSizeRefAsString(); return getSizeRefAsString( _SizeRef, _SizeDivW, _SizeDivH );
} }
if( name == "posparent" ) if( name == "posparent" )
{ {
@ -300,20 +300,25 @@ namespace NLGUI
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::string CInterfaceElement::getSizeRefAsString() const std::string CInterfaceElement::getSizeRefAsString() const
{
return getSizeRefAsString( _SizeRef, _SizeDivW, _SizeDivH );
}
std::string CInterfaceElement::getSizeRefAsString( const sint32 &sizeRef, const sint32 &sizeDivW, sint32 const &sizeDivH ) const
{ {
std::string s; std::string s;
if( ( _SizeRef & 1 ) != 0 ) if( ( sizeRef & 1 ) != 0 )
{ {
s += "w"; s += "w";
if( _SizeDivW < 10 ) if( sizeDivW < 10 )
s += toString( _SizeDivW ); s += toString( sizeDivW );
} }
if( ( _SizeRef & 2 ) != 0 ) if( ( _SizeRef & 2 ) != 0 )
{ {
s += "h"; s += "h";
if( _SizeDivH < 10 ) if( sizeDivH < 10 )
s += toString( _SizeDivH ); s += toString( sizeDivH );
} }
return s; return s;

View file

@ -355,6 +355,96 @@ namespace NLGUI
std::string CInterfaceGroup::getProperty( const std::string &name ) const std::string CInterfaceGroup::getProperty( const std::string &name ) const
{ {
if( name == "overlappable" )
{
return NLMISC::toString( _Overlappable );
}
else
if( name == "escapable" )
{
return NLMISC::toString( _Escapable );
}
else
if( name == "child_resize_w" )
{
return NLMISC::toString( _ResizeFromChildW );
}
else
if( name == "child_resize_h" )
{
return NLMISC::toString( _ResizeFromChildH );
}
else
if( name == "child_resize_wmargin" )
{
return NLMISC::toString( _ResizeFromChildWMargin );
}
else
if( name == "child_resize_hmargin" )
{
return NLMISC::toString( _ResizeFromChildHMargin );
}
else
if( name == "on_active" )
{
return getOnActiveHandler();
}
else
if( name == "on_active_params" )
{
return getOnActiveParams();
}
else
if( name == "on_deactive" )
{
return getOnDeactiveHandler();
}
else
if( name == "on_deactive_params" )
{
return getOnDeactiveParams();
}
else
if( name == "max_w" )
{
return NLMISC::toString( _MaxW );
}
else
if( name == "max_h" )
{
return NLMISC::toString( _MaxH );
}
else
if( name == "max_sizeref" )
{
return getSizeRefAsString( _GroupSizeRef, _SizeDivW, _SizeDivH );
}
else
if( name == "max_sizeparent" )
{
return CWidgetManager::getInstance()->getParser()->getParentSizeMaxAssociation( (CInterfaceElement*)this );
}
else
if( name == "group_onclick_r" )
{
return getRightClickHandler();
}
else
if( name == "group_params_r" )
{
return getRightClickHandlerParams();
}
else
if( name == "group_onclick_l" )
{
return getLeftClickHandler();
}
else
if( name == "group_params_l" )
{
return getLeftClickHandlerParams();
}
else
if( name == "on_enter" ) if( name == "on_enter" )
{ {
return getAHOnEnter(); return getAHOnEnter();
@ -364,8 +454,33 @@ namespace NLGUI
{ {
return getAHOnEnterParams(); return getAHOnEnterParams();
} }
else
return CCtrlBase::getProperty( name ); if( name == "win_priority" )
{
return NLMISC::toString( _Priority );
}
else
if( name == "use_cursor" )
{
return NLMISC::toString( _UseCursor );
}
else
if( name == "on_escape" )
{
return getAHOnEscape();
}
else
if( name == "on_escape_params" )
{
return getAHOnEscapeParams();
}
else
if( name == "lua_class" )
{
return CWidgetManager::getInstance()->getParser()->getLuaClassAssociation( (CInterfaceGroup*)this );
}
else
return CCtrlBase::getProperty( name );
} }

View file

@ -2017,6 +2017,16 @@ namespace NLGUI
_LuaClassAssociation.insert (std::map<CInterfaceGroup*,std::string>::value_type(group, luaScript)); _LuaClassAssociation.insert (std::map<CInterfaceGroup*,std::string>::value_type(group, luaScript));
} }
std::string CInterfaceParser::getLuaClassAssociation( CInterfaceGroup *group ) const
{
std::map< CInterfaceGroup*, std::string >::const_iterator itr =
_LuaClassAssociation.find( group );
if( itr == _LuaClassAssociation.end() )
return "";
else
return itr->second;
}
// *************************************************************************** // ***************************************************************************
const std::string &CInterfaceParser::getDefine(const std::string &id) const const std::string &CInterfaceParser::getDefine(const std::string &id) const
{ {

View file

@ -8,15 +8,50 @@
<icon></icon> <icon></icon>
</header> </header>
<properties> <properties>
<property>
<name>tooltip</name>
<type>string</type>
<default></default>
</property>
<property>
<name>tooltip_i18n</name>
<type>string</type>
<default></default>
</property>
<property> <property>
<name>on_tooltip</name> <name>on_tooltip</name>
<type>string</type> <type>string</type>
<default>handler</default> <default></default>
</property> </property>
<property> <property>
<name>on_tooltip_params</name> <name>on_tooltip_params</name>
<type>string</type> <type>string</type>
<default>params</default> <default></default>
</property>
<property>
<name>tooltip_parent</name>
<type>string</type>
<default></default>
</property>
<property>
<name>tooltip_special_parent</name>
<type>string</type>
<default></default>
</property>
<property>
<name>tooltip_posref</name>
<type>string</type>
<default>auto</default>
</property>
<property>
<name>tooltip_posref_alt</name>
<type>string</type>
<default>auto</default>
</property>
<property>
<name>instant_help</name>
<type>bool</type>
<default></default>
</property> </property>
</properties> </properties>
</widget> </widget>

View file

@ -8,6 +8,96 @@
<icon></icon> <icon></icon>
</header> </header>
<properties> <properties>
<property>
<name>overlappable</name>
<type>bool</type>
<default>true</default>
</property>
<property>
<name>escapable</name>
<type>bool</type>
<default>false</default>
</property>
<property>
<name>child_resize_w</name>
<type>bool</type>
<default>false</default>
</property>
<property>
<name>child_resize_h</name>
<type>bool</type>
<default>false</default>
</property>
<property>
<name>child_resize_wmargin</name>
<type>int</type>
<default>0</default>
</property>
<property>
<name>child_resize_hmargin</name>
<type>int</type>
<default>0</default>
</property>
<property>
<name>on_active</name>
<type>string</type>
<default></default>
</property>
<property>
<name>on_active_params</name>
<type>string</type>
<default></default>
</property>
<property>
<name>on_deactive</name>
<type>string</type>
<default></default>
</property>
<property>
<name>on_deactive_params</name>
<type>string</type>
<default></default>
</property>
<property>
<name>max_w</name>
<type>int</type>
<default>16384</default>
</property>
<property>
<name>max_h</name>
<type>int</type>
<default>16384</default>
</property>
<property>
<name>max_sizeref</name>
<type>string</type>
<default></default>
</property>
<property>
<name>max_sizeparent</name>
<type>string</type>
<default>parent</default>
</property>
<property>
<name>group_onclick_r</name>
<type>string</type>
<default></default>
</property>
<property>
<name>group_params_r</name>
<type>string</type>
<default></default>
</property>
<property>
<name>group_onclick_l</name>
<type>string</type>
<default></default>
</property>
<property>
<name>group_params_l</name>
<type>string</type>
<default></default>
</property>
<property> <property>
<name>on_enter</name> <name>on_enter</name>
<type>string</type> <type>string</type>
@ -18,5 +108,30 @@
<type>string</type> <type>string</type>
<default>params</default> <default>params</default>
</property> </property>
<property>
<name>win_proprity</name>
<type>int</type>
<default>3</default>
</property>
<property>
<name>use_cursor</name>
<type>bool</type>
<default>true</default>
</property>
<property>
<name>on_escape</name>
<type>string</type>
<default></default>
</property>
<property>
<name>on_escape_params</name>
<type>string</type>
<default></default>
</property>
<property>
<name>lua_class</name>
<type>string</type>
<default></default>
</property>
</properties> </properties>
</widget> </widget>