#include #include #include #include #include #include "Fl_File_Btn.h" Fl_File_Btn::Fl_File_Btn( int xx, int yy, int ww, int hh, const char* l ) : Fl_Group(xx,yy,ww,hh,l), _patStr(NULL),_typeId(kFile_Type_Id),_btn(NULL),_out(NULL) { _init(); end(); } Fl_File_Btn::Fl_File_Btn( unsigned typeId, const char* patStr, int xx, int yy, int ww, int hh, const char* l ) : Fl_Group(xx,yy,ww,hh,l), _patStr(NULL),_typeId(typeId),_btn(NULL),_out(NULL) { _init(); type(typeId); pattern_string(patStr); end(); } Fl_File_Btn::~Fl_File_Btn() { delete[] _patStr; } unsigned Fl_File_Btn::type() { return _typeId; } void Fl_File_Btn::type( unsigned typeId ) { switch(typeId) { case kFile_Type_Id: _btn->label("File"); _typeId = typeId; break; case kDir_Type_Id: _btn->label("Dir"); _typeId = typeId; break; } } const char* Fl_File_Btn::pattern_string() { return _patStr; } void Fl_File_Btn::pattern_string( const char* pat) { delete[] _patStr; if( pat != NULL ) { _patStr = new char[ strlen(pat) + 1]; strcpy(_patStr,pat); } } void Fl_File_Btn::btn_width( int ww ) { _btn->resize(_btn->x(),_btn->y(),ww,_btn->h()); _out->resize(_btn->x() + _btn->w() + 2, _out->y(), w() - _btn->w() - 2, _out->h()); } int Fl_File_Btn::btn_width() { return _btn->w(); } void Fl_File_Btn::filename( const char* fn ) { _out->value(fn); _out->redraw(); } const char* Fl_File_Btn::filename() const { return _out->value(); } void Fl_File_Btn::_s_btn_cb(Fl_Widget* w, void* data) { ((Fl_File_Btn*)data)->_btn_cb(); } void Fl_File_Btn::_btn_cb() { char* fn; if( _typeId == kFile_Type_Id ) fn = fl_file_chooser("Select a file",_patStr,_out->value(),0); else fn = fl_dir_chooser("Select a directory",_out->value(),0); if( fn != NULL ) { _out->value(fn); do_callback(this,user_data()); } } void Fl_File_Btn::_init() { _btn = new Fl_Button(x(),y(),40,h(),_typeId==kFile_Type_Id ? "File" : "Dir"); _btn->callback(_s_btn_cb,this); _out = new Fl_Output(x() + _btn->w() + 2, y(), w() - _btn->w(), h()); }