00001
00002 #include "std/support.H"
00003 #include "disp/view.H"
00004 #include "geom/winsys.H"
00005 #include "glui/glui.h"
00006
00007 #include "file_listbox.H"
00008
00009 ARRAY<FileListbox*> FileListbox::_file_list_boxes;
00010
00011 FileListbox::FileListbox(
00012 Cstr_ptr &label,
00013 Cstr_ptr &listbox_name,
00014 Cstr_ptr &button_name
00015 ) : _glui(0), _listbox(0), _selected(0), _shown(false)
00016 {
00017 _file_list_boxes += this;
00018 init(label, listbox_name, button_name);
00019 }
00020
00021 void
00022 FileListbox::init(
00023 Cstr_ptr &label,
00024 Cstr_ptr &listbox_name,
00025 Cstr_ptr &button_name
00026 )
00027 {
00028
00029 int main_win_id = VIEW::peek()->win()->id();
00030
00031
00032 _glui = GLUI_Master.create_glui(**listbox_name, 0);
00033 _glui->set_main_gfx_window(main_win_id);
00034
00035
00036 _glui->add_statictext(**label);
00037
00038 _glui->add_separator();
00039
00040
00041 _listbox = _glui->add_listbox(**listbox_name,
00042 NULL,
00043 _file_list_boxes.num()-1,
00044 FileListbox::listbox_cb
00045
00046 );
00047 assert(_listbox);
00048
00049
00050 _glui->add_separator();
00051
00052
00053 _glui->add_button(**button_name, _file_list_boxes.num()-1,
00054 FileListbox::set_cb);
00055
00056
00057 _glui->add_button("Hide", _file_list_boxes.num()-1,
00058 FileListbox::hide_cb);
00059
00060 _glui->hide();
00061 }
00062
00063 void
00064 FileListbox::fill_listbox(
00065 GLUI_Listbox *listbox,
00066 str_list &save_files,
00067 Cstr_ptr &full_path,
00068 Cstr_ptr &save_path,
00069 const char *extension
00070 )
00071 {
00072 int j = 0;
00073 str_list in_files = dir_list(full_path);
00074 for (int i = 0; i < in_files.num(); i++)
00075 {
00076 int len = in_files[i].len();
00077 if ( (extension) && (len>3) &&
00078 (strcmp(&(**in_files[i])[len-4],extension) == 0))
00079 {
00080 save_files += save_path + in_files[i];
00081 listbox->add_item(j++, **in_files[i]);
00082 }
00083 }
00084 }
00085
00086 void
00087 FileListbox::show()
00088 {
00089 if (_glui) {
00090 _glui->show();
00091 _shown = true;
00092 }
00093 }
00094
00095
00096 void
00097 FileListbox::hide()
00098 {
00099 if (_glui) {
00100 _glui->hide();
00101 _shown = false;
00102 }
00103 }
00104
00105 void
00106 FileListbox::toggle()
00107 {
00108 if (_shown) _glui->hide();
00109 else _glui->show();
00110 }
00111
00112 void
00113 FileListbox::listbox_cb(int id)
00114 {
00115 int item_id = _file_list_boxes[id]->_listbox->get_int_val();
00116 _file_list_boxes[id]->_selected = item_id;
00117 }
00118
00119 void
00120 FileListbox::set_cb(int id)
00121 {
00122 _file_list_boxes[id]->button_press_cb();
00123 }
00124
00125
00126 void
00127 FileListbox::hide_cb(int id)
00128 {
00129 _file_list_boxes[id]->hide();
00130 }