static void pattern_clist_sync_selection (void) { GSList *list; struct player_pattern *pp; if (current_row >= 0) { list = g_slist_nth (curplrs, current_row); pp = (struct player_pattern *) list->data; if (!GTK_WIDGET_REALIZED (comment_text)) gtk_widget_realize (comment_text); gtk_text_freeze (GTK_TEXT (comment_text)); gtk_text_set_point (GTK_TEXT (comment_text), 0); gtk_text_forward_delete (GTK_TEXT (comment_text), gtk_text_get_length (GTK_TEXT (comment_text))); gtk_text_set_point (GTK_TEXT (comment_text), 0); if (pp->comment) { gtk_text_insert (GTK_TEXT (comment_text), NULL, NULL, NULL, pp->comment, strlen (pp->comment)); gtk_text_set_point (GTK_TEXT (comment_text), 0); } gtk_text_set_editable (GTK_TEXT (comment_text), TRUE); gtk_text_thaw (GTK_TEXT (comment_text)); gtk_entry_set_text (GTK_ENTRY (pattern_entry), (pp->pattern)? pp->pattern : ""); gtk_entry_set_editable (GTK_ENTRY (pattern_entry), TRUE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_STRING], TRUE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_SUBSTR], TRUE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_REGEXP], TRUE); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (mode_buttons[pp->mode]), TRUE); gtk_widget_set_sensitive (delete_button, TRUE); gtk_widget_set_sensitive (up_button, TRUE); gtk_widget_set_sensitive (down_button, TRUE); } else { gtk_text_freeze (GTK_TEXT (comment_text)); gtk_text_set_point (GTK_TEXT (comment_text), 0); gtk_text_forward_delete (GTK_TEXT (comment_text), gtk_text_get_length (GTK_TEXT (comment_text))); gtk_text_set_editable (GTK_TEXT (comment_text), FALSE); gtk_text_thaw (GTK_TEXT (comment_text)); gtk_entry_set_text (GTK_ENTRY (pattern_entry), ""); gtk_entry_set_editable (GTK_ENTRY (pattern_entry), FALSE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_STRING], FALSE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_SUBSTR], FALSE); gtk_widget_set_sensitive (mode_buttons[PATTERN_MODE_REGEXP], FALSE); gtk_widget_set_sensitive (delete_button, FALSE); gtk_widget_set_sensitive (up_button, FALSE); gtk_widget_set_sensitive (down_button, FALSE); } }
void capture_start(GtkWidget *widget,gpointer data) { GtkWidget *isenable; uint8_t i = 0; guint text_len = 0; pthread_mutex_lock(&capture_state_mtx); if (capture_state == 0) capture_state = 1; pthread_mutex_unlock(&capture_state_mtx); init_file(); capture_packet(); pthread_mutex_lock(&packet_stat_mtx); tot_packet = 0; ip_packet = 0; tcp_packet = 0; udp_packet = 0; arp_packet = 0; icmp_packet = 0; igmp_packet = 0; capture_pre_packet = 0; pthread_mutex_unlock(&packet_stat_mtx); isenable = capture_menu[0].widget; gtk_widget_set_sensitive(isenable,FALSE); isenable = capture_menu[1].widget; gtk_widget_set_sensitive(isenable,TRUE); gtk_clist_clear((GtkCList *)clist); for (i = 0;i < 5;i++) { if (item[i]) { gtk_tree_item_remove_subtree((GtkTreeItem *)item[i]); gtk_container_remove (GTK_CONTAINER(tree), item[i]); item[i] = NULL; } } gtk_text_freeze(GTK_TEXT(hex_text)); text_len = gtk_text_get_length(GTK_TEXT(hex_text)); gtk_text_backward_delete(GTK_TEXT(hex_text),text_len); gtk_text_thaw(GTK_TEXT(hex_text)); gtk_text_freeze(GTK_TEXT(hex_text)); text_len = gtk_text_get_length(GTK_TEXT(hex_text)); gtk_text_backward_delete(GTK_TEXT(hex_text),text_len); gtk_text_thaw(GTK_TEXT(hex_text)); }
static void change_color(GtkText *gtktext, gint start, gint end, GdkColor *color) { gchar *newtext; /* So we don't need spaces at the very end of the text */ if ( end == gtk_text_get_length(GTK_TEXT(gtktext))+1 ) end--; newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end); gtk_text_freeze(gtktext); gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), GTK_SIGNAL_FUNC(entry_insert_cb), NULL); gtk_text_set_point(gtktext, start); gtk_text_forward_delete(gtktext, end-start); if (newtext && end-start > 0) gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start); gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), GTK_SIGNAL_FUNC(entry_insert_cb), NULL); gtk_text_thaw(gtktext); g_free(newtext); }
void on_save_ok_button_clicked(GtkButton * button, gpointer user_data) { GtkWidget *save_select; FILE *outfile; gchar *file, *text; save_select = gtk_widget_get_ancestor(GTK_WIDGET(button),GTK_TYPE_FILE_SELECTION); file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(save_select)); gtk_widget_hide(save_select); outfile = fopen(file,"w"); if(outfile == NULL) { fprintf(stderr,"IOL: couldn't open %s\n",file); gtk_widget_destroy(save_select); return; } gtk_widget_destroy(save_select); gtk_text_freeze(script_text); text = gtk_editable_get_chars(GTK_EDITABLE(script_text),0,-1); fprintf(outfile,"%s",text); fclose(outfile); g_free(text); gtk_text_thaw(script_text); }
void wxTextCtrl::DoFreeze() { if ( HasFlag(wxTE_MULTILINE) ) { gtk_text_freeze(GTK_TEXT(m_text)); } }
void gtkurl_check_all(GtkText *gtktext) { guint origpos; guint pos = 0; guint len; float adj_value; len = gtk_text_get_length(gtktext); adj_value = gtktext->vadj->value; gtk_text_freeze(gtktext); origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); while (pos < len) { while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos))) pos++; while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos))) pos++; if (pos > 0) check_at(gtktext, pos-1); } gtk_text_thaw(gtktext); gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); }
void on_iol_window_show(GtkWidget *widget, gpointer user_data) { char *hdir; char string[] = { "input red green blue alpha;\n\n#put your program here\n\noutput red green blue alpha;\n" }; script_text = GTK_TEXT(user_data); script_font = gdk_font_load("-*-courier-medium-r-normal-*-12-*-*-*-*-*-*-*"); gtk_text_freeze(script_text); gtk_text_insert(script_text,script_font,NULL,NULL,string,strlen(string)); gtk_text_thaw(script_text); stay_open = 0; hdir = getenv("IOL_SCRIPTS"); if(hdir == NULL) { fprintf(stderr,"IOL: $IOL_SCRIPTS environment variable not set, checking $HOME...\n"); hdir = getenv("HOME"); if(hdir == NULL) { fprintf(stderr,"IOL: $HOME environment variable not set\n"); strcpy(default_dir,"/usr"); } else { strncpy(default_dir,hdir,256); strncat(default_dir,"/.cinepaint/iol/",256); fprintf(stderr,"IOL: using %s as the default directory for scripts\n",default_dir); } } else { strncpy(default_dir,hdir,256); strncat(default_dir,"/",256); /* the file selection dialog needs it to end with a "/" so that it will know it's a directory we want */ } }
void on_load_ok_button_clicked(GtkButton *button, gpointer user_data) { GtkWidget *load_select; FILE *infile; char *filename; char text[512]; load_select = gtk_widget_get_ancestor(GTK_WIDGET(button),GTK_TYPE_FILE_SELECTION); filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(load_select)); gtk_widget_hide(load_select); infile = fopen(filename,"r"); if(infile == NULL) { fprintf(stderr,"IOL: can't open %s\n",filename); gtk_widget_destroy(load_select); return; } gtk_widget_destroy(load_select); gtk_text_freeze(script_text); /* since GTK+ (lamely) has no gtk_text_empty() or whatever, so we have to revert to kludges :( */ gtk_text_set_point(script_text,0); gtk_text_forward_delete(script_text,gtk_text_get_length(script_text)); while(fgets(text,512,infile) != NULL) gtk_text_insert(script_text,script_font,NULL,NULL,text,strlen(text)); fclose(infile); gtk_text_set_point(script_text,0); gtk_text_thaw(script_text); }
EXPORT void gtkTextFreeze( wText_p bt ) { #ifdef USE_TEXTVIEW gtk_text_view_set_editable( GTK_TEXT_VIEW(bt->text), FALSE ); #else gtk_text_freeze( GTK_TEXT (bt->text) ); #endif }
/////////////////////////////////////////////////////////////////////////////////////////// // // PRIVATE void freezeText(const gchar *pWidgetName, gboolean freeze) // IN : const gchar *pWidgetName : Widget name. // gboolean freeze : TRUE : Freeze widget. // FALSE : Thaw widget. // OUT : None. // RETURN : None. // PRIVATE void freezeText(const gchar *pWidgetName, gboolean freeze) { /*** Parameters start ***/ GtkWidget __attribute__ ((unused)) *widget = NULL; // Temporary pointer to widget. /*** Parameters end ***/ widget = lookupWidget(pWidgetName); #ifdef USE_GTK12 if (freeze == TRUE) { gtk_text_freeze(GTK_TEXT(widget)); } else { gtk_text_freeze(GTK_TEXT(widget)); } #endif return; }// End freezeText
int putmail (GtkWidget * widget) { synopsis *s; GtkCTreeNode *n; GtkWidget *from, *subj, *date, *recipt, *body; char *shtuff; if (widget != NULL) { n = gtk_ctree_node_nth (GTK_CTREE (widget), (&(GTK_CTREE (widget)->clist))->focus_row); s = (synopsis *) gtk_ctree_node_get_row_data (GTK_CTREE (widget), n); if (s) shtuff = (char *) db_read_body (s->id); else { printf ("synopsis for row %d is NULL!\n", (&(GTK_CTREE (widget)->clist))->focus_row); return FALSE; } } else { s = (synopsis *) malloc (sizeof (synopsis)); s->sender = strdup (" "); s->subject = strdup (" "); s->date = strdup (" "); s->sender = strdup (" "); shtuff = strdup (" "); } from = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (gems), "entry1"); date = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (gems), "entry2"); subj = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (gems), "entry3"); recipt = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (gems), "entry4"); body = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (gems), "text1"); gtk_entry_set_text (GTK_ENTRY (from), s->sender); gtk_entry_set_text (GTK_ENTRY (subj), s->subject); gtk_entry_set_text (GTK_ENTRY (date), s->date); gtk_text_freeze (GTK_TEXT (body)); gtk_text_set_point (GTK_TEXT (body), 0); gtk_text_forward_delete (GTK_TEXT (body), gtk_text_get_length (GTK_TEXT (body))); gtk_text_insert (GTK_TEXT (body), NULL, NULL, NULL, shtuff, -1); gtk_text_thaw (GTK_TEXT (body)); if (widget == NULL) { free (s); free (shtuff); } return TRUE; }
void on_toolbar_reply_clicked (GtkButton * UNUSED(button), gpointer UNUSED(user_data)) { synopsis *s; GtkCTreeNode *n; GtkWidget *from, *subj, *date, *recipt, *body, *comp, *widget; char *shtuff, buf[1024]; if ((widget = lookup_widget (gems, "mailbox")) == NULL) return; comp = create_compose (); from = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "entry1"); /* to = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "entry5"); */ date = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "entry2"); subj = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "entry6"); recipt = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "entry4"); body = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (comp), "text2"); n = gtk_ctree_node_nth (GTK_CTREE (widget), (&(GTK_CTREE (widget)->clist))->focus_row); s = (synopsis *) gtk_ctree_node_get_row_data (GTK_CTREE (widget), n); shtuff = replyify (s, (char *)db_read_body (s->id)); gtk_entry_set_text (GTK_ENTRY (from), s->sender); /* * if(!strncasecmp("re: ", s->subject, 4)) */ if (tolower (s->subject[0]) == 'r' && tolower (s->subject[1]) == 'e' && s->subject[2] == ':' && s->subject[3] == ' ') sprintf (buf, "%s", s->subject); else sprintf (buf, "Re: %s", s->subject); gtk_entry_set_text (GTK_ENTRY (subj), buf); gtk_entry_set_text (GTK_ENTRY (date), s->date); gtk_text_freeze (GTK_TEXT (body)); gtk_text_set_point (GTK_TEXT (body), 0); gtk_text_forward_delete (GTK_TEXT (body), gtk_text_get_length (GTK_TEXT (body))); gtk_text_insert (GTK_TEXT (body), NULL, NULL, NULL, shtuff, -1); gtk_text_thaw (GTK_TEXT (body)); if (widget == NULL) { free (s); free (shtuff); } gtk_text_set_editable (GTK_TEXT (body), TRUE); gtk_widget_show (comp); return; }
/* 텍스트 몇개를 텍스트 widget에 더한다. - 아래 함수는 우리의 윈도가 realize 될 때 불리는 callback이다. gtk_widget_realize로 realize되도록 강제할 수도 있지만 그건 먼저 계층구조의 한 부분이 되어야 할 것이다. */ void realize_text (GtkWidget *text, gpointer data) { gtk_text_freeze (GTK_TEXT (text)); gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, "From: [email protected]\n" "To: [email protected]\n" "Subject: Made it!\n" "\n" "We just got in this morning. The weather has been\n" "great - clear but cold, and there are lots of fun sights.\n" "Sojourner says hi. See you soon.\n" " -Path\n", -1); gtk_text_thaw (GTK_TEXT (text)); }
void gtkspell_uncheck_all(GtkText *gtktext) { int origpos; char *text; float adj_value; adj_value = gtktext->vadj->value; gtk_text_freeze(gtktext); origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1); gtk_text_set_point(gtktext, 0); gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext)); gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text)); gtk_text_thaw(gtktext); gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); gtk_adjustment_set_value(gtktext->vadj, adj_value); }
static GtkWidget *server_comment_page (struct server *s) { GtkWidget *page_vbox; GtkWidget *scrollwin; struct server_props *props; int sucks = 0; char* comment = NULL; props = properties (s); if (props) { sucks = props->sucks; comment = props->comment; } page_vbox = gtk_vbox_new (FALSE, 4); gtk_container_set_border_width (GTK_CONTAINER (page_vbox), 8); sucks_check_button = gtk_check_button_new_with_label (_("This server sucks")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sucks_check_button), sucks); gtk_box_pack_start (GTK_BOX (page_vbox), sucks_check_button, FALSE, FALSE, 0); gtk_widget_show (sucks_check_button); scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (page_vbox), scrollwin, TRUE, TRUE, 0); comment_text = gtk_text_new (NULL, NULL); // gtk_widget_set_usize (comment_text, -1, 80); gtk_container_add (GTK_CONTAINER (scrollwin), comment_text); gtk_widget_show (comment_text); gtk_text_freeze (GTK_TEXT (comment_text)); if (comment) { gtk_text_insert (GTK_TEXT (comment_text), NULL, NULL, NULL, comment, strlen (comment)); gtk_text_set_point (GTK_TEXT (comment_text), 0); } gtk_text_set_editable (GTK_TEXT (comment_text), TRUE); gtk_text_thaw (GTK_TEXT (comment_text)); gtk_widget_show (scrollwin); gtk_widget_show (page_vbox); return page_vbox; }
static void change_color(GtkText *gtktext, int start, int end, GdkColor *color) { char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end); gtk_text_freeze(gtktext); gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), GTK_SIGNAL_FUNC(entry_insert_cb), NULL); gtk_text_set_point(gtktext, start); gtk_text_forward_delete(gtktext, end-start); if (newtext && end-start > 0) gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start); gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), GTK_SIGNAL_FUNC(entry_insert_cb), NULL); gtk_text_thaw(gtktext); g_free(newtext); }
static void replace_word(GtkWidget *w, gpointer d) { int start, end; char *newword; char buf[BUFSIZE]; /* we don't save their position, * because the cursor is moved by the click. */ gtk_text_freeze(GTK_TEXT(d)); gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword); get_curword(GTK_TEXT(d), buf, &start, &end); gtk_text_set_point(GTK_TEXT(d), end); gtk_text_backward_delete(GTK_TEXT(d), end-start); gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, strlen(newword)); gtk_text_thaw(GTK_TEXT(d)); }
static void set_text_buffer(GtkWidget *widget, const char *text) { GtkText *buffer; g_return_if_fail(widget); g_return_if_fail(text); buffer = GTK_TEXT(widget); g_return_if_fail(buffer); gtk_text_freeze(buffer); gtk_text_set_point(buffer, 0); gtk_text_forward_delete(buffer, gtk_text_get_length(buffer)); gtk_text_set_point(buffer, 0); gtk_text_insert(buffer, NULL, NULL, NULL, lazy_utf8_to_ui_string(text), (-1)); gtk_text_thaw(buffer); }
void clear_text_page(gboolean add, gint *uncommitted) { guint len; gint ucm; ucm = *uncommitted; gtk_entry_set_text(GTK_ENTRY(sp->title_entry), ""); if (add == TRUE) { time_label_set_time(TIME_LABEL(sp->tlabel_created), time(NULL)); } else { time_label_set_time(TIME_LABEL(sp->tlabel_created), -1); } time_label_set_time(TIME_LABEL(sp->tlabel_changed), -1); if (add == TRUE) { gtk_label_set_text(GTK_LABEL(sp->label_changes), _("0")); } else { gtk_label_set_text(GTK_LABEL(sp->label_changes), ""); } time_label_set_time(TIME_LABEL(sp->tlabel_expire), -1); gtk_entry_set_text(GTK_ENTRY(sp->note_id_entry), ""); gnome_date_edit_set_time(GNOME_DATE_EDIT(sp->de_deadline), 0); gtk_entry_set_text(GTK_ENTRY(sp->prio_entry), ""); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(sp->todo_check), FALSE); gtk_adjustment_set_value(GTK_ADJUSTMENT(sp->ad_complete), 0); len = gtk_text_get_length(GTK_TEXT(sp->text_entry)); if (len) { gtk_text_freeze(GTK_TEXT(sp->text_entry)); gtk_text_set_point(GTK_TEXT(sp->text_entry), 0); gtk_text_forward_delete(GTK_TEXT(sp->text_entry), len); gtk_text_thaw(GTK_TEXT(sp->text_entry)); } *uncommitted = ucm; }
void on_go_button_clicked(GtkButton *button, gpointer user_data) { GtkWidget *window; gchar *text; window = (GtkWidget *)user_data; gtk_text_freeze(script_text); text = gtk_editable_get_chars(GTK_EDITABLE(script_text),0,-1); input_size = strlen((char *)text); iol_input = (char *)malloc(input_size + 1); if(iol_input == NULL) { dialog_status = 0; fprintf(stderr,"IOL error: callbacks.c: insufficient memory\n"); gtk_widget_destroy(window); gtk_main_quit(); return; } strncpy(iol_input, text, input_size); iol_input[input_size] = 0; iol_input_ptr = iol_input; iol_input_lim = (unsigned int)iol_input + input_size; g_free(text); gtk_text_thaw(script_text); if(!stay_open) { gtk_widget_destroy(window); gtk_main_quit(); } if(iol_process()) dialog_status = 0; else dialog_status = 1; }
void SendData (int istype, char *ssenddata) { if (istype == 1) { sprintf (sendline, "%s\n", ssenddata); } else { sprintf (sendline, "%s\n", gtk_entry_get_text (GTK_ENTRY (internetentry))); gtk_entry_set_text (GTK_ENTRY (internetentry), ""); } n = strlen (sendline); if (send (sockfd, sendline, n, 0) != n) { Message ("A send error has occured.", 3, 0); } gtk_text_freeze (GTK_TEXT (text)); gtk_text_insert (GTK_TEXT (text), fixed_font, &color, NULL, sendline, -1); gtk_text_thaw (GTK_TEXT (text)); gtk_adjustment_set_value (adj, adj->upper - adj->lower - adj->page_size); }
static gboolean script_fu_siod_read (GIOChannel *channel, GIOCondition cond, gpointer data) { int count; static int hack = 0; GIOError error; count = 0; error = g_io_channel_read (channel, read_buffer, BUFSIZE - 1, &count); if (error == G_IO_ERROR_NONE) { #ifndef G_OS_WIN32 /* Is this needed any longer on Unix? */ if (!hack) /* this is a stupid hack, but as of 10/27/98 * the script-fu-console will hang on my system without it. * the real cause of this needs to be tracked down. * posibly a problem with the text widget, or the * signal handlers not getting fully initialized or... * no reports of hangs on other platforms, could just be a * problem with my system. */ { hack = 1; return TRUE; } #endif read_buffer[count] = '\0'; gtk_text_freeze (GTK_TEXT (cint.console)); gtk_text_insert (GTK_TEXT (cint.console), cint.font_weak, NULL, NULL, read_buffer, -1); gtk_text_thaw (GTK_TEXT (cint.console)); script_fu_console_scroll_end (NULL); } return TRUE; }
void nk_load_file(NKEdit *doc, gchar *filename) { FILE *infile; gchar buffer[READ_BUFFER_SIZE]; gint nchars; #ifdef NK_DEBUG # printf("nk_load_file\n"); #endif if((infile = fopen(filename, "r")) == NULL) { fclose(infile); return; } nk_text_clean(NULL, doc); gtk_widget_realize(doc->text); gtk_text_freeze(GTK_TEXT(doc->text)); while (1) { nchars = fread(buffer, 1, READ_BUFFER_SIZE, infile); gtk_text_insert(GTK_TEXT(doc->text), NULL, NULL, NULL, buffer, nchars); if (nchars < READ_BUFFER_SIZE) break; } fclose(infile); gtk_text_set_point(GTK_TEXT(doc->text), 0); gtk_text_thaw(GTK_TEXT(doc->text)); g_snprintf(doc->filename, sizeof(doc->filename),filename); check_write_mode(doc, TRUE); return; }
void selection_received (GtkWidget *widget, GtkSelectionData *data) { int position; int i; SelType seltype; char *str; if (data->length < 0) { g_print("Error retrieving selection\n"); return; } seltype = SEL_TYPE_NONE; for (i=0; i<LAST_SEL_TYPE; i++) { if (seltypes[i] == data->type) { seltype = i; break; } } if (seltype == SEL_TYPE_NONE) { char *name = gdk_atom_name (data->type); g_print("Don't know how to handle type: %s\n", name?name:"<unknown>"); return; } if (selection_string != NULL) g_string_free (selection_string, TRUE); selection_string = g_string_new (NULL); gtk_text_freeze (GTK_TEXT (selection_text)); gtk_text_set_point (GTK_TEXT (selection_text), 0); gtk_text_forward_delete (GTK_TEXT (selection_text), gtk_text_get_length (GTK_TEXT (selection_text))); position = 0; while (position < data->length) { switch (seltype) { case ATOM: str = stringify_atom (data->data, &position); break; case COMPOUND_TEXT: case STRING: case TEXT: str = stringify_text (data->data, &position); break; case BITMAP: case DRAWABLE: case PIXMAP: case WINDOW: case COLORMAP: str = stringify_xid (data->data, &position); break; case INTEGER: case PIXEL: str = stringify_integer (data->data, &position); break; case SPAN: str = stringify_span (data->data, &position); break; default: { char *name = gdk_atom_name (data->type); g_print("Can't convert type %s to string\n", name?name:"<unknown>"); position = data->length; continue; } } gtk_text_insert (GTK_TEXT (selection_text), NULL, &selection_text->style->black, NULL, str, -1); gtk_text_insert (GTK_TEXT (selection_text), NULL, &selection_text->style->black, NULL, "\n", -1); g_string_append (selection_string, str); g_free (str); } gtk_text_thaw (GTK_TEXT (selection_text)); }
void Help (void) { if ((ifilestuff == 0) && ((biscomputer == 0) || (wiscomputer == 0)) && (iyesno == 0)) { helpwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (helpwindow), "help"); gtk_signal_connect (GTK_OBJECT (helpwindow), "delete_event", GTK_SIGNAL_FUNC (DestroyHelp), NULL); gtk_window_set_policy (GTK_WINDOW (helpwindow), 0, 0, 1); gtk_container_border_width (GTK_CONTAINER (helpwindow), 0); gtk_widget_realize (helpwindow); helpbox1 = gtk_vbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (helpbox1), 0); gtk_container_add (GTK_CONTAINER (helpwindow), helpbox1); gtk_widget_show (helpbox1); helpbox2 = gtk_hbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (helpbox2), 0); gtk_box_pack_start (GTK_BOX (helpbox1), helpbox2, TRUE, TRUE, 5); gtk_widget_show (helpbox2); helpbox3 = gtk_vbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (helpbox3), 0); gtk_box_pack_start (GTK_BOX (helpbox2), helpbox3, TRUE, TRUE, 0); gtk_widget_show (helpbox3); helptable1 = gtk_table_new (2, 1, FALSE); gtk_widget_show (helptable1); gtk_box_pack_start (GTK_BOX (helpbox3), helptable1, TRUE, TRUE, 0); helptable2 = gtk_table_new (1, 3, FALSE); gtk_widget_show (helptable2); gtk_box_pack_start (GTK_BOX (helpbox3), helptable2, TRUE, TRUE, 0); texth = gtk_text_new (NULL, NULL); gtk_widget_set_usize (texth, 535, 266); gtk_text_set_editable (GTK_TEXT (texth), FALSE); gtk_table_attach (GTK_TABLE (helptable1), texth, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 0); gtk_widget_show (texth); vscrollbarh = gtk_vscrollbar_new (GTK_TEXT (texth)->vadj); gtk_table_attach (GTK_TABLE (helptable1), vscrollbarh, 1, 2, 0, 1, GTK_FILL, GTK_EXPAND | GTK_FILL, 5, 0); gtk_widget_show (vscrollbarh); gtk_widget_realize (texth); wrapcheckh = gtk_check_button_new_with_label ("wrap"); gtk_table_attach (GTK_TABLE (helptable2), wrapcheckh, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 5, 10); gtk_signal_connect (GTK_OBJECT (wrapcheckh), "toggled", GTK_SIGNAL_FUNC (ToggleWrapH), texth); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (wrapcheckh), FALSE); gtk_widget_show (wrapcheckh); helpsep = gtk_hseparator_new (); gtk_table_attach (GTK_TABLE (helptable2), helpsep, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (helpsep); #ifdef USE_GNOME helpbutton = gnome_stock_button (GNOME_STOCK_BUTTON_CLOSE); #else helpbutton = gtk_button_new_with_label ("Close"); #endif gtk_signal_connect (GTK_OBJECT (helpbutton), "clicked", GTK_SIGNAL_FUNC (DestroyHelp), NULL); GTK_WIDGET_SET_FLAGS (helpbutton, GTK_CAN_DEFAULT); gtk_window_set_default (GTK_WINDOW (helpwindow), helpbutton); gtk_table_attach (GTK_TABLE (helptable2), helpbutton, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 2, 2); gtk_widget_show (helpbutton); gtk_text_freeze (GTK_TEXT (texth)); ihelpdes = open (PKGDATADIR"help/README", O_RDONLY, 0600); if (ihelpdes == -1) { Message ("Could not open README file.", 3, 0); } else { while (1) { nchars = read (ihelpdes, buffer, 1024); gtk_text_insert (GTK_TEXT (texth), fixed_font, NULL, NULL, buffer, nchars); if (nchars < 1024) { break; } } } close (ihelpdes); gtk_text_thaw (GTK_TEXT (texth)); gtk_widget_show (helpwindow); iyesno = 1; if (ichangestuff == 0) { Play ("open.mp3", 0); } } else { if (ichangestuff == 0) { Play ("click.mp3", 0); } } }
static void handle_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 tt; int minutes,seconds; char local_string[20]; GtkObject *adj; gtk_pipe_int_read(&tt); seconds=max_sec=tt/play_mode->rate; 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 */ 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. */ #ifdef HAVE_GTK_2 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); gtk_text_buffer_get_start_iter(textbuf, &start_iter); gtk_text_buffer_get_end_iter(textbuf, &end_iter); iter = start_iter; #else 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)); #endif } break; case FILE_LIST_MESSAGE: { gchar filename[255], *fnames[2]; gint i, number_of_files; /* 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; 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]; #ifdef HAVE_GTK_2 gchar *message_u8; #endif gtk_pipe_int_read(&type); gtk_pipe_string_read(message); #ifdef HAVE_GTK_2 message_u8 = g_locale_to_utf8( message, -1, NULL, NULL, NULL ); gtk_text_buffer_get_bounds(textbuf, &start_iter, &end_iter); gtk_text_buffer_insert(textbuf, &end_iter, message_u8, -1); gtk_text_buffer_insert(textbuf, &end_iter, "\n", 1); gtk_text_buffer_get_bounds(textbuf, &start_iter, &end_iter); mark = gtk_text_buffer_create_mark(textbuf, NULL, &end_iter, 1); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text), mark, 0.0, 0, 0.0, 1.0); gtk_text_buffer_delete_mark(textbuf, mark); g_free( message_u8 ); #else gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, message, -1); gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, "\n", 1); #endif } break; case LYRIC_MESSAGE: { char message[1000]; #ifdef HAVE_GTK_2 gchar *message_u8; #endif gtk_pipe_string_read(message); #ifdef HAVE_GTK_2 message_u8 = g_locale_to_utf8( message, -1, NULL, NULL, NULL ); gtk_text_buffer_get_bounds(textbuf, &start_iter, &end_iter); // mod JN iter -> end_iter gtk_text_buffer_insert(textbuf, &end_iter, message_u8, -1); gtk_text_buffer_get_bounds(textbuf, &start_iter, &end_iter); mark = gtk_text_buffer_create_mark(textbuf, NULL, &end_iter, 1); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text), mark, 0.0, 0, 0.0, 1.0); gtk_text_buffer_delete_mark(textbuf, mark); #else gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, message, -1); #endif } break; default: g_warning("UNKNOWN Gtk+ MESSAGE %i", message); } }
gint display_about_dbox() { GtkWidget *dbox; gpointer user_data; FILE *fd; gchar buffer[MAXCHARS]; GdkFont *fixed_font; GtkWidget *text; gchar tempstr[MAXCHARS]; dbox = create_about_dbox(); /* Set text */ user_data = gtk_object_get_data(GTK_OBJECT(dbox), "text1"); text = GTK_WIDGET(user_data); gtk_text_freeze(GTK_TEXT (text)); gtk_editable_delete_text(GTK_EDITABLE(text), 0, -1); strcpy(buffer, inst_paths.base_dir); // retrieve base path strcat(buffer, SHARE_DIR); // strcat(buffer, DIR_SEPARATOR); #if defined(__LINUX__) strcat(buffer, "COPYING"); #elif defined(__WIN32__) strcat(buffer, "Copying.txt"); #endif if(access(buffer, F_OK) == 0 ) { #if defined(__LINUX__) fixed_font = gdk_font_load ("-misc-clean-medium-r-*-*-*-140-*-*-*-*-*-*"); #elif defined(__WIN32__) fixed_font = gdk_font_load ("-adobe-courier-medium-r-normal--12-120-75-75-p-70-iso8859-1"); #endif if( (fd=fopen (buffer, "r")) != NULL) { memset (buffer, 0, sizeof(buffer)); while(fread (buffer, 1, sizeof(buffer)-1, fd)) { process_buffer(buffer); gtk_text_insert (GTK_TEXT (text), fixed_font, NULL, NULL, buffer, strlen (buffer)); memset (buffer, 0, sizeof(buffer)); } fclose (fd); } } gtk_text_thaw(GTK_TEXT (text)); /* Set label */ user_data = gtk_object_get_data(GTK_OBJECT(dbox), "label5"); #ifdef HAVE_LIBTIFFEP g_snprintf(tempstr, sizeof(tempstr), "* TILP version %s (cable=%s, tiffep=%s)", GTKTIEMU_VERSION, ticable_get_version(), tiffep_get_version()); #else g_snprintf(tempstr, sizeof(tempstr), "* TILP version %s (%s %s)", GTKTIEMU_VERSION, ticable_get_version(), "NA"); #endif gtk_label_set_text(GTK_LABEL(user_data), tempstr); /* Set pixmap */ user_data = gtk_object_get_data(GTK_OBJECT(dbox), "pixmap2"); #if 0 /* buggy code -- avoid segfault ... */ GtkWidget *tmp_pixmapwid = GTK_WIDGET(user_data); GdkPixmap *pixmap; GdkBitmap *mask; GtkStyle *style; FILE *f; gchar buffer[MAXCHARS]; return; /* Create the base filename */ strcpy(buffer, inst_paths.base_dir); // retrieve base path strcat(buffer, SHARE_DIR); // strcat(buffer, DIR_SEPARATOR); #if defined(__LINUX__) strcat(buffer, "logo.jpg"); #elif defined(__WIN32__) strcat(buffer, "logo.jpg"); #endif DISPLAY("logo: <%s>\n", buffer); /* Try to access the file */ if(access(buffer, F_OK) == 0 ) { /* Open and load file */ f = fopen(buffer, "rb"); if(f == NULL) g_error("Unable to open the logo (logo.jpg).\n"); img.depth = 3; // > 2 colors read_jpg_format(f, &img); fclose(f); convert_bytemap_to_pixmap(&img); style = gtk_widget_get_style(widget); pixmap = gdk_pixmap_create_from_xpm_d(widget->window, &mask, &style->bg[GTK_STATE_NORMAL], (gchar **)(img.pixmap)); gtk_pixmap_set(GTK_PIXMAP(tmp_pixmapwid), pixmap, mask); } else g_warning("Unable to open the logo (logo.jpg).\n"); #endif gtk_widget_show_all(dbox); return 0; }
static void cb_encrypt(GtkWidget *w, gpointer p) { GtkWidget *pass_entry; GtkWidget *warn_w; FILE *pgpin; FILE *pgpout; FILE *pgperr; static gchar sys_buf[] = "pgpe -catfq +batchmode"; gchar tmpbuf[1024]; note_data *note; g_return_if_fail(p != NULL); g_return_if_fail(GNOME_IS_DIALOG(p)); if (selected_node == NULL) { warn_w = gnome_warning_dialog_parented( _("Select a note first!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } ask_commit_changes(); note = (note_data *) gtk_ctree_node_get_row_data( GTK_CTREE(note_tree), GTK_CTREE_NODE(selected_node)); if (!note->text || !strlen(note->text)) { warn_w = gnome_warning_dialog_parented(_("Nothing to encrypt!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } pass_entry = gtk_object_get_user_data(GTK_OBJECT(p)); setenv("PGPPASSFD", "0", 1); run_pgp(sys_buf, &pgpin, &pgpout, &pgperr); /*Execute PGP*/ if(pgpin && pgpout) { fprintf(pgpin, "%s\n", gtk_entry_get_text(GTK_ENTRY(pass_entry))); /*Output buffer to PGP:*/ fwrite(note->text, sizeof(gchar), strlen(note->text), pgpin); fclose(pgpin); gtk_text_freeze(GTK_TEXT(text_entry)); gtk_editable_delete_text(GTK_EDITABLE(text_entry), 0, gtk_text_get_length(GTK_TEXT(text_entry))); /*Now, read the result back from PGP:*/ do { fgets(tmpbuf, sizeof(tmpbuf), pgpout); if (!feof(pgpout)) { gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL, tmpbuf, strlen(tmpbuf)); } } while (!feof(pgpout)); gtk_text_thaw(GTK_TEXT(text_entry)); fclose(pgpout); } unsetenv("PGPPASSFD"); }
static void cb_decrypt(GtkWidget *w, gpointer p) { GtkWidget *pass_entry; GtkWidget *warn_w; FILE *pgpin; FILE *pgpout; FILE *pgperr; static gchar sys_buf[] = "pgpv -qzd +batchmode +force -o - %s"; gchar tmpbuf[1024]; gchar *tmpfname; gchar *tmpcmd; note_data *note; pid_t pgp_pid; gint fd; g_return_if_fail(p != NULL); g_return_if_fail(GNOME_IS_DIALOG(p)); if (selected_node == NULL) { warn_w = gnome_warning_dialog_parented( _("Select a note first!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } ask_commit_changes(); note = (note_data *) gtk_ctree_node_get_row_data( GTK_CTREE(note_tree), GTK_CTREE_NODE(selected_node)); if (!note->text || !strlen(note->text)) { warn_w = gnome_warning_dialog_parented(_("Nothing to decrypt!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } tmpfname = tmpnam(NULL); if (tmpfname == NULL) { warn_w = gnome_warning_dialog_parented(_("Can't create tmp filename!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } fd = safe_open(tmpfname, O_CREAT | O_EXCL | O_WRONLY); if (fd == -1) { warn_w = gnome_warning_dialog_parented(_("Can't open tmp file!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); return; } write(fd, note->text, strlen(note->text)); close(fd); tmpcmd = g_strdup_printf(sys_buf, tmpfname); pass_entry = gtk_object_get_user_data(GTK_OBJECT(p)); setenv("PGPPASSFD", "0", 1); pgp_pid = run_pgp(tmpcmd, &pgpin, &pgpout, &pgperr); if (pgp_pid == -1) { warn_w = gnome_warning_dialog_parented(_("Error while running pgp!"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); unsetenv("PGPPASSFD"); unlink(tmpfname); g_free(tmpcmd); return; } if (pgpin && pgpout) { fprintf(pgpin, "%s\n", gtk_entry_get_text(GTK_ENTRY(pass_entry))); fwrite(note->text, sizeof (gchar), strlen(note->text), pgpin); fclose(pgpin); gtk_text_freeze(GTK_TEXT(text_entry)); gtk_editable_delete_text(GTK_EDITABLE(text_entry), 0, gtk_text_get_length(GTK_TEXT(text_entry))); do { fgets(tmpbuf, sizeof (tmpbuf), pgpout); if (!feof(pgpout)) { gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL, tmpbuf, strlen(tmpbuf)); } } while (!feof(pgpout)); gtk_text_thaw(GTK_TEXT(text_entry)); fclose(pgpout); fclose(pgperr); if ((gtk_text_get_length(GTK_TEXT(text_entry)) == 0) && note->text) { warn_w = gnome_warning_dialog_parented(_("Pgp didn't return any\ text. Maybe your're using the wrong password?"), yank_root_win(NULL)); gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE); gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL, note->text, strlen(note->text)); }
int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *box1; GtkWidget *box2; GtkWidget *hbox; GtkWidget *button; GtkWidget *check; GtkWidget *separator; GtkWidget *table; GtkWidget *vscrollbar; GtkWidget *text; GdkColormap *cmap; GdkColor color; GdkFont *fixed_font; FILE *infile; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (window, 600, 500); gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, FALSE); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(close_application), NULL); gtk_window_set_title (GTK_WINDOW (window), "Text Widget Example"); gtk_container_set_border_width (GTK_CONTAINER (window), 0); box1 = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), box1); gtk_widget_show (box1); box2 = gtk_vbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show (box2); table = gtk_table_new (2, 2, FALSE); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2); gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2); gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0); gtk_widget_show (table); /* Create the GtkText widget */ text = gtk_text_new (NULL, NULL); gtk_text_set_editable (GTK_TEXT (text), TRUE); gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (text); /* Add a vertical scrollbar to the GtkText widget */ vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj); gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1, GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (vscrollbar); /* Get the system color map and allot the color red */ cmap = gdk_colormap_get_system(); color.red = 0xffff; color.green = 0; color.blue = 0; if (!gdk_color_allot(cmap, &color)) { g_error("couldn't allot color"); } /* Load a fixed font */ fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*"); /* Realizing a widget creates a window for it, * * ready for us to insert some text */ gtk_widget_realize (text); /* Freeze the text widget, ready for multiple updates */ gtk_text_freeze (GTK_TEXT (text)); /* Insert some colored text */ gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, "Supports ", -1); gtk_text_insert (GTK_TEXT (text), NULL, &color, NULL, "colored ", -1); gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, "text and different ", -1); gtk_text_insert (GTK_TEXT (text), fixed_font, &text->style->black, NULL, "fonts\n\n", -1); /* Load the file text.c into the text window */ infile = fopen("text.c", "r"); if (infile) { char buffer[1024]; int nchars; while (1) { nchars = fread(buffer, 1, 1024, infile); gtk_text_insert (GTK_TEXT (text), fixed_font, NULL, NULL, buffer, nchars); if (nchars < 1024) break; } fclose (infile); } /* Thaw the text widget, allowing the updates to become visible */ gtk_text_thaw (GTK_TEXT (text)); hbox = gtk_hbutton_box_new (); gtk_box_pack_start (GTK_BOX (box2), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); check = gtk_check_button_new_with_label("Editable"); gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0); gtk_signal_connect (GTK_OBJECT(check), "toggled", GTK_SIGNAL_FUNC(text_toggle_editable), text); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE); gtk_widget_show (check); check = gtk_check_button_new_with_label("Wrap Words"); gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); gtk_signal_connect (GTK_OBJECT(check), "toggled", GTK_SIGNAL_FUNC(text_toggle_word_wrap), text); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), FALSE); gtk_widget_show (check); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); gtk_widget_show (separator); box2 = gtk_vbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); gtk_widget_show (box2); button = gtk_button_new_with_label ("close"); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(close_application), NULL); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); gtk_widget_set_flags (button, GTK_CAN_DEFAULT); gtk_widget_grab_default (button); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return(0); }