1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/*
* ggcov - A GTK frontend for exploring gcov coverage data
* Copyright (c) 2005 Greg Banks <gnb@users.sourceforge.net>
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "canvas_scenegen.H"
#include "ui.h"
#include "canvas_function_popup.H"
#include "cov_suppression.H"
CVSID("$Id: canvas_scenegen.C,v 1.4 2010-05-09 05:37:14 gnb Exp $");
#define RGB_TO_STR(b, rgb) \
snprintf((b), sizeof((b)), "#%02x%02x%02x", \
((rgb)>>16)&0xff, ((rgb)>>8)&0xff, (rgb)&0xff)
static const char BLOCK_KEY[] = "ggcov-canvas-scenegen-block";
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
canvas_scenegen_t::canvas_scenegen_t(GnomeCanvas *can)
{
canvas_ = can;
root_ = gnome_canvas_root(canvas_);
points_.coords = (double *)0;
points_.num_points = 0;
points_.ref_count = 1;
points_size_ = 0;
registered_tooltip_ = FALSE;
}
canvas_scenegen_t::~canvas_scenegen_t()
{
if (points_.coords != 0)
g_free(points_.coords);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void
canvas_scenegen_t::noborder()
{
border_flag_ = FALSE;
}
void
canvas_scenegen_t::border(unsigned int rgb)
{
border_flag_ = TRUE;
RGB_TO_STR(border_buf_, rgb);
}
void
canvas_scenegen_t::nofill()
{
fill_flag_ = FALSE;
}
void
canvas_scenegen_t::fill(unsigned int rgb)
{
fill_flag_ = TRUE;
RGB_TO_STR(fill_buf_, rgb);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void
canvas_scenegen_t::handle_object(GnomeCanvasItem *item)
{
cov_function_t *fn = get_function();
if (fn)
{
canvas_function_popup_t *fpop = new canvas_function_popup_t(item, fn);
fpop->set_foreground(border_color());
fpop->set_background(fill_color());
return;
}
cov_block_t *b = get_block();
if (b)
{
if (!registered_tooltip_)
{
GnomeCanvas *canvas = GNOME_CANVAS_ITEM(item)->canvas;
gtk_widget_set(GTK_WIDGET(canvas),
"has-tooltip", TRUE,
(char *)0);
gtk_signal_connect(GTK_OBJECT(canvas), "query-tooltip",
GTK_SIGNAL_FUNC(on_query_tooltip), NULL);
registered_tooltip_ = TRUE;
}
gtk_object_set_data(GTK_OBJECT(item), BLOCK_KEY, (gpointer)b);
return;
}
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void
canvas_scenegen_t::box(double x, double y, double w, double h)
{
GnomeCanvasItem *item;
item = gnome_canvas_item_new(root_, GNOME_TYPE_CANVAS_RECT,
"x1", x,
"y1", y,
"x2", x+w,
"y2", y+h,
"fill_color", fill_color(),
"outline_color",border_color(),
#if GTK2
"width_pixels", (border_flag_ ? 1 : 0),
#endif
(char *)0);
handle_object(item);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void
canvas_scenegen_t::textbox(
double x,
double y,
double w,
double h,
const char *text)
{
GnomeCanvasItem *item;
item = gnome_canvas_item_new(root_, GNOME_TYPE_CANVAS_TEXT,
"text", text,
"font", "fixed",
"fill_color", border_color(),
"x", x,
"y", y,
"clip", TRUE,
"clip_width", w,
"clip_height", h,
"anchor", GTK_ANCHOR_NORTH_WEST,
(char *)0);
handle_object(item);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void
canvas_scenegen_t::polyline_begin(gboolean arrow)
{
first_arrow_flag_ = arrow;
points_.num_points = 0;
}
void
canvas_scenegen_t::polyline_point(double x, double y)
{
unsigned int newsize = 2 * sizeof(double) * (points_.num_points+1);
if (newsize > points_size_)
{
/* round newsize up to a 256-byte boundary to reduce allocations */
newsize = (newsize + 0xff) & ~0xff;
/* TODO: use a new gnb_xrealloc */
points_.coords = (double *)g_realloc(points_.coords, newsize);
points_size_ = newsize;
}
double *p = points_.coords + 2*points_.num_points;
p[0] = x;
p[1] = y;
points_.num_points++;
}
void
canvas_scenegen_t::polyline_end(gboolean arrow)
{
GnomeCanvasItem *item;
if (!points_.num_points)
return;
item = gnome_canvas_item_new(root_, GNOME_TYPE_CANVAS_LINE,
"points", &points_,
"first_arrowhead", first_arrow_flag_,
"last_arrowhead", arrow,
"arrow_shape_a", arrow_size_ * arrow_shape_[0],
"arrow_shape_b", arrow_size_ * arrow_shape_[1],
"arrow_shape_c", arrow_size_ * arrow_shape_[2],
"fill_color", fill_color(),
/* setting width_pixels screws up the arrow heads !?!? */
(char *)0);
handle_object(item);
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
static void describe_status(estring &txt, const cov_suppression_t *sup, count_t count)
{
if (sup)
{
txt.append_printf("suppressed because %s\n", sup->describe());
}
else if (!count)
{
txt.append_printf("never executed\n");
}
else
{
txt.append_printf("executed "GNB_U64_DFMT" times\n", count);
}
}
void
canvas_scenegen_t::format_tooltip(estring &txt, cov_block_t *b)
{
txt.append_printf("Block %d", b->bindex());
txt.append_printf(" of %s\n", b->function()->name());
describe_status(txt, b->suppression(), b->count());
for (list_iterator_t<cov_arc_t> aiter = b->first_arc() ; *aiter ; ++aiter)
{
cov_arc_t *a = *aiter;
txt.append_printf("arc %u: ", a->aindex());
if (a->is_call())
{
const char *n = a->call_name();
txt.append_printf("call to %s", (n ? n : "unknown function"));
}
else if (a->is_return())
{
txt.append_printf("return from function");
}
else if (a->is_fall_through())
{
txt.append_printf("fall through to block %u", a->to()->bindex());
}
else
{
txt.append_printf("branch to block %u", a->to()->bindex());
}
txt.append_string(", ");
describe_status(txt, a->suppression(), a->count());
}
}
gboolean
canvas_scenegen_t::on_query_tooltip(GtkWidget *w, gint x, gint y,
gboolean keyboard_mode, GtkTooltip *tooltip,
gpointer closure)
{
GnomeCanvas *canvas = GNOME_CANVAS(w);
double wx, wy;
gnome_canvas_c2w(canvas, x, y, &wx, &wy);
GnomeCanvasItem *item = gnome_canvas_get_item_at(canvas, wx, wy);
if (!item)
return FALSE;
estring txt;
cov_block_t *b = (cov_block_t *)gtk_object_get_data(GTK_OBJECT(item), BLOCK_KEY);
if (b)
format_tooltip(txt, b);
while (txt.length() && txt.data()[txt.length()-1] == '\n')
txt.truncate_to(txt.length()-1);
if (txt.length())
{
gtk_tooltip_set_text(tooltip, txt.data());
return TRUE;
}
return FALSE;
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
/*END*/
|