Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/vlg/develop/gwavmerger/src/TopMenuBar.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                              TopMenuBar.cpp
00004 //------------------------------------------------------------------------------
00005 // $Id: TopMenuBar.cpp,v 1.6 2003/02/07 05:15:10 vlg Exp $
00006 //------------------------------------------------------------------------------
00007 //  Copyright (c) 2002-2003 by Vladislav Grinchenko
00008 //
00009 //  This program is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU General Public License
00011 //  as published by the Free Software Foundation; either version
00012 //  2 of the License, or (at your option) any later version.
00013 //------------------------------------------------------------------------------
00014 // Created: 03/01/2002
00015 //------------------------------------------------------------------------------
00016 
00017 #include <assa/Assert.h>
00018 
00019 #include "gWavMerger-main.h"
00020 #include "TopMenuBar.h"
00021 #include "MainWindow.h"
00022 #include "ActionsMenu.h"
00023 #include "Config.h"
00024 
00025 using SigC::bind;
00026 using SigC::slot;
00027 using namespace ASSA;
00028 
00029 
00030 TopMenuBar::TopMenuBar (MainWindow& mw_, Config& cfg_)
00031     : m_mw (mw_), 
00032       m_config (cfg_), 
00033       m_loaded (false), 
00034       m_file_menu (NULL), 
00035       m_new (NULL), 
00036       m_open (NULL), 
00037       m_save (NULL), 
00038       m_save_as (NULL), 
00039       m_open_recent (NULL),
00040       m_close (NULL)
00041 {
00042     trace("TopMenuBar::TopMenuBar");
00043 
00044     m_actions = new ActionsMenu (m_mw);
00045 }
00046 
00047 
00048 TopMenuBar::~TopMenuBar ()
00049 {
00050     trace("TopMenuBar::~TopMenuBar");
00051 
00052     if (m_actions) {
00053         delete m_actions;
00054         m_actions = 0;
00055     }
00056 }
00057 
00058 void
00059 
00060 TopMenuBar::create ()
00061 {
00062     trace("TopMenuBar::create");
00063     using namespace Gtk;
00064 
00065     m_menu_bar = manage (new MenuBar ());
00066     m_open_recent_menu = manage (new Menu ());
00067     {
00068         using namespace Menu_Helpers;
00069 
00070         // [File] Menu
00071         m_file_menu = manage (new Menu ());
00072         MenuList& fl = m_file_menu->items ();
00073     
00074         fl.push_back (MenuElem ("New", slot (m_mw, &MainWindow::new_cb)));
00075         m_new = &fl.back ();
00076 
00077         fl.push_back (MenuElem ("Open", slot (m_mw, &MainWindow::open_cb)));
00078         m_open = &fl.back ();
00079 
00080         refill_history_list ();
00081         fl.push_back (MenuElem ("Open Recent", *m_open_recent_menu));
00082         m_open_recent = &fl.back ();
00083 
00084         fl.push_back (MenuElem ("Save", slot (m_mw, &MainWindow::save_cb)));
00085         m_save = &fl.back ();
00086 
00087         fl.push_back(MenuElem("SaveAs", slot(m_mw, &MainWindow::save_as_cb)));
00088         m_save_as = &fl.back ();
00089 
00090         fl.push_back (MenuElem ("Close", slot (m_mw, &MainWindow::close_cb)));
00091         m_close = &fl.back ();
00092 
00093         fl.push_back (MenuElem ("Exit", slot (m_mw, &MainWindow::exit_cb)));
00094         m_exit = &fl.back ();
00095 
00096         // [Sub_Actions_A] Menu
00097         Menu* sub_act_a_menu = manage (new Menu ());
00098         MenuList& sub_act_a_list = sub_act_a_menu->items ();
00099 
00100         sub_act_a_list.
00101             push_back (MenuElem ("Delete at selection",
00102                                  slot (*m_actions, &ActionsMenu::shift_a_up)));
00103         sub_act_a_list.
00104             push_back (MenuElem ("Insert gap at selection",
00105                                  slot (*m_actions, &ActionsMenu::shift_a_down)));
00106 
00107         // [Sub_Actions_B] Menu
00108         Menu* sub_act_b_menu = manage (new Menu ());
00109         MenuList& sub_act_b_list = sub_act_b_menu->items ();
00110 
00111         sub_act_b_list.
00112             push_back (MenuElem ("Delete at selection",
00113                                  slot (*m_actions, &ActionsMenu::shift_b_up)));
00114         sub_act_b_list.
00115             push_back (MenuElem ("Insert gap at selection",
00116                                  slot (*m_actions, &ActionsMenu::shift_b_down)));
00117 
00118         // [Actions] Menu
00119         Menu* act_menu = manage (new Menu ());
00120         MenuList& act_list = act_menu->items ();
00121 
00122         act_list.push_back (MenuElem ("Left column",  *sub_act_a_menu));
00123         act_list.push_back (MenuElem ("Right column", *sub_act_b_menu));
00124 
00125         // [Preferences] Menu
00126         Menu* pref_menu = manage (new Menu ());
00127         MenuList& pref_list = pref_menu->items ();
00128 
00129         pref_list.push_back (MenuElem ("Project",
00130                                        slot (m_mw, &MainWindow::pref_cb)));
00131         pref_list.push_back (SeparatorElem ());
00132 
00133         pref_list.push_back (CheckMenuElem ("Jump next row",
00134                              slot (*this, &TopMenuBar::jump_next_row_cb)));
00135         m_jump = static_cast<Gtk::CheckMenuItem*> (&pref_list.back ());
00136         m_jump->set_active (m_config.get_jump_next_row ());
00137 
00138         // [Help] Menu
00139         Menu* help_menu = manage (new Menu ());
00140         MenuList& help_list = help_menu->items ();
00141 
00142         help_list.push_back (MenuElem ("Help Contents",
00143                                slot (m_mw, &MainWindow::help_contents_cb)));
00144 
00145         help_list.push_back (MenuElem ("About",
00146                                        slot (m_mw, &MainWindow::about_cb)));
00147 
00148         // Assemble (backwards?)
00149         MenuList& list_bar = m_menu_bar->items ();
00150 
00151         list_bar.push_front (MenuElem ("Help", 
00152                                        Gtk::Menu::AccelKey("<control>h"), 
00153                                        *help_menu));
00154         list_bar.front ().set_right_justified ();
00155 
00156         list_bar.push_front (MenuElem ("Preferences", 
00157                                        Gtk::Menu::AccelKey("<control>p"),
00158                                        *pref_menu));
00159         list_bar.push_front (MenuElem ("Edit", 
00160                                        Gtk::Menu::AccelKey("<control>e"), 
00161                                        *act_menu));
00162         list_bar.push_front (MenuElem ("File", 
00163                                        Gtk::Menu::AccelKey("<control>f"), 
00164                                        *m_file_menu));
00165     }
00166     // And finally attach top menu bar to the MainWindow widget
00167     m_mw.set_menus (*get_menu_bar ());
00168 }
00169 
00170 void
00171 
00172 TopMenuBar::add_history ()
00173 {
00174     trace("TopMenuBar::add_history");
00175 
00176     // Add whatever file Config has open to its history list
00177     string nm = m_config.add_document_history ();
00178     if (nm.size () == 0) {
00179         return;
00180     }
00181     refill_history_list ();
00182 }
00183 
00184 void
00185 
00186 TopMenuBar::refill_history_list ()
00187 {
00188     trace("TopMenuBar::refill_history_list");
00189 
00190     // Clear the list and refill it with history elements
00191 
00192     guint position = 0;
00193     const Config::DHList& dh_list = m_config.get_document_history ();
00194     Gtk::Menu_Helpers::MenuList& file_list = m_open_recent_menu->items ();
00195     file_list.clear ();
00196 
00197     Config::DHList_CIter cit = dh_list.begin ();
00198 
00199     while (cit != dh_list.end ()) {
00200         file_list.push_back (
00201             Gtk::Menu_Helpers::MenuElem (
00202                 (*cit).c_str (),
00203                 SigC::bind<guint> (
00204                     slot (m_mw, &MainWindow::open_recent_cb), position)));
00205         position++;
00206         cit++;
00207     }
00208 }
00209 
00210 MenuBar*
00211 
00212 TopMenuBar::get_menu_bar ()
00213 {
00214     if (m_menu_bar == NULL) {
00215         DL((ASSA::ERROR, 
00216             "TopMenuBar::get_menu_bar() : m_menu_bar uninitialized!\n"));
00217         Assert_exit (false);
00218     }
00219     return m_menu_bar;
00220 }
00226 void
00227 
00228 TopMenuBar::fill_toolbar_with_doc_controls  ()
00229 {
00230     trace("TopMenuBar::fill_toolbar_with_doc_controls");
00231 
00232     vector<Gnome::UI::Items::Info> toolbar;
00233 
00234     /* In Gnomemm, all standard pixmaps are defined in
00235      *  <libgnomeuimm/app-helper.h>
00236      */
00237     {
00238         using Gnome::UI::Items::Icon;
00239         using namespace Gtk::Stock;
00240 
00241         toolbar.push_back (
00242             Gnome::UI::Items::Item (Gnome::UI::Items::Icon (OPEN), 
00243                                     "Open", 
00244                                     slot (m_mw, &MainWindow::open_cb), 
00245                                     "Open existing project"));
00246 
00247         toolbar.push_back (
00248             Gnome::UI::Items::Item (Icon (SAVE), "Save", 
00249                                     slot (m_mw, &MainWindow::save_cb), 
00250                                     "Save current project" ));
00251 
00252         toolbar.push_back (
00253             Gnome::UI::Items::Item (Icon (CLOSE), "Close", 
00254                                     slot (m_mw, &MainWindow::close_cb), 
00255                                     "Close current project"));
00256         toolbar.push_back (
00257             Gnome::UI::Items::Item (Icon (QUIT), "Exit", 
00258                                     slot (m_mw, &MainWindow::exit_cb), 
00259                                     "Exit from gwavmerger"));
00260         
00261         toolbar.push_back (Gnome::UI::Items::Separator ());
00262 
00263         toolbar.push_back (
00264             Gnome::UI::Items::Item (Icon (REFRESH), "Reload", 
00265                                     slot (m_mw, &MainWindow::reload_cb), 
00266                                     "Re-load file list"));
00267         toolbar.push_back (
00268             Gnome::UI::Items::Item (Icon (EXECUTE), "Merge", 
00269                                 slot (m_mw, &MainWindow::merge_cb),
00270                                     "Merge files"));
00271     }
00272 
00276     Gnome::UI::Items::Array<Gnome::UI::Items::Info>& 
00277         array_info = m_mw.create_toolbar (toolbar);
00278 
00279     m_b_open    = array_info [0].get_widget ();
00280     m_b_save    = array_info [1].get_widget ();
00281     m_b_save_as = array_info [2].get_widget ();
00282     m_b_exit    = array_info [3].get_widget ();
00283 
00284     m_b_reload  = array_info [5].get_widget ();
00285     m_b_exec    = array_info [6].get_widget ();
00286 }
00287 
00293 void
00294 TopMenuBar::
00295 fill_toolbar_with_play_controls (vector<Gnome::UI::Items::Info>& toolbar_)
00296 {
00297     trace("TopMenuBar::fill_toolbar_with_play_controls");
00298 
00299     {
00300         using Gnome::UI::Items::Icon;
00301         using namespace Gtk::Stock;
00302 
00303         toolbar_.push_back (Gnome::UI::Items::Item (
00304                                 Icon (STOP),"", 
00305                                 slot (m_mw, &MainWindow::stop_cb),
00306                                 "Stop playing"));
00307 
00308         toolbar_.push_back (Gnome::UI::Items::Item (
00309                                 Icon (GO_FORWARD),"",
00310                                 SigC::bind<Column> (
00311                                     slot (m_mw, &MainWindow::play_sound), 
00312                                     left_column),
00313                                 "Play left selection"));
00314 
00315         toolbar_.push_back (Gnome::UI::Items::Item (
00316                                 Icon (GO_FORWARD), "", 
00317                                 SigC::bind<Column> (
00318                                     slot (m_mw, &MainWindow::play_sound), 
00319                                     right_column),
00320                                 "Play right selection"));
00321 
00322         toolbar_.push_back (Gnome::UI::Items::Separator ());
00323 
00324         toolbar_.push_back (Gnome::UI::Items::Item (
00325                                 Icon (GO_DOWN), "", 
00326                                 slot (m_mw, &MainWindow::go_next_row_cb),
00327                                 "Step down"));
00328         
00329         toolbar_.push_back (Gnome::UI::Items::Item (
00330                                 Icon (GO_UP), "",
00331                                 slot (m_mw, &MainWindow::go_prev_row_cb),
00332                                 "Step up"));
00333     }
00334 }
00335 
00336 void
00337 TopMenuBar::
00338 set_sensitivity (WMState state_)
00339 {
00340     trace("TopMenuBar::set_sensitivity");
00341 
00342     switch (state_) 
00343     {
00344     case Start:
00345         m_new        ->set_sensitive (true ); // new
00346         m_open       ->set_sensitive (true ); // open
00347         m_open_recent->set_sensitive (true ); // open recent
00348         m_save       ->set_sensitive (false); // save
00349         m_save_as    ->set_sensitive (false); // save as
00350         m_close      ->set_sensitive (false); // close
00351         m_exit       ->set_sensitive (true ); // exit
00352 
00353         m_b_open     ->set_sensitive (true );
00354         m_b_save     ->set_sensitive (false);
00355         m_b_save_as  ->set_sensitive (false);
00356         m_b_exit     ->set_sensitive (true );
00357         m_b_reload   ->set_sensitive (false);
00358         m_b_exec     ->set_sensitive (false);
00359 
00360         break;
00361 
00362     case Dirty:
00363         m_new        ->set_sensitive (false); // new
00364         m_open       ->set_sensitive (false); // open
00365         m_open_recent->set_sensitive (false); // open recent
00366         m_save       ->set_sensitive (true ); // save
00367         m_save_as    ->set_sensitive (true ); // save as
00368         m_close      ->set_sensitive (true ); // close
00369         m_exit       ->set_sensitive (false); // exit
00370 
00371         m_b_open     ->set_sensitive (false);
00372         m_b_save     ->set_sensitive (true );
00373         m_b_save_as  ->set_sensitive (true );
00374         m_b_exit     ->set_sensitive (false);
00375         m_b_reload   ->set_sensitive (true );
00376         m_b_exec     ->set_sensitive (m_loaded);
00377 
00378         break;
00379 
00380     case Clean:
00381         m_new        ->set_sensitive (false); // new
00382         m_open       ->set_sensitive (false); // open
00383         m_open_recent->set_sensitive (false); // open recent
00384         m_save       ->set_sensitive (false); // save
00385         m_save_as    ->set_sensitive (true ); // save as
00386         m_close      ->set_sensitive (true ); // close
00387         m_exit       ->set_sensitive (true ); // exit
00388 
00389         m_b_open     ->set_sensitive (false);
00390         m_b_save     ->set_sensitive (false);
00391         m_b_save_as  ->set_sensitive (true );
00392         m_b_exit     ->set_sensitive (true );
00393         m_b_reload   ->set_sensitive (true );
00394         m_b_exec     ->set_sensitive (m_loaded);
00395 
00396         break;
00397     }
00398 }
00399 
00405 void
00406 
00407 TopMenuBar::jump_next_row_cb ()
00408 {
00409     trace("TopMenuBar::jump_next_row_cb");
00410 
00411     m_config.set_jump_next_row (m_jump->get_active ());
00412     DL((APP,"Toggle jump_next_row to %s\n",
00413         m_config.get_jump_next_row () ? "true" : "false"));
00414 }

Generated on Tue Feb 11 23:05:20 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002