home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / fontutils-0.6-src.lha / fontutils-0.6 / include / xt-common.h < prev   
Encoding:
C/C++ Source or Header  |  1995-03-10  |  4.9 KB  |  136 lines

  1. /* xt-common.h: declarations that all programs using Xt need.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef XT_COMMON_H
  20. #define XT_COMMON_H
  21.  
  22. #ifdef HAVE_X11
  23. #include <X11/Intrinsic.h>
  24. #include <X11/StringDefs.h>
  25. #endif
  26.  
  27.  
  28. /* Our own definitions.  */
  29.  
  30. /* It is convenient to have this type for declaring action procedures.  */
  31. typedef void action_proc_type (Widget, XEvent *, String *, Cardinal *);
  32.  
  33. /* We virtually always want an arg array and its length together in
  34.    parameter lists.  */
  35. #define XTARG(arg_array) (arg_array), XtNumber (arg_array)
  36.  
  37. /* Assign a value to an Xt argument.  */
  38. #define XTASSIGN_ARG(arg, val) (arg).value = (XtArgVal) (val)
  39.  
  40. /* We use command buttons the same way in all programs, so here are
  41.    macros to make it easy to use them.  */
  42.  
  43. /* Our buttons only have one procedure associated with them.  This macro
  44.    expands into an XtCallbackRec array.  */
  45. #define SINGLE_CALLBACK(proc, data)                    \
  46.   { { (XtCallbackProc) proc, (XtPointer) (data) },            \
  47.     { NULL, NULL }                            \
  48.   }
  49.  
  50. /* This macro declares a command widget.  The routine that performs the
  51.    action should be named `NAME_command'; it will be passed the
  52.    CLIENT_DATA argument.  The string TITLE appears in the window.  */
  53. #define DECLARE_BUTTON(name, title, client_data)            \
  54.   XtCallbackRec name##_callback_list[]                    \
  55.     = SINGLE_CALLBACK (name##_command, client_data);            \
  56.   Arg name##_args[]                            \
  57.     = { { XtNfromHoriz,    (XtArgVal) NULL }, /* We assign to this below.  */\
  58.         { XtNlabel,    (XtArgVal) title },                \
  59.         { XtNcallback,    (XtArgVal) name##_callback_list },        \
  60.       };                                \
  61.   Widget name##_widget /* The invoker supplies the semicolon.  */
  62.   
  63.  
  64. /* This macro defines a command button NAME, by using the variables
  65.    that DECLARE_BUTTON creates.  It also keeps track of the widget that
  66.    should be to the left of the new one, by assuming a variable
  67.    `widget_to_the_left'.  */
  68.  
  69. #define DEFINE_BUTTON(name, parent)                    \
  70.   name##_args[0].value = (XtArgVal) widget_to_the_left;            \
  71.   name##_widget = XtCreateManagedWidget (#name, commandWidgetClass,    \
  72.                      parent, XTARG (name##_args));    \
  73.   widget_to_the_left = name##_widget
  74.   /* The invoker supplies the semicolon.  */
  75.  
  76.  
  77. /* Parse a character code in STR; if invalid, give a warning.  If valid,
  78.    assign the value to CODE.  Return whether it was valid.  */
  79. #define XTPARSE_CHARCODE(code, str, widget)                \
  80.   ({                                    \
  81.     boolean valid;                            \
  82.     charcode_type test = parse_charcode (str, &valid);            \
  83.                                     \
  84.     if (valid)                                \
  85.       code = test;                            \
  86.     else                                \
  87.       {                                    \
  88.         string s = concat3 ("`", str, "': invalid character code");    \
  89.         x_warning (XtParent (widget), s);                \
  90.         free (s);                            \
  91.       };                                \
  92.     valid;                                \
  93.   })
  94.  
  95.  
  96. /* Find the widget whose name is NAME in the widget tree rooted at
  97.    TOP.  If no such widget can be found, give a fatal error.
  98.    
  99.    We use the extra variable `root' in case `top' is an expression
  100.    involving some other widget named `w'.  */
  101. #define XFIND_WIDGET(top, name)                        \
  102.     ({                                    \
  103.       Widget root = top;                        \
  104.       Widget w = XtNameToWidget (root, name);                \
  105.       if (w == NULL)                            \
  106.         {                                \
  107.           string s = concat3 ("Cannot find widget `", name, "'.");     \
  108.           XtErrorMsg ("noWidget", "FindWidget", "Error", s, NULL, 0);    \
  109.         }                                \
  110.       w;                                \
  111.     })
  112.  
  113.  
  114. /* For consistency, so we can give `Pointer' as a `type' below.  */
  115. typedef XtPointer Pointer;
  116.  
  117. /* We define our widget resources in a predictable way.  We assume an
  118.    `OFFSET' macro has been defined as, e.g.,
  119.    #define OFFSET(field) XtOffset (BitmapWidget, bitmap.field)
  120. */
  121. #define DEFINE_RESOURCE(name, field_name, class_name, type,        \
  122.                         default_type, default)                \
  123.   { XtN##name, XtC##class_name, XtR##type, sizeof (type),        \
  124.     OFFSET (field_name), XtR##default_type, (XtPointer) (default) }
  125.  
  126. #define IMMEDIATE_RESOURCE2(name, field_name, class_name, type, default)\
  127.   DEFINE_RESOURCE (name, field_name, class_name, type, Immediate, default)
  128.  
  129. #define IMMEDIATE_RESOURCE(name, class_name, type, default)        \
  130.   IMMEDIATE_RESOURCE2 (name, name, class_name, type, default)
  131.  
  132. #define STRING_RESOURCE(name, class_name, default)            \
  133.   DEFINE_RESOURCE (name, name, class_name, String, String, default)
  134.  
  135. #endif /* not XT_COMMON_H */
  136.