Toolbars

To create an application that has a toolbar, create a normal Hildon::Window and then a normal Gtk::Toolbar. The toolbar is used as any GtkToolbar is used and it can contain normal GtkToolItems, like: The main difference compared to normal GTK+ usage is that toolbars can be common to all Windows in an application or they can be used only in a particular Hildon::Window.

The next example creates a window with a toolbar and add some toolitem.

Example

examplewindow.h
//$Id: examplewindow.h,v 1.1 2003/11/03 09:29:56 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <hildon-libsmm/window.h>
#include <gtkmm.h>

class ExampleWindow : public Hildon::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();
  
protected:
  //Signal handlers:
  virtual void on_close();

  Gtk::Toolbar toolbar;
  Gtk::ToolButton tool_close;
  Gtk::ToolButton tool_open;
  Gtk::ToolButton tool_new;
  Gtk::ToolButton tool_save;
  Gtk::SeparatorToolItem tool_separator;
  Gtk::ToolItem tool_combo;
};

#endif //GTKMM_EXAMPLEWINDOW_H

examplewindow.cc
//$Id: examplewindow.cc,v 1.5 2004/03/25 14:35:34 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include "examplewindow.h"
#include <gtkmm.h>
#include <iostream>

ExampleWindow::ExampleWindow() :
	tool_new(Gtk::Stock::NEW),
	tool_open(Gtk::Stock::OPEN),
	tool_save(Gtk::Stock::SAVE),
	tool_close(Gtk::Stock::CLOSE)
{
	/* Create Combobox on tool item */
	Gtk::ComboBoxText* combo = Gtk::manage(new Gtk::ComboBoxText);
	combo->append_text("Entry 1");
	combo->append_text("Entry 2");
	combo->append_text("Entry 3");
	combo->set_active(1);
    tool_combo.add(*combo);
    tool_combo.set_expand();
    
    /* Add toolbar items to toolbar*/
  	toolbar.append(tool_new);
  	toolbar.append(tool_separator);
  	toolbar.append(tool_open);
  	toolbar.append(tool_save);
  	toolbar.append(tool_combo);
  	toolbar.append(tool_close);
  	
    /* Add toolbar */
    add_toolbar(toolbar);
    toolbar.show_all();

    /* Attach the callback functions to the activate signal */
	tool_close.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_close) );
	
    /* Make all toolbar widgets visible */
    show_all();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_close()
{
	Gtk::Main::quit();
}


main.cc
//$Id: main.cc,v 1.1 2003/11/03 09:29:56 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <hildon-libsmm/program.h>
#include <gtkmm/main.h>

#include "examplewindow.h"

/* This is the C++ version of the example in the tutorial */

int main(int argc, char *argv[])
{
    /* Initialize the GTKmm. */
    Gtk::Main kit(&argc, &argv);

    /* Create the hildon program and setup the title */
   	Hildon::Program program;
    
	Glib::set_application_name("Hildon-Widgetsmm: Toolbar example");
	
    /* Create Window and set it to Program */
    ExampleWindow window;
	program.add_window(window);

	/* Add example label to window */
    Gtk::Label label("Hildon::Program example");
	window.add(label);

    /* Begin the main application */
	window.show_all();

    kit.run(window);
	
    /* Exit */
    return 0;

}

The documentation for the standard GTKmm toolbar handling can be found in the GTKmm tutorial.