home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / tvision / colorsel.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  10KB  |  451 lines

  1. /*
  2.  * colorsel.h
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #if !defined( __COLOR_COMMAND_CODES )
  13. #define __COLOR_COMMAND_CODES
  14.  
  15. const
  16.   cmColorForegroundChanged = 71,
  17.   cmColorBackgroundChanged = 72,
  18.   cmColorSet               = 73,
  19.   cmNewColorItem           = 74,
  20.   cmNewColorIndex          = 75,
  21.   cmSaveColorIndex         = 76;
  22.  
  23. #endif  // __COLOR_COMMAND_CODES
  24.  
  25. class TColorItem;
  26. class TColorGroup;
  27.  
  28. TColorItem& operator + ( TColorItem& i1, TColorItem& i2 );
  29. TColorGroup& operator + ( TColorGroup& g, TColorItem& i );
  30. TColorGroup& operator + ( TColorGroup& g1, TColorGroup& g2 );
  31.  
  32. #if defined( Uses_TColorItem ) && !defined( __TColorItem )
  33. #define __TColorItem
  34.  
  35. class TColorGroup;
  36.  
  37. class TColorItem
  38. {
  39.  
  40. public:
  41.  
  42.     TColorItem( const char *nm, uchar idx, TColorItem *nxt = 0 );
  43.     virtual ~TColorItem();
  44.     const char *name;
  45.     uchar index;
  46.     TColorItem *next;
  47.     friend TColorGroup& operator + ( TColorGroup&, TColorItem& );
  48.     friend TColorItem& operator + ( TColorItem& i1, TColorItem& i2 );
  49.  
  50. };
  51.  
  52. #endif  // Uses_TColorItem
  53.  
  54. #if defined( Uses_TColorGroup ) && !defined( __TColorGroup )
  55. #define __TColorGroup
  56.  
  57. class TColorItem;
  58.  
  59. class TColorGroup
  60. {
  61.  
  62. public:
  63.  
  64.     TColorGroup( const char *nm, TColorItem *itm = 0, TColorGroup *nxt = 0 );
  65.     virtual ~TColorGroup();
  66.     const char *name;
  67.     uchar index;
  68.     TColorItem *items;
  69.     TColorGroup *next;
  70.     friend TColorGroup& operator + ( TColorGroup&, TColorItem& );
  71.     friend TColorGroup& operator + ( TColorGroup& g1, TColorGroup& g2 );
  72.  
  73.  
  74. };
  75.  
  76. class TColorIndex
  77. {
  78. public:
  79.     uchar groupIndex;
  80.     uchar colorSize;
  81.     uchar colorIndex[256];
  82. };
  83.  
  84.  
  85. #endif  // Uses_TColorGroup
  86.  
  87. #if defined( Uses_TColorSelector ) && !defined( __TColorSelector )
  88. #define __TColorSelector
  89.  
  90. class TRect;
  91. class TEvent;
  92.  
  93. class TColorSelector : public TView
  94. {
  95.  
  96. public:
  97.  
  98.     enum ColorSel { csBackground, csForeground };
  99.  
  100.     TColorSelector( const TRect& Bounds, ColorSel ASelType );
  101.     virtual void draw();
  102.     virtual void handleEvent( TEvent& event );
  103.     static /*const*/ char icon;
  104.  
  105. protected:
  106.  
  107.     uchar color;
  108.     ColorSel selType;
  109.  
  110. private:
  111.  
  112.     void colorChanged();
  113.  
  114. //    static const char icon;
  115.  
  116.     virtual const char *streamableName() const
  117.         { return name; }
  118.  
  119. protected:
  120.  
  121.     TColorSelector( StreamableInit );
  122.     virtual void write( opstream& );
  123.     virtual void *read( ipstream& );
  124.  
  125. public:
  126.  
  127.     static const char * const name;
  128.     static TStreamable *build();
  129.  
  130. };
  131.  
  132. inline ipstream& operator >> ( ipstream& is, TColorSelector& cl )
  133.     { return is >> (TStreamable&)cl; }
  134. inline ipstream& operator >> ( ipstream& is, TColorSelector*& cl )
  135.     { return is >> (void *&)cl; }
  136.  
  137. inline opstream& operator << ( opstream& os, TColorSelector& cl )
  138.     { return os << (TStreamable&)cl; }
  139. inline opstream& operator << ( opstream& os, TColorSelector* cl )
  140.     { return os << (TStreamable *)cl; }
  141.  
  142. #endif  // Uses_TColorSelector
  143.  
  144.  
  145. #if defined( Uses_TMonoSelector ) && !defined( __TMonoSelector )
  146. #define __TMonoSelector
  147.  
  148. class TRect;
  149. class TEvent;
  150.  
  151. class TMonoSelector : public TCluster
  152. {
  153.  
  154. public:
  155.  
  156.     TMonoSelector( const TRect& bounds );
  157.     virtual void draw();
  158.     virtual void handleEvent( TEvent& event );
  159.     virtual Boolean mark( int item );
  160.     void newColor();
  161.     virtual void press( int item );
  162.     void movedTo( int item );
  163.  
  164. private:
  165.  
  166.     static const char * button;
  167.     static const char * normal;
  168.     static const char * highlight;
  169.     static const char * underline;
  170.     static const char * inverse;
  171.  
  172.     virtual const char *streamableName() const
  173.         { return name; }
  174.  
  175. protected:
  176.  
  177.     TMonoSelector( StreamableInit );
  178.  
  179. public:
  180.  
  181.     static const char * const name;
  182.     static TStreamable *build();
  183.  
  184. };
  185.  
  186. inline ipstream& operator >> ( ipstream& is, TMonoSelector& cl )
  187.     { return is >> (TStreamable&)cl; }
  188. inline ipstream& operator >> ( ipstream& is, TMonoSelector*& cl )
  189.     { return is >> (void *&)cl; }
  190.  
  191. inline opstream& operator << ( opstream& os, TMonoSelector& cl )
  192.     { return os << (TStreamable&)cl; }
  193. inline opstream& operator << ( opstream& os, TMonoSelector* cl )
  194.     { return os << (TStreamable *)cl; }
  195.  
  196. #endif  // Uses_TMonoSelector
  197.  
  198. #if defined( Uses_TColorDisplay ) && !defined( __TColorDisplay )
  199. #define __TColorDisplay
  200.  
  201. class TRect;
  202. class TEvent;
  203.  
  204. class TColorDisplay : public TView
  205. {
  206.  
  207. public:
  208.  
  209.     TColorDisplay( const TRect& bounds, const char *aText );
  210.     virtual ~TColorDisplay();
  211.     virtual void draw();
  212.     virtual void handleEvent( TEvent& event );
  213.     virtual void setColor( uchar *aColor );
  214.  
  215. protected:
  216.  
  217.     uchar *color;
  218.     const char *text;
  219.  
  220. private:
  221.  
  222.     virtual const char *streamableName() const
  223.         { return name; }
  224.  
  225. protected:
  226.  
  227.     TColorDisplay( StreamableInit );
  228.     virtual void write( opstream& );
  229.     virtual void *read( ipstream& );
  230.  
  231. public:
  232.  
  233.     static const char * const name;
  234.     static TStreamable *build();
  235.  
  236. };
  237.  
  238. inline ipstream& operator >> ( ipstream& is, TColorDisplay& cl )
  239.     { return is >> (TStreamable&)cl; }
  240. inline ipstream& operator >> ( ipstream& is, TColorDisplay*& cl )
  241.     { return is >> (void *&)cl; }
  242.  
  243. inline opstream& operator << ( opstream& os, TColorDisplay& cl )
  244.     { return os << (TStreamable&)cl; }
  245. inline opstream& operator << ( opstream& os, TColorDisplay* cl )
  246.     { return os << (TStreamable *)cl; }
  247.  
  248. #endif  // Uses_TColorDisplay
  249.  
  250.  
  251. #if defined( Uses_TColorGroupList ) && !defined( __TColorGroupList )
  252. #define __TColorGroupList
  253.  
  254. class TRect;
  255. class TScrollBar;
  256. class TColorGroup;
  257. class TColorItem;
  258.  
  259. class TColorGroupList : public TListViewer
  260. {
  261.  
  262. public:
  263.  
  264.     TColorGroupList( const TRect& bounds,
  265.                      TScrollBar *aScrollBar,
  266.                      TColorGroup *aGroups
  267.                    );
  268.     virtual ~TColorGroupList();
  269.     virtual void focusItem( short item );
  270.     virtual void getText( char *dest, short item, short maxLen );
  271.  
  272.     virtual void handleEvent(TEvent&);
  273.  
  274.  
  275. protected:
  276.  
  277.     TColorGroup *groups;
  278.  
  279. private:
  280.  
  281.     virtual const char *streamableName() const
  282.         { return name; }
  283.     static void writeItems( opstream&, TColorItem * );
  284.     static void writeGroups( opstream&, TColorGroup * );
  285.     static TColorItem *readItems( ipstream& );
  286.     static TColorGroup *readGroups( ipstream& );
  287.  
  288. protected:
  289.  
  290.     TColorGroupList( StreamableInit );
  291.     virtual void write( opstream& );
  292.     virtual void *read( ipstream& );
  293.  
  294. public:
  295.  
  296.     void setGroupIndex(uchar groupNum, uchar itemNum);
  297.     TColorGroup* getGroup(uchar groupNum);
  298.     uchar getGroupIndex(uchar groupNum);
  299.     uchar getNumGroups();
  300.     static const char * const name;
  301.     static TStreamable *build();
  302.  
  303. };
  304.  
  305. inline ipstream& operator >> ( ipstream& is, TColorGroupList& cl )
  306.     { return is >> (TStreamable&)cl; }
  307. inline ipstream& operator >> ( ipstream& is, TColorGroupList*& cl )
  308.     { return is >> (void *&)cl; }
  309.  
  310. inline opstream& operator << ( opstream& os, TColorGroupList& cl )
  311.     { return os << (TStreamable&)cl; }
  312. inline opstream& operator << ( opstream& os, TColorGroupList* cl )
  313.     { return os << (TStreamable *)cl; }
  314.  
  315. #endif  // Uses_TColorGroupList
  316.  
  317.  
  318. #if defined( Uses_TColorItemList ) && !defined( __TColorItemList )
  319. #define __TColorItemList
  320.  
  321. class TRect;
  322. class TScrollBar;
  323. class TColorItem;
  324. class TEvent;
  325.  
  326. class TColorItemList : public TListViewer
  327. {
  328.  
  329. public:
  330.  
  331.     TColorItemList( const TRect& bounds,
  332.                     TScrollBar *aScrollBar,
  333.                     TColorItem *aItems
  334.                   );
  335.     virtual void focusItem( short item );
  336.     virtual void getText( char *dest, short item, short maxLen );
  337.     virtual void handleEvent( TEvent& event );
  338.  
  339. protected:
  340.  
  341.     TColorItem *items;
  342.  
  343. private:
  344.  
  345.     virtual const char *streamableName() const
  346.         { return name; }
  347.  
  348. protected:
  349.  
  350.     TColorItemList( StreamableInit );
  351.  
  352. public:
  353.  
  354.     static const char * const name;
  355.     static TStreamable *build();
  356.  
  357. };
  358.  
  359. inline ipstream& operator >> ( ipstream& is, TColorItemList& cl )
  360.     { return is >> (TStreamable&)cl; }
  361. inline ipstream& operator >> ( ipstream& is, TColorItemList*& cl )
  362.     { return is >> (void *&)cl; }
  363.  
  364. inline opstream& operator << ( opstream& os, TColorItemList& cl )
  365.     { return os << (TStreamable&)cl; }
  366. inline opstream& operator << ( opstream& os, TColorItemList* cl )
  367.     { return os << (TStreamable *)cl; }
  368.  
  369. #endif  // Uses_TColorItemList
  370.  
  371.  
  372. #if defined( Uses_TColorDialog ) && !defined( __TColorDialog )
  373. #define __TColorDialog
  374.  
  375. class TColorGroup;
  376. class TEvent;
  377. class TColorDisplay;
  378. class TColorGroupList;
  379. class TLabel;
  380. class TColorSelector;
  381. class TMonoSelector;
  382. class TPalette;
  383.  
  384. class TColorDialog : public TDialog
  385. {
  386.  
  387. public:
  388.  
  389.     TColorDialog( TPalette *aPalette, TColorGroup *aGroups );
  390.     ~TColorDialog();
  391.     virtual ushort dataSize();
  392.     virtual void getData( void *rec );
  393.     virtual void handleEvent( TEvent& event );
  394.     virtual void setData( void *rec);
  395.  
  396.     TPalette *pal;
  397.  
  398. protected:
  399.  
  400.     TColorDisplay *display;
  401.     TColorGroupList *groups;
  402.     TLabel *forLabel;
  403.     TColorSelector *forSel;
  404.     TLabel *bakLabel;
  405.     TColorSelector *bakSel;
  406.     TLabel *monoLabel;
  407.     TMonoSelector *monoSel;
  408.     uchar groupIndex;
  409.  
  410. private:
  411.  
  412.     static const char * colors;
  413.     static const char * groupText;
  414.     static const char * itemText;
  415.     static const char * forText;
  416.     static const char * bakText;
  417.     static const char * textText;
  418.     static const char * colorText;
  419.     static const char * okText;
  420.     static const char * cancelText;
  421.  
  422.     virtual const char *streamableName() const
  423.         { return name; }
  424.  
  425. protected:
  426.  
  427.     TColorDialog( StreamableInit );
  428.     virtual void write( opstream& );
  429.     virtual void *read( ipstream& );
  430.  
  431. public:
  432.  
  433.     void getIndexes(TColorIndex*&);
  434.     void setIndexes(TColorIndex*&);
  435.     static const char * const name;
  436.     static TStreamable *build();
  437.  
  438. };
  439.  
  440. inline ipstream& operator >> ( ipstream& is, TColorDialog& cl )
  441.     { return is >> (TStreamable&)cl; }
  442. inline ipstream& operator >> ( ipstream& is, TColorDialog*& cl )
  443.     { return is >> (void *&)cl; }
  444.  
  445. inline opstream& operator << ( opstream& os, TColorDialog& cl )
  446.     { return os << (TStreamable&)cl; }
  447. inline opstream& operator << ( opstream& os, TColorDialog* cl )
  448.     { return os << (TStreamable *)cl; }
  449.  
  450. #endif  // TColorDialog
  451.