2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "cairo_widget.h"
21 #include "gui_thread.h"
23 CairoWidget::CairoWidget ()
26 , _active_state (CairoWidget::ActiveState (0))
27 , _visual_state (CairoWidget::VisualState (0))
34 CairoWidget::~CairoWidget ()
37 g_object_unref (_pixmap);
42 CairoWidget::on_expose_event (GdkEventExpose *event)
44 Gdk::Rectangle const exposure (
45 event->area.x, event->area.y, event->area.width, event->area.height
48 Gdk::Rectangle r = exposure;
49 Gdk::Rectangle content (0, 0, _width, _height);
51 r.intersect (content, intersects);
55 GdkDrawable* drawable = get_window()->gobj ();
60 g_object_unref (_pixmap);
63 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
65 cairo_t* cr = gdk_cairo_create (_pixmap);
74 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
88 /** Marks the widget as dirty, so that render () will be called on
89 * the next GTK expose event.
93 CairoWidget::set_dirty ()
95 ENSURE_GUI_THREAD (*this, &CairoWidget::set_dirty)
101 /** Handle a size allocation.
102 * @param alloc GTK allocation.
105 CairoWidget::on_size_allocate (Gtk::Allocation& alloc)
107 Gtk::EventBox::on_size_allocate (alloc);
109 _width = alloc.get_width ();
110 _height = alloc.get_height ();
116 CairoWidget::get_parent_bg ()
120 parent = get_parent ();
122 while (parent && !parent->get_has_window()) {
123 parent = parent->get_parent();
126 if (parent && parent->get_has_window()) {
127 return parent->get_style ()->get_bg (parent->get_state());
130 return get_style ()->get_bg (get_state());
134 CairoWidget::set_active_state (CairoWidget::ActiveState s)
136 if (_active_state != s) {
143 CairoWidget::set_visual_state (CairoWidget::VisualState s)
145 if (_visual_state != s) {