Flu_Toggle_Group.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // $Id: Flu_Toggle_Group.cpp,v 1.10 2004/09/16 01:32:25 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 "FLU/Flu_Toggle_Group.H"
  13. #include <stdlib.h>
  14. Flu_Toggle_Group :: Flu_Toggle_Group( int x, int y, int w, int h, const char *l )
  15. : Fl_Group( x, y, w, h, l )
  16. {
  17. chkBtn = new Fl_Check_Button( 0, 0, 0, 0 );
  18. chkBtn->callback( _toggleCB, this );
  19. box( FL_EMBOSSED_FRAME );
  20. align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  21. }
  22. void Flu_Toggle_Group :: toggleCB()
  23. {
  24. do_callback();
  25. redraw();
  26. }
  27. void Flu_Toggle_Group :: draw()
  28. {
  29. int lblW = 0, lblH, X, i;
  30. if( label() == 0 )
  31. lblW = lblH = 0;
  32. else if( strlen( label() ) == 0 )
  33. lblW = lblH = 0;
  34. else
  35. {
  36. measure_label( lblW, lblH );
  37. lblW += 18;
  38. lblH += 2;
  39. }
  40. // align the label
  41. if( align() & FL_ALIGN_LEFT )
  42. X = 4;
  43. else if( align() & FL_ALIGN_RIGHT )
  44. X = w() - lblW - 8;
  45. else
  46. X = w()/2 - lblW/2 - 2;
  47. // draw the main group box
  48. if( damage() & ~FL_DAMAGE_CHILD )
  49. fl_draw_box( box(), x(), y()+lblH/2, w(), h()-lblH/2, color() );
  50. unsigned char *active = 0;
  51. if( !chkBtn->value() )
  52. {
  53. active = (unsigned char*)malloc( children() );
  54. for( i = 1; i < children(); i++ )
  55. {
  56. active[i-1] = child(i)->active();
  57. child(i)->deactivate();
  58. }
  59. }
  60. // clip and draw the children
  61. chkBtn->resize( chkBtn->x(), chkBtn->y(), 0, 0 );
  62. fl_clip( x()+2, y()+lblH+1, w()-4, h()-lblH-3 );
  63. draw_children();
  64. fl_pop_clip();
  65. // clear behind the button and draw it
  66. fl_color( color() );
  67. fl_rectf( x()+X, y(), lblW+4, lblH );
  68. fl_color( labelcolor() );
  69. chkBtn->label( label() );
  70. chkBtn->resize( x()+X+2, y(), lblW, lblH );
  71. draw_child( *chkBtn );
  72. if( !chkBtn->value() )
  73. {
  74. for( i = 1; i < children(); i++ )
  75. {
  76. if( active[i-1] )
  77. child(i)->activate();
  78. else
  79. child(i)->deactivate();
  80. }
  81. free( active );
  82. }
  83. }