summaryrefslogtreecommitdiffstats
path: root/Source/FLTKDialog/FLTKPropertyItemRow.cxx
blob: c55cd8bbffde5126b9338051db1caf302431e312 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "FLTKPropertyItemRow.h"
#include <Fl/Fl_Button.H>
#include <Fl/Fl_Input.H>
#include <Fl/Fl_Tile.H>
#include <Fl/fl_ask.H>
#include <Fl/fl_file_chooser.H>

namespace fltk {

PropertyItemRow::PropertyItemRow( PropertyItem * pItem )
{
   
  m_PropertyItem = pItem;
  m_ItemValue    = new ItemValue;

  const unsigned int nameWidth    =        200;
  const unsigned int textWidth    =       1400;
  const unsigned int checkWidth   =  textWidth;
  const unsigned int browseWidth  =         20;
  const unsigned int firstColumn  =          0;

  const unsigned int secondColumn =  nameWidth;

  const unsigned int rowHeight    =         20;
  const unsigned int rowSpacing   =         20;
 
  Fl_Tile * group = new Fl_Tile(0,0,nameWidth+textWidth,rowHeight,"");

  group->parent()->size( nameWidth + textWidth , 100 );

  Fl_Button * name = new 
                Fl_Button( firstColumn, 0, nameWidth, rowHeight, 
                                              pItem->m_propName.c_str() );
  name->align( FL_ALIGN_CLIP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  name->labelsize(11);
  name->box( FL_DOWN_BOX );
  name->callback( NameClickCallback, (void *)pItem );
      
  switch( pItem->m_nItemType )
  {
  case 1: 
    {

      name->size( secondColumn, rowHeight );

      Fl_Input * input = new 
                    Fl_Input( secondColumn, 0, textWidth ,rowHeight ,"");
      input->value( pItem->m_curValue.c_str() );
      input->textsize(11);
      input->callback( InputTextCallback, (void *)pItem );
      input->when( FL_WHEN_CHANGED );

      break;
    }
  case 2:
    {
      break;
    }
  case 3:
    {
      break;
    }
  case 4:
    {

      name->size( secondColumn, rowHeight );
      Fl_Button * browseButton = new 
            Fl_Button( secondColumn, 0, browseWidth  ,rowHeight ,"...");
      browseButton->labelsize(11);

      Fl_Input * input = new 
                    Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
      input->value( pItem->m_curValue.c_str() );
      input->textsize(11);

      m_ItemValue->m_InputText    = input;
      m_ItemValue->m_PropertyItem = pItem;
        
      browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
      input->callback( InputTextCallback, pItem );
      input->when( FL_WHEN_CHANGED );
      
      break;
    }
  case 5:
    {
      Fl_Button * button = new 
            Fl_Button( secondColumn, 0, checkWidth  ,rowHeight ,"");
      button->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT );
      button->callback( CheckButtonCallback, (void *)pItem );

      if( pItem->m_curValue == "ON" ) 
      {
        button->label(" ON  ");
        button->value(1);
      }
      else if( pItem->m_curValue == "OFF" )
      {
        button->label(" OFF ");
        button->value(0);
      }
      button->type( FL_TOGGLE_BUTTON );
      button->labelsize(11);
      break;
    }
  case 6:
    {

      name->size( secondColumn, rowHeight );
      Fl_Button * browseButton = new 
            Fl_Button( secondColumn, 0, browseWidth  ,rowHeight ,"...");
      browseButton->labelsize(11);

      Fl_Input * input = new 
                    Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
      input->value( pItem->m_curValue.c_str() );
      input->textsize(11);

      m_ItemValue->m_InputText    = input;
      m_ItemValue->m_PropertyItem = pItem;
        
      browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
      input->callback( InputTextCallback, pItem );
      input->when( FL_WHEN_CHANGED );
      
      break;
    }
    break;
  default:
    fl_alert("Unkown item type %d",pItem->m_nItemType);
    break;
  }


  group->end();

}


PropertyItemRow::~PropertyItemRow( )
{
  delete m_ItemValue;
}

  
void 
PropertyItemRow::
CheckButtonCallback( Fl_Widget * widget, void * data) 
{
  Fl_Button    * button = (Fl_Button *)widget;
  PropertyItem * pItem  = (PropertyItem *)data;
  
  int value = button->value();

  if( value )
  {
    button->label(" ON ");
    pItem->m_curValue = "ON";
  }
  else 
  {
    button->label(" OFF ");
    pItem->m_curValue = "OFF";
  }
  button->redraw();
}


void 
PropertyItemRow::
NameClickCallback(   Fl_Widget * widget, void * data) 
{
  PropertyItem * pItem  = (PropertyItem *)data;
  fl_message( pItem->m_HelpString.c_str() );
}

void 
PropertyItemRow::
InputTextCallback(   Fl_Widget * widget, void * data)
{
  Fl_Input  * input     = (Fl_Input *)widget;
  PropertyItem * item   = (PropertyItem *)data;
  
  item->m_curValue      = input->value();

}

void 
PropertyItemRow::
BrowsePathCallback(   Fl_Widget * widget, void * data)
{
  ItemValue    * itemValue    = (ItemValue *)data;
  Fl_Input     * inputText    = itemValue->m_InputText;
  PropertyItem * propertyItem = itemValue->m_PropertyItem;

  const char * newpath = 
    fl_file_chooser("Select a path","*", inputText->value() );
  
  if( newpath ) 
  {
    propertyItem->m_curValue = newpath;
    inputText->value( newpath );
  }

}



} // end namespace fltk