home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / swlist.zip / SWLIST.C next >
C/C++ Source or Header  |  1998-06-22  |  11KB  |  303 lines

  1. /*
  2.  * Source file:
  3.  *
  4.  *        swlist.c  - switch-list functions
  5.  *
  6.  * Description:
  7.  *
  8.  *        Implementation of "swlist control" and "swlist info"
  9.  *
  10.  * Contents:
  11.  *
  12.  *   Public:
  13.  *
  14.  *        SwListQueryScrid     Get screen-session id for (sub)title
  15.  *        SwListQueryHandle    Get switchlist-handle for (sub)title in the
  16.  *                             specified screen-session
  17.  *        SwListActivate       Make session in switch-list active (focus)
  18.  *        SwListRemove         Remove indicated task from windowlist
  19.  *        SwListVisibility     Hide/show session in switch-list and desktop
  20.  *
  21.  * Remarks:
  22.  *
  23.  * Author:         J. van Wijk
  24.  *
  25.  * Date     By     Comment
  26.  * ======== ====== ============================================================
  27.  * 07-04-93 JvW    Initial version
  28.  * 22-06-98 JvW    Sample version, for demonstration purposes
  29.  *
  30.  *                 Note: probably not directly compilable
  31.  *                       Not tested in this stripped-down version,
  32.  *                       original code in production since 1993
  33.  */
  34.  
  35. /*===== Include section =====================================================*/
  36.  
  37. #include <string.h>                             // C string functions
  38. #include <stdio.h>                              // Std Input/Output
  39. #include <stdlib.h>                             // Std functions
  40.  
  41. #define INCL_BASE                               // base definitions
  42. #define INCL_WINWINDOWMGR                       // PM window functions
  43. #define INCL_WINSWITCHLIST                      // PM switchlist functions
  44. #include <os2.h>                                // OS/2 master include
  45.  
  46. #include "swlist.h"                             // swlist defs
  47.  
  48. /*===== Local constants =====================================================*/
  49.  
  50. /*===== Local type definitions ==============================================*/
  51.  
  52. /*===== Module globale variabelen ===========================================*/
  53.  
  54. /*===== Local function definitions ==========================================*/
  55.  
  56. // query switch list, retry until nr of entries stable
  57. static USHORT SwListQueryList                   // RET   nr of entries
  58. (
  59.     HAB                hab,                     // IN    PM anchor
  60.     PSWBLOCK          *list                     // OUT   switch list structure
  61. );
  62.  
  63. //
  64. /**************************************************************************
  65.  *
  66.  *  Name       : SwListQueryScrid
  67.  *
  68.  *  Description: screen-session id for specified (sub) title
  69.  *
  70.  *  API's      : WinQuerySwitchList
  71.  *
  72.  *  Return     : returncode
  73.  *
  74.  *************************************************************************/
  75. ULONG SwListQueryScrid                          // RET   screen-session nr
  76. (
  77.     HAB                hab,                     // IN    PM anchor
  78.     char              *title                    // IN    (sub) title
  79. )
  80. {
  81.     ULONG              scrid = 0;               // default returnvalue
  82.     USHORT             i;                       // counter in swlist
  83.     USHORT             count;                   // nr of entries
  84.     PSWBLOCK           ppswblk;                 // ptr to structure
  85.  
  86.     count = SwListQueryList(hab, &ppswblk);
  87.     if (count > 0)
  88.     {
  89.         for ( i = 0;
  90.              (i < count) && (scrid == 0);       // all entries or until found
  91.               i++)
  92.         {
  93.             if (strstr( ppswblk->aswentry[i].swctl.szSwtitle,
  94.                         title) != NULL)         // found (sub)title in list
  95.             {
  96.                 scrid = ppswblk->aswentry[i].swctl.idSession;
  97.             }
  98.         }
  99.         free( ppswblk);
  100.     }
  101.     return(scrid);
  102. }                                               // end SwListQueryScrid
  103. /*---------------------------------------------------------------------------*/
  104.  
  105. //
  106. /**************************************************************************
  107.  *
  108.  *  Name       : SwListQueryHandle
  109.  *
  110.  *  Description: query switch handle for (sub) title in screen-session
  111.  *
  112.  *  API's      : WinQuerySwitchList
  113.  *
  114.  *  Return     : Switch handle
  115.  *
  116.  *************************************************************************/
  117. HSWITCH SwListQueryHandle                       // RET   switch handle
  118. (
  119.     HAB                hab,                     // IN    PM anchor
  120.     char              *title,                   // IN    (sub) title
  121.     ULONG              scrid                    // IN    screen-session nr
  122. )
  123. {
  124.     HSWITCH            hswi = NULLHANDLE;       // default return value
  125.     USHORT             i;                       // counter in swlist
  126.     USHORT             count;                   // nr of entries
  127.     PSWBLOCK           ppswblk;                 // ptr to structure
  128.  
  129.     count = SwListQueryList(hab, &ppswblk);
  130.     if (count > 0)
  131.     {
  132.         for ( i = 0;
  133.              (i < count) &&                     // all entries or
  134.              (hswi == NULLHANDLE);              // until found
  135.               i++)
  136.         {
  137.             if ((scrid == 0) ||                 // not specified or match
  138.                 (scrid == ppswblk->aswentry[i].swctl.idSession))
  139.             {
  140.                 if (strstr( ppswblk->aswentry[i].swctl.szSwtitle,
  141.                             title) != NULL)     // found (sub)title in list
  142.                 {
  143.                     hswi = ppswblk->aswentry[i].hswitch;
  144.                 }
  145.             }
  146.         }
  147.         free( ppswblk);
  148.     }
  149.     return(hswi);
  150. }                                               // end SwListQueryHandle
  151. /*---------------------------------------------------------------------------*/
  152.  
  153. //
  154. /**************************************************************************
  155.  *
  156.  *  Name       : SwListActivate
  157.  *
  158.  *  Description: activate indicated emulator
  159.  *
  160.  *  API's      : WinSwitchToProgram
  161.  *
  162.  *  Return     : BOOL result
  163.  *
  164.  *************************************************************************/
  165. BOOL SwListActivate                             // RET   success
  166. (
  167.     HSWITCH            hswi                     // IN    swlist handle
  168. )
  169. {
  170.     BOOL               rc = FALSE;              // return code
  171.  
  172.     if (hswi != NULLHANDLE)
  173.     {
  174.         if (WinSwitchToProgram(hswi) == NO_ERROR)
  175.         {
  176.             rc = TRUE;
  177.         }
  178.     }
  179.     return(rc);
  180. }                                               // end SwListActivate
  181. /*---------------------------------------------------------------------------*/
  182.  
  183. //
  184. /**************************************************************************
  185.  *
  186.  *  Name       : SwListRemove
  187.  *
  188.  *  Description: remove indicated task from windowlist
  189.  *
  190.  *  API's      : WinRemoveSwitchEntry
  191.  *
  192.  *  Return     : BOOL result
  193.  *
  194.  *************************************************************************/
  195. BOOL SwListRemove                               // RET   success
  196. (
  197.     HSWITCH            hswi                     // IN    swlist handle
  198. )
  199. {
  200.     BOOL               rc = FALSE;              // return code
  201.  
  202.     if (hswi != NULLHANDLE)
  203.     {
  204.         if (WinRemoveSwitchEntry(hswi) == NO_ERROR)
  205.         {
  206.             rc = TRUE;
  207.         }
  208.     }
  209.     return(rc);
  210. }                                               // end SwListRemove
  211. /*---------------------------------------------------------------------------*/
  212.  
  213. //
  214. /**************************************************************************
  215.  *
  216.  *  Name       : SwListVisibility
  217.  *
  218.  *  Description: Make a task (in)vissible in windowlist and desktop
  219.  *
  220.  *  API's      : WinQuerySwitchEntry
  221.  *               WinChangeSwitchEntry
  222.  *               WinSetWindowPos
  223.  *
  224.  *  Return     : BOOL result
  225.  *
  226.  *************************************************************************/
  227. BOOL SwListVisibility                           // RET   success
  228. (
  229.     HSWITCH            hswi,                    // IN    swlist handle
  230.     ULONG              swlv,                    // IN    swlist visibility
  231.     ULONG              winv                     // IN    window visibility
  232. )
  233. {
  234.     BOOL               rc = TRUE;               // return code
  235.     SWCNTRL            swc;                     // switchlist control
  236.  
  237.     if (hswi != NULLHANDLE)                     // 1.02: rc TRUE if NULLHANDLE
  238.     {
  239.         if (WinQuerySwitchEntry(hswi, &swc) == NO_ERROR)
  240.         {
  241.             if (!WinSetWindowPos( swc.hwnd, NULLHANDLE, 0,0,0,0, winv))
  242.             {
  243.                 rc = FALSE;
  244.             }
  245.             swc.uchVisibility = swlv;
  246.             if (WinChangeSwitchEntry(hswi, &swc) != NO_ERROR)
  247.             {
  248.                 rc = FALSE;
  249.             }
  250.         }
  251.         else
  252.         {
  253.             rc = FALSE;
  254.         }
  255.     }
  256.     return(rc);
  257. }                                               // end SwListVisibility
  258. /*---------------------------------------------------------------------------*/
  259.  
  260. /**************************************************************************
  261.  *
  262.  *  Name       : SwListQueryList
  263.  *
  264.  *  Description: query switch list, retry until nr of entries stable
  265.  *
  266.  *  API's      : WinQuerySwitchList
  267.  *
  268.  *  Return     : nr of entries, switchlist
  269.  *
  270.  *************************************************************************/
  271. static USHORT SwListQueryList                   // RET   nr of entries
  272. (
  273.     HAB                hab,                     // IN    PM anchor
  274.     PSWBLOCK          *list                     // OUT   switch list structure
  275. )
  276. {
  277.     USHORT             count = 0;               // nr of entries 1st API call
  278.     USHORT             cnt_2 = 0;               // nr of entries 2nd API call
  279.     PSWBLOCK           ppswblk = NULL;          // ptr to structure
  280.     size_t             usSWBSize;               // size of structure
  281.  
  282.     do
  283.     {
  284.         if (ppswblk != NULL)
  285.         {
  286.             free( ppswblk);
  287.         }
  288.         count = WinQuerySwitchList(hab, NULL, 0);
  289.         if (count > 0)
  290.         {
  291.             usSWBSize = (count * sizeof(SWBLOCK));
  292.             if ((ppswblk = (SWBLOCK*) malloc( usSWBSize)) != NULL)
  293.             {
  294.                 cnt_2 = WinQuerySwitchList(hab, ppswblk, usSWBSize);
  295.             }
  296.         }
  297.     } while (count != cnt_2);
  298.     *list = ppswblk;                            // assign output
  299.     return(count);
  300. }                                               // end SwListQueryList
  301. /*---------------------------------------------------------------------------*/
  302.  
  303.