### 2.5.12 Example 3, A DirTree

In this example, we create a toplevel frame with a horizontal orientation. It has three children. A listTree, a paneHandle and a textWidget. The width of listTree is set to 200 pixels. This size can be adjusted by draging the paneHandle. When the toplevel frame is resized, the width of the listTree will stay fixed.

Note: The textWidget in this example will only load text files from the directory where the program was started.

    /************************** Example 3 ***********************/
    #include "EZ.h"                     /* the header file      */

    void listTreeCallBack(EZ_Widget *widget, void *data)
    {                                  /* callback for listTree */
      EZ_TreeNode  *node = EZ_GetListTreeWidgetSelection(widget);
      EZ_Widget    *textWidget = (EZ_Widget *)data;
      if(node && textWidget)
        {
          EZ_Item *item = EZ_TreeNodeGetItem(node);
          if(item)
    	{
    	  char *str=NULL;   int len;
    	  EZ_GetLabelItemStringInfo(item, &str, &len);
    	  if(str)  EZ_TextLoadFile(textWidget, str);
    	}
        }
    }

    main(int argc, char **argv)
    {
      EZ_Widget *frame, *listTree;
      EZ_Widget *textW, *tmp;
      EZ_TreeNode *root;

      frame = EZ_CreateWidget(EZ_WIDGET_FRAME, NULL,  /* a toplevel frame   */
    		     EZ_WIDTH, 600, EZ_HEIGHT, 400,
    		     EZ_PADY, 10, EZ_PADX,10,
    		     EZ_BACKGROUND, "bisque2",
    		     EZ_FILL_MODE, EZ_FILL_BOTH, 0);

                                             /* a list tree   */
      listTree = EZ_CreateWidget(EZ_WIDGET_TREE, frame,
                                 EZ_WIDTH, 200,     /* width  */
                                 EZ_OPTIONAL_HSCROLLBAR, True,
                                 EZ_OPTIONAL_VSCROLLBAR, True,
                                 0);
      /* add a pane handle so that user can adjust the relative
       * size of the two sibling widgets */
      tmp = EZ_CreateWidget(EZ_WIDGET_PANE_HANDLE, frame,
                            0);
      textW = EZ_CreateWidget(EZ_WIDGET_TEXT, frame,
                              EZ_OPTIONAL_HSCROLLBAR, True,
                              EZ_OPTIONAL_VSCROLLBAR, True,
                              EZ_TEXT_WIDGET_EDITABLE, True,
                              EZ_SELECTION_BACKGROUND, "yellow",
                              0);

      root = EZ_CreateDirTree("./*");  /* open the current dir   */

      EZ_AddWidgetCallBack(listTree, EZ_CALLBACK,
    		       listTreeCallBack, textW, 0);

      EZ_SetListTreeWidgetTree(listTree, /* link root to listTree*/
    		       root);

      EZ_DisplayWidget(frame);
      EZ_EventMainLoop();
    }
    /************************** Example 3 ***********************/

HTML Documentation Maintainance:`Arturo Espinosa <arturo@nuclecu.unam.mx>`