📄 gtk_i.c
字号:
gtk_box_pack_start(GTK_BOX(hbox), handlebox, FALSE, FALSE, 0); table = gtk_table_new(7, 2, TRUE); gtk_container_add(GTK_CONTAINER(handlebox), table); button = create_button_with_pixmap(window, playpaus_xpm, GTK_PAUSE, "Play/Pause"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 2, 0, 1); button = create_button_with_pixmap(window, prevtrk_xpm, GTK_PREV, "Previous file"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 1, 2); button = create_button_with_pixmap(window, nexttrk_xpm, GTK_NEXT, "Next file"); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 1, 2); button = create_button_with_pixmap(window, rew_xpm, GTK_RWD, "Rewind"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 2, 3); button = create_button_with_pixmap(window, ff_xpm, GTK_FWD, "Fast forward"); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 2, 3); button = create_button_with_pixmap(window, keydown_xpm, GTK_KEYDOWN, "Lower pitch"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 3, 4); button = create_button_with_pixmap(window, keyup_xpm, GTK_KEYUP, "Raise pitch"); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 3, 4); button = create_button_with_pixmap(window, slow_xpm, GTK_SLOWER, "Decrease tempo"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 4, 5); button = create_button_with_pixmap(window, fast_xpm, GTK_FASTER, "Increase tempo"); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 4, 5); button = create_button_with_pixmap(window, restart_xpm, GTK_RESTART, "Restart"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 5, 6); button = create_button_with_pixmap(window, open_xpm, 0, "Open"); gtk_signal_disconnect_by_func(GTK_OBJECT(button), generic_cb, 0); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(open_file_cb), 0); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 5, 6); button = create_button_with_pixmap(window, quit_xpm, GTK_QUIT, "Quit"); gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 2, 6, 7); gtk_widget_show(hbox); gtk_widget_show(vbox); gtk_widget_show(table); gtk_widget_show(handlebox); gtk_widget_show(window); gdk_input_add(pipe_number, GDK_INPUT_READ, handle_input, NULL); gtk_main();}static GtkWidget *create_button_with_pixmap(GtkWidget *window, gchar **bits, gint data, gchar *thelp){ GtkWidget *pw, *button; GdkPixmap *pixmap; GdkBitmap *mask; GtkStyle *style; style = gtk_widget_get_style(window); pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask, &style->bg[GTK_STATE_NORMAL], bits); pw = gtk_pixmap_new(pixmap, mask); gtk_widget_show(pw); button = gtk_button_new(); gtk_container_add(GTK_CONTAINER(button), pw); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(generic_cb), (gpointer)data); gtk_widget_show(button); gtk_tooltips_set_tip(ttip, button, thelp, NULL); return button;}static GtkWidget *create_pixmap_label(GtkWidget *window, gchar **bits){ GtkWidget *pw; GdkPixmap *pixmap; GdkBitmap *mask; GtkStyle *style; style = gtk_widget_get_style(window); pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask, &style->bg[GTK_STATE_NORMAL], bits); pw = gtk_pixmap_new(pixmap, mask); gtk_widget_show(pw); return pw;}static voidset_icon_pixmap(GtkWidget *window, gchar **bits){ GdkPixmap *pixmap; GdkBitmap *mask; GtkStyle *style; style = gtk_widget_get_style(window); pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask, &style->bg[GTK_STATE_NORMAL], bits); gdk_window_set_icon(window->window, NULL, pixmap, mask); gdk_window_set_icon_name(window->window, "TiMidity");}static GtkWidget *create_menubar(void){ GtkItemFactory *ifactory; GtkAccelGroup *ag; ag = gtk_accel_group_get_default(); ifactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<Main>", ag); gtk_item_factory_create_items(ifactory, sizeof(ife) / sizeof(GtkItemFactoryEntry), ife, NULL); gtk_widget_show(ifactory->widget); auto_next = gtk_item_factory_get_widget(ifactory, "/Options/Auto next"); gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(auto_next), TRUE); ttshow = gtk_item_factory_get_widget(ifactory, "/Options/Show tooltips"); gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(ttshow), TRUE); return ifactory->widget;}/* Following function curtesy of the gtk mailing list. */static GtkTooltips *create_yellow_tooltips(){ GdkColor *t_back; GtkTooltips *tip; t_back = (GdkColor*)g_malloc( sizeof(GdkColor)); /* First create a default Tooltip */ tip = gtk_tooltips_new(); /* Try to get the colors */ if ( gdk_color_parse("linen", t_back)){ if(gdk_colormap_alloc_color(gdk_colormap_get_system(), t_back, FALSE, TRUE)) { gtk_tooltips_set_colors(tip, t_back, NULL); } } return tip;}/* Receive DATA sent by the application on the pipe */static voidhandle_input(gpointer client_data, gint source, GdkInputCondition ic){ int message; gtk_pipe_int_read(&message); switch (message) { case REFRESH_MESSAGE: g_warning("REFRESH MESSAGE IS OBSOLETE !!!"); break; case TOTALTIME_MESSAGE: { int cseconds; int minutes,seconds; char local_string[20]; GtkObject *adj; gtk_pipe_int_read(&cseconds); seconds=cseconds/100; minutes=seconds/60; seconds-=minutes*60; sprintf(local_string,"/ %i:%02i",minutes,seconds); gtk_label_set(GTK_LABEL(tot_lbl), local_string); /* Readjust the time scale */ max_sec=cseconds/100; adj = gtk_adjustment_new(0., 0., (gfloat)max_sec, 1., 10., 0.); gtk_signal_connect(GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(generic_scale_cb), (gpointer)GTK_CHANGE_LOCATOR); gtk_range_set_adjustment(GTK_RANGE(locator), GTK_ADJUSTMENT(adj)); } break; case MASTERVOL_MESSAGE: { int volume; GtkAdjustment *adj; gtk_pipe_int_read(&volume); adj = gtk_range_get_adjustment(GTK_RANGE(vol_scale)); my_adjustment_set_value(adj, MAX_AMPLIFICATION - volume); } break; case FILENAME_MESSAGE: { char filename[255], title[255]; char *pc; gtk_pipe_string_read(filename); /* Extract basename of the file */ pc = strrchr(filename, '/'); if (pc == NULL) pc = filename; else pc++; sprintf(title, "Timidity %s - %s", timidity_version, pc); gtk_window_set_title(GTK_WINDOW(window), title); /* Clear the text area. */ gtk_text_freeze(GTK_TEXT(text)); gtk_text_set_point(GTK_TEXT(text), 0); gtk_text_forward_delete(GTK_TEXT(text), gtk_text_get_length(GTK_TEXT(text))); gtk_text_thaw(GTK_TEXT(text)); } break; case FILE_LIST_MESSAGE: { gchar filename[255], *fnames[2]; gint i, number_of_files, row; /* reset the playing list : play from the start */ file_number_to_play = -1; gtk_pipe_int_read(&number_of_files); for (i = 0; i < number_of_files; i++) { gtk_pipe_string_read(filename); fnames[0] = filename; fnames[1] = NULL; row = gtk_clist_append(GTK_CLIST(clist), fnames); } gtk_clist_columns_autosize(GTK_CLIST(clist)); } break; case NEXT_FILE_MESSAGE: case PREV_FILE_MESSAGE: case TUNE_END_MESSAGE: { int nbfile; /* When a file ends, launch next if auto_next toggle */ if ( (message==TUNE_END_MESSAGE) && !GTK_CHECK_MENU_ITEM(auto_next)->active ) return; /* Total number of file to play in the list */ nbfile = GTK_CLIST(clist)->rows; if (message == PREV_FILE_MESSAGE) file_number_to_play--; else file_number_to_play++; /* Do nothing if requested file is before first one */ if (file_number_to_play < 0) { file_number_to_play = 0; return; } /* Stop after playing the last file */ if (file_number_to_play >= nbfile) { file_number_to_play = nbfile - 1; return; } if(gtk_clist_row_is_visible(GTK_CLIST(clist), file_number_to_play) != GTK_VISIBILITY_FULL) { gtk_clist_moveto(GTK_CLIST(clist), file_number_to_play, -1, 1.0, 0.0); } gtk_clist_select_row(GTK_CLIST(clist), file_number_to_play, 0); } break; case CURTIME_MESSAGE: { int seconds, minutes; int nbvoice; char local_string[20]; gtk_pipe_int_read(&seconds); gtk_pipe_int_read(&nbvoice); if( is_quitting ) return; minutes=seconds/60; sprintf(local_string,"%2d:%02d", minutes, (int)(seconds % 60)); gtk_label_set(GTK_LABEL(cnt_lbl), local_string); /* Readjust the time scale if not dragging the scale */ if( !locating && (seconds <= max_sec)) { GtkAdjustment *adj; adj = gtk_range_get_adjustment(GTK_RANGE(locator)); my_adjustment_set_value(adj, (gfloat)seconds); } } break; case NOTE_MESSAGE: { int channel; int note; gtk_pipe_int_read(&channel); gtk_pipe_int_read(¬e); g_warning("NOTE chn%i %i", channel, note); } break; case PROGRAM_MESSAGE: { int channel; int pgm; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&pgm); g_warning("NOTE chn%i %i", channel, pgm); } break; case VOLUME_MESSAGE: { int channel; int volume; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&volume); g_warning("VOLUME= chn%i %i", channel, volume); } break; case EXPRESSION_MESSAGE: { int channel; int express; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&express); g_warning("EXPRESSION= chn%i %i", channel, express); } break; case PANNING_MESSAGE: { int channel; int pan; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&pan); g_warning("PANNING= chn%i %i", channel, pan); } break; case SUSTAIN_MESSAGE: { int channel; int sust; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&sust); g_warning("SUSTAIN= chn%i %i", channel, sust); } break; case PITCH_MESSAGE: { int channel; int bend; gtk_pipe_int_read(&channel); gtk_pipe_int_read(&bend); g_warning("PITCH BEND= chn%i %i", channel, bend); } break; case RESET_MESSAGE: g_warning("RESET_MESSAGE"); break; case CLOSE_MESSAGE: gtk_exit(0); break; case CMSG_MESSAGE: { int type; char message[1000]; gtk_pipe_int_read(&type); gtk_pipe_string_read(message); gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, message, -1); gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, "\n", 1); } break; case LYRIC_MESSAGE: { char message[1000]; gtk_pipe_string_read(message); gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, message, -1); } break; default: g_warning("UNKNOWN Gtk+ MESSAGE %i", message); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -