Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Building Robust UIs in Mono with Gtk#

Learn to use the native Gtk# GUI toolkit to build Mono-based desktop applications today.


advertisement
ust as Microsoft provides a native desktop UI toolkit called Windows Forms that ships with Microsoft .NET, the Mono project provides a compatible implementation of this same API, making it possible to build Windows Forms-based applications that run under a variety of operating systems.
Author's Note: When this article was written, Mono's implementation of Windows Forms had not yet been finalized (see this blog to view the current status of the project).

Even though Mono's Windows Forms implementation is not yet feature-complete you can use Mono to build robust desktop applications today by choosing an alternative API (see Table 1).

Table 1. A Survey of .NET desktop APIs: The table shows some of the APIs available for building desktop applications with Mono.

.NET Desktop
GUI API
Description
Gtk# Gtk# is considered the "native" GUI toolkit that ships with the Mono platform.
Glade# Glade# is an extension to Gtk#. Beyond adding several useful widgets, GUIs built using Glade# can be described via XML and bound to a runtime object model.
Cocoa# Cocoa# is a managed wrapper around the native Mac OS X cocoa API.
wx.NET Wx.NET is a wrapper around the platform-independent wx toolkit. A (major) benefit of Wx.NET is that it maintains the correct look-and-feel of the host OS (including Mac OS X).

This article introduces you to a very popular .NET GUI alternative named Gtk#. As you would expect from a modern-day desktop API, Gtk# provides a very rich fabric for building desktop applications. I'll discuss the following core topics:
  • Building main windows
  • Working with widgets
  • Creating menu systems
  • Understanding the role of HBox and VBox types
  • Creating and using dialog boxes
Author's Note: This article assumes that you're comfortable with C# and working with the .NET type system (classes, interfaces, enumerations, structures and delegates).

Getting to Know Gtk#
Gtk# is a managed wrapper around a Linux-centric API termed Gtk+. Gtk+ is a toolkit originally created to build the popular image processing application GIMP (the GNU Image Manipulation Program), which explains the origin of the acronym 'Gtk': GIMP Tool Kit.

Although Gtk+ was originally developed for use on Unix/Linux, this API has been ported to numerous operating systems (Win32, Mac OX X, etc). Given the connection between Gtk# and Gtk+, it should come as no surprise that you can use Gtk# to build platform-independent user interfaces on any operating system that supports Gtk+. Structurally, Gtk# consists of a set of .NET assemblies deployed to the Mono Global Assembly Cache. Table 2 defines the role of the core Gtk# assemblies.



Table 2. The Core Gtk# Assemblies: The table lists the most important Gtk# assemblies and a description of each.

Gtk# Assembly Description
gtk-sharp.dll Defines the core UI .NET bindings to Gtk+.
glib-sharp.dll Defines additional (non-UI) .NET bindings to Gtk+.
pango-sharp.dll Provides binding to the Pango API, used to format and internationalize textual data.
atk-sharp.dll Binding for the atk accessibility API.
gdk-sharp.dll Defines numerous low-level rendering APIs.
glade-sharp.dll Provides support for Glade development with Gtk#.
art-sharp.dll A vector rending library.
rsvg-sharp.dll A SVG rendering library.

 
Figure 1. The MonoDoc UI: MonoDoc provides solid documentation for Gtk#.
The Mono installation automatically deploys the Gtk# assemblies to the Mono GAC when you install the Mono platform on a Windows or Linux-based OS. Do be aware that installing Gtk# on Mac OS X is a bit more involved. Interested individuals can find OS X installation instructions here. While this article will in no way attempt to dive into the details of every type found within each Gtk# assembly, you'll find the API is well documented in the MonoDoc utility (see Figure 1).

A Survey of Gtk# Development Options
In this article you'll see how to build several Gtk# applications at the command line using the Mono C# compiler (gmcs) and your text editor of choice. I realize that this is not the visual GUI-building process you may be used to in Visual Studio, but bear with me—this approach is ideal from a learning point of view. Rest assured that if you are serious about building Gtk# user interfaces, several Mono-aware IDEs provide design time assistance. Table 3 documents several possibilities.

Author's Note: See Mono IDEs: Going Beyond the Command Line for more information on these Mono-aware IDEs.

Table 3. Mono-Aware IDEs: The table lists several IDEs that offer visual design support for Gtk# development.
.NET Desktop UI Technology Description
#develop SharpDevelop 2.0 provides Gtk# and Glade# project templates, however it currently lacks visual designer support.
MonoDevelop Provides a variety of visual tools for building Gtk# / Glade# projects.
X-Develop Provides a variety of visual tools for building Gtk# / Glade# projects.

In addition to the IDEs in Table 3, it is possible to build Gtk# applications using Visual Studio 2005 (as well as earlier editions of the product). Check out the following blog for more information.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap