📄 gui.c
字号:
/* GKrellM| Copyright (C) 1999-2006 Bill Wilson|| Author: Bill Wilson billw@gkrellm.net| Latest versions might be found at: http://gkrellm.net|| This program is free software which I release under the GNU General Public| License. You may redistribute and/or modify this program under the terms| of that license as published by the Free Software Foundation; either| version 2 of the License, or (at your option) any later version.|| This program is distributed in the hope that it will be useful,| but WITHOUT ANY WARRANTY; without even the implied warranty of| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the| GNU General Public License for more details. Version 2 is in the| COPYRIGHT file in the top level directory of this distribution.| | To get a copy of the GNU General Puplic License, write to the Free Software| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "gkrellm.h"#include "gkrellm-private.h"GtkWidget *config_window;voidgkrellm_message_dialog(gchar *title, gchar *message) { GtkWidget *top_win; GtkWidget *dialog; GtkWidget *scrolled; GtkWidget *vbox, *vbox1; GtkWidget *label; gchar *s; gint nlines; if (!message) return; top_win = gkrellm_get_top_window(); dialog = gtk_dialog_new_with_buttons(title ? title : "GKrellM", GTK_WINDOW(top_win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL); g_signal_connect_swapped(GTK_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), GTK_OBJECT(dialog)); gtk_window_set_wmclass(GTK_WINDOW(dialog), "Gkrellm_dialog", "Gkrellm"); vbox = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, FALSE, FALSE, 0); label = gtk_label_new(message); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); for (nlines = 0, s = message; *s; ++s) if (*s == '\n') ++nlines; if (nlines > 20) { vbox1 = gkrellm_gtk_scrolled_vbox(vbox, &scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request(scrolled, -1, 300); gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, FALSE, 0); } else gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show_all(dialog); }voidgkrellm_config_message_dialog(gchar *title, gchar *message) { GtkWidget *dialog; GtkWidget *vbox; GtkWidget *label; if (!message || !config_window) return; dialog = gtk_dialog_new_with_buttons(title ? title : "GKrellM", GTK_WINDOW(config_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_wmclass(GTK_WINDOW(dialog), "Gkrellm_dialog", "Gkrellm"); vbox = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, FALSE, FALSE, 0); label = gtk_label_new(message); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show_all(vbox); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); }#undef gkrellm_message_window#undef gkrellm_config_message_windowvoidgkrellm_message_window(gchar *title, gchar *message, GtkWidget *widget) { gkrellm_message_dialog(title, message); }voidgkrellm_config_message_window(gchar *title, gchar *message, GtkWidget *widget) { gkrellm_config_message_dialog(title, message); }static voidtext_view_append(GtkWidget *view, gchar *s) { GtkTextIter iter; GtkTextBuffer *buffer; buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); gtk_text_buffer_get_end_iter(buffer, &iter);// gtk_text_iter_forward_to_end(&iter); if (strncmp(s, "<b>", 3) == 0) gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, s + 3, -1, "bold", NULL); else if (strncmp(s, "<i>", 3) == 0) gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, s + 3, -1, "italic", NULL); else if (strncmp(s, "<h>", 3) == 0) gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, s + 3, -1, "heading", NULL); else if (strncmp(s, "<c>", 3) == 0) gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, s + 3, -1, "center", NULL); else if (strncmp(s, "<ul>", 4) == 0) gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, s + 4, -1, "underline", NULL); else gtk_text_buffer_insert(buffer, &iter, s, -1); }voidgkrellm_gtk_text_view_append(GtkWidget *view, gchar *string) { static gchar *tag; gchar *s; s = string; if ( *s == '<' && ( (*(s + 2) == '>' && !*(s + 3)) || (*(s + 3) == '>' && !*(s + 4)) ) ) { tag = g_strdup(s); return; } if (tag) { s = g_strconcat(tag, string, NULL); text_view_append(view, s); g_free(s); g_free(tag); tag = NULL; } else text_view_append(view, string); }voidgkrellm_gtk_text_view_append_strings(GtkWidget *view, gchar **string, gint n_strings) { gchar *tag = NULL; gchar *s, *t; gint i; for (i = 0; i < n_strings; ++i) { s = string[i]; if ( *s == '<' && ( (*(s + 2) == '>' && !*(s + 3)) || (*(s + 3) == '>' && !*(s + 4)) ) ) { tag = g_strdup(s); continue; }#if defined(ENABLE_NLS) s = gettext(string[i]);#else s = string[i];#endif if (tag) { t = g_strconcat(tag, s, NULL); text_view_append(view, t); g_free(t); g_free(tag); tag = NULL; } else text_view_append(view, s); } }GtkWidget *gkrellm_gtk_scrolled_text_view(GtkWidget *box, GtkWidget **scr, GtkPolicyType h_policy, GtkPolicyType v_policy) { GtkWidget *scrolled, *view; GtkTextBuffer *buffer; scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), h_policy, v_policy); gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); view = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); gtk_container_add(GTK_CONTAINER(scrolled), view); gtk_text_buffer_create_tag(buffer, "heading", "weight", PANGO_WEIGHT_BOLD, "size", 14 * PANGO_SCALE, NULL); gtk_text_buffer_create_tag(buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL); gtk_text_buffer_create_tag (buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_create_tag (buffer, "center", "justification", GTK_JUSTIFY_CENTER, NULL); gtk_text_buffer_create_tag (buffer, "underline", "underline", PANGO_UNDERLINE_SINGLE, NULL); if (scr) *scr = scrolled; return view; }GtkTreeSelection *gkrellm_gtk_scrolled_selection(GtkTreeView *treeview, GtkWidget *box, GtkSelectionMode s_mode, GtkPolicyType h_policy, GtkPolicyType v_policy, void (*func_cb)(), gpointer data) { GtkTreeSelection *selection; GtkWidget *scrolled; if (!box || !treeview) return NULL; scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(box), scrolled, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(scrolled), GTK_WIDGET(treeview)); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), h_policy, v_policy); selection = gtk_tree_view_get_selection(treeview); gtk_tree_selection_set_mode(selection, s_mode); if (func_cb) g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(func_cb), data); return selection; }voidgkrellm_launch_button_cb(GkrellmDecalbutton *button) { GkrellmLauncher *launch; launch = (GkrellmLauncher *) button->data; g_spawn_command_line_async(launch->command, NULL /* GError */); }voidgkrellm_remove_launcher(GkrellmLauncher *launch) { if (launch->button) gkrellm_destroy_button(launch->button); launch->button = NULL; if (launch->tooltip) gtk_tooltips_set_tip(launch->tooltip, launch->widget, NULL, NULL); }voidgkrellm_configure_tooltip(GkrellmPanel *p, GkrellmLauncher *launch) { launch->widget = p->drawing_area; if (!launch->tooltip) { if (*launch->tooltip_comment && *launch->command) { launch->tooltip = gtk_tooltips_new(); gtk_tooltips_set_tip(launch->tooltip, p->drawing_area, launch->tooltip_comment, NULL); } return; } if (*launch->tooltip_comment && *launch->command) { gtk_tooltips_set_tip(launch->tooltip, p->drawing_area, launch->tooltip_comment, NULL); gtk_tooltips_enable(launch->tooltip); } else gtk_tooltips_disable(launch->tooltip); }voidgkrellm_apply_launcher(GtkWidget **launch_entry, GtkWidget **tooltip_entry, GkrellmPanel *p, GkrellmLauncher *launch, void (*func)()) { gchar *command, *tip_comment; if (!launch_entry || !launch || !p) return; command = gkrellm_gtk_entry_get_text(launch_entry); tip_comment = tooltip_entry ? gkrellm_gtk_entry_get_text(tooltip_entry) : ""; if ( launch->command && !strcmp(command, launch->command) && launch->tooltip_comment && !strcmp(tip_comment, launch->tooltip_comment) ) return; if (*command) { if (!launch->button) { if (launch->type == METER_LAUNCHER) launch->button = gkrellm_put_label_in_meter_button(p, func, launch, launch->pad); else if (launch->type == PANEL_LAUNCHER) launch->button = gkrellm_put_label_in_panel_button(p, func, launch, launch->pad); else if (launch->type == DECAL_LAUNCHER) launch->button = gkrellm_put_decal_in_meter_button(p, launch->decal, gkrellm_launch_button_cb, launch, &launch->margin); } gkrellm_dup_string(&launch->command, command); } else { if (launch->button) gkrellm_destroy_button(launch->button); launch->button = NULL; launch->pipe = NULL; /* Close?? */ gkrellm_dup_string(&launch->command, ""); } gkrellm_dup_string(&launch->tooltip_comment, tip_comment); gkrellm_configure_tooltip(p, launch); }GtkWidget *gkrellm_gtk_launcher_table_new(GtkWidget *vbox, gint n_launchers) { GtkWidget *table; table = gtk_table_new(2 * n_launchers, 2, FALSE /*non-homogeneous*/); gtk_table_set_col_spacings(GTK_TABLE(table), 2); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 2); return table; }voidgkrellm_gtk_config_launcher(GtkWidget *table, gint n, GtkWidget **launch_entry, GtkWidget **tooltip_entry, gchar *desc, GkrellmLauncher *launch) { GtkWidget *label, *hbox; gchar buf[64]; gint row; if (!table || !launch_entry) return; row = (tooltip_entry ? 2 : 1) * n; hbox = gtk_hbox_new(FALSE, 0); /* Attach left right top bottom */ gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, row, row + 1, GTK_FILL, GTK_SHRINK, 0, 0); snprintf(buf, sizeof(buf), _("%s command"), desc); label = gtk_label_new(buf); gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4); *launch_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(*launch_entry), 255); gtk_table_attach_defaults(GTK_TABLE(table), *launch_entry, 1, 2, row, row + 1); gtk_entry_set_text(GTK_ENTRY(*launch_entry), (launch && launch->command) ? launch->command : ""); if (tooltip_entry) { hbox = gtk_hbox_new(FALSE, 0); gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, row + 1, row + 2, GTK_FILL, GTK_SHRINK, 0, 0); label = gtk_label_new(_("comment")); gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4); *tooltip_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(*tooltip_entry), 255); gtk_table_attach_defaults(GTK_TABLE(table), *tooltip_entry, 1, 2, row + 1, row + 2); gtk_entry_set_text(GTK_ENTRY(*tooltip_entry), (launch && launch->tooltip_comment) ? launch->tooltip_comment : ""); } } /* FIXME: this guy is called on panels at create events | when this situation has occured: the GKrellM rebuild has destroyed | the decal button list. But existing launchers have not had their | button pointer set to NULL! This could cause a problem with | code that tries to check for button pointers in the create routines. */voidgkrellm_setup_launcher(GkrellmPanel *p, GkrellmLauncher *launch, gint type, gint pad) { if (!launch) return; if (!launch->command) launch->command = g_strdup(""); if (!launch->tooltip_comment) launch->tooltip_comment = g_strdup(""); launch->type = type; launch->pad = pad; if (p) { gkrellm_configure_tooltip(p, launch); if (*(launch->command)) launch->button = gkrellm_put_label_in_meter_button(p, gkrellm_launch_button_cb, launch, launch->pad); else launch->button = NULL; /* In case dangling pointer, see above */ } }voidgkrellm_setup_decal_launcher(GkrellmPanel *p, GkrellmLauncher *launch, GkrellmDecal *d) { if (!launch) return; if (!launch->command) launch->command = g_strdup(""); if (!launch->tooltip_comment) launch->tooltip_comment = g_strdup(""); launch->type = DECAL_LAUNCHER; launch->pad = 0; launch->decal = d; if (p)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -