Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / FLTKDialog / FLTKPropertyItemRow.cxx
blob7b851b7b700946403df2dca1f6f9c4f8e542a4c5
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: FLTKPropertyItemRow.cxx,v $
5 Language: C++
6 Date: $Date: 2007/08/21 20:21:09 $
7 Version: $Revision: 1.20 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "FLTKPropertyItemRow.h"
18 #include <FL/Fl.H>
19 #include <FL/Fl_Window.H>
20 #include <FL/Fl_Button.H>
21 #include <FL/Fl_Box.H>
22 #include <FL/Fl_Input.H>
23 #include <FL/Fl_Tile.H>
24 #include <FL/fl_ask.H>
25 #include <FL/Fl_File_Chooser.H>
26 #include <FL/Fl_Color_Chooser.H>
27 #include <FL/Fl_Menu_Button.H>
28 #include "../cmCacheManager.h"
29 #include "FLTKPropertyList.h"
30 #include "CMakeSetupGUIImplementation.h"
31 #include <stdio.h>
32 #include "../cmake.h"
33 #include "../cmCacheManager.h"
35 namespace fltk {
39 CMakeSetupGUIImplementation * PropertyItemRow::m_CMakeSetup = 0;
44 PropertyItemRow
45 ::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"")
48 m_PropertyItem = pItem;
49 m_ItemValue = new ItemValue;
51 const unsigned int fontsize = 11;
52 const unsigned int nameWidth = 200;
53 const unsigned int textWidth = 1400;
54 const unsigned int checkWidth = textWidth;
55 const unsigned int browseWidth = 20;
56 const unsigned int firstColumn = 0;
58 const unsigned int secondColumn = nameWidth;
60 const unsigned int rowHeight = 20;
62 size( nameWidth + textWidth , rowHeight );
64 // Make the parent Fl_Pack widget at least a row wide.
65 parent()->size( nameWidth + textWidth , rowHeight );
67 m_NameButton = new
68 Fl_Button( firstColumn, 0, nameWidth, rowHeight,
69 m_PropertyItem->m_propName.c_str() );
71 m_NameButton->align( FL_ALIGN_CLIP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
72 m_NameButton->labelsize( fontsize );
73 m_NameButton->box( FL_DOWN_BOX );
74 m_NameButton->size( secondColumn, rowHeight );
75 m_NameButton->callback( NameButtonCallback, (void *)m_PropertyItem );
76 if( m_PropertyItem->m_NewValue )
78 m_NameButton->color(FL_RED);
81 switch( m_PropertyItem->m_nItemType )
83 case PropertyList::COMBO:
85 break;
87 case PropertyList::EDIT:
90 Fl_Input * input = new
91 Fl_Input( secondColumn, 0, textWidth ,rowHeight ,"");
92 input->value( m_PropertyItem->m_curValue.c_str() );
93 input->textsize( fontsize );
94 input->callback( InputTextCallback, (void *)m_PropertyItem );
95 input->when( FL_WHEN_CHANGED );
97 break;
99 case PropertyList::COLOR:
101 Fl_Button * colorButton = new
102 Fl_Button( secondColumn, 0, textWidth ,rowHeight ,"");
103 colorButton->labelsize( fontsize );
104 //colorButton->color();
105 colorButton->callback( ColorSelectionCallback, (void *)m_PropertyItem );
107 break;
109 case PropertyList::FILE:
112 Fl_Button * browseButton = new
113 Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
114 browseButton->labelsize( fontsize );
116 Fl_Input * input = new
117 Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
118 input->value( m_PropertyItem->m_curValue.c_str() );
119 input->textsize( fontsize );
121 m_ItemValue->m_InputText = input;
122 m_ItemValue->m_PropertyItem = m_PropertyItem;
124 browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
125 input->callback( InputTextCallback, m_PropertyItem );
126 input->when( FL_WHEN_CHANGED );
128 break;
130 case PropertyList::CHECKBOX:
132 Fl_Button * button = new
133 Fl_Button( secondColumn, 0, checkWidth ,rowHeight ,"");
134 button->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT );
135 button->callback( CheckButtonCallback, (void *)m_PropertyItem );
137 if( m_PropertyItem->m_curValue == "ON" )
139 button->label(" ON ");
140 button->value(1);
142 else if( m_PropertyItem->m_curValue == "OFF" )
144 button->label(" OFF ");
145 button->value(0);
147 button->type( FL_TOGGLE_BUTTON );
148 button->labelsize( fontsize );
149 break;
151 case PropertyList::PATH:
154 Fl_Button * browseButton = new
155 Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
156 browseButton->labelsize( fontsize );
158 Fl_Input * input = new
159 Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
160 input->value( m_PropertyItem->m_curValue.c_str() );
161 input->textsize( fontsize );
163 m_ItemValue->m_InputText = input;
164 m_ItemValue->m_PropertyItem = m_PropertyItem;
166 browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
167 input->callback( InputTextCallback, (void *)m_PropertyItem );
168 input->when( FL_WHEN_CHANGED );
170 break;
172 break;
173 default:
174 fl_alert("Unkown item type %d",m_PropertyItem->m_nItemType);
175 break;
179 end(); // Close the inclusion of widgets in the Tile object
187 PropertyItemRow::~PropertyItemRow( )
189 delete m_ItemValue;
194 void PropertyItemRow
195 ::SetCMakeSetupGUI( CMakeSetupGUIImplementation * cmakeSetup )
197 m_CMakeSetup = cmakeSetup;
202 void
203 PropertyItemRow::
204 NameButtonCallback( Fl_Widget * widget, void * data)
206 Fl_Button * button = (Fl_Button *)widget;
207 PropertyItem * pItem = (PropertyItem *)data;
209 static Fl_Menu_Button * popupMenu = 0;
210 if( !popupMenu )
212 int lastMousePositionX = Fl::event_x();
213 int lastMousePositionY = Fl::event_y();
214 popupMenu = new Fl_Menu_Button(lastMousePositionX,
215 lastMousePositionY,100,200);
218 popupMenu->type( Fl_Menu_Button::POPUP3 );
219 popupMenu->add("Help|Remove|Properties...");
220 popupMenu->popup();
222 typedef enum {
223 HELP=0,
224 REMOVE,
225 PROPERTIES
226 } MenuOptions;
229 switch( popupMenu->value() )
231 case HELP:
232 fl_message( pItem->m_HelpString.c_str() );
233 break;
234 case REMOVE: // Remove
236 const char * propertyName = pItem->m_propName.c_str();
237 int answer = fl_ask( "Do you want to remove property %s", propertyName );
238 if( answer == 1 )
240 // Remove the entry from the cache
241 m_CMakeSetup->GetCMakeInstance()->GetCacheManager()->RemoveCacheEntry(propertyName);
242 // Get the parent: Fl_Tile that manages the whole row in the GUI
243 Fl_Group * parentGroup = dynamic_cast<Fl_Group *>(button->parent());
244 // Get the grandParent: Fl_Pack with the property list
245 Fl_Group * grandParentGroup = dynamic_cast<Fl_Group *>( parentGroup->parent() );
246 // Remove the row from the list
247 grandParentGroup->remove( *parentGroup );
248 // Destroy the row
249 delete parentGroup; // Patricide... ?
250 // Redraw the list
251 grandParentGroup->redraw();
252 FillCacheManagerFromCacheGUI();
253 return;
255 break;
257 case PROPERTIES: // Properties
258 break;
264 void
265 PropertyItemRow::
266 FillCacheManagerFromCacheGUI( void )
268 if( m_CMakeSetup )
270 m_CMakeSetup->FillCacheManagerFromCacheGUI();
276 void
277 PropertyItemRow::
278 CheckButtonCallback( Fl_Widget * widget, void * data)
280 Fl_Button * button = (Fl_Button *)widget;
281 PropertyItem * pItem = (PropertyItem *)data;
283 int value = button->value();
285 if( value )
287 button->label(" ON ");
288 pItem->m_curValue = "ON";
290 else
292 button->label(" OFF ");
293 pItem->m_curValue = "OFF";
296 pItem->m_Dirty = true;
298 button->redraw();
300 FillCacheManagerFromCacheGUI();
306 void
307 PropertyItemRow::
308 InputTextCallback( Fl_Widget * widget, void * data)
310 Fl_Input * input = (Fl_Input *)widget;
311 PropertyItem * item = (PropertyItem *)data;
313 item->m_curValue = input->value();
315 item->m_Dirty = true;
317 FillCacheManagerFromCacheGUI();
323 void
324 PropertyItemRow::
325 ColorSelectionCallback( Fl_Widget * widget, void * data)
327 Fl_Button * colorButton = (Fl_Button *)widget;
328 PropertyItem * propertyItem = (PropertyItem *)data;
330 static Fl_Color colorIndex = FL_FREE_COLOR;
332 unsigned char red = 0;
333 unsigned char blue = 0;
334 unsigned char green = 0;
335 fl_color_chooser("Please pick a color",red,green,blue);
336 char buffer[300];
337 sprintf( buffer,"RGB(%d,%d,%d)", red, green, blue );
338 propertyItem->m_curValue = buffer;
339 Fl::set_color( colorIndex, red, green, blue );
340 colorButton->color( colorIndex );
341 colorIndex = (Fl_Color)( colorIndex + 1 );
342 if( colorIndex == FL_FREE_COLOR + FL_NUM_FREE_COLOR )
344 fl_alert("Maximum number of free colors used, recycling...");
345 colorIndex = FL_FREE_COLOR;
348 propertyItem->m_Dirty = true;
350 colorButton->redraw();
352 FillCacheManagerFromCacheGUI();
361 void
362 PropertyItemRow::
363 BrowsePathCallback( Fl_Widget * widget, void * data)
365 ItemValue * itemValue = (ItemValue *)data;
366 Fl_Input * inputText = itemValue->m_InputText;
367 PropertyItem * propertyItem = itemValue->m_PropertyItem;
369 const char * newpath =
370 fl_file_chooser("Select a path","*", inputText->value() );
372 if( newpath )
374 propertyItem->m_curValue = newpath;
375 inputText->value( newpath );
378 propertyItem->m_Dirty = true;
380 FillCacheManagerFromCacheGUI();
387 } // end namespace fltk