home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  24.3 KB  |  889 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/Tab.c>                                                */
  21. /* Description:    XfeTab widget source.                                    */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/TabP.h>
  28. #include <Xfe/ManagerP.h>
  29. #include <Xm/RowColumnP.h>
  30.  
  31. /*----------------------------------------------------------------------*/
  32. /*                                                                        */
  33. /* Warnings and messages                                                */
  34. /*                                                                        */
  35. /*----------------------------------------------------------------------*/
  36. #define MESSAGE1 "Widget is not a XfeButton."
  37. #define MESSAGE2 "XmNsubMenuId is a read-only resource."
  38. #define MESSAGE3 "XmNpoppedUp is a read-only resource."
  39. #define MESSAGE4 "XmNmappingDelay must be at least 1."
  40.  
  41. /*----------------------------------------------------------------------*/
  42. /*                                                                        */
  43. /* Core class methods                                                    */
  44. /*                                                                        */
  45. /*----------------------------------------------------------------------*/
  46. static void     Initialize        (Widget,Widget,ArgList,Cardinal *);
  47. static void     Destroy            (Widget);
  48. static Boolean    SetValues        (Widget,Widget,Widget,ArgList,Cardinal *);
  49.  
  50. /*----------------------------------------------------------------------*/
  51. /*                                                                        */
  52. /* XfePrimitive class methods                                            */
  53. /*                                                                        */
  54. /*----------------------------------------------------------------------*/
  55. static void    PreferredGeometry    (Widget,Dimension *,Dimension *);
  56. static void    PrepareComponents    (Widget,int);
  57. static void    DrawBackground        (Widget,XEvent *,Region,XRectangle *);
  58.  
  59. /*----------------------------------------------------------------------*/
  60. /*                                                                        */
  61. /* Misc XfeTab functions                                                */
  62. /*                                                                        */
  63. /*----------------------------------------------------------------------*/
  64. static void    DrawTab                (Widget,XEvent *,Region,XRectangle *);
  65. static void    FillTabVertical        (Widget,Pixmap,Dimension,Dimension);
  66. static void    FillTabHorizontal    (Widget,Pixmap,Dimension,Dimension);
  67.  
  68. /*----------------------------------------------------------------------*/
  69. /*                                                                        */
  70. /* XfeTab Resources                                                        */
  71. /*                                                                        */
  72. /*----------------------------------------------------------------------*/
  73. static XtResource resources[] = 
  74. {
  75.     /* Resources */
  76.     { 
  77.         XmNbottomPixmap,
  78.         XmCBottomPixmap,
  79.         XmRPixmap,
  80.         sizeof(Pixmap),
  81.         XtOffsetOf(XfeTabRec , xfe_tab . bottom_pixmap),
  82.         XmRImmediate, 
  83.         (XtPointer) XmUNSPECIFIED_PIXMAP
  84.     },
  85.     { 
  86.         XmNhorizontalPixmap,
  87.         XmCHorizontalPixmap,
  88.         XmRPixmap,
  89.         sizeof(Pixmap),
  90.         XtOffsetOf(XfeTabRec , xfe_tab . horizontal_pixmap),
  91.         XmRImmediate, 
  92.         (XtPointer) XmUNSPECIFIED_PIXMAP
  93.     },
  94.     { 
  95.         XmNleftPixmap,
  96.         XmCLeftPixmap,
  97.         XmRPixmap,
  98.         sizeof(Pixmap),
  99.         XtOffsetOf(XfeTabRec , xfe_tab . left_pixmap),
  100.         XmRImmediate, 
  101.         (XtPointer) XmUNSPECIFIED_PIXMAP
  102.     },
  103.     { 
  104.         XmNrightPixmap,
  105.         XmCRightPixmap,
  106.         XmRPixmap,
  107.         sizeof(Pixmap),
  108.         XtOffsetOf(XfeTabRec , xfe_tab . right_pixmap),
  109.         XmRImmediate, 
  110.         (XtPointer) XmUNSPECIFIED_PIXMAP
  111.     },
  112.     { 
  113.         XmNtopPixmap,
  114.         XmCTopPixmap,
  115.         XmRPixmap,
  116.         sizeof(Pixmap),
  117.         XtOffsetOf(XfeTabRec , xfe_tab . top_pixmap),
  118.         XmRImmediate, 
  119.         (XtPointer) XmUNSPECIFIED_PIXMAP
  120.     },
  121.     { 
  122.         XmNverticalPixmap,
  123.         XmCVerticalPixmap,
  124.         XmRPixmap,
  125.         sizeof(Pixmap),
  126.         XtOffsetOf(XfeTabRec , xfe_tab . vertical_pixmap),
  127.         XmRImmediate, 
  128.         (XtPointer) XmUNSPECIFIED_PIXMAP
  129.     },
  130.     { 
  131.         XmNbottomRaisedPixmap,
  132.         XmCBottomRaisedPixmap,
  133.         XmRPixmap,
  134.         sizeof(Pixmap),
  135.         XtOffsetOf(XfeTabRec , xfe_tab . bottom_raised_pixmap),
  136.         XmRImmediate, 
  137.         (XtPointer) XmUNSPECIFIED_PIXMAP
  138.     },
  139.     { 
  140.         XmNhorizontalRaisedPixmap,
  141.         XmCHorizontalRaisedPixmap,
  142.         XmRPixmap,
  143.         sizeof(Pixmap),
  144.         XtOffsetOf(XfeTabRec , xfe_tab . horizontal_raised_pixmap),
  145.         XmRImmediate, 
  146.         (XtPointer) XmUNSPECIFIED_PIXMAP
  147.     },
  148.     { 
  149.         XmNleftRaisedPixmap,
  150.         XmCLeftRaisedPixmap,
  151.         XmRPixmap,
  152.         sizeof(Pixmap),
  153.         XtOffsetOf(XfeTabRec , xfe_tab . left_raised_pixmap),
  154.         XmRImmediate, 
  155.         (XtPointer) XmUNSPECIFIED_PIXMAP
  156.     },
  157.     { 
  158.         XmNrightRaisedPixmap,
  159.         XmCRightRaisedPixmap,
  160.         XmRPixmap,
  161.         sizeof(Pixmap),
  162.         XtOffsetOf(XfeTabRec , xfe_tab . right_raised_pixmap),
  163.         XmRImmediate, 
  164.         (XtPointer) XmUNSPECIFIED_PIXMAP
  165.     },
  166.     { 
  167.         XmNtopRaisedPixmap,
  168.         XmCTopRaisedPixmap,
  169.         XmRPixmap,
  170.         sizeof(Pixmap),
  171.         XtOffsetOf(XfeTabRec , xfe_tab . top_raised_pixmap),
  172.         XmRImmediate, 
  173.         (XtPointer) XmUNSPECIFIED_PIXMAP
  174.     },
  175.     { 
  176.         XmNverticalRaisedPixmap,
  177.         XmCVerticalRaisedPixmap,
  178.         XmRPixmap,
  179.         sizeof(Pixmap),
  180.         XtOffsetOf(XfeTabRec , xfe_tab . vertical_raised_pixmap),
  181.         XmRImmediate, 
  182.         (XtPointer) XmUNSPECIFIED_PIXMAP
  183.     },
  184.     { 
  185.         XmNorientation,
  186.         XmCOrientation,
  187.         XmROrientation,
  188.         sizeof(unsigned char),
  189.         XtOffsetOf(XfeTabRec , xfe_tab . orientation),
  190.         XmRImmediate, 
  191.         (XtPointer) XmVERTICAL
  192.     },
  193.  
  194.     /* Force XmNraiseBorderThickness to 0 */
  195.     { 
  196.         XmNraiseBorderThickness,
  197.         XmCRaiseBorderThickness,
  198.         XmRHorizontalDimension,
  199.         sizeof(Dimension),
  200.         XtOffsetOf(XfeTabRec , xfe_button . raise_border_thickness),
  201.         XmRImmediate, 
  202.         (XtPointer) 0
  203.     },
  204.  
  205.     /* Force XmNraiseOnEnter to False */
  206.     { 
  207.         XmNraiseOnEnter,
  208.         XmCRaiseOnEnter,
  209.         XmRBoolean,
  210.         sizeof(Boolean),
  211.         XtOffsetOf(XfeTabRec , xfe_button . raise_on_enter),
  212.         XmRImmediate, 
  213.         (XtPointer) False
  214.     },
  215.  
  216.     /* Force XmNfillOnEnter to True */
  217.     { 
  218.         XmNfillOnEnter,
  219.         XmCFillOnEnter,
  220.         XmRBoolean,
  221.         sizeof(Boolean),
  222.         XtOffsetOf(XfeTabRec , xfe_button . fill_on_enter),
  223.         XmRImmediate, 
  224.         (XtPointer) True
  225.     },
  226.  
  227.     /* Force XmNbuttonLayout to XmBUTTON_PIXMAP_ONLY */
  228.     { 
  229.         XmNbuttonLayout,
  230.         XmCButtonLayout,
  231.         XmRButtonLayout,
  232.         sizeof(unsigned char),
  233.         XtOffsetOf(XfeTabRec , xfe_button . button_layout),
  234.         XmRImmediate, 
  235.         (XtPointer) XmBUTTON_PIXMAP_ONLY
  236.     },
  237. };
  238.  
  239. /*----------------------------------------------------------------------*/
  240. /*                                                                        */
  241. /* XfeTab widget class record initialization                            */
  242. /*                                                                        */
  243. /*----------------------------------------------------------------------*/
  244. _XFE_WIDGET_CLASS_RECORD(tab,Tab) =
  245. {
  246.     {
  247.         /* Core Part */
  248.         (WidgetClass) &xfeButtonClassRec,        /* superclass             */
  249.         "XfeTab",                                /* class_name             */
  250.         sizeof(XfeTabRec),                        /* widget_size            */
  251.         NULL,                                    /* class_initialize       */
  252.         NULL,                                    /* class_part_initialize*/
  253.         FALSE,                                  /* class_inited           */
  254.         Initialize,                             /* initialize             */
  255.         NULL,                                   /* initialize_hook        */
  256.         XtInheritRealize,                       /* realize                */
  257.         NULL,                                    /* actions                */
  258.         0,                                        /* num_actions            */
  259.         resources,                              /* resources              */
  260.         XtNumber(resources),                    /* num_resources          */
  261.         NULLQUARK,                              /* xrm_class              */
  262.         TRUE,                                   /* compress_motion        */
  263.         XtExposeCompressMaximal,                /* compress_exposure      */
  264.         TRUE,                                   /* compress_enterleave    */
  265.         FALSE,                                  /* visible_interest       */
  266.         Destroy,                                /* destroy                */
  267.         XtInheritResize,                        /* resize                 */
  268.         XtInheritExpose,                        /* expose                 */
  269.         SetValues,                              /* set_values             */
  270.         NULL,                                   /* set_values_hook        */
  271.         XtInheritSetValuesAlmost,                /* set_values_almost      */
  272.         NULL,                                    /* get_values_hook        */
  273.         NULL,                                   /* accept_focus           */
  274.         XtVersion,                              /* version                */
  275.         NULL,                                   /* callback_private       */
  276.         XtInheritTranslations,                    /* tm_table               */
  277.         XtInheritQueryGeometry,                    /* query_geometry         */
  278.         XtInheritDisplayAccelerator,            /* display accel          */
  279.         NULL,                                   /* extension              */
  280.     },
  281.  
  282.     /* XmPrimitive Part */
  283.     {
  284.         XmInheritBorderHighlight,                /* border_highlight        */
  285.         XmInheritBorderUnhighlight,                /* border_unhighlight     */
  286.         XtInheritTranslations,                  /* translations           */
  287.         XmInheritArmAndActivate,                /* arm_and_activate       */
  288.         NULL,                                    /* syn resources          */
  289.         0,                                        /* num syn_resources      */
  290.         NULL,                                    /* extension              */
  291.     },
  292.     
  293.     /* XfePrimitive Part */
  294.     {
  295.         XfeInheritBitGravity,                    /* bit_gravity            */
  296.         PreferredGeometry,                        /* preferred_geometry    */
  297.         XfeInheritMinimumGeometry,                /* minimum_geometry        */
  298.         XfeInheritUpdateRect,                    /* update_rect            */
  299.         PrepareComponents,                        /* prepare_components    */
  300.         XfeInheritLayoutComponents,                /* layout_components    */
  301.         DrawBackground,                            /* draw_background        */
  302.         XfeInheritDrawShadow,                    /* draw_shadow            */
  303.         XfeInheritDrawComponents,                /* draw_components        */
  304.         NULL,                                    /* extension            */
  305.     },
  306.  
  307.     /* XfeLabel Part */
  308.     {
  309.         XfeInheritLayoutString,                    /* layout_string        */
  310.         XfeInheritDrawString,                    /* draw_string            */
  311.         XfeInheritDrawSelection,                /* draw_selection        */
  312.         XfeInheritGetLabelGC,                    /* get_label_gc            */
  313.         XfeInheritGetSelectionGC,                /* get_selection_gc        */
  314.         NULL,                                    /* extension            */
  315.     },
  316.  
  317.     /* XfeButton Part */
  318.     {
  319.         XfeInheritLayoutPixmap,                    /* layout_pixmap        */
  320.         XfeInheritDrawPixmap,                    /* draw_pixmap            */
  321.         XfeInheritDrawRaiseBorder,                /* draw_raise_border    */
  322.         XfeInheritArmTimeout,                    /* arm_timeout            */
  323.         NULL,                                    /* extension            */
  324.     },
  325.  
  326.     /* XfeTab Part */
  327.     {
  328.         NULL,                                    /* extension            */
  329.     },
  330. };
  331.  
  332. /*----------------------------------------------------------------------*/
  333. /*                                                                        */
  334. /* xfeTabWidgetClass declaration.                                        */
  335. /*                                                                        */
  336. /*----------------------------------------------------------------------*/
  337. _XFE_WIDGET_CLASS(tab,Tab);
  338.  
  339. /*----------------------------------------------------------------------*/
  340. /*                                                                        */
  341. /* Core class methods                                                    */
  342. /*                                                                        */
  343. /*----------------------------------------------------------------------*/
  344. static void
  345. Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  346. {
  347.     /* Finish of initialization */
  348.     _XfePrimitiveChainInitialize(rw,nw,xfeTabWidgetClass);
  349. }
  350. /*----------------------------------------------------------------------*/
  351. static void
  352. Destroy(Widget w)
  353. {
  354. }
  355. /*----------------------------------------------------------------------*/
  356. static Boolean
  357. SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
  358. {
  359.     XfeTabPart *    np = _XfeTabPart(nw);
  360.     XfeTabPart *    op = _XfeTabPart(ow);
  361.  
  362.     /* vertical_pixmap */
  363.     if (np->vertical_pixmap != op->vertical_pixmap)
  364.     {
  365.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  366.  
  367.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_VERTICAL_PIXMAP;
  368.     }
  369.  
  370.     /* horizontal_pixmap */
  371.     if (np->horizontal_pixmap != op->horizontal_pixmap)
  372.     {
  373.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  374.  
  375.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_HORIZONTAL_PIXMAP;
  376.     }
  377.  
  378.     /* top_pixmap */
  379.     if (np->top_pixmap != op->top_pixmap)
  380.     {
  381.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  382.  
  383.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_TOP_PIXMAP;
  384.     }
  385.  
  386.     /* bottom_pixmap */
  387.     if (np->bottom_pixmap != op->bottom_pixmap)
  388.     {
  389.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  390.  
  391.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_BOTTOM_PIXMAP;
  392.     }
  393.  
  394.     /* left_pixmap */
  395.     if (np->left_pixmap != op->left_pixmap)
  396.     {
  397.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  398.  
  399.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_LEFT_PIXMAP;
  400.     }
  401.  
  402.     /* right_pixmap */
  403.     if (np->right_pixmap != op->right_pixmap)
  404.     {
  405.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  406.  
  407.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_RIGHT_PIXMAP;
  408.     }
  409.  
  410.     /* vertical_raised_pixmap */
  411.     if (np->vertical_raised_pixmap != op->vertical_raised_pixmap)
  412.     {
  413.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  414.  
  415.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_VERTICAL_RAISED_PIXMAP;
  416.     }
  417.  
  418.     /* horizontal_raised_pixmap */
  419.     if (np->horizontal_raised_pixmap != op->horizontal_raised_pixmap)
  420.     {
  421.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  422.  
  423.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_HORIZONTAL_RAISED_PIXMAP;
  424.     }
  425.  
  426.     /* top_raised_pixmap */
  427.     if (np->top_raised_pixmap != op->top_raised_pixmap)
  428.     {
  429.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  430.  
  431.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_TOP_RAISED_PIXMAP;
  432.     }
  433.  
  434.     /* bottom_raised_pixmap */
  435.     if (np->bottom_raised_pixmap != op->bottom_raised_pixmap)
  436.     {
  437.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  438.  
  439.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_BOTTOM_RAISED_PIXMAP;
  440.     }
  441.  
  442.     /* left_raised_pixmap */
  443.     if (np->left_raised_pixmap != op->left_raised_pixmap)
  444.     {
  445.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  446.  
  447.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_LEFT_RAISED_PIXMAP;
  448.     }
  449.  
  450.     /* right_raised_pixmap */
  451.     if (np->right_raised_pixmap != op->right_raised_pixmap)
  452.     {
  453.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  454.  
  455.         _XfePrepareFlags(nw) |= _XFE_PREPARE_TAB_RIGHT_RAISED_PIXMAP;
  456.     }
  457.  
  458.     /* orientation */
  459.     if (np->orientation != op->orientation)
  460.     {
  461.         _XfeConfigFlags(nw) |= XfeConfigGLE;
  462.     }
  463.  
  464.     return _XfePrimitiveChainSetValues(ow,rw,nw,xfeTabWidgetClass);
  465. }
  466. /*----------------------------------------------------------------------*/
  467.  
  468.  
  469. /*----------------------------------------------------------------------*/
  470. /*                                                                        */
  471. /* XfePrimitive methods                                                    */
  472. /*                                                                        */
  473. /*----------------------------------------------------------------------*/
  474. static void
  475. PreferredGeometry(Widget w,Dimension *width,Dimension *height)
  476. {
  477.     XfeTabPart *            tp = _XfeTabPart(w);
  478.     XfeButtonWidgetClass    bwc = (XfeButtonWidgetClass) xfeButtonWidgetClass;
  479.     Dimension                max;
  480.  
  481.     /* Explicit invoke of XfeButton's preferred_geometry() method */
  482.     (*bwc->xfe_primitive_class.preferred_geometry)(w,width,height);
  483.  
  484.     /* Vertical */
  485.     if (tp->orientation == XmVERTICAL)
  486.     {
  487.         max = XfeMax(tp->bottom_width,tp->horizontal_width);
  488.         max = XfeMax(max,tp->top_width);
  489.         max = XfeMax(max,*width);
  490.  
  491.         *width = max;
  492.     }
  493.     /* Horizontal */
  494.     else
  495.     {
  496.         max = XfeMax(tp->left_height,tp->vertical_height);
  497.         max = XfeMax(max,tp->right_height);
  498.         max = XfeMax(max,*height);
  499.  
  500.         *height = max;
  501.     }
  502. }
  503. /*----------------------------------------------------------------------*/
  504. static void
  505. PrepareComponents(Widget w,int flags)
  506. {
  507.     XfeTabPart * tp = _XfeTabPart(w);
  508.  
  509.     if (flags & _XFE_PREPARE_TAB_BOTTOM_PIXMAP)
  510.     {
  511.         _XfePixmapPrepare(w,
  512.                           &tp->bottom_pixmap,
  513.                           &tp->bottom_width,
  514.                           &tp->bottom_height,
  515.                           XmNbottomPixmap);
  516.     }
  517.  
  518.     if (flags & _XFE_PREPARE_TAB_TOP_PIXMAP)
  519.     {
  520.         _XfePixmapPrepare(w,
  521.                           &tp->top_pixmap,
  522.                           &tp->top_width,
  523.                           &tp->top_height,
  524.                           XmNtopPixmap);
  525.     }
  526.  
  527.     if (flags & _XFE_PREPARE_TAB_LEFT_PIXMAP)
  528.     {
  529.         _XfePixmapPrepare(w,
  530.                           &tp->left_pixmap,
  531.                           &tp->left_width,
  532.                           &tp->left_height,
  533.                           XmNleftPixmap);
  534.     }
  535.  
  536.     if (flags & _XFE_PREPARE_TAB_RIGHT_PIXMAP)
  537.     {
  538.         _XfePixmapPrepare(w,
  539.                           &tp->right_pixmap,
  540.                           &tp->right_width,
  541.                           &tp->right_height,
  542.                           XmNrightPixmap);
  543.     }
  544.  
  545.     if (flags & _XFE_PREPARE_TAB_VERTICAL_PIXMAP)
  546.     {
  547.         _XfePixmapPrepare(w,
  548.                           &tp->vertical_pixmap,
  549.                           &tp->vertical_width,
  550.                           &tp->vertical_height,
  551.                           XmNverticalPixmap);
  552.     }
  553.  
  554.     if (flags & _XFE_PREPARE_TAB_HORIZONTAL_PIXMAP)
  555.     {
  556.         _XfePixmapPrepare(w,
  557.                           &tp->horizontal_pixmap,
  558.                           &tp->horizontal_width,
  559.                           &tp->horizontal_height,
  560.                           XmNhorizontalPixmap);
  561.     }
  562.  
  563.     if (flags & _XFE_PREPARE_TAB_BOTTOM_RAISED_PIXMAP)
  564.     {
  565.         _XfePixmapPrepare(w,
  566.                           &tp->bottom_raised_pixmap,
  567.                           NULL,
  568.                           NULL,
  569.                           XmNbottomRaisedPixmap);
  570.     }
  571.  
  572.     if (flags & _XFE_PREPARE_TAB_TOP_RAISED_PIXMAP)
  573.     {
  574.         _XfePixmapPrepare(w,
  575.                           &tp->top_raised_pixmap,
  576.                           NULL,
  577.                           NULL,
  578.                           XmNtopRaisedPixmap);
  579.     }
  580.  
  581.     if (flags & _XFE_PREPARE_TAB_LEFT_RAISED_PIXMAP)
  582.     {
  583.         _XfePixmapPrepare(w,
  584.                           &tp->left_raised_pixmap,
  585.                           NULL,
  586.                           NULL,
  587.                           XmNleftRaisedPixmap);
  588.     }
  589.  
  590.     if (flags & _XFE_PREPARE_TAB_RIGHT_RAISED_PIXMAP)
  591.     {
  592.         _XfePixmapPrepare(w,
  593.                           &tp->right_raised_pixmap,
  594.                           NULL,
  595.                           NULL,
  596.                           XmNrightRaisedPixmap);
  597.     }
  598.  
  599.     if (flags & _XFE_PREPARE_TAB_VERTICAL_RAISED_PIXMAP)
  600.     {
  601.         _XfePixmapPrepare(w,
  602.                           &tp->vertical_raised_pixmap,
  603.                           NULL,
  604.                           NULL,
  605.                           XmNverticalRaisedPixmap);
  606.     }
  607.  
  608.     if (flags & _XFE_PREPARE_TAB_HORIZONTAL_RAISED_PIXMAP)
  609.     {
  610.         _XfePixmapPrepare(w,
  611.                           &tp->horizontal_raised_pixmap,
  612.                           NULL,
  613.                           NULL,
  614.                           XmNhorizontalRaisedPixmap);
  615.     }
  616. }
  617. /*----------------------------------------------------------------------*/
  618. static void
  619. DrawBackground(Widget w,XEvent *event,Region region,XRectangle * clip_rect)
  620. {
  621.     XfeButtonWidgetClass    bwc = (XfeButtonWidgetClass) xfeButtonWidgetClass;
  622.  
  623.     /* Call the XfeButtonClass' DrawBackground() */
  624.     (*bwc->xfe_primitive_class.draw_background)(w,event,region,clip_rect);
  625.  
  626.     /* Draw the tab */
  627.     DrawTab(w,event,region,clip_rect);
  628. }
  629. /*----------------------------------------------------------------------*/
  630.  
  631.  
  632. /*----------------------------------------------------------------------*/
  633. /*                                                                        */
  634. /* Misc XfeTab functions                                                */
  635. /*                                                                        */
  636. /*----------------------------------------------------------------------*/
  637. static void
  638. DrawTab(Widget w,XEvent *event,Region region,XRectangle * clip_rect)
  639. {
  640.     XfeTabPart *        tp = _XfeTabPart(w);
  641.     XfeButtonPart *        bp = _XfeButtonPart(w);
  642.     Boolean                raised = _XfePointerInside(w);
  643.  
  644.     switch(tp->orientation)
  645.     {
  646.     case XmVERTICAL:
  647.     {
  648.         Pixmap vertical_pixmap;
  649.         Pixmap top_pixmap;
  650.         Pixmap bottom_pixmap;
  651.  
  652.         vertical_pixmap = 
  653.             (raised && _XfePixmapGood(tp->vertical_raised_pixmap)) ?
  654.             tp->vertical_raised_pixmap :
  655.             tp->vertical_pixmap;
  656.         
  657.         top_pixmap = 
  658.             (raised && _XfePixmapGood(tp->top_raised_pixmap)) ?
  659.             tp->top_raised_pixmap :
  660.             tp->top_pixmap;
  661.         
  662.         bottom_pixmap = 
  663.             (raised && _XfePixmapGood(tp->bottom_raised_pixmap)) ?
  664.             tp->bottom_raised_pixmap :
  665.             tp->bottom_pixmap;
  666.  
  667.         /* Draw vertical pixmap if needed */
  668.         if (_XfePixmapGood(vertical_pixmap))
  669.         {
  670.             FillTabVertical(w,vertical_pixmap,
  671.                             tp->vertical_width,
  672.                             tp->vertical_height);
  673.         }
  674.  
  675.         /* Draw top pixmap if needed */
  676.         if (_XfePixmapGood(top_pixmap) && 
  677.             tp->top_width && tp->top_height)
  678.         {
  679.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  680.  
  681.             XCopyArea(XtDisplay(w),
  682.                       top_pixmap,
  683.                       _XfePrimitiveDrawable(w),
  684.                       bp->pixmap_GC,
  685.                       0,0,
  686.                       tp->top_width,
  687.                       tp->top_height,
  688.                       (_XfeWidth(w) - tp->top_width) / 2,
  689.                       _XfeRectY(w));
  690.         }
  691.  
  692.         /* Draw bottom pixmap if needed */
  693.         if (_XfePixmapGood(bottom_pixmap) && 
  694.             tp->bottom_width && tp->bottom_height)
  695.         {
  696.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  697.  
  698.             XCopyArea(XtDisplay(w),
  699.                       bottom_pixmap,
  700.                       _XfePrimitiveDrawable(w),
  701.                       bp->pixmap_GC,
  702.                       0,0,
  703.                       tp->bottom_width,
  704.                       tp->bottom_height,
  705.                       (_XfeWidth(w) - tp->bottom_width) / 2,
  706.  
  707.                       _XfeHeight(w) - 
  708.                       _XfeOffsetBottom(w) -
  709.                       tp->bottom_height);
  710.         }
  711.     }
  712.     break;
  713.  
  714.     case XmHORIZONTAL:
  715.     {
  716.         Pixmap horizontal_pixmap;
  717.         Pixmap right_pixmap;
  718.         Pixmap left_pixmap;
  719.  
  720.         horizontal_pixmap = 
  721.             (raised && _XfePixmapGood(tp->horizontal_raised_pixmap)) ?
  722.             tp->horizontal_raised_pixmap :
  723.             tp->horizontal_pixmap;
  724.         
  725.         left_pixmap = 
  726.             (raised && _XfePixmapGood(tp->left_raised_pixmap)) ?
  727.             tp->left_raised_pixmap :
  728.             tp->left_pixmap;
  729.         
  730.         right_pixmap = 
  731.             (raised && _XfePixmapGood(tp->right_raised_pixmap)) ?
  732.             tp->right_raised_pixmap :
  733.             tp->right_pixmap;
  734.         
  735.         /* Draw horizontal pixmap if needed */
  736.         if (_XfePixmapGood(horizontal_pixmap))
  737.         {
  738.             FillTabHorizontal(w,horizontal_pixmap,
  739.                               tp->horizontal_width,
  740.                               tp->horizontal_height);
  741.         }
  742.  
  743.         /* Draw top pixmap if needed */
  744.         if (_XfePixmapGood(left_pixmap) && 
  745.             tp->left_width && tp->left_height)
  746.         {
  747.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  748.  
  749.             XCopyArea(XtDisplay(w),
  750.                       left_pixmap,
  751.                       _XfePrimitiveDrawable(w),
  752.                       bp->pixmap_GC,
  753.                       0,0,
  754.                       tp->left_width,
  755.                       tp->left_height,
  756.                       _XfeRectX(w),
  757.                       (_XfeHeight(w) - tp->left_height) / 2);
  758.         }
  759.  
  760.         /* Draw right pixmap if needed */
  761.         if (_XfePixmapGood(right_pixmap) && 
  762.             tp->right_width && tp->right_height)
  763.         {
  764.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  765.  
  766.             XCopyArea(XtDisplay(w),
  767.                       right_pixmap,
  768.                       _XfePrimitiveDrawable(w),
  769.                       bp->pixmap_GC,
  770.                       0,0,
  771.                       tp->right_width,
  772.                       tp->right_height,
  773.                       
  774.                       _XfeWidth(w) - 
  775.                       _XfeOffsetRight(w) -
  776.                       tp->right_width,
  777.  
  778.                       (_XfeHeight(w) - tp->right_height) / 2);
  779.         }
  780.  
  781.     }
  782.         break;
  783.     }
  784.  
  785. }
  786. /*----------------------------------------------------------------------*/
  787. static void
  788. FillTabVertical(Widget w,Pixmap pixmap,Dimension width,Dimension height)
  789. {
  790.     XfeTabPart *        tp = _XfeTabPart(w);
  791.     XfeButtonPart *        bp = _XfeButtonPart(w);
  792.     Position            y;
  793.     Boolean                done = False;
  794.     Dimension            copy_height;
  795.     Dimension            max_y = _XfeHeight(w) - _XfeOffsetBottom(w);
  796.  
  797.     if (_XfePixmapGood(tp->top_pixmap))
  798.       y = _XfeOffsetTop(w) + tp->top_height;
  799.     else
  800.       y = _XfeOffsetTop(w);
  801.  
  802.     while(!done)
  803.     {
  804.         copy_height = height;
  805.  
  806.         if ((y + copy_height) > max_y)
  807.         {
  808.             copy_height -= (y + copy_height - max_y);
  809.         }
  810.  
  811.         if (copy_height)
  812.         {
  813.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  814.  
  815.             XCopyArea(XtDisplay(w),
  816.                       pixmap,
  817.                       _XfePrimitiveDrawable(w),
  818.                       bp->pixmap_GC,
  819.                       0,0,
  820.                       width,
  821.                       height,
  822.                       (_XfeWidth(w) - width) / 2,
  823.                       y);
  824.         }
  825.  
  826.         done = (copy_height < height);
  827.  
  828.         y += height;
  829.     }
  830. }
  831. /*----------------------------------------------------------------------*/
  832. static void
  833. FillTabHorizontal(Widget w,Pixmap pixmap,Dimension width,Dimension height)
  834. {
  835.     XfeTabPart *        tp = _XfeTabPart(w);
  836.     XfeButtonPart *        bp = _XfeButtonPart(w);
  837.     Position            x;
  838.     Boolean                done = False;
  839.     Dimension            copy_width;
  840.     Dimension            max_x = _XfeWidth(w) - _XfeOffsetRight(w);
  841.  
  842.     if (_XfePixmapGood(tp->left_pixmap))
  843.       x = _XfeOffsetLeft(w) + tp->left_width;
  844.     else 
  845.       x = _XfeOffsetLeft(w);
  846.  
  847.     while(!done)
  848.     {
  849.         copy_width = width;
  850.  
  851.         if ((x + copy_width) > max_x)
  852.         {
  853.             copy_width -= (x + copy_width - max_x);
  854.         }
  855.  
  856.         if (copy_width)
  857.         {
  858.             XSetClipMask(XtDisplay(w),bp->pixmap_GC,None);
  859.  
  860.             XCopyArea(XtDisplay(w),
  861.                       pixmap,
  862.                       _XfePrimitiveDrawable(w),
  863.                       bp->pixmap_GC,
  864.                       0,0,
  865.                       width,
  866.                       height,
  867.                       x,
  868.                       (_XfeHeight(w) - height) / 2);
  869.         }
  870.  
  871.         done = (copy_width < width);
  872.  
  873.         x += width;
  874.     }
  875. }
  876. /*----------------------------------------------------------------------*/
  877.  
  878. /*----------------------------------------------------------------------*/
  879. /*                                                                        */
  880. /* XfeTab Public Methods                                                */
  881. /*                                                                        */
  882. /*----------------------------------------------------------------------*/
  883. Widget
  884. XfeCreateTab(Widget parent,char *name,Arg *args,Cardinal count)
  885. {
  886.     return (XtCreateWidget(name,xfeTabWidgetClass,parent,args,count));
  887. }
  888. /*----------------------------------------------------------------------*/
  889.