OpenDialog Review
Volume Number: 13 (1997)
Issue Number: 5
Column Tag: Tools Of The Trade
OpenDialog
by Edward Ringel
Specialized dialog functions library for the industrial strength programmer
The Dialog Manager is a flexible package that is used by almost everyone creating forms for Macintosh applications. For some applications, these forms are limited to setting preferences or a few other limited tasks. In this situation, extensive customization of the dialog is unnecessary, and Toolbox calls are more than sufficient. In other circumstances, a series of dialogs, modal and modeless, may be the core of the project and represent the bulk of the user interface. In these applications, customization of the dialogs may be desirable and even mandatory. In this setting, the direct Dialog Manager calls may be clumsy and require large amounts of coding to achieve input filtering, relating data structures to items, cursor management, and the like.
Object oriented technologies have devised schemes to exercise considerable control over forms-style GUIs. Procedural programmers usually have a collection of routines and libraries tucked away which simplify the problem, at least to a degree. From time to time various programming tools become available which also purport to simplify the life of the dialog-forms programmer. OpenDialog is such a package.
Dialog Manager Replacement
OpenDialog is engineered and supported by FGM, Inc. of Herndon, VA. This company's primary business activity is writing end-user software, not creating programming tools. Nonetheless, their collection of routines and their systematic approach to addressing Dialog Manager problems and deficiencies resulted in a library that clearly has commercial appeal. As FGM states in its ads and introductory literature, this is a replacement for the Dialog Manager. It is recommended that you do not use OpenDialog and Dialog Manager calls on OpenDialog dialogs because, as the manual says, "the results may be unreliable."
When OpenDialog creates a new dialog (modal, moveable modal, and modeless dialogs are all supported) it creates private data structures and tags the dialog as its own. The library supplies a function, DMX_ItzaODlogWindow(), to test whether a dialog belongs to the OpenDialog manager or not. As a replacement for the Dialog Manager, OpenDialog has an equivalent function for just about all of the Dialog Manager functions.
With the exception of a few calls, the replacement function and the original function have very similar names and parameter lists; this is obviously helpful and important. Parameter lists are different when functionality is extended. DMX_GetNewDialog() may be a good example; this function's parameter list allows the programmer to specify if the dialog is to be modal or modeless, to assign a text style for the dialog, and to set flags for event handling.
As may be apparent from these two function call examples, the function calls all start with DMX_; this permits easy differentiation from Toolbox calls in your code. Throughout the library, there is a clear and consistent nomenclature that was very easy to follow; this helped shorten the learning curve considerably.
Extensions to the Dialog Manager
Clearly, one does not purchase a library to simply have a different prefix to a function. OpenDialog provides a very wide range of extensions to the services provided by the Toolbox.
One very nice feature of the product is item tagging. Every item in a dialog can have text associated with it; OpenDialog takes advantage of this to allow for customization of the item at the resource level. As I describe below, one powerful use of this feature is to customize an edit field to create filtering. Another is to "name" an item and free the programmer from needing to remember a DITL number. Controls and other elements may also be customized with item tagging. I think that the ability to set filtering (and other services) at the resource level is in the best spirit of Macintosh programming tools.
The largest (and probably for many programmers, the most important) group of services have to do with editable text boxes. By tagging the edit text item's default text in the resource editor, one can limit the number of characters in an entry, force numerical data only, etc. Getting and setting data from a text box is much, much easier than with Toolbox calls. To get any item's text, one simply calls pascal void DMX_GetItemText(const DialogPtr aDlog, short aItemNumber, Str255 aString), and to set the text, one calls the counterpart function, pascal void DMX_SetItemText(const DialogPtr aDlog, short aItemNumber, const Str255 aString). Specialized getters and setters for date, time and latitude and longitude are also supplied. Although one might functionally group cursor control with other types of service extension, the library supplies an automatic I-Beam cursor if the field is initialized correctly. To give a flavor of OpenDialog calls, below is a listing from a short program I converted to OpenDialog. This function creates a modeless dialog, counts the number of dialog items, tests to see if the item is of type editText, and if it is, installs automatic I-Beam management.
void CreateModelessDialog(short DialogID, DialogPtr *theNewDialog)
{
short tempType;
short numItems;
short i;
*theNewDialog = NULL;
*theNewDialog = DMX_GetNewDialog
(DialogID, kDMX_Modeless, 0L,kDMFlag_DoIdleEvents);
if (*theNewDialog !=NULL) {
numItems = DMX_CountDITL(*theNewDialog) +1;
for (i=1;i<numItems; i++){
tempType = DMX_GetItemType(*theNewDialog,i);
if (tempType==editText)
DMX_SetIBarFlag(*theNewDialog,i,true);
}
ShowWindow(*theNewDialog);
SetPort(*theNewDialog);
}
return;
}
OpenDialog also supports a variety of extensions to the dialog manager that are not directly edit-field related. Among others, OD has scrollable text, twisters (Finder type triangles), and specialized support for multiple pane dialogs. Although some elements, such as lists, are not supported directly, there is help provided with functions such as DMX_CouldFocus(), which allows the active user item to receive keyboard events.
OpenDialog contains a number of very valuable utility functions. It has a fairly large subset of ANSI library and other string and number utility functions, which eliminate dependence on much of the ANSI library functions. There's a nice call that gets extensive volume information. There are several functions for putting up a quick "question" alert, an error message alert, and a password dialog.
Perhaps of greatest utility are the callback functions. One can attach a callback to any item for any purpose. (Well, I guess I'm exaggerating a little, but you really can attach a callback to any item.) Event handlers, specialized update routines, data entry filters, cursor callbacks, action procedures and the like can all be attached with relative ease. While this part of the package has the steepest learning curve, it clearly also holds the most bounty. Since much of the interaction is with the Toolbox, many of the callbacks are framed as Universal Procedure Pointers, and appropriate macros are provided. All in all, this is a very robust package.
What OpenDialog is Not
OpenDialog is not a GUI builder, nor is it an application shell. This is a replacement and extension to the Dialog Manager, and no other services are provided, except in bits and pieces. For example, in my program which I converted to OD, I still had to SetPort() on my own after bringing a modeless window to the front. Window Manager routines work on OpenDialog dialogs without difficulty, and are used extensively when working with modeless dialogs. I think it is particularly important that OpenDialog's limitation be recognized. The novice or early intermediate programmer will certainly be able to use the package, but will feel somewhat unsupported in the lack of event loop support and help with printing, etc.
Documentation
The documentation of this package is difficult to characterize, as parts of it are very good, and other parts are problematic. There is an initial short introduction to the OpenDialog programming paradigm, and the remainder of the manual is a description of all the functions. The document, as I received it, was in e-doc format and about 12 months out of date. A large supplement of functions had been added and were in a Simple Text "Read Me" file.
The documentation present is quite good. The function descriptions follow a nice format, and I knew how to use a given function after reading the manual section describing it. The introduction gave me a good general feel for how the guys at FGM were approaching the dialog problem. e-doc format does not permit hypertext cross referencing - I think this is a must for electronic documentation; I would very much have liked to see some means of accessing a function description rapidly. I was unhappy that the manual was dozens of new functions out of date.
The primary instruction for the real-life use of the program is in the sample program and the DMC.h header file. The sample program is large, complex, and somewhat hard to follow; the demo shows off the features nicely, but I would have preferred a series of smaller programs that were easier to read and digest. My test conversion program used modeless dialogs, and there was no demonstration of how to use OpenDialog for modeless dialog work. An email to FGM resolved this quickly, and Charlie Vass, the engineer, was most helpful. When all is said and done, the information is there, and describes the product correctly, but could do with improvement in formatting and accessibility.
The Bottom Line
OpenDialog is a set of powerful routines that can simplify life tremendously for programmers pushing the Dialog Manager to its limits. I could see this product being quite helpful to anyone developing complex electronic forms in a procedural language. There is probably less of a need for this product with object oriented frameworks, given the design paradigm of a window view object populated by other views object. This product should not be used by a novice programmer.
OpenDialog is available directly from FGM for US$ 259. The package consists of documentation, a header file, and both 68K and PPC libraries for CodeWarrior. Libraries are available for the Symantec environment. All functions are declared pascal, and the commercial package comes with a Pascal interface file.
OpenDialog Lite is a free, limited version of OpenDialog (lacks some of the newer functions and does not have any documentation except for the sample program and header file) and is available on the CW 11 disk. It's a great way to test drive the product. I urge anyone with some programming experience and a need for sophisticated forms to look into this package.
Products Reviewed in this Article
OpenDialog, version 1.2.3 using C interface and CW 10.
Usefull URL's
<www.fgm.com>