UNIXworkcode

1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * ***** BEGIN LICENSE BLOCK ***** 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 * 6 * The contents of this file are subject to the Mozilla Public License Version 7 * 1.1 (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * http://www.mozilla.org/MPL/ 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 * 16 * The Original Code is the Microline Widget Library, originally made available under the NPL by Neuron Data <http://www.neurondata.com>. 17 * 18 * The Initial Developer of the Original Code is 19 * Netscape Communications Corporation. 20 * Portions created by the Initial Developer are Copyright (C) 1998 21 * the Initial Developer. All Rights Reserved. 22 * 23 * Contributor(s): 24 * 25 * Alternatively, the contents of this file may be used under the terms of 26 * either the GNU General Public License Version 2 or later (the "GPL"), or 27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 * in which case the provisions of the GPL or the LGPL are applicable instead 29 * of those above. If you wish to allow use of your version of this file only 30 * under the terms of either the GPL or the LGPL, and not to allow others to 31 * use your version of this file under the terms of the MPL, indicate your 32 * decision by deleting the provisions above and replace them with the notice 33 * and other provisions required by the GPL or the LGPL. If you do not delete 34 * the provisions above, a recipient may use your version of this file under 35 * the terms of any one of the MPL, the GPL or the LGPL. 36 * 37 * In addition, as a special exception to the GNU GPL, the copyright holders 38 * give permission to link the code of this program with the Motif and Open 39 * Motif libraries (or with modified versions of these that use the same 40 * license), and distribute linked combinations including the two. You 41 * must obey the GNU General Public License in all respects for all of 42 * the code used other than linking with Motif/Open Motif. If you modify 43 * this file, you may extend this exception to your version of the file, 44 * but you are not obligated to do so. If you do not wish to do so, 45 * delete this exception statement from your version. 46 * 47 * ***** END LICENSE BLOCK ***** */ 48 49 50 #include <Xm/Xm.h> 51 #include <Xm/Form.h> 52 #include <Xm/PushB.h> 53 #include <XmL/Grid.h> 54 55 void showSelected(); 56 57 static char *data = 58 "Country|Media|Price\n\ 59 Europe|CD-ROM|$29\n\ 60 Yugoslovia|Floppy|$39\n\ 61 North America|Tape|$29\n\ 62 South America|CD-ROM|$49\n\ 63 Japan|Tape|$49\n\ 64 Russia|Floppy|$49\n\ 65 Poland|CD-ROM|$39\n\ 66 Norway|CD-ROM|$29\n\ 67 England|Tape|$49\n\ 68 Jordan|CD-ROM|$39"; 69 70 Widget grid; 71 72 main(argc, argv) 73 int argc; 74 char *argv[]; 75 { 76 XtAppContext app; 77 Widget shell, form, button; 78 XmString str; 79 80 shell = XtAppInitialize(&app, "Grid2", NULL, 0, 81 &argc, argv, NULL, NULL, 0); 82 83 form = XtVaCreateManagedWidget("form", 84 xmFormWidgetClass, shell, 85 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 86 XmNmarginWidth, 5, 87 XmNmarginHeight, 5, 88 XmNverticalSpacing, 5, 89 XmNshadowThickness, 0, 90 NULL); 91 92 str = XmStringCreateSimple("Print Selected"); 93 button = XtVaCreateManagedWidget("button", 94 xmPushButtonWidgetClass, form, 95 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 96 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 97 XmNbottomAttachment, XmATTACH_FORM, 98 XmNrightAttachment, XmATTACH_FORM, 99 XmNlabelString, str, 100 NULL); 101 XmStringFree(str); 102 XtAddCallback(button, XmNactivateCallback, showSelected, NULL); 103 104 /* Create a Grid in multiple row select mode with 1 heading row */ 105 /* and 3 columns */ 106 grid = XtVaCreateManagedWidget("grid", 107 xmlGridWidgetClass, form, 108 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 109 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 110 XtVaTypedArg, XmNselectBackground, XmRString, "#000080", 8, 111 XtVaTypedArg, XmNselectForeground, XmRString, "white", 6, 112 XtVaTypedArg, XmNblankBackground, XmRString, "white", 6, 113 XmNheadingRows, 1, 114 XmNvisibleRows, 7, 115 XmNcolumns, 3, 116 XmNsimpleWidths, "20c 10c 10c", 117 XmNhorizontalSizePolicy, XmVARIABLE, 118 XmNvsbDisplayPolicy, XmSTATIC, 119 XmNhighlightRowMode, True, 120 XmNselectionPolicy, XmSELECT_MULTIPLE_ROW, 121 XmNshadowThickness, 0, 122 XmNtopAttachment, XmATTACH_FORM, 123 XmNbottomAttachment, XmATTACH_WIDGET, 124 XmNbottomWidget, button, 125 XmNleftAttachment, XmATTACH_FORM, 126 XmNrightAttachment, XmATTACH_FORM, 127 NULL); 128 /* Set default cell values for new cells (which will be the */ 129 /* cells created when we add content rows) */ 130 XtVaSetValues(grid, 131 XmNcellDefaults, True, 132 XtVaTypedArg, XmNcellBackground, XmRString, "white", 6, 133 XmNcellLeftBorderType, XmBORDER_NONE, 134 XmNcellRightBorderType, XmBORDER_NONE, 135 XmNcellTopBorderType, XmBORDER_NONE, 136 XmNcellBottomBorderType, XmBORDER_NONE, 137 NULL); 138 /* Set default cell alignment for new cells in columns 0 and 1 */ 139 XtVaSetValues(grid, 140 XmNcellDefaults, True, 141 XmNcolumnRangeStart, 0, 142 XmNcolumnRangeEnd, 1, 143 XmNcellAlignment, XmALIGNMENT_LEFT, 144 NULL); 145 /* Set default cell alignment for new cells in column 2 */ 146 XtVaSetValues(grid, 147 XmNcellDefaults, True, 148 XmNcolumn, 2, 149 XmNcellAlignment, XmALIGNMENT_RIGHT, 150 NULL); 151 /* Add 10 content rows */ 152 XtVaSetValues(grid, 153 XmNrows, 10, 154 NULL); 155 XmLGridSetStrings(grid, data); 156 157 XtRealizeWidget(shell); 158 159 XtAppMainLoop(app); 160 } 161 162 void showSelected(w, clientData, callData) 163 Widget w; 164 XtPointer clientData; 165 XtPointer callData; 166 { 167 int i, count, *pos; 168 169 printf ("Selected Rows: "); 170 count = XmLGridGetSelectedRowCount(grid); 171 if (count) 172 { 173 pos = (int *)malloc(sizeof(int) * count); 174 XmLGridGetSelectedRows(grid, pos, count); 175 for (i = 0; i < count; i++) 176 printf ("%d ", pos[i]); 177 free((char *)pos); 178 } 179 else 180 printf ("none"); 181 printf ("\n"); 182 } 183