## Contents

- Introduction
- Menus
- Toolbar
- Summary

## Introduction

> Apps derived from Bakery::App_GnomeUI or Bakery::App_WithDoc_GnomeUI already have standard menus and a toolbar, but you will need your own menu and toolbar items. You can override parts of the menu and toolbar creation in your own App, but Bakery is designed so that you can do this without having to re-implement too much of the standard code.

> The actual menu and toolbar creation is done using regular gtkmm or gnomemm code, but Bakery makes it easier by splitting it up into useful chunks and implementing signal handlers for the standard menus.

## Menus

> ### Adding menus

> By overriding App::init_menus() you can add extra menus to the m_menu_UI_Infos member variable. For instance,

> >     void App_Glom::init_menus()
> >     {
> >       init_menus_file();
> >       init_menus_edit();

> >       type_vecGnome_UI_Info menu_mode, menu_navigate;

> >       //Non-stock menus:
> >       menu_navigate.push_back( Gnome::UI::Item(_("_Database"), slot(&m_Frame, &Frame_Glom::on_menu_Navigate_Database), _("Choose database")) );
> >       menu_navigate.push_back( Gnome::UI::Item(_("_Table"), slot(&m_Frame, &Frame_Glom::on_menu_Navigate_Table), _("Choose table")) );

> >       menu_mode.push_back( Gnome::UI::Item(_("_Design"), slot(&m_Frame, &Frame_Glom::on_menu_Mode_Design), _("Definitions, Forms")) );
> >       menu_mode.push_back( Gnome::UI::Item(_("D_ata"), slot(&m_Frame, &Frame_Glom::on_menu_Mode_Data), _("List, Details")) );
> >       menu_mode.push_back( Gnome::UI::Item(_("_Find"), slot(&m_Frame, &Frame_Glom::on_menu_Mode_Find), _("Search in fields")) );
> >       //menu_mode.push_back( Gnome::UI::Item(_("_Users"), slot(&m_Frame, &Frame_Glom::on_menu_Mode_Users), _("Access Control")) );

> >       //Non-stock menus:
> >       m_menu_UI_Infos.push_back( Gnome::UI::Menu(_("_Navigate"), menu_navigate) );
> >       m_menu_UI_Infos.push_back( Gnome::UI::Menu(_("_Mode"), menu_mode) );

> >       init_menus_help();

> >       create_menus(m_menu_UI_Infos);
> >       install_menu_hints();
> >     }

> This adds the custom 'Navigate' and 'Mode' menus between the standard Edit and Help menus.

> ### Changing standard menus

> To change the standard menus, you could override init_menus_file(), init_menus_edit(), or init_menus_help(). Just look at the current implementation and use similar code. init_menus() will call your own version of these methods to build those parts of the application's menu.

> For instance, this is the default App::init_menus_file() implementation.

> >     void App::init_menus_file()
> >     {
> >       // File menu
> >       type_vecGnome_UI_Info menu_file;

> >       //Build menu:
> >       menu_file.push_back(Gnome::MenuItems::New(_("New Instance"), _("Create a new instance"), slot(this, &App::on_menu_File_New)));
> >       menu_file.push_back(Gnome::MenuItems::Close(slot(this, &App::on_menu_file_close)));
> >       menu_file.push_back(Gnome::MenuItems::Exit(slot(this, &App::on_menu_file_exit)));

> >       //Add menu:
> >       m_menu_UI_Infos.push_back(Gnome::Menus::File(menu_file));
> >     }

> And this is the App_WithDocs::init_menus_file() override:

> >     void App_WithDoc::init_menus_file()
> >     {
> >       // File menu
> >       type_vecGnome_UI_Info menu_file;

> >       //Build menu:
> >       menu_file.push_back(Gnome::MenuItems::New(_("New Document"), _("Create a new document"), slot(this, &App_WithDoc::on_menu_file_new)));
> >       menu_file.push_back(Gnome::MenuItems::Open(slot(this, &App_WithDoc::on_menu_file_open)));
> >       menu_file.push_back(Gnome::MenuItems::Save(slot(this, &App_WithDoc::on_menu_file_save)));
> >       menu_file.push_back(Gnome::MenuItems::SaveAs(slot(this, &App_WithDoc::on_menu_file_saveas)));
> >       menu_file.push_back(Gnome::UI::Separator());
> >       menu_file.push_back(Gnome::MenuItems::Close(slot(this, &App_WithDoc::on_menu_file_close)));
> >       menu_file.push_back(Gnome::MenuItems::Exit(slot(this, &App_WithDoc::on_menu_file_exit)));

> >       //Add menu:
> >       m_menu_UI_Infos.push_back(Gnome::Menus::File(menu_file));
> >     }

> ### Menu handlers

> You will notice that they the init_menus_*() methods connect the menu items to signal handlers such as on_menu_file_open(), so you can just override these virtual methods instead of specifying a different signal handler. Otherwise you would also have to reimplement all the other menu code that you didn't want to change.

## Toolbar

> By overriding App::init_toolbar() you can add extra toolbar items. This is similar to the menu creation code.

> For instance, this is the standard App::init_toolbar() implementation:

> >     void App::init_toolbars()
> >     {
> >       using namespace Gnome::UI;
> >       m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_NEW),
> >         N_("New "),
> >         slot(this, &App::on_menu_File_New),
> >         N_("Create a new " + m_strAppName)) );

> >       create_toolbar(m_toolbar_UI_Infos);
> >     }

> And this is the App_WithDoc::init_toolbar() override, which adds Open and Save items:

> >     void App_WithDoc::init_toolbars()
> >     {
> >       using namespace Gnome::UI;
> >       m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_NEW),
> >         N_("New "),
> >         slot(this, &App_WithDoc::on_menu_file_new),
> >         N_("Create a new " + m_strAppName)) );

> >       m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_OPEN),
> >         N_("Open "),
> >         slot(this, &App_WithDoc::on_menu_file_open),
> >         N_("Open a " + m_strAppName)) );

> >       m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_SAVE),
> >         N_("Save "),
> >         slot(this, &App_WithDoc::on_menu_file_save),
> >         N_("Save this " + m_strAppName)));

> >       create_toolbar(m_toolbar_UI_Infos);
> >     }

## Summary

> This isn't a perfect system, but it seems like a good way to provide commonly-used functionality while also allowing you to easily customize individual parts of the interface.

Copyright © 2001-2003, Murray Cumming. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.