00001
00025 #include "select_exceptions.h"
00026
00027
00028 static SelectionButtonSet selection_buttons[MAX_ROWS * MAX_COLUMNS];
00029
00030
00031 GtkWidget *select_exceptions_window = NULL;
00032
00033
00042 static void
00043 select_exceptions_clear_cb
00044 (
00045 GtkWidget *widget,
00047 GtkWidget *window
00049 )
00050 {
00051 gint i;
00052 gint j;
00053 SelectionButtonSet *selection_button;
00054 gint selection_button_index = 0;
00055 for (i = 0; (i < MAX_ROWS); i++)
00056 {
00057 for (j = 0; (j < MAX_COLUMNS); j++)
00058 {
00059 selection_button = &selection_buttons[selection_button_index];
00060 selection_button->active = FALSE;
00061 selection_button_index++;
00062 }
00063 }
00064 pin_pad_exceptions_string = g_strdup ("");
00065
00066 selection_button_index = 0;
00067 for (i = 0; (i < number_of_rows); i++)
00068 {
00069 for (j = 0; (j < number_of_columns); j++)
00070
00071
00072
00073 {
00074 selection_button = &selection_buttons[selection_button_index];
00075 selection_button->active = FALSE;
00076 gtk_toggle_button_set_active
00077 (GTK_TOGGLE_BUTTON (selection_button->button_widget),
00078 FALSE);
00079 selection_button_index++;
00080 }
00081 }
00082 }
00083
00084
00093 static void
00094 select_exceptions_close_cb
00095 (
00096 GtkWidget *widget,
00098 GtkWidget *window
00100 )
00101 {
00102 gtk_widget_destroy (window);
00103 select_exceptions_window = NULL;
00104 }
00105
00106
00115 static void
00116 select_exceptions_delete_event
00117 (
00118 GtkWidget *widget,
00120 GdkEvent *event
00122 )
00123 {
00124 gtk_widget_destroy (widget);
00125 select_exceptions_window = NULL;
00126 }
00127
00128
00140 static void
00141 select_exceptions_ok_cb
00142 (
00143 GtkWidget *widget,
00145 GtkWidget *window
00147 )
00148 {
00149
00150
00151 gint i;
00152 gint j;
00153 SelectionButtonSet *selection_button;
00154 gint selection_button_index = 0;
00155 gchar *exceptions = g_strdup ("");
00156 number_of_exceptions = 0;
00157
00158 for (i = 0; (i < number_of_rows); i++)
00159
00160
00161
00162 {
00163 for (j = 0; (j < number_of_columns); j++)
00164
00165
00166
00167 {
00168 gchar *selection_button_name = g_strdup_printf ("%s%d",
00169 (row_letters[i]), (j + 1));
00170 selection_button = &selection_buttons[selection_button_index];
00171 if (selection_button->active)
00172 {
00173 exceptions = g_strconcat (exceptions,
00174 selection_button->name, ",", NULL);
00175 number_of_exceptions++;
00176 }
00177 selection_button_index++;
00178 g_free (selection_button_name);
00179 }
00180 }
00181 pin_pad_exceptions_string = g_strdup_printf ("%s", exceptions);
00182 if (verbose)
00183 {
00184 g_log ("", G_LOG_LEVEL_INFO,
00185 (_("found a total of %d exceptions for pins/pads.")),
00186 number_of_exceptions);
00187 g_log ("", G_LOG_LEVEL_INFO,
00188 (_("found the following exceptions for pins/pads: %s.")),
00189 pin_pad_exceptions_string);
00190 }
00191 g_free (exceptions);
00192
00193 gtk_widget_destroy (select_exceptions_window);
00194 select_exceptions_window = NULL;
00195 }
00196
00197
00207 static void
00208 select_exceptions_selection_button_clicked_cb
00209 (
00210 GtkWidget *widget,
00212 GtkWidget *window
00214 )
00215 {
00216 const gchar *widget_name;
00217 SelectionButtonSet *selection_button;
00218 gint selection_button_index = -1;
00219 widget_name = gtk_widget_get_name (widget);
00220 do
00221 {
00222 selection_button_index++;
00223 selection_button = &selection_buttons[selection_button_index];
00224 } while (strcmp (widget_name, selection_button->name));
00225 selection_button->active = gtk_toggle_button_get_active
00226 (GTK_TOGGLE_BUTTON (widget));
00227 }
00228
00229
00242 int
00243 select_exceptions_create_window
00244 (
00245 gint number_of_rows,
00247 gint number_of_columns
00249 )
00250 {
00251
00252 if (select_exceptions_window)
00253 {
00254 return (EXIT_FAILURE);
00255 }
00256
00257 select_exceptions_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00258
00259
00260 gtk_window_set_destroy_with_parent (GTK_WINDOW (select_exceptions_window), TRUE);
00261
00262 gchar *window_title = g_strdup ("select exceptions");
00263 gtk_window_set_title (GTK_WINDOW (select_exceptions_window), window_title);
00264 g_free (window_title);
00265 gtk_container_set_border_width (GTK_CONTAINER (select_exceptions_window), 10);
00266
00267 g_signal_connect
00268 (
00269 GTK_OBJECT (select_exceptions_window),
00270 "delete_event",
00271 (GtkSignalFunc) select_exceptions_delete_event,
00272 NULL
00273 );
00274
00275
00276 GtkWidget *vbox = gtk_vbox_new (FALSE, 10);
00277 gtk_container_add (GTK_CONTAINER (select_exceptions_window),
00278 GTK_WIDGET (vbox));
00279
00280
00281 GtkWidget *table = gtk_table_new ((number_of_rows + 1),
00282 (number_of_columns + 1), TRUE);
00283 gtk_table_set_col_spacings (GTK_TABLE (table), 2);
00284 gtk_table_set_row_spacings (GTK_TABLE (table), 2);
00285
00286 gint i;
00287 gint j;
00288 SelectionButtonSet *selection_button;
00289 gint selection_button_index = 0;
00290
00291 for (j = 1; (j < (number_of_columns + 1)); j++)
00292 {
00293 GtkWidget *column_label = gtk_label_new (g_strdup_printf ("%d", j));
00294 gtk_label_set_justify (GTK_LABEL (column_label), GTK_JUSTIFY_CENTER);
00295 gtk_table_attach_defaults (GTK_TABLE (table), column_label,
00296 j, (j + 1),
00297 0, 1);
00298 }
00299
00300
00301 for (i = 0; (i < number_of_rows); i++)
00302
00303
00304
00305 {
00306
00307
00308 GtkWidget *row_label = gtk_label_new (g_strdup_printf ("%s",
00309 (row_letters[i])));
00310 gtk_table_attach_defaults (GTK_TABLE (table), row_label,
00311 0, 1,
00312 (i + 1), (i + 2));
00313 for (j = 0; (j < number_of_columns); j++)
00314
00315
00316 {
00317 selection_button = &selection_buttons[selection_button_index];
00318 selection_button->button_widget =
00319 gtk_check_button_new ();
00320 gtk_widget_show (selection_button->button_widget);
00321 selection_button->id = selection_button_index;
00322 gchar *selection_button_name = g_strdup_printf ("%s%d",
00323 (row_letters[i]), (j + 1));
00324 selection_button->name = g_strdup (selection_button_name);
00325 gtk_widget_set_name (selection_button->button_widget,
00326 selection_button_name);
00327 gtk_table_attach_defaults (GTK_TABLE (table),
00328 selection_button->button_widget,
00329 (j + 1), (j + 2), (i + 1), (i + 2));
00330 selection_button->active = !get_pin_pad_exception
00331 (selection_button_name);
00332 if (get_pin_pad_exception (selection_button_name) == EXIT_SUCCESS)
00333 {
00334 gtk_toggle_button_set_active
00335 (GTK_TOGGLE_BUTTON (selection_button->button_widget),
00336 TRUE);
00337 }
00338 else
00339 {
00340 gtk_toggle_button_set_active
00341 (GTK_TOGGLE_BUTTON (selection_button->button_widget),
00342 FALSE);
00343 }
00344
00345
00346
00347
00348
00349 g_signal_connect
00350 (
00351 G_OBJECT (selection_button->button_widget),
00352 "clicked",
00353 G_CALLBACK (select_exceptions_selection_button_clicked_cb),
00354 select_exceptions_window
00355 );
00356 selection_button_index++;
00357 g_free (selection_button_name);
00358 }
00359 }
00360
00361 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
00362
00363 GtkWidget *hbox = gtk_hbutton_box_new ();
00364 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
00365 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
00366
00367 GtkWidget *close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
00368 g_signal_connect
00369 (
00370 G_OBJECT (close_button),
00371 "clicked",
00372 G_CALLBACK (select_exceptions_close_cb),
00373 select_exceptions_window
00374 );
00375
00376 gtk_box_pack_start (GTK_BOX (hbox), close_button, TRUE, TRUE, 0);
00377
00378 GtkWidget *clear_button = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
00379 g_signal_connect
00380 (
00381 G_OBJECT (clear_button),
00382 "clicked",
00383 G_CALLBACK (select_exceptions_clear_cb),
00384 select_exceptions_window
00385 );
00386
00387 gtk_box_pack_start (GTK_BOX (hbox), clear_button, TRUE, TRUE, 0);
00388
00389 GtkWidget *ok_button = gtk_button_new_from_stock (GTK_STOCK_OK);
00390 g_signal_connect
00391 (
00392 G_OBJECT (ok_button),
00393 "clicked",
00394 G_CALLBACK (select_exceptions_ok_cb),
00395 select_exceptions_window
00396 );
00397
00398 gtk_box_pack_start (GTK_BOX (hbox), ok_button, TRUE, TRUE, 0);
00399
00400 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00401 gtk_window_set_resizable (GTK_WINDOW (select_exceptions_window), FALSE);
00402
00403 gtk_widget_realize (select_exceptions_window);
00404 gtk_widget_show_all (select_exceptions_window);
00405
00406 gtk_main ();
00407 return (EXIT_SUCCESS);
00408 }
00409
00410
00411