home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12732.ZIP / INIEDIT.C < prev    next >
Text File  |  1990-08-17  |  29KB  |  770 lines

  1. /******************************* Module Header ******************************\
  2. * Module Name: IniEdit.c
  3. *
  4. *
  5. * PM OS2.ini Editor
  6. *
  7. * Allows adding, deleting and modifying of os2.ini entries through PM
  8. * interface
  9. *
  10. *
  11. \***************************************************************************/
  12.  
  13. #define INCL_PM
  14. #define INCL_BASE
  15.  
  16. #include <string.h>
  17. #include <stdio.h>
  18.  
  19. #include <os2.h>
  20.  
  21. #include "IniEdit.h"
  22.  
  23. /******************************* Constants **********************************/
  24.  
  25. #define STACK_SIZE            0x2000        // Stack size for second thread
  26. #define UPPER_SEGMENT_LIMIT   0xFD00        // Amount of Segment used
  27.  
  28. /******************************** Globals **********************************/
  29.  
  30. char szALL[64] = "Show All Entries - System";
  31. char szAPP[64] = "Show Application Names - System";
  32.  
  33. char szIniEdit[] = "IniEdit";               // App String Name
  34.  
  35. HAB       habIniEdit;                       // Handle Anchor Block
  36. HMQ       hmqIniEdit;                       // Handle Message Queue
  37. HWND      hwndIniEdit;                      // Main Client Window
  38. HWND      hwndIniEditFrame;                 // Frame Window
  39. HDC       hdcScreen;                        // DC for Client Window
  40. HPS       hpsScreen;                        // PS for Client Window
  41.  
  42. USHORT    cAppNames = 0;                    // Count of App names in os2.ini
  43. USHORT    usShift = 0;                      // DosHugeAlloc segment offsets
  44. HWND      FocusWindow = (HWND)NULL;         // Focus of Dialog Box
  45. USHORT    cxBorder;                         // System border width
  46. USHORT    cyBorder;                         // System border height
  47.  
  48. USHORT    usFormat = APP_FORM;              // Current Display format
  49. USHORT    usPrintFormat = APP_FORM;         // Format for Printing
  50. USHORT    usLineHeight = 12;                // Current font Height
  51. HWND      hwndList = (HWND)NULL;            // Handle of Main ListBox
  52. HWND      hwndMenu = (HWND)NULL;            // Handle of Main Menu
  53.  
  54. PGROUPSTRUCT  pGroups;                      // Pointer to String Groups
  55. PPAIRSTRUCT   pPairsBase;                   // Pointer to Key-Value Pairs
  56. PPAIRSTRUCT   pPairsAlloc;                  // Pointer to next Avail Memory
  57. PBYTE         pPrintStack;                  // Pointer to Print Thread Stack
  58.  
  59. #define HOLD_LEN 4096
  60. CHAR          achNames[HOLD_LEN];           // Array of Character from Query
  61. CHAR          szBuf[2 * MAX_STRING_LEN];        // Character buffer for Pairs
  62.  
  63.  
  64.              /* ??????????????????????????????????????????????????????? */
  65. HINI hIniFile=HINI_SYSTEMPROFILE;     /* make this dynamic later ?????? */
  66.  
  67. /***************************** Function Decls ******************************/
  68.  
  69. VOID    ProcessMenuItem( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 );
  70. VOID    cdecl main( VOID );
  71. VOID    IniEditPaint( VOID );
  72. VOID    ReadIni( VOID );
  73. VOID    OldProfilePrint( VOID );
  74. VOID    UpdateListBox( BOOL fRead, USHORT usForm );
  75.  
  76. MRESULT _loadds EXPENTRY IniEditWndProc(HWND, USHORT, MPARAM, MPARAM);
  77.  
  78.  
  79. /***************************** Function Header *****************************\
  80. *
  81. * main
  82. *
  83. *
  84. * Do initialization then do a message loop
  85. *
  86. \***************************************************************************/
  87.  
  88. VOID cdecl main()
  89. {
  90.  
  91.     QMSG         qmsg;                      // Current Queue Message
  92.     ULONG        fcf;                       // Frame Control Flags
  93.     SIZEL        sizel;                     // Size of PS
  94.     RECTL        rclWindow;                 // Size Rect for ListBox Window
  95.     SEL          sel;                       // Selector of allocated segments
  96.     SWCNTRL      swcntrl;                   // Switch Control Block
  97.     FONTMETRICS  fmetrics;                  // FontMetrics of current font
  98.  
  99.  
  100.     /*** Set up and Initialization ***/
  101.  
  102.     /* Initialize the anchor block handle */
  103.     habIniEdit = WinInitialize(0);
  104.  
  105.     /* Create the message queue */
  106.     hmqIniEdit = WinCreateMsgQueue(habIniEdit, 0);
  107.  
  108.     /* Register the window class for the IniEdit window */
  109.     WinRegisterClass(habIniEdit, (PCH)szIniEdit, IniEditWndProc,
  110.             CS_SIZEREDRAW, 0);
  111.  
  112.     /* Create the window for IniEdit */
  113.     fcf = FCF_TITLEBAR | FCF_MINMAX | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MENU
  114.         | FCF_SHELLPOSITION | FCF_ACCELTABLE | FCF_ICON;
  115.  
  116.     hwndIniEditFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE,
  117.         (PVOID)&fcf, (PSZ)szIniEdit, (PSZ)szIniEdit, WS_VISIBLE,
  118.         (HMODULE)NULL, IDI_INIEDIT, (PHWND)&hwndIniEdit);
  119.  
  120.     /* Create a DC for the IniEdit window */
  121.     hdcScreen = WinOpenWindowDC(hwndIniEdit);
  122.  
  123.     /* also create a screen PS */
  124.  
  125.     sizel.cx= 0L;   // To use the default screen page size.
  126.     sizel.cy= 0L;
  127.  
  128.     if( (hpsScreen = GpiCreatePS( habIniEdit, hdcScreen, &sizel,
  129.             (PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC ))) == (HPS)NULL )
  130.         {
  131.                 ;
  132.         }
  133.  
  134.  
  135.     /* Initially set the keyboard focus to us */
  136.     WinSetFocus(HWND_DESKTOP, hwndIniEdit);
  137.  
  138.     /* get the font size */
  139.     GpiQueryFontMetrics( hpsScreen, (LONG)sizeof( FONTMETRICS ), &fmetrics );
  140.     usLineHeight = (USHORT)(fmetrics.lMaxDescender + fmetrics.lMaxBaselineExt);
  141.  
  142.     /* get the system widths of a border */
  143.     cxBorder = (USHORT) WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
  144.     cyBorder = (USHORT) WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
  145.  
  146.     /* this menu handle is often used */
  147.     hwndMenu = WinWindowFromID( hwndIniEditFrame, FID_MENU );
  148.  
  149.     /* add program to switch list */
  150.     swcntrl.hwnd             = hwndIniEditFrame;
  151.     swcntrl.hwndIcon         = NULL;
  152.     swcntrl.hprog            = (HPROGRAM) 0;
  153.     swcntrl.idProcess        = 0;
  154.     swcntrl.idSession        = 0;
  155.     swcntrl.uchVisibility    = (UCHAR) 0;
  156.     swcntrl.fbJump           = (UCHAR) NULL;
  157.     strcpy( swcntrl.szSwtitle, szIniEdit);
  158.     swcntrl.fReserved        = (BYTE) 0;
  159.  
  160.     WinAddSwitchEntry( &swcntrl );
  161.  
  162.     /* Create main list box in main window */
  163.     WinQueryWindowRect( hwndIniEdit, &rclWindow);
  164.     rclWindow.yTop -= usLineHeight;
  165.     rclWindow.yTop += cyBorder;
  166.     rclWindow.xRight += 2*cxBorder;
  167.     hwndList = WinCreateWindow( hwndIniEdit,            // parent
  168.                                 WC_LISTBOX,             // class
  169.                                 (PSZ)"Scroll",          // name
  170.                                 LS_NOADJUSTPOS,         // style
  171.                                 -cxBorder, -cyBorder,   // position
  172.                                 (USHORT)rclWindow.xRight,
  173.                                 (USHORT)rclWindow.yTop,
  174.                                 hwndIniEditFrame,       // Owner
  175.                                 HWND_TOP,               // InsertBehind
  176.                                 IDI_LIST,               // ID
  177.                                 (PVOID)NULL,            // pCtlData,
  178.                                 (PVOID)NULL);
  179.  
  180.  
  181.     /*** Memory Allocation ***/
  182.  
  183.     /* Alloc the needed space for the groups */
  184.     if( DosAllocSeg( 32000, &sel, 0) )
  185.         ErrMessage( "main: DosAlloc for pGroup failed" );
  186.     pGroups = MAKEP( sel, 0);
  187.  
  188.     if( DosAllocHuge( 4, 0, &sel, 0, 0) )
  189.         ErrMessage( "main: DosAlloc for pPairs failed" );
  190.     pPairsAlloc = pPairsBase = MAKEP( sel, 0);
  191.  
  192.     /* create a stack for second thread */
  193.     if( DosAllocSeg( STACK_SIZE, &sel, 0) )
  194.         ErrMessage( "main: DosAlloc for Stack failed" );
  195.     pPrintStack = MAKEP( sel, 0);
  196.  
  197.     DosGetHugeShift( &usShift );
  198.  
  199.     /* read in os2.ini and fill in list box */
  200.     UpdateListBox( TRUE, APP_FORM );
  201.  
  202.     WinShowWindow( hwndList, TRUE );
  203.  
  204.     /* Process messages for the window */
  205.     while ( WinGetMsg(habIniEdit, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
  206.         {
  207.  
  208.         /* Dispatch the message */
  209.         WinDispatchMsg(habIniEdit, (PQMSG)&qmsg);
  210.         }
  211.  
  212.  
  213.     /*** CleanUp ***/
  214.  
  215.     /* Destroy the IniEdit window and message queue */
  216.     GpiDestroyPS( hpsScreen );
  217.     WinDestroyWindow(hwndIniEditFrame);
  218.     WinDestroyMsgQueue(hmqIniEdit);
  219.  
  220.     /* Exit PM */
  221.     WinTerminate( habIniEdit );
  222.     DosExit( EXIT_PROCESS, 0 );
  223.  
  224. }  /* main */
  225.  
  226.  
  227. /****************************** Function Header ****************************\
  228. *
  229. * ReadIni
  230. *
  231. *
  232. * Reads in OS2.ini
  233. *
  234. \***************************************************************************/
  235.  
  236. VOID ReadIni()
  237. {
  238.     ULONG     cchNames;                     // Count of Character from Query
  239.     USHORT    Index[MAX_APP_NAMES];         // Index of Names into achNames
  240.     USHORT    cPairs;                       // Count of pairs in current AppName
  241.     ULONG     ul;
  242.     ULONG     i,j;                          // Loop Counters
  243.  
  244.  
  245.     /* Reset Count of App Names */
  246.     cAppNames = 0;
  247.  
  248.     /* Reset memory available pointer to Base */
  249.     pPairsAlloc = pPairsBase;
  250.  
  251.     /* Determine number of characters in app Names Strings */
  252.  
  253. #ifdef INI11
  254.     WinQueryProfileSize( habIniEdit, NULL, NULL, &cchNames );
  255. #else
  256.     PrfQueryProfileSize( hIniFile, NULL, NULL, &cchNames );
  257. #endif
  258.  
  259.     /* Read in the App Name strings */
  260. #ifdef INI11
  261.     WinQueryProfileString( habIniEdit, NULL, NULL, " ", achNames, cchNames );
  262. #else
  263.     PrfQueryProfileString( hIniFile, NULL, NULL, " ", achNames, cchNames );
  264. #endif
  265.  
  266.     /*** Find the starting index of each App ***/
  267.  
  268.     /* step through each string in set of app characters
  269.      * adding length of current string to find begining of next string
  270.      * also store each App Name into szAppName element of Group
  271.      */
  272.     for( i=0; i < cchNames; i += (strlen(pGroups[cAppNames-1].szAppName)+1) )
  273.         {
  274.         if( achNames[i] != (char)0 )
  275.             {
  276.             strcpy( pGroups[cAppNames++].szAppName, &achNames[i]);
  277.             }  /* if */
  278.         else
  279.             if( achNames[i+1] == (char)0 )
  280.                 break;
  281.         }  /* for */
  282.  
  283.     /*** Read elements of each App Name ***/
  284.     for( i=0; i<cAppNames; i++ )
  285.         {
  286.         /* Get number of Character Associated with App Name */
  287. #ifdef INI11
  288.         WinQueryProfileSize( habIniEdit, pGroups[i].szAppName, NULL, &cchNames );
  289. #else
  290.         PrfQueryProfileSize( hIniFile, pGroups[i].szAppName, NULL, &cchNames );
  291. #endif
  292.  
  293.         /* Enumerate all KeyNames for this app name */
  294. #ifdef INI11
  295.         WinQueryProfileString( habIniEdit, pGroups[i].szAppName, NULL, " ", achNames, HOLD_LEN );
  296. #else
  297.         PrfQueryProfileString( hIniFile, pGroups[i].szAppName, NULL, " ", achNames, HOLD_LEN );
  298. #endif
  299.  
  300.         /* Count the number of key Names */
  301.         cPairs = 0;
  302.         for( j=0; j < cchNames; j++)
  303.             if( achNames[j] != (CHAR)0 )
  304.                 {
  305.                 Index[cPairs++] = (USHORT) j;
  306.                 j += strlen( &achNames[j] );
  307.                 }
  308.  
  309.         pGroups[i].cKeys = cPairs;
  310.  
  311.         /*
  312.          * Make sure we can fit the entire structure into our current
  313.          * segment, if not, lets jump to the next segment
  314.          */
  315.         ul =  sizeof(PAIRSTRUCT) * cPairs;
  316.         if ((ul + (ULONG)OFFSETOF(pPairsAlloc)) >= 0x10000L)
  317.             pPairsAlloc = MAKEP( (HIUSHORT(pPairsAlloc)+(1<<usShift)), 0);
  318.  
  319.         /* Allocate the number of pair structures for the current group */
  320.         pGroups[i].pPairs = pPairsAlloc;
  321.  
  322.         // pPairsAlloc += sizeof(PAIRSTRUCT)*cPairs;
  323.         // Remember that incrementing a pointer automatically mult by size of item
  324.         pPairsAlloc += cPairs;
  325.  
  326.         /* Step to next segment if near end of current segment */
  327.         if( LOUSHORT(pPairsAlloc) > UPPER_SEGMENT_LIMIT)
  328.             {
  329.             pPairsAlloc = MAKEP( (HIUSHORT(pPairsAlloc)+(1<<usShift)), 0);
  330.             }
  331.  
  332.         /* Store the KeyName into the pair structure */
  333.         for( j=0; j<cPairs; j++ )
  334.             {
  335.             strcpy( pGroups[i].pPairs[j].szKey, &achNames[Index[j]] );
  336.  
  337.             /* store the key value */
  338. #ifdef INI11
  339.             WinQueryProfileString( habIniEdit, pGroups[i].szAppName,
  340.                      pGroups[i].pPairs[j].szKey, " ",
  341.                      pGroups[i].pPairs[j].szValue, MAX_STRING_LEN );
  342. #else
  343.  
  344.             PrfQueryProfileString( hIniFile, pGroups[i].szAppName,
  345.                      pGroups[i].pPairs[j].szKey, " ",
  346.                      pGroups[i].pPairs[j].szValue, MAX_STRING_LEN );
  347. #endif
  348.             }
  349.         }  /* each App Name */
  350.  
  351. }  /* ReadIni */
  352.  
  353.  
  354. /****************************** Function Header ****************************\
  355. *
  356. * ProcessMenuItem
  357. *
  358. *
  359. * Act on the corresponding Menu Item Choosen
  360. *
  361. \***************************************************************************/
  362.  
  363. VOID ProcessMenuItem( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  364. {
  365.     TID  Tid;                               // ID of new thread; Not used
  366.  
  367.  
  368.     /* Switch on the Menu Item choosen */
  369.     switch( LOUSHORT( mp1 ) )
  370.         {
  371.         case IDMI_SYSTEMINI:
  372.             hIniFile=HINI_SYSTEMPROFILE;
  373.             strcpy(szALL,"Show All Entries - System");
  374.             strcpy(szAPP,"Show Application Names - System");
  375.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  376.             WinInvalidateRect(hwnd, NULL, FALSE);
  377.             break;
  378.  
  379.         case IDMI_USERINI:
  380.             hIniFile=HINI_USERPROFILE;
  381.             strcpy(szALL,"Show All Entries - User");
  382.             strcpy(szAPP,"Show Application Names - User");
  383.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  384.             WinInvalidateRect(hwnd, NULL, FALSE);
  385.             break;
  386.  
  387.         case IDMI_PROFILE:
  388.             hIniFile=HINI_PROFILE;
  389.             strcpy(szALL,"Show All Entries - default");
  390.             strcpy(szAPP,"Show Application Names - default");
  391.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  392.             WinInvalidateRect(hwnd, NULL, FALSE);
  393.             break;
  394.  
  395.         case IDMI_SHOW_ALL:
  396.         case IDMI_SHOW_APPNAMES:
  397.             usFormat = (LOUSHORT(mp1) == IDMI_SHOW_ALL);
  398.             UpdateListBox( FALSE, usFormat ? ALL_FORM : APP_FORM );
  399.             break;
  400.  
  401.         case IDM_SEARCH:
  402.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)SearchWndProc,
  403.                             (HMODULE)NULL, IDD_SEARCH, (PVOID)NULL);
  404.             break;
  405.  
  406.         case IDMI_EDIT_DELETE_KEY:
  407.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelKeyWndProc,
  408.                             (HMODULE)NULL, IDD_DEL_KEY, (PVOID)NULL);
  409.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  410.             break;
  411.  
  412.         case IDMI_EDIT_DELETE_APP:
  413.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelAppWndProc,
  414.                             (HMODULE)NULL, IDD_DEL_APP, (PVOID)NULL);
  415.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  416.             break;
  417.  
  418.         case IDMI_EDIT_ADD_KEY:
  419.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)AddKeyWndProc,
  420.                             (HMODULE)NULL, IDD_ADD_KEY, (PVOID)NULL);
  421.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  422.             break;
  423.  
  424.         case IDMI_EDIT_CHANGE:
  425.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)ChangeKeyWndProc,
  426.                             (HMODULE)NULL, IDD_CHANGE_KEY, (PVOID)NULL);
  427.             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
  428.             break;
  429.  
  430.         case IDMI_PRINT_ALL:
  431.         case IDMI_PRINT_APP:
  432.             usPrintFormat = LOUSHORT(mp1) == IDMI_PRINT_ALL ? ALL_FORM : APP_FORM;
  433.             if( DosCreateThread( PrintThread, &Tid, ((PBYTE)(pPrintStack)+STACK_SIZE) ) )
  434.                 ErrMessage("StartThread2: DosCreateThread Failed");
  435.             break;
  436.  
  437.         case IDMI_REFRESH:
  438.             UpdateListBox( TRUE, usFormat );
  439.             break;
  440.  
  441.         case IDMI_ABOUT:
  442.             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelAppWndProc,
  443.                             (HMODULE)NULL, IDD_ABOUT, (PVOID)NULL);
  444.             break;
  445.  
  446.         default:
  447.             WinDefWindowProc(hwnd, msg, mp1, mp2);
  448.  
  449.             break;
  450.  
  451.         }  /* switch */
  452.  
  453. }  /* ProcessMenuItem */
  454.  
  455.  
  456. /****************************** Function Header ****************************\
  457. *
  458. * UpdateListBox
  459. *
  460. *
  461. * Update Main List Box to correct state
  462. *    May Also:
  463. *    - Check correct menu item
  464. *    - Repaint title of List Box
  465. *    - ReRead os2.ini file
  466. *
  467. \***************************************************************************/
  468.  
  469. VOID UpdateListBox( BOOL fReadIni, USHORT usNewFormat )
  470. {
  471.     INT       i,j;                          // Loop Counters
  472.     USHORT    Index;                        // Index into ListBox
  473.     static    USHORT    usLastFormat = -1;  // Last displayed format
  474.  
  475.  
  476.     /* Check the correct item if format changed */
  477.     if( usLastFormat != usNewFormat )
  478.         {
  479.         WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDMI_SHOW_ALL, TRUE),
  480.                 MPFROM2SHORT(MIA_CHECKED, usFormat ? MIA_CHECKED:FALSE));
  481.  
  482.         WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDMI_SHOW_APPNAMES, TRUE),
  483.                 MPFROM2SHORT(MIA_CHECKED, (!usFormat) ? MIA_CHECKED:FALSE));
  484.         usLastFormat = usNewFormat;
  485.  
  486.         WinSendMsg( hwndIniEdit, WM_PAINT, (MPARAM)NULL, (MPARAM)NULL );
  487.         }
  488.  
  489.  
  490.     /* Turn off list box updates */
  491.     WinEnableWindowUpdate( hwndList, FALSE );
  492.  
  493.     /* Remove all items from list box */
  494.     WinSendMsg( hwndList, LM_DELETEALL, (MPARAM)0, (MPARAM)0 );
  495.  
  496.     /* ReRead os2.ini if needed */
  497.     if( fReadIni )
  498.         ReadIni();
  499.  
  500.     /* Add elements to listbox */
  501.     if( usNewFormat == ALL_FORM )
  502.         {
  503.  
  504.         /* Insert all app Names */
  505.         for( i=0; i < (ULONG) cAppNames; i++ )
  506.             {
  507.             Index = (USHORT) (ULONG) WinSendMsg( hwndList, LM_INSERTITEM,
  508.                     MPFROM2SHORT(LIT_END, NULL),
  509.                     MPFROMP(pGroups[i].szAppName) );
  510.  
  511.             WinSendMsg( hwndList, LM_SETITEMHANDLE,
  512.                     MPFROMSHORT(Index),
  513.                     MPFROMSHORT(i) );
  514.  
  515.             /* Insert Key Value Pairs for App Name */
  516.             for( j=0; j<pGroups[i].cKeys; j++ )
  517.                 {
  518.                 sprintf( szBuf, "     %s: %s", pGroups[i].pPairs[j].szKey,
  519.                         pGroups[i].pPairs[j].szValue );
  520.                 Index = (USHORT) (ULONG) WinSendMsg( hwndList, LM_INSERTITEM,
  521.                         MPFROM2SHORT(LIT_END, NULL),
  522.                         MPFROMP(szBuf) );
  523.  
  524.                 WinSendMsg( hwndList, LM_SETITEMHANDLE,
  525.                         MPFROMSHORT(Index),
  526.                         MPFROM2SHORT(i,j) );
  527.  
  528.                 }
  529.             }
  530.         }  /* if */
  531.     else
  532.         {
  533.         /* Insert all app Names */
  534.         for( i=0; i<cAppNames; i++ )
  535.             {
  536.             WinSendMsg( hwndList, LM_INSERTITEM,
  537.                     MPFROM2SHORT(LIT_SORTASCENDING, NULL),
  538.                     MPFROMP(pGroups[i].szAppName) );
  539.             }
  540.         }  /* else */
  541.  
  542.     /* Do All repainting of ListBox */
  543.     WinEnableWindowUpdate( hwndList, TRUE );
  544.  
  545. }  /* UpdateListBox */
  546.  
  547.  
  548. /****************************** Function Header ****************************\
  549. *
  550. * IniEditPaint
  551. *
  552. *
  553. * Window Paint Routine
  554. *
  555. \***************************************************************************/
  556.  
  557. VOID IniEditPaint()
  558. {
  559.     RECTL     rclWindow;                    // Current size of Main Window
  560.     RECTL     rclBlit;                      // Size of Area to Blank for Title
  561.     CHAR      szShowMode[MAX_STRING_LEN];   // String Description of mode
  562.  
  563.  
  564.     /* Get the size of the whole window */
  565.     WinQueryWindowRect( hwndIniEdit, &rclWindow );
  566.  
  567.     /* Paint the window Title Area */
  568.     rclBlit = rclWindow;
  569.     rclBlit.yBottom = rclBlit.yTop - usLineHeight;
  570.  
  571.     GpiBitBlt( hpsScreen, (HPS)NULL, 2L, (PPOINTL)&rclBlit, ROP_ONE, (LONG)NULL);
  572.  
  573.     /* Write the Title */
  574.     strcpy( szShowMode, usFormat == APP_FORM ? szAPP : szALL );
  575.     WinDrawText( hpsScreen, strlen(szShowMode), szShowMode, &rclWindow,
  576.             CLR_BLUE, CLR_WHITE, DT_CENTER|DT_TOP);
  577.  
  578. }  /* IniEditPaint */
  579.  
  580.  
  581. /****************************** Function Header ****************************\
  582. *
  583. * IniEditWndProc
  584. *
  585. *
  586. * Window Proc for IniEdit
  587. *
  588. \***************************************************************************/
  589.  
  590. MRESULT _loadds EXPENTRY IniEditWndProc(HWND hwnd, USHORT msg,
  591.         MPARAM mp1, MPARAM mp2)
  592. {
  593.  
  594.     CHAR      szBuf[MAX_STRING_LEN];        // Input character Buffer
  595.     CHAR      szBuf2[MAX_STRING_LEN];       // Second Input Character Buffer
  596.     USHORT    Index;                        // Index of Current ListBox Item
  597.     USHORT    TopIndex;                     // Current Top Item in ListBox
  598.     ULONG     Handle;                       // ListBox Item Handle Info
  599.     HWND      hwndDialog;                   // Window handle of Dailog Box
  600.     HWND      hwndText;                     // Handle of current text window
  601.     HPS       hpsPaint;                     // PS to Paint
  602.     RECTL     rclPaint;                     // Rect in hpsPaint to Paint
  603.     BOOL      fScroll = FALSE;              // Scroll List Box Flag
  604.  
  605.  
  606.     /* Switch on message being processed */
  607.     switch( msg )
  608.         {
  609.         case WM_PAINT:
  610.             /* Paint the IniEdit window portion not covered by List Box */
  611.             hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);
  612.             IniEditPaint();
  613.             WinEndPaint(hpsPaint);
  614.             break;
  615.  
  616.         case WM_COMMAND:
  617.             /* If menu item call Processing Routine */
  618.             if( LOUSHORT( mp2 ) == CMDSRC_MENU )
  619.                 ProcessMenuItem( hwnd, msg, mp1, mp2 );
  620.  
  621.             /* If accelorator call appropriate routine */
  622.             if( LOUSHORT( mp2 ) == CMDSRC_ACCELERATOR )
  623.                 {
  624.                 switch( LOUSHORT( mp1 ) )
  625.                     {
  626.                     case IDDI_SEARCH_NEXT:
  627.                         FindNext();
  628.                         break;
  629.                     }
  630.                 }
  631.             break;
  632.  
  633.         case WM_SIZE:
  634.             /* Put the list box in the correct location of the window */
  635.             if( hwndList != (HWND)NULL )
  636.                 /* The position is set to fill the client, except for the */
  637.                 /* area at the top for some text.  In addition, the       */
  638.                 /* rectangle is outset by a border width on all dimensions*/
  639.                 /* except for the top so that the list box border is      */
  640.                 /* "tucked" under the clients border and doesn't cause    */
  641.                 /* there to be a double thick border around it.           */
  642.                 WinSetWindowPos( hwndList, HWND_TOP, -cxBorder, -cyBorder,
  643.                         SHORT1FROMMP(mp2)+(2*cxBorder),
  644.                         SHORT2FROMMP(mp2)-usLineHeight + cyBorder,
  645.                         SWP_SIZE | SWP_MOVE );
  646.             break;
  647.  
  648.         case WM_CONTROL:
  649.             /* Switch on Control activated */
  650.             switch( SHORT1FROMMP(mp1) )
  651.                 {
  652.  
  653.                 /*** Process List Box Activity ***/
  654.                 case IDI_LIST:
  655.                     /* was it a double click? */
  656.                     if( SHORT2FROMMP(mp1) == LN_ENTER )
  657.                         {
  658.                         /* get the item clicked on */
  659.                         Index = (USHORT) (ULONG) WinSendMsg( hwndList, LM_QUERYSELECTION,
  660.                                 (MPARAM)0, (MPARAM)0 );
  661.  
  662.                         /* grab its text */
  663.                         WinSendMsg( hwndList, LM_QUERYITEMTEXT,
  664.                                 MPFROM2SHORT(Index, MAX_STRING_LEN), MPFROMP(szBuf) );
  665.  
  666.                         /* if in APP form toggle to ALL form */
  667.                         if( usFormat == APP_FORM )
  668.                             {
  669.                             usFormat = ALL_FORM;
  670.                             fScroll = TRUE;
  671.                             }
  672.                         else
  673.                             {
  674.                             /* if an App name was choosen then go to APP form */
  675.                             if( szBuf[0] != ' ')
  676.                                 {
  677.                                 usFormat = APP_FORM;
  678.                                 fScroll = TRUE;
  679.                                 }
  680.                             else
  681.                                 /* A Key Value Pair was double clicked
  682.                                  * allow editing of key Value
  683.                                  */
  684.                                 {
  685.  
  686.                                 FocusWindow = (HWND)1;
  687.  
  688.                                 hwndDialog = WinLoadDlg( HWND_DESKTOP,
  689.                                     hwndIniEditFrame, ChangeKeyWndProc,
  690.                                     (HMODULE)NULL, IDD_CHANGE_KEY, NULL);
  691.  
  692.                                 Handle = (ULONG)WinSendMsg( hwndList, LM_QUERYITEMHANDLE,
  693.                                     MPFROMSHORT(Index), (MPARAM)NULL );
  694.  
  695.                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_APP );
  696.                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
  697.                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  698.                                 WinSetWindowText( hwndText, pGroups[LOUSHORT(Handle)].szAppName);
  699.  
  700.                                 /* note bug in PMWin GPs if full segment */
  701.                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY );
  702.                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
  703.                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  704.                                 strcpy( szBuf2, pGroups[LOUSHORT(Handle)].pPairs[HIUSHORT(Handle)].szKey );
  705.                                 WinSetWindowText( hwndText, szBuf2 );
  706.  
  707.                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );
  708.                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
  709.                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  710.                                 strcpy( szBuf2, pGroups[LOUSHORT(Handle)].pPairs[HIUSHORT(Handle)].szValue );
  711.                                 WinSetWindowText( hwndText, szBuf2 );
  712.  
  713.                                 WinPostMsg( hwndText, EM_SETSEL,
  714.                                         MPFROM2SHORT(0, strlen(szBuf2)), (MPARAM)0 );
  715.  
  716.                                 if( WinProcessDlg( hwndDialog ) == IDDI_CHANGE_KEY_OK )
  717.                                     {
  718.                                     TopIndex = (USHORT) (ULONG) WinSendMsg( hwndList, LM_QUERYTOPINDEX,
  719.                                          (MPARAM)NULL, (MPARAM)NULL );
  720.  
  721.                                     UpdateListBox( TRUE, usFormat );
  722.  
  723.                                     /* scroll to top */
  724.                                     WinSendMsg( hwndList, LM_SETTOPINDEX,
  725.                                          MPFROMSHORT(TopIndex), (MPARAM)NULL );
  726.  
  727.                                     /* make the item selected */
  728.                                     WinSendMsg( hwndList, LM_SELECTITEM,
  729.                                             MPFROMSHORT(Index), MPFROMSHORT(TRUE) );
  730.  
  731.                                     /* make selected */
  732.                                     }
  733.  
  734.                                 WinDestroyWindow( hwndDialog );
  735.                                 }
  736.                             }
  737.  
  738.                         /* Make the double clicked item selected in new form */
  739.                         if( fScroll )
  740.                             {
  741.                             /* put in correct form */
  742.                             UpdateListBox( FALSE, usFormat );
  743.  
  744.                             /* get the index of the item clicked on */
  745.                             Index = (USHORT) (ULONG) WinSendMsg( hwndList, LM_SEARCHSTRING,
  746.                                     MPFROM2SHORT(LSS_SUBSTRING, LIT_FIRST),
  747.                                     MPFROMP(szBuf) );
  748.  
  749.                             /* scroll that item to the top */
  750.                             WinSendMsg( hwndList, LM_SETTOPINDEX,
  751.                                     MPFROMSHORT(Index), (MPARAM)NULL );
  752.  
  753.                             /* make the item selected */
  754.                             WinSendMsg( hwndList, LM_SELECTITEM,
  755.                                     MPFROMSHORT(Index), MPFROMSHORT(TRUE) );
  756.                             }
  757.                         }  /* if ENTER */
  758.                 }
  759.             break;
  760.  
  761.         default:
  762.             return WinDefWindowProc(hwnd, msg, mp1, mp2);
  763.             break;
  764.         }
  765.  
  766.     return 0L;
  767.  
  768. }  /* IniEditWndProc */
  769. 
  770.