- Do things in a more C++ style
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@739 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
483cf2815d
commit
f84c7bbf40
|
@ -21,9 +21,8 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
|
||||||
#include "start_gui.hh"
|
#include "gui_builder.hh"
|
||||||
|
|
||||||
#include <libglademm/xml.h>
|
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
#include <gtkmm/aboutdialog.h>
|
#include <gtkmm/aboutdialog.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
|
@ -32,42 +31,57 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Gtk::Window*
|
using namespace sgpem;
|
||||||
start_gui(const std::string& filename)
|
using Gnome::Glade::Xml;
|
||||||
|
|
||||||
|
|
||||||
|
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
|
: _refXml(Xml::create(gladefile))
|
||||||
{
|
{
|
||||||
using namespace Gnome;
|
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
|
|
||||||
// Debug line (erase me when done):
|
Window& main_window = get_initial_window();
|
||||||
std::cout << _("Filename to open: ") << filename << std::endl;
|
|
||||||
|
|
||||||
Glib::RefPtr<Glade::Xml> refXml =
|
|
||||||
Glade::Xml::create(GLADEDIR "/main-window.glade");
|
|
||||||
|
|
||||||
Window* main_window = NULL;
|
|
||||||
refXml->get_widget("MainWindow", main_window);
|
|
||||||
assert(main_window != NULL);
|
|
||||||
|
|
||||||
// Connect extra signals (decide where to do this...
|
// Connect extra signals (decide where to do this...
|
||||||
// here -- ugly -- derive widgets and then use
|
// here -- ugly -- derive widgets and then use
|
||||||
// Glade::Xml::get_widget_derived -- better --)
|
// Glade::Xml::get_widget_derived -- better --)
|
||||||
MenuItem* file_quit = NULL;
|
MenuItem* file_quit = NULL;
|
||||||
refXml->get_widget("MenuItem.File.Quit", file_quit);
|
_refXml->get_widget("MenuItem.File.Quit", file_quit);
|
||||||
assert(file_quit != NULL);
|
assert(file_quit != NULL);
|
||||||
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
|
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
|
||||||
|
|
||||||
// About dialog
|
// About dialog
|
||||||
MenuItem* help_about = NULL;
|
MenuItem* help_about = NULL;
|
||||||
refXml->get_widget("MenuItem.Help.About", help_about);
|
_refXml->get_widget("MenuItem.Help.About", help_about);
|
||||||
assert(help_about != NULL);
|
assert(help_about != NULL);
|
||||||
AboutDialog* about_dialog = NULL;
|
AboutDialog* about_dialog = NULL;
|
||||||
refXml->get_widget("AboutDialog", about_dialog);
|
_refXml->get_widget("AboutDialog", about_dialog);
|
||||||
assert(about_dialog != NULL);
|
assert(about_dialog != NULL);
|
||||||
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
||||||
|
|
||||||
// FIXME: Here open filename if != ""
|
// main_window.show_all_children();
|
||||||
|
|
||||||
main_window->show_all_children();
|
|
||||||
return main_window;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GuiBuilder::~GuiBuilder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Gtk::Window&
|
||||||
|
GuiBuilder::get_initial_window() const
|
||||||
|
{
|
||||||
|
Gtk::Window* main_window = NULL;
|
||||||
|
_refXml->get_widget("MainWindow", main_window);
|
||||||
|
assert(main_window != NULL);
|
||||||
|
return *main_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GuiBuilder::open_file(const std::string& filename)
|
||||||
|
{
|
||||||
|
// FIXME: to be written.
|
||||||
|
// Debug line (erase me when done):
|
||||||
|
std::cout << _("Filename to open: ") << filename << std::endl;
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// src/startgui.hh - Copyright 2005, 2006, University
|
// src/gui_builder.hh - Copyright 2005, 2006, University
|
||||||
// of Padova, dept. of Pure and Applied
|
// of Padova, dept. of Pure and Applied
|
||||||
// Mathematics
|
// Mathematics
|
||||||
//
|
//
|
||||||
|
@ -18,19 +18,35 @@
|
||||||
// along with SGPEMv2; if not, write to the Free Software
|
// along with SGPEMv2; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
#ifndef GTKGUI_STARTGUI_HH
|
#ifndef GUI_BUILDER_HH
|
||||||
#define GTKGUI_STARTGUI_HH 1
|
#define GUI_BUILDER_HH 1
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
|
#include <libglademm/xml.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/** \brief This function initialize and starts the whole GUI
|
/** \brief This class initialize and starts the whole GUI
|
||||||
|
|
||||||
*/
|
*/
|
||||||
Gtk::Window* start_gui(const std::string& filename);
|
namespace sgpem {
|
||||||
|
|
||||||
#endif
|
class GuiBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GuiBuilder(const std::string& gladefile = GLADEDIR "/main-window.glade");
|
||||||
|
~GuiBuilder();
|
||||||
|
|
||||||
|
Gtk::Window& get_initial_window() const;
|
||||||
|
void open_file(const std::string& filename);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Glib::RefPtr<Gnome::Glade::Xml> _refXml;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
#endif //~ GUI_BUILDER_HH
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
#include "backend/global_preferences.hh"
|
#include "backend/global_preferences.hh"
|
||||||
#include "backend/plugin_manager.hh"
|
#include "backend/plugin_manager.hh"
|
||||||
|
#include "gui_builder.hh"
|
||||||
#include "parse_opts.hh"
|
#include "parse_opts.hh"
|
||||||
#include "start_gui.hh"
|
|
||||||
|
|
||||||
#include <glibmm/optioncontext.h>
|
#include <glibmm/optioncontext.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
|
@ -121,12 +121,11 @@ parse_options(int argc, char** argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Gtk::Window* main_window;
|
GuiBuilder* gui = new GuiBuilder();
|
||||||
if(fnames.begin() != fnames.end())
|
if(fnames.begin() != fnames.end())
|
||||||
main_window = start_gui(*fnames.begin());
|
gui->open_file(*fnames.begin());
|
||||||
else
|
main_loop.run(gui->get_initial_window());
|
||||||
main_window = start_gui("");
|
delete gui;
|
||||||
main_loop.run(*main_window);
|
|
||||||
}
|
}
|
||||||
} // ~ try
|
} // ~ try
|
||||||
catch(Glib::OptionError e)
|
catch(Glib::OptionError e)
|
||||||
|
@ -150,5 +149,3 @@ print_license()
|
||||||
"see file COPYING contained in the source package. \n"
|
"see file COPYING contained in the source package. \n"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue