Programmable real-time audio signal processing application
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Fl_File_Btn.cpp 2.3KB

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