Register your product to gain access to bonus material or receive a coupon.
The creator of Desktop KornShell (dtksh) details how to use the worldwide standard scripting language for creating Motif applications. As a part of the Common Desktop Environment (CDE), a uniform graphical user interface environment adopted by all the major UNIX companies including Sun, HP, IBM, DEC, and Novell, the Desktop KornShell is an essential tool for all serious UNIX programmers.
This book provides you with a quick introduction to graphical programming and teaches you everything you need to know to create elegant, consistent graphical user interfaces using Desktop KornShell. Written by the creator of the original Desktop KornShell code, this definitive book includes an X Windows tutorial, a comprehensive reference, and a library of useful examples for building your graphical applications.
You will learn the fundamentals of the X Window System, graphical programming concepts, and how to use the X interfaces to program the Desktop KornShell. There are more than 140 programming examples, each demonstrating a particular graphical programming technique; they are also available on Addison-Wesley's ftp site (ftp.aw.com). Also included is a real-life application developed throughout the course of the book to illustrate such interface elements as context-sensitive help, cascading menus, forms, window manager interactions and icon bars.
Figures.
Tables.
Program Listings.
Preface.
Chapter 1. Introduction.
What Is the Desktop KornShell?
Applications Suitable for DTKSH.
Relationship to Other Tools.
Graphical Builder Tools.
Desktop KornShell History.
I. X PROGRAMMING TUTORIAL.
2. X Window Basics.
The Nature of X.
The Ingredients of an X Program.
Your First X Program.
Steps of an X Program.
Resource Commands.
More About Callbacks.
Widget States.
Chapter 3. Motif Widget Taxonomy.
Primitive Widgets.
Gadgets.
Composite Widgets.
Manager Widgets.
Chapter 4. The Standard Main Window.
Checkbook Application Requirements.
Creating the MainWindow Widget.
Creating the MenuBar and Pulldown Menus.
Adding the Work and Message Areas.
Setting the MainWindow Areas.
Scaffolding.
The Real Thing.
Chapter 5. The Standard Dialogs.
General Dialog Concepts.
The Message Dialogs.
The SelectionDialog.
The FileSelectionDialog.
The PromptDialog.
Next Steps.
Chapter 6. Prompting Using Custom Dialogs.
The Two-Column Dialog.
Prompting for Text.
Prompting for Integers.
Prompting for Real Numbers and Money.
Prompting for Dates.
Prompting for Yes/No Values.
Prompting for Multiple Choices.
The ENTER Key in TextFields.
A Complete Example.
Validation.
The User Is Always Right.
Chapter 7. Help Me!
On Being Helpful.
Help File Structure.
The CDE Help Widgets.
Creating Help Volumes and Topics.
A Complete Volume Example.
Compiling the Help Volume.
Testing the Help Volume.
Tying Help into the Application.
Providing Help Using the F1 Key.
Providing Pointer Location Help.
The MainWindow Help Menu.
Chapter 8. Resources and Resource Files.
Using Resource Files.
A Simple Example.
More Complex Specifications.
Setting Resources Via Command Line Options.
Order of Resource Defaults.
The Dtksh Standard Resource File.
A Resource File for the Checkbook Program.
Chapter 9. Widget Layout Using Managers.
Manager Widget General Concepts.
Common Manager Widget Problems.
The RowColumn Widget.
The BulletinBoard Widget.
The PanedWindow Widget.
The Form Widget.
The ScrolledWindow Widget.
A Better Dialog for Checkbook Entry.
Multiple Screen Dialogs.
Chapter10. Providing Feedback During Long Callbacks.
General Concepts.
Changing the Pointer to a Busy Cursor.
Displaying a WorkingDialog.
Progress Indicators.
Following a Logfile.
Using WorkProcs to Break Up a Task.
Chapter 11. Decoration Widgets.
The Separator Widget.
The Label Widget and Gadget.
The Frame Widget. CHAPTER = Chapter 12. Button, Button.
The PushButton Widget and Gadget.
Creating a Button Bar 8 The ArrowButton Widget and Gadget.
The ToggleButton Widget and Gadget.
RadioButtons 8 CheckBoxes.
The DrawnButton Widget.
Chapter 13. Menu, Please.
PullDown Menus.
Advanced Uses of XUmenusystem.
Adding and Removing Menu Items.
Creating PulldownMenus Without Xumenusystem.
Tear-Off Menus.
Accelerators.
Option Menus.
Popup Menus.
Chapter 14. The Scale Widget.
Creating the Scale Widget.
Scale Widget Children.
Scale Callbacks.
Other Scale Widget Resources.
Scale Widget Pitfalls.
Chapter 15. The List Widget.
Creating List Widgets.
List Widget Selection Models.
Modifying the List Items.
Querying the List.
List Widget Callbacks.
Example: The Double List.
Limitations of the List Widget.
Chapter 16. Text and TextField Widgets.
General Features of Text Widgets.
Creating Text Widgets.
Text Widget Appearance Resources.
Text Widget Behavior Resources.
Modifying Text.
The Text Selection and Insertion Point.
Text Widget Command Example.
Searching for Text.
Changing the View.
Text Widget Callbacks.
Highlighting Areas of Text.
Limitations of the Text Widget.
II. ADVANCED PROGRAMMING. Chapter 17. Traditional X Commands.
Command Mapping General Concepts.
Exceptions for Convenience
Resource Mappings.
Call Data Variables.
Event Handlers.
Translations.
Chapter 18. Xlib: Low-Level Graphics.
Xlib General Concepts.
Widgets Used for Drawing.
Drawing Points.
Drawing Lines.
Drawing Rectangles.
Drawing Polygons.
Drawing Circles and Arcs.
Drawing Strings.
Copying and Clearing Areas.
Details, Details.
Chapter 19. Events, Translations, Etc.
General Concepts.
Using Translations.
Event Handlers.
Window Manager Protocols.
Input Handlers.
Timers.
Chapter 20. The Workspace Manager.
Workspace General Concepts.
Querying the Workspace Manager.
Modifying Occupied Workspaces.
Other Workspace Commands.
Common Mistakes.
Workspace Example.
Chapter 21. The Session Manager.
Session Manager General Concepts.
Registering Interest with the Session Manager.
Saving State.
Restoring State.
A Complete Example.
Debugging Considerations.
Chapter 22. Message Catalogs.
Message Catalog General Concepts.
Creating Message Catalogs.
Using Catalogs in a Program.
Using Internationalized String Notation.
Other Considerations.
Chapter 23. Attaching C Code.
Shared Library General Concepts.
Compilation on Different Operating Systems.
Creating New Dtksh Built-in Commands.
Accessing the KornShell Environment.
Using X from Attached Code.
Attached Code Caveats and Pitfalls.
Registering New Widgets.
Chapter 24. Nongraphical Interfaces.
The Action/Invocation Mechanism.
The Data Type Database.
Tooltalk.
III. UTILITIES AND APPLICATIONS.
25. Checkbook Application.
Techniques Illustrated.
Source Code.
Chapter 26. Stock Chart Display.
Techniques Illustrated.
Source Code.
Chapter 27. The X Utilities.
Techniques Illustrated.
Source Code.
IV. REFERENCES.
KornShell Language Review.
Cast of Characters.
Basic Definitions.
Comments.
Command Execution.
Variables.
Conditional Statements.
The Case Statement.
Looping Statements.
Redirection After Compound Commands.
Functions.
Aliases.
Other Built-in Commands.
Chapter 29. KornShell Style Guide.
Comment Conventions.
Sections of the Program.
Function Layout.
Variable Naming Conventions.
Indentation.
Quoting Conventions.
Chapter 30. KornShell Editing Reference.
Emacs Editing Commands.
Miscellaneous.
Vi Editing Commands.
Chapter 31. KornShell Command Reference.
Command Summary.
Alphabetical List of Commands.
Chapter 32. Desktop KornShell Built-in Commands.
Obtaining More Information.
Symbolic Parameters.
Alphabetical List of Commands.
Chapter 33. XU Library Reference.
Simple Aliases.
Widget Creation Commands.
Alphabetical List of Functions.
Chapter 34. Motif Widget Reference.
Standard Sections.
The ApplicationShell Widget.
The Composite Class.
The Constraint Class.
The Core Class.
The ArrowButton Widget and Gadget.
The BulletinBoard Widget.
The BulletinBoardDialog.
The CascadeButton Widget and Gadget.
The CheckBox Widget.
The Command Widget.
The DialogShell Widget.
The DrawingArea Widget.
The DrawnButton Widget.
The FileSelectionBox Widget.
The FileSelectionDialog Widget.
The Form Widget.
The Frame Widget.
The Gadget Class.
The Label Widget and Gadget.
The List Widget.
The MainWindow Widget.
The Manager Class.
The MenuShell Widget.
The MessageBox Widget.
The PanedWindow Widget.
The Primitive Class.
The PushButton Widget and Gadget.
The RowColumn Widget.
The Scale Widget.
The ScrollBar Widget.
The ScrolledWindow Widget.
The SelectionBox Widget.
The Separator Widget and Gadget.
The TextField Widget.
The Text Widget.
The ToggleButton Widget and Gadget.
Appendixes.
Bibliography.
Index. 0201633752T04062001
In early 1991, I wrote the first prototypes of a tool that would eventually evolve into the Desktop KornShell (dtksh for short). After a year or so I thought I was finished, having written a couple of versions of the tool itself, some manual page entries, and seven example programs. Then people started using the tool, and I learned a harsh reality: writing the tool itself is only a small fraction of the work. Writing manual page entries for every language feature is not enough either - that limits your audience to people who like reading manual pages, a dying breed. Writing a short tutorial gets you a little farther - now there will be a handful of people who can muddle through, but they won't be very happy.
What one has to do is write examples that cover virtually every feature in the language and also write a comprehensive tutorial. Undertaking such a project requires that one talk to many dtksh users to find out what they had trouble learning, and for what purposes they are using dtksh, and understanding the most common problems they are likely to encounter. Well, here it is!
Notice that I didn't mention people who know neither shell programming nor X. That was deliberate. No book can be all things to all people, and this one is no exception. Teaching shell programming from scratch is out of bounds for this book. That subject really requires a book of its own, and there are several excellent ones already out there (see the Bibliography). So, if you know absolutely nothing about shell programming, I advise you to start with a more basic tutorial before continuing here.
Readers who are knowledgeable in some shell other than KornShell should carefully study Chapter 28, KornShell Language Review. KornShell is syntactically different from csh, and has many extensions beyond Bourne shell.
Readers who are KornShell programmers should still scan Chapter 28, KornShell Language Review, looking for the KornShell-93 New Feature symbol shown here. It denotes parts of the KornShell language that are new with the latest version (on which dtksh is based). Some of these features are highly useful for graphics programming. Chapter 31, KornShell Command Reference, also uses this icon to highlight commands that are new or changed in KornShell-93.
The shell-knowledgeable reader should then read the X and Motif tutorial chapters (in Part I). These chapters do not assume any prior X experience and should be absorbed carefully. If possible, a system with dtksh installed should be nearby so the reader can experiment with the example programs. Nothing can substitute for hands-on experience when learning graphics programming. The example programs can be obtained over the Internet, so you don't have to type them in (see later section on Obtaining the Example Programs).
A first-time X programmer can skip Part II on first reading. These chapters contain advanced material and sometimes assume the reader is X and C literate.
These readers should study Chapter 28, KornShell Language Review, especially if they are not experts in shell programming or use a shell other than KornShell. If they are very fond of the traditional X function names and arguments, such readers should probably skip right over Part I of this book (which presents a simplified interface) and proceed to Part II. Part II begins with Chapter 17, Traditional X Commands, which is a summary of how the X functions are provided by dtksh.
computer typeface font
is used in the programming examples. In the main body of text, this font is also used to denote dtksh functions, built-in commands, and other programming elements.computer typeface italic font
is used to denote parts of a command that the programmer can choose. Words using this font are merely placeholders; the programmer would not type them in literally. For example, the following specificationtypeset options variable=value
indicates that typeset
and =
are literal strings, whereas options
, variable
, and value
are symbolic and could vary. Also note the usual use of brackets to indicate optional items in syntax summaries.
See Bolsky and Korn 1995 for more details on KornShell programming.
Technical and historical notes, parenthetical remarks, and anecdotes are presented using an indented paragraph in a small typeface. For example:
The main body of the text presents tutorial material; there are times, however, when technical fine points need to be presented for completeness. Instead of using footnotes, this book uses an indented, small-font paragraph for these items. You can skip them if you are not interested in such details.
The tutorial chapters (Part I) illustrate every Motif graphical object with one or more example programs. The chapters in Part III contain several longer examples that show commonly used techniques for combining several graphical objects.
You can obtain the source code for all these examples without cost if you have access to the Internet. Just use the ftp program to contact the Addison-Wesley anonymous file server as follows:
anonymous
. Give your email address as the password.cd /aw.prof.computing.series/pend.dtksh
binary
mget examples.tar.Z
quit
to exit ftp. You are now back at the UNIX shell prompt.uncompress
command on the file:uncompress examples.tar.Z
tar
command to unpack the directory:tar xfv examples.tar
dtksh.examples.
See the README file in that directory for further instructions.If you do not understand how to use the ftp program or the other programs mentioned, ask your system administrator for help or consult UNIX documentation.
XUTILDIR
to be a full path to the dtksh.examples directory you unpacked. For example, if you unpacked the tar file in your $HOME
directory, then you would do the following:XUTILDIR=$HOME/dtksh.examples
export XUTILDIR
Foremost, I must give credit to my wife Victoria. Besides having to put up with a husband who set up an entire computer center in the kitchen for 17 months (including two computers, a laser printer, and a dozen thick reference manuals strewn on every available horizontal surface), she provided me with constant support and encouragement.
David Korn, inventor of the KornShell, was instrumental in making dtksh a reality. He was amazingly responsive to requests for features and changes to the KornShell-93 architecture, many of which were directly for the benefit of dtksh. In addition, he answered many questions about KornShell architecture and provided me with valuable comments on this book, as well as prerelease versions of his own book on KornShell-93 Bolsky and Korn 1995. David also introduced me to John Wait at Addison-Wesley, who, it turns out, was the ideal editor for this work.
Betty Dall, lead engineer of the Common Desktop Environment Motif toolkit subsystem, provided insightful comments on the early versions of this manuscript and invaluable technical advice. In addition, she wrote and formatted most of Chapter 34, Motif Widget Reference, when my wrists (and wits!) started to give out near the end of this project.
David L. Beckedorf, of DLB Research, Inc., was one of the most thorough reviewers I have ever come across. His suggestions ranged from pure grammatical corrections, to fine points of word usage, to highly technical suggestions about X Window System programming. David is a multitalented individual, to be sure.
Bill Baker, of Novell, Inc., tested every single one of the more than 100 example programs to make sure they did what I claimed they did.
Other very useful comments were provided by Louis Iacona, Hok Chun Lee, Terri Laird, Steve Humphrey, Steve Zwaska, Joe Veach, Donald McMinds, Hao Wei Liu, Eric Wallengren, and Ming Gao.
The people at Addison-Wesley were terrific. John Wait took a chance on a new author and patiently answered my frequent questions about how to go about producing this book. His assistant, Kathleen Duff, was quick to offer assistance and support when I needed a fax, overnight delivery, or a contact for advice. Mike Hendrickson kept me on schedule and approved my weird production requests (Bookmark ribbons in the spine? Michelangelo cover art? No problem!). Marty Rabinowitz and the other folks in the production department offered sage advice on formatting. Lorretta Palagi and Hope Steele did a great job copy editing, and W. Richard Stevens provided advice culled from his vast writing experience.
I was fortunate indeed to find this group of talented people willing to spend so much time helping me produce this work. Any errors are, of course, solely my responsibility.
Readers are encouraged to send any suggestions or comments for future revisions of this work to me using electronic mail at the address shown below.
J. Stephen Pendergrast, Jr.
stevepe@aw.com.
May 1995
0201633752P04062001