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.

104 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. // If you comment this out - it makes the comment look nice, or does it?
  27. box(FL_NO_BOX);
  28. //m_DragBar->box(FL_NO_BOX);
  29. m_DragBar->label(m_Comment.c_str());
  30. m_DragBar->color(SpiralInfo::GUICOL_Device);
  31. NewText();
  32. // m_DragBar->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  33. }
  34. int Fl_CommentGUI::handle(int event)
  35. {
  36. if (Fl::event_button()==1 && event==FL_PUSH && Fl::event_clicks()==1)
  37. {
  38. char t[1024];
  39. if (Pawfal_Input("and your comment is:", m_Comment.c_str(), t))
  40. {
  41. string temp(t);
  42. if (temp!="")
  43. {
  44. m_Comment=temp;
  45. NewText();
  46. redraw();
  47. //parent()->redraw();
  48. }
  49. }
  50. }
  51. return Fl_DeviceGUI::handle(event);
  52. }
  53. void Fl_CommentGUI::Setup(const DeviceGUIInfo& Info, bool FirstTime)
  54. {
  55. Fl_DeviceGUI::Setup(Info,FirstTime);
  56. }
  57. void Fl_CommentGUI::Clear()
  58. {
  59. Fl_DeviceGUI::Clear();
  60. }
  61. void Fl_CommentGUI::NewText(void) {
  62. m_DragBar->label(m_Comment.c_str());
  63. int width=0, height=0;
  64. fl_font(fl_font(),10);
  65. fl_measure(m_Comment.c_str(),width,height);
  66. width+=10;
  67. m_DragBar->size(width,height);
  68. resize(x(),y(),width,height);
  69. }
  70. void Fl_CommentGUI::StreamOut(ostream &s)
  71. {
  72. s<<1<<" ";
  73. s<<m_Comment.size()<<" ";
  74. s<<m_Comment<<endl;
  75. }
  76. void Fl_CommentGUI::StreamIn(istream &s)
  77. {
  78. unsigned int size,version;
  79. string temp;
  80. s>>version;
  81. s>>size;
  82. size++; // see below
  83. char *str = new char[size+1];
  84. s.read(str,size);
  85. str[size]='\0';
  86. // have to move the pointer on by one, as the string
  87. // starts with " ", as the file pointer starts on
  88. // a blank space (after streaming the size)
  89. m_Comment=str+1;
  90. delete[] str;
  91. NewText();
  92. }