asciitab.pas 10 KB

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