- holt_container: added menu to select holt graph disposition
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1111 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
fe024ef461
commit
bd2999990e
|
@ -20,48 +20,158 @@
|
|||
|
||||
#include "holt_container_window.hh"
|
||||
|
||||
#include <glibmm/refptr.h>
|
||||
#include <gtkmm/action.h>
|
||||
#include <gtkmm/actiongroup.h>
|
||||
#include <gtkmm/menu.h>
|
||||
#include <gtkmm/uimanager.h>
|
||||
|
||||
|
||||
using namespace sgpem;
|
||||
using namespace Gtk;
|
||||
using namespace Glib;
|
||||
|
||||
|
||||
HoltContainerWindow::HoltContainerWindow(Simulation& simulation)
|
||||
: _holt_widget(simulation)
|
||||
{
|
||||
// This just sets the title of our new window.
|
||||
set_title(_("Holt Graph"));
|
||||
add(_holt_widget);
|
||||
_holt_widget.set_scaling_mode(CairoWidget::scaling_min);
|
||||
_holt_widget.show();
|
||||
_holt_widget.set_show_threads(true);
|
||||
//set_keep_above();
|
||||
}
|
||||
|
||||
HoltContainerWindow::~HoltContainerWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void HoltContainerWindow::on_size_request(Gtk::Requisition* /* requisition */ )
|
||||
{
|
||||
int height = get_height();
|
||||
int width = get_width();
|
||||
// if height/width >=5/3
|
||||
if(height * 3 >= width * 5)
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_vertical);
|
||||
}
|
||||
else if( width * 3 >= height * 5)
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_horizontal);
|
||||
}
|
||||
else
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_circular);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
HoltContainerWindow::HoltContainerWindow(Simulation& simulation)
|
||||
: _holt_widget(simulation), _auto_dispose(true)
|
||||
{
|
||||
// This just sets the title of our new window.
|
||||
set_title(_("Holt Graph"));
|
||||
add(_holt_widget);
|
||||
_holt_widget.set_scaling_mode(CairoWidget::scaling_min);
|
||||
_holt_widget.show();
|
||||
_holt_widget.set_show_threads(true);
|
||||
//set_keep_above();
|
||||
}
|
||||
|
||||
HoltContainerWindow::~HoltContainerWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void HoltContainerWindow::on_size_request(Gtk::Requisition* /* requisition */ )
|
||||
{
|
||||
set_disposition();
|
||||
}
|
||||
|
||||
HoltWidget& HoltContainerWindow::get_holt_widget()
|
||||
{
|
||||
return _holt_widget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool
|
||||
HoltContainerWindow::on_button_press_event(GdkEventButton* event)
|
||||
{
|
||||
if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
|
||||
{
|
||||
Glib::ustring ui_info =
|
||||
"<ui>"
|
||||
" <popup name='PopupMenu'>";
|
||||
|
||||
HoltWidget::arrange_mode arrange = _holt_widget.get_arrange_mode();
|
||||
|
||||
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
|
||||
|
||||
if(_auto_dispose || arrange!=HoltWidget::arrange_vertical)
|
||||
{
|
||||
action_group->add( Gtk::Action::create("DisposeVertical", "Dispose _Vertical"),
|
||||
sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_vertical) );
|
||||
ui_info += " <menuitem action='DisposeVertical'/>";
|
||||
}
|
||||
|
||||
if(_auto_dispose || arrange!=HoltWidget::arrange_horizontal)
|
||||
{
|
||||
action_group->add( Gtk::Action::create("DisposeHorizontal", "Dispose _Horizontal"),
|
||||
sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_horizontal) );
|
||||
ui_info += " <menuitem action='DisposeHorizontal'/>";
|
||||
}
|
||||
|
||||
if(_auto_dispose || arrange!=HoltWidget::arrange_circular)
|
||||
{
|
||||
action_group->add( Gtk::Action::create("DisposeCircular", "Dispose _Circular"),
|
||||
sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_circular) );
|
||||
ui_info += " <menuitem action='DisposeCircular'/>";
|
||||
}
|
||||
|
||||
if(!_auto_dispose)
|
||||
{
|
||||
action_group->add( Gtk::Action::create("DisposeAuto", "_Auto Dispose"),
|
||||
sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_auto) );
|
||||
ui_info += " <menuitem action='DisposeAuto'/>";
|
||||
}
|
||||
|
||||
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
|
||||
UIManager->insert_action_group(action_group);
|
||||
|
||||
ui_info +=
|
||||
" </popup>"
|
||||
"</ui>";
|
||||
|
||||
UIManager->add_ui_from_string(ui_info);
|
||||
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
|
||||
|
||||
menu->popup(event->button, event->time);
|
||||
return true; //It has been handled.
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
HoltContainerWindow::_on_dispose_vertical()
|
||||
{
|
||||
_auto_dispose = false;
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_vertical);
|
||||
_holt_widget.resize_redraw();
|
||||
}
|
||||
|
||||
void
|
||||
HoltContainerWindow::_on_dispose_circular()
|
||||
{
|
||||
_auto_dispose = false;
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_circular);
|
||||
_holt_widget.resize_redraw();
|
||||
}
|
||||
|
||||
void
|
||||
HoltContainerWindow::_on_dispose_horizontal()
|
||||
{
|
||||
_auto_dispose = false;
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_horizontal);
|
||||
_holt_widget.resize_redraw();
|
||||
}
|
||||
|
||||
void
|
||||
HoltContainerWindow::_on_dispose_auto()
|
||||
{
|
||||
_auto_dispose = true;
|
||||
set_disposition();
|
||||
_holt_widget.resize_redraw();
|
||||
}
|
||||
|
||||
void HoltContainerWindow::set_disposition()
|
||||
{
|
||||
if(_auto_dispose){
|
||||
int height = get_height();
|
||||
int width = get_width();
|
||||
// if height/width >=5/3
|
||||
if(height * 3 >= width * 5)
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_vertical);
|
||||
}
|
||||
else if( width * 3 >= height * 5)
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_horizontal);
|
||||
}
|
||||
else
|
||||
{
|
||||
_holt_widget.set_arrange_mode(HoltWidget::arrange_circular);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,21 @@ namespace sgpem {
|
|||
virtual ~HoltContainerWindow();
|
||||
|
||||
HoltWidget& get_holt_widget();
|
||||
|
||||
protected:
|
||||
virtual void on_size_request (Gtk::Requisition* requisition);
|
||||
bool on_button_press_event(GdkEventButton* event);
|
||||
|
||||
void set_disposition();
|
||||
|
||||
private:
|
||||
void _on_dispose_vertical();
|
||||
void _on_dispose_circular();
|
||||
void _on_dispose_horizontal();
|
||||
void _on_dispose_auto();
|
||||
|
||||
HoltWidget _holt_widget;
|
||||
bool _auto_dispose;
|
||||
};
|
||||
|
||||
} // ~ namespace sgpem
|
||||
|
|
Loading…
Reference in New Issue