--- np2/x11/gtk2/dialog_midi.c 2004/07/15 14:24:33 1.1 +++ np2/x11/gtk2/dialog_midi.c 2010/12/23 06:32:35 1.5 @@ -1,4 +1,4 @@ -/* $Id: dialog_midi.c,v 1.1 2004/07/15 14:24:33 monaka Exp $ */ +/* $Id: dialog_midi.c,v 1.5 2010/12/23 06:32:35 monaka Exp $ */ /* * Copyright (c) 2003 NONAKA Kimihiro @@ -12,8 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -83,7 +81,8 @@ static BYTE mpuopt; static void ok_button_clicked(GtkButton *b, gpointer d) { - const gchar *p; + const gchar *utf8; + gchar *p; BOOL enable; UINT update; int i; @@ -94,30 +93,42 @@ ok_button_clicked(GtkButton *b, gpointer if (np2cfg.mpuopt != mpuopt) { update |= SYS_UPDATECFG | SYS_UPDATEMIDI; } - p = gtk_entry_get_text(GTK_ENTRY(mpu98_midiout_entry)); - if (p != NULL) { - if (milstr_cmp(np2oscfg.mpu.mout, p)) { - milstr_ncpy(np2oscfg.mpu.mout, p, sizeof(np2oscfg.mpu.mout)); - update |= SYS_UPDATECFG | SYS_UPDATEMIDI; - } - } - p = gtk_entry_get_text(GTK_ENTRY(mpu98_midiin_entry)); - if (p != NULL) { - if (milstr_cmp(np2oscfg.mpu.min, p)) { - milstr_ncpy(np2oscfg.mpu.min, p, sizeof(np2oscfg.mpu.min)); - update |= SYS_UPDATECFG | SYS_UPDATEMIDI; - } - } - p = gtk_entry_get_text(GTK_ENTRY(mpu98_module_entry)); - if (p != NULL) { - if (milstr_cmp(np2oscfg.mpu.mdl, p)) { - milstr_ncpy(np2oscfg.mpu.mdl, p, sizeof(np2oscfg.mpu.mdl)); - update |= SYS_UPDATECFG | SYS_UPDATEMIDI; + utf8 = gtk_entry_get_text(GTK_ENTRY(mpu98_midiout_entry)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (milstr_cmp(np2oscfg.mpu.mout, p)) { + milstr_ncpy(np2oscfg.mpu.mout, p, sizeof(np2oscfg.mpu.mout)); + update |= SYS_UPDATECFG | SYS_UPDATEMIDI; + } + g_free(p); + } + } + utf8 = gtk_entry_get_text(GTK_ENTRY(mpu98_midiin_entry)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (milstr_cmp(np2oscfg.mpu.min, p)) { + milstr_ncpy(np2oscfg.mpu.min, p, sizeof(np2oscfg.mpu.min)); + update |= SYS_UPDATECFG | SYS_UPDATEMIDI; + } + g_free(p); + } + } + utf8 = gtk_entry_get_text(GTK_ENTRY(mpu98_module_entry)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (milstr_cmp(np2oscfg.mpu.mdl, p)) { + milstr_ncpy(np2oscfg.mpu.mdl, p, sizeof(np2oscfg.mpu.mdl)); + update |= SYS_UPDATECFG | SYS_UPDATEMIDI; + } + g_free(p); } } /* MIMPI def enable/file */ - enable = GTK_TOGGLE_BUTTON(mpu98_mimpi_def_checkbutton)->active ? 1 : 0; + enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mpu98_mimpi_def_checkbutton)) ? 1 : 0; if (np2oscfg.mpu.def_en != enable) { np2oscfg.mpu.def_en = enable; if (cm_mpu98) { @@ -125,24 +136,32 @@ ok_button_clicked(GtkButton *b, gpointer } update |= SYS_UPDATEOSCFG; } - p = gtk_entry_get_text(GTK_ENTRY(mpu98_mimpi_def_entry)); - if (p != NULL) { - if (milstr_cmp(np2oscfg.mpu.def, p)) { - milstr_ncpy(np2oscfg.mpu.def, p, sizeof(np2oscfg.mpu.def)); - if (cm_mpu98) { - (*cm_mpu98->msg)(cm_mpu98, COMMSG_MIMPIDEFFILE, (long)p); + utf8 = gtk_entry_get_text(GTK_ENTRY(mpu98_mimpi_def_entry)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (milstr_cmp(np2oscfg.mpu.def, p)) { + milstr_ncpy(np2oscfg.mpu.def, p, sizeof(np2oscfg.mpu.def)); + if (cm_mpu98) { + (*cm_mpu98->msg)(cm_mpu98, COMMSG_MIMPIDEFFILE, (long)p); + } + update |= SYS_UPDATEOSCFG; } - update |= SYS_UPDATEOSCFG; + g_free(p); } } /* MIDI-IN/OUT device */ for (i = 0; i < NELEMENTS(mpu98_devname_str); i++) { - p = gtk_entry_get_text(GTK_ENTRY(mpu98_devname_entry[i])); - if (p != NULL) { - if (milstr_cmp(np2oscfg.MIDIDEV[i], p)) { - milstr_ncpy(np2oscfg.MIDIDEV[i], p, sizeof(np2oscfg.MIDIDEV[0])); - update |= SYS_UPDATEOSCFG; + utf8 = gtk_entry_get_text(GTK_ENTRY(mpu98_devname_entry[i])); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (milstr_cmp(np2oscfg.MIDIDEV[i], p)) { + milstr_ncpy(np2oscfg.MIDIDEV[i], p, sizeof(np2oscfg.MIDIDEV[0])); + update |= SYS_UPDATEOSCFG; + } + g_free(p); } } } @@ -167,33 +186,48 @@ dialog_destroy(GtkWidget *w, GtkWidget * static void mpu98_ioport_entry_changed(GtkEditable *e, gpointer d) { - const gchar *p; + const gchar *utf8; + gchar *p; BYTE val; UNUSED(d); - p = gtk_entry_get_text(GTK_ENTRY(e)); - if ((p != NULL) && (strlen(p) >= 4)) { - val = (milstr_solveHEX(p) >> 6) & 0xf0; - mpuopt &= ~0xf0; - mpuopt |= val; + + utf8 = gtk_entry_get_text(GTK_ENTRY(e)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (strlen(p) >= 4) { + val = (milstr_solveHEX(p) >> 6) & 0xf0; + mpuopt &= ~0xf0; + mpuopt |= val; + } + g_free(p); + } } } static void mpu98_intr_entry_changed(GtkEditable *e, gpointer d) { - const gchar *p; + const gchar *utf8; + gchar *p; BYTE val; UNUSED(d); - p = gtk_entry_get_text(GTK_ENTRY(e)); - if ((p != NULL) && (strlen(p) >= 4)) { - val = p[3] - '0'; - if (val >= 3) - val = 3; - mpuopt &= ~0x03; - mpuopt |= val; + utf8 = gtk_entry_get_text(GTK_ENTRY(e)); + if (utf8 != NULL) { + p = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (p != NULL) { + if (strlen(p) >= 4) { + val = p[3] - '0'; + if (val >= 3) + val = 3; + mpuopt &= ~0x03; + mpuopt |= val; + } + g_free(p); + } } } @@ -225,14 +259,16 @@ mpu98_mimpi_def_button_clicked(GtkButton GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); if (dialog == NULL) - return; + goto end; g_object_set(G_OBJECT(dialog), "show-hidden", TRUE, NULL); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); - utf8 = g_filename_to_utf8(np2oscfg.mpu.def, -1, NULL, NULL, NULL); - if (utf8) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8); - g_free(utf8); + if (np2oscfg.mpu.def[0] != '\0') { + utf8 = g_filename_to_utf8(np2oscfg.mpu.def, -1, NULL, NULL, NULL); + if (utf8) { + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8); + g_free(utf8); + } } filter = gtk_file_filter_new(); @@ -249,20 +285,24 @@ mpu98_mimpi_def_button_clicked(GtkButton gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - if (utf8) { - path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); - if (path) { - if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IRUSR)) { - gtk_entry_set_text(GTK_ENTRY(mpu98_mimpi_def_entry), utf8); - } - g_free(path); + if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) + goto end; + + utf8 = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + if (utf8) { + path = g_filename_from_utf8(utf8, -1, NULL, NULL, NULL); + if (path) { + if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IRUSR)) { + gtk_entry_set_text(GTK_ENTRY(mpu98_mimpi_def_entry), utf8); } - g_free(utf8); + g_free(path); } + g_free(utf8); } - gtk_widget_destroy(dialog); + +end: + if (dialog) + gtk_widget_destroy(dialog); } void @@ -290,6 +330,7 @@ create_midi_dialog(void) GtkWidget *ok_button; GtkWidget *cancel_button; GtkWidget *mpu98_default_button; + gchar *utf8; int i; uninstall_idle_process(); @@ -301,7 +342,7 @@ create_midi_dialog(void) gtk_window_set_resizable(GTK_WINDOW(midi_dialog), FALSE); g_signal_connect(GTK_OBJECT(midi_dialog), "destroy", - GTK_SIGNAL_FUNC(dialog_destroy), NULL); + G_CALLBACK(dialog_destroy), NULL); main_widget = gtk_table_new(10, 6, FALSE); gtk_container_set_border_width(GTK_CONTAINER(main_widget), 5); @@ -317,7 +358,6 @@ create_midi_dialog(void) 0, 1, 0, 1); ioport_combo = gtk_combo_box_entry_new_text(); - gtk_widget_set_size_request(ioport_combo, 80, -1); gtk_widget_show(ioport_combo); gtk_table_attach_defaults(GTK_TABLE(main_widget), ioport_combo, 1, 2, 0, 1); @@ -328,7 +368,7 @@ create_midi_dialog(void) mpu98_ioport_entry = GTK_BIN(ioport_combo)->child; gtk_widget_show(mpu98_ioport_entry); g_signal_connect(GTK_OBJECT(mpu98_ioport_entry), "changed", - GTK_SIGNAL_FUNC(mpu98_ioport_entry_changed), NULL); + G_CALLBACK(mpu98_ioport_entry_changed), NULL); gtk_editable_set_editable(GTK_EDITABLE(mpu98_ioport_entry), FALSE); gtk_entry_set_text(GTK_ENTRY(mpu98_ioport_entry), mpu98_ioport_str[(np2cfg.mpuopt >> 4) & 0x0f]); @@ -342,7 +382,6 @@ create_midi_dialog(void) 0, 1, 1, 2); intr_combo = gtk_combo_box_entry_new_text(); - gtk_widget_set_size_request(intr_combo, 80, -1); gtk_widget_show(intr_combo); gtk_table_attach_defaults(GTK_TABLE(main_widget), intr_combo, 1, 2, 1, 2); @@ -353,7 +392,7 @@ create_midi_dialog(void) mpu98_intr_entry = GTK_BIN(intr_combo)->child; gtk_widget_show(mpu98_intr_entry); g_signal_connect(GTK_OBJECT(mpu98_intr_entry), "changed", - GTK_SIGNAL_FUNC(mpu98_intr_entry_changed), NULL); + G_CALLBACK(mpu98_intr_entry_changed), NULL); gtk_editable_set_editable(GTK_EDITABLE(mpu98_intr_entry), FALSE); gtk_entry_set_text(GTK_ENTRY(mpu98_intr_entry), mpu98_intr_str[np2cfg.mpuopt & 0x03]); @@ -385,8 +424,13 @@ create_midi_dialog(void) gtk_table_attach_defaults(GTK_TABLE(deviceframe_widget), mpu98_devname_entry[i], 1, 6, i, i + 1); - gtk_entry_set_text(GTK_ENTRY(mpu98_devname_entry[i]), - np2oscfg.MIDIDEV[i]); + if (np2oscfg.MIDIDEV[i][0] != '\0') { + utf8 = g_filename_to_utf8(np2oscfg.MIDIDEV[i], -1, NULL, NULL, NULL); + if (utf8 != NULL) { + gtk_entry_set_text(GTK_ENTRY(mpu98_devname_entry[i]), np2oscfg.MIDIDEV[i]); + g_free(utf8); + } + } } /* MIDI-IN disable */ gtk_widget_set_sensitive(mpu98_devname_entry[1], FALSE); @@ -512,14 +556,20 @@ create_midi_dialog(void) gtk_table_attach(GTK_TABLE(assignframe_widget), mpu98_mimpi_def_entry, 0, 5, 4, 5, GTK_FILL, GTK_FILL, 3, 3); gtk_widget_set_sensitive(mpu98_mimpi_def_entry, FALSE); - gtk_entry_set_text(GTK_ENTRY(mpu98_mimpi_def_entry), np2oscfg.mpu.def); + if (np2oscfg.mpu.def[0] != '\0') { + utf8 = g_filename_to_utf8(np2oscfg.mpu.def, -1, NULL, NULL, NULL); + if (utf8 != NULL) { + gtk_entry_set_text(GTK_ENTRY(mpu98_mimpi_def_entry), np2oscfg.mpu.def); + g_free(utf8); + } + } mimpi_button = gtk_button_new_with_label("..."); gtk_widget_show(mimpi_button); gtk_table_attach(GTK_TABLE(assignframe_widget), mimpi_button, 5, 6, 4, 5, GTK_FILL, GTK_FILL, 3, 3); g_signal_connect(GTK_OBJECT(mimpi_button), "clicked", - GTK_SIGNAL_FUNC(mpu98_mimpi_def_button_clicked), 0); + G_CALLBACK(mpu98_mimpi_def_button_clicked), midi_dialog); /* * "Default" button @@ -529,7 +579,7 @@ create_midi_dialog(void) gtk_table_attach(GTK_TABLE(main_widget), mpu98_default_button, 2, 3, 1, 2, GTK_SHRINK, GTK_SHRINK, 5, 5); g_signal_connect_swapped(GTK_OBJECT(mpu98_default_button), "clicked", - GTK_SIGNAL_FUNC(mpu98_default_button_clicked), NULL); + G_CALLBACK(mpu98_default_button_clicked), NULL); /* * OK, Cancel button @@ -544,18 +594,18 @@ create_midi_dialog(void) ok_button = gtk_button_new_from_stock(GTK_STOCK_OK); gtk_widget_show(ok_button); gtk_container_add(GTK_CONTAINER(confirm_widget), ok_button); - GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT); - GTK_WIDGET_SET_FLAGS(ok_button, GTK_HAS_DEFAULT); + gtk_widget_set_can_default(ok_button, TRUE); + gtk_widget_has_default(ok_button); g_signal_connect(GTK_OBJECT(ok_button), "clicked", - GTK_SIGNAL_FUNC(ok_button_clicked), (gpointer)midi_dialog); + G_CALLBACK(ok_button_clicked), (gpointer)midi_dialog); gtk_widget_grab_default(ok_button); cancel_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); gtk_widget_show(cancel_button); gtk_container_add(GTK_CONTAINER(confirm_widget), cancel_button); - GTK_WIDGET_SET_FLAGS(cancel_button, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(cancel_button, TRUE); g_signal_connect_swapped(GTK_OBJECT(cancel_button), "clicked", - GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(midi_dialog)); + G_CALLBACK(gtk_widget_destroy), GTK_OBJECT(midi_dialog)); gtk_widget_show_all(midi_dialog); }