home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp11demo.zip / rtlsrc.rar / tv / COLORSEL.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-08  |  6KB  |  236 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Turbo Pascal Version 7.0                        }
  4. {       Turbo Vision Unit                               }
  5. {                                                       }
  6. {       Copyright (c) 1992 Borland International        }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. {$PureInt+}
  11. unit ColorSel;
  12.  
  13. {$X+,I-,S-,Cdecl-}
  14.  
  15. interface
  16.  
  17. uses Objects, Drivers, Views, Dialogs, Use32;
  18.  
  19. const
  20.   cmColorForegroundChanged = 71;
  21.   cmColorBackgroundChanged = 72;
  22.   cmColorSet               = 73;
  23.   cmNewColorItem           = 74;
  24.   cmNewColorIndex          = 75;
  25.   cmSaveColorIndex         = 76;
  26.  
  27. type
  28.  
  29.   { TColorItem }
  30.  
  31.   PColorItem = ^TColorItem;
  32.   TColorItem = record
  33.     Name: PString;
  34.     Index: Byte;
  35.     Next: PColorItem;
  36.   end;
  37.  
  38.   { TColorGroup }
  39.  
  40.   PColorGroup = ^TColorGroup;
  41.   TColorGroup = record
  42.     Name:  PString;
  43.     Index: Byte;
  44.     Items: PColorItem;
  45.     Next:  PColorGroup;
  46.   end;
  47.  
  48.   { TColorIndexes }
  49.  
  50.   PColorIndex = ^TColorIndex;
  51.   TColorIndex = record
  52.     GroupIndex: byte;
  53.     ColorSize: byte;
  54.     ColorIndex: array[0..255] of byte;
  55.   end;
  56.  
  57.   { TColorSelector }
  58.  
  59.   TColorSel = (csBackground, csForeground);
  60.  
  61.   PColorSelector = ^TColorSelector;
  62.   TColorSelector = object(TView)
  63.     Color: Byte;
  64.     SelType: TColorSel;
  65.     constructor Init(var Bounds: TRect; ASelType: TColorSel);
  66.     constructor Load(var S: TStream);
  67.     procedure Draw; virtual;
  68.     procedure HandleEvent(var Event: TEvent); virtual;
  69.     procedure Store(var S: TStream);
  70.   end;
  71.  
  72.   { TMonoSelector }
  73.  
  74.   PMonoSelector = ^TMonoSelector;
  75.   TMonoSelector = object(TCluster)
  76.     constructor Init(var Bounds: TRect);
  77.     procedure Draw; virtual;
  78.     procedure HandleEvent(var Event: TEvent); virtual;
  79.     function Mark(Item: Integer): Boolean; virtual;
  80.     procedure NewColor;
  81.     procedure Press(Item: Integer); virtual;
  82.     procedure MovedTo(Item: Integer); virtual;
  83.   end;
  84.  
  85.   { TColorDisplay }
  86.  
  87.   PColorDisplay = ^TColorDisplay;
  88.   TColorDisplay = object(TView)
  89.     Color: ^Byte;
  90.     Text: PString;
  91.     constructor Init(var Bounds: TRect; AText: PString);
  92.     constructor Load(var S: TStream);
  93.     destructor Done; virtual;
  94.     procedure Draw; virtual;
  95.     procedure HandleEvent(var Event: TEvent); virtual;
  96.     procedure SetColor(var AColor: Byte); virtual;
  97.     procedure Store(var S: TStream);
  98.   end;
  99.  
  100.   { TColorGroupList }
  101.  
  102.   PColorGroupList = ^TColorGroupList;
  103.   TColorGroupList = object(TListViewer)
  104.     Groups: PColorGroup;
  105.     constructor Init(var Bounds: TRect; AScrollBar: PScrollBar;
  106.       AGroups: PColorGroup);
  107.     constructor Load(var S: TStream);
  108.     destructor Done; virtual;
  109.     procedure FocusItem(Item: Integer); virtual;
  110.     function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  111.     procedure HandleEvent(var Event: TEvent); virtual;
  112.     procedure Store(var S: TStream);
  113.     procedure SetGroupIndex(GroupNum, ItemNum: Byte);
  114.     function GetGroup(GroupNum: Byte): PColorGroup;
  115.     function GetGroupIndex(GroupNum: Byte): Byte;
  116.     function GetNumGroups: byte;
  117.   end;
  118.  
  119.   { TColorItemList }
  120.  
  121.   PColorItemList = ^TColorItemList;
  122.   TColorItemList = object(TListViewer)
  123.     Items: PColorItem;
  124.     constructor Init(var Bounds: TRect; AScrollBar: PScrollBar;
  125.       AItems: PColorItem);
  126.     procedure FocusItem(Item: Integer); virtual;
  127.     function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  128.     procedure HandleEvent(var Event: TEvent); virtual;
  129.   end;
  130.  
  131.   { TColorDialog }
  132.  
  133.   PColorDialog = ^TColorDialog;
  134.   TColorDialog = object(TDialog)
  135.     GroupIndex: byte;
  136.     Display: PColorDisplay;
  137.     Groups: PColorGroupList;
  138.     ForLabel: PLabel;
  139.     ForSel: PColorSelector;
  140.     BakLabel: PLabel;
  141.     BakSel: PColorSelector;
  142.     MonoLabel: PLabel;
  143.     MonoSel: PMonoSelector;
  144.     Pal: TPalette;
  145.     constructor Init(APalette: TPalette; AGroups: PColorGroup);
  146.     constructor Load(var S: TStream);
  147.     function DataSize: Word; virtual;
  148.     procedure GetData(var Rec); virtual;
  149.     procedure HandleEvent(var Event: TEvent); virtual;
  150.     procedure SetData(var Rec); virtual;
  151.     procedure Store(var S: TStream);
  152.     procedure GetIndexes(var Colors: PColorIndex);
  153.     procedure SetIndexes(var Colors: PColorIndex);
  154.   end;
  155.  
  156. { Pointer to saved color list item indexes }
  157. const
  158.   ColorIndexes: PColorIndex = nil;
  159.  
  160. { Load and Store Palette routines }
  161.  
  162. procedure StoreIndexes(var S: TStream);
  163. procedure LoadIndexes(var S: TStream);
  164.  
  165. { Color list building routines }
  166.  
  167. function ColorItem(const Name: String; Index: Byte;
  168.   Next: PColorItem): PColorItem;
  169. function ColorGroup(const Name: String; Items: PColorItem;
  170.   Next: PColorGroup): PColorGroup;
  171.  
  172. { Standard color items functions }
  173.  
  174. function DesktopColorItems(const Next: PColorItem): PColorItem;
  175. function MenuColorItems(const Next: PColorItem): PColorItem;
  176. function DialogColorItems(Palette: Word; const Next: PColorItem): PColorItem;
  177. function WindowColorItems(Palette: Word; const Next: PColorItem): PColorItem;
  178.  
  179. { ColorSel registration procedure }
  180.  
  181. procedure RegisterColorSel;
  182.  
  183. { Stream registration records }
  184.  
  185. const
  186.   RColorSelector: TStreamRec = (
  187.      ObjType: 21;
  188.      VmtLink: Ofs(TypeOf(TColorSelector)^);
  189.      Load:    @TColorSelector.Load;
  190.      Store:   @TColorSelector.Store
  191.   );
  192.  
  193. const
  194.   RMonoSelector: TStreamRec = (
  195.      ObjType: 22;
  196.      VmtLink: Ofs(TypeOf(TMonoSelector)^);
  197.      Load:    @TMonoSelector.Load;
  198.      Store:   @TMonoSelector.Store
  199.   );
  200.  
  201. const
  202.   RColorDisplay: TStreamRec = (
  203.      ObjType: 23;
  204.      VmtLink: Ofs(TypeOf(TColorDisplay)^);
  205.      Load:    @TColorDisplay.Load;
  206.      Store:   @TColorDisplay.Store
  207.   );
  208.  
  209. const
  210.   RColorGroupList: TStreamRec = (
  211.      ObjType: 24;
  212.      VmtLink: Ofs(TypeOf(TColorGroupList)^);
  213.      Load:    @TColorGroupList.Load;
  214.      Store:   @TColorGroupList.Store
  215.   );
  216.  
  217. const
  218.   RColorItemList: TStreamRec = (
  219.      ObjType: 25;
  220.      VmtLink: Ofs(TypeOf(TColorItemList)^);
  221.      Load:    @TColorItemList.Load;
  222.      Store:   @TColorItemList.Store
  223.   );
  224.  
  225. const
  226.   RColorDialog: TStreamRec = (
  227.      ObjType: 26;
  228.      VmtLink: Ofs(TypeOf(TColorDialog)^);
  229.      Load:    @TColorDialog.Load;
  230.      Store:   @TColorDialog.Store
  231.   );
  232.  
  233. implementation
  234.  
  235. end.
  236.