⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widgets.c

📁 串口调试工具。非常好的串口调试助手
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************//* widgets.c                                                           *//* ---------                                                           *//*           GTKTerm Software                                          *//*                      (c) Julien Schmitt                             *//*                      julien@jls-info.com                            *//*                                                                     *//* ------------------------------------------------------------------- *//*                                                                     *//*   Purpose                                                           *//*      Functions for the management of the GUI for the main window    *//*                                                                     *//*   ChangeLog                                                         *//*   (All changes by Julien Schmitt except when explicitly written)    *//*                                                                     *//*      - 0.99.5 : Make package buildable on pure *BSD by changing the *//*                 include to asm/termios.h by sys/ttycom.h            *//*                 Print message without converting it into the locale *//*                 in show_message()                                   *//*                 Set backspace key binding to backspace so that the  *//*                 backspace works. It would even be nicer if the      *//*                 behaviour of this key could be configured !         *//*      - 0.99.4 : - Sebastien Bacher -                                *//*                 Added functions for CR LF auto mode                 *//*                 Fixed put_text() to have \r\n for the VTE Widget    *//*                 Rewritten put_hexadecimal() function                *//*                 - Julien -                                          *//*                 Modified send_serial to return the actual number of *//*                 bytes written, and also only display exactly what   *//*                 is written                                          *//*      - 0.99.3 : Modified to use a VTE terminal                      *//*      - 0.99.2 : Internationalization                                *//*      - 0.99.0 : \b byte now handled correctly by the ascii widget   *//*                 SUPPR (0x7F) also prints correctly                  *//*                 adapted for macros                                  *//*                 modified "about" dialog                             *//*      - 0.98.6 : fixed possible buffer overrun in hex send           *//*                 new "Send break" option                             *//*      - 0.98.5 : icons in the menu                                   *//*                 bug fixed with local echo and hexadecimal           *//*                 modified hexadecimal send separator, and bug fixed  *//*      - 0.98.4 : new hexadecimal display / send                      *//*      - 0.98.3 : put_text() modified to fit with 0x0D 0x0A           *//*      - 0.98.2 : added local echo by Julien                          *//*      - 0.98 : file creation by Julien                               *//*                                                                     *//***********************************************************************/#include <gtk/gtk.h>#include <gdk/gdk.h>#include <gdk/gdkkeysyms.h>#if defined (__linux__)#  include <asm/termios.h>       /* For control signals */#endif#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) \     || defined (__NetBSD__) || defined (__NetBSD_kernel__) \     || defined (__OpenBSD__) || defined (__OpenBSD_kernel__) #  include <sys/ttycom.h>        /* For control signals */#endif#include <vte/vte.h>#include <stdio.h>#include <string.h>#include "config.h"#include "fichier.h"#include "serie.h"#include "widgets.h"#include "buffer.h"#include "macros.h"#include "gettext.h"#include "auto_config.h"guint id;gboolean echo_on;gboolean crlfauto_on;GtkWidget *StatusBar;GtkWidget *signals[6];static GtkWidget *echo_menu = NULL;static GtkWidget *crlfauto_menu = NULL;static GtkWidget *ascii_menu = NULL;static GtkWidget *hex_menu = NULL;static GtkWidget *hex_len_menu = NULL;static GtkWidget *hex_chars_menu = NULL;static GtkWidget *show_index_menu = NULL;static GtkWidget *Hex_Box;GtkWidget *Fenetre;GtkAccelGroup *shortcuts;GtkWidget *display = NULL;GtkWidget *Text;GtkTextBuffer *buffer;GtkTextIter iter;/* Variables for hexadecimal display */static gint bytes_per_line = 16;static gchar blank_data[128];static guint total_bytes;static gboolean show_index = FALSE;/* Local functions prototype */gint signaux(GtkWidget *, guint);gint a_propos(GtkWidget *, guint);gboolean Envoie_car(GtkWidget *, GdkEventKey *, gpointer);gboolean control_signals_read(void);gint Toggle_Echo(gpointer *, guint, GtkWidget *);gint Toggle_Crlfauto(gpointer *, guint, GtkWidget *);gint view(gpointer *, guint, GtkWidget *);gint hexadecimal_chars_to_display(gpointer *, guint, GtkWidget *);gint toggle_index(gpointer *, guint, GtkWidget *);gint show_hide_hex(gpointer *, guint, GtkWidget *);void initialize_hexadecimal_display(void);gboolean Send_Hexadecimal(GtkWidget *, GdkEventKey *, gpointer);void Put_temp_message(const gchar *, gint);gboolean pop_message(void);static gchar *translate_menu(const gchar *, gpointer);static void Got_Input(VteTerminal *, gchar *, guint, gpointer);/* Menu */#define NUMBER_OF_ITEMS 34static GtkItemFactoryEntry Tableau_Menu[] = {  {N_("/_File") , NULL, NULL, 0, "<Branch>"},  {N_("/File/Clear screen") , "<ctrl>L", (GtkItemFactoryCallback)clear_buffer, 0, "<StockItem>", GTK_STOCK_CLEAR},  {N_("/File/Send _raw file") , "<ctrl>R", (GtkItemFactoryCallback)fichier, 1, "<StockItem>",GTK_STOCK_JUMP_TO},  {N_("/File/_Save raw file") , NULL, (GtkItemFactoryCallback)fichier, 2, "<StockItem>", GTK_STOCK_SAVE_AS},  {N_("/File/Separator") , NULL, NULL, 0, "<Separator>"},  {N_("/File/E_xit") , "<ctrl>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT},  {N_("/_Configuration"), NULL, NULL, 0, "<Branch>"},  {N_("/Configuration/_Port"), "<ctrl>S", (GtkItemFactoryCallback)Config_Port_Fenetre, 0, "<StockItem>", GTK_STOCK_PREFERENCES},  {N_("/Configuration/_Main window"), NULL, (GtkItemFactoryCallback)Config_Terminal, 0, "<StockItem>", GTK_STOCK_SELECT_FONT},  {N_("/Configuration/Local _echo"), NULL, (GtkItemFactoryCallback)Toggle_Echo, 0, "<CheckItem>"},  {N_("/Configuration/_CR LF auto"), NULL, (GtkItemFactoryCallback)Toggle_Crlfauto, 0, "<CheckItem>"},  {N_("/Configuration/_Macros"), NULL, (GtkItemFactoryCallback)Config_macros, 0, "<Item>"},  {N_("/Configuration/Separator") , NULL, NULL, 0, "<Separator>"},  {N_("/Configuration/_Load configuration"), NULL, (GtkItemFactoryCallback)config_window, 0, "<StockItem>", GTK_STOCK_OPEN},  {N_("/Configuration/_Save configuration"), NULL, (GtkItemFactoryCallback)config_window, 1, "<StockItem>", GTK_STOCK_SAVE_AS},  {N_("/Configuration/_Delete configuration"), NULL, (GtkItemFactoryCallback)config_window, 2, "<StockItem>", GTK_STOCK_DELETE},  {N_("/Control _signals"), NULL, NULL, 0, "<Branch>"},  {N_("/Control signals/Send break"), "<ctrl>B", (GtkItemFactoryCallback)signaux, 2, "<Item>"},  {N_("/Control signals/Toggle DTR"), "F7", (GtkItemFactoryCallback)signaux, 0, "<Item>"},  {N_("/Control signals/Toggle RTS"), "F8", (GtkItemFactoryCallback)signaux, 1, "<Item>"},  {N_("/_View"), NULL, NULL, 0, "<Branch>"},  {N_("/View/_ASCII"), NULL, (GtkItemFactoryCallback)view, ASCII_VIEW, "<RadioItem>"},  {N_("/View/_Hexadecimal"), NULL, (GtkItemFactoryCallback)view, HEXADECIMAL_VIEW, "<RadioItem>"},  {N_("/View/Hexadecimal _chars"), NULL, NULL, 0, "<Branch>"},  {N_("/View/Hexadecimal chars/_8"), NULL, (GtkItemFactoryCallback)hexadecimal_chars_to_display, 8, "<RadioItem>"},  {N_("/View/Hexadecimal chars/1_0"), NULL, (GtkItemFactoryCallback)hexadecimal_chars_to_display, 10, "/View/Hexadecimal chars/8"},  {N_("/View/Hexadecimal chars/_16"), NULL, (GtkItemFactoryCallback)hexadecimal_chars_to_display, 16, "/View/Hexadecimal chars/8"},  {N_("/View/Hexadecimal chars/_24"), NULL, (GtkItemFactoryCallback)hexadecimal_chars_to_display, 24, "/View/Hexadecimal chars/8"},  {N_("/View/Hexadecimal chars/_32"), NULL, (GtkItemFactoryCallback)hexadecimal_chars_to_display, 32, "/View/Hexadecimal chars/8"},  {N_("/View/Show _index"), NULL, (GtkItemFactoryCallback)toggle_index, 0, "<CheckItem>"},  {N_("/View/Separator") , NULL, NULL, 0, "<Separator>"},  {N_("/View/_Send hexadecimal data") , NULL, (GtkItemFactoryCallback)show_hide_hex, 0, "<CheckItem>"},  {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},  {N_("/Help/_About..."), NULL, (GtkItemFactoryCallback)a_propos, 0, "<StockItem>", GTK_STOCK_DIALOG_INFO}};static gchar *translate_menu(const gchar *path, gpointer data){    return _(path);}gint show_hide_hex(gpointer *pointer, guint param, GtkWidget *widget){  if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))    gtk_widget_show(GTK_WIDGET(Hex_Box));  else    gtk_widget_hide(GTK_WIDGET(Hex_Box));  return FALSE;}gint toggle_index(gpointer *pointer, guint param, GtkWidget *widget){  show_index = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));  set_view(HEXADECIMAL_VIEW);  return FALSE;  }gint hexadecimal_chars_to_display(gpointer *pointer, guint param, GtkWidget *widget){  bytes_per_line = param;  set_view(HEXADECIMAL_VIEW);  return FALSE;}void set_view(guint type){  clear_display();  set_clear_func(clear_display);  switch(type)    {    case ASCII_VIEW:      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(hex_menu), FALSE);      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ascii_menu), TRUE);      gtk_widget_set_sensitive(GTK_WIDGET(show_index_menu), FALSE);      gtk_widget_set_sensitive(GTK_WIDGET(hex_chars_menu), FALSE);      total_bytes = 0;      set_display_func(put_text);      break;    case HEXADECIMAL_VIEW:      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(hex_menu), TRUE);      gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ascii_menu), FALSE);      gtk_widget_set_sensitive(GTK_WIDGET(show_index_menu), TRUE);      gtk_widget_set_sensitive(GTK_WIDGET(hex_chars_menu), TRUE);      total_bytes = 0;      set_display_func(put_hexadecimal);      break;    default:      set_display_func(NULL);    }  write_buffer();}gint view(gpointer *pointer, guint param, GtkWidget *widget){  if(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))    return FALSE;    set_view(param);  return FALSE;}void Set_local_echo(gboolean echo){  echo_on = echo;  if(echo_menu)    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(echo_menu), echo_on);}gint Toggle_Echo(gpointer *pointer, guint param, GtkWidget *widget){  echo_on = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));  configure_echo(echo_on);  return 0;}void Set_crlfauto(gboolean crlfauto){  crlfauto_on = crlfauto;  if(crlfauto_menu)    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(crlfauto_menu), crlfauto_on);}gint Toggle_Crlfauto(gpointer *pointer, guint param, GtkWidget *widget){  crlfauto_on = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));  configure_crlfauto(crlfauto_on);  return 0;}void create_main_window(void){  GtkWidget *Menu, *Boite, *BoiteH, *Label;  GtkWidget *Hex_Send_Entry;  GtkItemFactory *item_factory;  GtkAccelGroup *accel_group;  GSList *group;  Fenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);  shortcuts = gtk_accel_group_new();  gtk_window_add_accel_group(GTK_WINDOW(Fenetre), GTK_ACCEL_GROUP(shortcuts));  gtk_signal_connect(GTK_OBJECT(Fenetre), "destroy", (GtkSignalFunc)gtk_main_quit, NULL);  gtk_signal_connect(GTK_OBJECT(Fenetre), "delete_event", (GtkSignalFunc)gtk_main_quit, NULL);  gtk_window_set_title(GTK_WINDOW(Fenetre), "GtkTerm");    Boite = gtk_vbox_new(FALSE, 0);  gtk_container_add(GTK_CONTAINER(Fenetre), Boite);    accel_group = gtk_accel_group_new();  item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);  gtk_item_factory_set_translate_func(item_factory, translate_menu, "<main>", NULL);  gtk_window_add_accel_group(GTK_WINDOW(Fenetre), accel_group);  gtk_item_factory_create_items(item_factory, NUMBER_OF_ITEMS, Tableau_Menu, NULL);  Menu = gtk_item_factory_get_widget(item_factory, "<main>");  echo_menu = gtk_item_factory_get_item(item_factory, "/Configuration/Local echo");  crlfauto_menu = gtk_item_factory_get_item(item_factory, "/Configuration/LF auto");  ascii_menu = gtk_item_factory_get_item(item_factory, "/View/ASCII");  hex_menu = gtk_item_factory_get_item(item_factory, "/View/Hexadecimal");  hex_chars_menu = gtk_item_factory_get_item(item_factory, "/View/Hexadecimal chars");  show_index_menu = gtk_item_factory_get_item(item_factory, "/View/Show index");  group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(ascii_menu));  gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(hex_menu), group);  hex_len_menu = gtk_item_factory_get_item(item_factory, "/View/Hexadecimal chars/16");  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(hex_len_menu), TRUE);  gtk_box_pack_start(GTK_BOX(Boite), Menu, FALSE, TRUE, 0);    BoiteH = gtk_hbox_new(FALSE, 0);  gtk_box_pack_start(GTK_BOX(Boite), BoiteH, TRUE, TRUE, 0);  display = vte_terminal_new();  vte_terminal_set_backspace_binding(VTE_TERMINAL(display),				     VTE_ERASE_ASCII_BACKSPACE);  clear_display();  gtk_box_pack_start_defaults(GTK_BOX(BoiteH), display);  Hex_Box = gtk_hbox_new(TRUE, 0);  Label = gtk_label_new(_("Hexadecimal data to send (separator : ';' or space) : "));  gtk_box_pack_start_defaults(GTK_BOX(Hex_Box), Label);  Hex_Send_Entry = gtk_entry_new();  gtk_signal_connect(GTK_OBJECT(Hex_Send_Entry), "activate", (GtkSignalFunc)Send_Hexadecimal, NULL);  gtk_box_pack_start(GTK_BOX(Hex_Box), Hex_Send_Entry, FALSE, TRUE, 5);  gtk_box_pack_start(GTK_BOX(Boite), Hex_Box, FALSE, TRUE, 2);  BoiteH = gtk_hbox_new(FALSE, 0);  gtk_box_pack_start(GTK_BOX(Boite), BoiteH, FALSE, FALSE, 0);  StatusBar = gtk_statusbar_new();  gtk_box_pack_start(GTK_BOX(BoiteH), StatusBar, TRUE, TRUE, 0);  id = gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusBar), "Messages");  Label = gtk_label_new("RI");  gtk_box_pack_end(GTK_BOX(BoiteH), Label, FALSE, TRUE, 5);  gtk_widget_set_sensitive(GTK_WIDGET(Label), FALSE);  signals[0] = Label;  Label = gtk_label_new("DSR");  gtk_box_pack_end(GTK_BOX(BoiteH), Label, FALSE, TRUE, 5);  signals[1] = Label;  Label = gtk_label_new("CD");  gtk_box_pack_end(GTK_BOX(BoiteH), Label, FALSE, TRUE, 5);  signals[2] = Label;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -