asciitab.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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);
  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. DrawCurPos(true);
  157. ClearEvent(Event);
  158. end;
  159. begin
  160. case Event.What of
  161. evMouseDown :
  162. begin
  163. If MouseInView(Event.Where) then
  164. begin
  165. MakeLocal(Event.Where, CurrentPos);
  166. SetTo(CurrentPos.X, CurrentPos.Y);
  167. exit;
  168. end;
  169. end;
  170. evKeyDown :
  171. begin
  172. Handled:=true;
  173. case Event.Keycode of
  174. kbUp : if Cursor.Y>0 then
  175. SetTo(Cursor.X,Cursor.Y-1);
  176. kbDown : if Cursor.Y<Size.Y-1 then
  177. SetTo(Cursor.X,Cursor.Y+1);
  178. kbLeft : if Cursor.X>0 then
  179. SetTo(Cursor.X-1,Cursor.Y);
  180. kbRight: if Cursor.X<Size.X-1 then
  181. SetTo(Cursor.X+1,Cursor.Y);
  182. kbHome : SetTo(0,0);
  183. kbEnd : SetTo(Size.X-1,Size.Y-1);
  184. else
  185. Handled:=false;
  186. end;
  187. if Handled then
  188. exit;
  189. end;
  190. end;
  191. inherited HandleEvent(Event);
  192. end;
  193. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  194. { TReport OBJECT METHODS }
  195. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  196. constructor TReport.Load(var S: TStream);
  197. begin
  198. Inherited Load(S);
  199. S.Read(AsciiChar,Sizeof(AsciiChar));
  200. end;
  201. procedure TReport.Draw;
  202. var
  203. stHex,stDec : string[3];
  204. s : string;
  205. begin
  206. Str(AsciiChar,StDec);
  207. while length(stDec)<3 do
  208. stDec:=' '+stDec;
  209. stHex:=hexstr(AsciiChar,2);
  210. s:='Char "'+chr(AsciiChar)+'" Decimal: '+
  211. StDec+' Hex: $'+StHex+
  212. ' '; // //{!ss:fill gap. FormatStr function using be better}
  213. WriteStr(0,0,S,1);
  214. end;
  215. procedure TReport.HandleEvent(var Event:TEvent);
  216. begin
  217. if (Event.what=evCommand) and
  218. (Event.Command = AsciiTableCommandBase) then
  219. begin
  220. AsciiChar:=Event.InfoLong;
  221. Draw;
  222. ClearEvent(Event);
  223. end
  224. else inherited HandleEvent(Event);
  225. end;
  226. procedure TReport.Store(var S: TStream);
  227. begin
  228. Inherited Store(S);
  229. S.Write(AsciiChar,Sizeof(AsciiChar));
  230. end;
  231. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  232. { TAsciiChart OBJECT METHODS }
  233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  234. constructor TASCIIChart.Init;
  235. var
  236. R : Trect;
  237. begin
  238. R.Assign(0,0,34,12);
  239. Inherited Init(R,'Ascii table',wnNoNumber);
  240. Flags:=Flags and not (wfGrow or wfZoom);
  241. Palette:=wpGrayWindow;
  242. R.Assign(1,10,33,11);
  243. New(Report,Init(R));
  244. Report^.Options:=Report^.Options or ofFramed;
  245. Insert(Report);
  246. R.Assign(1,1,33,9);
  247. New(Table,Init(R));
  248. Table^.Options:=Table^.Options or (ofSelectable+ofTopSelect);
  249. Insert(Table);
  250. Table^.Select;
  251. end;
  252. constructor TASCIIChart.Load(var S: TStream);
  253. begin
  254. Inherited Load(S);
  255. GetSubViewPtr(S,Table);
  256. GetSubViewPtr(S,Report);
  257. end;
  258. procedure TASCIIChart.Store(var S: TStream);
  259. begin
  260. Inherited Store(S);
  261. PutSubViewPtr(S,Table);
  262. PutSubViewPtr(S,Report);
  263. end;
  264. procedure TASCIIChart.HandleEvent(var Event:TEvent);
  265. begin
  266. if (Event.what=evCommand) and
  267. (Event.Command = AsciiTableCommandBase) then
  268. begin
  269. Report^.HandleEvent(Event);
  270. end
  271. else inherited HandleEvent(Event);
  272. end;
  273. {---------------------------------------------------------------------------}
  274. { Registration procedure }
  275. {---------------------------------------------------------------------------}
  276. procedure RegisterASCIITab;
  277. begin
  278. RegisterType(RTable);
  279. RegisterType(RReport);
  280. RegisterType(RAsciiChart);
  281. end;
  282. END.