示例#1
0
文件: main.c 项目: arievanleyen/xpen
// 2nd part of get keycodes for paste and backspace
extern "C" G_MODULE_EXPORT gboolean on_key_release (GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
    if (key+add > 0) {
        gtk_entry_set_text(GTK_ENTRY(widget), key2string(key, add));
        if (widget == entry1) {
            conf.paste[0] = add;
            conf.paste[1] = key;
        } else {
            conf.backspace[0] = add;
            conf.backspace[1] = key;
        }
        add = key = 0;
        strcpy(toetsen, "");
    }
    return TRUE;
}
示例#2
0
bool PlayerParameters::IsToucheValide(sf::Keyboard::Key key)
{
    return key2string(key)!="";
}
示例#3
0
std::string PlayerParameters::GetStringTouche(const std::string& touche, int index) const
{
    return key2string(GetTouche(touche, index));
}
示例#4
0
// load preferences from file
void load_preferences (char *filepad) {
    char txt[100];
    GString *label = g_string_new_len("", 20);
    int i, p, choice = -1;
    GdkDevice *device, *nodevice;
    GList *list;
    TS keus;

    if (settings == NULL) settings = g_key_file_new();
    if (g_key_file_load_from_file(settings, filepad, G_KEY_FILE_NONE, NULL) == FALSE) {	// set defaults
        gchar *data;
        gsize len;

		// default settings when xpen.cfg not found
		g_key_file_set_integer (settings, "display", "x", -1);
		g_key_file_set_integer (settings, "display", "y", -1);
		g_key_file_set_integer (settings, "display", "lx", -1);
		g_key_file_set_integer (settings, "display", "ly", -1);
		g_key_file_set_integer (settings, "display", "dx", 300);
		g_key_file_set_integer (settings, "display", "dy", 400);
        g_key_file_set_double (settings, "display", "opacity", 0.7);
        g_key_file_set_string (settings, "display", "font", gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontbutton)));
        g_key_file_set_boolean (settings, "display", "tooltips", TRUE);
        g_key_file_set_string (settings, "reader", "device", "stylus");
        g_key_file_set_integer (settings, "reader", "speed", 6);
        g_key_file_set_uint64 (settings, "reader", "lijnkleur", 0x514942);
        g_key_file_set_uint64 (settings, "reader", "rasterkleur", 0xAB8C6D);
        g_key_file_set_boolean (settings, "reader", "raster", TRUE);
        g_key_file_set_boolean (settings, "reader", "speech", FALSE);
        g_key_file_set_string (settings, "reader", "command", "aplay -q");
        g_key_file_set_integer (settings, "reader", "voice", 0);
        g_key_file_set_integer (settings, "keys", "paste0", 37);
        g_key_file_set_integer (settings, "keys", "paste1", 55);
        g_key_file_set_integer (settings, "keys", "backspace0", 0);
        g_key_file_set_integer (settings, "keys", "backspace1", 22);

        g_key_file_set_integer (settings, "GB1", "key", 0);
        g_key_file_set_integer (settings, "GB1", "mode", 0);
        g_key_file_set_integer (settings, "BIG5", "key", CTRL_R);
        g_key_file_set_integer (settings, "BIG5", "mode", BIG5);
        g_key_file_set_integer (settings, "DIGITS", "key", ALT_L);
        g_key_file_set_integer (settings, "DIGITS", "mode", DIGITS);
        g_key_file_set_integer (settings, "LOWERCASE", "key", ALT_L);
        g_key_file_set_integer (settings, "LOWERCASE", "mode", LOWERCASE);
        g_key_file_set_integer (settings, "UPPERCASE", "key", 0);
        g_key_file_set_integer (settings, "UPPERCASE", "mode", 0);
        g_key_file_set_integer (settings, "PUNC", "key", 0);
        g_key_file_set_integer (settings, "PUNC", "mode", 0);
        g_key_file_set_integer (settings, "DEFAULT", "key", ESC);
        g_key_file_set_integer (settings, "DEFAULT", "mode", (GB1|GB2|DIGITS));

		g_key_file_set_string (settings, "keydefs", "label1", "Control-Left");
		g_key_file_set_integer (settings, "keydefs", "key1", CTRL_L);
		g_key_file_set_string (settings, "keydefs", "label2", "Control-Right");
		g_key_file_set_integer (settings, "keydefs", "key2", CTRL_R);
		g_key_file_set_string (settings, "keydefs", "label3", "Shift-Left");
		g_key_file_set_integer (settings, "keydefs", "key3", SHIFT_L);
		g_key_file_set_string (settings, "keydefs", "label4", "Shift-Right");
		g_key_file_set_integer (settings, "keydefs", "key4", SHIFT_R);
		g_key_file_set_string (settings, "keydefs", "label5", "Alt-Left");
		g_key_file_set_integer (settings, "keydefs", "key5", ALT_L);
		g_key_file_set_string (settings, "keydefs", "label6", "Alt-Right");
		g_key_file_set_integer (settings, "keydefs", "key6", ALT_R);
		g_key_file_set_string (settings, "keydefs", "label7", "Escape");
		g_key_file_set_integer (settings, "keydefs", "key7", ESC);
		g_key_file_set_string (settings, "keydefs", "label8", "Caps-Lock");
		g_key_file_set_integer (settings, "keydefs", "key8", CAPS);
		g_key_file_set_string (settings, "keydefs", "label9", "Num-Lock");
		g_key_file_set_integer (settings, "keydefs", "key9", NUMS);
		g_key_file_set_string (settings, "keydefs", "label10", "Scroll-Lock");
		g_key_file_set_integer (settings, "keydefs", "key10", SCROLLS);
		g_key_file_set_string (settings, "keydefs", "label11", "Pause/Break");
		g_key_file_set_integer (settings, "keydefs", "key11", PAUSE);
		g_key_file_set_string (settings, "keydefs", "label12", "not set");
		g_key_file_set_integer (settings, "keydefs", "key12", 0);
		g_key_file_set_string (settings, "keydefs", "label13", "not set");
		g_key_file_set_integer (settings, "keydefs", "key13", 0);

        data = g_key_file_to_data (settings, &len, NULL);	// save defaults
        g_file_set_contents (filepad, data, len, NULL);
        g_free(data);
    }
    // fill the preferences structure
    conf.x 				= g_key_file_get_integer (settings, "display", "x", NULL);
    conf.y 				= g_key_file_get_integer (settings, "display", "y", NULL);
    conf.lx 			= g_key_file_get_integer (settings, "display", "lx", NULL);
    conf.ly 			= g_key_file_get_integer (settings, "display", "ly", NULL);
    conf.dx 			= g_key_file_get_integer (settings, "display", "dx", NULL);
    conf.dy 			= g_key_file_get_integer (settings, "display", "dy", NULL);
    conf.opacity 		= g_key_file_get_double (settings, "display", "opacity", NULL);
    conf.tips			= g_key_file_get_boolean (settings, "display", "tooltips", NULL);
    conf.font 			= g_key_file_get_string (settings, "display", "font", NULL);
    conf.device 		= g_key_file_get_string (settings, "reader", "device", NULL);
    conf.speed 			= g_key_file_get_integer (settings, "reader", "speed", NULL);
    conf.lijnkleur		= g_key_file_get_uint64 (settings, "reader", "lijnkleur", NULL);
    conf.rasterkleur	= g_key_file_get_uint64 (settings, "reader", "rasterkleur", NULL);
    conf.raster 		= g_key_file_get_boolean (settings, "reader", "raster", NULL);
	conf.speech 		= g_key_file_get_boolean (settings, "reader", "speech", NULL);
	conf.voice	 		= g_key_file_get_integer (settings, "reader", "voice", NULL);
    conf.paste[0] 		= g_key_file_get_integer (settings, "keys", "paste0", NULL);
    conf.paste[1] 		= g_key_file_get_integer (settings, "keys", "paste1", NULL);
    conf.backspace[0]	= g_key_file_get_integer (settings, "keys", "backspace0", NULL);
    conf.backspace[1]	= g_key_file_get_integer (settings, "keys", "backspace1", NULL);
    conf.keymode[0].key	= g_key_file_get_integer (settings, "GB1", "key", NULL);
	conf.keymode[0].mode	= g_key_file_get_integer (settings, "GB1", "mode", NULL);
    conf.keymode[1].key	= g_key_file_get_integer (settings, "BIG5", "key", NULL);
	conf.keymode[1].mode	= g_key_file_get_integer (settings, "BIG5", "mode", NULL);
	conf.keymode[2].key	= g_key_file_get_integer (settings, "DIGITS", "key", NULL);
	conf.keymode[2].mode	= g_key_file_get_integer (settings, "DIGITS", "mode", NULL);
    conf.keymode[3].key	= g_key_file_get_integer (settings, "LOWERCASE", "key", NULL);
	conf.keymode[3].mode	= g_key_file_get_integer (settings, "LOWERCASE", "mode", NULL);
    conf.keymode[4].key	= g_key_file_get_integer (settings, "UPPERCASE", "key", NULL);
	conf.keymode[4].mode	= g_key_file_get_integer (settings, "UPPERCASE", "mode", NULL);
    conf.keymode[5].key	= g_key_file_get_integer (settings, "PUNC", "key", NULL);
	conf.keymode[5].mode	= g_key_file_get_integer (settings, "PUNC", "mode", NULL);
    conf.keymode[6].key	= g_key_file_get_integer (settings, "DEFAULT", "key", NULL);
	conf.keymode[6].mode	= g_key_file_get_integer (settings, "DEFAULT", "mode", NULL);

	// set speech + command
	GTK_TOGGLE_BUTTON(checkbutton9)->active = conf.speech;

	gtk_combo_box_set_active(GTK_COMBO_BOX(combobox1), conf.voice);

	for (i=0; i<13; i++) {
		g_string_sprintf(label, "key%d", i+1);
		conf.defkey[i].key = g_key_file_get_integer (settings, "keydefs", label->str, NULL);
		g_string_sprintf(label, "label%d", i+1);
		conf.defkey[i].label = g_key_file_get_string (settings, "keydefs", label->str, NULL);
	}

	// start setting all widgets with the values from the configuration (conf)

	// set tooltips
    GTK_TOGGLE_BUTTON(checkbutton8)->active = conf.tips;

	// set the 13 buttons/entries in preferences
	for (i=0; i<13; i++) {
		if (conf.defkey[i].key > 0) {
			g_string_sprintf(label, "key = %d", conf.defkey[i].key);
			gtk_button_set_label(GTK_BUTTON(conf.defkey[i].button), label->str);
			gtk_entry_set_text(GTK_ENTRY(conf.defkey[i].entry), conf.defkey[i].label);
		} else {
			gtk_button_set_label(GTK_BUTTON(conf.defkey[i].button), "not set");
			gtk_entry_set_text(GTK_ENTRY(conf.defkey[i].entry), "");
		}
	}
	g_string_free(label, TRUE);

	// set the default recognition mode
	mode = conf.keymode[6].mode;
	keus = (mode & BIG5) ? Traditional : Simplified;
	selecteer(keus);

	// set the labels of the hotkeys (preferences)
	for (i=0; i<7; i++) {
		bool found;

		hotkey[conf.keymode[i].key] |= conf.keymode[i].mode;		// set the hotkeys
		found = FALSE;
		for (p=0; p<13; p++) {
			if (conf.defkey[p].key > 0) {
				if (conf.keymode[i].key == conf.defkey[p].key) {
					strcpy(txt, conf.defkey[p].label);
					found = TRUE;
					break;
				}
			}
		}
		if (found == FALSE) {
			if (conf.keymode[i].key > 0)
				sprintf(txt, "key = %d", conf.keymode[i].key);
			else
				strcpy(txt, "not set");
		}
		gtk_button_set_label(GTK_BUTTON(modebits[i].button), txt);

		// set the default checkboxes (preferences)
		if (conf.keymode[6].mode & GB1)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[0].check), TRUE);
		if (conf.keymode[6].mode & BIG5)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[1].check), TRUE);
		if (conf.keymode[6].mode & DIGITS)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[2].check), TRUE);
		if (conf.keymode[6].mode & LOWERCASE)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[3].check), TRUE);
		if (conf.keymode[6].mode & UPPERCASE)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[4].check), TRUE);
		if (conf.keymode[6].mode & PUNC)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(modebits[5].check), TRUE);
	}

    // fill combobox with input-devices
    list = gdk_devices_list();
    device = (GdkDevice *) list->data;	// default device
    nodevice = NULL;
    for (p=0; list->next; p++) {
        strcpy(txt, gdk_device_get_name((GdkDevice *)list->data));
        gtk_combo_box_append_text(GTK_COMBO_BOX(combo), txt);
        if (strstr(txt, conf.device)) {
            device = (GdkDevice *) list->data;
            choice = p;
        }
        nodevice = (GdkDevice *) list->data;
        list = list->next;
    }
    if (choice == -1) {		// prefered device not found
		choice = p-1;
		device = nodevice;
    }

    //g_list_free(list);
    gtk_combo_box_set_active(GTK_COMBO_BOX(combo), choice);
    gdk_device_set_source (device, GDK_SOURCE_PEN);
    gdk_device_set_mode(device, GDK_MODE_SCREEN);

    // set line color
    lijnkleur.pixel = conf.lijnkleur;
    sprintf(txt, "#%.6X", lijnkleur.pixel);
    gdk_color_parse(txt, &lijnkleur);
    gtk_color_button_set_color(GTK_COLOR_BUTTON(colorbutton1),  &lijnkleur);

    // set raster color
    rasterkleur.pixel = conf.rasterkleur;
    sprintf(txt, "#%.6X", rasterkleur.pixel);
    gdk_color_parse(txt, &rasterkleur);
    gtk_color_button_set_color(GTK_COLOR_BUTTON(colorbutton2),  &rasterkleur);

    // set raster on/off check button
    GTK_TOGGLE_BUTTON(checkbutton1)->active = conf.raster;

    // set main window opacity slider
    gtk_adjustment_set_value(opacity, conf.opacity);

    // set the 9 candidate buttons with a default font
    for (i=0; i< 9; i++) {
		PangoFontDescription *pfont;
    	pfont = pango_font_description_from_string(conf.font);
        gtk_widget_modify_font (GTK_WIDGET(knop[i]), pfont );
        pango_font_description_free(pfont);
    }

    // set the font selection button with the font title
    gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), conf.font);

    // set the recognize speed slider
    gtk_adjustment_set_value(speed, conf.speed);
    WTSetSpeed(conf.speed);

    // set the default paste and backspace entry fields
    gtk_entry_set_text(GTK_ENTRY(entry1), key2string(conf.paste[1], conf.paste[0]));
    gtk_entry_set_text(GTK_ENTRY(entry2), key2string(conf.backspace[1], conf.backspace[0]));
}