asciitab.pas 11 KB

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