FindToolbar

A Hildon::FindToolbar is a special toolbar that offers a search feature. Maemo applications may have several toolbars, which are then attached above each other. The find toolbar is generally placed on the top of the main toolbar, as in the example below.

Reference

The Hildon::FindToolbar has two interesting signals:

To integrate the Hildon::FindToolbar in your application, you must add a button to your main toolbar which is used 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->show();
tool_find->signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_find_close) );
// ...

void ExampleWindow::on_find_close()
{
  // Show or hide find toolbar
  if (m_find_visible) {
    m_find_toolbar.hide();
    m_find_visible = false;
  } 
  else {
    m_find_toolbar.show_all();
    m_find_visible = true;
  }
}

Then you must connect a signal handler for the 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...
}

Example

Here is the full example code for the FindToolbar:

Figure 4.20. FindToolbar

FindToolbar

Source Code

File: examplewindow.h

#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H

#include <hildonmm/window.h>
#include <hildonmm/find-toolbar.h>
#include <gtkmm.h>

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

private:
  // Signal handlers:
  void on_item_close();
  void on_find_toolbar_close();
  void on_find_toolbar_search();

  // Child widgets:
  Gtk::Toolbar main_toolbar_;
  Hildon::FindToolbar find_toolbar_;
  
  Gtk::ToolButton tool_new_;
  Gtk::ToolButton tool_open_;
  Gtk::ToolButton tool_save_;
  Gtk::ToolButton tool_close_;
  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_;
  
  // Member variables:
  bool find_visible_;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

File: main.cc

#include <hildonmm.h>
#include "examplewindow.h"

int main(int argc, char *argv[])
{
  // Initialize gtkmm: 
  Gtk::Main kit(&argc, &argv);
  Hildon::init();

  // Create Window and set it to Program
  ExampleWindow window;
  Hildon::Program::get_instance()->add_window(window);
  
  // Add example label to window
  Gtk::Label label("Hildon::FindToolbar example");
  window.add(label);
  label.show();
  
  // Begin the main application
  kit.run(window);

  return 0;
}

File: examplewindow.cc

#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")
{
  set_title("Hildon::FindToolbar Example");
  // 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_);
  main_toolbar_.show_all();
  
  // Attach the callback functions to the activate signal.
  tool_close_.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_item_close));
  
  // Attach find toolbar callbacks.
  find_toolbar_.signal_close().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_find_toolbar_close));
  find_toolbar_.signal_search().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_find_toolbar_search));	
  tool_find_.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_find_toolbar_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_);
  main_.show_all(); // Show the menu and all its child widgets.
  set_main_menu(main_);

  // Attach the callback functions to the activate signal.
  item_close_.signal_activate().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_item_close));
  
  show_all_children();
  find_toolbar_.hide();
  
  find_visible_ = false;
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_item_close()
{
  hide();
}

void ExampleWindow::on_find_toolbar_close()
{
  // Show or hide find toolbar.
  if(find_visible_)
  {
    find_toolbar_.hide();
    find_visible_ = false;
  }
  else
  {
    find_toolbar_.show();
    find_visible_ = true;
  }
}

void ExampleWindow::on_find_toolbar_search()
{
  // TODO: This code does not work.
  Glib::ustring prefix;
  find_toolbar_.get_property("prefix", prefix);
  std::cout << "Search for: " << prefix << std::endl;
}