home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / ComboBoxTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.9 KB  |  244 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:        ComboBoxTest.c                                            */
  21. /* Description:    Test for XfeComboBox widget.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27.  
  28. #include <Xfe/XfeTest.h>
  29.  
  30. #include <Xfe/ListUtilP.h>
  31.  
  32. static void        activate_callback    (Widget,XtPointer,XtPointer);
  33. static void        arm_callback        (Widget,XtPointer,XtPointer);
  34. static void        disarm_callback        (Widget,XtPointer,XtPointer);
  35.  
  36. static void        combo_add_items        (Widget,String *,Cardinal);
  37. static void        list_add_items        (Widget,String *,Cardinal);
  38.  
  39. static String items1[] =
  40. {
  41.     "Item One",
  42.     "Item Two",
  43.     "Item Three",
  44.     "Item Four",
  45.     "Item Five",
  46.     "Item Six",
  47.     "Item Seven",
  48.     "Item Eight",
  49.     "Item Nine",
  50.     "Item Ten",
  51.     "Item Eleven",
  52.     "Item Twelve",
  53. };
  54.  
  55. static String items2[] =
  56. {
  57.     "Red",
  58.     "Green",
  59.     "Blue",
  60.     "Brown",
  61.     "Orange",
  62.     "Cyan",
  63.     "Magenta",
  64.     "Black",
  65.     "White",
  66.     "Yellow"
  67. };
  68.  
  69. static String items3[] =
  70. {
  71.     "North",
  72.     "South",
  73.     "East",
  74.     "West",
  75.     "South East",
  76.     "South West",
  77.     "North East",
  78.     "North West"
  79. };
  80.  
  81. static String items4[] =
  82. {
  83.     "January",
  84.     "February",
  85.     "March",
  86.     "April",
  87.     "May",
  88.     "June",
  89.     "July",
  90.     "August",
  91.     "September",
  92.     "October",
  93.     "November",
  94.     "December"
  95. };
  96.  
  97. #define num_items1    XtNumber(items1)
  98. #define num_items2    XtNumber(items2)
  99. #define num_items3    XtNumber(items3)
  100. #define num_items4    XtNumber(items4)
  101.  
  102. /*----------------------------------------------------------------------*/
  103. int
  104. main(int argc,char *argv[])
  105. {
  106.     Widget        form;
  107.     Widget        frame;
  108.     Widget        cb[4];
  109.     Widget        icon;
  110.     Widget        list;
  111.     
  112.     XfeAppCreateSimple("ComboBoxTest",&argc,argv,"MainFrame",&frame,&form);
  113.     
  114.     cb[0] = XtVaCreateManagedWidget("ComboBox1",
  115.                                   xfeComboBoxWidgetClass,
  116.                                   form,
  117.                                   XmNcomboBoxType,XmCOMBO_BOX_EDITABLE,
  118.                                   NULL);
  119.     
  120.     cb[1] = XtVaCreateManagedWidget("ComboBox2",
  121.                                   xfeComboBoxWidgetClass,
  122.                                   form,
  123.                                   XmNcomboBoxType,XmCOMBO_BOX_READ_ONLY,
  124.                                   NULL);
  125.     
  126.     cb[2] = XtVaCreateManagedWidget("ComboBox3",
  127.                                   xfeFancyBoxWidgetClass,
  128.                                   form,
  129.                                   XmNcomboBoxType,XmCOMBO_BOX_EDITABLE,
  130.                                   NULL);
  131.     
  132.     cb[3] = XtVaCreateManagedWidget("ComboBox4",
  133.                                     xfeFancyBoxWidgetClass,
  134.                                     form,
  135.                                     XmNcomboBoxType,XmCOMBO_BOX_READ_ONLY,
  136.                                     NULL);
  137.     
  138.     icon = XtVaCreateManagedWidget("IC",
  139.                                    xfeButtonWidgetClass,
  140.                                    cb[2],
  141.                                    XmNbackground,        XfeBackground(cb[2]),
  142.                                    XmNforeground,        XfeForeground(cb[2]),
  143.                                    NULL);
  144.     
  145.     assert( XfeIsAlive(icon) );
  146.     
  147.     XtVaSetValues(
  148.         icon,
  149.         XmNpixmap,                    XfeGetPixmap(icon,"proxy"),
  150.         XmNpixmapMask,                XfeGetMask(icon,"proxy"),
  151.         XmNraisedPixmap,            XfeGetPixmap(icon,"proxy_raised"),
  152.         XmNraisedPixmapMask,        XfeGetMask(icon,"proxy_raised"),
  153.         XmNbuttonLayout,            XmBUTTON_PIXMAP_ONLY,
  154.         XmNfillOnEnter,                False,
  155.         XmNfillOnArm,                False,
  156.         XmNraiseOnEnter,            True,
  157.         XmNshadowThickness,            0,
  158.         XmNraiseBorderThickness,    0,
  159.         NULL);
  160.  
  161.  
  162.      list = XmCreateScrolledList(form,"List",NULL,0);
  163.  
  164. /*     _XfeXmListAccess(list,BaseX) += 10; */
  165.  
  166. /*     lw->list.BaseX = (Position )lw->list.margin_width + */
  167.  
  168.     XtManageChild(list);
  169.  
  170.     combo_add_items(cb[0],items1,num_items1);
  171.     combo_add_items(cb[1],items2,num_items2);
  172.     combo_add_items(cb[2],items3,num_items3);
  173.     combo_add_items(cb[3],items4,num_items4);
  174.  
  175.     list_add_items(list,items1,num_items1);
  176.  
  177.     XtPopup(frame,XtGrabNone);
  178.     
  179.     XfeAppMainLoop();
  180.  
  181.     return 0;
  182. }
  183. /*----------------------------------------------------------------------*/
  184. static void
  185. combo_add_items(Widget w,String * items,Cardinal n)
  186. {
  187.     XmString *    table = NULL;
  188.     Cardinal    i;
  189.  
  190.     assert( XfeIsAlive(w) );
  191.     assert( XfeIsComboBox(w) );
  192.     assert( items != NULL );
  193.     assert( n > 0 );
  194.  
  195.     table = XfeGetXmStringTable(items,n);
  196.     
  197.     for (i = 0; i < n; i++)
  198.     {
  199.         XfeComboBoxAddItem(w,table[i],0);
  200.     }
  201.  
  202.     XfeFreeXmStringTable(table,n);
  203. }
  204. /*----------------------------------------------------------------------*/
  205. static void
  206. list_add_items(Widget w,String * items,Cardinal n)
  207. {
  208.     XmString *    table = NULL;
  209.     Cardinal    i;
  210.  
  211.     assert( XfeIsAlive(w) );
  212.     assert( XmIsList(w) );
  213.     assert( items != NULL );
  214.     assert( n > 0 );
  215.  
  216.     table = XfeGetXmStringTable(items,n);
  217.     
  218.     for (i = 0; i < n; i++)
  219.     {
  220.         XmListAddItem(w,table[i],0);
  221.     }
  222.  
  223.     XfeFreeXmStringTable(table,n);
  224. }
  225. /*----------------------------------------------------------------------*/
  226. static void
  227. activate_callback(Widget w,XtPointer client_data,XtPointer call_data)
  228. {
  229.     printf("Activate(%s)\n",XtName(w));
  230. }
  231. /*----------------------------------------------------------------------*/
  232. static void
  233. arm_callback(Widget w,XtPointer client_data,XtPointer call_data)
  234. {
  235.     printf("Arm(%s)\n",XtName(w));
  236. }
  237. /*----------------------------------------------------------------------*/
  238. static void
  239. disarm_callback(Widget w,XtPointer client_data,XtPointer call_data)
  240. {
  241.     printf("Disarm(%s)\n",XtName(w));
  242. }
  243. /*----------------------------------------------------------------------*/
  244.