home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / os20 / util / stickit / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  7.5 KB  |  341 lines

  1. /************************************************
  2.  **************    StickIt.c   ******************
  3.  ************************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/classes.h>
  10. #include <intuition/classusr.h>
  11. #include <intuition/imageclass.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/gadtools.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/gfxbase.h>
  16. #include <workbench/startup.h>
  17. #include <workbench/workbench.h>
  18. #include <dos/dos.h>
  19.  
  20. #include <clib/alib_protos.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/gadtools_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <clib/diskfont_protos.h>
  26. #include <clib/utility_protos.h>
  27. #include <clib/icon_protos.h>
  28. #include <clib/dos_protos.h>
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33.  
  34. #include "stickit.h"
  35.  
  36. #include "consts.h"
  37. #include "structs.h"
  38. #include "prototype.h"
  39.  
  40. struct IntuitionBase  *IntuitionBase = NULL;
  41. struct Library *GfxBase = NULL;
  42. struct Library *GadToolsBase = NULL;
  43. struct Library *UtilityBase = NULL;
  44. struct Library *DiskfontBase = NULL;
  45. struct Library *IconBase = NULL;
  46.  
  47. extern struct Gadget *editGadgets[];
  48.  
  49. extern struct WBStartup *WBenchMsg;
  50.  
  51. prjptr prj = NULL;
  52.  
  53. /***   Version string   ***/
  54.  
  55. char *version = "$VER: StickIt V1.03 15th November '93 ©1993 Andy Dean";
  56.  
  57. int main(int argc, char **argv)
  58.    {
  59.    /***   Open Libraries   ***/
  60.  
  61.    if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary
  62.                   ("intuition.library",OS_VER)))
  63.       cleanup();
  64.  
  65.    if (!(GfxBase = OpenLibrary("graphics.library",OS_VER)))
  66.       cleanup();
  67.  
  68.    if (!(GadToolsBase = OpenLibrary("gadtools.library",OS_VER)))
  69.       cleanup();
  70.  
  71.    if (!(UtilityBase = OpenLibrary("utility.library",OS_VER)))
  72.       cleanup();
  73.  
  74.    if (!(DiskfontBase = OpenLibrary("diskfont.library",36)))
  75.       cleanup();
  76.  
  77.    if (!(IconBase = OpenLibrary("icon.library",OS_VER)))
  78.       cleanup();
  79.  
  80.    /***   Main program    ***********************************************/
  81.  
  82.    init(argc);
  83.  
  84.    /***   Get lock on screen   ***/
  85.  
  86.    if (SetupScreen())
  87.       cleanup();
  88.  
  89.    /***   How do we look when we open up ?   ***/
  90.  
  91.    while (!prj->quit)
  92.       {
  93.       if ((prj->editnotes) || (prj->startedit) || (prj->no_notes == 0))
  94.          {
  95.          prj->startedit = FALSE;
  96.          openedit();
  97.          }
  98.       else
  99.          shownotes();
  100.       }
  101.  
  102.    /*********************************************************************/
  103.  
  104.    cleanup();
  105.    }
  106.  
  107. void init(int argc)
  108.    {
  109.    prj = (prjptr)malloc(sizeof(struct project));
  110.  
  111.    if (!prj)
  112.       error("Could not allocate prj",ERR_MALLOC);
  113.       
  114.    prj->no_notes = 0;
  115.    prj->no_notes_visable = 0;
  116.  
  117.    prj->notes_start = prj->notes_end = NULL;
  118.  
  119.    prj->editnotes = FALSE;
  120.    prj->showedit = TRUE;
  121.    prj->startedit = FALSE;
  122.    prj->abouttoclose = FALSE;
  123.    prj->quit = FALSE;
  124.  
  125.    prj->filechanged = prj->titlechanged = prj->notechanged = FALSE;
  126.  
  127.    prj->delay = 0;
  128.  
  129.    strncpy(prj->notefile,"StickIt.notes",STRLEN_FNAME);
  130.    prj->backcolour = 0;
  131.    prj->textcolour = 1;
  132.  
  133.    prj->notefont.ta_Name = prj->fontname;
  134.    strncpy(prj->fontname,"Helvetica.font",STRLEN_FONTNAME);
  135.  
  136.    prj->notefont.ta_YSize = 12;
  137.    prj->notefont.ta_Style = NULL;
  138.    prj->notefont.ta_Flags = NULL;
  139.  
  140.    prj->msgport = NULL;
  141.    prj->notefontptr = NULL;
  142.  
  143.    prj->currnode = NULL;
  144.    prj->copybuffernode = NULL;
  145.  
  146.    prj->noteheight = 70;
  147.    prj->notewidth = 150;
  148.  
  149.    prj->nextx = 40;
  150.    prj->nexty = 20;
  151.  
  152.    if (!argc)
  153.       readtooltypes();
  154.  
  155.    /***   Startup delay to stop disk thrashing   ***/
  156.  
  157.    Delay(prj->delay * 50);
  158.  
  159.    initlists();
  160.    readnotefile();
  161.  
  162.    /***   If no notes, don't show edit window if user doesn't want it   ***/
  163.  
  164.    if ((prj->no_notes == 0) && (!prj->startedit))
  165.       cleanup();
  166.  
  167.    /***   Open font   ***/
  168.  
  169.    prj->notefontptr = OpenDiskFont(&prj->notefont);
  170.  
  171.    if (!prj->notefontptr)
  172.       prj->notefontptr = ((struct GfxBase *)GfxBase)->DefaultFont;
  173.               
  174.    }
  175.  
  176. void cleanup()
  177.    {
  178.    /***   Remove any notes that may be on the screen   ***/
  179.  
  180.    if (prj)
  181.       removenotes();
  182.  
  183.    /***   Call GadToolsBox routines to shut everything down   ***/
  184.  
  185.    CloseaboutWindow();
  186.    CloseeditWindow();
  187.    CloseDownScreen();
  188.  
  189.    if (prj) {
  190.       /***   Close font   ***/
  191.  
  192.      if ((prj->notefontptr) && 
  193.                (prj->notefontptr != ((struct GfxBase *)GfxBase)->DefaultFont))
  194.          CloseFont(prj->notefontptr);
  195.  
  196.       prj->notefontptr = NULL;
  197.  
  198.       /***   Remove linked list   ***/
  199.  
  200.       if (prj->notes_start)
  201.          llfree(prj->notes_start);
  202.  
  203.       /**   Remove copy buffer   ***/
  204.  
  205.       if (prj->copybuffernode)
  206.          {
  207.          if (prj->copybuffernode->data)
  208.             free((void *)prj->copybuffernode->data);
  209.  
  210.          free((void *)prj->copybuffernode);
  211.         }
  212.  
  213.       /***   Remove message port   ***/
  214.  
  215.       if (prj->msgport)
  216.          DeleteMsgPort(prj->msgport);
  217.  
  218.       /***   Finally, remove prj   ***/
  219.  
  220.       if(prj)
  221.          free((void *)prj);
  222.    }
  223.  
  224.    /***   Close libraries   ***/
  225.  
  226.    if (IconBase)
  227.       CloseLibrary(IconBase);
  228.  
  229.    if (DiskfontBase)
  230.       CloseLibrary(DiskfontBase);
  231.  
  232.    if (UtilityBase)
  233.       CloseLibrary(UtilityBase);
  234.  
  235.    if (GadToolsBase)
  236.       CloseLibrary(GadToolsBase);
  237.  
  238.    if (GfxBase)
  239.       CloseLibrary(GfxBase);
  240.  
  241.    if (IntuitionBase)
  242.       CloseLibrary((struct Library *)IntuitionBase);
  243.  
  244.    exit(20);
  245.    }
  246.  
  247. void readtooltypes()
  248.    {
  249.    struct DiskObject *diskobj;
  250.  
  251.    char *toolstring;
  252.  
  253.    LONG value;
  254.  
  255.    if (WBenchMsg)
  256.       {
  257.       diskobj = GetDiskObject(WBenchMsg->sm_ArgList[0].wa_Name);
  258.  
  259.       if (diskobj)
  260.          {
  261.          /***   Our notefile   ***/
  262.  
  263.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEFILE");
  264.  
  265.          if (toolstring)
  266.             strncpy(prj->notefile,toolstring,STRLEN_FNAME);
  267.  
  268.          /***   Font   ***/
  269.  
  270.          toolstring = FindToolType(diskobj->do_ToolTypes,"FONTNAME");
  271.  
  272.          if (toolstring)
  273.             strncpy(prj->fontname,toolstring,STRLEN_FONTNAME);
  274.  
  275.          toolstring = FindToolType(diskobj->do_ToolTypes,"FONTSIZE");
  276.  
  277.          if (toolstring)
  278.             {
  279.             StrToLong(toolstring,&value);
  280.             prj->notefont.ta_YSize = (UWORD)value;
  281.             }
  282.  
  283.          /***   Start with edit window if no notes in file ?   ***/
  284.  
  285.          toolstring = FindToolType(diskobj->do_ToolTypes,"STARTEDIT");
  286.  
  287.          if (toolstring)
  288.             prj->startedit = (Stricmp(toolstring,"YES")?FALSE:TRUE);
  289.  
  290.          /***   Colours   ***/
  291.  
  292.          toolstring = FindToolType(diskobj->do_ToolTypes,"BACKCOLOUR");
  293.  
  294.          if (toolstring)
  295.             {
  296.             StrToLong(toolstring,&value);
  297.             prj->backcolour = (int)value;
  298.             }
  299.  
  300.          toolstring = FindToolType(diskobj->do_ToolTypes,"TEXTCOLOUR");
  301.  
  302.          if (toolstring)
  303.             {
  304.             StrToLong(toolstring,&value);
  305.             prj->textcolour = (int)value;
  306.             }
  307.  
  308.          /***   Opening delay to stop disk thrashing   ***/
  309.  
  310.          toolstring = FindToolType(diskobj->do_ToolTypes,"DELAY");
  311.  
  312.          if (toolstring)
  313.             {
  314.             StrToLong(toolstring,&value);
  315.             prj->delay = (ULONG)value;
  316.             }
  317.  
  318.          /***   Note sizes   ***/
  319.  
  320.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEHEIGHT");
  321.  
  322.          if (toolstring)
  323.             {
  324.             StrToLong(toolstring,&value);
  325.             prj->noteheight = (UWORD)value;
  326.             }
  327.  
  328.          toolstring = FindToolType(diskobj->do_ToolTypes,"NOTEWIDTH");
  329.  
  330.          if (toolstring)
  331.             {
  332.             StrToLong(toolstring,&value);
  333.             prj->notewidth = (UWORD)value;
  334.             }
  335.  
  336.  
  337.          FreeDiskObject(diskobj);
  338.          }
  339.       }
  340.    }
  341.