missing NULL terminator in set_config_x
[geda-gaf.git] / gschem / src / o_buffer.c
blobf3913cff8f42134d440d8450c8cec1d1e3123918
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
21 #include <stdio.h>
23 #include "gschem.h"
26 GList *object_buffer[MAX_BUFFERS];
29 /*! \brief Copy the contents of the clipboard to a buffer
31 * \param [in] w_current
32 * \param [in] buf_num
34 static void
35 clipboard_to_buffer(GschemToplevel *w_current, int buf_num)
37 GList *object_list;
38 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
40 g_return_if_fail (w_current != NULL);
41 g_return_if_fail (toplevel != NULL);
42 g_return_if_fail (buf_num >= 0);
43 g_return_if_fail (buf_num < MAX_BUFFERS);
45 object_list = x_clipboard_get (w_current);
47 if (object_buffer[buf_num] != NULL) {
48 s_delete_object_glist (toplevel, object_buffer[buf_num]);
51 object_buffer[buf_num] = object_list;
55 /*! \brief Copy the selection to a buffer
57 * \param [in] w_current
58 * \param [in] buf_num
60 static void
61 selection_to_buffer(GschemToplevel *w_current, int buf_num)
63 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
64 GList *s_current = NULL;
66 g_return_if_fail (w_current != NULL);
67 g_return_if_fail (toplevel != NULL);
68 g_return_if_fail (buf_num >= 0);
69 g_return_if_fail (buf_num < MAX_BUFFERS);
71 s_current = geda_list_get_glist (toplevel->page_current->selection_list);
73 if (object_buffer[buf_num] != NULL) {
74 s_delete_object_glist (toplevel, object_buffer[buf_num]);
75 object_buffer[buf_num] = NULL;
78 object_buffer[buf_num] = o_glist_copy_all (toplevel,
79 s_current,
80 object_buffer[buf_num]);
84 /*! \brief Copy the selection into a buffer
86 * \param [in] w_current
87 * \param [in] buf_num
89 void
90 o_buffer_copy(GschemToplevel *w_current, int buf_num)
92 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
94 g_return_if_fail (w_current != NULL);
95 g_return_if_fail (toplevel != NULL);
96 g_return_if_fail (buf_num >= 0);
97 g_return_if_fail (buf_num < MAX_BUFFERS);
99 selection_to_buffer (w_current, buf_num);
101 g_run_hook_object_list (w_current,
102 "%copy-objects-hook",
103 object_buffer[buf_num]);
105 if (buf_num == CLIPBOARD_BUFFER) {
106 x_clipboard_set (w_current, object_buffer[buf_num]);
111 /*! \brief Cut the selection into a buffer
113 * \param [in] w_current
114 * \param [in] buf_num
116 void
117 o_buffer_cut(GschemToplevel *w_current, int buf_num)
119 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
121 g_return_if_fail (w_current != NULL);
122 g_return_if_fail (toplevel != NULL);
123 g_return_if_fail (buf_num >= 0);
124 g_return_if_fail (buf_num < MAX_BUFFERS);
126 selection_to_buffer (w_current, buf_num);
127 o_delete_selected (w_current, _("Cut"));
129 if (buf_num == CLIPBOARD_BUFFER) {
130 x_clipboard_set (w_current, object_buffer[buf_num]);
135 /*! \brief place the contents of the buffer into the place list
137 * \retval TRUE the clipboard is empty
138 * \retval FALSE the clipboard contained objects
141 o_buffer_paste_start(GschemToplevel *w_current, int w_x, int w_y, int buf_num)
143 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
144 int rleft, rtop, rbottom, rright;
145 int x, y;
147 g_return_val_if_fail (w_current != NULL, TRUE);
148 g_return_val_if_fail (toplevel != NULL, TRUE);
149 g_return_val_if_fail (buf_num >= 0, TRUE);
150 g_return_val_if_fail (buf_num < MAX_BUFFERS, TRUE);
152 /* Cancel current place or draw action if it is being done */
153 if (w_current->inside_action) {
154 i_cancel (w_current);
157 w_current->last_drawb_mode = LAST_DRAWB_MODE_NONE;
159 if (buf_num == CLIPBOARD_BUFFER) {
160 clipboard_to_buffer(w_current, buf_num);
163 if (object_buffer[buf_num] == NULL) {
164 return TRUE;
167 /* remove the old place list if it exists */
168 s_delete_object_glist(toplevel, toplevel->page_current->place_list);
169 toplevel->page_current->place_list = NULL;
171 toplevel->page_current->place_list =
172 o_glist_copy_all (toplevel, object_buffer[buf_num],
173 toplevel->page_current->place_list);
175 if (!world_get_object_glist_bounds (toplevel,
176 toplevel->page_current->place_list,
177 &rleft, &rtop,
178 &rright, &rbottom)) {
179 /* If the place buffer doesn't have any objects
180 * to define its any bounds, we drop out here */
181 return TRUE;
184 /* Place the objects into the buffer at the mouse origin, (w_x, w_y). */
186 w_current->first_wx = w_x;
187 w_current->first_wy = w_y;
189 /* snap x and y to the grid, pointed out by Martin Benes */
190 x = snap_grid (w_current, rleft);
191 y = snap_grid (w_current, rtop);
193 o_glist_translate_world (toplevel->page_current->place_list,
194 w_x - x, w_y - y);
196 i_set_state(w_current, PASTEMODE);
197 o_place_start (w_current, w_x, w_y);
199 /* the next paste operation will be a copy of these objects */
201 g_run_hook_object_list (w_current,
202 "%copy-objects-hook",
203 object_buffer[buf_num]);
205 if (buf_num == CLIPBOARD_BUFFER) {
206 x_clipboard_set (w_current, object_buffer[buf_num]);
209 return FALSE;
213 /*! \todo Finish function documentation!!!
214 * \brief
215 * \par Function Description
218 void o_buffer_init(void)
220 int i;
222 for (i = 0 ; i < MAX_BUFFERS; i++) {
223 object_buffer[i] = NULL;
227 /*! \todo Finish function documentation!!!
228 * \brief
229 * \par Function Description
232 void o_buffer_free(GschemToplevel *w_current)
234 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
235 int i;
237 for (i = 0 ; i < MAX_BUFFERS; i++) {
238 if (object_buffer[i]) {
239 s_delete_object_glist(toplevel, object_buffer[i]);
240 object_buffer[i] = NULL;