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

  1. // this might look like 'C', but it's really  -*-c++-*-
  2. /* sbrowser.cc
  3.  *
  4.  * Implementation of class SingleBrowser 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: sbrowser.cc,v 1.3 1992/08/29 16:12:08 gruen Exp $
  12.  * $Log: sbrowser.cc,v $
  13. // Revision 1.3  1992/08/29  16:12:08  gruen
  14. // Fixed several bugs. This will become the official beta-release.
  15. //
  16. // Revision 1.2  1992/08/09  21:55:40  gruen
  17. // beta release 1.0 of cfged. Changed the architecture: now using a dialog
  18. // box as main window. As an result the accelerators now work. As goodie
  19. // there is a new special-browser for HELP and last but not least the
  20. // warning at the end of the program occures only if there not saved
  21. // changes to the configuration.
  22. //
  23. // Revision 1.1  1992/07/17  00:23:40  gruen
  24. // Initial revision
  25. //
  26.  *
  27.  * Copyright (c) 1992 Lutz Grueneberg
  28.  *
  29.  * This library is free software; you can redistribute it and/or modify
  30.  * it under the terms of the GNU Library General Public License as
  31.  * published by the Free Software Foundation; either version 2 of the
  32.  * License, or (at your option) any later version.  This library is
  33.  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  34.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  35.  * A PARTICULAR PURPOSE.  See the GNU Library General Public License for
  36.  * more details. You should have received a copy of the GNU Library
  37.  * General Public License along with this library; if not, write to the
  38.  * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  39.  */
  40. #define INCL_PM
  41. #include <os2.h>
  42. #include <pmviews/pmviews.h>
  43. #include <Regx.h>
  44. #include <Strng.h>
  45. #include "StrDLL.h"
  46. #include "maindlg.h"
  47. #include "prompter.h"
  48. #include "pmctool.h"
  49. #include "sbrowser.h"
  50.  
  51.      SingleBrowser::SingleBrowser( HWND hwndOwnerNew, USHORT  idResNew,
  52.                   CHAR* pszTitleNew, CHAR *pszCommentNew,
  53.                   StrDLList *pListNew)
  54. :( hwndOwnerNew, idResNew) {
  55.   pComment  = new StaticText( this, SB_TEXT);
  56.   plb       = new ListBox( this, SB_LB);
  57.   pbtInsert = new CntrlWindow( this, SB_INSERT_BUTT);
  58.   pbtAppend = new CntrlWindow( this, SB_APPEND_BUTT);
  59.   pbtDelete = new CntrlWindow( this, SB_DELETE_BUTT);
  60.   pbtHelp   = new CntrlWindow( this, SB_HELP_BUTT);
  61.   pbtCancel = new CntrlWindow( this, SB_CANCEL_BUTT);
  62.   pbtOK     = new CntrlWindow( this, SB_OK_BUTT);
  63.  
  64.   pszTitle  = pszTitleNew;
  65.   pszComment= pszCommentNew;
  66.   pList     = pListNew;
  67.   strList   = *pList;        // create a copy of the original list
  68. }
  69.  
  70.  
  71. MRESULT SingleBrowser::msgInitDlg( HWND hwnd, USHORT msg, 
  72.                 MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  73.   setTitle( pszTitle);
  74.   pComment->setText( pszComment);
  75.   pbtHelp ->enable( FALSE);    // no help available 
  76.   setState( 0);
  77.   printToListBox();
  78.   return 0;
  79. }
  80.  
  81. MRESULT SingleBrowser::msgControl( HWND hwnd, USHORT msg, 
  82.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  83.   USHORT usID;
  84.  
  85.   usID = SHORT1FROMMP(mp1);
  86.  
  87.   switch (SHORT2FROMMP(mp1)) {   
  88.   case LN_ENTER:  /* Auswahl eines Item oder Double-Click */
  89.     editEntry();
  90.     *fDoDefault = FALSE;
  91.     return 0;
  92.   case LN_SELECT: /* selection of a item of the list */
  93.     setState( 1);
  94.     *fDoDefault = 0;
  95.     return 0;
  96.   }
  97.   return 0;
  98. }
  99.  
  100. MRESULT SingleBrowser::msgCommand( HWND hwnd, USHORT msg, 
  101.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  102.   USHORT usID;
  103.  
  104.   usID = SHORT1FROMMP(mp1);    // the resource id of the sender
  105.   if( SHORT1FROMMP( mp2) == CMDSRC_PUSHBUTTON) {   
  106.     switch (SHORT1FROMMP(mp1)) {   
  107.     case SB_INSERT_BUTT:
  108.       {    PrompterDlg Prompter( queryHwnd(), PR_DLG);
  109.     SHORT i = plb->querySelection( LIT_NONE); // retrieve active Element
  110.     String strNew = "";
  111.     Prompter.setString( &strNew);
  112.     Prompter.setComment( "Enter new property:");
  113.     Prompter.create();
  114.     if( strNew.length()){
  115.       String *pStrg = new String( strNew);
  116.       strList.ins_before( (Pix)retrievePix( i), *pStrg);
  117.     }
  118.     SHORT j = plb->queryTopIndex();
  119.     printToListBox();
  120.     plb->setTopIndex( j);
  121.     plb->selectItem( i, TRUE);
  122.       }
  123.       break;
  124.     case SB_APPEND_BUTT:
  125.       // First this was implemented as an append at the end of the list.
  126.       // But this wasn't intuitive and so I've changed it. Now append means
  127.       // an insertion of an item after the actual one.
  128.       {    PrompterDlg Prompter( queryHwnd(), PR_DLG);
  129.     SHORT i = plb->querySelection( LIT_NONE); // retrieve active Element
  130.     String strNew = "";
  131.     Prompter.setString( &strNew);
  132.     Prompter.setComment( "Enter new property:");
  133.     Prompter.create();
  134.     if( strNew.length()){
  135.       String *pStrg = new String( strNew);
  136.       strList.ins_after( (Pix)(retrievePix( i)), *pStrg);
  137.       SHORT j = plb->queryTopIndex();
  138.       printToListBox();
  139.       plb->setTopIndex( j);
  140.       plb->selectItem( i+1, TRUE);
  141.     } else {
  142.       SHORT j = plb->queryTopIndex();
  143.       printToListBox();
  144.       plb->setTopIndex( j);
  145.       plb->selectItem( i, TRUE);
  146.     }
  147.       }
  148.       break;
  149.     case SB_DELETE_BUTT:
  150.       {    
  151.     SHORT i = plb->querySelection( LIT_NONE); // retrieve active Element
  152.     Pix p = i ? (Pix)retrievePix(i-1) : NULL;
  153.     strList.del_after( p);
  154.     printToListBox();
  155.     setState(0);
  156.       }
  157.       break;
  158.     case SB_OK_BUTT:        // OK Button Pressed
  159.       //DosBeep( 100, 100);
  160.       *pList = strList;        // copy local list to original list
  161.       destroy();
  162.       break;
  163.     case SB_CANCEL_BUTT:    // Cancel Button Pressed
  164.       destroy();
  165.       break;
  166.     }
  167.   }
  168.   *fDoDefault = FALSE;
  169.   return 0;
  170. }
  171.  
  172. // 
  173. // service methods for SingleBrowser
  174. //
  175.  
  176. // void SingleBrowser::printToListBox( void)
  177. //
  178. // This method prints the contents of the local StrDLList 
  179. // to the list box
  180.  
  181. VOID SingleBrowser::printToListBox( VOID)
  182. {
  183.   plb->enableUpdate( FALSE);    // disable update for performance reasons
  184.   plb->deleteAll();
  185.   for(Pix i = strList.first();
  186.       i != 0;
  187.       strList.next(i)) 
  188.     plb->insertItem( LIT_END, (char*)(strList(i)));
  189.   plb->show( TRUE);        // enable update and force redraw
  190. }
  191.  
  192. // String* SingleBrowser::retrieve( SHORT iItem)
  193. //
  194. // This method returns a pointer to the String at index iItem.
  195. // The pointer is valid only for exisiting values of iItem.
  196.  
  197. String* SingleBrowser::retrieve( SHORT iItem)
  198.   SHORT s;
  199.   Pix   i;
  200.  
  201.   for(s=0, i=strList.first(); s != iItem; s++)
  202.     strList.next(i);
  203.   return &(strList(i));
  204. }
  205.  
  206. Pix SingleBrowser::retrievePix( SHORT iItem)
  207. {
  208.   SHORT s;
  209.   Pix   i;
  210.  
  211.   for(s=0, i=strList.first(); s != iItem; s++)
  212.     strList.next(i);
  213.   return (i);
  214. }
  215.  
  216. // VOID SingleBrowser::setState( SHORT sState)
  217. //
  218. // This method changes the state of the Buttons in the
  219. // dialog according to the transmitted state.
  220. // Only the state of the Insert, Append and Delete Buttons is
  221. // changed.
  222.  
  223. VOID SingleBrowser::setState( SHORT sState)
  224. {
  225.   switch( sState) {
  226.   case 0:     
  227.     plb->enable( TRUE);
  228.     pbtInsert->enable( FALSE);
  229.     pbtAppend->enable( FALSE);
  230.     pbtDelete->enable( FALSE);
  231.     break;
  232.  
  233.   case 1:
  234.     plb->enable( TRUE);
  235.     pbtInsert->enable( TRUE);
  236.     pbtAppend->enable( TRUE);
  237.     pbtDelete->enable( TRUE);
  238.     break;
  239.   }
  240. }
  241.  
  242.  
  243. VOID SingleBrowser::editEntry( VOID)
  244. { SHORT iSelect;
  245.   SHORT iTopIndex;
  246.   
  247.   PrompterDlg Prompter( HWND_DESKTOP, PR_DLG);
  248.   String test = "Hallo";
  249.   CHAR   *szComment="Edit the line, press OK to accept the change.";
  250.   iTopIndex = plb->queryTopIndex();
  251.   // find the selected line
  252.   Prompter.setString
  253.     (retrieve(iSelect=plb->querySelection( LIT_NONE)));
  254.   Prompter.setComment( szComment);
  255.   Prompter.create();
  256.   // changes are detected by parent in lbmain
  257.   //if( Prompter.fChanged) fChanged = TRUE;
  258.   printToListBox();
  259.   plb->setTopIndex( iTopIndex);
  260.   plb->selectItem( iSelect, TRUE);
  261.   setState( 1);
  262. }
  263.