home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / diagen.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-11  |  8.4 KB  |  388 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // DialogClass
  8. // DiaPickList
  9. //
  10.  
  11. #include "fli.h"
  12. #include "elements.h"
  13. #include "colors.h"
  14.  
  15. #ifdef __BCPLUSPLUS__
  16. #pragma hdrstop
  17. #endif
  18.  
  19. #include <string.h>
  20.  
  21. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  22. //
  23. // DiaPickGeneric()
  24. //
  25. // Constructor for DiaPickGeneric
  26. //
  27. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  28.  
  29. DiaPickGeneric::DiaPickGeneric(int _X,int _Y,int _Width,int _Height,int &_Item,
  30.   int &_ItemCount) :
  31.   Item(_Item),
  32.   ItemCount(_ItemCount)
  33. {
  34.   X=_X;
  35.   Y=_Y;
  36.   Width=_Width+3;
  37.   Height=_Height;
  38.   ItemAtTopOfList=0;
  39.  
  40.   if (Item>=ItemCount)
  41.     Item=ItemCount-1;
  42.  
  43.   if (Item<0)
  44.     Item=0;
  45.  
  46.   if (Item>=ItemAtTopOfList+Height)
  47.     ItemAtTopOfList=(Item-Height)+1;
  48.  
  49.   if (Item<ItemAtTopOfList)
  50.     ItemAtTopOfList=Item;
  51. }
  52.  
  53. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  54. //
  55. // ScrollBar()
  56. //
  57. // Show the scroll bar
  58. //
  59. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  60.  
  61. void DiaPickGeneric::ScrollBar()
  62. {
  63.   int Avail=(Available()==CompleteEvent);
  64.  
  65.   Blaze->CharacterRepeaterDown(X+Width-1,Y,Height,
  66.     (Avail)?Colors.PickButton:Colors.DiaDeadLocator,0xb1);
  67.  
  68.   (*Blaze) (X+Width-1,Y)
  69.     << ((Avail)?Colors.PickButton:Colors.DiaDeadLocator)
  70.     << '\x1e';
  71.  
  72.   (*Blaze) (X+Width-1,Y+Height-1)
  73.     << '\x1f';
  74.  
  75.   if (ItemCount && ItemCount>Height)
  76.   {
  77.     int Calc=Height-2;
  78.  
  79.     int Determine=ItemCount/Calc;
  80.     int AnotherDetermine=0;
  81.     if (Item)
  82.       AnotherDetermine=Item/Determine;
  83.  
  84.     if (AnotherDetermine>=Height-2)
  85.       AnotherDetermine=Height-3;
  86.  
  87.     (*Blaze) (X+Width-1,Y+1+AnotherDetermine)
  88.       << '\xfe';
  89.   }
  90. }
  91.  
  92. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  93. //
  94. // Show()
  95. //
  96. // Show the pick list
  97. //
  98. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  99.  
  100. void DiaPickGeneric::Show()
  101. {
  102.   MouseHide();
  103.  
  104.   ScrollBar();
  105.  
  106.   int LocX, LocY, LocWide, LocHigh;
  107.  
  108.   int Avail=(Available()==CompleteEvent);
  109.  
  110.   if (Avail)
  111.   {
  112.     if (Item>=ItemCount)
  113.       Item=ItemCount-1;
  114.  
  115.     if (Item<0)
  116.       Item=0;
  117.  
  118.     if (ItemAtTopOfList+Height>ItemCount && ItemCount>Height)
  119.       ItemAtTopOfList=ItemCount-Height;
  120.  
  121.     if (Item>=ItemAtTopOfList+Height)
  122.       ItemAtTopOfList=(Item-Height)+1;
  123.  
  124.     if (Item<ItemAtTopOfList)
  125.       ItemAtTopOfList=Item;
  126.  
  127.     if (ItemCount<=Height && ItemAtTopOfList)
  128.       ItemAtTopOfList=0;
  129.  
  130.     Blaze->CharacterRepeaterDown(X+Width-2,Y,Height,Colors.PickText,' ');
  131.  
  132.     if (ItemCount<Height)
  133.       Blaze->EraseArea(X,Y+ItemCount,Width-1,Height-ItemCount,Colors.PickText);
  134.  
  135.     Blaze->WindowInformation(LocX,LocY,LocWide,LocHigh);
  136.  
  137.     BlazeClass Blaze;
  138.     Blaze.Window(LocX+X,LocY+Y,Width-2,Height);
  139.     +Blaze;
  140.     !Blaze;
  141.  
  142.     if (ItemCount)
  143.       for (int i=0;i<Height;i++)
  144.       {
  145.         char *ItemStore=GetItem(ItemAtTopOfList+i);
  146.  
  147.         Blaze (0,i)
  148.           << ((ItemAtTopOfList+i==Item)?Colors.PickMarked:Colors.PickText)
  149.           << ' '
  150.           << ItemStore;
  151.  
  152.         int Calc=(Width-3)-strlen(ItemStore);
  153.  
  154.         if (Calc>0)
  155.           Blaze.CharacterRepeater(strlen(ItemStore)+1,i,Calc,Colors.PickText,
  156.             ' ');
  157.  
  158.         if (ItemAtTopOfList+i>=ItemCount-1)
  159.           break;
  160.       }
  161.   }
  162.   else
  163.     Blaze->CharacterFill(X,Y,Width-1,Height,Colors.DiaDeadLocator,176);
  164.  
  165.   MouseShow();
  166. }
  167.  
  168. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  169. //
  170. // HighLight()
  171. //
  172. // Highlight the current pick list item
  173. //
  174. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  175.  
  176. void DiaPickGeneric::HighLight()
  177. {
  178.   MouseHide();
  179.   Blaze->LineAttribute(X,Y+Item-ItemAtTopOfList,Width-1,
  180.     Colors.PickHiLite);
  181.   Blaze->WindowGotoXY(X+1,Y+Item-ItemAtTopOfList);
  182.   MouseShow();
  183. }
  184.  
  185. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  186. //
  187. // EventHandler()
  188. //
  189. // Handles the events
  190. //
  191. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  192.  
  193. int DiaPickGeneric::EventHandler(int Event)
  194. {
  195.   if (Event==kbDown ||
  196.     (Event==ValidatedMousedEvent
  197.       && (MouseEvent&MouseLeftButtonRelease || MouseEvent&MouseHeldDown)
  198.       && MouseHorizontal==X+Width-1
  199.       && MouseVertical==Y+Height-1))
  200.   {
  201.     if (Item!=ItemCount-1 && ItemCount)
  202.     {
  203.       Item++;
  204.       if (Item-ItemAtTopOfList>=Height)
  205.       {
  206.         ItemAtTopOfList++;
  207.         Show();
  208.       }
  209.       else
  210.       {
  211.         MouseHide();
  212.         Blaze->LineAttribute(X,(Y+Item-ItemAtTopOfList)-1,Width-1,
  213.           Colors.PickText);
  214.         ScrollBar();
  215.         MouseShow();
  216.       }
  217.       HighLight();
  218.     }
  219.     return CompleteEvent;
  220.   }
  221.  
  222.   if (Event==kbUp ||
  223.     (Event==ValidatedMousedEvent
  224.       && (MouseEvent&MouseLeftButtonRelease || MouseEvent&MouseHeldDown)
  225.       && MouseHorizontal==X+Width-1
  226.       && MouseVertical==Y))
  227.   {
  228.     if (Item && ItemCount)
  229.     {
  230.       Item--;
  231.       if (Item<ItemAtTopOfList)
  232.       {
  233.         ItemAtTopOfList--;
  234.         Show();
  235.       }
  236.       else
  237.       {
  238.         MouseHide();
  239.         Blaze->LineAttribute(X,(Y+Item-ItemAtTopOfList)+1,Width-1,
  240.           Colors.PickText);
  241.         ScrollBar();
  242.         MouseShow();
  243.       }
  244.       HighLight();
  245.     }
  246.     return CompleteEvent;
  247.   }
  248.  
  249.   if (Event==ValidatedMousedEvent &&
  250.     (MouseEvent&MouseDoubleClick || MouseEvent&MouseLeftButtonRelease)
  251.     && MouseHorizontal<X+Width-1)
  252.   {
  253.     int Compute=(MouseVertical-Y)+ItemAtTopOfList;
  254.     if (Compute!=Item && Compute<ItemCount && ItemCount)
  255.     {
  256.       Item=Compute;
  257.       Show();
  258.       HighLight();
  259.     }
  260.     return (MouseEvent&MouseDoubleClick)?ClickEvent:CompleteEvent;
  261.   }
  262.  
  263.   if (MouseButtonStatus&LeftButton && ItemCount && ItemCount>Height && Height>3 &&
  264.     MouseHorizontal==X+Width-1 && MouseVertical>Y && MouseVertical<Y+Height-1)
  265.   {
  266.     int Block=MouseVertical-Y-1;
  267.  
  268.     int Calc=Height-2;
  269.  
  270.     int Determine=ItemCount/Calc;
  271.     int AnotherDetermine=Block*Determine;
  272.     if (AnotherDetermine>ItemCount)
  273.       AnotherDetermine=ItemCount-1;
  274.  
  275.     if (ItemAtTopOfList==AnotherDetermine)
  276.       return CompleteEvent;
  277.  
  278.     Item=AnotherDetermine;
  279.     ItemAtTopOfList=AnotherDetermine;
  280.  
  281.     if (MouseVertical==Y+Height-2)
  282.       Item=ItemCount-1;
  283.  
  284.     Show();
  285.     HighLight();
  286.  
  287.     return CompleteEvent;
  288.   }
  289.  
  290.   if (Event==kbHome)
  291.   {
  292.     ItemAtTopOfList=0;
  293.     Item=0;
  294.     Show();
  295.     HighLight();
  296.     return CompleteEvent;
  297.   }
  298.  
  299.   if (Event==kbEnd)
  300.   {
  301.     if (ItemCount>Height)
  302.     {
  303.       Item=ItemCount-1;
  304.       ItemAtTopOfList=Item-(Height-1);
  305.     }
  306.     else
  307.       Item=ItemCount-1;
  308.     Show();
  309.     HighLight();
  310.     return CompleteEvent;
  311.   }
  312.  
  313.   if (Event==kbPgUp)
  314.   {
  315.     if (ItemCount>Height)
  316.     {
  317.       ItemAtTopOfList-=Height;
  318.       if (ItemAtTopOfList<0)
  319.         ItemAtTopOfList=0;
  320.       Item=ItemAtTopOfList;
  321.       Show();
  322.       HighLight();
  323.       return CompleteEvent;
  324.     }
  325.   }
  326.  
  327.   if (Event==kbPgDn)
  328.   {
  329.     if (ItemCount>Height)
  330.     {
  331.       ItemAtTopOfList+=Height;
  332.       if (ItemAtTopOfList+(Height-1)>ItemCount-1)
  333.         ItemAtTopOfList=ItemCount-Height;
  334.       Item=ItemAtTopOfList+(Height-1);
  335.       Show();
  336.       HighLight();
  337.       return CompleteEvent;
  338.     }
  339.   }
  340.  
  341.   if (Event>=' ' && Event<='~') // QUIKFIND searching
  342.   {
  343.     int SearchFor=(Event>='a' && Event<='z')?(Event-32):Event;
  344.  
  345.     if (!Item && QuikFind(1,ItemCount,SearchFor))
  346.       return CompleteEvent;
  347.     else
  348.     {
  349.       if (Item+1<ItemCount && QuikFind(Item+1,ItemCount,SearchFor))
  350.         return CompleteEvent;
  351.       if (QuikFind(0,Item,SearchFor))
  352.         return CompleteEvent;
  353.     }
  354.   }
  355.  
  356.   return Event;
  357. }
  358.  
  359. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  360. //
  361. // QuikFind()
  362. //
  363. // QuikFind scanner -- scans for an item that starts with a given
  364. // character
  365. //
  366. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  367.  
  368. int DiaPickGeneric::QuikFind(int Low,int High,int SearchFor)
  369. {
  370.   if (Low==High)
  371.     return 0;
  372.  
  373.   for (int i=Low;i<High;i++)
  374.   {
  375.     char *GetIt=GetItem(i);
  376.     int Character=(*GetIt>='a' && *GetIt<='z')?(*GetIt-32):*GetIt;
  377.     if (SearchFor==Character)
  378.     {
  379.       Item=i;
  380.       Show();
  381.       HighLight();
  382.       return 1;
  383.     }
  384.   }
  385.  
  386.   return 0;
  387. }
  388.