added WidgetFactory class
This commit is contained in:
parent
e47b586ee3
commit
21f437745c
|
@ -21,7 +21,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Author : $Author: maroy $
|
# Author : $Author: maroy $
|
||||||
# Version : $Revision: 1.3 $
|
# Version : $Revision: 1.4 $
|
||||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
|
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
|
||||||
#
|
#
|
||||||
# @configure_input@
|
# @configure_input@
|
||||||
|
@ -77,6 +77,7 @@ TEST_XSLT = ../etc/testResultToHtml.xsl
|
||||||
WIDGETS_LIB = livesupport_widgets
|
WIDGETS_LIB = livesupport_widgets
|
||||||
WIDGETS_LIB_FILE = ${LIB_DIR}/lib${WIDGETS_LIB}.a
|
WIDGETS_LIB_FILE = ${LIB_DIR}/lib${WIDGETS_LIB}.a
|
||||||
TEST_EXE = ${TMP_DIR}/test
|
TEST_EXE = ${TMP_DIR}/test
|
||||||
|
TEST_CFG = ${ETC_DIR}/widgetFactory.xml
|
||||||
|
|
||||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||||
|
|
||||||
|
@ -108,7 +109,8 @@ LDFLAGS = @LDFLAGS@ -pthread \
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
|
WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
|
||||||
${TMP_DIR}/Button.o \
|
${TMP_DIR}/Button.o \
|
||||||
${TMP_DIR}/BlueBin.o
|
${TMP_DIR}/BlueBin.o \
|
||||||
|
${TMP_DIR}/WidgetFactory.o
|
||||||
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
|
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
|
||||||
${TMP_DIR}/main.o
|
${TMP_DIR}/main.o
|
||||||
|
|
||||||
|
@ -144,7 +146,7 @@ distclean: clean docclean
|
||||||
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||||
|
|
||||||
run: all ${TEST_EXE}
|
run: all ${TEST_EXE}
|
||||||
${TEST_EXE}
|
${TEST_EXE} -c ${TEST_CFG}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!DOCTYPE widgetFactory [
|
||||||
|
|
||||||
|
<!ELEMENT widgetFactory EMPTY >
|
||||||
|
<!ATTLIST widgetFactory path CDATA #REQUIRED >
|
||||||
|
]>
|
||||||
|
<widgetFactory path = "var/"
|
||||||
|
/>
|
||||||
|
|
|
@ -0,0 +1,262 @@
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: maroy $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
#ifndef LiveSupport_Widgets_WidgetFactory_h
|
||||||
|
#define LiveSupport_Widgets_WidgetFactory_h
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#error This is a C++ include file
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ============================================================ include files */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "configure.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "LiveSupport/Core/Configurable.h"
|
||||||
|
|
||||||
|
#include "LiveSupport/Widgets/Button.h"
|
||||||
|
#include "LiveSupport/Widgets/BlueBin.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace LiveSupport {
|
||||||
|
namespace Widgets {
|
||||||
|
|
||||||
|
using namespace LiveSupport::Core;
|
||||||
|
|
||||||
|
/* ================================================================ constants */
|
||||||
|
|
||||||
|
|
||||||
|
/* =================================================================== macros */
|
||||||
|
|
||||||
|
|
||||||
|
/* =============================================================== data types */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory to provide access to LiveSupport Widgets.
|
||||||
|
*
|
||||||
|
* The singleton instance of this class has to be configured with an XML
|
||||||
|
* element, which looks like the following:
|
||||||
|
*
|
||||||
|
* <pre><code>
|
||||||
|
* <widgetFactory> path = "path/to/widget/images/"
|
||||||
|
* </>
|
||||||
|
* </code></pre>
|
||||||
|
*
|
||||||
|
* The DTD for the above XML structure is:
|
||||||
|
*
|
||||||
|
* <pre><code>
|
||||||
|
* <!ELEMENT widgetFactory EMPTY >
|
||||||
|
* <!ATTLIST widgetFactory path CDATA #REQUIRED >
|
||||||
|
* </code></pre>
|
||||||
|
*
|
||||||
|
* @author $Author: maroy $
|
||||||
|
* @version $Revision: 1.1 $
|
||||||
|
*/
|
||||||
|
class WidgetFactory :
|
||||||
|
virtual public Configurable
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* The name of the configuration XML elmenent used by this object.
|
||||||
|
*/
|
||||||
|
static const std::string configElementNameStr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The singleton instance of this object.
|
||||||
|
*/
|
||||||
|
static Ptr<WidgetFactory>::Ref singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path to load the images from for the widgets.
|
||||||
|
*/
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The passive left image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageLeft;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The passive center image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageCenter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The passive right image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rollover left image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageLeft;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rollover center image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageCenter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rollover right image for the button.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The top left image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinTopLeftImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The left image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinLeftImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The top image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinTopImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The top right image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinTopRightImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The right image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinRightImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bottom left image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinBottomLeftImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bottom image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinBottomImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bottom right image of the border for BlueBin.
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> blueBinBottomRightImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default constructor.
|
||||||
|
*/
|
||||||
|
WidgetFactory(void) throw ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load an image relative the path, and signal error if not found.
|
||||||
|
*
|
||||||
|
* @param imageName the name of the image, relative to path
|
||||||
|
* @return the loaded image
|
||||||
|
* @exception std::invalid_argument if the image was not found
|
||||||
|
*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf>
|
||||||
|
loadImage(const std::string imageName)
|
||||||
|
throw (std::invalid_argument);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* A virtual destructor, as this class has virtual functions.
|
||||||
|
*/
|
||||||
|
virtual
|
||||||
|
~WidgetFactory(void) throw ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the name of the XML element this object expects
|
||||||
|
* to be sent to a call to configure().
|
||||||
|
*
|
||||||
|
* @return the name of the expected XML configuration element.
|
||||||
|
*/
|
||||||
|
static const std::string
|
||||||
|
getConfigElementName(void) throw ()
|
||||||
|
{
|
||||||
|
return configElementNameStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the singleton instance of this object.
|
||||||
|
*
|
||||||
|
* @return the singleton instance of this object.
|
||||||
|
*/
|
||||||
|
static Ptr<WidgetFactory>::Ref
|
||||||
|
getInstance() throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the object based on the XML element supplied.
|
||||||
|
*
|
||||||
|
* @param element the XML element to configure the object from.
|
||||||
|
* @exception std::invalid_argument if the supplied XML element
|
||||||
|
* contains bad configuraiton information
|
||||||
|
* @exception std::logic_error if the object has already
|
||||||
|
* been configured, and can not be reconfigured.
|
||||||
|
*/
|
||||||
|
virtual void
|
||||||
|
configure(const xmlpp::Element & element)
|
||||||
|
throw (std::invalid_argument,
|
||||||
|
std::logic_error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return a button.
|
||||||
|
*
|
||||||
|
* @param label the label shown inside the button.
|
||||||
|
*/
|
||||||
|
Ptr<Button>::Ref
|
||||||
|
createButton(const Glib::ustring & label) throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return a blue singular container.
|
||||||
|
*/
|
||||||
|
Ptr<BlueBin>::Ref
|
||||||
|
createBlueBin(void) throw ();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* ================================================= external data structures */
|
||||||
|
|
||||||
|
|
||||||
|
/* ====================================================== function prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Widgets
|
||||||
|
} // namespace LiveSupport
|
||||||
|
|
||||||
|
#endif // LiveSupport_Widgets_WidgetFactory_h
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: maroy $
|
Author : $Author: maroy $
|
||||||
Version : $Revision: 1.3 $
|
Version : $Revision: 1.4 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "LiveSupport/Widgets/WidgetFactory.h"
|
||||||
#include "TestWindow.h"
|
#include "TestWindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +58,8 @@ using namespace LiveSupport::Widgets;
|
||||||
TestWindow :: TestWindow (void)
|
TestWindow :: TestWindow (void)
|
||||||
throw ()
|
throw ()
|
||||||
{
|
{
|
||||||
|
Ptr<WidgetFactory>::Ref widgetFactory = WidgetFactory::getInstance();
|
||||||
|
|
||||||
// init the imageButton
|
// init the imageButton
|
||||||
Glib::RefPtr<Gdk::Pixbuf> passiveImage;
|
Glib::RefPtr<Gdk::Pixbuf> passiveImage;
|
||||||
Glib::RefPtr<Gdk::Pixbuf> rollImage;
|
Glib::RefPtr<Gdk::Pixbuf> rollImage;
|
||||||
|
@ -66,41 +69,11 @@ TestWindow :: TestWindow (void)
|
||||||
|
|
||||||
imageButton.reset(new ImageButton(passiveImage, rollImage));
|
imageButton.reset(new ImageButton(passiveImage, rollImage));
|
||||||
|
|
||||||
// init the button
|
// create a button
|
||||||
Glib::RefPtr<Gdk::Pixbuf> passiveImageLeft;
|
button = widgetFactory->createButton("Hello, World!");
|
||||||
Glib::RefPtr<Gdk::Pixbuf> passiveImageCenter;
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> passiveImageRight;
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> rollImageLeft;
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> rollImageCenter;
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> rollImageRight;
|
|
||||||
|
|
||||||
passiveImageLeft = Gdk::Pixbuf::create_from_file("var/button_left.png");
|
// create a blue container
|
||||||
passiveImageCenter = Gdk::Pixbuf::create_from_file("var/button_centre.png");
|
blueBin = widgetFactory->createBlueBin();
|
||||||
passiveImageRight = Gdk::Pixbuf::create_from_file("var/button_right.png");
|
|
||||||
rollImageLeft = Gdk::Pixbuf::create_from_file("var/button_left_roll.png");
|
|
||||||
rollImageCenter = Gdk::Pixbuf::create_from_file(
|
|
||||||
"var/button_centre_roll.png");
|
|
||||||
rollImageRight = Gdk::Pixbuf::create_from_file(
|
|
||||||
"var/button_right_roll.png");
|
|
||||||
|
|
||||||
button.reset(new Button("Hello, World!",
|
|
||||||
passiveImageLeft,
|
|
||||||
passiveImageCenter,
|
|
||||||
passiveImageRight,
|
|
||||||
rollImageLeft,
|
|
||||||
rollImageCenter,
|
|
||||||
rollImageRight));
|
|
||||||
|
|
||||||
// init the blue container
|
|
||||||
blueBin.reset(new BlueBin(
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_topleft.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_leftside.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_topcentre.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_topright.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_rightside.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_botleft.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_botcentre.png"),
|
|
||||||
Gdk::Pixbuf::create_from_file("var/corner_botright.png")));
|
|
||||||
|
|
||||||
// create and set up the layout
|
// create and set up the layout
|
||||||
layout.reset(new Gtk::Table());
|
layout.reset(new Gtk::Table());
|
||||||
|
|
|
@ -0,0 +1,246 @@
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: maroy $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* ============================================================ include files */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "configure.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "LiveSupport/Widgets/WidgetFactory.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace LiveSupport::Core;
|
||||||
|
using namespace LiveSupport::Widgets;
|
||||||
|
|
||||||
|
/* =================================================== local data structures */
|
||||||
|
|
||||||
|
|
||||||
|
/* ================================================ local constants & macros */
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the config element for this class
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
const std::string WidgetFactory::configElementNameStr = "widgetFactory";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The singleton instance of WidgetFactory
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<WidgetFactory>::Ref WidgetFactory::singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the attribute to get the path for the widget images.
|
||||||
|
*/
|
||||||
|
static const std::string pathAttrName = "path";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the left passive image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonPassiveLeftName = "button_left.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the center passive image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonPassiveCenterName = "button_centre.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the right passive image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonPassiveRightName = "button_right.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the left rollover image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonRollLeftName = "button_left_roll.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the center rollover image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonRollCenterName = "button_centre_roll.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the right rollover image for the button.
|
||||||
|
*/
|
||||||
|
static const std::string buttonRollRightName = "button_right_roll.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the top left image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinTopLeftName = "corner_topleft.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the left image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinLeftName = "corner_leftside.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the top image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinTopName = "corner_topcentre.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the top right image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinTopRightName = "corner_topright.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the right image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinRightName = "corner_rightside.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the bottom left image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinBottomLeftName = "corner_botleft.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the bottom image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinBottomName = "corner_botcentre.png";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the bottom right image for BlueBin.
|
||||||
|
*/
|
||||||
|
static const std::string blueBinBottomRightName = "corner_botright.png";
|
||||||
|
|
||||||
|
/* =============================================== local function prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* ============================================================= module code */
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Return the singleton instance to WidgetFactory
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<WidgetFactory>::Ref
|
||||||
|
WidgetFactory :: getInstance(void) throw ()
|
||||||
|
{
|
||||||
|
if (!singleton.get()) {
|
||||||
|
singleton.reset(new WidgetFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Configure the widget factory.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
WidgetFactory :: configure(const xmlpp::Element & element)
|
||||||
|
throw (std::invalid_argument,
|
||||||
|
std::logic_error)
|
||||||
|
{
|
||||||
|
if (element.get_name() != configElementNameStr) {
|
||||||
|
std::string eMsg = "Bad configuration element ";
|
||||||
|
eMsg += element.get_name();
|
||||||
|
throw std::invalid_argument(eMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const xmlpp::Attribute * attribute;
|
||||||
|
|
||||||
|
if (!(attribute = element.get_attribute(pathAttrName))) {
|
||||||
|
throw std::invalid_argument("Missing path attribute");
|
||||||
|
}
|
||||||
|
path = attribute->get_value();
|
||||||
|
|
||||||
|
// load the button images, and check if all exist
|
||||||
|
buttonPassiveImageLeft = loadImage(buttonPassiveLeftName);
|
||||||
|
buttonPassiveImageCenter = loadImage(buttonPassiveCenterName);
|
||||||
|
buttonPassiveImageRight = loadImage(buttonPassiveRightName);
|
||||||
|
buttonRollImageLeft = loadImage(buttonRollLeftName);
|
||||||
|
buttonRollImageCenter = loadImage(buttonRollCenterName);
|
||||||
|
buttonRollImageRight = loadImage(buttonRollRightName);
|
||||||
|
|
||||||
|
// load the blue bin images.
|
||||||
|
blueBinTopLeftImage = loadImage(blueBinTopLeftName);
|
||||||
|
blueBinLeftImage = loadImage(blueBinLeftName);
|
||||||
|
blueBinTopImage = loadImage(blueBinTopName);
|
||||||
|
blueBinTopRightImage = loadImage(blueBinTopRightName);
|
||||||
|
blueBinRightImage = loadImage(blueBinRightName);
|
||||||
|
blueBinBottomLeftImage = loadImage(blueBinBottomLeftName);
|
||||||
|
blueBinBottomImage = loadImage(blueBinBottomName);
|
||||||
|
blueBinBottomRightImage = loadImage(blueBinBottomRightName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Load an image
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf>
|
||||||
|
WidgetFactory :: loadImage(const std::string imageName)
|
||||||
|
throw (std::invalid_argument)
|
||||||
|
{
|
||||||
|
Glib::RefPtr<Gdk::Pixbuf> image;
|
||||||
|
|
||||||
|
if (!(image = Gdk::Pixbuf::create_from_file(path + imageName))) {
|
||||||
|
throw std::invalid_argument("Missing " + image);
|
||||||
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Create a button
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<Button>::Ref
|
||||||
|
WidgetFactory :: createButton(const Glib::ustring & label) throw ()
|
||||||
|
{
|
||||||
|
Ptr<Button>::Ref button(new Button(label,
|
||||||
|
buttonPassiveImageLeft,
|
||||||
|
buttonPassiveImageCenter,
|
||||||
|
buttonPassiveImageRight,
|
||||||
|
buttonRollImageLeft,
|
||||||
|
buttonRollImageCenter,
|
||||||
|
buttonRollImageRight));
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Create a blue bin
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<BlueBin>::Ref
|
||||||
|
WidgetFactory :: createBlueBin(void) throw ()
|
||||||
|
{
|
||||||
|
Ptr<BlueBin>::Ref blueBin(new BlueBin(blueBinTopLeftImage,
|
||||||
|
blueBinLeftImage,
|
||||||
|
blueBinTopImage,
|
||||||
|
blueBinTopRightImage,
|
||||||
|
blueBinRightImage,
|
||||||
|
blueBinBottomLeftImage,
|
||||||
|
blueBinBottomImage,
|
||||||
|
blueBinBottomRightImage));
|
||||||
|
|
||||||
|
return blueBin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: maroy $
|
Author : $Author: maroy $
|
||||||
Version : $Revision: 1.1 $
|
Version : $Revision: 1.2 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/main.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/main.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
|
|
||||||
#include "LiveSupport/Core/Ptr.h"
|
#include "LiveSupport/Core/Ptr.h"
|
||||||
|
#include "LiveSupport/Widgets/WidgetFactory.h"
|
||||||
#include "TestWindow.h"
|
#include "TestWindow.h"
|
||||||
|
|
||||||
using namespace LiveSupport::Core;
|
using namespace LiveSupport::Core;
|
||||||
|
@ -149,19 +149,13 @@ int main ( int argc,
|
||||||
|
|
||||||
std::cerr << "using config file '" << configFileName << '\'' << std::endl;
|
std::cerr << "using config file '" << configFileName << '\'' << std::endl;
|
||||||
|
|
||||||
|
Ptr<WidgetFactory>::Ref widgetFactory = WidgetFactory::getInstance();
|
||||||
TestWindow testWindow;
|
|
||||||
Gtk::Main::run(testWindow);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Ptr<LiveSupport::GLiveSupport::GLiveSupport>::Ref
|
|
||||||
gLiveSupport(new LiveSupport::GLiveSupport::GLiveSupport());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::auto_ptr<xmlpp::DomParser>
|
std::auto_ptr<xmlpp::DomParser>
|
||||||
parser(new xmlpp::DomParser(configFileName, true));
|
parser(new xmlpp::DomParser(configFileName, true));
|
||||||
const xmlpp::Document * document = parser->get_document();
|
const xmlpp::Document * document = parser->get_document();
|
||||||
gLiveSupport->configure(*(document->get_root_node()));
|
widgetFactory->configure(*(document->get_root_node()));
|
||||||
} catch (std::invalid_argument &e) {
|
} catch (std::invalid_argument &e) {
|
||||||
std::cerr << "semantic error in configuration file" << std::endl
|
std::cerr << "semantic error in configuration file" << std::endl
|
||||||
<< e.what() << std::endl;
|
<< e.what() << std::endl;
|
||||||
|
@ -172,8 +166,9 @@ int main ( int argc,
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
gLiveSupport->show();
|
TestWindow testWindow;
|
||||||
*/
|
Gtk::Main::run(testWindow);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue