1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library. |
---|
3 | |
---|
4 | Copyright (C) 2001, Ximian, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #include <config.h> |
---|
24 | #include <string.h> |
---|
25 | #include <glib.h> |
---|
26 | #include "htmlmap.h" |
---|
27 | #include "htmlshape.h" |
---|
28 | |
---|
29 | void |
---|
30 | html_map_destroy (HTMLMap *map) |
---|
31 | { |
---|
32 | gint i; |
---|
33 | |
---|
34 | for (i = 0; i < map->shapes->len; i++) |
---|
35 | html_shape_destroy (g_ptr_array_index (map->shapes, i)); |
---|
36 | |
---|
37 | g_ptr_array_free (map->shapes, FALSE); |
---|
38 | map->shapes = NULL; |
---|
39 | |
---|
40 | g_free (map->name); |
---|
41 | g_free (map); |
---|
42 | } |
---|
43 | |
---|
44 | void |
---|
45 | html_map_add_shape (HTMLMap *map, HTMLShape *shape) |
---|
46 | { |
---|
47 | g_return_if_fail (shape != NULL); |
---|
48 | |
---|
49 | g_ptr_array_add (map->shapes, shape); |
---|
50 | } |
---|
51 | |
---|
52 | char * |
---|
53 | html_map_calc_point (HTMLMap *map, gint x, gint y) |
---|
54 | { |
---|
55 | int i; |
---|
56 | |
---|
57 | for (i = 0; i < map->shapes->len; i++) { |
---|
58 | HTMLShape *shape; |
---|
59 | shape = g_ptr_array_index (map->shapes, i); |
---|
60 | |
---|
61 | if (html_shape_point (shape, x, y)) { |
---|
62 | return html_shape_get_url (shape); |
---|
63 | } |
---|
64 | } |
---|
65 | return NULL; |
---|
66 | } |
---|
67 | |
---|
68 | HTMLMap * |
---|
69 | html_map_new (const gchar *name) |
---|
70 | { |
---|
71 | HTMLMap *map; |
---|
72 | |
---|
73 | map = g_new (HTMLMap, 1); |
---|
74 | map->shapes = g_ptr_array_new (); |
---|
75 | map->name = g_strdup (name); |
---|
76 | |
---|
77 | return map; |
---|
78 | } |
---|