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 <XmL/Tree.h> 52 53 #define sphere_width 16 54 #define sphere_height 16 55 static unsigned char sphere_bits[] = { 56 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f, 57 0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f, 58 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 59 #define monitor_width 16 60 #define monitor_height 16 61 static unsigned char monitor_bits[] = { 62 0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30, 63 0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03, 64 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00}; 65 66 main(argc, argv) 67 int argc; 68 char *argv[]; 69 { 70 XtAppContext app; 71 Widget shell, tree; 72 XmLTreeRowDefinition *rows; 73 Pixmap monitorPixmap, spherePixmap; 74 Pixel black, white; 75 int i, n, size; 76 static struct 77 { 78 Boolean expands; 79 int level; 80 char *string; 81 } data[] = 82 { 83 { True, 0, "Root" }, 84 { True, 1, "Parent A" }, 85 { False, 2, "Node A1" }, 86 { False, 2, "Node A2" }, 87 { True, 2, "Parent B" }, 88 { False, 3, "Node B1" }, 89 { False, 3, "Node B2" }, 90 { True, 1, "Parent C" }, 91 { False, 2, "Node C1" }, 92 { True, 1, "Parent D" }, 93 { False, 2, "Node D1" }, 94 }; 95 96 shell = XtAppInitialize(&app, "Tree3", NULL, 0, 97 &argc, argv, NULL, NULL, 0); 98 99 black = BlackPixelOfScreen(XtScreen(shell)); 100 white = WhitePixelOfScreen(XtScreen(shell)); 101 spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell), 102 DefaultRootWindow(XtDisplay(shell)), 103 sphere_bits, sphere_width, sphere_height, 104 black, white, 105 DefaultDepthOfScreen(XtScreen(shell))); 106 monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell), 107 DefaultRootWindow(XtDisplay(shell)), 108 monitor_bits, monitor_width, monitor_height, 109 black, white, 110 DefaultDepthOfScreen(XtScreen(shell))); 111 112 /* Create a Tree with 3 columns and 1 heading row in multiple */ 113 /* select mode. We also set globalPixmapWidth and height here */ 114 /* which specifys that every Pixmap we set on the Tree will be */ 115 /* the size specified (16x16). This will increase performance. */ 116 tree = XtVaCreateManagedWidget("tree", 117 xmlTreeWidgetClass, shell, 118 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 119 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 120 XtVaTypedArg, XmNblankBackground, XmRString, "white", 6, 121 XtVaTypedArg, XmNselectBackground, XmRString, "#000080", 8, 122 XtVaTypedArg, XmNselectForeground, XmRString, "white", 6, 123 XtVaTypedArg, XmNconnectingLineColor, XmRString, "#808080", 8, 124 XmNallowColumnResize, True, 125 XmNheadingRows, 1, 126 XmNvisibleRows, 14, 127 XmNcolumns, 3, 128 XmNvisibleColumns, 5, 129 XmNsimpleWidths, "12c 8c 10c", 130 XmNsimpleHeadings, "All Folders|SIZE|DATA2", 131 XmNselectionPolicy, XmSELECT_MULTIPLE_ROW, 132 XmNhighlightRowMode, True, 133 XmNglobalPixmapWidth, 16, 134 XmNglobalPixmapHeight, 16, 135 NULL); 136 137 /* Set default values for new cells (the cells in the content rows) */ 138 XtVaSetValues(tree, 139 XmNcellDefaults, True, 140 XtVaTypedArg, XmNcellBackground, XmRString, "white", 6, 141 XmNcellLeftBorderType, XmBORDER_NONE, 142 XmNcellRightBorderType, XmBORDER_NONE, 143 XmNcellTopBorderType, XmBORDER_NONE, 144 XmNcellBottomBorderType, XmBORDER_NONE, 145 NULL); 146 147 /* Create a TreeRowDefinition array from the data array */ 148 /* and add rows to the Tree */ 149 n = 11; 150 size = sizeof(XmLTreeRowDefinition) * n; 151 rows = (XmLTreeRowDefinition *)malloc(size); 152 for (i = 0; i < n; i++) 153 { 154 rows[i].level = data[i].level; 155 rows[i].expands = data[i].expands; 156 rows[i].isExpanded = True; 157 if (data[i].expands) 158 rows[i].pixmap = spherePixmap; 159 else 160 rows[i].pixmap = monitorPixmap; 161 rows[i].pixmask = XmUNSPECIFIED_PIXMAP; 162 rows[i].string = XmStringCreateSimple(data[i].string); 163 } 164 XmLTreeAddRows(tree, rows, n, -1); 165 166 /* Free the TreeRowDefintion array we created above and set strings */ 167 /* in column 1 and 2 */ 168 for (i = 0; i < n; i++) 169 { 170 XmStringFree(rows[i].string); 171 XmLGridSetStringsPos(tree, XmCONTENT, i, XmCONTENT, 1, "1032|1123"); 172 } 173 free((char *)rows); 174 175 XtRealizeWidget(shell); 176 XtAppMainLoop(app); 177 } 178