lumiera_/src/gui/widgets/menu-button.hpp

177 lines
4.3 KiB
C++
Raw Normal View History

/*
menu-button.hpp - Declaration of the menu button widget
2010-12-17 23:28:49 +01:00
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
2010-12-17 23:28:49 +01:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
2010-12-17 23:28:49 +01:00
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
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.
2010-12-17 23:28:49 +01:00
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., 675 Mass Ave, Cambridge, MA 02139, USA.
2010-12-17 23:28:49 +01:00
*/
/** @file menu-button.hpp
** This file contains the definition of menu button widget
*/
#ifndef MENU_BUTTON_HPP
#define MENU_BUTTON_HPP
#include "gui/gtk-base.hpp"
#include <iostream>
using namespace Gtk;
namespace gui {
namespace widgets {
/**
* A button that display a menu when clicked on.
*/
class MenuButton : public ToggleButton
{
public:
/**
* Create an empty button.
* @remarks With an empty button, you can Button::add() a widget
* such as a Pixmap or Box. If you just wish to add a
* Label, you may want to use the
* MenuButton(cuString& label) ctor directly instead.
*/
MenuButton();
/**
* Creates a new Button containing the image and text from a stock
* item.
* @remarks Stock ids have identifiers like Stock::OK and
* Stock::APPLY.
*/
MenuButton(const StockID& stock_id);
/**
* Creates a simple Push Button with label.
* @remarks Create a button with the given label inside. You won't be
* able to add a widget in this button since it already has a
* Label in it
*/
MenuButton(cuString& label, bool mnemonic=false);
2012-08-14 09:45:13 +02:00
/* Testing Code */
void dump_xml() { /* std::cout << uimanager->get_ui() << std::endl; */ }
/**
* Gets the menu which will be displayed when the button is clicked
* on.
* @return Returns a reference to the menu that will be clicked on.
* This reference can be used to populate the menu with items.
*/
Menu& get_menu();
/**
* Append a Menu Item to the Menu
* @param slug Unique identifier in the UI Manager
* @param title The title of the item
* @param callback The signal handler when clicked
*/
void append (uString &slug, uString &title, sigc::slot<void>& callback);
/**
* Append a Menu Item to the Menu
* @param slug Unique identifier in the UI Manager
* @param title The title of the item
* @param callback The signal handler when clicked
*/
void append (const char *slug, const char* title, sigc::slot<void>& callback);
/**
* Append a Gtk::SeparatorMenuItem to the Menu
*/
void appendSeparator();
/**
* Pops up the menu.
*/
void popup();
protected:
2008-12-29 17:29:30 +01:00
/**
* An internal method which sets up the button at create time.
*/
2008-12-29 17:29:30 +01:00
void setup_button();
/**
* An event handler for when the button is pressed.
*/
void on_pressed();
/**
* An event handler for when the menu is closed.
*/
void on_menu_deactivated();
private:
/**
* A callback function used to determine the correct position for the
* popup menu.
* @param x The x-coordinate to display the menu in root window
* coordinates.
* @param y The y-coordinate to display the menu in root window
* coordinates.
* @param push_in This value is set to true if the menu should be
* pushed in if it collides with the edge of the screen.
*/
void on_menu_position(int& x, int& y, bool& push_in);
private:
2009-03-14 21:29:16 +01:00
/**
* The hBox for the layout of image, caption and arrow.
*/
HBox hBox;
2009-03-08 17:50:23 +01:00
2009-03-14 21:29:16 +01:00
/**
* The image that will optionally display an icon.
*/
Image image;
2009-03-08 17:50:23 +01:00
/**
2009-03-14 21:29:16 +01:00
* The caption text label to show on the button.
*/
Label caption;
2008-12-29 17:29:30 +01:00
/**
* The arrow widget that will be displayed to hint the user that this
* button is a drop-down.
*/
Arrow arrow;
2009-03-14 21:29:16 +01:00
/**
* The internal menu object which is the popup menu of this widget.
*/
Menu menu;
Glib::RefPtr<UIManager> uimanager;
Glib::RefPtr<ActionGroup> actions;
2009-03-14 21:29:16 +01:00
};
} // gui
} // widgets
#endif // MENU_BUTTON_HPP