~ubuntu-branches/ubuntu/trusty/libcdk5/trusty

« back to all changes in this revision

Viewing changes to cli/cdkalphalist.c

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2007-06-06 03:54:31 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070606035431-1ac5o7r653u6qk8e
Tags: upstream-5.0.20060507
ImportĀ upstreamĀ versionĀ 5.0.20060507

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: cdkalphalist.c,v 1.9 2005/03/08 19:51:01 tom Exp $ */
 
1
/* $Id: cdkalphalist.c,v 1.12 2005/12/27 17:26:08 tom Exp $ */
2
2
 
3
 
#include <cdk.h>
 
3
#include <cdk_test.h>
4
4
 
5
5
#ifdef XCURSES
6
6
char *XCursesProgramName="cdkalphalist";
77
77
   {
78
78
      if ((fp = fopen (outputFile, "w")) == 0)
79
79
      {
80
 
         fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
81
 
         exit (-1);
 
80
         fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
 
81
         ExitProgram (CLI_ERROR);
82
82
      }
83
83
   }
84
84
 
88
88
      /* Maybe they gave a filename to use to read. */
89
89
      if (filename != 0)
90
90
      {
91
 
         /* Read the file in. */
92
 
         scrollLines = CDKreadFile (filename, &scrollList);
 
91
         /* Read the file in. */
 
92
         scrollLines = CDKreadFile (filename, &scrollList);
93
93
 
94
 
         /* Check if there was an error. */
95
 
         if (scrollLines == -1)
96
 
         {
97
 
            fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
98
 
            exit (-1);
99
 
         }
 
94
         /* Check if there was an error. */
 
95
         if (scrollLines == -1)
 
96
         {
 
97
            fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
 
98
            ExitProgram (CLI_ERROR);
 
99
         }
100
100
      }
101
101
      else
102
102
      {
103
 
         /* They didn't provide anything. */
104
 
         fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
105
 
         exit (-1);
 
103
         /* They didn't provide anything. */
 
104
         fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
 
105
         ExitProgram (CLI_ERROR);
106
106
      }
107
107
   }
108
108
   else
155
155
   /* Make sure we could create the widget. */
156
156
   if (widget == 0)
157
157
   {
158
 
      /* Clean up some memory. */
159
158
      CDKfreeStrings(scrollList);
160
 
 
161
 
      /* Shut down curses and CDK. */
162
159
      destroyCDKScreen (cdkScreen);
163
160
      endCDK();
164
161
 
165
 
      /* Spit out the message. */
166
162
      fprintf (stderr, "Error: Could not create the alphalist. Is the window too small?\n");
167
163
 
168
 
      /* Exit with an error. */
169
 
      exit (-1);
 
164
      ExitProgram (CLI_ERROR);
170
165
   }
171
166
 
172
167
   /* Split the buttons if they supplied some. */
173
168
   if (buttons != 0)
174
169
   {
175
 
      /* Split the button list up. */
176
170
      buttonList = CDKsplitString (buttons, '\n');
177
171
      buttonCount = CDKcountStrings (buttonList);
178
172
 
179
 
      /* We need to create a buttonbox widget. */
180
173
      buttonWidget = newCDKButtonbox (cdkScreen,
181
174
                                        getbegx (widget->win) + 1,
182
175
                                        getbegy (widget->win) + widget->boxHeight - 1,
184
177
                                        0, 1, buttonCount,
185
178
                                        buttonList, buttonCount,
186
179
                                        A_REVERSE, boxWidget, FALSE);
 
180
      CDKfreeStrings(buttonList);
 
181
 
187
182
      setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
188
183
      setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
189
184
 
190
 
     /*
191
 
      * We need to set the lower left and right
192
 
      * characters of the entry field.
193
 
      */
 
185
      /*
 
186
       * We need to set the lower left and right
 
187
       * characters of the entry field.
 
188
       */
194
189
      setCDKAlphalistLLChar (widget, ACS_LTEE);
195
190
      setCDKAlphalistLRChar (widget, ACS_RTEE);
196
191
 
197
 
     /*
198
 
      * Bind the Tab key in the entry field to send a
199
 
      * Tab key to the button box widget.
200
 
      */
 
192
      /*
 
193
       * Bind the Tab key in the entry field to send a
 
194
       * Tab key to the button box widget.
 
195
       */
201
196
      bindCDKObject (vENTRY, widget->entryField, KEY_RIGHT, widgetCB, buttonWidget);
202
197
      bindCDKObject (vENTRY, widget->entryField, KEY_LEFT, widgetCB, buttonWidget);
203
198
      bindCDKObject (vENTRY, widget->entryField, CDK_NEXT, widgetCB, buttonWidget);
204
199
      bindCDKObject (vENTRY, widget->entryField, CDK_PREV, widgetCB, buttonWidget);
205
200
 
206
 
      /* Check if the user wants to set the background of the widget. */
207
201
      setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
208
202
 
209
 
      /* Draw the button widget. */
210
203
      drawCDKButtonbox (buttonWidget, boxWidget);
211
204
   }
212
205
 
213
 
  /*
214
 
   * If the user asked for a shadow, we need to create one.
215
 
   * I do this instead of using the shadow parameter because
216
 
   * the button widget sin't part of the main widget and if
217
 
   * the user asks for both buttons and a shadow, we need to
218
 
   * create a shadow big enough for both widgets. We'll create
219
 
   * the shadow window using the widgets shadowWin element, so
220
 
   * screen refreshes will draw them as well.
221
 
   */
 
206
   /*
 
207
    * If the user asked for a shadow, we need to create one.  Do this instead
 
208
    * of using the shadow parameter because the button widget is not part of
 
209
    * the main widget and if the user asks for both buttons and a shadow, we
 
210
    * need to create a shadow big enough for both widgets.  Create the shadow
 
211
    * window using the widgets shadowWin element, so screen refreshes will draw
 
212
    * them as well.
 
213
    */
222
214
   if (shadowWidget == TRUE)
223
215
   {
224
216
      /* Determine the height of the shadow window. */
235
227
      /* Make sure we could have created the shadow window. */
236
228
      if (widget->shadowWin != 0)
237
229
      {
238
 
         widget->shadow = TRUE;
 
230
         widget->shadow = TRUE;
239
231
 
240
 
        /*
241
 
         * We force the widget and buttonWidget to be drawn so the
242
 
         * buttonbox widget will be drawn when the widget is activated.
243
 
         * Otherwise the shadow window will draw over the button widget.
244
 
         */
245
 
         drawCDKAlphalist (widget, ObjOf(widget)->box);
246
 
         eraseCDKButtonbox (buttonWidget);
247
 
         drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box);
 
232
         /*
 
233
          * We force the widget and buttonWidget to be drawn so the
 
234
          * buttonbox widget will be drawn when the widget is activated.
 
235
          * Otherwise the shadow window will draw over the button widget.
 
236
          */
 
237
         drawCDKAlphalist (widget, ObjOf(widget)->box);
 
238
         eraseCDKButtonbox (buttonWidget);
 
239
         drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box);
248
240
      }
249
241
   }
250
242
 
261
253
      destroyCDKButtonbox (buttonWidget);
262
254
   }
263
255
 
264
 
   /* Shut down curses. */
 
256
   CDKfreeStrings(scrollList);
 
257
 
265
258
   destroyCDKAlphalist (widget);
266
259
   destroyCDKScreen (cdkScreen);
267
260
   endCDK();
270
263
   if (answer != 0)
271
264
   {
272
265
      fprintf (fp, "%s\n", answer);
 
266
      freeChar (answer);
273
267
   }
274
268
 
275
269
   /* Exit with the selected button. */
276
 
   exit (0);
 
270
   ExitProgram (0);
277
271
}
278
272
 
279
273
int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key)