[ Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters ]

Arc de Triomphe clipart (2486 bytes)

GRAPE for SmallEiffel


Converted by Steven White.

GRAPE.zip (2,326,930 bytes) - source code and documentation
http://www.findmail.com/list/noframes/elj-grape-discuss/info.html (GRAPE mailing list)
http://www.elj.com/elj-win32/grape/ (GRAPE for SmallEiffel home page)

sjwhite@apexmail.com Mail address of Steven White
http://www.barf.homepad.com/The Home Page of Steven White

Welcome to the first instalment of GRAPE for SE. Having been introduced to GRAPE in August, 1998 I decided to port GRAPE to SmallEiffel. While I had had some experience with ISE Eiffel and WEL the task of porting GRAPE was much bigger then I first thought. This was mainly due the fact that the libraries supplied with each Eiffel compiler are not compatible.

This system has been tested with SmallEiffel -.80 and -.79b3.

Here is a summary of changes I have made to the library.

  1. Changed Eiffel STRING class creation function from 'adapt' to 'copy'.
  2. Changed the case of constants to first letter as upper case subsequent letters are lower case. EG: Idm_menu.
  3. Changed all standard variables to lowercase
  4. Removed empty argument lists '()'
  5. Reformatted most of the classes to follow standard Eiffel indenting style (I think its standard, I like it anyway...)
  6. Changed the BOOLEAN type to G_BOOL because of name clashes with the Microsoft compilers BOOLEAN type.
  7. C code that returned a new Eiffel STRING class were changed to return POINTERs, Eiffel code changed to create a string from the returned pointer (.from_external)
  8. Centering windows or dialog boxes was found to fail under some conditions, fixed.
  9. Incorrect function definition causing window positioning problems, fixed.
  10. Fixed a memory leak in C code. A temporary bitmap was not being deallocated, In one of my classes I was loosing over 1MB per second by holding the shift key down!
  11. As GRAPE sets the value of some features from C a GPF was triggered because SE doesn't produce code for features that it thinks are not used. I initialised these variables in the 'make' clause so SE would leave them alone.
  12. Created the MENU_ACCELERATOR class to provide menu accelerator support.
  13. Added the on_erase_background routine to class TILE so flicker free graphics updates can be done.
  14. Enabled scroll bar thumb track support.

SE performs no error checking on features not actually used by your program. Because of this there may be features that don't work although the majority of GRAPE has been tested. If you find any problems please let me know.

With resource handling I suggest you create a .RES file (if using a Microsoft compiler) and link it in with your application. You can use the RESOURCE_CONTAINER class to load resources by specifying 'command_arguments.item(0)' as the filename. This is the current .EXE file. Checkout the 'ReadMe.txt" file in the ...\source\graperesources path.

Some of the classes in the Widgets directory have not been tested (although they should work...) I have tested the splitter, tabs, caret and validation classes though.

If you have problems I would appreciate a way to duplicate the problem.

Installation

The files under the \GRAPE\WIN32\SOURCE\SMALLEIFFEL\GRAPE path are all that's required to get GRAPE going. The C files in the \GRAPE\WIN32\SOURCE\C-CODE path are for creating grape.lib. Don't bother with them unless you want to recompile GRAPE.LIB.

Copy the files from \GRAPE\WIN32\SOURCE\SMALLEIFFEL\GRAPE to wherever you like to store your libraries. Add the new paths to your loadpath file. For example, if you copy the files into C:\EIFFEL\GRAPE you will need to add the following to the loadpath file.

C:\EIFFEL\GRAPE\WINDOWS\

If you wish to use any of the classes in the WIDGETS directory then those paths will need to be added to the loadpath file also.

Porting GRAPE

One of the first problems with porting grape was a conflict with the MS Visual C++ BOOLEAN keyword and the definition of BOOLEAN that SmallEiffel uses. The cleanest way to resolve this problem was to rename all the BOOLEAN keywords in the GRAPE C source files to G_BOOL. I also found several prototype mismatches such as and Eiffel file was passing a REAL to C but the C definition was INTEGER.

I created a dummy program that listed all the classes that C needed to create or call. From this I got a SE_Structs.H file that contains the C prototypes I needed and linked this in with the GRAPE.

This is the RECT class definition. A fundamental GRAPE feature.
struct S107{int id;T4 _x;T4 _y;T4 _w;T4 _h;};

To pass text to SE memory was allocated using malloc, the text copied into the new memory and the result sent to Eiffel. In Eiffel the returned pointer was turned into a string by using Se's from_external function.

For an example examine the ENTRY_AREA class, get_text routine and the ENTRY.C file, get_window_text function.

Once the library file was built from the C source I made a number of modifications to the Eiffel source. The Eiffel string adapt function had to be replaced with copy and many of the routines containing math require the to_real and floor as SE does not convert automatically in many cases.

I also changed the style of the Eiffel code to match my own style which is based on ISE Eiffel standards. ISE Eiffel was my first introduction to Eiffel although I only have a personal license (version 3.3) I find it a lot easier to read and spot problems. Of course this was personal choice but it gave me a chance to go over all the code in the library as well. The case of constants, class names and variables was made consistent and follows the SmallEiffel standard. SmallEiffel is case sensitive by default and produces warnings for expressions that don't use the right case. (in its opinion!)

The last change is the implementation of the handling of the on_erase_background message. This Windows message determines whether the screen will be cleared before Windows sends a WM_PAINT message. Returning processed stops Windows from clearing the display. As the EDIT_CONTROL class uses scrolling to speed drawing performance I needed this function together with the MEMORY_GRAPHICS_CONTEXT class to provide flicker free editing.

Using GRAPE with SE

For information on compiling GRAPE programs see the document Compiling a GRAPE Program in this directory.

Compiling the example files may result in Eiffel warnings. I did not change the syntax of all the example files to match SE's standard case settings and I didn't remove the empty argument lists. You can add the -no_warnings switch to the 'compile' command which will stop any warning message being displayed. You will also get warnings about features being used but not created first. Ignore these.

In the 'helpex' example (and maybe one or two of the others) you will also need to add 'resources.res' to the 'compile' command line as this file contains the images for the toolbar buttons. Note that .RES files may only work with the Microsoft C++ compilers. Resources are normally handled using the GRAPE ERC mechanism.

I have recently found out that the mallocs I have inserted into the SE version of GRAPE may not be garbage collected. If this is correct then I will make the neccessary changes to get garbage collection to work in the next release. Note that on a non-trivial program the memory consumed is quite small and the memory is released when the application is closed.

Adding resources to your project

GRAPE has it own resource compiler, to create resources for this you will need a copy of the resource editor available with Visual Eiffel. You can use this or you can create your resources from your C compilers resource editor, compile the resources (rc.exe for MSVC) and then link in the generated .RES file at the end of the 'compile' command line. This way you don't have a seperate dll floating around...

Rebuilding GRAPE.LIB

The C files are used to create grape.lib. If all you want to do is code in Eiffel (ahhh, a perfect world :-)) then don't touch the C stuff. Just link grape.lib into your GRAPE project as described above.

To create the .LIB file using a Microsoft C++ compiler, make sure __USE_CECIL__ and _SMALLEIFFEL_ are defined, these are the only _required_ options.

Using other compilers or OS's

The Eiffel classes should work on other OS's that SE supports but the C code would need to be converted. The C code can now be compiled for use with either Object Tools Visual Eiffel or SmallEiffel. I plan to get it going under ISE Eiffel also.

I have successfully compiled the GRAPE library using the free LCC-WIN32 compiler. However, Even though LCC-WIN32 links successfully the GRAPE applications do not work because the MSDOS 'main' routine is called instead of the the windows 'winmain' function.

If you want to convert GRAPE to another OS or compiler I will be happy to let you know what is required.

Thanks

Many thanks go to Object Tools(www.object-tools.com) for releasing GRAPE as Open Source. Thanks go to Geoff Eldridge for the incentive to get this far :-)

If you have any new functions you would like incorporated into GRAPE I would appreciate it if they did not modify any of the existing GRAPE classes is such a way that old programs wont work. Sometimes this may be needed but we should avoid having a dozen version of GRAPE available, all being incompatible with each other!

Bug fixes are a different propersition please make sure you send them to me!

Of course, this is not my code, The licence specified by Object Tools still applies and I am not responsible for any damages to anything whatsoever. Use at your own risk.

Enjoy!
Steven White


[ Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters ]