home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / Icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  7.5 KB  |  275 lines

  1. /***********************************************************
  2. Copyright 1993 by Ove Kalkan
  3.  
  4.                         All Rights Reserved
  5.  
  6. Permission to use, copy, modify, and distribute this software and its 
  7. documentation for any purpose and without fee is hereby granted, 
  8. provided that the above copyright notice appear in all copies and that
  9. both that copyright notice and this permission notice appear in 
  10. supporting documentation, and that the names of Digital or MIT not be
  11. used in advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.  
  13.  
  14. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20. SOFTWARE.
  21.  
  22. ******************************************************************/
  23.  
  24. /*
  25.  * Icon.c - Icon widget
  26.  *
  27.  */
  28.  
  29. #include <X11/IntrinsicP.h>
  30. #include <X11/StringDefs.h>
  31. #include <X11/Xaw/XawInit.h>
  32. #include <X11/Xmu/Converters.h>
  33. #include <X11/Xmu/Drawing.h>
  34. #include <X11/extensions/shape.h>
  35. #include "IconP.h"
  36.  
  37. #include <stdio.h>
  38.  
  39.  
  40. /****************************************************************
  41.  *
  42.  * Full class record constant
  43.  *
  44.  ****************************************************************/
  45.  
  46. /* Private Data */
  47.  
  48. #define offset(field) XtOffsetOf(IconRec, field)
  49. static XtResource resources[] = {
  50.      {XtNimage,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  51.     offset(icon.image), XtRImmediate, (XtPointer) None},
  52.      {XtNshape,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  53.     offset(icon.shape), XtRImmediate, (XtPointer) None},
  54.     {XtNimageWidth, XtCWidth, XtRDimension,  sizeof(Dimension),
  55.     offset(icon.width), XtRImmediate, (XtPointer)0},
  56.     {XtNimageHeight, XtCHeight, XtRDimension, sizeof(Dimension),
  57.     offset(icon.height), XtRImmediate, (XtPointer)0},
  58. };
  59. #undef offset
  60.  
  61. static void Initialize();
  62. static void Redisplay();
  63. static Boolean SetValues();
  64. static void ClassInitialize();
  65. static void Destroy();
  66. static void Resize();
  67.  
  68. IconClassRec iconClassRec = {
  69.   {
  70. /* core_class fields */    
  71. #define superclass        (&simpleClassRec)
  72.     /* superclass          */    (WidgetClass) superclass,
  73.     /* class_name          */    "Icon",
  74.     /* widget_size          */    sizeof(IconRec),
  75.     /* class_initialize       */    ClassInitialize,
  76.     /* class_part_initialize    */    NULL,
  77.     /* class_inited           */    FALSE,
  78.     /* initialize          */    Initialize,
  79.     /* initialize_hook        */    NULL,
  80.     /* realize              */    XtInheritRealize,
  81.     /* actions              */    NULL,
  82.     /* num_actions          */    0,
  83.     /* resources          */    resources,
  84.     /* num_resources          */    XtNumber(resources),
  85.     /* xrm_class          */    NULLQUARK,
  86.     /* compress_motion          */    TRUE,
  87.     /* compress_exposure      */    TRUE,
  88.     /* compress_enterleave    */    TRUE,
  89.     /* visible_interest          */    FALSE,
  90.     /* destroy              */    Destroy,
  91.     /* resize              */    Resize,
  92.     /* expose              */    Redisplay,
  93.     /* set_values          */    SetValues,
  94.     /* set_values_hook        */    NULL,
  95.     /* set_values_almost    */    XtInheritSetValuesAlmost,
  96.     /* get_values_hook        */    NULL,
  97.     /* accept_focus         */    NULL,
  98.     /* version            */    XtVersion,
  99.     /* callback_private       */    NULL,
  100.     /* tm_table               */    NULL,
  101.     /* query_geometry        */    XtInheritQueryGeometry,
  102.     /* display_accelerator    */    NULL,/*XtInheritDisplayAccelerator,*/
  103.     /* extension        */    NULL
  104.   },
  105. /* Simple class fields initialization */
  106.   {
  107.     /* change_sensitive        */    XtInheritChangeSensitive
  108.   }
  109. };
  110.  
  111. WidgetClass iconWidgetClass = (WidgetClass)&iconClassRec;
  112. /****************************************************************
  113.  *
  114.  * Private Procedures
  115.  *
  116.  ****************************************************************/
  117.  
  118. static void ClassInitialize()
  119. {
  120.     XawInitializeWidgetSet();
  121. }
  122.  
  123.  
  124.  
  125. static void GetnormalGC(lw)
  126.     IconWidget lw;
  127. {
  128.     XGCValues    values;
  129.  
  130.     values.foreground    = lw->core.border_pixel;
  131.     values.background    = lw->core.background_pixel;
  132.     values.graphics_exposures = False;
  133.  
  134.     lw->icon.normal_GC = XtGetGC(
  135.     (Widget)lw,
  136.     (unsigned) GCForeground | GCBackground | GCGraphicsExposures,
  137.     &values);
  138. }
  139.  
  140. static void GetgrayGC(lw)
  141.     IconWidget lw;
  142. {
  143.     XGCValues    values;
  144.  
  145.     values.foreground = lw->core.border_pixel;
  146.     values.background = lw->core.background_pixel;
  147.     values.fill_style = FillTiled;
  148.     values.tile       = XmuCreateStippledPixmap(XtScreen((Widget)lw),
  149.                         lw->core.border_pixel, 
  150.                         lw->core.background_pixel,
  151.                         lw->core.depth);
  152.     values.graphics_exposures = False;
  153.  
  154.     lw->icon.stipple = values.tile;
  155.     lw->icon.gray_GC = XtGetGC((Widget)lw, 
  156.                 (unsigned) GCForeground | GCBackground |
  157.                        GCTile | GCFillStyle |
  158.                        GCGraphicsExposures,
  159.                 &values);
  160. }
  161.  
  162.  
  163. /* ARGSUSED */
  164. static void Initialize(request, new)
  165.  Widget request, new;
  166. {
  167.     IconWidget lw = (IconWidget) new;
  168.  
  169.     GetnormalGC(lw);
  170.     GetgrayGC(lw);
  171.  
  172.     if (lw->core.height == 0)
  173.         lw->core.height = lw->icon.height;
  174.  
  175.     if (lw->core.width == 0)        /* need icon.lbm_width */
  176.         lw->core.width = lw->icon.width;
  177.  
  178.     (*XtClass(new)->core_class.resize) ((Widget)lw);
  179. } /* Initialize */
  180.  
  181. /*
  182.  * Repaint the widget window
  183.  */
  184.  
  185. /* ARGSUSED */
  186. static void Redisplay(w, event, region)
  187.     Widget w;
  188.     XEvent *event;
  189.     Region region;
  190. {
  191.    IconWidget lw = (IconWidget) w;
  192.    GC gc;
  193.  
  194.    gc = XtIsSensitive((Widget)lw) ? lw->icon.normal_GC : lw->icon.gray_GC;
  195.  
  196.    if (lw->icon.image != None && lw->icon.width != 0 && lw->icon.height != 0) {
  197.         int x, y;
  198.         Display *dpy = XtDisplay((Widget) lw);
  199.         Window win = XtWindow((Widget) lw);
  200.  
  201.         x = (lw->core.width - lw->icon.width)/2;
  202.         y = (lw->core.height - lw->icon.height)/2;
  203.  
  204.         XFillRectangle(dpy,win,gc,0,0,lw->core.width,lw->core.height);
  205.         if (lw->icon.shape != None) {
  206.              XShapeCombineMask(dpy,win,ShapeBounding,x,y,lw->icon.shape,ShapeSet);
  207.         }
  208.         XCopyArea (dpy,lw->icon.image,win,gc,0,0,lw->icon.width,lw->icon.height,x,y);
  209.    }
  210.    else {
  211.         Display *dpy = XtDisplay((Widget) lw);
  212.         Window win = XtWindow((Widget) lw);
  213.  
  214.         XFillRectangle(dpy,win,lw->icon.gray_GC,0,0,lw->core.width,lw->core.height);
  215.    }
  216. }
  217.  
  218. /*
  219.  * Set specified arguments into widget
  220.  */
  221.  
  222. static Boolean SetValues(current, request, new, args, num_args)
  223.     Widget current, request, new;
  224.     ArgList args;
  225.     Cardinal *num_args;
  226. {
  227.     IconWidget curlw = (IconWidget) current;
  228.     IconWidget reqlw = (IconWidget) request;
  229.     IconWidget newlw = (IconWidget) new;
  230.     Boolean redisplay;
  231.  
  232.     if (curlw->icon.image != newlw->icon.image) {
  233.     redisplay = True;
  234.     }
  235.     if (curlw->icon.shape != newlw->icon.shape) {
  236.     redisplay = True;
  237.     }
  238.     if (curlw->icon.width != newlw->icon.width) {
  239.     redisplay = True;
  240.     }
  241.     if (curlw->icon.height != newlw->icon.height) {
  242.     redisplay = True;
  243.     }
  244.  
  245.     if (curlw->core.border_pixel != newlw->core.border_pixel
  246.     || curlw->core.background_pixel != newlw->core.background_pixel) {
  247.  
  248.     XtReleaseGC(new, curlw->icon.normal_GC);
  249.     XtReleaseGC(new, curlw->icon.gray_GC);
  250.     XmuReleaseStippledPixmap( XtScreen(current), curlw->icon.stipple );
  251.     GetnormalGC(newlw);
  252.     GetgrayGC(newlw);
  253.     redisplay = True;
  254.     }
  255.  
  256.     return (redisplay || XtIsSensitive(current) != XtIsSensitive(new));
  257. }
  258.  
  259. static void Destroy(w)
  260.     Widget w;
  261. {
  262.     IconWidget lw = (IconWidget)w;
  263.  
  264.     XtReleaseGC( w, lw->icon.normal_GC );
  265.     XtReleaseGC( w, lw->icon.gray_GC);
  266.     XmuReleaseStippledPixmap( XtScreen(w), lw->icon.stipple );
  267. }
  268.  
  269. static void Resize(w)
  270.     Widget w;
  271. {
  272. }
  273.  
  274.  
  275.