123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
- //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
- #include <Fl/Fl.H>
- #include <Fl/Fl_Button.H>
- #include <Fl/Fl_File_Chooser.H>
- #include <Fl/Fl_Output.H>
- #include <Fl/Fl_Group.H>
- #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());
-
- }
|