home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xpaint-247 / coloredit.c < prev    next >
C/C++ Source or Header  |  1997-01-03  |  4KB  |  142 lines

  1. /* +-------------------------------------------------------------------+ */
  2. /* | Copyright 1993, David Koblas (koblas@netcom.com)               | */
  3. /* | Copyright 1995, 1996 Torsten Martinsen (bullestock@dk-online.dk)  | */
  4. /* |                                       | */
  5. /* | Permission to use, copy, modify, and to distribute this software  | */
  6. /* | and its documentation for any purpose is hereby granted without   | */
  7. /* | fee, provided that the above copyright notice appear in all       | */
  8. /* | copies and that both that copyright notice and this permission    | */
  9. /* | notice appear in supporting documentation.     There is no           | */
  10. /* | representations about the suitability of this software for           | */
  11. /* | any purpose.  this software is provided "as is" without express   | */
  12. /* | or implied warranty.                           | */
  13. /* |                                       | */
  14. /* +-------------------------------------------------------------------+ */
  15.  
  16. /* $Id: colorEdit.c,v 1.3 1996/04/19 09:06:29 torsten Exp $ */
  17.  
  18. #include <X11/Intrinsic.h>
  19. #include <X11/StringDefs.h>
  20. #include <X11/Shell.h>
  21. #ifndef VMS
  22. #include <X11/Xaw/Form.h>
  23. #include <X11/Xaw/Command.h>
  24. #else
  25. #include <X11Xaw/Form.h>
  26. #include <X11Xaw/Command.h>
  27. #endif
  28. #include "misc.h"
  29. #include "palette.h"
  30. #include "color.h"
  31. #include "protocol.h"
  32.  
  33. typedef struct {
  34.     XtCallbackProc okProc;
  35.     XtPointer closure;
  36.     Widget wIn;
  37.  
  38.     Widget shell, pick;
  39.     Palette *map;
  40.     Boolean allowWrite;
  41.     XColor origColor;
  42. } LocalInfo;
  43.  
  44. static void 
  45. commonCB(LocalInfo * info, XColor * col)
  46. {
  47.     Widget cw = info->wIn;
  48.     XtCallbackProc proc = info->okProc;
  49.     XtPointer closure = info->closure;
  50.  
  51.     XtDestroyWidget(info->shell);
  52.     XtFree((XtPointer) info);
  53.  
  54.     proc(cw, closure, (XtPointer) col);
  55. }
  56.  
  57. static void 
  58. changeBgCancel(Widget w, LocalInfo * info, XtPointer junk2)
  59. {
  60.     if (info->allowWrite)
  61.     PaletteSetPixel(info->map, ColorPickerGetPixel(info->pick),
  62.             &info->origColor);
  63.     commonCB(info, NULL);
  64. }
  65. static void 
  66. changeBgOk(Widget w, LocalInfo * info, XtPointer junk2)
  67. {
  68.     XColor xcol;
  69.  
  70.     xcol = *ColorPickerGetXColor(info->pick);
  71.  
  72.     commonCB(info, &xcol);
  73. }
  74.  
  75. void 
  76. ColorEditor(Widget w, Pixel pixel, Palette * map, Boolean allowWrite,
  77.         XtCallbackProc okProc, XtPointer closure)
  78. {
  79.     Position x, y;
  80.     Widget shell, form, ok, cancel, pick;
  81.     Pixel pix;
  82.     LocalInfo *info = XtNew(LocalInfo);
  83.  
  84.     info->okProc = okProc;
  85.     info->closure = closure;
  86.     info->wIn = w;
  87.     info->allowWrite = allowWrite;
  88.  
  89.     XtVaGetValues(GetShell(w), XtNx, &x, XtNy, &y, NULL);
  90.  
  91.     shell = XtVaCreatePopupShell("colorEditDialog",
  92.                  transientShellWidgetClass, GetShell(w),
  93.                  XtNx, x + 24,
  94.                  XtNy, y + 24,
  95.                  XtNcolormap, map->cmap,
  96.                  NULL);
  97.     PaletteAddUser(map, shell);
  98.  
  99.     form = XtVaCreateManagedWidget("form", formWidgetClass, shell,
  100.                    NULL);
  101.  
  102.     if (allowWrite) {
  103.     pix = pixel;
  104.     } else {
  105.     pix = PaletteGetUnused(map);
  106.     }
  107.     pick = ColorPickerPalette(form, map, &pix);
  108.     info->origColor = *PaletteLookup(map, pixel);
  109.     ColorPickerSetXColor(pick, &info->origColor);
  110.  
  111.     ok = XtVaCreateManagedWidget("ok",
  112.                  commandWidgetClass, form,
  113.                  XtNfromVert, pick,
  114.                  XtNtop, XtChainBottom,
  115.                  XtNbottom, XtChainBottom,
  116.                  XtNleft, XtChainLeft,
  117.                  XtNright, XtChainLeft,
  118.                  NULL);
  119.  
  120.     cancel = XtVaCreateManagedWidget("cancel",
  121.                      commandWidgetClass, form,
  122.                      XtNfromVert, pick,
  123.                      XtNfromHoriz, ok,
  124.                      XtNtop, XtChainBottom,
  125.                      XtNbottom, XtChainBottom,
  126.                      XtNleft, XtChainLeft,
  127.                      XtNright, XtChainLeft,
  128.                      NULL);
  129.     XtAddCallback(cancel, XtNcallback,
  130.           (XtCallbackProc) changeBgCancel, (XtPointer) info);
  131.     XtAddCallback(ok, XtNcallback,
  132.           (XtCallbackProc) changeBgOk, (XtPointer) info);
  133.     AddDestroyCallback(shell,
  134.                (DestroyCallbackFunc) changeBgCancel, (XtPointer) info);
  135.  
  136.     info->shell = shell;
  137.     info->pick = pick;
  138.     info->map = map;
  139.  
  140.     XtPopup(shell, XtGrabNone);
  141. }
  142.