2002-01-21 23:39:30 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Insight Consortium. All rights reserved.
|
|
|
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-06-11 02:21:55 +04:00
|
|
|
#include "FLTKPropertyItemRow.h"
|
2001-06-14 22:32:20 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Tile.H>
|
|
|
|
#include <FL/fl_ask.H>
|
|
|
|
#include <FL/fl_file_chooser.H>
|
|
|
|
#include <FL/Fl_Color_Chooser.H>
|
2001-06-21 15:37:49 +04:00
|
|
|
#include <FL/Fl_Menu_Button.H>
|
|
|
|
#include "../cmCacheManager.h"
|
2001-06-21 16:41:14 +04:00
|
|
|
#include "FLTKPropertyList.h"
|
|
|
|
#include "CMakeSetupGUIImplementation.h"
|
2001-06-28 23:11:40 +04:00
|
|
|
#include <stdio.h>
|
2001-06-11 02:21:55 +04:00
|
|
|
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
namespace fltk {
|
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
|
2001-06-21 16:41:14 +04:00
|
|
|
|
|
|
|
CMakeSetupGUIImplementation * PropertyItemRow::m_CMakeSetup = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PropertyItemRow
|
|
|
|
::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"")
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
m_PropertyItem = pItem;
|
2001-06-21 16:41:14 +04:00
|
|
|
m_ItemValue = new ItemValue;
|
2001-06-13 02:44:07 +04:00
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
const unsigned int fontsize = 11;
|
2001-06-11 02:21:55 +04:00
|
|
|
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;
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
size( nameWidth + textWidth , rowHeight );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
2001-06-12 16:34:29 +04:00
|
|
|
// Make the parent Fl_Pack widget at least a row wide.
|
2001-06-13 02:44:07 +04:00
|
|
|
parent()->size( nameWidth + textWidth , rowHeight );
|
|
|
|
|
|
|
|
m_NameButton = new
|
2001-06-21 15:37:49 +04:00
|
|
|
Fl_Button( firstColumn, 0, nameWidth, rowHeight,
|
2001-06-13 02:44:07 +04:00
|
|
|
m_PropertyItem->m_propName.c_str() );
|
|
|
|
|
|
|
|
m_NameButton->align( FL_ALIGN_CLIP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
|
2001-06-13 08:16:35 +04:00
|
|
|
m_NameButton->labelsize( fontsize );
|
2001-06-13 02:44:07 +04:00
|
|
|
m_NameButton->box( FL_DOWN_BOX );
|
|
|
|
m_NameButton->size( secondColumn, rowHeight );
|
2001-06-21 15:37:49 +04:00
|
|
|
m_NameButton->callback( NameButtonCallback, (void *)m_PropertyItem );
|
2001-10-28 06:47:23 +03:00
|
|
|
if( m_PropertyItem->m_NewValue )
|
|
|
|
{
|
|
|
|
m_NameButton->color(FL_RED);
|
|
|
|
}
|
2001-06-13 02:44:07 +04:00
|
|
|
|
|
|
|
switch( m_PropertyItem->m_nItemType )
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
2001-06-13 08:16:35 +04:00
|
|
|
case PropertyList::COMBO:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PropertyList::EDIT:
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
Fl_Input * input = new
|
|
|
|
Fl_Input( secondColumn, 0, textWidth ,rowHeight ,"");
|
2001-06-13 02:44:07 +04:00
|
|
|
input->value( m_PropertyItem->m_curValue.c_str() );
|
2001-06-13 08:16:35 +04:00
|
|
|
input->textsize( fontsize );
|
2001-06-13 02:44:07 +04:00
|
|
|
input->callback( InputTextCallback, (void *)m_PropertyItem );
|
2001-06-11 02:21:55 +04:00
|
|
|
input->when( FL_WHEN_CHANGED );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2001-06-13 08:16:35 +04:00
|
|
|
case PropertyList::COLOR:
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
2001-06-13 08:16:35 +04:00
|
|
|
Fl_Button * colorButton = new
|
|
|
|
Fl_Button( secondColumn, 0, textWidth ,rowHeight ,"");
|
|
|
|
colorButton->labelsize( fontsize );
|
|
|
|
//colorButton->color();
|
|
|
|
colorButton->callback( ColorSelectionCallback, (void *)m_PropertyItem );
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-06-13 08:16:35 +04:00
|
|
|
case PropertyList::FILE:
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
Fl_Button * browseButton = new
|
|
|
|
Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
|
2001-06-13 08:16:35 +04:00
|
|
|
browseButton->labelsize( fontsize );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
Fl_Input * input = new
|
|
|
|
Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
|
2001-06-13 02:44:07 +04:00
|
|
|
input->value( m_PropertyItem->m_curValue.c_str() );
|
2001-06-13 08:16:35 +04:00
|
|
|
input->textsize( fontsize );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
m_ItemValue->m_InputText = input;
|
2001-06-13 02:44:07 +04:00
|
|
|
m_ItemValue->m_PropertyItem = m_PropertyItem;
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
|
2001-06-13 02:44:07 +04:00
|
|
|
input->callback( InputTextCallback, m_PropertyItem );
|
2001-06-11 02:21:55 +04:00
|
|
|
input->when( FL_WHEN_CHANGED );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2001-06-13 08:16:35 +04:00
|
|
|
case PropertyList::CHECKBOX:
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
Fl_Button * button = new
|
|
|
|
Fl_Button( secondColumn, 0, checkWidth ,rowHeight ,"");
|
|
|
|
button->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT );
|
2001-06-13 02:44:07 +04:00
|
|
|
button->callback( CheckButtonCallback, (void *)m_PropertyItem );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
if( m_PropertyItem->m_curValue == "ON" )
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
button->label(" ON ");
|
|
|
|
button->value(1);
|
|
|
|
}
|
2001-06-13 02:44:07 +04:00
|
|
|
else if( m_PropertyItem->m_curValue == "OFF" )
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
button->label(" OFF ");
|
|
|
|
button->value(0);
|
|
|
|
}
|
|
|
|
button->type( FL_TOGGLE_BUTTON );
|
2001-06-13 08:16:35 +04:00
|
|
|
button->labelsize( fontsize );
|
2001-06-11 02:21:55 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-06-13 08:16:35 +04:00
|
|
|
case PropertyList::PATH:
|
2001-06-11 02:21:55 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
Fl_Button * browseButton = new
|
|
|
|
Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"...");
|
2001-06-13 08:16:35 +04:00
|
|
|
browseButton->labelsize( fontsize );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
Fl_Input * input = new
|
|
|
|
Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,"");
|
2001-06-13 02:44:07 +04:00
|
|
|
input->value( m_PropertyItem->m_curValue.c_str() );
|
2001-06-13 08:16:35 +04:00
|
|
|
input->textsize( fontsize );
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
m_ItemValue->m_InputText = input;
|
2001-06-13 02:44:07 +04:00
|
|
|
m_ItemValue->m_PropertyItem = m_PropertyItem;
|
2001-06-11 02:21:55 +04:00
|
|
|
|
|
|
|
browseButton->callback( BrowsePathCallback, (void *)m_ItemValue );
|
2001-06-13 08:16:35 +04:00
|
|
|
input->callback( InputTextCallback, (void *)m_PropertyItem );
|
2001-06-11 02:21:55 +04:00
|
|
|
input->when( FL_WHEN_CHANGED );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2001-06-13 02:44:07 +04:00
|
|
|
fl_alert("Unkown item type %d",m_PropertyItem->m_nItemType);
|
2001-06-11 02:21:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
end(); // Close the inclusion of widgets in the Tile object
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
PropertyItemRow::~PropertyItemRow( )
|
|
|
|
{
|
|
|
|
delete m_ItemValue;
|
|
|
|
}
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
|
|
|
|
|
2001-06-21 16:41:14 +04:00
|
|
|
void PropertyItemRow
|
|
|
|
::SetCMakeSetupGUI( CMakeSetupGUIImplementation * cmakeSetup )
|
|
|
|
{
|
|
|
|
m_CMakeSetup = cmakeSetup;
|
|
|
|
}
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
|
2001-06-21 15:37:49 +04:00
|
|
|
void
|
|
|
|
PropertyItemRow::
|
|
|
|
NameButtonCallback( Fl_Widget * widget, void * data)
|
|
|
|
{
|
|
|
|
Fl_Button * button = (Fl_Button *)widget;
|
|
|
|
PropertyItem * pItem = (PropertyItem *)data;
|
|
|
|
|
|
|
|
static Fl_Menu_Button * popupMenu = 0;
|
|
|
|
if( !popupMenu )
|
|
|
|
{
|
2001-06-21 17:45:46 +04:00
|
|
|
int lastMousePositionX = Fl::event_x();
|
|
|
|
int lastMousePositionY = Fl::event_y();
|
2001-06-21 15:37:49 +04:00
|
|
|
popupMenu = new Fl_Menu_Button(lastMousePositionX,
|
|
|
|
lastMousePositionY,100,200);
|
|
|
|
}
|
|
|
|
|
|
|
|
popupMenu->type( Fl_Menu_Button::POPUP3 );
|
|
|
|
popupMenu->add("Help|Remove|Properties...");
|
|
|
|
popupMenu->popup();
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
HELP=0,
|
|
|
|
REMOVE,
|
|
|
|
PROPERTIES
|
|
|
|
} MenuOptions;
|
|
|
|
|
|
|
|
|
|
|
|
switch( popupMenu->value() )
|
|
|
|
{
|
|
|
|
case HELP:
|
|
|
|
fl_message( pItem->m_HelpString.c_str() );
|
|
|
|
break;
|
|
|
|
case REMOVE: // Remove
|
|
|
|
{
|
|
|
|
const char * propertyName = pItem->m_propName.c_str();
|
|
|
|
int answer = fl_ask( "Do you want to remove property %s", propertyName );
|
|
|
|
if( answer == 1 )
|
|
|
|
{
|
|
|
|
// Remove the entry from the cache
|
|
|
|
cmCacheManager::GetInstance()->RemoveCacheEntry( propertyName );
|
|
|
|
// Get the parent: Fl_Tile that manages the whole row in the GUI
|
2001-06-21 16:41:14 +04:00
|
|
|
Fl_Group * parentGroup = dynamic_cast<Fl_Group *>(button->parent());
|
2001-06-21 15:37:49 +04:00
|
|
|
// Get the grandParent: Fl_Pack with the property list
|
2001-06-21 16:41:14 +04:00
|
|
|
Fl_Group * grandParentGroup = dynamic_cast<Fl_Group *>( parentGroup->parent() );
|
2001-06-21 15:37:49 +04:00
|
|
|
// Remove the row from the list
|
|
|
|
grandParentGroup->remove( *parentGroup );
|
|
|
|
// Destroy the row
|
|
|
|
delete parentGroup; // Patricide... ?
|
|
|
|
// Redraw the list
|
|
|
|
grandParentGroup->redraw();
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI();
|
2001-06-21 15:37:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROPERTIES: // Properties
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-21 16:41:14 +04:00
|
|
|
void
|
|
|
|
PropertyItemRow::
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI( void )
|
2001-06-21 16:41:14 +04:00
|
|
|
{
|
|
|
|
if( m_CMakeSetup )
|
|
|
|
{
|
2001-10-31 02:32:34 +03:00
|
|
|
m_CMakeSetup->FillCacheManagerFromCacheGUI();
|
2001-06-21 16:41:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-21 15:37:49 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
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";
|
|
|
|
}
|
2001-10-28 06:47:23 +03:00
|
|
|
|
|
|
|
pItem->m_Dirty = true;
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
button->redraw();
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI();
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PropertyItemRow::
|
|
|
|
InputTextCallback( Fl_Widget * widget, void * data)
|
|
|
|
{
|
|
|
|
Fl_Input * input = (Fl_Input *)widget;
|
|
|
|
PropertyItem * item = (PropertyItem *)data;
|
|
|
|
|
|
|
|
item->m_curValue = input->value();
|
|
|
|
|
2001-10-28 06:47:23 +03:00
|
|
|
item->m_Dirty = true;
|
|
|
|
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI();
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
}
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
|
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
void
|
|
|
|
PropertyItemRow::
|
|
|
|
ColorSelectionCallback( Fl_Widget * widget, void * data)
|
|
|
|
{
|
|
|
|
Fl_Button * colorButton = (Fl_Button *)widget;
|
|
|
|
PropertyItem * propertyItem = (PropertyItem *)data;
|
|
|
|
|
|
|
|
static Fl_Color colorIndex = FL_FREE_COLOR;
|
|
|
|
|
|
|
|
unsigned char red = 0;
|
|
|
|
unsigned char blue = 0;
|
|
|
|
unsigned char green = 0;
|
|
|
|
fl_color_chooser("Please pick a color",red,green,blue);
|
|
|
|
char buffer[300];
|
|
|
|
sprintf( buffer,"RGB(%d,%d,%d)", red, green, blue );
|
|
|
|
propertyItem->m_curValue = buffer;
|
|
|
|
Fl::set_color( colorIndex, red, green, blue );
|
|
|
|
colorButton->color( colorIndex );
|
|
|
|
colorIndex = (Fl_Color)( colorIndex + 1 );
|
|
|
|
if( colorIndex == FL_FREE_COLOR + FL_NUM_FREE_COLOR )
|
|
|
|
{
|
|
|
|
fl_alert("Maximum number of free colors used, recycling...");
|
|
|
|
colorIndex = FL_FREE_COLOR;
|
|
|
|
}
|
|
|
|
|
2001-10-28 06:47:23 +03:00
|
|
|
propertyItem->m_Dirty = true;
|
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
colorButton->redraw();
|
|
|
|
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI();
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-13 02:44:07 +04:00
|
|
|
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2001-10-28 06:47:23 +03:00
|
|
|
propertyItem->m_Dirty = true;
|
|
|
|
|
2001-10-31 02:32:34 +03:00
|
|
|
FillCacheManagerFromCacheGUI();
|
2001-06-21 16:41:14 +04:00
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-13 08:16:35 +04:00
|
|
|
|
|
|
|
|
2001-06-11 02:21:55 +04:00
|
|
|
} // end namespace fltk
|