2 Copyright (C) 2014 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 <cairomm/context.h>
21 #include "pbd/stacktrace.h"
22 #include "pbd/compose.h"
24 #include "canvas/canvas.h"
25 #include "canvas/widget.h"
26 #include "canvas/debug.h"
27 #include "canvas/utils.h"
30 using namespace ArdourCanvas;
32 Widget::Widget (Canvas* c, CairoWidget& w)
36 Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
39 Widget::Widget (Item* parent, CairoWidget& w)
43 Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
47 Widget::event_proxy (GdkEvent* ev)
49 /* XXX need to translate coordinate into widget's own coordinate space */
50 return _widget.event (ev);
54 Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
56 // std::cerr << "Render widget\n";
59 std::cerr << "no bbox\n";
63 Rect self = item_to_window (_bounding_box.get());
64 boost::optional<Rect> r = self.intersection (area);
67 std::cerr << "no intersection\n";
72 cairo_rectangle_t crect;
75 crect.height = draw.height();
76 crect.width = draw.width();
78 // std::cerr << "will draw " << draw << "\n";
80 context->translate (-draw.x0, -draw.y0);
81 //context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
84 _widget.render (context->cobj(), &crect);
90 Widget::compute_bounding_box () const
92 std::cerr << "cbbox for widget\n";
94 GtkRequisition req = { 0, 0 };
95 Gtk::Allocation alloc;
97 _widget.size_request (req);
99 std::cerr << "widget wants " << req.width << " x " << req.height << "\n";
101 _bounding_box = Rect (0, 0, req.width, req.height);
103 /* make sure the widget knows that it got what it asked for */
106 alloc.set_width (req.width);
107 alloc.set_height (req.height);
109 _widget.size_allocate (alloc);
111 _bounding_box_dirty = false;