diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-01 21:57:52 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-01 21:57:52 +0000 |
| commit | c20891fabc8c3ee2251e0545878e06545b6f0cdd (patch) | |
| tree | c19727ea5ec4c7fb90b7e4512a3cc5fb89f58945 /src/widgets | |
| parent | Merge branch 'master' of gitlab.com:inkscape/inkscape (diff) | |
| download | inkscape-c20891fabc8c3ee2251e0545878e06545b6f0cdd.tar.gz inkscape-c20891fabc8c3ee2251e0545878e06545b6f0cdd.zip | |
First batch
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/ege-adjustment-action.cpp | 13 | ||||
| -rw-r--r-- | src/widgets/gradient-vector.cpp | 61 | ||||
| -rw-r--r-- | src/widgets/paint-selector.cpp | 74 |
3 files changed, 48 insertions, 100 deletions
diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp index 09a4a542b..fc72f00c7 100644 --- a/src/widgets/ege-adjustment-action.cpp +++ b/src/widgets/ege-adjustment-action.cpp @@ -45,6 +45,7 @@ #include <algorithm> #include <gtkmm/container.h> +#include <gtkmm/radiomenuitem.h> #include <gdk/gdkkeysyms.h> #include "icon-size.h" @@ -626,7 +627,7 @@ static void process_menu_action( GtkWidget* obj, gpointer data ) } } -static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* menu, EgeAdjustmentAction* act, GtkWidget** dst, GSList** group, gdouble num, gboolean active ) +static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* menu, EgeAdjustmentAction* act, GtkWidget** dst, Gtk::RadioMenuItem::Group *group, gdouble num, gboolean active ) { char* str = 0; EgeAdjustmentDescr* marker = 0; @@ -647,10 +648,8 @@ static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* men ((marker && marker->descr) ? ": " : ""), ((marker && marker->descr) ? marker->descr : "")); - *dst = gtk_radio_menu_item_new_with_label( *group, str ); - if ( !*group) { - *group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(*dst) ); - } + auto rmi = new Gtk::RadioMenuItem(*group,Glib::ustring(str)); + *dst = GTK_WIDGET(rmi->gobj()); if ( active ) { gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(*dst), TRUE ); } @@ -669,7 +668,7 @@ static int flush_explicit_items( std::vector<EgeAdjustmentDescr*> descriptions, GtkWidget* menu, EgeAdjustmentAction* act, GtkWidget** dst, - GSList** group, + Gtk::RadioMenuItem::Group *group, gdouble num ) { if(pos >= descriptions.size() || pos < 0) return pos; @@ -693,7 +692,7 @@ static GtkWidget* create_popup_number_menu( EgeAdjustmentAction* act ) { GtkWidget* menu = gtk_menu_new(); - GSList* group = 0; + Gtk::RadioMenuItem::Group group; GtkWidget* single = 0; std::vector<EgeAdjustmentDescr*> list = act->private_data->descriptions; int addOns = list.size() - 1; diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 0c5f3cf47..fdba2b56d 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -268,17 +268,16 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs) gvs->store->clear(); /* Pick up all gradients with vectors */ - GSList *gl = NULL; + std::vector<SPGradient *> gl; if (gvs->gr) { std::vector<SPObject *> gradients = gvs->gr->document->getResourceList("gradient"); for (std::vector<SPObject *>::const_iterator it = gradients.begin(); it != gradients.end(); ++it) { SPGradient* grad = SP_GRADIENT(*it); if ( grad->hasStops() && (grad->isSwatch() == gvs->swatched) ) { - gl = g_slist_prepend(gl, *it); + gl.push_back(SP_GRADIENT(*it)); } } } - gl = g_slist_reverse(gl); /* Get usage count of all the gradients */ std::map<SPGradient *, gint> usageCount; @@ -288,7 +287,7 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs) Gtk::TreeModel::Row row = *(gvs->store->append()); row[gvs->columns->name] = _("No document selected"); - } else if (!gl) { + } else if (gl.empty()) { Gtk::TreeModel::Row row = *(gvs->store->append()); row[gvs->columns->name] = _("No gradients in document"); @@ -297,11 +296,7 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs) row[gvs->columns->name] = _("No gradient selected"); } else { - while (gl) { - SPGradient *gr; - gr = SP_GRADIENT(gl->data); - gl = g_slist_remove(gl, gr); - + for (auto gr:gl) { unsigned long hhssll = sp_gradient_to_hhssll(gr); GdkPixbuf *pixb = sp_gradient_to_pixbuf (gr, 64, 18); Glib::ustring label = gr_prepare_label(gr); @@ -312,7 +307,6 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs) row[gvs->columns->refcount] = usageCount[gr]; row[gvs->columns->data] = gr; row[gvs->columns->pixbuf] = Glib::wrap(pixb); - } } @@ -333,19 +327,14 @@ unsigned long sp_gradient_to_hhssll(SPGradient *gr) return ((int)(hsl[0]*100 * 10000)) + ((int)(hsl[1]*100 * 100)) + ((int)(hsl[2]*100 * 1)); } -static GSList *get_all_doc_items(GSList *list, SPObject *from, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude) +static void get_all_doc_items(std::vector<SPItem*> &list, SPObject *from) { for (auto& child: from->children) { if (SP_IS_ITEM(&child)) { - list = g_slist_prepend(list, SP_ITEM(&child)); - } - - if (ingroups || SP_IS_ITEM(&child)) { - list = get_all_doc_items(list, &child, onlyvisible, onlysensitive, ingroups, exclude); + list.push_back(SP_ITEM(&child)); } + get_all_doc_items(list, &child); } - - return list; } /* @@ -377,15 +366,10 @@ void gr_get_usage_counts(SPDocument *doc, std::map<SPGradient *, gint> *mapUsage if (!doc) return; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); - bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); - bool ingroups = TRUE; - - GSList *all_list = get_all_doc_items(NULL, doc->getRoot(), onlyvisible, onlysensitive, ingroups, NULL); + std::vector<SPItem *> all_list; + get_all_doc_items(all_list, doc->getRoot()); - for (GSList *i = all_list; i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + for (auto item:all_list) { if (!item->getId()) continue; SPGradient *gr = NULL; @@ -565,34 +549,29 @@ static void update_stop_list( GtkWidget *vb, SPGradient *gradient, SPStop *new_s GtkTreeIter iter; /* Populate the combobox store */ - GSList *sl = NULL; + std::vector<SPStop *> sl; if ( gradient->hasStops() ) { for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { - sl = g_slist_append(sl, &ochild); + sl.push_back(SP_STOP(&ochild)); } } } - if (!sl) { + if (sl.empty()) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, NULL, 1, _("No stops in gradient"), 2, NULL, -1); gtk_widget_set_sensitive (combo_box, FALSE); } else { - for (; sl != NULL; sl = sl->next){ - if (SP_IS_STOP(sl->data)){ - SPStop *stop = SP_STOP(sl->data); - Inkscape::XML::Node *repr = reinterpret_cast<SPItem *>(sl->data)->getRepr(); - Inkscape::UI::Widget::ColorPreview *cpv = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(stop->get_rgba32())); - GdkPixbuf *pb = cpv->toPixbuf(64, 16); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, pb, 1, repr->attribute("id"), 2, stop, -1); - gtk_widget_set_sensitive (combo_box, FALSE); - } + for (auto stop:sl) { + Inkscape::XML::Node *repr = stop->getRepr(); + Inkscape::UI::Widget::ColorPreview *cpv = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(stop->get_rgba32())); + GdkPixbuf *pb = cpv->toPixbuf(64, 16); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, pb, 1, repr->attribute("id"), 2, stop, -1); + gtk_widget_set_sensitive (combo_box, FALSE); } - gtk_widget_set_sensitive(combo_box, TRUE); } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 27fe4b63a..4457b712d 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -23,6 +23,7 @@ #include <cstring> #include <string> +#include <vector> #include "widgets/swatch-selector.h" #include "sp-pattern.h" @@ -789,25 +790,23 @@ static void sp_psel_mesh_change(GtkWidget * /*widget*/, SPPaintSelector *psel) /** - * Returns a list of meshes in the defs of the given source document as a GSList object - * Returns NULL if there are no meshes in the document. + * Returns a list of meshes in the defs of the given source document as a vector */ -static GSList * +static std::vector<SPMeshGradient *> ink_mesh_list_get (SPDocument *source) { + std::vector<SPMeshGradient *> pl; if (source == NULL) - return NULL; + return pl; + - GSList *pl = NULL; std::vector<SPObject *> meshes = source->getResourceList("gradient"); for (std::vector<SPObject *>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) { if (SP_IS_MESHGRADIENT(*it) && SP_GRADIENT(*it) == SP_GRADIENT(*it)->getArray()) { // only if this is a root mesh - pl = g_slist_prepend(pl, *it); + pl.push_back(SP_MESHGRADIENT(*it)); } } - - pl = g_slist_reverse(pl); return pl; } @@ -815,14 +814,14 @@ ink_mesh_list_get (SPDocument *source) * Adds menu items for mesh list. */ static void -sp_mesh_menu_build (GtkWidget *combo, GSList *mesh_list, SPDocument */*source*/) +sp_mesh_menu_build (GtkWidget *combo, std::vector<SPMeshGradient *> &mesh_list, SPDocument */*source*/) { GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo))); GtkTreeIter iter; - for (; mesh_list != NULL; mesh_list = mesh_list->next) { + for (auto i:mesh_list) { - Inkscape::XML::Node *repr = reinterpret_cast<SPItem *>(mesh_list->data)->getRepr(); + Inkscape::XML::Node *repr = i->getRepr(); gchar const *meshid = repr->attribute("id"); gchar const *label = meshid; @@ -847,21 +846,8 @@ sp_mesh_menu_build (GtkWidget *combo, GSList *mesh_list, SPDocument */*source*/) */ static void sp_mesh_list_from_doc(GtkWidget *combo, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*mesh_doc*/) { - GSList *pl = ink_mesh_list_get(source); - GSList *clean_pl = NULL; - - for (; pl != NULL; pl = pl->next) { - if (!SP_IS_MESHGRADIENT(pl->data)) { - continue; - } - // Add to the list of meshes we really do wish to show - clean_pl = g_slist_prepend (clean_pl, pl->data); - } - - sp_mesh_menu_build (combo, clean_pl, source); - - g_slist_free (pl); - g_slist_free (clean_pl); + std::vector<SPMeshGradient *> pl = ink_mesh_list_get(source); + sp_mesh_menu_build (combo, pl, source); } @@ -1138,24 +1124,22 @@ static void sp_psel_pattern_change(GtkWidget * /*widget*/, SPPaintSelector *psel /** - * Returns a list of patterns in the defs of the given source document as a GSList object - * Returns NULL if there are no patterns in the document. + * Returns a list of patterns in the defs of the given source document as a vector */ -static GSList * +static std::vector<SPPattern*> ink_pattern_list_get (SPDocument *source) { + std::vector<SPPattern *> pl; if (source == NULL) - return NULL; + return pl; - GSList *pl = NULL; std::vector<SPObject *> patterns = source->getResourceList("pattern"); for (std::vector<SPObject *>::const_iterator it = patterns.begin(); it != patterns.end(); ++it) { if (SP_PATTERN(*it) == SP_PATTERN(*it)->rootPattern()) { // only if this is a root pattern - pl = g_slist_prepend(pl, *it); + pl.push_back(SP_PATTERN(*it)); } } - pl = g_slist_reverse(pl); return pl; } @@ -1163,14 +1147,14 @@ ink_pattern_list_get (SPDocument *source) * Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point. */ static void -sp_pattern_menu_build (GtkWidget *combo, GSList *pattern_list, SPDocument */*source*/) +sp_pattern_menu_build (GtkWidget *combo, std::vector<SPPattern *> &pl, SPDocument */*source*/) { GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo))); GtkTreeIter iter; - for (; pattern_list != NULL; pattern_list = pattern_list->next) { + for (auto i=pl.rbegin(); i!=pl.rend(); ++i) { - Inkscape::XML::Node *repr = reinterpret_cast<SPItem *>(pattern_list->data)->getRepr(); + Inkscape::XML::Node *repr = (*i)->getRepr(); // label for combobox gchar const *label; @@ -1200,22 +1184,8 @@ sp_pattern_menu_build (GtkWidget *combo, GSList *pattern_list, SPDocument */*sou */ static void sp_pattern_list_from_doc(GtkWidget *combo, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*pattern_doc*/) { - GSList *pl = ink_pattern_list_get(source); - GSList *clean_pl = NULL; - - for (; pl != NULL; pl = pl->next) { - if (!SP_IS_PATTERN(pl->data)) { - continue; - } - - // Add to the list of patterns we really do wish to show - clean_pl = g_slist_prepend (clean_pl, pl->data); - } - - sp_pattern_menu_build (combo, clean_pl, source); - - g_slist_free (pl); - g_slist_free (clean_pl); + std::vector<SPPattern *> pl = ink_pattern_list_get(source); + sp_pattern_menu_build (combo, pl, source); } |
