home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / tvpal / tvpal.txt < prev   
Encoding:
INI File  |  1992-03-09  |  3.5 KB  |  111 lines

  1. [-----------------]
  2. |  TVPAL Package  |
  3. [-----------------]
  4.  
  5. Copyright (c) 1992 CC Software
  6. All rights reserved
  7.  
  8. Author: Craig Nelson
  9.         71151,3264
  10.  
  11.  
  12. TVPAL.ZIP Contents
  13. ------------------
  14.  
  15. The following files should be in TVPAL.ZIP:
  16.  
  17.     TVPAL.H         : Header file for inclusion into TVision programs
  18.     TVPAL.CPP       : Source code for the TStreamPalette class
  19.     TVPAL.TXT       : Description of the class in general.
  20.     EXAMPLE.CPP     : Example program for using TStreamPalette
  21.  
  22.  
  23. Please make sure you have these files.  If get some other version
  24. feel free to write the author and ask for the complete package.
  25.  
  26.  
  27. Description
  28. -----------
  29. Streamable palette is something Borland left out of the Turbo Vision
  30. hierarchy.  Through multiple inheritence we can solve this problem
  31. with the class TStreamPalette.  Since it is derived from both the
  32. TPalette and TStreamable classes, you can freely use all the members
  33. of both in your applications.  No new members are added so for complete
  34. descriptions on what TStreamPalette is capable of see the source code,
  35. and the documentation on TPalette and TStreamable from Borland
  36.  
  37.  
  38. Streamablilty
  39. -------------
  40. Suppose you wanted to store serveral versions of the application
  41. palette on an object stream, for example, to have serveral predefined
  42. color schemes available to the user.  Using the standard TPalette and
  43. regular streams requires more work than you deserve to go through.
  44. TStreamPalette solves this problem.  For example, say you want to
  45. save the application palette on a stream.  Under normal stream
  46. operation this is not at all intuitive. However, using TStreamPalette,
  47. the code (assuming it is somewhere in the TApplication derived class
  48. members) simplifies to the following:
  49.  
  50. TApp::savePalette( const char *fileName )
  51. {
  52.   fpstream fp( fileName, ios::binary | ios::out );
  53.   TStreamablePalette *sp;
  54.  
  55.   if ( fp.good() )
  56.   {
  57.      sp = new TStreamPalette( application->getPalette() );
  58.      if ( sp )
  59.      {
  60.         fp << sp;
  61.         delete sp;
  62.      }
  63.   }
  64. };
  65. // --------------------------------------------------------------------
  66.  
  67.  
  68.  
  69. Reading the object written in the above code and assigning it to the
  70. application would simplify to the following:
  71.  
  72.  
  73. TApp::readPalette( const char *fileName )
  74. {
  75.   fpstream fp( fileName, ios::binary | ios::in | ios::nocreate )
  76.   TStreamPalette *sp;
  77.  
  78.   if ( fp.good() )
  79.   (
  80.      fp >> sp;
  81.      if ( sp )
  82.      {
  83.         application->getPalette() = *sp;
  84.         delete sp;
  85.      }
  86.   }
  87. };
  88. // --------------------------------------------------------------------
  89.  
  90.  
  91.  
  92.  
  93. Example Program
  94. ---------------
  95. The example program uses the TVPAL object definitions for a resource
  96. file that can store the application palette.  Please make note that
  97. if you are using the TStreamPalette object class and are actually
  98. performing stream IO (why else would you use it) the RStreamPalette
  99. stream registration record MUST be __link() 'ed in to any source
  100. module calling for this IO.  These aren't my rules; their Borlands :)
  101.  
  102. Feel free to play with the example, possibly adding the functionality
  103. for the user to create different color schemes and save them in the
  104. resource file.  A TListBox in a TDialog object to save/restore color
  105. schemes would make for a nice touch, and I would be interested in what
  106. you all think.
  107.  
  108. Above all, have FUN.  Turbo Vision is easy to break, but if you're
  109. carefull you can create wonderfull user options with just a few
  110. program lines.
  111.