FLTKPropertyItemRow.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #include "FLTKPropertyItemRow.h"
  2. #include <Fl/Fl_Button.H>
  3. #include <Fl/Fl_Input.H>
  4. #include <Fl/Fl_Tile.H>
  5. #include <Fl/fl_ask.H>
  6. #include <Fl/fl_file_chooser.H>
  7. namespace fltk {
  8. PropertyItemRow::PropertyItemRow( PropertyItem * pItem )
  9. {
  10. m_PropertyItem = pItem;
  11. m_ItemValue = new ItemValue;
  12. const unsigned int nameWidth = 200;
  13. const unsigned int textWidth = 1400;
  14. const unsigned int checkWidth = textWidth;
  15. const unsigned int browseWidth = 20;
  16. const unsigned int firstColumn = 0;
  17. const unsigned int secondColumn = nameWidth;
  18. const unsigned int rowHeight = 20;
  19. const unsigned int rowSpacing = 20;
  20. Fl_Tile * group = new Fl_Tile(0,0,nameWidth+textWidth,rowHeight,"");
  21. // Make the parent Fl_Pack widget at least a row wide.
  22. group->parent()->size( nameWidth + textWidth , rowHeight );
  23. Fl_Button * name = new
  24. Fl_Button( firstColumn, 0, nameWidth, rowHeight,
  25. pItem->m_propName.c_str() );
  26. name->align( FL_ALIGN_CLIP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  27. name->labelsize(11);
  28. name->box( FL_DOWN_BOX );
  29. name->callback( NameClickCallback, (void *)pItem );
  30. switch( pItem->m_nItemType )
  31. {
  32. case 1:
  33. {
  34. name->size( secondColumn, rowHeight );
  35. Fl_Input * input = new
  36. Fl_Input( secondColumn, 0, textWidth ,rowHeight ,"");
  37. input->value( pItem->m_curValue.c_str() );
  38. input->textsize(11);
  39. input->callback( InputTextCallback, (void *)pItem );
  40. input->when( FL_WHEN_CHANGED );
  41. break;
  42. }
  43. case 2:
  44. {
  45. break;
  46. }
  47. case 3:
  48. {
  49. break;
  50. }
  51. case 4:
  52. {
  53. name->size( secondColumn, rowHeight );
  54. Fl_Button * browseButton = new
  55. Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
  56. browseButton->labelsize(11);
  57. Fl_Input * input = new
  58. Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
  59. input->value( pItem->m_curValue.c_str() );
  60. input->textsize(11);
  61. m_ItemValue->m_InputText = input;
  62. m_ItemValue->m_PropertyItem = pItem;
  63. browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
  64. input->callback( InputTextCallback, pItem );
  65. input->when( FL_WHEN_CHANGED );
  66. break;
  67. }
  68. case 5:
  69. {
  70. Fl_Button * button = new
  71. Fl_Button( secondColumn, 0, checkWidth ,rowHeight ,"");
  72. button->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT );
  73. button->callback( CheckButtonCallback, (void *)pItem );
  74. if( pItem->m_curValue == "ON" )
  75. {
  76. button->label(" ON ");
  77. button->value(1);
  78. }
  79. else if( pItem->m_curValue == "OFF" )
  80. {
  81. button->label(" OFF ");
  82. button->value(0);
  83. }
  84. button->type( FL_TOGGLE_BUTTON );
  85. button->labelsize(11);
  86. break;
  87. }
  88. case 6:
  89. {
  90. name->size( secondColumn, rowHeight );
  91. Fl_Button * browseButton = new
  92. Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
  93. browseButton->labelsize(11);
  94. Fl_Input * input = new
  95. Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
  96. input->value( pItem->m_curValue.c_str() );
  97. input->textsize(11);
  98. m_ItemValue->m_InputText = input;
  99. m_ItemValue->m_PropertyItem = pItem;
  100. browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
  101. input->callback( InputTextCallback, pItem );
  102. input->when( FL_WHEN_CHANGED );
  103. break;
  104. }
  105. break;
  106. default:
  107. fl_alert("Unkown item type %d",pItem->m_nItemType);
  108. break;
  109. }
  110. group->end();
  111. }
  112. PropertyItemRow::~PropertyItemRow( )
  113. {
  114. delete m_ItemValue;
  115. }
  116. void
  117. PropertyItemRow::
  118. CheckButtonCallback( Fl_Widget * widget, void * data)
  119. {
  120. Fl_Button * button = (Fl_Button *)widget;
  121. PropertyItem * pItem = (PropertyItem *)data;
  122. int value = button->value();
  123. if( value )
  124. {
  125. button->label(" ON ");
  126. pItem->m_curValue = "ON";
  127. }
  128. else
  129. {
  130. button->label(" OFF ");
  131. pItem->m_curValue = "OFF";
  132. }
  133. button->redraw();
  134. }
  135. void
  136. PropertyItemRow::
  137. NameClickCallback( Fl_Widget * widget, void * data)
  138. {
  139. PropertyItem * pItem = (PropertyItem *)data;
  140. fl_message( pItem->m_HelpString.c_str() );
  141. }
  142. void
  143. PropertyItemRow::
  144. InputTextCallback( Fl_Widget * widget, void * data)
  145. {
  146. Fl_Input * input = (Fl_Input *)widget;
  147. PropertyItem * item = (PropertyItem *)data;
  148. item->m_curValue = input->value();
  149. }
  150. void
  151. PropertyItemRow::
  152. BrowsePathCallback( Fl_Widget * widget, void * data)
  153. {
  154. ItemValue * itemValue = (ItemValue *)data;
  155. Fl_Input * inputText = itemValue->m_InputText;
  156. PropertyItem * propertyItem = itemValue->m_PropertyItem;
  157. const char * newpath =
  158. fl_file_chooser("Select a path","*", inputText->value() );
  159. if( newpath )
  160. {
  161. propertyItem->m_curValue = newpath;
  162. inputText->value( newpath );
  163. }
  164. }
  165. } // end namespace fltk