---

IBM developerWorks: GNOMEnclature: Handling multiple documents – Using the GnomeMDI framework

In this installment, George Lebl turns away from widgets to
look at GnomeMDI, the Multiple Documents Interface from gnome-libs.
GnomeMDI makes it easier to handle a variety of different documents
at the same time in one program.

“Many end-user applications are document-centric (that is, they
are tools for manipulating documents of one type or another). End
users of these applications generally consider them merely a
convenient way to modify a document. (Applications that are not
document-centric focus on things like the program itself; games are
a good example of this). From the end user’s perspective, it’s
easier to think of document-centric applications in terms of
opening new documents, rather than in terms of running a program.
When you look at it this way, the program just happens to start up
when you open a document. Taking this perspective one step further,
there should be nothing too strange about editing multiple
documents at the same time. However, as most programmers know,
running multiple instances of one program does not work all that
smoothly. The two primary problems are that multiple instances do
not cooperate nicely and they take up way too much memory. A
Multiple Document Interface such as the GnomeMDI simplifies these
problems by handling the user interface. So, let’s take a closer
look at how the GnomeMDI does this.”

“GnomeMDI is actually not a widget but a simple object, because
it derives directly from GtkObject, the main object of your
application. Most likely, you will create only one of these and
store it as a global variable. The document we will create here is
the GnomeMDIChild, which is actually a second type of simple object
altogether. (If your application were opening files, for example,
there would be exactly one GnomeMDIChild for each file.) Each
GnomeMDIChild can also have one or more views. Each view is a
GtkWidget, which knows how to display the data that GnomeMDIChild
stores. Now this is where the tricky part comes in. In order to use
GnomeMDI, you must be able to store all data relevant to a file
without having any view. You must also be able to update several
views simultaneously. You should not therefore store any data in
the view widget itself. You should always be able to generate
another view, purely from the data stored in the GnomeMDIChild
object. This is usually called the Model/View/Controller
design.”


Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis