Programmable real-time audio signal processing application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Fl_File_Btn.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <Fl/Fl.H>
  2. #include <Fl/Fl_Button.H>
  3. #include <Fl/Fl_File_Chooser.H>
  4. #include <Fl/Fl_Output.H>
  5. #include <Fl/Fl_Group.H>
  6. #include "Fl_File_Btn.h"
  7. Fl_File_Btn::Fl_File_Btn( int xx, int yy, int ww, int hh, const char* l )
  8. : Fl_Group(xx,yy,ww,hh,l),
  9. _patStr(NULL),_typeId(kFile_Type_Id),_btn(NULL),_out(NULL)
  10. {
  11. _init();
  12. }
  13. Fl_File_Btn::Fl_File_Btn( unsigned typeId, const char* patStr, int xx, int yy, int ww, int hh, const char* l )
  14. : Fl_Group(xx,yy,ww,hh,l),
  15. _patStr(NULL),_typeId(typeId),_btn(NULL),_out(NULL)
  16. {
  17. _init();
  18. type(typeId);
  19. pattern_string(patStr);
  20. }
  21. Fl_File_Btn::~Fl_File_Btn()
  22. { delete[] _patStr; }
  23. unsigned Fl_File_Btn::type()
  24. { return _typeId; }
  25. void Fl_File_Btn::type( unsigned typeId )
  26. {
  27. switch(typeId)
  28. {
  29. case kFile_Type_Id:
  30. _btn->label("File");
  31. _typeId = typeId;
  32. break;
  33. case kDir_Type_Id:
  34. _btn->label("Dir");
  35. _typeId = typeId;
  36. break;
  37. }
  38. }
  39. const char* Fl_File_Btn::pattern_string()
  40. { return _patStr; }
  41. void Fl_File_Btn::pattern_string( const char* pat)
  42. {
  43. delete[] _patStr;
  44. if( pat != NULL )
  45. {
  46. _patStr = new char[ strlen(pat) + 1];
  47. strcpy(_patStr,pat);
  48. }
  49. }
  50. void Fl_File_Btn::btn_width( int ww )
  51. {
  52. _btn->resize(_btn->x(),_btn->y(),ww,_btn->h());
  53. _out->resize(_btn->x() + _btn->w() + 2, _out->y(), w() - _btn->w() - 2, _out->h());
  54. }
  55. int Fl_File_Btn::btn_width()
  56. { return _btn->w(); }
  57. void Fl_File_Btn::filename( const char* fn )
  58. { _out->value(fn); _out->redraw(); }
  59. const char* Fl_File_Btn::filename() const
  60. { return _out->value(); }
  61. void Fl_File_Btn::_s_btn_cb(Fl_Widget* w, void* data)
  62. { ((Fl_File_Btn*)data)->_btn_cb(); }
  63. void Fl_File_Btn::_btn_cb()
  64. {
  65. char* fn;
  66. if( _typeId == kFile_Type_Id )
  67. fn = fl_file_chooser("Select a file",_patStr,_out->value(),0);
  68. else
  69. fn = fl_dir_chooser("Select a directory",_out->value(),0);
  70. if( fn != NULL )
  71. {
  72. _out->value(fn);
  73. do_callback(this,user_data());
  74. }
  75. }
  76. void Fl_File_Btn::_init()
  77. {
  78. _btn = new Fl_Button(x(),y(),40,h(),_typeId==kFile_Type_Id ? "File" : "Dir");
  79. _btn->callback(_s_btn_cb,this);
  80. _out = new Fl_Output(x() + _btn->w() + 2, y(), w() - _btn->w(), h());
  81. }