Motif Programming Manual
1 Preface...........................................................................................................................................................................1
1.1 The Plot..........................................................................................................................................................1
1.2 Assumptions...................................................................................................................................................2
1.3 How This Book Is Organized........................................................................................................................3
1.4 Related Documents........................................................................................................................................5
1.5 Conventions Used in This Book....................................................................................................................6
1.6 Obtaining Motif.............................................................................................................................................6
1.7 Obtaining the Example Programs..................................................................................................................7
1.7.1 FTP.................................................................................................................................................7
1.7.2 FTPMAIL......................................................................................................................................7
1.7.3 BITFTP..........................................................................................................................................8
1.7.4 UUCP.............................................................................................................................................9
1.7.5 Copyright.......................................................................................................................................9
1.7.6 Compiling the Example Programs.................................................................................................9
1.8 Notes on Z−Mail............................................................................................................................................9
1.9 Acknowledgments........................................................................................................................................10
1.10 We'd Like to Hear From You.....................................................................................................................12
2 Introduction to Motif.................................................................................................................................................13
2.1 A True Story................................................................................................................................................13
2.2 Basic User−interface Concepts....................................................................................................................15
2.3 What Is Motif?.............................................................................................................................................16
2.4 Designing User Interfaces............................................................................................................................18
3 The Motif Programming Model................................................................................................................................21
3.1 Basic X Toolkit Terminology and Concepts...............................................................................................21
3.2 The Xm and Xt Libraries.............................................................................................................................23
3.3 Programming With Xt and Motif.................................................................................................................24
3.3.1 Header Files.................................................................................................................................26
3.3.2 Setting the Language Procedure..................................................................................................27
3.3.3 Initializing the Toolkit.................................................................................................................28
3.3.4 Creating Widgets.........................................................................................................................30
3.3.5 Setting and Getting Widget Resources........................................................................................32
3.3.6 Event Handling for Widgets........................................................................................................37
3.3.7 The Event Loop............................................................................................................................42
3.4 Summary......................................................................................................................................................42
4 Overview of the Motif Toolkit...................................................................................................................................43
4.1 The Motif Style............................................................................................................................................43
4.2 Application Controls....................................................................................................................................45
4.2.1 The Primitive Widget Class.........................................................................................................46
4.2.2 Gadgets........................................................................................................................................51
4.3 Application Layout......................................................................................................................................52
4.3.1 The Manager Widget Class..........................................................................................................54
4.3.2 Geometry Management................................................................................................................56
4.3.3 Gadget Management....................................................................................................................57
4.3.4 Keyboard Traversal......................................................................................................................58
4.4 Putting Together a Complete Application...................................................................................................59
4.4.1 The Main Window.......................................................................................................................59
4.4.2 Menus...........................................................................................................................................61
i
Motif Programming Manual
4 Overview of the Motif Toolkit
4.4.3 The Window Manager.................................................................................................................62
4.4.4 Dialogs.........................................................................................................................................66
4.4.5 Pixmaps........................................................................................................................................71
4.4.6 Color............................................................................................................................................73
4.5 Changes in Motif 1.2....................................................................................................................................75
4.5.1 General Toolkit Changes.............................................................................................................76
4.5.2 Specific Widget Changes.............................................................................................................78
4.5.3 Changes to the Example Programs..............................................................................................80
4.6 Summary......................................................................................................................................................80
5 The Main Window.....................................................................................................................................................81
5.1 Creating a MainWindow..............................................................................................................................82
5.2 The MenuBar...............................................................................................................................................87
5.2.1 Creating a PulldownMenu...........................................................................................................88
5.2.2 SimpleMenu Callback Routines..................................................................................................90
5.2.3 A Sample Application..................................................................................................................92
5.3 The Command and Message Areas............................................................................................................100
5.4 Using Resources.........................................................................................................................................104
5.5 Summary....................................................................................................................................................105
5.6 Exercises....................................................................................................................................................106
6 Introduction to Dialogs............................................................................................................................................107
6.1 The Purpose of Dialogs..............................................................................................................................107
6.2 The Anatomy of a Dialog..........................................................................................................................110
6.3 Creating Motif Dialogs..............................................................................................................................111
6.3.1 Dialog Header Files...................................................................................................................112
6.3.2 Creating a Dialog.......................................................................................................................112
6.3.3 Setting Resources.......................................................................................................................113
6.3.4 Dialog Management...................................................................................................................114
6.3.5 Closing Dialogs..........................................................................................................................118
6.3.6 Generalizing Dialog Creation....................................................................................................119
6.4 Dialog Resources.......................................................................................................................................120
6.4.1 The Default Button....................................................................................................................120
6.4.2 Initial Keyboard Focus...............................................................................................................122
6.4.3 Button Sizes...............................................................................................................................122
6.4.4 The Dialog Title.........................................................................................................................123
6.4.5 Dialog Resizing..........................................................................................................................123
6.4.6 Dialog Fonts...............................................................................................................................124
6.5 Dialog Callback Routines..........................................................................................................................124
6.6 Piercing the Dialog Abstraction.................................................................................................................127
6.6.1 Convenience Routines...............................................................................................................127
6.6.2 The DialogShell.........................................................................................................................128
6.6.3 Internal Widgets.........................................................................................................................130
6.7 Dialog Modality.........................................................................................................................................131
6.7.1 Implementing Modal Dialogs....................................................................................................133
6.7.2 Forcing an Immediate Response................................................................................................136
6.8 Summary....................................................................................................................................................142
ii
Motif Programming Manual
7 Selection Dialogs.......................................................................................................................................................143
7.1 Types of SelectionDialogs.........................................................................................................................143
7.2 SelectionDialogs........................................................................................................................................144
7.2.1 Callback Routines......................................................................................................................148
7.2.2 Internal Widgets.........................................................................................................................149
7.3 PromptDialogs...........................................................................................................................................150
7.4 The Command Widget...............................................................................................................................152
7.5 FileSelectionDialogs..................................................................................................................................154
7.5.1 Creating a FileSelectionDialog..................................................................................................156
7.5.2 Internal Widgets.........................................................................................................................157
7.5.3 Callback Routines......................................................................................................................158
7.5.4 File Searching............................................................................................................................158
7.6 Summary....................................................................................................................................................164
8 Custom Dialogs.........................................................................................................................................................165
8.1 Modifying Motif Dialogs...........................................................................................................................165
8.1.1 Modifying MessageDialogs.......................................................................................................165
8.1.2 Modifying SelectionDialogs......................................................................................................168
8.2 Designing New Dialogs.............................................................................................................................172
8.2.1 The Shell....................................................................................................................................173
8.2.2 The Manager Child....................................................................................................................173
8.2.3 The Control Area.......................................................................................................................174
8.2.4 The Action Area.........................................................................................................................174
8.3 Building a Dialog.......................................................................................................................................176
8.3.1 The Shell....................................................................................................................................183
8.3.2 The Manager Child....................................................................................................................184
8.3.3 The Control Area.......................................................................................................................185
8.3.4 The Action Area.........................................................................................................................186
8.4 Generalizing the Action Area....................................................................................................................188
8.5 Using a TopLevelShell for a Dialog..........................................................................................................194
8.6 Positioning Dialogs....................................................................................................................................196
8.7 Summary....................................................................................................................................................198
9 Manager Widgets.....................................................................................................................................................199
9.1 Types of Manager Widgets........................................................................................................................199
9.2 Creating Manager Widgets........................................................................................................................200
9.3 The BulletinBoard Widget.........................................................................................................................202
9.3.1 Resources...................................................................................................................................202
9.3.2 Geometry Management..............................................................................................................203
9.4 The Form Widget.......................................................................................................................................207
9.4.1 Form Attachments......................................................................................................................207
9.4.2 Attachment Offsets....................................................................................................................213
9.4.3 Position Attachments.................................................................................................................216
9.4.4 Additional Resources.................................................................................................................219
9.4.5 Nested Forms.............................................................................................................................220
9.4.6 Common Problems....................................................................................................................222
9.5 The RowColumn Widget...........................................................................................................................224
9.5.1 Rows and Columns....................................................................................................................226
9.5.2 Homogeneous Children.............................................................................................................230
9.5.3 Callbacks....................................................................................................................................231
iii
Motif Programming Manual
9 Manager Widgets
9.6 The Frame Widget.....................................................................................................................................233
9.7 The PanedWindow Widget........................................................................................................................236
9.7.1 Pane Constraints........................................................................................................................239
9.7.2 Sashes.........................................................................................................................................242
9.8 Keyboard Traversal....................................................................................................................................242
9.8.1 Turning Traversal Off................................................................................................................244
9.8.2 Modifying Tab Groups..............................................................................................................246
9.8.3 Handling Event Translations......................................................................................................247
9.8.4 Processing Traversal Manually..................................................................................................248
9.9 Summary....................................................................................................................................................251
10 ScrolledWindows and ScrollBars.........................................................................................................................252
10.1 The ScrolledWindow Design Model.......................................................................................................252
10.1.1 The Automatic Scrolling Model..............................................................................................252
10.1.2 The Application−defined Scrolling Model..............................................................................253
10.2 Creating a ScrolledWindow.....................................................................................................................255
10.2.1 Automatic Scrolling.................................................................................................................255
10.2.2 Application−defined Scrolling.................................................................................................256
10.2.3 Additional Resources...............................................................................................................256
10.2.4 An Automatic ScrolledWindow Example...............................................................................256
10.3 Working Directly With ScrollBars..........................................................................................................260
10.3.1 Resources.................................................................................................................................262
10.3.2 Orientation...............................................................................................................................265
10.3.3 Callback Routines....................................................................................................................266
10.4 Implementing True Application−defined Scrolling.................................................................................269
10.5 Working With Keyboard Traversal in ScrolledWindows........................................................................279
10.6 Summary..................................................................................................................................................281
10.7 Exercises..................................................................................................................................................281
11 The DrawingArea Widget.....................................................................................................................................282
11.1 Creating a DrawingArea Widget.............................................................................................................282
11.2 Using DrawingArea Callback Functions.................................................................................................283
11.2.1 Handling Input Events.............................................................................................................284
11.2.2 Redrawing a DrawingArea......................................................................................................287
11.3 Using Translations on a DrawingArea.....................................................................................................290
11.4 Using Color in a DrawingArea................................................................................................................296
11.5 Summary..................................................................................................................................................301
11.6 Exercises..................................................................................................................................................301
12 Labels and Buttons.................................................................................................................................................303
12.1 Labels.......................................................................................................................................................303
12.1.1 Creating a Label.......................................................................................................................304
12.1.2 Text Labels...............................................................................................................................305
12.1.3 Images as Labels......................................................................................................................306
12.1.4 Label Sensitivity......................................................................................................................308
12.1.5 Label Alignment......................................................................................................................309
12.1.6 Multi−line and Multi−font Labels...........................................................................................310
12.2 PushButtons.............................................................................................................................................313
12.2.1 PushButton Callbacks..............................................................................................................314
iv
Motif Programming Manual
12 Labels and Buttons
12.2.2 Multiple Button Clicks.............................................................................................................316
12.3 ToggleButtons..........................................................................................................................................318
12.3.1 Creating ToggleButtons...........................................................................................................319
12.3.2 ToggleButton Resources..........................................................................................................320
12.3.3 ToggleButton Pixmaps............................................................................................................321
12.3.4 ToggleButton Callbacks..........................................................................................................323
12.3.5 RadioBoxes..............................................................................................................................324
12.3.6 CheckBoxes.............................................................................................................................328
12.4 ArrowButtons...........................................................................................................................................331
12.5 DrawnButtons..........................................................................................................................................336
12.6 Summary..................................................................................................................................................339
12.7 Exercise....................................................................................................................................................340
13 The List Widget......................................................................................................................................................341
13.1 Creating a List Widget.............................................................................................................................342
13.2 Using ScrolledLists..................................................................................................................................345
13.3 Manipulating Items..................................................................................................................................346
13.3.1 Adding Items............................................................................................................................347
13.3.2 Finding Items...........................................................................................................................350
13.3.3 Replacing Items.......................................................................................................................351
13.3.4 Deleting Items..........................................................................................................................352
13.3.5 Selecting Items.........................................................................................................................353
13.3.6 An Example.............................................................................................................................355
13.4 Positioning the List..................................................................................................................................359
13.5 List Callback Routines.............................................................................................................................361
13.5.1 The Default Action..................................................................................................................361
13.5.2 Browse and Single Selection Callbacks...................................................................................362
13.5.3 Multiple Selection Callback.....................................................................................................364
13.5.4 Extended Selection Callback...................................................................................................365
13.6 Summary..................................................................................................................................................366
13.7 Exercises..................................................................................................................................................366
14 The Scale Widget....................................................................................................................................................367
14.1 Creating a Scale Widget...........................................................................................................................367
14.2 Scale Values.............................................................................................................................................370
14.3 Scale Orientation and Movement.............................................................................................................371
14.4 Scale Callbacks........................................................................................................................................371
14.5 Scale Tick Marks.....................................................................................................................................375
14.6 Summary..................................................................................................................................................376
15 Text Widgets...........................................................................................................................................................377
15.1 Interacting With Text Widgets.................................................................................................................378
15.1.1 Inserting Text...........................................................................................................................378
15.1.2 Selecting Text..........................................................................................................................379
15.2 Text Widget Basics..................................................................................................................................381
15.2.1 The Textual Data......................................................................................................................381
15.2.2 Single and Multiple Lines........................................................................................................383
15.2.3 Scrollable Text.........................................................................................................................384
15.2.4 Text Positions..........................................................................................................................390
v

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.