home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / glbcolor.hpp < prev    next >
C/C++ Source or Header  |  1999-07-13  |  4KB  |  129 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1996, 1999  Paul Elliott
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     Paul Elliott
  20.     PMB # 181
  21.     11900 Metric Blvd Ste. J
  22.     Austin Tx 78758-3117
  23.     pelliott@io.com
  24. */
  25. #ifndef GLBCOLOR
  26. #define GLBCOLOR
  27. #include <ibcolor.hpp>
  28.  
  29. #include "Ltper.hpp"
  30. #include "LtProf.hpp"
  31.  
  32.  
  33. // pcolor is the essance of a IBaseColor
  34. // can be constructed from a IBaseColor and
  35. // conversion operator allows it to convert to one.
  36. struct pcolor
  37. {
  38.    CharIntensity fRed, fGreen, fBlue, fOpacity;
  39.    pcolor( const IBaseColor color )
  40.    {
  41.       fRed    = color.redMix();
  42.       fGreen  = color.greenMix();
  43.       fBlue   = color.blueMix();
  44.       fOpacity= color.opacity();
  45.    };
  46.    pcolor( const IColor color )
  47.    {
  48.       fRed    = color.redMix();
  49.       fGreen  = color.greenMix();
  50.       fBlue   = color.blueMix();
  51.       fOpacity= color.opacity();
  52.    };
  53.    // default constructor
  54.    pcolor( )
  55.    {
  56.       fRed = fGreen = fBlue = fOpacity = 0;
  57.    };
  58.    operator IBaseColor() const
  59.    {
  60.       return IBaseColor( fRed, fGreen, fBlue, fOpacity );
  61.    };
  62.    operator IColor() const
  63.    {
  64.       return IColor( fRed, fGreen, fBlue, fOpacity );
  65.    };
  66. };
  67.  
  68.  
  69. // a source of IColors.
  70. // Can create IColor from a stored pcolor.
  71. typedef ExternalExistance<IColor, pcolor, pcolor > ExternalColor;
  72.  
  73.  
  74.  
  75. // a source of IColor from application profiles.
  76.  
  77. class ColorStore
  78. {
  79.      private:
  80.         ProfStorage storage;                  // Profile source.
  81.         ExternalColor color_existance;          // ExternalExistance from profile.
  82.      public:
  83.  
  84.         // constuctor. Profile from application name, user ini file.key=color.
  85.         ColorStore() :
  86.           storage("listpm","application_ini","color"),
  87.           // external existance from profile.
  88.           color_existance(storage)
  89.           {};
  90.  
  91.         // key attribute from storage
  92.         virtual void setKey( const IString& key )
  93.         {
  94.            storage.setKey( key );
  95.         };
  96.         virtual IString getKey() const
  97.         {
  98.            return storage.getKey();
  99.         };
  100.  
  101.         virtual void deleteKey()
  102.         {
  103.            storage.deleteKey();
  104.         };
  105.  
  106.         // returns true when key exists in profile.
  107.         Boolean colorExternal(void) { return color_existance.ExistsExternally(); };
  108.  
  109.         // get IColor stored externally.
  110.         operator IColor()
  111.         {
  112.            ExternalColor::Created created(color_existance);
  113. //         return created.operator IColor();
  114.            IColor rtn = created;
  115.            return rtn;
  116.  
  117.         };
  118.  
  119.         // Store IColor in profile.
  120.         ColorStore& operator<<(const IColor& color)
  121.         {
  122.            IColor tcolor(color);
  123.            color_existance << tcolor;
  124.            return *this;
  125.         };
  126. };
  127.  
  128.  
  129. #endif //GLBCOLOR