home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / Microline3.0 / examples / grid2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  161 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.  * The following source code is part of the Microline Widget Library.
  21.  * The Microline widget library is made available to Mozilla developers
  22.  * under the Netscape Public License (NPL) by Neuron Data.  To learn
  23.  * more about Neuron Data, please visit the Neuron Data Home Page at
  24.  * http://www.neurondata.com.
  25.  */
  26.  
  27.  
  28. #include <Xm/Xm.h>
  29. #include <Xm/Form.h>
  30. #include <Xm/PushB.h>
  31. #include <XmL/Grid.h>
  32.  
  33. void showSelected();
  34.  
  35. static char *data = 
  36. "Country|Media|Price\n\
  37. Europe|CD-ROM|$29\n\
  38. Yugoslovia|Floppy|$39\n\
  39. North America|Tape|$29\n\
  40. South America|CD-ROM|$49\n\
  41. Japan|Tape|$49\n\
  42. Russia|Floppy|$49\n\
  43. Poland|CD-ROM|$39\n\
  44. Norway|CD-ROM|$29\n\
  45. England|Tape|$49\n\
  46. Jordan|CD-ROM|$39";
  47.  
  48. Widget grid;
  49.  
  50. main(argc, argv)
  51. int argc;
  52. char *argv[];
  53. {
  54.     XtAppContext app;
  55.     Widget shell, form, button;
  56.     XmString str;
  57.  
  58.     shell =  XtAppInitialize(&app, "Grid2", NULL, 0,
  59.         &argc, argv, NULL, NULL, 0);
  60.  
  61.     form = XtVaCreateManagedWidget("form",
  62.         xmFormWidgetClass, shell,
  63.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  64.         XmNmarginWidth, 5,
  65.         XmNmarginHeight, 5,
  66.         XmNverticalSpacing, 5,
  67.         XmNshadowThickness, 0,
  68.         NULL);
  69.  
  70.     str = XmStringCreateSimple("Print Selected");
  71.     button = XtVaCreateManagedWidget("button",
  72.         xmPushButtonWidgetClass, form,
  73.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  74.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  75.         XmNbottomAttachment, XmATTACH_FORM,
  76.         XmNrightAttachment, XmATTACH_FORM,
  77.         XmNlabelString, str,
  78.         NULL);
  79.     XmStringFree(str);
  80.     XtAddCallback(button, XmNactivateCallback, showSelected, NULL);
  81.  
  82.     /* Create a Grid in multiple row select mode with 1 heading row */
  83.     /* and 3 columns */
  84.     grid = XtVaCreateManagedWidget("grid",
  85.         xmlGridWidgetClass, form,
  86.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  87.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  88.         XtVaTypedArg, XmNselectBackground, XmRString, "#000080", 8,
  89.         XtVaTypedArg, XmNselectForeground, XmRString, "white", 6,
  90.         XtVaTypedArg, XmNblankBackground, XmRString, "white", 6,
  91.         XmNheadingRows, 1,
  92.         XmNvisibleRows, 7,
  93.         XmNcolumns, 3,
  94.         XmNsimpleWidths, "20c 10c 10c",
  95.         XmNhorizontalSizePolicy, XmVARIABLE,
  96.         XmNvsbDisplayPolicy, XmSTATIC,
  97.         XmNhighlightRowMode, True,
  98.         XmNselectionPolicy, XmSELECT_MULTIPLE_ROW,
  99.         XmNshadowThickness, 0,
  100.         XmNtopAttachment, XmATTACH_FORM,
  101.         XmNbottomAttachment, XmATTACH_WIDGET,
  102.         XmNbottomWidget, button,
  103.         XmNleftAttachment, XmATTACH_FORM,
  104.         XmNrightAttachment, XmATTACH_FORM,
  105.         NULL);
  106.     /* Set default cell values for new cells (which will be the */
  107.     /* cells created when we add content rows) */
  108.     XtVaSetValues(grid,
  109.         XmNcellDefaults, True,
  110.         XtVaTypedArg, XmNcellBackground, XmRString, "white", 6,
  111.         XmNcellLeftBorderType, XmBORDER_NONE,
  112.         XmNcellRightBorderType, XmBORDER_NONE,
  113.         XmNcellTopBorderType, XmBORDER_NONE,
  114.         XmNcellBottomBorderType, XmBORDER_NONE,
  115.         NULL);
  116.     /* Set default cell alignment for new cells in columns 0 and 1 */
  117.     XtVaSetValues(grid,
  118.         XmNcellDefaults, True,
  119.         XmNcolumnRangeStart, 0,
  120.         XmNcolumnRangeEnd, 1,
  121.         XmNcellAlignment, XmALIGNMENT_LEFT,
  122.         NULL);
  123.     /* Set default cell alignment for new cells in column 2 */
  124.     XtVaSetValues(grid,
  125.         XmNcellDefaults, True,
  126.         XmNcolumn, 2,
  127.         XmNcellAlignment, XmALIGNMENT_RIGHT,
  128.         NULL);
  129.     /* Add 10 content rows */
  130.     XtVaSetValues(grid,
  131.         XmNrows, 10,
  132.         NULL);
  133.     XmLGridSetStrings(grid, data);
  134.  
  135.     XtRealizeWidget(shell);
  136.  
  137.     XtAppMainLoop(app);
  138. }
  139.  
  140. void showSelected(w, clientData, callData)
  141. Widget w;
  142. XtPointer clientData;
  143. XtPointer callData;
  144. {
  145.     int i, count, *pos;
  146.  
  147.     printf ("Selected Rows: ");
  148.     count = XmLGridGetSelectedRowCount(grid);
  149.     if (count)
  150.     {
  151.         pos = (int *)malloc(sizeof(int) * count);
  152.         XmLGridGetSelectedRows(grid, pos, count);
  153.         for (i = 0; i < count; i++)
  154.             printf ("%d ", pos[i]);
  155.         free((char *)pos);
  156.     }
  157.     else
  158.         printf ("none");
  159.     printf ("\n");
  160. }
  161.