home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / findfile / ffsource.lha / FFWindow.c < prev    next >
C/C++ Source or Header  |  1993-04-03  |  9KB  |  353 lines

  1. /******************************** FindFile Window Management **********************
  2.   FindFile window management routines
  3.  
  4.   1.8
  5.  
  6. **********************************************************************************/
  7. #include "FindFile.h"
  8.  
  9. /* Export library bases */
  10.  
  11. extern struct Library *IntuitionBase;
  12. extern struct Library *GadToolsBase;
  13. extern struct Library *CxBase;
  14. extern struct Library *IconBase;
  15.  
  16. extern struct TextAttr DefaultFont;
  17. extern char *windowTitle;
  18.  
  19. void
  20. OpenFFWindow( struct controlPanel *cp )
  21. {
  22.   struct Screen   *defScreen;
  23.   WORD           left,
  24.            top;
  25.  
  26.  
  27.  
  28.   if( cp->ffWindow )
  29.   {
  30.     WindowToFront( cp->ffWindow );
  31.     ActivateWindow( cp->ffWindow );
  32.     return;
  33.   }
  34.  
  35.   if( !( defScreen = (struct Screen *)LockPubScreen( NULL )))
  36.     Shutdown( cp, 20 );
  37.  
  38.   if( !(cp->ffWinVi = GetVisualInfo( defScreen, TAG_DONE )))
  39.     Shutdown( cp, 20 );
  40.  
  41.   CreateFFGadgets( cp, ( defScreen->WBorTop + defScreen->Font->ta_YSize+1 ),
  42.            defScreen->WBorLeft );
  43.  
  44.   if( (cp->centerWindow) || cp->lastX == -1 || cp->lastY == -1 )
  45.     CenterWindow( defScreen, &left, &top );
  46.   else
  47.   {
  48.     left = cp->lastX;
  49.     top  = cp->lastY;
  50.   }
  51.  
  52.   cp->ffWindow = OpenWindowTags( NULL,  WA_Left ,    left,
  53.                     WA_Top,      top,
  54.                     WA_InnerWidth,      FF_WIDTH,
  55.                     WA_InnerHeight,   FF_HEIGHT,
  56.                     WA_Activate, TRUE,
  57.                     WA_Flags,    WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  58.                              WFLG_CLOSEGADGET |
  59.                              WFLG_SMART_REFRESH,
  60.                     WA_IDCMP,    STRINGIDCMP|CYCLEIDCMP|
  61.                              BUTTONIDCMP|LISTVIEWIDCMP|
  62.                              IDCMP_CLOSEWINDOW|
  63.                              IDCMP_VANILLAKEY|
  64.                              IDCMP_REFRESHWINDOW|
  65.                              IDCMP_DISKINSERTED|
  66.                              IDCMP_DISKREMOVED,
  67.                     WA_PubScreen, defScreen,
  68.                     WA_Title,    windowTitle,
  69.                     WA_Gadgets,  cp->ffWinGadList,
  70.                     TAG_DONE );
  71.  
  72.   GT_RefreshWindow( cp->ffWindow, NULL );
  73.  
  74.   GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
  75.              cp->ffWindow, NULL,
  76.              GTLV_Labels,  (&cp->foundList),
  77.              GTLV_Selected, ~0L,
  78.              TAG_DONE );
  79.  
  80.   UnlockPubScreen( NULL , defScreen );
  81.  
  82. }
  83.  
  84. void
  85. CloseFFWindow( struct controlPanel *cp )
  86. {
  87.   int count;
  88.  
  89.   cp->lastX = cp->ffWindow->LeftEdge;
  90.   cp->lastY = cp->ffWindow->TopEdge;
  91.  
  92.   CloseWindow( cp->ffWindow );
  93.   cp->ffWindow = NULL;
  94.  
  95.   FreeVisualInfo( cp->ffWinVi );
  96.   cp->ffWinVi = NULL;
  97.  
  98.   FreeGadgets( cp->ffWinGadList );
  99.   cp->ffWinGadList = NULL;
  100.  
  101.   for( count = 0; count < ID_NUMGADS; count++ )
  102.     cp->ffWinGads[ count ] = NULL;
  103.  
  104. }
  105.  
  106. void
  107. HandleFFWindowCommand( struct controlPanel *cp )
  108. {
  109.   struct IntuiMessage *msg;
  110.  
  111.   while( msg = GT_GetIMsg( cp->ffWindow->UserPort ) )
  112.   {
  113.     struct Gadget    *gad;
  114.     ULONG         class;
  115.     UWORD         code,
  116.              qualifier;
  117.  
  118.     gad   = (struct Gadget *)msg->IAddress;
  119.     class = msg->Class;
  120.     code  = msg->Code;
  121.     qualifier = msg->Qualifier;
  122.  
  123.     GT_ReplyIMsg( msg );
  124.  
  125.     switch( class )
  126.     {
  127.       case IDCMP_CLOSEWINDOW : CMD_Hide( cp );
  128.                    break;
  129.  
  130.       case IDCMP_VANILLAKEY : switch( code )
  131.                   {
  132.                 case '?' : DoFileReq( cp );
  133.                        GT_SetGadgetAttrs(cp->ffWinGads[ID_DEVGAD],
  134.                                   cp->ffWindow, NULL,
  135.                                   GTST_String, cp->searchPath,
  136.                                   TAG_END );
  137.                        break;
  138.                 case 'p' :
  139.                 case 'P' : ActivateGadget(cp->ffWinGads[ID_PATGAD],
  140.                               cp->ffWindow, NULL );
  141.                        break;
  142.  
  143.                 case 'D' :
  144.                 case 'd' : ActivateGadget(cp->ffWinGads[ID_DEVGAD],
  145.                               cp->ffWindow, NULL );
  146.                        break;
  147.  
  148.                 case 'F' : if( cp->currFound != ~0 )
  149.                          cp->currFound = cp->currFound == 0 ?
  150.                                  0 :
  151.                                  (--(cp->currFound)) % cp->numFound;
  152.  
  153.                          GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
  154.                                   cp->ffWindow, NULL,
  155.                                   GTLV_Selected, cp->currFound,
  156.                                   GTLV_Top,    cp->currFound,
  157.                                   TAG_END );
  158.                        break;
  159.                 case 'f' : if( cp->currFound == ~0 )
  160.                          cp->currFound = 0;
  161.                        else
  162.                          cp->currFound = cp->currFound == (cp->numFound-1) ?
  163.                                  cp->currFound :
  164.                                  (++cp->currFound) % cp->numFound;
  165.  
  166.                          GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
  167.                                   cp->ffWindow, NULL,
  168.                                   GTLV_Selected, cp->currFound,
  169.                                   GTLV_Top,    cp->currFound,
  170.                                   TAG_END );
  171.                        break;
  172.                 case 'h' :
  173.                 case 'H' : CMD_Hide( cp );
  174.                        break;
  175.  
  176.                 case 's' :
  177.                 case 'S' : CMD_Search( cp );
  178.                        break;
  179.  
  180.                 case 'q' :
  181.                 case 'Q' : CMD_Quit( cp );
  182.                        break;
  183.  
  184.                   }
  185.                   break;
  186.  
  187.       case IDCMP_REFRESHWINDOW : GT_BeginRefresh(cp->ffWindow);
  188.                  GT_EndRefresh(cp->ffWindow,TRUE);
  189.                  break;
  190.  
  191.       case IDCMP_GADGETUP : switch( gad->GadgetID )
  192.                 {
  193.                   case ID_PATGAD :    strncpy( cp->searchString ,
  194.                              ((struct StringInfo *)
  195.                              cp->ffWinGads[ID_PATGAD]
  196.                              ->SpecialInfo)->Buffer ,
  197.                              MAXSTR );
  198.                         break;
  199.  
  200.                   case ID_DEVGAD :    strncpy( cp->searchPath,
  201.                              ((struct StringInfo *)
  202.                              cp->ffWinGads[ID_DEVGAD]
  203.                              ->SpecialInfo)->Buffer,
  204.                              MAXSTR );
  205.                         break;
  206.  
  207.                   case ID_FILEREQ: DBf("File Request on %s\n",cp->searchPath )
  208.                            DoFileReq( cp );
  209.                            GT_SetGadgetAttrs(cp->ffWinGads[ID_DEVGAD],
  210.                                 cp->ffWindow, NULL,
  211.                                 GTST_String, cp->searchPath,
  212.                                 TAG_END );
  213.                            DBf("File request returned %s\n",cp->searchPath )
  214.                            break;
  215.  
  216.                   case ID_SEARCH :    CMD_Search( cp );
  217.                         break;
  218.  
  219.                   case ID_HIDE : CMD_Hide( cp );
  220.                          break;
  221.  
  222.                   case ID_QUIT : CMD_Quit( cp );
  223.                           break;
  224.  
  225.                 }
  226.                 break;
  227.     }
  228.     if( ! cp->ffWindow )
  229.       break;
  230.   }
  231. }
  232.  
  233. void
  234. CreateFFGadgets( struct controlPanel *cp, int topEdge , BYTE leftEdge)
  235. {
  236.   struct Gadget    *gadget;
  237.   struct NewGadget  ng;
  238.  
  239.  
  240.  
  241.   cp->ffWinGadList = NULL;
  242.  
  243.   if( ! ( gadget = CreateContext( &(cp->ffWinGadList) ) ) )
  244.     Shutdown( cp , 20 );
  245.  
  246.   ng.ng_Width =       312;
  247.   ng.ng_Height =      16;
  248.   ng.ng_GadgetText =  "Search _Pattern :";
  249.   ng.ng_TextAttr =    &DefaultFont;
  250.   ng.ng_VisualInfo =  cp->ffWinVi;
  251.   ng.ng_GadgetID  =   ID_PATGAD;
  252.   ng.ng_Flags =       0;
  253.   ng.ng_LeftEdge =    ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
  254.   ng.ng_TopEdge =     5 + topEdge;
  255.  
  256.   cp->ffWinGads[ID_PATGAD] = gadget = CreateGadget( STRING_KIND, gadget, &ng,
  257.                               GT_Underscore, '_',
  258.                               GTST_MaxChars, MAXSTR,
  259.                               GTST_String,   cp->searchString,
  260.                               TAG_DONE );
  261.  
  262.   ng.ng_GadgetID =    ID_DEVGAD;
  263.   ng.ng_GadgetText =  "_Device to Search :";
  264.   ng.ng_TopEdge +=    ng.ng_Height + INTERHEIGHT;
  265.   ng.ng_LeftEdge =    ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
  266.   ng.ng_Width =       275;
  267.   ng.ng_Height =      18;
  268.  
  269.  
  270.   cp->ffWinGads[ID_DEVGAD] = gadget = CreateGadget( STRING_KIND, gadget, &ng,
  271.                               GT_Underscore, '_',
  272.                               GTST_MaxChars, MAXSTR,
  273.                               GTST_String,  cp->searchPath,
  274.                               TAG_DONE );
  275.  
  276.  
  277.   ng.ng_GadgetID =    ID_FILEREQ;
  278.   ng.ng_GadgetText =  "_?";
  279.   ng.ng_LeftEdge =    ng.ng_LeftEdge + ng.ng_Width;
  280.   ng.ng_Width     =    20;
  281.  
  282.  
  283.   cp->ffWinGads[ID_FILEREQ] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
  284.                                GT_Underscore, '_',
  285.                                TAG_DONE );
  286.  
  287.   ng.ng_GadgetID =    ID_FOUNDLIST;
  288.   ng.ng_GadgetText =   "_Files Found :";
  289.   ng.ng_TopEdge +=    ng.ng_Height + 16;
  290.   ng.ng_LeftEdge =    leftEdge + 5;
  291.   ng.ng_Width =       448;
  292.   ng.ng_Height =      76;
  293.  
  294.   cp->ffWinGads[ID_FOUNDLIST] = gadget = CreateGadget( LISTVIEW_KIND, gadget, &ng,
  295.                               GTLV_ShowSelected, NULL,
  296.                               GT_Underscore, '_',
  297.                               TAG_DONE );
  298.  
  299.   ng.ng_GadgetID =    ID_SEARCH;
  300.   ng.ng_GadgetText =  "_Search";
  301.   ng.ng_LeftEdge =    leftEdge + 5L;
  302.   ng.ng_TopEdge +=    ng.ng_Height + 4;
  303.   ng.ng_Width =       106;
  304.   ng.ng_Height =      20;
  305.  
  306.   cp->ffWinGads[ID_SEARCH] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
  307.                               GT_Underscore, '_',
  308.                               TAG_DONE );
  309.   ng.ng_GadgetID =    ID_ABORT;
  310.   ng.ng_GadgetText =  "_Abort";
  311.   ng.ng_LeftEdge +=   ng.ng_Width + INTERWIDTH;
  312.  
  313.   cp->ffWinGads[ID_ABORT] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
  314.                             GT_Underscore, '_',
  315.                             GA_Disabled,   TRUE,
  316.                             TAG_DONE );
  317.   ng.ng_GadgetID =    ID_HIDE;
  318.   ng.ng_GadgetText =  "_Hide";
  319.   ng.ng_LeftEdge +=   ng.ng_Width + INTERWIDTH;
  320.  
  321.   cp->ffWinGads[ID_HIDE] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
  322.                             GT_Underscore, '_',
  323.                             TAG_DONE );
  324.  
  325.   ng.ng_GadgetID =    ID_QUIT;
  326.   ng.ng_GadgetText =  "_Quit";
  327.   ng.ng_LeftEdge +=   ng.ng_Width + INTERWIDTH;
  328.  
  329.   cp->ffWinGads[ID_QUIT] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
  330.                             GT_Underscore, '_',
  331.                             TAG_DONE );
  332.  
  333. }
  334.  
  335. void
  336. CenterWindow( struct Screen *sc, WORD *leftEdge, WORD *topEdge )
  337. {
  338.  (*leftEdge)   = sc->MouseX - (FF_WIDTH >> 1);
  339.   (*topEdge)    = sc->MouseY - (FF_HEIGHT >> 1);
  340.  
  341.   while((*leftEdge) + FF_WIDTH > sc->Width)
  342.     (*leftEdge)--;
  343.  
  344.   while((*leftEdge) < 0)
  345.     (*leftEdge)++;
  346.  
  347.   while((*topEdge) + FF_HEIGHT > sc->Height)
  348.     (*topEdge)--;
  349.  
  350.   while((*topEdge) < 0)
  351.     (*topEdge)++;
  352. }
  353.