/* timeline-header-widget.cpp - Implementation of the timeline header widget Copyright (C) Lumiera.org 2008, Joel Holdsworth 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 #include "gui/widgets/timeline-widget.hpp" #include "gui/util/rectangle.hpp" using namespace Gtk; using namespace std; using namespace boost; using namespace util; namespace gui { namespace widgets { namespace timeline { TimelineHeaderWidget::TimelineHeaderWidget( timeline::Track &timeline_track) : Glib::ObjectBase("TimelineHeaderWidget"), track(timeline_track), widget(NULL), hoveringExpander(false), clickedExpander(false), margin(-1), expand_button_size(12) { set_flags(Gtk::NO_WINDOW); set_redraw_on_allocate(false); // Install style properties register_styles(); // Load the styles up read_styles(); } void TimelineHeaderWidget::on_realize() { set_flags(Gtk::NO_WINDOW); Container::on_realize(); // Create the GdkWindow: GdkWindowAttr attributes; memset(&attributes, 0, sizeof(attributes)); Allocation allocation = get_allocation(); // 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(); attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK; attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_OUTPUT; 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); // Make the widget receive expose events gdkWindow->set_user_data(gobj()); } void TimelineHeaderWidget::on_unrealize() { // Unreference any window we may have created gdkWindow.clear(); // Call base class: Container::on_unrealize(); } void TimelineHeaderWidget::set_child_widget(Widget& child) { widget = &child; widget->set_parent(*this); } void TimelineHeaderWidget::on_size_request(Requisition* requisition) { REQUIRE(requisition); Requisition child_requisition = {0, 0}; if(widget && widget->is_visible()) child_requisition = widget->size_request(); requisition->width = child_requisition.width, requisition->height = child_requisition.height; ENSURE(requisition->width >= 0); ENSURE(requisition->height >= 0); } void TimelineHeaderWidget::on_size_allocate(Gtk::Allocation& allocation) { //Use the offered allocation for this container: set_allocation(allocation); // Resize the widget's window if(gdkWindow) { gdkWindow->move_resize(allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height()); } //Assign sign space to the child: Gtk::Allocation child_allocation( margin + expand_button_size, margin, max(allocation.get_width() - expand_button_size - margin * 2, 0), allocation.get_height() - margin*2); if(widget && widget->is_visible()) widget->size_allocate(child_allocation); } bool TimelineHeaderWidget::on_expose_event(GdkEventExpose *event) { Glib::RefPtr