home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / guidexv / gcc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  7.6 KB  |  338 lines

  1. /*
  2.  * This file is a product of Sun Microsystems, Inc. and is provided for
  3.  * unrestricted use provided that this legend is included on all tape
  4.  * media and as a part of the software program in whole or part.  Users
  5.  * may copy or modify this file without charge, but are not authorized to
  6.  * license or distribute it to anyone else except as part of a product
  7.  * or program developed by the user.
  8.  * 
  9.  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12.  * 
  13.  * This file is provided with no support and without any obligation on the
  14.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15.  * modification or enhancement.
  16.  * 
  17.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
  19.  * OR ANY PART THEREOF.
  20.  * 
  21.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22.  * or profits or other special, indirect and consequential damages, even
  23.  * if Sun has been advised of the possibility of such damages.
  24.  * 
  25.  * Sun Microsystems, Inc.
  26.  * 2550 Garcia Avenue
  27.  * Mountain View, California  94043
  28.  */
  29.  
  30. #ifndef lint
  31. static char    sccsid[] = "@(#)gcc.c    2.9 91/10/15 Copyright 1989 Sun Microsystems";
  32. #endif
  33.  
  34. #include    <stdio.h>
  35. #include    <sys/param.h>
  36. #include    <sys/types.h>
  37. #include    <xview/xview.h>
  38. #include    <xview/panel.h>
  39. #include    <xview/cms.h>
  40. #include    <xview/svrimage.h>
  41. #include    "gcm.h"
  42. #include    "gcc_ui.h"
  43.  
  44. void            (*Callback)();
  45. static caddr_t        Client_data;
  46. static char        Current_color[MAXPATHLEN];
  47. static gcc_gccwin_objects    *Gcc_win;
  48. static void        set_color_field();
  49. static void        activate_values();
  50. static void        fill_color_list();
  51.  
  52. /*
  53.  * Initialize the gcc popup window with a title.
  54.  */
  55. void
  56. #ifdef __STDC__
  57. gcc_initialize(Xv_opaque owner, char *title)
  58. #else
  59. gcc_initialize(owner, title)
  60.     Xv_opaque    owner;
  61.     char        *title;
  62. #endif
  63. {
  64.     if(!Gcc_win)
  65.         Gcc_win = gcc_gccwin_objects_initialize(NULL, owner);
  66.  
  67.     xv_set(Gcc_win->gccwin, XV_LABEL, title, 0);
  68.  
  69.     fill_color_list();
  70.  
  71.     set_color_field(Gcm_colornames[0]);
  72. }
  73.  
  74. /*
  75.  * Activate the color popup.  Set footer messages, current color, and
  76.  * register a callback function to be called when the apply button is
  77.  * pressed.  Store some client data for the caller.
  78.  */
  79. void
  80. #ifdef __STDC__
  81. gcc_activate(char *left, char *right, void (*func)(),
  82.          caddr_t client_data, char *color)
  83. #else
  84. gcc_activate(left, right, func, client_data, color)
  85.     char    *left;
  86.     char    *right;
  87.     void    (*func)();
  88.     caddr_t    client_data;
  89.     char    *color;
  90. #endif
  91. {
  92. int    index;
  93.  
  94.     xv_set(Gcc_win->gccwin, FRAME_LEFT_FOOTER, left, 0);
  95.     xv_set(Gcc_win->gccwin, FRAME_RIGHT_FOOTER, right, 0);
  96.     xv_set(Gcc_win->gccwin, WIN_SHOW, TRUE, WIN_FRONT, 0);
  97.  
  98.     activate_values(TRUE);
  99.  
  100.     if((index = gcm_color_index(color)) == -1)
  101.         index = gcm_color_index("black");
  102.  
  103.     xv_set(Gcc_win->color_list, PANEL_LIST_SELECT, index, TRUE, 0);
  104.  
  105.     strcpy(Current_color, color);
  106.     set_color_field(Current_color);
  107.  
  108.     Callback = func;
  109.     Client_data = client_data;
  110. }
  111.  
  112. /*
  113.  * Deactivate the color popup.
  114.  */
  115. void
  116. gcc_deactivate()
  117. {
  118.     Callback = NULL;
  119.     Client_data = NULL;
  120.     xv_set(Gcc_win->gccwin, FRAME_LEFT_FOOTER, "", 0);
  121.     xv_set(Gcc_win->gccwin, FRAME_RIGHT_FOOTER, "", 0);
  122.  
  123.     set_color_field("");
  124.     activate_values(FALSE);
  125. }
  126.  
  127. /*
  128.  * Suspend or re-enable color chooser if active or was active.
  129.  */
  130. void
  131. #ifdef __STDC__
  132. gcc_suspend(int suspend)
  133. #else
  134. gcc_suspend(suspend)
  135.     int    suspend;
  136. #endif
  137. {
  138. static int    was_active = FALSE;
  139.  
  140.     if(!Gcc_win)
  141.         return;
  142.  
  143.     if((suspend && (int)xv_get(Gcc_win->gccwin, WIN_SHOW)) ||
  144.        (!suspend && was_active))
  145.     {
  146.         xv_set(Gcc_win->gccwin,
  147.             FRAME_CMD_PUSHPIN_IN,    !suspend,
  148.             WIN_SHOW,        !suspend,
  149.             0);
  150.         was_active = suspend;
  151.     }
  152. }
  153.  
  154. /*
  155.  * Notify callback function for `color_list'.
  156.  */
  157. /* ARGSUSED */
  158. int
  159. #ifdef __STDC__
  160. gcc_list_proc(Panel_item item, char *string, Xv_opaque client_data,
  161.           Panel_list_op op, Event *event)
  162. #else
  163. gcc_list_proc(item, string, client_data, op, event)
  164.     Panel_item    item;
  165.     char        *string;
  166.     Xv_opaque    client_data;
  167.     Panel_list_op    op;
  168.     Event        *event;
  169. #endif
  170. {
  171.     switch(op)
  172.     {
  173.     case PANEL_LIST_OP_DESELECT:
  174.         break;
  175.  
  176.     case PANEL_LIST_OP_SELECT:
  177.         set_color_field(string);
  178.         break;
  179.  
  180.     case PANEL_LIST_OP_VALIDATE:
  181.         break;
  182.  
  183.     case PANEL_LIST_OP_DELETE:
  184.         break;
  185.     }
  186.     return XV_OK;
  187. }
  188.  
  189. /*
  190.  * Notify callback function for `apply'.
  191.  */
  192. /*ARGSUSED*/
  193. void
  194. #ifdef __STDC__
  195. gcc_apply(Panel_item item, Event *event)
  196. #else
  197. gcc_apply(item, event)
  198.     Panel_item    item;
  199.     Event        *event;
  200. #endif
  201. {
  202.     strcpy(Current_color,
  203.         (char *)xv_get(Gcc_win->color_name, PANEL_VALUE));
  204.     set_color_field(Current_color);
  205.  
  206.     if(Callback)
  207.         (Callback)(Current_color, Client_data);
  208.  
  209.     xv_set(Gcc_win->apply, PANEL_NOTIFY_STATUS, XV_ERROR, 0);
  210. }
  211.  
  212. /*
  213.  * Notify callback function for `reset'.
  214.  */
  215. /*ARGSUSED*/
  216. void
  217. #ifdef __STDC__
  218. gcc_reset(Panel_item item, Event *event)
  219. #else
  220. gcc_reset(item, event)
  221.     Panel_item    item;
  222.     Event        *event;
  223. #endif
  224. {
  225.     set_color_field(Current_color);
  226.     xv_set(Gcc_win->reset, PANEL_NOTIFY_STATUS, XV_ERROR, 0);
  227. }
  228.  
  229. /*
  230.  * Set a color name into the text field and change the color on the blot.
  231.  */
  232. static void
  233. #ifdef __STDC__
  234. set_color_field(char *color)
  235. #else
  236. set_color_field(color)
  237.     char    *color;
  238. #endif
  239. {
  240. int    index;
  241.  
  242.     if((index = gcm_color_index(color)) == -1)
  243.         index = gcm_color_index("black");
  244.  
  245.     xv_set(Gcc_win->color_name, PANEL_VALUE, color, 0);
  246.     xv_set(Gcc_win->color_blot, PANEL_ITEM_COLOR, index, 0);
  247. }
  248.  
  249. /*
  250.  * Make panel items active or inactive.
  251.  */
  252. static void
  253. #ifdef __STDC__
  254. activate_values(int state)
  255. #else
  256. activate_values(state)
  257.     int    state;
  258. #endif
  259. {
  260.     xv_set(Gcc_win->apply, PANEL_INACTIVE, !state, 0);
  261.     xv_set(Gcc_win->reset, PANEL_INACTIVE, !state, 0);
  262. }
  263.  
  264. /*
  265.  * Fill the scrolling list with all of the available colors.  Only
  266.  * fill it with the names if color isn't available.
  267.  */
  268. static void
  269. fill_color_list()
  270. {
  271.     Display        *display = (Display *)xv_get(Gcc_win->gccwin, XV_DISPLAY);
  272.     Drawable    xid = (Drawable)xv_get(Gcc_win->gccwin, XV_XID);
  273.     int        depth = (unsigned int)xv_get(Gcc_win->gccwin, XV_DEPTH);
  274.     int        visual_class;
  275.     int        row = 0;
  276.     int        size;
  277.     int        color_available = FALSE;
  278.     int        color_index;
  279.     char        **color;
  280.     unsigned long    *pixel_table;
  281.     GC        gc;
  282.     Pixmap        pixmap;
  283.     Xv_opaque    color_glyph;
  284.  
  285.     visual_class = (int)xv_get(Gcc_win->gccwin, XV_VISUAL_CLASS);
  286.  
  287.     if ((depth > 7) &&
  288.         ((visual_class == StaticColor) || (visual_class == PseudoColor) ||
  289.          (visual_class == TrueColor) || (visual_class == DirectColor)))
  290.         color_available = TRUE;
  291.     /* MOOSE: SHould we worry about .Xdefaults entries here? Like OpenWindows.3DLook.Color */
  292.  
  293.     if (color_available)
  294.     {
  295.         gcm_initialize_colors(Gcc_win->controls, NULL, NULL);
  296.         pixel_table = (unsigned long *)xv_get(xv_get(Gcc_win->controls,
  297.                                  WIN_CMS),
  298.                               CMS_INDEX_TABLE);
  299.         gc = XCreateGC(display, xid, 0, NULL);
  300.         size = (int)xv_get(Gcc_win->color_list,
  301.                    PANEL_LIST_ROW_HEIGHT) - 2;
  302.     }
  303.  
  304.     for(color = Gcm_colornames; *color; row++, color++)
  305.     {
  306.         if (color_available)
  307.         {
  308.             pixmap = XCreatePixmap(display, xid, size,
  309.                            size, depth);
  310.             color_index = pixel_table[gcm_color_index(*color)];
  311.             XSetForeground(display, gc, color_index);
  312.             XFillRectangle(display, pixmap, gc, 0, 0, size, size);
  313.  
  314.             color_glyph =
  315.                 xv_create(0, SERVER_IMAGE,
  316.                       SERVER_IMAGE_COLORMAP, gcm_colormap_name(),
  317.                       SERVER_IMAGE_PIXMAP,    pixmap,
  318.                         0);
  319.  
  320.             xv_set(Gcc_win->color_list,
  321.                    PANEL_LIST_INSERT, row,
  322.                    PANEL_LIST_GLYPH, row, color_glyph,
  323.                    PANEL_LIST_STRING, row, *color,
  324.                    0);
  325.         }
  326.         else
  327.         {
  328.             xv_set(Gcc_win->color_list,
  329.                    PANEL_LIST_INSERT, row,
  330.                    PANEL_LIST_STRING, row, *color,
  331.                    0);
  332.         }
  333.     }
  334.  
  335.     if (color_available)
  336.         XFreeGC(display, gc);
  337. }
  338.