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