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
24 * $XConsortium: bil_loadact.c /main/3 1995/11/06 18:24:00 rswiston $
26 * @(#)bil_loadact.c 1.47 02 Feb 1995
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 * billdact.c - load action and handler attributes
50 #include <ab_private/trav.h>
51 #include <ab_private/util.h>
52 #include <ab/util_types.h>
53 #include "../libABobj/obj_utils.h"
55 #include "bil_loadattP.h"
58 /*static int add_user_handler(ABObj obj, ABObj module,
59 ISTRING handler, AB_WHEN when);
60 static int install_action(ABObj obj, ABObj module, ABObj action);*/
62 static int install_action(ABObj obj, ABObj module, ABObj action);
64 static ABObj find_or_create_target(ABObj obj, ABObj module,
65 ISTRING parent_name, ISTRING name);
68 #define nset_att(a) (bilP_load_set_current_att(a))
70 /*************************************************************************
76 **************************************************************************/
80 * Get the source object.
83 bilP_load_att_from(BIL_TOKEN valueToken)
86 ABObj src_module = NULL;
87 STRING stringValue = bilP_load_get_value();
90 util_dprintf(4, "bilP_load_att_from: %d/%s\n",
92 str_safe(bilP_token_to_string(valueToken)));
95 nset_att(AB_BIL_FROM);
96 if (valueToken == AB_BIL_APPLICATION)
98 bilP_load.obj->info.action.from = bilP_load.project;
100 else if (valueToken == AB_BIL_VALUE_IDENT)
102 /* This will either find the correct ABObj for the connection
103 * source or it will create a proxy object for it. If the
104 * connection is a cross-module one, this will create both
105 * the source module and the source object if they have not
106 * yet been loaded into the tree. In this case, the dummy
107 * module and object will be handled when the bil file is
108 * read in and the name of the module is encountered. See
109 * bilP_load_att_name() in bil_loadatt.c.
111 newObj = obj_scoped_find_or_create_undef(bilP_load.module,
112 stringValue, AB_TYPE_UNKNOWN);
113 src_module = obj_get_module(newObj);
115 /* bilP_load.obj is the action created in bilP_load_att_class().
116 * If the connection is a cross-module one, it is stored off of
117 * the project object, otherwise it is stored off of the module.
119 bilP_load.obj->info.action.from = newObj;
121 else if (valueToken == AB_BIL_NIL)
126 abil_print_load_err(ERR_WANT_NAME);
133 * Get the destination object.
136 bilP_load_att_to(BIL_TOKEN valueToken)
139 STRING stringValue= bilP_load_get_value();
142 util_dprintf(3, "bilP_load_att_to: %d/%s\n",
144 str_safe(bilP_token_to_string(valueToken)));
149 if (valueToken == AB_BIL_VALUE_IDENT)
151 /* This will either find the correct ABObj for the connection
152 * source or it will create a proxy object for it. If the
153 * connection is a cross-module one, this will create both
154 * the source module and the source object if they have not
155 * yet been loaded into the tree. In this case, the dummy
156 * module and object will be handled when the bil file is
157 * read in and the name of the module is encountered. See
158 * bilP_load_att_name() in bil_loadatt.c.
160 toObj = obj_scoped_find_or_create_undef(bilP_load.module,
161 stringValue, AB_TYPE_UNKNOWN);
162 bilP_load.obj->info.action.to = toObj;
164 else if (valueToken == AB_BIL_NIL)
169 abil_print_load_err(ERR_WANT_NAME);
176 * Get the when part of a connection.
179 bilP_load_att_when(BIL_TOKEN valueToken)
181 AB_WHEN when= AB_WHEN_UNDEF;
184 util_dprintf(3, "bilP_load_att_when: %d/%s\n",
186 str_safe(bilP_token_to_string(valueToken)));
190 abil_loadmsg_set_att(":when");
192 nset_att(AB_BIL_WHEN);
194 when = bilP_token_to_when(valueToken);
195 if (when == AB_WHEN_UNDEF)
197 abil_print_load_err(ERR_WANT_NAME);
200 /* If the source object is a radiobox or
201 * checkbox item and the when is :activate,
202 * convert it to be :toggle. This is done
203 * to maintain backwards compatibility.
205 if (obj_is_choice_item(bilP_load.obj->info.action.from) &&
206 !obj_is_option_menu(obj_get_root(
207 obj_get_parent(bilP_load.obj->info.action.from))))
209 if (when == AB_WHEN_ACTIVATED)
210 when = AB_WHEN_TOGGLED;
212 bilP_load.obj->info.action.when = when;
218 * Get the action_type for an action holder
221 bilP_load_att_action_type(BIL_TOKEN valueToken)
223 AB_FUNC_TYPE func_type = bilP_token_to_func_type(valueToken);
225 util_dprintf(3, "bilP_load_att_action: %d/%s\n",
227 str_safe(bilP_token_to_string(valueToken)));
229 nset_att(AB_BIL_ACTION_TYPE);
230 if (func_type == AB_FUNC_UNDEF)
232 abil_print_load_err(ERR_UNKNOWN_OBJ);
235 obj_set_func_type(bilP_load.obj, func_type);
240 bilP_load_att_action(BIL_TOKEN valueToken)
242 STRING stringValue = bilP_load_get_value();
245 util_dprintf(3, "bilP_load_att_action: %d/%s\n",
247 str_safe(bilP_token_to_string(valueToken)));
250 nset_att(AB_BIL_ACTION);
252 /* Check if this is user defined */
253 if (valueToken == AB_BIL_VALUE_IDENT)
255 obj_set_func_name(bilP_load.obj, stringValue);
257 /* Check if this is execute code */
259 if (valueToken == AB_BIL_VALUE_STRING)
261 obj_set_func_code(bilP_load.obj, stringValue);
265 AB_BUILTIN_ACTION action = AB_STDACT_UNDEF;
266 action = bilP_token_to_builtin_action(valueToken);
267 obj_set_func_builtin(bilP_load.obj, action);
273 * Get the arg_type of an action_holder
276 bilP_load_att_arg_type(BIL_TOKEN valueToken)
278 AB_ARG_TYPE arg_type = bilP_token_to_arg_type(valueToken);
281 util_dprintf(3, "bilP_load_att_arg_type: %d/%s\n",
283 str_safe(bilP_token_to_string(valueToken)));
286 nset_att(AB_BIL_ARG_TYPE);
288 if (arg_type == AB_ARG_UNDEF)
290 abil_print_load_err(ERR_UNKNOWN_OBJ);
293 obj_set_arg_type(bilP_load.obj, arg_type);
299 install_action(ABObj obj, ABObj module, ABObj action)
301 ABObj oldaction= NULL;
302 ABObj project= obj_get_project(module);
305 * For efficiency, we check this module first to avoid searching
306 * the entire project unless necessary.
309 oldaction= obj_find_action(module, action);
310 if (oldaction == NULL)
312 oldaction= obj_find_action(project, action);
315 if (oldaction != NULL)
317 /* we've seen this action, before */
320 if (obj_get_module(action) != module)
323 * The action is in another module. Move
326 if (!obj_is_project(action->parent))
328 obj_unparent(action);
329 obj_add_action(project, action);
335 /* insert it into the current module */
336 obj_add_action(module, action);
345 * Finds the target matching the given description, creating it if necessary.
347 * Assumes: strings are pointers to allocated space. Sets strings to NULL,
348 * if the values are used.
350 * Assumes that obj may not be in the object tree yet, and may return
354 find_or_create_target(ABObj obj, ABObj module,
358 STRING target_parent_name[256];
359 STRING target_name[256];
360 ABObj target_parent= NULL;
363 /* util_dprintf(3, "find_or_create_target('%s' '%s' '%s')\n",
364 nullstr(parent_name),
365 nullstr(obj_name), nullstr(item_label)); */
367 *target_parent_name= 0;
369 if (obj_name == NULL)
373 if (parent_name != NULL)
375 /* we have parent name and object name */
376 strcpy((STRING)target_parent_name, istr_string(parent_name));
377 strcpy((STRING)target_name, istr_string(obj_name));
381 /* object name only (what a concept!) */
382 strcpy((STRING)target_name, istr_string(obj_name));
388 if (*target_parent_name == 0)
390 target_parent= module;
394 if (istr_equalstr(obj->name, (STRING)target_parent_name))
400 target_parent= obj_scoped_find_or_create_undef(module,
401 (STRING)target_parent_name,
409 if (istr_equalstr(obj->name, (STRING)target_name))
415 target= obj_scoped_find_or_create_undef(target_parent,
416 (STRING)target_name, AB_TYPE_UNKNOWN);
423 bilP_load_att_arg_value(BIL_TOKEN valueToken)
425 STRING stringValue = bilP_load_get_value();
428 util_dprintf(3, "bilP_load_att_arg_value: %d/%s\n",
430 str_safe(bilP_token_to_string(valueToken)));
433 nset_att(AB_BIL_ARG_VALUE);
435 /* Check if arg is an integer */
436 if (valueToken == AB_BIL_VALUE_INT)
439 util_dprintf(0, "\targ is an int = %d\n", atoi(stringValue));
441 obj_set_arg_int(bilP_load.obj, atoi(stringValue));
443 /* Check if arg is a float */
445 if (valueToken == AB_BIL_VALUE_FLOAT)
448 fval = (float) atof(stringValue);
450 util_dprintf(3, "\targ is a float = %f\n", fval);
452 obj_set_arg_float(bilP_load.obj, fval);
455 if (valueToken == AB_BIL_VALUE_STRING)
457 ISTRING istringValue = bilP_get_string();
459 util_dprintf(3, "\targ is an istring = %s\n", istr_string(istringValue));
461 obj_set_arg_string(bilP_load.obj, stringValue);