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.2KB

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