void FolderWindow::AddStructure(const char* filename, const int index) { Fl_Pack* pack = folderPack; pack->begin(); int vertPosn = pack->children() * 30 + pack->y(); Fl_Group* group = new Fl_Group(pack->x(), vertPosn, pack->w(), 30); group->begin(); Fl_Button* label = new Fl_Button(pack->x() + 10, vertPosn, pack->w() - 40, 30, filename); label->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_LEFT); label->callback(FolderWindow::ShowFileCallback); label->user_data((void*)index); Fl_Button* removeButton = new Fl_Button(pack->x() + pack->w() - 20, vertPosn + 5, 20, 20); removeButton->callback(FolderWindow::RemoveCallback); removeButton->user_data((void*)index); removeButton->label("@1+"); //printf("Added file: %s\n",label->label()); group->resizable(label); group->end(); pack->end(); folderScroll->redraw(); }
void FolderWindow::RemoveCallback(Fl_Widget* widget, void* userData) { FolderWindow* fwindow = (FolderWindow*)(widget->parent()->parent()->parent()->parent()); Fl_Pack* pack = fwindow->folderPack; for(int i = 0; i < pack->children(); ++i) { Fl_Group* tempGroup = (Fl_Group*)pack->child(i); Fl_Button* childButton = (Fl_Button*)tempGroup->child(1); // <--- here if (childButton == widget) { RNAStructViz* appInstance = RNAStructViz::GetInstance(); const std::vector<DiagramWindow*>& diagrams = appInstance->GetDiagramWindows(); for (unsigned int ui = 0; ui < diagrams.size(); ++ui) { if(diagrams[ui]->GetFolderIndex() == fwindow->m_folderIndex) { diagrams[ui]->RemoveStructure((intptr_t)userData); break; } } const std::vector<StatsWindow*>& stats = appInstance->GetStatsWindows(); for (unsigned int ui = 0; ui < stats.size(); ++ui) { if(stats[ui]->GetFolderIndex() == fwindow->m_folderIndex) { stats[ui]->RemoveStructure((intptr_t)userData); break; } } Fl_Group* toRemove = (Fl_Group*)pack->child(i); // <--- here pack->remove(toRemove); fwindow->folderScroll->redraw(); Fl::delete_widget(toRemove); appInstance->GetStructureManager()->DecreaseStructCount( fwindow->m_folderIndex); appInstance->GetStructureManager()->RemoveStructure((intptr_t)userData); break; } } }
void FolderWindow::AddStructure(const char* filename, const int index) { Fl_Pack* pack = folderPack; pack->begin(); int vertPosn = pack->children() * NAVBUTTONS_BHEIGHT; //+ pack->y() + 15; Fl_Group* group = new Fl_Group(pack->x(), vertPosn, pack->w(), NAVBUTTONS_BHEIGHT); group->begin(); Fl_Button* label = new Fl_Button(pack->x() + 10, vertPosn, pack->w() - 40, 30, filename); label->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_LEFT); label->callback(FolderWindow::ShowFileCallback); label->user_data((void*)index); label->labelcolor(GUI_BTEXT_COLOR); char labelWithIcon[MAX_BUFFER_SIZE]; std::string spaceBuffer = string(" "); int curLabelLen = 0; char filePrefix[MAX_BUFFER_SIZE]; size_t fileNameBytes = strlen(filename); snprintf(filePrefix, MAX_BUFFER_SIZE, "%-.20s%s", filename, fileNameBytes > MAX_FOLDER_LABEL_CHARS ? "..." : ""); snprintf(labelWithIcon, MAX_BUFFER_SIZE - 1, "@filenew %s%s", filePrefix, spaceBuffer.substr(0, MAX(0, MAX_FOLDER_LABEL_CHARS - ((int ) strlen(filePrefix)))).c_str()); //strcat(labelWithIcon, " @|>"); label->copy_label(labelWithIcon); label->tooltip(filename); Fl_Button* removeButton = new Fl_Button(pack->x() + pack->w() - 20, vertPosn + 5, 20, 20); removeButton->callback(FolderWindow::RemoveCallback); removeButton->user_data((void*)index); removeButton->label("@1+"); removeButton->labelcolor(GUI_TEXT_COLOR); group->resizable(label); group->end(); pack->end(); folderScroll->redraw(); }