Filter:   InfoImg
download Fl_FileChooser2.cxx
Language: C++
Copyright: Copyright 1997-2000 by Easy Software Products.
LOC: 448
Project Info
Fast Light Tool Kit(fltk)
Server: SourceForge
Type: cvs
...Forge\f\fltk\fltk\fltk\src\
   allfiles.xbm
   ARRAY.h
   browser_minus.xbm
   browser_plus.xbm
   cmap.cxx
   CycleButton.cxx
   d1.xbm
   d1_mask.xbm
   dlload_osx.cxx
   dump_compose.c
   ew.xbm
   ew_mask.xbm
   fastarrow.h
   filename_absolute.cxx
   filename_expand.cxx
   filename_ext.cxx
   filename_isdir.cxx
   filename_list.cxx
   filename_match.cxx
   filename_setext.cxx
   Fl.cxx
   Fl_abort.cxx
   Fl_add_idle.cxx
   Fl_Adjuster.cxx
   Fl_Align_Group.cxx
   fl_arc.cxx
   fl_arci.cxx
   Fl_arg.cxx
   fl_ask.cxx
   Fl_Bar.cxx
   Fl_Bitmap.cxx
   fl_bmp.cxx
   Fl_Box.cxx
   Fl_Boxtype.cxx
   Fl_Browser.cxx
   Fl_Browser_load.cxx
   Fl_Button.cxx
   fl_call_main.c
   Fl_Check_Button.cxx
   Fl_Choice.cxx
   fl_clip.cxx
   Fl_Clock.cxx
   fl_cmap.h
   fl_color.cxx
   Fl_Color_Chooser.cxx
   fl_color_mac.cxx
   fl_color_win32.cxx
   fl_color_x.cxx
   Fl_compose.cxx
   fl_cursor.cxx
   fl_curve.cxx
   Fl_Dial.cxx
   fl_diamond_box.cxx
   Fl_display.cxx
   fl_dnd.cxx
   fl_dnd_mac.cxx
   fl_dnd_win32.cxx
   fl_dnd_x.cxx
   fl_draw.cxx
   fl_draw_image.cxx
   fl_draw_image_mac.cxx
   fl_draw_image_win32.cxx
   fl_draw_image_x.cxx
   fl_draw_pixmap.cxx
   fl_engraved_label.cxx
   fl_file_chooser.cxx
   Fl_FileBrowser.cxx
   Fl_FileChooser.cxx
   Fl_FileChooser.fl
   Fl_FileChooser2.cxx
   Fl_FileIcon.cxx
   Fl_FileIcon2.cxx
   Fl_FileInput.cxx
   Fl_Float_Input.cxx
   fl_font.cxx
   fl_font_mac.cxx
   fl_font_win32.cxx
   fl_font_x.cxx
   fl_font_xft.cxx
   Fl_get_key.cxx
   Fl_get_key_mac.cxx
   Fl_get_key_win32.cxx
   fl_gif.cxx
   fl_glyph.cxx
   Fl_Group.cxx
   Fl_Help_Dialog.cxx
   Fl_Help_View.cxx
   Fl_Highlight_Button.cxx
   Fl_Image.cxx
   Fl_Input.cxx
   Fl_Input_Browser.cxx
   Fl_Item.cxx
   Fl_key_name.cxx
   fl_labeltype.cxx
   Fl_Light_Button.cxx
   fl_list_fonts.cxx
   fl_list_fonts_mac.cxx
   fl_list_fonts_win32.cxx
   fl_list_fonts_x.cxx
   fl_load_plugin.cxx
   Fl_lock.cxx
   Fl_mac.cxx
   Fl_Menu.cxx
   Fl_Menu_.cxx
   Fl_Menu_add.cxx
   Fl_Menu_Bar.cxx
   Fl_Menu_Button.cxx
   Fl_Menu_global.cxx
   Fl_Menu_Item.cxx
   Fl_Menu_Window.cxx
   Fl_Multi_Image.cxx
   Fl_Numeric_Input.cxx
   Fl_Output.cxx
   fl_oval_box.cxx
   fl_overlay.cxx
   fl_overlay_visual.cxx
   Fl_own_colormap.cxx
   Fl_Pack.cxx
   Fl_Pixmap.cxx
   fl_plastic_box.cxx
   Fl_ProgressBar.cxx
   Fl_Radio_Button.cxx
   fl_rect.cxx
   Fl_Repeat_Button.cxx
   Fl_Return_Button.cxx
   fl_rgb.cxx
   Fl_RGB_Image.cxx
   Fl_Roller.cxx
   fl_round_box.cxx
   fl_rounded_box.cxx
   Fl_Scroll.cxx
   fl_scroll_area.cxx
   Fl_Scrollbar.cxx
   fl_set_fonts_mac.cxx
   fl_shadow_box.cxx
   Fl_Shaped_Window.cxx
   Fl_Shared_Image.cxx
   fl_show_colormap.cxx
   Fl_Single_Window.cxx
   Fl_Slider.cxx
   Fl_String_List.cxx
   Fl_Style.cxx
   Fl_Style_Set.cxx
   fl_symbols.cxx
   Fl_Tabs.cxx
   Fl_Text_Buffer.cxx
   Fl_Text_Display.cxx
   Fl_Text_Editor.cxx
   Fl_Tile.cxx
   Fl_Tiled_Image.cxx
   Fl_Tooltip.cxx
   Fl_Valuator.cxx
   Fl_Value_Input.cxx
   Fl_Value_Slider.cxx
   fl_vertex.cxx
   Fl_visual.cxx
   Fl_Widget.cxx
   Fl_win32.cxx
   Fl_Window.cxx
   Fl_Window_fullscreen.cxx
   Fl_Window_hotspot.cxx
   Fl_Window_iconize.cxx
   Fl_x.cxx
   Fl_XColor.h
   fl_xpm.cxx
   fltk_theme.cxx
   fltk_theme_win32.cxx
   fltk_theme_x.cxx
   IFont.h
   mediumarrow.h
   new.xbm
   ns.xbm
   ns_mask.xbm
   pktdef.h
   scandir.c
   scandir_win32.c
   shortcuts.cxx
   slowarrow.h
   string.c
   up.xbm
   utf.c
   ValueOutput.cxx
   vsnprintf.c
   wintab.h
   wintabx.h
   XColorMap.h
   xutf8.cxx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
//
// "$Id: Fl_FileChooser2.cxx,v 1.31 2004/12/19 18:09:33 leka Exp $"
//
// More FileChooser routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1997-2000 by Easy Software Products.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
// Contents:
//
//   FileChooser::directory()  - Set the directory in the file chooser.
//   FileChooser::count()      - Return the number of selected files.
//   FileChooser::value()      - Return a selected filename.
//   FileChooser::up()         - Go up one directory.
//   FileChooser::newdir()     - Make a new directory.
//   FileChooser::rescan()     - Rescan the current directory.
//   FileChooser::fileListCB() - Handle clicks (and double-clicks) in the
//                                  FileBrowser.
//   FileChooser::fileNameCB() - Handle text entry in the FileBrowser.
//

//
// Include necessary headers.
//

#include <fltk/FileChooser.h>
#include <fltk/filename.h>
#include <fltk/ask.h>
#include <fltk/string.h>
#include <fltk/events.h>
#include <config.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#include <fltk/utf.h>
# undef _POSIX_
# include <direct.h>
# include <io.h>
# define access(a,b) _access(a,b)
# define R_OK 4
#else
# include <unistd.h>
# include <pwd.h>
#endif
#if (__MINGW32__)
#  include <ctype.h> // needed for isalpha()
#endif

using namespace fltk;

//
// 'FileChooser::directory()' - Set the directory in the file chooser.
//

void
FileChooser::directory(const char *d)	// I - Directory to change to
{
  char		pathname[1024],			// Full path of directory
		*pathptr,			// Pointer into full path
		*dirptr;			// Pointer into directory
  int		levels;				// Number of levels in directory


  // NULL == current directory
  if (d == NULL)
    d = ".";

  if (d[0] != '\0')
  {
    // Make the directory absolute...
#if defined(_WIN32) || defined(__EMX__)
    if (d[0] != '/' && d[0] != '\\' && d[1] != ':')
#else
    if (d[0] != '/' && d[0] != '\\')
#endif /* _WIN32 || __EMX__ */
      filename_absolute(directory_, d);
    else
    {
      strncpy(directory_, d, sizeof(directory_) - 1);
      directory_[sizeof(directory_) - 1] = '\0';
    }

    // Strip any trailing slash and/or period...
    dirptr = directory_ + strlen(directory_) - 1;
    if (*dirptr == '.')
      *dirptr-- = '\0';
    if ((*dirptr == '/' || *dirptr == '\\') && dirptr > directory_)
      *dirptr = '\0';
  }
  else
    directory_[0] = '\0';

  // Clear the directory menu and fill it as needed...
  dirMenu->clear();
#if defined(_WIN32) || defined(__EMX__)
  dirMenu->add("My Computer");
#else
  dirMenu->add("File Systems");
#endif /* _WIN32 || __EMX__ */

  levels = 0;
  for (dirptr = directory_, pathptr = pathname; *dirptr != '\0';)
  {
    if (*dirptr == '/' || *dirptr == '\\')
    {
      // Need to quote the slash first, and then add it to the menu...
      // Quoting is no longer needed with new menu->add() code, which
      // was changed to match fltk1.1
      // *pathptr++ = '\\';
      *pathptr++ = '/';
      *pathptr   = '\0';
      dirptr ++;

      dirMenu->add(pathname);
      levels ++;
    }
    else
      *pathptr++ = *dirptr++;
  }

  if (pathptr > pathname)
  {
    *pathptr = '\0';
    dirMenu->add(pathname);
    levels ++;
  }

  dirMenu->value(levels);
  dirMenu->redraw();

  // Rescan the directory...
  rescan();
}


//
// 'FileChooser::count()' - Return the number of selected files.
//

int				// O - Number of selected files
FileChooser::count()
{
  int		i;		// Looping var
  int		count;		// Number of selected files
  const char	*filename;	// Filename in input field or list
  char		pathname[1024];	// Full path to file


  if (type_ != MULTI)
  {
    // Check to see if the file name input field is blank...
    filename = fileName->value();
    if (filename == NULL || filename[0] == '\0')
      return (0);

    // Is the file name a directory?
    if (directory_[0] != '\0')
      snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
    else
    {
      strncpy(pathname, filename, sizeof(pathname) - 1);
      pathname[sizeof(pathname) - 1] = '\0';
    }

    if (filename_isdir(pathname))
      return (0);
    else
      return (1);
  }

  for (i = 0, count = 0; i < fileList->size(); i ++)
    if (fileList->selected(i))
    {
      // See if this file is a directory...
      filename = (char *)fileList->child(i)->label();
      if (directory_[0] != '\0')
	snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
      else
      {
        strncpy(pathname, filename, sizeof(pathname) - 1);
        pathname[sizeof(pathname) - 1] = '\0';
      }

      if (!filename_isdir(pathname))
	count ++;
    }

  return (count);
}


//
// 'FileChooser::value()' - Return a selected filename.
//

const char *			// O - Filename or NULL
FileChooser::value(int f)	// I - File number
{
  int		i;		// Looping var
  int		count;		// Number of selected files
  const char	*name;		// Current filename
  static char	pathname[1024];	// Filename + directory


  if (type_ != MULTI)
  {
    name = fileName->value();
    if (name[0] == '\0')
      return (NULL);

    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name);
    return ((const char *)pathname);
  }

  for (i = 0, count = 0; i < fileList->size(); i ++)
    if (fileList->selected(i))
    {
      // See if this file is a directory...
      name = fileList->child(i)->label();
      snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name);

      if (!filename_isdir(pathname))
      {
        // Nope, see if this this is "the one"...
	count ++;
	if (count == f)
          return ((const char *)pathname);
      }
    }

  return (NULL);
}


//
// 'FileChooser::value()' - Set the current filename.
//

void
FileChooser::value(const char *filename)	// I - Filename + directory
{
  int	i,					// Looping var
  	count;					// Number of items in list
  char	*slash;					// Directory separator
  char	pathname[1024];				// Local copy of filename


  // See if the filename is actually a directory...
  if (filename == NULL || filename_isdir(filename))
  {
    // Yes, just change the current directory...
    directory(filename);
    return;
  }

  if (!filename[0])
  {
    // Just show the current directory...
    directory(NULL);
    return;
  }

  // Switch to single-selection mode as needed
  if (type_ == MULTI)
    type(SINGLE);

  // See if there is a directory in there...
  strncpy(pathname, filename, sizeof(pathname) - 1);
  pathname[sizeof(pathname) - 1] = '\0';

  if ((slash = strrchr(pathname, '/')) == NULL)
    slash = strrchr(pathname, '\\');

  if (slash != NULL)
  {
    // Yes, change the display to the directory... 
    *slash++ = '\0';
    directory(pathname);
  }
  else
  {
    directory(NULL);
    slash = pathname;
  }

  // Set the input field to the remaining portion
  fileName->value(slash);
  fileName->position(0, strlen(slash));
  okButton->activate();

  // Then find the file in the file list and select it...
  count = fileList->size();

  for (i = 0; i < count; i ++)
    if (strcmp(fileList->child(i)->label(), slash) == 0)
    {
      fileList->select(i);
      break;
    }
}


//
// 'FileChooser::up()' - Go up one directory.
//

void
FileChooser::up()
{
  char *slash;		// Trailing slash


  if ((slash = strrchr(directory_, '/')) == NULL)
    slash = strrchr(directory_, '\\');

  if (directory_[0] != '\0')
    dirMenu->value(dirMenu->value() - 1);

  if (slash != NULL)
    *slash = '\0';
  else
  {
    upButton->deactivate();
    directory_[0] = '\0';
  }

  rescan();
}


//
// 'FileChooser::newdir()' - Make a new directory.
//

void
FileChooser::newdir()
{
  const char	*dir;		// New directory name
  char		pathname[1024];	// Full path of directory


  // Get a directory name from the user
  if ((dir = input("New Directory?")) == NULL)
    return;

  // Make it relative to the current directory as needed...
#if defined(_WIN32) || defined(__EMX__)
  if (dir[0] != '/' && dir[0] != '\\' && dir[1] != ':')
#else
  if (dir[0] != '/' && dir[0] != '\\')
#endif /* _WIN32 || __EMX__ */
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, dir);
  else
  {
    strncpy(pathname, dir, sizeof(pathname) - 1);
    pathname[sizeof(pathname) - 1] = '\0';
  }

  // Create the directory; ignore EEXIST errors...
#if defined(_WIN32) && !defined(__CYGWIN__)
  char namebuf[FL_PATH_MAX];
  utf8tomb(pathname, strlen(pathname), namebuf, FL_PATH_MAX);
  if (mkdir(namebuf))
#else
  if (mkdir(pathname, 0777))
#endif /* _WIN32 || __EMX__ */
    if (errno != EEXIST)
    {
      alert("Unable to create directory!");
      return;
    }

  // Show the new directory...
  directory(pathname);
}


//
// 'FileChooser::rescan()' - Rescan the current directory.
//

void
FileChooser::rescan()
{
  // Clear the current filename
  fileName->value("");
  okButton->deactivate();

  // Build the file list...
  fileList->load(directory_);
  fileList->redraw();
}


//
// 'FileChooser::fileListCB()' - Handle clicks (and double-clicks) in the
//                               FileBrowser.
//

void
FileChooser::fileListCB()
{
  char	filename[1024],		// New filename
	pathname[1024];		// Full pathname to file


  strncpy(filename, fileList->item()->label(), sizeof(filename) - 1);
  filename[sizeof(filename) - 1] = '\0';

#if defined(_WIN32) || defined(__EMX__)
  if (directory_[0] != '\0' && filename[0] != '/' && filename[0] != '\\' &&
      !(isalpha((uchar)filename[0]) && filename[1] == ':'))
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
  else
  {
    strncpy(pathname, filename, sizeof(pathname) - 1);
    pathname[sizeof(pathname) - 1] = '\0';
  }
#else
  if (directory_[0] != '\0' && filename[0] != '/')
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
  else
  {
    strncpy(pathname, filename, sizeof(pathname) - 1);
    pathname[sizeof(pathname) - 1] = '\0';
  }
#endif /* _WIN32 || __EMX__ */

  if (event_clicks() || event_key() == ReturnKey || event_key()==KeypadEnter)
  {
    if (filename_isdir(pathname))
    {
      fileList->deselect();
      directory(pathname);
      upButton->activate();
    } else {
      fileName->value(filename);
      window->hide();
    }
  }
  else
  {
    fileName->value(filename);
    okButton->activate();
  }
}


//
// 'FileChooser::fileNameCB()' - Handle text entry in the FileBrowser.
//

void
FileChooser::fileNameCB()
{
  char		*filename,	// New filename
		*slash,		// Pointer to trailing slash
		pathname[1024];	// Full pathname to file
  int		i,		// Looping var
		min_match,	// Minimum number of matching chars
		max_match,	// Maximum number of matching chars
		num_files,	// Number of files in directory
		first_line;	// First matching line
  const char	*file;		// File from directory


  // Get the filename from the text field...
  filename = (char *)fileName->value();

  if (filename == NULL || filename[0] == '\0')
  {
    okButton->deactivate();
    return;
  }

#if defined(_WIN32) || defined(__EMX__)
  if (directory_[0] != '\0' && filename[0] != '/' && filename[0] != '\\' &&
      !(isalpha((uchar)filename[0]) && filename[1] == ':'))
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
  else
  {
    strncpy(pathname, filename, sizeof(pathname) - 1);
    pathname[sizeof(pathname) - 1] = '\0';
  }
#else
  if (filename[0] == '~')
  {
    // Lookup user...
    struct passwd	*pwd;

    if (!filename[1] || filename[1] == '/')
      pwd = getpwuid(getuid());
    else
    {
      strncpy(pathname, filename + 1, sizeof(pathname) - 1);
      pathname[sizeof(pathname) - 1] = '\0';

      i = strlen(pathname) - 1;
      if (pathname[i] == '/')
        pathname[i] = '\0';

      pwd = getpwnam(pathname);
    }

    if (pwd)
    {
      strncpy(pathname, pwd->pw_dir, sizeof(pathname) - 1);
      pathname[sizeof(pathname) - 1] = '\0';

      if (filename[strlen(filename) - 1] == '/')
        strncat(pathname, "/", sizeof(pathname) - strlen(pathname) - 1);
    }
    else
      snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);

    endpwent();
  }
  else if (directory_[0] != '\0' && filename[0] != '/')
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
  else
  {
    strncpy(pathname, filename, sizeof(pathname) - 1);
    pathname[sizeof(pathname) - 1] = '\0';
  }
#endif /* _WIN32 || __EMX__ */

  if (event_key() == ReturnKey || event_key()==KeypadEnter)
  {
    // Enter pressed - select or change directory...
    if (filename_isdir(pathname))
      directory(pathname);
    else //if (type_ == CREATE || access(pathname, R_OK) == 0)
    {
      // New file or file exists...  If we are in multiple selection mode,
      // switch to single selection mode...
      if (type_ == MULTI)
        type(SINGLE);

      // Hide the window to signal things are done...
      window->hide();
    }
//  else
//  {
//    // File doesn't exist, so alert the user...
//    alert("Please choose an existing file!");
//   }
  }
  else if (event_key() != DeleteKey)
  {
    // Check to see if the user has entered a directory...
    if ((slash = strrchr(filename, '/')) == NULL)
      slash = strrchr(filename, '\\');

    if (slash != NULL)
    {
      // Yes, change directories and update the file name field...
      if ((slash = strrchr(pathname, '/')) == NULL)
	slash = strrchr(pathname, '\\');

      if (slash > pathname)		// Special case for "/"
        *slash++ = '\0';
      else
        slash++;

      if (strcmp(filename, "../") == 0)	// Special case for "../"
        up();
      else
        directory(pathname);

      // If the string ended after the slash, we're done for now...
      if (*slash == '\0')
        return;

      // Otherwise copy the remainder and proceed...
      fileName->value(slash);
      fileName->position(strlen(slash));
      filename = slash;
    }

    // Other key pressed - do filename completion as possible...
    num_files  = fileList->size();
    min_match  = strlen(filename);
    max_match  = 100000;
    first_line = 0;

    for (i = 0; i < num_files && max_match > min_match; i ++)
    {
      file = fileList->child(i)->label();

#if defined(_WIN32) || defined(__EMX__)
      if (strnicmp(filename, file, min_match) == 0)
#else
      if (strncmp(filename, file, min_match) == 0)
#endif // _WIN32 || __EMX__
      {
        // OK, this one matches; check against the previous match
	if (max_match == 100000)
	{
	  // First match; copy stuff over...
	  strncpy(pathname, file, sizeof(pathname) - 1);
	  pathname[sizeof(pathname) - 1] = '\0';
	  max_match = strlen(pathname);

	  // And then make sure that the item is visible
          fileList->topline(i);
	  first_line = i;
	}
	else
	{
	  // Succeeding match; compare to find maximum string match...
	  while (max_match > min_match)
#if defined(_WIN32) || defined(__EMX__)
	    if (strnicmp(file, pathname, max_match) == 0)
#else
	    if (strncmp(file, pathname, max_match) == 0)
#endif // _WIN32 || __EMX__
	      break;
	    else
	      max_match --;

          // Truncate the string as needed...
          pathname[max_match] = '\0';
	}
      }
    }

    fileList->deselect(0);
    fileList->redraw();

    // If we have any matches, add them to the input field...
    if (first_line > 0 && min_match == max_match &&
        max_match == (int)strlen(fileList->child(first_line)->label()))
      fileList->select(first_line);
    else if (max_match > min_match && max_match != 100000)
    {
      // Add the matching portion...
      fileName->replace(0, min_match, pathname, strlen(pathname));

      // Highlight it; if the user just pressed the backspace
      // key, position the cursor at the start of the selection.
      // Otherwise, put the cursor at the end of the selection so
      // s/he can press the right arrow to accept the selection
      // (Tab and End also do this for both cases.)
      if (event_key() == BackSpaceKey)
        fileName->position(min_match - 1, max_match);
      else
        fileName->position(max_match, min_match);
    }

    // See if we need to enable the OK button...
    snprintf(pathname, sizeof(pathname), "%s/%s", directory_, fileName->value());

    if (type_ == CREATE || access(pathname, R_OK) == 0)
      okButton->activate();
    else
      okButton->deactivate();
  }
}


//
// End of "$Id: Fl_FileChooser2.cxx,v 1.31 2004/12/19 18:09:33 leka Exp $".
//