1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2019 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_linetypecb.c
22 * \brief A GtkComboBox for gschem line types.
39 /*! \brief The columns in the GtkListStore
50 /*! \brief Stores the list of fill styles for use in GtkComboBox
52 static GtkListStore
* line_type_list_store
= NULL
;
56 static GtkListStore
* create_line_type_list_store();
60 /*! \brief Create the GtkListStore for fill styles.
63 create_line_type_list_store ()
68 store
= gtk_list_store_new (COLUMN_COUNT
,
72 gtk_list_store_append (store
, &iter
);
73 gtk_list_store_set (store
, &iter
,
74 COLUMN_NAME
, pgettext ("line-type", "Solid"),
75 COLUMN_INDEX
, TYPE_SOLID
,
79 gtk_list_store_append (store
, &iter
);
80 gtk_list_store_set (store
, &iter
,
81 COLUMN_NAME
, pgettext ("line-type", "Dotted"),
82 COLUMN_INDEX
, TYPE_DOTTED
,
86 gtk_list_store_append (store
, &iter
);
87 gtk_list_store_set (store
, &iter
,
88 COLUMN_NAME
, pgettext ("line-type", "Dashed"),
89 COLUMN_INDEX
, TYPE_DASHED
,
93 gtk_list_store_append (store
, &iter
);
94 gtk_list_store_set (store
, &iter
,
95 COLUMN_NAME
, pgettext ("line-type", "Center"),
96 COLUMN_INDEX
, TYPE_CENTER
,
100 gtk_list_store_append (store
, &iter
);
101 gtk_list_store_set (store
, &iter
,
102 COLUMN_NAME
, pgettext ("line-type", "Phantom"),
103 COLUMN_INDEX
, TYPE_PHANTOM
,
112 /*! \brief Create a ComboBox with the gschem line types.
120 GtkCellLayout
*layout
;
121 GtkCellRenderer
*text_cell
;
123 if (line_type_list_store
== NULL
) {
124 line_type_list_store
= create_line_type_list_store ();
127 combo
= GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (line_type_list_store
)));
128 layout
= GTK_CELL_LAYOUT (combo
); /* For convenience */
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 line type index
143 * \param [in,out] widget The line type combo box
144 * \return The currently selected line type index
147 x_linetypecb_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 (line_type_list_store
), &iter
, COLUMN_INDEX
, &value
);
155 index
= g_value_get_int (&value
);
156 g_value_unset (&value
);
164 /*! \brief Select the given line type index
166 * \param [in,out] widget The line type combo box
167 * \param [in] style The line type index to select
170 x_linetypecb_set_index (GtkWidget
*widget
, int index
)
172 GtkTreeIter
*active
= NULL
;
175 g_return_if_fail (widget
!= NULL
);
176 g_return_if_fail (line_type_list_store
!= NULL
);
182 success
= gtk_tree_model_get_iter_first (GTK_TREE_MODEL (line_type_list_store
), &iter
);
184 gtk_tree_model_get_value (GTK_TREE_MODEL (line_type_list_store
), &iter
, COLUMN_INDEX
, &value
);
185 if (g_value_get_int (&value
) == index
) {
186 g_value_unset (&value
);
190 g_value_unset (&value
);
191 success
= gtk_tree_model_iter_next (GTK_TREE_MODEL(line_type_list_store
), &iter
);
195 gtk_combo_box_set_active_iter (GTK_COMBO_BOX(widget
), active
);