Commit 3a1bce32 authored by Cyril Deguet's avatar Cyril Deguet

* parser/builder.cpp, parser/skin_parser.cpp: unique IDs are generated

 in the xml parser instead of the builder: fixes nasty bugs related
 to layout IDs
* theme/skin.dtd: "id" attribute is no longer required for window
parent e9050e58
......@@ -2,7 +2,7 @@
* builder.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: builder.cpp,v 1.7 2004/02/29 16:49:55 asmax Exp $
* $Id: builder.cpp,v 1.8 2004/03/01 18:33:31 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -143,7 +143,7 @@ void Builder::addWindow( const BuilderData::Window &rData )
m_pTheme->getWindowManager(), *pFont,
rData.m_dragDrop, rData.m_playOnDrop );
m_pTheme->m_windows[uniqueId( rData.m_id) ] = GenericWindowPtr( pWin );
m_pTheme->m_windows[rData.m_id] = GenericWindowPtr( pWin );
}
......@@ -166,7 +166,7 @@ void Builder::addLayout( const BuilderData::Layout &rData )
rData.m_height,
minWidth, maxWidth, minHeight,
maxHeight );
m_pTheme->m_layouts[uniqueId( rData.m_id) ] = GenericLayoutPtr( pLayout );
m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
// Attach the layout to its window
pWin->setActiveLayout( pLayout );
......@@ -227,7 +227,7 @@ void Builder::addButton( const BuilderData::Button &rData )
pLayout->addControl( pButton, pos, rData.m_layer );
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pButton );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
}
......@@ -298,7 +298,7 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
pLayout->addControl( pCheckbox, pos, rData.m_layer );
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pCheckbox );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
}
......@@ -350,7 +350,7 @@ void Builder::addImage( const BuilderData::Image &rData )
pLayout->addControl( pImage, pos, rData.m_layer );
}
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pImage );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
}
......@@ -386,7 +386,7 @@ void Builder::addText( const BuilderData::Text &rData )
rData.m_yPos + height, *pLayout ),
rData.m_layer );
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pText );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
}
......@@ -428,7 +428,7 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
pLayout->addControl( pRadial, pos, rData.m_layer );
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pRadial );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
}
......@@ -492,9 +492,8 @@ void Builder::addSlider( const BuilderData::Slider &rData )
pLayout->addControl( pBackground, pos, rData.m_layer );
pLayout->addControl( pCursor, pos, rData.m_layer );
string newId = uniqueId( rData.m_id );
m_pTheme->m_controls[newId] = CtrlGenericPtr( pCursor );
m_pTheme->m_controls[newId + "_bg"] = CtrlGenericPtr( pBackground );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
}
......@@ -537,50 +536,10 @@ void Builder::addList( const BuilderData::List &rData )
pLayout->addControl( pList, pos, rData.m_layer );
m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pList );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
}
const string Builder::generateId() const
{
static int i = 1;
char genId[5];
snprintf( genId, 4, "%i", i++ );
string base = "_ReservedId_" + (string)genId;
return base;
}
const string Builder::uniqueId( const string &id )
{
string newId;
if( m_idSet.find( id ) != m_idSet.end() )
{
// The id was already used
if( id != "none" )
{
msg_Warn( getIntf(), "Non unique id: %s", id.c_str() );
}
newId = generateId();
}
else
{
// OK, this is a new id
newId = id;
}
// Add the id to the set
m_idSet.insert( newId );
return newId;
}
const Position Builder::makePosition( const string &rLeftTop,
const string &rRightBottom,
int xPos, int yPos, int width,
......
......@@ -2,7 +2,7 @@
* builder.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: builder.hpp,v 1.3 2004/01/25 11:44:19 asmax Exp $
* $Id: builder.hpp,v 1.4 2004/03/01 18:33:31 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -37,7 +37,6 @@
#include <string>
#include <list>
#include <set>
#include <map>
class Theme;
......@@ -64,9 +63,6 @@ class Builder: public SkinObject
/// Theme under construction
Theme *m_pTheme;
/// Set of used id
set<string> m_idSet;
void addTheme( const BuilderData::Theme &rData );
void addBitmap( const BuilderData::Bitmap &rData );
void addFont( const BuilderData::Font &rData );
......@@ -81,13 +77,7 @@ class Builder: public SkinObject
void addSlider( const BuilderData::Slider &rData );
void addList( const BuilderData::List &rData );
/// Generate a new id
const string generateId() const;
/// Check if the id is unique, and if not generate a new one
const string uniqueId( const string &id );
/// Compute the position of a control
/// Compute the position of a control
const Position makePosition( const string &rLeftTop,
const string &rRightBottom,
int xPos, int yPos, int width, int height,
......
......@@ -2,7 +2,7 @@
* skin_parser.cpp
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: skin_parser.cpp,v 1.2 2004/02/29 16:49:55 asmax Exp $
* $Id: skin_parser.cpp,v 1.3 2004/03/01 18:33:31 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
*
......@@ -46,14 +46,14 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Bitmap" )
{
const BuilderData::Bitmap bitmap( attr["id"], attr["file"],
const BuilderData::Bitmap bitmap( attr["id"] , attr["file"],
ConvertColor( attr["alphacolor"] ) );
m_data.m_listBitmap.push_back( bitmap );
}
else if( rName == "Button" )
{
const BuilderData::Button button( attr["id"], atoi( attr["x"] ) +
const BuilderData::Button button( uniqueId( attr["id"] ), atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
attr["rightbottom"], attr["up"], attr["down"], attr["over"],
attr["action"], attr["tooltiptext"], attr["help"], m_curLayer,
......@@ -64,7 +64,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "CheckBox" )
{
const BuilderData::Checkbox checkbox( attr["id"], atoi( attr["x"] ) +
const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ), atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
attr["rightbottom"], attr["up1"], attr["down1"], attr["over1"],
attr["up2"], attr["down2"], attr["over2"], attr["state"],
......@@ -92,7 +92,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Image" )
{
const BuilderData::Image imageData( attr["id"], atoi( attr["x"] ) +
const BuilderData::Image imageData( uniqueId( attr["id"] ), atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
attr["rightbottom"], ConvertBoolean( attr["visible"] ),
attr["image"], attr["onclick"], attr["help"], m_curLayer,
......@@ -103,18 +103,19 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Layout" )
{
const BuilderData::Layout layout( attr["id"], atoi( attr["width"] ),
m_curLayoutId = uniqueId( attr["id"] );
const BuilderData::Layout layout( m_curLayoutId, atoi( attr["width"] ),
atoi( attr["height"] ), atoi( attr["minwidth"] ),
atoi( attr["maxwidth"] ), atoi( attr["minheight"] ),
atoi( attr["maxheight"] ), m_curWindowId );
m_data.m_listLayout.push_back( layout );
m_curLayoutId = attr["id"];
m_curLayer = 0;
}
else if( rName == "Playlist" )
{
const BuilderData::List listData( attr["id"], atoi( attr["x"] ) +
m_curListId = uniqueId( attr["id"] );
const BuilderData::List listData( m_curListId, atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["width"]),
atoi( attr["height"] ), attr["lefttop"], attr["rightbottom"],
attr["font"], attr["var"], ConvertColor( attr["fgcolor"] ),
......@@ -124,13 +125,12 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
ConvertColor( attr["selcolor"] ), attr["help"],
m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++;
m_curListId = attr["id"];
m_data.m_listList.push_back( listData );
}
else if( rName == "RadialSlider" )
{
const BuilderData::RadialSlider radial( attr["id"], attr["visible"],
const BuilderData::RadialSlider radial( uniqueId( attr["id"] ), attr["visible"],
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
attr["lefttop"], attr["rightbottom"], attr["sequence"],
atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI / 180,
......@@ -149,7 +149,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
// Slider associated to a list
newValue = "playlist.slider";
}
const BuilderData::Slider slider( attr["id"], attr["visible"],
const BuilderData::Slider slider( uniqueId( attr["id"] ), attr["visible"],
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
attr["lefttop"], attr["rightbottom"], attr["up"], attr["down"],
attr["over"], attr["points"], atoi( attr["thickness"] ),
......@@ -161,7 +161,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Text" )
{
const BuilderData::Text textData( attr["id"], atoi( attr["x"] ) +
const BuilderData::Text textData( uniqueId( attr["id"] ), atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["font"],
attr["text"], atoi( attr["width"] ),
ConvertColor( attr["color"] ), attr["help"], m_curLayer,
......@@ -192,13 +192,13 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Window" )
{
const BuilderData::Window window( attr["id"],
m_curWindowId = uniqueId( attr["id"] );
const BuilderData::Window window( m_curWindowId,
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
ConvertBoolean( attr["visible"] ),
ConvertBoolean( attr["dragdrop"] ),
ConvertBoolean( attr["playondrop"] ) );
m_data.m_listWindow.push_back( window );
m_curWindowId = attr["id"];
}
}
......@@ -234,3 +234,41 @@ int SkinParser::ConvertColor( const char *transcolor ) const
return ( iRed << 16 | iGreen << 8 | iBlue );
}
const string SkinParser::generateId() const
{
static int i = 1;
char genId[5];
snprintf( genId, 4, "%i", i++ );
string base = "_ReservedId_" + (string)genId;
return base;
}
const string SkinParser::uniqueId( const string &id )
{
string newId;
if( m_idSet.find( id ) != m_idSet.end() )
{
// The id was already used
if( id != "none" )
{
msg_Warn( getIntf(), "Non unique id: %s", id.c_str() );
}
newId = generateId();
}
else
{
// OK, this is a new id
newId = id;
}
// Add the id to the set
m_idSet.insert( newId );
return newId;
}
......@@ -2,7 +2,7 @@
* skin_parser.hpp
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: skin_parser.hpp,v 1.1 2004/01/25 11:44:19 asmax Exp $
* $Id: skin_parser.hpp,v 1.2 2004/03/01 18:33:31 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
*
......@@ -26,6 +26,7 @@
#include "xmlparser.hpp"
#include "builder_data.hpp"
#include <set>
/// Parser for the skin DTD
......@@ -49,6 +50,8 @@ class SkinParser: public XMLParser
list<int> m_xOffsetList, m_yOffsetList;
/// Layer of the current control in the layout
int m_curLayer;
/// Set of used id
set<string> m_idSet;
/// Callbacks
virtual void handleBeginElement( const string &rName, AttrList_t &attr );
......@@ -57,6 +60,12 @@ class SkinParser: public XMLParser
/// Helper functions
bool ConvertBoolean( const char *value ) const;
int ConvertColor( const char *transcolor ) const;
/// Generate a new id
const string generateId() const;
/// Check if the id is unique, and if not generate a new one
const string uniqueId( const string &id );
};
#endif
......@@ -42,7 +42,7 @@
>
<!ELEMENT Window (Layout)+>
<!ATTLIST Window
id CDATA #REQUIRED
id CDATA "none"
visible CDATA "true"
x CDATA "0"
y CDATA "0"
......
......@@ -64,7 +64,7 @@
<Font id="default_font" font="FreeSansBold.ttf" size="15"/>
<Font id="playlist_font" font="FreeSansBold.ttf" size="12"/>
<Window id="mainwindow" x="230" y="250" dragdrop="true">
<Window x="230" y="250" dragdrop="true">
<Layout id="testlayout" width="424" height="152">
<Group x="0" y="0">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment