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