home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / source.lha / src / RSysIntuiCtrl.c < prev    next >
C/C++ Source or Header  |  1995-01-09  |  11KB  |  503 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *    RSysIntuiCtrl.c
  6. *
  7. * Inhalt:
  8. *    void *LockWindow(struct Window *win);
  9. *    void UnlockWindow(void *req);
  10. *    void EnableGadget(struct Window *Wnd, struct Gadget *gad, int on_off);
  11. *    void makelabelvisible(struct Gadget *gad);
  12. *    char *gadgetbuff(struct Gadget *gad);
  13. *    void DisableSysRequest(int disable);
  14. *    void MakeWindowRefresh(struct Window *window);
  15. *    void RefreshMainWindowPattern(void);
  16. *    void InitListView(struct Window *wind, struct Gadget *gad, struct List *list, int top);
  17. *    void RefreshListView(void);
  18. *    void EmptyListView(void);
  19. *    void ClearIntuiMsgPort(struct Window *wnd);
  20. *    void PrintHeader(enum ListTypes type, char *text);
  21. *    void PrintInfo(char *text, int speakit, int waitit);
  22. *    void PrintStatistics(void);
  23. *    short MyEasyRequest(struct Window *wind, unsigned char *title, unsigned char *Gadgets, unsigned char *Body, ...);
  24. *    void OpenMainWindow(void);
  25. *    void CloseASysWindow(struct Window **wind, struct Gadget **windgadlist, struct Menu **windmenus);
  26. *    int OpenASysWindow(int (*func)(), int kill);
  27. *    void CenterWindow(struct Screen *scr, unsigned short *top, unsigned short *left, unsigned short width, unsigned short height);
  28. *
  29. * Bemerkungen:
  30. *    Intuition Supportroutinen für die Verwaltung der Intuitionobjekte
  31. *    des Hauptwindows von RSys.
  32. *    (Aus RSysUtils.c ausgelagert)
  33. *
  34. * Erstellungsdatum:
  35. *    25-Jun-93    Rolf Böhme
  36. *
  37. * Änderungen:
  38. *    25-Jun-93    Rolf Böhme    Erstellung
  39. *    25-Jun-93    Rolf Böhme    makelabelvisible() hinzugefügt
  40. *
  41. ***************************************************************************
  42. */
  43.  
  44. #include "RSysDebug.h"
  45. #include "RSysFunc.h"
  46.  
  47.    /*
  48.     * LockWindow() öffnet einen Requester der Größe 1x1 und sperrt
  49.     * das Window damit gegen Eingaben
  50.     */
  51. APTR
  52. LockWindow(struct Window * win)
  53. {
  54.    struct Requester *req;
  55.  
  56.    DPOS;
  57.  
  58.    req = (struct Requester *) MyAllocVec(sizeof(struct Requester),
  59.                                          MEMF_ANY | MEMF_CLEAR, NO_KILL);
  60.  
  61.    if (req)
  62.    {
  63.       req->LeftEdge = 1;
  64.       req->TopEdge = 1;
  65.       req->Width = 1;
  66.       req->Height = 1;
  67.       req->Flags = SIMPLEREQ | NOREQBACKFILL;
  68.  
  69.       Request(req, win);
  70.    }
  71.  
  72.    return ((APTR) req);
  73. }
  74.  
  75.    /*
  76.     * UnlockWindow() gibt ein mit LockWindow() gesperrtes Window
  77.     * wieder frei. Es ist dann wieder für Benutzereingaben
  78.     * zugänglich
  79.     */
  80. void
  81. UnlockWindow(APTR req)
  82. {
  83.    DPOS;
  84.  
  85.    if (req)
  86.    {
  87.       EndRequest((struct Requester *) req, ((struct Requester *) req)->RWindow);
  88.       MyFreeVec(req);
  89.    }
  90.  
  91.    return;
  92. }
  93.  
  94.    /*
  95.     * EnableGadget() schaltet ein Gadget auf einem Window ein oder
  96.     * aus
  97.     */
  98. void
  99. EnableGadget(struct Window *Wnd, struct Gadget *gad, int on_off)
  100. {
  101.    DPOS;
  102.  
  103.    GT_SetGadgetAttrs(gad, Wnd,
  104.                      NULL,
  105.                      GA_Disabled, NOT(on_off),
  106.                      TAG_DONE);
  107.  
  108.    return;
  109. }
  110.  
  111. void
  112. makelabelvisible(struct Gadget *gad)
  113. {
  114.    extern int bgc, bpc;
  115.  
  116.    if(gad->GadgetText)
  117.    {
  118.       gad->GadgetText->DrawMode |= JAM2;
  119.       /*
  120.       gad->GadgetText->BackPen   = bgc ? bgc : 0;
  121.       gad->GadgetText->FrontPen  = bpc ? bpc : 1;
  122.       */
  123.       gad->GadgetText->BackPen   = 0;
  124.       gad->GadgetText->FrontPen  = 1;
  125.    }
  126.  
  127.    return;
  128. }
  129.  
  130.    /*
  131.     * gadgetbuff() ermittelt den String, der in einem Stringgadget
  132.     * steht
  133.     */
  134. char *
  135. gadgetbuff(struct Gadget *gad)
  136. {
  137.    DPOS;
  138.  
  139.    return ((char *)(((struct StringInfo *) (gad->SpecialInfo))->Buffer));
  140. }
  141.  
  142.  
  143.    /*
  144.     * DisableSysRequest() unterdrückt die Anzeige von
  145.     * Systemrequestern, die beispielsweise nach einem Zugriff auf
  146.     * einen nicht existierenden Datenträger erscheinen
  147.     */
  148. void
  149. DisableSysRequest(int disable)
  150. {
  151.    static APTR wind;
  152.    struct Process *p = (struct Process *) FindTask(NULL);
  153.  
  154.    DPOS;
  155.  
  156.    if (disable)
  157.    {
  158.       wind = (APTR) p->pr_WindowPtr;
  159.       p->pr_WindowPtr = (APTR) (-1);
  160.    }
  161.    else
  162.       p->pr_WindowPtr = wind;
  163.  
  164.    return;
  165. }
  166.  
  167.    /*
  168.     * MakeWindowRefresh() führt die Standard-System-Routinen zur
  169.     * Erneuerung eines Windows aus
  170.     */
  171. void
  172. MakeWindowRefresh(struct Window *window)
  173. {
  174.    GT_BeginRefresh(window);
  175.    GT_EndRefresh(window, TRUE);
  176.    return;
  177. }
  178.  
  179.    /*
  180.     * RefreshMainWindowPattern() erneuert das Patternmuster
  181.     * des Hauptfensters von RSys
  182.     */
  183. void
  184. RefreshMainWindowPattern(void)
  185. {
  186.    int gl[] = {GD_ListeLV, GD_TextHeader, GD_InfoMsgGad};
  187.  
  188.    RefreshRastPort(SysWnd, SysGadgets, gl, 3);
  189.  
  190.    return;
  191. }
  192.  
  193.  
  194.    /*
  195.     * InitListView() initialisiert ein ListView in einem Fenster
  196.     * mit einer anzugebenden Liste. Ist die Liste NULL, wird das
  197.     * ListView systemgemäß mit ~0 initialisiert
  198.     */
  199. void
  200. InitListView(struct Window *wind, struct Gadget *gad, struct List *list, int top)
  201. {
  202.    struct List *lvlist = (list != NULL) ? list : (struct List *)(~0);
  203.  
  204.    DPOS;
  205.  
  206.    if(list != NULL)
  207.       GT_SetGadgetAttrs(gad, wind,NULL,GTLV_Labels, (~0), TAG_DONE);
  208.  
  209.    if(top == UNSETLVPOS)
  210.       GT_SetGadgetAttrs(gad, wind,
  211.                         NULL,
  212.                         GTLV_Labels, lvlist,
  213.                         TAG_DONE);
  214.    else
  215.       GT_SetGadgetAttrs(gad, wind,
  216.                         NULL,
  217.                         GTLV_Labels, lvlist,
  218.                         GTLV_Top, top,
  219.                         GTLV_Selected, (~0),
  220.                         TAG_DONE);
  221. }
  222.  
  223.    /*
  224.     * RefreshListView() erneuert das ListView auf dem Hauptwindow
  225.     */
  226. void
  227. RefreshListView(void)
  228. {
  229.    DPOS;
  230.  
  231.    InitListView(SysWnd,SysGadgets[GD_ListeLV],&ListeLVList,UNSETLVPOS);
  232.    return;
  233. }
  234.  
  235.    /*
  236.     * EmptyListView() löscht die Einträge des Haupt-ListViews
  237.     */
  238. void
  239. EmptyListView(void)
  240. {
  241.    DPOS;
  242.  
  243.    InitListView(SysWnd,SysGadgets[GD_ListeLV],NULL,0);
  244.  
  245.    NewList(&ListeLVList);
  246.  
  247.    RefreshListView();
  248.  
  249.    GT_RefreshWindow(SysWnd, NULL);
  250.  
  251.    return;
  252. }
  253.  
  254.    /*
  255.     * ClearIntuiMsgPort() beantwortet alle anliegenden Messages
  256.     * eines Windows
  257.     */
  258. void
  259. ClearIntuiMsgPort(struct Window *wnd)
  260. {
  261.    struct IntuiMessage *message;
  262.  
  263.    DPOS;
  264.  
  265.    while (message = (struct IntuiMessage *) GT_GetIMsg(wnd->UserPort))
  266.       GT_ReplyIMsg(message);
  267.  
  268.    return;
  269. }
  270.  
  271.    /*
  272.     * PrintHeader() gibt einen Text im Titelfeld über dem
  273.     * Haupt-ListView aus
  274.     */
  275. void
  276. PrintHeader(enum ListTypes type, char *text)
  277. {
  278.    DPOS;
  279.  
  280.    LastID = type;
  281.  
  282.    GT_SetGadgetAttrs(SysGadgets[GD_TextHeader], SysWnd,
  283.                      NULL,
  284.                      GTTX_Text, (UBYTE *) ((text == NULL) ?
  285.                                     EntryAttr[type].ea_header :
  286.                                     text),
  287.                      TAG_DONE);
  288.  
  289.    return;
  290. }
  291.  
  292.    /*
  293.     * PrintInfo() gibt einen Text im Messagefeld vom Hauptfenster
  294.     * aus. Falls der Sprachmodus aktiviert ist und der Text
  295.     * gesprochen werden soll, wird er zusätzlich auf dem
  296.     * Narrator-Device ausgegeben
  297.     */
  298. void
  299. PrintInfo(char *text, int speakit,int waitit)
  300. {
  301.    static char help[BUFSIZE];
  302.    int   i,
  303.          len = strlen(text),
  304.          fill = ((BUFSIZE - len) >> 1);
  305.  
  306.    DPOS;
  307.  
  308.    for (i = 0; i < fill; i++)
  309.       help[i] = ' ';
  310.  
  311.    help[fill] = STRINGEND;
  312.  
  313.    strcat(help, text);
  314.  
  315.    if (SysWnd)
  316.    {
  317.       GT_SetGadgetAttrs(SysGadgets[GD_InfoMsgGad], SysWnd,
  318.                         NULL,
  319.                         GTTX_Text, (UBYTE *) help,
  320.                         TAG_DONE);
  321.  
  322.       if (NOT(Flags.fastmode))
  323.          WaitTOF();
  324.    }
  325.  
  326.    if (Flags.speakmode && speakit)
  327.       Speak(help);
  328.  
  329.    if(waitit != 0)
  330.       Delay(waitit);
  331.  
  332.    return;
  333. }
  334.  
  335.    /*
  336.     * PrintStatistics() gibt für bestimmte Listen eine
  337.     * Zusammenfasung (Anzahl der ermittelten Einträge) aus
  338.     */
  339. void
  340. PrintStatistics(void)
  341. {
  342.    char  help[BUFSIZE];
  343.  
  344.    DPOS;
  345.  
  346.    if(countentries == 0)
  347.       sprintf(help, "No %s entries read", EntryAttr[LastID].ea_type);
  348.    else
  349.       if (EntryAttr[LastID].ea_counted)
  350.          sprintf(help, "%ld %s entries read", countentries,
  351.                  EntryAttr[LastID].ea_type);
  352.       else
  353.          sprintf(help, "%s entries read", EntryAttr[LastID].ea_type);
  354.  
  355.    PrintInfo(help, SPEAK, 0);
  356.  
  357.    if (SysWnd)
  358.       RefreshListView();
  359.  
  360.    return;
  361. }
  362.  
  363.    /*
  364.     * MyEasyRequest() erzeugt nach Vorgaben einen
  365.     * System-Standard-Requester
  366.     */
  367. WORD
  368. MyEasyRequest(struct Window * wind, UBYTE * title,
  369.               UBYTE * Gadgets, UBYTE * Body,...)
  370. {
  371.    struct EasyStruct Easy;
  372.    WORD  Result;
  373.    va_list VarArgs;
  374.    APTR  req;
  375.  
  376.    DPOS;
  377.  
  378.    Easy.es_StructSize = sizeof(struct EasyStruct);
  379.  
  380.    Easy.es_Flags = NULL;
  381.    Easy.es_Title = title;
  382.    Easy.es_TextFormat = Body;
  383.    Easy.es_GadgetFormat = Gadgets;
  384.  
  385.    if (wind)
  386.       req = LockWindow(wind);
  387.  
  388.    va_start(VarArgs, Body);
  389.    Result = EasyRequestArgs(wind, &Easy, NULL, VarArgs);
  390.    va_end(VarArgs);
  391.  
  392.    if (wind)
  393.       UnlockWindow(req);
  394.  
  395.    return (Result);
  396. }
  397.  
  398.    /*
  399.     * OpenMainWindow() öffnet das Hauptffenster
  400.     */
  401. void
  402. OpenMainWindow(void)
  403. {
  404.    DPOS;
  405.  
  406.    if (!SetupScreen())
  407.       OpenASysWindow(OpenSysWindow, KILL);
  408.    else
  409.       ErrorHandle(SCREEN_ERR, INFO_FAIL, KILL);
  410.  
  411.    return;
  412. }
  413.  
  414.    /*
  415.     * CloseASysWindow() schließt ein von RSys verwaltetes Window
  416.     */
  417. void
  418. CloseASysWindow(struct Window **wind,
  419.                 struct Gadget **windgadlist,
  420.                 struct Menu **windmenus)
  421. {
  422.    DPOS;
  423.  
  424.    if (windmenus && *windmenus)
  425.    {
  426.       ClearMenuStrip(*wind);
  427.       FreeMenus(*windmenus);
  428.       *windmenus = NULL;
  429.    }
  430.  
  431.    if (wind && *wind)
  432.    {
  433.       CloseWindow(*wind);
  434.       *wind = NULL;
  435.    }
  436.  
  437.    if (windgadlist && *windgadlist)
  438.    {
  439.       FreeGadgets(*windgadlist);
  440.       *windgadlist = NULL;
  441.    }
  442.  
  443.    return;
  444. }
  445.  
  446.    /*
  447.     * OpenASysWindow() öffnet Window mit einer
  448.     * vorzugebenden Funktion und mit einer allgemeinen
  449.     * Fehlerbehandlung
  450.     */
  451. int
  452. OpenASysWindow(int (*func) (void), int kill)
  453. {
  454.    ULONG failed = (*func) ();
  455.  
  456.    DPOS;
  457.  
  458.    switch (failed)
  459.    {
  460.       case 1L:
  461.       case 2L:
  462.       case 3L:
  463.          ErrorHandle(GADGET_MENU_ERR, CREATE_FAIL, kill);
  464.          break;
  465.  
  466.       case 4L:
  467.          ErrorHandle(WINDOW_ERR, OPEN_FAIL, kill);
  468.          break;
  469.    }
  470.  
  471.    return (failed ? FALSE : TRUE);
  472. }
  473.  
  474.    /*
  475.     * CenterWindow() ermittelt die Fensterposition, um das
  476.     * Fenster zentriert auf einem Screen erscheinen zu lassen
  477.     */
  478. void
  479. CenterWindow(struct Screen *scr, UWORD * top, UWORD * left,
  480.              UWORD width, UWORD height)
  481. {
  482.    WORD  LE,
  483.          TE;
  484.  
  485.    DPOS;
  486.  
  487.    if (scr)
  488.    {
  489.       WORD restwidth  = scr->Width  - width,
  490.            restheight = scr->Height - height;
  491.  
  492.       LE = (Flags.mousewindow ? scr->MouseX : (scr->Width  >> 1)) -
  493.            (width  >> 1);
  494.       TE = (Flags.mousewindow ? scr->MouseY : (scr->Height >> 1)) -
  495.            (height >> 1);
  496.  
  497.       *left = (LE < 0) ? (UWORD)0 : ((LE > restwidth ) ? restwidth  : LE);
  498.       *top  = (TE < 0) ? (UWORD)0 : ((TE > restheight) ? restheight : TE);
  499.    }
  500.  
  501.    return;
  502. }
  503.