4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
8 /* filer.c - code for handling filer windows */
15 #include <collection.h>
18 #include "directory.h"
19 #include "gui_support.h"
22 static int number_of_windows
= 0;
24 /* Static prototypes */
25 static void filer_window_destroyed(GtkWidget
*widget
,
26 FilerWindow
*filer_window
);
27 static void scan_callback(char *leafname
, gpointer data
);
28 static void draw_item(GtkWidget
*widget
,
34 static void filer_window_destroyed(GtkWidget
*widget
,
35 FilerWindow
*filer_window
)
37 directory_destroy(filer_window
->dir
);
40 if (--number_of_windows
< 1)
44 static void scan_callback(char *leafname
, gpointer data
)
46 FilerWindow
*filer_window
= (FilerWindow
*) data
;
49 item
= g_malloc(sizeof(FileItem
));
50 item
->leafname
= g_strdup(leafname
);
52 collection_insert(filer_window
->collection
, item
);
54 item
->text_width
= gdk_string_width(filer_window
->window
->style
->font
,
57 if (item
->text_width
+ 4 > filer_window
->collection
->item_width
)
58 collection_set_item_size(filer_window
->collection
,
60 filer_window
->collection
->item_height
);
63 static void draw_item(GtkWidget
*widget
,
68 FileItem
*item
= (FileItem
*) data
;
70 gdk_draw_rectangle(widget
->window
,
71 widget
->style
->black_gc
,
74 area
->width
- 1, area
->height
- 1);
76 gdk_draw_text(widget
->window
,
78 selected
? widget
->style
->white_gc
79 : widget
->style
->black_gc
,
80 area
->x
+ ((area
->width
- item
->text_width
) >> 1),
81 area
->y
+ area
->height
-
82 widget
->style
->font
->descent
- 2,
83 item
->leafname
, strlen(item
->leafname
));
86 void filer_opendir(char *path
)
88 GtkWidget
*hbox
, *scrollbar
, *collection
;
89 FilerWindow
*filer_window
;
91 filer_window
= g_malloc(sizeof(FilerWindow
));
92 filer_window
->dir
= directory_new(path
);
94 collection
= collection_new(NULL
);
95 filer_window
->collection
= COLLECTION(collection
);
96 collection_set_functions(filer_window
->collection
,
99 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
100 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
101 filer_window
->dir
->path
);
102 gtk_window_set_default_size(GTK_WINDOW(filer_window
->window
),
105 hbox
= gtk_hbox_new(FALSE
, 0);
106 gtk_container_add(GTK_CONTAINER(filer_window
->window
), hbox
);
108 gtk_box_pack_start(GTK_BOX(hbox
), collection
, TRUE
, TRUE
, 0);
110 scrollbar
= gtk_vscrollbar_new(COLLECTION(collection
)->vadj
);
111 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
113 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "destroy",
114 filer_window_destroyed
, filer_window
);
116 gtk_widget_show_all(filer_window
->window
);
119 if (!directory_scan(filer_window
->dir
, scan_callback
, filer_window
))
120 report_error("Error opening directory", g_strerror(errno
));