source: abuse/trunk/src/imlib/filesel.cpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 14 years ago
  • imported original 0.7.0 tarball
File size: 3.2 KB
Line 
1#include "filesel.hpp"
2#include "input.hpp"
3#include "scroller.hpp"
4#include "jdir.hpp"
5
6#ifdef __WATCOMC__
7#include <direct.h>
8#endif
9
10class file_picker : public spicker
11{
12  char **f,**d;
13  int tf,td,wid,sid;
14  char cd[300];
15  public:
16  file_picker(int X, int Y, int ID, int Rows, ifield *Next);
17  virtual int total() { return tf+td; }
18  virtual int item_width(window_manager *wm) { return wm->font()->width()*wid; }
19  virtual int item_height(window_manager *wm) { return wm->font()->height()+1; }
20  virtual void draw_item(window_manager *wm, image *screen, int x, int y, int num, int active);
21  virtual void note_selection(window_manager *wm, image *screen, input_manager *inm, int x);
22  void free_up();
23  ~file_picker() { free_up(); }
24} ;
25
26void file_picker::free_up()
27{
28  int i=0;
29  for (;i<tf;i++)
30    jfree(f[i]);
31  for (i=0;i<td;i++)
32    jfree(d[i]);
33  if (tf) jfree(f);
34  if (td) jfree(d);
35}
36
37void file_picker::note_selection(window_manager *wm, image *screen, input_manager *inm, int x)
38{
39  if (x<td)
40  {
41    if (strcmp(d[x],"."))
42    {
43      int x1,y1,x2,y2;
44      area(x1,y1,x2,y2,wm);
45      screen->bar(x1,y1,x2,y2,wm->medium_color());
46
47      char st[200],curdir[200];
48      sprintf(st,"%s/%s",cd,d[x]);
49      getcwd(curdir,200);
50      chdir(st);
51      getcwd(cd,200);
52      chdir(curdir);
53
54      free_up();
55      get_directory(cd,f,tf,d,td);
56      wid=0;
57      int i=0;
58      for (;i<tf;i++)
59      if (strlen(f[i])>wid) wid=strlen(f[i]);
60      for (i=0;i<td;i++)
61      if (strlen(d[i])+2>wid) wid=strlen(d[i])+2;
62      sx=0;
63
64     
65
66      reconfigure(); 
67      draw_first(screen,wm);
68    }
69  } else
70  {
71    char nm[200];
72    sprintf(nm,"%s/%s",cd,f[x-td]);
73    text_field *link=(text_field *)inm->get(sid);
74    link->change_data(nm,strlen(nm),1,screen,wm);
75  }
76
77}
78
79void file_picker::draw_item(window_manager *wm, image *screen, int x, int y, int num, int active)
80{
81  if (active)
82    screen->bar(x,y,x+item_width(wm)-1,y+item_height(wm)-1,wm->black());
83
84  if (num<td)
85  {
86    char st[100];
87    sprintf(st,"<%s>",d[num]);
88    wm->font()->put_string(screen,x,y,st,wm->bright_color());
89  } else
90    wm->font()->put_string(screen,x,y,f[num-td],wm->bright_color());
91}
92
93file_picker::file_picker(int X, int Y, int ID, int Rows, ifield *Next)
94  : spicker(X,Y,0,Rows,1,1,0,Next)
95{
96 
97  sid=ID;
98
99  strcpy(cd,".");
100 
101  get_directory(cd,f,tf,d,td);
102  wid=0;
103  int i=0;
104  for (;i<tf;i++)
105    if (strlen(f[i])>wid) wid=strlen(f[i]);
106  for (i=0;i<td;i++)
107    if (strlen(d[i])+2>wid) wid=strlen(d[i])+2;
108  reconfigure(); 
109}
110
111jwindow *file_dialog(window_manager *wm, char *prompt, char *def,
112                     int ok_id, char *ok_name, int cancel_id, char *cancel_name, char *FILENAME_str, int filename_id)
113{
114  int wl=WINDOW_FRAME_LEFT,wh=WINDOW_FRAME_TOP;
115  int wh2=wh+5+wm->font()->height()+5;
116  int wh3=wh2+wm->font()->height()+12;
117  jwindow *j=wm->new_window(0,0,-1,-1,
118                            new info_field(wl+5,wh+5,0,prompt,
119                            new text_field(wl,wh2,filename_id,
120                                           ">","****************************************",def,
121                            new button(wl+50,wh3,ok_id,     ok_name,
122                            new button(wl+100,wh3,cancel_id,cancel_name,
123                            new file_picker(wl+15,wh3+wm->font()->height()+10,filename_id,8,
124                                          NULL))))),
125
126                            FILENAME_str);
127  return j;
128}
129
130
131
132
133
Note: See TracBrowser for help on using the repository browser.