Reformatted code to comply with project format guidlines, and added some documentation

This commit is contained in:
Joel Holdsworth 2008-04-11 22:04:39 +01:00
parent 6f5c701c57
commit bd0e634a27
6 changed files with 290 additions and 228 deletions

View file

@ -1,19 +1,33 @@
/* /*
* This program is free software; you can redistribute it and/or modify gtk-lumiera.hpp - Application wide global definitions
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or Copyright (C) Lumiera.org
* (at your option) any later version. 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
*
* This program is distributed in the hope that it will be useful, This program is free software; you can redistribute it and/or
* but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU General Public License as
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the published by the Free Software Foundation; either version 2 of the
* GNU Library General Public License for more details. License, or (at your option) any later version.
*
* You should have received a copy of the GNU General Public License This program is distributed in the hope that it will be useful,
* along with this program; if not, write to the Free Software but WITHOUT ANY WARRANTY; without even the implied warranty of
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file gtk-lumiera.hpp
** This file contains application wide global definitions
** user actions.
** @see main.cpp
*/ */
#ifndef GTK_LUMIERA_HPP
#define GTK_LUMIERA_HPO
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
# include <libintl.h> # include <libintl.h>
# define _(String) gettext (String) # define _(String) gettext (String)
@ -26,4 +40,11 @@
# define bindtextdomain(Package, Directory) # define bindtextdomain(Package, Directory)
#endif #endif
const gchar* AppTitle = N_("Lumiera"); /**
* The name of the Lumiera application
*/
static const gchar* AppTitle = N_("Lumiera");
#endif

View file

@ -1,26 +1,24 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/* /*
* main.cpp Main.cpp - The entry point for the GTK GUI application
* Copyright (C) Joel Holdsworth 2008 <joel@airwebreathe.org.uk>
* Copyright (C) Lumiera.org
* main.cc is free software. 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
*
* You may redistribute it and/or modify it under the terms of the This program is free software; you can redistribute it and/or
* GNU General Public License, as published by the Free Software modify it under the terms of the GNU General Public License as
* Foundation; either version 2 of the License, or (at your option) published by the Free Software Foundation; either version 2 of the
* any later version. License, or (at your option) any later version.
*
* main.cc is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* See the GNU General Public License for more details. GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with main.cc. If not, write to: along with this program; if not, write to the Free Software
* The Free Software Foundation, Inc., Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA. * *****************************************************/
*/
#include <gtkmm.h> #include <gtkmm.h>
#include <iostream> #include <iostream>
@ -29,20 +27,27 @@
# include <libintl.h> # include <libintl.h>
#endif #endif
#include "gtk-lumiera.hpp"
#include "workspace/mainwindow.hpp" #include "workspace/mainwindow.hpp"
using namespace Lumiera::Workspace;
//const gchar* AppTitle
//const gchar AppTitle[] = N_("Lumiera");
using namespace lumiera::workspace;
using namespace Gtk; using namespace Gtk;
int main (int argc, char *argv[]) int
{ main (int argc, char *argv[])
{
Main kit(argc, argv); Main kit(argc, argv);
Glib::set_application_name("UIManager example"); Glib::set_application_name(AppTitle);
MainWindow main_window; MainWindow main_window;
kit.run(main_window); kit.run(main_window);
return 0; return 0;
} }

View file

@ -1,101 +1,105 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/* /*
* gui Actions.cpp - Definition of the main workspace window object
* Copyright (C) 2008 <>
* Copyright (C) Lumiera.org
* gui is free software. 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
*
* You may redistribute it and/or modify it under the terms of the This program is free software; you can redistribute it and/or
* GNU General Public License, as published by the Free Software modify it under the terms of the GNU General Public License as
* Foundation; either version 2 of the License, or (at your option) published by the Free Software Foundation; either version 2 of the
* any later version. License, or (at your option) any later version.
*
* gui is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* See the GNU General Public License for more details. GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with gui. If not, write to: along with this program; if not, write to the Free Software
* The Free Software Foundation, Inc., Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA. * *****************************************************/
*/
#include "actions.hpp" #include "actions.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
namespace Lumiera { namespace lumiera
namespace Workspace { {
namespace workspace
{
Actions::Actions(MainWindow &main_window) : Actions::Actions(MainWindow &main_window) :
_main_window(main_window) mainWindow(main_window)
{ {
_action_group = Gtk::ActionGroup::create(); actionGroup = Gtk::ActionGroup::create();
// File|New sub menu: // File|New sub menu:
_action_group->add(Gtk::Action::create("FileNewStandard", actionGroup->add(Gtk::Action::create("FileNewStandard",
Gtk::Stock::NEW, "_New", "Create a new file"), Gtk::Stock::NEW, "_New", "Create a new file"),
sigc::mem_fun(*this, &Actions::on_menu_file_new_generic)); sigc::mem_fun(*this, &Actions::on_menu_file_new_generic));
_action_group->add(Gtk::Action::create("FileNewFoo", actionGroup->add(Gtk::Action::create("FileNewFoo",
Gtk::Stock::NEW, "New Foo", "Create a new foo"), Gtk::Stock::NEW, "New Foo", "Create a new foo"),
sigc::mem_fun(*this, &Actions::on_menu_file_new_generic)); sigc::mem_fun(*this, &Actions::on_menu_file_new_generic));
_action_group->add(Gtk::Action::create("FileNewGoo", actionGroup->add(Gtk::Action::create("FileNewGoo",
Gtk::Stock::NEW, "_New Goo", "Create a new goo"), Gtk::Stock::NEW, "_New Goo", "Create a new goo"),
sigc::mem_fun(*this, &Actions::on_menu_file_new_generic)); sigc::mem_fun(*this, &Actions::on_menu_file_new_generic));
// File menu: // File menu:
_action_group->add(Gtk::Action::create("FileMenu", "File")); actionGroup->add(Gtk::Action::create("FileMenu", "File"));
// Sub-menu. // Sub-menu.
_action_group->add(Gtk::Action::create("FileNew", Gtk::Stock::NEW)); actionGroup->add(Gtk::Action::create("FileNew", Gtk::Stock::NEW));
_action_group->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), actionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
sigc::mem_fun(*this, &Actions::on_menu_file_quit)); sigc::mem_fun(*this, &Actions::on_menu_file_quit));
// Edit menu: // Edit menu:
_action_group->add(Gtk::Action::create("EditMenu", "Edit")); actionGroup->add(Gtk::Action::create("EditMenu", "Edit"));
_action_group->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY), actionGroup->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY),
sigc::mem_fun(*this, &Actions::on_menu_others)); sigc::mem_fun(*this, &Actions::on_menu_others));
_action_group->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE), actionGroup->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE),
sigc::mem_fun(*this, &Actions::on_menu_others)); sigc::mem_fun(*this, &Actions::on_menu_others));
_action_group->add(Gtk::Action::create("EditSomething", "Something"), actionGroup->add(Gtk::Action::create("EditSomething", "Something"),
Gtk::AccelKey("<control><alt>S"), Gtk::AccelKey("<control><alt>S"),
sigc::mem_fun(*this, &Actions::on_menu_others)); sigc::mem_fun(*this, &Actions::on_menu_others));
// Choices menu, to demonstrate Radio items // Choices menu, to demonstrate Radio items
_action_group->add( Gtk::Action::create("ChoicesMenu", "Choices") ); actionGroup->add( Gtk::Action::create("ChoicesMenu", "Choices") );
Gtk::RadioAction::Group group_userlevel; Gtk::RadioAction::Group group_userlevel;
m_refChoiceOne = Gtk::RadioAction::create(group_userlevel, "ChoiceOne", "One"); m_refChoiceOne = Gtk::RadioAction::create(group_userlevel, "ChoiceOne", "One");
_action_group->add(m_refChoiceOne, actionGroup->add(m_refChoiceOne,
sigc::mem_fun(*this, &Actions::on_menu_choices_one) ); sigc::mem_fun(*this, &Actions::on_menu_choices_one) );
m_refChoiceTwo = Gtk::RadioAction::create(group_userlevel, "ChoiceTwo", "Two"); m_refChoiceTwo = Gtk::RadioAction::create(group_userlevel, "ChoiceTwo", "Two");
_action_group->add(m_refChoiceTwo, actionGroup->add(m_refChoiceTwo,
sigc::mem_fun(*this, &Actions::on_menu_choices_two) ); sigc::mem_fun(*this, &Actions::on_menu_choices_two) );
// Help menu: // Help menu:
_action_group->add( Gtk::Action::create("HelpMenu", "Help") ); actionGroup->add( Gtk::Action::create("HelpMenu", "Help") );
_action_group->add( Gtk::Action::create("HelpAbout", Gtk::Stock::HELP), actionGroup->add( Gtk::Action::create("HelpAbout", Gtk::Stock::HELP),
sigc::mem_fun(*this, &Actions::on_menu_others) ); sigc::mem_fun(*this, &Actions::on_menu_others) );
} }
void Actions::on_menu_file_quit() void
{ Actions::on_menu_file_quit()
_main_window.hide(); // Closes the main window to stop the Gtk::Main::run(). {
} mainWindow.hide(); // Closes the main window to stop the Gtk::Main::run().
}
void Actions::on_menu_file_new_generic() void
{ Actions::on_menu_file_new_generic()
{
g_message("A File|New menu item was selecteda."); g_message("A File|New menu item was selecteda.");
} }
void Actions::on_menu_others() void
{ Actions::on_menu_others()
{
g_message("A menu item was selected."); g_message("A menu item was selected.");
} }
void Actions::on_menu_choices_one() void
{ Actions::on_menu_choices_one()
{
Glib::ustring message; Glib::ustring message;
//if(m_refChoiceOne->get_active()) //if(m_refChoiceOne->get_active())
// message = "Choice 1 was selected."; // message = "Choice 1 was selected.";
@ -103,10 +107,11 @@ void Actions::on_menu_choices_one()
message = "Choice 1 was deselected"; message = "Choice 1 was deselected";
g_message(message.c_str()); g_message(message.c_str());
} }
void Actions::on_menu_choices_two() void
{ Actions::on_menu_choices_two()
{
Glib::ustring message; Glib::ustring message;
//if(_main_window.m_refChoiceTwo->get_active()) //if(_main_window.m_refChoiceTwo->get_active())
// message = "Choice 2 was selected."; // message = "Choice 2 was selected.";
@ -114,8 +119,8 @@ void Actions::on_menu_choices_two()
message = "Choice 2 was deselected"; message = "Choice 2 was deselected";
g_message(message.c_str()); g_message(message.c_str());
} }
} // namespace Workspace } // namespace workspace
} // namespace Lumiera } // namespace lumiera

View file

@ -1,61 +1,71 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/* /*
* gui ACTIONS.hpp - Definition of a helper class for user actions
* Copyright (C) 2008 <>
* Copyright (C) Lumiera.org
* gui is free software. 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
*
* You may redistribute it and/or modify it under the terms of the This program is free software; you can redistribute it and/or
* GNU General Public License, as published by the Free Software modify it under the terms of the GNU General Public License as
* Foundation; either version 2 of the License, or (at your option) published by the Free Software Foundation; either version 2 of the
* any later version. License, or (at your option) any later version.
*
* gui is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* See the GNU General Public License for more details. GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with gui. If not, write to: along with this program; if not, write to the Free Software
* The Free Software Foundation, Inc., Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA. */
/** @file actions.hpp
** This file contains the definition of a helper class for the
** main workspace window object, which registers and handles
** user actions.
** @see mainwindow.hpp
*/ */
#ifndef ACTIONS_H #ifndef ACTIONS_HPP
#define ACTIONS_H #define ACTIONS_HPP
#include <gtkmm.h> #include <gtkmm.h>
namespace Lumiera { namespace lumiera {
namespace Workspace { namespace workspace {
class MainWindow; class MainWindow;
class Actions /**
{ * A helper class which registers and handles
private: * user action events.
Actions(MainWindow &main_window); */
class Actions
{
private:
Actions(MainWindow &main_window);
//----- Event Handlers -----// /**
void on_menu_file_new_generic(); * A reference to the MainWindow which owns
void on_menu_file_quit(); * this helper */
void on_menu_others(); MainWindow &mainWindow;
void on_menu_choices_one(); /* ===== Event Handlers ===== */
void on_menu_choices_two(); void on_menu_file_new_generic();
void on_menu_file_quit();
void on_menu_others();
//----- Actions -----// void on_menu_choices_one();
Glib::RefPtr<Gtk::ActionGroup> _action_group; void on_menu_choices_two();
Glib::RefPtr<Gtk::RadioAction> m_refChoiceOne, m_refChoiceTwo;
// Reference to the main window /* ===== Actions ===== */
MainWindow &_main_window; Glib::RefPtr<Gtk::ActionGroup> actionGroup;
Glib::RefPtr<Gtk::RadioAction> m_refChoiceOne, m_refChoiceTwo;
friend class MainWindow; friend class MainWindow;
}; };
} // namespace Workspace } // namespace workspace
} // namespace Lumiera } // namespace lumiera
#endif // ACTIONS_H #endif // ACTIONS_H

View file

@ -1,21 +1,24 @@
// main-window.cpp /*
// Tue Apr 8 23:54:36 2008 MainWindow.cpp - Definition of the main workspace window object
// Copyright 2008 joel
// <joel@airwebreathe.org.uk>
// This program is free software; you can redistribute it and/or modify Copyright (C) Lumiera.org
// it under the terms of the GNU General Public License as published by 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version. This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// This program is distributed in the hope that it will be useful, published by the Free Software Foundation; either version 2 of the
// but WITHOUT ANY WARRANTY; without even the implied warranty of License, or (at your option) any later version.
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details. This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// You should have received a copy of the GNU General Public License MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// along with this program; if not, write to the Free Software GNU General Public License for more details.
// Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include <gtkmm/stock.h> #include <gtkmm/stock.h>
@ -26,32 +29,33 @@
#include "gtk-lumiera.hpp" #include "gtk-lumiera.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
namespace Lumiera { namespace lumiera {
namespace Workspace { namespace workspace {
MainWindow::MainWindow() MainWindow::MainWindow()
: _actions(*this) : actions(*this)
{ {
create_ui(); create_ui();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
} }
void MainWindow::create_ui() void
{ MainWindow::create_ui()
{
//----- Configure the Window -----// //----- Configure the Window -----//
set_title(AppTitle); set_title(AppTitle);
set_default_size(1024, 768); set_default_size(1024, 768);
// The UI will be nested within a VBOX // The UI will be nested within a VBOX
add(_box); add(box);
m_refUIManager = Gtk::UIManager::create(); uiManager = Gtk::UIManager::create();
m_refUIManager->insert_action_group(_actions._action_group); uiManager->insert_action_group(actions.actionGroup);
add_accel_group(m_refUIManager->get_accel_group()); add_accel_group(uiManager->get_accel_group());
//Layout the actions in a menubar and toolbar: //Layout the actions in a menubar and toolbar:
Glib::ustring ui_info = Glib::ustring ui_info =
@ -87,35 +91,33 @@ void MainWindow::create_ui()
#ifdef GLIBMM_EXCEPTIONS_ENABLED #ifdef GLIBMM_EXCEPTIONS_ENABLED
try try
{ {
m_refUIManager->add_ui_from_string(ui_info); uiManager->add_ui_from_string(ui_info);
} }
catch(const Glib::Error& ex) catch(const Glib::Error& ex)
{ {
g_error("building menus failed: "); g_error("building menus failed: ");
return; return;
} }
#else #else
std::auto_ptr<Glib::Error> ex; std::auto_ptr<Glib::Error> ex;
m_refUIManager->add_ui_from_string(ui_info, ex); uiManager->add_ui_from_string(ui_info, ex);
if(ex.get()) if(ex.get())
{ {
g_error("building menus failed: "); g_error("building menus failed: ");
return; return;
} }
#endif //GLIBMM_EXCEPTIONS_ENABLED #endif //GLIBMM_EXCEPTIONS_ENABLED
// Get the menubar and toolbar widgets, and add them to a container widget: // Get the menubar and toolbar widgets, and add them to a container widget:
Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar"); Gtk::Widget* menu_bar = uiManager->get_widget("/MenuBar");
if(pMenubar) if(menu_bar) box.pack_start(*menu_bar, Gtk::PACK_SHRINK);
_box.pack_start(*pMenubar, Gtk::PACK_SHRINK);
Gtk::Widget* pToolbar = m_refUIManager->get_widget("/ToolBar") ; Gtk::Widget* toolbar = uiManager->get_widget("/ToolBar") ;
if(pToolbar) if(toolbar) box.pack_start(*toolbar, Gtk::PACK_SHRINK);
_box.pack_start(*pToolbar, Gtk::PACK_SHRINK);
show_all_children(); show_all_children();
} }
} // namespace Workspace } // namespace workspace
} // namespace Lumiera } // namespace lumiera

View file

@ -1,17 +1,29 @@
/* /*
* This program is free software; you can redistribute it and/or modify MainWindow.hpp - Definition of the main workspace window object
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or Copyright (C) Lumiera.org
* (at your option) any later version. 2008, Joel Holdsworth <joel@airwebreathe.org.uk>
*
* This program is distributed in the hope that it will be useful, This program is free software; you can redistribute it and/or
* but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU General Public License as
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the published by the Free Software Foundation; either version 2 of the
* GNU Library General Public License for more details. License, or (at your option) any later version.
*
* You should have received a copy of the GNU General Public License This program is distributed in the hope that it will be useful,
* along with this program; if not, write to the Free Software but WITHOUT ANY WARRANTY; without even the implied warranty of
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file mainwindow.hpp
** This file contains the definition of the main workspace window
** parent, which is the toplevel parent of the whole workspace.
**
** @see mainwindow.hpp
*/ */
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
@ -20,28 +32,35 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "actions.hpp" #include "actions.hpp"
namespace Lumiera { namespace lumiera {
namespace Workspace { namespace workspace {
class MainWindow : public Gtk::Window /**
{ * The main lumiera workspace window
public: */
MainWindow(); class MainWindow : public Gtk::Window
virtual ~MainWindow(); {
public:
MainWindow();
virtual ~MainWindow();
protected: protected:
void create_ui(); void create_ui();
// Helpers /* ===== UI ===== */
Actions _actions; protected:
Gtk::VBox box;
Glib::RefPtr<Gtk::UIManager> uiManager;
// Child widgets /* ===== Helpers ===== */
Gtk::VBox _box; protected:
/**
* The instantiation of the actions helper class, which
* registers and handles user action events */
Actions actions;
};
Glib::RefPtr<Gtk::UIManager> m_refUIManager; } // namespace workspace
}; } // namespace lumiera
} // namespace Workspace
} // namespace Lumiera
#endif // MAIN_WINDOW_H #endif // MAIN_WINDOW_H