home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / VarCreate.c.orig < prev    next >
Encoding:
Text File  |  1993-07-21  |  9.3 KB  |  391 lines

  1. /* $XConsortium: VarCreate.c,v 1.24 91/12/10 18:57:25 converse Exp $ */
  2.  
  3. /*
  4.  
  5. Copyright 1985, 1986, 1987, 1988, 1989 by the
  6. Massachusetts Institute of Technology
  7.  
  8. Permission to use, copy, modify, and distribute this
  9. software and its documentation for any purpose and without
  10. fee is hereby granted, provided that the above copyright
  11. notice appear in all copies and that both that copyright
  12. notice and this permission notice appear in supporting
  13. documentation, and that the name of M.I.T. not be used in
  14. advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16. M.I.T. makes no representations about the suitability of
  17. this software for any purpose.  It is provided "as is"
  18. without express or implied warranty.
  19.  
  20. */
  21.  
  22. #include "IntrinsicI.h"
  23. #include <X11/StringDefs.h>
  24. #include <X11/Shell.h>
  25. #include "VarargsI.h"
  26.  
  27. #if (defined(SUNSHLIB) || defined(AIXSHLIB)) && defined(SHAREDCODE)
  28. #define XtToolkitInitialize _XtToolkitInitialize
  29. #endif /* (SUNSHLIB || AIXSHLIB) && SHAREDCODE */
  30.  
  31. extern Widget _XtCreateWidget();
  32. extern Widget _XtAppCreateShell();
  33. extern Widget _XtCreatePopupShell();
  34.  
  35. static Widget
  36. _XtVaCreateWidget(name, widget_class, parent, var, count)
  37.     String      name;
  38.     WidgetClass widget_class;
  39.     Widget      parent;
  40.     va_list     var;
  41.     int        count;
  42. {
  43.     register Widget         widget;
  44.     XtTypedArgList        typed_args = NULL;
  45.     Cardinal            num_args;
  46.  
  47.     _XtVaToTypedArgList(var, count, &typed_args, &num_args);
  48.  
  49.     widget = _XtCreateWidget(name, widget_class, parent, (ArgList)NULL, 
  50.             (Cardinal)0, typed_args, num_args);
  51.  
  52.     if (typed_args != NULL) {
  53.         XtFree((XtPointer)typed_args);
  54.     }    
  55.  
  56.     return(widget);
  57. }
  58.  
  59.  
  60. #if NeedVarargsPrototypes
  61. Widget
  62. XtVaCreateWidget(
  63.     _Xconst char* name,
  64.     WidgetClass widget_class,
  65.     Widget parent,
  66.     ...)
  67. #else
  68. /*VARARGS3*/
  69. Widget XtVaCreateWidget(name, widget_class, parent, va_alist)
  70.     String name;
  71.     WidgetClass widget_class;
  72.     Widget parent;
  73.     va_dcl
  74. #endif
  75. {
  76.     va_list                 var;
  77.     register Widget         widget;
  78.     int                total_count, typed_count;
  79.  
  80.     Va_start(var,parent);
  81.     _XtCountVaList(var, &total_count, &typed_count);
  82.     va_end(var);
  83.  
  84.     Va_start(var,parent);
  85.     widget = _XtVaCreateWidget(name, widget_class, parent, var, total_count);
  86.     va_end(var);
  87.  
  88.     return(widget);
  89. }
  90.  
  91.  
  92. #if NeedVarargsPrototypes
  93. Widget
  94. XtVaCreateManagedWidget(
  95.     _Xconst char* name,
  96.     WidgetClass widget_class,
  97.     Widget parent,
  98.     ...)
  99. #else
  100. /*VARARGS3*/
  101. Widget XtVaCreateManagedWidget(name, widget_class, parent, va_alist)
  102.     String name;
  103.     WidgetClass widget_class;
  104.     Widget parent;
  105.     va_dcl
  106. #endif
  107. {
  108.     va_list        var;
  109.     register Widget    widget;
  110.     int            total_count, typed_count;
  111.  
  112.     Va_start(var,parent);
  113.     _XtCountVaList(var, &total_count, &typed_count);
  114.     va_end(var);
  115.  
  116.     Va_start(var,parent);
  117.     widget = _XtVaCreateWidget(name, widget_class, parent, var, total_count);
  118.     XtManageChild(widget);
  119.     va_end(var);
  120.  
  121.     return (widget);
  122. }
  123.  
  124.  
  125. #if NeedVarargsPrototypes
  126. Widget
  127. XtVaAppCreateShell(
  128.     _Xconst char* name,
  129.     _Xconst char* class,
  130.     WidgetClass widget_class,
  131.     Display* display,
  132.     ...)
  133. #else
  134. /*VARARGS4*/
  135. Widget XtVaAppCreateShell(name, class, widget_class, display, va_alist)
  136.     String name;
  137.     String class;
  138.     WidgetClass widget_class;
  139.     Display* display;
  140.     va_dcl
  141. #endif
  142. {
  143.     va_list                 var;
  144.     register Widget         widget;
  145.     XtTypedArgList          typed_args = NULL;
  146.     Cardinal                num_args;
  147.     int                total_count, typed_count;
  148.  
  149.     Va_start(var,display);
  150.     _XtCountVaList(var, &total_count, &typed_count);
  151.     va_end(var);
  152.  
  153.     Va_start(var,display);
  154.  
  155.     _XtVaToTypedArgList(var, total_count, &typed_args, &num_args);
  156.     widget = _XtAppCreateShell(name, class, widget_class, display,
  157.         (ArgList)NULL, (Cardinal)0, typed_args, num_args);
  158.     if (typed_args != NULL) {
  159.     XtFree((XtPointer)typed_args);
  160.     }
  161.  
  162.     va_end(var);
  163.     return(widget);
  164. }
  165.  
  166.  
  167. #if NeedVarargsPrototypes
  168. Widget
  169. XtVaCreatePopupShell(
  170.     _Xconst char* name,
  171.     WidgetClass widget_class,
  172.     Widget parent,
  173.     ...)
  174. #else
  175. /*VARARGS3*/
  176. Widget XtVaCreatePopupShell(name, widget_class, parent, va_alist)
  177.     String name;
  178.     WidgetClass widget_class;
  179.     Widget parent;
  180.     va_dcl
  181. #endif
  182. {
  183.     va_list                 var;
  184.     register Widget         widget;
  185.     XtTypedArgList          typed_args = NULL;
  186.     Cardinal                num_args;
  187.     int                total_count, typed_count;
  188.  
  189.     Va_start(var,parent);
  190.     _XtCountVaList(var, &total_count, &typed_count);
  191.     va_end(var);
  192.  
  193.     Va_start(var,parent);
  194.  
  195.     _XtVaToTypedArgList(var, total_count, &typed_args, &num_args);
  196.     widget = _XtCreatePopupShell(name, widget_class, parent,
  197.         (ArgList)NULL, (Cardinal)0, typed_args, num_args);
  198.     if (typed_args != NULL) {
  199.     XtFree((XtPointer)typed_args);
  200.     }
  201.  
  202.     va_end(var);
  203.     return widget;
  204. }
  205.  
  206. #if NeedVarargsPrototypes
  207. void
  208. XtVaSetValues(Widget widget, ...)
  209. #else
  210. /*VARARGS1*/
  211. void XtVaSetValues(widget, va_alist)
  212.     Widget widget;
  213.     va_dcl
  214. #endif
  215. {
  216.     va_list                 var;
  217.     ArgList                 args = NULL;
  218.     Cardinal                num_args;
  219.     int                total_count, typed_count;
  220.  
  221.     Va_start(var,widget);
  222.     _XtCountVaList(var, &total_count, &typed_count);
  223.     va_end(var);
  224.  
  225.     Va_start(var,widget);
  226.  
  227.     _XtVaToArgList(widget, var, total_count, &args, &num_args);
  228.     XtSetValues(widget, args, num_args);
  229.     if (args != NULL) {
  230.     XtFree((XtPointer)args);
  231.     }
  232.  
  233.     va_end(var);
  234. }
  235.  
  236.  
  237. #if NeedVarargsPrototypes
  238. void
  239. XtVaSetSubvalues(XtPointer base, XtResourceList resources, Cardinal num_resources, ...)
  240. #else
  241. /*VARARGS3*/
  242. void XtVaSetSubvalues(base, resources, num_resources, va_alist)
  243.     XtPointer base;
  244.     XtResourceList resources;
  245.     Cardinal num_resources;
  246.     va_dcl
  247. #endif
  248. {
  249.     va_list    var;
  250.     ArgList        args;
  251.     Cardinal       num_args;
  252.     int        total_count, typed_count;        
  253.  
  254.     Va_start(var, num_resources);
  255.     _XtCountVaList(var, &total_count, &typed_count);
  256.     va_end(var);
  257.  
  258.     if (typed_count != 0) {
  259.     XtWarning("XtVaTypedArg is not valid in XtVaSetSubvalues()\n");
  260.     }
  261.  
  262.     Va_start(var, num_resources);
  263.     _XtVaToArgList((Widget)NULL, var, total_count, &args, &num_args);
  264.  
  265.     XtSetSubvalues(base, resources, num_resources, args, num_args);
  266.  
  267.     if (num_args != 0) {
  268.         XtFree((XtPointer)args);
  269.     }    
  270.  
  271.     va_end(var);
  272. }
  273.  
  274. #if NeedVarargsPrototypes
  275. Widget
  276. _XtVaAppInitialize(
  277.     XtAppContext *app_context_return,
  278.     _Xconst char* application_class,
  279.     XrmOptionDescList options,
  280.     Cardinal num_options,
  281.     int *argc_in_out,
  282.     String *argv_in_out,
  283.     String *fallback_resources,
  284.     va_list var_args)
  285. #else
  286. /*VARARGS7*/
  287. Widget _XtVaAppInitialize(app_context_return, application_class, options,
  288.               num_options, argc_in_out, argv_in_out,
  289.               fallback_resources, var_args)
  290.     XtAppContext *app_context_return;
  291.     char *application_class;
  292.     XrmOptionDescList options;
  293.     Cardinal num_options;
  294.     int *argc_in_out;
  295.     String *argv_in_out;
  296.     String *fallback_resources;
  297.     va_list var_args;
  298. #endif
  299. {
  300.     va_list var;
  301.     XtAppContext app_con;
  302.     Display * dpy;
  303.     register int saved_argc = *argc_in_out;
  304.     Widget root;
  305.     String attr;
  306.     int count = 0;
  307.     XtTypedArgList typed_args;
  308.  
  309.     XtToolkitInitialize(); /* cannot be moved into _XtAppInit */
  310.     
  311.     dpy = _XtAppInit(&app_con, (String)application_class, options, num_options,
  312.              argc_in_out, &argv_in_out, fallback_resources);
  313.  
  314.     var = var_args;
  315.     for(attr = va_arg(var,String); attr != NULL; attr = va_arg(var,String)) {
  316.         ++count;
  317.         if (strcmp(attr, XtVaTypedArg) == 0) {
  318.             va_arg(var, String);
  319.             va_arg(var, String);
  320.             va_arg(var, XtArgVal);
  321.             va_arg(var, int);
  322.         } else {
  323.             va_arg(var, XtArgVal);
  324.         }
  325.     }
  326.     va_end(var);
  327.  
  328.     var = var_args;
  329.     typed_args = _XtVaCreateTypedArgList(var, count);
  330.     va_end(var);
  331.  
  332.     root =
  333.     XtVaAppCreateShell( NULL, application_class, 
  334.                 applicationShellWidgetClass, dpy,
  335.                 XtNscreen, (XtArgVal)DefaultScreenOfDisplay(dpy),
  336.                 XtNargc, (XtArgVal)saved_argc,
  337.                 XtNargv, (XtArgVal)argv_in_out,
  338.                 XtVaNestedList, (XtVarArgsList)typed_args,
  339.                 NULL );
  340.    
  341.     if (app_context_return != NULL)
  342.     *app_context_return = app_con;
  343.  
  344.     XtFree((XtPointer)typed_args);
  345.     XtFree((XtPointer)argv_in_out);
  346.     return(root);
  347. }
  348.  
  349. #if !((defined(SUNSHLIB) || defined(AIXSHLIB)) && defined(SHAREDCODE))
  350.  
  351. /*
  352.  * If not used as a shared library, we still need a front end to 
  353.  * _XtVaAppInitialize.
  354.  */
  355.  
  356. #if NeedVarargsPrototypes
  357. Widget
  358. XtVaAppInitialize(
  359.     XtAppContext *app_context_return,
  360.     _Xconst char* application_class,
  361.     XrmOptionDescList options,
  362.     Cardinal num_options,
  363.     int *argc_in_out,
  364.     String *argv_in_out,
  365.     String *fallback_resources,
  366.     ...)
  367. #else
  368. Widget XtVaAppInitialize(app_context_return, application_class, options,
  369.              num_options, argc_in_out, argv_in_out,
  370.              fallback_resources, va_alist)
  371.     XtAppContext *app_context_return;
  372.     String application_class;
  373.     XrmOptionDescList options;
  374.     Cardinal num_options;
  375.     int *argc_in_out;
  376.     String *argv_in_out;
  377.     String *fallback_resources;
  378.     va_dcl
  379. #endif
  380. {
  381.     va_list    var;
  382.  
  383.     Va_start(var, fallback_resources);    
  384.     return _XtVaAppInitialize(app_context_return, (String)application_class,
  385.                   options, num_options, argc_in_out, argv_in_out,
  386.                   fallback_resources, var);
  387. }
  388.  
  389. #endif /* !((SUNSHLIB || AIXSHLIB) && SHAREDCODE) */
  390.  
  391.