void IconChooser::load_from_list(list<String>& lst) { if(lst.empty()) return; Fl_Shared_Image* img = NULL; int imax_w = 0; int imax_h = 0; int iw, ih; bool show_progress = false; list<String>::iterator it = lst.begin(), it_end = lst.end(); /* * lst_info contains coresponding indexes with list<String> so we can deduce what * files to skip (not readable image or dimensions greater than allowed); skippable are marked as 0 */ int* lst_info = new int[lst.size()]; for(int n = 0; it != it_end; ++it, n++){ img = Fl_Shared_Image::get((*it).c_str()); if(!img) { lst_info[n] = 0; continue; } iw = img->w(); ih = img->h(); if(iw > MAX_ICON_W || ih > MAX_ICON_H) { lst_info[n] = 0; continue; } imax_w = MAX(imax_w, iw); imax_h = MAX(imax_h, ih); lst_info[n] = 1; } /* clear potential content of ExpandableGroup */ if(icongrp->children()) icongrp->clear(); if(lst.size() > 10) { show_progress = true; progress->minimum(0); progress->maximum(lst.size()); progress->show(); } if(imax_w < 64) imax_w = 64; else imax_w += 10; if(imax_h < 64) imax_h = 64; else imax_h += 10; imax_w += 5; imax_h += 5; /* * focus_index() is only valid on childs before we show them and that is what we need * so other childs don't mess it when they are added */ //icongrp->focus(child(0)); icongrp->set_visible_focus(); IconBox* preview; it = lst.begin(); for(int n = 0; it != it_end; ++it, n++) { img = Fl_Shared_Image::get((*it).c_str()); if(img && lst_info[n] == 1) { preview = new IconBox(0, 0, imax_w, imax_h); preview->set_icon_path((*it)); /* use background/selection from ExpandableGroup */ preview->color(icongrp->color()); preview->selection_color(icongrp->color()); if(show_progress) progress->value(int((n * 100) / int(progress->maximum()))); preview->image(img); preview->callback(iconbox_cb, this); icongrp->add(preview); Fl::check(); } } progress->hide(); delete [] lst_info; }