Use new text accessors.
[geda-gaf/berndj.git] / gschem / src / g_hook.c
blob2ff687f206ab75a84458fda00fb56dfc7307167c
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
21 #include <stdio.h>
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #endif
25 #include <math.h>
27 #include "gschem.h"
29 #ifdef HAVE_LIBDMALLOC
30 #include <dmalloc.h>
31 #endif
33 /*! \todo Finish function documentation!!!
34 * \brief
35 * \par Function Description
39 * Adds an attribute <B>scm_attrib_name</B> with value <B>scm_attrib_value</B> to the given <B>object</B>.
40 The attribute has the visibility <B>scm_vis</B> and show <B>scm_show</B> flags.
41 The possible values are:
42 - <B>scm_vis</B>: scheme boolean. Visible (TRUE) or hidden (FALSE).
43 - <B>scm_show</B>: a list containing what to show: "name", "value", or both.
44 The return value is always TRUE.
46 SCM g_add_attrib(SCM object, SCM scm_attrib_name,
47 SCM scm_attrib_value, SCM scm_vis, SCM scm_show)
49 GSCHEM_TOPLEVEL *w_current=global_window_current;
50 OBJECT *o_current=NULL;
51 gboolean vis;
52 int show=0;
53 gchar *attrib_name=NULL;
54 gchar *attrib_value=NULL;
55 gchar *value=NULL;
56 gchar *newtext=NULL;
57 SCM rest;
59 SCM_ASSERT (scm_is_string(scm_attrib_name), scm_attrib_name,
60 SCM_ARG2, "add-attribute-to-object");
61 SCM_ASSERT (scm_is_string(scm_attrib_value), scm_attrib_value,
62 SCM_ARG3, "add-attribute-to-object");
63 SCM_ASSERT (scm_boolean_p(scm_vis), scm_vis,
64 SCM_ARG4, "add-attribute-to-object");
65 SCM_ASSERT (scm_list_p(scm_show), scm_show,
66 SCM_ARG5, "add-attribute-to-object");
68 /* Get o_current */
69 SCM_ASSERT(g_get_data_from_object_smob(object, NULL, &o_current),
70 object, SCM_ARG1, "add-attribute-to-object");
72 scm_dynwind_begin(0);
74 /* Get parameters */
75 attrib_name = scm_to_locale_string(scm_attrib_name);
76 attrib_value = scm_to_locale_string(scm_attrib_value);
77 scm_dynwind_free(attrib_name);
78 scm_dynwind_free(attrib_value);
79 vis = SCM_NFALSEP(scm_vis);
81 for (rest = scm_show; !scm_is_null(rest); rest = SCM_CDR(rest)) {
82 /* Check every element in the list. It should be a string! */
83 SCM_ASSERT(scm_is_string(SCM_CAR(rest)), SCM_CAR(rest), SCM_ARG5,
84 "add-attribute-to-object");
86 value = scm_to_locale_string(SCM_CAR(rest));
87 scm_dynwind_free(value);
89 /* Only "name" or "value" strings are allowed */
90 SCM_ASSERT(!((strcasecmp(value, "name") != 0) &&
91 (strcasecmp(value, "value") != 0) ), SCM_CAR(rest),
92 SCM_ARG5, "add-attribute-to-object");
94 /* show = 1 => show value;
95 show = 2 => show name;
96 show = 3 => show both */
97 if (strcasecmp(value, "value") == 0) {
98 show |= 1;
100 else if (strcasecmp(value, "name") == 0) {
101 show |= 2;
104 /* Show name and value (show = 3) => show=0 for gschem */
105 if (show == 3) {
106 show = 0;
109 newtext = g_strdup_printf("%s=%s", attrib_name, attrib_value);
110 o_attrib_add_attrib (w_current, newtext, vis, show, o_current);
111 g_free(newtext);
113 scm_dynwind_end();
114 return SCM_BOOL_T;
117 /*! \todo Finish function documentation!!!
118 * \brief
119 * \par Function Description
122 /*! \todo Finish function documentation!!!
123 * \brief
124 * \par Function Description
128 * Sets several text properties of the given <B>attribute smob</B>:
129 - <B>coloridx</B>: The index of the text color, or -1 to keep previous color.
130 - <B>size</B>: Size (numeric) of the text, or -1 to keep the previous size.
131 - <B>alignment</B>: String with the alignment of the text. Possible values are:
132 * "" : Keep the previous alignment.
133 * "Lower Left"
134 * "Middle Left"
135 * "Upper Left"
136 * "Lower Middle"
137 * "Middle Middle"
138 * "Upper Middle"
139 * "Lower Right"
140 * "Middle Right"
141 * "Upper Right"
142 - <B>rotation</B>: Angle of the text, or -1 to keep previous angle.
143 - <B>x</B>, <B>y</B>: Coords of the text.
145 SCM g_set_attrib_text_properties(SCM attrib_smob, SCM scm_coloridx,
146 SCM scm_size, SCM scm_alignment,
147 SCM scm_rotation, SCM scm_x, SCM scm_y)
149 struct st_attrib_smob *attribute =
150 (struct st_attrib_smob *) SCM_SMOB_DATA(attrib_smob);
151 OBJECT *object;
152 GSCHEM_TOPLEVEL *w_current = global_window_current;
153 TOPLEVEL *toplevel = w_current->toplevel;
155 int color = -1;
156 int size = -1;
157 char *alignment_string;
158 int alignment = -2;
159 int rotation = 0;
160 int x = -1, y = -1;
162 SCM_ASSERT (scm_is_integer(scm_coloridx), scm_coloridx,
163 SCM_ARG2, "set-attribute-text-properties!");
164 SCM_ASSERT ( scm_is_integer(scm_size),
165 scm_size, SCM_ARG3, "set-attribute-text-properties!");
166 SCM_ASSERT (scm_is_string(scm_alignment), scm_alignment,
167 SCM_ARG4, "set-attribute-text-properties!");
168 SCM_ASSERT ( scm_is_integer(scm_rotation),
169 scm_rotation, SCM_ARG5, "set-attribute-text-properties!");
170 SCM_ASSERT ( scm_is_integer(scm_x),
171 scm_x, SCM_ARG6, "set-attribute-text-properties!");
172 SCM_ASSERT ( scm_is_integer(scm_y),
173 scm_y, SCM_ARG7, "set-attribute-text-properties!");
175 color = scm_to_int(scm_coloridx);
177 SCM_ASSERT (!(color < -1 || color >= MAX_COLORS),
178 scm_coloridx, SCM_ARG2, "set-attribute-text-properties!");
180 size = scm_to_int(scm_size);
181 rotation = scm_to_int(scm_rotation);
182 x = scm_to_int(scm_x);
183 y = scm_to_int(scm_y);
185 scm_dynwind_begin(0);
186 alignment_string = scm_to_locale_string(scm_alignment);
187 scm_dynwind_free(alignment_string);
189 if (strlen(alignment_string) == 0) {
190 alignment = -1;
192 if (strcmp(alignment_string, "Lower Left") == 0) {
193 alignment = 0;
195 if (strcmp(alignment_string, "Middle Left") == 0) {
196 alignment = 1;
198 if (strcmp(alignment_string, "Upper Left") == 0) {
199 alignment = 2;
201 if (strcmp(alignment_string, "Lower Middle") == 0) {
202 alignment = 3;
204 if (strcmp(alignment_string, "Middle Middle") == 0) {
205 alignment = 4;
207 if (strcmp(alignment_string, "Upper Middle") == 0) {
208 alignment = 5;
210 if (strcmp(alignment_string, "Lower Right") == 0) {
211 alignment = 6;
213 if (strcmp(alignment_string, "Middle Right") == 0) {
214 alignment = 7;
216 if (strcmp(alignment_string, "Upper Right") == 0) {
217 alignment = 8;
219 if (alignment == -2) {
220 /* Bad specified */
221 SCM_ASSERT (scm_is_string(scm_alignment), scm_alignment,
222 SCM_ARG4, "set-attribute-text-properties!");
224 scm_dynwind_end();
226 if (attribute &&
227 attribute->attribute) {
228 object = attribute->attribute;
229 if (object &&
230 object->text) {
231 int new_x, new_y;
233 o_erase_single(w_current, object);
235 o_text_get_xy(object, &new_x, &new_y);
236 if (x != -1) {
237 new_x = x;
239 if (y != -1) {
240 new_y = y;
242 o_text_set_xy(object, new_x, new_y);
243 if (size != -1) {
244 o_text_set_size(object, size);
246 if (alignment != -1) {
247 o_text_set_alignment(object, alignment);
249 if (rotation != -1) {
250 o_text_set_angle(object, rotation);
252 o_text_recreate(object);
253 if (!toplevel->DONT_REDRAW) {
254 o_text_draw(w_current, object);
258 return SCM_BOOL_T;
261 /*! \brief Return a list of selected objects in a page.
262 * \par Function Description
263 * Returns a list containing the selected objects in the given page.
265 * \param [in] page_smob Page to look at.
267 * \return a list of objects in the selection list.
269 SCM g_get_selected_objects(SCM page_smob)
271 TOPLEVEL *toplevel;
272 PAGE *page;
273 SCM return_list = SCM_EOL;
274 GList *iter;
276 /* Get toplevel and the page */
277 SCM_ASSERT(g_get_data_from_page_smob(page_smob, &toplevel, &page),
278 page_smob, SCM_ARG1, "get-selected-objects");
280 for (iter = geda_list_get_glist(page->selection_list); iter != NULL; iter = iter->next) {
281 return_list = scm_cons(g_make_object_smob(toplevel, iter->data),
282 return_list);
285 return return_list;
289 SCM g_get_current_page(void)
291 return (g_make_page_smob(global_window_current->toplevel,
292 global_window_current->toplevel->page_current));