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 libraries 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: stubs_c_file.c /main/3 1995/11/06 18:13:48 rswiston $
27 * @(#)stubs_c_file.c 3.48 11 Feb 1994 cde_app_builder/src/abmf
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 * Create a file containing callback proc stubs. These are example notify
45 * procedures that will serve as a template for the actual notify procedures
49 #include <sys/param.h>
55 #include <ab/util_types.h>
56 #include <ab_private/abio.h>
57 #include <ab_private/trav.h>
58 #include <ab_private/objxm.h>
60 #include "ui_header_fileP.h"
62 #include "motifdefsP.h"
63 #include "obj_namesP.h"
65 #include "instancesP.h"
69 #include "lib_func_stringsP.h"
70 #include "stubs_c_fileP.h"
72 typedef void *VoidPtr;
75 * Action argument type.
85 * REMIND: some time in the future, "instance" should be "dtbTarget"
87 static STRING fromVarName = "dtbSource";
88 static STRING toVarName = "dtbTarget";
89 static STRING instanceVarName = "instance";
94 static STRING begin_tt_callback_body =
96 %s(Tt_message msg, void *calldata)\n";
98 static STRING begin_ss_save_callback_body =
100 %s(Widget widget, String session_file, char ***argv, int *argc)\n";
102 static STRING begin_ss_restore_callback_body =
104 %s(Widget widget, char *session_file)\n";
109 static int printf_setval(GenCodeInfo, ABObj, ...);
110 static int printf_getval(GenCodeInfo, ABObj, int nres, ...);
111 static int write_tooltalk_cb_vars(GenCodeInfo genCodeInfo, ABObj action);
112 static int write_tooltalk_cb_body1(GenCodeInfo genCodeInfo, ABObj action);
113 static int write_tooltalk_cb_body2(GenCodeInfo genCodeInfo, ABObj action);
114 static int write_tooltalk_msg_reply(File codeFile);
115 static int write_ss_cb_vars(GenCodeInfo genCodeInfo, ABObj action);
116 static int write_ss_cb_body1(GenCodeInfo genCodeInfo, ABObj action);
117 static int write_ss_cb_body2(GenCodeInfo genCodeInfo, ABObj action);
118 static int write_instance_ptr_var(
119 GenCodeInfo genCodeInfo,
121 STRING instanceVarName,
127 static int write_builtin_action_for_ref(
128 GenCodeInfo genCodeInfo,
132 AB_BUILTIN_ACTION builtin_action,
133 STRING actionTKResource,
134 STRING actionResource
137 static int write_builtin_action(
138 GenCodeInfo genCodeInfo,
141 AB_BUILTIN_ACTION builtin_action,
142 STRING actionTKResource,
143 STRING actionResource
147 * Gets the object that the connection is "actually" from. If write_conn*
148 * is called on an object that has references to it, it's actually the
149 * references that have the connections, not the object, itself.
150 * (e.g., menus never have connections written, it's the menu references
154 get_actual_from_obj(ABObj actionOrObj)
156 static ABObj lastFromObj = NULL;
157 static ABObj lastActualFromObj = NULL;
158 AB_TRAVERSAL refTrav;
161 ABObj fromObj = NULL;
162 ABObj actualFromObj = NULL;
164 if (actionOrObj == NULL)
172 if (obj_is_action(actionOrObj))
174 fromObj = obj_get_from(actionOrObj);
176 else if (obj_is_ui(actionOrObj))
178 fromObj = actionOrObj;
182 * Shortcut, to avoid a lengthy traversal
184 if (fromObj == lastFromObj)
190 * See if we can do anything
196 module = obj_get_module(fromObj);
201 if ( (!obj_is_ref(fromObj))
202 && ( (obj_get_type(fromObj) == AB_TYPE_MENU)
203 || (obj_get_parent_of_type(fromObj, AB_TYPE_MENU) != NULL)) )
205 /* find an object that references this one, to
206 * get the appropriate type (only menu references are
207 * supported, currently).
209 for (trav_open(&refTrav, module, AB_TRAV_UI);
210 (refObj = trav_next(&refTrav)) != NULL; )
212 if (refObj->ref_to == fromObj)
217 trav_close(&refTrav);
220 if (actualFromObj == NULL)
224 actualFromObj = refObj;
228 actualFromObj = fromObj;
232 lastFromObj = fromObj;
233 lastActualFromObj = actualFromObj;
236 return lastActualFromObj;
241 cwd_is_dtbuilder_src_dir(void)
243 static BOOL initialized = FALSE;
244 static BOOL isSrcDir = FALSE;
249 isSrcDir = (util_paths_are_same_file(".", "../../src/ab"));
257 get_to_var_name(void)
259 return (cwd_is_dtbuilder_src_dir()? instanceVarName:toVarName);
264 get_from_var_name(void)
271 * Generate XtVaSetvalues calls in callbacks.
272 * obj is the object that will have it's resources set.
274 * Resource list must be name,value pairs, NULL-terminated
275 * All resource values must be of type (void *)
278 printf_setval(GenCodeInfo genCodeInfo, ABObj obj, ...)
280 int return_value = 0;
281 File codeFile = genCodeInfo->code_file;
282 #if defined(linux) || defined(CSRG_BASED)
283 /* Define va_list in <va_list.h> as structure of char ** and int
284 * Sun define va_list as void * */
285 va_list paramList = { 0, 0 };
287 va_list paramList = NULL;
289 STRING resName = NULL;
290 void *resValue = NULL;
291 STRING objCName = NULL;
292 ISTRING istrValue = NULL;
294 va_start(paramList, obj);
296 objCName = abmfP_get_c_name(genCodeInfo, obj);
297 abio_printf(codeFile, "\tXtVaSetValues(%s,", objCName);
298 abio_printf(codeFile, "\n\t\t");
300 while ((resName = va_arg(paramList, STRING)) != NULL)
302 resValue = va_arg(paramList, VoidPtr);
303 switch (abmfP_get_res_type(resName, obj))
308 case AB_ARG_XMSTRING:
309 istrValue = istr_create((STRING)resValue);
310 resValue = (VoidPtr)istrValue;
315 "Ignoring unsupported connection resource type: WIDGET\n");
318 abmfP_write_arg_val(genCodeInfo, FALSE, resName, resValue, obj);
319 abio_printf(codeFile, ",\n\t\t");
321 istr_destroy(istrValue);
324 abio_printf(codeFile, "NULL);");
332 * printf_getval - can only get one resource. This can be changed at a later
333 * date if need be. NOTE: We need to declare local variables in one pass,
334 * Then write out an XtVaGetValues on a second pass, if we ever want to get
335 * more that one value back.
338 printf_getval(GenCodeInfo genCodeInfo, ABObj obj, int nres,...)
340 int return_value = 0;
341 File codeFile = genCodeInfo->code_file;
345 STRING objCName = NULL;
346 nres = nres; /* avoid warning */
350 objCName = abmfP_get_c_name(genCodeInfo, obj);
351 resource = va_arg(ap, STRING);
352 type = va_arg(ap, ARG_TYPES);
354 /* Print the declaration */
359 abio_printf(codeFile, "\tint i;\n\n");
362 abio_printf(codeFile, "\tchar *str;\n\n");
366 abio_printf(codeFile, "\tXtVaGetValues(%s,\n\t\t%s, ", objCName, resource);
368 /* Print the local variable reference */
373 abio_printf(codeFile, "&i");
376 abio_printf(codeFile, "&str");
379 abio_printf(codeFile, ",\n\t\tNULL);\n");
386 set_up_user_type_variables(GenCodeInfo genCodeInfo, ABObj toObj)
388 File codeFile = genCodeInfo->code_file;
389 ABObj structObj = abmfP_obj_get_struct_obj(toObj);
390 ABObj winParent = NULL;
391 char winParentName[1024];
395 * Determine window parent of this popup
397 winParent = obj_get_win_parent(structObj);
398 if (winParent == NULL)
400 sprintf(winParentName, "%s()", abmfP_lib_get_toplevel_widget->name);
404 snprintf(winParentName, sizeof(winParentName), "%s", abmfP_get_c_name(genCodeInfo, winParent));
408 * REMIND: This is obsolete and should be removed!
410 if (cwd_is_dtbuilder_src_dir())
412 write_instance_ptr_var(genCodeInfo, toObj,
413 instanceVarName, abmfP_client_data_var_name, TRUE, NULL);
414 abio_puts(genCodeInfo->code_file, nlstr);
418 write_instance_ptr_var(genCodeInfo, toObj,
419 toVarName, abmfP_client_data_var_name, TRUE, NULL);
420 write_instance_ptr_var(genCodeInfo, toObj,
421 instanceVarName, toVarName, FALSE, "/* obsolete */");
422 abio_puts(genCodeInfo->code_file, nlstr);
424 abio_printf(codeFile, "if (!(%s->initialized))\n", get_to_var_name());
425 abmfP_write_c_block_begin(genCodeInfo);
426 abio_printf(codeFile, "%s(%s, %s);\n",
427 abmfP_get_init_proc_name(structObj),
430 abmfP_write_c_block_end(genCodeInfo);
435 write_instance_ptr_var(
436 GenCodeInfo genCodeInfo,
438 STRING instanceVarName,
444 FILE *codeFile = genCodeInfo->code_file;
450 abio_printf(genCodeInfo->code_file, "%s\t%s = ",
451 abmfP_get_c_struct_ptr_type_name(ipObj),
455 abio_printf(codeFile, "(%s)", abmfP_get_c_struct_ptr_type_name(ipObj));
458 abio_printf(codeFile, "%s;", paramName);
462 abio_printf(genCodeInfo->code_file, "\t%s", comment);
464 abio_puts(genCodeInfo->code_file, nlstr);
470 write_tooltalk_cb_vars(
471 GenCodeInfo genCodeInfo,
477 if (!genCodeInfo || !action)
480 codeFile = genCodeInfo->code_file;
482 switch(obj_get_when(action))
484 case AB_WHEN_TOOLTALK_QUIT:
485 abio_puts(codeFile, "int\t\tsilent = 0;\n");
486 abio_puts(codeFile, "int\t\tforce = 0;\n");
487 abio_puts(codeFile, "Boolean\t\tcancel = False;\n");
489 case AB_WHEN_TOOLTALK_GET_STATUS:
490 abio_puts(codeFile, "char\t\t*status_string = \"\";\n");
492 case AB_WHEN_TOOLTALK_PAUSE_RESUME:
493 abio_puts(codeFile, "Boolean\t\tsensitive = (Bool)calldata;\n");
494 abio_puts(codeFile, "Boolean\t\talready_set = False;\n");
496 case AB_WHEN_TOOLTALK_DO_COMMAND:
497 abio_puts(codeFile, "Tt_status\t\tstatus = TT_DESKTOP_ENOTSUP;\n");
498 abio_puts(codeFile, "char\t\t*command;\n");
499 abio_puts(codeFile, "char\t\t*result;\n");
508 write_tooltalk_cb_body1(
509 GenCodeInfo genCodeInfo,
515 if (!genCodeInfo || !action)
518 codeFile = genCodeInfo->code_file;
520 switch(obj_get_when(action))
522 case AB_WHEN_TOOLTALK_QUIT:
523 abio_puts(codeFile, "tt_message_arg_ival(msg, 0, &silent);\n");
524 abio_puts(codeFile, "tt_message_arg_ival(msg, 1, &force);\n");
525 abio_puts(codeFile,"\n");
526 abio_puts(codeFile, abmfP_comment_begin);
527 abio_puts(codeFile, abmfP_comment_continue);
529 "Process Quit request->\n");
530 abio_puts(codeFile, abmfP_comment_continue);
532 "if \"silent\" == 1, then the Quit should occur without\n");
533 abio_puts(codeFile, abmfP_comment_continue);
535 "notifying the user. If \"force\" == 1, then the user may\n");
536 abio_puts(codeFile, abmfP_comment_continue);
538 "be notified, but the Quit should not be cancellable.\n");
539 abio_puts(codeFile, abmfP_comment_continue);
541 "If \"silent\" == 0 and \"force\" == 0, then this Quit\n");
542 abio_puts(codeFile, abmfP_comment_continue);
544 "request may be cancelled, in which case \"cancel\" should\n");
545 abio_puts(codeFile, abmfP_comment_continue);
547 "be set to True in order send the \"failed\" reply.\n");
548 abio_puts(codeFile, abmfP_comment_continue);
550 "If the Quit request is honored (not cancelled), the\n");
551 abio_puts(codeFile, abmfP_comment_continue);
553 "application exit should not occur until after the request\n");
554 abio_puts(codeFile, abmfP_comment_continue);
556 "has been replied-to.\n");
557 abio_puts(codeFile, abmfP_comment_end);
560 case AB_WHEN_TOOLTALK_GET_STATUS:
561 abio_puts(codeFile, abmfP_comment_begin);
562 abio_puts(codeFile, abmfP_comment_continue);
564 "Process Get Status request->\n");
565 abio_puts(codeFile, abmfP_comment_continue);
567 "The application should assign \"status_string\" an appropriate\n");
568 abio_puts(codeFile, abmfP_comment_continue);
570 "string value reflecting the application's status.\n");
571 abio_puts(codeFile, abmfP_comment_end);
573 case AB_WHEN_TOOLTALK_PAUSE_RESUME:
574 abio_puts(codeFile, abmfP_comment_begin);
575 abio_puts(codeFile, abmfP_comment_continue);
577 "Process Pause/Resume request->\n");
578 abio_puts(codeFile, abmfP_comment_continue);
580 "If \"sensitive\" == False (Pause), then the application should\n");
581 abio_puts(codeFile, abmfP_comment_continue);
583 "set the sensitivity on all mapped shells to False. If\n");
584 abio_puts(codeFile, abmfP_comment_continue);
586 "\"sensitive\" == True (Resume), then the application should\n");
587 abio_puts(codeFile, abmfP_comment_continue);
589 "set the sensitivity on all mapped shells to True.n");
590 abio_puts(codeFile, abmfP_comment_continue);
592 "If the application is already in the requested state of\n");
593 abio_puts(codeFile, abmfP_comment_continue);
595 "sensitivity, then \"already_set\" should be set to True.\n");
596 abio_puts(codeFile, abmfP_comment_end);
598 case AB_WHEN_TOOLTALK_DO_COMMAND:
599 abio_puts(codeFile, "command = tt_message_arg_val(msg, 0);\n");
600 abio_puts(codeFile, "\n");
601 abio_puts(codeFile, abmfP_comment_begin);
602 abio_puts(codeFile, abmfP_comment_continue);
604 "Process Do_Command request->\n");
605 abio_puts(codeFile, abmfP_comment_continue);
607 "The application should execute the code defined by \"command\".\n");
608 abio_puts(codeFile, abmfP_comment_continue);
610 "If execution is successful, then \"status\" should be set to TT_OK,\n");
611 abio_puts(codeFile, abmfP_comment_continue);
613 "else set to the appropriate Tt_status value.\n");
614 abio_puts(codeFile, abmfP_comment_continue);
616 "If the command returns a result, then \"result\" should be set\n");
617 abio_puts(codeFile, abmfP_comment_continue);
619 "to the appropriate result string.\n");
620 abio_puts(codeFile, abmfP_comment_end);
625 abio_puts(codeFile, "\n");
631 write_tooltalk_cb_body2(
632 GenCodeInfo genCodeInfo,
638 if (!genCodeInfo || !action)
641 codeFile = genCodeInfo->code_file;
643 abio_puts(codeFile, "\n");
645 switch(obj_get_when(action))
647 case AB_WHEN_TOOLTALK_QUIT:
648 abio_puts(codeFile, "if (cancel == True)\n");
649 abio_indent(codeFile);
650 abio_puts(codeFile, "tttk_message_fail(msg, TT_DESKTOP_ECANCELED, 0, 1);\n");
651 abio_outdent(codeFile);
652 abio_puts(codeFile, "else\n");
653 abio_puts(codeFile, "{\n");
654 abio_indent(codeFile);
655 write_tooltalk_msg_reply(codeFile);
656 abio_puts(codeFile, "\n");
658 abmfP_write_c_comment(genCodeInfo, FALSE,
659 "Now that the Message has been replied, process Quit operation");
660 abmfP_write_user_code_seg(genCodeInfo, NULL);
661 abio_puts(codeFile, nlstr);
663 abio_outdent(codeFile);
664 abio_puts(codeFile, "}\n");
666 case AB_WHEN_TOOLTALK_GET_STATUS:
667 abio_puts(codeFile, "tt_message_arg_val_set(msg, 0, status_string);\n");
668 write_tooltalk_msg_reply(codeFile);
670 case AB_WHEN_TOOLTALK_PAUSE_RESUME:
671 abio_puts(codeFile, "if (already_set == True)\n");
672 abio_indent(codeFile);
673 abio_puts(codeFile, "tt_message_status_set(msg, TT_DESKTOP_EALREADY);\n");
674 abio_outdent(codeFile);
675 write_tooltalk_msg_reply(codeFile);
677 case AB_WHEN_TOOLTALK_DO_COMMAND:
678 abio_puts(codeFile, "tt_free(command);\n");
679 abio_puts(codeFile, "tt_message_status_set(msg, status);\n");
680 abio_puts(codeFile, "if (tt_is_err(status))\n");
681 abio_indent(codeFile);
682 abio_puts(codeFile, "tttk_message_fail(msg, status, 0, 1);\n");
683 abio_outdent(codeFile);
684 abio_puts(codeFile, "else\n");
685 abio_puts(codeFile, "{\n");
686 abio_indent(codeFile);
687 abio_puts(codeFile, "if (result != NULL)\n");
688 abio_indent(codeFile);
689 abio_puts(codeFile, "tt_message_arg_val_set(msg, 1, result);\n");
690 abio_outdent(codeFile);
691 write_tooltalk_msg_reply(codeFile);
692 abio_outdent(codeFile);
693 abio_puts(codeFile, "}\n");
699 abio_puts(codeFile, nlstr);
700 abmfP_write_user_code_seg(genCodeInfo, NULL);
701 abio_puts(codeFile, nlstr);
702 abio_puts(codeFile, "return True;\n");
708 write_tooltalk_msg_reply(
712 abio_puts(codeFile, "tt_message_reply(msg);\n");
713 abio_puts(codeFile, "tttk_message_destroy(msg);\n");
721 GenCodeInfo genCodeInfo,
727 if (!genCodeInfo || !action)
730 codeFile = genCodeInfo->code_file;
732 switch(obj_get_when(action))
734 case AB_WHEN_SESSION_SAVE:
735 case AB_WHEN_SESSION_RESTORE:
736 abio_puts(codeFile, "Boolean\t\tret_value = False;\n");
746 GenCodeInfo genCodeInfo,
752 if (!genCodeInfo || !action)
755 codeFile = genCodeInfo->code_file;
757 switch(obj_get_when(action))
759 case AB_WHEN_SESSION_RESTORE:
760 abio_puts(codeFile, abmfP_comment_begin);
761 abio_puts(codeFile, abmfP_comment_continue);
763 "Restore application state via session file.\n");
764 abio_puts(codeFile, abmfP_comment_continue);
766 "Use contents of \"session file\" to bring the application\n");
767 abio_puts(codeFile, abmfP_comment_continue);
769 "to the desired state.\n");
770 abio_puts(codeFile, abmfP_comment_continue);
772 "Set \"ret_value\" to True to indicate success.\n");
773 abio_puts(codeFile, abmfP_comment_end);
775 case AB_WHEN_SESSION_SAVE:
776 abio_puts(codeFile, abmfP_comment_begin);
777 abio_puts(codeFile, abmfP_comment_continue);
779 "Save application state in either session file and/or\n");
780 abio_puts(codeFile, abmfP_comment_continue);
782 "command line vector.\n");
783 abio_puts(codeFile, abmfP_comment_continue);
784 abio_puts(codeFile, "\n");
785 abio_puts(codeFile, abmfP_comment_continue);
788 abio_puts(codeFile, abmfP_comment_continue);
790 " Open the file \"session_file\"\n");
791 abio_puts(codeFile, abmfP_comment_continue);
793 " Write application state information into it\n");
794 abio_puts(codeFile, abmfP_comment_continue);
796 " Close the file\n");
797 abio_puts(codeFile, abmfP_comment_continue);
799 " Set \"ret_value\" to True\n");
800 abio_puts(codeFile, abmfP_comment_continue);
802 " (Setting \"ret_value\" to True is important if you are using\n");
803 abio_puts(codeFile, abmfP_comment_continue);
805 " session files! Do not set it to True if you are not using\n");
806 abio_puts(codeFile, abmfP_comment_continue);
808 " session files.)\n");
809 abio_puts(codeFile, abmfP_comment_continue);
810 abio_puts(codeFile, "\n");
811 abio_puts(codeFile, abmfP_comment_continue);
813 "Command line vector:\n");
814 abio_puts(codeFile, abmfP_comment_continue);
816 " Allocate an argv vector\n");
817 abio_puts(codeFile, abmfP_comment_continue);
819 " Fill it up with the appropriate strings\n");
820 abio_puts(codeFile, abmfP_comment_continue);
822 " Return the argv vector in \"argv\" i.e.\n");
823 abio_puts(codeFile, abmfP_comment_continue);
825 " \t*argv = my_new_argv;\n");
826 abio_puts(codeFile, abmfP_comment_continue);
828 " Return the size of the vector in argc\n");
829 abio_puts(codeFile, abmfP_comment_end);
834 abio_puts(codeFile, "\n");
841 GenCodeInfo genCodeInfo,
847 if (!genCodeInfo || !action)
850 codeFile = genCodeInfo->code_file;
852 abio_puts(codeFile, "\n");
853 abio_puts(codeFile, "return ret_value;\n");
859 write_action_functions(GenCodeInfo genCodeInfo, ABObj obj)
861 File codeFile = genCodeInfo->code_file;
862 static char msg[256],
866 ABObj fromObj = NULL; /* for error reports */
870 * Auto-named functions
872 for (trav_open(&trav, obj, AB_TRAV_ACTIONS_FOR_OBJ | AB_TRAV_MOD_SAFE), i = 0;
873 (action = trav_next(&trav)) != NULL; ++i)
875 if ( mfobj_has_flags(action, CGenFlagIsDuplicateDef)
876 || mfobj_has_flags(action, CGenFlagWriteDefToProjFile))
881 if (action->info.action.auto_named)
883 abmfP_write_action_function(genCodeInfo, action);
884 abio_puts(genCodeInfo->code_file, "\n");
887 /* don't close traversal, yet */
890 * User-named functions
892 for (trav_reset(&trav);
893 (action = trav_next(&trav)) != NULL; ++i)
895 if ( mfobj_has_flags(action, CGenFlagIsDuplicateDef)
896 || mfobj_has_flags(action, CGenFlagWriteDefToProjFile))
901 if (!(action->info.action.auto_named))
903 abmfP_write_action_function(genCodeInfo, action);
904 abio_puts(genCodeInfo->code_file, "\n");
914 * Write the callback proc stub file.
917 abmfP_write_stubs_c_file(
918 GenCodeInfo genCodeInfo,
923 File codeFile = genCodeInfo->code_file;
924 STRING errmsg = NULL;
925 ABObj win_obj = NULL;
926 ABObj project = obj_get_project(module);
927 char moduleHeaderFileName[MAX_PATH_SIZE];
928 char moduleName[MAX_PATH_SIZE];
934 abmfP_write_user_header_seg(genCodeInfo);
935 abio_puts(codeFile, nlstr);
937 sprintf(moduleName, "module %s", obj_get_name(module));
938 abmfP_write_file_header(
943 util_get_program_name(),
944 ABMF_MODIFY_USER_SEGS,
945 " * Contains: Module callbacks and connection functions"
952 strcpy(moduleHeaderFileName, abmfP_get_ui_header_file_name(module));
953 abmfP_write_c_system_include(genCodeInfo, "stdint.h");
954 abmfP_write_c_system_include(genCodeInfo, "stdio.h");
955 abmfP_write_c_system_include(genCodeInfo, "Xm/Xm.h");
956 abmfP_write_c_local_include(genCodeInfo,
957 abmfP_get_utils_header_file_name(module));
960 * Include project file if i18n is enabled. This file
961 * is needed for the message catalog stuff
963 if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
964 abmfP_write_c_local_include(genCodeInfo,
965 abmfP_get_project_header_file_name(project));
966 abmfP_write_c_local_include(genCodeInfo, moduleHeaderFileName);
970 * Write out includes for modules with connection targets
973 StringListRec connIncludes;
976 strlist_construct(&connIncludes);
978 strlist_add_str(&connIncludes, moduleHeaderFileName, NULL);
979 abmfP_get_connect_includes(&connIncludes, module);
980 num_strings = strlist_get_num_strs(&connIncludes);
981 if (num_strings > 1) /* start at 1 - skip this_ui.h */
983 abio_puts(codeFile, nlstr);
984 abmfP_write_c_comment(genCodeInfo, FALSE,
985 "Header files for cross-module connections");
987 for (i = 1; i < num_strings; ++i)
989 abio_printf(codeFile, "#include %s\n",
990 strlist_get_str(&connIncludes, i, NULL));
993 strlist_destruct(&connIncludes);
995 abio_puts(codeFile, nlstr);
997 abmfP_write_user_file_top_seg(genCodeInfo);
998 abio_puts(codeFile, nlstr);
1000 if (write_action_functions(genCodeInfo, module) != OK)
1003 abmfP_write_user_file_bottom_seg(genCodeInfo);
1009 abmfP_write_action_function(
1010 GenCodeInfo genCodeInfo,
1014 int rc = 0; /* return code */
1015 BOOL isTTCB = FALSE;
1017 File codeFile = genCodeInfo->code_file;
1018 BOOL topUserSegWritten = FALSE;
1019 BOOL bottomUserSegWritten = FALSE;
1020 BOOL funcBodyWritten = FALSE;
1021 BOOL funcEndWritten = FALSE;
1022 BOOL actionPrintfWritten = FALSE;
1023 int return_value = 0;
1024 ABObj fromObj = obj_get_from(action);
1025 ABObj actualFromObj = NULL;
1026 ABObj toObj = obj_get_to(action);
1027 ABObj module = NULL;
1028 char actionName[1024];
1029 char actionPrintf[1024];
1031 abmfP_gencode_enter_func(genCodeInfo);
1032 abmfP_ip_obj(genCodeInfo) = obj_get_to(action);
1033 util_strncpy(actionName, abmfP_get_action_name(action), 1024);
1034 sprintf(actionPrintf, "printf(\"action: %s()\\n\");\n", actionName);
1037 *** START OF FUNCTION
1040 switch (obj_get_when(action))
1042 case AB_WHEN_AFTER_CREATED:
1044 * post-create procs have the signature of an Xt Callback,
1045 * although they are called as conventional functions.
1047 fromObj = obj_get_from(action);
1048 actualFromObj = get_actual_from_obj(action);
1049 abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName);
1050 write_instance_ptr_var(genCodeInfo, actualFromObj,
1051 get_from_var_name(), "callData", TRUE, NULL);
1052 abio_puts(genCodeInfo->code_file, nlstr);
1056 case AB_WHEN_DRAGGED_FROM:
1058 abio_printf(genCodeInfo->code_file,
1059 abmfP_lib_default_dragCB->def, /* this is a format string */
1060 actionName,actionName,actionName,
1061 actionName,actionName, actionName);
1062 abio_puts(genCodeInfo->code_file, "\n\n");
1064 /* these are all in the "library" definition */
1065 topUserSegWritten = TRUE;
1066 bottomUserSegWritten = TRUE;
1067 funcBodyWritten = TRUE;
1068 funcEndWritten = TRUE;
1069 actionPrintfWritten = TRUE;
1073 case AB_WHEN_DROPPED_ON:
1075 abio_printf(genCodeInfo->code_file,
1076 abmfP_lib_default_dropCB->def, /* this is a format string */
1077 actionName,actionName,actionName,actionName);
1078 abio_puts(genCodeInfo->code_file, "\n\n");
1080 /* these are all in the "library" definition */
1081 topUserSegWritten = TRUE;
1082 bottomUserSegWritten = TRUE;
1083 funcBodyWritten = TRUE;
1084 funcEndWritten = TRUE;
1085 actionPrintfWritten = TRUE;
1089 case AB_WHEN_TOOLTALK_QUIT:
1090 case AB_WHEN_TOOLTALK_DO_COMMAND:
1091 case AB_WHEN_TOOLTALK_GET_STATUS:
1092 case AB_WHEN_TOOLTALK_PAUSE_RESUME:
1094 abio_printf(codeFile, begin_tt_callback_body, actionName);
1095 abmfP_write_c_block_begin(genCodeInfo);
1096 write_tooltalk_cb_vars(genCodeInfo, action);
1099 case AB_WHEN_SESSION_RESTORE:
1101 abio_printf(codeFile, begin_ss_restore_callback_body,
1102 abmfP_get_action_name(action));
1103 abmfP_write_c_block_begin(genCodeInfo);
1104 write_ss_cb_vars(genCodeInfo, action);
1107 case AB_WHEN_SESSION_SAVE:
1109 abio_printf(codeFile, begin_ss_save_callback_body,
1110 abmfP_get_action_name(action));
1111 abmfP_write_c_block_begin(genCodeInfo);
1112 write_ss_cb_vars(genCodeInfo, action);
1116 abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName);
1119 } /* switch obj_get_when() */
1123 ***** TOP USER SEGMENT
1126 if (!topUserSegWritten)
1129 (actionPrintfWritten? NULL:(isTTCB? actionPrintf:NULL));
1130 abmfP_write_user_var_and_code_seg(genCodeInfo, contents);
1131 abio_puts(codeFile, nlstr);
1132 topUserSegWritten = TRUE;
1133 if (contents != NULL)
1135 actionPrintfWritten = TRUE;
1145 write_tooltalk_cb_body1(genCodeInfo, action);
1146 abmfP_write_user_code_seg(genCodeInfo, NULL);
1147 write_tooltalk_cb_body2(genCodeInfo, action);
1148 funcBodyWritten = TRUE;
1149 bottomUserSegWritten = TRUE;
1153 write_ss_cb_body1(genCodeInfo, action);
1154 abmfP_write_user_code_seg(genCodeInfo, NULL);
1155 write_ss_cb_body2(genCodeInfo, action);
1156 funcBodyWritten = TRUE;
1157 bottomUserSegWritten = TRUE;
1159 else if (!funcBodyWritten) switch (obj_get_func_type(action))
1161 case AB_FUNC_BUILTIN:
1162 rc = abmfP_write_builtin_action(genCodeInfo, action, TRUE);
1163 return_if_err(rc,rc);
1164 funcBodyWritten = TRUE;
1167 case AB_FUNC_USER_DEF:
1168 abmfP_write_user_start_comment(genCodeInfo, "vvv Add C code below vvv");
1169 abmfP_write_user_end_comment(genCodeInfo, "^^^ Add C code above ^^^");
1170 bottomUserSegWritten = TRUE;
1171 funcBodyWritten = TRUE;
1174 case AB_FUNC_CODE_FRAG:
1175 abio_puts(codeFile, obj_get_func_code(action));
1176 funcBodyWritten = TRUE;
1179 case AB_FUNC_ON_ITEM_HELP:
1180 abio_printf(codeFile, "dtb_do_onitem_help();\n");
1181 funcBodyWritten = TRUE;
1184 case AB_FUNC_HELP_VOLUME:
1185 abio_printf(codeFile,
1186 "dtb_show_help_volume_info(\"%s\", \"%s\");\n",
1187 istr_string(action->info.action.volume_id),
1188 istr_string(action->info.action.location));
1189 funcBodyWritten = TRUE;
1194 char *obj_name_string = obj_get_name(fromObj);
1195 util_printf_err(catgets(Dtb_project_catd, 1, 78,
1196 "unknown function type for action from object, %s"),
1204 ***** BOTTOM USER SEGMENT
1207 if (!bottomUserSegWritten)
1209 STRING contents = (actionPrintfWritten? NULL:actionPrintf);
1210 abmfP_write_user_code_seg(genCodeInfo, contents);
1211 bottomUserSegWritten = TRUE;
1212 if (contents != NULL)
1214 actionPrintfWritten = TRUE;
1222 if (!funcEndWritten)
1224 abmfP_write_c_func_end(genCodeInfo, NULL);
1225 funcEndWritten = TRUE;
1229 abmfP_gencode_exit_func(genCodeInfo);
1230 return return_value;
1235 abmfP_write_builtin_action(
1236 GenCodeInfo genCodeInfo,
1241 int return_value = 0;
1242 File codeFile = genCodeInfo->code_file;
1244 STRING actionTKResource = NULL; /* in toolkit */
1245 STRING actionResource = NULL; /* in source code */
1246 ISTRING istr_resource = NULL;
1247 AB_BUILTIN_ACTION builtin_action = AB_STDACT_UNDEF;
1249 toObj = obj_get_to(action);
1250 builtin_action = obj_get_func_builtin(action);
1253 toObj = objxm_comp_get_target_for_builtin_action(toObj, builtin_action);
1257 abmfP_write_c_comment(genCodeInfo, FALSE, "Invalid action ignored.");
1258 abio_puts(codeFile, nlstr);
1263 * We need to convert the resource into a string that can be put
1266 actionTKResource = objxm_get_resource_for_builtin_action(
1267 toObj, builtin_action);
1268 istr_resource = objxm_get_res_strname(actionTKResource);
1269 actionResource = istr_string(istr_resource);
1271 if (abmfP_get_c_name(genCodeInfo, toObj) == NULL)
1273 return_value = write_builtin_action_for_ref(genCodeInfo,
1274 action, toObj, setUpVars, builtin_action, actionTKResource,
1281 set_up_user_type_variables(genCodeInfo, toObj);
1284 return_value = write_builtin_action(genCodeInfo, action, toObj,
1285 builtin_action, actionTKResource, actionResource);
1288 if (return_value == 0)
1289 abio_printf(codeFile, nlstr);
1292 abio_printf(codeFile, nlstr);
1293 return return_value;
1298 ** we are on a virtual object and need to write the actual builtin action
1299 ** for each ref to it.
1302 write_builtin_action_for_ref(
1303 GenCodeInfo genCodeInfo,
1307 AB_BUILTIN_ACTION builtin_action,
1308 STRING actionTKResource, /* in toolkit */
1309 STRING actionResource /* in source code */
1314 int return_value = 0;
1315 ABObj refObj = NULL;
1316 ABObjList refList = NULL;
1318 if (!genCodeInfo || !action || !toObj)
1321 refList = abmfP_find_refs_to(toObj);
1322 numRefs = objlist_get_num_objs(refList);
1324 if ((refList != NULL) && (numRefs > 0))
1328 refObj = objlist_get_obj(refList, 0, NULL);
1329 set_up_user_type_variables(genCodeInfo, refObj);
1332 /* write the builtin actions */
1333 for (i = 0; i < numRefs; ++i)
1335 refObj = objlist_get_obj(refList, i, NULL);
1337 if (abmfP_get_c_name(genCodeInfo, refObj) != NULL)
1339 return_value = write_builtin_action(genCodeInfo,
1340 action, refObj, builtin_action, actionTKResource,
1347 util_dprintf(0, "ERROR: write_builtin_action_for_ref(): ");
1348 util_dprintf(0, "Unable to obtain references to the object.\n");
1352 objlist_destroy(refList);
1353 return return_value;
1358 ** determine which builtin action and write the appropriate code.
1361 write_builtin_action(
1362 GenCodeInfo genCodeInfo,
1365 AB_BUILTIN_ACTION builtin_action,
1366 STRING actionTKResource, /* in toolkit */
1367 STRING actionResource /* in source code */
1370 #define IS(type) (obj_get_func_type(action) ==(type))
1371 #define SVAL(action) ((STRING)obj_get_arg_string(action))
1372 #define IVAL(action) ((int)obj_get_arg_int(action))
1374 File codeFile = genCodeInfo->code_file;
1375 int return_value = 0;
1377 if (!codeFile || !action || !toObj || !builtin_action)
1378 return return_value;
1380 switch (builtin_action)
1382 case AB_STDACT_ENABLE:
1383 abio_print_line(codeFile, NULL);
1384 abio_print_line(codeFile, "XtSetSensitive(%s, True);",
1385 abmfP_get_c_name(genCodeInfo, toObj));
1388 case AB_STDACT_DISABLE:
1389 abio_print_line(codeFile, NULL);
1390 abio_print_line(codeFile, "XtSetSensitive(%s, False);",
1391 abmfP_get_c_name(genCodeInfo, toObj));
1394 case AB_STDACT_SHOW:
1395 switch((obj_get_root(toObj))->type)
1397 case AB_TYPE_BASE_WINDOW:
1398 abio_print_line(codeFile, "XtPopup(%s, XtGrabNone);",
1399 abmfP_get_c_name(genCodeInfo, toObj));
1402 case AB_TYPE_DIALOG:
1403 case AB_TYPE_FILE_CHOOSER:
1405 abio_print_line(codeFile, "XtManageChild(%s);",
1406 abmfP_get_c_name(genCodeInfo, toObj));
1411 case AB_STDACT_HIDE:
1412 switch((obj_get_root(toObj))->type)
1414 case AB_TYPE_BASE_WINDOW:
1415 abio_print_line(codeFile, "XtPopdown(%s);",
1416 abmfP_get_c_name(genCodeInfo, toObj));
1419 case AB_TYPE_DIALOG:
1420 case AB_TYPE_FILE_CHOOSER:
1422 abio_print_line(codeFile, "XtUnmanageChild(%s);",
1423 abmfP_get_c_name(genCodeInfo, toObj));
1428 case AB_STDACT_SET_LABEL:
1429 /* check toObj for root */
1430 if ( obj_get_label_type(obj_get_root(toObj)) == AB_LABEL_GLYPH)
1432 abio_printf(codeFile, "%s(%s, ",
1433 abmfP_lib_set_label_from_image_file->name,
1434 abmfP_get_c_name(genCodeInfo, toObj));
1435 abio_put_string(codeFile, SVAL(action));
1436 abio_puts(codeFile, ");\n");
1440 assert(actionTKResource != NULL);
1441 printf_setval(genCodeInfo, toObj,
1442 actionTKResource, SVAL(action),
1447 case AB_STDACT_SET_VALUE:
1448 printf_setval(genCodeInfo, toObj,
1449 actionTKResource, IVAL(action), NULL);
1452 case AB_STDACT_SET_TEXT:
1453 printf_setval(genCodeInfo, toObj,
1454 actionTKResource, SVAL(action),
1458 /* case AB_STDACT_SHOW_HELP: */
1459 /* abio_print_line(codeFile, NULL); */
1460 /* abio_print_line(codeFile, */
1461 /* "XtCallCallbacks(%s,XmNhelpCallback,(XtPointer)NULL);", */
1462 /* abmfP_get_c_name(genCodeInfo, toObj)); */
1467 static char msg[255];
1469 if (obj_get_name(action) != NULL)
1471 char *action_name = obj_get_name(action);
1472 sprintf(msg, catgets(Dtb_project_catd, 1, 76,
1473 "Unknown action name, %s"), action_name);
1477 int action_type = obj_get_func_builtin(action);
1478 sprintf(msg, catgets(Dtb_project_catd, 1, 77,
1479 "Unknown action type, %d"), action_type);
1482 return_value = ERR_INTERNAL;
1485 * return msg; Just print message and go on - JT
1489 } /* switch func.value.builtin */
1491 return return_value;