2 * Copyright (C) 2011-2015 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "gtkmm2ext/utils.h"
21 #include "gtkmm2ext/cairo_widget.h"
22 #include "gtkmm2ext/cairo_packer.h"
25 CairoPacker::draw_background (Gtk::Widget& w, GdkEventExpose*)
28 Gtk::Widget* window_parent;
29 Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (w, &window_parent);
33 Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
34 w.translate_coordinates (*window_parent, 0, 0, x, y);
36 Gdk::Color bg = get_bg ();
38 context->set_source_rgba (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p(), 1.0);
39 Gtkmm2ext::rounded_rectangle (context, x, y, w.get_allocation().get_width(), w.get_allocation().get_height(), 4);
44 CairoHPacker::CairoHPacker ()
49 CairoHPacker::on_realize ()
52 CairoWidget::provide_background_for_cairo_widget (*this, get_bg ());
56 CairoHPacker::get_bg () const
58 return get_style()->get_bg (Gtk::STATE_NORMAL);
62 CairoHPacker::on_expose_event (GdkEventExpose* ev)
64 draw_background (*this, ev);
65 return HBox::on_expose_event (ev);
69 CairoHPacker::on_size_allocate (Gtk::Allocation& alloc)
71 get_parent()->queue_draw();
72 HBox::on_size_allocate (alloc);
75 CairoVPacker::CairoVPacker ()
80 CairoVPacker::on_expose_event (GdkEventExpose* ev)
82 draw_background (*this, ev);
83 return VBox::on_expose_event (ev);
87 CairoVPacker::on_realize ()
90 CairoWidget::provide_background_for_cairo_widget (*this, get_bg());
94 CairoVPacker::on_size_allocate (Gtk::Allocation& alloc)
96 get_parent()->queue_draw();
97 VBox::on_size_allocate (alloc);
101 CairoVPacker::get_bg () const
103 return get_style()->get_bg (Gtk::STATE_NORMAL);