diff --git a/livesupport/modules/widgets/etc/Makefile.in b/livesupport/modules/widgets/etc/Makefile.in index ff46cc81c..4dc1915da 100644 --- a/livesupport/modules/widgets/etc/Makefile.in +++ b/livesupport/modules/widgets/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.18 $ +# Version : $Revision: 1.19 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $ # # @configure_input@ @@ -39,6 +39,8 @@ DOXYGEN = doxygen #------------------------------------------------------------------------------- # Basic directory and file definitions #------------------------------------------------------------------------------- +PACKAGE_NAME = @PACKAGE_NAME@ + BASE_DIR = @builddir@ DOC_DIR = ${BASE_DIR}/doc DOXYGEN_DIR = ${DOC_DIR}/doxygen @@ -48,9 +50,11 @@ INCLUDE_DIR = ${BASE_DIR}/include LIB_DIR = ${BASE_DIR}/lib SRC_DIR = ${BASE_DIR}/src TMP_DIR = ${BASE_DIR}/tmp +VAR_DIR = ${BASE_DIR}/var USR_DIR = ${BASE_DIR}/../../usr USR_INCLUDE_DIR = ${USR_DIR}/include +USR_BIN_DIR = ${USR_DIR}/bin USR_LIB_DIR = ${USR_DIR}/lib BOOST_INCLUDE_DIR = ${USR_INCLUDE_DIR}/boost-1_31 @@ -62,12 +66,19 @@ CORE_LIB_DIR = ${CORE_DIR}/lib CORE_LIB = livesupport_core CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a +GENRB = ${USR_BIN_DIR}/genrb +GENRBOPTS = --destdir ${TMP_DIR} \ + --encoding utf-8 \ + --package-name ${PACKAGE_NAME} \ + --strict + VPATH = ${SRC_DIR} LIBXMLPP_CFLAGS=@LIBXMLPP_CFLAGS@ LIBXMLPP_LIBS=@LIBXMLPP_LIBS@ # TODO: move ICU flag determination to configure script +ICU_CFLAGS= ICU_LIBS=`${USR_DIR}/bin/icu-config --ldflags --ldflags-toolutil --ldflags-icuio` GTKMM_CFLAGS=@GTKMM_CFLAGS@ @@ -94,6 +105,7 @@ CPPFLAGS = @CPPFLAGS@ CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \ -pedantic -Wall -Wno-long-long \ ${LIBXMLPP_CFLAGS} \ + ${ICU_CFLAGS} \ ${GTKMM_CFLAGS} \ -I${USR_INCLUDE_DIR} \ -I${BOOST_INCLUDE_DIR} \ @@ -101,6 +113,7 @@ CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \ -I${INCLUDE_DIR} -I${TMP_DIR} LDFLAGS = @LDFLAGS@ -pthread \ ${LIBXMLPP_LIBS} \ + ${ICU_LIBS} \ ${GTKMM_LIBS} \ -L${USR_LIB_DIR} \ -L${CORE_LIB_DIR} \ @@ -125,11 +138,16 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \ ${TMP_DIR}/ZebraTreeView.o \ ${TMP_DIR}/ZebraCellRenderer.o \ ${TMP_DIR}/Colors.o \ - ${TMP_DIR}/MessageWindow.o + ${TMP_DIR}/MessageWindow.o \ + ${TMP_DIR}/DialogWindow.o TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \ ${TMP_DIR}/main.o +TEST_RUNNER_RES = ${TMP_DIR}/${PACKAGE_NAME}_root.res \ + ${TMP_DIR}/${PACKAGE_NAME}_en.res \ + ${TMP_DIR}/${PACKAGE_NAME}_hu.res + TEST_EXE_LIBS = -l${WIDGETS_LIB} -l${CORE_LIB} ${ICU_LIBS} \ -lboost_date_time-gcc \ -lxmlrpc++ -lssl @@ -161,7 +179,7 @@ depclean: clean distclean: clean docclean ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* -run: all ${TEST_EXE} +run: all ${TEST_EXE} ${TEST_RUNNER_RES} ${TEST_EXE} -c ${TEST_CFG} check: all @@ -193,3 +211,6 @@ ${CORE_LIB_FILE}: ${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $< +${TMP_DIR}/${PACKAGE_NAME}_%.res : ${VAR_DIR}/%.txt + ${GENRB} ${GENRBOPTS} $^ + diff --git a/livesupport/modules/widgets/etc/resourceBundle.xml b/livesupport/modules/widgets/etc/resourceBundle.xml new file mode 100644 index 000000000..6245c9e92 --- /dev/null +++ b/livesupport/modules/widgets/etc/resourceBundle.xml @@ -0,0 +1,11 @@ + + + + + +]> + diff --git a/livesupport/modules/widgets/include/LiveSupport/Widgets/DialogWindow.h b/livesupport/modules/widgets/include/LiveSupport/Widgets/DialogWindow.h new file mode 100644 index 000000000..62b42ab15 --- /dev/null +++ b/livesupport/modules/widgets/include/LiveSupport/Widgets/DialogWindow.h @@ -0,0 +1,196 @@ +/*------------------------------------------------------------------------------ + + 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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/DialogWindow.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef DialogWindow_h +#define DialogWindow_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include +#include + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/LocalizedObject.h" + +#include "LiveSupport/Widgets/WhiteWindow.h" + +namespace LiveSupport { +namespace Widgets { + +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A dialog window, displaying a single line of message, + * with a pair of buttons: Yes and No, or OK and Cancel etc. + * + * The constructor is called with a message, a list of ButtonType values + * (e.g. cancelButton|okButton), and a resource bundle. The resource bundle + * is expected to contain keys named cancelButtonLabel, noButtonLabel, + * yesButtonLabel and okButtonLabel. + * + * The return value of the run() method is a single ButtonType value. + * The DialogWindow object is not destroyed when it returns from run(); + * it is the responsibility of the caller to delete it (or it can be + * reused a few times first). + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class DialogWindow : public WhiteWindow, + public LocalizedObject +{ + public: + /** + * The types of possible buttons. + */ + typedef enum { cancelButton = 1, + noButton = 2, + yesButton = 4, + okButton = 8 } ButtonType; + + + private: + /** + * The type of the button clicked. + */ + ButtonType buttonClicked; + + + protected: + /** + * The vertical box holding the message and the button. + */ + Gtk::Box * layout; + + /** + * The message. + */ + Gtk::Label * messageLabel; + + /** + * The Cancel button. + */ + Button * cancelDialogButton; + + /** + * The No button. + */ + Button * noDialogButton; + + /** + * The Yes button. + */ + Button * yesDialogButton; + + /** + * The OK button. + */ + Button * okDialogButton; + + /** + * The event handler for the Cancel button clicked. + */ + virtual void + onCancelButtonClicked(void) throw (); + + /** + * The event handler for the No button clicked. + */ + virtual void + onNoButtonClicked(void) throw (); + + /** + * The event handler for the Yes button clicked. + */ + virtual void + onYesButtonClicked(void) throw (); + + /** + * The event handler for the OK button clicked. + */ + virtual void + onOkButtonClicked(void) throw (); + + + public: + /** + * Constructor. + * + * @param message the message to display in the window + * @param buttonTypes a list of button types, e.g., + * noButton|yesButton + * @param bundle a resource bundle containing the localized + * button labels + */ + DialogWindow(Ptr::Ref message, + int buttonTypes, + Ptr::Ref bundle) throw (); + + /** + * Virtual destructor. + */ + virtual + ~DialogWindow(void) throw (); + + /** + * Run the window and return the button pressed. + */ + virtual ButtonType + run(void) throw (); + +}; + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Widgets +} // namespace LiveSupport + +#endif // DialogWindow_h + diff --git a/livesupport/modules/widgets/src/DialogWindow.cxx b/livesupport/modules/widgets/src/DialogWindow.cxx new file mode 100644 index 000000000..7cae5e1b0 --- /dev/null +++ b/livesupport/modules/widgets/src/DialogWindow.cxx @@ -0,0 +1,194 @@ +/*------------------------------------------------------------------------------ + + 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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/DialogWindow.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "LiveSupport/Widgets/WidgetFactory.h" +#include "LiveSupport/Widgets/Colors.h" + +#include "LiveSupport/Widgets/DialogWindow.h" + + +using namespace LiveSupport::Widgets; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Constructor. + *----------------------------------------------------------------------------*/ +DialogWindow :: DialogWindow (Ptr::Ref message, + int buttonTypes, + Ptr::Ref bundle) + throw () + : WhiteWindow("", + Colors::White, + WidgetFactory::getInstance()->getWhiteWindowCorners(), + false), + LocalizedObject(bundle) +{ + hide(); + Ptr::Ref widgetFactory = WidgetFactory::getInstance(); + + layout = Gtk::manage(new Gtk::VBox()); + + messageLabel = Gtk::manage(new Gtk::Label(*message)); + layout->pack_start(*messageLabel, true, true); + + Gtk::ButtonBox * buttonBox = Gtk::manage(new Gtk::HButtonBox( + Gtk::BUTTONBOX_END, 5)); + layout->pack_start(*buttonBox, Gtk::PACK_SHRINK, 0); + + int buttonCount = 0; + try { + if (buttonTypes & cancelButton) { + cancelDialogButton = Gtk::manage(widgetFactory->createButton( + *getResourceUstring("cancelButtonLabel") )); + cancelDialogButton->signal_clicked().connect(sigc::mem_fun(*this, + &DialogWindow::onCancelButtonClicked)); + buttonBox->pack_start(*cancelDialogButton); + ++buttonCount; + } + + if (buttonTypes & noButton) { + noDialogButton = Gtk::manage(widgetFactory->createButton( + *getResourceUstring("noButtonLabel") )); + noDialogButton->signal_clicked().connect(sigc::mem_fun(*this, + &DialogWindow::onNoButtonClicked)); + buttonBox->pack_start(*noDialogButton); + ++buttonCount; + } + + if (buttonTypes & yesButton) { + yesDialogButton = Gtk::manage(widgetFactory->createButton( + *getResourceUstring("yesButtonLabel") )); + yesDialogButton->signal_clicked().connect(sigc::mem_fun(*this, + &DialogWindow::onYesButtonClicked)); + buttonBox->pack_start(*yesDialogButton); + ++buttonCount; + } + + if (buttonTypes & okButton) { + okDialogButton = Gtk::manage(widgetFactory->createButton( + *getResourceUstring("okButtonLabel") )); + okDialogButton->signal_clicked().connect(sigc::mem_fun(*this, + &DialogWindow::onOkButtonClicked)); + buttonBox->pack_start(*okDialogButton); + ++buttonCount; + } + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } + + set_default_size(100*buttonCount + 50, 120); + set_modal(true); + property_window_position().set_value(Gtk::WIN_POS_NONE); + + add(*layout); +} + + +/*------------------------------------------------------------------------------ + * Destructor. + *----------------------------------------------------------------------------*/ +DialogWindow :: ~DialogWindow (void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Event handler for the Cancel button clicked + *----------------------------------------------------------------------------*/ +void +DialogWindow :: onCancelButtonClicked(void) throw () +{ + buttonClicked = cancelButton; + hide(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the No button clicked. + *----------------------------------------------------------------------------*/ +void +DialogWindow :: onNoButtonClicked(void) throw () +{ + buttonClicked = noButton; + hide(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the Yes button clicked. + *----------------------------------------------------------------------------*/ +void +DialogWindow :: onYesButtonClicked(void) throw () +{ + buttonClicked = yesButton; + hide(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the OK button clicked. + *----------------------------------------------------------------------------*/ +void +DialogWindow :: onOkButtonClicked(void) throw () +{ + buttonClicked = okButton; + hide(); +} + + +/*------------------------------------------------------------------------------ + * Show the window and return the button clicked. + *----------------------------------------------------------------------------*/ +DialogWindow::ButtonType +DialogWindow :: run(void) throw () +{ + show_all(); + Gtk::Main::run(*this); + return buttonClicked; +} + diff --git a/livesupport/modules/widgets/src/TestWindow.cxx b/livesupport/modules/widgets/src/TestWindow.cxx index 802ddc3cc..3b872b2f1 100644 --- a/livesupport/modules/widgets/src/TestWindow.cxx +++ b/livesupport/modules/widgets/src/TestWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.17 $ + Version : $Revision: 1.18 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -48,6 +48,11 @@ using namespace LiveSupport::Widgets; /* ================================================ local constants & macros */ +/** + * The name of the configuration file for the resource bundle. + */ +static const std::string bundleConfigFileName = "etc/resourceBundle.xml"; + /* =============================================== local function prototypes */ @@ -111,6 +116,33 @@ TestWindow :: TestWindow (void) add(*blueBin); show_all(); layout->attach(*cueStopImageButton, 1, 2, 0, 1); + + Ptr::Ref resourceBundle; + try { + Ptr::Ref parser( + new xmlpp::DomParser(bundleConfigFileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + resourceBundle = LocalizedObject::getBundle(*root); + + } catch (std::invalid_argument &e) { + std::cerr << "semantic error in bundle configuration file:\n" + << e.what() << std::endl; + exit(1); + } catch (std::exception &e) { + std::cerr << "XML error in bundle configuration file:\n" + << e.what() << std::endl; + exit(1); + } + + Ptr::Ref confirmationMessage(new Glib::ustring( + "Are you sure?" )); + dialogWindow = new DialogWindow(confirmationMessage, + DialogWindow::cancelButton | + DialogWindow::noButton | + DialogWindow::yesButton, + resourceBundle); } @@ -119,6 +151,7 @@ TestWindow :: TestWindow (void) *----------------------------------------------------------------------------*/ TestWindow :: ~TestWindow (void) throw () { + delete dialogWindow; } @@ -143,6 +176,20 @@ TestWindow :: onButtonClicked(void) throw () void TestWindow :: onPlayButtonPressed(void) throw () { + DialogWindow::ButtonType result = dialogWindow->run(); + switch (result) { + case DialogWindow::cancelButton: + std::cerr << "Cancelled." << std::endl; + break; + case DialogWindow::noButton: + std::cerr << "No." << std::endl; + break; + case DialogWindow::yesButton: + std::cerr << "Yes." << std::endl; + break; + default: std::cerr << "This can never happen." << std::endl; + } + cuePlayImageButton->hide(); cueStopImageButton->show(); } diff --git a/livesupport/modules/widgets/src/TestWindow.h b/livesupport/modules/widgets/src/TestWindow.h index 8dc59bcd7..686244ec1 100644 --- a/livesupport/modules/widgets/src/TestWindow.h +++ b/livesupport/modules/widgets/src/TestWindow.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.10 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.11 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -53,6 +53,7 @@ #include "LiveSupport/Widgets/EntryBin.h" #include "LiveSupport/Widgets/Notebook.h" #include "LiveSupport/Widgets/WhiteWindow.h" +#include "LiveSupport/Widgets/DialogWindow.h" namespace LiveSupport { @@ -71,8 +72,8 @@ using namespace LiveSupport::Core; /** * A window, enabling interactive testing of UI components. * - * @author $Author: maroy $ - * @version $Revision: 1.10 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.11 $ */ class TestWindow : public WhiteWindow { @@ -89,6 +90,12 @@ class TestWindow : public WhiteWindow void onStopButtonPressed(void) throw (); + /** + * The "are you sure?" dialog window. + */ + DialogWindow * dialogWindow; + + protected: /** * The layout used in the window. diff --git a/livesupport/modules/widgets/var/en.txt b/livesupport/modules/widgets/var/en.txt new file mode 100644 index 000000000..d59f768a0 --- /dev/null +++ b/livesupport/modules/widgets/var/en.txt @@ -0,0 +1,3 @@ +en:table +{ +} diff --git a/livesupport/modules/widgets/var/hu.txt b/livesupport/modules/widgets/var/hu.txt new file mode 100644 index 000000000..91a5ce237 --- /dev/null +++ b/livesupport/modules/widgets/var/hu.txt @@ -0,0 +1,8 @@ +hu:table +{ + cancelButtonLabel:string { "Mégsem" } + noButtonLabel:string { "Nem" } + yesButtonLabel:string { "Igen" } + okButtonLabel:string { "OK" } +} + diff --git a/livesupport/modules/widgets/var/root.txt b/livesupport/modules/widgets/var/root.txt new file mode 100644 index 000000000..c7fb8e6e5 --- /dev/null +++ b/livesupport/modules/widgets/var/root.txt @@ -0,0 +1,8 @@ +root:table +{ + cancelButtonLabel:string { "Cancel" } + noButtonLabel:string { "No" } + yesButtonLabel:string { "Yes" } + okButtonLabel:string { "OK" } +} +