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:
- The GNAT Ada Compilation System, including GNAT Studio. Ada Core Technologies (ACT) Community editions are OK
- GTK Libraries
- Glade
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:
- -rp windows forms path
- -rf windows forms name with no extension
- -gp path where place the generated files
- -gf name (with no extension) of the generated glade file
- -ip path to icons
- -glade generate the glade file
- -ap path where to place the generated Ada files
- -dump produce a dump of the windows and widgets
- -log produce lots of messages when progressing in the translation
- -h or --help help
Mechanics of the translation
A Windows Forms is described in three files:
- The Designer file (ending in .Designer.vb)
- The Resource file (ending in .resx)
- The Visual Basic code (ending in .vb)
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:
- a dump of the information (ending in .dump)
- a log file (ending in .log)
- the XML file (ending in .glade) containing the glade definition of the GTK windows and widgets
- several Ada files to support the application
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:
- GtkWindow
- GtkDialog
- GtkFileChooserDialog
- GtkFileFilter
- GtkEntryBuffer
- GtkListStore
- GtkTreeStore
- GtkImage
- Cell Renderer
Also currently the generated GTK widgets are:
- GtkLabel
- GtkEntry
- GtkComboTextBox (unsorted)
- GtkButton (with possibly image)
- GtkRadioButton (with possibly image)
- GtkCheckButton (with possibly image)
- GtkToggleButton (with possibly image)
- GtkImage
- GtkSpinButton
- GtkFrame
- GtkBox
- GtkToolTip
- GtkCalendar
- GtkColorButton
- GtkListBox
- GtkMenu and siblings
- GtkToolBar and siblings
- GtkNotebook
- GtkTreeview and siblings
- GtkStatusbar
Pending widgets:
- GtkCombobox and sorted GtkComboTextBox
Other Windows Forms elements are generated:
- Date Picker
- Time Picker
In addition, several Windows Forms elements are accepted however code is not generated:
- PrintDocument
- PrintDialog
- FolderBrowserDialog
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:
- a gpr (only for top level window)
- a css (only for top level window) that can be used as template
- the main window Ada file
- the widget collection file within the window
- the signal callbacks
- the register signals Ada file
- Ada enumerations (for gtkstores) file
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.