fixed the Test Window in the widgets module

This commit is contained in:
fgerlits 2007-08-08 09:37:40 +00:00
parent 31fe5a69c8
commit d4345e7e98
10 changed files with 296 additions and 177 deletions

View File

@ -138,7 +138,7 @@ class LocalizedObject
* a sample configuration element is as follows:
*
* <pre><code>
* <resourceBundle path = "./tmp/Core"
* <resourceBundle path = "./tmp/localization"
* locale = "en"
* />
* </code></pre>

View File

@ -70,9 +70,9 @@ CORE_LIB = livesupport_core
CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a
GENRB = @GENRB@
GENRBOPTS = --destdir ${TMP_DIR} \
TMP_LOCALIZATION_DIR = ${TMP_DIR}/localization
GENRBOPTS = --destdir ${TMP_LOCALIZATION_DIR} \
--encoding utf-8 \
--package-name ${PACKAGE_NAME} \
--strict
VPATH = ${SRC_DIR}
@ -147,9 +147,9 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ComboBoxText.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_RUNNER_RES = ${TMP_LOCALIZATION_DIR}/root.res \
${TMP_LOCALIZATION_DIR}/en.res \
${TMP_LOCALIZATION_DIR}/hu.res
TEST_EXE_LIBS = -l${WIDGETS_LIB} -l${CORE_LIB} ${ICU_LIBS} \
${BOOST_DATE_TIME_LIB} -lxmlrpc++ -lssl
@ -161,7 +161,7 @@ TEST_EXE_LIBS = -l${WIDGETS_LIB} -l${CORE_LIB} ${ICU_LIBS} \
all: dir_setup ${WIDGETS_LIB_FILE}
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
dir_setup: ${TMP_DIR} ${TMP_LOCALIZATION_DIR} ${DOXYGEN_DIR}
doc:
${DOXYGEN} ${DOXYGEN_CONFIG}
@ -170,6 +170,7 @@ clean:
${RM} ${WIDGETS_LIB_OBJS} ${WIDGETS_LIB_FILE}
${RM} ${TEST_EXE_OBJS} ${TEST_EXE}
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
${RMDIR} ${TMP_LOCALIZATION_DIR}
docclean:
${RMDIR} ${DOXYGEN_DIR}/html
@ -205,6 +206,9 @@ ${WIDGETS_LIB_FILE}: ${WIDGETS_LIB_OBJS}
${TMP_DIR}:
${MKDIR} ${TMP_DIR}
${TMP_LOCALIZATION_DIR}:
${MKDIR} ${TMP_LOCALIZATION_DIR}
${DOXYGEN_DIR}:
${MKDIR} ${DOXYGEN_DIR}
@ -222,6 +226,6 @@ ${CORE_LIB_FILE}:
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
${TMP_DIR}/${PACKAGE_NAME}_%.res : ${VAR_DIR}/%.txt
${TMP_LOCALIZATION_DIR}/%.res : ${VAR_DIR}/%.txt
${GENRB} ${GENRBOPTS} $^

View File

@ -6,6 +6,6 @@
<!ATTLIST resourceBundle locale CDATA #REQUIRED >
]>
<resourceBundle path = "./tmp/Widgets"
<resourceBundle path = "./tmp/localization"
locale = "en"
/>

View File

@ -34,13 +34,13 @@
#endif
#include <iostream>
#include <gtkmm/main.h>
#include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/Colors.h"
#include "TestWindow.h"
using namespace LiveSupport::Core;
using namespace LiveSupport::Widgets;
/* =================================================== local data structures */
@ -48,11 +48,19 @@ 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";
namespace {
/*------------------------------------------------------------------------------
* The name of the configuration file for the resource bundle.
*----------------------------------------------------------------------------*/
const std::string bundleConfigFileName = "etc/resourceBundle.xml";
/*------------------------------------------------------------------------------
* The name of the Glade file.
*----------------------------------------------------------------------------*/
const std::string gladeFileName = "var/glade/TestWindow.glade";
}
/* =============================================== local function prototypes */
@ -62,75 +70,55 @@ static const std::string bundleConfigFileName = "etc/resourceBundle.xml";
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
TestWindow :: TestWindow (void)
throw ()
: WhiteWindow(Colors::White,
WidgetFactory::getInstance()->getWhiteWindowCorners())
TestWindow :: TestWindow (void) throw ()
{
Ptr<WidgetFactory>::Ref widgetFactory = WidgetFactory::getInstance();
configureBundle();
setTitle("test widget", "Test App");
Glib::RefPtr<Gnome::Glade::Xml> glade = Gnome::Glade::Xml::create(
gladeFileName);
// init the imageButtons
hugeImageButton = Gtk::manage(
widgetFactory->createButton(WidgetConstants::hugePlayButton));
cuePlayImageButton = Gtk::manage(
widgetFactory->createButton(WidgetConstants::cuePlayButton));
cuePlayImageButton->signal_clicked().connect(sigc::mem_fun(*this,
&TestWindow::onPlayButtonClicked));
cueStopImageButton = Gtk::manage(
widgetFactory->createButton(WidgetConstants::cueStopButton));
cueStopImageButton->signal_clicked().connect(sigc::mem_fun(*this,
&TestWindow::onStopButtonClicked));
glade->get_widget("mainWindow1", mainWindow);
mainWindow->set_title(*getResourceUstring("windowTitle"));
mainWindow->signal_delete_event().connect(sigc::mem_fun(*this,
&TestWindow::onDeleteEvent));
// create a button
button = Gtk::manage(widgetFactory->createButton(
"Hello, World!",
WidgetConstants::radioButton));
button->signal_clicked().connect(sigc::mem_fun(*this,
&TestWindow::onButtonClicked));
glade->get_widget_derived("comboBox1", comboBox);
comboBox->append_text(*getResourceUstring("firstOption"));
comboBox->append_text(*getResourceUstring("secondOption"));
comboBox->append_text(*getResourceUstring("thirdOption"));
comboBox->set_active(0);
comboBox->signal_changed().connect(sigc::mem_fun(*this,
&TestWindow::onComboBoxSelectionChanged));
// and another button
disableTestButton = Gtk::manage(widgetFactory->createButton(
"I can be disabled",
WidgetConstants::radioButton));
treeModel = Gtk::ListStore::create(modelColumns);
// create a combo box
comboBoxText = Gtk::manage(widgetFactory->createComboBoxText());
comboBoxText->append_text("item1");
comboBoxText->append_text("long item2");
comboBoxText->append_text("very very very long item3");
comboBoxText->set_active_text("item2");
glade->get_widget_derived("treeView1", treeView);
treeView->set_model(treeModel);
treeView->connectModelSignals(treeModel);
treeView->appendColumn(*getResourceUstring("pixbufColumnTitle"),
modelColumns.pixbufColumn);
treeView->appendColumn(*getResourceUstring("textColumnTitle"),
modelColumns.textColumn);
fillTreeModel();
// create a text entry, ant put it inside a blue bin
entryBin = Gtk::manage(widgetFactory->createEntryBin());
entry = entryBin->getEntry();
glade->connect_clicked("okButton1", sigc::mem_fun(*this,
&TestWindow::onOkButtonClicked));
}
// create a notebook
notebook = Gtk::manage(new Notebook());
notebook->appendPage(*button, "first page");
notebook->appendPage(*comboBoxText, "second page");
notebook->appendPage(*entryBin, "third page");
// create a blue container
blueBin = Gtk::manage(widgetFactory->createBlueBin());
// create and set up the layout
layout = Gtk::manage(new Gtk::Table());
layout->attach(*hugeImageButton, 0, 1, 0, 2);
layout->attach(*cuePlayImageButton, 1, 2, 0, 1);
layout->attach(*disableTestButton, 1, 2, 1, 2);
layout->attach(*notebook, 0, 2, 2, 3);
blueBin->add(*layout);
add(*blueBin);
show_all();
layout->attach(*cueStopImageButton, 1, 2, 0, 1);
/*------------------------------------------------------------------------------
* Configure the resource bundle.
*----------------------------------------------------------------------------*/
void
TestWindow :: configureBundle (void) throw ()
{
Ptr<ResourceBundle>::Ref bundle;
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(bundleConfigFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
bundle = LocalizedObject::getBundle(*root);
@ -143,80 +131,83 @@ TestWindow :: TestWindow (void)
<< e.what() << std::endl;
exit(1);
}
Ptr<Glib::ustring>::Ref confirmationMessage(new Glib::ustring(
"Are you sure?" ));
dialogWindow.reset(new DialogWindow(confirmationMessage,
DialogWindow::noButton |
DialogWindow::yesButton,
bundle ));
setBundle(bundle);
}
/*------------------------------------------------------------------------------
* Destructor.
*----------------------------------------------------------------------------*/
TestWindow :: ~TestWindow (void) throw ()
{
}
/*------------------------------------------------------------------------------
* Event handler for the button being clicked.
* Fill the tree model.
*----------------------------------------------------------------------------*/
void
TestWindow :: onButtonClicked(void) throw ()
TestWindow :: fillTreeModel (void) throw ()
{
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Ptr<Glib::ustring>::Ref message(new Glib::ustring("Hello, World!"));
DialogWindow * helloWindow = wf->createDialogWindow(message, bundle);
helloWindow->run();
button->setSelected(false);
delete helloWindow;
}
/*------------------------------------------------------------------------------
* Change the image from "play" to "stop" on the button when clicked.
*----------------------------------------------------------------------------*/
void
TestWindow :: onPlayButtonClicked(void) throw ()
{
cuePlayImageButton->hide();
cueStopImageButton->show();
disableTestButton->setDisabled(true);
}
/*------------------------------------------------------------------------------
* Change the image from "stop" to "play" on the button when clicked.
*----------------------------------------------------------------------------*/
void
TestWindow :: onStopButtonClicked(void) throw ()
{
cueStopImageButton->hide();
cuePlayImageButton->show();
disableTestButton->setDisabled(false);
}
/*------------------------------------------------------------------------------
* Override the close button functionality.
*----------------------------------------------------------------------------*/
void
TestWindow :: onCloseButtonClicked(void) throw ()
{
DialogWindow::ButtonType result = dialogWindow->run();
switch (result) {
case DialogWindow::noButton:
return;
case DialogWindow::yesButton:
hide();
break;
default: std::cerr << "This can never happen." << std::endl;
Glib::RefPtr<Gdk::Pixbuf> pixbuf = wf->getPixbuf(
WidgetConstants::audioClipIconImage);
Glib::ustring text;
switch (comboBox->get_active_row_number()) {
case -1: break;
case 0: text = *getResourceUstring("textOne");
break;
case 1: text = *getResourceUstring("textTwo");
break;
case 2: text = *getResourceUstring("textThree");
break;
default: break;
}
treeModel->clear();
Gtk::TreeModel::Row row = *treeModel->append();
row[modelColumns.pixbufColumn] = pixbuf;
row[modelColumns.textColumn] = text;
}
/*------------------------------------------------------------------------------
* Event handler for selection change in the combo box.
*----------------------------------------------------------------------------*/
void
TestWindow :: onComboBoxSelectionChanged (void) throw ()
{
fillTreeModel();
}
/*------------------------------------------------------------------------------
* Event handler for the OK button being clicked.
*----------------------------------------------------------------------------*/
void
TestWindow :: onOkButtonClicked (void) throw ()
{
std::cerr << "TestWindow::onOkButtonClicked() called." << std::endl;
mainWindow->hide();
}
/*------------------------------------------------------------------------------
* Event handler for the window being hidden.
*----------------------------------------------------------------------------*/
bool
TestWindow :: onDeleteEvent (GdkEventAny * event) throw ()
{
// We could add a confirmation dialog here.
std::cerr << "TestWindow::onDeleteEvent() called." << std::endl;
return false;
}
/*------------------------------------------------------------------------------
* Run the window.
*----------------------------------------------------------------------------*/
void
TestWindow :: run (void) throw ()
{
Gtk::Main::run(*mainWindow);
}

View File

@ -43,9 +43,12 @@
#include <gtkmm.h>
#include <libglademm.h>
#include "LiveSupport/Core/LocalizedObject.h"
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Widgets/ComboBoxText.h"
#include "LiveSupport/Widgets/ZebraTreeView.h"
#include "LiveSupport/Widgets/ZebraTreeModelColumnRecord.h"
namespace LiveSupport {
@ -72,67 +75,95 @@ class TestWindow : public LocalizedObject
private:
/**
* Change the image from "play" to "stop" on the button when pressed.
* Configure the resource bundle.
*/
void
onPlayButtonClicked(void) throw ();
configureBundle (void) throw ();
/**
* Change the image from "stop" to "play" on the button when pressed.
* Fill the tree model.
*/
void
onStopButtonClicked(void) throw ();
/**
* The "are you sure?" dialog window.
*/
Ptr<Gtk::Dialog>::Ref dialogWindow;
fillTreeModel (void) throw ();
protected:
/**
* A large button.
* The window itself.
*/
Gtk::Button * largeButton;
Gtk::Window * mainWindow;
/**
* A button showing a "play" icon.
* The combo box.
*/
Gtk::Button * cuePlayButton;
ComboBoxText * comboBox;
/**
* A button showing a "stop" icon.
* The tree view.
*/
Gtk::Button * cueStopButton;
ZebraTreeView * treeView;
/**
* A button.
* The OK button.
*/
Gtk::Button * button;
Gtk::Button * okButton;
/**
* A button which sometimes gets disabled.
* The columns model needed by Gtk::TreeView.
*/
Gtk::Button * disableTestButton;
class ModelColumns : public ZebraTreeModelColumnRecord
{
public:
/**
* A column showing a Pixbuf.
*/
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> >
pixbufColumn;
/**
* A text column.
*/
Gtk::TreeModelColumn<Glib::ustring> textColumn;
/**
* Constructor.
*/
ModelColumns(void) throw ()
{
add(pixbufColumn);
add(textColumn);
}
};
/**
* A combo box.
* The column model.
*/
ComboBoxText * comboBoxText;
ModelColumns modelColumns;
/**
* Event handler for the large button being clicked.
* The tree model, as a GTK reference.
*/
Glib::RefPtr<Gtk::ListStore> treeModel;
/**
* Event handler for selection change in the combo box.
*/
virtual void
onButtonClicked(void) throw ();
onComboBoxSelectionChanged (void) throw ();
/**
* Event handler for the close button being clicked
* (overrides WhiteWindow::onCloseButtonClicked()).
* Event handler for the OK button being clicked.
*/
virtual void
onCloseButtonClicked(void) throw ();
onOkButtonClicked (void) throw ();
/**
* Event handler for the window being hidden.
*/
virtual bool
onDeleteEvent (GdkEventAny * event) throw ();
public:
@ -140,14 +171,21 @@ class TestWindow : public LocalizedObject
/**
* Constructor.
*/
TestWindow(void) throw ();
TestWindow (void) throw ();
/**
* Virtual destructor.
*/
virtual
~TestWindow(void) throw ();
~TestWindow (void) throw ()
{
}
/**
* Run the window.
*/
void
run (void) throw ();
};
/* ================================================= external data structures */

View File

@ -28,7 +28,7 @@
------------------------------------------------------------------------------*/
/** @file
* This file contains the main entry point to the Scheduler daemon.
* This file is the main entry point for the TestWindow in the Widgets module.
*/
/* ============================================================ include files */
@ -168,7 +168,7 @@ int main ( int argc,
{
TestWindow testWindow;
Gtk::Main::run(testWindow);
testWindow.run();
}
exit(EXIT_SUCCESS);

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.0 on Wed Aug 8 11:34:54 2007 by fgerlits@fgerlits-laptop-->
<glade-interface>
<widget class="GtkWindow" id="mainWindow1">
<property name="width_request">300</property>
<property name="height_request">200</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">8</property>
<property name="spacing">8</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">8</property>
<child>
<widget class="GtkComboBox" id="comboBox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkTreeView" id="treeView1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="headers_clickable">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="okButton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,8 +1,16 @@
hu:table
{
cancelButtonLabel:string { "Mégsem" }
noButtonLabel:string { "Nem" }
yesButtonLabel:string { "Igen" }
okButtonLabel:string { "OK" }
windowTitle:string { "Próbaablak" }
pixbufColumnTitle:string { "Kép" }
textColumnTitle:string { "Szöveg" }
firstOption:string { "Első lehetőség" }
secondOption:string { "Második lehetőség" }
thirdOption:string { "Harmadik lehetőség" }
textOne:string { "Egy - megérett a meggy." }
textTwo:string { "Kettő - csipkebokor vessző." }
textThree:string { "Három - te leszel a párom. " }
}

View File

@ -1,8 +1,16 @@
root:table
{
cancelButtonLabel:string { "Cancel" }
noButtonLabel:string { "No" }
yesButtonLabel:string { "Yes" }
okButtonLabel:string { "OK" }
windowTitle:string { "Test Window" }
pixbufColumnTitle:string { "Pixbuf" }
textColumnTitle:string { "Text" }
firstOption:string { "First option" }
secondOption:string { "Second option" }
thirdOption:string { "Third option" }
textOne:string { "When I was One, I had just begun." }
textTwo:string { "When I was Two, I was nearly new." }
textThree:string { "When I was Three, I was hardly me." }
}

View File

@ -145,6 +145,7 @@ class ScratchpadWindow : public BasicWindow,
class ModelColumns : public PlayableTreeModelColumnRecord
{
public:
/**
* The column for the type of the entry in the list
*/