--- gimp/app/text_tool.c	Sat Aug 29 13:56:39 1998
+++ gimp/app/text_tool.c.save	Sun Aug 23 17:45:47 1998
@@ -60,6 +60,10 @@
 
 #define SUPERSAMPLE 3
 
+#define JUSTIFY_LEFT    1
+#define JUSTIFY_CENTER  2
+#define JUSTIFY_RIGHT   3
+
 typedef struct _TextTool TextTool;
 struct _TextTool
 {
@@ -73,6 +77,7 @@
   GtkWidget *the_text;
   GtkWidget *menus[7];
   GtkWidget *option_menus[7];
+  GtkWidget *justify_menu;
   GtkWidget **foundry_items;
   GtkWidget **weight_items;
   GtkWidget **slant_items;
@@ -94,6 +99,7 @@
   int spacing;
   int registry;
   int encoding;
+  int justify;
   void *gdisp_ptr;
 };
 
@@ -136,6 +142,9 @@
 static void       text_spacing_callback   (GtkWidget *, gpointer);
 static void       text_registry_callback  (GtkWidget *, gpointer);
 static void       text_encoding_callback  (GtkWidget *, gpointer);
+static void       justify_left_callback   (GtkWidget *, gpointer);
+static void       justify_center_callback (GtkWidget *, gpointer);
+static void       justify_right_callback  (GtkWidget *, gpointer);
 static gint       text_size_key_function  (GtkWidget *, GdkEventKey *, gpointer);
 static void       text_antialias_update   (GtkWidget *, gpointer);
 static void       text_font_item_update   (GtkWidget *, gpointer);
@@ -155,7 +164,7 @@
 static void       text_init_render        (TextTool *);
 static void       text_gdk_image_to_region (GdkImage *, int, PixelRegion *);
 static int        text_get_extents        (char *, char *, int *, int *, int *, int *);
-static Layer *    text_render             (GImage *, GimpDrawable *, int, int, char *, char *, int, int);
+static Layer *    text_render             (GImage *, GimpDrawable *, int, int, char *, char *, int, int, int);
 
 static int        font_compare_func (gpointer, gpointer);
 
@@ -179,6 +188,14 @@
   { NULL, 0, 0, NULL, NULL, NULL, NULL }
 };
 
+static MenuItem justify_items[] =
+{
+  { "Left",   0, 0, justify_left_callback,   (gpointer) JUSTIFY_LEFT,   NULL, NULL },
+  { "Center", 0, 0, justify_center_callback, (gpointer) JUSTIFY_CENTER, NULL, NULL },
+  { "Right",  0, 0, justify_right_callback,  (gpointer) JUSTIFY_RIGHT , NULL, NULL },
+  { NULL, 0, 0, NULL, NULL, NULL, NULL }
+};
+
 static TextTool *the_text_tool = NULL;
 static FontInfo **font_info;
 static int nfonts = -1;
@@ -239,6 +256,8 @@
       the_text_tool->spacing = 0;
       the_text_tool->registry = 0;
       the_text_tool->encoding = 0;
+      the_text_tool->justify_menu = NULL;
+      the_text_tool->justify = JUSTIFY_LEFT;
     }
 
   tool->type = TEXT;
@@ -408,10 +427,14 @@
   GtkWidget *list_item;
   GtkWidget *size_opt_menu;
   GtkWidget *border_label;
+  GtkWidget *justify_label;
+  GtkWidget *justify_opt_menu;
   GtkWidget *menu_table;
   GtkWidget *menu_label;
   GtkWidget **menu_items[7];
   GtkWidget *alignment;
+  GtkWidget *vscrollbar;
+  GtkObject *adjustment_info;
   int nmenu_items[7];
   char *menu_strs[7];
   char **menu_item_strs[7];
@@ -489,9 +512,19 @@
   text_tool->text_frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (text_tool->text_frame), GTK_SHADOW_NONE);
   gtk_box_pack_start (GTK_BOX (text_tool->main_vbox), text_tool->text_frame, FALSE, FALSE, 2);
-  text_tool->the_text = gtk_entry_new ();
+//  text_tool->the_text = gtk_entry_new ();
+//  gtk_entry_set_editable(GTK_ENTRY(text_tool->the_text), TRUE);
+  adjustment_info = gtk_adjustment_new (text_tool->size_type,
+                       0.0, 100.0, 1.0, 1.0, 0.0);
+  text_tool->the_text = gtk_text_new (GTK_ADJUSTMENT(adjustment_info), NULL);
+
+  gtk_text_set_editable(GTK_TEXT(text_tool->the_text), TRUE);
   gtk_container_add (GTK_CONTAINER (text_tool->text_frame), text_tool->the_text);
 
+//  vscrollbar = gtk_vscrollbar_new (GTK_TEXT(text_tool->the_text)->vadj);
+//  gtk_box_pack_start(GTK_BOX(text_tool->text_frame), vscrollbar, FALSE, FALSE, 0);
+//  gtk_widget_show (vscrollbar);
+  
   /* create the antialiasing toggle button  */
   text_tool->antialias_toggle = gtk_check_button_new_with_label ("Antialiasing");
   gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (text_tool->antialias_toggle), text_tool->antialias);
@@ -557,7 +590,7 @@
   font_infos[5] = font_info[0]->registries;
   font_infos[6] = font_info[0]->encodings;
 
-  menu_table = gtk_table_new (8, 2, FALSE);
+  menu_table = gtk_table_new (9, 2, FALSE);
   gtk_box_pack_start (GTK_BOX (right_vbox), menu_table, TRUE, TRUE, 0);
 
   /* Create the other menus */
@@ -609,6 +642,22 @@
   gtk_container_add (GTK_CONTAINER (alignment), text_tool->border_text);
   gtk_widget_show (alignment);
 
+  /* Create the justification selector */
+  ++i;
+  justify_label = gtk_label_new ("Justify");
+  gtk_misc_set_alignment (GTK_MISC (justify_label), 0.0, 0.5);
+  gtk_table_attach (GTK_TABLE (menu_table), justify_label, 0, 1, i, i + 1,
+		    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 1);
+
+  /* Create the justification menu */
+  justify_items[0].user_data = text_tool;
+  justify_items[1].user_data = text_tool;
+  justify_items[2].user_data = text_tool;
+  text_tool->justify_menu = build_menu (justify_items, NULL);
+  justify_opt_menu = gtk_option_menu_new ();
+  gtk_table_attach (GTK_TABLE (menu_table), justify_opt_menu, 1, 2, i, i + 1,
+		    GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_SHRINK, 1, 1);
+
   /* Create the action area */
   action_items[0].user_data = text_tool;
   action_items[1].user_data = text_tool;
@@ -621,6 +670,8 @@
   gtk_widget_show (border_label);
   gtk_widget_show (text_tool->border_text);
   gtk_widget_show (size_opt_menu);
+  gtk_widget_show (justify_label);
+  gtk_widget_show (justify_opt_menu);
   gtk_widget_show (text_hbox);
   gtk_widget_show (list_box);
   gtk_widget_show (right_vbox);
@@ -631,6 +682,7 @@
 
   /* Post initialization */
   gtk_option_menu_set_menu (GTK_OPTION_MENU (size_opt_menu), text_tool->size_menu);
+  gtk_option_menu_set_menu (GTK_OPTION_MENU (justify_opt_menu), text_tool->justify_menu);
 
   if (nfonts)
     text_load_font (text_tool);
@@ -882,6 +934,27 @@
     the_text_tool->encoding = old_value;
 }
 
+static void
+justify_left_callback (GtkWidget *w,
+		       gpointer   data)
+{
+  the_text_tool->justify = JUSTIFY_LEFT;
+}
+
+static void
+justify_center_callback (GtkWidget *w,
+		       gpointer   data)
+{
+  the_text_tool->justify = JUSTIFY_CENTER;
+}
+
+static void
+justify_right_callback (GtkWidget *w,
+		       gpointer   data)
+{
+  the_text_tool->justify = JUSTIFY_RIGHT;
+}
+
 static gint
 text_size_key_function (GtkWidget   *w,
 			GdkEventKey *event,
@@ -1672,8 +1745,8 @@
 		     registry_str, encoding_str, fontname))
     {
       /* get the text */
-      text = gtk_entry_get_text (GTK_ENTRY (text_tool->the_text));
-
+//~~~~~      text = gtk_entry_get_text (GTK_ENTRY (text_tool->the_text));
+      text = GTK_TEXT (text_tool->the_text)->text;
       border_text = gtk_entry_get_text (GTK_ENTRY (text_tool->border_text));
       border = atoi (border_text);
 
@@ -1681,7 +1754,7 @@
 
       text_render (gdisp->gimage, gimage_active_drawable (gdisp->gimage),
 		   text_tool->click_x, text_tool->click_y,
-		   fontname, text, border, text_tool->antialias);
+		   fontname, text, border, text_tool->antialias, text_tool->justify);
 
       gdisplays_flush ();
     }
@@ -1734,7 +1807,8 @@
 	     char   *fontname,
 	     char   *text,
 	     int     border,
-	     int     antialias)
+	     int     antialias,
+	     int     justify)
 {
   GdkFont *font;
   GdkPixmap *pixmap;
@@ -1850,6 +1924,19 @@
 
       for (k = 0; k < nstrs; k++)
 	{
+      x = -maskPR.x * antialias;
+      line_width = gdk_string_measure (font, str) + 5;
+      switch (justify)
+      {
+      case JUSTIFY_LEFT:	/* nothing to be done here */
+           break;
+      case JUSTIFY_CENTER:
+           x += ((width - line_width) / 2);
+           break;
+      case JUSTIFY_RIGHT:
+           x += (width - line_width);
+           break;
+      }
 	  gdk_draw_string (pixmap, font, gc, x, y, str);
 	  str += strlen (str) + 1;
 	  y += line_height;
@@ -2121,6 +2208,10 @@
     "the size of the border: border >= 0"
   },
   { PDB_INT32,
+    "justification",
+    "specify how multi-line text should be justified"
+  },
+  { PDB_INT32,
     "antialias",
     "generate antialiased text"
   },
@@ -2583,6 +2674,7 @@
   char *text;
   int border;
   int antialias;
+  int justify;
   double size;
   int size_type;
   char *foundry;
@@ -2605,6 +2697,7 @@
   text        = NULL;
   border      = FALSE;
   antialias   = FALSE;
+  justify     = JUSTIFY_LEFT;
   size        = 0;
   size_type   = PIXELS;
   foundry     = NULL;
@@ -2700,7 +2793,7 @@
   /*  call the text render procedure  */
   if (success)
     success = ((text_layer = text_render (gimage, drawable, x, y, fontname,
-					  text, border, antialias)) != NULL);
+					  text, border, antialias, justify)) != NULL);
 
   return_args = procedural_db_return_args (&text_tool_proc, success);
 
