aboutsummaryrefslogtreecommitdiffstats
path: root/appveyor.yml
Commit message (Expand)AuthorAgeFilesLines
* Create bytecode for all tests and push to remote repo.chriseth2017-03-231-0/+12
* Include --show-progress in soltestAlex Beregszaszi2017-02-091-1/+1
* Fix licensing headersVoR02202016-11-231-5/+5
* Trying to attach artifacts to tags only.chriseth2016-11-031-3/+2
* AppVeyor: build only pushes to master and develop branchPaweł Bylica2016-10-201-0/+4
* fix yml scriptDimitry2016-09-011-1/+0
* soltest on windowsDimitry2016-08-311-6/+13
* Confirmed that ZIPs work for Solidity.Bob Summerwill2016-08-161-1/+1
* Flipped solidity whitelisting to develop, to check ZIP workflow is OK.Bob Summerwill2016-08-161-1/+1
* Disable AppVeyorBot commentsDenton Liu2016-08-161-0/+6
* Merge pull request #837 from chriseth/testsuitecleanupchriseth2016-08-121-1/+1
|\
| * Move custom test options to after --chriseth2016-08-121-1/+1
* | Flip whitelisting to release branch.Bob Summerwill2016-08-121-1/+1
|/
* Flipped back to whitelisting develop, and attempting to fix conditional.Bob Summerwill2016-08-121-1/+1
* Switched whitelisting to 'release' branch for Appveyor and TravisCI.Bob Summerwill2016-08-121-5/+1
* Publish releases for develop branch.chriseth2016-08-121-2/+2
* New appveyor key.chriseth2016-08-121-1/+1
* Flip whitelisting back to 'release' branch.Bob Summerwill2016-08-121-1/+1
* Added comments about 'auth_token' setup for Appveyor.Bob Summerwill2016-08-121-1/+10
* Re-add the ZIP release flow for Solidity.Bob Summerwill2016-08-111-20/+22
* Re-enabled Appveyor cache.Bob Summerwill2016-08-031-0/+1
* OK - Looks like Appveyor softest automation still needs more work before it i...Bob Summerwill2016-08-031-6/+6
* Clear Appveyor cache.Bob Summerwill2016-08-031-2/+1
* Re-enable code builds for Solidity unit-tests within Appveyor.Bob Summerwill2016-08-031-1/+1
* Let's try Windows Tests-over-IPC and see where we are at.Bob Summerwill2016-08-031-7/+7
* Make the Solidity repository standalone.Bob Summerwill2016-08-011-0/+76
'>297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 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 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 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 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 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 858 859
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-reflow.c
 * Copyright (C) 2000  Helix Code, Inc.
 * Author: Chris Lahey <clahey@helixcode.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <gnome.h>
#include <math.h>
#include "e-reflow.h"
#include "gal/e-text/e-text.h"
#include "e-canvas-utils.h"
#include "e-canvas.h"
#include "gal/util/e-util.h"

static void e_reflow_init       (EReflow         *reflow);
static void e_reflow_class_init (EReflowClass    *klass);
static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void e_reflow_destroy (GtkObject *object);
static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event);
static void e_reflow_realize (GnomeCanvasItem *item);
static void e_reflow_unrealize (GnomeCanvasItem *item);
static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
                    int x, int y, int width, int height);
static void e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags);
static double e_reflow_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item);
static void e_reflow_reflow (GnomeCanvasItem *item, int flags);
static void e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item);
static void set_empty(EReflow *e_reflow);

static void e_reflow_resize_children (GnomeCanvasItem *item);

#define E_REFLOW_DIVIDER_WIDTH 2
#define E_REFLOW_BORDER_WIDTH 7
#define E_REFLOW_FULL_GUTTER (E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH * 2)

static GnomeCanvasGroupClass *parent_class = NULL;

/* The arguments we take */
enum {
    ARG_0,
    ARG_MINIMUM_WIDTH,
    ARG_WIDTH,
    ARG_HEIGHT,
    ARG_EMPTY_MESSAGE,
};

GtkType
e_reflow_get_type (void)
{
  static GtkType reflow_type = 0;

  if (!reflow_type)
    {
      static const GtkTypeInfo reflow_info =
      {
        "EReflow",
        sizeof (EReflow),
        sizeof (EReflowClass),
        (GtkClassInitFunc) e_reflow_class_init,
        (GtkObjectInitFunc) e_reflow_init,
        /* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
        (GtkClassInitFunc) NULL,
      };

      reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info);
    }

  return reflow_type;
}

static void
e_reflow_class_init (EReflowClass *klass)
{
    GtkObjectClass *object_class;
    GnomeCanvasItemClass *item_class;

    object_class = (GtkObjectClass*) klass;
    item_class = (GnomeCanvasItemClass *) klass;

    parent_class = gtk_type_class (gnome_canvas_group_get_type ());
  
    gtk_object_add_arg_type ("EReflow::minimum_width", GTK_TYPE_DOUBLE, 
                 GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); 
    gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, 
                 GTK_ARG_READABLE, ARG_WIDTH); 
    gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, 
                 GTK_ARG_READWRITE, ARG_HEIGHT);
    gtk_object_add_arg_type ("EReflow::empty_message", GTK_TYPE_STRING, 
                 GTK_ARG_READWRITE, ARG_EMPTY_MESSAGE);

    klass->add_item       = e_reflow_real_add_item;
 
    object_class->set_arg   = e_reflow_set_arg;
    object_class->get_arg   = e_reflow_get_arg;
    object_class->destroy   = e_reflow_destroy;
  
    /* GnomeCanvasItem method overrides */
    item_class->event       = e_reflow_event;
    item_class->realize     = e_reflow_realize;
    item_class->unrealize   = e_reflow_unrealize;
    item_class->draw        = e_reflow_draw;
    item_class->update      = e_reflow_update;
    item_class->point       = e_reflow_point;
}

static void
e_reflow_init (EReflow *reflow)
{
    reflow->items = NULL;
    reflow->columns = NULL;
    reflow->column_width = 150;

    reflow->minimum_width = 10;
    reflow->width = 10;
    reflow->height = 10;
    reflow->idle = 0;

    reflow->empty_message = NULL;
    reflow->empty_text = NULL;

    reflow->column_drag = FALSE;

    reflow->need_height_update = FALSE;
    reflow->need_column_resize = FALSE;

    reflow->default_cursor_shown = TRUE;
    reflow->arrow_cursor = NULL;
    reflow->default_cursor = NULL;

    e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(reflow), e_reflow_reflow);
}

static void
e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
    GnomeCanvasItem *item;
    EReflow *e_reflow;

    item = GNOME_CANVAS_ITEM (o);
    e_reflow = E_REFLOW (o);
    
    switch (arg_id){
    case ARG_HEIGHT:
        e_reflow->height = GTK_VALUE_DOUBLE (*arg);
        e_canvas_item_request_reflow(item);
        break;
    case ARG_MINIMUM_WIDTH:
        e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg);
        if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o))
            set_empty(e_reflow);
        e_canvas_item_request_reflow(item);
        break;
    case ARG_EMPTY_MESSAGE:
        g_free(e_reflow->empty_message);
        e_reflow->empty_message = g_strdup(GTK_VALUE_STRING (*arg));
        if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o))
            set_empty(e_reflow);
    }
}

static void
e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
    EReflow *e_reflow;

    e_reflow = E_REFLOW (object);

    switch (arg_id) {
    case ARG_MINIMUM_WIDTH:
        GTK_VALUE_DOUBLE (*arg) = e_reflow->minimum_width;
        break;
    case ARG_WIDTH:
        GTK_VALUE_DOUBLE (*arg) = e_reflow->width;
        break;
    case ARG_HEIGHT:
        GTK_VALUE_DOUBLE (*arg) = e_reflow->height;
        break;
    case ARG_EMPTY_MESSAGE:
        GTK_VALUE_STRING (*arg) = g_strdup(e_reflow->empty_message);
        break;
    default:
        arg->type = GTK_TYPE_INVALID;
        break;
    }
}

static void
e_reflow_destroy (GtkObject *object)
{
    EReflow *reflow = E_REFLOW(object);

    g_list_foreach(reflow->items, (GFunc) gtk_object_unref, NULL);
    g_list_free(reflow->items);
    reflow->items = NULL;
    
    g_free(reflow->empty_message);
  
    GTK_OBJECT_CLASS(parent_class)->destroy (object);
}

static void
e_reflow_realize (GnomeCanvasItem *item)
{
    EReflow *e_reflow;
    GnomeCanvasGroup *group;
    GList *list;
    GtkAdjustment *adjustment;

    e_reflow = E_REFLOW (item);
    group = GNOME_CANVAS_GROUP( item );

    if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize)
        (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item);
    
    e_reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
    e_reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR);

    for(list = e_reflow->items; list; list = g_list_next(list)) {
        GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data);
        gnome_canvas_item_set(item,
                      "width", (double) e_reflow->column_width,
                      NULL);
    }

    set_empty(e_reflow);

    e_canvas_item_request_reflow(item);
    
    adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
    adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
    adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
    gtk_adjustment_changed(adjustment);
    
    if (!item->canvas->aa) {
    }
}

static void
e_reflow_unrealize (GnomeCanvasItem *item)
{
  EReflow *e_reflow;

  e_reflow = E_REFLOW (item);

  if (!item->canvas->aa)
    {
    }
  
  gdk_cursor_destroy (e_reflow->arrow_cursor);
  gdk_cursor_destroy (e_reflow->default_cursor);
  e_reflow->arrow_cursor = NULL;
  e_reflow->default_cursor = NULL;

  g_list_free (e_reflow->columns);
  e_reflow->columns = NULL;

  if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize)
    (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item);
}

static gint
e_reflow_pick_line (EReflow *e_reflow, double x)
{
    x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
    x /= e_reflow->column_width + E_REFLOW_FULL_GUTTER;
    return x;
}

static gboolean
e_reflow_event (GnomeCanvasItem *item, GdkEvent *event)
{
    EReflow *e_reflow;
 
    e_reflow = E_REFLOW (item);

    switch( event->type )
        {
        case GDK_KEY_PRESS:
            if (event->key.keyval == GDK_Tab || 
                event->key.keyval == GDK_KP_Tab || 
                event->key.keyval == GDK_ISO_Left_Tab) {
                GList *list;
                for (list = e_reflow->items; list; list = list->next) {
                    GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data);
                    EFocus has_focus;
                    gtk_object_get(GTK_OBJECT(item),
                               "has_focus", &has_focus,
                               NULL);
                    if (has_focus) {
                        if (event->key.state & GDK_SHIFT_MASK)
                            list = list->prev;
                        else
                            list = list->next;
                        if (list) {
                            item = GNOME_CANVAS_ITEM(list->data);
                            gnome_canvas_item_set(item,
                                          "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START,
                                          NULL);
                            return 1;
                        } else {
                            return 0;
                        }
                    }
                }
            }
            break;
        case GDK_BUTTON_PRESS:
            switch(event->button.button) 
                {
                case 1:
                    {
                        GdkEventButton *button = (GdkEventButton *) event;
                        double n_x, max_x;
                        n_x = button->x;
                        n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
                        n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER));

                        max_x = E_REFLOW_BORDER_WIDTH;
                        max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count;
                        if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > button->x ) {
                            e_reflow->which_column_dragged = e_reflow_pick_line(e_reflow, button->x);
                            e_reflow->start_x = e_reflow->which_column_dragged * (e_reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2;
                            e_reflow->temp_column_width = e_reflow->column_width;
                            e_reflow->column_drag = TRUE;
                          
                            gnome_canvas_item_grab (item, 
                                        GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
                                        e_reflow->arrow_cursor,
                                        button->time);
                          
                            e_reflow->previous_temp_column_width = -1;
                            e_reflow->need_column_resize = TRUE;
                            gnome_canvas_item_request_update(item);
                            return TRUE;
                        }
                    }
                    break;
                case 4:
                    {
                        GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
                        gdouble new_value = adjustment->value;
                        new_value -= adjustment->step_increment;
                        gtk_adjustment_set_value(adjustment, new_value);
                    }
                    break;
                case 5: 
                    {
                        GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
                        gdouble new_value = adjustment->value;
                        new_value += adjustment->step_increment;
                        if ( new_value > adjustment->upper - adjustment->page_size )
                            new_value = adjustment->upper - adjustment->page_size;
                        gtk_adjustment_set_value(adjustment, new_value);
                    }
                    break;
                }
            break;
        case GDK_BUTTON_RELEASE:
            if (e_reflow->column_drag) {
                gdouble old_width = e_reflow->column_width;
                GdkEventButton *button = (GdkEventButton *) event;
                GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
                e_reflow->temp_column_width = e_reflow->column_width +
                    (button->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value));
                if ( e_reflow->temp_column_width < 50 )
                    e_reflow->temp_column_width = 50;
                e_reflow->column_drag = FALSE;
                if ( old_width != e_reflow->temp_column_width ) {
                    gtk_adjustment_set_value(adjustment, adjustment->value + e_reflow_pick_line(e_reflow, adjustment->value) * (e_reflow->temp_column_width - e_reflow->column_width));
                    e_reflow->column_width = e_reflow->temp_column_width;
                    adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
                    adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
                    gtk_adjustment_changed(adjustment);
                    e_reflow_resize_children(item);
                    e_canvas_item_request_reflow(item);
                }
                e_reflow->need_column_resize = TRUE;
                gnome_canvas_item_request_update(item);
                gnome_canvas_item_ungrab (item, button->time);
                return TRUE;
            }
            break;
        case GDK_MOTION_NOTIFY:
            if (e_reflow->column_drag) {
                double old_width = e_reflow->temp_column_width;
                GdkEventMotion *motion = (GdkEventMotion *) event;
                GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
                e_reflow->temp_column_width = e_reflow->column_width +
                    (motion->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value));
                if (e_reflow->temp_column_width < 50)
                    e_reflow->temp_column_width = 50;
                if (old_width != e_reflow->temp_column_width) {
                    e_reflow->need_column_resize = TRUE;
                    gnome_canvas_item_request_update(item);
                }
                return TRUE;
            } else {
                GdkEventMotion *motion = (GdkEventMotion *) event;
                double n_x, max_x;

                n_x = motion->x;
                n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
                n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER));

                max_x = E_REFLOW_BORDER_WIDTH;
                max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count;

                if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > motion->x) {
                    if ( e_reflow->default_cursor_shown ) {
                        gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor);
                        e_reflow->default_cursor_shown = FALSE;
                    }
                } else 
                    if ( ! e_reflow->default_cursor_shown ) {
                        gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor);
                        e_reflow->default_cursor_shown = TRUE;
                    }
                
            }
            break;
        case GDK_ENTER_NOTIFY:
            if (!e_reflow->column_drag) {
                GdkEventCrossing *crossing = (GdkEventCrossing *) event;
                double n_x, max_x;
                n_x = crossing->x;
                n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
                n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER));

                max_x = E_REFLOW_BORDER_WIDTH;
                max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count;
                if ( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > crossing->x) {
                    if ( e_reflow->default_cursor_shown ) {
                        gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor);
                        e_reflow->default_cursor_shown = FALSE;
                    }
                }
            }
            break;
        case GDK_LEAVE_NOTIFY:
            if (!e_reflow->column_drag) {
                GdkEventCrossing *crossing = (GdkEventCrossing *) event;
                double n_x;
                n_x = crossing->x;
                n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
                n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER));
                if ( !( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) ) {
                    if ( ! e_reflow->default_cursor_shown ) {
                        gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor);
                        e_reflow->default_cursor_shown = TRUE;
                    }
                }
            }
            break;
        default:
            break;
        }
  
    if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event)
        return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event);
    else
        return 0;
}

static void
e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item)
{
    e_reflow->items = g_list_append(e_reflow->items, item);
    gtk_object_ref(GTK_OBJECT(item));
    if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) {
        gnome_canvas_item_set(item,
                      "width", (double) e_reflow->column_width,
                      NULL);
        e_reflow_post_add_item(e_reflow, item);
        e_canvas_item_request_reflow(item);
    }

}

static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
                    int x, int y, int width, int height)
{
    int x_rect, y_rect, width_rect, height_rect;
    gdouble running_width;
    EReflow *e_reflow = E_REFLOW(item);
    int i;
    double column_width;

    if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw)
        GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height);
    column_width = e_reflow->column_width;
    running_width = E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
    x_rect = running_width;
    y_rect = E_REFLOW_BORDER_WIDTH;
    width_rect = E_REFLOW_DIVIDER_WIDTH;
    height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

    /* Compute first column to draw. */
    i = x;
    i /= column_width + E_REFLOW_FULL_GUTTER;
    running_width += i * (column_width + E_REFLOW_FULL_GUTTER);

    for ( ; i < e_reflow->column_count; i++) {
        if ( running_width > x + width )
            break;
        x_rect = running_width;
        gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style,
                   drawable,
                   GTK_STATE_ACTIVE,
                   GTK_SHADOW_NONE,
                   NULL,
                   GTK_WIDGET(item->canvas),
                   "reflow",
                   x_rect - x,
                   y_rect - y,
                   width_rect,
                   height_rect);
        running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
    }
    if (e_reflow->column_drag) {
        int start_line = e_reflow_pick_line(e_reflow,
                            gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); 
        i = x - start_line * (column_width + E_REFLOW_FULL_GUTTER);
        running_width = start_line * (column_width + E_REFLOW_FULL_GUTTER);
        column_width = e_reflow->temp_column_width;
        running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
        i += start_line * (column_width + E_REFLOW_FULL_GUTTER);
        running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
        x_rect = running_width;
        y_rect = E_REFLOW_BORDER_WIDTH;
        width_rect = E_REFLOW_DIVIDER_WIDTH;
        height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

        /* Compute first column to draw. */
        i /= column_width + E_REFLOW_FULL_GUTTER;
        running_width += i * (column_width + E_REFLOW_FULL_GUTTER);
        
        for ( ; i < e_reflow->column_count; i++) {
            if ( running_width > x + width )
                break;
            x_rect = running_width;
            gdk_draw_rectangle(drawable,
                       GTK_WIDGET(item->canvas)->style->fg_gc[GTK_STATE_NORMAL],
                       TRUE,
                       x_rect - x,
                       y_rect - y,
                       width_rect - 1,
                       height_rect - 1);                       
            running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
        }
    }
}

static void
e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags)
{
    EReflow *e_reflow;
    double x0, x1, y0, y1;

    e_reflow = E_REFLOW (item);

    if (GNOME_CANVAS_ITEM_CLASS(parent_class)->update)
        GNOME_CANVAS_ITEM_CLASS(parent_class)->update (item, affine, clip_path, flags);
    
    x0 = item->x1;
    y0 = item->y1;
    x1 = item->x2;
    y1 = item->y2;
    if ( x1 < x0 + e_reflow->width )
        x1 = x0 + e_reflow->width;
    if ( y1 < y0 + e_reflow->height )
        y1 = y0 + e_reflow->height;
    item->x2 = x1;
    item->y2 = y1;

    if (e_reflow->need_height_update) {
        x0 = item->x1;
        y0 = item->y1;
        x1 = item->x2;
        y1 = item->y2;
        if ( x0 > 0 )
            x0 = 0;
        if ( y0 > 0 )
            y0 = 0;
        if ( x1 < E_REFLOW(item)->width )
            x1 = E_REFLOW(item)->width;
        if ( x1 < E_REFLOW(item)->height )
            x1 = E_REFLOW(item)->height;

        gnome_canvas_request_redraw(item->canvas, x0, y0, x1, y1);
        e_reflow->need_height_update = FALSE;
    } else if (e_reflow->need_column_resize) {
        int x_rect, y_rect, width_rect, height_rect;
        int start_line = e_reflow_pick_line(e_reflow,
                            gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); 
        gdouble running_width;
        int i;
        double column_width;
        
        if ( e_reflow->previous_temp_column_width != -1 ) {
            running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER);
            column_width = e_reflow->previous_temp_column_width;
            running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
            running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
            y_rect = E_REFLOW_BORDER_WIDTH;
            width_rect = E_REFLOW_DIVIDER_WIDTH;
            height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2);
            
            for ( i = 0; i < e_reflow->column_count; i++) {
                x_rect = running_width;
                gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect);
                running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
            }
        }
        
        if ( e_reflow->temp_column_width != -1 ) {
            running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER);
            column_width = e_reflow->temp_column_width;
            running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
            running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
            y_rect = E_REFLOW_BORDER_WIDTH;
            width_rect = E_REFLOW_DIVIDER_WIDTH;
            height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2);
            
            for ( i = 0; i < e_reflow->column_count; i++) {
                x_rect = running_width;
                gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect);
                running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
            }
        }
        
        e_reflow->previous_temp_column_width = e_reflow->temp_column_width;
        e_reflow->need_column_resize = FALSE;
    }
}

static void
e_reflow_resize_children (GnomeCanvasItem *item)
{
    GList *list;
    EReflow *e_reflow;

    e_reflow = E_REFLOW (item);
    for ( list = e_reflow->items; list; list = list->next ) {
        GnomeCanvasItem *child = GNOME_CANVAS_ITEM(list->data);
        gnome_canvas_item_set(child,
                      "width", (double) e_reflow->column_width,
                      NULL);
    }
}

static double
e_reflow_point (GnomeCanvasItem *item,
        double x, double y, int cx, int cy,
        GnomeCanvasItem **actual_item)
{
    double distance = 1;

    if (GNOME_CANVAS_ITEM_CLASS(parent_class)->point)
        distance = GNOME_CANVAS_ITEM_CLASS(parent_class)->point (item, x, y, cx, cy, actual_item);
    if (*actual_item)
        return 0;
    
    *actual_item = item;
    return 0;
#if 0
    if (y >= E_REFLOW_BORDER_WIDTH && y <= e_reflow->height - E_REFLOW_BORDER_WIDTH) {
            float n_x;
        n_x = x;
        n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
        n_x = fmod(n_x, (e_reflow->column_width + E_REFLOW_FULL_GUTTER));
        if (n_x < E_REFLOW_FULL_GUTTER) {
            *actual_item = item;
            return 0;
        }
    }
    return distance;
#endif
}

static void
_reflow( EReflow *e_reflow )
{
    gdouble running_height;
    GList *list;
    double item_height;

    if (e_reflow->columns) {
        g_list_free (e_reflow->columns);
        e_reflow->columns = NULL;
    }

    e_reflow->column_count = 0;

    if (e_reflow->items == NULL) {
        e_reflow->columns = NULL;
        e_reflow->column_count = 0;
        return;
    }

    list = e_reflow->items;
    
    gtk_object_get (GTK_OBJECT(list->data),
            "height", &item_height,
            NULL);
    running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH;
    e_reflow->columns = g_list_append (e_reflow->columns, list);
    e_reflow->column_count = 1;

    list = g_list_next(list);

    for ( ; list; list = g_list_next(list)) {
        gtk_object_get (GTK_OBJECT(list->data),
                "height", &item_height,
                NULL);
        if (running_height + item_height + E_REFLOW_BORDER_WIDTH > e_reflow->height) {
            running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH;
            e_reflow->columns = g_list_append (e_reflow->columns, list);
            e_reflow->column_count ++;
        } else {
            running_height += item_height + E_REFLOW_BORDER_WIDTH;
        }
    }
}

static void
set_empty(EReflow *e_reflow)
{
    if (e_reflow->items == NULL) {
        if (e_reflow->empty_text) {
            if (e_reflow->empty_message) {
                gnome_canvas_item_set(e_reflow->empty_text,
                              "width", e_reflow->minimum_width,
                              "text", e_reflow->empty_message,
                              NULL);
                e_canvas_item_move_absolute(e_reflow->empty_text,
                                e_reflow->minimum_width / 2,
                                0);
            } else {
                gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text));
                e_reflow->empty_text = NULL;
            }
        } else {
            if (e_reflow->empty_message)
                e_reflow->empty_text = 
                    gnome_canvas_item_new(GNOME_CANVAS_GROUP(e_reflow),
                                  e_text_get_type(),
                                  "anchor", GTK_ANCHOR_N,
                                  "width", e_reflow->minimum_width,
                                  "clip", TRUE,
                                  "use_ellipsis", TRUE,
                                  "font_gdk", GTK_WIDGET(GNOME_CANVAS_ITEM(e_reflow)->canvas)->style->font,
                                  "fill_color", "black",
                                  "justification", GTK_JUSTIFY_CENTER,
                                  "text", e_reflow->empty_message,
                                  NULL);
            e_canvas_item_move_absolute(e_reflow->empty_text,
                            e_reflow->minimum_width / 2,
                            0);
        }
    } else {
        if (e_reflow->empty_text) {
            gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text));
            e_reflow->empty_text = NULL;
        }
    }
}

static void
e_reflow_reflow( GnomeCanvasItem *item, int flags )
{
    EReflow *e_reflow = E_REFLOW(item);
    if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) {

        gdouble old_width;
        gdouble running_width;

        _reflow (e_reflow);
        
        old_width = e_reflow->width;
        
        running_width = E_REFLOW_BORDER_WIDTH;

        if (e_reflow->items == NULL) {
        } else {
            GList *list;
            GList *next_column;
            gdouble item_height;
            gdouble running_height;

            running_height = E_REFLOW_BORDER_WIDTH;
            
            list = e_reflow->items;
            gtk_object_get (GTK_OBJECT(list->data),
                    "height", &item_height,
                    NULL);
            e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data),
                            (double) running_width,
                            (double) running_height);
            running_height += item_height + E_REFLOW_BORDER_WIDTH;
            next_column = g_list_next(e_reflow->columns);
            list = g_list_next(list);
            
            for( ; list; list = g_list_next(list)) {
                gtk_object_get (GTK_OBJECT(list->data),
                        "height", &item_height,
                        NULL);

                if (next_column && (next_column->data == list)) {
                    next_column = g_list_next (next_column);
                    running_height = E_REFLOW_BORDER_WIDTH;
                    running_width += e_reflow->column_width + E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH;
                }
                e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data),
                                (double) running_width,
                                (double) running_height);

                running_height += item_height + E_REFLOW_BORDER_WIDTH;
            }
                 
        }
        e_reflow->width = running_width + e_reflow->column_width + E_REFLOW_BORDER_WIDTH;
        if ( e_reflow->width < e_reflow->minimum_width )
            e_reflow->width = e_reflow->minimum_width;
        if (old_width != e_reflow->width)
            e_canvas_item_request_parent_reflow(item);
    }
}

void
e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item)
{
    if (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item)
        (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) (e_reflow, item);
}

void
e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item)
{
    set_empty(e_reflow);
}