Remove memory leaks in BeginSmartIndent()
[nedit.git] / Microline / examples / tree5.c
blob062a071cfd3287f60e601bc9e3dbef0ce06a86b1
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is the Microline Widget Library, originally made available under the NPL by Neuron Data <http://www.neurondata.com>.
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.
23 * Contributor(s):
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.
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.
47 * ***** END LICENSE BLOCK ***** */
50 #include <Xm/Xm.h>
51 #include <Xm/Form.h>
52 #include <Xm/PushB.h>
53 #include <XmL/Tree.h>
55 #define sphere_width 16
56 #define sphere_height 16
57 static unsigned char sphere_bits[] = {
58 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f,
59 0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f,
60 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
61 #define monitor_width 16
62 #define monitor_height 16
63 static unsigned char monitor_bits[] = {
64 0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30,
65 0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03,
66 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00};
68 #if 0
69 void
70 hide_cb(Widget w, XtPointer clientData, XtPointer cb_data)
72 Widget tree = (Widget) clientData;
74 XmLGridHideRightColumn(tree);
76 void
77 show_cb(Widget w, XtPointer clientData, XtPointer cb_data)
79 Widget tree = (Widget) clientData;
81 XmLGridUnhideRightColumn(tree);
83 #endif /*0*/
86 main(argc, argv)
87 int argc;
88 char *argv[];
90 XtAppContext app;
91 Widget shell, tree, form, hideB, showB;
92 XmLTreeRowDefinition *rows;
93 Pixmap monitorPixmap, spherePixmap;
94 Pixel black, white;
95 int i, n, size;
96 static struct
98 Boolean expands;
99 int level;
100 char *string;
101 } data[] =
103 { True, 0, "Root" },
104 { True, 1, "Parent A" },
105 { False, 2, "Node A1" },
106 { False, 2, "Node A2" },
107 { True, 2, "Parent B" },
108 { False, 3, "Node B1" },
109 { False, 3, "Node B2" },
110 { True, 1, "Parent C" },
111 { False, 2, "Node C1" },
112 { True, 1, "Parent D" },
113 { False, 2, "Node D1" },
116 shell = XtAppInitialize(&app, "Tree3", NULL, 0,
117 &argc, argv, NULL, NULL, 0);
119 black = BlackPixelOfScreen(XtScreen(shell));
120 white = WhitePixelOfScreen(XtScreen(shell));
121 spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
122 DefaultRootWindow(XtDisplay(shell)),
123 sphere_bits, sphere_width, sphere_height,
124 black, white,
125 DefaultDepthOfScreen(XtScreen(shell)));
126 monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
127 DefaultRootWindow(XtDisplay(shell)),
128 monitor_bits, monitor_width, monitor_height,
129 black, white,
130 DefaultDepthOfScreen(XtScreen(shell)));
132 form = XtVaCreateManagedWidget("form",
133 xmFormWidgetClass, shell,
134 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
135 XmNshadowThickness, 0,
136 NULL);
138 #if 0
139 hideB = XtVaCreateManagedWidget("hide",
140 xmPushButtonWidgetClass, form,
141 XmNleftAttachment, XmATTACH_NONE,
142 XmNtopAttachment, XmATTACH_POSITION,
143 XmNtopPosition, 30,
144 XmNbottomAttachment, XmATTACH_NONE,
145 XmNrightAttachment, XmATTACH_FORM,
146 NULL);
148 showB = XtVaCreateManagedWidget("show",
149 xmPushButtonWidgetClass, form,
150 XmNleftAttachment, XmATTACH_NONE,
151 XmNtopAttachment, XmATTACH_POSITION,
152 XmNtopPosition, 30,
153 XmNbottomAttachment, XmATTACH_NONE,
154 XmNrightAttachment, XmATTACH_WIDGET,
155 XmNrightWidget, hideB,
156 NULL);
157 #endif /*0*/
159 /* Create a Tree with 3 columns and 1 heading row in multiple */
160 /* select mode. We also set globalPixmapWidth and height here */
161 /* which specifys that every Pixmap we set on the Tree will be */
162 /* the size specified (16x16). This will increase performance. */
163 tree = XtVaCreateManagedWidget("tree",
164 xmlTreeWidgetClass, form,
165 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
166 XtVaTypedArg, XmNforeground, XmRString, "black", 6,
167 XtVaTypedArg, XmNblankBackground, XmRString, "white", 6,
168 XtVaTypedArg, XmNselectBackground, XmRString, "#000080", 8,
169 XtVaTypedArg, XmNselectForeground, XmRString, "white", 6,
170 XtVaTypedArg, XmNconnectingLineColor, XmRString, "#808080", 8,
171 XmNhorizontalSizePolicy, XmRESIZE_IF_POSSIBLE,
172 XmNallowColumnResize, True,
173 XmNheadingRows, 1,
174 XmNvisibleRows, 14,
175 XmNcolumns, 3,
176 XmNvisibleColumns, 1,
177 XmNhideUnhideButtons, True,
178 XmNsimpleWidths, "80c 40c 40c",
179 XmNsimpleHeadings, "All Folders|SIZE|DATA2",
180 XmNselectionPolicy, XmSELECT_MULTIPLE_ROW,
181 XmNhighlightRowMode, True,
182 XmNglobalPixmapWidth, 16,
183 XmNglobalPixmapHeight, 16,
184 XmNleftAttachment, XmATTACH_FORM,
185 XmNtopAttachment, XmATTACH_FORM,
186 XmNbottomAttachment, XmATTACH_FORM,
187 XmNrightAttachment, XmATTACH_FORM,
188 #if 0
189 XmNrightAttachment, XmATTACH_WIDGET,
190 XmNrightWidget, showB,
191 #endif /*0*/
192 XmNdebugLevel, 2,
193 NULL);
195 /* Set default values for new cells (the cells in the content rows) */
196 XtVaSetValues(tree,
197 XmNcellDefaults, True,
198 XtVaTypedArg, XmNcellBackground, XmRString, "white", 6,
199 XmNcellEditable, True,
200 XmNcellLeftBorderType, XmBORDER_NONE,
201 XmNcellRightBorderType, XmBORDER_NONE,
202 XmNcellTopBorderType, XmBORDER_NONE,
203 XmNcellBottomBorderType, XmBORDER_NONE,
204 NULL);
206 #if 0
207 XtAddCallback(hideB, XmNactivateCallback, hide_cb, (XtPointer)tree);
208 XtAddCallback(showB, XmNactivateCallback, show_cb, (XtPointer)tree);
209 #endif /*0*/
211 /* Create a TreeRowDefinition array from the data array */
212 /* and add rows to the Tree */
213 n = 11;
214 size = sizeof(XmLTreeRowDefinition) * n;
215 rows = (XmLTreeRowDefinition *)malloc(size);
216 for (i = 0; i < n; i++)
218 rows[i].level = data[i].level;
219 rows[i].expands = data[i].expands;
220 rows[i].isExpanded = True;
221 if (data[i].expands)
222 rows[i].pixmap = spherePixmap;
223 else
224 rows[i].pixmap = monitorPixmap;
225 rows[i].pixmask = XmUNSPECIFIED_PIXMAP;
226 rows[i].string = XmStringCreateSimple(data[i].string);
228 XmLTreeAddRows(tree, rows, n, -1);
230 /* Free the TreeRowDefintion array we created above and set strings */
231 /* in column 1 and 2 */
232 for (i = 0; i < n; i++)
234 XmStringFree(rows[i].string);
235 XmLGridSetStringsPos(tree, XmCONTENT, i, XmCONTENT, 1, "1032|1123");
237 free((char *)rows);
238 XtRealizeWidget(shell);
239 XtAppMainLoop(app);