From 663ac89c7dea13c7017bd65598db1fe3ccae694d Mon Sep 17 00:00:00 2001 From: maroy Date: Fri, 19 Nov 2004 17:05:07 +0000 Subject: [PATCH] created LoginWindow renamed HelloWorld to UiTestMainWindow, enabling testing of UI components --- .../products/gLiveSupport/etc/Makefile.in | 5 +- .../products/gLiveSupport/etc/configure.ac | 6 +- .../products/gLiveSupport/src/LoginWindow.cxx | 175 ++++++++++++++++++ .../products/gLiveSupport/src/LoginWindow.h | 168 +++++++++++++++++ .../{HelloWorld.cxx => UiTestMainWindow.cxx} | 71 ++++--- .../src/{HelloWorld.h => UiTestMainWindow.h} | 46 +++-- .../products/gLiveSupport/src/main.cxx | 12 +- 7 files changed, 439 insertions(+), 44 deletions(-) create mode 100644 livesupport/products/gLiveSupport/src/LoginWindow.cxx create mode 100644 livesupport/products/gLiveSupport/src/LoginWindow.h rename livesupport/products/gLiveSupport/src/{HelloWorld.cxx => UiTestMainWindow.cxx} (56%) rename livesupport/products/gLiveSupport/src/{HelloWorld.h => UiTestMainWindow.h} (67%) diff --git a/livesupport/products/gLiveSupport/etc/Makefile.in b/livesupport/products/gLiveSupport/etc/Makefile.in index 15655cc1d..2b6cfe647 100644 --- a/livesupport/products/gLiveSupport/etc/Makefile.in +++ b/livesupport/products/gLiveSupport/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.2 $ +# Version : $Revision: 1.3 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/etc/Makefile.in,v $ # # @configure_input@ @@ -103,7 +103,8 @@ LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} \ #------------------------------------------------------------------------------- # Dependencies #------------------------------------------------------------------------------- -G_LIVESUPPORT_OBJS = ${TMP_DIR}/HelloWorld.o +G_LIVESUPPORT_OBJS = ${TMP_DIR}/UiTestMainWindow.o \ + ${TMP_DIR}/LoginWindow.o G_LIVESUPPORT_EXE_OBJS = ${G_LIVESUPPORT_OBJS} \ diff --git a/livesupport/products/gLiveSupport/etc/configure.ac b/livesupport/products/gLiveSupport/etc/configure.ac index fb1ad782a..7007609f7 100644 --- a/livesupport/products/gLiveSupport/etc/configure.ac +++ b/livesupport/products/gLiveSupport/etc/configure.ac @@ -21,7 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl dnl dnl Author : $Author: maroy $ -dnl Version : $Revision: 1.2 $ +dnl Version : $Revision: 1.3 $ dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/etc/configure.ac,v $ dnl----------------------------------------------------------------------------- @@ -35,7 +35,7 @@ dnl----------------------------------------------------------------------------- AC_INIT(gLiveSupport, 0.1, bugs@campware.org) AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL]) -AC_REVISION($Revision: 1.2 $) +AC_REVISION($Revision: 1.3 $) AC_CONFIG_SRCDIR(../src/main.cxx) @@ -45,7 +45,7 @@ AC_PROG_CXX() AC_CHECK_HEADERS(sys/types.h unistd.h getopt.h signal.h sys/stat.h time.h) AC_CHECK_HEADERS(stdio.h fcntl.h pthread.h sys/time.h) -PKG_CHECK_MODULES(GTKMM,[gtkmm-2.0 >= 2.2.0]) +PKG_CHECK_MODULES(GTKMM,[gtkmm-2.4 >= 2.4.0]) AC_SUBST(GTKMM_CFLAGS) AC_SUBST(GTKMM_LIBS) diff --git a/livesupport/products/gLiveSupport/src/LoginWindow.cxx b/livesupport/products/gLiveSupport/src/LoginWindow.cxx new file mode 100644 index 000000000..0ec67402d --- /dev/null +++ b/livesupport/products/gLiveSupport/src/LoginWindow.cxx @@ -0,0 +1,175 @@ +/*------------------------------------------------------------------------------ + + 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/products/gLiveSupport/src/LoginWindow.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "LoginWindow.h" + + +using namespace LiveSupport::Core; +using namespace LiveSupport::GLiveSupport; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Constructor. + *----------------------------------------------------------------------------*/ +LoginWindow :: LoginWindow (void) throw () +{ + table.reset(new Gtk::Table(2, 2, false)); + loginLabel.reset(new Gtk::Label("login:")); + passwordLabel.reset(new Gtk::Label("password:")); + loginEntry.reset(new Gtk::Entry()); + passwordEntry.reset(new Gtk::Entry()); + okButton.reset(new Gtk::Button("OK")); + + // set up the login label + loginLabel->set_name("loginLabel"); + loginLabel->set_alignment(0, 0.5); + loginLabel->set_padding(0, 0); + loginLabel->set_justify(Gtk::JUSTIFY_RIGHT); + loginLabel->set_line_wrap(false); + loginLabel->set_use_markup(false); + loginLabel->set_selectable(false); + + // set up the password label + passwordLabel->set_name("passwordLabel"); + passwordLabel->set_alignment(0, 0.5); + passwordLabel->set_padding(0, 0); + passwordLabel->set_justify(Gtk::JUSTIFY_RIGHT); + passwordLabel->set_line_wrap(false); + passwordLabel->set_use_markup(false); + passwordLabel->set_selectable(false); + + // set up the login text entry area + loginEntry->set_name("loginEntry"); + loginEntry->set_flags(Gtk::CAN_FOCUS|Gtk::HAS_FOCUS); + loginEntry->set_visibility(true); + loginEntry->set_editable(true); + loginEntry->set_max_length(0); + loginEntry->set_text(""); + loginEntry->set_has_frame(true); + loginEntry->set_activates_default(true); + + // set up the password text entry area + passwordEntry->set_name("passwordEntry"); + passwordEntry->set_flags(Gtk::CAN_FOCUS); + passwordEntry->set_visibility(false); + passwordEntry->set_editable(true); + passwordEntry->set_max_length(0); + passwordEntry->set_text(""); + passwordEntry->set_has_frame(true); + passwordEntry->set_activates_default(true); + + // set up the OK button + okButton->set_name("okButton"); + okButton->set_flags(Gtk::CAN_FOCUS|Gtk::CAN_DEFAULT|Gtk::HAS_DEFAULT); + okButton->set_relief(Gtk::RELIEF_NORMAL); + // Register the signal handler for the button getting clicked. + okButton->signal_clicked().connect(sigc::mem_fun(*this, + &LoginWindow::onOkButtonClicked)); + + // set up the table, which provides the layout, and place the widgets + // inside the table + table->set_name("table"); + table->set_row_spacings(0); + table->set_col_spacings(0); + table->attach(*loginLabel, + 0, 1, 0, 1, + Gtk::FILL, Gtk::AttachOptions(), 0, 0); + table->attach(*passwordLabel, + 0, 1, 1, 2, + Gtk::FILL, Gtk::AttachOptions(), 0, 0); + table->attach(*loginEntry, + 1, 2, 0, 1, + Gtk::EXPAND|Gtk::FILL, Gtk::AttachOptions(), 0, 0); + table->attach(*passwordEntry, + 1, 2, 1, 2, + Gtk::EXPAND|Gtk::FILL, Gtk::AttachOptions(), 0, 0); + table->attach(*okButton, + 1, 2, 2, 3, + Gtk::FILL, Gtk::AttachOptions(), 0, 0); + + // set up the window itself + set_name("loginWindow"); + set_title("LiveSupport login"); + set_modal(true); + property_window_position().set_value(Gtk::WIN_POS_NONE); + set_resizable(false); + property_destroy_with_parent().set_value(false); + set_default(*okButton); + + // add the table to the window, and show everything + add(*table); + loginLabel->show(); + passwordLabel->show(); + loginEntry->show(); + passwordEntry->show(); + okButton->show(); + table->show(); + show(); +} + + +/*------------------------------------------------------------------------------ + * Destructor. + *----------------------------------------------------------------------------*/ +LoginWindow :: ~LoginWindow (void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Event handler for the button getting clicked. + *----------------------------------------------------------------------------*/ +void +LoginWindow :: onOkButtonClicked (void) throw () +{ + loginText.reset(new std::string(loginEntry->get_text())); + passwordText.reset(new std::string(passwordEntry->get_text())); + + hide(); +} + + diff --git a/livesupport/products/gLiveSupport/src/LoginWindow.h b/livesupport/products/gLiveSupport/src/LoginWindow.h new file mode 100644 index 000000000..019002826 --- /dev/null +++ b/livesupport/products/gLiveSupport/src/LoginWindow.h @@ -0,0 +1,168 @@ +/*------------------------------------------------------------------------------ + + 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/products/gLiveSupport/src/LoginWindow.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef LoginWindow_h +#define LoginWindow_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 +#include +#include + +#include "LiveSupport/Core/Ptr.h" + +namespace LiveSupport { +namespace GLiveSupport { + +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A window, handling user login. + * + * @author $Author: maroy $ + * @version $Revision: 1.1 $ + */ +class LoginWindow : public Gtk::Window +{ + + protected: + /** + * The table, which provides the layout for the window. + */ + Ptr::Ref table; + + /** + * The login label in the window. + */ + Ptr::Ref loginLabel; + + /** + * The password label in the window. + */ + Ptr::Ref passwordLabel; + + /** + * The login text entry area. + */ + Ptr::Ref loginEntry; + + /** + * The password text entry area. + */ + Ptr::Ref passwordEntry; + + /** + * The OK button. + */ + Ptr::Ref okButton; + + /** + * The login text, that was entered by the user. + */ + Ptr::Ref loginText; + + /** + * The password text, that was entered by the user. + */ + Ptr::Ref passwordText; + + /** + * Signal handler for the ok button clicked. + */ + virtual void + onOkButtonClicked(void) throw (); + + + public: + /** + * Constructor. + */ + LoginWindow(void) throw (); + + /** + * Virtual destructor. + */ + virtual + ~LoginWindow(void) throw (); + + /** + * Get the login entered by the user. + * + * @return the login entered by the user. + */ + Ptr::Ref + getLogin(void) const throw () + { + return loginText; + } + + /** + * Get the password entered by the user. + * + * @return the password entered by the user. + */ + Ptr::Ref + getPassword(void) const throw () + { + return passwordText; + } +}; + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace GLiveSupport +} // namespace LiveSupport + +#endif // LoginWindow_h + diff --git a/livesupport/products/gLiveSupport/src/HelloWorld.cxx b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx similarity index 56% rename from livesupport/products/gLiveSupport/src/HelloWorld.cxx rename to livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx index 9af734e17..79d8f95e0 100644 --- a/livesupport/products/gLiveSupport/src/HelloWorld.cxx +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx @@ -23,7 +23,7 @@ Author : $Author: maroy $ Version : $Revision: 1.1 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/HelloWorld.cxx,v $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -35,7 +35,10 @@ #include -#include "HelloWorld.h" +#include + +#include "LoginWindow.h" +#include "UiTestMainWindow.h" using namespace LiveSupport::GLiveSupport; @@ -45,11 +48,6 @@ using namespace LiveSupport::GLiveSupport; /* ================================================ local constants & macros */ -/** - * The Hello, World! string - */ -static std::string helloWorld("Hello, World!"); - /* =============================================== local function prototypes */ @@ -59,37 +57,66 @@ static std::string helloWorld("Hello, World!"); /*------------------------------------------------------------------------------ * Constructor. *----------------------------------------------------------------------------*/ -HelloWorld :: HelloWorld (void) throw () - : button(helloWorld) +UiTestMainWindow :: UiTestMainWindow (void) throw () { - // Sets the border width of the window. + // set up the quit button + quitButton.reset(new Gtk::Button("quit")); + quitButton->signal_clicked().connect(sigc::mem_fun(*this, + &UiTestMainWindow::onQuitButtonClicked)); + + // set up the login button + loginButton.reset(new Gtk::Button("loginWindow")); + loginButton->signal_clicked().connect(sigc::mem_fun(*this, + &UiTestMainWindow::onLoginButtonClicked)); + + // set up the layout, which is a button box + layout.reset(new Gtk::VButtonBox()); + + // set up the main window, and show everything set_border_width(10); + layout->add(*loginButton); + layout->add(*quitButton); + add(*layout); - // Register the signal handler for the button getting clicked. - button.signal_clicked().connect(slot(*this, &HelloWorld::onButtonClicked)); - - // This packs the button into the Window (a container). - add(button); - - // The final step is to display this newly created widget... - button.show(); + // show everything + loginButton->show(); + quitButton->show(); + layout->show(); + show(); } /*------------------------------------------------------------------------------ * Destructor. *----------------------------------------------------------------------------*/ -HelloWorld :: ~HelloWorld (void) throw () +UiTestMainWindow :: ~UiTestMainWindow (void) throw () { } /*------------------------------------------------------------------------------ - * Event handler for the button getting clicked. + * Event handler for the quit getting clicked. *----------------------------------------------------------------------------*/ void -HelloWorld :: onButtonClicked (void) throw () +UiTestMainWindow :: onQuitButtonClicked (void) throw () { - std::cout << helloWorld << std::endl; + hide(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the login button getting clicked. + *----------------------------------------------------------------------------*/ +void +UiTestMainWindow :: onLoginButtonClicked (void) throw () +{ + std::cout << "invoking loginWindow" << std::endl; + + Ptr::Ref loginWindow(new LoginWindow()); + + Gtk::Main::run(*loginWindow); + + std::cout << "login: " << *loginWindow->getLogin() << std::endl; + std::cout << "password: " << *loginWindow->getPassword() << std::endl; } diff --git a/livesupport/products/gLiveSupport/src/HelloWorld.h b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h similarity index 67% rename from livesupport/products/gLiveSupport/src/HelloWorld.h rename to livesupport/products/gLiveSupport/src/UiTestMainWindow.h index 458339fa1..f5f079d4b 100644 --- a/livesupport/products/gLiveSupport/src/HelloWorld.h +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h @@ -23,11 +23,11 @@ Author : $Author: maroy $ Version : $Revision: 1.1 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/HelloWorld.h,v $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.h,v $ ------------------------------------------------------------------------------*/ -#ifndef HelloWorld_h -#define HelloWorld_h +#ifndef UiTestMainWindow_h +#define UiTestMainWindow_h #ifndef __cplusplus #error This is a C++ include file @@ -41,11 +41,16 @@ #endif #include +#include #include +#include "LiveSupport/Core/Ptr.h" + namespace LiveSupport { namespace GLiveSupport { +using namespace LiveSupport::Core; + /* ================================================================ constants */ @@ -55,38 +60,53 @@ namespace GLiveSupport { /* =============================================================== data types */ /** - * A simple window, just saying "Hello, World!" + * A window, enabling interactive testing of UI components. * * @author $Author: maroy $ * @version $Revision: 1.1 $ */ -class HelloWorld : public Gtk::Window +class UiTestMainWindow : public Gtk::Window { - protected: /** - * The only button in the window. + * The layout used in the window. */ - Gtk::Button button; + Ptr::Ref layout; /** - * Signal handler for the only button clicked. + * The to quit the applicaiton. + */ + Ptr::Ref quitButton; + + /** + * The button invoking the LoginWindow. + */ + Ptr::Ref loginButton; + + /** + * Signal handler for the quit button clicked. */ virtual void - onButtonClicked(void) throw (); + onQuitButtonClicked(void) throw (); + + /** + * Signal handler for the login button clicked. + */ + virtual void + onLoginButtonClicked(void) throw (); public: /** * Constructor. */ - HelloWorld(void) throw (); + UiTestMainWindow(void) throw (); /** * Virtual destructor. */ virtual - ~HelloWorld(void) throw (); + ~UiTestMainWindow(void) throw (); }; @@ -99,5 +119,5 @@ class HelloWorld : public Gtk::Window } // namespace GLiveSupport } // namespace LiveSupport -#endif // HelloWorld_h +#endif // UiTestMainWindow_h diff --git a/livesupport/products/gLiveSupport/src/main.cxx b/livesupport/products/gLiveSupport/src/main.cxx index b07ae275b..67ad9221e 100644 --- a/livesupport/products/gLiveSupport/src/main.cxx +++ b/livesupport/products/gLiveSupport/src/main.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/main.cxx,v $ ------------------------------------------------------------------------------*/ @@ -39,8 +39,11 @@ #include -#include "HelloWorld.h" +#include "LiveSupport/Core/Ptr.h" +#include "UiTestMainWindow.h" + +using namespace LiveSupport::Core; using namespace LiveSupport::GLiveSupport; /* =================================================== local data structures */ @@ -65,9 +68,10 @@ int main ( int argc, { Gtk::Main kit(argc, argv); - HelloWorld helloworld; + Ptr::Ref mainWindow(new UiTestMainWindow()); + // Shows the window and returns when it is closed. - Gtk::Main::run(helloworld); + Gtk::Main::run(*mainWindow); return 0; }