Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-release > by-pkgid > 67749e1d53ab4919a475df6bdefe75d1 > files > 38

lib64bakery2.6-devel-2.6.3-2mdv2010.0.x86_64.rpm

<html><head><!--This file created 8/1/98 1:41 pm by Claris Home Page version 3.0 30 Day Trial-->

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="description" content="Bakery Menus and Toolbars"><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><meta name="keywords" content="Bakery, Menus, Toolbars, C++, GnomeUIInfo UI::Info"><meta name="ProgId" content="FrontPage.Editor.Document"><title>Bakery Menus and Toolbars</title><style type="text/css"><!--a.menu {color:000000;}a.menu:hover {color:cc0000;}--></style></head>





<body bgcolor="#ffffff"><x-claris-window top="65" bottom="479" left="35" right="565">

<h2>Contents</h2>



<ul>

  <li><a href="#Introduction">Introduction</a></li>

  <li><a href="#Menus">Menus</a></li>

  <li><a href="#Toolbar">Toolbar</a></li> 

  <li><a href="#Summary">Summary</a></li> 

</ul> 

 

<h2><a name="Introduction"></a>Introduction</h2> 

 

<blockquote> 

 

<p>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.</p>



<p>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.</p>
</blockquote> 

 
<h2><a name="Menus"></a>Menus</h2>                

              
<blockquote>
  <h3>Adding menus</h3>                

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

            
  <blockquote>
    <pre>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(&amp;m_Frame, &amp;Frame_Glom::on_menu_Navigate_Database), _("Choose database")) );
  menu_navigate.push_back( Gnome::UI::Item(_("_Table"), slot(&amp;m_Frame, &amp;Frame_Glom::on_menu_Navigate_Table), _("Choose table")) );

  menu_mode.push_back( Gnome::UI::Item(_("_Design"), slot(&amp;m_Frame, &amp;Frame_Glom::on_menu_Mode_Design), _("Definitions, Forms")) );
  menu_mode.push_back( Gnome::UI::Item(_("D_ata"), slot(&amp;m_Frame, &amp;Frame_Glom::on_menu_Mode_Data), _("List, Details")) );
  menu_mode.push_back( Gnome::UI::Item(_("_Find"), slot(&amp;m_Frame, &amp;Frame_Glom::on_menu_Mode_Find), _("Search in fields")) );
  //menu_mode.push_back( Gnome::UI::Item(_("_Users"), slot(&amp;m_Frame, &amp;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();
}</pre>             

             

  </blockquote>
  <p>This adds the custom 'Navigate' and 'Mode' menus between the standard Edit 
  and Help menus.</p>             

             

  <h3>Changing standard menus</h3>             

             

  <p>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.</p>             

             

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

             

  <blockquote>
    <pre>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, &amp;App::on_menu_File_New)));
  menu_file.push_back(Gnome::MenuItems::Close(slot(this, &amp;App::on_menu_file_close)));
  menu_file.push_back(Gnome::MenuItems::Exit(slot(this, &amp;App::on_menu_file_exit)));

  //Add menu:
  m_menu_UI_Infos.push_back(Gnome::Menus::File(menu_file));
}</pre>
  </blockquote>
  <p>And this is the App_WithDocs::init_menus_file() override:</p>             

             

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

  //Add menu:
  m_menu_UI_Infos.push_back(Gnome::Menus::File(menu_file));
}</pre>
  </blockquote>
  <h3>Menu handlers</h3>             

             

  <p>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.</p>             

             

</blockquote>

  <h2><a name="Toolbar"></a>Toolbar</h2>             

             

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

             

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

             

  <blockquote>
    <pre>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, &amp;App::on_menu_File_New), 
    N_("Create a new " + m_strAppName)) );

  create_toolbar(m_toolbar_UI_Infos);
}</pre>
  </blockquote>
  <p>And this is the App_WithDoc::init_toolbar() override, which adds Open and 
  Save items:</p>             

             

  <blockquote>
    <pre>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, &amp;App_WithDoc::on_menu_file_new),
    N_("Create a new " + m_strAppName)) );</pre>
    <pre>  m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_OPEN),
    N_("Open "),
    slot(this, &amp;App_WithDoc::on_menu_file_open),
    N_("Open a " + m_strAppName)) );</pre>
    <pre>  m_toolbar_UI_Infos.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_SAVE),
    N_("Save "),
    slot(this, &amp;App_WithDoc::on_menu_file_save),
    N_("Save this " + m_strAppName)));

  create_toolbar(m_toolbar_UI_Infos);
}</pre>
  </blockquote>
</blockquote>

  <h2><a name="Summary"></a>Summary</h2>             

             

<blockquote>
  <p>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. </p>              

             

</blockquote>

                 

<p align="center"><font size="1">Copyright © 2001-2003, Murray Cumming. Verbatim         

copying and distribution of this entire article is permitted in any medium,         

provided this notice is preserved.</font></p>        

                

</body></html>