Ejemplo n.º 1
0
static char *voff_ac_cmd(void * arg)
{
    double *argp;
    int rv;
    
    argp = (double *)(arg);
    rv = set_vert_offset(*argp, 1);
    if ( rv < 0 ) {
	return "could not set vertical offset";
    }
    return NULL;
}    
Ejemplo n.º 2
0
static gboolean dialog_set_offset(int chan_num)
{
    scope_vert_t *vert;
    scope_chan_t *chan;
    dialog_generic_t dialog;
    gchar *title, msg[BUFLEN], *cptr;
    struct offset_data data;
    GtkWidget *label, *button;
    double tmp;

    vert = &(ctrl_usr->vert);
    chan = &(ctrl_usr->chan[chan_num - 1]);
    title = _("Set Offset");
    snprintf(msg, BUFLEN - 1, _("Set the vertical offset\n"
	"for channel %d."), chan_num);
    /* create dialog window, disable resizing */
    dialog.retval = 0;
    dialog.window = gtk_dialog_new();
    dialog.app_data = &data;
    /* allow user to grow but not shrink the window */
    gtk_window_set_policy(GTK_WINDOW(dialog.window), FALSE, TRUE, FALSE);
    /* window should appear in center of screen */
    gtk_window_set_position(GTK_WINDOW(dialog.window), GTK_WIN_POS_CENTER);
    /* set title */
    gtk_window_set_title(GTK_WINDOW(dialog.window), title);
    /* display message */
    label = gtk_label_new(msg);
    gtk_misc_set_padding(GTK_MISC(label), 15, 5);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox), label, FALSE,
	TRUE, 0);
    /* a separator */
    gtk_hseparator_new_in_box(GTK_DIALOG(dialog.window)->vbox, 0);
    /* a checkbox: AC coupled */
    vert->offset_ac = gtk_check_button_new_with_label(_("AC Coupled"));
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox),
        vert->offset_ac, FALSE, TRUE, 0);
    /* react to changes to the checkbox */
    gtk_signal_connect(GTK_OBJECT(vert->offset_ac), "toggled",
	GTK_SIGNAL_FUNC(offset_changed), &data);
    /* the entry */
    vert->offset_entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox),
	vert->offset_entry, FALSE, TRUE, 0);
    snprintf(data.buf, BUFLEN, "%f", chan->vert_offset);
    gtk_entry_set_text(GTK_ENTRY(vert->offset_entry), data.buf);
    gtk_entry_set_max_length(GTK_ENTRY(vert->offset_entry), BUFLEN-1);
    /* point at first char */
    gtk_entry_set_position(GTK_ENTRY(vert->offset_entry), 0);
    /* select all chars, so if the user types the original value goes away */
    gtk_entry_select_region(GTK_ENTRY(vert->offset_entry), 0, strlen(data.buf));
    /* make it active so user doesn't have to click on it */
    gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry));
    gtk_widget_show(vert->offset_entry);
    /* capture entry data to the buffer whenever the user types */
    gtk_signal_connect(GTK_OBJECT(vert->offset_entry), "changed",
	GTK_SIGNAL_FUNC(offset_changed), data.buf);
    /* set up a callback function when the window is destroyed */
    gtk_signal_connect(GTK_OBJECT(dialog.window), "destroy",
	GTK_SIGNAL_FUNC(dialog_generic_destroyed), &dialog);
    /* make OK and Cancel buttons */
    button = gtk_button_new_with_label(_("OK"));
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->action_area),
	button, TRUE, TRUE, 4);
    gtk_signal_connect(GTK_OBJECT(button), "clicked",
	GTK_SIGNAL_FUNC(dialog_generic_button1), &dialog);
    /* hit the "OK" button if the user hits enter */
    gtk_signal_connect(GTK_OBJECT(vert->offset_entry), "activate",
	GTK_SIGNAL_FUNC(offset_activated), button);
    button = gtk_button_new_with_label(_("Cancel"));
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->action_area),
	button, TRUE, TRUE, 4);
    gtk_signal_connect(GTK_OBJECT(button), "clicked",
	GTK_SIGNAL_FUNC(dialog_generic_button2), &dialog);
    /* make window transient and modal */
    gtk_window_set_transient_for(GTK_WINDOW(dialog.window),
	GTK_WINDOW(ctrl_usr->main_win));
    gtk_window_set_modal(GTK_WINDOW(dialog.window), TRUE);
    gtk_widget_show_all(dialog.window);
    gtk_main();
    /* we get here when the user makes a selection, hits Cancel, or closes
       the window */
    if ((dialog.retval == 0) || (dialog.retval == 2)) {
	/* user either closed dialog, or hit cancel */
	return FALSE;
    }
    tmp = strtod(data.buf, &cptr);
    if (cptr == data.buf) {
	return FALSE;
    }
    set_vert_offset(tmp, data.ac_coupled);
    return TRUE;
}