Esempio n. 1
0
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));
}
Esempio n. 2
0
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);
}
///////////////////////////////////////////////////////////////////////////////////////////
// 
// 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_thaw(GTK_TEXT(widget));
	}
#endif
	
	return;
}// End freezeText
Esempio n. 4
0
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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;
}
Esempio n. 8
0
void gtkspell_check_all(GtkText *gtktext) {
	guint origpos;
	guint pos = 0;
	guint len;
	float adj_value;
	
	if (!gtkspell_running()) return;
	
	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);
}
Esempio n. 9
0
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;
}
Esempio n. 10
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");
}
Esempio n. 11
0
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));
}
Esempio n. 12
0
void
nh_message_putstr(const char *str)
{
    int i;
    int	len;
    char *buf;
    GtkText *t;
#ifdef FROZEN_INSERT
    static int	freeze_count=0;
#endif

    if (!message_text)
	return;

    t = GTK_TEXT(message_text);

    len = strlen(str);
    buf = (char *)alloc(len + 2);

    sprintf(buf, "\n%s", str);

#ifdef FROZEN_INSERT
    /* ALI: gimpwin 20001226 looks very bad if you update a text widget without
     * freezing it (the text is displayed half-scrolled, with lines overlapping
     * each other). This is not ideal (the text is redrawn each thaw), but it
     * is an improvement. Due to a bug in gimpwin we can't trim text if we've
     * frozen the widget, thus every so often we don't freeze but trim instead.
     */
    if (++freeze_count >= 50)	/* Trim text every 50 inserts */
	freeze_count = 0;
    else
	gtk_text_freeze(t);
#endif

    if (nh_status_in_trouble())
	i = CLR_RED;
    else
	i = MAP_BLACK;
    gtk_text_insert(t, NULL, &nh_color[i], &nh_color[MAP_WHITE], buf, len + 1);

    len = gtk_text_get_length(t);
#ifdef FROZEN_INSERT
    if (!freeze_count && len > NH_TEXT_REMEMBER) {
#else
    if (len > NH_TEXT_REMEMBER) {
#endif
	gtk_text_freeze(t);
	for(i = 0; i < len && len > NH_TEXT_REMEMBER; i++)
	    if (GTK_TEXT_INDEX(t, i) == '\n') {
		i++;
		gtk_text_set_point(t, i);
		gtk_text_backward_delete(t, i);
		len -= i;
	    }
	gtk_text_set_point(t, len);
	gtk_text_thaw(t);
    }
#ifdef FROZEN_INSERT
    /* ALI: t->vadj->upper would be more correct, but causes gimpwin to crash */
    if (freeze_count) {
	gtk_adjustment_set_value(t->vadj, t->vadj->upper - 1);
	gtk_text_thaw(t);
    }
#endif

    free(buf);
}

#endif	/* USE_TEXTVIEW */

int
GTK_doprev_message()
{
    return 0;
}

void
nh_message_destroy(void)
{
    message_text = NULL;
}
Esempio n. 13
0
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;
}
Esempio n. 14
0
int
nsWelcomeDlg::Show()
{
    int err = OK;
    if (!mShowDlg)
    {
       gCtx->ldlg->Show();
       return err;
    }
   
    char *readmeContents = NULL;

    XI_VERIFY(gCtx);
    XI_VERIFY(gCtx->notebook);

    if (mWidgetsInit == FALSE) // static widget init
    {
        // create a new table and add it as a page of the notebook
        mTable = gtk_table_new(1, 3, FALSE);
        gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook), mTable, NULL);
        mPageNum = gtk_notebook_get_current_page(GTK_NOTEBOOK(gCtx->notebook));
        // gtk_table_set_row_spacing(GTK_TABLE(mTable), 0, 0);
        gtk_table_set_col_spacing(GTK_TABLE(mTable), 1, 0);
        gtk_widget_show(mTable);

        // read the readme file contents into memory
        readmeContents = GetReadmeContents();
        if (!readmeContents)
        {
            err = ErrorHandler(E_EMPTY_README);
            goto BAIL;
        }

        // create a new scrollable textarea and add it to the table
#if defined(MOZ_WIDGET_GTK)
        GtkWidget *text = gtk_text_new(NULL, NULL);
        GdkFont *font = gdk_font_load( README_FONT );
        gtk_text_set_editable(GTK_TEXT(text), FALSE);
        gtk_table_attach(GTK_TABLE(mTable), text, 1, 2, 0, 1,
                       static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND),
                       static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND),
                       0, 0);
        gtk_text_freeze(GTK_TEXT(text));
        gtk_text_insert (GTK_TEXT(text), font, &text->style->black, NULL,
                       readmeContents, -1);
        gtk_text_thaw(GTK_TEXT(text));
        gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
        gtk_widget_show(text);

        // Add a vertical scrollbar to the GtkText widget 
        GtkWidget *vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
        gtk_table_attach(GTK_TABLE(mTable), vscrollbar, 2, 3, 0, 1, GTK_FILL,
                       static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_SHRINK | GTK_FILL),
                       0, 0);
        gtk_widget_show(vscrollbar);
#elif defined(MOZ_WIDGET_GTK2)
        GtkWidget *text = gtk_scrolled_window_new (NULL, NULL);
        GtkWidget *textview = gtk_text_view_new();
        GtkTextBuffer *textbuffer;

        textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
        gtk_text_buffer_set_text (textbuffer, readmeContents, -1);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (text),
                       GTK_POLICY_AUTOMATIC,
                       GTK_POLICY_AUTOMATIC);
        gtk_container_add (GTK_CONTAINER (text), textview);
        gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE);
        gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW(textview), FALSE);
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD);
        gtk_table_attach_defaults(GTK_TABLE(mTable), text, 1, 2, 0, 1);
        gtk_widget_show_all(text);
#endif

        mWidgetsInit = TRUE;
    }
    else
    {
        gtk_notebook_set_page(GTK_NOTEBOOK(gCtx->notebook), mPageNum);
        gtk_widget_show(mTable);
    }

    // signal connect the buttons
    gCtx->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked",
                   GTK_SIGNAL_FUNC(nsWelcomeDlg::Next), gCtx->wdlg);

    GTK_WIDGET_SET_FLAGS(gCtx->next, GTK_CAN_DEFAULT);
    gtk_widget_grab_default(gCtx->next);
    gtk_widget_grab_focus(gCtx->next);

    // show the Next button
    gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
    gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
    gtk_widget_show(gCtx->nextLabel);
    gtk_widget_show(gCtx->next);

BAIL:
    XI_IF_FREE(readmeContents);

    return err;
}
Esempio n. 15
0
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);       
}
Esempio n. 16
0
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));
        }
static gint
script_fu_cc_key_function (GtkWidget   *widget,
			   GdkEventKey *event,
			   gpointer     data)
{
  GList *list;
  int direction = 0;

  switch (event->keyval)
    {
    case GDK_Return:
      gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");

      if (script_fu_cc_is_empty ())
	return TRUE;

      list = g_list_nth (history, (g_list_length (history) - 1));
      if (list->data)
	g_free (list->data);
      list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc)));

      gtk_text_freeze (GTK_TEXT (cint.console));
      gtk_text_insert (GTK_TEXT (cint.console), cint.font_strong, NULL, NULL, "=> ", -1);
      gtk_text_insert (GTK_TEXT (cint.console), cint.font, NULL, NULL,
		       gtk_entry_get_text (GTK_ENTRY (cint.cc)), -1);
      gtk_text_insert (GTK_TEXT (cint.console), cint.font, NULL, NULL, "\n\n", -1);
      gtk_text_thaw (GTK_TEXT (cint.console));

      cint.vadj->value = cint.vadj->upper - cint.vadj->page_size;
      gtk_signal_emit_by_name (GTK_OBJECT (cint.vadj), "changed");

      gtk_entry_set_text (GTK_ENTRY (cint.cc), "");
      gdk_flush ();

      repl_c_string ((char *) list->data, 0, 0, 1);
      gimp_displays_flush ();

      history = g_list_append (history, NULL);
      if (history_len == history_max)
	{
	  history = g_list_remove (history, history->data);
	  if (history->data)
	    g_free (history->data);
	}
      else
	history_len++;
      history_cur = g_list_length (history) - 1;

      return TRUE;
      break;

    case GDK_KP_Up:
    case GDK_Up:
      gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
      direction = -1;
      break;

    case GDK_KP_Down:
    case GDK_Down:
      gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
      direction = 1;
      break;

    case GDK_P:
    case GDK_p:
      if (event->state & GDK_CONTROL_MASK)
	{
	  gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
	  direction = -1;
	}
      break;

    case GDK_N:
    case GDK_n:
      if (event->state & GDK_CONTROL_MASK)
	{
	  gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
	  direction = 1;
	}
      break;

    default:
      break;
    }

  if (direction)
    {
      /*  Make sure we keep track of the current one  */
      if (history_cur == g_list_length (history) - 1)
	{
	  list = g_list_nth (history, history_cur);
	  if (list->data)
	    g_free (list->data);
	  list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc)));
	}

      history_cur += direction;
      if (history_cur < 0)
	history_cur = 0;
      if (history_cur >= history_len)
	history_cur = history_len - 1;

      gtk_entry_set_text (GTK_ENTRY (cint.cc), (char *) (g_list_nth (history, history_cur))->data);

      return TRUE;
    }

  return FALSE;
}
Esempio n. 18
0
static void logbox_reload_single(GtkWidget *window, GtkWidget *text, char *default_text)
{
    FILE *handle;
    struct wave_logfile_lines_t *wlog_head=NULL, *wlog_curr=NULL;
    int wlog_size = 0;

    handle = fopen(default_text, "rb");
    if(!handle)
	{
	char *buf = malloc_2(strlen(default_text)+128);
	sprintf(buf, "Could not open logfile '%s'\n", default_text);
	status_text(buf);
	free_2(buf);
	return;
	}

#if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
    {
    GtkTextIter st_iter, en_iter;
  
    gtk_text_buffer_get_start_iter(GTK_TEXT_VIEW (text)->buffer, &st_iter);
    gtk_text_buffer_get_end_iter(GTK_TEXT_VIEW (text)->buffer, &en_iter);
    gtk_text_buffer_delete(GTK_TEXT_VIEW (text)->buffer, &st_iter, &en_iter);

    gtk_text_buffer_get_start_iter (GTK_TEXT_VIEW (text)->buffer, &GLOBALS->iter_logfile_c_2);
    }
#else
    {
    guint len = gtk_text_get_length(GTK_TEXT(text));
    gtk_text_set_point(GTK_TEXT(text), 0);

    gtk_text_freeze(GTK_TEXT(text)); 
    gtk_text_forward_delete (GTK_TEXT(text), len);
    }
#endif

    log_text_bold(text, NULL, "Click-select");
    log_text(text, NULL, " on numbers to jump to that time value in the wave viewer.\n");
    log_text(text, NULL, " \n");

    while(!feof(handle))
	{
	char *pnt = fgetmalloc(handle);
	if(pnt)
		{
		struct wave_logfile_lines_t *w = calloc_2(1, sizeof(struct wave_logfile_lines_t));

		wlog_size += (GLOBALS->fgetmalloc_len+1);
		w->text = pnt;
		if(!wlog_curr) { wlog_head = wlog_curr = w; } else { wlog_curr->next = w; wlog_curr = w; }
		}
	}

    if(wlog_curr)
	{
	struct wave_logfile_lines_t *w = wlog_head;
	struct wave_logfile_lines_t *wt;
	char *pnt = malloc_2(wlog_size + 1);
	char *pnt2 = pnt;

	while(w)
		{
		int len = strlen(w->text);
		memcpy(pnt2, w->text, len);
		pnt2 += len;
		*pnt2 = '\n';
		pnt2++;

		free_2(w->text);
		wt = w;
		w = w->next;
		free_2(wt);
		}
	/* wlog_head = */ wlog_curr = NULL; /* scan-build */
	*pnt2 = 0;
	log_text(text, GLOBALS->font_logfile_c_1, pnt);
	free_2(pnt);
	}

#if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
#else
    gtk_text_thaw(GTK_TEXT(text));
#endif

    fclose(handle);
}
Esempio n. 19
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(&note);
	    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);
    }
}
Esempio n. 20
0
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);
    }
  }
}