FLTKPropertyItemRow.cxx 4.9 KB

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