home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / CFGED1B.ZIP / CFGEDSRC.ZIP / LOADCFG.CC < prev    next >
C/C++ Source or Header  |  1992-08-09  |  6KB  |  204 lines

  1. // this might look like 'C', but it's really  -*-c++-*-
  2. /* loadcfg.cc
  3.  *
  4.  * Implementation of class LoadConfigDlg for CFGED
  5.  *
  6.  * Language        : C++
  7.  * Operating System: OS/2 V2.0 and higher
  8.  * Compiler        : GNU GCC V2.1 and higher
  9.  *
  10.  *
  11.  * $Id: loadcfg.cc,v 1.2 1992/08/09 21:55:29 gruen Exp $
  12.  * $Log: loadcfg.cc,v $
  13. // Revision 1.2  1992/08/09  21:55:29  gruen
  14. // beta release 1.0 of cfged. Changed the architecture: now using a dialog
  15. // box as main window. As an result the accelerators now work. As goodie
  16. // there is a new special-browser for HELP and last but not least the
  17. // warning at the end of the program occures only if there not saved
  18. // changes to the configuration.
  19. //
  20. // Revision 1.1  1992/07/17  00:23:34  gruen
  21. // Initial revision
  22. //
  23.  *
  24.  * Copyright (c) 1992 Lutz Grueneberg
  25.  *
  26.  * This library is free software; you can redistribute it and/or modify
  27.  * it under the terms of the GNU Library General Public License as
  28.  * published by the Free Software Foundation; either version 2 of the
  29.  * License, or (at your option) any later version.  This library is
  30.  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  31.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  32.  * A PARTICULAR PURPOSE.  See the GNU Library General Public License for
  33.  * more details. You should have received a copy of the GNU Library
  34.  * General Public License along with this library; if not, write to the
  35.  * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  36.  */
  37.  
  38. #define INCL_PM
  39. //#define INCL_DOS
  40. #include <os2.h>
  41. #include <stdio.h>
  42. #include <unistd.h>
  43. #include <pmviews/pmviews.h>
  44. #include "StrDLL.h"
  45. #include "maindlg.h"
  46. #include "loadcfg.h"
  47. #include "pmctool.h"
  48.  
  49.      LoadConfigDlg::LoadConfigDlg( HWND hwndOwnerNew,
  50.                     USHORT  idResNew,
  51.                                     HWND hwndParentNew=HWND_DESKTOP)
  52. :( hwndOwnerNew, idResNew, hwndParentNew) {
  53.           
  54.   plb   = new ListBox( this, LDCFG_LB);
  55.   pbtOK = new CntrlWindow( this, LDCFG_OK_BUTT);
  56. }
  57.  
  58.         
  59.  
  60. VOID LoadConfigDlg::setState( int stateNew) {
  61.   switch( stateNew) {
  62.   case 0:     
  63.     pbtOK->enable( FALSE);
  64.     break;
  65.  
  66.   case 1:
  67.     pbtOK->enable( TRUE);
  68.     break;
  69.   }
  70. }
  71. // void LoadConfigDlg::printToListBox( void)
  72. //
  73. // This method prints the contents of the local StrDLList 
  74. // to the list box
  75.  
  76. VOID LoadConfigDlg::printToListBox( VOID)
  77. {
  78.   plb->enableUpdate( FALSE);    // disable update for performance reasons
  79.   plb->deleteAll();
  80.   for(Pix i = strList.first();
  81.       i != 0;
  82.       strList.next(i)) 
  83.     plb->insertItem( LIT_END, (char*)(strList(i)));
  84.   plb->show( TRUE);        // enable update and force redraw
  85. }
  86.  
  87. // String* LoadConfigDlg::retrieve( SHORT iItem)
  88. //
  89. // This method returns a pointer to the String at index iItem.
  90. // The pointer is valid only for exisiting values of iItem.
  91.  
  92. String* LoadConfigDlg::retrieve( SHORT iItem)
  93.   SHORT s;
  94.   Pix   i;
  95.  
  96.   for(s=0, i=strList.first(); s != iItem; s++)
  97.     strList.next(i);
  98.   return &(strList(i));
  99. }
  100.  
  101. Pix LoadConfigDlg::retrievePix( SHORT iItem)
  102. {
  103.   SHORT s;
  104.   Pix   i;
  105.  
  106.   for(s=0, i=strList.first(); s != iItem; s++)
  107.     strList.next(i);
  108.   return (i);
  109. }
  110.  
  111.  
  112. MRESULT LoadConfigDlg::msgInitDlg( HWND hwnd, USHORT msg, 
  113.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  114.   findConfigFiles();
  115.   switch( strList.length()){
  116.   case 0:
  117.     pSelected = NULL;
  118.     PmUserMessage( HWND_DESKTOP,
  119.           "The CfgEd couldn't find any CONFIG.SYS, exiting\n");
  120.     destroy();
  121.     exit(-1);
  122.     break;
  123.  
  124.   case 1:
  125.     pSelected = retrieve(0);
  126.     destroy();
  127.     break;
  128.  
  129.   default:
  130.     printToListBox();
  131.     setState( 0);
  132.     break;
  133.   }
  134.   return 0;
  135. }
  136.  
  137.  
  138. MRESULT LoadConfigDlg::msgControl( HWND hwnd, USHORT msg, 
  139.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  140.   USHORT usID;
  141.  
  142.   usID = SHORT1FROMMP(mp1);
  143.  
  144.   switch (SHORT2FROMMP(mp1)) {   
  145.   case LN_ENTER:  /* Auswahl eines Item oder Double-Click */
  146.     pSelected   = retrieve( plb->querySelection( LIT_NONE));
  147.     destroy();
  148.     *fDoDefault = FALSE;
  149.     return 0;
  150.  
  151.   case LN_SELECT: /* selection of a item of the list */
  152.     setState( 1);
  153.     *fDoDefault = 0;
  154.     return 0;
  155.   }
  156.   return 0;
  157. }
  158.  
  159. // this method reacts on the click to buttons
  160. MRESULT LoadConfigDlg::msgCommand( HWND hwnd, USHORT msg, 
  161.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  162.   if( SHORT1FROMMP( mp2) == CMDSRC_PUSHBUTTON) {   
  163.     switch (SHORT1FROMMP(mp1)) {   
  164.     case LDCFG_OK_BUTT:        // OK Button Pressed
  165.       pSelected   = retrieve( plb->querySelection( LIT_NONE));
  166.       *fDoDefault = TRUE;
  167.       return 0;               
  168.     }
  169.   }
  170.   return 0;
  171. }
  172.  
  173.  
  174. /*------------------------------------------------------------*
  175.  * VOID LoadConfigDlg::findConfigFiles(VOID)
  176.  *------------------------------------------------------------*
  177.  * Diese Funktion durchsucht alle vorhandenen Laufwerke
  178.  * nach einer Datei mit dem Namen 'config.sys'. Die Ergebnisse
  179.  * werden in einer DLL gespeichert.
  180.  *------------------------------------------------------------*/
  181. VOID LoadConfigDlg::findConfigFiles( VOID)
  182. {
  183.   ULONG   ulCurDisk;
  184.   ULONG   ulDiskMap;
  185.   CHAR    chDrives;
  186.   CHAR    szFileName[] = "C:\\CONFIG.SYS";
  187.   String* str;
  188.   
  189.   strList.clear();
  190.   
  191.   DosQueryCurrentDisk( &ulCurDisk, &ulDiskMap); /*Liste der Laufwerke holen*/
  192.   for( ulDiskMap >>= 2,chDrives = 'C'; chDrives <= 'Z'; chDrives++){
  193.     if( ulDiskMap & 1) {        /* Laufwerksbit gesetzt ?*/
  194.       szFileName[0] = chDrives;
  195.       if( access( szFileName, 00) == 0) { /* gefunden ? */
  196.     str = new String( szFileName);
  197.     strList.append( *str);
  198.       }
  199.     }
  200.     ulDiskMap >>= 1;    /* unteres Bit rausruecken */
  201.   }
  202. }
  203.