home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / show / amiga / searchwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  10.0 KB  |  396 lines

  1. #include "defines.h"
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.  
  7. #include <exec/types.h>
  8. #include <exec/lists.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/screens.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <libraries/gadtools.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/gadtools_protos.h>
  18.  
  19. #include <pragmas/intuition_pragmas.h>
  20. #include <pragmas/dos_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22. #include <pragmas/gadtools_pragmas.h>
  23.  
  24.  
  25. #ifdef AZTEC_C
  26. #  include <functions.h>
  27. #endif
  28.  
  29.  
  30. #include "globals.h"
  31. #include "amscreen.h"
  32. #include "searchwin.h"
  33.  
  34. #include "amscreen.i"
  35. #include "am_requ.i"
  36. #include "searchwin.i"
  37. #include "globals.i"
  38. #include "help.i"
  39. #include "search.i"
  40.  
  41.  
  42. /*
  43.  * Fuer die locale-Library:
  44.  *
  45.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  46.  * Achtung:
  47.  * Es muss/sollte 'multiple-include' erlaubt sein!
  48.  */
  49. #include "local.i"
  50.  
  51. #undef  CATCOMP_ARRAY
  52. #undef  CATCOMP_BLOCK
  53. #undef  CATCOMP_STRINGS
  54. #define CATCOMP_NUMBERS
  55. #include "localstr.h"
  56.  
  57.  
  58.  
  59. /*******************************************************************************/
  60. /*                 S E A R C H W I N D O W                   */
  61. /*******************************************************************************/
  62.  
  63. /* externals... */
  64. extern UBYTE         sig_searchwin;
  65. extern struct Screen    *screen;
  66. extern struct Window    *win2;
  67. extern struct TextAttr     txtAttr;
  68. extern short         HeightWintitle;
  69.  
  70.  
  71. static long ActionScreenPref(enum SearchActions action, int * cont, char * searchbuf, int len);
  72.  
  73.  
  74. #define GADID_SEARCH_STRING    1
  75. #define GADID_SEARCH_SEARCH    2
  76. #define GADID_SEARCH_CANCEL    3
  77.  
  78.  
  79.  
  80. /* globals (help.c) */
  81. struct Window    *SearchWin = NULL;    /* = NULL wichtig, damit wird gearbeitet! */
  82.  
  83.  
  84. /* locals... */
  85. static struct Gadget    *GList = NULL;
  86.  
  87.  
  88. static struct Gadget *Gad_string;
  89. static struct Gadget *Gad_ok;
  90. static struct Gadget *Gad_cancel;
  91.  
  92. static int IsSearchActive = FALSE;
  93.  
  94.  
  95. #define SEARCHWIN_WIDTH        200
  96. #define SEARCHWIN_HEIGHT    110
  97.  
  98.  
  99. /* functions... */
  100.  
  101. void OpenSearchWin(void)
  102. {
  103.   struct NewWindow new_win;
  104.   WORD LeftEdge, TopEdge, Width, Height;
  105.   struct NewGadget ng;
  106.   struct Gadget * gad;
  107.   int l, h;
  108.   int l1, l2;
  109.  
  110.   if (SearchWin) {        // kann schon mal vorkommen, mach aber nix!
  111.     ActivateWindow(SearchWin);
  112.     return;
  113.   }
  114.  
  115.  
  116.   if (GadToolsBase == NULL || GadToolsBase->lib_Version < 37L) {
  117.     MySimpleRequest(1, NULL, NULL, NULL, NULL, GetTeXString(MSG_PREFWIN_GADTOOLS));
  118.     return;
  119.   }
  120.   
  121.   
  122.   IsSearchActive = FALSE;
  123.   
  124.  
  125.   Width  = SEARCHWIN_WIDTH;
  126.   Height = SEARCHWIN_HEIGHT+win2->BorderTop;
  127.  
  128.   h = screen->Font->ta_YSize;
  129.   
  130.   Height = (h+4)*3+2*h+2 + win2->BorderTop;
  131.  
  132.   l1 = TextLength(&(screen->RastPort), GetTeXString(MSG_SEARCHWIN_SEARCH), strlen(GetTeXString(MSG_SEARCHWIN_SEARCH)));
  133.   l2 = TextLength(&(screen->RastPort), GetTeXString(MSG_SEARCHWIN_CANCEL), strlen(GetTeXString(MSG_SEARCHWIN_CANCEL)));
  134.   
  135.   l = (l1>l2 ? l1 : l2) + 4;
  136.  
  137.   if (2*l+l/2+40 > Width) Width = 2*l+l/2+40;
  138.  
  139.   CenterWindow(&LeftEdge, &TopEdge, Width, Height);
  140.  
  141.  
  142.   GList = NULL;
  143.   if ((gad = CreateContext(&GList)) == NULL) return;
  144.  
  145.   ng.ng_GadgetText = GetTeXString(MSG_SEARCHWIN_STRING);  // l = TextLength(&(screen->RastPort), ng.ng_GadgetText, strlen(ng.ng_GadgetText));
  146.   ng.ng_LeftEdge   = 20;
  147.   ng.ng_TopEdge    = h+4+h/2 + win2->BorderTop;
  148.   ng.ng_Width      = Width - 40;
  149.   ng.ng_Height     = h + 4;
  150.   ng.ng_TextAttr   = screen->Font;
  151.   ng.ng_GadgetID   = GADID_SEARCH_STRING;
  152.   ng.ng_Flags      = PLACETEXT_ABOVE;
  153.   ng.ng_VisualInfo = SDVI_VI;
  154.   ng.ng_UserData   = (void *)SEARCHWIN_ACTION_STRING;
  155.   
  156.   Gad_string = gad = CreateGadget(STRING_KIND, gad, &ng, GT_Underscore, '_', 
  157.                              GTST_String, SearchPattern, 
  158.                              GTST_MaxChars, sizeof(SearchPattern)-1, 
  159.                               TAG_DONE);
  160.  
  161.  
  162.   ng.ng_GadgetText = GetTeXString(MSG_SEARCHWIN_SEARCH);  
  163.   ng.ng_LeftEdge   = 20;
  164.   ng.ng_TopEdge    = Height - (h+4+2+h/2);
  165.   ng.ng_Width      = l;
  166.   ng.ng_Height     = h + 4;
  167.   ng.ng_TextAttr   = screen->Font;
  168.   ng.ng_GadgetID   = GADID_SEARCH_SEARCH;
  169.   ng.ng_Flags      = PLACETEXT_IN;
  170.   ng.ng_VisualInfo = SDVI_VI;
  171.   ng.ng_UserData   = (void *)SEARCHWIN_ACTION_SEARCH;
  172.   
  173.   Gad_ok = gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_', TAG_DONE);
  174.  
  175.   ng.ng_GadgetText = GetTeXString(MSG_SEARCHWIN_CANCEL);  
  176.   ng.ng_LeftEdge   = Width - 20 - l;
  177.   ng.ng_TopEdge    = Height - (h+4+2+h/2);
  178.   ng.ng_Width      = l;
  179.   ng.ng_Height     = h + 4;
  180.   ng.ng_TextAttr   = screen->Font;
  181.   ng.ng_GadgetID   = GADID_SEARCH_CANCEL;
  182.   ng.ng_Flags      = PLACETEXT_IN;
  183.   ng.ng_VisualInfo = SDVI_VI;
  184.   ng.ng_UserData   = (void *)SEARCHWIN_ACTION_CANCEL;
  185.   
  186.   Gad_cancel = gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_', TAG_DONE);
  187.  
  188.  
  189.   new_win.LeftEdge  = LeftEdge;
  190.   new_win.TopEdge   = TopEdge;
  191.   new_win.Width     = Width;
  192.   new_win.Height    = Height;
  193.   new_win.DetailPen = 0;
  194.   new_win.BlockPen  = 1; 
  195.   new_win.Title     = GetTeXString(MSG_SEARCHWIN_WIN_TITLE);
  196.   new_win.Flags     = WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_NOCAREREFRESH | WFLG_ACTIVATE | WFLG_RMBTRAP;
  197.   new_win.IDCMPFlags = IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | BUTTONIDCMP | STRINGIDCMP | IDCMP_ACTIVEWINDOW | ((is_amigaguide) ? IDCMP_GADGETHELP : 0);
  198.   new_win.Type      = CUSTOMSCREEN;
  199.   new_win.FirstGadget = GList;
  200.   new_win.CheckMark = NULL;
  201.   new_win.Screen    = screen;
  202.   new_win.BitMap    = NULL;
  203.   
  204.   if (is_amigaguide) {
  205.     SearchWin = (struct Window *)OpenWindowTags(&new_win, WA_HelpGroupWindow, win2, TAG_DONE);
  206.   }
  207.   else {
  208.     SearchWin = (struct Window *)OpenWindow(&new_win);
  209.   }
  210.  
  211.   if (SearchWin == NULL) {
  212.     MySimpleRequest(1, NULL, NULL, NULL, GetTeXString(MSG_SHOWDVI_MESSAGE), GetTeXString(MSG_SEARCHWIN_CANT_OPEN));
  213.     return;
  214.   }
  215.   
  216.   //DrawBevelBox(SearchWin->RPort, 20, Height - 30 - 10, Width - 40, 2, GT_VisualInfo, SDVI_VI, TAG_DONE);
  217.  
  218.  
  219.   sig_searchwin = SearchWin->UserPort->mp_SigBit;
  220. }
  221.  
  222.  
  223.  
  224. void CloseSearchWin(void)
  225. {
  226.   if (SearchWin != NULL) {
  227.     CloseWindow(SearchWin);
  228.     SearchWin = NULL;
  229.   }
  230.   if (GList != NULL) {
  231.     FreeGadgets(GList);
  232.     GList = NULL;
  233.   }
  234.  
  235.   IsSearchActive = FALSE;
  236. }
  237.  
  238.  
  239.  
  240.  
  241. enum SearchActions DoSearchWin(char * searchbuf, int len)
  242. {
  243.   enum SearchActions action;
  244.   struct IntuiMessage *msg;
  245.   ULONG msg_class;
  246.   UWORD    Code;
  247.   UWORD Qualifier;
  248.   struct Gadget *m_gad;
  249.   int cont = TRUE;
  250.  
  251.   enum SearchActions ex = SEARCHWIN_ACTION_NONE;
  252.   
  253.   if (SearchWin == NULL) return ex;
  254.  
  255.   
  256.   while(cont && ex == 0 && SearchWin != NULL && (msg = GT_GetIMsg(SearchWin->UserPort)) != NULL) {
  257.     msg_class    = msg->Class;
  258.     Code      = msg->Code;
  259.     Qualifier    = msg->Qualifier;
  260.     m_gad    = (struct Gadget *)(msg->IAddress);
  261.  
  262.     action = SEARCHWIN_ACTION_NONE;
  263.  
  264.     switch (msg_class) {
  265.       case IDCMP_GADGETHELP:
  266.         work_with_gadgethelp(msg);
  267.         break;
  268.  
  269.       case IDCMP_CLOSEWINDOW:
  270.         action = SEARCHWIN_ACTION_CLOSE;
  271.       cont = FALSE;
  272.       break;
  273.  
  274.       case IDCMP_ACTIVEWINDOW:
  275.         // tja, hier muesste das Gad_string Teil aktiviert werden!
  276.         if (!IsSearchActive) (void)ActivateGadget(Gad_string, SearchWin, NULL);
  277.     break;
  278.  
  279.       case IDCMP_RAWKEY:
  280.         if (Code == 95) HelpKeyAGuide(Qualifier & IEQUALIFIER_CONTROL);
  281.         break;
  282.  
  283.       case IDCMP_VANILLAKEY:
  284.         switch (toupper(Code)) {
  285.       case 13 :        /* RET */
  286.       case 'S':        /* use */
  287.         action = SEARCHWIN_ACTION_SEARCH;
  288.         break;
  289.       case 27 :        /* ESC */
  290.         action = SEARCHWIN_ACTION_CLOSE;
  291.         break;
  292.       case 'C':        /* cancel */
  293.         action = SEARCHWIN_ACTION_CANCEL;
  294.         break;
  295.       case 'G':
  296.         action = SEARCHWIN_ACTION_SEARCH;
  297.         break;
  298.       case 3  :        /* CTRL C */
  299.         CXBRK();
  300.         break;
  301.         }
  302.         break;
  303.       case IDCMP_GADGETUP: 
  304.         action = (short)m_gad->UserData;
  305.         break;
  306.     }
  307.  
  308.     GT_ReplyIMsg(msg);
  309.  
  310.     ex = ActionScreenPref(action, &cont, searchbuf, len);
  311.   }
  312.   
  313.   return ex;
  314. }
  315.  
  316.  
  317. static enum SearchActions ActionScreenPref(enum SearchActions action, int * cont, char * searchbuf, int len)
  318. {
  319.   enum SearchActions ret = action;
  320.  
  321.   switch (action) {
  322.  
  323.     case SEARCHWIN_ACTION_CLOSE:
  324.       CloseSearchWin();
  325.       *cont = FALSE;
  326.       break;
  327.  
  328.     case SEARCHWIN_ACTION_CANCEL:
  329.       if (IsSearchActive) {
  330.         ReEnableSearchWin();
  331.       }
  332.       else {
  333.         ret = SEARCHWIN_ACTION_CLOSE;
  334.         CloseSearchWin();
  335.       }
  336.       *cont = FALSE;
  337.       break;
  338.     
  339.     case SEARCHWIN_ACTION_STRING:
  340.       if (!*((struct StringInfo *)Gad_string->SpecialInfo)->Buffer) {
  341.         // Suche nach einem leeren String??
  342.         (void)ActivateGadget(Gad_string, SearchWin, NULL);
  343.       }
  344.       ret = SEARCHWIN_ACTION_NONE;
  345.       break;
  346.  
  347.     case SEARCHWIN_ACTION_SEARCH:
  348.       // Wenn IsSearchActive, dann kann nicht noch eine Suche gestartet werden!
  349.       if (IsSearchActive) {
  350.         action = SEARCHWIN_ACTION_NONE;
  351.       }
  352.       else {
  353.     if (searchbuf) {
  354.       if (*((struct StringInfo *)Gad_string->SpecialInfo)->Buffer) {
  355.         strncpy(searchbuf, ((struct StringInfo *)Gad_string->SpecialInfo)->Buffer, len);
  356.             IsSearchActive = TRUE;
  357.         
  358.             // nun muessen noch ein paar Gadgets inactiviert werden
  359.             GT_SetGadgetAttrs(Gad_string, SearchWin, NULL, GA_Disabled, TRUE, TAG_DONE);
  360.             GT_SetGadgetAttrs(Gad_ok, SearchWin, NULL, GA_Disabled, TRUE, TAG_DONE);
  361.             
  362.             SetWindowTitles(SearchWin, GetTeXString(MSG_SEARCHWIN_DOSEARCH), (UBYTE *)-1);
  363.           }
  364.           else {
  365.             // Suche nach einem leeren String??
  366.             (void)ActivateGadget(Gad_string, SearchWin, NULL);
  367.             ret = SEARCHWIN_ACTION_NONE;
  368.           }
  369.     }
  370.     else {
  371.           ret = SEARCHWIN_ACTION_NONE;
  372.     }
  373.       }
  374.       break;
  375.   }
  376.   
  377.   return ret;
  378. }
  379.  
  380.  
  381. // wenn eine Suche zuende war, abgebrochen wurde oder was auch immer, setze SuchWindow wieder aktiv
  382. void ReEnableSearchWin(void)
  383. {
  384.   IsSearchActive = FALSE;
  385.   if (SearchWin) {
  386.     GT_SetGadgetAttrs(Gad_string, SearchWin, NULL, GA_Disabled, FALSE, TAG_DONE);
  387.     GT_SetGadgetAttrs(Gad_ok, SearchWin, NULL, GA_Disabled, FALSE, TAG_DONE);
  388.     SetWindowTitles(SearchWin, GetTeXString(MSG_SEARCHWIN_WIN_TITLE), (UBYTE *)-1);
  389.   }
  390. }
  391.  
  392. char * GetCurSearchString(void)
  393. {
  394.   return (SearchWin) ? ((struct StringInfo *)Gad_string->SpecialInfo)->Buffer : NULL;
  395. }
  396.