home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / IconB.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  10.6 KB  |  398 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.  * IconB.c - IconB 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 "IconBP.h"
  36.  
  37. #include <stdio.h>
  38.  
  39.  
  40. /****************************************************************
  41.  *
  42.  * Full class record constant
  43.  *
  44.  ****************************************************************/
  45.  
  46. /* Private Data */
  47. static char defaultTranslations[] =
  48.     "<EnterWindow>:    highlight()        \n\
  49.      <LeaveWindow>:    unhighlight() reset()    \n\
  50.      <Btn1Down>:    set() highlight()    \n\
  51.      <Btn1Up>:        notify() unset()    ";
  52.  
  53. #define offset(field) XtOffsetOf(IconBRec, field)
  54. static XtResource resources[] = {
  55.    {XtNimage,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  56.     offset(iconB.image), XtRImmediate, (XtPointer) None},
  57.    {XtNshape,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  58.     offset(iconB.shape), XtRImmediate, (XtPointer) None},
  59.    {XtNsimage,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  60.     offset(iconB.simage), XtRImmediate, (XtPointer) None},
  61.    {XtNsshape,  XtCPixmap, XtRPixmap, sizeof(Pixmap),
  62.     offset(iconB.sshape), XtRImmediate, (XtPointer) None},
  63.    {XtNimageWidth, XtCWidth, XtRDimension,  sizeof(Dimension),
  64.     offset(iconB.width), XtRImmediate, (XtPointer)0},
  65.    {XtNimageHeight, XtCHeight, XtRDimension, sizeof(Dimension),
  66.     offset(iconB.height), XtRImmediate, (XtPointer)0},
  67.    {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer), 
  68.     offset(iconB.callbacks), XtRCallback, (XtPointer)NULL},
  69.    {XtNhighlightThickness, XtCThickness, XtRDimension, sizeof(Dimension),
  70.     offset(iconB.highlight_thickness), XtRImmediate,
  71.     (XtPointer) 2},
  72. };
  73. #undef offset
  74.  
  75. static void Initialize();
  76. static void Redisplay();
  77. static Boolean SetValues();
  78. static void ClassInitialize();
  79. static void Destroy();
  80. static void Resize();
  81. static void Realize();
  82.  
  83. static void Set(), Reset(), Notify(), Unset();
  84. static void Highlight(), Unhighlight();
  85.  
  86. static XtActionsRec actionsList[] = {
  87.   {"set",        Set},
  88.   {"notify",        Notify},
  89.   {"highlight",        Highlight},
  90.   {"reset",        Reset},
  91.   {"unset",        Unset},
  92.   {"unhighlight",    Unhighlight}
  93. };
  94.  
  95. IconBClassRec iconBClassRec = {
  96.   {
  97. /* core_class fields */    
  98. #define superclass        (&simpleClassRec)
  99.     /* superclass          */    (WidgetClass) superclass,
  100.     /* class_name          */    "IconB",
  101.     /* widget_size          */    sizeof(IconBRec),
  102.     /* class_initialize       */    ClassInitialize,
  103.     /* class_part_initialize    */    NULL,
  104.     /* class_inited           */    FALSE,
  105.     /* initialize          */    Initialize,
  106.     /* initialize_hook        */    NULL,
  107.     /* realize              */    XtInheritRealize,
  108.     /* actions              */    actionsList,
  109.     /* num_actions          */    XtNumber(actionsList),
  110.     /* resources          */    resources,
  111.     /* num_resources          */    XtNumber(resources),
  112.     /* xrm_class          */    NULLQUARK,
  113.     /* compress_motion          */    TRUE,
  114.     /* compress_exposure      */    TRUE,
  115.     /* compress_enterleave    */    TRUE,
  116.     /* visible_interest          */    FALSE,
  117.     /* destroy              */    Destroy,
  118.     /* resize              */    Resize,
  119.     /* expose              */    Redisplay,
  120.     /* set_values          */    SetValues,
  121.     /* set_values_hook        */    NULL,
  122.     /* set_values_almost    */    XtInheritSetValuesAlmost,
  123.     /* get_values_hook        */    NULL,
  124.     /* accept_focus         */    NULL,
  125.     /* version            */    XtVersion,
  126.     /* callback_private       */    NULL,
  127.     /* tm_table               */    defaultTranslations,
  128.     /* query_geometry        */    XtInheritQueryGeometry,
  129.     /* display_accelerator    */    XtInheritDisplayAccelerator,
  130.     /* extension        */    NULL
  131.   },
  132. /* Simple class fields initialization */
  133.   {
  134.     /* change_sensitive        */    XtInheritChangeSensitive
  135.   }
  136. };
  137.  
  138. WidgetClass iconBWidgetClass = (WidgetClass)&iconBClassRec;
  139. /****************************************************************
  140.  *
  141.  * Private Procedures
  142.  *
  143.  ****************************************************************/
  144.  
  145. static void ClassInitialize()
  146. {
  147.     XawInitializeWidgetSet();
  148. }
  149.  
  150.  
  151.  
  152. static void GetnormalGC(lw)
  153.     IconBWidget lw;
  154. {
  155.     XGCValues    values;
  156.  
  157.     values.foreground    = lw->core.border_pixel;
  158.     values.background    = lw->core.background_pixel;
  159.     values.graphics_exposures = False;
  160.  
  161.     lw->iconB.normal_GC = XtGetGC(
  162.     (Widget)lw,
  163.     (unsigned) GCForeground | GCBackground | GCGraphicsExposures,
  164.     &values);
  165. }
  166.  
  167. static void GetgrayGC(lw)
  168.     IconBWidget lw;
  169. {
  170.     XGCValues    values;
  171.  
  172.     values.foreground = lw->core.border_pixel;
  173.     values.background = lw->core.background_pixel;
  174.     values.fill_style = FillTiled;
  175.     values.tile       = XmuCreateStippledPixmap(XtScreen((Widget)lw),
  176.                         lw->core.border_pixel, 
  177.                         lw->core.background_pixel,
  178.                         lw->core.depth);
  179.     values.graphics_exposures = False;
  180.  
  181.     lw->iconB.stipple = values.tile;
  182.     lw->iconB.gray_GC = XtGetGC((Widget)lw, 
  183.                 (unsigned) GCForeground | GCBackground |
  184.                        GCTile | GCFillStyle |
  185.                        GCGraphicsExposures,
  186.                 &values);
  187. }
  188.  
  189.  
  190. /* ARGSUSED */
  191. static void Initialize(request, new)
  192.  Widget request, new;
  193. {
  194.     IconBWidget lw = (IconBWidget) new;
  195.  
  196.     GetnormalGC(lw);
  197.     GetgrayGC(lw);
  198.  
  199.     if (lw->core.height == 0)
  200.         lw->core.height = lw->iconB.height;
  201.  
  202.     if (lw->core.width == 0)        /* need iconB.lbm_width */
  203.         lw->core.width = lw->iconB.width;
  204.  
  205.     lw->iconB.set = FALSE;
  206.  
  207.     (*XtClass(new)->core_class.resize) ((Widget)lw);
  208. } /* Initialize */
  209.  
  210. /*
  211.  * Repaint the widget window
  212.  */
  213.  
  214. /* ARGSUSED */
  215. static void Redisplay(w, event, region)
  216.     Widget w;
  217.     XEvent *event;
  218.     Region region;
  219. {
  220.     IconBWidget lw = (IconBWidget) w;
  221.     GC gc;
  222.     Pixmap image;
  223.     Pixmap shape;
  224.  
  225.     gc = XtIsSensitive((Widget)lw) ? lw->iconB.normal_GC : lw->iconB.gray_GC;
  226.     image = lw->iconB.set ? lw->iconB.simage : lw->iconB.image;
  227.     shape = lw->iconB.set ? lw->iconB.sshape : lw->iconB.shape;
  228.  
  229.     if (image != None && lw->iconB.width != 0 && lw->iconB.height != 0) {
  230.          int x, y;
  231.          Display *dpy = XtDisplay((Widget) lw);
  232.          Window win = XtWindow((Widget) lw);
  233.  
  234.          x = (lw->core.width - lw->iconB.width)/2;
  235.          y = (lw->core.height - lw->iconB.height)/2;
  236.  
  237.          XFillRectangle(dpy,win,gc,0,0,lw->core.width,lw->core.height);
  238.          if (shape != None) {
  239.               XShapeCombineMask(dpy,win,ShapeBounding,x,y,shape,ShapeSet);
  240.          }
  241.          XCopyArea (dpy,image,win,gc,0,0,lw->iconB.width,lw->iconB.height,x,y);
  242.     }
  243.     else {
  244.          Display *dpy = XtDisplay((Widget) lw);
  245.          Window win = XtWindow((Widget) lw);
  246.  
  247.          XFillRectangle(dpy,win,lw->iconB.gray_GC,0,0,lw->core.width,lw->core.height);
  248.     }
  249. }
  250.  
  251. /*
  252.  * Set specified arguments into widget
  253.  */
  254.  
  255. static Boolean SetValues(current, request, new, args, num_args)
  256.     Widget current, request, new;
  257.     ArgList args;
  258.     Cardinal *num_args;
  259. {
  260.     IconBWidget curlw = (IconBWidget) current;
  261.     IconBWidget reqlw = (IconBWidget) request;
  262.     IconBWidget newlw = (IconBWidget) new;
  263.     Boolean redisplay;
  264.  
  265.     if (curlw->iconB.image != newlw->iconB.image) {
  266.     redisplay = True;
  267.     }
  268.     if (curlw->iconB.shape != newlw->iconB.shape) {
  269.     redisplay = True;
  270.     }
  271.     if (curlw->iconB.simage != newlw->iconB.simage) {
  272.     redisplay = True;
  273.     }
  274.     if (curlw->iconB.sshape != newlw->iconB.sshape) {
  275.     redisplay = True;
  276.     }
  277.     if (curlw->iconB.width != newlw->iconB.width) {
  278.     redisplay = True;
  279.     }
  280.     if (curlw->iconB.height != newlw->iconB.height) {
  281.     redisplay = True;
  282.     }
  283.  
  284.     if (curlw->core.border_pixel != newlw->core.border_pixel
  285.     || curlw->core.background_pixel != newlw->core.background_pixel) {
  286.  
  287.     XtReleaseGC(new, curlw->iconB.normal_GC);
  288.     XtReleaseGC(new, curlw->iconB.gray_GC);
  289.     XmuReleaseStippledPixmap( XtScreen(current), curlw->iconB.stipple );
  290.     GetnormalGC(newlw);
  291.     GetgrayGC(newlw);
  292.     redisplay = True;
  293.     }
  294.     return (redisplay || XtIsSensitive(current) != XtIsSensitive(new));
  295. }
  296.  
  297. static void Destroy(w)
  298.     Widget w;
  299. {
  300.     IconBWidget lw = (IconBWidget) w;
  301.  
  302.     XtReleaseGC( w, lw->iconB.normal_GC );
  303.     XtReleaseGC( w, lw->iconB.gray_GC);
  304.     XmuReleaseStippledPixmap( XtScreen(w), lw->iconB.stipple );
  305. }
  306.  
  307. static void Realize(w)
  308.     Widget w;
  309. {
  310.     IconBWidget lw = (IconBWidget) w;
  311. }
  312.  
  313. static void Resize(w)
  314.     Widget w;
  315. {
  316.     IconBWidget lw = (IconBWidget) w;
  317. }
  318.  
  319.  
  320.  
  321. /* Actions */
  322.  
  323. static    void    Notify(w,event,params,num_params)
  324. Widget w;
  325. XEvent *event;
  326. String *params;        /* unused */
  327. Cardinal *num_params;    /* unused */
  328. {
  329.     IconBWidget lw = (IconBWidget) w;
  330.     XtCallCallbackList(w, lw->iconB.callbacks, NULL);
  331. }
  332.  
  333.  
  334. static    void    Set(w,event,params,num_params)
  335. Widget w;
  336. XEvent *event;
  337. String *params;        /* unused */
  338. Cardinal *num_params;    /* unused */
  339. {
  340.     IconBWidget lw = (IconBWidget) w;
  341.  
  342.     lw->iconB.set = TRUE;
  343.     Redisplay(w,NULL,NULL);
  344. }
  345.  
  346.  
  347. static    void    Highlight(w,event,params,num_params)
  348. Widget w;
  349. XEvent *event;
  350. String *params;        /* unused */
  351. Cardinal *num_params;    /* unused */
  352. {
  353.     IconBWidget lw = (IconBWidget) w;
  354.  
  355.     if (XtIsRealized(w) && XtIsSensitive(w)) {
  356.         int    i;
  357.         Display *dpy = XtDisplay((Widget) lw);
  358.         Window win = XtWindow((Widget) lw);
  359.  
  360.         for (i = 0; i < lw->iconB.highlight_thickness; i++)
  361.              XDrawRectangle(dpy,win,lw->iconB.normal_GC,i,i,
  362.                             lw->core.width-i*2-1,lw->core.height-i*2-1);
  363.     }
  364. }
  365.  
  366.  
  367. static    void    Reset(w,event,params,num_params)
  368. Widget w;
  369. XEvent *event;
  370. String *params;        /* unused */
  371. Cardinal *num_params;    /* unused */
  372. {
  373.     IconBWidget lw = (IconBWidget) w;
  374. }
  375.  
  376.  
  377. static    void    Unset(w,event,params,num_params)
  378. Widget w;
  379. XEvent *event;
  380. String *params;        /* unused */
  381. Cardinal *num_params;    /* unused */
  382. {
  383.     IconBWidget lw = (IconBWidget) w;
  384.     lw->iconB.set = FALSE;
  385.     Redisplay(w,NULL,NULL);
  386. }
  387.  
  388.  
  389. static    void    Unhighlight(w,event,params,num_params)
  390. Widget w;
  391. XEvent *event;
  392. String *params;        /* unused */
  393. Cardinal *num_params;    /* unused */
  394. {
  395.     IconBWidget lw = (IconBWidget) w;
  396.     Redisplay(w,NULL,NULL);
  397. }
  398.