Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gschem / src / g_keys.c
blob4bee5d34ae938af89a63cc7ac27bfb4c1e716370
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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>
22 #include <stdio.h>
23 #include <sys/stat.h>
24 #include <ctype.h>
25 #ifdef HAVE_STRING_H
26 #include <string.h>
27 #endif
28 #ifdef HAVE_STDLIB_H
29 #include <stdlib.h>
30 #endif
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
35 #include "gschem.h"
37 #ifdef HAVE_LIBDMALLOC
38 #include <dmalloc.h>
39 #endif
41 /*! \todo Finish function documentation!!!
42 * \brief
43 * \par Function Description
46 /* for now this only supports single chars, not shift/alt/ctrl etc... */
47 int g_keys_execute(GSCHEM_TOPLEVEL *w_current, int state, int keyval)
49 char *guile_string = NULL;
50 char *modifier = NULL;
51 char *key_name = NULL;
52 SCM scm_retval;
54 if (keyval == 0) {
55 return 0;
58 key_name = gdk_keyval_name(keyval);
59 if ( key_name == NULL ) {
60 return 0;
63 /* don't pass the raw modifier key presses to the guile code */
64 if (strstr(key_name, "Alt") ||
65 strstr(key_name, "Shift") ||
66 strstr(key_name, "Control") ) {
67 return 0;
70 if (state & GDK_SHIFT_MASK) {
71 modifier = g_strdup_printf("Shift ");
72 } else if (state & GDK_CONTROL_MASK) {
73 modifier = g_strdup_printf("Control ");
74 } else if (state & GDK_MOD1_MASK) {
75 modifier = g_strdup_printf("Alt ");
76 } else
77 modifier = g_strdup("");
79 if(strcmp(key_name, "Escape") == 0) {
80 g_free(w_current->keyaccel_string);
81 w_current->keyaccel_string = NULL;
82 } else if(w_current->keyaccel_string &&
83 strlen(w_current->keyaccel_string) + strlen(key_name) > 10) {
84 g_free(w_current->keyaccel_string);
85 w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL);
86 } else {
87 gchar *p, *r;
89 p = w_current->keyaccel_string;
90 w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL);
91 if(p) {
92 r = g_strconcat(p, w_current->keyaccel_string, NULL);
93 g_free(p);
94 g_free(w_current->keyaccel_string);
95 w_current->keyaccel_string = r;
99 i_show_state(w_current, NULL);
101 guile_string = g_strdup_printf("(press-key \"%s%s\")",
102 modifier, key_name);
104 #if DEBUG
105 printf("_%s_\n", guile_string);
106 #endif
107 scm_retval = g_scm_c_eval_string_protected (guile_string);
108 g_free(guile_string);
109 g_free(modifier);
111 return (SCM_FALSEP (scm_retval)) ? 0 : 1;
114 /*! \brief Exports the keymap in scheme to a GLib GArray.
115 * \par Function Description
116 * This function converts the list of key sequence/action pairs
117 * returned by the scheme function \c dump-current-keymap into an
118 * array of C structures.
120 * The returned value must be freed by caller.
122 * \return A GArray with keymap data.
124 GArray*
125 g_keys_dump_keymap (void)
127 SCM dump_proc = scm_c_lookup ("dump-current-keymap");
128 SCM scm_ret;
129 GArray *ret = NULL;
130 struct keyseq_action_t {
131 gchar *keyseq, *action;
134 dump_proc = scm_variable_ref (dump_proc);
135 g_return_val_if_fail (SCM_NFALSEP (scm_procedure_p (dump_proc)), NULL);
137 scm_ret = scm_call_0 (dump_proc);
138 g_return_val_if_fail (SCM_CONSP (scm_ret), NULL);
140 ret = g_array_sized_new (FALSE,
141 FALSE,
142 sizeof (struct keyseq_action_t),
143 (guint)scm_ilength (scm_ret));
144 for (; scm_ret != SCM_EOL; scm_ret = SCM_CDR (scm_ret)) {
145 SCM scm_keymap_entry = SCM_CAR (scm_ret);
146 struct keyseq_action_t keymap_entry;
148 g_return_val_if_fail (SCM_CONSP (scm_keymap_entry) &&
149 SCM_SYMBOLP (SCM_CAR (scm_keymap_entry)) &&
150 scm_is_string (SCM_CDR (scm_keymap_entry)), ret);
151 keymap_entry.action = g_strdup (SCM_SYMBOL_CHARS (SCM_CAR (scm_keymap_entry)));
152 keymap_entry.keyseq = g_strdup (SCM_STRING_CHARS (SCM_CDR (scm_keymap_entry)));
153 ret = g_array_append_val (ret, keymap_entry);
156 return ret;
159 /*! \brief Clear the current key accelerator string
161 * \par Function Description
162 * This function clears the current keyboard accelerator
163 * string in the status bar of the relevant toplevel.
164 * Called after the action specifed by the keyboard
165 * accelerator is executed and the associated timeout interval
166 * has passed.
168 * \param [in] data a pointer to the GSCHEM_TOPLEVEL
170 static gboolean clear_keyaccel_string(gpointer data)
172 GSCHEM_TOPLEVEL *w_current = data;
174 /* Find out if the GSCHEM_TOPLEVEL is present... */
175 if (g_list_find(global_window_list, w_current) != NULL) {
176 g_free(w_current->keyaccel_string);
177 w_current->keyaccel_string = NULL;
178 i_show_state(w_current, NULL);
181 return FALSE;
184 #define DEFINE_G_KEYS(name) \
185 SCM g_keys_ ## name(SCM rest) \
187 g_timeout_add(400, clear_keyaccel_string, global_window_current); \
188 i_callback_ ## name(global_window_current, 0, NULL); \
189 return SCM_BOOL_T; \
192 /*! \brief test-comment
193 * test-comment
195 DEFINE_G_KEYS(file_new)
197 DEFINE_G_KEYS(file_new_window)
199 /* don't use the widget parameter on this function, or do some checking... */
200 /* since there is a call: widget = NULL, data = 0 (will be w_current) */
201 /* This should be renamed to page_open perhaps... */
202 DEFINE_G_KEYS(file_open)
204 /* don't use the widget parameter on this function, or do some checking... */
205 /* since there is a call: widget = NULL, data = 0 (will be w_current) */
206 DEFINE_G_KEYS(file_script)
208 /* don't use the widget parameter on this function, or do some checking... */
209 /* since there is a call: widget = NULL, data = 0 (will be w_current) */
210 DEFINE_G_KEYS(file_save)
211 DEFINE_G_KEYS(file_save_as)
212 DEFINE_G_KEYS(file_save_all)
213 DEFINE_G_KEYS(file_print)
214 DEFINE_G_KEYS(file_write_png)
216 /* don't use the widget parameter on this function, or do some checking... */
217 /* since there is a call: widget = NULL, data = 0 (will be w_current) */
218 /* this function closes a window */
219 DEFINE_G_KEYS(file_close)
220 DEFINE_G_KEYS(file_quit)
222 /* Select also does not update the middle button shortcut */
223 DEFINE_G_KEYS(edit_undo)
224 DEFINE_G_KEYS(edit_redo)
225 DEFINE_G_KEYS(edit_select)
226 DEFINE_G_KEYS(edit_copy)
227 DEFINE_G_KEYS(edit_copy_hotkey)
228 DEFINE_G_KEYS(edit_mcopy)
229 DEFINE_G_KEYS(edit_mcopy_hotkey)
230 DEFINE_G_KEYS(edit_move)
231 DEFINE_G_KEYS(edit_move_hotkey)
232 DEFINE_G_KEYS(edit_delete)
233 DEFINE_G_KEYS(edit_rotate_90)
234 DEFINE_G_KEYS(edit_rotate_90_hotkey)
235 DEFINE_G_KEYS(edit_mirror)
236 DEFINE_G_KEYS(edit_mirror_hotkey)
237 DEFINE_G_KEYS(edit_slot)
238 DEFINE_G_KEYS(edit_color)
239 DEFINE_G_KEYS(edit_edit)
240 DEFINE_G_KEYS(edit_pin_type)
241 DEFINE_G_KEYS(edit_text)
242 DEFINE_G_KEYS(edit_lock)
243 DEFINE_G_KEYS(edit_unlock)
244 DEFINE_G_KEYS(edit_linetype)
245 DEFINE_G_KEYS(edit_filltype)
246 DEFINE_G_KEYS(edit_translate)
247 DEFINE_G_KEYS(edit_invoke_macro)
248 DEFINE_G_KEYS(edit_embed)
249 DEFINE_G_KEYS(edit_unembed)
250 DEFINE_G_KEYS(edit_update)
251 DEFINE_G_KEYS(edit_show_hidden)
252 DEFINE_G_KEYS(edit_make_visible)
253 DEFINE_G_KEYS(edit_find)
254 DEFINE_G_KEYS(edit_show_text)
255 DEFINE_G_KEYS(edit_hide_text)
256 DEFINE_G_KEYS(edit_autonumber_text)
258 DEFINE_G_KEYS(clipboard_copy)
259 DEFINE_G_KEYS(clipboard_cut)
260 DEFINE_G_KEYS(clipboard_paste)
261 DEFINE_G_KEYS(clipboard_paste_hotkey)
263 DEFINE_G_KEYS(buffer_copy1)
264 DEFINE_G_KEYS(buffer_copy2)
265 DEFINE_G_KEYS(buffer_copy3)
266 DEFINE_G_KEYS(buffer_copy4)
267 DEFINE_G_KEYS(buffer_copy5)
268 DEFINE_G_KEYS(buffer_cut1)
269 DEFINE_G_KEYS(buffer_cut2)
270 DEFINE_G_KEYS(buffer_cut3)
271 DEFINE_G_KEYS(buffer_cut4)
272 DEFINE_G_KEYS(buffer_cut5)
273 DEFINE_G_KEYS(buffer_paste1)
274 DEFINE_G_KEYS(buffer_paste2)
275 DEFINE_G_KEYS(buffer_paste3)
276 DEFINE_G_KEYS(buffer_paste4)
277 DEFINE_G_KEYS(buffer_paste5)
278 DEFINE_G_KEYS(buffer_paste1_hotkey)
279 DEFINE_G_KEYS(buffer_paste2_hotkey)
280 DEFINE_G_KEYS(buffer_paste3_hotkey)
281 DEFINE_G_KEYS(buffer_paste4_hotkey)
282 DEFINE_G_KEYS(buffer_paste5_hotkey)
284 /* repeat middle shortcut doesn't make sense on redraw, just hit right
285 * button */
286 DEFINE_G_KEYS(view_redraw)
288 /* for these functions, repeat middle shortcut would get into the way
289 * of what user is try to do */
290 DEFINE_G_KEYS(view_zoom_full)
291 DEFINE_G_KEYS(view_zoom_extents)
292 DEFINE_G_KEYS(view_zoom_in)
293 DEFINE_G_KEYS(view_zoom_out)
294 DEFINE_G_KEYS(view_zoom_in_hotkey)
295 DEFINE_G_KEYS(view_zoom_out_hotkey)
297 DEFINE_G_KEYS(view_zoom_box)
298 DEFINE_G_KEYS(view_zoom_box_hotkey)
299 DEFINE_G_KEYS(view_pan)
300 DEFINE_G_KEYS(view_pan_left)
301 DEFINE_G_KEYS(view_pan_right)
302 DEFINE_G_KEYS(view_pan_up)
303 DEFINE_G_KEYS(view_pan_down)
304 DEFINE_G_KEYS(view_pan_hotkey)
305 DEFINE_G_KEYS(view_update_cues)
306 DEFINE_G_KEYS(view_dark_colors)
307 DEFINE_G_KEYS(view_light_colors)
308 DEFINE_G_KEYS(page_manager)
309 DEFINE_G_KEYS(page_next)
310 DEFINE_G_KEYS(page_prev)
311 DEFINE_G_KEYS(page_new)
312 DEFINE_G_KEYS(page_close)
313 DEFINE_G_KEYS(page_revert)
314 DEFINE_G_KEYS(page_discard)
315 DEFINE_G_KEYS(page_print)
316 DEFINE_G_KEYS(add_component)
317 DEFINE_G_KEYS(add_attribute)
318 DEFINE_G_KEYS(add_attribute_hotkey)
319 DEFINE_G_KEYS(add_net)
320 DEFINE_G_KEYS(add_net_hotkey)
321 DEFINE_G_KEYS(add_bus)
322 DEFINE_G_KEYS(add_bus_hotkey)
323 DEFINE_G_KEYS(add_text)
324 DEFINE_G_KEYS(add_line)
325 DEFINE_G_KEYS(add_line_hotkey)
326 DEFINE_G_KEYS(add_box)
327 DEFINE_G_KEYS(add_box_hotkey)
328 DEFINE_G_KEYS(add_picture)
329 DEFINE_G_KEYS(add_picture_hotkey)
330 DEFINE_G_KEYS(add_circle)
331 DEFINE_G_KEYS(add_circle_hotkey)
332 DEFINE_G_KEYS(add_arc)
333 DEFINE_G_KEYS(add_arc_hotkey)
334 DEFINE_G_KEYS(add_pin)
335 DEFINE_G_KEYS(add_pin_hotkey)
336 DEFINE_G_KEYS(hierarchy_down_schematic)
337 DEFINE_G_KEYS(hierarchy_down_symbol)
338 DEFINE_G_KEYS(hierarchy_up)
339 DEFINE_G_KEYS(hierarchy_documentation)
340 DEFINE_G_KEYS(attributes_attach)
341 DEFINE_G_KEYS(attributes_detach)
342 DEFINE_G_KEYS(attributes_show_name)
343 DEFINE_G_KEYS(attributes_show_value)
344 DEFINE_G_KEYS(attributes_show_both)
345 DEFINE_G_KEYS(attributes_visibility_toggle)
347 /* i_callback_script_console is not currently implemented */
348 DEFINE_G_KEYS(script_console)
350 /* repeat last command doesn't make sense on options either??? (does
351 * it?) */
352 DEFINE_G_KEYS(options_text_size)
354 /* repeat last command doesn't make sense on options either??? (does
355 * it?) */
356 DEFINE_G_KEYS(options_afeedback)
357 DEFINE_G_KEYS(options_grid)
358 DEFINE_G_KEYS(options_snap)
359 DEFINE_G_KEYS(options_snap_size)
360 DEFINE_G_KEYS(options_scale_up_snap_size)
361 DEFINE_G_KEYS(options_scale_down_snap_size)
362 DEFINE_G_KEYS(options_rubberband)
363 DEFINE_G_KEYS(options_magneticnet)
364 DEFINE_G_KEYS(options_show_log_window)
365 DEFINE_G_KEYS(options_show_coord_window)
366 DEFINE_G_KEYS(misc)
367 DEFINE_G_KEYS(misc2)
368 DEFINE_G_KEYS(misc3)
370 DEFINE_G_KEYS(help_about)
371 DEFINE_G_KEYS(help_hotkeys)
373 /* be sure that you don't use the widget parameter in this one, since it is
374 being called with a null, I suppose we should call it with the right param.
375 hack */
376 DEFINE_G_KEYS(cancel)
379 /*! \todo Finish function documentation!!!
380 * \brief
381 * \par Function Description
384 /*help for generate-netlist hot key*/
385 SCM g_get_selected_filename(void)
387 return (get_selected_filename(global_window_current));
390 /*! \todo Finish function documentation!!!
391 * \brief
392 * \par Function Description
395 SCM g_get_selected_component_attributes(void)
397 return (get_selected_component_attributes(global_window_current));