home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / Microline3.0 / examples / tree2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.0 KB  |  100 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 <XmL/Tree.h>
  30.  
  31. main(argc, argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.     XtAppContext app;
  36.     Widget shell, tree;
  37.     int i, n, size;
  38.     XmString str;
  39.     XmLTreeRowDefinition *rows;
  40.     static struct
  41.             {
  42.         Boolean expands;
  43.         int level;
  44.         char *string;
  45.     } data[] =
  46.     {
  47.         { True,  0, "Root" },
  48.         { True,  1, "Level 1 Parent" },
  49.         { False, 2, "1st Child of Level 1 Parent" },
  50.         { False, 2, "2nd Child of Level 1 Parent" },
  51.         { True,  2, "Level 2 Parent" },
  52.         { False, 3, "Child of Level 2 Parent" },
  53.         { True,  1, "Level 1 Parent" },
  54.         { False, 2, "Child of Level 1 Parent" },
  55.     };
  56.  
  57.     shell =  XtAppInitialize(&app, "Tree2", NULL, 0,
  58.         &argc, argv, NULL, NULL, 0);
  59.  
  60.     tree = XtVaCreateManagedWidget("tree",
  61.         xmlTreeWidgetClass, shell,
  62.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 6,
  63.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  64.         XtVaTypedArg, XmNblankBackground, XmRString, "white", 6,
  65.         XtVaTypedArg, XmNselectBackground, XmRString, "#000080", 8,
  66.         XtVaTypedArg, XmNselectForeground, XmRString, "white", 6,
  67.         XtVaTypedArg, XmNconnectingLineColor, XmRString, "#808080", 8,
  68.         XmNvisibleRows, 10,
  69.         XmNwidth, 250,
  70.         NULL);
  71.     XtVaSetValues(tree,
  72.         XmNcellDefaults, True,
  73.         XtVaTypedArg, XmNcellBackground, XmRString, "white", 6,
  74.         NULL);
  75.  
  76.     /* Create a TreeRowDefinition array from the data array */
  77.     /* and add rows to the Tree */
  78.     n = 8;
  79.     size = sizeof(XmLTreeRowDefinition) * n;
  80.     rows = (XmLTreeRowDefinition *)malloc(size);
  81.     for (i = 0; i < n; i++)
  82.     {
  83.         rows[i].level = data[i].level;
  84.         rows[i].expands = data[i].expands;
  85.         rows[i].isExpanded = True;
  86.         rows[i].pixmap = XmUNSPECIFIED_PIXMAP;
  87.         rows[i].pixmask = XmUNSPECIFIED_PIXMAP;
  88.         rows[i].string = XmStringCreateSimple(data[i].string);
  89.     }
  90.     XmLTreeAddRows(tree, rows, n, -1);
  91.  
  92.     /* Free the TreeRowDefintion array (and XmStrings) we created above */
  93.     for (i = 0; i < n; i++)
  94.         XmStringFree(rows[i].string);
  95.     free((char *)rows);
  96.  
  97.     XtRealizeWidget(shell);
  98.     XtAppMainLoop(app);
  99. }
  100.