home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / Triton / Developer / DemoSource / progind.c < prev    next >
C/C++ Source or Header  |  1998-02-03  |  5KB  |  140 lines

  1. /*
  2.  *  OpenTriton -- A free release of the triton.library source code
  3.  *  Copyright (C) 1993-1998  Stefan Zeiger
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  progind.c - Progress indicator demo
  20.  *
  21.  */
  22.  
  23.  
  24. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  25. /* ////////////////////////////////////////////////////////////////////////////////// Include our stuff // */
  26. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #include <libraries/triton.h>
  33.  
  34. #ifdef __GNUC__
  35. #ifndef __OPTIMIZE__
  36. #include <clib/triton_protos.h>
  37. #include <clib/dos_protos.h>
  38. #include <clib/intuition_protos.h>
  39. #else
  40. #include <inline/triton.h>
  41. #include <inline/dos.h>
  42. #include <inline/intuition.h>
  43. #endif /* __OPTIMIZE__ */
  44. #else
  45. #include <proto/triton.h>
  46. #include <proto/dos.h>
  47. #include <proto/intuition.h>
  48. #endif /* __GNUC__ */
  49.  
  50.  
  51. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  52. /* ////////////////////////////////////////////////////////////////////////////////////// Window 'main' // */
  53. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  54.  
  55. enum IDs {ID_MAIN_GADGET_STOP=1, ID_MAIN_PROGIND};
  56.  
  57.  
  58. VOID do_main(VOID)
  59. {
  60.   BOOL close_me=FALSE;
  61.   struct TR_Message *trmsg;
  62.   struct TR_Project *project;
  63.   ULONG i;
  64.  
  65.   if(project=TR_OpenProjectTags(Application,
  66.     WindowID(1),
  67.     WindowTitle("Progress Indicator Demo"),
  68.     WindowPosition(TRWP_CENTERDISPLAY),
  69.     WindowFlags(TRWF_NOCLOSEGADGET|TRWF_NOESCCLOSE),
  70.  
  71.     VertGroupA,
  72.       Space,  CenteredText("Working..."),
  73.       Space,  HorizGroupA,
  74.                 Space, Progress(100,0,ID_MAIN_PROGIND), /* A per cent progress indicator */
  75.                 Space, EndGroup,
  76.       SpaceS,HorizGroupA,
  77.                 Space, HorizGroupSA, TextN("000%"), Space, TextN("050%"), Space, TextN("100%"), EndGroup,
  78.                 Space, EndGroup,
  79.       Space, HorizGroupSA,
  80.                 Space, ButtonE("_Stop",ID_MAIN_GADGET_STOP),
  81.                 Space, EndGroup,
  82.       Space, EndGroup,
  83.  
  84.     EndProject))
  85.   {
  86.     for(i=0;(i<100)&&(!close_me);i++)
  87.     {
  88.       /* Wait 1/5 second. You might want to do some real work here ;) */
  89.  
  90.       Delay(10L);
  91.  
  92.       /* Display our progress */
  93.  
  94.       TR_SetAttribute(project,ID_MAIN_PROGIND,TRAT_Value,i);
  95.  
  96.       /* And Check for the 'Stop' gadget. Note that you always have to include
  97.          such a TR_GetMsg() loop, even if there's no gadget for stopping. You
  98.          have to call TR_GetMsg() regularly so that Triton may react on the
  99.          user's wishes, e.g. redrawing the window contents after a resize. */
  100.  
  101.       while(trmsg=TR_GetMsg(Application))
  102.       {
  103.         if(trmsg->trm_Project==project) switch(trmsg->trm_Class)
  104.         {
  105.           case TRMS_CLOSEWINDOW:
  106.             close_me=TRUE;
  107.             break;
  108.  
  109.           case TRMS_ERROR:
  110.             puts(TR_GetErrorString(trmsg->trm_Data));
  111.             break;
  112.  
  113.           case TRMS_ACTION:
  114.             if(trmsg->trm_ID==ID_MAIN_GADGET_STOP) close_me=TRUE;
  115.         }
  116.         TR_ReplyMsg(trmsg);
  117.       }
  118.     }
  119.     TR_CloseProject(project);
  120.   }
  121.   else puts("Can't open window.");
  122. }
  123.  
  124.  
  125. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  126. /* ////////////////////////////////////////////////////////////////////////////////////// Main function // */
  127. /* /////////////////////////////////////////////////////////////////////////////////////////////////////// */
  128.  
  129. int main(void)
  130. {
  131.   if(TR_OpenTriton(TRITON11VERSION,TRCA_Name,"trProgIndDemo",TRCA_Version,"1.0",TAG_END))
  132.   {
  133.     do_main();
  134.     TR_CloseTriton();
  135.     return 0;
  136.   } else puts("Can't open triton.library v2+.");
  137.  
  138.   return 20;
  139. }
  140.