diff --git a/Source/FLTKDialog/FLTKPropertyItemRow.cxx b/Source/FLTKDialog/FLTKPropertyItemRow.cxx index 87b20d043..c48cd5d64 100644 --- a/Source/FLTKDialog/FLTKPropertyItemRow.cxx +++ b/Source/FLTKDialog/FLTKPropertyItemRow.cxx @@ -7,10 +7,12 @@ #include #include #include +#include +#include namespace fltk { - + PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") { @@ -18,6 +20,7 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") m_ItemValue = new ItemValue; + const unsigned int fontsize = 11; const unsigned int nameWidth = 200; const unsigned int textWidth = 1400; const unsigned int checkWidth = textWidth; @@ -39,44 +42,50 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") m_PropertyItem->m_propName.c_str() ); m_NameButton->align( FL_ALIGN_CLIP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE ); - m_NameButton->labelsize(11); + m_NameButton->labelsize( fontsize ); m_NameButton->box( FL_DOWN_BOX ); m_NameButton->SetHelpText( m_PropertyItem->m_HelpString.c_str() ); m_NameButton->size( secondColumn, rowHeight ); switch( m_PropertyItem->m_nItemType ) { - case 1: + case PropertyList::COMBO: + { + break; + } + case PropertyList::EDIT: { Fl_Input * input = new Fl_Input( secondColumn, 0, textWidth ,rowHeight ,""); input->value( m_PropertyItem->m_curValue.c_str() ); - input->textsize(11); + input->textsize( fontsize ); input->callback( InputTextCallback, (void *)m_PropertyItem ); input->when( FL_WHEN_CHANGED ); break; } - case 2: + case PropertyList::COLOR: { + Fl_Button * colorButton = new + Fl_Button( secondColumn, 0, textWidth ,rowHeight ,""); + colorButton->labelsize( fontsize ); + //colorButton->color(); + colorButton->callback( ColorSelectionCallback, (void *)m_PropertyItem ); + break; } - case 3: - { - break; - } - case 4: + case PropertyList::FILE: { Fl_Button * browseButton = new Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"..."); - browseButton->labelsize(11); + browseButton->labelsize( fontsize ); Fl_Input * input = new Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,""); input->value( m_PropertyItem->m_curValue.c_str() ); - input->textsize(11); + input->textsize( fontsize ); m_ItemValue->m_InputText = input; m_ItemValue->m_PropertyItem = m_PropertyItem; @@ -87,7 +96,7 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") break; } - case 5: + case PropertyList::CHECKBOX: { Fl_Button * button = new Fl_Button( secondColumn, 0, checkWidth ,rowHeight ,""); @@ -105,26 +114,26 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") button->value(0); } button->type( FL_TOGGLE_BUTTON ); - button->labelsize(11); + button->labelsize( fontsize ); break; } - case 6: + case PropertyList::PATH: { Fl_Button * browseButton = new Fl_Button( secondColumn, 0, browseWidth ,rowHeight ,"..."); - browseButton->labelsize(11); + browseButton->labelsize( fontsize ); Fl_Input * input = new Fl_Input( secondColumn+browseWidth, 0, textWidth ,rowHeight ,""); input->value( m_PropertyItem->m_curValue.c_str() ); - input->textsize(11); + input->textsize( fontsize ); m_ItemValue->m_InputText = input; m_ItemValue->m_PropertyItem = m_PropertyItem; browseButton->callback( BrowsePathCallback, (void *)m_ItemValue ); - input->callback( InputTextCallback, m_PropertyItem ); + input->callback( InputTextCallback, (void *)m_PropertyItem ); input->when( FL_WHEN_CHANGED ); break; @@ -138,7 +147,6 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem ):Fl_Tile(0,0,10,10,"") end(); // Close the inclusion of widgets in the Tile object - } @@ -191,6 +199,38 @@ InputTextCallback( Fl_Widget * widget, void * data) +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; + } + + colorButton->redraw(); + +} + + + + void @@ -213,13 +253,14 @@ BrowsePathCallback( Fl_Widget * widget, void * data) } + + int PropertyItemRow:: handle(int event) { int status = Fl_Tile::handle( event ); - switch( event ) { case FL_LEAVE: diff --git a/Source/FLTKDialog/FLTKPropertyItemRow.h b/Source/FLTKDialog/FLTKPropertyItemRow.h index 4803b9a96..d3adb3ebf 100644 --- a/Source/FLTKDialog/FLTKPropertyItemRow.h +++ b/Source/FLTKDialog/FLTKPropertyItemRow.h @@ -8,6 +8,7 @@ #include #include + namespace fltk { @@ -42,9 +43,11 @@ class PropertyItemRow : public Fl_Tile // manages the popup help blob PropertyNameButtonWithHelp * m_NameButton; + static void CheckButtonCallback( Fl_Widget *, void *); static void InputTextCallback( Fl_Widget *, void *); static void BrowsePathCallback( Fl_Widget *, void *); + static void ColorSelectionCallback( Fl_Widget * widget, void * data); }; diff --git a/Source/FLTKDialog/FLTKPropertyList.cxx b/Source/FLTKDialog/FLTKPropertyList.cxx index 7efbf2462..e1651e179 100644 --- a/Source/FLTKDialog/FLTKPropertyList.cxx +++ b/Source/FLTKDialog/FLTKPropertyList.cxx @@ -18,10 +18,10 @@ namespace fltk { PropertyList::PropertyList() { - m_Dirty = false; - m_curSel = -1; } + + PropertyList::~PropertyList() { for(std::set::iterator i = m_PropertyItems.begin(); @@ -34,7 +34,7 @@ PropertyList::~PropertyList() -int PropertyList::AddItem(string txt) +int PropertyList::AddItem( std::string txt) { int nIndex =0;// = AddString(txt); return nIndex; @@ -71,7 +71,6 @@ int PropertyList::AddProperty(const char* name, { pItem->m_curValue = value; pItem->m_HelpString = helpString; - m_Dirty = true; Invalidate(); } return i; @@ -88,74 +87,6 @@ int PropertyList::AddProperty(const char* name, -void PropertyList::OnButton() -{ - PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel); - - //display the appropriate common dialog depending on what type - //of chooser is associated with the property - if (pItem->m_nItemType == PropertyList::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); - pItem->m_curValue = buffer; - m_Dirty = true; - Invalidate(); - } - else if (pItem->m_nItemType == PropertyList::FILE) - { - string currPath = pItem->m_curValue; - - const char * SelectedFile - = fl_file_chooser("Choose a file", - "*",currPath.c_str() ); - - if( SelectedFile ) - { - pItem->m_curValue = SelectedFile; - m_Dirty = true; - Invalidate(); - } - } - else if (pItem->m_nItemType == PropertyList::PATH) - { - string currPath = pItem->m_curValue; - string initialDir = currPath; - - const char * SelectedFile - = fl_file_chooser("Choose a directory", - "*/",initialDir.c_str() ); - - if( SelectedFile && filename_isdir( SelectedFile ) ) - { - pItem->m_curValue = SelectedFile; - m_Dirty = true; - Invalidate(); - } - } - else if (pItem->m_nItemType == PropertyList::FONT) - { - } -} - - - - -void PropertyList::OnHelp() -{ - if(m_curSel == -1 || this->GetCount() <= 0) - { - return; - } - PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel); - fl_message(pItem->m_HelpString.c_str()); -} - - void PropertyList::RemoveAll() { int c = this->GetCount(); diff --git a/Source/FLTKDialog/FLTKPropertyList.h b/Source/FLTKDialog/FLTKPropertyList.h index f08dd6cb0..b750c27a5 100644 --- a/Source/FLTKDialog/FLTKPropertyList.h +++ b/Source/FLTKDialog/FLTKPropertyList.h @@ -7,7 +7,6 @@ namespace fltk { -using std::string; ///////////////////////////////////////////////////////////////////////////// //PropertyList Items @@ -15,16 +14,18 @@ class PropertyItem { // Attributes public: - string m_HelpString; - string m_propName; - string m_curValue; + std::string m_HelpString; + std::string m_propName; + std::string m_curValue; int m_nItemType; - string m_cmbItems; + std::string m_cmbItems; bool m_Removed; public: - PropertyItem(string propName, string curValue, - string helpString, - int nItemType, string cmbItems) + PropertyItem( std::string propName, + std::string curValue, + std::string helpString, + int nItemType, + std::string cmbItems ) { m_HelpString = helpString; m_Removed = false; @@ -59,7 +60,7 @@ public: // Operations public: - int AddItem(string txt); + int AddItem( std::string txt ); int AddProperty(const char* name, const char* value, const char* helpString, @@ -88,17 +89,11 @@ public: public: virtual ~PropertyList(); - // Generated message map functions protected: int AddPropItem(PropertyItem* pItem); -// CComboBox m_cmbBox; -// CEdit m_editBox; -// CButton m_btnCtrl; -// CButton m_CheckBoxControl; - - + /* bool m_Dirty; int m_curSel; int m_prevSel; @@ -107,6 +102,7 @@ protected: int m_nDivBtm; int m_nOldDivX; int m_nLastBox; + */ std::set m_PropertyItems; diff --git a/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.cxx b/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.cxx index 33c8f646b..3b8858dbc 100644 --- a/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.cxx +++ b/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.cxx @@ -1,5 +1,9 @@ #include #include +#include +#include +#include "../cmCacheManager.h" + namespace fltk { @@ -72,6 +76,8 @@ PropertyNameButtonWithHelp:: handle( int event ) { + static bool helpBlobVisible = false; + const float delayForShowingHelpBlob = 1.0; // seconds const int maxWidth = 300; @@ -96,7 +102,7 @@ handle( int event ) switch( event ) { case FL_ENTER: - { + { lastMousePositionX = Fl::event_x(); lastMousePositionY = Fl::event_y(); const float factor = helpText->labelsize() * 0.5; @@ -117,15 +123,33 @@ handle( int event ) helpText->label( m_HelpText.c_str() ); Fl_Widget * parent = this->parent(); Fl::add_timeout( delayForShowingHelpBlob, ShowHelpBlobCallback, (void *)parent ); + helpBlobVisible = true; eventManaged = 0; break; - } + } case FL_LEAVE: - helpBlob->hide(); + { + if( helpBlobVisible ) + { + helpBlobVisible = false; + helpBlob->hide(); + } eventManaged = 0; break; + } case FL_MOVE: - helpBlob->hide(); + if( helpBlobVisible ) + { + helpBlobVisible = false; + helpBlob->hide(); + } + eventManaged = 0; + break; + case FL_PUSH: + if( Fl::event_button() == FL_RIGHT_MOUSE ) + { + PopupMenu(); + } eventManaged = 0; break; default: @@ -156,5 +180,53 @@ ShowHelpBlobCallback( void * data ) +//////////////////////////////////////////////////////////////// +// This popup menu is displayed when the +// right mouse button is pressed +void +PropertyNameButtonWithHelp:: +PopupMenu(void) +{ + static Fl_Menu_Button * popupMenu = 0; + if( !popupMenu ) + { + popupMenu = new Fl_Menu_Button(0,0,100,200); + } + + popupMenu->type( Fl_Menu_Button::POPUP3 ); + popupMenu->add("Remove|Properties..."); + popupMenu->popup(); + + switch( popupMenu->value() ) + { + case 0: // Remove + { + const char * propertyName = label(); + 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 + Fl_Group * parentGroup = (Fl_Group *) parent(); + // Get the grandParent: Fl_Pack with the property list + Fl_Group * grandParentGroup = (Fl_Group *) parentGroup->parent(); + // Remove the row from the list + grandParentGroup->remove( *parentGroup ); + // Destroy the row + delete parentGroup; // Patricide... ? + // Redraw the list + grandParentGroup->redraw(); + return; + } + break; + } + case 1: // Properties + break; + } +} + + + } // end namespace fltk diff --git a/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.h b/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.h index 040b2e9b0..12c02984d 100644 --- a/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.h +++ b/Source/FLTKDialog/FLTKPropertyNameButtonWithHelp.h @@ -28,9 +28,11 @@ class PropertyNameButtonWithHelp : public Fl_Button static void ShowHelpBlobCallback( void * ); + void PopupMenu( void ); + private: - string m_HelpText; + std::string m_HelpText; // Class variables static Fl_Window * helpBlob;