From: Dirk B. <db...@us...> - 2006-01-13 17:50:42
|
Update of /cvsroot/win32forth/win32forth/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26243/src/lib Modified Files: AcceleratorTables.f file.f Log Message: Added documentation for the Accelerator table support and the file I/O classes Index: file.f =================================================================== RCS file: /cvsroot/win32forth/win32forth/src/lib/file.f,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** file.f 31 Dec 2005 11:12:44 -0000 1.6 --- file.f 13 Jan 2006 17:50:33 -0000 1.7 *************** *** 1,4 **** --- 1,8 ---- \ $Id$ + \ *D doc\classes\ + \ *! File + \ *T Classes for File I/O + anew -File.f *************** *** 11,18 **** \ ----------------------------------------------------------------------------- ! \ File I/O class \ ----------------------------------------------------------------------------- - :Class File <Super Object int errorcode --- 15,23 ---- \ ----------------------------------------------------------------------------- ! \ *W <a name="File"></a> ! \ *S File I/O class \ ----------------------------------------------------------------------------- :Class File <Super Object + \ *G File I/O class int errorcode *************** *** 53,56 **** --- 58,62 ---- :M Close: ( -- ) + \ *G Close the file. hfile if hfile close-file to errorcode *************** *** 61,64 **** --- 67,71 ---- :M Open: ( -- f ) + \ *G Open the file Close: self filename count mode open-file dup to errorcode *************** *** 69,72 **** --- 76,80 ---- :M Read: { addr cnt -- f } + \ *G Read cnt bytes from the file into memory hfile if addr cnt hfile read-file *************** *** 77,80 **** --- 85,89 ---- :M Write: { addr cnt -- f } + \ *G Write cnt bytes from memory into the file. hfile if addr cnt hfile write-file *************** *** 85,88 **** --- 94,98 ---- :M Create: ( -- f ) + \ *G Create the file. Close: self filename count mode create-file dup to errorcode *************** *** 93,96 **** --- 103,107 ---- :M Delete: ( -- ) + \ *G Delete the file Close: self filename count delete-file to errorcode *************** *** 98,101 **** --- 109,113 ---- :M Rename: { addr cnt -- } + \ *G Rename the file. Close: self filename count addr cnt rename-file to errorcode *************** *** 105,108 **** --- 117,121 ---- :M GetPosition: ( -- ud ) + \ *G Get the position of the file pointer hfile if hfile file-position to errorcode *************** *** 111,114 **** --- 124,128 ---- :M RePosition: ( ud -- ) + \ *G Set the position of the file pointer hfile -if reposition-file to errorcode *************** *** 117,120 **** --- 131,135 ---- :M FileSize: ( -- ud ) + \ *G Get the size of the file hfile if hfile file-size to errorcode *************** *** 122,126 **** then ;M ! :M Append: ( -- ) \ set append mode hfile if hfile file-append to errorcode --- 137,142 ---- then ;M ! :M Append: ( -- ) ! \ *G Set append mode hfile if hfile file-append to errorcode *************** *** 128,131 **** --- 144,148 ---- :M Flush: ( -- ) + \ *G Flush the file hfile if hfile flush-file to errorcode *************** *** 134,137 **** --- 151,155 ---- :M ReadLine: ( addr len -- len eof ) + \ *G Read a line from the file. hfile ?dup if read-line to errorcode *************** *** 141,146 **** :M WriteLine: ( addr len -- ) hfile ! -if write-line to errorcode s" Write Line" ismsgtext ?fileerror else 3drop --- 159,165 ---- :M WriteLine: ( addr len -- ) + \ *G Write a line to the file hfile ! -if write-line to errorcode s" Write Line" ismsgtext ?fileerror else 3drop *************** *** 148,151 **** --- 167,171 ---- :M Resize: ( ud -- ) + \ *G Resize the file hfile ?dup if resize-file to errorcode *************** *** 154,184 **** then ;M ! :M Exist?: ( -- ) filename count file-status nip 0= ;M :M SetName: ( addr cnt -- ) maxcounted min 0max filename place filename +NULL ;M :M GetName: ( -- addr ) filename ;M :M ClearName: ( -- ) filename max-path erase ;M :M SetMode: ( mode -- ) to mode ;M :M ErrorCode: ( -- n ) errorcode ;M ;Class ! \ ----------------------------------------------------------------------------- ! \ class for loading/saving a complete file from/to memory \ ----------------------------------------------------------------------------- :Class ReadFile <Super File int FileBuffer --- 174,212 ---- then ;M ! :M Exist?: ( -- f ) ! \ *G Check if the file exist filename count file-status nip 0= ;M :M SetName: ( addr cnt -- ) + \ *G Set the file name maxcounted min 0max filename place filename +NULL ;M :M GetName: ( -- addr ) + \ *G Get the file name filename ;M :M ClearName: ( -- ) + \ *G Clear the file name filename max-path erase ;M :M SetMode: ( mode -- ) + \ *G Set the I/O mode to mode ;M :M ErrorCode: ( -- n ) + \ *G Get the error code of the previous file I/O errorcode ;M ;Class ! \ *G End of File class \ ----------------------------------------------------------------------------- ! \ *W <a name="ReadFile"></a> ! \ *S Class for loading/saving a complete file from/to memory \ ----------------------------------------------------------------------------- :Class ReadFile <Super File + \ *G ReadFile class for loading/saving a complete file from/to memory. int FileBuffer *************** *** 188,197 **** 0 to FileBuffer ;M ! :M ReleaseBuffer: ( -- ) \ free the memory of the file-buffer FileBuffer ?dup if release 0 to FileBuffer then ;M ! :M GetBuffer: ( -- addr len ) \ get the address and len of the file-buffer FileBuffer ?dup if lcount --- 216,227 ---- 0 to FileBuffer ;M ! :M ReleaseBuffer: ( -- ) ! \ *G Free the memory of the file-buffer FileBuffer ?dup if release 0 to FileBuffer then ;M ! :M GetBuffer: ( -- addr len ) ! \ *G Fet the address and len of the file-buffer FileBuffer ?dup if lcount *************** *** 199,203 **** then ;M ! :M GetLength: ( -- len ) \ get the length of the file-buffer FileBuffer ?dup if @ --- 229,234 ---- then ;M ! :M GetLength: ( -- len ) ! \ *G Get the length of the file-buffer FileBuffer ?dup if @ *************** *** 205,211 **** then ;M ! :M SetLength: ( len -- ) \ set the length of the file-buffer ! \ NOTE: You can set the length with this method behind the ! \ allocated memory of the file-buffer! So take care. FileBuffer ?dup if ! --- 236,243 ---- then ;M ! :M SetLength: ( len -- ) ! \ *G Set the length of the file-buffer. ! \ *P NOTE: with this method you can set the length behind the ! \ ** allocated memory of the file-buffer! So take care. FileBuffer ?dup if ! *************** *** 213,224 **** then ;M ! :M SetBuffer: ( addr len -- ) \ set the address and len of the file-buffer ReleaseBuffer: self swap dup to FileBuffer ! ;M :M AllocBuffer: ( len -- ) dup cell+ malloc swap SetBuffer: self ;M ! :M LoadFile: ( addr len -- f ) \ load a file into the file-buffer, f=true on success Setname: self r/o SetMode: self --- 245,259 ---- then ;M ! :M SetBuffer: ( addr len -- ) ! \ *G Set the address and length of the file-buffer ReleaseBuffer: self swap dup to FileBuffer ! ;M :M AllocBuffer: ( len -- ) + \ *G Allocate memory for the file-buffer dup cell+ malloc swap SetBuffer: self ;M ! :M LoadFile: ( addr len -- f ) ! \ *G load a file into the file-buffer, f=true on success Setname: self r/o SetMode: self *************** *** 232,236 **** then Close: self ;M ! :M SaveFile: ( -- ) \ save the file-buffer to the file FileBuffer 0= ?exitm r/w SetMode: self --- 267,272 ---- then Close: self ;M ! :M SaveFile: ( -- ) ! \ *G Save the file-buffer to the file FileBuffer 0= ?exitm r/w SetMode: self *************** *** 244,266 **** ;Class ! ! \ ReadFile MyDumpFile ! \ ! \ : DumpFile ( addr len -- ) ! \ ! \ \ Load the file into memory ! \ LoadFile: MyDumpFile ! \ if \ get the address and length of the file buffer ! \ GetBuffer: MyDumpFile ( addr len ) ! \ ! \ \ do something with the file data ! \ dump ! \ ! \ \ don't forget to close the file ! \ Close: MyDumpFile ! \ else abort" Can't read file." ! \ then ; ! \ ! \ s" temp.f" DumpFile module --- 280,311 ---- ;Class ! \ *G End of ReadFile class module + + \s + + \ *S Example + \ *+ + + ReadFile MyDumpFile + + : DumpFile ( addr len -- ) + + \ Load the file into memory + LoadFile: MyDumpFile + if \ get the address and length of the file buffer + GetBuffer: MyDumpFile ( addr len ) + + \ do something with the file data + dump + + \ don't forget to close the file + Close: MyDumpFile + else abort" Can't read file." + then ; + + s" temp.f" DumpFile + + \ *- + \ *Z Index: AcceleratorTables.f =================================================================== RCS file: /cvsroot/win32forth/win32forth/src/lib/AcceleratorTables.f,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AcceleratorTables.f 1 May 2005 06:27:41 -0000 1.2 --- AcceleratorTables.f 13 Jan 2006 17:50:33 -0000 1.3 *************** *** 2,20 **** \ October 2004 Rod Oakford ! \ --------------------------------------------------------------------------------------------- ! \ To use Accelerator Tables in an application: (see the example below) ! \ Define the Accelerator Tables required using: AcceleratorTable <name> ! \ Start the entries for each table with: <name> table ! \ Add entries with: ( flags key-code command-id ) AccelEntry ! \ End the table with: ( Window ) HandlesThem ! \ This will add code to process the Accelerator Keys in the message chain. ! \ Use: <name> EnableAccelerators to enable the accelerator commands ! \ and send them to the window used with HandlesThem. ! \ These accelerator commands are handled in the window's OnWmCommand: method. ! \ Use: <name> DisableAccelerators to disable the accelerator commands for this table. ! \ Always disable (destroy) every table before the application closes to prevent memory leaks. ! \ --------------------------------------------------------------------------------------------- cr .( Windows Accelerator Table support...) --- 2,22 ---- \ October 2004 Rod Oakford ! \ *D doc ! \ *! p-AcceleratorTables ! \ *T Windows Accelerator Table support ! \ *P To use Accelerator Tables in an application: ! \ *P Define the Accelerator Tables required using: AcceleratorTable <name> ! \ *P Start the entries for each table with: <name> table ! \ *P Add entries with: ( flags key-code command-id ) AccelEntry ! \ *P End the table with: ( Window ) HandlesThem ! \ ** This will add code to process the Accelerator Keys in the message chain. ! \ *P Use: <name> EnableAccelerators to enable the accelerator commands ! \ ** and send them to the window used with HandlesThem. ! \ *P These accelerator commands are handled in the window's OnWmCommand: method. ! \ *P Use: <name> DisableAccelerators to disable the accelerator commands for this table. ! \ ** Always disable (destroy) every table before the application closes to prevent memory leaks. ! \ *S Glossary cr .( Windows Accelerator Table support...) *************** *** 27,46 **** EXTERNAL ! : Dump-Accelerator-Key-Table ( a -- ) cr dup BODY> .name ." Table:" cr ." Address Flags Key ID" cell+ 2@ 6 * bounds DO ! cr i 6 h.R i w@ 5 h.R i 2 + w@ 5 h.R i 4 + w@ 4 h.R 6 +LOOP cr ; ! : AcceleratorTable ( <name> -- ) \ creates a new named Accelerator Table Create here to CurrentTable ( Handle ) 0 , ( AccelEntries ) 0 , ( AccelTable ) here , ; ! : Table ( a -- ) \ starts a table of entries in the dictionary dup to CurrentTable here 0 rot cell+ 2! ; ! : AccelEntry ( flags key-code command-id -- ) \ adds entries to the current table ! rot 3 ( FVIRTKEY FNOINVERT or ) or w, swap w, w, CurrentTable cell+ incr ; --- 29,52 ---- EXTERNAL ! : Dump-Accelerator-Key-Table ( a -- ) \ W32F sys ! \ *G Dump an Accelerator Table to the console window- cr dup BODY> .name ." Table:" cr ." Address Flags Key ID" cell+ 2@ 6 * bounds DO ! cr i 6 h.R i w@ 5 h.R i 2 + w@ 5 h.R i 4 + w@ 4 h.R 6 +LOOP cr ; ! : AcceleratorTable ( <name> -- ) ! \ *G Create a new named Accelerator Table Create here to CurrentTable ( Handle ) 0 , ( AccelEntries ) 0 , ( AccelTable ) here , ; ! : Table ( a -- ) \ W32F sys ! \ *G Start a table of entries in the dictionary dup to CurrentTable here 0 rot cell+ 2! ; ! : AccelEntry ( flags key-code command-id -- ) \ W32F sys ! \ *G Add a entry to the current table ! rot 3 ( FVIRTKEY FNOINVERT or ) or w, swap w, w, CurrentTable cell+ incr ; *************** *** 48,52 **** Sys-warning-off ! : HandlesThem ( Window -- ) \ adds the code in #DOES> to the message chain here DOVAR , CurrentTable , swap ( Window ) , dup msg-chain noop-chain-add ! #DOES> ( pMsg f pfa -- pMsg f ) --- 54,60 ---- Sys-warning-off ! : HandlesThem ( Window -- ) \ W32F ! \ *G Close a table and assign it to the given window. ! \ adds the code in #DOES> to the message chain here DOVAR , CurrentTable , swap ( Window ) , dup msg-chain noop-chain-add ! #DOES> ( pMsg f pfa -- pMsg f ) *************** *** 57,68 **** Sys-warning-on ! : DisableAccelerators ( a -- ) \ destroys the Windows Accelerator Table dup @ Call DestroyAcceleratorTable drop off ; - \ it does not matter trying to destroy a table more than once ! : EnableAccelerators ( a -- ) \ creates the Windows Accelerator Table dup DisableAccelerators ! dup cell+ 2@ swap Call CreateAcceleratorTable swap ! ; ! \ it does not matter creating the same table again as long as it is destroyed first MODULE --- 65,78 ---- Sys-warning-on ! : DisableAccelerators ( a -- ) \ W32F ! \ *G Destroys the Windows Accelerator Table. ! \ ** It does not matter trying to destroy a table more than once dup @ Call DestroyAcceleratorTable drop off ; ! : EnableAccelerators ( a -- ) \ W32F ! \ *G Creates the Windows Accelerator Table. ! \ ** It does not matter creating the same table again as long as it is destroyed first dup DisableAccelerators ! dup cell+ 2@ swap Call CreateAcceleratorTable swap ! ; MODULE *************** *** 72,76 **** \s ! \ EXAMPLE \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ --- 82,87 ---- \s ! \ *S Example ! \ *+ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ *************** *** 90,94 **** :M StartSize: 220 50 ;M ! :M On_Init: ( -- ) NumKeys EnableAccelerators --- 101,105 ---- :M StartSize: 220 50 ;M ! :M On_Init: ( -- ) NumKeys EnableAccelerators *************** *** 175,177 **** cr .( CharKeys EnableAccelerators will enable them again.) cr .( Closing the Test window will disable all the accelerators) ! |