home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CMIDLE.ZIP / UWIDLE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1991-03-16  |  4.9 KB  |  257 lines

  1. {--------------------------------------------------------------}
  2. { UWIDLE.PAS                                                   }
  3. { COPYRIGHT (C) USERWARE 1991 ALL RIGHTS RESERVED.             }
  4. { (portions copyright 1990 Borland International.)
  5. { USERWARE, 4 FALCON LN E, FAIRPORT NY 14450-3312 USA.         }
  6. { VOICE: 716-425-3463. CIS: 71540,3660.                        }
  7. {==============================================================}
  8.  
  9. unit uwidle;
  10.  
  11. interface
  12.  uses
  13.   objects,drivers,views,dialogs;
  14.  
  15. const
  16.  cmidle=$FFFF;
  17.  
  18. type
  19.  pidlewhen=^tidlewhen;
  20.  tidlewhen=record
  21.   hour,min,sec,sec100:word
  22.  end;
  23.  
  24. type
  25.  pidleview=^tidleview;
  26.  tidleview=object(tview)
  27.   lastidle:tidlewhen;
  28.   constructor init(var bounds:trect);
  29.   procedure update;virtual;
  30.   procedure handleevent(var event:tevent);virtual;
  31.  end;
  32.  
  33. type
  34.  pidleclock=^tidleclock;
  35.  tidleclock=object(tidleview)
  36.   lastsec:byte; {read-only}
  37.   refresh:byte; {0..59!}
  38.   timestr:string[10];
  39.   constructor init(var bounds:trect);
  40.   procedure draw;virtual;
  41.   procedure update;virtual;
  42.  end;
  43.  
  44. type
  45.  pidleheap=^tidleheap;
  46.  tidleheap=object(tidleview)
  47.   oldmem:longint;
  48.   procedure draw;virtual;
  49.   procedure update;virtual;
  50.  end;
  51.  
  52. type 
  53.  pkbcheckbox=^tkbcheckbox;
  54.  tkbcheckbox=object(tcheckboxes)
  55.   procedure conform;
  56.   constructor init(var bounds:trect);
  57.   procedure update;
  58.   procedure handleevent(var event:tevent);virtual;
  59.   procedure press(item:integer);virtual;
  60.  end;
  61.  
  62. const
  63.  minpanelsize:tpoint=(x:8;y:3);
  64. type
  65.  ppanel=^tpanel;
  66.  tpanel=object(tdialog)
  67.   constructor init(var bounds:trect;atitle:ttitlestr);
  68.   procedure sizelimits(var min,max:tpoint);virtual;
  69.   procedure zoom;virtual;
  70.  end;
  71.  
  72. type
  73.  pstatuspanel=^tstatuspanel;
  74.  tstatuspanel=object(tpanel)
  75.   constructor init;
  76.  end;
  77.  
  78. implementation
  79.  uses app;
  80.  
  81. constructor tidleview.init;
  82. begin
  83.  tview.init(bounds);
  84.  fillchar(lastidle,sizeof(lastidle),#$FF);
  85.  eventmask:=eventmask or evbroadcast
  86. end;
  87.  
  88. procedure tidleview.update;
  89. begin
  90.  drawview
  91. end;
  92.  
  93. procedure tidleview.handleevent;
  94. begin
  95.  tview.handleevent(event);
  96.  if (event.what=evbroadcast) and (event.command=cmidle)
  97.   then begin
  98.    lastidle:=pidlewhen(event.infoptr)^;
  99.    update
  100.   end
  101. end;
  102.  
  103. {}
  104.  
  105. constructor tidleclock.init;
  106. begin
  107.  tidleview.init(bounds);
  108.  lastsec:=$FF;
  109.  refresh:=$01
  110. end;
  111.  
  112. procedure tidleclock.draw;
  113. var
  114.  b:tdrawbuffer;  
  115.  c:byte;
  116. begin
  117.  lastsec:=lastidle.sec;
  118.  c:=getcolor(2);
  119.  movechar(b,' ',c,size.x);
  120.  movestr(b,timestr,c);
  121.  writeline(0,0,size.x,1,b)
  122. end;
  123.  
  124. procedure tidleclock.update;
  125.  function leadingzero(w:word):string;
  126.  var 
  127.   s:string;
  128.  begin
  129.   str(w:0,s); leadingzero:=copy('00',1,2-length(s))+s
  130.  end;
  131. begin
  132.  if(abs(lastidle.sec-lastsec)<refresh) then exit;
  133.  with lastidle do 
  134.   timestr:=leadingzero(hour)+':'+leadingzero(min)+':'+leadingzero(sec);
  135.  drawview
  136. end;
  137.  
  138. {}
  139.  
  140. procedure tidleheap.draw;
  141. var
  142.  s:string;
  143.  b:tdrawbuffer;
  144.  c:byte;
  145. begin
  146.  oldmem:=memavail;
  147.  str(oldmem:size.x,s);
  148.  c:=getcolor(2);
  149.  movechar(b,' ',c,size.x);
  150.  movestr(b,s,c);
  151.  writeline(0,0,size.x,1,b)
  152. end;
  153.  
  154. procedure tidleheap.update;
  155. begin
  156.  if (oldmem<>memavail) then drawview
  157. end;
  158.  
  159. {}
  160.  
  161. var
  162.  shiftstate:byte absolute $40:$17;
  163.  
  164. procedure tkbcheckbox.conform;
  165. var
  166.  nowstate:word;
  167. begin
  168.  nowstate:=shiftstate shr 4;
  169.  setdata(nowstate)
  170. end;
  171.  
  172. constructor tkbcheckbox.init;
  173. begin
  174.  tcheckboxes.init(bounds,
  175.   newsitem('Scroll Lock',
  176.   newsitem('Num Lock',
  177.   newsitem('Caps Lock',
  178.   newsitem('Ins Mode',
  179.   nil)))) );
  180.  eventmask:=eventmask or evbroadcast;
  181.  helpctx:=$F000; {force out of range for standard hints.}
  182.  conform
  183. end;
  184.  
  185. procedure tkbcheckbox.update;
  186. begin
  187.  conform; 
  188.  drawview
  189. end;
  190.  
  191. procedure tkbcheckbox.handleevent;
  192. begin
  193.  tcheckboxes.handleevent(event);
  194.  if (event.what=evbroadcast) and (event.command=cmidle)
  195.   then update
  196. end; 
  197.  
  198. procedure tkbcheckbox.press;
  199. begin
  200.  tcheckboxes.press(item);
  201.  case item of 
  202.   0:shiftstate:=shiftstate xor kbscrollstate;
  203.   1:shiftstate:=shiftstate xor kbnumstate;
  204.   2:shiftstate:=shiftstate xor kbcapsstate;
  205.   3:shiftstate:=shiftstate xor kbinsstate
  206.  end
  207. end;
  208.  
  209. {}
  210.  
  211. constructor tpanel.init;
  212. begin
  213.  tdialog.init(bounds,atitle);
  214.  setstate(sfshadow,false);
  215.  flags:=flags or wfzoom
  216. end;
  217.  
  218. procedure tpanel.sizelimits;
  219. begin
  220.  tdialog.sizelimits(min,max);
  221.  min:=minpanelsize
  222. end;
  223.  
  224. procedure tpanel.zoom;
  225. begin
  226.  if (origin.x=0) and (origin.y=0)
  227.   then moveto(zoomrect.a.x,zoomrect.a.y)
  228.   else begin
  229.    zoomrect.assign(origin.x,origin.y,origin.x+size.x,origin.y+size.y);
  230.    moveto(0,0)
  231.   end
  232. end;
  233.  
  234. {}
  235.  
  236. constructor tstatuspanel.init;
  237. var
  238.  r:trect;
  239. begin 
  240.  desktop^.getextent(r);
  241.  r.a.x:=r.b.x-20;
  242.  r.a.y:=r.b.y-02;
  243.  inc(r.b.y,5);
  244.  
  245.  tpanel.init(r,'');
  246.   r.assign(1,1,9,2);
  247.  insert(new(pidleclock,init(r)));
  248.   inc(r.a.x,10); inc(r.b.x,10);
  249.  insert(new(pidleheap,init(r)));
  250.   r.assign(1,2, 19,6);
  251.  insert(new(pkbcheckbox,init(r)))
  252. end;
  253.  
  254. {}
  255.  
  256. end.
  257.