home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / fieldlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  5.1 KB  |  211 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/FieldList.c,v 1.1.2.1 1998/02/28 17:45:12 mlemos Exp $
  3.  *
  4.  * FieldList.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995-1996 Jaba Development.
  8.  * (C) Copyright 1995-1996 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * This example is a bit more complicated. It will
  12.  * open a window with two listviews. The left-one
  13.  * is a sortable listview which will automatically
  14.  * sort the entries which are dropped on it.
  15.  *
  16.  * The right listview allows you to position the
  17.  * dropped entries.
  18.  *
  19.  * This demonstration uses the listview subclass
  20.  * as defined in the "fieldlist.h" file.
  21.  *
  22.  * $Log: FieldList.c,v $
  23.  * Revision 1.1.2.1  1998/02/28 17:45:12  mlemos
  24.  * Ian sources
  25.  *
  26.  *
  27.  */
  28.  
  29. /* Execute me to compile with DICE V3.0.
  30. dcc FieldList.c -proto -mi -ms -mRR -3.0 -lbgui
  31. quit
  32. */
  33.  
  34. #include "DemoCode.h"
  35. #include "FieldList.h"
  36.  
  37. #include <graphics/gfxbase.h>
  38. #include <string.h>
  39.  
  40. /*
  41.  *    Just a bunch of entries like the
  42.  *    ones found in the SnoopDos 3.0
  43.  *    Format Editor.
  44.  *
  45.  *    This does not have to be sorted since the
  46.  *    class will do this for us.
  47.  */
  48. STATIC UBYTE *entries[] = {
  49.     "CallAddr\t%c",
  50.     "Date\t%d",
  51.     "Hunk:Offset\t%h",
  52.     "Task ID\t%i",
  53.     "Segment Name\t%s",
  54.     "Time\t%t",
  55.     "Count\t%u",
  56.     "Process Name\t%p",
  57.     "Action\t%a",
  58.     "Target Name\t%n",
  59.     "Options\t%o",
  60.     "Res.\t%r",
  61.     NULL
  62. };
  63.  
  64. /*
  65.  *    Object ID's
  66.  */
  67. #define ID_QUIT         1
  68.  
  69. extern struct GfxBase        *GfxBase;
  70.  
  71. /*
  72.  *    Here we go...
  73.  */
  74. VOID StartDemo( void )
  75. {
  76.     struct Window            *window;
  77.     struct TextAttr                  fixed;
  78.     UBYTE                 fname[ 32 ];
  79.     Object                *WO_Window, *GO_ListSorted, *GO_ListPlace;
  80.     ULONG                 signal, rc;
  81.     Class                *class;
  82.     BOOL                 running = TRUE;
  83.     
  84.     ULONG                 weights[] = { 50, 5 };
  85.  
  86.     /*
  87.      *    Close your eyes! This is very ugly code and should
  88.      *    not be regarded as good programming practice!
  89.      *
  90.      *    Do not use this kind of code in serious programs. I
  91.      *    just did this to keep it simple.
  92.      */
  93.     Forbid();
  94.     strcpy( fname, GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name );
  95.     fixed.ta_Name    = fname;
  96.     fixed.ta_YSize    = GfxBase->DefaultFont->tf_YSize;
  97.     fixed.ta_Style    = GfxBase->DefaultFont->tf_Style;
  98.     fixed.ta_Flags    = GfxBase->DefaultFont->tf_Flags;
  99.     Permit();
  100.  
  101.     /*
  102.      *    Initialize the class.
  103.      */
  104.     if ( class = InitFLClass()) {
  105.         /*
  106.          *    Build the window object tree.
  107.          */
  108.         WO_Window = WindowObject,
  109.             WINDOW_Title,            "Listview Drag-n-Drop",
  110.             WINDOW_ScaleWidth,    25,
  111.             WINDOW_ScaleHeight,    15,
  112.             WINDOW_RMBTrap,        TRUE,
  113.             WINDOW_AutoAspect,    TRUE,
  114.             WINDOW_AutoKeyLabel,    TRUE,
  115.             WINDOW_MasterGroup,
  116.                 VGroupObject, HOffset(6), VOffset(6), Spacing(6),
  117.                     StartMember,
  118.                         InfoFixed( NULL, ISEQ_C "Field selection using\nListview Drag-n-Drop.", NULL, 2 ), FixMinHeight,
  119.                     EndMember,
  120.                     StartMember,
  121.                         HGroupObject, Spacing(6),
  122.                             StartMember,
  123.                                 /*
  124.                                  *    Create a auto-sort draggable and
  125.                                  *    droppable FL class object.
  126.                                  */
  127.                                 GO_ListSorted = NewObject( class, NULL, LAB_Label,        "Available Fields",
  128.                                                     LAB_Place,                    PLACE_ABOVE,
  129.                                                     LISTV_EntryArray,            entries,
  130.                                                     LISTV_SortEntryArray,    TRUE,
  131.                                                     LISTV_Columns,                2,
  132.                                                     LISTV_ColumnWeights,        weights,
  133.                                                 //    LISTV_ListFont,         &fixed,
  134.                                                     FL_SortDrops,                TRUE,
  135.                                                     BT_DragObject,                TRUE,
  136.                                                     BT_DropObject,                TRUE,
  137.                                                     TAG_END ),
  138.                             EndMember,
  139.                             StartMember,
  140.                                 /*
  141.                                  *    Create a draggable and dropable
  142.                                  *    FL class object which allows positioning
  143.                                  *    the drops.
  144.                                  */
  145.                                 GO_ListPlace = NewObject( class, NULL, LAB_Label,        "Current Format",
  146.                                                        LAB_Place,        PLACE_ABOVE,
  147.                                                        LISTV_ShowDropSpot,    TRUE,
  148.                                                   //     LISTV_Columns,        2,
  149.                                                 //        LISTV_ColumnWeights,        weights,
  150.                                                    //  LISTV_ListFont,           &fixed,
  151.                                                        BT_DragObject,        TRUE,
  152.                                                        BT_DropObject,        TRUE,
  153.                                                        TAG_END ),
  154.                             EndMember,
  155.                         EndObject,
  156.                     EndMember,
  157.                     StartMember,
  158.                         HGroupObject,
  159.                             VarSpace( DEFAULT_WEIGHT ),
  160.                             StartMember, FuzzButton( "_Quit", ID_QUIT ), EndMember,
  161.                             VarSpace( DEFAULT_WEIGHT ),
  162.                         EndObject, FixMinHeight,
  163.                     EndMember,
  164.                 EndObject,
  165.         EndObject;
  166.  
  167.         /*
  168.          *    Window object tree OK?
  169.          */
  170.         if ( WO_Window ) {
  171.             /*
  172.              *    Tell the FL class objects to accept
  173.              *    drops from eachother.
  174.              */
  175.             SetAttrs( GO_ListSorted, FL_AcceptDrop, GO_ListPlace,  TAG_END );
  176.             SetAttrs( GO_ListPlace,  FL_AcceptDrop, GO_ListSorted, TAG_END );
  177.  
  178.             /*
  179.              *    Open the window.
  180.              */
  181.             if ( window = WindowOpen( WO_Window )) {
  182.                 /*
  183.                  *    Get signal wait mask.
  184.                  */
  185.                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  186.  
  187.                 do {
  188.                     Wait( signal );
  189.  
  190.                     /*
  191.                      *    Handle messages.
  192.                      */
  193.                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  194.                         switch ( rc ) {
  195.                             case    WMHI_CLOSEWINDOW:
  196.                             case    ID_QUIT:
  197.                                 running = FALSE;
  198.                                 break;
  199.                         }
  200.                     }
  201.                 } while ( running );
  202.             } else
  203.                 Tell( "Unable to open the window.\n" );
  204.             DisposeObject( WO_Window );
  205.         } else
  206.             Tell( "Unable to create the window object.\n" );
  207.         FreeClass( class );
  208.     } else
  209.         Tell( "Unable to initialize the FL class.\n" );
  210. }
  211.