gtktexttag.c 36.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/* gtktexttag.c - text tag object
 * 
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000      Red Hat, Inc.
 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
 *
 * This software is copyrighted by the Regents of the University of
 * California, Sun Microsystems, Inc., and other parties.  The
 * following terms apply to all files associated with the software
 * unless explicitly disclaimed in individual files.
 * 
 * The authors hereby grant permission to use, copy, modify,
 * distribute, and license this software and its documentation for any
 * purpose, provided that existing copyright notices are retained in
 * all copies and that this notice is included verbatim in any
 * distributions. No written agreement, license, or royalty fee is
 * required for any of the authorized uses.  Modifications to this
 * software may be copyrighted by their authors and need not follow
 * the licensing terms described here, provided that the new terms are
 * clearly indicated on the first page of each file where they apply.
 * 
 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * GOVERNMENT USE: If you are acquiring this software on behalf of the
 * U.S. government, the Government shall have only "Restricted Rights"
 * in the software and related documentation as defined in the Federal
 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
 * are acquiring the software on behalf of the Department of Defense,
 * the software shall be classified as "Commercial Computer Software"
 * and the Government shall have only "Restricted Rights" as defined
 * in Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 * foregoing, the authors grant the U.S. Government and others acting
 * in its behalf permission to use and distribute the software in
 * accordance with the terms specified in this license.
 * 
 */

50
#include "gtkmain.h"
51 52 53 54
#include "gtktexttag.h"
#include "gtktexttypes.h"
#include "gtktexttagtable.h"
#include "gtksignal.h"
55
#include "gtkmain.h"
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

#include <stdlib.h>

enum {
  EVENT,
  LAST_SIGNAL
};

enum {
  ARG_0,
  /* Construct args */
  ARG_NAME,

  /* Style args */
  ARG_BACKGROUND,
  ARG_FOREGROUND,
  ARG_BACKGROUND_GDK,
  ARG_FOREGROUND_GDK,
  ARG_BACKGROUND_STIPPLE,
  ARG_FOREGROUND_STIPPLE,
  ARG_FONT,
  ARG_FONT_DESC,
  ARG_PIXELS_ABOVE_LINES,
  ARG_PIXELS_BELOW_LINES,
  ARG_PIXELS_INSIDE_WRAP,
  ARG_EDITABLE,
  ARG_WRAP_MODE,
  ARG_JUSTIFY,
  ARG_DIRECTION,
  ARG_LEFT_MARGIN,
  ARG_LEFT_WRAPPED_LINE_MARGIN,
87
  ARG_STRIKETHROUGH,
88 89 90 91
  ARG_RIGHT_MARGIN,
  ARG_UNDERLINE,
  ARG_OFFSET,
  ARG_BG_FULL_HEIGHT,
92
  ARG_LANGUAGE,
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  
  /* Whether-a-style-arg-is-set args */
  ARG_BACKGROUND_SET,
  ARG_FOREGROUND_SET,
  ARG_BACKGROUND_GDK_SET,
  ARG_FOREGROUND_GDK_SET,
  ARG_BACKGROUND_STIPPLE_SET,
  ARG_FOREGROUND_STIPPLE_SET,
  ARG_FONT_SET,
  ARG_PIXELS_ABOVE_LINES_SET,
  ARG_PIXELS_BELOW_LINES_SET,
  ARG_PIXELS_INSIDE_WRAP_SET,
  ARG_EDITABLE_SET,
  ARG_WRAP_MODE_SET,
  ARG_JUSTIFY_SET,
  ARG_LEFT_MARGIN_SET,
  ARG_LEFT_WRAPPED_LINE_MARGIN_SET,
110
  ARG_STRIKETHROUGH_SET,
111 112 113 114
  ARG_RIGHT_MARGIN_SET,
  ARG_UNDERLINE_SET,
  ARG_OFFSET_SET,
  ARG_BG_FULL_HEIGHT_SET,
115
  ARG_LANGUAGE_SET,
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  
  LAST_ARG
};

static void gtk_text_tag_init       (GtkTextTag      *tkxt_tag);
static void gtk_text_tag_class_init (GtkTextTagClass *klass);
static void gtk_text_tag_destroy    (GtkObject       *object);
static void gtk_text_tag_finalize   (GObject         *object);
static void gtk_text_tag_set_arg    (GtkObject       *object,
				     GtkArg          *arg,
				     guint            arg_id);
static void gtk_text_tag_get_arg    (GtkObject       *object,
				     GtkArg          *arg,
				     guint            arg_id);

static GtkObjectClass *parent_class = NULL;
static guint signals[LAST_SIGNAL] = { 0 };

GtkType
gtk_text_tag_get_type (void)
{
  static GtkType our_type = 0;

  if (our_type == 0)
    {
      static const GtkTypeInfo our_info =
      {
        "GtkTextTag",
        sizeof (GtkTextTag),
        sizeof (GtkTextTagClass),
        (GtkClassInitFunc) gtk_text_tag_class_init,
        (GtkObjectInitFunc) gtk_text_tag_init,
        /* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
        (GtkClassInitFunc) NULL
      };

    our_type = gtk_type_unique (GTK_TYPE_OBJECT, &our_info);
  }

  return our_type;
}

static void
gtk_text_tag_class_init (GtkTextTagClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);

  parent_class = gtk_type_class (GTK_TYPE_OBJECT);

  /* Construct */
  gtk_object_add_arg_type ("GtkTextTag::name", GTK_TYPE_STRING,
                           GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY,
                           ARG_NAME);

  /* Style args */
  gtk_object_add_arg_type ("GtkTextTag::background", GTK_TYPE_STRING,
                           GTK_ARG_WRITABLE, ARG_BACKGROUND);
  gtk_object_add_arg_type ("GtkTextTag::background_gdk", GTK_TYPE_GDK_COLOR,
                           GTK_ARG_READWRITE, ARG_BACKGROUND_GDK);
177 178
  gtk_object_add_arg_type ("GtkTextTag::background_full_height", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_BG_FULL_HEIGHT);
179 180
  gtk_object_add_arg_type ("GtkTextTag::background_stipple",
                           GDK_TYPE_PIXMAP,
181
                           GTK_ARG_READWRITE, ARG_BACKGROUND_STIPPLE);
182 183 184 185
  gtk_object_add_arg_type ("GtkTextTag::direction", GTK_TYPE_ENUM,
                           GTK_ARG_READWRITE, ARG_DIRECTION);
  gtk_object_add_arg_type ("GtkTextTag::editable", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_EDITABLE);
186 187 188 189
  gtk_object_add_arg_type ("GtkTextTag::font", GTK_TYPE_STRING,
                           GTK_ARG_READWRITE, ARG_FONT);
  gtk_object_add_arg_type ("GtkTextTag::font_desc", GTK_TYPE_BOXED,
                           GTK_ARG_READWRITE, ARG_FONT_DESC);
190 191 192 193 194 195 196
  gtk_object_add_arg_type ("GtkTextTag::foreground", GTK_TYPE_STRING,
                           GTK_ARG_WRITABLE, ARG_FOREGROUND);
  gtk_object_add_arg_type ("GtkTextTag::foreground_gdk", GTK_TYPE_GDK_COLOR,
                           GTK_ARG_READWRITE, ARG_FOREGROUND_GDK);
  gtk_object_add_arg_type ("GtkTextTag::foreground_stipple",
                           GDK_TYPE_PIXMAP,
                           GTK_ARG_READWRITE, ARG_FOREGROUND_STIPPLE);
197 198
  gtk_object_add_arg_type ("GtkTextTag::justify", GTK_TYPE_ENUM,
                           GTK_ARG_READWRITE, ARG_JUSTIFY);
199 200
  gtk_object_add_arg_type ("GtkTextTag::language", GTK_TYPE_STRING,
                           GTK_ARG_READWRITE, ARG_LANGUAGE);
201 202 203 204
  gtk_object_add_arg_type ("GtkTextTag::left_margin", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_LEFT_MARGIN);
  gtk_object_add_arg_type ("GtkTextTag::left_wrapped_line_margin", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_LEFT_WRAPPED_LINE_MARGIN);
205 206
  gtk_object_add_arg_type ("GtkTextTag::offset", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_OFFSET);
207 208 209 210 211 212
  gtk_object_add_arg_type ("GtkTextTag::pixels_above_lines", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_PIXELS_ABOVE_LINES);
  gtk_object_add_arg_type ("GtkTextTag::pixels_below_lines", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_PIXELS_BELOW_LINES);
  gtk_object_add_arg_type ("GtkTextTag::pixels_inside_wrap", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_PIXELS_INSIDE_WRAP);
213 214
  gtk_object_add_arg_type ("GtkTextTag::right_margin", GTK_TYPE_INT,
                           GTK_ARG_READWRITE, ARG_RIGHT_MARGIN);
215 216
  gtk_object_add_arg_type ("GtkTextTag::strikethrough", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_STRIKETHROUGH);
217 218 219 220
  gtk_object_add_arg_type ("GtkTextTag::underline", GTK_TYPE_ENUM,
                           GTK_ARG_READWRITE, ARG_UNDERLINE);
  gtk_object_add_arg_type ("GtkTextTag::wrap_mode", GTK_TYPE_ENUM,
                           GTK_ARG_READWRITE, ARG_WRAP_MODE);
221
  
222 223 224
  /* Style args are set or not */
  gtk_object_add_arg_type ("GtkTextTag::background_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_BACKGROUND_SET);
225 226
  gtk_object_add_arg_type ("GtkTextTag::background_full_height_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_BG_FULL_HEIGHT_SET);
227 228 229 230 231 232
  gtk_object_add_arg_type ("GtkTextTag::background_gdk_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_BACKGROUND_GDK_SET);
  gtk_object_add_arg_type ("GtkTextTag::background_stipple_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_BACKGROUND_STIPPLE_SET);
  gtk_object_add_arg_type ("GtkTextTag::editable_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_EDITABLE_SET);
233 234 235 236 237 238 239 240
  gtk_object_add_arg_type ("GtkTextTag::font_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_FONT_SET);
  gtk_object_add_arg_type ("GtkTextTag::foreground_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_FOREGROUND_SET);
  gtk_object_add_arg_type ("GtkTextTag::foreground_gdk_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_FOREGROUND_GDK_SET);
  gtk_object_add_arg_type ("GtkTextTag::foreground_stipple_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_FOREGROUND_STIPPLE_SET);
241 242
  gtk_object_add_arg_type ("GtkTextTag::justify_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_JUSTIFY_SET);
243 244
  gtk_object_add_arg_type ("GtkTextTag::language_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_LANGUAGE_SET);
245 246 247 248
  gtk_object_add_arg_type ("GtkTextTag::left_margin_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_LEFT_MARGIN_SET);
  gtk_object_add_arg_type ("GtkTextTag::left_wrapped_line_margin_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_LEFT_WRAPPED_LINE_MARGIN_SET);
249 250
  gtk_object_add_arg_type ("GtkTextTag::offset_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_OFFSET_SET);  
251 252 253 254 255 256
  gtk_object_add_arg_type ("GtkTextTag::pixels_above_lines_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_PIXELS_ABOVE_LINES_SET);
  gtk_object_add_arg_type ("GtkTextTag::pixels_below_lines_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_PIXELS_BELOW_LINES_SET);
  gtk_object_add_arg_type ("GtkTextTag::pixels_inside_wrap_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_PIXELS_INSIDE_WRAP_SET);
257 258
  gtk_object_add_arg_type ("GtkTextTag::strikethrough_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_STRIKETHROUGH_SET);
259 260
  gtk_object_add_arg_type ("GtkTextTag::right_margin_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_RIGHT_MARGIN_SET);
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  gtk_object_add_arg_type ("GtkTextTag::underline_set", GTK_TYPE_ENUM,
                           GTK_ARG_READWRITE, ARG_UNDERLINE_SET);
  gtk_object_add_arg_type ("GtkTextTag::wrap_mode_set", GTK_TYPE_BOOL,
                           GTK_ARG_READWRITE, ARG_WRAP_MODE_SET);
  
  signals[EVENT] =
    gtk_signal_new ("event",
                    GTK_RUN_LAST,
                    GTK_CLASS_TYPE (object_class),
                    GTK_SIGNAL_OFFSET (GtkTextTagClass, event),
                    gtk_marshal_INT__OBJECT_BOXED_POINTER,
                    GTK_TYPE_INT,
                    3,
                    GTK_TYPE_OBJECT,
                    GTK_TYPE_GDK_EVENT,
                    GTK_TYPE_POINTER);

  gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);

  object_class->set_arg = gtk_text_tag_set_arg;
  object_class->get_arg = gtk_text_tag_get_arg;

  object_class->destroy = gtk_text_tag_destroy;
  gobject_class->finalize = gtk_text_tag_finalize;
}

void
gtk_text_tag_init (GtkTextTag *tkxt_tag)
{
  /* 0 is basically a fine way to initialize everything in the
     entire struct */
  
}

GtkTextTag*
gtk_text_tag_new (const gchar *name)
{
  GtkTextTag *tag;

  tag = GTK_TEXT_TAG (gtk_type_new (gtk_text_tag_get_type ()));

  tag->name = g_strdup(name);

304
  tag->values = gtk_text_attributes_new();
305 306 307 308 309 310 311 312 313 314 315 316 317 318
  
  return tag;
}

static void
gtk_text_tag_destroy (GtkObject *object)
{
  GtkTextTag *tkxt_tag;

  tkxt_tag = GTK_TEXT_TAG (object);

  g_assert(!tkxt_tag->values->realized);
  
  if (tkxt_tag->table)
319
    gtk_text_tag_table_remove(tkxt_tag->table, tkxt_tag);
320 321 322

  g_assert(tkxt_tag->table == NULL);
  
323
  gtk_text_attributes_unref(tkxt_tag->values);
324
  tkxt_tag->values = NULL;
325
  
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
  (* GTK_OBJECT_CLASS(parent_class)->destroy) (object);
}

static void
gtk_text_tag_finalize (GObject *object)
{
  GtkTextTag *tkxt_tag;

  tkxt_tag = GTK_TEXT_TAG (object);

  g_free(tkxt_tag->name);
  tkxt_tag->name = NULL;

  (* G_OBJECT_CLASS(parent_class)->finalize) (object);
}

static void
set_bg_color(GtkTextTag *tag, GdkColor *color)
{
  if (color)
    {
      tag->bg_color_set = TRUE;
      tag->values->appearance.bg_color = *color;
    }
  else
    {
      tag->bg_color_set = FALSE;
    }
}

static void
set_fg_color(GtkTextTag *tag, GdkColor *color)
{
  if (color)
    {
      tag->fg_color_set = TRUE;
      tag->values->appearance.fg_color = *color;
    }
  else
    {
      tag->fg_color_set = FALSE;
    }
}

static void
gtk_text_tag_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
  GtkTextTag *tkxt_tag;
  gboolean size_changed = FALSE;
  
  tkxt_tag = GTK_TEXT_TAG (object);

  g_return_if_fail(!tkxt_tag->values->realized);
  
  switch (arg_id)
    {
    case ARG_NAME:
      g_return_if_fail(tkxt_tag->name == NULL);
      tkxt_tag->name = g_strdup(GTK_VALUE_STRING(*arg));
      break;

    case ARG_BACKGROUND:
      {
        GdkColor color;

        if (gdk_color_parse(GTK_VALUE_STRING(*arg), &color))
          set_bg_color(tkxt_tag, &color);
        else
          g_warning("Don't know color `%s'", GTK_VALUE_STRING(*arg));
      }
      break;

    case ARG_FOREGROUND:
      {
        GdkColor color;

        if (gdk_color_parse(GTK_VALUE_STRING(*arg), &color))
          set_fg_color(tkxt_tag, &color);
        else
          g_warning("Don't know color `%s'", GTK_VALUE_STRING(*arg));
      }
      break;
      
    case ARG_BACKGROUND_GDK:
      {
        GdkColor *color = GTK_VALUE_POINTER(*arg);
        set_bg_color(tkxt_tag, color);
      }
      break;

    case ARG_FOREGROUND_GDK:
      {
        GdkColor *color = GTK_VALUE_POINTER(*arg);
        set_fg_color(tkxt_tag, color);
      }
      break;

    case ARG_BACKGROUND_STIPPLE:
      {
        GdkBitmap *bitmap = GTK_VALUE_POINTER(*arg);

        tkxt_tag->bg_stipple_set = TRUE;
        
        if (tkxt_tag->values->appearance.bg_stipple != bitmap)
          {
            if (bitmap != NULL)
              gdk_bitmap_ref(bitmap);
            
            if (tkxt_tag->values->appearance.bg_stipple)
              gdk_bitmap_unref(tkxt_tag->values->appearance.bg_stipple);
            
            tkxt_tag->values->appearance.bg_stipple = bitmap;
          }
      }
      break;

    case ARG_FOREGROUND_STIPPLE:
      {
        GdkBitmap *bitmap = GTK_VALUE_POINTER(*arg);

        tkxt_tag->fg_stipple_set = TRUE;
        
        if (tkxt_tag->values->appearance.fg_stipple != bitmap)
          {
            if (bitmap != NULL)
              gdk_bitmap_ref(bitmap);
            
            if (tkxt_tag->values->appearance.fg_stipple)
              gdk_bitmap_unref(tkxt_tag->values->appearance.fg_stipple);
            
            tkxt_tag->values->appearance.fg_stipple = bitmap;
          }
      }
      break;

    case ARG_FONT:
      {
        PangoFontDescription *font_desc = NULL;
        const gchar *name;

        name = GTK_VALUE_STRING(*arg);        

        if (name)
	  font_desc = pango_font_description_from_string (name);

	if (tkxt_tag->values->font_desc)
	  pango_font_description_free (tkxt_tag->values->font_desc);
	
	tkxt_tag->font_set = (font_desc != NULL);
	tkxt_tag->values->font_desc = font_desc;

        size_changed = TRUE;
      }
      break;

    case ARG_FONT_DESC:
      {
        PangoFontDescription *font_desc;

        font_desc = GTK_VALUE_BOXED(*arg);        

	if (tkxt_tag->values->font_desc)
	  pango_font_description_free (tkxt_tag->values->font_desc);

	if (font_desc)
	  tkxt_tag->values->font_desc = pango_font_description_copy (font_desc);
	else
	  tkxt_tag->values->font_desc = NULL;
	
	tkxt_tag->font_set = (font_desc != NULL);

        size_changed = TRUE;
      }
      break;

    case ARG_PIXELS_ABOVE_LINES:
      tkxt_tag->pixels_above_lines_set = TRUE;
      tkxt_tag->values->pixels_above_lines = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

    case ARG_PIXELS_BELOW_LINES:
      tkxt_tag->pixels_below_lines_set = TRUE;
      tkxt_tag->values->pixels_below_lines = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

    case ARG_PIXELS_INSIDE_WRAP:
      tkxt_tag->pixels_inside_wrap_set = TRUE;
      tkxt_tag->values->pixels_inside_wrap = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

    case ARG_EDITABLE:
      tkxt_tag->editable_set = TRUE;
      tkxt_tag->values->editable = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_WRAP_MODE:
      tkxt_tag->wrap_mode_set = TRUE;
      tkxt_tag->values->wrap_mode = GTK_VALUE_ENUM(*arg);
      size_changed = TRUE;
      break;

    case ARG_JUSTIFY:
      tkxt_tag->justify_set = TRUE;
      tkxt_tag->values->justify = GTK_VALUE_ENUM(*arg);
      size_changed = TRUE;
      break;

    case ARG_DIRECTION:
      tkxt_tag->values->direction = GTK_VALUE_ENUM(*arg);
      break;

    case ARG_LEFT_MARGIN:
      tkxt_tag->left_margin_set = TRUE;
      tkxt_tag->values->left_margin = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

    case ARG_LEFT_WRAPPED_LINE_MARGIN:
      tkxt_tag->left_wrapped_line_margin_set = TRUE;
      tkxt_tag->values->left_wrapped_line_margin = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

552 553 554
    case ARG_STRIKETHROUGH:
      tkxt_tag->strikethrough_set = TRUE;
      tkxt_tag->values->appearance.strikethrough = GTK_VALUE_BOOL(*arg);
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
      break;
      
    case ARG_RIGHT_MARGIN:
      tkxt_tag->right_margin_set = TRUE;
      tkxt_tag->values->right_margin = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;
      
    case ARG_UNDERLINE:
      tkxt_tag->underline_set = TRUE;
      tkxt_tag->values->appearance.underline = GTK_VALUE_ENUM(*arg);
      break;
      
    case ARG_OFFSET:
      tkxt_tag->offset_set = TRUE;
      tkxt_tag->values->offset = GTK_VALUE_INT(*arg);
      size_changed = TRUE;
      break;

    case ARG_BG_FULL_HEIGHT:
      tkxt_tag->bg_full_height_set = TRUE;
      tkxt_tag->values->bg_full_height = GTK_VALUE_BOOL(*arg);
      break;

579 580 581 582
    case ARG_LANGUAGE:
      tkxt_tag->language_set = TRUE;
      tkxt_tag->values->language = g_strdup (GTK_VALUE_STRING(*arg));
      break;
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
      
      /* Whether the value should be used... */
      
    case ARG_BACKGROUND_SET:
    case ARG_BACKGROUND_GDK_SET:
      tkxt_tag->bg_color_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_FOREGROUND_SET:
    case ARG_FOREGROUND_GDK_SET:
      tkxt_tag->fg_color_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_BACKGROUND_STIPPLE_SET:
      tkxt_tag->bg_stipple_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_FOREGROUND_STIPPLE_SET:
      tkxt_tag->fg_stipple_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_FONT_SET:
      tkxt_tag->font_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_PIXELS_ABOVE_LINES_SET:
      tkxt_tag->pixels_above_lines_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_PIXELS_BELOW_LINES_SET:
      tkxt_tag->pixels_below_lines_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_PIXELS_INSIDE_WRAP_SET:
      tkxt_tag->pixels_inside_wrap_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_EDITABLE_SET:
      tkxt_tag->editable_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_WRAP_MODE_SET:
      tkxt_tag->wrap_mode_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_JUSTIFY_SET:
      tkxt_tag->justify_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_LEFT_MARGIN_SET:
      tkxt_tag->left_margin_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_LEFT_WRAPPED_LINE_MARGIN_SET:
      tkxt_tag->left_wrapped_line_margin_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

648 649
    case ARG_STRIKETHROUGH_SET:
      tkxt_tag->strikethrough_set = GTK_VALUE_BOOL(*arg);
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
      break;

    case ARG_RIGHT_MARGIN_SET:
      tkxt_tag->right_margin_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_UNDERLINE_SET:
      tkxt_tag->underline_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_OFFSET_SET:
      tkxt_tag->offset_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
      break;

    case ARG_BG_FULL_HEIGHT_SET:
667 668 669 670 671 672
      tkxt_tag->bg_full_height_set = GTK_VALUE_BOOL(*arg);
      break;

    case ARG_LANGUAGE_SET:
      tkxt_tag->language_set = GTK_VALUE_BOOL(*arg);
      size_changed = TRUE;
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
      break;
      
    default:
      g_assert_not_reached();
      break;
    }
  
  /* FIXME I would like to do this after all set_arg in a single
     gtk_object_set() have been called. But an idle function
     won't work; we need to emit when the tag is changed, not
     when we get around to the event loop. So blah, we eat some
     inefficiency. */
  
  /* This is also somewhat weird since we emit another object's
     signal here, but the two objects are already tightly bound. */
  
  if (tkxt_tag->table)
    gtk_signal_emit_by_name(GTK_OBJECT(tkxt_tag->table),
                            "tag_changed",
                            tkxt_tag, size_changed);
}

static void
get_color_arg (GtkArg *arg, GdkColor *orig)
{
  GdkColor *color;
  
  color = g_new (GdkColor, 1);
  *color = *orig;
  GTK_VALUE_BOXED (*arg) = color;
}

static void
gtk_text_tag_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
  GtkTextTag *tag;

  tag = GTK_TEXT_TAG (object);

  switch (arg_id)
    {
    case ARG_NAME:
      GTK_VALUE_STRING(*arg) = g_strdup(tag->name);
      break;
      
    case ARG_BACKGROUND_GDK:
      get_color_arg(arg, &tag->values->appearance.bg_color);
      break;

    case ARG_FOREGROUND_GDK:
      get_color_arg(arg, &tag->values->appearance.fg_color);
      break;

    case ARG_BACKGROUND_STIPPLE:
      GTK_VALUE_BOXED(*arg) = tag->values->appearance.bg_stipple;
      break;

    case ARG_FOREGROUND_STIPPLE:
      GTK_VALUE_BOXED(*arg) = tag->values->appearance.fg_stipple;
      break;

    case ARG_FONT:
      if (tag->values->font_desc)
	GTK_VALUE_STRING(*arg) = pango_font_description_to_string (tag->values->font_desc);
      else
	GTK_VALUE_STRING(*arg) = NULL;
      break;

    case ARG_FONT_DESC:
      if (tag->values->font_desc)
	GTK_VALUE_BOXED(*arg) = pango_font_description_copy (tag->values->font_desc);
      else
	GTK_VALUE_BOXED(*arg) = NULL;
      break;

    case ARG_PIXELS_ABOVE_LINES:
      GTK_VALUE_INT(*arg) = tag->values->pixels_above_lines;
      break;

    case ARG_PIXELS_BELOW_LINES:
      GTK_VALUE_INT(*arg) = tag->values->pixels_below_lines;
      break;

    case ARG_PIXELS_INSIDE_WRAP:
      GTK_VALUE_INT(*arg) = tag->values->pixels_inside_wrap;
      break;

    case ARG_EDITABLE:
      GTK_VALUE_BOOL(*arg) = tag->values->editable;
      break;      

    case ARG_WRAP_MODE:
      GTK_VALUE_ENUM(*arg) = tag->values->wrap_mode;
      break;

    case ARG_JUSTIFY:
      GTK_VALUE_ENUM(*arg) = tag->values->justify;
      break;

    case ARG_LEFT_MARGIN:
      GTK_VALUE_INT(*arg) = tag->values->left_margin;
      break;

    case ARG_LEFT_WRAPPED_LINE_MARGIN:
      GTK_VALUE_INT(*arg) = tag->values->left_wrapped_line_margin;
      break;

780 781
    case ARG_STRIKETHROUGH:
      GTK_VALUE_BOOL(*arg) = tag->values->appearance.strikethrough;
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
      break;
      
    case ARG_RIGHT_MARGIN:
      GTK_VALUE_INT(*arg) = tag->values->right_margin;
      break;
      
    case ARG_UNDERLINE:
      GTK_VALUE_ENUM(*arg) = tag->values->appearance.underline;
      break;

    case ARG_OFFSET:
      GTK_VALUE_INT(*arg) = tag->values->offset;
      break;

    case ARG_BG_FULL_HEIGHT:
      GTK_VALUE_BOOL(*arg) = tag->values->bg_full_height;
      break;
799 800 801 802

    case ARG_LANGUAGE:
      GTK_VALUE_STRING(*arg) = g_strdup (tag->values->language);
      break;
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
      
    case ARG_BACKGROUND_SET:
    case ARG_BACKGROUND_GDK_SET:
      GTK_VALUE_BOOL(*arg) = tag->bg_color_set;
      break;

    case ARG_FOREGROUND_SET:
    case ARG_FOREGROUND_GDK_SET:
      GTK_VALUE_BOOL(*arg) = tag->fg_color_set;
      break;

    case ARG_BACKGROUND_STIPPLE_SET:
      GTK_VALUE_BOOL(*arg) = tag->bg_stipple_set;
      break;

    case ARG_FOREGROUND_STIPPLE_SET:
      GTK_VALUE_BOOL(*arg) = tag->fg_stipple_set;
      break;

    case ARG_FONT_SET:
      GTK_VALUE_BOOL(*arg) = tag->font_set;
      break;

    case ARG_PIXELS_ABOVE_LINES_SET:
      GTK_VALUE_BOOL(*arg) = tag->pixels_above_lines_set;
      break;

    case ARG_PIXELS_BELOW_LINES_SET:
      GTK_VALUE_BOOL(*arg) = tag->pixels_below_lines_set;
      break;

    case ARG_PIXELS_INSIDE_WRAP_SET:
      GTK_VALUE_BOOL(*arg) = tag->pixels_inside_wrap_set;
      break;

    case ARG_EDITABLE_SET:
      GTK_VALUE_BOOL(*arg) = tag->editable_set;
      break;

    case ARG_WRAP_MODE_SET:
      GTK_VALUE_BOOL(*arg) = tag->wrap_mode_set;
      break;

    case ARG_JUSTIFY_SET:
      GTK_VALUE_BOOL(*arg) = tag->justify_set;
      break;

    case ARG_LEFT_MARGIN_SET:
      GTK_VALUE_BOOL(*arg) = tag->left_margin_set;
      break;

    case ARG_LEFT_WRAPPED_LINE_MARGIN_SET:
      GTK_VALUE_BOOL(*arg) = tag->left_wrapped_line_margin_set;
      break;

858 859
    case ARG_STRIKETHROUGH_SET:
      GTK_VALUE_BOOL(*arg) = tag->strikethrough_set;
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
      break;

    case ARG_RIGHT_MARGIN_SET:
      GTK_VALUE_BOOL(*arg) = tag->right_margin_set;
      break;

    case ARG_UNDERLINE_SET:
      GTK_VALUE_BOOL(*arg) = tag->underline_set;
      break;

    case ARG_OFFSET_SET:
      GTK_VALUE_BOOL(*arg) = tag->offset_set;
      break;

    case ARG_BG_FULL_HEIGHT_SET:
      GTK_VALUE_BOOL(*arg) = tag->bg_full_height_set;
      break;
877 878 879 880

    case ARG_LANGUAGE_SET:
      GTK_VALUE_BOOL(*arg) = tag->language_set;
      break;
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
      
    case ARG_BACKGROUND:
    case ARG_FOREGROUND:
    default:
      arg->type = GTK_TYPE_INVALID;
      break;
    }
  /* FIXME */
  arg->type = GTK_TYPE_INVALID;
}

/*
 * Tag operations
 */

typedef struct {
  gint high;
  gint low;
  gint delta;
} DeltaData;

static void
903
delta_priority_foreach(GtkTextTag *tag, gpointer user_data)
904 905 906 907 908 909 910
{
  DeltaData *dd = user_data;

  if (tag->priority >= dd->low && tag->priority <= dd->high)
    tag->priority += dd->delta;
}

911 912 913 914 915 916 917 918
gint
gtk_text_tag_get_priority (GtkTextTag *tag)
{
  g_return_val_if_fail(GTK_IS_TEXT_TAG(tag), 0);

  return tag->priority;
}

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
void
gtk_text_tag_set_priority(GtkTextTag *tag,
                           gint priority)
{
    DeltaData dd;
    
    g_return_if_fail(GTK_IS_TEXT_TAG(tag));
    g_return_if_fail(tag->table != NULL);
    g_return_if_fail(priority >= 0);
    g_return_if_fail(priority < gtk_text_tag_table_size(tag->table));

    if (priority == tag->priority)
      return;

    if (priority < tag->priority) {
      dd.low = priority;
      dd.high = tag->priority - 1;
      dd.delta = 1;
    } else {
      dd.low = tag->priority + 1;
      dd.high = priority;
      dd.delta = -1;
    }

    gtk_text_tag_table_foreach(tag->table, delta_priority_foreach,
944
                               &dd);
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    
    tag->priority = priority;
}

gint
gtk_text_tag_event(GtkTextTag *tag,
                    GtkObject *event_object,
                    GdkEvent *event,
                    const GtkTextIter *iter)
{
  gint retval = FALSE;

  g_return_val_if_fail(GTK_IS_TEXT_TAG(tag), FALSE);
  g_return_val_if_fail(GTK_IS_OBJECT(event_object), FALSE);
  g_return_val_if_fail(event != NULL, FALSE);
  
  gtk_signal_emit(GTK_OBJECT(tag),
                  signals[EVENT],
                  event_object,
                  event,
                  iter,
                  &retval);

  return retval;
}

static int
tag_sort_func(gconstpointer first, gconstpointer second)
{
    GtkTextTag *tag1, *tag2;

    tag1 = * (GtkTextTag **) first;
    tag2 = * (GtkTextTag **) second;
    return tag1->priority - tag2->priority;
}

void
gtk_text_tag_array_sort(GtkTextTag** tag_array_p,
                         guint len)
{
  int i, j, prio;
  GtkTextTag **tag;
  GtkTextTag **maxPtrPtr, *tmp;

  g_return_if_fail(tag_array_p != NULL);
  g_return_if_fail(len > 0);
  
  if (len < 2) {
    return;
  }
  if (len < 20) {
    GtkTextTag **iter = tag_array_p;

    for (i = len-1; i > 0; i--, iter++) {
      maxPtrPtr = tag = iter;
      prio = tag[0]->priority;
      for (j = i, tag++; j > 0; j--, tag++) {
        if (tag[0]->priority < prio) {
          prio = tag[0]->priority;
          maxPtrPtr = tag;
        }
      }
      tmp = *maxPtrPtr;
      *maxPtrPtr = *iter;
      *iter = tmp;
    }
  } else {
    qsort((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
          tag_sort_func);
  }

#if 0
  {
    printf("Sorted tag array: \n");
    i = 0;
    while (i < len)
      {
        GtkTextTag *t = tag_array_p[i];
        printf("  %s priority %d\n", t->name, t->priority);
        
        ++i;
      }
  }
#endif
}

/*
1032
 * Attributes
1033 1034
 */

1035 1036
GtkTextAttributes*
gtk_text_attributes_new(void)
1037
{
1038
  GtkTextAttributes *values;
1039

1040
  values = g_new0(GtkTextAttributes, 1);
1041 1042 1043 1044

  /* 0 is a valid value for most of the struct */

  values->refcount = 1;
1045 1046

  values->language = gtk_get_default_language ();
1047 1048 1049 1050 1051
  
  return values;
}

void
1052 1053
gtk_text_attributes_copy(GtkTextAttributes *src,
                           GtkTextAttributes *dest)
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
{
  guint orig_refcount;

  g_return_if_fail(!dest->realized);

  if (src == dest)
    return;
  
  /* Add refs */
  
  if (src->appearance.bg_stipple)
    gdk_bitmap_ref(src->appearance.bg_stipple);

  if (src->appearance.fg_stipple)
    gdk_bitmap_ref(src->appearance.fg_stipple);

  if (src->tab_array)
    gtk_text_view_tab_array_ref(src->tab_array);

  /* Remove refs */
  
  if (dest->appearance.bg_stipple)
    gdk_bitmap_unref(dest->appearance.bg_stipple);

  if (dest->appearance.fg_stipple)
    gdk_bitmap_unref(dest->appearance.fg_stipple);

  if (dest->tab_array)
    gtk_text_view_tab_array_unref(dest->tab_array);

  /* Copy */
  orig_refcount = dest->refcount;
  
  *dest = *src;

  dest->font_desc = pango_font_description_copy (src->font_desc);
1090 1091
  dest->language = g_strdup (src->language);
  
1092 1093 1094 1095 1096
  dest->refcount = orig_refcount;
  dest->realized = FALSE;
}

void
1097
gtk_text_attributes_ref(GtkTextAttributes *values)
1098 1099 1100 1101 1102 1103 1104
{
  g_return_if_fail(values != NULL);

  values->refcount += 1;
}

void
1105
gtk_text_attributes_unref(GtkTextAttributes *values)
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
{
  g_return_if_fail(values != NULL);
  g_return_if_fail(values->refcount > 0);

  values->refcount -= 1;

  if (values->refcount == 0)
    {
      g_assert(!values->realized);
      
      if (values->appearance.bg_stipple)
        gdk_bitmap_unref(values->appearance.bg_stipple);
      
      if (values->font_desc)
        pango_font_description_free (values->font_desc);
      
      if (values->appearance.fg_stipple)
        gdk_bitmap_unref(values->appearance.fg_stipple);

      if (values->tab_array)
        gtk_text_view_tab_array_unref(values->tab_array);
1127 1128 1129

      if (values->language)
        g_free (values->language);
1130 1131 1132 1133 1134 1135
      
      g_free(values);
    }
}

void
1136
gtk_text_attributes_realize(GtkTextAttributes *values,
1137 1138
                              GdkColormap *cmap,
                              GdkVisual *visual)
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
{
  g_return_if_fail(values != NULL);
  g_return_if_fail(values->refcount > 0);
  g_return_if_fail(!values->realized);
  
  /* It is wrong to use this colormap, FIXME */
  gdk_colormap_alloc_color(cmap,
                           &values->appearance.fg_color,
                           FALSE, TRUE);

  gdk_colormap_alloc_color(cmap,
                           &values->appearance.bg_color,
                           FALSE, TRUE);

  values->realized = TRUE;
}

void
1157
gtk_text_attributes_unrealize(GtkTextAttributes *values,
1158 1159
                                GdkColormap *cmap,
                                GdkVisual *visual)
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
{
  g_return_if_fail(values != NULL);
  g_return_if_fail(values->refcount > 0);
  g_return_if_fail(values->realized);
  
  gdk_colormap_free_colors(cmap,
                           &values->appearance.fg_color, 1);
  
  
  gdk_colormap_free_colors(cmap,
                           &values->appearance.bg_color, 1);

  values->appearance.fg_color.pixel = 0;
  values->appearance.bg_color.pixel = 0;

  values->realized = FALSE;
}

void
1179
gtk_text_attributes_fill_from_tags(GtkTextAttributes *dest,
1180 1181
                                     GtkTextTag**        tags,
                                     guint               n_tags)
1182 1183 1184 1185 1186 1187 1188 1189
{
  guint n = 0;

  g_return_if_fail(!dest->realized);  
  
  while (n < n_tags)
    {
      GtkTextTag *tag = tags[n];
1190
      GtkTextAttributes *vals = tag->values;
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276

      if (n > 0)
        g_assert(tags[n]->priority > tags[n-1]->priority);
      
      if (tag->bg_color_set)
        {
          dest->appearance.bg_color = vals->appearance.bg_color;
          
          dest->appearance.draw_bg = TRUE;
        }
      
      if (tag->border_width_set)
        dest->border_width = vals->border_width;

      if (tag->relief_set)
        dest->relief = vals->relief;

      if (tag->bg_stipple_set)
        {
          gdk_bitmap_ref(vals->appearance.bg_stipple);
          if (dest->appearance.bg_stipple)
            gdk_bitmap_unref(dest->appearance.bg_stipple);
          dest->appearance.bg_stipple = vals->appearance.bg_stipple;

          dest->appearance.draw_bg = TRUE;
        }

      if (tag->fg_color_set)
        dest->appearance.fg_color = vals->appearance.fg_color;
         
      if (tag->font_set)
        {
          if (dest->font_desc)
            pango_font_description_free (dest->font_desc);
          dest->font_desc = pango_font_description_copy (vals->font_desc);
        }

      if (tag->fg_stipple_set)
        {
          gdk_bitmap_ref(vals->appearance.fg_stipple);
          if (dest->appearance.fg_stipple)
            gdk_bitmap_unref(dest->appearance.fg_stipple);
          dest->appearance.fg_stipple = vals->appearance.fg_stipple;
        }

      if (tag->justify_set)
        dest->justify = vals->justify;

      if (vals->direction != GTK_TEXT_DIR_NONE)
        dest->direction = vals->direction;
      
      if (tag->left_margin_set)
        dest->left_margin = vals->left_margin;

      if (tag->left_wrapped_line_margin_set)
        dest->left_wrapped_line_margin = vals->left_wrapped_line_margin;

      if (tag->offset_set)
        dest->offset = vals->offset;

      if (tag->right_margin_set)
        dest->right_margin = vals->right_margin;

      if (tag->pixels_above_lines_set)
        dest->pixels_above_lines = vals->pixels_above_lines;

      if (tag->pixels_below_lines_set)
        dest->pixels_below_lines = vals->pixels_below_lines;

      if (tag->pixels_inside_wrap_set)
        dest->pixels_inside_wrap = vals->pixels_inside_wrap;

      if (tag->tab_array_set)
        {
          gtk_text_view_tab_array_ref(vals->tab_array);
          if (dest->tab_array)
            gtk_text_view_tab_array_unref(dest->tab_array);
          dest->tab_array = vals->tab_array;
        }

      if (tag->wrap_mode_set)
        dest->wrap_mode = vals->wrap_mode;

      if (tag->underline_set)
        dest->appearance.underline = vals->appearance.underline;

1277 1278
      if (tag->strikethrough_set)
        dest->appearance.strikethrough = vals->appearance.strikethrough;
1279

1280 1281
      if (tag->invisible_set)
        dest->invisible = vals->invisible;
1282 1283 1284 1285 1286 1287

      if (tag->editable_set)
        dest->editable = vals->editable;

      if (tag->bg_full_height_set)
        dest->bg_full_height = vals->bg_full_height;
1288 1289 1290 1291 1292 1293

      if (tag->language_set)
        {
          g_free (dest->language);
          dest->language = g_strdup (vals->language);
        }
1294 1295 1296 1297
      
      ++n;
    }
}