home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0979.lha / StartWindow / StartWindowE.c < prev    next >
C/C++ Source or Header  |  1994-04-04  |  16KB  |  607 lines

  1.  
  2. #include <exec/types.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/classes.h>
  5. #include <intuition/classusr.h>
  6. #include <intuition/imageclass.h>
  7. #include <intuition/gadgetclass.h>
  8. #include <libraries/gadtools.h>
  9. #include <graphics/displayinfo.h>
  10. #include <graphics/gfxbase.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/gadtools_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/utility_protos.h>
  16. #include <string.h>
  17.  
  18. /*********************************************/
  19.  
  20. #define GetString( g )   ((( struct StringInfo * )g->SpecialInfo )->Buffer  )
  21. #define GetNumber( g )   ((( struct StringInfo * )g->SpecialInfo )->LongInt )
  22.  
  23. #define GD_CList                               0
  24. #define GD_new                                 1
  25. #define GD_del                                 2
  26. #define GD_gadtxt                              3
  27. #define GD_command                             4
  28. #define GD_start                               5
  29. #define GD_save                                6
  30.  
  31. #define GDX_CList                              0
  32. #define GDX_new                                1
  33. #define GDX_del                                2
  34. #define GDX_gadtxt                             3
  35. #define GDX_command                            4
  36. #define GDX_start                              5
  37. #define GDX_save                               6
  38.  
  39. #define Project0_CNT 7
  40.  
  41. extern struct IntuitionBase *IntuitionBase;
  42. extern struct Library       *GadToolsBase;
  43.  
  44. extern struct Screen        *Scr;
  45. extern UBYTE                 *PubScreenName;
  46. extern APTR                  VisualInfo;
  47. extern struct Window        *Project0Wnd;
  48. extern struct Gadget        *Project0GList;
  49. extern struct Gadget        *Project0Gadgets[7];
  50. extern UWORD                 Project0Left;
  51. extern UWORD                 Project0Top;
  52. extern UWORD                 Project0Width;
  53. extern UWORD                 Project0Height;
  54. extern UBYTE                *Project0Wdt;
  55. extern struct TextAttr       topaz8;
  56. extern UWORD                 Project0GTypes[];
  57. extern struct NewGadget      Project0NGad[];
  58. extern ULONG                 Project0GTags[];
  59.  
  60.  
  61. extern int SetupScreen( void );
  62. extern void CloseDownScreen( void );
  63. extern int OpenProject0Window( void );
  64. extern void CloseProject0Window( void );
  65.  
  66. /**************************************************/
  67.  
  68. struct Screen         *Scr = NULL;
  69. UBYTE                 *PubScreenName = NULL;
  70. APTR                   VisualInfo = NULL;
  71. struct Window         *Project0Wnd = NULL;
  72. struct Gadget         *Project0GList = NULL;
  73. struct Gadget         *Project0Gadgets[7];
  74. UWORD                  Project0Left = 468;
  75. UWORD                  Project0Top = 10;
  76. UWORD                  Project0Width = 194;
  77. UWORD                  Project0Height = 0;
  78. UBYTE                 *Project0Wdt = (UBYTE *)" Start Window";
  79.  
  80. struct TextAttr topaz8 = {
  81.         ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
  82.  
  83. UWORD Project0GTypes[] = {
  84.         LISTVIEW_KIND,
  85.         BUTTON_KIND,
  86.         BUTTON_KIND,
  87.         STRING_KIND,
  88.         STRING_KIND,
  89.         BUTTON_KIND,
  90.         BUTTON_KIND
  91. };
  92.  
  93. struct NewGadget Project0NGad[] = {
  94.         3, 14, 168, 72,
  95.         (UBYTE *)"Start List",
  96.         NULL, GD_CList,
  97.         PLACETEXT_ABOVE,
  98.         NULL, NULL,
  99.  
  100.         4, 86, 80, 11,
  101.         (UBYTE *)"NEW",
  102.         NULL, GD_new,
  103.         PLACETEXT_IN,
  104.         NULL, NULL,
  105.  
  106.         88, 86, 80, 11,
  107.         (UBYTE *)"DELETE",
  108.         NULL, GD_del,
  109.         PLACETEXT_IN,
  110.         NULL, NULL,
  111.  
  112.         4, 101, 165, 12,
  113.         NULL, NULL,
  114.         GD_gadtxt, 0,
  115.         NULL, NULL,
  116.  
  117.         4, 116, 165, 12,
  118.         NULL, NULL,
  119.         GD_command, 0,
  120.         NULL, NULL,
  121.  
  122.         5, 131, 80, 11,
  123.         (UBYTE *)"RUN",
  124.         NULL, GD_start,
  125.         PLACETEXT_IN,
  126.         NULL, NULL,
  127.  
  128.         88, 131, 80, 11,
  129.         (UBYTE *)"SAVE",
  130.         NULL, GD_save,
  131.         PLACETEXT_IN,
  132.         NULL, NULL
  133. };
  134.  
  135. ULONG Project0GTags[] = {
  136.         (TAG_DONE),
  137.         (TAG_DONE),
  138.         (TAG_DONE),
  139.         (GTST_MaxChars), 20, (TAG_DONE),
  140.         (GTST_MaxChars), 50, (TAG_DONE),
  141.         (TAG_DONE),
  142.         (TAG_DONE)
  143. };
  144.  
  145. int SetupScreen( void )
  146. {
  147.         if ( ! ( Scr = LockPubScreen( PubScreenName )))
  148.                 return( 1L );
  149.  
  150.         if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  151.                 return( 2L );
  152.  
  153.         return( 0L );
  154. }
  155.  
  156. void CloseDownScreen( void )
  157. {
  158.         if ( VisualInfo ) {
  159.                 FreeVisualInfo( VisualInfo );
  160.                 VisualInfo = NULL;
  161.         }
  162.  
  163.         if ( Scr        ) {
  164.                 UnlockPubScreen( NULL, Scr );
  165.                 Scr = NULL;
  166.         }
  167. }
  168.  
  169. int OpenProject0Window( void )
  170. {
  171. struct NewGadget        ng;
  172. struct Gadget   *g;
  173. UWORD  lc, tc;
  174. UWORD  offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  175.  
  176.         if ( ! ( g = CreateContext( &Project0GList )))
  177.         return( 1L );
  178.  
  179.         for( lc = 0, tc = 0; lc < Project0_CNT; lc++ ) {
  180.  
  181.         CopyMem((char * )&Project0NGad[ lc ], (char * )&ng,
  182.                                           (long)sizeof( struct NewGadget ));
  183.  
  184.         ng.ng_VisualInfo = VisualInfo;
  185.         ng.ng_TextAttr   = &topaz8;
  186.         ng.ng_LeftEdge  += offx;
  187.         ng.ng_TopEdge   += offy;
  188.  
  189.         Project0Gadgets[ lc ] = g = CreateGadgetA((ULONG)Project0GTypes[ lc ],
  190.                            g, &ng, ( struct TagItem * )&Project0GTags[ tc ] );
  191.  
  192.         while( Project0GTags[ tc ] ) tc += 2;
  193.         tc++;
  194.  
  195.         if ( NOT g )
  196.                 return( 2L );
  197.         }
  198.  
  199.         if ( ! ( Project0Wnd = OpenWindowTags( NULL,
  200.                                 WA_Left,        Project0Left,
  201.                                 WA_Top,         Project0Top,
  202.                                 WA_Width,       Project0Width,
  203.                                 WA_Height,      Project0Height + offy,
  204.                                 WA_IDCMP,       LISTVIEWIDCMP|
  205.                                                 BUTTONIDCMP|
  206.                                                 STRINGIDCMP|
  207.                                                 IDCMP_NEWSIZE|
  208.                                                 IDCMP_CLOSEWINDOW|
  209.                                                 IDCMP_CHANGEWINDOW|
  210.                                                 IDCMP_REFRESHWINDOW,
  211.                                 WA_Flags,       WFLG_SIZEGADGET|
  212.                                                 WFLG_DRAGBAR|
  213.                                                 WFLG_DEPTHGADGET|
  214.                                                 WFLG_CLOSEGADGET|
  215.                                                 WFLG_SMART_REFRESH,
  216.                                 WA_Gadgets,     Project0GList,
  217.                                 WA_Title,       Project0Wdt,
  218.                                 WA_ScreenTitle, "Heinz Reinert ⌐ 1993",
  219.                                 WA_PubScreen,   Scr,
  220.                                 WA_MinWidth,    194,
  221.                                 WA_MinHeight,   157,
  222.                                 WA_MaxWidth,    194,
  223.                                 WA_MaxHeight,   157,
  224.                                 TAG_DONE )))
  225.         return( 4L );
  226.  
  227.         GT_RefreshWindow( Project0Wnd, NULL );
  228.  
  229.         return( 0L );
  230. }
  231.  
  232. void CloseProject0Window( void )
  233. {
  234.         if ( Project0Wnd        ) {
  235.                 CloseWindow( Project0Wnd );
  236.                 Project0Wnd = NULL;
  237.         }
  238.  
  239.         if ( Project0GList      ) {
  240.                 FreeGadgets( Project0GList );
  241.                 Project0GList = NULL;
  242.         }
  243. }
  244.  
  245. /******************************************************/
  246.  
  247. #include <proto/intuition.h>
  248. #include <proto/graphics.h>
  249. #include <proto/exec.h>
  250. #include <proto/dos.h>
  251. #include <proto/gadtools.h>
  252. #include <intuition/gadgetclass.h>
  253. #include <exec/memory.h>
  254. #include <string.h>
  255.  
  256.  
  257. struct PRJ {
  258.  
  259.     char    Name[0];
  260.  
  261.     USHORT  new;
  262.     USHORT  del;
  263.  
  264.     char    gadtxt[20];
  265.     char    command[50];
  266.  
  267.     USHORT  start;
  268.     USHORT  save;
  269. };
  270.  
  271. struct PRJnode {
  272.         struct  Node n; /*** Fⁿr Liste    ***/
  273.         struct  PRJ d;  /*** PRJ-Struktur ***/
  274. };
  275.  
  276.  
  277. struct List prjlist;
  278.  
  279.  
  280. struct PRJnode *currentprj;
  281.  
  282. void gt_SetString( struct Gadget        *gad,
  283.                                    struct Window        *w,
  284.                                    char                         *string )
  285. {
  286.         GT_SetGadgetAttrs( gad, w, NULL, GTST_String, string, TAG_DONE );
  287. }
  288.  
  289. char * gt_GetString( struct Gadget      *gad )
  290. {
  291.         struct StringInfo *si = gad->SpecialInfo;
  292.  
  293.         if( si )
  294.                 return( ( char * ) si->Buffer );
  295.         else
  296.                 return( NULL );
  297. }
  298.  
  299. void gt_AttachList(     struct Gadget   *lv,
  300.                                         struct Window   *w,
  301.                                         struct List     *list )
  302. {
  303.         GT_SetGadgetAttrs( lv, w, NULL, GTLV_Labels, list, TAG_DONE );
  304. }
  305.  
  306. void gt_SetLV( struct Gadget    *gad,
  307.                            struct Window        *w,
  308.                            ULONG                        value)
  309. {
  310.         GT_SetGadgetAttrs( gad, w, NULL, GTLV_Selected, value, TAG_DONE );
  311. }
  312.  
  313. struct Node * gt_GetListEntry( struct List *l,
  314.                                                            int num )
  315. {
  316.         int count = 0;
  317.         struct Node *n = l->lh_Head;
  318.  
  319.         while( n->ln_Succ )
  320.         {
  321.                 if( num==count ) return( n );
  322.                 n = n->ln_Succ;
  323.                 count++;
  324.         }
  325.         return( NULL );
  326. }
  327.  
  328. int gt_GetListEntryNum( struct List *l,
  329.                                                 struct Node *n )
  330. {
  331.         int count = 0;
  332.         struct Node *r = l->lh_Head;
  333.  
  334.         while( r->ln_Succ )
  335.         {
  336.                 if( r==n ) return( count );
  337.                 r = r->ln_Succ;
  338.                 count++;
  339.         }
  340.         return( -1 );
  341. }
  342.  
  343. int gt_GetListNumEntries( struct List *l )
  344. {
  345.         int count = 0;
  346.         struct Node *n = l->lh_Head;
  347.  
  348.         while( n->ln_Succ )
  349.         {
  350.                 n = n->ln_Succ;
  351.                 count++;
  352.         }
  353.  
  354.         return( count );
  355. }
  356.  
  357. /************************************************************************/
  358.  
  359. void loadprjlist( void )
  360. {
  361.         struct PRJ new;
  362.         struct PRJnode *n;
  363.         BPTR f;
  364.  
  365.         NewList( &prjlist );
  366.         currentprj = NULL;
  367.  
  368.         f = Open( "S:Kommando.DAT", MODE_OLDFILE );
  369.         if( !f )
  370.                 return;
  371.  
  372.         while( Read( f, &new, sizeof( new ) ) == sizeof( new ) )
  373.         {
  374.                 n = AllocVec( sizeof( *n ), 0 );
  375.                 if( !n )
  376.                         break;
  377.  
  378.                 n->d = new;
  379.                 n->n.ln_Name = n->d.Name;
  380.                 n->n.ln_Pri      = - n->d.Name[0];
  381.                 Enqueue( &prjlist, (struct Node *) n );
  382.         }
  383.  
  384.         Close( f );
  385. }
  386.  
  387. void save_and_freeprjlist( void )
  388. {
  389.         struct PRJnode *n;
  390.         BPTR f;
  391.  
  392.         f = Open( "S:Kommando.DAT", MODE_NEWFILE );
  393.  
  394.         while( ( n = (struct PRJnode * ) RemHead( &prjlist ) ) )
  395.         {
  396.                 if( f )
  397.                         Write( f, &n->d, sizeof( struct PRJ ) );
  398.  
  399.                 FreeVec( n );
  400.         }
  401.  
  402.         if( f )
  403.                 Close( f );
  404. }
  405.  
  406.  
  407. /************************************************************************/
  408.  
  409. void setgadvals( void )
  410. {
  411.  
  412.         if( !currentprj )
  413.             return;
  414.  
  415.         gt_SetString(   Project0Gadgets[ GD_gadtxt ], Project0Wnd,
  416.                                                        currentprj->d.Name );
  417.  
  418.         gt_SetString(   Project0Gadgets[ GD_command ], Project0Wnd,
  419.                                                     currentprj->d.command );
  420.  
  421. }
  422.  
  423. void newprj( void )
  424. {
  425.         struct PRJnode *new;
  426.  
  427.         new = AllocVec( sizeof( *new ), MEMF_CLEAR );
  428.  
  429.         if( !new )
  430.                 return;
  431.  
  432.         currentprj = new;
  433.  
  434.         new->n.ln_Name = new->d.Name;
  435.  
  436.         strcpy( new->d.Name, "new" );
  437.  
  438.         gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd,
  439.                                                       (struct List *) ~0 );
  440.  
  441.         new->n.ln_Pri    = - new->d.Name[0];
  442.         Enqueue( &prjlist, (struct Node *) new );
  443.  
  444.         gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd, &prjlist );
  445.  
  446.         gt_SetLV( Project0Gadgets[GD_CList], Project0Wnd,
  447.                                      gt_GetListEntryNum( &prjlist, new ) );
  448.         setgadvals();
  449. }
  450.  
  451.  
  452. void dogadup( struct IntuiMessage *im )
  453. {
  454.         struct Gadget *g = im->IAddress;
  455.  
  456.         switch( g->GadgetID )
  457.         {
  458.  
  459. case GD_CList:
  460.         currentprj = (struct PRJnode *) gt_GetListEntry( &prjlist, im->Code );
  461.         setgadvals();
  462.         break;
  463.  
  464. case GD_new:
  465.         newprj();
  466.         break;
  467.  
  468. case GD_del:
  469.         if( currentprj )
  470.         {
  471.         gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd,
  472.                                                        (struct List *) ~0 );
  473.         Remove( currentprj );
  474.         FreeVec( currentprj );
  475.         currentprj = FALSE;
  476.         gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd, &prjlist );
  477.         gt_SetLV( Project0Gadgets[ GD_CList ], Project0Wnd, ~0 );
  478.         }
  479.         break;
  480.  
  481. case GD_gadtxt:
  482.         if( currentprj )
  483.         {
  484.         gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd,
  485.                                                          (struct List *) ~0 );
  486.    strcpy( currentprj->d.Name, gt_GetString( Project0Gadgets[ GD_gadtxtá] ) );
  487.         gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd, &prjlist );
  488.         }
  489.         break;
  490.  
  491. case GD_command:
  492.         if( currentprj )
  493.         strcpy( currentprj->d.command,
  494.                              gt_GetString( Project0Gadgets[ GD_command ] ) );
  495.         break;
  496.  
  497. case GD_start:
  498.         Execute(currentprj->d.command, NULL, Output());
  499.         break;
  500.  
  501. case GD_save:
  502.         {
  503.         struct PRJnode *n;
  504.         BPTR f;
  505.  
  506.         f = Open( "S:Kommando.DAT", MODE_NEWFILE );
  507.  
  508.         while( ( n = (struct PRJnode * ) RemHead( &prjlist ) ) )
  509.         {
  510.                 if( f )
  511.                         Write( f, &n->d, sizeof( struct PRJ ) );
  512.  
  513.                 FreeVec( n );
  514.         }
  515.  
  516.         if( f )
  517.                 Close( f );
  518.         }
  519.  
  520.         {
  521.         struct PRJ new;
  522.         struct PRJnode *n;
  523.         BPTR f;
  524.  
  525.         NewList( &prjlist );
  526.         currentprj = NULL;
  527.  
  528.         f = Open( "S:Kommando.DAT", MODE_OLDFILE );
  529.         if( !f )
  530.                 return;
  531.  
  532.         while( Read( f, &new, sizeof( new ) ) == sizeof( new ) )
  533.         {
  534.                 n = AllocVec( sizeof( *n ), 0 );
  535.                 if( !n )
  536.                         break;
  537.  
  538.                 n->d = new;
  539.                 n->n.ln_Name = n->d.Name;
  540.                 n->n.ln_Pri      = - n->d.Name[0];
  541.                 Enqueue( &prjlist, (struct Node *) n );
  542.         }
  543.  
  544.         Close( f );
  545.         }
  546.         break;
  547.  
  548.         }
  549. }
  550.  
  551. int main( void )
  552. {
  553.  
  554.         struct IntuiMessage     *im,imsg;
  555.         BOOL   Done = FALSE;
  556.  
  557.         SetupScreen();
  558.         OpenProject0Window();
  559.  
  560.         loadprjlist();
  561.  
  562.         gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd, &prjlist );
  563.  
  564.         while( !Done )
  565.         {
  566.  
  567.                 while( !( im=GT_GetIMsg( Project0Wnd->UserPort ) ) )
  568.                         WaitPort( Project0Wnd->UserPort );
  569.  
  570.                 imsg = *im;
  571.                 GT_ReplyIMsg( im );
  572.  
  573.                 switch( imsg.Class )
  574.                 {
  575.  
  576.                         case IDCMP_CLOSEWINDOW:
  577.                                 Done = TRUE;
  578.                                 break;
  579.  
  580.                         case GADGETUP:
  581.                                 dogadup( &imsg );
  582.                                 break;
  583.  
  584.  
  585.                         case IDCMP_REFRESHWINDOW:
  586.                                 GT_BeginRefresh( Project0Wnd );
  587.                                 GT_EndRefresh( Project0Wnd, TRUE );
  588.                                 break;
  589.  
  590.                 }
  591.  
  592.         }
  593.  
  594.         CloseProject0Window();
  595.         CloseDownScreen();
  596.  
  597.         save_and_freeprjlist();
  598.  
  599.         return(0);
  600. }
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.