home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d913 / stickit.lha / StickIt / Source / Source.lha / general.c < prev    next >
C/C++ Source or Header  |  1993-06-01  |  5KB  |  226 lines

  1. /*****************************************
  2.  *************   general.c   *************
  3.  *****************************************/
  4.  
  5. #include <dos/dos.h>
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/classes.h>
  9. #include <intuition/classusr.h>
  10. #include <intuition/imageclass.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/text.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <clib/diskfont_protos.h>
  23. #include <clib/dos_protos.h>
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. #include "stickit.h"
  30.  
  31. #include "consts.h"
  32. #include "structs.h"
  33. #include "prototype.h"
  34.  
  35. extern struct IntuitionBase *IntuitionBase;
  36.  
  37. extern struct Screen *Scr;
  38.  
  39. extern prjptr prj;
  40.  
  41. extern struct Gadget *editGadgets[];
  42.  
  43. struct EasyStruct reqwarn =
  44.    {
  45.    sizeof (struct EasyStruct),
  46.    0,
  47.    "StickIt...",
  48.    "Warning, %s",
  49.    "Continue",
  50.    };
  51.             
  52. struct EasyStruct reqfatal =
  53.    {
  54.    sizeof (struct EasyStruct),
  55.    0,
  56.    "StickIt...",
  57.    "Fatal error, %s",
  58.    "Quit",
  59.    };
  60.  
  61. UWORD __chip waitPointer[] =
  62.    {
  63.    0x0000, 0x0000,     /* reserved, must be NULL */
  64.                
  65.    0x0400, 0x07C0,
  66.    0x0000, 0x07C0,
  67.    0x0100, 0x0380,
  68.    0x0000, 0x07E0,
  69.    0x07C0, 0x1FF8,
  70.    0x1FF0, 0x3FEC,
  71.    0x3FF8, 0x7FDE,
  72.    0x3FF8, 0x7FBE,
  73.    0x7FFC, 0xFF7F,
  74.    0x7EFC, 0xFFFF,
  75.    0x7FFC, 0xFFFF,
  76.    0x3FF8, 0x7FFE,
  77.    0x3FF8, 0x7FFE,
  78.    0x1FF0, 0x3FFC,
  79.    0x07C0, 0x1FF8,
  80.    0x0000, 0x07E0,
  81.               
  82.    0x0000, 0x0000,     /* reserved, must be NULL */
  83.    };
  84.          
  85. void error(char *msg,int number)
  86.    {
  87.    LONG reply;
  88.  
  89.    if ((IntuitionBase) && (number < ERR_FATAL))
  90.       reply = EasyRequest(NULL,&reqwarn,NULL,(APTR)msg);
  91.    else if ((IntuitionBase) && (number >= ERR_FATAL))
  92.       reply = EasyRequest(NULL,&reqfatal,NULL,(APTR)msg);
  93.  
  94.    if (number >= ERR_FATAL)
  95.       cleanup();
  96.    }
  97.  
  98. void printfnotes()
  99.    {
  100.    struct ndnode *ndptr;
  101.    nteptr currnote;
  102.    int noteno = 0;
  103.  
  104.    ndptr = prj->notes_start->next;
  105.  
  106.    printf("Printing notes (%d in total)...\n",prj->no_notes);
  107.  
  108.    while (ndptr->next)
  109.       {
  110.       currnote = ndptr->data;
  111.  
  112.       printf("\t... Note number %d\n",++noteno);
  113.       printf("\t... (xpos,ypos) : (%d,%d)\n",currnote->xpos,
  114.          currnote->ypos);
  115.       printf("\t... (title) : (%s)\n",currnote->title);
  116.       printf("\t... (note) : (%s)\n\n",currnote->note);
  117.  
  118.       ndptr = ndptr->next;
  119.       }
  120.    }
  121.  
  122. void andysoffgadget(struct Gadget *gad, struct Window *win)
  123.    {
  124.    if (!(gad->Flags & GFLG_DISABLED))
  125.       GT_SetGadgetAttrs(gad,win,NULL,GA_Disabled,TRUE,TAG_END);
  126.    }
  127.  
  128. void andysongadget(struct Gadget *gad, struct Window *win)
  129.    {
  130.    if (gad->Flags & GFLG_DISABLED)
  131.       GT_SetGadgetAttrs(gad,win,NULL,GA_Disabled,FALSE,TAG_END);
  132.    }
  133.  
  134. void andysselectgadget(struct Gadget *gad, struct Window *win)
  135.    {
  136.    if (!(gad->Flags & GFLG_SELECTED))
  137.       GT_SetGadgetAttrs(gad,win,NULL,GTCB_Checked,TRUE,TAG_END);
  138.    }
  139.  
  140. void andysunselectgadget(struct Gadget *gad, struct Window *win)
  141.    {
  142.    if (gad->Flags & GFLG_SELECTED)
  143.       GT_SetGadgetAttrs(gad,win,NULL,GTCB_Checked,FALSE,TAG_END);
  144.    }
  145.  
  146. void storenote()
  147.    {
  148.    nteptr currnote;
  149.  
  150.    if (prj->currnode)
  151.       {
  152.       currnote = prj->currnode->data;
  153.  
  154.       /***   The 2 tests below are done like this for speed   ***/
  155.  
  156.       if (prj->titlechanged)
  157.          {
  158.          strncpy(currnote->title,GetString(editGadgets[GDX_title]),STRLEN_TITLE);
  159.          prj->filechanged = TRUE;
  160.          }
  161.       else if (strncmp(currnote->title,GetString(editGadgets[GDX_title]),STRLEN_TITLE))
  162.          {
  163.          strncpy(currnote->title,GetString(editGadgets[GDX_title]),STRLEN_TITLE);
  164.          prj->filechanged = TRUE;
  165.          }
  166.  
  167.       if (prj->notechanged)
  168.          {
  169.          strncpy(currnote->note,GetString(editGadgets[GDX_note]),STRLEN_NOTE);
  170.          prj->filechanged = TRUE;
  171.          }
  172.       else if (strncmp(currnote->note,GetString(editGadgets[GDX_note]),STRLEN_NOTE))
  173.          {
  174.          strncpy(currnote->note,GetString(editGadgets[GDX_note]),STRLEN_NOTE);
  175.          prj->filechanged = TRUE;
  176.          }
  177.  
  178.       currnote->show = editGadgets[GDX_show]->Flags & GFLG_SELECTED;
  179.       }
  180.    else
  181.       {
  182.       if ((strlen(GetString(editGadgets[GDX_title])) != 0) ||
  183.             (strlen(GetString(editGadgets[GDX_note])) != 0))
  184.          prj->filechanged = TRUE;
  185.       }
  186.  
  187.    prj->titlechanged = prj->notechanged = FALSE;
  188.    }
  189.  
  190. void createcopybuffernode()
  191.    {
  192.    prj->copybuffernode = llealloc();
  193.    prj->copybuffernode->data = notealloc();
  194.  
  195.    if (!prj->copybuffernode->data)
  196.       error("createcopybuffernode; Can't allocate note",ERR_MALLOC);
  197.    }
  198.  
  199. nteptr notealloc()
  200.    {
  201.    nteptr newnote;
  202.  
  203.    newnote = (nteptr)malloc(sizeof(struct note));
  204.  
  205.    if (!newnote)
  206.       error("notealloc; Can't allocate newnote",ERR_MALLOC);
  207.  
  208.    newnote->win = NULL;
  209.  
  210.    return (newnote);
  211.    }
  212.  
  213. void andyssleeppointer(struct Window *win)
  214.    {
  215.    SetPointer(win, waitPointer, 16, 16, -6, 0);
  216.    }
  217.  
  218. void andysstripintuimessages(struct MsgPort *msgport, struct Window *win)
  219.    {
  220.    Forbid();
  221.  
  222.    StripIntuiMessages(msgport,win);
  223.  
  224.    Permit();
  225.    }
  226.