2008-06-05 21:27:53 +02:00
|
|
|
/*
|
|
|
|
|
header-container.cpp - Implementation of the header container 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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
2008-06-07 14:53:17 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
2008-06-05 21:27:53 +02:00
|
|
|
#include "header-container.hpp"
|
|
|
|
|
#include "track.hpp"
|
|
|
|
|
#include "../timeline-widget.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace lumiera {
|
|
|
|
|
namespace gui {
|
|
|
|
|
namespace widgets {
|
|
|
|
|
namespace timeline {
|
|
|
|
|
|
|
|
|
|
HeaderContainer::HeaderContainer(lumiera::gui::widgets::TimelineWidget *timeline_widget) :
|
2008-10-18 00:36:37 +02:00
|
|
|
Glib::ObjectBase("HeaderContainer"),
|
|
|
|
|
timelineWidget(timeline_widget),
|
|
|
|
|
margin(-1)
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
|
|
|
|
REQUIRE(timeline_widget != NULL);
|
|
|
|
|
|
2008-08-04 17:39:36 +02:00
|
|
|
// This widget will not have a window at first
|
|
|
|
|
set_flags(Gtk::NO_WINDOW);
|
|
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
set_redraw_on_allocate(false);
|
2008-06-07 14:53:17 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
// Connect to the timeline widget's vertical scroll event,
|
|
|
|
|
// so that we get notified when the view shifts
|
|
|
|
|
timelineWidget->verticalAdjustment.signal_value_changed().connect(
|
|
|
|
|
sigc::mem_fun(this, &HeaderContainer::on_scroll) );
|
2008-10-18 00:36:37 +02:00
|
|
|
|
|
|
|
|
// Install style properties
|
|
|
|
|
register_styles();
|
2008-06-23 22:21:29 +02:00
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::update_headers()
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
2008-10-18 00:36:37 +02:00
|
|
|
REQUIRE(timelineWidget != NULL);
|
|
|
|
|
|
|
|
|
|
// Remove any pre-exisitng headers
|
|
|
|
|
BOOST_FOREACH( RootHeader header, rootHeaders )
|
|
|
|
|
{
|
|
|
|
|
header.widget->unparent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rootHeaders.clear();
|
2008-06-23 22:21:29 +02:00
|
|
|
|
2008-10-18 00:36:37 +02:00
|
|
|
// Add fresh headers
|
2008-06-23 22:21:29 +02:00
|
|
|
BOOST_FOREACH( Track* track, timelineWidget->tracks )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(track != NULL);
|
2008-10-18 00:36:37 +02:00
|
|
|
|
|
|
|
|
const RootHeader header = { &track->get_header_widget(), track };
|
|
|
|
|
header.widget->set_parent(*this);
|
|
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
rootHeaders.push_back(header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layout_headers();
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::on_realize()
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
|
|
|
|
set_flags(Gtk::NO_WINDOW);
|
|
|
|
|
|
|
|
|
|
// Call base class:
|
2008-10-18 00:36:37 +02:00
|
|
|
Gtk::Container::on_realize();
|
|
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
// Create the GdkWindow:
|
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
memset(&attributes, 0, sizeof(attributes));
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
Allocation allocation = get_allocation();
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
// Set initial position and size of the Gdk::Window:
|
|
|
|
|
attributes.x = allocation.get_x();
|
|
|
|
|
attributes.y = allocation.get_y();
|
|
|
|
|
attributes.width = allocation.get_width();
|
|
|
|
|
attributes.height = allocation.get_height();
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
gdkWindow = Gdk::Window::create(get_window(), &attributes,
|
|
|
|
|
GDK_WA_X | GDK_WA_Y);
|
|
|
|
|
unset_flags(Gtk::NO_WINDOW);
|
|
|
|
|
set_window(gdkWindow);
|
|
|
|
|
|
|
|
|
|
// Unset the background so as to make the colour match the parent window
|
|
|
|
|
unset_bg(STATE_NORMAL);
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
// Make the widget receive expose events
|
|
|
|
|
gdkWindow->set_user_data(gobj());
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::on_unrealize()
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
|
|
|
|
// Unreference any window we may have created
|
|
|
|
|
gdkWindow.clear();
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
// Call base class:
|
|
|
|
|
Gtk::Widget::on_unrealize();
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::on_size_request (Requisition* requisition)
|
2008-10-18 00:36:37 +02:00
|
|
|
{
|
2008-06-23 22:21:29 +02:00
|
|
|
// Initialize the output parameter:
|
|
|
|
|
*requisition = Gtk::Requisition();
|
2008-10-18 00:36:37 +02:00
|
|
|
|
|
|
|
|
// We don't care about the size of all the child widgets, but if we
|
|
|
|
|
// don't send the size request down the tree, some widgets fail to
|
|
|
|
|
// calculate their text layout correctly.
|
|
|
|
|
BOOST_FOREACH( RootHeader header, rootHeaders )
|
|
|
|
|
{
|
|
|
|
|
if(header.widget != NULL && header.widget->is_visible())
|
|
|
|
|
header.widget->size_request();
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-06-23 22:21:29 +02:00
|
|
|
requisition->width = TimelineWidget::HeaderWidth;
|
|
|
|
|
requisition->height = 0;
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::on_size_allocate (Allocation& allocation)
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
|
|
|
|
// Use the offered allocation for this container:
|
|
|
|
|
set_allocation(allocation);
|
|
|
|
|
|
|
|
|
|
// Resize the widget's window
|
|
|
|
|
if(gdkWindow)
|
|
|
|
|
gdkWindow->resize(allocation.get_width(), allocation.get_height());
|
|
|
|
|
|
|
|
|
|
// Relayout the child widgets of the headers
|
|
|
|
|
layout_headers();
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::forall_vfunc(gboolean /* include_internals */,
|
|
|
|
|
GtkCallback callback, gpointer callback_data)
|
2008-10-18 00:36:37 +02:00
|
|
|
{
|
2008-06-23 22:21:29 +02:00
|
|
|
BOOST_FOREACH( RootHeader &header, rootHeaders )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(header.widget);
|
|
|
|
|
callback(header.widget->gobj(), callback_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-10-18 00:36:37 +02:00
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
HeaderContainer::on_expose_event(GdkEventExpose *event)
|
|
|
|
|
{
|
|
|
|
|
if(gdkWindow)
|
|
|
|
|
{
|
|
|
|
|
int offset = 0;
|
|
|
|
|
const int y_scroll_offset = timelineWidget->get_y_scroll_offset();
|
|
|
|
|
|
|
|
|
|
Glib::RefPtr<Style> style = get_style();
|
|
|
|
|
const Allocation container_allocation = get_allocation();
|
|
|
|
|
|
|
|
|
|
read_styles();
|
|
|
|
|
|
|
|
|
|
// Paint a border underneath all the root headers
|
|
|
|
|
BOOST_FOREACH( RootHeader &header, rootHeaders )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(header.widget);
|
|
|
|
|
ASSERT(header.track != NULL);
|
|
|
|
|
|
|
|
|
|
const int height = header.track->get_height();
|
|
|
|
|
ASSERT(height >= 0);
|
|
|
|
|
|
|
|
|
|
style->paint_box(
|
|
|
|
|
gdkWindow, STATE_NORMAL, SHADOW_OUT,
|
|
|
|
|
Gdk::Rectangle(
|
|
|
|
|
0, 0,
|
|
|
|
|
container_allocation.get_width(),
|
|
|
|
|
container_allocation.get_height()),
|
|
|
|
|
*this, "", 0, offset - y_scroll_offset,
|
|
|
|
|
container_allocation.get_width(), height);
|
|
|
|
|
|
|
|
|
|
offset += height + TimelineWidget::TrackPadding;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container::on_expose_event(event);
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::on_scroll()
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
|
|
|
|
// If the scroll has changed, we will have to shift all the
|
|
|
|
|
// header widgets
|
|
|
|
|
layout_headers();
|
|
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::layout_headers()
|
2008-06-23 22:21:29 +02:00
|
|
|
{
|
2008-10-18 00:36:37 +02:00
|
|
|
ASSERT(timelineWidget != NULL);
|
|
|
|
|
|
|
|
|
|
// We can't layout before the widget has been set up
|
|
|
|
|
if(!gdkWindow)
|
|
|
|
|
return;
|
2008-06-23 22:21:29 +02:00
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
|
const int y_scroll_offset = timelineWidget->get_y_scroll_offset();
|
2008-06-05 21:27:53 +02:00
|
|
|
|
2008-10-18 00:36:37 +02:00
|
|
|
read_styles();
|
|
|
|
|
|
|
|
|
|
const Allocation container_allocation = get_allocation();
|
|
|
|
|
const int header_width = container_allocation.get_width ()
|
|
|
|
|
- margin * 2;
|
2008-06-23 22:21:29 +02:00
|
|
|
|
|
|
|
|
BOOST_FOREACH( RootHeader &header, rootHeaders )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(header.widget);
|
|
|
|
|
ASSERT(header.track != NULL);
|
|
|
|
|
|
|
|
|
|
const int height = header.track->get_height();
|
|
|
|
|
ASSERT(height >= 0);
|
|
|
|
|
|
|
|
|
|
Gtk::Allocation header_allocation;
|
2008-10-18 00:36:37 +02:00
|
|
|
header_allocation.set_x (margin);
|
|
|
|
|
header_allocation.set_y (offset - y_scroll_offset + margin);
|
|
|
|
|
header_allocation.set_width (header_width);
|
|
|
|
|
header_allocation.set_height (height - margin * 2);
|
|
|
|
|
|
|
|
|
|
if(header.widget->is_visible())
|
|
|
|
|
header.widget->size_allocate (header_allocation);
|
2008-06-23 22:21:29 +02:00
|
|
|
|
|
|
|
|
offset += height + TimelineWidget::TrackPadding;
|
|
|
|
|
}
|
2008-10-18 00:36:37 +02:00
|
|
|
|
|
|
|
|
// Repaint the background of our parenting
|
|
|
|
|
queue_draw ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::register_styles() const
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass *klass = GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj()));
|
|
|
|
|
|
|
|
|
|
gtk_widget_class_install_style_property(klass,
|
|
|
|
|
g_param_spec_int("heading_margin",
|
|
|
|
|
"Heading Margin",
|
|
|
|
|
"The amount of padding around each header pixels.",
|
|
|
|
|
0, G_MAXINT, 4, G_PARAM_READABLE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
HeaderContainer::read_styles()
|
|
|
|
|
{
|
|
|
|
|
if(margin <= 0)
|
|
|
|
|
get_style_property("heading_margin", margin);
|
2008-06-23 22:21:29 +02:00
|
|
|
}
|
2008-06-05 21:27:53 +02:00
|
|
|
|
|
|
|
|
} // namespace timeline
|
|
|
|
|
} // namespace widgets
|
|
|
|
|
} // namespace gui
|
|
|
|
|
} // namespace lumiera
|