From 75d2890ab72c30edac39df33007bf000cd0b8ca3 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 14 Jan 2009 23:22:04 +0000 Subject: [PATCH] WIP: Added new header code --- .../timeline/timeline-header-widget.cpp | 330 ++++++++++++++++++ .../timeline/timeline-header-widget.hpp | 138 ++++++++ 2 files changed, 468 insertions(+) create mode 100644 src/gui/widgets/timeline/timeline-header-widget.cpp create mode 100644 src/gui/widgets/timeline/timeline-header-widget.hpp diff --git a/src/gui/widgets/timeline/timeline-header-widget.cpp b/src/gui/widgets/timeline/timeline-header-widget.cpp new file mode 100644 index 000000000..d11f96ce1 --- /dev/null +++ b/src/gui/widgets/timeline/timeline-header-widget.cpp @@ -0,0 +1,330 @@ +/* + 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 "../timeline-widget.hpp" +#include "../../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; + 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()); + + // Make the widget sensitive to mouse events + add_events( + Gdk::POINTER_MOTION_MASK | + Gdk::BUTTON_PRESS_MASK | + Gdk::BUTTON_RELEASE_MASK); +} + +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