asciitab.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  2. { }
  3. { System independent GRAPHICAL clone of ASCIITAB.PAS }
  4. { }
  5. { Interface Copyright (c) 1992 Borland International }
  6. { }
  7. { Copyright (c) 2002 by Pierre Muller }
  8. { [email protected] }
  9. {****************[ THIS CODE IS FREEWARE ]*****************}
  10. { }
  11. { This sourcecode is released for the purpose to }
  12. { promote the pascal language on all platforms. You may }
  13. { redistribute it and/or modify with the following }
  14. { DISCLAIMER. }
  15. { }
  16. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  17. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  18. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  19. { }
  20. {*****************[ SUPPORTED PLATFORMS ]******************}
  21. { 16 and 32 Bit compilers }
  22. { DPMI - FPC 0.9912+ (GO32V2) (32 Bit) }
  23. { WIN95/NT - FPC 0.9912+ (32 Bit) }
  24. { }
  25. UNIT AsciiTab;
  26. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  27. INTERFACE
  28. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  29. {====Include file to sort compiler platform out =====================}
  30. {$I platform.inc}
  31. {====================================================================}
  32. {==== Compiler directives ===========================================}
  33. {$X+} { Extended syntax is ok }
  34. {$R-} { Disable range checking }
  35. {$S-} { Disable Stack Checking }
  36. {$I-} { Disable IO Checking }
  37. {$Q-} { Disable Overflow Checking }
  38. {$V-} { Turn off strict VAR strings }
  39. {====================================================================}
  40. USES FVConsts, Objects, Drivers, Views, App; { Standard GFV units }
  41. {***************************************************************************}
  42. { PUBLIC OBJECT DEFINITIONS }
  43. {***************************************************************************}
  44. {---------------------------------------------------------------------------}
  45. { TTABLE OBJECT - 32x32 matrix of all chars }
  46. {---------------------------------------------------------------------------}
  47. type
  48. PTable = ^TTable;
  49. TTable = object(TView)
  50. procedure Draw; virtual;
  51. procedure HandleEvent(var Event:TEvent); virtual;
  52. private
  53. procedure DrawCurPos(enable : boolean);
  54. end;
  55. {---------------------------------------------------------------------------}
  56. { TREPORT OBJECT - View with details of current char }
  57. {---------------------------------------------------------------------------}
  58. PReport = ^TReport;
  59. TReport = object(TView)
  60. ASCIIChar: LongInt;
  61. constructor Load(var S: TStream);
  62. procedure Draw; virtual;
  63. procedure HandleEvent(var Event:TEvent); virtual;
  64. procedure Store(var S: TStream);
  65. end;
  66. {---------------------------------------------------------------------------}
  67. { TASCIIChart OBJECT - the complete AsciiChar window }
  68. {---------------------------------------------------------------------------}
  69. PASCIIChart = ^TASCIIChart;
  70. TASCIIChart = object(TWindow)
  71. Report: PReport;
  72. Table: PTable;
  73. constructor Init;
  74. constructor Load(var S: TStream);
  75. procedure Store(var S: TStream);
  76. procedure HandleEvent(var Event:TEvent); virtual;
  77. end;
  78. {---------------------------------------------------------------------------}
  79. { AsciiTableCommandBase }
  80. {---------------------------------------------------------------------------}
  81. const
  82. AsciiTableCommandBase: Word = 910;
  83. {---------------------------------------------------------------------------}
  84. { Registrations records }
  85. {---------------------------------------------------------------------------}
  86. RTable: TStreamRec = (
  87. ObjType: idTable;
  88. VmtLink: Ofs(TypeOf(TTable)^);
  89. Load: @TTable.Load;
  90. Store: @TTable.Store
  91. );
  92. RReport: TStreamRec = (
  93. ObjType: idReport;
  94. VmtLink: Ofs(TypeOf(TReport)^);
  95. Load: @TReport.Load;
  96. Store: @TReport.Store
  97. );
  98. RASCIIChart: TStreamRec = (
  99. ObjType: idASCIIChart;
  100. VmtLink: Ofs(TypeOf(TASCIIChart)^);
  101. Load: @TASCIIChart.Load;
  102. Store: @TASCIIChart.Store
  103. );
  104. {---------------------------------------------------------------------------}
  105. { Registration procedure }
  106. {---------------------------------------------------------------------------}
  107. procedure RegisterASCIITab;
  108. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  109. IMPLEMENTATION
  110. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  111. {***************************************************************************}
  112. { OBJECT METHODS }
  113. {***************************************************************************}
  114. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  115. { TTable OBJECT METHODS }
  116. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  117. procedure TTable.Draw;
  118. var
  119. NormColor : byte;
  120. B : TDrawBuffer;
  121. x,y : sw_integer;
  122. begin
  123. NormColor:=GetColor(1);
  124. For y:=0 to size.Y-1 do begin
  125. For x:=0 to size.X-1 do
  126. B[x]:=(NormColor shl 8) or ((y*Size.X+x) and $ff);
  127. WriteLine(0,Y,Size.X,1,B);
  128. end;
  129. DrawCurPos(true);
  130. end;
  131. procedure TTable.DrawCurPos(enable : boolean);
  132. var
  133. Color : byte;
  134. B : word;
  135. begin
  136. Color:=GetColor(1);
  137. { add blinking if enable }
  138. If Enable then
  139. Color:=((Color and $F) shl 4) or (Color shr 4);
  140. B:=(Color shl 8) or ((Cursor.Y*Size.X+Cursor.X) and $ff);
  141. WriteLine(Cursor.X,Cursor.Y,1,1,B);
  142. end;
  143. procedure TTable.HandleEvent(var Event:TEvent);
  144. var
  145. CurrentPos : TPoint;
  146. Handled : boolean;
  147. procedure SetTo(xpos, ypos : sw_integer;press:SmallInt);
  148. var
  149. newchar : ptrint;
  150. begin
  151. newchar:=(ypos*size.X+xpos) and $ff;
  152. DrawCurPos(false);
  153. SetCursor(xpos,ypos);
  154. Message(Owner,evCommand,AsciiTableCommandBase,
  155. pointer(newchar));
  156. if press>0 then
  157. begin
  158. Message(Owner,evCommand,AsciiTableCommandBase+press,pointer(newchar));
  159. end;
  160. DrawCurPos(true);
  161. ClearEvent(Event);
  162. end;
  163. begin
  164. case Event.What of
  165. evMouseDown :
  166. begin
  167. If MouseInView(Event.Where) then
  168. begin
  169. MakeLocal(Event.Where, CurrentPos);
  170. SetTo(CurrentPos.X, CurrentPos.Y,1);
  171. exit;
  172. end;
  173. end;
  174. evKeyDown :
  175. begin
  176. Handled:=true;
  177. case Event.Keycode of
  178. kbUp : if Cursor.Y>0 then
  179. SetTo(Cursor.X,Cursor.Y-1,0);
  180. kbDown : if Cursor.Y<Size.Y-1 then
  181. SetTo(Cursor.X,Cursor.Y+1,0);
  182. kbLeft : if Cursor.X>0 then
  183. SetTo(Cursor.X-1,Cursor.Y,0);
  184. kbRight: if Cursor.X<Size.X-1 then
  185. SetTo(Cursor.X+1,Cursor.Y,0);
  186. kbHome : SetTo(0,0,0);
  187. kbEnd : SetTo(Size.X-1,Size.Y-1,0);
  188. kbEnter: SetTo(Cursor.X,Cursor.Y,1);
  189. else
  190. Handled:=false;
  191. end;
  192. if Handled then
  193. exit;
  194. end;
  195. end;
  196. inherited HandleEvent(Event);
  197. end;
  198. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  199. { TReport OBJECT METHODS }
  200. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  201. constructor TReport.Load(var S: TStream);
  202. begin
  203. Inherited Load(S);
  204. S.Read(AsciiChar,Sizeof(AsciiChar));
  205. end;
  206. procedure TReport.Draw;
  207. var
  208. stHex,stDec : string[3];
  209. s : string;
  210. begin
  211. Str(AsciiChar,StDec);
  212. while length(stDec)<3 do
  213. stDec:=' '+stDec;
  214. stHex:=hexstr(AsciiChar,2);
  215. s:='Char "'+chr(AsciiChar)+'" Decimal: '+
  216. StDec+' Hex: $'+StHex+
  217. ' '; // //{!ss:fill gap. FormatStr function using be better}
  218. WriteStr(0,0,S,1);
  219. end;
  220. procedure TReport.HandleEvent(var Event:TEvent);
  221. begin
  222. if (Event.what=evCommand) and
  223. (Event.Command = AsciiTableCommandBase) then
  224. begin
  225. AsciiChar:=PtrInt(Event.InfoPtr);
  226. Draw;
  227. ClearEvent(Event);
  228. end
  229. else inherited HandleEvent(Event);
  230. end;
  231. procedure TReport.Store(var S: TStream);
  232. begin
  233. Inherited Store(S);
  234. S.Write(AsciiChar,Sizeof(AsciiChar));
  235. end;
  236. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  237. { TAsciiChart OBJECT METHODS }
  238. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  239. constructor TASCIIChart.Init;
  240. var
  241. R : Trect;
  242. begin
  243. R.Assign(0,0,34,12);
  244. Inherited Init(R,'Ascii table',wnNoNumber);
  245. Flags:=Flags and not (wfGrow or wfZoom);
  246. Palette:=wpGrayWindow;
  247. R.Assign(1,10,33,11);
  248. New(Report,Init(R));
  249. Report^.Options:=Report^.Options or ofFramed;
  250. Insert(Report);
  251. R.Assign(1,1,33,9);
  252. New(Table,Init(R));
  253. Table^.Options:=Table^.Options or (ofSelectable+ofTopSelect);
  254. Insert(Table);
  255. Table^.Select;
  256. end;
  257. constructor TASCIIChart.Load(var S: TStream);
  258. begin
  259. Inherited Load(S);
  260. GetSubViewPtr(S,Table);
  261. GetSubViewPtr(S,Report);
  262. end;
  263. procedure TASCIIChart.Store(var S: TStream);
  264. begin
  265. Inherited Store(S);
  266. PutSubViewPtr(S,Table);
  267. PutSubViewPtr(S,Report);
  268. end;
  269. procedure TASCIIChart.HandleEvent(var Event:TEvent);
  270. begin
  271. {writeln(stderr,'ascii cmd',event.what, ' ', event.command);}
  272. if (Event.what=evCommand) and
  273. (Event.Command = AsciiTableCommandBase) then
  274. begin
  275. Report^.HandleEvent(Event);
  276. end
  277. else inherited HandleEvent(Event);
  278. end;
  279. {---------------------------------------------------------------------------}
  280. { Registration procedure }
  281. {---------------------------------------------------------------------------}
  282. procedure RegisterASCIITab;
  283. begin
  284. RegisterType(RTable);
  285. RegisterType(RReport);
  286. RegisterType(RAsciiChart);
  287. end;
  288. END.