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.

105 lines
2.7KB

  1. /* DeviceGUI composite Widget
  2. * Copyleft (C) 2002 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "Fl_CommentGUI.h"
  19. #include <FL/fl_draw.H>
  20. #include "../../SpiralSound/SpiralInfo.h"
  21. #include "../../GUI/Widgets/PawfalInput.h"
  22. Fl_CommentGUI::Fl_CommentGUI(const DeviceGUIInfo& Info, SpiralGUIType *PW, Fl_Pixmap *Icon) :
  23. Fl_DeviceGUI(Info,PW,Icon),
  24. m_Comment("double click to edit.")
  25. {
  26. box(FL_NO_BOX);
  27. m_DragBar->box(FL_NO_BOX);
  28. m_DragBar->label(m_Comment.c_str());
  29. m_DragBar->color(SpiralInfo::GUICOL_Device);
  30. // m_DragBar->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  31. }
  32. int Fl_CommentGUI::handle(int event)
  33. {
  34. if (Fl::event_button()==1 && event==FL_PUSH && Fl::event_clicks()==1)
  35. {
  36. char t[1024];
  37. if (Pawfal_Input("and your comment is:", m_Comment.c_str(), t))
  38. {
  39. string temp(t);
  40. if (temp!="")
  41. {
  42. m_Comment=temp;
  43. m_DragBar->label(m_Comment.c_str());
  44. int width,height;
  45. fl_font(fl_font(),10);
  46. fl_measure(m_Comment.c_str(),width,height);
  47. m_DragBar->size(width,height);
  48. resize(x(),y(),width,height);
  49. redraw();
  50. parent()->redraw();
  51. //int x,y;
  52. //fl_measure(m_Comment.c_str(),x,y);
  53. //m_DragBar->size(x,y);
  54. }
  55. }
  56. }
  57. return Fl_DeviceGUI::handle(event);
  58. }
  59. void Fl_CommentGUI::Setup(const DeviceGUIInfo& Info, bool FirstTime)
  60. {
  61. Fl_DeviceGUI::Setup(Info,FirstTime);
  62. }
  63. void Fl_CommentGUI::Clear()
  64. {
  65. Fl_DeviceGUI::Clear();
  66. }
  67. void Fl_CommentGUI::StreamOut(ostream &s)
  68. {
  69. s<<1<<" ";
  70. s<<m_Comment.size()<<" ";
  71. s<<m_Comment<<endl;
  72. }
  73. void Fl_CommentGUI::StreamIn(istream &s)
  74. {
  75. unsigned int size,version;
  76. string temp;
  77. s>>version;
  78. s>>size;
  79. size++; // see below
  80. char *str = new char[size+1];
  81. s.read(str,size);
  82. str[size]='\0';
  83. // have to move the pointer on by one, as the string
  84. // starts with " ", as the file pointer starts on
  85. // a blank space (after streaming the size)
  86. m_Comment=str+1;
  87. delete[] str;
  88. m_DragBar->label(m_Comment.c_str());
  89. int width,height;
  90. fl_font(fl_font(),10);
  91. fl_measure(m_Comment.c_str(),width,height);
  92. m_DragBar->size(width,height);
  93. resize(x(),y(),width,height);
  94. }