asciitab.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 DrawBackground; 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.DrawBackground;
  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
  126. For x:=0 to size.X-1 do
  127. begin
  128. B[x]:=(NormColor shl 8) or ((y*Size.X+x) and $ff);
  129. WriteLine(0,Y,Size.X,1,B);
  130. end;
  131. DrawCurPos(true);
  132. end;
  133. procedure TTable.DrawCurPos(enable : boolean);
  134. var
  135. Color : byte;
  136. B : word;
  137. begin
  138. Color:=GetColor(1);
  139. { add blinking if enable }
  140. If Enable then
  141. Color:=((Color and $F) shl 4) or (Color shr 4);
  142. B:=(Color shl 8) or ((Cursor.Y*Size.X+Cursor.X) and $ff);
  143. WriteLine(Cursor.X,Cursor.Y,1,1,B);
  144. end;
  145. procedure TTable.HandleEvent(var Event:TEvent);
  146. var
  147. xpos,ypos : sw_integer;
  148. Handled : boolean;
  149. procedure SetTo(xpos, ypos : sw_integer);
  150. var
  151. newchar : ptrint;
  152. begin
  153. newchar:=(ypos*size.X+xpos) and $ff;
  154. DrawCurPos(false);
  155. SetCursor(xpos,ypos);
  156. Message(Owner,evCommand,AsciiTableCommandBase,
  157. pointer(newchar));
  158. DrawCurPos(true);
  159. ClearEvent(Event);
  160. end;
  161. begin
  162. case Event.What of
  163. evMouseDown :
  164. begin
  165. If MouseInView(Event.Where) then
  166. begin
  167. xpos:=Event.Where.X-Origin.X;
  168. ypos:=Event.Where.Y-Origin.Y;
  169. SetTo(xpos, ypos);
  170. exit;
  171. end;
  172. end;
  173. evKeyDown :
  174. begin
  175. Handled:=true;
  176. case Event.Keycode of
  177. kbUp : if Cursor.Y>0 then
  178. SetTo(Cursor.X,Cursor.Y-1);
  179. kbDown : if Cursor.Y<Size.Y-1 then
  180. SetTo(Cursor.X,Cursor.Y+1);
  181. kbLeft : if Cursor.X>0 then
  182. SetTo(Cursor.X-1,Cursor.Y);
  183. kbRight: if Cursor.X<Size.X-1 then
  184. SetTo(Cursor.X+1,Cursor.Y);
  185. kbHome : SetTo(0,0);
  186. kbEnd : SetTo(Size.X-1,Size.Y-1);
  187. else
  188. Handled:=false;
  189. end;
  190. if Handled then
  191. exit;
  192. end;
  193. end;
  194. inherited HandleEvent(Event);
  195. end;
  196. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  197. { TReport OBJECT METHODS }
  198. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  199. constructor TReport.Load(var S: TStream);
  200. begin
  201. Inherited Load(S);
  202. S.Read(AsciiChar,Sizeof(AsciiChar));
  203. end;
  204. procedure TReport.Draw;
  205. var
  206. stHex,stDec : string[3];
  207. s : string;
  208. begin
  209. Str(AsciiChar,StDec);
  210. while length(stDec)<3 do
  211. stDec:=' '+stDec;
  212. stHex:=hexstr(AsciiChar,2);
  213. s:='Char "'+chr(AsciiChar)+'" Decimal: '+
  214. StDec+' Hex: $'+StHex;
  215. WriteStr(0,0,S,1);
  216. end;
  217. procedure TReport.HandleEvent(var Event:TEvent);
  218. begin
  219. if (Event.what=evCommand) and
  220. (Event.Command = AsciiTableCommandBase) then
  221. begin
  222. AsciiChar:=Event.InfoLong;
  223. Draw;
  224. ClearEvent(Event);
  225. end
  226. else inherited HandleEvent(Event);
  227. end;
  228. procedure TReport.Store(var S: TStream);
  229. begin
  230. Inherited Store(S);
  231. S.Write(AsciiChar,Sizeof(AsciiChar));
  232. end;
  233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  234. { TAsciiChart OBJECT METHODS }
  235. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  236. constructor TASCIIChart.Init;
  237. var
  238. R : Trect;
  239. begin
  240. R.Assign(0,0,34,12);
  241. Inherited Init(R,'Ascii table',wnNoNumber);
  242. Flags:=Flags and not (wfGrow or wfZoom);
  243. Palette:=wpGrayWindow;
  244. R.Assign(1,10,33,11);
  245. New(Report,Init(R));
  246. Report^.Options:=Report^.Options or ofFramed;
  247. Insert(Report);
  248. R.Assign(1,1,33,9);
  249. New(Table,Init(R));
  250. Table^.Options:=Table^.Options or (ofSelectable+ofTopSelect);
  251. Insert(Table);
  252. Table^.Select;
  253. end;
  254. constructor TASCIIChart.Load(var S: TStream);
  255. begin
  256. Inherited Load(S);
  257. GetSubViewPtr(S,Table);
  258. GetSubViewPtr(S,Report);
  259. end;
  260. procedure TASCIIChart.Store(var S: TStream);
  261. begin
  262. Inherited Store(S);
  263. PutSubViewPtr(S,Table);
  264. PutSubViewPtr(S,Report);
  265. end;
  266. procedure TASCIIChart.HandleEvent(var Event:TEvent);
  267. begin
  268. if (Event.what=evCommand) and
  269. (Event.Command = AsciiTableCommandBase) then
  270. begin
  271. Report^.HandleEvent(Event);
  272. end
  273. else inherited HandleEvent(Event);
  274. end;
  275. {---------------------------------------------------------------------------}
  276. { Registration procedure }
  277. {---------------------------------------------------------------------------}
  278. procedure RegisterASCIITab;
  279. begin
  280. RegisterType(RTable);
  281. RegisterType(RReport);
  282. RegisterType(RAsciiChart);
  283. end;
  284. END.
  285. {
  286. $Log$
  287. Revision 1.7 2004-12-19 20:20:47 hajny
  288. * ObjType references constants from fvconsts
  289. Revision 1.6 2004/12/19 13:05:56 florian
  290. * fixed x86_64 compilation
  291. Revision 1.5 2004/11/06 17:08:48 peter
  292. * drawing of tview merged from old fv code
  293. }