2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
25 * $XConsortium: gil_loadact.c /main/3 1995/11/06 18:27:51 rswiston $
27 * @(#)gil_loadact.c 1.20 13 Feb 1994 cde_app_builder/src/libABil
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special restrictions in a
32 * confidential disclosure agreement between HP, IBM, Sun, USL, SCO and
33 * Univel. Do not distribute this document outside HP, IBM, Sun, USL, SCO,
34 * or Univel without Sun's specific written approval. This document and all
35 * copies and derivative works thereof must be returned or destroyed at Sun's
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 * loadact.c - load action and handler attributes
50 #include <sys/param.h>
52 #include <ab_private/obj.h>
53 #include <ab_private/abio.h>
54 #include <ab_private/trav.h>
55 #include <ab_private/util.h>
56 #include <ab_private/istr.h>
57 #include "../libABobj/obj_utils.h"
62 #include "gil_loadattP.h"
64 static int get_action(
70 static int get_action_attribute(
94 static int get_operation(FILE * inFile, ABObj action);
95 static int get_function_type(FILE * inFile, ABObj action);
96 static int get_arg_type(FILE * inFile, ABObj action);
97 static int add_user_handler(ABObj obj, ABObj module,
98 ISTRING handler, AB_WHEN when);
99 static int install_action(
104 static ABObj find_or_create_target(
107 ISTRING interface_name,
113 /*************************************************************************
115 ** Specific handlers **
117 **************************************************************************/
122 gilP_load_att_done_handler(FILE * inFile, ABObj obj, ABObj module)
124 int return_value = 0;
125 int rc = 0; /* r turn code */
126 ISTRING handler = NULL;
129 if ((rc = gilP_load_handler(inFile, &handler)) < 0)
135 * I don't know what this a DONE when signifies. It doesn't exist in BIL
136 * add_user_handler(obj, module, handler, AB_WHEN_DONE);
138 abil_print_load_err(ERR_NOT_IMPL);
140 istr_destroy(handler);
145 gilP_load_att_event_handler(FILE * inFile, ABObj obj, ABObj module)
147 int return_value = 0;
148 int rc = 0; /* r turn code */
149 ISTRING event_handler = NULL;
151 if ((rc = gilP_load_handler(inFile, &event_handler)) < 0)
153 istr_destroy(event_handler);
158 * Doesn't exist in BIL add_user_handler(obj, module, event_handler,
159 * AB_WHEN_ANY_EVENT);
161 abil_print_load_err(ERR_NOT_IMPL);
162 istr_destroy(event_handler);
169 gilP_load_att_menu_handler(FILE * inFile, ABObj obj, ABObj module)
171 int return_value = 0;
172 int rc = 0; /* r turn code */
173 ISTRING handler = NULL;
175 if ((rc = gilP_load_handler(inFile, &handler)) < 0)
179 add_user_handler(obj, module, handler, AB_WHEN_ACTIVATED);
180 istr_destroy(handler);
187 gilP_load_att_menu_item_handlers(FILE * inFile, ABObj obj, ABObj module)
189 int return_value = 0;
190 int rc = 0; /* r turn code */
191 ISTRING_ARRAY handlers;
196 istr_array_init(&handlers);
197 if ((rc = gilP_load_handlers(inFile, &handlers)) < 0)
201 obj_ensure_num_children(obj, handlers.count);
202 for (trav_open(&trav, obj, AB_TRAV_ITEMS_FOR_OBJ), i = 0;
203 (item = trav_next(&trav)) != NULL; ++i)
205 add_user_handler(item, module,
206 handlers.strings[i], AB_WHEN_ACTIVATED);
207 handlers.strings[i] = NULL;
210 istr_array_uninit(&handlers);
217 gilP_load_att_notify_handler(FILE * inFile, ABObj obj, ABObj module)
219 int return_value = 0;
220 int rc = 0; /* r turn code */
221 ISTRING handler = NULL;
223 if ((rc = gilP_load_handler(inFile, &handler)) < 0)
227 add_user_handler(obj, module, handler, AB_WHEN_ACTIVATED);
229 istr_destroy(handler);
236 gilP_load_att_repaint_proc(FILE * inFile, ABObj obj, ABObj module)
238 int return_value = 0;
239 int rc = 0; /* r turn code */
240 ISTRING repaint = NULL;
242 if ((rc = gilP_load_handler(inFile, &repaint)) < 0)
246 add_user_handler(obj, module, repaint, AB_WHEN_REPAINT_NEEDED);
248 istr_destroy(repaint);
253 /*************************************************************************
256 ** General actions **
259 **************************************************************************/
263 * Load the actions attributes
266 gilP_load_att_actions(FILE * inFile, ABObj obj, ABObj module)
268 int return_value = 0;
269 int rc = 0; /* r turn code */
272 if (!abio_get_list_begin(inFile))
273 return (abil_print_load_err(ERR_WANT_LIST), -1);
275 while (!abio_get_list_end(inFile))
277 action = obj_create(AB_TYPE_ACTION, NULL);
279 if ((rc = get_action(inFile, obj, module, action)) < 0)
286 if (obj_get_when(action) == AB_WHEN_UNDEF)
288 /* unsupported :when value - ignore it and continue */
293 install_action(obj, module, action);
312 int return_value = 0;
313 int rc = 0; /* r turn code */
315 AB_GIL_ATTRIBUTE action_attr;
317 if (!abio_get_list_begin(inFile))
318 return (abil_print_load_err(ERR_WANT_LIST), -1);
320 while (!abio_get_list_end(inFile))
322 if (abio_get_eof(inFile))
324 abil_print_load_err(ERR_EOF);
328 if (!abio_get_keyword(inFile, &keyword))
330 abil_print_load_err(ERR_WANT_KEYWORD);
334 action_attr = gilP_string_to_att(istr_string(keyword));
335 if ((rc = get_action_attribute(inFile, obj, module,
336 action, action_attr))
342 abil_loadmsg_set_action_att(NULL);
344 abil_loadmsg_set_action_att(NULL);
351 * Load one action attribute.
354 get_action_attribute(
359 AB_GIL_ATTRIBUTE attr
362 int return_value = 0;
363 int rc = 0; /* r turn code */
365 if (abio_get_eof(inFile))
367 return (abil_print_load_err(ERR_EOF), -1);
373 rc = get_from(inFile, obj, module, action);
376 rc = get_operation(inFile, action);
379 rc = get_to(inFile, obj, module, action);
382 rc = get_when(inFile, obj, action);
384 case AB_GIL_FUNCTION_TYPE:
385 rc = get_function_type(inFile, action);
387 case AB_GIL_ARG_TYPE:
388 rc = get_arg_type(inFile, action);
391 abil_print_load_err(ERR_UNKNOWN);
398 * Get the source object.
401 get_from(FILE * inFile, ABObj obj, ABObj module, ABObj action)
403 int return_value = 0;
404 int rc = 0; /* r turn code */
405 ISTRING interface_name = NULL;
406 ISTRING parent_name = NULL;
408 ISTRING item_name = NULL;
411 if ( (abio_gil_get_full_name(inFile,
412 &interface_name, &parent_name, &name, &item_name) < 0)
415 abil_print_load_err(ERR_WANT_FULL_NAME);
420 from = find_or_create_target(obj, module,
421 interface_name, parent_name, name, item_name);
425 rc = abil_print_load_err(ERR_UNKNOWN_OBJECT);
429 obj_set_from(action, from);
432 istr_destroy(parent_name);
434 istr_destroy(item_name);
440 * Get the destination object.
443 get_to(FILE * inFile, ABObj obj, ABObj module, ABObj action)
445 int return_value = 0;
446 int rc = 0; /* r turn code */
447 ISTRING interface_name = NULL;
448 ISTRING parent_name = NULL;
450 ISTRING item_name = NULL;
453 if ( (abio_gil_get_full_name(inFile,
454 &interface_name, &parent_name, &name, &item_name) < 0)
457 abil_print_load_err(ERR_WANT_FULL_NAME);
462 to = find_or_create_target(obj, module,
463 interface_name, parent_name, name, item_name);
467 rc = abil_print_load_err(ERR_UNKNOWN_OBJECT);
471 action->info.action.to = to;
474 istr_destroy(parent_name);
476 istr_destroy(item_name);
485 get_operation(FILE * inFile, ABObj action)
487 int return_value = 0;
488 int rc = 0; /* r turn code */
489 ISTRING string = NULL;
493 if (!abio_get_list_begin(inFile))
495 return (abil_print_load_err(ERR_WANT_LIST), -1);
498 switch (obj_get_func_type(action))
500 case AB_FUNC_CODE_FRAG: /* code fragment */
501 if (!abio_get_string(inFile, &string))
503 rc = abil_print_load_err(ERR_WANT_STRING);
506 obj_set_func_code(action, istr_string(string));
509 case AB_FUNC_USER_DEF: /* function name (user defined) */
510 if (!abio_gil_get_name(inFile, &name))
512 rc = abil_print_load_err(ERR_WANT_NAME);
515 obj_set_func_name(action, istr_string(name));
518 case AB_FUNC_BUILTIN: /* predefined function */
519 if (!abio_gil_get_name(inFile, &name))
521 return (abil_print_load_err(ERR_WANT_NAME), -1);
523 obj_set_func_builtin(action,
524 gilP_string_to_builtin_action(istr_string(name)));
526 if (obj_get_func_builtin(action) != AB_STDACT_UNDEF)
528 if (abio_get_list_end(inFile))
531 switch (obj_get_arg_type(action))
534 if (!abio_get_string(inFile, &string))
535 return (abil_print_load_err(ERR_WANT_STRING), -1);
536 obj_set_arg_string(action, istr_string(string));
539 if (!abio_get_integer(inFile, &intval))
540 return (abil_print_load_err(ERR_WANT_INTEGER), -1);
541 obj_set_arg_int(action, intval);
544 rc = abil_print_load_err(ERR_UNKNOWN);
547 rc = abil_print_load_err(ERR_WANT_ARG);
564 if (!abio_get_list_end(inFile))
566 return (abil_print_load_err(ERR_WANT_LIST), -1);
571 istr_destroy(string);
577 * Get the when part of a connection.
580 get_when(FILE * inFile, ABObj obj, ABObj action)
582 int return_value = 0;
583 ISTRING string = NULL;
584 AB_WHEN when = AB_WHEN_UNDEF;
587 if (!abio_get_list_begin(inFile))
588 return (abil_print_load_err(ERR_WANT_LIST), -1);
590 while (!abio_get_list_end(inFile))
592 if (!abio_gil_get_name(inFile, &string))
593 return (abil_print_load_err(ERR_WANT_NAME), -1);
595 when = gilP_string_to_when(istr_string(string));
596 if (when == AB_WHEN_UNDEF)
598 if (util_be_verbose())
600 util_printf("WARNING: ignoring unsupported when: %s\n",
601 istr_string(string));
606 obj_set_when(action, when);
607 istr_destroy(string);
612 "WARNING: multiple :when values not supported. "
613 "Using first value\n");
621 * Get the function_type for an action holder
624 get_function_type(FILE * inFile, ABObj action)
626 int return_value = 0;
627 ISTRING type_name = NULL;
629 if (!abio_gil_get_name(inFile, &type_name))
631 return (abil_print_load_err(ERR_WANT_KEYWORD), -1);
634 if (istr_equalstr(type_name, "ExecuteCode"))
636 obj_set_func_type(action, AB_FUNC_CODE_FRAG);
638 else if (istr_equalstr(type_name, ":user_defined"))
640 /* yes, :user_defined in GIL means a builtin action */
641 obj_set_func_type(action, AB_FUNC_BUILTIN);
643 else if (istr_equalstr(type_name, "CallFunction"))
645 obj_set_func_type(action, AB_FUNC_USER_DEF);
649 return (abil_print_load_err(ERR_WANT_KEYWORD), -1);
652 istr_destroy(type_name);
658 * Get the arg_type of an action_holder
661 get_arg_type(FILE * inFile, ABObj action)
663 int return_value = 0;
664 ISTRING type_name = NULL;
666 obj_set_arg_type(action, AB_ARG_VOID_PTR);
668 if (!abio_get_list_begin(inFile))
669 return (abil_print_load_err(ERR_WANT_LIST), -1);
671 if (abio_get_list_end(inFile))
676 while (!abio_get_list_end(inFile))
678 if (!abio_gil_get_name(inFile, &type_name))
679 return (abil_print_load_err(ERR_WANT_NAME), -1);
681 obj_set_arg_type(action,
682 gilP_string_to_arg_type(istr_string(type_name)));
690 add_user_handler(ABObj obj, ABObj module,
691 ISTRING handler, AB_WHEN when)
694 ABObj project = NULL;
701 project = obj_get_project(module);
704 * With "callbacks," the to field is irrelevant. The target is generally
705 * whatever widget calls the callback, so we set the "to" field to NULL,
706 * so that this action may be used by multiple widgets. I.e., if the
707 * function type, name and to fields match, an action will be shared.
709 action = obj_create(AB_TYPE_ACTION, NULL);
710 obj_set_func_type(action, AB_FUNC_USER_DEF);
711 obj_set_func_name(action, istr_string(handler));
712 obj_set_arg_type(action, AB_ARG_VOID_PTR);
713 action->info.action.to = NULL;
715 obj_set_from(action, obj);
716 obj_set_when(action, when);
718 install_action(obj, module, action);
724 install_action(ABObj obj, ABObj module, ABObj action)
726 int return_value = 0;
729 * Cross-module connections sit under the project
730 * intra-module connectoins sit under the module
732 return_value = obj_add_action(module, action);
739 * Finds the target matching the given description, creating it if necessary.
741 * Assumes: strings are pointers to allocated space. Sets strings to NULL, if
742 * the values are used.
744 * Assumes that obj may not be in the object tree yet, and may return it as the
748 find_or_create_target(
751 ISTRING interface_name,
757 ABObj target = NULL; /* the real thing, baby! */
758 ABObj target_project = NULL;
759 char target_interface_file[MAXPATHLEN+1];
760 char target_interface_name[GIL_MAX_NAME_SIZE];
761 ABObj target_module = NULL;
762 char target_parent_name[GIL_MAX_NAME_SIZE];
763 ABObj target_parent = NULL;
764 char target_obj_name[GIL_MAX_NAME_SIZE];
765 ABObj target_obj = NULL;
766 char target_item_label[GIL_MAX_NAME_SIZE];
767 ABObj target_item = NULL;
769 *target_interface_file = 0;
770 *target_interface_name = 0;
771 *target_parent_name = 0;
772 *target_obj_name = 0;
773 *target_item_label = 0;
775 /* must have object name */
778 assert( (obj_name != NULL)
779 && (obj_is_project(module) || obj_is_module(module)));
782 if (obj_is_project(module))
784 /* The first string must be an interface file name */
785 if (interface_name != NULL)
787 util_strncpy(target_interface_file, istr_string(interface_name),
789 if (parent_name != NULL)
791 util_strncpy(target_parent_name, istr_string(parent_name),
795 else if (parent_name != NULL)
797 util_strncpy(target_interface_file, istr_string(parent_name),
802 abil_print_load_err(ERR_WANT_FULL_NAME);
806 /* derive the name from the file name */
807 strcpy(target_interface_name, target_interface_file);
809 int len = strlen(target_interface_name);
811 && ( util_streq(&(target_interface_name[len-2]), ".G")
812 || util_streq(&(target_interface_name[len-2]), ".P")))
814 target_interface_name[len-2] = 0;
818 util_strncpy(target_obj_name, istr_string(obj_name),
820 if (item_label != NULL)
822 util_strncpy(target_item_label, istr_string(item_label),
826 else /* ! obj_is_project() */
828 if (parent_name != NULL)
830 /* we have parent name and object name */
831 util_strncpy(target_parent_name, istr_string(parent_name),
835 util_strncpy(target_obj_name, istr_string(obj_name),
837 if (item_label != NULL)
839 /* we have object name and item_label */
840 util_strncpy(target_item_label, istr_string(item_label),
846 * We've got the name broken down into the appropriate pieces.
847 * Now find the actual target.
849 /*util_dprintf(3, "finding: module:'%s' parent:'%s' obj:'%s' item:'%s'\n",
850 target_interface_name, target_parent_name,
851 target_obj_name, target_item_label);*/
855 * Find target project
857 target_project = obj_get_project(module);
862 if (util_strempty(target_interface_name))
864 target_module = module;
868 /* find specified intefarce (module) */
869 for (trav_open(&trav, target_project, AB_TRAV_MODULES);
870 (target_module = trav_next(&trav)) != NULL; )
872 if ( (target_module != target_project)
874 obj_get_file(target_module), target_interface_file)))
880 if (target_module == NULL)
882 target_module = obj_create(AB_TYPE_MODULE, target_project);
883 obj_set_is_defined(target_module, FALSE);
884 obj_set_file(target_module, target_interface_file);
885 obj_set_name(target_module, target_interface_name);
892 if (util_strempty(target_parent_name))
894 target_parent = target_module;
898 for (trav_open(&trav, target_module,
899 AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
900 (target_parent = trav_next(&trav)) != NULL; )
902 if ( (target_parent != target_module)
904 obj_get_name(target_parent), target_parent_name)))
910 if (target_parent == NULL)
912 target_parent = obj_create(AB_TYPE_UNDEF, target_module);
913 obj_set_is_defined(target_parent, FALSE);
914 obj_set_file(target_parent, target_interface_file);
915 obj_set_name(target_parent, target_parent_name);
922 for (trav_open(&trav, target_parent,
923 AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
924 (target_obj = trav_next(&trav)) != NULL; )
926 if ( (target_obj != target_parent)
927 && util_streq(target_obj_name, obj_get_name(target_obj)))
933 if (target_obj == NULL)
935 target_obj = obj_create(AB_TYPE_UNDEF, target_parent);
936 obj_set_is_defined(target_obj, FALSE);
937 obj_set_file(target_obj, target_interface_file);
938 obj_set_name(target_obj, target_obj_name);
944 if (util_strempty(target_item_label))
950 for (trav_open(&trav, target_obj, AB_TRAV_ITEMS);
951 (target_item = trav_next(&trav)) != NULL; )
953 if ( (target_item != target_obj)
954 && util_streq(obj_get_label(target_item), target_item_label))
960 if (target_item == NULL)
962 target_item = obj_create(AB_TYPE_ITEM, target_obj);
963 obj_set_is_defined(target_item, FALSE);
964 obj_set_file(target_item, target_interface_file);
965 obj_set_label(target_item, target_item_label);
966 obj_set_name_from_label(target_item,
967 obj_get_name(obj_get_parent(target_item)));
971 if (target_item != NULL)
973 target = target_item;