home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / XKBGeom.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  23KB  |  805 lines

  1. /* $XConsortium: XKBGeom.c /main/7 1996/02/02 14:38:29 kaleb $ */
  2. /************************************************************
  3. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  4.  
  5. Permission to use, copy, modify, and distribute this
  6. software and its documentation for any purpose and without
  7. fee is hereby granted, provided that the above copyright
  8. notice appear in all copies and that both that copyright
  9. notice and this permission notice appear in supporting
  10. documentation, and that the name of Silicon Graphics not be 
  11. used in advertising or publicity pertaining to distribution 
  12. of the software without specific prior written permission.
  13. Silicon Graphics makes no representation about the suitability 
  14. of this software for any purpose. It is provided "as is"
  15. without any express or implied warranty.
  16.  
  17. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  18. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
  19. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  20. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  21. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
  22. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
  23. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  24. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  
  26. ********************************************************/
  27.  
  28. #ifdef DEBUG
  29. #include <stdio.h>
  30. #endif
  31.  
  32. #define NEED_EVENTS
  33. #define NEED_REPLIES
  34. #include "Xlib_private.h"
  35. #include "XKBlibint.h"
  36. #include <X11/extensions/XKBgeom.h>
  37. #include <X11/extensions/XKBproto.h>
  38.  
  39. #ifndef MINSHORT
  40. #define    MINSHORT    -32768
  41. #endif
  42. #ifndef MAXSHORT
  43. #define    MAXSHORT    32767
  44. #endif
  45.  
  46. /***====================================================================***/
  47.  
  48. static void
  49. #if NeedFunctionPrototypes
  50. _XkbCheckBounds(XkbBoundsPtr bounds,int    x,int y)
  51. #else
  52. _XkbCheckBounds(bounds,x,y)
  53.     XkbBoundsPtr    bounds;
  54.     int            x,y;
  55. #endif
  56. {
  57.     DBUG_ENTER("_XkbCheckBounds")
  58.     if (x<bounds->x1)    bounds->x1= x;
  59.     if (x>bounds->x2)    bounds->x2= x;
  60.     if (y<bounds->y1)    bounds->y1= y;
  61.     if (y>bounds->y2)    bounds->y2= y;
  62.     DBUG_VOID_RETURN;
  63. }
  64.  
  65. Bool
  66. #if NeedFunctionPrototypes
  67. XkbComputeShapeBounds(XkbShapePtr shape)
  68. #else
  69. XkbComputeShapeBounds(shape)
  70.    XkbShapePtr    shape;
  71. #endif
  72. {
  73.     DBUG_ENTER("XkbComputeShapeBounds")
  74.     register int    o,p;
  75.     XkbOutlinePtr    outline;
  76.     XkbPointPtr    pt;
  77.  
  78.     if ((!shape)||(shape->num_outlines<1))
  79.     DBUG_RETURN(False);
  80.     shape->bounds.x1= shape->bounds.y1= MAXSHORT;
  81.     shape->bounds.x2= shape->bounds.y2= MINSHORT;
  82.     for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) {
  83.     for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
  84.         _XkbCheckBounds(&shape->bounds,pt->x,pt->y);
  85.     }
  86.     }
  87.     DBUG_RETURN(True);
  88. }
  89.  
  90. Bool
  91. #if NeedFunctionPrototypes
  92. XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds)
  93. #else
  94. XkbComputeShapeTop(shape,bounds)
  95.    XkbShapePtr    shape;
  96.    XkbBoundsPtr    bounds;
  97. #endif
  98. {
  99.     DBUG_ENTER("XkbComputeShapeTop")
  100.     register int    p;
  101.     XkbOutlinePtr    outline;
  102.     XkbPointPtr    pt;
  103.  
  104.     if ((!shape)||(shape->num_outlines<1))
  105.     DBUG_RETURN(False);
  106.     if (shape->approx)    outline= shape->approx;
  107.     else        outline= &shape->outlines[shape->num_outlines-1];
  108.     if (outline->num_points<2) {
  109.      bounds->x1= bounds->y1= 0;
  110.      bounds->x2= bounds->y2= 0;
  111.     }
  112.     else {
  113.     bounds->x1= bounds->y1= MAXSHORT;
  114.     bounds->x2= bounds->y2= MINSHORT;
  115.     }
  116.     for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
  117.     _XkbCheckBounds(bounds,pt->x,pt->y);
  118.     }
  119.     DBUG_RETURN(True);
  120. }
  121.  
  122. Bool
  123. #if NeedFunctionPrototypes
  124. XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row)
  125. #else
  126. XkbComputeRowBounds(geom,section,row)
  127.     XkbGeometryPtr    geom;
  128.     XkbSectionPtr    section;
  129.     XkbRowPtr        row;
  130. #endif
  131. {
  132.     DBUG_ENTER("XkbComputeRowBounds")
  133.     register int    k,pos;
  134.     XkbKeyPtr    key;
  135.     XkbBoundsPtr    bounds,sbounds;
  136.  
  137.     if ((!geom)||(!section)||(!row))
  138.     DBUG_RETURN(False);
  139.     pos= 0;
  140.     bounds= &row->bounds;
  141.     bzero(bounds,sizeof(XkbBoundsRec));
  142.     for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) {
  143.     sbounds= &XkbKeyShape(geom,key)->bounds;
  144.     _XkbCheckBounds(bounds,pos,0);
  145.     if (!row->vertical) {
  146.         if (key->gap!=0) {
  147.         pos+= key->gap;
  148.         _XkbCheckBounds(bounds,pos,0);
  149.         }
  150.         _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
  151.         _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
  152.         pos+= sbounds->x2;
  153.     }
  154.     else {
  155.         if (key->gap!=0) {
  156.         pos+= key->gap;
  157.         _XkbCheckBounds(bounds,0,pos);
  158.         }
  159.         _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
  160.         _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
  161.         pos+= sbounds->y2;
  162.     }
  163.     }
  164.     DBUG_RETURN(True);
  165. }
  166.  
  167. Bool
  168. #if NeedFunctionPrototypes
  169. XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section)
  170. #else
  171. XkbComputeSectionBounds(geom,section)
  172.     XkbGeometryPtr    geom;
  173.     XkbSectionPtr    section;
  174. #endif
  175. {
  176.     DBUG_ENTER("XkbComputeSectionBounds")
  177.     register int    i;
  178.     XkbShapePtr    shape;
  179.     XkbRowPtr    row;
  180.     XkbDoodadPtr    doodad;
  181.     XkbBoundsPtr    bounds,rbounds;
  182.  
  183.     if ((!geom)||(!section))
  184.     DBUG_RETURN(False);
  185.     bounds= §ion->bounds;
  186.     bzero(bounds,sizeof(XkbBoundsRec));
  187.     for (i=0,row=section->rows;i<section->num_rows;i++,row++) {
  188.     if (!XkbComputeRowBounds(geom,section,row))
  189.         DBUG_RETURN(False);
  190.     rbounds= &row->bounds;
  191.     _XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1);
  192.     _XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2);
  193.     }
  194.     for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) {
  195.     static XkbBoundsRec    tbounds;
  196.     switch (doodad->any.type) {
  197.         case XkbOutlineDoodad:
  198.         case XkbSolidDoodad:
  199.         shape= XkbShapeDoodadShape(geom,&doodad->shape);
  200.         rbounds= &shape->bounds;
  201.         break;
  202.         case XkbTextDoodad:
  203.         tbounds.x1= doodad->text.left;
  204.         tbounds.y1= doodad->text.top;
  205.         tbounds.x2= tbounds.x1+doodad->text.width;
  206.         tbounds.y2= tbounds.y1+doodad->text.height;
  207.         rbounds= &tbounds;
  208.         break;
  209.         case XkbIndicatorDoodad:
  210.         shape= XkbIndicatorDoodadShape(geom,&doodad->indicator);
  211.         rbounds= &shape->bounds;
  212.         break;
  213.         case XkbLogoDoodad:
  214.         shape= XkbLogoDoodadShape(geom,&doodad->logo);
  215.         rbounds= &shape->bounds;
  216.         break;
  217.         default:
  218.         tbounds.x1= tbounds.x2= doodad->any.left;
  219.         tbounds.y1= tbounds.y2= doodad->any.top;
  220.         break;
  221.     }
  222.     _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1);
  223.     _XkbCheckBounds(bounds,rbounds->x2,rbounds->y2);
  224.     }
  225.     DBUG_RETURN(True);
  226. }
  227.  
  228. /***====================================================================***/
  229.  
  230. char *
  231. #if NeedFunctionPrototypes
  232. XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under)
  233. #else
  234. XkbFindOverlayForKey(geom,wanted,under)
  235.     XkbGeometryPtr    geom;
  236.     XkbSectionPtr    wanted;
  237.     char *        under;
  238. #endif
  239. {
  240.     DBUG_ENTER("XkbFindOverlayForKey")
  241.     int        s;
  242.     XkbSectionPtr    section;
  243.  
  244.     if ((geom==NULL)||(under==NULL)||(geom->num_sections<1))
  245.     DBUG_RETURN(NULL);
  246.  
  247.     if (wanted)
  248.      section= wanted;
  249.     else section= geom->sections;
  250.  
  251.     for (s=0;s<geom->num_sections;s++,section++) {
  252.     XkbOverlayPtr    ol;
  253.     int        o;
  254.  
  255.     if (section->num_overlays<1)
  256.         continue;
  257.     for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
  258.         XkbOverlayRowPtr    row;
  259.         int            r;
  260.  
  261.         for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
  262.         XkbOverlayKeyPtr    key;
  263.         int            k;
  264.         for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
  265.             if (strncmp(under,key->under.name,XkbKeyNameLength)==0)
  266.             DBUG_RETURN(key->over.name);
  267.         }
  268.         }
  269.     }
  270.     if (wanted!=NULL)
  271.         break;
  272.     }
  273.     DBUG_RETURN(NULL);
  274. }
  275.  
  276. /***====================================================================***/
  277.  
  278. static Status
  279. #if NeedFunctionPrototypes
  280. _XkbReadGeomProperties(    XkbReadBufferPtr    buf,
  281.             XkbGeometryPtr         geom,
  282.             xkbGetGeometryReply *    rep)
  283. #else
  284. _XkbReadGeomProperties(buf,geom,rep)
  285.     XkbReadBufferPtr        buf;
  286.     XkbGeometryPtr        geom;
  287.     xkbGetGeometryReply *    rep;
  288. #endif
  289. {
  290.     DBUG_ENTER("_XkbReadGeomProperties")
  291.     Status    rtrn;
  292.  
  293.     if (rep->nProperties<1)
  294.     DBUG_RETURN(Success);
  295.     if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) {
  296.     register int i;
  297.     register Bool ok;
  298.     char *name,*value;
  299.     ok= True;
  300.     for (i=0;(i<rep->nProperties)&&ok;i++) {
  301.         ok= _XkbGetReadBufferCountedString(buf,&name)&&ok;
  302.         ok= _XkbGetReadBufferCountedString(buf,&value)&&ok;
  303.         ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL);
  304.     }
  305.     if (ok)    rtrn= Success;
  306.     else    rtrn= BadLength;
  307.     }
  308.     DBUG_RETURN(rtrn);
  309. }
  310.  
  311. static Status
  312. #if NeedFunctionPrototypes
  313. _XkbReadGeomKeyAliases(    XkbReadBufferPtr    buf,
  314.             XkbGeometryPtr        geom,
  315.             xkbGetGeometryReply *    rep)
  316. #else
  317. _XkbReadGeomKeyAliases(buf,geom,rep)
  318.     XkbReadBufferPtr        buf;
  319.     XkbGeometryPtr        geom;
  320.     xkbGetGeometryReply *    rep;
  321. #endif
  322. {
  323.     DBUG_ENTER("_XkbReadGeomKeyAliases")
  324.     Status    rtrn;
  325.  
  326.     if (rep->nKeyAliases<1)
  327.     DBUG_RETURN(Success);
  328.     if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) {
  329.     register int i;
  330.     if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases,
  331.                     (rep->nKeyAliases*XkbKeyNameLength*2)))
  332.         DBUG_RETURN(BadLength);
  333.     geom->num_key_aliases= rep->nKeyAliases;
  334.     DBUG_RETURN(Success);
  335.     }
  336.     else { /* alloc failed, just skip the aliases */
  337.     _XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2));
  338.     }
  339.     DBUG_RETURN(rtrn);
  340. }
  341.  
  342. static Status
  343. #if NeedFunctionPrototypes
  344. _XkbReadGeomColors(    XkbReadBufferPtr    buf,
  345.             XkbGeometryPtr        geom,
  346.             xkbGetGeometryReply *    rep)
  347. #else
  348. _XkbReadGeomColors(buf,geom,rep)
  349.     XkbReadBufferPtr        buf;
  350.     XkbGeometryPtr        geom;
  351.     xkbGetGeometryReply *    rep;
  352. #endif
  353. {
  354.     DBUG_ENTER("_XkbReadGeomColors")
  355.     Status    rtrn;
  356.  
  357.     if (rep->nColors<1)
  358.     DBUG_RETURN(Success);
  359.     if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) {
  360.     register int i;
  361.     char *spec;
  362.     for (i=0;i<rep->nColors;i++) {
  363.         if (!_XkbGetReadBufferCountedString(buf,&spec))
  364.         DBUG_RETURN(BadLength);
  365.         if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL)
  366.         DBUG_RETURN(BadAlloc);
  367.     }
  368.     DBUG_RETURN(Success);
  369.     }
  370.     DBUG_RETURN(rtrn);
  371. }
  372.  
  373. static Status
  374. #if NeedFunctionPrototypes
  375. _XkbReadGeomShapes(    XkbReadBufferPtr    buf,
  376.             XkbGeometryPtr        geom,
  377.             xkbGetGeometryReply *    rep)
  378. #else
  379. _XkbReadGeomShapes(buf,geom,rep)
  380.     XkbReadBufferPtr        buf;
  381.     XkbGeometryPtr        geom;
  382.     xkbGetGeometryReply *    rep;
  383. #endif
  384. {
  385.     DBUG_ENTER("_XkbReadGeomShapes")
  386.     register int i;
  387.     Status    rtrn;
  388.  
  389.     if (rep->nShapes<1)
  390.     DBUG_RETURN(Success);
  391.     if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success)
  392.     DBUG_RETURN(rtrn);
  393.     for (i=0;i<rep->nShapes;i++) {
  394.     xkbShapeWireDesc *shapeWire;
  395.     XkbShapePtr     shape;
  396.     register int     o;
  397.     shapeWire= (xkbShapeWireDesc *)
  398.            _XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc));
  399.     if (!shapeWire)
  400.         DBUG_RETURN(BadLength);
  401.     shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines);
  402.     if (!shape)
  403.        DBUG_RETURN(BadAlloc);
  404.     for (o=0;o<shapeWire->nOutlines;o++) {
  405.         xkbOutlineWireDesc *olWire;
  406.         XkbOutlinePtr    ol;
  407.         register int    p;
  408.         XkbPointPtr        pt;
  409.         olWire=  (xkbOutlineWireDesc *)
  410.          _XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc));
  411.         if (!olWire)
  412.         DBUG_RETURN(BadLength);
  413.         ol= XkbAddGeomOutline(shape,olWire->nPoints);
  414.         if (!ol)
  415.         DBUG_RETURN(BadAlloc);
  416.         ol->corner_radius=  olWire->cornerRadius;
  417.         for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) {
  418.         xkbPointWireDesc *    ptWire;
  419.         ptWire= (xkbPointWireDesc *)
  420.             _XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc));
  421.         if (!ptWire)
  422.             DBUG_RETURN(BadLength);
  423.         pt->x= ptWire->x;
  424.         pt->y= ptWire->y;
  425.         }
  426.         ol->num_points= olWire->nPoints;
  427.     }
  428.     if (shapeWire->primaryNdx!=XkbNoShape)
  429.          shape->primary= &shape->outlines[shapeWire->primaryNdx];
  430.     else shape->primary= NULL;
  431.     if (shapeWire->approxNdx!=XkbNoShape)
  432.          shape->approx= &shape->outlines[shapeWire->approxNdx];
  433.     else shape->approx= NULL;
  434.     XkbComputeShapeBounds(shape);
  435.     }
  436.     DBUG_RETURN(Success);
  437. }
  438.  
  439. static Status
  440. #if NeedFunctionPrototypes
  441. _XkbReadGeomDoodad(    XkbReadBufferPtr     buf,
  442.             XkbGeometryPtr         geom,
  443.             XkbSectionPtr         section)
  444. #else
  445. _XkbReadGeomDoodad(buf,geom,section)
  446.     XkbReadBufferPtr        buf;
  447.     XkbGeometryPtr        geom;
  448.     XkbSectionPtr        section;
  449. #endif
  450. {
  451.     DBUG_ENTER("_XkbReadGeomDoodad")
  452.     XkbDoodadPtr        doodad;
  453.     xkbDoodadWireDesc *    doodadWire;
  454.  
  455.     doodadWire= (xkbDoodadWireDesc *)
  456.            _XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc));
  457.     if (!doodadWire)
  458.     DBUG_RETURN(BadLength);
  459.     doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name);
  460.     if (!doodad)
  461.     DBUG_RETURN(BadAlloc);
  462.     doodad->any.type= doodadWire->any.type;
  463.     doodad->any.priority= doodadWire->any.priority;
  464.     doodad->any.top= doodadWire->any.top;
  465.     doodad->any.left= doodadWire->any.left;
  466.     doodad->any.angle= doodadWire->any.angle;
  467.     switch (doodad->any.type) {
  468.     case XkbOutlineDoodad:
  469.     case XkbSolidDoodad:
  470.         doodad->shape.color_ndx= doodadWire->shape.colorNdx;
  471.         doodad->shape.shape_ndx= doodadWire->shape.shapeNdx;
  472.         break;
  473.     case XkbTextDoodad:
  474.         doodad->text.width= doodadWire->text.width;
  475.         doodad->text.height= doodadWire->text.height;
  476.         doodad->text.color_ndx= doodadWire->text.colorNdx;
  477.         if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text))
  478.         DBUG_RETURN(BadLength);
  479.         if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font))
  480.         DBUG_RETURN(BadLength);
  481.         break;
  482.     case XkbIndicatorDoodad:
  483.         doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx;
  484.         doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx;
  485.         doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx;
  486.         break;
  487.     case XkbLogoDoodad:
  488.         doodad->logo.color_ndx= doodadWire->logo.colorNdx;
  489.         doodad->logo.shape_ndx= doodadWire->logo.shapeNdx;
  490.         if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name))
  491.         DBUG_RETURN(BadLength);
  492.         break;
  493.     default:
  494.         DBUG_RETURN(BadValue);
  495.     }
  496.     DBUG_RETURN(Success);
  497. }
  498.  
  499. static Status
  500. #if NeedFunctionPrototypes
  501. _XkbReadGeomOverlay(    XkbReadBufferPtr    buf,
  502.             XkbGeometryPtr        geom,
  503.             XkbSectionPtr        section)
  504. #else
  505. _XkbReadGeomOverlay(buf,geom,section)
  506.     XkbReadBufferPtr        buf;
  507.     XkbGeometryPtr        geom;
  508.     XkbSectionPtr        section;
  509. #endif
  510. {
  511.     DBUG_ENTER("_XkbReadGeomOverlay")
  512.     XkbOverlayPtr        ol;
  513.     xkbOverlayWireDesc *    olWire;
  514.     register int        r;
  515.  
  516.     olWire= (xkbOverlayWireDesc *)
  517.            _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc));
  518.     if (olWire==NULL)
  519.     DBUG_RETURN(BadLength);
  520.     ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows);
  521.     if (ol==NULL)
  522.     DBUG_RETURN(BadLength);
  523.     for (r=0;r<olWire->nRows;r++) {
  524.     register int             k;
  525.     XkbOverlayRowPtr        row;
  526.     xkbOverlayRowWireDesc *        rowWire;
  527.     xkbOverlayKeyWireDesc *        keyWire;
  528.     rowWire= (xkbOverlayRowWireDesc *)
  529.             _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc));
  530.     if (rowWire==NULL)
  531.         DBUG_RETURN(BadLength);
  532.     row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys);
  533.     row->row_under= rowWire->rowUnder;
  534.     if (!row)
  535.         DBUG_RETURN(BadAlloc);
  536.     if (rowWire->nKeys<1)
  537.         continue;
  538.     keyWire= (xkbOverlayKeyWireDesc *)
  539.                  _XkbGetReadBufferPtr(buf,
  540.                 SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys);
  541.     if (keyWire==NULL)
  542.         DBUG_RETURN(BadLength);
  543.     for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) {
  544.         memcpy(row->keys[row->num_keys].over.name,keyWire->over,
  545.                                 XkbKeyNameLength);
  546.         memcpy(row->keys[row->num_keys].under.name,keyWire->under,
  547.                                 XkbKeyNameLength);
  548.     }
  549.     }
  550.     DBUG_RETURN(Success);
  551. }
  552.  
  553. static Status
  554. #if NeedFunctionPrototypes
  555. _XkbReadGeomSections(    XkbReadBufferPtr    buf,
  556.             XkbGeometryPtr        geom,
  557.             xkbGetGeometryReply *    rep)
  558. #else
  559. _XkbReadGeomSections(buf,geom,rep)
  560.     XkbReadBufferPtr        buf;
  561.     XkbGeometryPtr        geom;
  562.     xkbGetGeometryReply *    rep;
  563. #endif
  564. {
  565.     DBUG_ENTER("_XkbReadGeomSections")
  566.     register int         s;
  567.     XkbSectionPtr        section;
  568.     xkbSectionWireDesc *    sectionWire;
  569.     Status            rtrn;
  570.  
  571.     if (rep->nSections<1)
  572.     DBUG_RETURN(Success);
  573.     if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success)
  574.     DBUG_RETURN(rtrn);
  575.     for (s=0;s<rep->nSections;s++) {
  576.     sectionWire= (xkbSectionWireDesc *)
  577.             _XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc));
  578.     if (!sectionWire)
  579.         DBUG_RETURN(BadLength);
  580.     section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows,
  581.                         sectionWire->nDoodads,
  582.                         sectionWire->nOverlays);
  583.     if (!section)
  584.         DBUG_RETURN(BadAlloc);
  585.     section->top= sectionWire->top;
  586.     section->left= sectionWire->left;
  587.     section->width= sectionWire->width;
  588.     section->height= sectionWire->height;
  589.     section->angle= sectionWire->angle;
  590.     section->priority= sectionWire->priority;
  591.     if (sectionWire->nRows>0) {
  592.         register int     r;
  593.         XkbRowPtr        row;
  594.         xkbRowWireDesc *    rowWire;
  595.         for (r=0;r<sectionWire->nRows;r++) {
  596.         rowWire= (xkbRowWireDesc *)
  597.              _XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc));
  598.         if (!rowWire)
  599.             DBUG_RETURN(BadLength);
  600.         row= XkbAddGeomRow(section,rowWire->nKeys);
  601.         if (!row)
  602.             DBUG_RETURN(BadAlloc);
  603.         row->top= rowWire->top;
  604.         row->left= rowWire->left;
  605.         row->vertical= rowWire->vertical;
  606.         if (rowWire->nKeys>0) {
  607.             register int    k;
  608.             XkbKeyPtr        key;
  609.             xkbKeyWireDesc *    keyWire;
  610.             for (k=0;k<rowWire->nKeys;k++) {
  611.             keyWire= (xkbKeyWireDesc *)
  612.                   _XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc));
  613.             if (!keyWire)
  614.                 DBUG_RETURN(BadLength);
  615.             key= XkbAddGeomKey(row);
  616.             if (!key)
  617.                 DBUG_RETURN(BadAlloc);
  618.             memcpy(key->name.name,keyWire->name,XkbKeyNameLength);
  619.             key->gap= keyWire->gap;
  620.             key->shape_ndx= keyWire->shapeNdx;
  621.             key->color_ndx= keyWire->colorNdx;
  622.             }
  623.         }
  624.         }
  625.     }
  626.     if (sectionWire->nDoodads>0) {
  627.         register int d;
  628.         for (d=0;d<sectionWire->nDoodads;d++) {
  629.         if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success)
  630.             DBUG_RETURN(rtrn);
  631.         }
  632.     }
  633.     if (sectionWire->nOverlays>0) {
  634.         register int o;
  635.         for (o=0;o<sectionWire->nOverlays;o++) {
  636.         if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success)
  637.             DBUG_RETURN(rtrn);
  638.         }
  639.     }
  640.     }
  641.     DBUG_RETURN(Success);
  642. }
  643.  
  644. static Status
  645. #if NeedFunctionPrototypes
  646. _XkbReadGeomDoodads(    XkbReadBufferPtr    buf,
  647.             XkbGeometryPtr        geom,
  648.             xkbGetGeometryReply *    rep)
  649. #else
  650. _XkbReadGeomDoodads(buf,geom,rep)
  651.     XkbReadBufferPtr        buf;
  652.     XkbGeometryPtr        geom;
  653.     xkbGetGeometryReply *    rep;
  654. #endif
  655. {
  656.     DBUG_ENTER("_XkbReadGeomDoodads")
  657.     register int d;
  658.     Status    rtrn;
  659.  
  660.     if (rep->nDoodads<1)
  661.     DBUG_RETURN(Success);
  662.     if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success)
  663.     DBUG_RETURN(rtrn);
  664.     for (d=0;d<rep->nDoodads;d++) {
  665.     if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success)
  666.         DBUG_RETURN(rtrn);
  667.     }
  668.     DBUG_RETURN(Success);
  669. }
  670.  
  671. Status
  672. #if NeedFunctionPrototypes
  673. _XkbReadGetGeometryReply(    Display * dpy,
  674.                 xkbGetGeometryReply * rep,
  675.                 XkbDescPtr xkb,
  676.                 int * nread_rtrn)
  677. #else
  678. _XkbReadGetGeometryReply(dpy,rep,xkb,nread_rtrn)
  679.     Display *            dpy;
  680.     xkbGetGeometryReply *    rep;
  681.     XkbDescPtr            xkb;
  682.     int *            nread_rtrn;
  683. #endif
  684. {
  685.     DBUG_ENTER("_XkbReadGetGeometryReply")
  686.     XkbGeometryPtr    geom;
  687.  
  688.     geom= _XkbTypedCalloc(1,XkbGeometryRec);
  689.     if (!geom)
  690.     DBUG_RETURN(BadAlloc);
  691.     if (xkb->geom)
  692.     XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
  693.     xkb->geom= geom;
  694.  
  695.     geom->name= rep->name;
  696.     geom->width_mm= rep->widthMM;
  697.     geom->height_mm= rep->heightMM;
  698.     if (rep->length) {
  699.     XkbReadBufferRec    buf;
  700.     int            left;
  701.     if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) {
  702.         Status status= Success;
  703.         if (nread_rtrn)
  704.         *nread_rtrn= (int)rep->length*4;
  705.         if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font))
  706.         status= BadLength;
  707.         if (status==Success)
  708.         status= _XkbReadGeomProperties(&buf,geom,rep);
  709.         if (status==Success)
  710.         status= _XkbReadGeomColors(&buf,geom,rep);
  711.         if (status==Success)
  712.         status= _XkbReadGeomShapes(&buf,geom,rep);
  713.         if (status==Success)
  714.         status= _XkbReadGeomSections(&buf,geom,rep);
  715.         if (status==Success)
  716.         status= _XkbReadGeomDoodads(&buf,geom,rep);
  717.         if (status==Success)
  718.         status= _XkbReadGeomKeyAliases(&buf,geom,rep);
  719.         left= _XkbFreeReadBuffer(&buf);
  720.         if ((status!=Success) || left || buf.error) {
  721.         if (status==Success)    
  722.             status= BadLength;
  723.         XkbFreeGeometry(geom,XkbGeomAllMask,True);
  724.         xkb->geom= NULL;
  725.         DBUG_RETURN(status);
  726.         }
  727.         geom->base_color= &geom->colors[rep->baseColorNdx];
  728.         geom->label_color= &geom->colors[rep->labelColorNdx];
  729.     }
  730.     else {
  731.         XkbFreeGeometry(geom,XkbGeomAllMask,True);
  732.         xkb->geom= NULL;
  733.         DBUG_RETURN(BadAlloc);
  734.     }
  735.     }
  736.     DBUG_RETURN(Success);
  737. }
  738.  
  739. #if 0
  740. Status
  741. #if NeedFunctionPrototypes
  742. XkbGetGeometry(Display *dpy,XkbDescPtr xkb)
  743. #else
  744. XkbGetGeometry(dpy,xkb)
  745.     Display *    dpy;
  746.     XkbDescPtr    xkb;
  747. #endif
  748. {
  749.     DBUG_ENTER("XkbGetGeometry")
  750.     xkbGetGeometryReq    *req;
  751.     xkbGetGeometryReply     rep;
  752.  
  753.     if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
  754.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  755.     DBUG_RETURN(BadAccess);
  756.     
  757.     GetReq(kbGetGeometry, req);
  758.     req->reqType = dpy->xkb_info->codes->major_opcode;
  759.     req->xkbReqType = X_kbGetGeometry;
  760.     req->deviceSpec = xkb->device_spec;
  761.     req->name= None;
  762.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
  763.     DBUG_RETURN(BadImplementation);
  764.     if (!rep.found)
  765.     DBUG_RETURN(BadName);
  766.     {
  767.     Status result = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
  768.     DBUG_RETURN(result);
  769.     }
  770. }
  771.  
  772. Status
  773. #if NeedFunctionPrototypes
  774. XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name)
  775. #else
  776. XkbGetNamedGeometry(dpy,xkb,name)
  777.     Display *    dpy;
  778.     XkbDescPtr    xkb;
  779.     Atom    name;
  780. #endif
  781. {
  782.     DBUG_ENTER("XkbGetNamedGeometry")
  783.     xkbGetGeometryReq    *req;
  784.     xkbGetGeometryReply     rep;
  785.  
  786.     if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) ||
  787.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
  788.     DBUG_RETURN(BadAccess);
  789.     
  790.     GetReq(kbGetGeometry, req);
  791.     req->reqType = dpy->xkb_info->codes->major_opcode;
  792.     req->xkbReqType = X_kbGetGeometry;
  793.     req->deviceSpec = xkb->device_spec;
  794.     req->name= (CARD32)name;
  795.     if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found))
  796.     DBUG_RETURN(BadImplementation);
  797.     if (!rep.found)
  798.     DBUG_RETURN(BadName);
  799.     {
  800.     Status result = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
  801.     DBUG_RETURN(result);
  802.     }
  803. }
  804. #endif
  805.