Flu_Label.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // $Id: Flu_Label.cpp,v 1.6 2004/10/21 15:21:07 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #include <FL/fl_draw.H>
  13. #include "FLU/Flu_Label.H"
  14. Flu_Label :: Flu_Label( int x, int y, int w, int h, const char* l )
  15. : Fl_Box( x, y, w, h, 0 )
  16. {
  17. _autoSize = false;
  18. align( FL_ALIGN_LEFT | FL_ALIGN_WRAP | FL_ALIGN_INSIDE );
  19. _label = NULL;
  20. label( l );
  21. box( FL_NO_BOX );
  22. clear_visible_focus();
  23. }
  24. Flu_Label :: ~Flu_Label()
  25. {
  26. if( _label )
  27. delete[] _label;
  28. }
  29. void Flu_Label :: draw()
  30. {
  31. if( _autoSize )
  32. {
  33. fl_font( labelfont(), labelsize() );
  34. int W = 0, H = 0;
  35. fl_measure( label(), W, H );
  36. if( W != w() || H != h() )
  37. resize( x(), y(), W, H );
  38. }
  39. Fl_Box::draw();
  40. }
  41. void Flu_Label :: label( const char* l )
  42. {
  43. if( _label )
  44. delete[] _label;
  45. if( l == NULL )
  46. {
  47. _label = new char[1];
  48. _label[0] = '\0';
  49. }
  50. else
  51. {
  52. _label = new char[strlen(l)+1];
  53. strcpy( _label, l );
  54. }
  55. Fl_Box::label( _label );
  56. redraw();
  57. }