home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / dos / listz21s.exe / LZSET10S.RAR / LZS_CHAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-25  |  3.7 KB  |  147 lines

  1. /*
  2.  * This file is part of LZSETUP (Configuration program for Listerz)
  3.  *
  4.  * Copyright (c) 1997 Branislav L. Slantchev (gargoyle)
  5.  * A fine product of Silicon Creations, Inc.
  6.  *
  7.  * This file is released under the terms and conditions of the GNU
  8.  * General Public License Version 2. The full text of the license is
  9.  * supplied in the Copying.Doc file included with this archive. This
  10.  * free software comes with absolutely no warranty, as outlined in the
  11.  * licensing text. You are not allowed to remove this copyright notice.
  12.  *
  13.  * Contact: Branislav L. Slantchev at 73023.262@compuserve.com
  14. */
  15. #include <string.h>
  16. #include <oppick.h>
  17. #include <opstring.h>
  18.  
  19. extern ColorSet   lz_Colors;
  20. extern FrameArray lz_FrameType;
  21. extern boolean    lz_Dirty;
  22.  
  23. typedef char     csArray[256][6];
  24. typedef csArray* csArrayPtr;
  25.  
  26. class CharSelector: public PickList
  27. {
  28.     csArrayPtr csItemPtr;
  29.     void csItemStringPrim(word I, char* IString);
  30.  
  31. public:
  32.     boolean Init(byte X1, byte Y1, byte X2, byte Y2);
  33.  
  34.     boolean      InitCustom(byte X1, byte Y1, byte X2, byte Y2,
  35.                             ColorSet &Colors, long Options);
  36.     virtual void Done();
  37.     virtual void ItemString(word, pkMode mode, pkItemType &type, char* s);
  38.     void         SetChar(char Ch);
  39.     char         GetChar();
  40. };
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CharSelector methods
  44. /////////////////////////////////////////////////////////////////////////////
  45. boolean
  46. CharSelector::Init(byte X1, byte Y1, byte X2, byte Y2)
  47. {
  48.     return CharSelector::InitCustom(X1,Y1,X2,Y2,lz_Colors,DefWindowOptions);
  49. }
  50.  
  51. boolean
  52. CharSelector::InitCustom(byte X1, byte Y1, byte X2, byte Y2,
  53.                          ColorSet &Colors, long Options)
  54. {
  55.     word I;
  56.     csItemPtr = NULL;
  57.  
  58.     if( !PickList::InitAbstract(X1, Y1, X2, Y2, Colors, Options, 9, 256,
  59.                                 PickSnaking, SingleChoice) )
  60.     {
  61.         return FALSE;
  62.     }
  63.  
  64.     // try to pre-calculate the strings and store them on the heap
  65.     if( GetMemCheck((void *&)csItemPtr, sizeof(csArray)) )
  66.     {
  67.         for( I = 0; I <= 255; I++ ) csItemStringPrim(I, (*csItemPtr)[I]);
  68.     }
  69.  
  70.     return TRUE;
  71. }
  72.  
  73. void
  74. CharSelector::Done()
  75. {
  76.     FreeMemCheck(csItemPtr);
  77.     PickList::Done();
  78. }
  79.  
  80. void
  81. CharSelector::ItemString(word Item, pkMode Mode, pkItemType &IType,
  82.                          char *IString)
  83. {
  84.     if( csItemPtr != NULL ) strcpy(IString, (*csItemPtr)[Item-1]);
  85.     else csItemStringPrim(Item-1, IString);
  86.  
  87.     if( pkOptionsAreOn(pkSetDefault) )
  88.         if( Item == GetDefaultChoice() )
  89.             IType = pkAlternate;
  90.     Insert(" ", IString, 0);
  91.     strcat(IString, " ");
  92. }
  93.  
  94. void
  95. CharSelector::SetChar(char Ch)
  96. {
  97.     SetInitialChoice(((byte)Ch)+1);
  98. }
  99.  
  100. char
  101. CharSelector::GetChar()
  102. {
  103.     return (char)GetLastChoice() - 1;
  104. }
  105.  
  106. void
  107. CharSelector::csItemStringPrim(word index, char *s)
  108. {
  109.     switch( (char)index )
  110.     {
  111.         case  00: strcpy(s, "0   0"); break;
  112.         case ' ': strcpy(s, "32 sp"); break;
  113.         default : sprintf(s, "%-4d%c", index, (char)index);
  114.     }
  115. }
  116.  
  117. ////////////////////////////////////////////////////////////////////////////
  118. // the public function called by the setup program
  119. ////////////////////////////////////////////////////////////////////////////
  120. void
  121. SelectSymbol(byte *symbol, char *header)
  122. {
  123.     CharSelector CS;
  124.     long         options = DefWindowOptions | wBordered;
  125.  
  126.     if( CS.InitCustom(29, 4, 74, 21, lz_Colors, options) )
  127.     {
  128.         CS.EnableExplosions(15);
  129.         CS.wFrame.SetFrameType(lz_FrameType);
  130.         CS.wFrame.AddHeader(header, heTR);
  131.         CS.wFrame.AddShadow(shBR, shSeeThru);
  132.         CS.wFrame.AddCustomScrollBar(frBB,0,MaxLongInt,1,1,'▓','░',lz_Colors);
  133.         CS.SetChar(*symbol);
  134.         CS.Draw();
  135.         CS.Process();
  136.  
  137.         if( ccQuit != CS.GetLastCommand() && *symbol != CS.GetChar() )
  138.         {
  139.             *symbol = CS.GetChar();
  140.             lz_Dirty = TRUE;
  141.         }
  142.  
  143.         CS.Erase();
  144.         CS.Done();
  145.     }
  146. }
  147.