Home

Awesome

winforms2gtk (or in short w2gtk)

winforms2gtk, a program to help in the conversion of Windows Forms to Glade, the GTK UID

This is a program to help in the conversion of the User Interface (UI) of Visual Basic Microsoft Windows Forms applications to Gtk and Ada.

Windows provides Visual Studio as a Rapid Application Development tool including its User Interface Designer. For each window, several files are produced, defining a Windows Form.

Correspondingly, Gtk also has a Rapid Application Development tool, called Glade.

The goal of winforms2gtk is to help in the translation of these files to Glade format such that the output (a sort ov XML) can be used in GTK applications.

Not only the glade file is produced but also several Ada files such as the gpr, the main window, the widget collection, the signal callbacks and several enumerations files.

This is still an on-going project however it is gaining stability ans it is now usable.

Dependencies

You should have the following tools installed:

Building winforms2gtk

Once downloaded, just double-click on w2gtk.gpr and build it inside GNAT Studio.

You can change compilation/building options in w2gtk.gpr if you wish. Initially, the switches are those used by ACT in their programs.

Using winforms2gtk

The best way is to use a shell script to convert all windows forms of an application. Calling w2gtk can be as

w2gtk -rp wpath -rf wfile -gp gpath -gf gfile -h --help -glade -dump -log -ap apath

Switches that are accepted by winforms2gtk:

Mechanics of the translation

A Windows Forms is described in three files:

w2gtk starts by parsing some parts of the Designer to identify windows and widgets. Then it continues by parsing the Resource file to get the majority of attributes or properties. It comes back again to the Designer to complete the attributes and continues to partially parse the Visual Basic code to identify the handlers.

Then, w2gtk can generate, depending upon the switches:

Note that parsing of the three windows form files is no complete and may fail. It covers the most usual options only. A complete parser for these files is considered out-of-scope.

For the case of a top level window, w2gtk generates also the corresponding gpr file. A Windows' window is considered top level when it is resizable and not modal. In other case, it is considered a dialog.

Also note that, in general, it is usual in Windows Forms to employ relative position of elements in dialogs whilst GTK is more oriented to automatic placement by using boxes (although Windows has a control called FlowLayoutPanel that plays the same role). Converting relative position to automatic placement is not even attempted. Instead, an intermediate GTKFixed box is generated, where the Windows Forms elements are then placed using the specific location and size.

The visual result is not always perfect. In the glade file generated by winforms2gtk you should fine-tune the positions to get a correct visual impression of the window. Sorry for that. Or even better, replace the GtkFixed by automatic positioning Gtk Widgets such as GtkBox. Note in any case that converting FlowLayoutPanel to gtkbox is performed by w2gtk.

Currently the generated GTK top level windows are:

Also currently the generated GTK widgets are:

Pending widgets:

Other Windows Forms elements are generated:

In addition, several Windows Forms elements are accepted however code is not generated:

and perphaps others

This is a work in progress. there are items pending to convert and also some of the generated widgets merit an improvement.

The generate the Ada files are:

You can then modify these files to build your application. No line of your code will be lost as w2gtk will include your modifications in the newly generated files by backing up, as a first step, your files to an increasing version using "~" and then using diff and patch. These backups files are kept as well the patch to facilitate manual checks of the inclusion.

Recommendation:

Before purging backup files, check that the .log for errors and if there are any, recover your files from the backup and correct the errors.

Testing

Testing is performed by using the elements of an actual Windows application with about 70 forms with the listed Windows elements.

Bug reports

Please send questions and bug reports to the author. Of course, any help/contributions are welcome.