Added custom layouts for better PanelBar overflow

This commit is contained in:
Joel Holdsworth 2009-04-16 15:44:40 +01:00
parent 5eed949e27
commit 8cd3d64679
4 changed files with 142 additions and 9 deletions

View file

@ -23,15 +23,19 @@
#include "button-bar.hpp"
#include <nobug.h>
#include <algorithm>
using namespace Gtk;
using namespace Glib;
using namespace sigc;
using namespace std;
namespace gui {
namespace widgets {
ButtonBar::ButtonBar()
{
set_flags(Gtk::NO_WINDOW);
}
void
@ -40,5 +44,64 @@ ButtonBar::append(Widget &widget)
pack_start(widget, Gtk::PACK_SHRINK);
}
void
ButtonBar::on_size_request(Gtk::Requisition* requisition)
{
REQUIRE(requisition);
requisition->width = 0;
requisition->height = 0;
Box::BoxList &list = children();
Box::BoxList::const_iterator i;
for(i = list.begin(); i != list.end(); i++)
{
Widget *widget = (*i).get_widget();
REQUIRE(widget);
Requisition child_requisition = widget->size_request();
requisition->width += child_requisition.width;
requisition->height = max(requisition->height,
child_requisition.height);
}
ENSURE(requisition->width >= 0);
ENSURE(requisition->height >= 0);
}
void
ButtonBar::on_size_allocate(Gtk::Allocation& allocation)
{
//Use the offered allocation for this container:
set_allocation(allocation);
int offset = 0;
Box::BoxList &list = children();
Box::BoxList::const_iterator i;
for(i = list.begin(); i != list.end(); i++)
{
Widget *widget = (*i).get_widget();
REQUIRE(widget);
const Requisition child_requisition = widget->size_request();
const Gtk::Allocation child_allocation(
allocation.get_x() + offset,
allocation.get_y(),
child_requisition.width,
allocation.get_height());
offset += child_requisition.width;
if(offset > allocation.get_width())
widget->set_child_visible(false);
else
{
widget->size_allocate(child_allocation);
widget->set_child_visible(true);
}
}
}
} // widgets
} // gui

View file

@ -34,7 +34,7 @@ namespace widgets {
/**
* A modified toolbar widget for use in dialogs.
**/
class ButtonBar : public Gtk::HBox
class ButtonBar : public Gtk::Box
{
public:
/**
@ -59,6 +59,23 @@ public:
button.signal_clicked().connect(clicked_slot);
append(button);
}
private:
/* ===== Overrides ===== */
/**
* An event handler that is called to offer an allocation to this
* widget.
* @param requisition The area offered for this widget.
*/
void on_size_request(Gtk::Requisition* requisition);
/**
* An event handler that is called to notify this widget to allocate
* a given area for itself.
* @param allocation The area to allocate for this widget.
*/
void on_size_allocate(Gtk::Allocation& allocation);
};
} // gui

View file

@ -39,7 +39,7 @@ namespace gui {
namespace widgets {
PanelBar::PanelBar(panels::Panel &owner_panel, const gchar *stock_id) :
HBox(),
Box(),
panel(owner_panel),
panelButton(StockID(stock_id)),
lockItem(NULL)
@ -126,20 +126,66 @@ PanelBar::on_realize()
unset_bg(STATE_NORMAL);
}
void
PanelBar::on_size_request(Gtk::Requisition* requisition)
{
REQUIRE(requisition);
requisition->width = 0;
requisition->height = 0;
Box::BoxList &list = children();
Box::BoxList::const_iterator i;
for(i = list.begin(); i != list.end(); i++)
{
Widget *widget = (*i).get_widget();
REQUIRE(widget);
Requisition child_requisition = widget->size_request();
requisition->width += child_requisition.width;
requisition->height = max(requisition->height,
child_requisition.height);
}
ENSURE(requisition->width >= 0);
ENSURE(requisition->height >= 0);
}
void
PanelBar::on_size_allocate(Gtk::Allocation& allocation)
{
// Use the offered allocation for this container
set_allocation(allocation);
// Lay out the child widgets
int offset = 0;
Box::BoxList &list = children();
Box::BoxList::const_iterator i;
for(i = list.begin(); i != list.end(); i++)
{
Widget *widget = (*i).get_widget();
REQUIRE(widget);
const Requisition child_requisition = widget->size_request();
const Gtk::Allocation child_allocation(
offset, 0,
min(child_requisition.width, allocation.get_width() - offset),
allocation.get_height());
offset += child_requisition.width;
widget->size_allocate(child_allocation);
}
// Resize the window
int width = allocation.get_width();
if(window)
{
const Requisition requisition(get_requisition());
const int width = max(min(requisition.width,
allocation.get_width()), 0);
width = max(min(allocation.get_width(), offset), 0);
window->move_resize(allocation.get_x(), allocation.get_y(),
width, allocation.get_height());
}
allocation.set_x(0);
HBox::on_size_allocate(allocation);
}
void

View file

@ -40,7 +40,7 @@ namespace widgets {
/**
* A container widget for widgets to be displayed on GDL panels grips.
**/
class PanelBar : public Gtk::HBox
class PanelBar : public Gtk::Box
{
public:
@ -66,6 +66,13 @@ private:
**/
void on_realize();
/**
* An event handler that is called to offer an allocation to this
* widget.
* @param requisition The area offered for this widget.
*/
void on_size_request(Gtk::Requisition* requisition);
/**
* An override to intercept size allocate events.
**/