FindToolbar

A Hildon::FindToolbar is a special toolbar for a find feature. Maemo applications may have several toolbars, which are then attached on top of each other. The find toolbar is generally placed on the top of the main toolbar, as in this example. The Hildon::FindToolbar has two interesting signals:

To integrate the Hildon::FindToolbar in your application, you have to add a button to your main toolbar which is uses to show the toolbar, like this:

/* ... */
Gtk::ToolButton tool_find = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::FIND));
main_toolbar.append(tool_find);
tool_find->signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_find_close) );
/* ... */

void ExampleWindow::on_find_close()
{
  /* Show or hide find toolbar */
  if (find_visible) {
    find_toolbar.hide();
    find_visible = FALSE;
  } 
  else {
    find_toolbar.show_all();
    find_visible = TRUE;
  }
}

Then you have to connect your search_signal to actually perform the search:

find_toolbar.signal_search().connect( sigc::mem_fun(*this, &ExampleWindow::on_search) );

/* ... */

void ExampleWindow::on_search()
{
  Glib::ustring prefix;
  find_toolbar.get_property("prefix", prefix);
  /* Search for prefix now... */
}

Here is the full example code for the FindToolbar:

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 <hildon-libsmm/find-toolbar.h>

#include <gtkmm.h>

class ExampleWindow : public Hildon::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  virtual void on_close();
  virtual void on_find_close();
  virtual void on_search();

  Gtk::Toolbar main_toolbar;
  Hildon::FindToolbar find_toolbar;
  
  Gtk::ToolButton tool_close;
  Gtk::ToolButton tool_open;
  Gtk::ToolButton tool_new;
  Gtk::ToolButton tool_save;
  Gtk::ToolButton tool_find;
  Gtk::SeparatorToolItem tool_separator;
  Gtk::ToolItem tool_combo;
  
  Gtk::Menu main;
  Gtk::Menu sub_others;
  
  Gtk::MenuItem item_others;
  Gtk::RadioMenuItem::Group group;
  Gtk::RadioMenuItem item_radio1;
  Gtk::RadioMenuItem item_radio2;
    
  Gtk::CheckMenuItem item_check;
  Gtk::CheckMenuItem item_close;
  Gtk::SeparatorMenuItem item_separator;
  
  bool find_visible;
};

#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() :
	find_toolbar("Find string: "),
	tool_new(Gtk::Stock::NEW),
	tool_open(Gtk::Stock::OPEN),
	tool_save(Gtk::Stock::SAVE),
	tool_close(Gtk::Stock::CLOSE),
	tool_find(Gtk::Stock::FIND),
	item_others("Others"),
    item_radio1(group, "Radio1"),
    item_radio2(group, "Radio2"),  
    item_check("Check"),
    item_close("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.set_expand();
    tool_combo.add(*combo);
    
    /* Add toolbar items to toolbar*/
  	main_toolbar.append(tool_new);
  	main_toolbar.append(tool_separator);
  	main_toolbar.append(tool_open);
  	main_toolbar.append(tool_save);
  	main_toolbar.append(tool_combo);
  	main_toolbar.append(tool_find);
  	main_toolbar.append(tool_close);

    /* Attach the callback functions to the activate signal */
	tool_close.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_close) );
	
	/* Attach find toolbar callbacks */
	find_toolbar.signal_close().connect( sigc::mem_fun(*this, &ExampleWindow::on_find_close) );
	find_toolbar.signal_search().connect( sigc::mem_fun(*this, &ExampleWindow::on_search) );	
	tool_find.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_find_close) );
	
	/* Attach find toolbar */
	add_toolbar(main_toolbar);
	add_toolbar(find_toolbar);
	
	 /* Add menu items to right menus */
    main.append(item_others);
   	sub_others.append(item_radio1);
    sub_others.append(item_radio2);
   	sub_others.append(item_separator);
    sub_others.append(item_check);
    main.append(item_close);

    /* Add others submenu to the "Others" item */
    item_others.set_submenu(sub_others);
    set_menu(main);

    /* Attach the callback functions to the activate signal */
	item_close.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_close) );
	
	show_all();
	find_toolbar.hide_all();
	
    find_visible = false;
}

ExampleWindow::~ExampleWindow()
{
}

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

void ExampleWindow::on_find_close()
{
	/* Show or hide find toolbar */
    if (find_visible) {
        find_toolbar.hide();
        find_visible = FALSE;
    } else {
        find_toolbar.show_all();
        find_visible = TRUE;
    }
}

void ExampleWindow::on_search()
{
	Glib::ustring prefix;
	find_toolbar.get_property("prefix", prefix);
	std::cout << "Search for: " << prefix << std::endl;
}

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("FindToolbar example");

    /* Create Window and set it to Program */
    ExampleWindow window;
	program.add_window(window);

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

    /* Begin the main application */
    kit.run(window);
	
    /* Exit */
    return 0;

}