Exemple #1
0
void ghack_menu_window_put_string(GtkWidget *menuWin, int attr,
                                  const char* text, gpointer data)
{
    GnomeLess *gless;
    MenuWinType isMenu;

    if (text == NULL)
        return;
    
    isMenu = (MenuWinType) GPOINTER_TO_INT
    	(gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu"));

    if (isMenu == MenuText) {
      gless = GNOME_LESS (gtk_object_get_data (GTK_OBJECT (menuWin), "gless"));
      g_assert (gless != NULL);
      g_assert (gless->text != NULL);
      g_assert (GTK_IS_TEXT (gless->text));

      /* Don't bother with attributes yet */
      gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, text, -1);
      gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1);

    }

    else if (isMenu == MenuUnknown) {
      isMenu = MenuText;
      gtk_object_set_data (GTK_OBJECT (menuWin), "isMenu",
      			   GINT_TO_POINTER (isMenu));

      gtk_widget_set_usize (GTK_WIDGET (menuWin), 500, 400);
      gtk_window_set_policy (GTK_WINDOW (menuWin), TRUE, TRUE, FALSE);
    
      gless = GNOME_LESS (gnome_less_new ());
      g_assert (gless != NULL);
      gtk_object_set_data (GTK_OBJECT (menuWin), "gless", gless);
      gtk_widget_show (GTK_WIDGET (gless));

      gnome_less_show_string (gless, text);
      gtk_text_insert (GTK_TEXT (gless->text), NULL, NULL, NULL, "\n", -1);

      gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (menuWin)->vbox),
      			  GTK_WIDGET (gless), TRUE, TRUE, 0);
    }
}
Exemple #2
0
/* Display the file named str.  Complain about missing files
                   iff complain is TRUE.
*/
void gnome_display_file(const char *filename,BOOLEAN_P must_exist)
{
	/* Strange -- for some reason it makes us create a new text window
	 * instead of reusing any existing ones -- perhaps we can work out
	 * some way to reuse stuff -- but for now just make and destroy new
	 * ones each time */
        
	dlb *f;
       
        f = dlb_fopen(filename, "r");
        if (!f) {
	  if (must_exist) {
	    GtkWidget *box;
            char message[90];
            sprintf(message, "Warning! Could not find file: %s\n",filename);

	    box = gnome_message_box_new (_(message),
		    GNOME_MESSAGE_BOX_ERROR,
		    GNOME_STOCK_BUTTON_OK,
		    NULL);
	    gnome_dialog_set_default( GNOME_DIALOG(box), 0);
	    gnome_dialog_set_parent (GNOME_DIALOG (box), 
		    GTK_WINDOW (ghack_get_main_window ()) );
	    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
	    gtk_widget_show (box);
	  }
        }
	else {
    	  GtkWidget *txtwin, *gless, *frametxt;
#define LLEN 128
	  char line[LLEN], *textlines;
	  int num_lines, charcount;

	  txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK,
				    NULL);
          gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400);
          gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE);
          gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window");
	  gnome_dialog_set_default( GNOME_DIALOG(txtwin), 0);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  frametxt = gtk_frame_new ("");
	  gtk_widget_show (frametxt);

	  /*
	   * Count the number of lines and characters in the file.
	   */
	  num_lines = 0;
	  charcount = 1;
	  while (dlb_fgets(line, LLEN, f)) {
	    num_lines++;
	    charcount += strlen(line);
	  }
	  (void) dlb_fclose(f);
	  
	  /* Ignore empty files */
	  if (num_lines == 0) return;

	  /*
	   * Re-open the file and read the data into a buffer.  
	   */
	  textlines = (char *) alloc((unsigned int) charcount);
	  textlines[0] = '\0';
	  f = dlb_fopen( filename, RDTMODE);

	  while (dlb_fgets(line, LLEN, f)) {
	    (void) strcat(textlines, line);
	  }
	  (void) dlb_fclose(f);

	  gless = gnome_less_new ();
	  gnome_less_show_string (GNOME_LESS (gless), textlines);
	  gtk_container_add (GTK_CONTAINER (frametxt), gless);
          gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (txtwin)->vbox), frametxt,
                             TRUE, TRUE, 0);
	  gtk_widget_show_all( txtwin);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  gnome_dialog_set_parent (GNOME_DIALOG (txtwin), 
		  GTK_WINDOW (ghack_get_main_window ()) );
	  gnome_dialog_run_and_close (GNOME_DIALOG (txtwin));
	  free(textlines);
        }
}