1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /*! \file x_fstylecb.c
22 * \brief A GtkComboBox for gschem fill styles.
38 /*! \brief The columns in the GtkListStore
49 /*! \brief Stores the list of fill styles for use in GtkComboBox
51 static GtkListStore
* fstyle_list_store
= NULL
;
55 static GtkListStore
* create_fstyle_list_store();
59 /*! \brief Create the GtkListStore for fill styles.
62 create_fstyle_list_store ()
67 store
= gtk_list_store_new (COLUMN_COUNT
,
71 gtk_list_store_append (store
, &iter
);
72 gtk_list_store_set (store
, &iter
,
73 COLUMN_NAME
, pgettext ("fill-type", "Hollow"),
74 COLUMN_INDEX
, FILLING_HOLLOW
,
78 gtk_list_store_append (store
, &iter
);
79 gtk_list_store_set (store
, &iter
,
80 COLUMN_NAME
, pgettext ("fill-type", "Filled"),
81 COLUMN_INDEX
, FILLING_FILL
,
85 gtk_list_store_append (store
, &iter
);
86 gtk_list_store_set (store
, &iter
,
87 COLUMN_NAME
, pgettext ("fill-type", "Mesh"),
88 COLUMN_INDEX
, FILLING_MESH
,
92 gtk_list_store_append (store
, &iter
);
93 gtk_list_store_set (store
, &iter
,
94 COLUMN_NAME
, pgettext ("fill-type", "Hatch"),
95 COLUMN_INDEX
, FILLING_HATCH
,
104 /*! \brief Create a ComboBox with the gschem fill styles.
112 GtkCellLayout
*layout
;
113 GtkCellRenderer
*swatch_cell
;
114 GtkCellRenderer
*text_cell
;
116 if (fstyle_list_store
== NULL
) {
117 fstyle_list_store
= create_fstyle_list_store ();
120 combo
= GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (fstyle_list_store
)));
121 layout
= GTK_CELL_LAYOUT (combo
); /* For convenience */
123 /* Renders the fill swatch. Since this won't contain text, set a
125 swatch_cell
= GTK_CELL_RENDERER (gschem_fill_swatch_cell_renderer_new ());
126 g_object_set (swatch_cell
, "width", 25, NULL
);
127 gtk_cell_layout_pack_start (layout
, swatch_cell
, FALSE
);
128 gtk_cell_layout_add_attribute (layout
, swatch_cell
, "fill-type", COLUMN_INDEX
);
130 /* Renders the name of the fill style */
131 text_cell
= GTK_CELL_RENDERER (gtk_cell_renderer_text_new());
132 g_object_set (text_cell
, "xpad", 5, NULL
);
133 gtk_cell_layout_pack_start (layout
, text_cell
, TRUE
);
134 gtk_cell_layout_add_attribute (layout
, text_cell
, "text", COLUMN_NAME
);
136 return GTK_WIDGET (combo
);
141 /*! \brief Get the currently selected fill style index
143 * \param [in,out] widget The fill style combo box
144 * \return The currently selected fill style index
147 x_fstylecb_get_index (GtkWidget
*widget
)
153 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget
), &iter
)) {
154 gtk_tree_model_get_value (GTK_TREE_MODEL (fstyle_list_store
), &iter
, COLUMN_INDEX
, &value
);
155 index
= g_value_get_int (&value
);
156 g_value_unset (&value
);
164 /*! \brief Select the given fill style index
166 * \param [in,out] widget The fill style combo box
167 * \param [in] style The fill style index to select
170 x_fstylecb_set_index (GtkWidget
*widget
, int style
)
172 GtkTreeIter
*active
= NULL
;
175 g_return_if_fail (fstyle_list_store
!= NULL
);
181 success
= gtk_tree_model_get_iter_first (GTK_TREE_MODEL (fstyle_list_store
), &iter
);
183 gtk_tree_model_get_value (GTK_TREE_MODEL (fstyle_list_store
), &iter
, COLUMN_INDEX
, &value
);
184 if (g_value_get_int (&value
) == style
) {
185 g_value_unset (&value
);
189 g_value_unset (&value
);
190 success
= gtk_tree_model_iter_next (GTK_TREE_MODEL(fstyle_list_store
), &iter
);
194 gtk_combo_box_set_active_iter (GTK_COMBO_BOX(widget
), active
);