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

  1. /* This file contains empty template routines that
  2.  * the IDCMP handler will call uppon. Fill out these
  3.  * routines with your code or use them as a reference
  4.  * to create your program.
  5.  */
  6.  
  7. #include <dos/dos.h>
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18.  
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/utility_protos.h>
  24. #include <clib/diskfont_protos.h>
  25. #include <clib/dos_protos.h>
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. #include "stickit.h"
  32.  
  33. #include "consts.h"
  34. #include "structs.h"
  35. #include "prototype.h"
  36.  
  37. extern prjptr prj;
  38.  
  39. extern struct Window *editWnd;
  40. extern struct Window *aboutWnd;
  41.  
  42. extern struct Gadget *editGadgets[];
  43.  
  44. extern struct IntuiMessage    editMsg;
  45.  
  46. extern UWORD editTop;
  47. extern UWORD editLeft;
  48. extern UWORD editHeight;
  49. extern UWORD editWidth;
  50.  
  51. struct EasyStruct andysreq =
  52.    {
  53.    sizeof(struct EasyStruct),
  54.    0,
  55.    "StickIt",
  56.    "%s",
  57.    "Okay|Cancel"
  58.    };
  59.        
  60. int titleClicked( void )
  61.    {
  62.    /* routine when gadget "Title" is clicked. */
  63.  
  64.    prj->titlechanged = TRUE;
  65.    prj->filechanged = TRUE;
  66.  
  67.    /* Place cursor in next field */
  68.  
  69.    ActivateGadget(editGadgets[GDX_note],editWnd,NULL);
  70.  
  71.    return(TRUE);
  72.    }
  73.  
  74. int noteClicked( void )
  75.    {
  76.    /* routine when gadget "Note" is clicked. */
  77.  
  78.    prj->notechanged = TRUE;
  79.    prj->filechanged = TRUE;
  80.  
  81.    /* Place cursor in next field */
  82.  
  83.    ActivateGadget(editGadgets[GDX_title],editWnd,NULL);
  84.  
  85.    return(TRUE);
  86.    }
  87.  
  88. int notesClicked( void )
  89.    {
  90.    /* routine when gadget "Notes..." is clicked. */
  91.  
  92.    storenote();
  93.  
  94.    return (FALSE);
  95.    }
  96.  
  97. int tostartClicked( void )
  98.    {
  99.    /* routine when gadget "Front" is clicked. */
  100.  
  101.    if (editGadgets[GDX_tostart]->Flags & GFLG_DISABLED)
  102.       return (TRUE);
  103.  
  104.    storenote();
  105.  
  106.    prj->currnode = prj->notes_start->next;
  107.  
  108.    displaynote();
  109.    updatebuttons();
  110.  
  111.    return(TRUE);
  112.    }
  113.  
  114. int prevClicked( void )
  115.    {
  116.    /* routine when gadget "<" is clicked. */
  117.  
  118.    if (editGadgets[GDX_prev]->Flags & GFLG_DISABLED)
  119.       return (TRUE);
  120.  
  121.    storenote();
  122.  
  123.    prj->currnode = prj->currnode->prev;
  124.  
  125.    displaynote();
  126.    updatebuttons();
  127.  
  128.    return(TRUE);
  129.    }
  130.  
  131. int nextClicked( void )
  132.    {
  133.    /* routine when gadget ">" is clicked. */
  134.  
  135.    if (editGadgets[GDX_next]->Flags & GFLG_DISABLED)
  136.       return (TRUE);
  137.  
  138.    storenote();
  139.  
  140.    prj->currnode = prj->currnode->next;
  141.  
  142.    displaynote();
  143.    updatebuttons();
  144.  
  145.    return(TRUE);
  146.    }
  147.  
  148. int toendClicked( void )
  149.    {
  150.    /* routine when gadget "Back" is clicked. */
  151.  
  152.    if (editGadgets[GDX_toend]->Flags & GFLG_DISABLED)
  153.       return (TRUE);
  154.  
  155.    storenote();
  156.  
  157.    prj->currnode = prj->notes_end->prev;
  158.  
  159.    displaynote();
  160.    updatebuttons();
  161.  
  162.    return(TRUE);
  163.    }
  164.  
  165. int addClicked( void )
  166.    {
  167.    nteptr newnote;
  168.  
  169.    /* routine when gadget "Add" is clicked. */
  170.  
  171.    if (!prj->currnode)
  172.       {
  173.       /*** Create a new note in the linked list   ***/
  174.           
  175.       prj->currnode = llealloc();
  176.       prj->currnode->data = notealloc();
  177.  
  178.       newnote = prj->currnode->data;
  179.  
  180.       if (!newnote)
  181.          error("addClicked; Can't allocate new note",ERR_MALLOC);
  182.  
  183.       /***   Add to list   ***/
  184.  
  185.       lleadd(prj->notes_start,prj->currnode);
  186.  
  187.       newnote->show = editGadgets[GDX_show]->Flags & GFLG_SELECTED;
  188.  
  189.       strncpy(newnote->title,GetString(editGadgets[GDX_title]),STRLEN_TITLE);
  190.       strncpy(newnote->note,GetString(editGadgets[GDX_note]),STRLEN_NOTE);
  191.  
  192.       newnote->xpos = prj->nextx;
  193.       newnote->ypos = prj->nexty;
  194.  
  195.       prj->nextx += INC_X;
  196.       prj->nexty += INC_Y;
  197.  
  198.       updatebuttons();
  199.  
  200.       changeno_notes(1);
  201.  
  202.       prj->filechanged = TRUE;
  203.       }
  204.    else
  205.       {
  206.       storenote();
  207.  
  208.       prj->currnode = NULL;
  209.  
  210.       strcpy(GetString(editGadgets[GDX_title]),"");
  211.       strcpy(GetString(editGadgets[GDX_note]),"");
  212.  
  213.       RefreshGList(editGadgets[GDX_title],editWnd,NULL,1);
  214.       RefreshGList(editGadgets[GDX_note],editWnd,NULL,1);
  215.  
  216.       andysselectgadget(editGadgets[GDX_show],editWnd);
  217.  
  218.       updatebuttons();
  219.  
  220.       ActivateGadget(editGadgets[GDX_title],editWnd,NULL);
  221.       }
  222.  
  223.    return(TRUE);
  224.    }
  225.  
  226. int showClicked( void )
  227.    {
  228.    /* routine when gadget "Show" is clicked. */
  229.  
  230.    ((nteptr)prj->currnode->data)->show = 
  231.                               editGadgets[GDX_show]->Flags & GFLG_SELECTED;
  232.  
  233.    return (TRUE);
  234.    }
  235.  
  236. int editopen( void )
  237.    {
  238.    LONG reqreply;
  239.  
  240.    /* routine when (sub)item "Open" is selected. */
  241.  
  242.    storenote();
  243.  
  244.    /***   If data has changed, ask if continue else do nothing   ***/
  245.  
  246.    if (prj->filechanged)
  247.       {
  248.       /***   If data has changed, ask if continue else open anyway   ***/
  249.  
  250.       andysoffgadget(editGadgets[GDX_title],editWnd);
  251.       andysoffgadget(editGadgets[GDX_note],editWnd);
  252.  
  253.       reqreply = EasyRequest(editWnd,&andysreq,NULL,
  254.             "Data has been changed, continue with open ?"); /* 1 = Ok */
  255.  
  256.       /***   Clear any stray messages   ***/
  257.  
  258.       andysstripintuimessages(editWnd->UserPort,editWnd);
  259.  
  260.       if (aboutWnd)
  261.          andysstripintuimessages(aboutWnd->UserPort,aboutWnd);
  262.  
  263.       if (reqreply)  /* If user has clicked on Okay */
  264.          {
  265.          /***   Free old notes   ***/
  266.  
  267.          llfreemid(prj->notes_start->next);
  268.  
  269.          readnotefile();
  270.  
  271.          if (prj->no_notes == 0)
  272.             {
  273.             prj->currnode = NULL;
  274.             addClicked();
  275.             }
  276.          else
  277.             prj->currnode = prj->notes_start->next;
  278.          }
  279.  
  280.       /***   Re-draw text (may have been altered)   ***/
  281.  
  282.       if (prj->currnode)
  283.          {
  284.          displaynote();
  285.          updatebuttons();
  286.          }
  287.  
  288.       andysongadget(editGadgets[GDX_title],editWnd);
  289.       andysongadget(editGadgets[GDX_note],editWnd);
  290.       }
  291.  
  292.    return(TRUE);
  293.    }
  294.  
  295. int editsave( void )
  296.    {
  297.    /* routine when (sub)item "Save" is selected. */
  298.  
  299.    storenote();
  300.    writenotefile();
  301.  
  302.    return(TRUE);
  303.    }
  304.  
  305. int editabout( void )
  306.    {
  307.    /* routine when (sub)item "About" is selected. */
  308.  
  309.    if (!aboutWnd)
  310.       openabout();
  311.    else
  312.       WindowToFront(aboutWnd);
  313.  
  314.    return (TRUE);
  315.    }
  316.  
  317. int editquit( void )
  318.    {
  319.    /* routine when (sub)item "Quit" is selected. */
  320.  
  321.    return(editCloseWindow());
  322.    }
  323.  
  324. int editcut( void )
  325.    {
  326.    /* routine when (sub)item "Cut" is selected. */
  327.  
  328.    if (prj->currnode)
  329.       {
  330.       editcopy();
  331.       editdelete();
  332.  
  333.       prj->nextx -= INC_X;
  334.       prj->nexty -= INC_Y;
  335.       }
  336.  
  337.    return (TRUE);
  338.    }
  339.  
  340. int editcopy( void )
  341.    {
  342.    /* routine when (sub)item "Copy" is selected. */
  343.  
  344.    if (prj->currnode)
  345.       {
  346.       if (!prj->copybuffernode)
  347.          createcopybuffernode();
  348.  
  349.       strncpy(((nteptr)prj->copybuffernode->data)->title,GetString(
  350.                                         editGadgets[GDX_title]),STRLEN_TITLE);
  351.       strncpy(((nteptr)prj->copybuffernode->data)->note,GetString(
  352.                                         editGadgets[GDX_note]),STRLEN_NOTE);
  353.  
  354.       prj->nextx = ((nteptr)prj->currnode->data)->xpos;
  355.       prj->nexty = ((nteptr)prj->currnode->data)->ypos;
  356.  
  357.       prj->nextx += INC_X;
  358.       prj->nexty += INC_Y;
  359.  
  360.       ((nteptr)prj->copybuffernode->data)->xpos =
  361.                                        ((nteptr)prj->currnode->data)->xpos;
  362.       ((nteptr)prj->copybuffernode->data)->ypos =
  363.                                        ((nteptr)prj->currnode->data)->ypos;
  364.  
  365.       ((nteptr)prj->copybuffernode->data)->show =
  366.                                  editGadgets[GDX_show]->Flags & GFLG_SELECTED;
  367.  
  368.       }
  369.  
  370.    return(TRUE);
  371.    }
  372.  
  373. int editpaste( void )
  374.    {
  375.    struct ndnode *ndptr;
  376.  
  377.    /* routine when (sub)item "Paste" is selected. */
  378.  
  379.    if ((prj->copybuffernode) && (prj->currnode))
  380.       {
  381.       /***   Only do it if there is something in the buffer   ***/
  382.  
  383.       storenote();
  384.  
  385.       ndptr = llealloc();
  386.       ndptr->data = notealloc();
  387.  
  388.       if (!ndptr->data)
  389.          error("editpaste; Can't alloc note",ERR_MALLOC);
  390.  
  391.       strncpy(((nteptr)ndptr->data)->title,
  392.                      ((nteptr)prj->copybuffernode->data)->title,STRLEN_TITLE);
  393.       strncpy(((nteptr)ndptr->data)->note,
  394.                      ((nteptr)prj->copybuffernode->data)->note,STRLEN_NOTE);
  395.       ((nteptr)ndptr->data)->show = ((nteptr)prj->copybuffernode->data)->show;
  396.       ((nteptr)ndptr->data)->win = NULL;
  397.  
  398.       ((nteptr)ndptr->data)->xpos = prj->nextx;
  399.       ((nteptr)ndptr->data)->ypos = prj->nexty;
  400.  
  401.       prj->nextx += INC_X;
  402.       prj->nexty += INC_Y;
  403.  
  404.       /***   Add to list   ***/
  405.  
  406.       lleadd(prj->currnode->prev,ndptr);
  407.  
  408.       prj->currnode = ndptr;
  409.  
  410.       displaynote();
  411.  
  412.       updatebuttons();
  413.  
  414.       changeno_notes(1);
  415.  
  416.       prj->filechanged = TRUE;
  417.       }
  418.  
  419.    return(TRUE);
  420.    }
  421.  
  422. int editdelete( void )
  423.    {
  424.    struct ndnode *new;
  425.  
  426.    if (prj->currnode)    /* 'cos I can't ghost the menu out yet */
  427.       {
  428.       /* routine when (sub)item "Delete" is selected. */
  429.  
  430.       strcpy(GetString(editGadgets[GDX_title]),"");
  431.       strcpy(GetString(editGadgets[GDX_note]),"");
  432.  
  433.       new = prj->currnode->prev;
  434.  
  435.       lleremove(prj->currnode);
  436.  
  437.       changeno_notes(-1);
  438.  
  439.       prj->currnode = new->next;
  440.  
  441.       if (prj->currnode->next == NULL)    /* If we're at the end, move back */
  442.          prj->currnode = new;
  443.  
  444.       if (prj->no_notes != 0)
  445.          {
  446.          displaynote();
  447.          updatebuttons();
  448.          }
  449.       else
  450.          {
  451.          RefreshGList(editGadgets[GDX_title],editWnd,NULL,1);
  452.          RefreshGList(editGadgets[GDX_note],editWnd,NULL,1);
  453.  
  454.          prj->currnode = NULL;
  455.  
  456.          updatebuttons();
  457.          }
  458.  
  459.       prj->filechanged = TRUE;
  460.       }
  461.  
  462.    return (TRUE);
  463.    }
  464.  
  465. int editshownotes( void )
  466.    {
  467.    /* routine when (sub)item "Show notes..." is selected. */
  468.  
  469.    storenote();
  470.  
  471.    return (FALSE);
  472.    }
  473.  
  474. int editCloseWindow( void )
  475.    {
  476.    /* routine for "IDCMP_CLOSEWINDOW". */
  477.  
  478.    LONG reqreply;
  479.  
  480.    storenote();
  481.  
  482.    if (prj->filechanged)
  483.       {
  484.       /***   If data has changed, ask if continue else open anyway   ***/
  485.  
  486.       andysoffgadget(editGadgets[GDX_title],editWnd);
  487.       andysoffgadget(editGadgets[GDX_note],editWnd);
  488.  
  489.       reqreply = EasyRequest(editWnd,&andysreq,NULL,
  490.             "Data has been changed, continue with quit ?"); /* 1 = Ok */
  491.  
  492.       /***   Clear any stray messages   ***/
  493.  
  494.       andysstripintuimessages(editWnd->UserPort,editWnd);
  495.  
  496.       if (aboutWnd)
  497.          andysstripintuimessages(aboutWnd->UserPort,aboutWnd);
  498.  
  499.       if (reqreply)  /* If user has clicked on Okay */
  500.          {
  501.          prj->quit = TRUE;
  502.          return(FALSE);
  503.          }
  504.  
  505.       andysongadget(editGadgets[GDX_title],editWnd);
  506.       andysongadget(editGadgets[GDX_note],editWnd);
  507.  
  508.       return(TRUE);
  509.       }
  510.  
  511.    prj->quit = TRUE;
  512.    return(FALSE);
  513.    }
  514.  
  515. int editChangeWindow( void )
  516.    {
  517.    /* routine for "IDCMP_CHANGEWINDOW". */
  518.  
  519.    editLeft   = editWnd->LeftEdge;
  520.    editTop    = editWnd->TopEdge;
  521.    editWidth  = editWnd->Width;
  522.    editHeight = editWnd->Height - editWnd->BorderTop;
  523.  
  524.    return (TRUE);
  525.    }
  526.  
  527. int aboutMouseButtons( void )
  528.    {
  529.    /* routine for "IDCMP_MOUSEBUTTONS". */
  530.  
  531.    if (aboutWnd)
  532.       prj->abouttoclose = TRUE;
  533.  
  534.    return (TRUE);
  535.    }
  536.            
  537. int dummynoteMouseButtons( void )
  538.    {
  539.    /* routine for "IDCMP_MOUSEBUTTONS". */
  540.  
  541.    return(TRUE);
  542.    }
  543.                
  544. int dummynoteChangeWindow( void )
  545.    {
  546.    /* routine for "IDCMP_CHANGEWINDOW". */
  547.  
  548.    return(TRUE);
  549.    }
  550.        
  551. int gadeditbutdelClicked( void )
  552.    {
  553.    /* routine when gadget "Del" is clicked. */
  554.  
  555.    return(TRUE);
  556.    }
  557.  
  558. int editVanillaKey( void )
  559.    {
  560.    /* routine for "IDCMP_VANILLAKEY". */
  561.  
  562.    switch (editMsg.Code)
  563.       {
  564.       case 'f':
  565.       case 'F':
  566.          tostartClicked();
  567.          break;
  568.       case 'b':
  569.       case 'B':
  570.          toendClicked();
  571.          break;
  572.       case ',':
  573.       case '<':
  574.          prevClicked();
  575.          break;
  576.       case '.':
  577.       case '>':
  578.          nextClicked();
  579.          break;
  580.  
  581.       case 'a':
  582.       case 'A':
  583.          addClicked();
  584.          break;
  585.  
  586.       case 't':
  587.       case 'T':
  588.          ActivateGadget(editGadgets[GDX_title],editWnd,NULL);
  589.          break;
  590.  
  591.       case 'n':
  592.       case 'N':
  593.          ActivateGadget(editGadgets[GDX_note],editWnd,NULL);
  594.          break;
  595.  
  596.       case 's':
  597.       case 'S':
  598.          editGadgets[GDX_show]->Flags ^= GFLG_SELECTED;
  599.  
  600.          if (editGadgets[GDX_show]->Flags & GFLG_SELECTED)
  601.             GT_SetGadgetAttrs(editGadgets[GDX_show],editWnd,NULL,
  602.                GTCB_Checked,TRUE);
  603.          else
  604.             GT_SetGadgetAttrs(editGadgets[GDX_show],editWnd,NULL,
  605.                GTCB_Checked,FALSE);         
  606.          break;
  607.  
  608.       default:
  609.          break;
  610.       }
  611.    return (TRUE);
  612.    }
  613.            
  614.