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

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // FusionWindow -> Status -> Icons -> ScrollBars -> WindowElement
  8. //
  9.  
  10. #include "fliwin.h"
  11. #include "colors.h"
  12.  
  13. #ifdef __BCPLUSPLUS__
  14. #pragma hdrstop
  15. #endif
  16.  
  17. #include <string.h>
  18. #include <ctype.h>
  19.  
  20. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  21. //
  22. // WindowElement()
  23. //
  24. // Constructor for Window Element class
  25. //
  26. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  27.  
  28. WindowColors::WindowColors()
  29. {
  30.   WinBorder=Colors.WinBorder;
  31.   WinIcons=Colors.WinIcons;
  32.   WinTitle=Colors.WinTitle;
  33.   WinScrollBar=Colors.WinScrollBar;
  34.   WinSizeCorner=Colors.WinSizeCorner;
  35.   WinInterior=Colors.WinInterior;
  36.   WinBoldInterior=Colors.WinBoldInterior;
  37.   WinAltInterior=Colors.WinAltInterior;
  38.   WinDead=Colors.WinDead;
  39. }
  40.  
  41. WindowElement::WindowElement()
  42. {
  43.   Title=0;
  44.   MinimumWidth=13;
  45.   MinimumHeight=5;
  46.   X=0;
  47.   Y=1;
  48.   Width=Blaze.WhatWidth();
  49.   Height=Blaze.WhatHeight()-2;
  50.   Blaze.Window(X+1,Y+1,Width-2,Height-2);
  51.   WindowNumber=0;
  52.   Active=0;
  53.   ZoomIcon=1;
  54.   CloseIcon=1;
  55.   SizeIcon=1;
  56.   Moveable=1;
  57.   WindowZoomed=0;
  58.   OldX=0;
  59.   OldY=0;
  60.   OldWidth=0;
  61.   OldHeight=0;
  62.   ExistXScrollBar=0;
  63.   ExistYScrollBar=0;
  64.   XMaximum=0;
  65.   XCurrent=0;
  66.   YMaximum=0;
  67.   YCurrent=0;
  68.   MainHandler=0;
  69.   VirtualUpdate=0;
  70.   InAWindow=1;
  71. }
  72.  
  73. WindowElement::~WindowElement()
  74. {
  75.   // Intentional
  76. }
  77.  
  78. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  79. //
  80. // ShowWindow()
  81. //
  82. // Shows the window on the display
  83. //
  84. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  85.  
  86. void WindowElement::ShowWindow()
  87. {
  88.   Blaze.Window(0,0,Blaze.WhatWidth(),Blaze.WhatHeight());
  89.  
  90.   MouseHide();
  91.  
  92.   int Icons=(Active)?WinIcons:WinDead;
  93.   int Border=(Active)?WinBorder:WinDead;
  94.  
  95.   if (Width<13 || Width<MinimumWidth)
  96.   {
  97.     if (MinimumWidth>=13)
  98.       Width=MinimumWidth;
  99.     else
  100.       Width=13;
  101.  
  102.     if (X+Width>Blaze.WhatWidth())
  103.       X=Blaze.WhatWidth()-Width;
  104.   }
  105.  
  106.   if (Height<5 || Height<MinimumHeight)
  107.   {
  108.     if (MinimumHeight>=5)
  109.       Height=MinimumHeight;
  110.     else
  111.       Height=5;
  112.  
  113.     if (Height>Blaze.WhatHeight()-2)
  114.       Y=Blaze.WhatHeight()-2-Height;
  115.   }
  116.  
  117.   if (Active)
  118.   {
  119.     Blaze.UserBoxDefineQuick(2);
  120.     Blaze.Box(X,Y,Width,Height,Border);
  121.     Blaze.UserBoxDefineQuick(1);
  122.   }
  123.   else
  124.     Blaze.Box(X,Y,Width,Height,Border);
  125.  
  126.   Blaze.EraseArea(X+1,Y+1,Width-2,Height-2,WinInterior);
  127.  
  128.   if (NumberOfMenus)
  129.   {
  130.     int MenuWidth=SetMenuBar(X+1,Y+1,Width-2,Blaze.WhatOutput());
  131.     if (MinimumWidth<MenuWidth)
  132.       MinimumWidth=MenuWidth;
  133.   }
  134.  
  135.   if (CloseIcon)
  136.     Blaze (X+1,Y)
  137.       << Border
  138.       << '['
  139.       << Icons
  140.       << '\x7'
  141.       << Border
  142.       << ']';
  143.  
  144.   if (ZoomIcon)
  145.     Blaze (X+Width-4,Y)
  146.       << Border
  147.       << '['
  148.       << Icons
  149.       << (char)((!WindowZoomed)?'\x1e':'\x1f')
  150.       << Border
  151.       << ']';
  152.  
  153.   if (SizeIcon)
  154.     Blaze (X+Width-1,Y+Height-1)
  155.       << (int)((Active)?WinSizeCorner:WinDead)
  156.       << '\xfe';
  157.  
  158.   if (Title &&
  159.     strlen(Title)<(Width-((WindowNumber)?4:0)-(ZoomIcon*3)-(CloseIcon*3)-3))
  160.     Blaze (X+((CloseIcon)?5:1),Y)
  161.       << (int)((Active)?WinTitle:WinDead)
  162.       << Title;
  163.  
  164.   if (WindowNumber)
  165.     Blaze ((X+Width-8)+((!ZoomIcon)?4:0),Y)
  166.       << Border
  167.       << '|'
  168.       << Icons
  169.       << (char)('0'+WindowNumber)
  170.       << Border
  171.       << '|';
  172.  
  173.   if (Active)
  174.     DisplayScrollBar();
  175.   else
  176.     MouseShow();
  177.  
  178.   int CalcHeight=Height-2-((NumberOfMenus)?1:0);
  179.  
  180.   if (!CalcHeight)
  181.     CalcHeight++;
  182.  
  183.   Blaze.Window(X+1,Y+1+((NumberOfMenus)?1:0),Width-2,CalcHeight);
  184. }
  185.  
  186. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  187. //
  188. // DisplayScrollBar()
  189. //
  190. // Displays the scroll bars
  191. //
  192. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  193.  
  194. void WindowElement::DisplayScrollBar()
  195. {
  196.   Blaze.Window(0,0,Blaze.WhatWidth(),Blaze.WhatHeight());
  197.  
  198.   MouseHide();
  199.  
  200.   if (ExistXScrollBar)
  201.   {
  202.     Blaze.CharacterRepeater(X+2,Y+Height-1,Width-4,WinScrollBar,0xb1);
  203.     Blaze (X+1,Y+Height-1)
  204.       << WinScrollBar
  205.       << '\x11';
  206.     Blaze (X+Width-2,Y+Height-1)
  207.       << '\x10';
  208.  
  209.     if (XMaximum && XMaximum>Width-4)
  210.     {
  211.       int ActualAvail=Width-4;
  212.  
  213.       int Determine=XMaximum/ActualAvail;
  214.  
  215.       int AnotherDetermine=0;
  216.       if (XCurrent)
  217.         AnotherDetermine=XCurrent/Determine;
  218.  
  219.       if (AnotherDetermine>=Width-4)
  220.         AnotherDetermine=Width-5;
  221.  
  222.       Blaze (X+2+AnotherDetermine,Y+Height-1) << '\xfe';
  223.     }
  224.   }
  225.  
  226.   if (ExistYScrollBar)
  227.   {
  228.     Blaze.CharacterRepeaterDown(X+Width-1,Y+2,Height-4,WinScrollBar,0xb1);
  229.     Blaze (X+Width-1,Y+1)
  230.       << WinScrollBar
  231.       << '\x1e';
  232.     Blaze (X+Width-1,Y+Height-2)
  233.       << '\x1f';
  234.  
  235.     if (YMaximum && YMaximum>Height-4)
  236.     {
  237.       int ActualAvail=Height-4;
  238.  
  239.       int Determine=YMaximum/ActualAvail;
  240.  
  241.       int AnotherDetermine=0;
  242.       if (YCurrent)
  243.         AnotherDetermine=YCurrent/Determine;
  244.  
  245.       if (AnotherDetermine>=Height-4)
  246.         AnotherDetermine=Height-5;
  247.  
  248.       Blaze (X+Width-1,Y+2+AnotherDetermine) << '\xfe';
  249.     }
  250.   }
  251.  
  252.   int CalcHeight=Height-2-((NumberOfMenus)?1:0);
  253.  
  254.   if (!CalcHeight)
  255.     CalcHeight++;
  256.  
  257.   MouseShow();
  258.  
  259.   Blaze.Window(X+1,Y+1+((NumberOfMenus)?1:0),Width-2,CalcHeight);
  260. }
  261.  
  262. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  263. //
  264. // CheckScrollBar()
  265. //
  266. // Displays the scroll bars
  267. //
  268. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  269.  
  270. int WindowElement::CheckScrollBar()
  271. {
  272.   if (!ExistXScrollBar && !ExistYScrollBar)
  273.     return 0;
  274.  
  275.   if (MouseVertical<Y+Height-2 && MouseVertical>Y+1 &&
  276.     MouseHorizontal==X+Width-1 && YMaximum>Height-4)
  277.   {
  278.     int Blocks=(Y+Height-2)-(Y+1)-1;
  279.  
  280.     if (Blocks<=1 || !YMaximum)
  281.       return 0;
  282.  
  283.     YCurrent=(YMaximum/Blocks)*(MouseVertical-(Y+2));
  284.  
  285.     DisplayScrollBar();
  286.     ShowInterior();
  287.  
  288.     return 1;
  289.   }
  290.  
  291.   if (MouseHorizontal<X+Width-2 && MouseHorizontal>X+1 &&
  292.     MouseVertical==Y+Height-1 && XMaximum>Width-4)
  293.   {
  294.     int Blocks=(X+Width-2)-(X+1)-1;
  295.  
  296.     if (Blocks<=1 || !XMaximum)
  297.       return 0;
  298.  
  299.     XCurrent=(XMaximum/Blocks)*(MouseHorizontal-(X+2));
  300.  
  301.     DisplayScrollBar();
  302.     ShowInterior();
  303.  
  304.     return 1;
  305.   }
  306.  
  307.   if (ExistXScrollBar && XMaximum)
  308.   {
  309.     // Right Button
  310.  
  311.     if (MouseVertical==Y+Height-1 && MouseHorizontal==X+Width-2)
  312.     {
  313.       if (XCurrent<XMaximum)
  314.       {
  315.         XCurrent++;
  316.         DisplayScrollBar();
  317.         ShowInterior();
  318.       }
  319.       return 1;
  320.     }
  321.  
  322.     // Left Button
  323.  
  324.     if (MouseVertical==Y+Height-1 && MouseHorizontal==X+1)
  325.     {
  326.       if (XCurrent)
  327.       {
  328.         XCurrent--;
  329.         DisplayScrollBar();
  330.         ShowInterior();
  331.       }
  332.       return 1;
  333.     }
  334.   }
  335.  
  336.   if (ExistYScrollBar && YMaximum)
  337.   {
  338.     // Down Button
  339.  
  340.     if (MouseVertical==Y+Height-2 && MouseHorizontal==X+Width-1)
  341.     {
  342.       if (YCurrent<YMaximum)
  343.       {
  344.         YCurrent++;
  345.         DisplayScrollBar();
  346.         ShowInterior();
  347.       }
  348.       return 1;
  349.     }
  350.  
  351.     // Up Button
  352.  
  353.     if (MouseVertical==Y+1 && MouseHorizontal==X+Width-1)
  354.     {
  355.       if (YCurrent)
  356.       {
  357.         YCurrent--;
  358.         DisplayScrollBar();
  359.         ShowInterior();
  360.       }
  361.       return 1;
  362.     }
  363.   }
  364.  
  365.   return 0;
  366. }
  367.  
  368. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  369. //
  370. // RemoveTheMenus()
  371. //
  372. // Removes both global and local menus
  373. //
  374. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  375.  
  376. void WindowElement::RemoveTheMenus()
  377. {
  378.   if (!MainHandler)
  379.     return;
  380.   MainHandler->RemoveAllMenus();
  381.   RemoveAllMenus();
  382. }
  383.  
  384. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  385. //
  386. // Cursor()
  387. //
  388. // Shows the cursor
  389. //
  390. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  391.  
  392. void WindowElement::Cursor()
  393. {
  394.   // Intentionally left empty
  395. }
  396.  
  397. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  398. //
  399. // Echo()
  400. //
  401. // Echos a signal back to the caller
  402. //
  403. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  404.  
  405. int WindowElement::Echo()
  406. {
  407.   return 0;
  408. }
  409.  
  410. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  411. //
  412. // ReAlign()
  413. //
  414. // Realigns the window (resets the window boundaries)
  415. //
  416. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  417.  
  418. void WindowElement::ReAlign()
  419. {
  420.   int CalcHeight=Height-2-((NumberOfMenus)?1:0);
  421.  
  422.   if (!CalcHeight)
  423.     CalcHeight++;
  424.  
  425.   Blaze.Window(X+1,Y+1+((NumberOfMenus)?1:0),Width-2,CalcHeight);
  426.   if (NumberOfMenus)
  427.     SetMenuBar(X+1,Y+1,Width-2,Blaze.WhatOutput());
  428. }
  429.  
  430.