aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs
diff options
context:
space:
mode:
authorArturo Espinosa <unammx@src.gnome.org>1998-04-18 12:02:46 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-04-18 12:02:46 +0800
commitf1b08663ddff6432289ca4780bc823c96d471657 (patch)
treefed1c651f292c4855550302ef94808338b9fd0dc /calendar/pcs
parentd79ee74dad39ee5210482aa90a7c6a7b2f0b7517 (diff)
downloadgsoc2013-evolution-f1b08663ddff6432289ca4780bc823c96d471657.tar.gz
gsoc2013-evolution-f1b08663ddff6432289ca4780bc823c96d471657.tar.zst
gsoc2013-evolution-f1b08663ddff6432289ca4780bc823c96d471657.zip
Yes.
Yes. It works. It loads, it saves, it does all that stuff. It works, even if federico complains that we did not test close. Repetition, alarms, all that stuff you all guys love. It it is there. We did minimal testing, but we know you will happilly commit a fix if you find a problem, right? Ok, we are off to a party now. Miguel svn path=/trunk/; revision=155
Diffstat (limited to 'calendar/pcs')
-rw-r--r--calendar/pcs/calobj.c18
-rw-r--r--calendar/pcs/calobj.h7
2 files changed, 25 insertions, 0 deletions
diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c
index 47d8c8a97e..624a179b05 100644
--- a/calendar/pcs/calobj.c
+++ b/calendar/pcs/calobj.c
@@ -1102,3 +1102,21 @@ ical_object_compute_end (iCalObject *ico)
ico->recur->_enddate = 0;
ical_object_generate_events (ico, ico->dtstart, 0, duration_callback, &count);
}
+
+int
+alarm_compute_offset (CalendarAlarm *a)
+{
+ if (!a->enabled)
+ return -1;
+ switch (a->units){
+ case ALARM_MINUTES:
+ a->offset = a->count * 60;
+ break;
+ case ALARM_HOURS:
+ a->offset = a->count * 3600;
+ break;
+ case ALARM_DAYS:
+ a->offset = a->count * 24 * 3600;
+ }
+ return a->offset;
+}
diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h
index 26b0acf35b..60483c68ad 100644
--- a/calendar/pcs/calobj.h
+++ b/calendar/pcs/calobj.h
@@ -32,6 +32,10 @@ typedef struct {
int count;
enum AlarmUnit units;
char *data;
+
+ /* Does not get saved, internally used */
+ time_t offset;
+ time_t trigger;
/* Widgets */
void *w_count; /* A GtkEntry */
@@ -180,6 +184,9 @@ void ical_object_generate_events (iCalObject *ico, time_t start, time
/* Computes the enddate field of the recurrence based on the duration */
void ical_object_compute_end (iCalObject *ico);
+/* Returns the number of seconds configured to trigger the alarm in advance to an event */
+int alarm_compute_offset (CalendarAlarm *a);
+
END_GNOME_DECLS
#endif
249 250 251 252 253 254 255 256 257 258 259 260 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 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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * e-canvas.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 <gnome.h>
#include "e-canvas.h"
static void e_canvas_init           (ECanvas         *card);
static void e_canvas_destroy        (GtkObject        *object);
static void e_canvas_class_init     (ECanvasClass    *klass);
static void e_canvas_realize        (GtkWidget        *widget);
static void e_canvas_unrealize      (GtkWidget        *widget);
static gint e_canvas_key            (GtkWidget        *widget,
                     GdkEventKey      *event);

static gint e_canvas_focus_in       (GtkWidget        *widget,
                     GdkEventFocus    *event);
static gint e_canvas_focus_out      (GtkWidget        *widget,
                     GdkEventFocus    *event);

static int emit_event (GnomeCanvas *canvas, GdkEvent *event);

static GnomeCanvasClass *parent_class = NULL;

enum {
    REFLOW,
    LAST_SIGNAL
};

static guint e_canvas_signals [LAST_SIGNAL] = { 0, };

GtkType
e_canvas_get_type (void)
{
    static GtkType canvas_type = 0;

    if (!canvas_type)
    {
        static const GtkTypeInfo canvas_info =
        {
            "ECanvas",
            sizeof (ECanvas),
            sizeof (ECanvasClass),
            (GtkClassInitFunc) e_canvas_class_init,
            (GtkObjectInitFunc) e_canvas_init,
            /* reserved_1 */ NULL,
            /* reserved_2 */ NULL,
            (GtkClassInitFunc) NULL,
        };

        canvas_type = gtk_type_unique (gnome_canvas_get_type (), &canvas_info);
    }

    return canvas_type;
}

static void
e_canvas_class_init (ECanvasClass *klass)
{
    GtkObjectClass *object_class;
    GnomeCanvasClass *canvas_class;
    GtkWidgetClass *widget_class;

    object_class = (GtkObjectClass*) klass;
    canvas_class = (GnomeCanvasClass *) klass;
    widget_class = (GtkWidgetClass *) klass;

    parent_class = gtk_type_class (gnome_canvas_get_type ());

    object_class->destroy = e_canvas_destroy;

    widget_class->key_press_event = e_canvas_key;
    widget_class->key_release_event = e_canvas_key;
    widget_class->focus_in_event = e_canvas_focus_in;
    widget_class->focus_out_event = e_canvas_focus_out;
    widget_class->realize = e_canvas_realize;
    widget_class->unrealize = e_canvas_unrealize;

    klass->reflow = NULL;

    e_canvas_signals [REFLOW] =
        gtk_signal_new ("reflow",
                GTK_RUN_LAST,
                object_class->type,
                GTK_SIGNAL_OFFSET (ECanvasClass, reflow),
                gtk_marshal_NONE__NONE,
                GTK_TYPE_NONE, 0);

    gtk_object_class_add_signals (object_class, e_canvas_signals, LAST_SIGNAL);
}

static void
e_canvas_init (ECanvas *canvas)
{
    canvas->selection = NULL;
    canvas->cursor = NULL;
    canvas->ic = NULL;
    canvas->ic_attr = NULL;
}

static void
e_canvas_destroy (GtkObject *object)
{
    ECanvas *canvas = E_CANVAS(object);
    if (canvas->idle_id)
        g_source_remove(canvas->idle_id);
    if ((GTK_OBJECT_CLASS (parent_class))->destroy)
        (*(GTK_OBJECT_CLASS (parent_class))->destroy) (object);
}

GtkWidget *
e_canvas_new ()
{
    return GTK_WIDGET (gtk_type_new (e_canvas_get_type ()));
}


/* Returns whether the item is an inferior of or is equal to the parent. */
static int
is_descendant (GnomeCanvasItem *item, GnomeCanvasItem *parent)
{
    for (; item; item = item->parent)
        if (item == parent)
            return TRUE;

    return FALSE;
}

/* Emits an event for an item in the canvas, be it the current item, grabbed
 * item, or focused item, as appropriate.
 */
static int
emit_event (GnomeCanvas *canvas, GdkEvent *event)
{
    /*GdkEvent ev;*/
    gint finished;
    GnomeCanvasItem *item;
    GnomeCanvasItem *parent;
    guint mask;

    /* Perform checks for grabbed items */

    if (canvas->grabbed_item && !is_descendant (canvas->current_item, canvas->grabbed_item))
        return FALSE;

    if (canvas->grabbed_item) {
        switch (event->type) {
        case GDK_ENTER_NOTIFY:
            mask = GDK_ENTER_NOTIFY_MASK;
            break;

        case GDK_LEAVE_NOTIFY:
            mask = GDK_LEAVE_NOTIFY_MASK;
            break;

        case GDK_MOTION_NOTIFY:
            mask = GDK_POINTER_MOTION_MASK;
            break;

        case GDK_BUTTON_PRESS:
        case GDK_2BUTTON_PRESS:
        case GDK_3BUTTON_PRESS:
            mask = GDK_BUTTON_PRESS_MASK;
            break;

        case GDK_BUTTON_RELEASE:
            mask = GDK_BUTTON_RELEASE_MASK;
            break;

        case GDK_KEY_PRESS:
            mask = GDK_KEY_PRESS_MASK;
            break;

        case GDK_KEY_RELEASE:
            mask = GDK_KEY_RELEASE_MASK;
            break;

        default:
            mask = 0;
            break;
        }

        if (!(mask & canvas->grabbed_event_mask))
            return FALSE;
    }

    /* Convert to world coordinates -- we have two cases because of diferent
     * offsets of the fields in the event structures.
     */

    /*ev = *event;*/

    switch (event->type) {
    case GDK_ENTER_NOTIFY:
    case GDK_LEAVE_NOTIFY:
        gnome_canvas_window_to_world (canvas,
                          event->crossing.x, 
                          event->crossing.y,
                          &(event->crossing.x), 
                          &(event->crossing.y));
        break;

    case GDK_MOTION_NOTIFY:
    case GDK_BUTTON_PRESS:
    case GDK_2BUTTON_PRESS:
    case GDK_3BUTTON_PRESS:
    case GDK_BUTTON_RELEASE:
        gnome_canvas_window_to_world (canvas,
                          event->motion.x, 
                          event->motion.y,
                          &(event->motion.x), 
                          &(event->motion.y));
        break;

    default:
        break;
    }

    /* Choose where we send the event */

    item = canvas->current_item;

    if (canvas->focused_item
        && ((event->type == GDK_KEY_PRESS) || (event->type == GDK_KEY_RELEASE) || (event->type == GDK_FOCUS_CHANGE)))
        item = canvas->focused_item;

    /* The event is propagated up the hierarchy (for if someone connected to
     * a group instead of a leaf event), and emission is stopped if a
     * handler returns TRUE, just like for GtkWidget events.
     */

    finished = FALSE;

    while (item && !finished) {
        gtk_object_ref (GTK_OBJECT (item));

        gtk_signal_emit_by_name (GTK_OBJECT (item), "event",
                     event,
                     &finished);

        if (GTK_OBJECT_DESTROYED (item))
            finished = TRUE;

        parent = item->parent;
        gtk_object_unref (GTK_OBJECT (item));

        item = parent;
    }

    return finished;
}

/* Key event handler for the canvas */
static gint
e_canvas_key (GtkWidget *widget, GdkEventKey *event)
{
    GnomeCanvas *canvas;

    g_return_val_if_fail (widget != NULL, FALSE);
    g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE);
    g_return_val_if_fail (event != NULL, FALSE);

    canvas = GNOME_CANVAS (widget);

    return emit_event (canvas, (GdkEvent *) event);
}


/**
 * e_canvas_item_grab_focus:
 * @item: A canvas item.
 *
 * Makes the specified item take the keyboard focus, so all keyboard events will
 * be sent to it.  If the canvas widget itself did not have the focus, it grabs
 * it as well.
 **/
void
e_canvas_item_grab_focus (GnomeCanvasItem *item)
{
    GnomeCanvasItem *focused_item;
    GdkEvent ev;

    g_return_if_fail (item != NULL);
    g_return_if_fail (GNOME_IS_CANVAS_ITEM (item));
    g_return_if_fail (GTK_WIDGET_CAN_FOCUS (GTK_WIDGET (item->canvas)));

    focused_item = item->canvas->focused_item;

    if (focused_item) {
        ev.focus_change.type = GDK_FOCUS_CHANGE;
        ev.focus_change.window = GTK_LAYOUT (item->canvas)->bin_window;
        ev.focus_change.send_event = FALSE;
        ev.focus_change.in = FALSE;

        emit_event (item->canvas, &ev);
    }

    item->canvas->focused_item = item;

    if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET(item->canvas))) {
        gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
    }

    if (focused_item) {
        ev.focus_change.type = GDK_FOCUS_CHANGE;
        ev.focus_change.window = GTK_LAYOUT (item->canvas)->bin_window;
        ev.focus_change.send_event = FALSE;
        ev.focus_change.in = TRUE;

        emit_event (item->canvas, &ev);
    }
}

/* Focus in handler for the canvas */
static gint
e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event)
{
    GnomeCanvas *canvas;
    ECanvas *ecanvas;

    canvas = GNOME_CANVAS (widget);
    ecanvas = E_CANVAS (widget);

    GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);

    if (ecanvas->ic)
        gdk_im_begin (ecanvas->ic, canvas->layout.bin_window);

    if (canvas->focused_item)
        return emit_event (canvas, (GdkEvent *) event);
    else
        return FALSE;
}

/* Focus out handler for the canvas */
static gint
e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
{
    GnomeCanvas *canvas;
    ECanvas *ecanvas;

    canvas = GNOME_CANVAS (widget);
    ecanvas = E_CANVAS (widget);

    GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);

    if (ecanvas->ic)
        gdk_im_end ();

    if (canvas->focused_item)
        return emit_event (canvas, (GdkEvent *) event);
    else
        return FALSE;
}

static void
e_canvas_realize (GtkWidget *widget)
{
    ECanvas *ecanvas = E_CANVAS (widget);

    if (GTK_WIDGET_CLASS (parent_class)->realize)
        (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);

    gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);

    if (gdk_im_ready () && (ecanvas->ic_attr = gdk_ic_attr_new ()) != NULL) {
        GdkEventMask mask;
        GdkICAttr *attr = ecanvas->ic_attr;
        GdkICAttributesType attrmask = GDK_IC_ALL_REQ;
        GdkIMStyle style;
        GdkIMStyle supported_style = GDK_IM_PREEDIT_NONE |
            GDK_IM_PREEDIT_NOTHING |
            GDK_IM_STATUS_NONE |
            GDK_IM_STATUS_NOTHING;

        attr->style = style = gdk_im_decide_style (supported_style);
        attr->client_window = ecanvas->parent.layout.bin_window;

        ecanvas->ic = gdk_ic_new (attr, attrmask);
        if (ecanvas->ic != NULL) {
            mask = gdk_window_get_events (attr->client_window);
            mask |= gdk_ic_get_events (ecanvas->ic);
            gdk_window_set_events (attr->client_window, mask);

            if (GTK_WIDGET_HAS_FOCUS (widget))
                gdk_im_begin (ecanvas->ic, attr->client_window);
        } else
            g_warning ("Can't create input context.");
    }

}

static void
e_canvas_unrealize (GtkWidget *widget)
{
    ECanvas * ecanvas = E_CANVAS (widget);
    if (ecanvas->ic) {
        gdk_ic_destroy (ecanvas->ic);
        ecanvas->ic = NULL;
    }
    if (ecanvas->ic_attr) {
        gdk_ic_attr_destroy (ecanvas->ic_attr);
        ecanvas->ic_attr = NULL;
    }
    if (GTK_WIDGET_CLASS (parent_class)->unrealize)
        (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
}

static void
e_canvas_item_invoke_reflow (GnomeCanvasItem *item, int flags)
{
    GnomeCanvasGroup *group;
    GList *list;
    GnomeCanvasItem *child;

    if (GNOME_IS_CANVAS_GROUP (item)) {
        group = GNOME_CANVAS_GROUP (item);
        for (list = group->item_list; list; list = list->next) {
            child = GNOME_CANVAS_ITEM (list->data);
            if (child->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW)
                e_canvas_item_invoke_reflow (child, flags);
        }
    }

    if (item->object.flags & E_CANVAS_ITEM_NEEDS_REFLOW) {
        ECanvasItemReflowFunc func;
        func = gtk_object_get_data (GTK_OBJECT (item),
                        "ECanvasItem::reflow_callback");
        if (func)
            func (item, flags);
    }

    item->object.flags &= ~E_CANVAS_ITEM_NEEDS_REFLOW;
    item->object.flags &= ~E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW;
}

static void
do_reflow (ECanvas *canvas)
{
    if (GNOME_CANVAS(canvas)->root->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW)
        e_canvas_item_invoke_reflow (GNOME_CANVAS(canvas)->root, 0);
}

/* Idle handler for the e-canvas.  It deals with pending reflows. */
static gint