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

100 lines
2.2 KiB
C++
Raw Normal View History

/*
timeline-widget.cpp - Implementation of the menu button widget
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
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.
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.
* *****************************************************/
#include "menu-button.hpp"
#include <nobug.h>
using namespace Gtk;
using namespace sigc;
namespace gui {
namespace widgets {
2008-12-29 17:29:30 +01:00
const ArrowType arrowType = ARROW_DOWN;
const ShadowType shadowType = SHADOW_NONE;
MenuButton::MenuButton() :
2008-12-29 17:29:30 +01:00
Button(),
arrow(arrowType, shadowType)
{
setup_button();
}
2008-12-29 17:29:30 +01:00
MenuButton::MenuButton(const Gtk::StockID& stock_id) :
Button(stock_id),
arrow(arrowType, shadowType)
{
setup_button();
}
2008-12-29 17:29:30 +01:00
MenuButton::MenuButton(const Glib::ustring& label, bool mnemonic) :
Button(label, mnemonic),
arrow(arrowType, shadowType)
{
setup_button();
}
Gtk::Menu&
MenuButton::get_menu()
{
return menu;
}
void
2008-12-29 17:29:30 +01:00
MenuButton::popup()
{
2008-12-29 17:29:30 +01:00
menu.popup( mem_fun(this, &MenuButton::on_menu_position),
0, gtk_get_current_event_time());
}
void
2008-12-29 17:29:30 +01:00
MenuButton::setup_button()
{
2008-12-29 17:29:30 +01:00
arrow.set(ARROW_DOWN, SHADOW_NONE);
set_image_position(POS_RIGHT);
set_image(arrow);
}
void
MenuButton::on_pressed()
{
popup();
}
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