home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / ListUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.4 KB  |  287 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/ListUtil.c>                                        */
  21. /* Description:    List misc utilities source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28. #include <Xfe/PrimitiveP.h>
  29. #include <Xfe/ManagerP.h>
  30. #include <Xfe/ListUtilP.h>
  31.  
  32. #include <Xm/ScrolledWP.h>
  33.  
  34. #define SW_ACCESS(_w,_m) (((XmScrolledWindowWidget) _w ) -> swindow . _m)
  35.  
  36. /*----------------------------------------------------------------------*/
  37. /*                                                                        */
  38. /* XmList utilities.                                                    */
  39. /*                                                                        */
  40. /*----------------------------------------------------------------------*/
  41. /* extern */ int
  42. XfeListGetItemCount(Widget list)
  43. {
  44.     assert( _XfeIsAlive(list) );
  45.     assert( XmIsList(list) );
  46.  
  47.     return _XfeXmListAccess(list,itemCount);
  48. }
  49. /*----------------------------------------------------------------------*/
  50. /* extern */ int
  51. XfeListGetSelectedItemPos(Widget list)
  52. {
  53.     int *        sel_items;
  54.     int            sel_item_count;
  55.     int            position = -1;
  56.  
  57.     if (XmListGetSelectedPos(list,&sel_items,&sel_item_count))
  58.     {
  59.         if (sel_items)
  60.         {
  61.             position = sel_items[0];
  62.         
  63.             XtFree((char *) sel_items);
  64.         }
  65.     }
  66.  
  67.     return position;
  68. }
  69. /*----------------------------------------------------------------------*/
  70. /* extern */ XmString
  71. XfeListGetSelectedItem(Widget list)
  72. {
  73.     XmString    item = NULL;
  74.     XmString *    sel_items;
  75.     int            sel_item_count;
  76.  
  77.     XtVaGetValues(list,
  78.                   XmNselectedItems,        &sel_items,
  79.                   XmNselectedItemCount,    &sel_item_count,
  80.                   NULL);
  81.  
  82.     if (sel_item_count)
  83.     {
  84.         item = sel_items[0];
  85.     }
  86.  
  87.     return item;
  88. }
  89. /*----------------------------------------------------------------------*/
  90. /* extern */ void
  91. XfeListSelectItemAtPos(Widget list,int position)
  92. {
  93.     assert( _XfeIsAlive(list) );
  94.     assert( XmIsList(list) );
  95.  
  96.     if (position > 0)
  97.     {
  98.         XmListSelectPos(list,position,False);
  99.     }
  100. }
  101. /*----------------------------------------------------------------------*/
  102. /* extern */ void
  103. XfeListDeselectItemAtPos(Widget list,int position)
  104. {
  105.     assert( _XfeIsAlive(list) );
  106.     assert( XmIsList(list) );
  107.  
  108.     if (position > 0)
  109.     {
  110.         XmListDeselectPos(list,position);
  111.     }
  112. }
  113. /*----------------------------------------------------------------------*/
  114. /* extern */ int
  115. XfeListGetItemAtY(Widget list,Position y)
  116. {
  117.     int position;
  118.  
  119.     assert( _XfeIsAlive(list) );
  120.     assert( XmIsList(list) );
  121.  
  122.     position = XmListYToPos(list,y);
  123.      
  124.     if ((position == 0) && (y <= _XfeHeight(list)))
  125.     {
  126.         position = XfeListGetItemCount(list);
  127.     }
  128.  
  129.     return position;
  130. }
  131. /*----------------------------------------------------------------------*/
  132. /* extern */ Dimension
  133. XfeListGetMaxItemHeight(Widget list)
  134. {
  135.     assert( _XfeIsAlive(list) );
  136.     assert( XmIsList(list) );
  137.  
  138.     return _XfeXmListAccess(list,MaxItemHeight);
  139. }
  140. /*----------------------------------------------------------------------*/
  141. /* extern */ Dimension
  142. XfeListGetMaxItemWidth(Widget list)
  143. {
  144.     Dimension    max_width = 0;
  145.     Cardinal    i;
  146.  
  147.     assert( _XfeIsAlive(list) );
  148.     assert( XmIsList(list) );
  149.  
  150.     if (_XfeXmListAccess(list,InternalList) && 
  151.         _XfeXmListAccess(list,itemCount))
  152.     {
  153.         for (i = 0; i < _XfeXmListAccess(list,itemCount); i++)
  154.         {
  155.             if (_XfeXmListAccess(list,InternalList)[i]->width > max_width)
  156.             {
  157.                 max_width = _XfeXmListAccess(list,InternalList)[i]->width;
  158.             }
  159.         }
  160.     }
  161.  
  162.     return max_width;
  163. }
  164. /*----------------------------------------------------------------------*/
  165. /* extern */ Dimension
  166. XfeListGetSpacing(Widget list)
  167. {
  168.     assert( _XfeIsAlive(list) );
  169.     assert( XmIsList(list) );
  170.  
  171.     return _XfeXmListAccess(list,ItemSpacing);
  172. }
  173. /*----------------------------------------------------------------------*/
  174. /* extern */ Dimension
  175. XfeListGetMarginHeight(Widget list)
  176. {
  177.     assert( _XfeIsAlive(list) );
  178.     assert( XmIsList(list) );
  179.  
  180.     return _XfeXmListAccess(list,margin_height);
  181. }
  182. /*----------------------------------------------------------------------*/
  183. /* extern */ Dimension
  184. XfeListGetMarginWidth(Widget list)
  185. {
  186.     assert( _XfeIsAlive(list) );
  187.     assert( XmIsList(list) );
  188.  
  189.     return _XfeXmListAccess(list,margin_width);
  190. }
  191. /*----------------------------------------------------------------------*/
  192. /* extern */ void
  193. XfeListPreferredGeometry(Widget            list,
  194.                          Dimension *    width_out,
  195.                          Dimension *    height_out)
  196. {
  197.     Dimension    width;
  198.     Dimension    height;
  199.     Cardinal    item_count;
  200.  
  201.     short spacing;
  202.  
  203.     assert( _XfeIsAlive(list) );
  204.     assert( XmIsList(list) );
  205.     assert( width_out != NULL || height_out != NULL );
  206.  
  207.     item_count = _XfeXmListAccess(list,itemCount);
  208.  
  209.     width = XfeListGetMaxItemWidth(list);
  210.  
  211.     spacing = _XfeXmListAccess(list,ItemSpacing);
  212.  
  213.     height = 
  214.         item_count * XfeListGetMaxItemHeight(list) +
  215.         item_count * 2 * _XfeHighlightThickness(list) +
  216.         (item_count - 1) * _XfeXmListAccess(list,ItemSpacing);
  217.  
  218.     printf("spacing = %d\n",spacing);
  219.     printf("highlight = %d\n",_XfeHighlightThickness(list));
  220.     printf("item_count = %d\n",item_count);
  221.     printf("height = %d\n",height);
  222.         
  223.     if (height_out)
  224.     {
  225.         *height_out = height;
  226.     }
  227.  
  228.     if (width_out)
  229.     {
  230.         *width_out = width;
  231.     }
  232.  
  233. }
  234. /*----------------------------------------------------------------------*/
  235.  
  236. /*----------------------------------------------------------------------*/
  237. /*                                                                        */
  238. /* XmScrolledWindow utilities.                                            */
  239. /*                                                                        */
  240. /*----------------------------------------------------------------------*/
  241. /* extern */ Widget
  242. XfeScrolledWindowGetVSB(Widget sw)
  243. {
  244.     assert( _XfeIsAlive(sw) );
  245.     assert( XmIsScrolledWindow(sw) );
  246.  
  247.     return (Widget) SW_ACCESS(sw,vScrollBar);
  248. }
  249. /*----------------------------------------------------------------------*/
  250. /* extern */ Widget
  251. XfeScrolledWindowGetHSB(Widget sw)
  252. {
  253.     assert( _XfeIsAlive(sw) );
  254.     assert( XmIsScrolledWindow(sw) );
  255.  
  256.     return (Widget) SW_ACCESS(sw,hScrollBar);
  257.  
  258. }
  259. /*----------------------------------------------------------------------*/
  260. /* extern */ Dimension
  261. XfeScrolledWindowGetMarginHeight(Widget sw)
  262. {
  263.     assert( _XfeIsAlive(sw) );
  264.     assert( XmIsScrolledWindow(sw) );
  265.  
  266.     return SW_ACCESS(sw,HeightPad);
  267. }
  268. /*----------------------------------------------------------------------*/
  269. /* extern */ Dimension
  270. XfeScrolledWindowGetMarginWidth(Widget sw)
  271. {
  272.     assert( _XfeIsAlive(sw) );
  273.     assert( XmIsScrolledWindow(sw) );
  274.  
  275.     return SW_ACCESS(sw,WidthPad);
  276. }
  277. /*----------------------------------------------------------------------*/
  278. /* extern */ Dimension
  279. XfeScrolledWindowGetSpacing(Widget sw)
  280. {
  281.     assert( _XfeIsAlive(sw) );
  282.     assert( XmIsScrolledWindow(sw) );
  283.  
  284.     return SW_ACCESS(sw,pad);
  285. }
  286. /*----------------------------------------------------------------------*/
  287.