2008-12-26 19:10:28 +01:00
|
|
|
/*
|
2009-02-04 20:08:51 +01:00
|
|
|
menu-button.cpp - Implementation of the menu button widget
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2008-12-26 19:10:28 +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.
|
|
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
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
|
|
|
|
2008-12-26 19:10:28 +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
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 07:02:48 +02:00
|
|
|
#include "gui/widgets/menu-button.hpp"
|
|
|
|
|
#include "include/logging.h"
|
|
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
|
using namespace sigc;
|
|
|
|
|
|
2009-03-08 17:50:23 +01:00
|
|
|
const int CaptionPadding = 4;
|
|
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
namespace gui {
|
|
|
|
|
namespace widgets {
|
|
|
|
|
|
2008-12-29 17:29:30 +01:00
|
|
|
const ArrowType arrowType = ARROW_DOWN;
|
|
|
|
|
const ShadowType shadowType = SHADOW_NONE;
|
|
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
MenuButton::MenuButton() :
|
2009-04-07 00:04:33 +02:00
|
|
|
ToggleButton(),
|
2008-12-29 17:29:30 +01:00
|
|
|
arrow(arrowType, shadowType)
|
|
|
|
|
{
|
|
|
|
|
setup_button();
|
|
|
|
|
}
|
2008-12-26 19:10:28 +01:00
|
|
|
|
2009-03-08 17:50:23 +01:00
|
|
|
MenuButton::MenuButton(const StockID& stock_id) :
|
2009-04-07 00:04:33 +02:00
|
|
|
ToggleButton(),
|
2009-03-08 17:50:23 +01:00
|
|
|
image(stock_id, ICON_SIZE_MENU),
|
|
|
|
|
caption(),
|
2008-12-29 17:29:30 +01:00
|
|
|
arrow(arrowType, shadowType)
|
|
|
|
|
{
|
2009-03-08 17:50:23 +01:00
|
|
|
StockItem stock_item;
|
|
|
|
|
REQUIRE(StockItem::lookup(stock_id, stock_item));
|
|
|
|
|
caption.set_text_with_mnemonic(stock_item.get_label());
|
|
|
|
|
|
|
|
|
|
hBox.pack_start(image);
|
|
|
|
|
|
2008-12-29 17:29:30 +01:00
|
|
|
setup_button();
|
|
|
|
|
}
|
2008-12-26 19:10:28 +01:00
|
|
|
|
2011-02-07 00:54:44 +01:00
|
|
|
MenuButton::MenuButton(cuString& label, bool mnemonic) :
|
2009-04-07 00:04:33 +02:00
|
|
|
ToggleButton(),
|
|
|
|
|
caption(label, mnemonic),
|
2008-12-29 17:29:30 +01:00
|
|
|
arrow(arrowType, shadowType)
|
|
|
|
|
{
|
|
|
|
|
setup_button();
|
|
|
|
|
}
|
2008-12-26 19:10:28 +01:00
|
|
|
|
|
|
|
|
Gtk::Menu&
|
|
|
|
|
MenuButton::get_menu()
|
|
|
|
|
{
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-12-29 17:29:30 +01:00
|
|
|
MenuButton::popup()
|
2008-12-26 19:10:28 +01:00
|
|
|
{
|
2008-12-29 17:29:30 +01:00
|
|
|
menu.popup( mem_fun(this, &MenuButton::on_menu_position),
|
|
|
|
|
0, gtk_get_current_event_time());
|
2009-04-07 00:04:33 +02:00
|
|
|
set_active();
|
2008-12-26 19:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-12-29 17:29:30 +01:00
|
|
|
MenuButton::setup_button()
|
2008-12-26 19:10:28 +01:00
|
|
|
{
|
2009-04-07 00:04:33 +02:00
|
|
|
menu.signal_deactivate().connect(mem_fun(
|
|
|
|
|
this, &MenuButton::on_menu_deactivated));
|
|
|
|
|
|
2008-12-29 17:29:30 +01:00
|
|
|
arrow.set(ARROW_DOWN, SHADOW_NONE);
|
2009-03-08 17:50:23 +01:00
|
|
|
|
|
|
|
|
hBox.pack_start(caption, PACK_EXPAND_WIDGET, CaptionPadding);
|
|
|
|
|
hBox.pack_start(arrow);
|
|
|
|
|
|
|
|
|
|
add(hBox);
|
|
|
|
|
show_all();
|
2008-12-29 17:29:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MenuButton::on_pressed()
|
|
|
|
|
{
|
|
|
|
|
popup();
|
2008-12-26 19:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-07 00:04:33 +02:00
|
|
|
void
|
|
|
|
|
MenuButton::on_menu_deactivated()
|
|
|
|
|
{
|
|
|
|
|
set_active(false);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 19:10:28 +01:00
|
|
|
void
|
|
|
|
|
MenuButton::on_menu_position(int& x, int& y, bool& push_in)
|
|
|
|
|
{
|
|
|
|
|
Glib::RefPtr<Gdk::Window> window = get_window();
|
|
|
|
|
REQUIRE(window);
|
|
|
|
|
|
|
|
|
|
window->get_origin(x, y);
|
|
|
|
|
const Allocation allocation = get_allocation();
|
|
|
|
|
x += allocation.get_x();
|
|
|
|
|
y += allocation.get_y() + allocation.get_height();
|
|
|
|
|
|
|
|
|
|
push_in = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // widgets
|
|
|
|
|
} // gui
|