From a57b12708dae1c8eff2906e853c28c243f280307 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 9 Feb 2000 23:19:13 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'GNOME_APPLETS_1_1_3'. svn path=/tags/GNOME_APPLETS_1_1_3/; revision=1716 --- widgets/.cvsignore | 9 - widgets/LICENSE | 1 - widgets/Makefile.am | 3 - widgets/e-minicard/Makefile.am | 47 - widgets/e-minicard/e-minicard-label.c | 456 --- widgets/e-minicard/e-minicard-label.h | 84 - widgets/e-minicard/e-minicard.c | 462 --- widgets/e-minicard/e-minicard.h | 91 - widgets/e-minicard/e-reflow.c | 787 ----- widgets/e-minicard/e-reflow.h | 104 - widgets/e-minicard/test-minicard-label.c | 125 - widgets/e-minicard/test-minicard.c | 115 - widgets/e-minicard/test-reflow.c | 161 - widgets/e-reflow/e-reflow.c | 787 ----- widgets/e-reflow/e-reflow.h | 104 - widgets/e-table/.cvsignore | 7 - widgets/e-table/ChangeLog | 605 ---- widgets/e-table/LICENSE | 1 - widgets/e-table/Makefile.am | 62 - widgets/e-table/ROADMAP.e-table | 113 - widgets/e-table/TODO | 24 - widgets/e-table/add-col.xpm | 22 - widgets/e-table/check-empty.xpm | 21 - widgets/e-table/check-filled.xpm | 21 - widgets/e-table/e-cell-checkbox.c | 44 - widgets/e-table/e-cell-checkbox.h | 24 - widgets/e-table/e-cell-string.c | 9 - widgets/e-table/e-cell-text.c | 1843 ------------ widgets/e-table/e-cell-text.h | 63 - widgets/e-table/e-cell-toggle.c | 298 -- widgets/e-table/e-cell-toggle.h | 35 - widgets/e-table/e-cell.c | 176 -- widgets/e-table/e-cell.h | 73 - widgets/e-table/e-table-col-dnd.h | 10 - widgets/e-table/e-table-col.c | 64 - widgets/e-table/e-table-col.h | 44 - widgets/e-table/e-table-column-item.c | 199 -- widgets/e-table/e-table-column-item.h | 20 - widgets/e-table/e-table-column-model.h | 5 - widgets/e-table/e-table-column.c | 293 -- widgets/e-table/e-table-group.c | 276 -- widgets/e-table/e-table-group.h | 63 - widgets/e-table/e-table-header-item.c | 795 ----- widgets/e-table/e-table-header-item.h | 56 - widgets/e-table/e-table-header.c | 342 --- widgets/e-table/e-table-header.h | 65 - widgets/e-table/e-table-item.c | 1316 --------- widgets/e-table/e-table-item.h | 106 - widgets/e-table/e-table-model.c | 176 -- widgets/e-table/e-table-model.h | 58 - widgets/e-table/e-table-render.c | 20 - widgets/e-table/e-table-render.h | 21 - widgets/e-table/e-table-simple.c | 112 - widgets/e-table/e-table-simple.h | 37 - widgets/e-table/e-table-sorted.c | 89 - widgets/e-table/e-table-sorted.h | 29 - widgets/e-table/e-table-subset.c | 178 -- widgets/e-table/e-table-subset.h | 32 - widgets/e-table/e-table-tree.h | 19 - widgets/e-table/e-table.c | 564 ---- widgets/e-table/e-table.h | 48 - widgets/e-table/image1.png | Bin 1858 -> 0 bytes widgets/e-table/image2.png | Bin 1987 -> 0 bytes widgets/e-table/image3.png | Bin 2051 -> 0 bytes widgets/e-table/remove-col.xpm | 22 - widgets/e-table/sample.table | 11 - widgets/e-table/table-test.c | 45 - widgets/e-table/table-test.h | 4 - widgets/e-table/test-check.c | 153 - widgets/e-table/test-cols.c | 196 -- widgets/e-table/test-table.c | 306 -- widgets/e-table/test.c | 17 - widgets/e-text-event-processor-emacs-like.c | 357 --- widgets/e-text-event-processor-emacs-like.h | 68 - widgets/e-text-event-processor-types.h | 136 - widgets/e-text-event-processor.c | 103 - widgets/e-text-event-processor.h | 74 - widgets/e-text.c | 2526 ---------------- widgets/e-text.h | 196 -- widgets/e-text/Makefile.am | 13 - widgets/e-text/e-text-event-processor-emacs-like.c | 357 --- widgets/e-text/e-text-event-processor-emacs-like.h | 68 - widgets/e-text/e-text-event-processor-types.h | 136 - widgets/e-text/e-text-event-processor.c | 103 - widgets/e-text/e-text-event-processor.h | 74 - widgets/e-text/e-text.c | 2526 ---------------- widgets/e-text/e-text.h | 196 -- widgets/meeting-time-sel/.cvsignore | 7 - widgets/meeting-time-sel/LICENSE | 1 - widgets/meeting-time-sel/Makefile.am | 30 - widgets/meeting-time-sel/e-meeting-time-sel-item.c | 924 ------ widgets/meeting-time-sel/e-meeting-time-sel-item.h | 78 - .../e-meeting-time-sel-list-item.c | 303 -- .../e-meeting-time-sel-list-item.h | 74 - .../meeting-time-sel/e-meeting-time-sel-mail.xpm | 135 - .../e-meeting-time-sel-no-mail.xpm | 123 - widgets/meeting-time-sel/e-meeting-time-sel.c | 3065 -------------------- widgets/meeting-time-sel/e-meeting-time-sel.h | 496 ---- widgets/meeting-time-sel/test-meeting-time-sel.c | 236 -- widgets/misc/e-canvas-utils.c | 36 - widgets/misc/e-canvas-utils.h | 24 - widgets/misc/e-canvas.c | 301 -- widgets/misc/e-canvas.h | 71 - widgets/misc/e-colors.c | 73 - widgets/misc/e-colors.h | 14 - widgets/misc/e-cursors.c | 38 - widgets/misc/e-cursors.h | 38 - widgets/misc/e-gui-utils.c | 58 - widgets/misc/e-gui-utils.h | 12 - widgets/misc/e-reflow.c | 787 ----- widgets/misc/e-reflow.h | 104 - widgets/misc/pixmaps/cursor_cross.xpm | 38 - widgets/misc/pixmaps/cursor_hand_closed.xpm | 38 - widgets/misc/pixmaps/cursor_hand_open.xpm | 38 - widgets/misc/pixmaps/cursor_zoom_in.xpm | 37 - widgets/misc/pixmaps/cursor_zoom_out.xpm | 37 - widgets/shortcut-bar/.cvsignore | 7 - widgets/shortcut-bar/LICENSE | 1 - widgets/shortcut-bar/Makefile.am | 33 - widgets/shortcut-bar/e-clipped-label.c | 361 --- widgets/shortcut-bar/e-clipped-label.h | 90 - widgets/shortcut-bar/e-group-bar.c | 1496 ---------- widgets/shortcut-bar/e-group-bar.h | 171 -- widgets/shortcut-bar/e-icon-bar-bg-item.c | 361 --- widgets/shortcut-bar/e-icon-bar-bg-item.h | 72 - widgets/shortcut-bar/e-icon-bar-text-item.c | 1696 ----------- widgets/shortcut-bar/e-icon-bar-text-item.h | 158 - widgets/shortcut-bar/e-icon-bar.c | 1449 --------- widgets/shortcut-bar/e-icon-bar.h | 222 -- widgets/shortcut-bar/e-shortcut-bar.c | 562 ---- widgets/shortcut-bar/e-shortcut-bar.h | 114 - widgets/shortcut-bar/e-vscrolled-bar.c | 652 ----- widgets/shortcut-bar/e-vscrolled-bar.h | 97 - widgets/shortcut-bar/test-shortcut-bar.c | 445 --- widgets/table/.cvsignore | 7 - widgets/table/add-col.xpm | 22 - widgets/table/check-empty.xpm | 21 - widgets/table/check-filled.xpm | 21 - widgets/table/e-cell-checkbox.c | 44 - widgets/table/e-cell-checkbox.h | 24 - widgets/table/e-cell-string.c | 9 - widgets/table/e-cell-text.c | 1843 ------------ widgets/table/e-cell-text.h | 63 - widgets/table/e-cell-toggle.c | 298 -- widgets/table/e-cell-toggle.h | 35 - widgets/table/e-cell.c | 176 -- widgets/table/e-cell.h | 73 - widgets/table/e-table-col-dnd.h | 10 - widgets/table/e-table-col.c | 64 - widgets/table/e-table-col.h | 44 - widgets/table/e-table-column-item.c | 199 -- widgets/table/e-table-column-item.h | 20 - widgets/table/e-table-column-model.h | 5 - widgets/table/e-table-column.c | 293 -- widgets/table/e-table-group.c | 276 -- widgets/table/e-table-group.h | 63 - widgets/table/e-table-header-item.c | 795 ----- widgets/table/e-table-header-item.h | 56 - widgets/table/e-table-header.c | 342 --- widgets/table/e-table-header.h | 65 - widgets/table/e-table-item.c | 1316 --------- widgets/table/e-table-item.h | 106 - widgets/table/e-table-model.c | 176 -- widgets/table/e-table-model.h | 58 - widgets/table/e-table-render.c | 20 - widgets/table/e-table-render.h | 21 - widgets/table/e-table-simple.c | 112 - widgets/table/e-table-simple.h | 37 - widgets/table/e-table-sorted.c | 89 - widgets/table/e-table-sorted.h | 29 - widgets/table/e-table-subset.c | 178 -- widgets/table/e-table-subset.h | 32 - widgets/table/e-table-tree.h | 19 - widgets/table/e-table.c | 564 ---- widgets/table/e-table.h | 48 - widgets/table/image1.png | Bin 1858 -> 0 bytes widgets/table/image2.png | Bin 1987 -> 0 bytes widgets/table/image3.png | Bin 2051 -> 0 bytes widgets/table/remove-col.xpm | 22 - widgets/table/sample.table | 11 - widgets/table/table-test.c | 45 - widgets/table/table-test.h | 4 - widgets/table/test-check.c | 153 - widgets/table/test-cols.c | 196 -- widgets/table/test-table.c | 306 -- widgets/table/test.c | 17 - widgets/text/e-text-event-processor-emacs-like.c | 357 --- widgets/text/e-text-event-processor-emacs-like.h | 68 - widgets/text/e-text-event-processor-types.h | 136 - widgets/text/e-text-event-processor.c | 103 - widgets/text/e-text-event-processor.h | 74 - widgets/text/e-text.c | 2526 ---------------- widgets/text/e-text.h | 196 -- 193 files changed, 46591 deletions(-) delete mode 100644 widgets/.cvsignore delete mode 100644 widgets/LICENSE delete mode 100644 widgets/Makefile.am delete mode 100644 widgets/e-minicard/Makefile.am delete mode 100644 widgets/e-minicard/e-minicard-label.c delete mode 100644 widgets/e-minicard/e-minicard-label.h delete mode 100644 widgets/e-minicard/e-minicard.c delete mode 100644 widgets/e-minicard/e-minicard.h delete mode 100644 widgets/e-minicard/e-reflow.c delete mode 100644 widgets/e-minicard/e-reflow.h delete mode 100644 widgets/e-minicard/test-minicard-label.c delete mode 100644 widgets/e-minicard/test-minicard.c delete mode 100644 widgets/e-minicard/test-reflow.c delete mode 100644 widgets/e-reflow/e-reflow.c delete mode 100644 widgets/e-reflow/e-reflow.h delete mode 100644 widgets/e-table/.cvsignore delete mode 100644 widgets/e-table/ChangeLog delete mode 100644 widgets/e-table/LICENSE delete mode 100644 widgets/e-table/Makefile.am delete mode 100644 widgets/e-table/ROADMAP.e-table delete mode 100644 widgets/e-table/TODO delete mode 100644 widgets/e-table/add-col.xpm delete mode 100644 widgets/e-table/check-empty.xpm delete mode 100644 widgets/e-table/check-filled.xpm delete mode 100644 widgets/e-table/e-cell-checkbox.c delete mode 100644 widgets/e-table/e-cell-checkbox.h delete mode 100644 widgets/e-table/e-cell-string.c delete mode 100644 widgets/e-table/e-cell-text.c delete mode 100644 widgets/e-table/e-cell-text.h delete mode 100644 widgets/e-table/e-cell-toggle.c delete mode 100644 widgets/e-table/e-cell-toggle.h delete mode 100644 widgets/e-table/e-cell.c delete mode 100644 widgets/e-table/e-cell.h delete mode 100644 widgets/e-table/e-table-col-dnd.h delete mode 100644 widgets/e-table/e-table-col.c delete mode 100644 widgets/e-table/e-table-col.h delete mode 100644 widgets/e-table/e-table-column-item.c delete mode 100644 widgets/e-table/e-table-column-item.h delete mode 100644 widgets/e-table/e-table-column-model.h delete mode 100644 widgets/e-table/e-table-column.c delete mode 100644 widgets/e-table/e-table-group.c delete mode 100644 widgets/e-table/e-table-group.h delete mode 100644 widgets/e-table/e-table-header-item.c delete mode 100644 widgets/e-table/e-table-header-item.h delete mode 100644 widgets/e-table/e-table-header.c delete mode 100644 widgets/e-table/e-table-header.h delete mode 100644 widgets/e-table/e-table-item.c delete mode 100644 widgets/e-table/e-table-item.h delete mode 100644 widgets/e-table/e-table-model.c delete mode 100644 widgets/e-table/e-table-model.h delete mode 100644 widgets/e-table/e-table-render.c delete mode 100644 widgets/e-table/e-table-render.h delete mode 100644 widgets/e-table/e-table-simple.c delete mode 100644 widgets/e-table/e-table-simple.h delete mode 100644 widgets/e-table/e-table-sorted.c delete mode 100644 widgets/e-table/e-table-sorted.h delete mode 100644 widgets/e-table/e-table-subset.c delete mode 100644 widgets/e-table/e-table-subset.h delete mode 100644 widgets/e-table/e-table-tree.h delete mode 100644 widgets/e-table/e-table.c delete mode 100644 widgets/e-table/e-table.h delete mode 100644 widgets/e-table/image1.png delete mode 100644 widgets/e-table/image2.png delete mode 100644 widgets/e-table/image3.png delete mode 100644 widgets/e-table/remove-col.xpm delete mode 100644 widgets/e-table/sample.table delete mode 100644 widgets/e-table/table-test.c delete mode 100644 widgets/e-table/table-test.h delete mode 100644 widgets/e-table/test-check.c delete mode 100644 widgets/e-table/test-cols.c delete mode 100644 widgets/e-table/test-table.c delete mode 100644 widgets/e-table/test.c delete mode 100644 widgets/e-text-event-processor-emacs-like.c delete mode 100644 widgets/e-text-event-processor-emacs-like.h delete mode 100644 widgets/e-text-event-processor-types.h delete mode 100644 widgets/e-text-event-processor.c delete mode 100644 widgets/e-text-event-processor.h delete mode 100644 widgets/e-text.c delete mode 100644 widgets/e-text.h delete mode 100644 widgets/e-text/Makefile.am delete mode 100644 widgets/e-text/e-text-event-processor-emacs-like.c delete mode 100644 widgets/e-text/e-text-event-processor-emacs-like.h delete mode 100644 widgets/e-text/e-text-event-processor-types.h delete mode 100644 widgets/e-text/e-text-event-processor.c delete mode 100644 widgets/e-text/e-text-event-processor.h delete mode 100644 widgets/e-text/e-text.c delete mode 100644 widgets/e-text/e-text.h delete mode 100644 widgets/meeting-time-sel/.cvsignore delete mode 100644 widgets/meeting-time-sel/LICENSE delete mode 100644 widgets/meeting-time-sel/Makefile.am delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-item.c delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-item.h delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-list-item.c delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-list-item.h delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel.c delete mode 100644 widgets/meeting-time-sel/e-meeting-time-sel.h delete mode 100644 widgets/meeting-time-sel/test-meeting-time-sel.c delete mode 100644 widgets/misc/e-canvas-utils.c delete mode 100644 widgets/misc/e-canvas-utils.h delete mode 100644 widgets/misc/e-canvas.c delete mode 100644 widgets/misc/e-canvas.h delete mode 100644 widgets/misc/e-colors.c delete mode 100644 widgets/misc/e-colors.h delete mode 100644 widgets/misc/e-cursors.c delete mode 100644 widgets/misc/e-cursors.h delete mode 100644 widgets/misc/e-gui-utils.c delete mode 100644 widgets/misc/e-gui-utils.h delete mode 100644 widgets/misc/e-reflow.c delete mode 100644 widgets/misc/e-reflow.h delete mode 100644 widgets/misc/pixmaps/cursor_cross.xpm delete mode 100644 widgets/misc/pixmaps/cursor_hand_closed.xpm delete mode 100644 widgets/misc/pixmaps/cursor_hand_open.xpm delete mode 100644 widgets/misc/pixmaps/cursor_zoom_in.xpm delete mode 100644 widgets/misc/pixmaps/cursor_zoom_out.xpm delete mode 100644 widgets/shortcut-bar/.cvsignore delete mode 100644 widgets/shortcut-bar/LICENSE delete mode 100644 widgets/shortcut-bar/Makefile.am delete mode 100644 widgets/shortcut-bar/e-clipped-label.c delete mode 100644 widgets/shortcut-bar/e-clipped-label.h delete mode 100644 widgets/shortcut-bar/e-group-bar.c delete mode 100644 widgets/shortcut-bar/e-group-bar.h delete mode 100644 widgets/shortcut-bar/e-icon-bar-bg-item.c delete mode 100644 widgets/shortcut-bar/e-icon-bar-bg-item.h delete mode 100644 widgets/shortcut-bar/e-icon-bar-text-item.c delete mode 100644 widgets/shortcut-bar/e-icon-bar-text-item.h delete mode 100644 widgets/shortcut-bar/e-icon-bar.c delete mode 100644 widgets/shortcut-bar/e-icon-bar.h delete mode 100644 widgets/shortcut-bar/e-shortcut-bar.c delete mode 100644 widgets/shortcut-bar/e-shortcut-bar.h delete mode 100644 widgets/shortcut-bar/e-vscrolled-bar.c delete mode 100644 widgets/shortcut-bar/e-vscrolled-bar.h delete mode 100644 widgets/shortcut-bar/test-shortcut-bar.c delete mode 100644 widgets/table/.cvsignore delete mode 100644 widgets/table/add-col.xpm delete mode 100644 widgets/table/check-empty.xpm delete mode 100644 widgets/table/check-filled.xpm delete mode 100644 widgets/table/e-cell-checkbox.c delete mode 100644 widgets/table/e-cell-checkbox.h delete mode 100644 widgets/table/e-cell-string.c delete mode 100644 widgets/table/e-cell-text.c delete mode 100644 widgets/table/e-cell-text.h delete mode 100644 widgets/table/e-cell-toggle.c delete mode 100644 widgets/table/e-cell-toggle.h delete mode 100644 widgets/table/e-cell.c delete mode 100644 widgets/table/e-cell.h delete mode 100644 widgets/table/e-table-col-dnd.h delete mode 100644 widgets/table/e-table-col.c delete mode 100644 widgets/table/e-table-col.h delete mode 100644 widgets/table/e-table-column-item.c delete mode 100644 widgets/table/e-table-column-item.h delete mode 100644 widgets/table/e-table-column-model.h delete mode 100644 widgets/table/e-table-column.c delete mode 100644 widgets/table/e-table-group.c delete mode 100644 widgets/table/e-table-group.h delete mode 100644 widgets/table/e-table-header-item.c delete mode 100644 widgets/table/e-table-header-item.h delete mode 100644 widgets/table/e-table-header.c delete mode 100644 widgets/table/e-table-header.h delete mode 100644 widgets/table/e-table-item.c delete mode 100644 widgets/table/e-table-item.h delete mode 100644 widgets/table/e-table-model.c delete mode 100644 widgets/table/e-table-model.h delete mode 100644 widgets/table/e-table-render.c delete mode 100644 widgets/table/e-table-render.h delete mode 100644 widgets/table/e-table-simple.c delete mode 100644 widgets/table/e-table-simple.h delete mode 100644 widgets/table/e-table-sorted.c delete mode 100644 widgets/table/e-table-sorted.h delete mode 100644 widgets/table/e-table-subset.c delete mode 100644 widgets/table/e-table-subset.h delete mode 100644 widgets/table/e-table-tree.h delete mode 100644 widgets/table/e-table.c delete mode 100644 widgets/table/e-table.h delete mode 100644 widgets/table/image1.png delete mode 100644 widgets/table/image2.png delete mode 100644 widgets/table/image3.png delete mode 100644 widgets/table/remove-col.xpm delete mode 100644 widgets/table/sample.table delete mode 100644 widgets/table/table-test.c delete mode 100644 widgets/table/table-test.h delete mode 100644 widgets/table/test-check.c delete mode 100644 widgets/table/test-cols.c delete mode 100644 widgets/table/test-table.c delete mode 100644 widgets/table/test.c delete mode 100644 widgets/text/e-text-event-processor-emacs-like.c delete mode 100644 widgets/text/e-text-event-processor-emacs-like.h delete mode 100644 widgets/text/e-text-event-processor-types.h delete mode 100644 widgets/text/e-text-event-processor.c delete mode 100644 widgets/text/e-text-event-processor.h delete mode 100644 widgets/text/e-text.c delete mode 100644 widgets/text/e-text.h (limited to 'widgets') diff --git a/widgets/.cvsignore b/widgets/.cvsignore deleted file mode 100644 index d5b3a2ad62..0000000000 --- a/widgets/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -minicard-test -minicard-label-test -reflow-test diff --git a/widgets/LICENSE b/widgets/LICENSE deleted file mode 100644 index b1f6ae08a4..0000000000 --- a/widgets/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is released under the terms of the GNU GPL. diff --git a/widgets/Makefile.am b/widgets/Makefile.am deleted file mode 100644 index 5d052b11a0..0000000000 --- a/widgets/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ - -SUBDIRS = \ - e-text e-minicard meeting-time-sel shortcut-bar e-table diff --git a/widgets/e-minicard/Makefile.am b/widgets/e-minicard/Makefile.am deleted file mode 100644 index 0790577ad1..0000000000 --- a/widgets/e-minicard/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir)/widgets/e-text \ - -I$(top_srcdir)/e-util \ - $(GNOME_INCLUDEDIR) - -noinst_LIBRARIES = \ - libeminicard.a - -libeminicard_a_SOURCES = \ - e-minicard.c \ - e-minicard.h \ - e-minicard-label.c \ - e-minicard-label.h \ - e-reflow.c \ - e-reflow.h - -noinst_PROGRAMS = \ - minicard-label-test \ - minicard-test \ - reflow-test - -minicard_label_test_SOURCES = \ - test-minicard-label.c - -minicard_label_test_LDADD = \ - $(EXTRA_GNOME_LIBS) \ - libeminicard.a \ - $(top_builddir)/e-util/libeutil.a \ - $(top_builddir)/widgets/e-text/libetext.a - -minicard_test_SOURCES = \ - test-minicard.c - -minicard_test_LDADD = \ - $(EXTRA_GNOME_LIBS) \ - libeminicard.a \ - $(top_builddir)/e-util/libeutil.a \ - $(top_builddir)/widgets/e-text/libetext.a - -reflow_test_SOURCES = \ - test-reflow.c - -reflow_test_LDADD = \ - $(EXTRA_GNOME_LIBS) \ - libeminicard.a \ - $(top_builddir)/e-util/libeutil.a \ - $(top_builddir)/widgets/e-text/libetext.a diff --git a/widgets/e-minicard/e-minicard-label.c b/widgets/e-minicard/e-minicard-label.c deleted file mode 100644 index 43603f2d6d..0000000000 --- a/widgets/e-minicard/e-minicard-label.c +++ /dev/null @@ -1,456 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-minicard-label.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-minicard-label.h" -#include "e-text.h" -#include "e-canvas.h" -static void e_minicard_label_init (EMinicardLabel *card); -static void e_minicard_label_class_init (EMinicardLabelClass *klass); -static void e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static gboolean e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event); -static void e_minicard_label_realize (GnomeCanvasItem *item); -static void e_minicard_label_unrealize (GnomeCanvasItem *item); - -static void _update_label( EMinicardLabel *minicard_label ); -static void _resize( GtkObject *object, gpointer data ); - -static GnomeCanvasGroupClass *parent_class = NULL; - -enum { - E_MINICARD_LABEL_RESIZE, - E_MINICARD_LABEL_LAST_SIGNAL -}; - -static guint e_minicard_label_signals[E_MINICARD_LABEL_LAST_SIGNAL] = { 0 }; - -/* The arguments we take */ -enum { - ARG_0, - ARG_WIDTH, - ARG_HEIGHT, - ARG_HAS_FOCUS, - ARG_FIELD, - ARG_FIELDNAME -}; - -GtkType -e_minicard_label_get_type (void) -{ - static GtkType minicard_label_type = 0; - - if (!minicard_label_type) - { - static const GtkTypeInfo minicard_label_info = - { - "EMinicardLabel", - sizeof (EMinicardLabel), - sizeof (EMinicardLabelClass), - (GtkClassInitFunc) e_minicard_label_class_init, - (GtkObjectInitFunc) e_minicard_label_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - minicard_label_type = gtk_type_unique (gnome_canvas_group_get_type (), &minicard_label_info); - } - - return minicard_label_type; -} - -static void -e_minicard_label_class_init (EMinicardLabelClass *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 ()); - - e_minicard_label_signals[E_MINICARD_LABEL_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EMinicardLabelClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_minicard_label_signals, E_MINICARD_LABEL_LAST_SIGNAL); - - gtk_object_add_arg_type ("EMinicardLabel::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("EMinicardLabel::has_focus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_HAS_FOCUS); - gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_FIELD); - gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_FIELDNAME); - - klass->resize = NULL; - - object_class->set_arg = e_minicard_label_set_arg; - object_class->get_arg = e_minicard_label_get_arg; - /* object_class->destroy = e_minicard_label_destroy; */ - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_minicard_label_realize; - item_class->unrealize = e_minicard_label_unrealize; - item_class->event = e_minicard_label_event; -} - -static void -e_minicard_label_init (EMinicardLabel *minicard_label) -{ - minicard_label->width = 10; - minicard_label->height = 10; - minicard_label->rect = NULL; - minicard_label->fieldname = NULL; - minicard_label->field = NULL; - minicard_label->fieldname_text = NULL; - minicard_label->field_text = NULL; -} - -static void -e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMinicardLabel *e_minicard_label; - - item = GNOME_CANVAS_ITEM (o); - e_minicard_label = E_MINICARD_LABEL (o); - - switch (arg_id){ - case ARG_WIDTH: - e_minicard_label->width = GTK_VALUE_DOUBLE (*arg); - _update_label( e_minicard_label ); - gnome_canvas_item_request_update (item); - break; - case ARG_HAS_FOCUS: - if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) - e_canvas_item_grab_focus(e_minicard_label->field); - break; - case ARG_FIELD: - if ( e_minicard_label->field ) - gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); - else - e_minicard_label->field_text = g_strdup( GTK_VALUE_STRING (*arg) ); - break; - case ARG_FIELDNAME: - if ( e_minicard_label->fieldname ) - gnome_canvas_item_set( e_minicard_label->fieldname, "text", GTK_VALUE_STRING (*arg), NULL ); - else - e_minicard_label->fieldname_text = g_strdup( GTK_VALUE_STRING (*arg) ); - break; - } -} - -static void -e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EMinicardLabel *e_minicard_label; - char *temp; - - e_minicard_label = E_MINICARD_LABEL (object); - - switch (arg_id) { - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_minicard_label->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height; - break; - case ARG_HAS_FOCUS: - GTK_VALUE_BOOL (*arg) = e_minicard_label->has_focus; - break; - case ARG_FIELD: - if ( e_minicard_label->field ) { - gtk_object_get( GTK_OBJECT( e_minicard_label->field ), "text", &temp, NULL ); - GTK_VALUE_STRING (*arg) = temp; - } else - GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->field_text ); - break; - case ARG_FIELDNAME: - if ( e_minicard_label->fieldname ) { - gtk_object_get( GTK_OBJECT( e_minicard_label->fieldname ), "text", &temp, NULL ); - GTK_VALUE_STRING (*arg) = temp; - } else - GTK_VALUE_STRING (*arg) = g_strdup( e_minicard_label->fieldname_text ); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_minicard_label_realize (GnomeCanvasItem *item) -{ - EMinicardLabel *e_minicard_label; - GnomeCanvasGroup *group; - - e_minicard_label = E_MINICARD_LABEL (item); - group = GNOME_CANVAS_GROUP( item ); - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) - (* GNOME_CANVAS_ITEM_CLASS( parent_class )->realize) (item); - - e_minicard_label->rect = - gnome_canvas_item_new( group, - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) e_minicard_label->width - 1, - "y2", (double) e_minicard_label->height - 1, - "outline_color", NULL, - NULL ); - e_minicard_label->fieldname = - gnome_canvas_item_new( group, - e_text_get_type(), - "x", (double) 2, - "y", (double) 1, - "anchor", GTK_ANCHOR_NW, - "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), - "clip_height", (double) 1, - "clip", TRUE, - "use_ellipsis", TRUE, - "font", "lucidasans-10", - "fill_color", "black", - NULL ); - if ( e_minicard_label->fieldname_text ) - { - gnome_canvas_item_set( e_minicard_label->fieldname, - "text", e_minicard_label->fieldname_text, - NULL ); - g_free( e_minicard_label->fieldname_text ); - } - gtk_signal_connect(GTK_OBJECT(e_minicard_label->fieldname), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard_label); - - e_minicard_label->field = - gnome_canvas_item_new( group, - e_text_get_type(), - "x", (double) ( e_minicard_label->width / 2 + 2 ), - "y", (double) 1, - "anchor", GTK_ANCHOR_NW, - "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), - "clip_height", (double) 1, - "clip", TRUE, - "use_ellipsis", TRUE, - "font", "lucidasans-10", - "fill_color", "black", - "editable", TRUE, - NULL ); - if ( e_minicard_label->field_text ) - { - gnome_canvas_item_set( e_minicard_label->field, - "text", e_minicard_label->field_text, - NULL ); - g_free( e_minicard_label->field_text ); - } - - gtk_signal_connect(GTK_OBJECT(e_minicard_label->field), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard_label); - - _update_label (e_minicard_label); - - if (!item->canvas->aa) - { - } - -} - -static void -e_minicard_label_unrealize (GnomeCanvasItem *item) -{ - EMinicardLabel *e_minicard_label; - - e_minicard_label = E_MINICARD_LABEL (item); - - if (!item->canvas->aa) - { - } - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->unrealize) - (* GNOME_CANVAS_ITEM_CLASS( parent_class )->unrealize) (item); -} - -static gboolean -e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EMinicardLabel *e_minicard_label; - - e_minicard_label = E_MINICARD_LABEL (item); - - switch( event->type ) - { - case GDK_FOCUS_CHANGE: - { - GdkEventFocus *focus_event = (GdkEventFocus *) event; - if ( focus_event->in ) - { - gnome_canvas_item_set( e_minicard_label->rect, - "outline_color", "grey50", - "fill_color", "grey90", - NULL ); - e_minicard_label->has_focus = TRUE; - } - else - { - gnome_canvas_item_set( e_minicard_label->rect, - "outline_color", NULL, - "fill_color", NULL, - NULL ); - e_minicard_label->has_focus = FALSE; - } - } - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_MOTION_NOTIFY: - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: { - GnomeCanvasItem *field; - ArtPoint p; - double inv[6], affine[6]; - gboolean return_val; - - field = e_minicard_label->field; - art_affine_identity (affine); - - if (field->xform != NULL) { - if (field->object.flags & GNOME_CANVAS_ITEM_AFFINE_FULL) { - art_affine_multiply (affine, affine, field->xform); - } else { - affine[4] += field->xform[0]; - affine[5] += field->xform[1]; - } - } - - art_affine_invert (inv, affine); - switch(event->type) { - case GDK_MOTION_NOTIFY: - p.x = event->motion.x; - p.y = event->motion.y; - art_affine_point (&p, &p, inv); - event->motion.x = p.x; - event->motion.y = p.y; - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - p.x = event->button.x; - p.y = event->button.y; - art_affine_point (&p, &p, inv); - event->button.x = p.x; - event->button.y = p.y; - break; - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - p.x = event->crossing.x; - p.y = event->crossing.y; - art_affine_point (&p, &p, inv); - event->crossing.x = p.x; - event->crossing.y = p.y; - break; - default: - break; - } - - gtk_signal_emit_by_name(GTK_OBJECT(e_minicard_label->field), "event", event, &return_val); - return return_val; - 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 -_update_label( EMinicardLabel *e_minicard_label ) -{ - if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) - { - gint old_height; - gdouble text_height; - old_height = e_minicard_label->height; - - gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname), - "text_height", &text_height, - NULL); - gnome_canvas_item_set(e_minicard_label->fieldname, - "clip_height", (double) text_height, - NULL); - - e_minicard_label->height = text_height; - - - gtk_object_get(GTK_OBJECT(e_minicard_label->field), - "text_height", &text_height, - NULL); - gnome_canvas_item_set(e_minicard_label->field, - "clip_height", (double) text_height, - NULL); - - if (e_minicard_label->height < text_height) - e_minicard_label->height = text_height; - e_minicard_label->height += 3; - - gnome_canvas_item_set( e_minicard_label->rect, - "x2", (double) e_minicard_label->width - 1, - "y2", (double) e_minicard_label->height - 1, - NULL ); - gnome_canvas_item_set( e_minicard_label->fieldname, - "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), - NULL ); - gnome_canvas_item_set( e_minicard_label->field, - "x", (double) ( e_minicard_label->width / 2 + 2 ), - "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), - NULL ); - - if (old_height != e_minicard_label->height) - gtk_signal_emit_by_name (GTK_OBJECT (e_minicard_label), "resize"); - - } -} - - - -static void -_resize( GtkObject *object, gpointer data ) -{ - _update_label(E_MINICARD_LABEL(data)); -} diff --git a/widgets/e-minicard/e-minicard-label.h b/widgets/e-minicard/e-minicard-label.h deleted file mode 100644 index ddbe7ab191..0000000000 --- a/widgets/e-minicard/e-minicard-label.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-minicard-label.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_MINICARD_LABEL_H__ -#define __E_MINICARD_LABEL_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EMinicardLabel - A label doing focus with non-marching ants. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * width double RW width of the label - * height double R height of the label - * field string RW text in the field label - * fieldname string RW text in the fieldname label - */ - -#define E_MINICARD_LABEL_TYPE (e_minicard_label_get_type ()) -#define E_MINICARD_LABEL(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_LABEL_TYPE, EMinicardLabel)) -#define E_MINICARD_LABEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_LABEL_TYPE, EMiniCardLabelClass)) -#define E_IS_MINICARD_LABEL(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_LABEL_TYPE)) -#define E_IS_MINICARD_LABEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_LABEL_TYPE)) - - -typedef struct _EMinicardLabel EMinicardLabel; -typedef struct _EMinicardLabelClass EMinicardLabelClass; - -struct _EMinicardLabel -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - double width; - double height; - GnomeCanvasItem *fieldname; - GnomeCanvasItem *field; - GnomeCanvasItem *rect; - char *fieldname_text; - char *field_text; - - gboolean has_focus; -}; - -struct _EMinicardLabelClass -{ - GnomeCanvasGroupClass parent_class; - - void (* resize) (EMinicardLabel *text); -}; - - -GtkType e_minicard_label_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_MINICARD_LABEL_H__ */ diff --git a/widgets/e-minicard/e-minicard.c b/widgets/e-minicard/e-minicard.c deleted file mode 100644 index b667f1ac21..0000000000 --- a/widgets/e-minicard/e-minicard.c +++ /dev/null @@ -1,462 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-minicard.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-minicard.h" -#include "e-minicard-label.h" -#include "e-text.h" -#include "e-canvas.h" -static void e_minicard_init (EMinicard *card); -static void e_minicard_class_init (EMinicardClass *klass); -static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static gboolean e_minicard_event (GnomeCanvasItem *item, GdkEvent *event); -static void e_minicard_realize (GnomeCanvasItem *item); -static void e_minicard_unrealize (GnomeCanvasItem *item); - -static void _update_card ( EMinicard *minicard ); -static void _resize( GtkObject *object, gpointer data ); - -static GnomeCanvasGroupClass *parent_class = NULL; - -enum { - E_MINICARD_RESIZE, - E_MINICARD_LAST_SIGNAL -}; - -static guint e_minicard_signals[E_MINICARD_LAST_SIGNAL] = { 0 }; - -/* The arguments we take */ -enum { - ARG_0, - ARG_WIDTH, - ARG_HEIGHT, - ARG_HAS_FOCUS, - ARG_CARD -}; - -GtkType -e_minicard_get_type (void) -{ - static GtkType minicard_type = 0; - - if (!minicard_type) - { - static const GtkTypeInfo minicard_info = - { - "EMinicard", - sizeof (EMinicard), - sizeof (EMinicardClass), - (GtkClassInitFunc) e_minicard_class_init, - (GtkObjectInitFunc) e_minicard_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - minicard_type = gtk_type_unique (gnome_canvas_group_get_type (), &minicard_info); - } - - return minicard_type; -} - -static void -e_minicard_class_init (EMinicardClass *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 ()); - - e_minicard_signals[E_MINICARD_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EMinicardClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_minicard_signals, E_MINICARD_LAST_SIGNAL); - - gtk_object_add_arg_type ("EMinicard::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("EMinicard::has_focus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_HAS_FOCUS); - gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_CARD); - - object_class->set_arg = e_minicard_set_arg; - object_class->get_arg = e_minicard_get_arg; - /* object_class->destroy = e_minicard_destroy; */ - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_minicard_realize; - item_class->unrealize = e_minicard_unrealize; - item_class->event = e_minicard_event; -} - -static void -e_minicard_init (EMinicard *minicard) -{ - /* minicard->card = NULL;*/ - minicard->rect = NULL; - minicard->fields = NULL; - minicard->width = 10; - minicard->height = 10; - minicard->has_focus = FALSE; -} - -static void -e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMinicard *e_minicard; - - item = GNOME_CANVAS_ITEM (o); - e_minicard = E_MINICARD (o); - - switch (arg_id){ - case ARG_WIDTH: - if (e_minicard->width != GTK_VALUE_DOUBLE (*arg)) { - e_minicard->width = GTK_VALUE_DOUBLE (*arg); - _update_card(e_minicard); - gnome_canvas_item_request_update (item); - } - break; - case ARG_HAS_FOCUS: - if (e_minicard->fields) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), - "has_focus", GTK_VALUE_BOOL(*arg), - NULL); - else - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); - break; - case ARG_CARD: - /* e_minicard->card = GTK_VALUE_POINTER (*arg); - _update_card(e_minicard); - gnome_canvas_item_request_update (item);*/ - break; - } -} - -static void -e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EMinicard *e_minicard; - - e_minicard = E_MINICARD (object); - - switch (arg_id) { - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_minicard->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = e_minicard->height; - break; - case ARG_HAS_FOCUS: - GTK_VALUE_BOOL (*arg) = e_minicard->has_focus; - break; - case ARG_CARD: - /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */ - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_minicard_realize (GnomeCanvasItem *item) -{ - EMinicard *e_minicard; - GnomeCanvasGroup *group; - GnomeCanvasItem *new_item; - - e_minicard = E_MINICARD (item); - group = GNOME_CANVAS_GROUP( item ); - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); - - e_minicard->rect = - gnome_canvas_item_new( group, - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) e_minicard->width - 1, - "y2", (double) e_minicard->height - 1, - "outline_color", NULL, - NULL ); - - e_minicard->header_rect = - gnome_canvas_item_new( group, - gnome_canvas_rect_get_type(), - "x1", (double) 2, - "y1", (double) 2, - "x2", (double) e_minicard->width - 3, - "y2", (double) e_minicard->height - 3, - "fill_color", "grey70", - NULL ); - - e_minicard->header_text = - gnome_canvas_item_new( group, - e_text_get_type(), - "x", (double) 6, - "y", (double) 6, - "anchor", GTK_ANCHOR_NW, - "clip_width", (double) ( e_minicard->width - 12 ), - "clip", TRUE, - "use_ellipsis", TRUE, - "font", "lucidasans-bold-10", - "fill_color", "black", - "text", "Chris Lahey", - NULL ); - - gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - if ( rand() % 2 ) { - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - } - - if (rand() % 2) { - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Address:", - "field", "100 Main St\nHome town, USA", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - } - - if (rand() % 2) { - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@address.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - } - _update_card( e_minicard ); - - if (!item->canvas->aa) { - } -} - -static void -e_minicard_unrealize (GnomeCanvasItem *item) -{ - EMinicard *e_minicard; - - e_minicard = E_MINICARD (item); - - if (!item->canvas->aa) - { - } - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); -} - -static gboolean -e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EMinicard *e_minicard; - - e_minicard = E_MINICARD (item); - - switch( event->type ) - { - case GDK_FOCUS_CHANGE: - { - GdkEventFocus *focus_event = (GdkEventFocus *) event; - if ( focus_event->in ) - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", "grey50", - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "darkblue", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "white", - NULL ); - e_minicard->has_focus = TRUE; - } - else - { - gnome_canvas_item_set( e_minicard->rect, - "outline_color", NULL, - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey70", - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "fill_color", "black", - NULL ); - e_minicard->has_focus = FALSE; - } - } - break; - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - e_canvas_item_grab_focus(item); - } - break; - 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_minicard->fields; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); - gboolean 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", TRUE, - NULL); - return 1; - } else { - return 0; - } - } - } - } - 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 -_update_card( EMinicard *e_minicard ) -{ - if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED ) { - GList *list; - gdouble text_height; - gint old_height; - - old_height = e_minicard->height; - - gtk_object_get( GTK_OBJECT( e_minicard->header_text ), - "text_height", &text_height, - NULL ); - - e_minicard->height = text_height + 10.0; - - gnome_canvas_item_set( e_minicard->header_rect, - "y2", text_height + 9.0, - NULL ); - - gnome_canvas_item_set( e_minicard->header_text, - "clip_height", (double)text_height, - NULL ); - - for(list = e_minicard->fields; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), - "height", &text_height, - NULL); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data), - "y", (double) e_minicard->height, - NULL); - e_minicard->height += text_height; - } - e_minicard->height += 2; - - gnome_canvas_item_set( e_minicard->rect, - "y2", (double) e_minicard->height - 1, - NULL ); - - gnome_canvas_item_set( e_minicard->rect, - "x2", (double) e_minicard->width - 1.0, - "y2", (double) e_minicard->height - 1.0, - NULL ); - gnome_canvas_item_set( e_minicard->header_rect, - "x2", (double) e_minicard->width - 3.0, - NULL ); - gnome_canvas_item_set( e_minicard->header_text, - "clip_width", (double) e_minicard->width - 12, - NULL ); - for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { - gnome_canvas_item_set( GNOME_CANVAS_ITEM( list->data ), - "width", (double) e_minicard->width - 4.0, - NULL ); - - if (old_height != e_minicard->height) - gtk_signal_emit_by_name (GTK_OBJECT (e_minicard), "resize"); - } - } -} - -static void -_resize( GtkObject *object, gpointer data ) -{ - _update_card(E_MINICARD(data)); -} diff --git a/widgets/e-minicard/e-minicard.h b/widgets/e-minicard/e-minicard.h deleted file mode 100644 index 3be80c1586..0000000000 --- a/widgets/e-minicard/e-minicard.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-minicard.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_MINICARD_H__ -#define __E_MINICARD_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EMinicard - A small card displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * width double RW width of the card - * height double R height of the card - * card ECard* RW Pointer to the ECard - */ - -#define E_MINICARD_TYPE (e_minicard_get_type ()) -#define E_MINICARD(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_TYPE, EMinicard)) -#define E_MINICARD_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_TYPE, EMinicardClass)) -#define E_IS_MINICARD(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_TYPE)) -#define E_IS_MINICARD_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_TYPE)) - - -typedef struct _EMinicard EMinicard; -typedef struct _EMinicardClass EMinicardClass; -typedef enum _EMinicardFocusType EMinicardFocusType; - -enum _EMinicardFocusType { - E_MINICARD_FOCUS_TYPE_START, - E_MINICARD_FOCUS_TYPE_END -}; - -struct _EMinicard -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - /* ECard *card; */ - - GnomeCanvasItem *rect; - GnomeCanvasItem *header_rect; - GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ - - gboolean has_focus; - - double width; - double height; -}; - -struct _EMinicardClass -{ - GnomeCanvasGroupClass parent_class; - - void (* resize) (EMinicard *minicard); -}; - - -GtkType e_minicard_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_MINICARD_H__ */ diff --git a/widgets/e-minicard/e-reflow.c b/widgets/e-minicard/e-reflow.c deleted file mode 100644 index c1022f8f78..0000000000 --- a/widgets/e-minicard/e-reflow.c +++ /dev/null @@ -1,787 +0,0 @@ -/* -*- 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 - * - * 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 -#include -#include "e-reflow.h" -#include "e-canvas-utils.h" -static void e_reflow_init (EReflow *card); -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 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 _update_reflow ( EReflow *reflow ); -static void _resize( GtkObject *object, gpointer data ); -static void _queue_reflow(EReflow *e_reflow); - -#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; - -enum { - E_REFLOW_RESIZE, - E_REFLOW_LAST_SIGNAL -}; - -static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT -}; - -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 ()); - - e_reflow_signals[E_REFLOW_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EReflowClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); - - 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); - - 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->card = NULL;*/ - reflow->items = NULL; - reflow->columns = NULL; - reflow->column_width = 150; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - reflow->idle = 0; - - 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; -} - -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); - _queue_reflow(e_reflow); - break; - case ARG_MINIMUM_WIDTH: - e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg); - _queue_reflow(e_reflow); - break; - } -} - -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; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -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); - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - } - - _queue_reflow( e_reflow ); - - 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); - - g_list_free (e_reflow->items); - g_list_free (e_reflow->columns); - - 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); - gboolean 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", TRUE, - NULL); - return 1; - } else { - return 0; - } - } - } - } - break; - case GDK_BUTTON_PRESS: - switch(event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - double n_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)); - if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) { - 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); - _queue_reflow(e_reflow); - } else { - 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; - 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)); - if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->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->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; - 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->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; -} - -void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - e_reflow->items = g_list_append(e_reflow->items, item); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - _queue_reflow(e_reflow); - } - -} - -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 double -e_reflow_point (GnomeCanvasItem *item, - double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - EReflow *e_reflow = E_REFLOW(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 = 1; - 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 -_update_reflow( EReflow *e_reflow ) -{ - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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) - gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); - } -} - - -static gboolean -_idle_reflow(gpointer data) -{ - EReflow *e_reflow = E_REFLOW(data); - _update_reflow(e_reflow); - e_reflow->need_height_update = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(e_reflow)); - e_reflow->idle = 0; - return FALSE; -} - -static void -_queue_reflow(EReflow *e_reflow) -{ - if (e_reflow->idle == 0) - e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); -} - -static void -_resize( GtkObject *object, gpointer data ) -{ - _queue_reflow(E_REFLOW(data)); -} diff --git a/widgets/e-minicard/e-reflow.h b/widgets/e-minicard/e-reflow.h deleted file mode 100644 index 3a731474cb..0000000000 --- a/widgets/e-minicard/e-reflow.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_REFLOW_H__ -#define __E_REFLOW_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflow - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_TYPE (e_reflow_get_type ()) -#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) -#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) -#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) -#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) - - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; - -struct _EReflow -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - /* EBook *book; */ - - GList *items; /* Of type GnomeCanvasItem */ - GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ - gint column_count; /* Number of columnns */ - - double minimum_width; - double width; - double height; - - double column_width; - - int idle; - - /* These are all for when the column is being dragged. */ - gboolean column_drag; - gdouble start_x; - gint which_column_dragged; - double temp_column_width; - double previous_temp_column_width; - - guint need_height_update : 1; - guint need_column_resize : 1; - - guint default_cursor_shown : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - void (* resize) (EReflow *reflow); -}; - -/* To be added to a reflow, an item must have the arguments "x", "y", - and "width" as Read/Write arguments and "height" as a Read Only - argument. It must also have a "resize" signal. */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-minicard/test-minicard-label.c b/widgets/e-minicard/test-minicard-label.c deleted file mode 100644 index 67c17a0ace..0000000000 --- a/widgets/e-minicard/test-minicard-label.c +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* test-minicard-label.c - * - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * This program 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, 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. - */ - - - -#include "config.h" - -#include -#include "e-minicard-label.h" - -/* This is a horrible thing to do, but it is just a test. */ -GnomeCanvasItem *label; -GnomeCanvasItem *rect; - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) -{ - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, allocation->width, allocation->height ); - gnome_canvas_item_set( label, - "width", (double) allocation->width, - "height", (double) allocation->height, - NULL ); - gnome_canvas_item_set( rect, - "x2", (double) allocation->width, - "y2", (double) allocation->height, - NULL ); -} - -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey ", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Minicard Label Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the minicard label canvas item" ), - NULL); - gtk_widget_show (about); -} - -static void button_press_callback( GtkWidget *widget, gpointer data ) -{ - gnome_canvas_item_grab_focus( label ); -} - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *canvas; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "Minicard Label Test", VERSION, argc, argv); - app = gnome_app_new("Minicard Label Test", NULL); - - canvas = gnome_canvas_new(); - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - label = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - e_minicard_label_get_type(), - "x", (double) 0, - "y", (double) 0, - "width", (double) 100, - "height", (double) 100, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), - 0, 0, - 100, 100 ); - - gnome_app_set_contents( GNOME_APP( app ), canvas ); - - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - ( gpointer ) app ); - - gtk_signal_connect( GTK_OBJECT( canvas ), "button_press_event", - GTK_SIGNAL_FUNC( button_press_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/e-minicard/test-minicard.c b/widgets/e-minicard/test-minicard.c deleted file mode 100644 index 79077c4b2d..0000000000 --- a/widgets/e-minicard/test-minicard.c +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* test-minicard.c - * - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * This program 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, 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. - */ - - - -#include "config.h" - -#include -#include "e-minicard.h" - -/* This is a horrible thing to do, but it is just a test. */ -GnomeCanvasItem *card; -GnomeCanvasItem *rect; - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) -{ - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, allocation->width, allocation->height ); - gnome_canvas_item_set( card, - "width", (double) allocation->width, - NULL ); - gnome_canvas_item_set( rect, - "x2", (double) allocation->width, - "y2", (double) allocation->height, - NULL ); -} - -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey ", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Minicard Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the minicard canvas item" ), - NULL); - gtk_widget_show (about); -} - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *canvas; - int i; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "Minicard Test", VERSION, argc, argv); - app = gnome_app_new("Minicard Test", NULL); - - canvas = gnome_canvas_new(); - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - for ( i = 0; i < 1; i++ ) - { - card = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - e_minicard_get_type(), - "x", (double) 0, - "y", (double) 0, - "width", (double) 100, - NULL ); - } - gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), - 0, 0, - 100, 100 ); - - gnome_app_set_contents( GNOME_APP( app ), canvas ); - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/e-minicard/test-reflow.c b/widgets/e-minicard/test-reflow.c deleted file mode 100644 index 4533e0249d..0000000000 --- a/widgets/e-minicard/test-reflow.c +++ /dev/null @@ -1,161 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* test-reflow.c - * - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * This program 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, 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. - */ - - - -#include "config.h" - -#include -#include "e-canvas.h" -#include "e-reflow.h" -#include "e-minicard.h" - -/* This is a horrible thing to do, but it is just a test. */ -GnomeCanvasItem *reflow; -GnomeCanvasItem *rect; -GtkAllocation last_alloc; - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) -{ - double width; - last_alloc = *allocation; - gnome_canvas_item_set( reflow, - "height", (double) allocation->height, - NULL ); - gnome_canvas_item_set( reflow, - "minimum_width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(reflow), - "width", &width, - NULL); - width = MAX(width, allocation->width); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); - gnome_canvas_item_set( rect, - "x2", (double) width, - "y2", (double) allocation->height, - NULL ); -} - -static void resize(GnomeCanvasItem *item, gpointer data) -{ - double width; - gtk_object_get(GTK_OBJECT(reflow), - "width", &width, - NULL); - width = MAX(width, last_alloc.width); - gnome_canvas_set_scroll_region(item->canvas , 0, 0, width, last_alloc.height ); - gnome_canvas_item_set( rect, - "x2", (double) width, - "y2", (double) last_alloc.height, - NULL ); -} - -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey ", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Reflow Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the reflow canvas item" ), - NULL); - gtk_widget_show (about); -} - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *canvas; - GtkWidget *vbox; - GtkWidget *scrollbar; - int i; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "Reflow Test", VERSION, argc, argv); - app = gnome_app_new("Reflow Test", NULL); - - vbox = gtk_vbox_new(FALSE, 0); - - canvas = e_canvas_new(); - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - e_reflow_get_type(), - "x", (double) 0, - "y", (double) 0, - "height", (double) 100, - "minimum_width", (double) 100, - NULL ); - gtk_signal_connect( GTK_OBJECT( reflow ), "resize", - GTK_SIGNAL_FUNC( resize ), - ( gpointer ) app); - for ( i = 0; i < 200; i++ ) - { - GnomeCanvasItem *item; - item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), - e_minicard_get_type(), - NULL); - e_reflow_add_item(E_REFLOW(reflow), item); - } - gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), - 0, 0, - 100, 100 ); - - gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); - - scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); - - gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); - - gnome_app_set_contents( GNOME_APP( app ), vbox ); - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - gdk_window_set_back_pixmap( GTK_LAYOUT(canvas)->bin_window, NULL, FALSE); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/e-reflow/e-reflow.c b/widgets/e-reflow/e-reflow.c deleted file mode 100644 index c1022f8f78..0000000000 --- a/widgets/e-reflow/e-reflow.c +++ /dev/null @@ -1,787 +0,0 @@ -/* -*- 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 - * - * 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 -#include -#include "e-reflow.h" -#include "e-canvas-utils.h" -static void e_reflow_init (EReflow *card); -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 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 _update_reflow ( EReflow *reflow ); -static void _resize( GtkObject *object, gpointer data ); -static void _queue_reflow(EReflow *e_reflow); - -#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; - -enum { - E_REFLOW_RESIZE, - E_REFLOW_LAST_SIGNAL -}; - -static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT -}; - -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 ()); - - e_reflow_signals[E_REFLOW_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EReflowClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); - - 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); - - 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->card = NULL;*/ - reflow->items = NULL; - reflow->columns = NULL; - reflow->column_width = 150; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - reflow->idle = 0; - - 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; -} - -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); - _queue_reflow(e_reflow); - break; - case ARG_MINIMUM_WIDTH: - e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg); - _queue_reflow(e_reflow); - break; - } -} - -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; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -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); - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - } - - _queue_reflow( e_reflow ); - - 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); - - g_list_free (e_reflow->items); - g_list_free (e_reflow->columns); - - 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); - gboolean 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", TRUE, - NULL); - return 1; - } else { - return 0; - } - } - } - } - break; - case GDK_BUTTON_PRESS: - switch(event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - double n_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)); - if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) { - 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); - _queue_reflow(e_reflow); - } else { - 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; - 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)); - if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->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->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; - 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->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; -} - -void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - e_reflow->items = g_list_append(e_reflow->items, item); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - _queue_reflow(e_reflow); - } - -} - -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 double -e_reflow_point (GnomeCanvasItem *item, - double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - EReflow *e_reflow = E_REFLOW(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 = 1; - 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 -_update_reflow( EReflow *e_reflow ) -{ - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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) - gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); - } -} - - -static gboolean -_idle_reflow(gpointer data) -{ - EReflow *e_reflow = E_REFLOW(data); - _update_reflow(e_reflow); - e_reflow->need_height_update = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(e_reflow)); - e_reflow->idle = 0; - return FALSE; -} - -static void -_queue_reflow(EReflow *e_reflow) -{ - if (e_reflow->idle == 0) - e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); -} - -static void -_resize( GtkObject *object, gpointer data ) -{ - _queue_reflow(E_REFLOW(data)); -} diff --git a/widgets/e-reflow/e-reflow.h b/widgets/e-reflow/e-reflow.h deleted file mode 100644 index 3a731474cb..0000000000 --- a/widgets/e-reflow/e-reflow.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_REFLOW_H__ -#define __E_REFLOW_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflow - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_TYPE (e_reflow_get_type ()) -#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) -#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) -#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) -#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) - - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; - -struct _EReflow -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - /* EBook *book; */ - - GList *items; /* Of type GnomeCanvasItem */ - GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ - gint column_count; /* Number of columnns */ - - double minimum_width; - double width; - double height; - - double column_width; - - int idle; - - /* These are all for when the column is being dragged. */ - gboolean column_drag; - gdouble start_x; - gint which_column_dragged; - double temp_column_width; - double previous_temp_column_width; - - guint need_height_update : 1; - guint need_column_resize : 1; - - guint default_cursor_shown : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - void (* resize) (EReflow *reflow); -}; - -/* To be added to a reflow, an item must have the arguments "x", "y", - and "width" as Read/Write arguments and "height" as a Read Only - argument. It must also have a "resize" signal. */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-table/.cvsignore b/widgets/e-table/.cvsignore deleted file mode 100644 index 0963d457d9..0000000000 --- a/widgets/e-table/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -table-test diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog deleted file mode 100644 index 0010fe934f..0000000000 --- a/widgets/e-table/ChangeLog +++ /dev/null @@ -1,605 +0,0 @@ -2000-02-09 Christopher James Lahey - - * Makefile.am: Changes where e-text is included from. - -2000-02-07 Christopher James Lahey - - * e-table-item.c (eti_event): Fixed some motion event - bugs. (incorrect x and y.) - - * Makefile.am: Added includes for dependencies in - evolution/widgets/libevolutionwidgets.a - - * e-cell-text.h, e-cell-text.c: Completely revamped using code - from e-text.c and e-text.h. - -2000-02-07 Miguel de Icaza - - * e-table.c (e_table_setup_table): Setup the scroll region of the - table canvas on size allocation. - (e_table_canvas_realize): Do not set the scrollregion here. - (e_table_canvas_init): Move root initialization here. - -2000-01-30 Miguel de Icaza - - * e-table-simple.c (e_table_simple_new): Add data field back in. - -1999-12-30 Miguel de Icaza - - * e-table-item.c (eti_attach_cell_views): New routine, creates the - cell views. - (eti_detach_cell_views): Detaches the cell_views from the - ETableItem. - (eti_realize_cell_views, eti_unrealize_cell_views): Simplified to - just do realize/unrealize notification. - (eti_add_table_model): Only attach the cells when we have both the - table model and the header model. - - * e-cell.h (ECellClass): Added two new methods: new_view and - kill_view which drive the view process (instead of putting that on - realize/unrealize). - - * e-cell.c: Adapt the code to use the new scheme for view - instantiation. - - * e-cell-text.c, e-cell-toggle.c: Adapted to the new class - changes. - -1999-12-22 Miguel de Icaza - - * e-table-item.c (e_table_item_focus): grab focus here with the - canvas method. - -1999-12-20 Miguel de Icaza - - * e-table-group.c (etg_update): Change the dimensions only if the - child changes its own. - - * e-table-item.c (eti_table_model_changed): Emit new signal on - table height change. - (eti_class_init): Register new "height_change" signal. - -1999-12-19 Damon Chaplin - - * Makefile.am (SUBDIRS): created SUBDIRS with meeting-time-sel. - - * meeting-time-sel/Makefile.am: - * meeting-time-sel/.cvsignore: - * meeting-time-sel/e-meeting-time-sel.h: - * meeting-time-sel/e-meeting-time-sel.c: - * meeting-time-sel/e-meeting-time-sel-item.h: - * meeting-time-sel/e-meeting-time-sel-item.c: - * meeting-time-sel/e-meeting-time-sel-list-item.h: - * meeting-time-sel/e-meeting-time-sel-list-item.c: - * meeting-time-sel/e-meeting-time-sel-mail.xpm: - * meeting-time-sel/e-meeting-time-sel-no-mail.xpm: - * meeting-time-sel/test-meeting-time-sel.c: new files implementing - the meeting time selector. - -1999-12-12 Miguel de Icaza - - * e-table-item.c (eti_class_init): X and Y arguments are now - doubles (to make it consistent with the rest of the canvas x, y - arguments). - - * e-table.c (e_table_create_leaf): Use new argument values here - - * test-*.c: Update to new argument types for x and y - - * e-table-group.c: New implementation as a canvas item used to - group childs. - - * e-table-item.c (eti_update): Make this play nicely with groups. - (eti_draw): ditto. - (eti_request_region_redraw): ditto. - (eti_item_region_redraw): New function. - - * e-table-subset.c (etss_proxy_model_row_changed): Added model - proxying. - - * e-cell.h: Drop ETableModel from the ECell; - (realize): Now takes an ETableModel - - * e-cell-checkbox.c: Adapted to new class - changes; - * e-cell-toggle.c: ditto - - * e-table-subset.c (etss_row_count): Fix this guy. - -1999-12-11 Miguel de Icaza - - * e-table-item.c (eti_unrealize_cell_views): Null the cell views. - (eti_header_structure_changed): Only unrealize/realize if we were - realized before. - - * e-table-header.c (e_table_header_add_column): Allow -1 as an - insert position - -1999-12-11 Miguel de Icaza - - * e-table.c: Massive fixage. - - * test-table.c: Updates to test the mega widget. - -1999-12-10 Miguel de Icaza - - * e-table.c: New file, implements the mega widget. - -1999-12-09 Miguel de Icaza - - * e-table-header.c (e_table_header_col_diff): fix this routine. - -1999-12-04 Miguel de Icaza - - * e-table-header-item.c (ethi_event): Started drag and drop - support. - - * e-table-item.c (eti_table_model_changed): The columns are - controled by the Header, not by the TableModel. - - * e-table-header-item.c (ethi_draw): Fixed redraw logic to support - arbitrary header positioning. - - * e-cell.h: Revamped e-cell interface. We now provide the model - column and the view column to all methods (so that the methods can - talk to the view and to the model at the same time). - - * e-table-item.c: Update to new API - * e-cell-test.c: Update to new API - -1999-12-03 Miguel de Icaza - - * e-cell.c (e_cell_class_init): Provide emtpy methods for - enter_edit, and leave_edit. - - * e-table-item.c: Killed draw cell. - (eti_draw): Perform column mapping here. - (e_table_item_leave_edit): ditto. - (e_table_item_enter_edit): ditto. - (eti_event): ditto. - -1999-12-02 Miguel de Icaza - - * e-table-header.c (e_table_header_index): fixed api. - -1999-12-01 Miguel de Icaza - - * test-cols.c (multi_cols_test): Update to simplified API. - * test-check.c (check_test): ditto - * test-table.c (table_browser_test): ditto - - * e-table-simple.c (e_table_simple_class_init): Kill column_name method. - - * e-table-model.h: Kill column_name method. - - * e-table-col.c (e_table_col_new): Instead of using a column name, - use a column index. - - * e-cell-text.c (ect_draw): Keep track of the originally allocated - piece of code. - - * e-table-header-item.c (ethi_unrealize): Removed change cursor - from here. - - * e-cell-text.c (ect_draw): Memory leak fix. - - * table-test.c (main): Enhance the demo to load sample.table - automatically, to get memprof working. - - * e-table-header.c (eth_do_remove): Take an argument: do -remove. - - * e-table-header.c (e_table_header_add_column): Sink ETableCol to - own the object. - - * e-table-col.h: Made ETableCol a GtkObject to make reference - counting the lifecycle method for these objects. - - * e-table-col.c (e_table_col_destroy): New API call. - - * e-table-subset.c (e_table_subset_get_toplevel): New API call. - -1999-11-30 Miguel de Icaza - - * e-cell-checkbox.c (e_cell_checkbox_new): This one derives from - e-cell-toggle. - - * check-emtpy.xpm, check-filled.xpm: new files. - - * e-cell-toggle.c (etog_draw): Paint in white. - If we have transparency enabled, do the nice alpha computation. - - * test-table.c, test-cols.c: new files; They implement the split - tests. - -1999-11-29 Miguel de Icaza - - * e-table-col.c (e_table_col_new): Set etc->resizeable. - - * e-table-header-item.c (ethi_event): Handle non-resizeables - columns; Add support for minimum width. - - * e-cell-toggle.c, e-cell-toggle.h: New file. Implement a - multi-state image toggle cell object. - - * e-cell-text.c (ect_leave_edit): Handle the case of us calling - leave edit manually. - (ect_stop_editing): Leave manually editing here. - (ect_draw): Add one pixel to the border for left and right; - Handle off-screen cursor (must be improved). - (ect_edit_select_all): New function. - (ect_event): Select all text on editing start - - * e-table-item.c (eti_event): Map mouse events and dispatch them. - (eti_event): Add spreadsheet mode for editing; Enter editing only - with visual characters; - Leave editing mode when a different row has been selected. - (eti_get_height): Fix the computation for this; Fix logic for the - length_threshold. - - (eti_draw): Add borders on all sides of the box; - Only draw focus if the cell is not being edited. - -1999-11-28 Miguel de Icaza - - * e-table-item.c (eti_draw): Focus inside, not outside. - (eti_realize): Enhance our focus gc. - - * e-cell-text.c (ect_enter_edit, ect_leave_edit): New methods; - They implement editing. - - * e-cell.h: new methods: enter_edit, leave_edit - - * e-table-model.h (set_value_at): make val argument const. - - * e-table-simple.c (simple_set_value_at): Make value argument const; - - * e-table-item.c (eti_set_arg): Add new mode: draw_focus; - -1999-11-27 Miguel de Icaza - - * e-table-item.c (eti_event): beginning of the keyboard navigation. - - * e-table-model.c (e_table_model_row_changed): new function. - (e_table_model_cell_changed): new function. - (e_table_model_class_init): New signals. - - * e-table-item.c (eti_request_region_redraw): x2, y2 offsets were - wrong. - (eti_select): Repaint selected region. - (eti_request_region_redraw): Fix range. - (eti_draw): Correct offset computation here. - (e_table_item_class_init): New method: row_selection, handles the - selection. - - Now it implement GTK_SELECTION_SINGLE and GTK_SELECTION_MULTIPLE. - - Focusing and selection should be correct now. - -1999-11-26 Miguel de Icaza - - * e-table-item.c (eti_realize): Compute height using the ecell - methods here. - (eti_get_height): new method to compute dimensions. - - * e-cursors.c: use a different cursor. - - * e-table-model.h: kill height and row_height methods. - - * e-cell.c (ec_height): New method. - - * e-cell-text.c (ect_realize): Load the font from the canvas. - (ect_draw): New color setup. - Center in the row. - (ect_height): Implement new method. - -1999-11-26 Michael Meeks - - * ROADMAP.e-table: small spelling/typo fixes. - -1999-11-25 Miguel de Icaza - - * e-table-item.c (eti_event): Work on mouse-button event - propagation to cells. - - * e-cell-text.c (ect_draw): Use CellViews now. - - * e-table-item.c (eti_realize_cell_views): New routine: Realizes - the cell views - (eti_unrealize_cell_views): New routine: unrealizes the cell views. - - * e-table-item.h: Move cell_views array here. - - * table-test.c (value_at): Fix return value. - (main): use new invocation method. - - * e-table-header-item.c (ethi_realize): Realize cells. - - * e-table-item.c (eti_header_dim_changed): redraw before and after. - - * e-table-header-item.c (ethi_event): Add continuous resizing. - -1999-11-24 Miguel de Icaza - - * e-table-subset.h, e-table-subset.c: New files, used to implement - subset tables. - - * e-table-sorted.h, e-table-sorted.c: Now they derive from - e-table-subset. - - * e-cell.c, e-cell.h: realize method now return per view instance - data. - -1999-11-20 Miguel de Icaza - - * e-table-item.c (eti_draw): WOOOOHOOOOOoO! It took me quite a - while to figure this one out. Fixed. - - * e-table-header-item.c (ethi_set_arg): Compute width, keep track - of it. - (ethi_add_table_header): Monitor changes to the Header model; - Queue updates. - (ethi_draw): Fix the redraw logic here. - - * table-test.c (main): Change the sample code, so we can better - debug this. - - * e-table-item.c (eti_header_structure_changed): Keep track of - width; - (eti_header_dim_changed): ditto. - (eti_draw): Many redraw fixes. - -1999-11-19 Miguel de Icaza - - * e-table-item.c (eti_realize): Hook up; Load gcs. - (eti_unrealize): Hook up. - - * e-table-sorted.c: Finished implementing. - -1999-11-18 Miguel de Icaza - - * e-table-model.c (e_table_model_class_init): Add model_changed - signal here. - - * e-table-item.c, e-table-item.h: New files. They implement the - view of the ETableModel as Canvas Items. - - * e-table-header-item.c (ethi_set_arg): Ref header here. - (ethi_destroy): Unref it here. - -1999-11-17 Ettore Perazzoli - - * e-msg-composer-address-dialog.c: Moved to `$(srcdir)/composer'. - * e-msg-composer-address-dialog.h: Likewise. - * e-msg-composer-address-entry.c: Likewise. - * e-msg-composer-address-entry.h: Likewise. - * e-msg-composer-attachment-bar.c: Likewise. - * e-msg-composer-attachment-bar.h: Likewise. - * e-msg-composer-attachment.c: Likewise. - * e-msg-composer-attachment.h: Likewise. - * e-msg-composer-hdrs.c: Likewise. - * e-msg-composer-hdrs.h: Likewise. - * e-msg-composer.c: Likewise. - * e-msg-composer.h: Likewise. - * e-msg-composer-address-dialog.glade: Likewise. - * e-msg-composer-attachment.glade: Likewise. - * e-msg-composer.glade: Likewise. - * Makefile.am: Updated accordingly. - -Nov 14 1999 Elliot Lee - * Makefile.am: It's libevolutionwidgets.la, not .a - -1999-11-14 Miguel de Icaza - - * e-table-header-item.c (is_pointer_on_division): Add resizing - capabilities. - - * e-table-sorted.c: Finish implementation. - -1999-11-13 Miguel de Icaza - - * e-table-sorted.c: Implement e-table-sorted object. - -1999-11-12 Miguel de Icaza - - * e-table-header-item.c: Make the thing configurable. - - * e-table-header-item.h: Add font field, location, height. - -1999-11-12 Ettore Perazzoli - - * e-msg-composer-hdrs.c: New member `tooltips' in `struct - _EMsgComposerHdrsPrivate'. - (init): Initialize it. - (destroy): New function. - (class_init): Install it as the `destroy' GtkObject method. - (add_header): New parameters `tip', `tip_private'. Setup a - tooltip for the entry with them. - (setup_headers): Updated accordingly. - -1999-11-11 Miguel de Icaza - - * e-table-header.c (e_table_header_add_column): Update offsets. - (eth_update_offsets): New routine. - - * e-table-col.h, e-table-col.c: New files. - - * e-table-header.h (e_table_header_get_selected_indexes): - Pretify. - - * table-test.c (main): New file; used for testing ETable package. - - * e-table-simple.h: Fix type. - -1999-11-12 Ettore Perazzoli - - * e-msg-composer-address-dialog.glade: Cosmetical changes. - - * e-msg-composer-attachment-bar.c (size_to_string): New helper - function. - (update): Put the size in the icon's label using this function. - (ICON_SEPARATORS): Remove '.' to avoid wrapping of the size string - on the decimal dot. But gnome-libs is broken and this has no real - effect! :-( - (e_msg_composer_attachment_bar_new): No longer make text editable. - Use the `GTK_SELECTION_MULTIPLE' selection mode. - (remove_selected): No longer assume only one attachment is - selected. - - * e-msg-composer-attachment.c: #include - (init): Initialize all the members. - (e_msg_composer_attachment_new): Set size using `stat()'. - - * e-msg-composer-attachment.h: New member `size' in `struct - _EMsgComposerAttachment'. - - * e-msg-composer.c (setup_signals): Connect `address_dialog_cb' to - the "show_address_dialog" signal of the header widget. - - * e-msg-composer-hdrs.c (add_address_header): Renamed to - `add_header'. New parameter `addrbook_button': if true, use a - button instead of a label and make it trigger an - "show_address_dialog" signal. - (address_button_clicked_cb): Signal handler to handle this on a - "clicked" signal from the button. - (setup_headers): Updated accordingly. Also, make "Subject" the - last item. (This makes it look more like Outlook and friends.) - - * e-msg-composer-hdrs.c: New signal "show_address_dialog". - * e-msg-composer-hdrs.h: Updated accordingly. - - * e-msg-composer-hdrs.c (add_address_header): Reduce padding - considerably. - - * e-msg-composer.c (e_msg_composer_construct): Do not use any - padding in the main vbox. - - * Makefile.am: Moved the `e-table*' sources to `EXTRA_DIST'. - Compile as a shared library. - -1999-11-08 Ettore Perazzoli - - * e-msg-composer-address-dialog.c: Implemented cut & paste for the - recipient lists. - (init): Initialize `cut_buffer'. - (destroy): Free it. - (recipient_clist_selection_get_cb): New function. - (recipient_clist_selection_received_cb): New function. - (recipient_clist_selection_clear_event_cb): New function. - (setup_recipient_list_signals): Install them as signal handlers - for "selection_get", "selection_received" and - "selection_clear_event" respectively. - (copy_recipient_cb): New function implementing the "copy" - operation. - (cut_recipient_cb): New function implementing the "cut" operation. - (paste_recipient_cb): New function implementing the "paste" - operation. - - * e-msg-composer-address-dialog.h: New member `cut_buffer' in - `struct _EMsgComposerAddressDialog'. - -1999-11-07 Ettore Perazzoli - - * e-msg-composer-address-dialog.c: New context menu - `recipient_list_popup_info' for the recipient CLists. - (recipient_clist_button_press_cb): New function. - (setup_signals): Install it as the "button_press_event" signal - handler for popping up the CList context menu. - - * e-msg-composer.c (free_string_list): New helper function. - (setup_address_dialog): Setup the initial values in the address - dialog according to the ones in the header widget. - - * e-msg-composer-hdrs.c (e_msg_composer_hdrs_get_to): New function. - (e_msg_composer_hdrs_get_cc): New function. - (e_msg_composer_hdrs_get_bcc): New function. - - * e-msg-composer.c (setup_address_dialog): New helper function. - (address_dialog_cb): Use it. - - * e-msg-composer-address-dialog.c (add_address): Do not set the - row data anymore. Instead, put the full address description - (i.e. complete with the email address, not just the full name) in - the CList. - (add_address): Do nothing if no item is selected in the address - CList. - (get_list): Get the address list from the CList without passing - through the address CList. - (set_list): New helper function. - (e_msg_composer_address_dialog_set_to_list): New function. - (e_msg_composer_address_dialog_set_cc_list): New function. - (e_msg_composer_address_dialog_set_bcc_list): New function. - - * e-msg-composer.c (address_dialog_apply_cb): Apply values from - the address dialog into the composer. - - * e-msg-composer-hdrs.c (e_msg_composer_hdrs_set_to): New function. - (e_msg_composer_hdrs_set_cc): New function. - (e_msg_composer_hdrs_set_bcc): New function. - - * e-msg-composer-address-entry.c - (e_msg_composer_address_entry_set_list): New function. - - * e-msg-composer-address-dialog.c (apply): New helper function. - (clicked): New function, `clicked' method for the `GnomeDialog' - class. - (class_init): Install it. - -1999-11-06 Ettore Perazzoli - - * e-msg-composer-attachment-bar.c (destroy): Call the destroy - method of the parent class. - - * e-msg-composer.c: #include "e-msg-composer-address-dialog.h". - (address_dialog_cb): New callback to start the address dialog. - (setup_signals): Connect it to the appropriate button/menu item. - (init): Initialize the new `address_dialog' member to NULL. - (destroy): Destroy the `address_dialog' if not NULL. - - * e-msg-composer.h: New member `address_dialog' in `struct - _EMsgComposer'. - - * e-msg-composer.glade: Added button to activate the address - composition dialog. - - * e-msg-composer-address-dialog.h, e-msg-composer-address-dialog.c: - New files implementing the address composition dialog for Evolution. - - * e-msg-composer-address-dialog.glade: New file. - - * e-msg-composer-attachment.c: `signals' made static. - -1999-11-05 Ettore Perazzoli - - * Makefile.am: Compile the new files in a `libevolutionwidgets' - library. - (CPPFLAGS): #define `E_GUIDIR'. - - * e-msg-composer.c, e-msg-composer.h: New files implementing an - initial version of the Evolution message composer widget. - - * e-msg-composer-address-entry.c, e-msg-composer-address-entry.h: - New files implementing a GtkEntry customized for entering email - address lists. - - * e-msg-composer-attachment-bar.c, e-msg-composer-attachment-bar.h: - New files implementing a widget for editing mail attachments. - - * e-msg-composer-attachment.c, e-msg-composer-attachment.h: New - files implementing file attachment objects for the message - composer. - - * e-msg-composer-hdrs.c, e-msg-composer-hdrs.h: New files - implementing a widget for editing of email message headers. - - * e-msg-composer-attachment.glade: New file. - * e-msg-composer.glade: New file. - -1999-10-31 Miguel de Icaza - - * widgets/e-table-column.c, e-table-column.h: New file, implements the - e-table-column object. - - * widget/e-table-model.h, e-table-model.c, e-table-simple.c, - e-table-simple.h: New files. Implements the column model and - a simple table wrapper. - diff --git a/widgets/e-table/LICENSE b/widgets/e-table/LICENSE deleted file mode 100644 index b1f6ae08a4..0000000000 --- a/widgets/e-table/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is released under the terms of the GNU GPL. diff --git a/widgets/e-table/Makefile.am b/widgets/e-table/Makefile.am deleted file mode 100644 index 4bbfea58ab..0000000000 --- a/widgets/e-table/Makefile.am +++ /dev/null @@ -1,62 +0,0 @@ -INCLUDES = \ - $(GNOME_INCLUDEDIR) \ - -I$(top_srcdir)/widgets/e-text \ - -I$(top_srcdir)/e-util \ - -I$(top_srcdir) - -noinst_LIBRARIES = \ - libetable.a - -libetable_a_SOURCES = \ - e-cell.c \ - e-cell.h \ - e-cell-checkbox.c \ - e-cell-checkbox.h \ - e-cell-text.c \ - e-cell-text.h \ - e-cell-toggle.c \ - e-cell-toggle.h \ - e-table.c \ - e-table.h \ - e-table-col.c \ - e-table-col.h \ - e-table-group.c \ - e-table-group.h \ - e-table-header.c \ - e-table-header.h \ - e-table-header-item.c \ - e-table-header-item.h \ - e-table-item.c \ - e-table-item.h \ - e-table-model.c \ - e-table-model.h \ - e-table-simple.c \ - e-table-simple.h \ - e-table-sorted.c \ - e-table-sorted.h \ - e-table-subset.c \ - e-table-subset.h - -noinst_PROGRAMS = \ - table-test - -table_test_SOURCES = \ - test-table.c \ - test-check.c \ - test-cols.c \ - table-test.c - -table_test_LDADD = \ - $(EXTRA_GNOME_LIBS) \ - libetable.a \ - $(top_builddir)/e-util/libeutil.a \ - $(top_builddir)/widgets/e-text/libetext.a - -table_test_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -EXTRA_DIST = \ - sample.table \ - add-col.xpm \ - check-empty.xpm \ - check-filled.xpm \ - remove-col.xpm diff --git a/widgets/e-table/ROADMAP.e-table b/widgets/e-table/ROADMAP.e-table deleted file mode 100644 index 4edacced86..0000000000 --- a/widgets/e-table/ROADMAP.e-table +++ /dev/null @@ -1,113 +0,0 @@ - -The E-Table package implements an editable table that provides -user-defined rendering, user-defined editing, sorting and grouping of -the objects displayed. - -It is inspired by Java's Swing JTable object. There are models for -the actual table contents and for the table headers; they are the -actual repository of information. - -The objects are rendered by various view objects. In the current code -base, we use we use GnomeCanvasItems to do the rendering. One for -each table and one for the headers. - -* The main widget - -e-table.c, e-table.h: - - Implements a full widget. Uses various components described - below. Handles column display as well as grouping/nesting - -* The Models - -All of them are GtkObjects. - -e-table-model.h, e-table-model.c: - - These implement the abstract E-Table-Model class. You - can derive this object to create your own data repository. - - These emits signals to notify the views about selection, and - changes in the model. - -e-table-simple.h, e-table-simple.c: - - A simple implementation of e-table-model that uses callback - routines (you provide the callbacks). For lazy people, like - me. - -e-cell.c, e-cell.h: - - These are actually mis-named. Objects of type e-cell know - about rendering a single cell, and these are attached to the - e-table-cols (described next). - - The user provides the various rendering modes as e-cells (they - are actually column-rendering repositories). - - This is just an abstract class. I will provide various - e-cells: a text cell, a checkbox cell, an image cell, and - perhaps an n-state image cell (one that switches the image when - the cell is clicked). - -e-table-col.h, e-table-col.c: - - Describes a single column (the size, the string displayed, the - rendering function for each row and comparison function for - this field). - - -* The Views - -e-table-header.h, e-table-header.c: - - These implement the ETableHeaderItem canvas item. This item is - used both to control the columns displayed as well as displaying them. - - They describe what columns are shown in the screen and in - which order. - - These emit signals: column-size-changed and structure-changed - (if a column is added/removed) - -e-table-item.c, e-table-item.h - - This is a canvas item that renders the contents of a - ETableModel into the screen. - -e-table-header-item.c, e-table-header-item.h - - This canvas item renders the ETableHeader headings. - -e-cell-text.c, e-cell-text.h - - Not really a view, but actually a derivative of e-cell that - implements text display: supports justification and font - setting. Will add color in the future most likely - -e-cell-toggle.c, e-cell-toggle.h - - A derivative of e-cell as well that support N-toggle values - using images. - -e-cell-check.c, e-cell-check.h - - An e-cell-toggle with two states only (for checkboxes). - -* The Filters - -e-table-sorted.c, e-table-sorted.h - - This is an ETableModel that can sort an existing ETableModel. - -e-table-subset.c, e-table-subset.h - - Not finished, but it is just an ETableModel that happens to be - a subset of another ETableModel. - -* Everything - -e-table.c, e-table.h - - In the future these guys will implement the whole widget for - doing table editing. Nothing done about these yet. diff --git a/widgets/e-table/TODO b/widgets/e-table/TODO deleted file mode 100644 index 29dbd454e5..0000000000 --- a/widgets/e-table/TODO +++ /dev/null @@ -1,24 +0,0 @@ -Implement e-cell-height -Implement computation of heights from the e-cell-heights -Make sure we compute the height from that -Include spacing in columns and rows for the decoration lines -Add threshold to compute a "global" size -Implement the two methods for row finding: by full thing, or by a factor. - - -Add editing -mouse grabbing for scrolling - - -1. Make sure that all values are updated on header changes and table - model changes (they are slightly out of sync now) - -* Correctness - - * Make sure we can boot and shutdown with no memory leaks. - - * Run Insure on the thing. - -* Propagation - - * Row changes should be reflected in the subsets. diff --git a/widgets/e-table/add-col.xpm b/widgets/e-table/add-col.xpm deleted file mode 100644 index 9c5f314c8e..0000000000 --- a/widgets/e-table/add-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * add_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" ....+++....... ", -" .+. ", -" . ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/e-table/check-empty.xpm b/widgets/e-table/check-empty.xpm deleted file mode 100644 index 2dd873e137..0000000000 --- a/widgets/e-table/check-empty.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static char * check_empty_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/e-table/check-filled.xpm b/widgets/e-table/check-filled.xpm deleted file mode 100644 index 689d7a7967..0000000000 --- a/widgets/e-table/check-filled.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static char * check_filled_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . . ", -" . .. . ", -" . ... . ", -" . . ... . ", -" . .. ... . ", -" . ..... . ", -" . ... . ", -" . . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/e-table/e-cell-checkbox.c b/widgets/e-table/e-cell-checkbox.c deleted file mode 100644 index 431c1663d1..0000000000 --- a/widgets/e-table/e-cell-checkbox.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * e-cell-checkbox.c: Checkbox cell renderer - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-checkbox.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -#define PARENT_TYPE e_cell_toggle_get_type() - -static GdkPixbuf *checks [2]; - -static void -e_cell_checkbox_class_init (GtkObjectClass *object_class) -{ - checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_checkbox_new (void) -{ - ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - - e_cell_toggle_construct (E_CELL_TOGGLE (eccb), 2, 2, checks); - - return (ECell *) eccb; -} diff --git a/widgets/e-table/e-cell-checkbox.h b/widgets/e-table/e-cell-checkbox.h deleted file mode 100644 index 969e4a5edc..0000000000 --- a/widgets/e-table/e-cell-checkbox.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include "e-cell-toggle.h" - -#define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_CHECKBOX_TYPE, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(o) (GTK_CHECK_TYPE ((o), E_CELL_CHECKBOX_TYPE)) -#define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) - -typedef struct { - ECellToggle parent; -} ECellCheckbox; - -typedef struct { - ECellToggleClass parent_class; -} ECellCheckboxClass; - -GtkType e_cell_checkbox_get_type (void); -ECell *e_cell_checkbox_new (void); - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/e-table/e-cell-string.c b/widgets/e-table/e-cell-string.c deleted file mode 100644 index 992b1bd10e..0000000000 --- a/widgets/e-table/e-cell-string.c +++ /dev/null @@ -1,9 +0,0 @@ -ECell * -e_cell_string_new (void) -{ - ECell *ecell; - - ecell = gtk_type_new (ecell); - - return ecell; -} diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c deleted file mode 100644 index 6e5b28b8a1..0000000000 --- a/widgets/e-table/e-cell-text.c +++ /dev/null @@ -1,1843 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-text.c - Text cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Authors: Miguel de Icaza (miguel@kernel.org) - * Chris Lahey - * - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-text.h" -#include "e-util/e-util.h" -#include "e-table-item.h" -#include "e-text-event-processor-emacs-like.h" - -#include /* for BlackPixel */ -#include -#include - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -static GdkAtom clipboard_atom = GDK_NONE; - - - -#define PARENT_TYPE e_cell_get_type() - -#define TEXT_PAD 2 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - int max_width; - int ref_count; -} ECellTextLineBreaks; - - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GdkFont *font; - GdkCursor *default_cursor; - GdkCursor *i_cursor; - GdkBitmap *stipple; /* Stipple for text */ - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - - int xofs, yofs; /* This gets added to the x - and y for the cell text. */ - double ellipsis_width; /* The width of the ellipsis. */ - -} ECellTextView; - -typedef struct _CurrentCell{ - - ECellTextView *text_view; - int width; - gchar *text; - int model_col, view_col, row; - ECellTextLineBreaks *breaks; -} CurrentCell; - -#define CURRENT_CELL(x) ((CurrentCell *)(x)) - -struct _CellEdit { - CurrentCell cell; - - char *old_text; - - /* - * Where the editing is taking place - */ - - int xofs_edit, yofs_edit; /* Offset because of editing. - This is negative compared - to the other offsets. */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - /* Cursor handling. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; - guint default_cursor_shown : 1; -}; - -static void e_cell_text_view_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_cell_text_view_get_selection(CellEdit *edit, GdkAtom selection, guint32 time); -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, guchar *data, gint length); - -static GtkWidget *e_cell_text_view_get_invisible(CellEdit *edit); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit); -static void split_into_lines (CurrentCell *cell); -static void unref_lines(CurrentCell *cell); -static void calc_line_widths (CurrentCell *cell); -static int get_line_ypos (CurrentCell *cell, struct line *line); -static int get_line_xpos (CurrentCell *cell, struct line *line); -static void _get_tep(CellEdit *edit); - -static gint _get_position_from_xy (CurrentCell *cell, gint x, gint y); -static void _get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp); -static gboolean _blink_scroll_timeout (gpointer data); - -static void build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row); - -static ECellClass *parent_class; - -static void -ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Accept the currently edited text - */ -static void -ect_accept_edits (ECellTextView *text_view) -{ - CurrentCell *cell = (CurrentCell *) text_view->edit; - - e_table_model_set_value_at (text_view->cell_view.e_table_model, cell->model_col, cell->row, cell->text); -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - - g_free (edit->old_text); - edit->old_text = NULL; - g_free (edit->cell.text); - edit->cell.text = NULL; - if (edit->invisible) - gtk_widget_unref (edit->invisible); - if (edit->tep) - gtk_object_unref (GTK_OBJECT(edit->tep)); - if (edit->primary_selection) - g_free(edit->primary_selection); - if (edit->clipboard_selection) - g_free(edit->clipboard_selection); - - g_free (edit); - - text_view->edit = NULL; - - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view); - ect_queue_redraw (text_view, text_view->edit->cell.view_col, text_view->edit->cell.row); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *text_view = g_new0 (ECellTextView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - text_view->cell_view.ecell = ecell; - text_view->cell_view.e_table_model = table_model; - text_view->cell_view.e_table_item_view = e_table_item_view; - - if (ect->font_name){ - GdkFont *f; - - f = gdk_fontset_load (ect->font_name); - text_view->font = f; - } - if (!text_view->font){ - text_view->font = GTK_WIDGET (canvas)->style->font; - - gdk_font_ref (text_view->font); - } - - text_view->canvas = canvas; - - text_view->xofs = 0.0; - text_view->yofs = 0.0; - - return (ECellView *)text_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->gc = gdk_gc_new (GTK_WIDGET (text_view->canvas)->window); - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - text_view->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - gdk_gc_unref (text_view->gc); - text_view->gc = NULL; - - if (text_view->font) - gdk_font_unref (text_view->font); - - if (text_view->stipple) - gdk_bitmap_unref (text_view->stipple); - - gdk_cursor_destroy (text_view->i_cursor); - gdk_cursor_destroy (text_view->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - /* New ECellText */ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *text_view = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GdkFont *font = text_view->font; - const int height = font->ascent + font->descent; - CellEdit *edit = text_view->edit; - gboolean edit_display = FALSE; - ECellTextLineBreaks *linebreaks; - - - if (edit){ - - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) - edit_display = TRUE; - fg_gc = canvas->style->fg_gc[edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - } else { - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if ( edit_display ) { - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - cell->width = x2 - x1; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - ypos = get_line_ypos (cell, lines); - ypos += font->ascent; - ypos -= edit->yofs_edit; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (cell, lines); - xpos -= edit->xofs_edit; - start_char = lines->text - cell->text; - end_char = start_char + lines->length; - sel_start = edit->selection_start; - sel_end = edit->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char); - sel_rect.y = ypos + y1 - font->ascent; - sel_rect.width = gdk_text_width (font, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = height; - gtk_paint_flat_box(canvas->style, - drawable, - edit->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - canvas, - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - sel_start - start_char); - gdk_draw_text (drawable, - font, - fg_gc, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char), - ypos + y1, - lines->text + sel_start - start_char, - sel_end - sel_start); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_end - start_char), - ypos + y1, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); - } - if (edit->selection_start == edit->selection_end && - edit->selection_start >= start_char && - edit->selection_start <= end_char && - edit->show_cursor) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char), - ypos + y1 - font->ascent, - 1, - height); - } - } - unref_lines(cell); - } else { - - ECellTextLineBreaks *linebreaks; - CurrentCell cell; - build_current_cell ( &cell, text_view, model_col, view_col, row ); - - cell.width = x2 - x1; - - split_into_lines(&cell); - - linebreaks = cell.breaks; - lines = linebreaks->lines; - ypos = get_line_ypos(&cell, lines); - ypos += font->ascent; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (&cell, lines); - if ( ect->use_ellipsis && lines->ellipsis_length < lines->length) { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->ellipsis_length); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1 + - lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } else { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); - } - } - - ypos += height; - lines++; - unref_lines(&cell); - } - - gdk_gc_set_clip_rectangle (text_view->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); -#if 0 - /* Old ECellText */ - - int xoff; - gboolean edit_display = FALSE; - - /* - * Figure if this cell is being edited - */ - if (edit_display){ - CellEdit *edit = text_view->edit; - const char *text = gtk_entry_get_text (edit->entry); - GdkWChar *p, *text_wc = g_new (GdkWChar, strlen (text) + 1); - int text_wc_len = gdk_mbstowcs (text_wc, text, strlen (text)); - const int cursor_pos = GTK_EDITABLE (edit->entry)->current_pos; - const int left_len = gdk_text_width_wc (text_view->font, text_wc, cursor_pos); - - text_wc [text_wc_len] = 0; - /* - * Paint - */ - gdk_gc_set_foreground (text_view->gc, &w->style->base [GTK_STATE_NORMAL]); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, &w->style->text [GTK_STATE_NORMAL]); - - { - GdkGC *gc = text_view->gc; - const int y = y2 - font->descent - ((y2-y1-height)/2); - int px, i; - - /* - * Border - */ - x1 += 2; - x2--; - - px = x1; - - /* - * If the cursor is outside the visible range - * - * FIXME: we really want a better behaviour. - */ - if ((px + left_len) > x2) - px -= left_len - (x2-x1); - - /* - * Draw - */ - for (i = 0, p = text_wc; *p; p++, i++){ - gdk_draw_text_wc ( - drawable, font, gc, px, y, p, 1); - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - - px += gdk_text_width_wc (font, p, 1); - } - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - } - g_free (text_wc); - } else { - /* - * Regular cell - */ - GdkColor *background, *foreground; - int width; - - /* - * Border - */ - x1++; - x2--; - - /* - * Compute draw mode - */ - switch (ect->justify){ - case GTK_JUSTIFY_LEFT: - xoff = 1; - break; - - case GTK_JUSTIFY_RIGHT: - width = 1 + gdk_text_width (font, str, strlen (str)); - xoff = (x2 - x1) - width; - break; - - case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (font, str, strlen (str))) / 2; - break; - default: - xoff = 0; - g_warning ("Can not handle GTK_JUSTIFY_FILL"); - break; - } - - - if (selected){ - background = &w->style->bg [GTK_STATE_SELECTED]; - foreground = &w->style->text [GTK_STATE_SELECTED]; - } else { - background = &w->style->base [GTK_STATE_NORMAL]; - foreground = &w->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (text_view->gc, background); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, foreground); - - gdk_draw_string ( - drawable, font, text_view->gc, - x1 + xoff, - y2 - font->descent - ((y2-y1-height)/2), str); - } -#endif -} - -/* - * Selects the entire string - */ -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_assert (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen(text_view->edit->cell.text); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - - CurrentCell cell, *cellptr; - build_current_cell ( &cell, text_view, model_col, view_col, row ); - - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - cellptr = CURRENT_CELL(edit); - } else { - cellptr = &cell; - } - } else { - cellptr = &cell; - } - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (ect->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!edit_display) { -#if 0 - if ( edit->pointer_in ) { - if ( edit->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } -#endif - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - edit->xofs_edit = 0; - edit->yofs_edit = 0; - if (edit->timeout_id == 0) - edit->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text_view); - edit->timer = g_timer_new(); - g_timer_elapsed(edit->timer, &(edit->scroll_start)); - g_timer_start(edit->timer); - } - } else { - if ( ! edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->default_cursor); - edit->default_cursor_shown = TRUE; - } - if (edit->timeout_id) { - g_source_remove(edit->timeout_id); - edit->timeout_id = 0; - } - if (edit->timer) { - g_timer_stop(edit->timer); - g_timer_destroy(edit->timer); - edit->timer = NULL; - } - } - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (edit_display) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(edit); - return e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (edit_display) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(cellptr, button.x, button.y); - _get_tep(edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - } else if (ect->editable && event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - return 1; - } - break; - case GDK_MOTION_NOTIFY: - if (edit) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(cellptr, motion.x, motion.y); - _get_tep(edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->lastx = motion.x; - edit->lasty = motion.y; - edit->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: -#if 0 - edit->pointer_in = TRUE; -#endif - if (edit) { - if ( edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: -#if 0 - text_view->pointer_in = FALSE; -#endif - if (edit) { - if ( ! edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->default_cursor); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; -#if 0 - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); -#endif - else - return 0; - -#if 0 - switch (event->type){ - case GDK_BUTTON_PRESS: - /* - * Adjust for the border we use - */ - event->button.x++; - - printf ("Button pressed at %g %g\n", event->button.x, event->button.y); - if (text_view->edit){ - printf ("FIXME: Should handle click here\n"); - } else - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - break; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return TRUE; - } - - if (!text_view->edit){ - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - } - - gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event); - ect_queue_redraw (text_view, view_col, row); - break; -#endif -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CurrentCell cell; - int return_val; - - build_current_cell ( &cell, text_view, model_col, view_col, row ); - split_into_lines( &cell ); - - return_val = (text_view->font->ascent + text_view->font->descent) * cell.breaks->num_lines + TEXT_PAD; - - unref_lines( &cell ); - - return return_val; -} - -/* - * Callback: invoked when the user pressed "enter" on the GtkEntry - */ -static void -ect_entry_activate (GtkEntry *entry, ECellTextView *text_view) -{ - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - const char *str = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - CellEdit *edit; - - edit = g_new (CellEdit, 1); - text_view->edit = edit; - - build_current_cell ( CURRENT_CELL(edit), text_view, model_col, view_col, row ); - - edit->xofs_edit = 0.0; - edit->yofs_edit = 0.0; - - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - - edit->timeout_id = 0; - edit->timer = NULL; - - edit->lastx = 0; - edit->lasty = 0; - edit->last_state = 0; - - edit->scroll_start = 0; - edit->show_cursor = TRUE; - edit->button_down = FALSE; - - edit->tep = NULL; - - edit->has_selection = FALSE; - - edit->invisible = NULL; - edit->primary_selection = NULL; - edit->primary_length = 0; - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - - edit->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - edit->old_text = g_strdup (str); - edit->cell.text = g_strdup (str); - - ect_queue_redraw (text_view, view_col, row); - - return NULL; -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - if (text_view->edit){ - ect_accept_edits (text_view); - ect_stop_editing (text_view); - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_text_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - - parent_class = gtk_type_class (PARENT_TYPE); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) -{ - ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - - ect->ellipsis = NULL; - ect->use_ellipsis = FALSE; - - ect->editable = TRUE; - - ect->font_name = g_strdup (fontname); - ect->justify = justify; - - return (ECell *) ect; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (CurrentCell *cell, struct line *line) -{ - int x; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - - x = text_view->xofs + ect->x; - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - x += cell->width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (cell->width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_ypos (CurrentCell *cell, struct line *line) -{ - int y; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - - struct line *lines = linebreaks->lines; - - y = text_view->yofs + ect->y; - y += (line - lines) * (text_view->font->ascent + text_view->font->descent); - - return y; -} - -static void -_get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - ECellTextView *text_view = cell->text_view; - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - lines = linebreaks->lines; - - x = get_line_xpos (cell, lines); - y = get_line_ypos (cell, lines); - for (j = 0, lines = linebreaks->lines; j < linebreaks->num_lines; lines++, j++) { - if (lines->text > cell->text + position) - break; - y += font->ascent + font->descent; - } - lines --; - y -= font->descent; - - x += gdk_text_width (font, - lines->text, - position - (lines->text - cell->text)); - if ( (CellEdit *) cell == cell->text_view->edit ) { - x -= ((CellEdit *)cell)->xofs_edit; - y -= ((CellEdit *)cell)->yofs_edit; - } - if (xp) - *xp = x; - if (yp) - *yp = y; - unref_lines(cell); - } -} - -static gint -_get_position_from_xy (CurrentCell *cell, gint x, gint y) -{ - int i, j; - int xpos, ypos; - struct line *lines; - int return_val; - - ECellTextView *text_view = cell->text_view; - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - - if ( (CellEdit *) cell == cell->text_view->edit ) { - x += ((CellEdit *)cell)->xofs_edit; - y += ((CellEdit *)cell)->yofs_edit; - } - - ypos = get_line_ypos (cell, linebreaks->lines); - j = 0; - while (y > ypos) { - ypos += font->ascent + font->descent; - j ++; - } - j--; - if (j >= linebreaks->num_lines) - j = linebreaks->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - - lines += j; - xpos = get_line_xpos (cell, lines); - for(i = 0; i < lines->length; i++) { - int charwidth = gdk_text_width(font, - lines->text + i, - 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - - return_val = lines->text + i - cell->text; - - unref_lines(cell); - - return return_val; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - CurrentCell *cell = CURRENT_CELL(data); - ECellTextView *text_view = (ECellTextView *) data; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - CellEdit *edit = text_view->edit; - ECellTextLineBreaks *linebreaks = cell->breaks; - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(edit->timer, ¤t_time); - - if (edit->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > edit->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < edit->scroll_start) - scroll = TRUE; - } else { - if (current_time > edit->scroll_start + SCROLL_WAIT_TIME || - current_time < edit->scroll_start) - scroll = TRUE; - } - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > cell->width && - edit->xofs_edit < linebreaks->max_width - cell->width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > linebreaks->max_width - cell->width + 1) - edit->xofs_edit = linebreaks->max_width - cell->width + 1; - redraw = TRUE; - } - if (edit->lastx - ect->x < 0 && - edit->xofs_edit > 0) { - edit->xofs_edit -= 4; - if (edit->xofs_edit < 0) - edit->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = edit->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(cell, edit->lastx, edit->lasty); - _get_tep(edit); - e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!edit->show_cursor) - redraw = TRUE; - edit->show_cursor = TRUE; - } else { - if (edit->show_cursor) - redraw = TRUE; - edit->show_cursor = FALSE; - } -#if 0 - if (redraw) - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - return TRUE; -} - -static int -_get_position(ECellTextView *text_view, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return edit->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return strlen(cell->text); - - case E_TEP_START_OF_LINE: - for (i = edit->selection_end - 2; i > 0; i--) - if (cell->text[i] == '\n') { - i++; - break; - } - return i; - case E_TEP_END_OF_LINE: - length = strlen(cell->text); - for (i = edit->selection_end + 1; i < length; i++) - if (cell->text[i] == '\n') { - break; - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = strlen(cell->text); - i = edit->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = edit->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = strlen(cell->text); - for (i = edit->selection_end + 1; i < length; i++) - if (isspace(cell->text[i])) { - break; - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = edit->selection_end - 2; i > 0; i--) - if (isspace(cell->text[i])) { - i++; - break; - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(cell, edit->selection_end, &x, &y); - y += text_view->font->ascent + text_view->font->descent; - return _get_position_from_xy(cell, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(cell, edit->selection_end, &x, &y); - y -= text_view->font->ascent + text_view->font->descent; - return _get_position_from_xy(cell, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return edit->selection_end; - default: - return edit->selection_end; - } -} - -static void -_delete_selection(ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length = strlen(cell->text); - if (edit->selection_end == edit->selection_start) - return; - if (edit->selection_end < edit->selection_start) { - edit->selection_end ^= edit->selection_start; - edit->selection_start ^= edit->selection_end; - edit->selection_end ^= edit->selection_start; - } - memmove( cell->text + edit->selection_start, - cell->text + edit->selection_end, - length - edit->selection_end + 1 ); - length -= edit->selection_end - edit->selection_start; - edit->selection_end = edit->selection_start; -} - -static void -_insert(ECellTextView *text_view, char *string, int value) -{ - if (value > 0) { - char *temp; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length = strlen(cell->text); - temp = g_new(gchar, length + value + 1); - strncpy(temp, cell->text, edit->selection_start); - strncpy(temp + edit->selection_start, string, value); - strcpy(temp + edit->selection_start + value, cell->text + edit->selection_start); - g_free(cell->text); - cell->text = temp; - edit->selection_start += value; - edit->selection_end = edit->selection_start; - } -} - -static void -e_cell_text_view_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - CurrentCell *cell = CURRENT_CELL(edit); - ECellTextView *text_view = cell->text_view; - - gboolean change = FALSE; - gboolean redraw = FALSE; - - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - edit->selection_start = _get_position(text_view, command); - edit->selection_end = edit->selection_start; - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - break; - case E_TEP_SELECT: - edit->selection_end = _get_position(text_view, command); - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, GDK_SELECTION_PRIMARY, cell->text + sel_start, sel_end - sel_start); - } else if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - break; - case E_TEP_DELETE: - if (edit->selection_end == edit->selection_start) { - edit->selection_end = _get_position(text_view, command); - } - _delete_selection(text_view); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - - case E_TEP_INSERT: - if (edit->selection_end != edit->selection_start) { - _delete_selection(text_view); - } - _insert(text_view, command->string, command->value); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_COPY: - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, clipboard_atom, cell->text + sel_start, sel_end - sel_start); - } - if (edit->timer) { - g_timer_reset(edit->timer); - } - break; - case E_TEP_PASTE: - e_cell_text_view_get_selection (edit, clipboard_atom, command->time); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_GET_SELECTION: - e_cell_text_view_get_selection (edit, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - if (edit->timer) { - g_timer_reset(edit->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - edit->select_by_word = command->value; - break; - case E_TEP_GRAB: - case E_TEP_UNGRAB: -#if 0 - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text_view->i_cursor, - command->time); - break; - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; -#endif - case E_TEP_NOP: - break; - } - - if (!edit->button_down) { - int x; - int i; - struct line *lines; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - for (lines = linebreaks->lines, i = 0; i < linebreaks->num_lines ; i++, lines ++) { - if (lines->text - cell->text > edit->selection_end) { - break; - } - } - lines --; - x = gdk_text_width(text_view->font, - lines->text, - edit->selection_end - (lines->text - cell->text)); - - - if (x < edit->xofs_edit) { - edit->xofs_edit = x; - redraw = TRUE; - } - - if (2 + x - cell->width > edit->xofs_edit) { - edit->xofs_edit = 2 + x - cell->width; - redraw = TRUE; - } - unref_lines(cell); - } - - if ( redraw ) { - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif -} - -static void _invisible_destroy (GtkInvisible *invisible, - CellEdit *edit) -{ - edit->invisible = NULL; -} - -static GtkWidget *e_cell_text_view_get_invisible(CellEdit *edit) -{ - GtkWidget *invisible; - if (edit->invisible) { - invisible = edit->invisible; - } else { - invisible = gtk_invisible_new(); - edit->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - edit); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - edit); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (edit->primary_selection); - edit->primary_selection = NULL; - edit->primary_length = 0; - - edit->has_selection = FALSE; -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - - } else if (event->selection == clipboard_atom) { - g_free (edit->clipboard_selection); - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->primary_selection, edit->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->clipboard_selection, edit->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_cell_text_view_command(edit->tep, &command, edit); - } -} - -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_cell_text_view_get_invisible(edit); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (edit->primary_selection) { - g_free (edit->primary_selection); - } - edit->primary_selection = g_strndup(data, length); - edit->primary_length = length; - } else if (selection == clipboard_atom) { - if (edit->clipboard_selection) { - g_free (edit->clipboard_selection); - } - edit->clipboard_selection = g_strndup(data, length); - edit->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - edit->has_selection = successful; -} - -static void -e_cell_text_view_get_selection(CellEdit *edit, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_cell_text_view_get_invisible(edit); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -static void -_get_tep(CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (edit->tep)); - gtk_object_sink (GTK_OBJECT (edit->tep)); - gtk_signal_connect(GTK_OBJECT(edit->tep), - "command", - GTK_SIGNAL_FUNC(e_cell_text_view_command), - (gpointer) edit); - } -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (CurrentCell *cell) -{ - char *p; - struct line *lines; - int len; - - gchar *text = cell->text; - ECellTextLineBreaks *linebreaks = cell->breaks; - - if (! cell->breaks) { - cell->breaks = g_new(ECellTextLineBreaks, 1); - cell->breaks->ref_count = 1; - } else { - cell->breaks->ref_count ++; - return; - } - linebreaks = cell->breaks; - - /* Check if already split. */ - - linebreaks->lines = NULL; - linebreaks->num_lines = 0; - - if (!text) - return; - - /* First, count the number of lines */ - - for (p = text; *p; p++) - if (*p == '\n') - linebreaks->num_lines++; - - linebreaks->num_lines++; - - /* Allocate array of lines and calculate split positions */ - - linebreaks->lines = lines = g_new0 (struct line, linebreaks->num_lines); - len = 0; - - for (p = text; *p; p++) { - if (len == 0) - lines->text = p; - if (*p == '\n') { - lines->length = len; - lines++; - len = 0; - } else - len++; - } - - if (len == 0) - lines->text = p; - lines->length = len; - - calc_line_widths (cell); -} - -/* Free lines structure. */ -static void -unref_lines(CurrentCell *cell) -{ - if ( cell->breaks ) { - cell->breaks->ref_count --; - if ( cell->breaks->ref_count <= 0 ) { - g_free(cell->breaks->lines); - g_free(cell->breaks); - cell->breaks = NULL; - } - } -} - -static void -calc_ellipsis (ECellTextView *text_view) -{ - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - if (text_view->font) - text_view->ellipsis_width = - gdk_text_width (text_view->font, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (CurrentCell *cell) -{ - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks = cell->breaks; - struct line *lines; - int i; - int j; - - - - lines = linebreaks->lines; - linebreaks->max_width = 0; - - if (!lines) - return; - - for (i = 0; i < linebreaks->num_lines; i++) { - if (lines->length != 0) { - if (font) { - lines->width = gdk_text_width (font, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (ect->use_ellipsis && - ! text_view->edit && - lines->width > cell->width) { - if (font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (font, lines->text, j) + text_view->ellipsis_width <= cell->width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = gdk_text_width (font, lines->text, lines->ellipsis_length) + - text_view->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > linebreaks->max_width) - linebreaks->max_width = lines->width; - } else { - lines->width = 0; - lines->ellipsis_length = 0; - } - - lines++; - } -} - -static void -build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row) -{ - ECellView *ecell_view = (ECellView *) text_view; - cell->text_view = text_view; - cell->model_col = model_col; - cell->view_col = view_col; - cell->row = row; - cell->breaks = NULL; - cell->text = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - cell->width = e_table_header_get_column(((ETableItem *)ecell_view->e_table_item_view)->header, view_col)->width; -} diff --git a/widgets/e-table/e-cell-text.h b/widgets/e-table/e-cell-text.h deleted file mode 100644 index 379ccf30a8..0000000000 --- a/widgets/e-table/e-cell-text.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellText - Text item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * Drawing and event handling from: - * - * EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ -#ifndef _E_CELL_TEXT_H_ -#define _E_CELL_TEXT_H_ - -#include -#include "e-cell.h" -#include "e-text-event-processor.h" - -#define E_CELL_TEXT_TYPE (e_cell_text_get_type ()) -#define E_CELL_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_TEXT_TYPE, ECellText)) -#define E_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TEXT_TYPE, ECellTextClass)) -#define E_IS_CELL_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_TEXT_TYPE)) -#define E_IS_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TEXT_TYPE)) - -typedef struct { - ECell parent; - - GtkJustification justify; - char *font_name; - - double x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - guint editable : 1; /* Item is editable */ -} ECellText; - -typedef struct { - ECellClass parent_class; -} ECellTextClass; - -GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); - -#endif /* _E_CELL_TEXT_H_ */ - - diff --git a/widgets/e-table/e-cell-toggle.c b/widgets/e-table/e-cell-toggle.c deleted file mode 100644 index 679d04a0ca..0000000000 --- a/widgets/e-table/e-cell-toggle.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * e-cell-toggle.c: Multi-state image toggle cell object. - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-toggle.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#define PARENT_TYPE e_cell_get_type() - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; -} ECellToggleView; - -static ECellClass *parent_class; - -static void -etog_queue_redraw (ECellToggleView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * ECell::realize method - */ -static ECellView * -etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - toggle_view->cell_view.ecell = ecell; - toggle_view->cell_view.e_table_model = table_model; - toggle_view->cell_view.e_table_item_view = e_table_item_view; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -etog_kill_view (ECellView *ecell_view) -{ - g_free (ecell_view); -} - -static void -etog_realize (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - toggle_view->gc = gdk_gc_new (GTK_WIDGET (toggle_view->canvas)->window); -} - -/* - * ECell::unrealize method - */ -static void -etog_unrealize (ECellView *ecv) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecv; - - gdk_gc_unref (toggle_view->gc); - toggle_view->gc = NULL; -} - -/* - * ECell::draw method - */ -static void -etog_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - GdkPixbuf *image; - ArtPixBuf *art; - int x, y, width, height; - const int value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - if (value >= toggle->n_states){ - g_warning ("Value from the table model is %d, the states we support are [0..%d)\n", - value, toggle->n_states); - return; - } - - /* - * Paint the background - */ - gdk_draw_rectangle (drawable, GTK_WIDGET (toggle_view->canvas)->style->white_gc, TRUE, x1, y1, x2 - x1, y2 - y1); - - image = toggle->images [value]; - art = image->art_pixbuf; - - if ((x2 - x1) < art->width){ - x = x1; - width = x2 - x1; - } else { - x = x1 + ((x2 - x1) - art->width) / 2; - width = art->width; - } - - if ((y2 - y1) < art->height){ - y = y1; - height = y2 - y1; - } else { - y = y1 + ((y2 - y1) - art->height) / 2; - height = art->height; - } - - width = y2 - y1; - - if (image->art_pixbuf->has_alpha){ - GdkColor background; - guchar *buffer; - int alpha, ix, iy; - - buffer = g_malloc (art->rowstride * art->height * 3); - - background.red = 255; - background.green = 255; - background.blue = 255; - - for (iy = 0; iy < art->height; iy++){ - unsigned char *dest; - unsigned char *src; - - dest = buffer + (iy * art->rowstride); - src = art->pixels + (iy * art->rowstride); - - for (ix = 0; ix < art->width; ix++){ - alpha = src [3]; - if (alpha == 0){ - *dest++ = background.red; - *dest++ = background.green; - *dest++ = background.blue; - src += 3; - } else if (alpha == 255){ - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - } else { - *dest++ = (background.red + ((*src++ - background.red) * alpha + 0x80)) >> 8; - *dest++ = (background.green + ((*src++ - background.green) * alpha + 0x80)) >> 8; - *dest++ = (background.blue + ((*src++ - background.blue) * alpha + 0x80)) >> 8; - } - src++; - } - } - - gdk_draw_rgb_image_dithalign ( - drawable, toggle_view->gc, x, y, width, height, - GDK_RGB_DITHER_NORMAL, buffer, art->rowstride, 0, 0); - - g_free (buffer); - } else - gdk_draw_rgb_image_dithalign ( - drawable, toggle_view->gc, x, y, width, height, - GDK_RGB_DITHER_NORMAL, art->pixels, art->rowstride, 0, 0); -} - -static void -etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) -{ - ECell *ecell = toggle_view->cell_view.ecell; - ECellToggle *toggle = E_CELL_TOGGLE (ecell); - - if (value >= toggle->n_states) - value = 0; - - e_table_model_set_value_at (toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); - etog_queue_redraw (toggle_view, view_col, row); -} - -/* - * ECell::event method - */ -static gint -etog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - const int value = GPOINTER_TO_INT (_value); - - switch (event->type){ - case GDK_BUTTON_RELEASE: - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_space){ - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - } - return FALSE; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -etog_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - - return toggle->height; -} - -static void -etog_destroy (GtkObject *object) -{ - ECellToggle *etog = E_CELL_TOGGLE (object); - int i; - - for (i = 0; i < etog->n_states; i++) - gdk_pixbuf_unref (etog->images [i]); - - g_free (etog->images); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_toggle_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = etog_destroy; - - ecc->new_view = etog_new_view; - ecc->kill_view = etog_kill_view; - ecc->realize = etog_realize; - ecc->unrealize = etog_unrealize; - ecc->draw = etog_draw; - ecc->event = etog_event; - ecc->height = etog_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); - -void -e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf **images) -{ - int max_height = 0; - int i; - - etog->border = border; - etog->n_states = n_states; - - etog->images = g_new (GdkPixbuf *, n_states); - - for (i = 0; i < n_states; i++){ - etog->images [i] = images [i]; - gdk_pixbuf_ref (images [i]); - - if (images [i]->art_pixbuf->height > max_height) - max_height = images [i]->art_pixbuf->height; - } - - etog->height = max_height; -} - -ECell * -e_cell_toggle_new (int border, int n_states, GdkPixbuf **images) -{ - ECellToggle *etog = gtk_type_new (e_cell_toggle_get_type ()); - - e_cell_toggle_construct (etog, border, n_states, images); - - return (ECell *) etog; -} - - diff --git a/widgets/e-table/e-cell-toggle.h b/widgets/e-table/e-cell-toggle.h deleted file mode 100644 index d5773b454a..0000000000 --- a/widgets/e-table/e-cell-toggle.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _E_CELL_TOGGLE_H_ -#define _E_CELL_TOGGLE_H_ - -#include -#include -#include "e-cell.h" - -#define E_CELL_TOGGLE_TYPE (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(o) (GTK_CHECK_CAST ((o), E_CELL_TOGGLE_TYPE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TOGGLE_TYPE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(o) (GTK_CHECK_TYPE ((o), E_CELL_TOGGLE_TYPE)) -#define E_IS_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TOGGLE_TYPE)) - -typedef struct { - ECell parent; - - int border; - int n_states; - GdkPixbuf **images; - - int height; -} ECellToggle; - -typedef struct { - ECellClass parent_class; -} ECellToggleClass; - -GtkType e_cell_toggle_get_type (void); -ECell *e_cell_toggle_new (int border, int n_states, GdkPixbuf **images); -void e_cell_toggle_construct (ECellToggle *etog, int border, - int n_states, GdkPixbuf **images); - -#endif /* _E_CELL_TOGGLE_H_ */ - - diff --git a/widgets/e-table/e-cell.c b/widgets/e-table/e-cell.c deleted file mode 100644 index f1345e8c6b..0000000000 --- a/widgets/e-table/e-cell.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * e-cell.c: base class for cell renderers in e-table - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include "e-cell.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE gtk_object_get_type() - -static ECellView * -ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return NULL; -} - -static void -ec_realize (ECellView *e_cell) -{ -} - -static void -ec_kill_view (ECellView *ecell_view) -{ -} - -static void -ec_unrealize (ECellView *e_cell) -{ -} - -static void -ec_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - g_error ("e-cell-draw invoked\n"); -} - -static gint -ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static gint -ec_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static void -ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2) -{ - ecell_view->focus_col = view_col; - ecell_view->focus_row = row; - ecell_view->focus_x1 = x1; - ecell_view->focus_y1 = y1; - ecell_view->focus_x2 = x2; - ecell_view->focus_y2 = y2; -} - -static void -ec_unfocus (ECellView *ecell_view) -{ - ecell_view->focus_col = -1; - ecell_view->focus_row = -1; - ecell_view->focus_x1 = -1; - ecell_view->focus_y1 = -1; - ecell_view->focus_x2 = -1; - ecell_view->focus_y2 = -1; -} - -static void * -ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context) -{ -} - -static void -e_cell_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = ec_realize; - ecc->unrealize = ec_unrealize; - ecc->new_view = ec_new_view; - ecc->kill_view = ec_kill_view; - ecc->draw = ec_draw; - ecc->event = ec_event; - ecc->focus = ec_focus; - ecc->unfocus = ec_unfocus; - ecc->height = ec_height; - ecc->enter_edit = ec_enter_edit; - ecc->leave_edit = ec_leave_edit; -} - -static void -e_cell_init (GtkObject *object) -{ -} - -E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE); - - -void -e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event ( - ecell_view, event, model_col, view_col, row); -} - -ECellView * -e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view ( - ecell, table_model, e_table_item_view); -} - -void -e_cell_view_realize (ECellView *ecell_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view); -} - -void -e_cell_kill_view (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view); -} - -void -e_cell_unrealize (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view); -} - -void -e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, int x1, int y1, int x2, int y2) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw ( - ecell_view, drawable, model_col, view_col, row, selected, x1, y1, x2, y2); -} - -int -e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( - ecell_view, model_col, view_col, row); -} - -void * -e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit ( - ecell_view, model_col, view_col, row); -} - -void -e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit ( - ecell_view, model_col, view_col, row, edit_context); -} diff --git a/widgets/e-table/e-cell.h b/widgets/e-table/e-cell.h deleted file mode 100644 index 3c258689e4..0000000000 --- a/widgets/e-table/e-cell.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include -#include "e-table-model.h" - -#define E_CELL_TYPE (e_cell_get_type ()) -#define E_CELL(o) (GTK_CHECK_CAST ((o), E_CELL_TYPE, ECell)) -#define E_CELL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TYPE, ECellClass)) -#define E_IS_CELL(o) (GTK_CHECK_TYPE ((o), E_CELL_TYPE)) -#define E_IS_CELL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TYPE)) - -typedef struct _ECell ECell; -typedef struct _ECellView ECellView; - -struct _ECell { - GtkObject object; -}; - -struct _ECellView { - ECell *ecell; - ETableModel *e_table_model; - void *e_table_item_view; - - gint focus_x1, focus_y1, focus_x2, focus_y2; - gint focus_col, focus_row; -}; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -typedef struct { - GtkObjectClass parent_class; - - ECellView *(*new_view) (ECell *ecell, ETableModel *table_model, void *e_table_item_view); - void (*kill_view) (ECellView *ecell_view); - - void (*realize) (ECellView *ecell_view); - void (*unrealize) (ECellView *ecell_view); - - void (*draw) (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, - gboolean selected, int x1, int y1, int x2, int y2); - gint (*event) (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - void (*focus) (ECellView *ecell_view, int model_col, int view_col, - int row, int x1, int y1, int x2, int y2); - void (*unfocus) (ECellView *ecell_view); - int (*height) (ECellView *ecell_view, int model_col, int view_col, int row); - - void *(*enter_edit)(ECellView *ecell_view, int model_col, int view_col, int row); - void (*leave_edit)(ECellView *ecell_view, int model_col, int view_col, int row, void *context); -} ECellClass; - -GtkType e_cell_get_type (void); -ECellView *e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -void e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - -void e_cell_realize (ECellView *ecell_view); -void e_cell_unrealize (ECellView *ecell_view); - -void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2); -void e_cell_focus (ECellView *ecell_view, int model_col, int view_col, int row, - int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell_view); -int e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row); - -void *e_cell_enter_edit(ECellView *ecell_view, int model_col, int view_col, int row); -void e_cell_leave_edit(ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context); - -#endif /* _E_CELL_H_ */ diff --git a/widgets/e-table/e-table-col-dnd.h b/widgets/e-table/e-table-col-dnd.h deleted file mode 100644 index c1c26175c7..0000000000 --- a/widgets/e-table/e-table-col-dnd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -#endif /* _E_TABLE_COL_DND_H_ */ diff --git a/widgets/e-table/e-table-col.c b/widgets/e-table/e-table-col.c deleted file mode 100644 index 6f475158a5..0000000000 --- a/widgets/e-table/e-table-col.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * E-table-col.c: ETableCol implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include "e-table-col.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - -static void -etc_destroy (GtkObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - g_free (etc->text); - - (*parent_class->destroy)(object); -} - -static void -e_table_col_class_init (GtkObjectClass *object_class) -{ - parent_class = gtk_type_class (PARENT_TYPE); - object_class->destroy = etc_destroy; -} - -E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, NULL, PARENT_TYPE); - -ETableCol * -e_table_col_new (int col_idx, const char *text, int width, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (width >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (width >= min_width, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->col_idx = col_idx; - etc->text = g_strdup (text); - etc->width = width; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->selected = 0; - etc->resizeable = resizable; - - return etc; -} - - diff --git a/widgets/e-table/e-table-col.h b/widgets/e-table/e-table-col.h deleted file mode 100644 index 54f03ae237..0000000000 --- a/widgets/e-table/e-table-col.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _E_TABLE_COL_H_ -#define _E_TABLE_COL_H_ - -#include "e-cell.h" - -#define E_TABLE_COL_TYPE (e_table_col_get_type ()) -#define E_TABLE_COL(o) (GTK_CHECK_CAST ((o), E_TABLE_COL_TYPE, ETableCol)) -#define E_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COL_TYPE, ETableColClass)) -#define E_IS_TABLE_COL(o) (GTK_CHECK_TYPE ((o), E_TABLE_COL_TYPE)) -#define E_IS_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COL_TYPE)) - -typedef struct _ETableCol ETableCol; - -/* - * Information about a single column - */ -struct _ETableCol { - GtkObject base; - char *text; - short width; - short min_width; - short x; - GCompareFunc compare; - unsigned int selected:1; - unsigned int resizeable:1; - int col_idx; - - ECell *ecell; -}; - -typedef struct { - GtkObjectClass parent_class; -} ETableColClass; - -GtkType e_table_col_get_type (void); -ETableCol *e_table_col_new (int col_idx, const char *text, - int width, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -void e_table_col_destroy (ETableCol *etc); - - -#endif /* _E_TABLE_COL_H_ */ - diff --git a/widgets/e-table/e-table-column-item.c b/widgets/e-table/e-table-column-item.c deleted file mode 100644 index 0616327a93..0000000000 --- a/widgets/e-table/e-table-column-item.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * E-table-column-view.c: A canvas view of the TableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include "e-table-column.h" -#include "e-table-column-view.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -static GnomeCanvasItemClass *etci_parent_class; - -enum { - ARG_0, - ARG_TABLE_COLUMN -}; - -static void -etci_destroy (GtkObject *object) -{ - ETableColumnItem *etcv = E_TABLE_COLUMN_VIEW (object); - - gtk_object_unref (GTK_OBJECT (etcv)); - - if (GTK_OBJECT_CLASS (etcv_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etcv_parent_class)->destroy) (object); -} - -static void -etci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update)(item, affine, clip_path, flags); - - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableColumnItem *etci; - int v; - - item = GNOME_CANVAS_ITEM (o); - etci = E_TABLE_COLUMN_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_COLUMN: - etci->etci = GTK_VALUE_POINTER (*arg); - break; - } - etci_update (item, NULL, NULL, 0); -} - -static void -etci_realize (GnomeCanvasItem *item) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - GdkWindow *window; - GdkColor c; - - if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - etci->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (etci->gc, &c); - - etci->normal_cursor = gdk_cursor_new (GDK_ARROW); -} - -static void -etci_unrealize (GnomeCanvasItem *item) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - - gdk_gc_unref (etci->gc); - etci->gc = NULL; - - gdk_cursor_destroy (etci->change_cursor); - etci->change_cursor = NULL; - - gdk_cursor_destroy (etci->normal_cursor); - etci->normal_cursor = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize)(item); -} - -static void -etci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int width, int height) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_column_count (etci->etc); - int x2 = x1 + width; - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *col = e_table_column_get_column (etci->etc, col); - const int col_width = col->width; - - if (x1 > total + col_width) - continue; - - if (x2 < total) - return; - - gc = canvas->style->bg_gc [GTK_STATE_ACTIVE]; - gdk_draw_rectangle (drawble, gc, TRUE, - gtk_draw_shadow (canvas->style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x, y, width, height - } -} - -static double -etci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = *item; - return 0.0; -} - -static void -etci_event (GnomeCanvasItem *item, GdkEvent *e) -{ - switch (e->type){ - default: - return FALSE; - } - return TRUE; -} - -static void -etci_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - object_class->destroy = etci_destroy; - object_class->set_arg = etci_set_arg; - - item_class->update = etci_update; - item_class->realize = etci_realize; - item_class->unrealize = etci_unrealize; - item_class->draw = etci_draw; - item_class->point = etci_point; - item_class->event = etci_event; - - gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_COLUMN); -} - -static void -etci_init (GnomeCanvasItem *item) -{ - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - -GtkType -e_table_column_view_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumnItem", - sizeof (ETableColumnItem), - sizeof (ETableColumnItemClass), - (GtkClassInitFunc) etci_class_init, - (GtkObjectInitFunc) etci_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - - - diff --git a/widgets/e-table/e-table-column-item.h b/widgets/e-table/e-table-column-item.h deleted file mode 100644 index fd38681a73..0000000000 --- a/widgets/e-table/e-table-column-item.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _E_TABLE_COLUMN_VIEW_H -#defein _E_TABLE_COLUMN_VIEW_H - -#include "e-table-column.h" - -typedef struct { - GnomeCanvasItem parent; - ETableColumn *etc; - - GdkGC *gc; - GdkCursor *change_cursor, *normal_cursor; -} ETableColumnView; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableColumnViewClass; - -GtkType e_table_column_item_get_type (void); - -#endif /* _E_TABLE_COLUMN_VIEW_H */ diff --git a/widgets/e-table/e-table-column-model.h b/widgets/e-table/e-table-column-model.h deleted file mode 100644 index 043dd783ca..0000000000 --- a/widgets/e-table/e-table-column-model.h +++ /dev/null @@ -1,5 +0,0 @@ - -class ETableColumnModel { - virtual void add_column (ETableCol *et) = 0; - virtual ETableCol *get_column (int column); - virtual diff --git a/widgets/e-table/e-table-column.c b/widgets/e-table/e-table-column.c deleted file mode 100644 index d17a285321..0000000000 --- a/widgets/e-table/e-table-column.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-table-column.c: TableColumn implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include "e-table-column.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint etc_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_column_parent_class; - -static void -e_table_column_destroy (GtkObject *object) -{ - ETableColumn *etc = E_TABLE_COLUMN (object); - const int cols = etc->col_count; - - /* - * Destroy listeners - */ - for (l = etc->listeners; l; l = l->next) - g_free (l->data); - g_slist_free (etc->listeners); - etc->listeners = NULL; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++) - e_table_column_remove (etc, i); - - if (e_table_column_parent_class->destroy) - e_table_column_parent_class->destroy (object); -} - -static void -e_table_column_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_column_destroy; - - e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ())); - - etc_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - etc_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etc_signals, LAST_SIGNAL); -} - -GtkType -e_table_column_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumn", - sizeof (ETableColumn), - sizeof (ETableColumnClass), - (GtkClassInitFunc) e_table_column_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -static void -etc_do_insert (ETableColumn *etc, int pos, ETableCol *val) -{ - memcpy (&etc->columns [pos+1], &etc->columns [pos], - sizeof (ETableCol *) * (etc->col_count - pos)); - etc->columns [pos] = val; -} - -void -e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos) -{ - ETableCol **new_ptr; - - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (tc != NULL); - g_return_if_fail (pos >= 0 && pos < etc->col_count); - - if (pos == -1) - pos = etc->col_count; - etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1)); - etc_do_insert (etc, pos, tc); - etc->col_count++; - - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_column_get_column (ETableColumn *etc, int column) -{ - g_return_val_if_fail (etc != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL); - - if (column < 0) - return NULL; - - if (column >= etc->col_count) - return NULL; - - return etc->columns [column]; -} - -int -e_table_column_count (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - return etc->col_count; -} - -int -e_table_column_index (ETableColumn *etc, const char *identifier) -{ - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - for (i = 0; i < etc->col_count; i++){ - ETableCol *tc = etc->columns [i]; - - if (strcmp (i->id, identifier) == 0) - return i; - } - - return -1; -} - -int -e_table_column_get_index_at (ETableColumn *etc, int x_offset) -{ - int i, total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - total = 0; - for (i = 0; i < etc->col_count; i++){ - total += etc->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_column_get_columns (ETableColumn *etc) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - ret = g_new (ETableCol *, etc->col_count + 1); - memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count); - ret [etc->col_count] = NULL; - - return ret; -} - -gboolean -e_table_column_selection_ok (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE); - - return etc->selectable; -} - -int -ve_table_column_get_selected (ETableColumn *etc) -{ - int i; - int selected = 0; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - for (i = 0; i < etc->col_count; i++){ - if (etc->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_column_total_width (ETableColumn *etc) -{ - int total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - total = 0; - for (i = 0; i < etc->col_count; i++) - total += etc->columns [i].width; - - return total; -} - -static void -etc_do_remove (ETableColumn *etc, int idx) -{ - memcpy (&etc->columns [idx], &etc->columns [idx+1], - sizeof (ETableCol *) * etc->col_count - idx); - etc->col_count--; -} - -void -e_table_column_move (ETableColumn *etc, int source_index, int target_index) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < etc->col_count); - g_return_if_fail (target_index < etc->col_count); - - old = etc->columns [source_index]; - etc_do_remove (etc, source_index); - etc_do_insert (etc, target_index, old); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_remove (ETableColumn *etc, int idx) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - - etc_do_remove (etc, idx); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection); -{ -} - -void -e_table_column_set_size (ETableColumn *etc, int idx, int size) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - g_return_if_fail (size > 0); - - etc->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx); -} diff --git a/widgets/e-table/e-table-group.c b/widgets/e-table/e-table-group.c deleted file mode 100644 index 5652d2623f..0000000000 --- a/widgets/e-table/e-table-group.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@gnu.org() - * - * Copyright 1999, Helix Code, Inc. - */ - -#include -#include -#include "e-table-group.h" -#include "e-table-item.h" -#include -#include "e-util/e-util.h" - -#define TITLE_HEIGHT 16 -#define GROUP_INDENT 10 - -#define PARENT_TYPE gnome_canvas_group_get_type () - -static GnomeCanvasGroupClass *etg_parent_class; - -enum { - HEIGHT_CHANGED, - LAST_SIGNAL -}; - -static gint etg_signals [LAST_SIGNAL] = { 0, }; - -static void -etg_destroy (GtkObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - - GTK_OBJECT_CLASS (etg_parent_class)->destroy (object); -} - -static void -etg_dim (ETableGroup *etg, int *width, int *height) -{ - GSList *l; - - *width = *height = 0; - - for (l = etg->children; l; l = l->next){ - GnomeCanvasItem *child = l->data; - - *height += child->y2 - child->y1; - *width += child->x2 - child->x1; - } - - if (!etg->transparent){ - *height += TITLE_HEIGHT; - *width += GROUP_INDENT; - } -} - -void -e_table_group_construct (GnomeCanvasGroup *parent, ETableGroup *etg, - ETableCol *ecol, gboolean open, - gboolean transparent) -{ - gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL); - - etg->ecol = ecol; - etg->open = open; - etg->transparent = transparent; - - etg_dim (etg, &etg->width, &etg->height); - - if (!etg->transparent) - etg->rect = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (etg), - gnome_canvas_rect_get_type (), - "fill_color", "gray", - "outline_color", "gray20", - "x1", 0.0, - "y1", 0.0, - "x2", (double) etg->width, - "y2", (double) etg->height, - NULL); - -#if 0 - /* - * Reparent the child into our space. - */ - gnome_canvas_item_reparent (child, GNOME_CANVAS_GROUP (etg)); - - gnome_canvas_item_set ( - child, - "x", (double) GROUP_INDENT, - "y", (double) TITLE_HEIGHT, - NULL); - - /* - * Force dimension computation - */ - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->update ( - GNOME_CANVAS_ITEM (etg), NULL, NULL, GNOME_CANVAS_UPDATE_REQUESTED); -#endif -} - -GnomeCanvasItem * -e_table_group_new (GnomeCanvasGroup *parent, ETableCol *ecol, - gboolean open, gboolean transparent) -{ - ETableGroup *etg; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (ecol != NULL, NULL); - - etg = gtk_type_new (e_table_group_get_type ()); - - e_table_group_construct (parent, etg, ecol, open, transparent); - - return GNOME_CANVAS_ITEM (etg); -} - -static void -etg_relayout (GnomeCanvasItem *eti, ETableGroup *etg) -{ - GSList *l; - int height = etg->transparent ? 0 : GROUP_INDENT; - gboolean move = FALSE; - - printf ("Relaying out\n"); - - for (l = etg->children; l->next; l = l->next){ - GnomeCanvasItem *child = l->data; - - height += child->y2 - child->y1; - - if (child == eti) - move = TRUE; - - if (move){ - printf ("Moving item %p\n", child); - gnome_canvas_item_set ( - child, - "y", (double) height, - NULL); - } - } - if (height != etg->height){ - etg->height = height; - gtk_signal_emit (GTK_OBJECT (etg), etg_signals [HEIGHT_CHANGED]); - } -} - -void -e_table_group_add (ETableGroup *etg, GnomeCanvasItem *item) -{ - double x1, y1, x2, y2; - - g_return_if_fail (etg != NULL); - g_return_if_fail (item != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - - etg->children = g_slist_append (etg->children, item); - - GNOME_CANVAS_ITEM_CLASS (GTK_OBJECT (etg)->klass)->bounds (etg, &x1, &y1, &x2, &y2); - - if (GTK_OBJECT (etg)->flags & GNOME_CANVAS_ITEM_REALIZED){ - GSList *l; - int height = etg->transparent ? 0 : TITLE_HEIGHT; - int x = etg->transparent ? 0 : GROUP_INDENT; - - for (l = etg->children; l->next; l = l->next){ - GnomeCanvasItem *child = l->data; - - height += child->y2 - child->y1; - - printf ("Height\n"); - if (E_IS_TABLE_ITEM (item)){ - printf (" Item: "); - } else { - printf (" Group: "); - } - printf ("%d\n", child->y2-child->y1); - } - - gnome_canvas_item_set ( - item, - "y", (double) height, - "x", (double) x, - NULL); - - - if (E_IS_TABLE_ITEM (item)){ - - printf ("Table item! ---------\n"); - gtk_signal_connect (GTK_OBJECT (item), "height_changed", - GTK_SIGNAL_FUNC (etg_relayout), etg); - } - } -} - -static void -etg_realize (GnomeCanvasItem *item) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - GSList *l; - int height = 0; - - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->realize (item); - - for (l = etg->children; l; l = l->next){ - GnomeCanvasItem *child = l->data; - - printf ("During realization for child %p -> %d\n", child, height); - gnome_canvas_item_set ( - child, - "y", (double) height, - NULL); - - height += child->y2 - child->y1; - } -} - -static void -etg_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->update (item, affine, clip_path, flags); - - if (!etg->transparent){ - int current_width, current_height; - - etg_dim (etg, ¤t_width, ¤t_height); - - if ((current_height != etg->height) || (current_width != etg->width)){ - etg->width = current_width; - etg->height = current_height; - - gnome_canvas_item_set ( - etg->rect, - "x1", 0.0, - "y1", 0.0, - "x2", (double) etg->width, - "y2", (double) etg->height, - NULL); - } - } -} - -static void -etg_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - object_class->destroy = etg_destroy; - - item_class->realize = etg_realize; - item_class->update = etg_update; - - etg_parent_class = gtk_type_class (PARENT_TYPE); - - etg_signals [HEIGHT_CHANGED] = - gtk_signal_new ("height_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, height_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, etg_signals, LAST_SIGNAL); - -} - -E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE); - - - diff --git a/widgets/e-table/e-table-group.h b/widgets/e-table/e-table-group.h deleted file mode 100644 index 468d5dd794..0000000000 --- a/widgets/e-table/e-table-group.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -#include -#include "e-table-model.h" -#include "e-table-header.h" - -#define E_TABLE_GROUP_TYPE (e_table_group_get_type ()) -#define E_TABLE_GROUP(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_TYPE, ETableGroup)) -#define E_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_TYPE, ETableGroupClass)) -#define E_IS_TABLE_GROUP(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_TYPE)) -#define E_IS_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_TYPE)) - -typedef struct { - GnomeCanvasGroup group; - - /* - * The ETableCol used to group this set - */ - ETableCol *ecol; - - /* - * The canvas rectangle that contains the children - */ - GnomeCanvasItem *rect; - - /* - * Dimensions of the ETableGroup - */ - int width, height; - - /* - * State: the ETableGroup is open or closed - */ - guint open:1; - - /* - * Whether we should add indentation and open/close markers, - * or if we just act as containers of subtables. - */ - guint transparent:1; - - /* - * List of GnomeCanvasItems we stack - */ - GSList *children; -} ETableGroup; - -typedef struct { - GnomeCanvasGroupClass parent_class; - void (*height_changed) (ETableGroup *etg); -} ETableGroupClass; - -GnomeCanvasItem *e_table_group_new (GnomeCanvasGroup *parent, ETableCol *ecol, - gboolean open, gboolean transparent); -void e_table_group_construct (GnomeCanvasGroup *parent, ETableGroup *etg, - ETableCol *ecol, gboolean open, gboolean transparent); - -void e_table_group_add (ETableGroup *etg, GnomeCanvasItem *child); - -GtkType e_table_group_get_type (void); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c deleted file mode 100644 index e8f73fc432..0000000000 --- a/widgets/e-table/e-table-header-item.c +++ /dev/null @@ -1,795 +0,0 @@ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col-dnd.h" - -#include "add-col.xpm" -#include "remove-col.xpm" - -/* Padding above and below of the string in the header display */ -#define PADDING 4 - -/* Defines the tolerance for proximity of the column division to the cursor position */ -#define TOLERANCE 2 - -#define ETHI_RESIZING(x) ((x)->resize_col != -1) - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *ethi_parent_class; - -/* - * DnD icons - */ -static GdkColormap *dnd_colormap; -static GdkPixmap *remove_col_pixmap, *remove_col_mask; -static GdkPixmap *add_col_pixmap, *add_col_mask; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_X, - ARG_TABLE_Y, - ARG_TABLE_FONTSET -}; - -static GtkTargetEntry ethi_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, -}; - -static GtkTargetEntry ethi_drop_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, -}; - -static void -ethi_destroy (GtkObject *object) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - gtk_object_unref (GTK_OBJECT (ethi->eth)); - - if (GTK_OBJECT_CLASS (ethi_parent_class)->destroy) - (*GTK_OBJECT_CLASS (ethi_parent_class)->destroy) (object); -} - -static void -ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update)(item, affine, clip_path, flags); - - item->x1 = ethi->x1; - item->y1 = ethi->y1; - item->x2 = ethi->x1 + ethi->width; - item->y2 = ethi->y1 + ethi->height; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -ethi_font_load (ETableHeaderItem *ethi, char *font) -{ - if (ethi->font) - gdk_font_unref (ethi->font); - - ethi->font = gdk_fontset_load (font); - if (ethi->font == NULL) - ethi->font = gdk_font_load ("fixed"); - - ethi->height = ethi->font->ascent + ethi->font->descent + PADDING; -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GtkObject *header; - - if (!ethi->eth) - return; - - header = GTK_OBJECT (ethi->eth); - gtk_signal_disconnect (header, ethi->structure_change_id); - gtk_signal_disconnect (header, ethi->dimension_change_id); - - gtk_object_unref (header); - ethi->eth = NULL; - ethi->width = 0; -} - -static void -structure_changed (ETableHeader *header, ETableHeaderItem *ethi) -{ - ethi->width = e_table_header_total_width (header); - - ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi) -{ - ethi->width = e_table_header_total_width (header); - - ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0); -} - -static void -ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header) -{ - ethi->eth = header; - gtk_object_ref (GTK_OBJECT (ethi->eth)); - ethi->width = e_table_header_total_width (header); - - ethi->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), ethi); - ethi->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), ethi); -} - -static void -ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (o); - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_X: - ethi->x1 = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_Y: - ethi->y1 = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_FONTSET: - ethi_font_load (ethi, GTK_VALUE_STRING (*arg)); - break; - - } - ethi_update (item, NULL, NULL, 0); -} - -static int -ethi_find_col_by_x (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = ethi->x1; - int col; - - if (x < x1) - return -1; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) - return col; - - x1 += ecol->width; - } - return -1; -} - -static void -ethi_remove_drop_marker (ETableHeaderItem *ethi) -{ - if (ethi->drag_mark == -1) - return; - - ethi->drag_mark = -1; - gtk_object_destroy (GTK_OBJECT (ethi->drag_mark_item)); - ethi->drag_mark_item = NULL; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, int col) -{ - GnomeCanvasPoints *points; - int x; - - if (ethi->drag_mark == col) - return; - - if (ethi->drag_mark_item) - gtk_object_destroy (GTK_OBJECT (ethi->drag_mark_item)); - - ethi->drag_mark = col; - - ethi->drag_mark_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_group_get_type (), - "x", 0, - "y", 0, - NULL); - - points = gnome_canvas_points_new (3); - - x = e_table_header_col_diff (ethi->eth, 0, col); - - points->coords [0] = ethi->x1 + x - 5; - points->coords [1] = ethi->y1; - points->coords [2] = points->coords [0] + 10; - points->coords [3] = points->coords [1]; - points->coords [4] = ethi->x1 + x; - points->coords [5] = ethi->y1 + 5; - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (ethi->drag_mark_item), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", "red", - NULL); - - points->coords [0] --; - points->coords [1] += ethi->height - 1; - points->coords [3] = points->coords [1]; - points->coords [5] = points->coords [1] - 6; - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (ethi->drag_mark_item), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", "red", - NULL); - - gnome_canvas_points_unref (points); -} - -#define gray50_width 2 -#define gray50_height 2 -static char gray50_bits [] = { - 0x02, 0x01, }; - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - double x1; - - if (ethi->remove_item) - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - - if (!ethi->stipple) - ethi->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - - x1 = ethi->x1 + (double) e_table_header_col_diff (ethi->eth, 0, ethi->drag_col); - ethi->remove_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_rect_get_type (), - "x1", x1 + 1, - "y1", (double) ethi->y1 + 1, - "x2", (double) x1 + e_table_header_col_diff (ethi->eth, ethi->drag_col, ethi->drag_col+1) - 2, - "y2", (double) ethi->y1 + ethi->height - 2, - "fill_color", "red", - "fill_stipple", ethi->stipple, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - ethi->remove_item = NULL; -} - -static gboolean -ethi_drag_motion (GtkObject *canvas, GdkDragContext *context, - gint x, gint y, guint time, - ETableHeaderItem *ethi) -{ - - if ((x >= ethi->x1) && (x <= (ethi->x1 + ethi->width)) && - (y >= ethi->y1) && (y <= (ethi->y1 + ethi->height))){ - int col; - - col = ethi_find_col_by_x (ethi, x); - - if (col != -1){ - ethi_remove_destroy_marker (ethi); - ethi_add_drop_marker (ethi, col); - } else { - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); - } - } else { - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); - } - - gdk_drag_status (context, context->suggested_action, time); - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, GdkDragContext *context, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; -} - -static void -ethi_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); -} - -static void -ethi_realize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GdkWindow *window; - GdkColor c; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - ethi->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (ethi->gc, &c); - - ethi->normal_cursor = gdk_cursor_new (GDK_ARROW); - - if (!ethi->font){ - g_warning ("Font had not been set for this ETableHeader"); - ethi_font_load (ethi, "fixed"); - } - - /* - * Now, configure DnD - */ - gtk_drag_dest_set (GTK_WIDGET (item->canvas), GTK_DEST_DEFAULT_ALL, - ethi_drop_types, ELEMENTS (ethi_drop_types), - GDK_ACTION_MOVE); - - ethi->drag_motion_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_motion", - GTK_SIGNAL_FUNC (ethi_drag_motion), ethi); - - ethi->drag_leave_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_leave", - GTK_SIGNAL_FUNC (ethi_drag_leave), ethi); - - ethi->drag_end_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (ethi_drag_end), ethi); -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - gdk_gc_unref (ethi->gc); - ethi->gc = NULL; - - gdk_cursor_destroy (ethi->normal_cursor); - ethi->normal_cursor = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_motion_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_end_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_leave_id); - - if (ethi->stipple){ - gdk_bitmap_unref (ethi->stipple); - ethi->stipple = NULL; - } - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableHeaderItem *ethi, ETableCol *col, - GdkDrawable *drawable, GdkGC *gc, GtkStyle *style, - int x, int y, int width, int height) -{ - GdkRectangle clip; - int xtra; - - gdk_draw_rectangle ( - drawable, gc, TRUE, - x + 1, y + 1, width - 2, height -2); - - gtk_draw_shadow ( - style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x , y, width, height); - - clip.x = x + 2; - clip.y = y + 2; - clip.width = width - 4; - clip.height = ethi->height; - - gdk_gc_set_clip_rectangle (ethi->gc, &clip); - - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (ethi->font, col->text))/2; - - if (xtra < 0) - xtra = 0; - - /* Skip over border */ - x += xtra + 2; - - gdk_draw_text ( - drawable, ethi->font, - ethi->gc, x, y + ethi->height - PADDING, - col->text, strlen (col->text)); -} - -static void -ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_header_count (ethi->eth); - int x1, x2; - int col; - -#if 0 - printf ("My coords are: %g %g %g %g\n", - item->x1, item->y1, item->x2, item->y2); -#endif - x1 = x2 = ethi->x1; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - int col_width; - - if (col == ethi->resize_col) - col_width = ethi->resize_width; - else - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - gc = GTK_WIDGET (canvas)->style->bg_gc [GTK_STATE_ACTIVE]; - - draw_button (ethi, ecol, drawable, gc, - GTK_WIDGET (canvas)->style, - x1 - x, ethi->y1 - y, col_width, ethi->height); - } -} - -static double -ethi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * is_pointer_on_division: - * - * Returns whether @pos is a column header division; If @the_total is not NULL, - * then the actual position is returned here. If @return_ecol is not NULL, - * then the ETableCol that actually contains this point is returned here - */ -static gboolean -is_pointer_on_division (ETableHeaderItem *ethi, int pos, int *the_total, int *return_col) -{ - const int cols = e_table_header_count (ethi->eth); - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - total += ecol->width; - - if ((total - TOLERANCE < pos ) && (pos < total + TOLERANCE)){ - if (return_col) - *return_col = col; - if (the_total) - *the_total = total; - - return TRUE; - } - - if (total > pos + TOLERANCE) - return FALSE; - } - - return FALSE; -} - -#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y) - -static void -set_cursor (ETableHeaderItem *ethi, int pos) -{ - GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - - /* We might be invoked before we are realized */ - if (!canvas->window) - return; - - if (is_pointer_on_division (ethi, pos, NULL, NULL)) - e_cursor_set (canvas->window, E_CURSOR_SIZE_X); - else - e_cursor_set (canvas->window, E_CURSOR_ARROW); -} - -static void -ethi_request_redraw (ETableHeaderItem *ethi) -{ - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (ethi)->canvas; - - /* - * request a redraw - */ - gnome_canvas_request_redraw ( - canvas, ethi->x1, ethi->y1, ethi->x1 + ethi->width, ethi->x1 + ethi->height); -} - -static void -ethi_end_resize (ETableHeaderItem *ethi, int new_size) -{ - e_table_header_set_size (ethi->eth, ethi->resize_col, new_size); - - ethi->resize_col = -1; - ethi_request_redraw (ethi); -} - -static gboolean -ethi_maybe_start_drag (ETableHeaderItem *ethi, GdkEventMotion *event) -{ - if (!ethi->maybe_drag) - return FALSE; - - if (MAX (abs (ethi->click_x - event->x), - abs (ethi->click_y - event->y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - GtkTargetList *list; - GdkDragContext *context; - - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - if (ethi->drag_col == -1) - return; - - list = gtk_target_list_new (ethi_drag_types, ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - ethi->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static int -ethi_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gboolean resizing = ETHI_RESIZING (ethi); - int x, y, start, col; - - switch (e->type){ - case GDK_ENTER_NOTIFY: - convert (canvas, e->crossing.x, e->crossing.y, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); - break; - - case GDK_MOTION_NOTIFY: - convert (canvas, e->motion.x, e->motion.y, &x, &y); - if (resizing){ - int new_width; - - if (ethi->resize_guide == NULL){ - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - gnome_canvas_item_grab (item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - e_cursor_get (E_CURSOR_SIZE_X), - e->button.time); - } - - new_width = x - ethi->resize_start_pos; - if (new_width <= 0) - break; - - if (new_width < ethi->resize_min_width) - break; - - ethi_request_redraw (ethi); - - ethi->resize_width = new_width; - e_table_header_set_size (ethi->eth, ethi->resize_col, ethi->resize_width); - - ethi_request_redraw (ethi); - } else if (ethi_maybe_start_drag (ethi, &e->motion)){ - ethi_start_drag (ethi, e); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - convert (canvas, e->button.x, e->button.y, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col)){ - ETableCol *ecol; - - /* - * Record the important bits. - * - * By setting resize_pos to a non -1 value, - * we know that we are being resized (used in the - * other event handlers). - */ - ecol = e_table_header_get_column (ethi->eth, col); - - if (!ecol->resizeable) - break; - ethi->resize_col = col; - ethi->resize_width = ecol->width; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - } else { - if (e->button.button == 1){ - ethi->click_x = e->button.x; - ethi->click_y = e->button.y; - ethi->maybe_drag = TRUE; - } - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (e->button.button != 1) - break; - break; - - case GDK_BUTTON_RELEASE: { - gboolean needs_ungrab = FALSE; - - if (ethi->resize_col != -1){ - needs_ungrab = (ethi->resize_guide != NULL); - ethi_end_resize (ethi, ethi->resize_width); - } - if (needs_ungrab) - gnome_canvas_item_ungrab (item, e->button.time); - - ethi->maybe_drag = FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - ethi_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = ethi_destroy; - object_class->set_arg = ethi_set_arg; - - item_class->update = ethi_update; - item_class->realize = ethi_realize; - item_class->unrealize = ethi_unrealize; - item_class->draw = ethi_draw; - item_class->point = ethi_point; - item_class->event = ethi_event; - - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::x", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_TABLE_X); - gtk_object_add_arg_type ("ETableHeaderItem::y", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_TABLE_Y); - gtk_object_add_arg_type ("ETableHeaderItem::fontset", GTK_TYPE_STRING, - GTK_ARG_WRITABLE, ARG_TABLE_FONTSET); - - /* - * Create our pixmaps for DnD - */ - dnd_colormap = gtk_widget_get_default_colormap (); - remove_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &remove_col_mask, NULL, remove_col_xpm); - - add_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &add_col_mask, NULL, add_col_xpm); -} - -static void -ethi_init (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - ethi->resize_col = -1; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - ethi->drag_col = -1; - ethi->drag_mark = -1; -} - -GtkType -e_table_header_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeaderItem", - sizeof (ETableHeaderItem), - sizeof (ETableHeaderItemClass), - (GtkClassInitFunc) ethi_class_init, - (GtkObjectInitFunc) ethi_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/e-table/e-table-header-item.h b/widgets/e-table/e-table-header-item.h deleted file mode 100644 index 5522d24fae..0000000000 --- a/widgets/e-table/e-table-header-item.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include -#include "e-table-header.h" - -#define E_TABLE_HEADER_ITEM_TYPE (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkGC *gc; - GdkCursor *change_cursor, *normal_cursor; - - short x1, y1, height, width; - GdkFont *font; - - /* - * Used during resizing; Could be shorts - */ - int resize_col; - int resize_width; - int resize_start_pos; - int resize_min_width; - - GtkObject *resize_guide; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag:1; - guint dnd_ready:1; - int click_x, click_y; - int drag_col, drag_mark; - guint drag_motion_id, drag_end_id, drag_leave_id; - GnomeCanvasItem *drag_mark_item, *remove_item; - GdkBitmap *stipple; -} ETableHeaderItem; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableHeaderItemClass; - -GtkType e_table_header_item_get_type (void); - -#endif /* _E_TABLE_HEADER_ITEM_H_ */ diff --git a/widgets/e-table/e-table-header.c b/widgets/e-table/e-table-header.c deleted file mode 100644 index 7c54bd936e..0000000000 --- a/widgets/e-table/e-table-header.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * E-table-col-head.c: TableColHead implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include "e-table-header.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint eth_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_header_parent_class; - -static void -e_table_header_destroy (GtkObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const int cols = eth->col_count; - int i; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++){ - e_table_header_remove (eth, i); - } - - if (e_table_header_parent_class->destroy) - e_table_header_parent_class->destroy (object); -} - -static void -e_table_header_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_header_destroy; - - e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ())); - - eth_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - eth_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL); -} - -GtkType -e_table_header_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeader", - sizeof (ETableHeader), - sizeof (ETableHeaderClass), - (GtkClassInitFunc) e_table_header_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -ETableHeader * -e_table_header_new (void) -{ - ETableHeader *eth; - - eth = gtk_type_new (e_table_header_get_type ()); - - return eth; -} - -static void -eth_do_insert (ETableHeader *eth, int pos, ETableCol *val) -{ - memcpy (ð->columns [pos+1], ð->columns [pos], - sizeof (ETableCol *) * (eth->col_count - pos)); - eth->columns [pos] = val; -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - int i; - int x = 0; - - for (i = 0; i < eth->col_count; i++){ - ETableCol *etc = eth->columns [i]; - - etc->x = x; - x += etc->width; - } -} - -void -e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (tc != NULL); - g_return_if_fail (E_IS_TABLE_COL (tc)); - g_return_if_fail (pos >= -1 && pos <= eth->col_count); - - if (pos == -1) - pos = eth->col_count; - eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1)); - - /* - * We are the primary owners of the column - */ - gtk_object_ref (GTK_OBJECT (tc)); - gtk_object_sink (GTK_OBJECT (tc)); - - eth_do_insert (eth, pos, tc); - eth->col_count++; - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -ETableCol * -e_table_header_get_column (ETableHeader *eth, int column) -{ - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - if (column < 0) - return NULL; - - if (column >= eth->col_count) - return NULL; - - return eth->columns [column]; -} - -int -e_table_header_count (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - return eth->col_count; -} - -int -e_table_header_index (ETableHeader *eth, int col) -{ - g_return_val_if_fail (eth != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), -1); - g_return_val_if_fail (col < eth->col_count, -1); - - return eth->columns [col]->col_idx; -} - -int -e_table_header_get_index_at (ETableHeader *eth, int x_offset) -{ - int i, total; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++){ - total += eth->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - ret = g_new (ETableCol *, eth->col_count + 1); - memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count); - ret [eth->col_count] = NULL; - - return ret; -} - -gboolean -e_table_header_selection_ok (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), FALSE); - - return eth->selectable; -} - -int -e_table_header_get_selected (ETableHeader *eth) -{ - int i; - int selected = 0; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - for (i = 0; i < eth->col_count; i++){ - if (eth->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_header_total_width (ETableHeader *eth) -{ - int total, i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++) - total += eth->columns [i]->width; - - return total; -} - -static void -eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref) -{ - if (do_unref) - gtk_object_unref (GTK_OBJECT (eth->columns [idx])); - - memcpy (ð->columns [idx], ð->columns [idx+1], - sizeof (ETableCol *) * eth->col_count - idx); - eth->col_count--; -} - -void -e_table_header_move (ETableHeader *eth, int source_index, int target_index) -{ - ETableCol *old; - - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < eth->col_count); - g_return_if_fail (target_index < eth->col_count); - - old = eth->columns [source_index]; - eth_do_remove (eth, source_index, FALSE); - eth_do_insert (eth, target_index, old); - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -void -e_table_header_remove (ETableHeader *eth, int idx) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - eth_do_remove (eth, idx, TRUE); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -void -e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection) -{ -} - -void -e_table_header_set_size (ETableHeader *eth, int idx, int size) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - g_return_if_fail (size > 0); - - eth->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE], idx); -} - -int -e_table_header_col_diff (ETableHeader *eth, int start_col, int end_col) -{ - int total, col; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - { - const int max_col = eth->col_count; - - total = 0; - for (col = start_col; col < end_col; col++){ - - if (col == max_col) - break; - total += eth->columns [col]->width; - } - } - - return total; -} diff --git a/widgets/e-table/e-table-header.h b/widgets/e-table/e-table-header.h deleted file mode 100644 index 96e65fdc2f..0000000000 --- a/widgets/e-table/e-table-header.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include -#include -#include "e-table-col.h" - -typedef struct _ETableHeader ETableHeader; - -#define E_TABLE_HEADER_TYPE (e_table_header_get_type ()) -#define E_TABLE_HEADER(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_TYPE, ETableHeader)) -#define E_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_TYPE, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_TYPE)) -#define E_IS_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_TYPE)) - -/* - * A Columnar header. - */ -struct _ETableHeader { - GtkObject base; - - int col_count; - ETableCol **columns; - gboolean selectable; -}; - -typedef struct { - GtkObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, int col); -} ETableHeaderClass; - -GtkType e_table_header_get_type (void); -ETableHeader *e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, int pos); -ETableCol * e_table_header_get_column (ETableHeader *eth, - int column); -int e_table_header_count (ETableHeader *eth); -int e_table_header_index (ETableHeader *eth, - int col); -int e_table_header_get_index_at (ETableHeader *eth, - int x_offset); -ETableCol **e_table_header_get_columns (ETableHeader *eth); -gboolean e_table_header_selection_ok (ETableHeader *eth); -int e_table_header_get_selected (ETableHeader *eth); -int e_table_header_total_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - int source_index, - int target_index); -void e_table_header_remove (ETableHeader *eth, int idx); -void e_table_header_set_size (ETableHeader *eth, int idx, int size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); - -int e_table_header_col_diff (ETableHeader *eth, - int start_col, int end_col); - -GList *e_table_header_get_selected_indexes(ETableHeader *eth); - - -#endif /* _E_TABLE_HEADER_H_ */ - diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c deleted file mode 100644 index 8455ed4824..0000000000 --- a/widgets/e-table/e-table-item.c +++ /dev/null @@ -1,1316 +0,0 @@ -/* - * E-table-item.c: A GnomeCanvasItem that is a view of an ETableModel. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - * - * TODO: - * Add a border to the thing, so that focusing works properly. - * - */ -#include -#include -#include -#include -#include -#include "e-table-item.h" -#include "e-cell.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define FOCUSED_BORDER 2 - -static GnomeCanvasItemClass *eti_parent_class; - -enum { - ROW_SELECTION, - HEIGHT_CHANGED, - LAST_SIGNAL -}; - -static gint eti_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_MODEL, - ARG_TABLE_X, - ARG_TABLE_Y, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_MODE_SPREADSHEET, - ARG_LENGHT_THRESHOLD -}; - -static gboolean -eti_editing (ETableItem *eti) -{ - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -/* - * During realization, we have to invoke the per-ecell realize routine - * (On our current setup, we have one e-cell per column. - * - * We might want to optimize this to only realize the unique e-cells: - * ie, a strings-only table, uses the same e-cell for every column, and - * we might want to avoid realizing each e-cell. - */ -static void -eti_realize_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++) - e_cell_view_realize (eti->cell_views [i], eti); - eti->cell_views_realized = 1; -} - -static void eti_compute_height (ETableItem *eti); - -static void -eti_attach_cell_views (ETableItem *eti) -{ - int i; - - g_assert (eti->header); - g_assert (eti->table_model); - - /* - * Now realize the various ECells - */ - eti->n_cells = eti->cols; - eti->cell_views = g_new (ECellView *, eti->n_cells); - - for (i = 0; i < eti->n_cells; i++){ - ETableCol *col = e_table_header_get_column (eti->header, i); - - eti->cell_views [i] = e_cell_new_view (col->ecell, eti->table_model, eti); - } - - eti_compute_height (eti); -} - -/* - * During unrealization: we invoke every e-cell (one per column in the current - * setup) to dispose all X resources allocated - */ -static void -eti_unrealize_cell_views (ETableItem *eti) -{ - int i; - - if (eti->cell_views_realized == 0) - return; - - for (i = 0; i < eti->n_cells; i++) - e_cell_unrealize (eti->cell_views [i]); - eti->cell_views_realized = 0; -} - -static void -eti_detach_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++){ - e_cell_kill_view (eti->cell_views [i]); - eti->cell_views [i] = NULL; - } - - g_free (eti->cell_views); - eti->cell_views = NULL; - eti->n_cells = 0; -} - -static void -eti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - double i2c [6]; - ArtPoint c1, c2, i1, i2; - ETableItem *eti = E_TABLE_ITEM (item); - - gnome_canvas_item_i2c_affine (item, i2c); - i1.x = eti->x1; - i1.y = eti->y1; - i2.x = eti->x1 + eti->width; - i2.y = eti->y1 + eti->height; - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; -} - - -/* - * GnomeCanvasItem::update method - */ -static void -eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, affine, clip_path, flags); - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_model (ETableItem *eti) -{ - if (!eti->table_model) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_change_id); - gtk_object_unref (GTK_OBJECT (eti->table_model)); - - eti->table_model_change_id = 0; - eti->table_model_row_change_id = 0; - eti->table_model = NULL; -} - -/* - * eti_remove_header_model: - * - * Invoked to release the header model associated with this ETableItem - */ -static void -eti_remove_header_model (ETableItem *eti) -{ - if (!eti->header) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_structure_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_dim_change_id); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - gtk_object_unref (GTK_OBJECT (eti->header)); - - - eti->header_structure_change_id = 0; - eti->header_dim_change_id = 0; - eti->header = NULL; -} - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height (ETableItem *eti, int row) -{ - const int cols = e_table_header_count (eti->header); - int col; - int h, max_h; - - g_assert (eti->cell_views); - - max_h = 0; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - h = e_cell_height (eti->cell_views [col], ecol->col_idx, col, row); - - if (h > max_h) - max_h = h; - } - return max_h; -} - -/* - * eti_get_height: - * - * Returns the height of the ETableItem. - * - * The ETableItem might compute the whole height by asking every row its - * size. There is a special mode (designed to work when there are too - * many rows in the table that performing the previous step could take - * too long) set by the ETableItem->length_threshold that would determine - * when the height is computed by using the first row as the size for - * every other row in the ETableItem. - */ -static int -eti_get_height (ETableItem *eti) -{ - const int rows = eti->rows; - int row; - int height; - - if (rows == 0) - return 0; - - if (eti->length_threshold != -1){ - if (rows > eti->length_threshold){ - height = (eti_row_height (eti, 0) + 1) * rows; - - /* - * 1 pixel at the top - */ - return height + 1; - } - } - - height = 1; - for (row = 0; row < rows; row++) - height += eti_row_height (eti, row) + 1; - - return height; -} - -static void -eti_compute_height (ETableItem *eti) -{ - int new_height = eti_get_height (eti); - - if (new_height != eti->height){ - double x1, y1, x2, y2; - printf ("Emitting!\n"); - - eti->height = new_height; - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [HEIGHT_CHANGED]); - } -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ -static void -eti_table_model_changed (ETableModel *table_model, ETableItem *eti) -{ - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->cell_views) - eti_compute_height (eti); - - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); -} - -static void -eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - ArtDRect rect; - double i2c [6]; - - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - gnome_canvas_item_i2c_affine (item, i2c); - art_drect_affine_transform (&rect, &rect, i2c); - - gnome_canvas_request_redraw (item->canvas, rect.x0, rect.y0, rect.x1, rect.y1); -} - -/* - * eti_request_redraw: - * - * Queues a canvas redraw for the entire ETableItem. - */ -static void -eti_request_redraw (ETableItem *eti) -{ - eti_item_region_redraw (eti, eti->x1, eti->y1, eti->x1 + eti->width + 1, eti->y1 + eti->height + 1); -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -static int -eti_row_diff (ETableItem *eti, int start_row, int end_row) -{ - int row, total; - - total = 0; - - for (row = start_row; row < end_row; row++) - total += eti_row_height (eti, row) + 1; - - return total; -} - -/* - * eti_request_region_redraw: - * - * Request a canvas redraw on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to redraw the first cell). - * - * The @border argument is a number of pixels around the region that should also be queued - * for redraw. This is typically used by the focus routines to queue a redraw for the - * border as well. - */ -static void -eti_request_region_redraw (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int border) -{ - int x1, y1, width, height; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - width = e_table_header_col_diff (eti->header, start_col, end_col + 1); - height = eti_row_diff (eti, start_row, end_row + 1); - - eti_item_region_redraw (eti, eti->x1 + x1 - border, - eti->y1 + y1 - border, - eti->x1 + x1 + width + 1 + border, - eti->y1 + y1 + height + 1 + border); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size){ - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols, row, 0); -} - -void -e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int border; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if ((start_col == eti->focused_col) || - (end_col == eti->focused_col) || - (start_row == eti->focused_row) || - (end_row == eti->focused_row)) - border = 2; - else - border = 0; - - eti_request_region_redraw (eti, start_col, start_row, end_col, end_row, border); -} - -static void -eti_add_table_model (ETableItem *eti, ETableModel *table_model) -{ - g_assert (eti->table_model == NULL); - - eti->table_model = table_model; - gtk_object_ref (GTK_OBJECT (eti->table_model)); - - eti->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_changed", - GTK_SIGNAL_FUNC (eti_table_model_changed), eti); - - eti->table_model_row_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_changed", - GTK_SIGNAL_FUNC (eti_table_model_row_changed), eti); - - if (eti->header){ - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - - eti_table_model_changed (table_model, eti); -} - -static void -eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti) -{ - eti_request_redraw (eti); - - eti->width = e_table_header_total_width (eti->header); - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - eti_request_redraw (eti); -} - -static void -eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) -{ - eti_request_redraw (eti); - - eti->cols = e_table_header_count (eti->header); - eti->width = e_table_header_total_width (eti->header); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - eti_realize_cell_views (eti); - } else { - if (eti->table_model){ - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - } - - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - eti_request_redraw (eti); -} - -static void -eti_add_header_model (ETableItem *eti, ETableHeader *header) -{ - g_assert (eti->header == NULL); - - eti->header = header; - gtk_object_ref (GTK_OBJECT (header)); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC (eti_header_dim_changed), eti); - - eti->header_structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC (eti_header_structure_changed), eti); -} - -/* - * GtkObject::destroy method - */ -static void -eti_destroy (GtkObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - - g_slist_free (eti->selection); - - if (GTK_OBJECT_CLASS (eti_parent_class)->destroy) - (*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object); -} - -static void -eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_X: - eti->x1 = GTK_VALUE_DOUBLE (*arg); - break; - - case ARG_TABLE_Y: - eti->y1 = GTK_VALUE_DOUBLE (*arg); - break; - - case ARG_LENGHT_THRESHOLD: - eti->length_threshold = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_DRAW_GRID: - eti->draw_grid = GTK_VALUE_BOOL (*arg); - break; - - case ARG_TABLE_DRAW_FOCUS: - eti->draw_focus = GTK_VALUE_BOOL (*arg); - break; - - case ARG_MODE_SPREADSHEET: - eti->mode_spreadsheet = GTK_VALUE_BOOL (*arg); - break; - } - eti_update (item, NULL, NULL, 0); -} - -static void -eti_init (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - eti->focused_col = -1; - eti->focused_row = -1; - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - - eti->length_threshold = -1; - eti->renderers_can_change_size = 0; - - eti->selection_mode = GTK_SELECTION_SINGLE; -} - -#define gray50_width 2 -#define gray50_height 2 -static const char gray50_bits[] = { - 0x02, 0x01, }; - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - /* - * Gdk Resource allocation - */ - window = canvas_widget->window; - - eti->fill_gc = canvas_widget->style->white_gc; - gdk_gc_ref (canvas_widget->style->white_gc); - - eti->grid_gc = gdk_gc_new (window); -#if 0 - /* This sets it to gray */ -/* gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); */ -#else - gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->black); -#endif - eti->focus_gc = gdk_gc_new (window); - gdk_gc_set_foreground (eti->focus_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); - gdk_gc_set_background (eti->focus_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); - eti->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - gdk_gc_set_ts_origin (eti->focus_gc, 0, 0); - gdk_gc_set_stipple (eti->focus_gc, eti->stipple); - gdk_gc_set_fill (eti->focus_gc, GDK_OPAQUE_STIPPLED); - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - eti_compute_height (eti); - - eti_update (item, NULL, NULL, 0); -} - -static void -eti_unrealize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - gdk_gc_unref (eti->fill_gc); - eti->fill_gc = NULL; - gdk_gc_unref (eti->grid_gc); - eti->grid_gc = NULL; - gdk_gc_unref (eti->focus_gc); - eti->focus_gc = NULL; - gdk_bitmap_unref (eti->stipple); - eti->stipple = NULL; - - eti_unrealize_cell_views (eti); - - eti->height = 0; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); -} - -static void -eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const int rows = eti->rows; - const int cols = eti->cols; - int row, col, y1, y2; - int first_col, last_col, x_offset; - int first_row, last_row, y_offset, yd; - int x1, x2; - int f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - double i2c [6]; - ArtPoint eti_base, eti_base_item; - - /* - * Clear the background - */ -#if 0 - gdk_draw_rectangle ( - drawable, eti->fill_gc, TRUE, - eti->x1 - x, eti->y1 - y, eti->width, eti->height); -#endif - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_affine (item, i2c); - eti_base_item.x = eti->x1; - eti_base_item.y = eti->y1; - art_affine_point (&eti_base, &eti_base_item, i2c); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - last_col = x_offset = 0; - x1 = x2 = floor (eti_base.x); - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - x2 = x1 + ecol->width; - - if (x1 > (x + width)) - break; - if (x2 < x) - continue; - if (first_col == -1){ - x_offset = x1 - x; - first_col = col; - } - } - last_col = col; - - /* - * Nothing to paint - */ - if (first_col == -1) - return; - - /* - * Compute row span. - */ - first_row = -1; - y_offset = 0; - y1 = y2 = floor (eti_base.y) + 1; - for (row = 0; row < rows; row++, y1 = y2){ - - y2 += eti_row_height (eti, row) + 1; - - if (y1 > y + height) - break; - - if (y2 < y) - continue; - - if (first_row == -1){ - y_offset = y1 - y; - first_row = row; - } - } - last_row = row; - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->draw_grid && first_row == 0){ - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - } - yd++; - - for (row = first_row; row < last_row; row++){ - int xd, height; - gboolean selected; - - height = eti_row_height (eti, row); - - xd = x_offset; -/* printf ("paint: %d %d\n", yd, yd + height); */ - - selected = g_slist_find (eti->selection, GINT_TO_POINTER (row)) != NULL; - - for (col = first_col; col < last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - ECellView *ecell_view = eti->cell_views [col]; - - e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, selected, - xd, yd, xd + ecol->width, yd + height); - - if (col == eti->focused_col && row == eti->focused_row){ - f_x1 = xd; - f_x2 = xd + ecol->width; - f_y1 = yd; - f_y2 = yd + height; - f_found = TRUE; - } - - xd += ecol->width; - } - yd += height; - - if (eti->draw_grid) - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - yd++; - } - - if (eti->draw_grid){ - int xd = x_offset; - - for (col = first_col; col <= last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - gdk_draw_line ( - drawable, eti->grid_gc, - xd, y_offset, xd, yd - 1); - - /* - * This looks wierd, but it is to draw the last line - */ - if (ecol) - xd += ecol->width; - } - } - - /* - * Draw focus - */ - if (f_found && eti->draw_focus){ - - if (!eti_editing (eti)) - gdk_draw_rectangle ( - drawable, eti->focus_gc, FALSE, - f_x1 + 1, f_y1, f_x2 - f_x1 - 2, f_y2 - f_y1 - 1); - } -} - -static double -eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - - return 0.0; -} - -static gboolean -find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, double *x1_res, double *y1_res) -{ - const int cols = eti->cols; - const int rows = eti->rows; - gdouble x1, y1, x2, y2; - int col, row; - - /* FIXME: this routine is inneficient, fix later */ - - x -= eti->x1; - y -= eti->y1; - - x1 = 0; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - if (x < x1) - return FALSE; - - x2 = x1 + ecol->width; - - if (x > x2) - continue; - - *col_res = col; - if (x1_res) - *x1_res = x - x1; - break; - } - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2){ - if (y < y1) - return FALSE; - - y2 += eti_row_height (eti, row) + 1; - - if (y > y2) - continue; - - *row_res = row; - if (y1_res) - *y1_res = y - y1; - break; - } - - return TRUE; -} - -static void -eti_cursor_move_left (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col - 1, eti->focused_row); -} - -static void -eti_cursor_move_right (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col + 1, eti->focused_row); -} - -static void -eti_cursor_move_up (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col, eti->focused_row - 1); -} - -static void -eti_cursor_move_down (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col, eti->focused_row + 1); -} - -static int -eti_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - ETableCol *ecol; - - switch (e->type){ - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: { - double x1, y1; - int col, row; - - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - if (eti->focused_row == row && eti->focused_col == col){ - - ecol = e_table_header_get_column (eti->header, col); - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, ecol->col_idx, col, row); - } else { - /* - * Focus the cell, and select the row - */ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, col, row); - e_table_item_select_row (eti, row); - } - break; - } - - case GDK_MOTION_NOTIFY: { - int col, row; - double x1, y1; - - gnome_canvas_item_w2i (item, &e->motion.x, &e->motion.y); - - if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1)) - return TRUE; - - if (eti->focused_row == row && eti->focused_col == col){ - ecol = e_table_header_get_column (eti->header, col); - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->motion.x = x1; - e->motion.y = y1; - - e_cell_event (ecell_view, e, ecol->col_idx, col, row); - } - break; - } - - case GDK_KEY_PRESS: - if (eti->focused_col == -1) - return FALSE; - - switch (e->key.keyval){ - case GDK_Left: - if (!eti->mode_spreadsheet && eti_editing (eti)) - break; - - if (eti->focused_col > 0) - eti_cursor_move_left (eti); - - return TRUE; - - case GDK_Right: - if (!eti->mode_spreadsheet && eti_editing (eti)) - break; - - if ((eti->focused_col + 1) < eti->cols) - eti_cursor_move_right (eti); - return TRUE; - - case GDK_Up: - if (eti->focused_row > 0) - eti_cursor_move_up (eti); - return TRUE; - - case GDK_Down: - if ((eti->focused_row + 1) < eti->rows) - eti_cursor_move_down (eti); - - return TRUE; - - case GDK_Tab: - if ((e->key.state & GDK_SHIFT_MASK) != 0){ - /* shift tab */ - if (eti->focused_col > 0) - eti_cursor_move_left (eti); - else if (eti->focused_row > 0){ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->cols - 1, eti->focused_row - 1); - } else { - /* FIXME: request focus leave backward */ - } - } else { - if ((eti->focused_col + 1) < eti->cols) - eti_cursor_move_right (eti); - else if ((eti->focused_row + 1) < eti->rows){ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, 0, eti->rows - 1); - } else { - /* FIXME: request focus leave forward */ - } - } - break; - - default: - if (!eti_editing (eti)){ - if ((e->key.state & (GDK_MOD1_MASK | GDK_CONTROL_MASK)) != 0) - return 0; - - if (!(e->key.keyval >= 0x20 && e->key.keyval <= 0xff)) - return 0; - } - } - - ecol = e_table_header_get_column (eti->header, eti->focused_col); - ecell_view = eti->cell_views [eti->focused_col]; - e_cell_event (ecell_view, e, ecol->col_idx, eti->focused_col, eti->focused_row); - break; - - case GDK_KEY_RELEASE: - if (eti->focused_col == -1) - return FALSE; - - if (eti_editing (eti)){ - ecell_view = eti->cell_views [eti->editing_col]; - ecol = e_table_header_get_column (eti->header, eti->editing_col); - e_cell_event (ecell_view, e, ecol->col_idx, eti->editing_col, eti->editing_row); - } - break; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ETableItem::row_selection method - */ -static void -eti_row_selection (ETableItem *eti, int row, gboolean selected) -{ - eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0); - - if (selected) - eti->selection = g_slist_prepend (eti->selection, GINT_TO_POINTER (row)); - else - eti->selection = g_slist_remove (eti->selection, GINT_TO_POINTER (row)); - -} - -static void -eti_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableItemClass *eti_class = (ETableItemClass *) object_class; - - eti_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = eti_destroy; - object_class->set_arg = eti_set_arg; - - item_class->update = eti_update; - item_class->realize = eti_realize; - item_class->unrealize = eti_unrealize; - item_class->draw = eti_draw; - item_class->point = eti_point; - item_class->event = eti_event; - item_class->bounds = eti_bounds; - - eti_class->row_selection = eti_row_selection; - - gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_MODEL); - gtk_object_add_arg_type ("ETableItem::x", GTK_TYPE_DOUBLE, - GTK_ARG_WRITABLE, ARG_TABLE_X); - gtk_object_add_arg_type ("ETableItem::y", GTK_TYPE_DOUBLE, - GTK_ARG_WRITABLE, ARG_TABLE_Y); - gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableItem::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableItem::spreadsheet", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_MODE_SPREADSHEET); - - eti_signals [ROW_SELECTION] = - gtk_signal_new ("row_selection", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, row_selection), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - eti_signals [HEIGHT_CHANGED] = - gtk_signal_new ("height_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, height_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, eti_signals, LAST_SIGNAL); - -} - -GtkType -e_table_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableItem", - sizeof (ETableItem), - sizeof (ETableItemClass), - (GtkClassInitFunc) eti_class_init, - (GtkObjectInitFunc) eti_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_item_focus (ETableItem *eti, int col, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti->focused_col != -1) - e_table_item_unfocus (eti); - - eti->focused_col = col; - eti->focused_row = row; - - eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER); - - /* - * make sure we have the Gtk Focus - */ - gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti)); -} - -void -e_table_item_unfocus (ETableItem *eti) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti->focused_row == -1) - return; - - { - const int col = eti->focused_col; - const int row = eti->focused_row; - - eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER); - } - eti->focused_col = -1; - eti->focused_row = -1; -} - -const GSList * -e_table_item_get_selection (ETableItem *eti) -{ - g_return_val_if_fail (eti != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), NULL); - - return eti->selection; -} - -GtkSelectionMode -e_table_item_get_selection_mode (ETableItem *eti) -{ - g_return_val_if_fail (eti != NULL, GTK_SELECTION_SINGLE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), GTK_SELECTION_SINGLE); - - return eti->selection_mode; -} - -void -e_table_item_set_selection_mode (ETableItem *eti, GtkSelectionMode selection_mode) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (selection_mode == GTK_SELECTION_BROWSE || - selection_mode == GTK_SELECTION_EXTENDED){ - g_error ("GTK_SELECTION_BROWSE and GTK_SELECTION_EXTENDED are not implemented"); - } - - eti->selection_mode = selection_mode; -} - -gboolean -e_table_item_is_row_selected (ETableItem *eti, int row) -{ - g_return_val_if_fail (eti != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), FALSE); - - if (g_slist_find (eti->selection, GINT_TO_POINTER (row))) - return TRUE; - else - return FALSE; -} - -void -e_table_item_unselect_row (ETableItem *eti, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (e_table_item_is_row_selected (eti, row)){ - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - row, 0); - } -} - -void -e_table_item_select_row (ETableItem *eti, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - switch (eti->selection_mode){ - case GTK_SELECTION_SINGLE: - if (eti->selection){ - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GPOINTER_TO_INT (eti->selection->data), 0); - } - g_slist_free (eti->selection); - eti->selection = NULL; - - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GINT_TO_POINTER (row), 1); - break; - - case GTK_SELECTION_MULTIPLE: - if (g_slist_find (eti->selection, GINT_TO_POINTER (row))) - return; - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GINT_TO_POINTER (row), 1); - break; - - default: - - } -} - -void -e_table_item_enter_edit (ETableItem *eti, int col, int row) -{ - ETableCol *ecol; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - eti->editing_col = col; - eti->editing_row = row; - - ecol = e_table_header_get_column (eti->header, col); - eti->edit_ctx = e_cell_enter_edit (eti->cell_views [col], ecol->col_idx, col, row); -} - -void -e_table_item_leave_edit (ETableItem *eti) -{ - ETableCol *ecol; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (!eti_editing (eti)) - return; - - ecol = e_table_header_get_column (eti->header, eti->editing_col); - e_cell_leave_edit ( - eti->cell_views [eti->editing_col], - ecol->col_idx, eti->editing_col, - eti->editing_row, eti->edit_ctx); - eti->editing_col = -1; - eti->editing_row = -1; - eti->edit_ctx = NULL; -} - diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h deleted file mode 100644 index f19819f2fc..0000000000 --- a/widgets/e-table/e-table-item.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include -#include "e-table-model.h" -#include "e-table-header.h" - -#define E_TABLE_ITEM_TYPE (e_table_item_get_type ()) -#define E_TABLE_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_ITEM_TYPE, ETableItem)) -#define E_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ITEM_TYPE, ETableItemClass)) -#define E_IS_TABLE_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_ITEM_TYPE)) -#define E_IS_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - int x1, y1; - int width, height; - - int cols, rows; - - /* - * Ids for the signals we connect to - */ - int header_dim_change_id; - int header_structure_change_id; - int table_model_change_id; - int table_model_row_change_id; - - GdkGC *fill_gc; - GdkGC *grid_gc; - GdkGC *focus_gc; - GdkBitmap *stipple; - - unsigned int draw_grid:1; - unsigned int draw_focus:1; - unsigned int mode_spreadsheet:1; - unsigned int renderers_can_change_size:1; - unsigned int cell_views_realized:1; - - int focused_col, focused_row; - - /* - * Realized views, per column - */ - ECellView **cell_views; - int n_cells; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - int length_threshold; - - GSList *selection; - GtkSelectionMode selection_mode; - - /* - * During edition - */ - int editing_col, editing_row; - void *edit_ctx; -} ETableItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - void (*row_selection) (ETableItem *eti, int row, gboolean selected); - void (*height_changed) (ETableItem *eti); -} ETableItemClass; - -GtkType e_table_item_get_type (void); - -/* - * Focus - */ -void e_table_item_focus (ETableItem *eti, int col, int row); -void e_table_item_unfocus (ETableItem *eti); - -/* - * Selection - */ -void e_table_item_select_row (ETableItem *e_table_Item, int row); -void e_table_item_unselect_row (ETableItem *e_table_Item, int row); - -/* - * Handling the selection - */ -const GSList*e_table_item_get_selection (ETableItem *e_table_Item); - -GtkSelectionMode e_table_item_get_selection_mode (ETableItem *e_table_Item); -void e_table_item_set_selection_mode (ETableItem *e_table_Item, - GtkSelectionMode selection_mode); -gboolean e_table_item_is_row_selected (ETableItem *e_table_Item, - int row); - -void e_table_item_leave_edit (ETableItem *eti); -void e_table_item_enter_edit (ETableItem *eti, int col, int row); - -void e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/e-table/e-table-model.c b/widgets/e-table/e-table-model.c deleted file mode 100644 index 9e397710ef..0000000000 --- a/widgets/e-table/e-table-model.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * e-table-model.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include "e-table-model.h" - -#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass) - -static GtkObjectClass *e_table_model_parent_class; - -enum { - MODEL_CHANGED, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint e_table_model_signals [LAST_SIGNAL] = { 0, }; - -int -e_table_model_column_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->column_count (e_table_model); -} - - -int -e_table_model_row_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->row_count (e_table_model); -} - -void * -e_table_model_value_at (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - return ETM_CLASS (e_table_model)->value_at (e_table_model, col, row); -} - -void -e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - ETM_CLASS (e_table_model)->set_value_at (e_table_model, col, row, data); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); - - /* - * Notice that "model_changed" is not emitted - */ -} - -gboolean -e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - return ETM_CLASS (e_table_model)->is_cell_editable (e_table_model, col, row); -} - -static void -e_table_model_destroy (GtkObject *object) -{ - if (e_table_model_parent_class->destroy) - (*e_table_model_parent_class->destroy)(object); -} - -static void -e_table_model_class_init (GtkObjectClass *object_class) -{ - e_table_model_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class->destroy = e_table_model_destroy; - - e_table_model_signals [MODEL_CHANGED] = - gtk_signal_new ("model_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_ROW_CHANGED] = - gtk_signal_new ("model_row_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_CELL_CHANGED] = - gtk_signal_new ("model_cell_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_cell_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); -} - -GtkType -e_table_model_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableModel", - sizeof (ETableModel), - sizeof (ETableModelClass), - (GtkClassInitFunc) e_table_model_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -void -e_table_model_changed (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CHANGED]); -} - -void -e_table_model_row_changed (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); -} - -void -e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); -} - - diff --git a/widgets/e-table/e-table-model.h b/widgets/e-table/e-table-model.h deleted file mode 100644 index 2d08f3744e..0000000000 --- a/widgets/e-table/e-table-model.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include - -#define E_TABLE_MODEL_TYPE (e_table_model_get_type ()) -#define E_TABLE_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_MODEL_TYPE, ETableModel)) -#define E_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MODEL_TYPE, ETableModelClass)) -#define E_IS_TABLE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_MODEL_TYPE)) -#define E_IS_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MODEL_TYPE)) - -typedef struct { - GtkObject base; -} ETableModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Virtual methods - */ - int (*column_count) (ETableModel *etm); - int (*row_count) (ETableModel *etm); - void *(*value_at) (ETableModel *etm, int col, int row); - void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); - gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - - /* - * Signals - */ - - /* - * Major structural changes: model_changed - * Changes only in a row: row_changed - * Only changes in a cell: cell_changed - */ - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, int row); - void (*model_cell_changed) (ETableModel *etm, int col, int row); -} ETableModelClass; - -GtkType e_table_model_get_type (void); - -int e_table_model_column_count (ETableModel *e_table_model); -const char *e_table_model_column_name (ETableModel *e_table_model, int col); -int e_table_model_row_count (ETableModel *e_table_model); -void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); -void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, int row); -void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row); - -#endif /* _E_TABLE_MODEL_H_ */ diff --git a/widgets/e-table/e-table-render.c b/widgets/e-table/e-table-render.c deleted file mode 100644 index 49d742132b..0000000000 --- a/widgets/e-table/e-table-render.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * E-table-render.c: Various renderers - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col.h" -#include "e-table-render.h" - -void -e_table_render_string (ERenderContext *ctxt) -{ - printf ("Rendering string: %s\n", ctxt->render_data); -} - diff --git a/widgets/e-table/e-table-render.h b/widgets/e-table/e-table-render.h deleted file mode 100644 index ebc65968f0..0000000000 --- a/widgets/e-table/e-table-render.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef E_TABLE_RENDER_H -#define E_TABLE_RENDER_H - -#include - -struct ERenderContext { - ETableCol *etc; - int row; - int base_x, base_y; - GnomeCanvasItem *gnome_canvas_item; - GdkDrawable *drawable; - int drawable_width; - int drawable_height; - void *render_data; - void *closure; -}; - -void e_table_render_string (ERenderContext *ctxt); - - -#endif diff --git a/widgets/e-table/e-table-simple.c b/widgets/e-table/e-table-simple.c deleted file mode 100644 index 38e1dd8eb0..0000000000 --- a/widgets/e-table/e-table-simple.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * e-table-model.c: a simple table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include -#include "e-table-simple.h" - -#define PARENT_TYPE e_table_model_get_type() - -static int -simple_column_count (ETableModel *etm) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->col_count (etm, simple->data); -} - -static int -simple_row_count (ETableModel *etm) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->row_count (etm, simple->data); -} - -static void * -simple_value_at (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->value_at (etm, col, row, simple->data); -} - -static void -simple_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSimple *simple = (ETableSimple *)etm; - - simple->set_value_at (etm, col, row, val, simple->data); -} - -static gboolean -simple_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->is_cell_editable (etm, col, row, simple->data); -} - -static void -e_table_simple_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - model_class->column_count = simple_column_count; - model_class->row_count = simple_row_count; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_cell_editable = simple_is_cell_editable; -} - -GtkType -e_table_simple_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableSimple", - sizeof (ETableSimple), - sizeof (ETableSimpleClass), - (GtkClassInitFunc) e_table_simple_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - void *data) -{ - ETableSimple *et; - - et = gtk_type_new (e_table_simple_get_type ()); - - et->col_count = col_count; - et->row_count = row_count; - et->value_at = value_at; - et->set_value_at = set_value_at; - et->is_cell_editable = is_cell_editable; - et->data = data; - - return (ETableModel *) et; -} diff --git a/widgets/e-table/e-table-simple.h b/widgets/e-table/e-table-simple.h deleted file mode 100644 index d890245386..0000000000 --- a/widgets/e-table/e-table-simple.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _E_TABLE_SIMPLE_H_ -#define _E_TABLE_SIMPLE_H_ - -#include "e-table-model.h" - -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); - -typedef struct { - ETableModel parent; - - ETableSimpleColumnCountFn col_count; - ETableSimpleRowCountFn row_count; - ETableSimpleValueAtFn value_at; - ETableSimpleSetValueAtFn set_value_at; - ETableSimpleIsCellEditableFn is_cell_editable; - void *data; -} ETableSimple; - -typedef struct { - ETableModelClass parent_class; -} ETableSimpleClass; - -GtkType e_table_simple_get_type (void); - -ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - void *data); - -#endif /* _E_TABLE_SIMPLE_H_ */ - diff --git a/widgets/e-table/e-table-sorted.c b/widgets/e-table/e-table-sorted.c deleted file mode 100644 index 16644a45b1..0000000000 --- a/widgets/e-table/e-table-sorted.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include "e-util/e-util.h" -#include "e-table-sorted.h" - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -static ETableModelClass *ets_parent_class; - -static void -ets_class_init (GtkObjectClass *klass) -{ - ets_parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_table_sorted, "ETableSorted", ETableSorted, ets_class_init, NULL, PARENT_TYPE); - -static ETableSorted *sort_ets; - -static int -my_sort (const void *a, const void *b) -{ - ETableModel *source = E_TABLE_SUBSET (sort_ets)->source; - const int *ia = (const int *) a; - const int *ib = (const int *) b; - void *va, *vb; - - va = e_table_model_value_at (source, sort_ets->sort_col, *ia); - vb = e_table_model_value_at (source, sort_ets->sort_col, *ib); - - return (*sort_ets->compare) (va, vb); -} - -static void -do_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - g_assert (sort_ets == NULL); - - sort_ets = ets; - qsort (etss->map_table, etss->n_map, sizeof (unsigned int), my_sort); - sort_ets = NULL; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, int col, GCompareFunc compare) -{ - ETableSorted *ets = gtk_type_new (E_TABLE_SORTED_TYPE); - ETableSubset *etss = E_TABLE_SUBSET (ets); - const int nvals = e_table_model_row_count (source); - int i; - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (ets)); - return NULL; - } - - ets->compare = compare; - ets->sort_col = col; - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - do_sort (ets); - - return (ETableModel *) ets; -} - -void -e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare) -{ - if (col == -1 || compare == NULL) - do_sort (ets); - else { - ets->sort_col = col; - ets->compare = compare; - do_sort (ets); - } -} - diff --git a/widgets/e-table/e-table-sorted.h b/widgets/e-table/e-table-sorted.h deleted file mode 100644 index 2ec52df2e7..0000000000 --- a/widgets/e-table/e-table-sorted.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include -#include "e-table-model.h" -#include "e-table-subset.h" - -#define E_TABLE_SORTED_TYPE (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_TYPE, ETableSorted)) -#define E_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_TYPE, ETableSortedClass)) -#define E_IS_TABLE_SORTED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_TYPE)) -#define E_IS_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_TYPE)) - -typedef struct { - ETableSubset base; - - short sort_col; - GCompareFunc compare; -} ETableSorted; - -typedef struct { - ETableSubset parent_class; -} ETableSortedClass; - -GtkType e_table_sorted_get_type (void); -ETableModel *e_table_sorted_new (ETableModel *etm, int col, GCompareFunc compare); -void e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare); - -#endif /* _E_TABLE_SORTED_H_ */ diff --git a/widgets/e-table/e-table-subset.c b/widgets/e-table/e-table-subset.c deleted file mode 100644 index a9e4a5c5a4..0000000000 --- a/widgets/e-table/e-table-subset.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include -#include "e-util/e-util.h" -#include "e-table-subset.h" - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModelClass *etss_parent_class; - -static void -etss_destroy (GtkObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) - gtk_object_unref (GTK_OBJECT (etss->source)); - - if (etss->map_table) - free (etss->map_table); - - GTK_OBJECT_CLASS (etss_parent_class)->destroy (object); -} - -static int -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_column_count (etss->source); -} - -static int -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return etss->n_map; -} - -static void * -etss_value_at (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_at (etss->source, col, etss->map_table [row]); -} - -static void -etss_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_set_value_at (etss->source, col, etss->map_table [row], val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_is_cell_editable (etss->source, col, etss->map_table [row]); -} - -static void -etss_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - - etss_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etss_destroy; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->value_at = etss_value_at; - table_class->set_value_at = etss_set_value_at; - table_class->is_cell_editable = etss_is_cell_editable; -} - -E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, NULL, PARENT_TYPE); - -static void -etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - return; - } - } -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - return; - } - } -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals) -{ - unsigned int *buffer; - int i; - - buffer = (unsigned int *) malloc (sizeof (unsigned int) * nvals); - if (buffer == NULL) - return NULL; - etss->map_table = buffer; - etss->n_map = nvals; - etss->source = source; - gtk_object_ref (GTK_OBJECT (source)); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss); - gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_row_changed), etss); - gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_cell_changed), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, const int nvals) -{ - ETableSubset *etss = gtk_type_new (E_TABLE_SUBSET_TYPE); - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (etss)); - return NULL; - } - - return (ETableModel *) etss; -} - -ETableModel * -e_table_subset_get_toplevel (ETableSubset *table) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SUBSET (table), NULL); - - if (E_IS_TABLE_SUBSET (table->source)) - return e_table_subset_get_toplevel (E_TABLE_SUBSET (table->source)); - else - return table->source; -} diff --git a/widgets/e-table/e-table-subset.h b/widgets/e-table/e-table-subset.h deleted file mode 100644 index 314f28aea6..0000000000 --- a/widgets/e-table/e-table-subset.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include -#include "e-table-model.h" - -#define E_TABLE_SUBSET_TYPE (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_TYPE, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_TYPE, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_TYPE)) -#define E_IS_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_TYPE)) - -typedef struct { - ETableModel base; - - ETableModel *source; - int n_map; - int *map_table; -} ETableSubset; - -typedef struct { - ETableModelClass parent_class; -} ETableSubsetClass; - -GtkType e_table_subset_get_type (void); -ETableModel *e_table_subset_new (ETableModel *etm, int n_vals); -ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals); - -ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model); - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/e-table/e-table-tree.h b/widgets/e-table/e-table-tree.h deleted file mode 100644 index e7e125a6af..0000000000 --- a/widgets/e-table/e-table-tree.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -typedef struct { - char *title; - - union { - ETableModel *table; - GList *children; - } u; - - guint expanded :1; - guint is_leaf :1; -} ETableGroup; - -ETableGroup *e_table_group_new (const char *title, ETableModel *table); -ETableGroup *e_table_group_new_leaf (const char *title); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/e-table/e-table.c b/widgets/e-table/e-table.c deleted file mode 100644 index efda8931d2..0000000000 --- a/widgets/e-table/e-table.c +++ /dev/null @@ -1,564 +0,0 @@ -/* - * E-table-view.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include "e-util/e-util.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" - -#define COLUMN_HEADER_HEIGHT 16 -#define TITLE_HEIGHT 16 -#define GROUP_INDENT 10 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *e_table_parent_class; - -static void -et_destroy (GtkObject *object) -{ - ETable *et = E_TABLE (object); - - gtk_object_unref (GTK_OBJECT (et->model)); - gtk_object_unref (GTK_OBJECT (et->full_header)); - gtk_object_unref (GTK_OBJECT (et->header)); - - g_free (et->group_spec); - - (*e_table_parent_class->destroy)(object); -} - -static void -e_table_init (GtkObject *object) -{ - ETable *e_table = E_TABLE (object); - - e_table->draw_grid = 1; - e_table->draw_focus = 1; - e_table->spreadsheet = 1; -} - -static ETableHeader * -e_table_make_header (ETable *e_table, ETableHeader *full_header, const char *cols) -{ - ETableHeader *nh; - char *copy = alloca (strlen (cols) + 1); - char *p, *state; - const int max_cols = e_table_header_count (full_header); - - nh = e_table_header_new (); - strcpy (copy, cols); - while ((p = strtok_r (copy, ",", &state)) != NULL){ - int col = atoi (p); - - copy = NULL; - if (col >= max_cols) - continue; - - e_table_header_add_column (nh, e_table_header_get_column (full_header, col), -1); - } - - return nh; -} - -static void -header_canvas_size_alocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, alloc->width, COLUMN_HEADER_HEIGHT); -} - -static void -e_table_setup_header (ETable *e_table) -{ - e_table->header_canvas = GNOME_CANVAS (gnome_canvas_new ()); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - e_table->header_item = gnome_canvas_item_new ( - gnome_canvas_root (e_table->header_canvas), - e_table_header_item_get_type (), - "ETableHeader", e_table->header, - "x", 0, - "y", 0, - NULL); - - gtk_signal_connect ( - GTK_OBJECT (e_table->header_canvas), "size_allocate", - GTK_SIGNAL_FUNC (header_canvas_size_alocate), e_table); - - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, COLUMN_HEADER_HEIGHT); - - gtk_table_attach ( - GTK_TABLE (e_table), GTK_WIDGET (e_table->header_canvas), - 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); - -} - -typedef struct { - void *value; - GArray *array; -} group_key_t; - -static GArray * -e_table_create_groups (ETableModel *etm, int key_col, GCompareFunc comp) -{ - GArray *groups; - const int rows = e_table_model_row_count (etm); - int row, i; - - groups = g_array_new (FALSE, FALSE, sizeof (group_key_t)); - - for (row = 0; row < rows; row++){ - void *val = e_table_model_value_at (etm, key_col, row); - const int n_groups = groups->len; - - /* - * Should replace this with a bsearch later - */ - for (i = 0; i < n_groups; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - - if ((*comp) (g->value, val)){ - g_array_append_val (g->array, row); - break; - } - } - if (i != n_groups) - continue; - - /* - * We need to create a new group - */ - { - group_key_t gk; - - gk.value = val; - gk.array = g_array_new (FALSE, FALSE, sizeof (int)); - - g_array_append_val (gk.array, row); - g_array_append_val (groups, gk); - } - } - - return groups; -} - -static void -e_table_destroy_groups (GArray *groups) -{ - const int n = groups->len; - int i; - - for (i = 0; i < n; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - - g_array_free (g->array, TRUE); - } - g_array_free (groups, TRUE); -} - -static ETableModel ** -e_table_make_subtables (ETableModel *model, GArray *groups) -{ - const int n_groups = groups->len; - ETableModel **tables; - int i; - - tables = g_new (ETableModel *, n_groups+1); - - for (i = 0; i < n_groups; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - const int sub_size = g->array->len; - ETableSubset *ss; - int j; - - tables [i] = e_table_subset_new (model, sub_size); - ss = E_TABLE_SUBSET (tables [i]); - - for (j = 0; j < sub_size; j++) - ss->map_table [j] = g_array_index (g->array, int, j); - } - tables [i] = NULL; - - return (ETableModel **) tables; -} - -typedef struct _Node Node; - -struct _Node { - Node *parent; - GnomeCanvasItem *item; - ETableModel *table_model; - GSList *children; - - guint is_leaf:1; -}; - -static Node * -leaf_new (GnomeCanvasItem *table_item, ETableModel *table_model, Node *parent) -{ - Node *node = g_new (Node, 1); - - g_assert (table_item != NULL); - g_assert (table_model != NULL); - g_assert (parent != NULL); - - node->item = table_item; - node->parent = parent; - node->table_model = table_model; - node->is_leaf = 1; - - g_assert (!parent->is_leaf); - - parent->children = g_slist_append (parent->children, node); - - e_table_group_add (E_TABLE_GROUP (parent->item), table_item); - - return node; -} - -static Node * -node_new (GnomeCanvasItem *group_item, ETableModel *table_model, Node *parent) -{ - Node *node = g_new (Node, 1); - - g_assert (table_model != NULL); - - node->children = NULL; - node->item = group_item; - node->parent = parent; - node->table_model = table_model; - node->is_leaf = 0; - - if (parent){ - parent->children = g_slist_append (parent->children, node); - - e_table_group_add (E_TABLE_GROUP (parent->item), group_item); - } - - return node; -} - -static Node * -e_table_create_leaf (ETable *e_table, ETableModel *etm, Node *parent) -{ - GnomeCanvasItem *table_item; - Node *leaf; - - table_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (parent->item), - e_table_item_get_type (), - "ETableHeader", e_table->header, - "ETableModel", etm, - "drawgrid", e_table->draw_grid, - "drawfocus", e_table->draw_focus, - "spreadsheet", e_table->spreadsheet, - NULL); - - leaf = leaf_new (table_item, etm, parent); - - return leaf; -} - -static int -leaf_height (Node *leaf) -{ - const GnomeCanvasItem *item = leaf->item; - - return item->y2 - item->y1; -} - -static int -leaf_event (GnomeCanvasItem *item, GdkEvent *event) -{ - static int last_x = -1; - static int last_y = -1; - - if (event->type == GDK_BUTTON_PRESS){ - last_x = event->button.x; - last_y = event->button.y; - } else if (event->type == GDK_BUTTON_RELEASE){ - last_x = -1; - last_y = -1; - } else if (event->type == GDK_MOTION_NOTIFY){ - if (last_x == -1) - return FALSE; - - gnome_canvas_item_move (item, event->motion.x - last_x, event->motion.y - last_y); - last_x = event->motion.x; - last_y = event->motion.y; - } else - return FALSE; - return TRUE; -} - -static Node * -e_table_create_nodes (ETable *e_table, ETableModel *model, ETableHeader *header, - GnomeCanvasGroup *root, Node *parent, int *groups_list) -{ - GArray *groups; - ETableModel **tables; - ETableCol *ecol; - int key_col, i; - GnomeCanvasItem *group_item; - Node *group; - - key_col = *groups_list; - g_assert (key_col != -1); - - /* - * Create groups - */ - ecol = e_table_header_get_column (header, key_col); - - g_assert (ecol != NULL); - - groups = e_table_create_groups (model, key_col, ecol->compare); - tables = e_table_make_subtables (e_table->model, groups); - e_table_destroy_groups (groups); - - group_item = e_table_group_new (root, ecol, TRUE, parent == NULL); - group = node_new (group_item, model, parent); - - for (i = 0; tables [i] != NULL; i++){ - /* - * Leafs - */ - if (groups_list [1] == -1){ - GnomeCanvasItem *item_leaf_header; - Node *leaf_header; - - item_leaf_header = e_table_group_new ( - GNOME_CANVAS_GROUP (group_item), ecol, TRUE, FALSE); - leaf_header = node_new (item_leaf_header, tables [i], group); - - e_table_create_leaf (e_table, tables [i], leaf_header); - } else { - e_table_create_nodes ( - e_table, tables [i], header, GNOME_CANVAS_GROUP (group_item), - group, &groups_list [1]); - } - } - - return group; -} - -static int * -group_spec_to_desc (const char *group_spec) -{ - int a_size = 10; - int *elements; - char *p, *copy, *follow; - int n_elements = 0; - - if (group_spec == NULL) - return NULL; - - elements = g_new (int, a_size); - copy = alloca (strlen (group_spec) + 1); - strcpy (copy, group_spec); - - while ((p = strtok_r (copy, ",", &follow)) != NULL){ - elements [n_elements] = atoi (p); - ++n_elements; - if (n_elements+1 == a_size){ - int *new_e; - - n_elements += 10; - new_e = g_renew (int, elements, n_elements); - if (new_e == NULL){ - g_free (elements); - return NULL; - } - elements = new_e; - } - copy = NULL; - } - - /* Tag end */ - elements [n_elements] = -1; - - return elements; -} - -/* - * The ETableCanvas object is just used to enable us to - * hook up to the realize/unrealize phases of the canvas - * initialization (as laying out the subtables requires us to - * know the actual size of the subtables we are inserting - */ - -#define E_TABLE_CANVAS_PARENT_TYPE gnome_canvas_get_type () - -typedef struct { - GnomeCanvas base; - - ETable *e_table; -} ETableCanvas; - -typedef struct { - GnomeCanvasClass base_class; -} ETableCanvasClass; - -static GnomeCanvasClass *e_table_canvas_parent_class; - -static void -e_table_canvas_realize (GtkWidget *widget) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) widget; - ETable *e_table = e_table_canvas->e_table; - int *groups; - Node *leaf; - - GTK_WIDGET_CLASS (e_table_canvas_parent_class)->realize (widget); - - groups = group_spec_to_desc (e_table->group_spec); - - leaf = e_table_create_nodes ( - e_table, e_table->model, - e_table->header, GNOME_CANVAS_GROUP (e_table->root), 0, groups); - - - if (groups) - g_free (groups); -} - -static void -e_table_canvas_unrealize (GtkWidget *widget) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) widget; - ETable *e_table = e_table_canvas->e_table; - - gtk_object_destroy (GTK_OBJECT (e_table->root)); - - GTK_WIDGET_CLASS (e_table_canvas_parent_class)->unrealize (widget); -} - -static void -e_table_canvas_class_init (GtkObjectClass *object_class) -{ - GtkWidgetClass *widget_class = (GtkWidgetClass *) object_class; - - widget_class->realize = e_table_canvas_realize; - widget_class->unrealize = e_table_canvas_unrealize; - - e_table_canvas_parent_class = gtk_type_class (E_TABLE_CANVAS_PARENT_TYPE); -} - -static void -e_table_canvas_init (GtkObject *canvas) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) (canvas); - ETable *e_table = e_table_canvas->e_table; - - GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS); - -} - -GtkType e_table_canvas_get_type (void); - -E_MAKE_TYPE (e_table_canvas, "ETableCanvas", ETableCanvas, e_table_canvas_class_init, - e_table_canvas_init, E_TABLE_CANVAS_PARENT_TYPE); - -static GnomeCanvas * -e_table_canvas_new (ETable *e_table) -{ - ETableCanvas *e_table_canvas; - - e_table_canvas = gtk_type_new (e_table_canvas_get_type ()); - e_table_canvas->e_table = e_table; - - e_table->root = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS (e_table_canvas)->root), - gnome_canvas_group_get_type (), - "x", 0.0, - "y", 0.0, - NULL); - - return GNOME_CANVAS (e_table_canvas); -} - -static void -table_canvas_size_alocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, alloc->width, alloc->height); -} - -static void -e_table_setup_table (ETable *e_table) -{ - e_table->table_canvas = e_table_canvas_new (e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "size_allocate", - GTK_SIGNAL_FUNC (table_canvas_size_alocate), e_table); - - gtk_widget_show (GTK_WIDGET (e_table->table_canvas)); - gtk_table_attach ( - GTK_TABLE (e_table), GTK_WIDGET (e_table->table_canvas), - 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); -} - -void -e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec) -{ - GTK_TABLE (e_table)->homogeneous = FALSE; - - gtk_table_resize (GTK_TABLE (e_table), 1, 2); - - e_table->full_header = full_header; - gtk_object_ref (GTK_OBJECT (full_header)); - - e_table->model = etm; - gtk_object_ref (GTK_OBJECT (etm)); - - e_table->header = e_table_make_header (e_table, full_header, cols_spec); - - e_table_setup_header (e_table); - e_table_setup_table (e_table); - - e_table->group_spec = g_strdup (group_spec); - -} - -GtkWidget * -e_table_new (ETableHeader *full_header, ETableModel *etm, const char *cols_spec, const char *group_spec) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table_construct (e_table, full_header, etm, cols_spec, group_spec); - - return (GtkWidget *) e_table; -} - -static void -e_table_class_init (GtkObjectClass *object_class) -{ - e_table_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = et_destroy; -} - -E_MAKE_TYPE(e_table, "ETable", ETable, e_table_class_init, e_table_init, PARENT_TYPE); - diff --git a/widgets/e-table/e-table.h b/widgets/e-table/e-table.h deleted file mode 100644 index 63c131324f..0000000000 --- a/widgets/e-table/e-table.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include -#include -#include "e-table-model.h" -#include "e-table-header.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_TYPE (e_table_get_type ()) -#define E_TABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_TYPE, ETable)) -#define E_TABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_TYPE, ETableClass)) -#define E_IS_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_TYPE)) -#define E_IS_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_TYPE)) - -typedef struct { - GtkTable parent; - - ETableModel *model; - - ETableHeader *full_header, *header; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - guint draw_grid:1; - guint draw_focus:1; - guint spreadsheet:1; - - char *group_spec; -} ETable; - -typedef struct { - GtkTableClass parent_class; -} ETableClass; - -GtkType e_table_get_type (void); -void e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec); -GtkWidget *e_table_new (ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec); - - -END_GNOME_DECLS - - #endif /* _E_TABLE_H_ */ diff --git a/widgets/e-table/image1.png b/widgets/e-table/image1.png deleted file mode 100644 index 8326ac241f..0000000000 Binary files a/widgets/e-table/image1.png and /dev/null differ diff --git a/widgets/e-table/image2.png b/widgets/e-table/image2.png deleted file mode 100644 index e6a4c75dbe..0000000000 Binary files a/widgets/e-table/image2.png and /dev/null differ diff --git a/widgets/e-table/image3.png b/widgets/e-table/image3.png deleted file mode 100644 index 50e16e8620..0000000000 Binary files a/widgets/e-table/image3.png and /dev/null differ diff --git a/widgets/e-table/remove-col.xpm b/widgets/e-table/remove-col.xpm deleted file mode 100644 index ff1024f0c9..0000000000 --- a/widgets/e-table/remove-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * remove_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FF0000", -"... ...", -".++. .++.", -".+++. .+++.", -" .+++. .+++. ", -" .+++. .+++. ", -" .+++..+++. ", -" .++++++. ", -" .++++. ", -" .++++. ", -" .++++++. ", -" .+++..+++. ", -" .+++. .+++. ", -" .+++. .+++. ", -".+++. .+++.", -".++. .++.", -"... ..."}; diff --git a/widgets/e-table/sample.table b/widgets/e-table/sample.table deleted file mode 100644 index 45c8ff0691..0000000000 --- a/widgets/e-table/sample.table +++ /dev/null @@ -1,11 +0,0 @@ -Col1 Col2 Address Title Dorks -c1.a c2.a a.a tit-1 DorkA -c1.b c2.b a.b tit-2 DDork -c1.c c2.c a.c tit-1 DorkB -c1.d c2.d a.d tit-2 ADork -c1.e c2.e a.e tit-1 DorkC -c1.f c2.f a.f tit-2 UDork -c1.g c2.g a.g tit-3 Dork--- -j k k tit-1 DorkA - - diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c deleted file mode 100644 index 3009297906..0000000000 --- a/widgets/e-table/table-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "table-test.h" - -int -main (int argc, char *argv []) -{ - - if (isatty (0)){ - int fd; - - close (0); - fd = open ("sample.table", O_RDONLY); - if (fd == -1){ - fprintf (stderr, "Could not find sample.table, try feeding a table on stdin"); - exit (1); - } - dup2 (fd, 0); - } - - gnome_init ("TableTest", "TableTest", argc, argv); - e_cursors_init (); - -#if 0 - table_browser_test (); - multi_cols_test (); - check_test (); -#endif - e_table_test (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/e-table/table-test.h b/widgets/e-table/table-test.h deleted file mode 100644 index ad8cfcc083..0000000000 --- a/widgets/e-table/table-test.h +++ /dev/null @@ -1,4 +0,0 @@ -void table_browser_test (void); -void multi_cols_test (void); -void check_test (void); -void e_table_test (void); diff --git a/widgets/e-table/test-check.c b/widgets/e-table/test-check.c deleted file mode 100644 index 8cc5f6834e..0000000000 --- a/widgets/e-table/test-check.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-util/e-cursors.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "Buy food" }, - { 1, "Breathe " }, - { 0, "Cancel gdb session with shrink" }, - { 1, "Make screenshots" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -check_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_check; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - cell_image_check = e_cell_checkbox_new (); - col_0 = e_table_col_new (0, "", 18, 18, cell_image_check, g_int_equal, TRUE); - e_table_header_add_column (e_table_header, col_0, 0); - - col_1 = e_table_col_new (1, "Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); - e_table_header_add_column (e_table_header, col_1, 1); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - -} - - - - - diff --git a/widgets/e-table/test-cols.c b/widgets/e-table/test-cols.c deleted file mode 100644 index 288e2bd408..0000000000 --- a/widgets/e-table/test-cols.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-toggle.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "You are not" }, - { 1, "A beautiful and unique " }, - { 0, "Snowflake" }, - { 2, "You are not your wallet" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -multi_cols_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header, *e_table_header_multiple; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_toggle; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - { - GdkPixbuf **images = g_new (GdkPixbuf *, 3); - int i; - - images [0] = gdk_pixbuf_new_from_file ("image1.png"); - images [1] = gdk_pixbuf_new_from_file ("image2.png"); - images [2] = gdk_pixbuf_new_from_file ("image3.png"); - - cell_image_toggle = e_cell_toggle_new (0, 3, images); - - for (i = 0; i < 3; i++) - gdk_pixbuf_unref (images [i]); - - g_free (images); - } - - col_1 = e_table_col_new (1, "Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); - e_table_header_add_column (e_table_header, col_1, 0); - - col_0 = e_table_col_new (0, "A", 48, 48, cell_image_toggle, g_int_equal, TRUE); - e_table_header_add_column (e_table_header, col_0, 1); - - /* - * Second test - */ - e_table_header_multiple = e_table_header_new (); - e_table_header_add_column (e_table_header_multiple, col_0, 0); - e_table_header_add_column (e_table_header_multiple, col_1, 1); - e_table_header_add_column (e_table_header_multiple, col_1, 2); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header_multiple, - "x", 300, - "y", 0, - NULL); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header_multiple, - "ETableModel", e_table_model, - "x", (double) 300, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - -} - - - - - diff --git a/widgets/e-table/test-table.c b/widgets/e-table/test-table.c deleted file mode 100644 index 428bb52c52..0000000000 --- a/widgets/e-table/test-table.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-table.h" - -#include "table-test.h" - -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () -{ - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); - exit (1); - } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - { - static int loaded; - - if (loaded) - return; - - loaded = TRUE; - } - - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -table_browser_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - GnomeCanvasItem *group; - int i; - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 80, 20, cell_left_just, - g_str_equal, TRUE); - - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - group = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_group_get_type (), - "x", 30.0, - "y", 30.0, - NULL); - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (group), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 0, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); -} - -static void -do_e_table_demo (const char *col_spec, const char *group_spec) -{ - GtkWidget *e_table, *window, *frame; - ETableModel *e_table_model; - ECell *cell_left_just; - ETableHeader *full_header; - int i; - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - full_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 80, 20, cell_left_just, - g_str_equal, TRUE); - - e_table_header_add_column (full_header, ecol, i); - } - - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - frame = gtk_frame_new (NULL); - e_table = e_table_new (full_header, e_table_model, col_spec, group_spec); - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - gtk_widget_set_usize (window, 200, 200); - gtk_widget_show (e_table); - gtk_widget_show (frame); - gtk_widget_show (window); -} - -void -e_table_test (void) -{ - load_data (); - - if (getenv ("DO")){ - do_e_table_demo ("0,1,2,3,4", NULL); - do_e_table_demo ("0,1,2,3,4", "3,4"); - } - do_e_table_demo ("0,1,2,3,4", "3"); -} diff --git a/widgets/e-table/test.c b/widgets/e-table/test.c deleted file mode 100644 index 0eece34467..0000000000 --- a/widgets/e-table/test.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "e-table-simple.h" - -struct { - char *str; - int val; -} data [] = { - { "Miguel", 10 }, - { "Nat", 20 }, - { NULL, 0 }, -}; - -main () -{ - -} - diff --git a/widgets/e-text-event-processor-emacs-like.c b/widgets/e-text-event-processor-emacs-like.c deleted file mode 100644 index 41bcd0c31d..0000000000 --- a/widgets/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,357 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor-emacs-like.h" -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_BACKWARD_WORD, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - case GDK_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: command.position = E_TEP_BACKWARD_LINE; break; - case GDK_Down: command.position = E_TEP_FORWARD_LINE; break; - case GDK_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT */ - } - break; - case GDK_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/widgets/e-text-event-processor-emacs-like.h b/widgets/e-text-event-processor-emacs-like.h deleted file mode 100644 index 651bb552b3..0000000000 --- a/widgets/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include -#include "e-text-event-processor.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - gboolean mouse_down; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/widgets/e-text-event-processor-types.h b/widgets/e-text-event-processor-types.h deleted file mode 100644 index 32a39bf0c0..0000000000 --- a/widgets/e-text-event-processor-types.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include - -typedef enum _ETextEventProcessorCommandPosition ETextEventProcessorCommandPosition; -typedef enum _ETextEventProcessorCommandAction ETextEventProcessorCommandAction; -typedef struct _ETextEventProcessorCommand ETextEventProcessorCommand; - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; -typedef struct _ETextEventProcessorEventButton ETextEventProcessorEventButton; -typedef struct _ETextEventProcessorEventKey ETextEventProcessorEventKey; -typedef struct _ETextEventProcessorEventMotion ETextEventProcessorEventMotion; - -enum _ETextEventProcessorCommandPosition { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE -}; - -enum _ETextEventProcessorCommandAction { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -}; - -struct _ETextEventProcessorCommand { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -}; - -struct _ETextEventProcessorEventButton { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -}; - -struct _ETextEventProcessorEventKey { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -}; - -struct _ETextEventProcessorEventMotion { - GdkEventType type; - guint32 time; - guint state; - gint position; -}; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/widgets/e-text-event-processor.c b/widgets/e-text-event-processor.c deleted file mode 100644 index 47f028ca62..0000000000 --- a/widgets/e-text-event-processor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor.h" -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - klass->event = NULL; - klass->command = NULL; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} diff --git a/widgets/e-text-event-processor.h b/widgets/e-text-event-processor.h deleted file mode 100644 index 1fc79f3f70..0000000000 --- a/widgets/e-text-event-processor.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include -#include "e-text-event-processor-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/widgets/e-text.c b/widgets/e-text.c deleted file mode 100644 index b33e99194d..0000000000 --- a/widgets/e-text.c +++ /dev/null @@ -1,2526 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#include -#include -#include -#include "e-text.h" -#include /* for BlackPixel */ -#include -#include -#include -#include - -#include "e-text-event-processor-emacs-like.h" - -enum { - E_TEXT_RESIZE, - E_TEXT_CHANGE, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_MAX_LINES -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static guint32 e_text_get_event_time (EText *text); - -static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time); -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); - - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - e_text_signals[E_TEXT_CHANGE] = - gtk_signal_new ("change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); - - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::x", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X); - gtk_object_add_arg_type ("EText::y", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->resize = NULL; - klass->change = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->x = 0.0; - text->y = 0.0; - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = 0.0; - text->clip_height = 0.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->max_lines = -1; -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CANVAS_TEXT (object)); - - text = E_TEXT (object); - - if (text->text) - g_free (text->text); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - if (text->lines) - g_free (text->lines); - - if (text->font) - gdk_font_unref (text->font); - - if (text->suckfont) - e_suck_font_free (text->suckfont); - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = text->x; - y = text->y; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - clip_x -= text->clip_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - clip_x -= text->clip_width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - clip_y -= text->clip_height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - clip_y -= text->clip_height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - *px2 = clip_x + text->clip_width; - *py2 = clip_y + text->clip_height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = text->x; - wy = text->y; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - /* Get canvas pixel coordinates for clip rectangle position */ - - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = text->clip_width * item->canvas->pixels_per_unit; - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -/* Recalculates the bounding box of the text item. The bounding box is defined - * by the text's extents if the clip rectangle is disabled. If it is enabled, - * the bounding box is defined by the clip rectangle itself. - */ -static void -recalc_bounds (EText *text) -{ - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (text); - - get_bounds (text, &item->x1, &item->y1, &item->x2, &item->y2); - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - gdk_text_width (text->font, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - int j; - - lines = text->lines; - text->max_width = 0; - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = gdk_text_width (text->font, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > text->clip_width) { - if (text->font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (text->font, lines->text, j) + text->ellipsis_width <= text->clip_width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = gdk_text_width (text->font, lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - char *p; - struct line *lines; - int len; - int line_num; - char *laststart; - char *lastend; - char *linestart; - - /* Free old array of lines */ - - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; - - if (!text->text) - return; - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - for (p = text->text; *p; p++) { - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - } - } - if (*p == '\n') { - text->num_lines ++; - lastend = p + 1; - laststart = p + 1; - linestart = p + 1; - } - } - - if (text->line_wrap) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - } - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - for (p = text->text; line_num < text->num_lines && *p; p++) { - gboolean handled = FALSE; - if (len == 0) - lines->text = p; - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - len ++; - } - handled = TRUE; - } - if ( line_num >= text->num_lines ) - break; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - line_num ++; - len = 0; - lastend = p + 1; - laststart = p + 1; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } - } - - if (len == 0) - lines->text = p; - lines->length = strlen(lines->text); - - calc_line_widths (text); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - GdkColor c; - - if (!text->gc) - return; - - c.pixel = text->pixel; - gdk_gc_set_foreground (text->gc, &c); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_TEXT: - if (text->text) - g_free (text->text); - - text->text = g_strdup (GTK_VALUE_STRING (*arg)); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_X: - text->x = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y: - text->y = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FONT: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_font_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONTSET: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_fontset_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONT_GDK: - if (text->font) - gdk_font_unref (text->font); - - text->font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (text->font); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - recalc_bounds (text); - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - recalc_bounds (text); - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - gdk_color_context_query_color (item->canvas->cc, &color); - have_pixel = TRUE; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color_changed = TRUE; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - default: - break; - } - - if (color_changed) { - if (have_pixel) - text->pixel = color.pixel; - else - text->pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba); - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - gnome_canvas_item_request_update (item); - } -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - case ARG_X: - GTK_VALUE_DOUBLE (*arg) = text->x; - break; - - case ARG_Y: - GTK_VALUE_DOUBLE (*arg) = text->y; - break; - - case ARG_FONT_GDK: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - color->pixel = text->pixel; - gdk_color_context_query_color (text->item.canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - - gnome_canvas_update_bbox (item, x1, y1, x2, y2); - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - gnome_canvas_update_bbox (item, c_bbox.x0, c_bbox.y0, c_bbox.x1, c_bbox.y1); - - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - gdk_cursor_destroy (text->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = text->x; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = text->y; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GnomeCanvas *canvas; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - - fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - - if (!text->text || !text->font) - return; - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - lines = text->lines; - ypos = text->cy + text->font->ascent; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, text->gc); - - for (i = 0; i < text->num_lines; i++) { - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = lines->text - text->text; - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - text->font->ascent; - sel_rect.width = gdk_text_width (text->font, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = text->font->ascent + text->font->descent; - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - gdk_draw_text (drawable, - text->font, - fg_gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + sel_start - start_char, - sel_end - sel_start); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y - text->font->ascent, - 1, - text->font->ascent + text->font->descent); - } - } else { - if ( text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + - lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); - } else - - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - - ypos += text->font->ascent + text->font->descent; - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (text->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - ETextSuckFont *suckfont; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = text->font->ascent + text->font->descent; - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = text->x; - *y1 = text->y; - - if (text->clip) { - width = text->clip_width; - height = text->clip_height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static void -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - x = get_line_xpos (text, lines); - y = text->cy; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += text->font->ascent + text->font->descent; - } - lines --; - y -= text->font->descent; - - x += gdk_text_width (text->font, - lines->text, - position - (lines->text - text->text)); - x -= text->xofs_edit; - if (xp) - *xp = x; - if (yp) - *yp = y; - } -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->cy; - int xpos; - struct line *lines; - j = 0; - while (y > ypos) { - ypos += text->font->ascent + text->font->descent; - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos (text, lines); - for(i = 0; i < lines->length; i++) { - int charwidth = gdk_text_width(text->font, - lines->text + i, - 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - return lines->text + i - text->text; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - return TRUE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!text->editing) { - text->editing = TRUE; - if ( text->pointer_in ) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - text->xofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); - } - } else { - text->editing = FALSE; - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - } - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(text); - return e_text_event_processor_handle_event (text->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->editing) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } else if (text->editable && event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { - gnome_canvas_item_grab_focus (item); - return 1; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - text->pointer_in = TRUE; - if (text->editing) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - text->pointer_in = FALSE; - if (text->editing) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return text->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return strlen(text->text); - - case E_TEP_START_OF_LINE: - for (i = text->selection_end - 2; i > 0; i--) - if (text->text[i] == '\n') { - i++; - break; - } - return i; - case E_TEP_END_OF_LINE: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (text->text[i] == '\n') { - break; - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = strlen(text->text); - i = text->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = text->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (isspace(text->text[i])) { - break; - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = text->selection_end - 2; i > 0; i--) - if (isspace(text->text[i])) { - i++; - break; - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y += text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y -= text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return text->selection_end; - default: - return text->selection_end; - } -} - -static void -_delete_selection(EText *text) -{ - gint length = strlen(text->text); - if (text->selection_end == text->selection_start) - return; - if (text->selection_end < text->selection_start) { - text->selection_end ^= text->selection_start; - text->selection_start ^= text->selection_end; - text->selection_end ^= text->selection_start; - } - memmove( text->text + text->selection_start, - text->text + text->selection_end, - length - text->selection_end + 1 ); - length -= text->selection_end - text->selection_start; - text->selection_end = text->selection_start; -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - char *temp; - gint length = strlen(text->text); - temp = g_new(gchar, length + value + 1); - strncpy(temp, text->text, text->selection_start); - strncpy(temp + text->selection_start, string, value); - strcpy(temp + text->selection_start + value, text->text + text->selection_start); - g_free(text->text); - text->text = temp; - text->selection_start += value; - text->selection_end = text->selection_start; - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SELECT: - text->selection_end = _get_position(text, command); - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, text->text + sel_start, sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, text->text + sel_start, sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; - case E_TEP_NOP: - break; - } - - if (!text->button_down) { - int x; - int i; - struct line *lines = text->lines; - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (lines->text - text->text > text->selection_end) { - break; - } - } - lines --; - x = gdk_text_width(text->font, - lines->text, - text->selection_end - (lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - if (2 + x - text->clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - text->clip_width; - } - } - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void _invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget *e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->primary_selection, text->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->clipboard_selection, text->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } -} - -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (text->primary_selection) { - g_free (text->primary_selection); - } - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - if (text->clipboard_selection) { - g_free (text->clipboard_selection); - } - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - -/* Get the timestamp of the current event. Actually, the only thing - * we really care about below is the key event - */ -static guint32 -e_text_get_event_time (EText *text) -{ - GdkEvent *event; - guint32 tm = GDK_CURRENT_TIME; - - event = gtk_get_current_event(); - - if (event) - switch (event->type) - { - case GDK_MOTION_NOTIFY: - tm = event->motion.time; break; - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - tm = event->button.time; break; - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - tm = event->key.time; break; - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - tm = event->crossing.time; break; - case GDK_PROPERTY_NOTIFY: - tm = event->property.time; break; - case GDK_SELECTION_CLEAR: - case GDK_SELECTION_REQUEST: - case GDK_SELECTION_NOTIFY: - tm = event->selection.time; break; - case GDK_PROXIMITY_IN: - case GDK_PROXIMITY_OUT: - tm = event->proximity.time; break; - default: /* use current time */ - break; - } - gdk_event_free(event); - - return tm; -} - - - -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} diff --git a/widgets/e-text.h b/widgets/e-text.h deleted file mode 100644 index ef8da442d6..0000000000 --- a/widgets/e-text.h +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include -#include "e-text-event-processor.h" - - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * x double RW X coordinate of anchor point - * y double RW Y coordinate of anchor point - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * max_line_wrap int RW Number of lines possible when doing line wrap. - * - * These are not implemented yet: - * background boolean RW Draw a background rectangle. - * background_on_edit boolean RW Draw a background when editing. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; - -struct _EText { - GnomeCanvasItem item; - - char *text; /* Text to display */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - - double x, y; /* Position at anchor */ - GdkFont *font; /* Font for text */ - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - gulong pixel; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int height; /* Rendered text height in pixels */ - - guint clip : 1; /* Use clip rectangle? */ - - /* Antialiased specific stuff follows */ - ETextSuckFont *suckfont; /* Sucked font */ - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - gboolean use_ellipsis; /* Whether to use the ellipsis. */ - - gboolean editable; /* Item is editable */ - gboolean editing; /* Item is currently being edited */ - - int xofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - - guint line_wrap : 1; /* Do line wrap */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* resize) (EText *text); - void (* change) (EText *text); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); - - -END_GNOME_DECLS - -#endif diff --git a/widgets/e-text/Makefile.am b/widgets/e-text/Makefile.am deleted file mode 100644 index ec7795f283..0000000000 --- a/widgets/e-text/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -INCLUDES = \ - $(GNOME_INCLUDEDIR) - -noinst_LIBRARIES = \ - libetext.a - -libetext_a_SOURCES = \ - e-text.c \ - e-text.h \ - e-text-event-processor.c \ - e-text-event-processor.h \ - e-text-event-processor-emacs-like.c \ - e-text-event-processor-emacs-like.h diff --git a/widgets/e-text/e-text-event-processor-emacs-like.c b/widgets/e-text/e-text-event-processor-emacs-like.c deleted file mode 100644 index 41bcd0c31d..0000000000 --- a/widgets/e-text/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,357 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor-emacs-like.h" -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_BACKWARD_WORD, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - case GDK_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: command.position = E_TEP_BACKWARD_LINE; break; - case GDK_Down: command.position = E_TEP_FORWARD_LINE; break; - case GDK_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT */ - } - break; - case GDK_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/widgets/e-text/e-text-event-processor-emacs-like.h b/widgets/e-text/e-text-event-processor-emacs-like.h deleted file mode 100644 index 651bb552b3..0000000000 --- a/widgets/e-text/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include -#include "e-text-event-processor.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - gboolean mouse_down; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/widgets/e-text/e-text-event-processor-types.h b/widgets/e-text/e-text-event-processor-types.h deleted file mode 100644 index 32a39bf0c0..0000000000 --- a/widgets/e-text/e-text-event-processor-types.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include - -typedef enum _ETextEventProcessorCommandPosition ETextEventProcessorCommandPosition; -typedef enum _ETextEventProcessorCommandAction ETextEventProcessorCommandAction; -typedef struct _ETextEventProcessorCommand ETextEventProcessorCommand; - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; -typedef struct _ETextEventProcessorEventButton ETextEventProcessorEventButton; -typedef struct _ETextEventProcessorEventKey ETextEventProcessorEventKey; -typedef struct _ETextEventProcessorEventMotion ETextEventProcessorEventMotion; - -enum _ETextEventProcessorCommandPosition { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE -}; - -enum _ETextEventProcessorCommandAction { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -}; - -struct _ETextEventProcessorCommand { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -}; - -struct _ETextEventProcessorEventButton { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -}; - -struct _ETextEventProcessorEventKey { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -}; - -struct _ETextEventProcessorEventMotion { - GdkEventType type; - guint32 time; - guint state; - gint position; -}; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/widgets/e-text/e-text-event-processor.c b/widgets/e-text/e-text-event-processor.c deleted file mode 100644 index 47f028ca62..0000000000 --- a/widgets/e-text/e-text-event-processor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor.h" -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - klass->event = NULL; - klass->command = NULL; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} diff --git a/widgets/e-text/e-text-event-processor.h b/widgets/e-text/e-text-event-processor.h deleted file mode 100644 index 1fc79f3f70..0000000000 --- a/widgets/e-text/e-text-event-processor.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include -#include "e-text-event-processor-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c deleted file mode 100644 index b33e99194d..0000000000 --- a/widgets/e-text/e-text.c +++ /dev/null @@ -1,2526 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#include -#include -#include -#include "e-text.h" -#include /* for BlackPixel */ -#include -#include -#include -#include - -#include "e-text-event-processor-emacs-like.h" - -enum { - E_TEXT_RESIZE, - E_TEXT_CHANGE, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_MAX_LINES -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static guint32 e_text_get_event_time (EText *text); - -static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time); -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); - - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - e_text_signals[E_TEXT_CHANGE] = - gtk_signal_new ("change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); - - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::x", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X); - gtk_object_add_arg_type ("EText::y", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->resize = NULL; - klass->change = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->x = 0.0; - text->y = 0.0; - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = 0.0; - text->clip_height = 0.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->max_lines = -1; -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CANVAS_TEXT (object)); - - text = E_TEXT (object); - - if (text->text) - g_free (text->text); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - if (text->lines) - g_free (text->lines); - - if (text->font) - gdk_font_unref (text->font); - - if (text->suckfont) - e_suck_font_free (text->suckfont); - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = text->x; - y = text->y; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - clip_x -= text->clip_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - clip_x -= text->clip_width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - clip_y -= text->clip_height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - clip_y -= text->clip_height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - *px2 = clip_x + text->clip_width; - *py2 = clip_y + text->clip_height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = text->x; - wy = text->y; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - /* Get canvas pixel coordinates for clip rectangle position */ - - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = text->clip_width * item->canvas->pixels_per_unit; - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -/* Recalculates the bounding box of the text item. The bounding box is defined - * by the text's extents if the clip rectangle is disabled. If it is enabled, - * the bounding box is defined by the clip rectangle itself. - */ -static void -recalc_bounds (EText *text) -{ - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (text); - - get_bounds (text, &item->x1, &item->y1, &item->x2, &item->y2); - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - gdk_text_width (text->font, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - int j; - - lines = text->lines; - text->max_width = 0; - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = gdk_text_width (text->font, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > text->clip_width) { - if (text->font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (text->font, lines->text, j) + text->ellipsis_width <= text->clip_width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = gdk_text_width (text->font, lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - char *p; - struct line *lines; - int len; - int line_num; - char *laststart; - char *lastend; - char *linestart; - - /* Free old array of lines */ - - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; - - if (!text->text) - return; - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - for (p = text->text; *p; p++) { - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - } - } - if (*p == '\n') { - text->num_lines ++; - lastend = p + 1; - laststart = p + 1; - linestart = p + 1; - } - } - - if (text->line_wrap) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - } - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - for (p = text->text; line_num < text->num_lines && *p; p++) { - gboolean handled = FALSE; - if (len == 0) - lines->text = p; - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - len ++; - } - handled = TRUE; - } - if ( line_num >= text->num_lines ) - break; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - line_num ++; - len = 0; - lastend = p + 1; - laststart = p + 1; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } - } - - if (len == 0) - lines->text = p; - lines->length = strlen(lines->text); - - calc_line_widths (text); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - GdkColor c; - - if (!text->gc) - return; - - c.pixel = text->pixel; - gdk_gc_set_foreground (text->gc, &c); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_TEXT: - if (text->text) - g_free (text->text); - - text->text = g_strdup (GTK_VALUE_STRING (*arg)); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_X: - text->x = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y: - text->y = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FONT: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_font_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONTSET: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_fontset_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONT_GDK: - if (text->font) - gdk_font_unref (text->font); - - text->font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (text->font); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - recalc_bounds (text); - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - recalc_bounds (text); - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - gdk_color_context_query_color (item->canvas->cc, &color); - have_pixel = TRUE; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color_changed = TRUE; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - default: - break; - } - - if (color_changed) { - if (have_pixel) - text->pixel = color.pixel; - else - text->pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba); - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - gnome_canvas_item_request_update (item); - } -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - case ARG_X: - GTK_VALUE_DOUBLE (*arg) = text->x; - break; - - case ARG_Y: - GTK_VALUE_DOUBLE (*arg) = text->y; - break; - - case ARG_FONT_GDK: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - color->pixel = text->pixel; - gdk_color_context_query_color (text->item.canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - - gnome_canvas_update_bbox (item, x1, y1, x2, y2); - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - gnome_canvas_update_bbox (item, c_bbox.x0, c_bbox.y0, c_bbox.x1, c_bbox.y1); - - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - gdk_cursor_destroy (text->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = text->x; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = text->y; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GnomeCanvas *canvas; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - - fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - - if (!text->text || !text->font) - return; - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - lines = text->lines; - ypos = text->cy + text->font->ascent; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, text->gc); - - for (i = 0; i < text->num_lines; i++) { - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = lines->text - text->text; - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - text->font->ascent; - sel_rect.width = gdk_text_width (text->font, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = text->font->ascent + text->font->descent; - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - gdk_draw_text (drawable, - text->font, - fg_gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + sel_start - start_char, - sel_end - sel_start); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y - text->font->ascent, - 1, - text->font->ascent + text->font->descent); - } - } else { - if ( text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + - lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); - } else - - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - - ypos += text->font->ascent + text->font->descent; - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (text->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - ETextSuckFont *suckfont; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = text->font->ascent + text->font->descent; - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = text->x; - *y1 = text->y; - - if (text->clip) { - width = text->clip_width; - height = text->clip_height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static void -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - x = get_line_xpos (text, lines); - y = text->cy; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += text->font->ascent + text->font->descent; - } - lines --; - y -= text->font->descent; - - x += gdk_text_width (text->font, - lines->text, - position - (lines->text - text->text)); - x -= text->xofs_edit; - if (xp) - *xp = x; - if (yp) - *yp = y; - } -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->cy; - int xpos; - struct line *lines; - j = 0; - while (y > ypos) { - ypos += text->font->ascent + text->font->descent; - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos (text, lines); - for(i = 0; i < lines->length; i++) { - int charwidth = gdk_text_width(text->font, - lines->text + i, - 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - return lines->text + i - text->text; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - return TRUE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!text->editing) { - text->editing = TRUE; - if ( text->pointer_in ) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - text->xofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); - } - } else { - text->editing = FALSE; - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - } - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(text); - return e_text_event_processor_handle_event (text->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->editing) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } else if (text->editable && event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { - gnome_canvas_item_grab_focus (item); - return 1; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - text->pointer_in = TRUE; - if (text->editing) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - text->pointer_in = FALSE; - if (text->editing) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return text->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return strlen(text->text); - - case E_TEP_START_OF_LINE: - for (i = text->selection_end - 2; i > 0; i--) - if (text->text[i] == '\n') { - i++; - break; - } - return i; - case E_TEP_END_OF_LINE: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (text->text[i] == '\n') { - break; - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = strlen(text->text); - i = text->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = text->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (isspace(text->text[i])) { - break; - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = text->selection_end - 2; i > 0; i--) - if (isspace(text->text[i])) { - i++; - break; - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y += text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y -= text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return text->selection_end; - default: - return text->selection_end; - } -} - -static void -_delete_selection(EText *text) -{ - gint length = strlen(text->text); - if (text->selection_end == text->selection_start) - return; - if (text->selection_end < text->selection_start) { - text->selection_end ^= text->selection_start; - text->selection_start ^= text->selection_end; - text->selection_end ^= text->selection_start; - } - memmove( text->text + text->selection_start, - text->text + text->selection_end, - length - text->selection_end + 1 ); - length -= text->selection_end - text->selection_start; - text->selection_end = text->selection_start; -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - char *temp; - gint length = strlen(text->text); - temp = g_new(gchar, length + value + 1); - strncpy(temp, text->text, text->selection_start); - strncpy(temp + text->selection_start, string, value); - strcpy(temp + text->selection_start + value, text->text + text->selection_start); - g_free(text->text); - text->text = temp; - text->selection_start += value; - text->selection_end = text->selection_start; - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SELECT: - text->selection_end = _get_position(text, command); - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, text->text + sel_start, sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, text->text + sel_start, sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; - case E_TEP_NOP: - break; - } - - if (!text->button_down) { - int x; - int i; - struct line *lines = text->lines; - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (lines->text - text->text > text->selection_end) { - break; - } - } - lines --; - x = gdk_text_width(text->font, - lines->text, - text->selection_end - (lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - if (2 + x - text->clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - text->clip_width; - } - } - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void _invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget *e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->primary_selection, text->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->clipboard_selection, text->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } -} - -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (text->primary_selection) { - g_free (text->primary_selection); - } - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - if (text->clipboard_selection) { - g_free (text->clipboard_selection); - } - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - -/* Get the timestamp of the current event. Actually, the only thing - * we really care about below is the key event - */ -static guint32 -e_text_get_event_time (EText *text) -{ - GdkEvent *event; - guint32 tm = GDK_CURRENT_TIME; - - event = gtk_get_current_event(); - - if (event) - switch (event->type) - { - case GDK_MOTION_NOTIFY: - tm = event->motion.time; break; - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - tm = event->button.time; break; - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - tm = event->key.time; break; - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - tm = event->crossing.time; break; - case GDK_PROPERTY_NOTIFY: - tm = event->property.time; break; - case GDK_SELECTION_CLEAR: - case GDK_SELECTION_REQUEST: - case GDK_SELECTION_NOTIFY: - tm = event->selection.time; break; - case GDK_PROXIMITY_IN: - case GDK_PROXIMITY_OUT: - tm = event->proximity.time; break; - default: /* use current time */ - break; - } - gdk_event_free(event); - - return tm; -} - - - -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h deleted file mode 100644 index ef8da442d6..0000000000 --- a/widgets/e-text/e-text.h +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include -#include "e-text-event-processor.h" - - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * x double RW X coordinate of anchor point - * y double RW Y coordinate of anchor point - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * max_line_wrap int RW Number of lines possible when doing line wrap. - * - * These are not implemented yet: - * background boolean RW Draw a background rectangle. - * background_on_edit boolean RW Draw a background when editing. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; - -struct _EText { - GnomeCanvasItem item; - - char *text; /* Text to display */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - - double x, y; /* Position at anchor */ - GdkFont *font; /* Font for text */ - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - gulong pixel; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int height; /* Rendered text height in pixels */ - - guint clip : 1; /* Use clip rectangle? */ - - /* Antialiased specific stuff follows */ - ETextSuckFont *suckfont; /* Sucked font */ - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - gboolean use_ellipsis; /* Whether to use the ellipsis. */ - - gboolean editable; /* Item is editable */ - gboolean editing; /* Item is currently being edited */ - - int xofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - - guint line_wrap : 1; /* Do line wrap */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* resize) (EText *text); - void (* change) (EText *text); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); - - -END_GNOME_DECLS - -#endif diff --git a/widgets/meeting-time-sel/.cvsignore b/widgets/meeting-time-sel/.cvsignore deleted file mode 100644 index 21ce3ebb95..0000000000 --- a/widgets/meeting-time-sel/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -test-meeting-time-selector diff --git a/widgets/meeting-time-sel/LICENSE b/widgets/meeting-time-sel/LICENSE deleted file mode 100644 index 9babf4395f..0000000000 --- a/widgets/meeting-time-sel/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is licensed under the terms of the GNU GPL diff --git a/widgets/meeting-time-sel/Makefile.am b/widgets/meeting-time-sel/Makefile.am deleted file mode 100644 index fdf6e90b67..0000000000 --- a/widgets/meeting-time-sel/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ - -INCLUDES = \ - $(GNOME_INCLUDEDIR) - -noinst_LIBRARIES = \ - libevolutionmtsel.a - -libevolutionmtsel_a_SOURCES = \ - e-meeting-time-sel.c \ - e-meeting-time-sel.h \ - e-meeting-time-sel-item.c \ - e-meeting-time-sel-item.h \ - e-meeting-time-sel-list-item.c \ - e-meeting-time-sel-list-item.h - -noinst_PROGRAMS = \ - test-meeting-time-selector - -test_meeting_time_selector_SOURCES = \ - test-meeting-time-sel.c - -test_meeting_time_selector_LDADD = \ - libevolutionmtsel.a - -test_meeting_time_selector_LDFLAGS = `gnome-config --libs gnomeui` - -EXTRA_DIST = \ - e-meeting-time-sel-mail.xpm \ - e-meeting-time-sel-no-mail.xpm - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-item.c b/widgets/meeting-time-sel/e-meeting-time-sel-item.c deleted file mode 100644 index cb716d6f08..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-item.c +++ /dev/null @@ -1,924 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EMeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#include -#include -#include "e-meeting-time-sel-item.h" -#include "e-meeting-time-sel.h" - -/* Initially the grid lines were drawn at the bottom of cells, but this didn't - line up well with the GtkEntry widgets, which in the default theme draw a - black shadow line across the top. So I've switched our code to draw the - lines across the top of cells. */ -#define E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM 0 - -static void e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class); -static void e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item); -static void e_meeting_time_selector_item_destroy (GtkObject *object); - -static void e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_meeting_time_selector_item_realize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_meeting_time_selector_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_meeting_time_selector_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_meeting_time_selector_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); - -static void e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int y, int width, int height); -static void e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height); -static gint e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row); -static void e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int row, int x, int y, int width, int first_period, EMeetingTimeSelectorBusyType busy_type); - -static EMeetingTimeSelectorPosition e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, gint x, gint y); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MEETING_TIME_SELECTOR -}; - - -GtkType -e_meeting_time_selector_item_get_type (void) -{ - static GtkType e_meeting_time_selector_item_type = 0; - - if (!e_meeting_time_selector_item_type) { - GtkTypeInfo e_meeting_time_selector_item_info = { - "EMeetingTimeSelectorItem", - sizeof (EMeetingTimeSelectorItem), - sizeof (EMeetingTimeSelectorItemClass), - (GtkClassInitFunc) e_meeting_time_selector_item_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_meeting_time_selector_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_meeting_time_selector_item_info); - } - - return e_meeting_time_selector_item_type; -} - - -static void -e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) mts_item_class; - item_class = (GnomeCanvasItemClass *) mts_item_class; - - gtk_object_add_arg_type ("EMeetingTimeSelectorItem::meeting_time_selector", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_MEETING_TIME_SELECTOR); - - object_class->destroy = e_meeting_time_selector_item_destroy; - object_class->set_arg = e_meeting_time_selector_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_meeting_time_selector_item_realize; - item_class->unrealize = e_meeting_time_selector_item_unrealize; - item_class->update = e_meeting_time_selector_item_update; - item_class->draw = e_meeting_time_selector_item_draw; - item_class->point = e_meeting_time_selector_item_point; - item_class->event = e_meeting_time_selector_item_event; -} - - -static void -e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (mts_item); - - mts_item->mts = NULL; - - mts_item->main_gc = NULL; - - /* Create the cursors. */ - mts_item->normal_cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW); - mts_item->resize_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - mts_item->last_cursor_set = NULL; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_meeting_time_selector_item_destroy (GtkObject *object) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (object); - - gdk_cursor_destroy (mts_item->normal_cursor); - gdk_cursor_destroy (mts_item->resize_cursor); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (*GTK_OBJECT_CLASS (parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMeetingTimeSelectorItem *mts_item; - - item = GNOME_CANVAS_ITEM (o); - mts_item = E_MEETING_TIME_SELECTOR_ITEM (o); - - switch (arg_id){ - case ARG_MEETING_TIME_SELECTOR: - mts_item->mts = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_meeting_time_selector_item_realize (GnomeCanvasItem *item) -{ - GnomeCanvas *canvas; - GdkWindow *window; - EMeetingTimeSelectorItem *mts_item; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->realize)(item); - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - canvas = item->canvas; - window = GTK_WIDGET (canvas)->window; - - mts_item->main_gc = gdk_gc_new (window); -} - - -static void -e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - gdk_gc_unref (mts_item->main_gc); - mts_item->main_gc = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize)(item); -} - - -static void -e_meeting_time_selector_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The grid covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorItem *mts_item; - EMeetingTimeSelectorAttendee *attendee; - gint day_x, meeting_start_x, meeting_end_x, bar_y, bar_height; - gint row, row_y; - GDate date, last_date, current_date; - gboolean is_display_top, show_meeting_time; - GdkGC *gc; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - mts = mts_item->mts; - g_return_if_fail (mts != NULL); - gc = mts_item->main_gc; - - is_display_top = (GTK_WIDGET (item->canvas) == mts->display_top) - ? TRUE : FALSE; - - /* Calculate the first and last visible days and positions. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, - &date, &day_x); - e_meeting_time_selector_calculate_day_and_position (mts, x + width, - &last_date, NULL); - - /* For the top display draw the 'All Attendees' row background. */ - if (is_display_top) { - gdk_gc_set_foreground (gc, &mts->all_attendees_bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, - 0, mts->row_height * 2 - y, - width, mts->row_height); - } else { - gdk_gc_set_foreground (gc, &mts->bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height); - } - - /* Calculate the x coordinates of the meeting time. */ - show_meeting_time = e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x); - - /* Draw the meeting time background. */ - if (show_meeting_time - && (meeting_end_x - 1 >= x) && (meeting_start_x + 1 < x + width) - && (meeting_end_x - meeting_start_x > 2)) { - gdk_gc_set_foreground (gc, &mts->meeting_time_bg_color); - if (is_display_top) - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, mts->row_height * 2 - y, - meeting_end_x - meeting_start_x - 2, height); - else - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, 0, - meeting_end_x - meeting_start_x - 2, height); - } - - /* For the main display draw the stipple background for attendee's - that have no calendar information. */ - if (!is_display_top) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_background (gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (gc, mts->stipple); - gnome_canvas_set_stipple_origin (item->canvas, gc); - gdk_gc_set_fill (gc, GDK_OPAQUE_STIPPLED); - row = y / mts->row_height; - row_y = row * mts->row_height - y; - while (row < mts->attendees->len && row_y < height) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (!attendee->has_calendar_info) { - gdk_draw_rectangle (drawable, gc, TRUE, - 0, row_y, - width, mts->row_height); - } - row++; - row_y += mts->row_height; - } - gdk_gc_set_fill (gc, GDK_SOLID); - } - - /* Now paint the visible days one by one. */ - current_date = date; - for (;;) { - /* Currently we use the same GnomeCanvasItem class for the - top display and the main display. We may use separate - classes in future if necessary. */ - if (is_display_top) - e_meeting_time_selector_item_paint_day_top (mts_item, drawable, ¤t_date, day_x, y, width, height); - else - e_meeting_time_selector_item_paint_day (mts_item, drawable, ¤t_date, day_x, y, width, height); - - day_x += mts_item->mts->day_width; - if (g_date_compare (¤t_date, &last_date) == 0) - break; - g_date_add_days (¤t_date, 1); - } - - /* Draw the busy periods. */ - if (is_display_top) - e_meeting_time_selector_item_paint_all_attendees_busy_periods (mts_item, drawable, &date, x, y, width, height); - else - e_meeting_time_selector_item_paint_busy_periods (mts_item, drawable, &date, x, y, width, height); - - - /* Draw the currently-selected meeting time vertical bars. */ - if (show_meeting_time) { - if (is_display_top) { - bar_y = mts->row_height * 2 - y; - bar_height = mts->row_height; - } else { - bar_y = 0; - bar_height = height; - } - - gdk_gc_set_foreground (gc, &mts->grid_color); - - if ((meeting_start_x + 2 >= x) - && (meeting_start_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x - 2 - x, bar_y, - 5, bar_height); - } - - if ((meeting_end_x + 2 >= x) - && (meeting_end_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_end_x - 2 - x, bar_y, - 5, bar_height); - } - } -} - - -static void -e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - GdkFont *font; - gint y, grid_x; - gchar buffer[128]; - gint hour, hour_x, hour_y; - GdkRectangle clip_rect; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - gdk_gc_set_foreground (gc, &mts->grid_color); - - /* Draw the horizontal lines. */ - y = mts->row_height - 1 - scroll_y; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - gdk_gc_set_foreground (gc, &mts->grid_shadow_color); - gdk_draw_line (drawable, gc, x, y + 1, x + mts->day_width - 1, y + 1); - gdk_gc_set_foreground (gc, &mts->grid_color); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - - - /* Draw the vertical grid lines. */ - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) { - gdk_draw_line (drawable, gc, - x + grid_x, mts->row_height * 2 - 4, - x + grid_x, height); - } - grid_x = mts->day_width - 2; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - grid_x++; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - font = GTK_WIDGET (mts)->style->font; - if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_FULL) - g_date_strftime (buffer, 128, "%A, %B %d, %Y", date); - else if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY) - g_date_strftime (buffer, 128, "%a %x", date); - else - g_date_strftime (buffer, 128, "%x", date); - clip_rect.x = x; - clip_rect.y = -scroll_y; - clip_rect.width = mts->day_width - 2; - clip_rect.height = mts->row_height - 2; - gdk_gc_set_clip_rectangle (gc, &clip_rect); - gdk_draw_string (drawable, font, gc, - x + 4, 4 + font->ascent - scroll_y, buffer); - gdk_gc_set_clip_rectangle (gc, NULL); - - /* Draw the hours. */ - hour = mts->first_hour_shown + (mts->zoomed_out ? 3 : 1); - hour_x = x + mts->col_width; - hour_y = mts->row_height + 4 + font->ascent - scroll_y; - while (hour < mts->last_hour_shown) { - gdk_draw_string (drawable, font, gc, - hour_x - (mts->hour_widths[hour] / 2), - hour_y, EMeetingTimeSelectorHours[hour]); - - hour += mts->zoomed_out ? 3 : 1; - hour_x += mts->col_width; - } -} - - -/* This paints the colored bars representing busy periods for the combined - list of attendees. For now we just paint the bars for each attendee of - each other. If we want to speed it up we could optimise it later. */ -static void -e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorBusyType busy_type; - gint row, y; - GdkGC *gc; - gint *first_periods; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = 2 * mts->row_height - scroll_y - 1; - - /* Get the first visible busy periods for all the attendees. */ - first_periods = g_new (gint, mts->attendees->len); - for (row = 0; row < mts->attendees->len; row++) { - first_periods[row] = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, row); - } - - for (busy_type = 0; - busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - for (row = 0; row < mts->attendees->len; row++) { - if (first_periods[row] == -1) - continue; - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, row, first_periods[row], busy_type); - } - } - - g_free (first_periods); -} - - -static void -e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - gint grid_x, grid_y, attendee_index, unused_y; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Draw the grid lines. The grid lines around unused rows are drawn in - a different color. */ - - /* Draw the horizontal grid lines. */ - attendee_index = scroll_y / mts->row_height; -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - for (grid_y = mts->row_height - 1 - (scroll_y % mts->row_height); -#else - for (grid_y = - (scroll_y % mts->row_height); -#endif - grid_y < height; - grid_y += mts->row_height) - { - if (attendee_index < mts->attendees->len) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } else { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } - attendee_index++; - } - - /* Draw the vertical grid lines. */ - unused_y = (mts->attendees->len * mts->row_height) - scroll_y; - if (unused_y >= 0) { - gdk_gc_set_foreground (gc, &mts->grid_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, 0, - x + grid_x, unused_y - 1); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, 0, - 2, unused_y); - } - - if (unused_y < height) { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, unused_y, - x + grid_x, height); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, unused_y, - 2, height - unused_y); - } - - -} - - -/* This paints the colored bars representing busy periods for the individual - attendees. */ -static void -e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorBusyType busy_type; - gint row, y, first_period; - GdkGC *gc; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Calculate the first visible attendee row. */ - row = scroll_y / mts->row_height; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = row * mts->row_height - scroll_y; - - /* Step through the attendees painting the busy periods. */ - while (y < height && row < mts->attendees->len) { - - /* Find the first visible busy period. */ - first_period = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, row); - if (first_period != -1) { - /* Paint the different types of busy periods, in - reverse order of precedence, so the highest - precedences are displayed. */ - for (busy_type = 0; - busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, row, first_period, busy_type); - } - } - y += mts->row_height; - row++; - } -} - - -/* This subtracts the attendees longest_period_in_days from the given date, - and does a binary search of the attendee's busy periods array to find the - first one which could possible end on the given day or later. - If none are found it returns -1. */ -static gint -e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - gint period_num; - - mts = mts_item->mts; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - period_num = e_meeting_time_selector_find_first_busy_period (mts, attendee, date); - if (period_num == -1) - return -1; - - /* Check if the period starts after the end of the current canvas - scroll area. */ - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, period_num); - if (g_date_compare (&mts->last_date_shown, &period->start.date) < 0) - return -1; - - return period_num; -} - - -/* This paints the visible busy periods for one attendee which are of a certain - busy type, e.g out of office. It is passed the index of the first visible - busy period of the attendee and continues until it runs off the screen. */ -static void -e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int x, int y, int width, int row, int first_period, EMeetingTimeSelectorBusyType busy_type) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - GdkGC *gc; - gint period_num, x1, x2, x2_within_day, x2_within_col; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - for (period_num = first_period; - period_num < attendee->busy_periods->len; - period_num++) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, period_num); - - if (period->busy_type != busy_type) - continue; - - /* Convert the period start and end times to x coordinates. */ - x1 = e_meeting_time_selector_calculate_time_position (mts, &period->start); - /* If the period is off the right of the area being drawn, we - are finished. */ - if (x1 >= x + width) - return; - - x2 = e_meeting_time_selector_calculate_time_position (mts, &period->end); - /* If the period is off the left edge of the area skip it. */ - if (x2 <= x) - continue; - - /* We paint from x1 to x2 - 1, so that for example a time - from 5:00-6:00 is distinct from 6:00-7:00. - We never finish on a grid line separating days, and we only - ever paint on a normal vertical grid line if the period is - only 1 pixel wide. */ - x2_within_day = x2 % mts->day_width; - if (x2_within_day == 0) { - x2 -= 2; - } else if (x2_within_day == mts->day_width - 1) { - x2 -= 1; - } else { - x2_within_col = x2_within_day % mts->col_width; - if (x2_within_col == 0 && x2 > x1 + 1) - x2 -= 1; - } - - /* Paint the rectangle. We leave a gap of 2 pixels at the - top and bottom, remembering that the grid is painted along - the top/bottom line of each row. */ - if (x2 - x1 > 0) { -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 2, - x2 - x1, mts->row_height - 5); -#else - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 3, - x2 - x1, mts->row_height - 5); -#endif - } - } -} - - -/* - * CANVAS ITEM ROUTINES - functions to be a GnomeCanvasItem. - */ - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_meeting_time_selector_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_meeting_time_selector_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_meeting_time_selector_item_button_press (mts_item, - event); - case GDK_BUTTON_RELEASE: - return e_meeting_time_selector_item_button_release (mts_item, - event); - case GDK_MOTION_NOTIFY: - return e_meeting_time_selector_item_motion_notify (mts_item, - event); - default: - break; - } - - return FALSE; -} - - -/* This handles all button press events for the item. If the cursor is over - one of the meeting time vertical bars we start a drag. If not we set the - meeting time to the nearest half-hour interval. - Note that GnomeCanvas converts the event coords to world coords, - i.e. relative to the entire canvas scroll area. */ -static gint -e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime start_time, end_time; - EMeetingTimeSelectorPosition position; - GDate *start_date, *end_date; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->button.x; - y = (gint) event->button.y; - - /* Check if we are starting a drag of the vertical meeting time bars.*/ - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - if (position != E_MEETING_TIME_SELECTOR_POS_NONE) { - if (gnome_canvas_item_grab (GNOME_CANVAS_ITEM (mts_item), - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - mts_item->resize_cursor, - event->button.time) == 0 /*Success*/) { - mts->dragging_position = position; - return TRUE; - } - } - - /* Convert the x coordinate into a EMeetingTimeSelectorTime. */ - e_meeting_time_selector_calculate_time (mts, x, &start_time); - start_date = &start_time.date; - end_date = &end_time.date; - - /* Find the nearest half-hour or hour interval, depending on whether - zoomed_out is set. */ - if (mts->zoomed_out) { - start_time.minute = 0; - end_time = start_time; - end_time.hour += 1; - } else { - start_time.minute -= start_time.minute % 30; - end_time = start_time; - end_time.minute += 30; - } - - /* Fix any overflows. */ - e_meeting_time_selector_fix_time_overflows (&end_time); - - /* Set the new meeting time. */ - e_meeting_time_selector_set_meeting_time (mts_item->mts, - g_date_year (start_date), - g_date_month (start_date), - g_date_day (start_date), - start_time.hour, - start_time.minute, - g_date_year (end_date), - g_date_month (end_date), - g_date_day (end_date), - end_time.hour, - end_time.minute); - - - return FALSE; -} - - -/* This handles all button release events for the item. If we were dragging, - we finish the drag. */ -static gint -e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - - mts = mts_item->mts; - - /* Reset any drag. */ - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - e_meeting_time_selector_remove_timeout (mts); - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (mts_item), - event->button.time); - } - - return FALSE; -} - - -/* This handles all motion notify events for the item. If button1 is pressed - we check if a drag is in progress. If not, we set the cursor if we are over - the meeting time vertical bars. Note that GnomeCanvas doesn't use motion - hints, which may affect performance. */ -static gint -e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorPosition position; - GdkCursor *cursor; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->motion.x; - y = (gint) event->motion.y; - - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - e_meeting_time_selector_drag_meeting_time (mts, x); - return TRUE; - } - - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - - /* Determine which cursor should be used. */ - if (position == E_MEETING_TIME_SELECTOR_POS_NONE) - cursor = mts_item->normal_cursor; - else - cursor = mts_item->resize_cursor; - - /* Only set the cursor if it is different to the last one we set. */ - if (mts_item->last_cursor_set != cursor) { - mts_item->last_cursor_set = cursor; - gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas)->window, cursor); - } - - return FALSE; -} - - -static EMeetingTimeSelectorPosition -e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, - gint x, gint y) -{ - EMeetingTimeSelector *mts; - gboolean is_display_top; - gint meeting_start_x, meeting_end_x; - - mts = mts_item->mts; - - is_display_top = (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas) == mts->display_top) ? TRUE : FALSE; - - if (is_display_top && y < mts->row_height * 2) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (!e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x)) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (x >= meeting_end_x - 2 && x <= meeting_end_x + 2) - return E_MEETING_TIME_SELECTOR_POS_END; - - if (x >= meeting_start_x - 2 && x <= meeting_start_x + 2) - return E_MEETING_TIME_SELECTOR_POS_START; - - return E_MEETING_TIME_SELECTOR_POS_NONE; -} - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-item.h b/widgets/meeting-time-sel/e-meeting-time-sel-item.h deleted file mode 100644 index c2bd2872ce..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-item.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * MeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#ifndef _E_MEETING_TIME_SELECTOR_ITEM_H_ -#define _E_MEETING_TIME_SELECTOR_ITEM_H_ - -#include "e-meeting-time-sel.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_MEETING_TIME_SELECTOR_ITEM(obj) (GTK_CHECK_CAST((obj), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItem)) -#define E_MEETING_TIME_SELECTOR_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItemClass)) -#define IS_E_MEETING_TIME_SELECTOR_ITEM(o) (GTK_CHECK_TYPE((o), e_meeting_time_selector_item_get_type ())) - - -typedef struct _EMeetingTimeSelectorItem EMeetingTimeSelectorItem; -typedef struct _EMeetingTimeSelectorItemClass EMeetingTimeSelectorItemClass; - -struct _EMeetingTimeSelectorItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EMeetingTimeSelector widget. */ - EMeetingTimeSelector *mts; - - /* This GC is used for most of the drawing. The fg/bg colors are - changed for each bit. */ - GdkGC *main_gc; - - /* The normal & resize cursors. */ - GdkCursor *normal_cursor; - GdkCursor *resize_cursor; - - /* This remembers the last cursor set on the window. */ - GdkCursor *last_cursor_set; -}; - - -struct _EMeetingTimeSelectorItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_meeting_time_selector_item_get_type (void); - - -#endif /* _E_MEETING_TIME_SELECTOR_ITEM_H_ */ diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c b/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c deleted file mode 100644 index ac4b7b9009..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c +++ /dev/null @@ -1,303 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EMeetingTimeSelectorListItem - A GnomeCanvasItem covering the entire attendee - * list. It just draws the grid lines between the rows and after the icon - * column. It probably won't be needed when we switch to Miguel's new editable - * GtkList-like widget. - */ - -#include -#include -#include "e-meeting-time-sel-list-item.h" -#include "e-meeting-time-sel.h" - -/* This is the size of our icons. */ -#define E_MEETING_TIME_SELECTOR_ICON_WIDTH 19 -#define E_MEETING_TIME_SELECTOR_ICON_HEIGHT 16 - -#include "e-meeting-time-sel-mail.xpm" -#include "e-meeting-time-sel-no-mail.xpm" - -static void e_meeting_time_selector_list_item_class_init (EMeetingTimeSelectorListItemClass *mtsl_item_class); -static void e_meeting_time_selector_list_item_init (EMeetingTimeSelectorListItem *mtsl_item); -static void e_meeting_time_selector_list_item_destroy (GtkObject *object); - -static void e_meeting_time_selector_list_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_meeting_time_selector_list_item_realize (GnomeCanvasItem *item); -static void e_meeting_time_selector_list_item_unrealize (GnomeCanvasItem *item); -static void e_meeting_time_selector_list_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_meeting_time_selector_list_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_meeting_time_selector_list_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); - - -static GnomeCanvasItemClass *e_meeting_time_selector_list_item_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MEETING_TIME_SELECTOR -}; - - -GtkType -e_meeting_time_selector_list_item_get_type (void) -{ - static GtkType e_meeting_time_selector_list_item_type = 0; - - if (!e_meeting_time_selector_list_item_type) { - GtkTypeInfo e_meeting_time_selector_list_item_info = { - "EMeetingTimeSelectorListItem", - sizeof (EMeetingTimeSelectorListItem), - sizeof (EMeetingTimeSelectorListItemClass), - (GtkClassInitFunc) e_meeting_time_selector_list_item_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_list_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_meeting_time_selector_list_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_meeting_time_selector_list_item_info); - } - - return e_meeting_time_selector_list_item_type; -} - - -static void -e_meeting_time_selector_list_item_class_init (EMeetingTimeSelectorListItemClass *mtsl_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - e_meeting_time_selector_list_item_parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) mtsl_item_class; - item_class = (GnomeCanvasItemClass *) mtsl_item_class; - - gtk_object_add_arg_type ("EMeetingTimeSelectorListItem::meeting_time_selector", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_MEETING_TIME_SELECTOR); - - object_class->destroy = e_meeting_time_selector_list_item_destroy; - object_class->set_arg = e_meeting_time_selector_list_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_meeting_time_selector_list_item_realize; - item_class->unrealize = e_meeting_time_selector_list_item_unrealize; - item_class->update = e_meeting_time_selector_list_item_update; - item_class->draw = e_meeting_time_selector_list_item_draw; - item_class->point = e_meeting_time_selector_list_item_point; -#if 0 - item_class->event = e_meeting_time_selector_list_item_event; -#endif -} - - -static void -e_meeting_time_selector_list_item_init (EMeetingTimeSelectorListItem *mtsl_item) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (mtsl_item); - GdkColormap *colormap; - - mtsl_item->mts = NULL; - - colormap = gtk_widget_get_default_colormap (); - mtsl_item->mail_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mtsl_item->mail_icon_mask, NULL, e_meeting_time_sel_mail_xpm); - mtsl_item->no_mail_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mtsl_item->no_mail_icon_mask, NULL, e_meeting_time_sel_no_mail_xpm); - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_meeting_time_selector_list_item_destroy (GtkObject *object) -{ - EMeetingTimeSelectorListItem *mtsl_item; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (object); - - gdk_pixmap_unref (mtsl_item->mail_icon); - gdk_pixmap_unref (mtsl_item->no_mail_icon); - gdk_bitmap_unref (mtsl_item->mail_icon_mask); - gdk_bitmap_unref (mtsl_item->mail_icon_mask); - - if (GTK_OBJECT_CLASS (e_meeting_time_selector_list_item_parent_class)->destroy) - (*GTK_OBJECT_CLASS (e_meeting_time_selector_list_item_parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_list_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMeetingTimeSelectorListItem *mtsl_item; - - item = GNOME_CANVAS_ITEM (o); - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (o); - - switch (arg_id){ - case ARG_MEETING_TIME_SELECTOR: - mtsl_item->mts = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_meeting_time_selector_list_item_realize (GnomeCanvasItem *item) -{ - GnomeCanvas *canvas; - GdkWindow *window; - EMeetingTimeSelectorListItem *mtsl_item; - - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->realize)(item); - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - - canvas = item->canvas; - window = GTK_WIDGET (canvas)->window; - - mtsl_item->main_gc = gdk_gc_new (window); -} - - -static void -e_meeting_time_selector_list_item_unrealize (GnomeCanvasItem *item) -{ - EMeetingTimeSelectorListItem *mtsl_item; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - - gdk_gc_unref (mtsl_item->main_gc); - mtsl_item->main_gc = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->unrealize)(item); -} - - -static void -e_meeting_time_selector_list_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_meeting_time_selector_list_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - EMeetingTimeSelectorListItem *mtsl_item; - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - GdkGC *gc; - gint row, row_y, icon_x, icon_y; - GdkPixmap *pixmap; - GdkBitmap *mask; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - mts = mtsl_item->mts; - gc = mtsl_item->main_gc; - - gdk_gc_set_foreground (gc, &mts->attendee_list_bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_line (drawable, gc, 24 - x, 0, 24 - x, height); - - /* Draw the grid line across the top of the row. */ - row = y / mts->row_height; - row_y = row * mts->row_height - y; - while (row_y < height) { - gdk_draw_line (drawable, gc, 0, row_y, width, row_y); - row_y += mts->row_height; - } - - row = y / mts->row_height; - row_y = row * mts->row_height - y; - icon_x = (E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - E_MEETING_TIME_SELECTOR_ICON_WIDTH + 1) / 2 - x; - icon_y = row_y + (mts->row_height - E_MEETING_TIME_SELECTOR_ICON_HEIGHT + 1) / 2; - while (row < mts->attendees->len && row_y < height) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - - if (attendee->send_meeting_to) { - pixmap = mtsl_item->mail_icon; - mask = mtsl_item->mail_icon_mask; - } else { - pixmap = mtsl_item->no_mail_icon; - mask = mtsl_item->no_mail_icon_mask; - } - - gdk_gc_set_clip_mask (gc, mask); - gdk_draw_pixmap (drawable, gc, pixmap, 0, 0, - icon_x, icon_y, 24, 24); - - row++; - row_y += mts->row_height; - icon_y += mts->row_height; - } - gdk_gc_set_clip_mask (gc, NULL); -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we cover the entire canvas we just return ourself and 0 for the - distance. This is needed so that we get button/motion events. */ -static double -e_meeting_time_selector_list_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h b/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h deleted file mode 100644 index 9ef295ebb2..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * MeetingTimeSelectorListItem - A GnomeCanvasItem covering the entire attendee - * list. It just draws the grid lines between the rows and after the icon - * column. It probably won't be needed when we switch to Miguel's new editable - * GtkList-like widget. - */ - -#ifndef _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ -#define _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ - -#include "e-meeting-time-sel.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_MEETING_TIME_SELECTOR_LIST_ITEM(obj) (GTK_CHECK_CAST((obj), e_meeting_time_selector_list_item_get_type (), EMeetingTimeSelectorListItem)) -#define E_MEETING_TIME_SELECTOR_LIST_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_meeting_time_selector_list_item_get_type (), EMeetingTimeSelectorListItemClass)) -#define IS_E_MEETING_TIME_SELECTOR_LIST_ITEM(o) (GTK_CHECK_TYPE((o), e_meeting_time_selector_list_item_get_type ())) - - -typedef struct _EMeetingTimeSelectorListItem EMeetingTimeSelectorListItem; -typedef struct _EMeetingTimeSelectorListItemClass EMeetingTimeSelectorListItemClass; - -struct _EMeetingTimeSelectorListItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EMeetingTimeSelector widget. */ - EMeetingTimeSelector *mts; - - /* This GC is used for most of the drawing. The fg/bg colors are - changed for each bit. */ - GdkGC *main_gc; - - GdkPixmap *mail_icon, *no_mail_icon; - GdkBitmap *mail_icon_mask, *no_mail_icon_mask; -}; - - -struct _EMeetingTimeSelectorListItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_meeting_time_selector_list_item_get_type (void); - - -#endif /* _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ */ diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm b/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm deleted file mode 100644 index 5a03c7ea8a..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm +++ /dev/null @@ -1,135 +0,0 @@ -/* XPM */ -static char * e_meeting_time_sel_mail_xpm[] = { -"19 16 116 2", -" c None", -". c #000000", -"+ c #7B7B78", -"@ c #C7C7C3", -"# c #F1F0EB", -"$ c #BFBFBC", -"% c #5F5E5E", -"& c #E3E3DF", -"* c #F3F3EF", -"= c #F2F2EE", -"- c #F1F1EC", -"; c #F0EFEB", -"> c #D2D2CD", -", c #969592", -"' c #616060", -") c #B5B5B4", -"! c #F8F8F6", -"~ c #F7F7F5", -"{ c #F6F6F3", -"] c #F5F5F2", -"^ c #F4F4F0", -"/ c #F2F1ED", -"( c #F1F0EC", -"_ c #F0EFEA", -": c #EFEEE9", -"< c #4F4F4D", -"[ c #BDBCB8", -"} c #A7A6A3", -"| c #C6C6C4", -"1 c #7C7C7B", -"2 c #525251", -"3 c #DBDBD9", -"4 c #F5F4F1", -"5 c #F4F3F0", -"6 c #F3F2EE", -"7 c #999894", -"8 c #62625F", -"9 c #BCBCB6", -"0 c #EBE9E3", -"a c #838381", -"b c #D7D6D4", -"c c #A8A8A6", -"d c #515150", -"e c #7E7D7C", -"f c #DAD9D5", -"g c #EFEEE8", -"h c #EEEDE7", -"i c #4F4E4C", -"j c #BCBBB6", -"k c #EBE9E2", -"l c #EAE8E1", -"m c #F6F5F2", -"n c #F4F3EF", -"o c #B5B4B1", -"p c #9B9A97", -"q c #646361", -"r c #92918E", -"s c #EEEDE8", -"t c #EDECE6", -"u c #4E4E4C", -"v c #797976", -"w c #797874", -"x c #E9E8E1", -"y c #E8E7DF", -"z c #B4B3AF", -"A c #D0D0CD", -"B c #F2F2ED", -"C c #BFBEBA", -"D c #BEBDB9", -"E c #7A7A77", -"F c #979691", -"G c #EAE9E2", -"H c #959590", -"I c #787773", -"J c #B8B7B0", -"K c #E6E4DC", -"L c #A9A9A6", -"M c #626260", -"N c #ECEBE4", -"O c #EBEAE3", -"P c #E9E7E0", -"Q c #E8E6DF", -"R c #E7E5DD", -"S c #777671", -"T c #93918C", -"U c #BEBDB8", -"V c #989793", -"W c #ECEAE4", -"X c #E8E6DE", -"Y c #E6E4DB", -"Z c #E4E3DA", -"` c #75746F", -" . c #91908A", -".. c #EEECE7", -"+. c #62615F", -"@. c #EBEAE4", -"#. c #E7E6DE", -"$. c #E6E5DC", -"%. c #E5E4DB", -"&. c #E4E2DA", -"*. c #CCCBC4", -"=. c #A3A29D", -"-. c #B6B5B2", -";. c #BCBCB7", -">. c #CDCCC6", -",. c #959490", -"'. c #ECEBE5", -"). c #61615E", -"!. c #E9E8E0", -"~. c #CECDC7", -"{. c #797875", -"]. c #969590", -"^. c #CFCEC8", -"/. c #AEADA8", -"(. c #585754", -"_. c #7B7A76", -" . . . . ", -" . . . . . + @ # $ . ", -" . . . . . % $ & * = - ; > , . ", -". ' ) ! ~ { ] ^ * / ( _ : < [ } . ", -". | 1 2 3 4 5 6 / # _ : 7 8 9 0 . ", -". a b c d e f / # _ g h i j k l . ", -" . m 4 n o p q r s t u v w x y z . ", -" . A * B ( ; C D E u F G H I J K . ", -" . L / ( _ : M t N O l P Q R S T . ", -" . # _ g U V W 0 l P X R Y Z ` .. ", -" . ; g ..+.@.G x y #.$.%.&.*.=.. . ", -" . -.t ;.F G x y #.K >.,.. . . ", -" . '.).G !.Q ~.H . . . ", -" . {.].^./.. . . ", -" . (._.. . ", -" . . "}; diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm b/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm deleted file mode 100644 index 747202b3e2..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm +++ /dev/null @@ -1,123 +0,0 @@ -/* XPM */ -static char * e_meeting_time_sel_no_mail_xpm[] = { -"19 16 104 2", -" c None", -". c #000000", -"+ c #7B7B78", -"@ c #C7C7C3", -"# c #F1F0EB", -"$ c #BFBFBC", -"% c #5F5E5E", -"& c #E3E3DF", -"* c #F3F3EF", -"= c #F2F2EE", -"- c #F1F1EC", -"; c #F0EFEB", -"> c #D2D2CD", -", c #969592", -"' c #616060", -") c #B5B5B4", -"! c #F8F8F6", -"~ c #F7F7F5", -"{ c #F6F6F3", -"] c #F5F5F2", -"^ c #F4F4F0", -"/ c #F2F1ED", -"( c #F1F0EC", -"_ c #F0EFEA", -": c #EFEEE9", -"< c #4F4F4D", -"[ c #BDBCB8", -"} c #A7A6A3", -"| c #C6C6C4", -"1 c #7C7C7B", -"2 c #525251", -"3 c #DBDBD9", -"4 c #F5F4F1", -"5 c #F4F3F0", -"6 c #F3F2EE", -"7 c #999894", -"8 c #62625F", -"9 c #BCBCB6", -"0 c #EBE9E3", -"a c #838381", -"b c #D7D6D4", -"c c #A8A8A6", -"d c #515150", -"e c #7E7D7C", -"f c #DAD9D5", -"g c #D16069", -"h c #EEEDE7", -"i c #4F4E4C", -"j c #BCBBB6", -"k c #F6F5F2", -"l c #F4F3EF", -"m c #B5B4B1", -"n c #9B9A97", -"o c #646361", -"p c #92918E", -"q c #9F3C44", -"r c #797976", -"s c #B5444E", -"t c #B4B3AF", -"u c #D0D0CD", -"v c #F2F2ED", -"w c #BFBEBA", -"x c #BEBDB9", -"y c #BB565F", -"z c #812F36", -"A c #E6E4DC", -"B c #A9A9A6", -"C c #626260", -"D c #EDECE6", -"E c #ECEBE4", -"F c #BB555D", -"G c #90353D", -"H c #777671", -"I c #93918C", -"J c #EFEEE8", -"K c #BEBDB8", -"L c #989793", -"M c #ECEAE4", -"N c #E6E4DB", -"O c #E4E3DA", -"P c #75746F", -"Q c #91908A", -"R c #EEECE7", -"S c #62615F", -"T c #EBEAE4", -"U c #EAE9E2", -"V c #BD5A62", -"W c #E4E2DA", -"X c #CCCBC4", -"Y c #A3A29D", -"Z c #B6B5B2", -"` c #BCBCB7", -" . c #979691", -".. c #BC5760", -"+. c #A13C45", -"@. c #ECEBE5", -"#. c #61615E", -"$. c #C0636B", -"%. c #A83F48", -"&. c #797875", -"*. c #969590", -"=. c #CFCEC8", -"-. c #585754", -";. c #7B7A76", -" . . . . ", -" . . . . . + @ # $ . ", -" . . . . . % $ & * = - ; > , . ", -". ' ) ! ~ { ] ^ * / ( _ : < [ } . ", -". | 1 2 3 4 5 6 / # _ : 7 8 9 0 . ", -". a b c d e f / # g g h i j g g . ", -" . k 4 l m n o p g q g r g s g t . ", -" . u * v ( ; w x g s g g y z g A . ", -" . B / ( _ : C D E g s F G g H I . ", -" . # _ J K L M 0 g s s g N O P Q . ", -" . ; J R S T U g V s s g W X Y . . ", -" . Z D ` .U g ..G g g +.g . . ", -" . @.#.U g $.G g . g %.g ", -" . &.*.=.g g g . g g ", -" . -.;.. . ", -" . . "}; diff --git a/widgets/meeting-time-sel/e-meeting-time-sel.c b/widgets/meeting-time-sel/e-meeting-time-sel.c deleted file mode 100644 index 86f81cc80e..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel.c +++ /dev/null @@ -1,3065 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "e-meeting-time-sel.h" -#include "e-meeting-time-sel-item.h" -#include "e-meeting-time-sel-list-item.h" - -/* An array of hour strings, "0:00" .. "23:00". */ -const gchar *EMeetingTimeSelectorHours[24] = { - "0:00", "1:00", "2:00", "3:00", "4:00", "5:00", "6:00", "7:00", - "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", - "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" -}; - -/* The number of days shown in the entire canvas. */ -#define E_MEETING_TIME_SELECTOR_DAYS_SHOWN 365 - -#define E_MEETING_TIME_SELECTOR_ENTRY_INNER_BORDER 2 - -/* This is the number of pixels between the mouse has to move before the - scroll speed is incremented. */ -#define E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH 10 - -/* This is the maximum scrolling speed. */ -#define E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED 4 - - -static void e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass); -static void e_meeting_time_selector_init (EMeetingTimeSelector * mts); -static void e_meeting_time_selector_destroy (GtkObject *object); -static void e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c); -static void e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, - GdkColor *color); -static gint e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color); -static gint e_meeting_time_selector_expose_title_bar (GtkWidget *darea, - GdkEventExpose *event, - gpointer data); -static void e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_realize (GtkWidget *widget); -static void e_meeting_time_selector_unrealize (GtkWidget *widget); -static void e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static gint e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts); - -static gint e_meeting_time_selector_compare_period_starts (const void *arg1, - const void *arg2); -#if 0 -static gint e_meeting_time_selector_compare_periods (const void *arg1, - const void *arg2); -#endif -static gint e_meeting_time_selector_compare_times (EMeetingTimeSelectorTime *time1, - EMeetingTimeSelectorTime *time2); -static void e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data); -static void e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_working_hours_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data); -static void e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward); -static void e_meeting_time_selector_calculate_time_difference (EMeetingTimeSelectorTime *start, - EMeetingTimeSelectorTime *end, - gint *days, - gint *hours, - gint *minutes); -static void e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_adjust_time (EMeetingTimeSelectorTime *mtstime, - gint days, gint hours, gint minutes); -static EMeetingTimeSelectorPeriod* e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time); - - -static void e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); -static void e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); -static void e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_attendees_list_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_attendees_list_scroll_region (EMeetingTimeSelector *mts); -static gboolean e_meeting_time_selector_timeout_handler (gpointer data); -static void e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_update_attendees_list_positions (EMeetingTimeSelector *mts); - -static GtkTableClass *e_meeting_time_selector_parent_class; - - -GtkType -e_meeting_time_selector_get_type (void) -{ - static guint e_meeting_time_selector_type = 0; - - if (!e_meeting_time_selector_type) { - GtkTypeInfo e_meeting_time_selector_info = - { - "EMeetingTimeSelector", - sizeof (EMeetingTimeSelector), - sizeof (EMeetingTimeSelectorClass), - (GtkClassInitFunc) e_meeting_time_selector_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - e_meeting_time_selector_type = gtk_type_unique (GTK_TYPE_TABLE, - &e_meeting_time_selector_info); - } - return e_meeting_time_selector_type; -} - - -static void -e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - e_meeting_time_selector_parent_class = gtk_type_class (gtk_table_get_type()); - - object_class = (GtkObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - object_class->destroy = e_meeting_time_selector_destroy; - - widget_class->realize = e_meeting_time_selector_realize; - widget_class->unrealize = e_meeting_time_selector_unrealize; - widget_class->style_set = e_meeting_time_selector_style_set; - widget_class->expose_event = e_meeting_time_selector_expose_event; -} - - -static void -e_meeting_time_selector_init (EMeetingTimeSelector * mts) -{ - GtkWidget *hbox, *separator, *button, *label, *table; - GtkWidget *alignment, *child_hbox, *arrow, *menuitem; - GSList *group; - GdkVisual *visual; - GdkColormap *colormap; - guint accel_key; - GtkAccelGroup *menu_accel_group; - time_t meeting_start_time; - struct tm *meeting_start_tm; - guchar stipple_bits[] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - }; - - mts->accel_group = gtk_accel_group_new (); - - mts->attendees = g_array_new (FALSE, FALSE, - sizeof (EMeetingTimeSelectorAttendee)); - - mts->working_hours_only = TRUE; - mts->day_start_hour = 9; - mts->day_start_minute = 0; - mts->day_end_hour = 18; - mts->day_end_minute = 0; - mts->zoomed_out = FALSE; - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - - /* The default meeting time is the nearest half-hour interval in the - future, in working hours. */ - meeting_start_time = time (NULL); - g_date_clear (&mts->meeting_start_time.date, 1); - g_date_set_time (&mts->meeting_start_time.date, meeting_start_time); - meeting_start_tm = localtime (&meeting_start_time); - mts->meeting_start_time.hour = meeting_start_tm->tm_hour; - mts->meeting_start_time.minute = meeting_start_tm->tm_min; - - e_meeting_time_selector_find_nearest_interval (mts, &mts->meeting_start_time, - &mts->meeting_end_time, - 0, 0, 30); - - e_meeting_time_selector_update_dates_shown (mts); - - mts->meeting_positions_valid = FALSE; - - mts->row_height = 30; - mts->col_width = 50; - mts->day_width = 50 * 24 + 1; - - mts->auto_scroll_timeout_id = 0; - - - mts->attendees_title_bar_vbox = gtk_vbox_new (FALSE, 2); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), - mts->attendees_title_bar_vbox, - 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 2, 0); - gtk_widget_show (mts->attendees_title_bar_vbox); - - mts->attendees_title_bar = gtk_drawing_area_new (); - gtk_box_pack_end (GTK_BOX (mts->attendees_title_bar_vbox), - mts->attendees_title_bar, FALSE, FALSE, 0); - gtk_widget_show (mts->attendees_title_bar); - gtk_signal_connect (GTK_OBJECT (mts->attendees_title_bar), - "expose_event", - GTK_SIGNAL_FUNC (e_meeting_time_selector_expose_title_bar), mts); - - mts->attendees_list = gnome_canvas_new (); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->attendees_list, - 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (mts->attendees_list); - gtk_signal_connect (GTK_OBJECT (mts->attendees_list), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - gtk_signal_connect (GTK_OBJECT (mts->attendees_list), "size_allocate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_attendees_list_size_allocate), mts); - - /* Create the item in the list canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->attendees_list)->root), - e_meeting_time_selector_list_item_get_type (), - "EMeetingTimeSelectorListItem::meeting_time_selector", mts, - NULL); - - mts->display_top = gnome_canvas_new (); - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_top, - 1, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 0); - gtk_widget_show (mts->display_top); - gtk_signal_connect (GTK_OBJECT (mts->display_top), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - - mts->display_main = gnome_canvas_new (); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_main, - 1, 4, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (mts->display_main); - gtk_signal_connect (GTK_OBJECT (mts->display_main), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - gtk_signal_connect (GTK_OBJECT (mts->display_main), "size_allocate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_size_allocate), mts); - - mts->hscrollbar = gtk_hscrollbar_new (GTK_LAYOUT (mts->display_main)->hadjustment); - gtk_table_attach (GTK_TABLE (mts), mts->hscrollbar, - 1, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->hscrollbar); - - mts->vscrollbar = gtk_vscrollbar_new (GTK_LAYOUT (mts->display_main)->vadjustment); - gtk_table_attach (GTK_TABLE (mts), mts->vscrollbar, - 4, 5, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (mts->vscrollbar); - - /* Create the item in the top canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_top)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the item in the main canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_main)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the hbox containing the color key. */ - hbox = gtk_hbox_new (FALSE, 2); - gtk_table_attach (GTK_TABLE (mts), hbox, - 1, 4, 3, 4, GTK_FILL, 0, 0, 8); - gtk_widget_show (hbox); - - e_meeting_time_selector_add_key_color (mts, hbox, _("Tentative"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Busy"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_BUSY]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Out of Office"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("No Information"), - NULL); - - separator = gtk_hseparator_new (); - gtk_table_attach (GTK_TABLE (mts), separator, - 0, 5, 4, 5, GTK_FILL, 0, 0, 0); - gtk_widget_show (separator); - - /* Create the Invite Others & Options buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 4); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 3, 4, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_Invite Others...")); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_invite_others_button_clicked), mts); - - mts->options_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->options_button, TRUE, TRUE, 0); - gtk_widget_show (mts->options_button); - - gtk_signal_connect (GTK_OBJECT (mts->options_button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_options_button_clicked), mts); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->options_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Options")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->options_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 2); - gtk_widget_show (arrow); - - /* Create the Options menu. */ - mts->options_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->options_menu), mts->options_button, - e_meeting_time_selector_options_menu_detacher); - menu_accel_group = gtk_menu_ensure_uline_accel_group (GTK_MENU (mts->options_menu)); - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Only Working Hours")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->working_hours_only); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_working_hours_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Zoomed Out")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->zoomed_out); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_zoomed_out_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new (); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Update Free/Busy")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_update_free_busy), mts); - gtk_widget_show (menuitem); - - /* Create the 3 AutoPick buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_<<")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_prev_button_clicked), mts); - - mts->autopick_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->autopick_button, TRUE, TRUE, 0); - gtk_widget_show (mts->autopick_button); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->autopick_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Autopick")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->autopick_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (mts->autopick_button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_button_clicked), mts); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 2); - gtk_widget_show (arrow); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _(">_>")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_next_button_clicked), mts); - - /* Create the Autopick menu. */ - mts->autopick_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->autopick_menu), mts->autopick_button, - e_meeting_time_selector_autopick_menu_detacher); - menu_accel_group = gtk_menu_ensure_uline_accel_group (GTK_MENU (mts->autopick_menu)); - - menuitem = gtk_radio_menu_item_new_with_label (NULL, ""); - mts->autopick_all_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_All People and Resources")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_all_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("All _People and One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Required People")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Required People and _One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - /* Create the date entry fields on the right. */ - alignment = gtk_alignment_new (0.5, 0.5, 0, 0); - gtk_table_attach (GTK_TABLE (mts), alignment, - 1, 4, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (alignment); - - table = gtk_table_new (2, 2, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - gtk_widget_show (table); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _start time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 0, 1, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->start_date_edit = gnome_date_edit_new (0, TRUE, TRUE); - /* I don't like the 'Calendar' label. */ - gtk_widget_hide (GNOME_DATE_EDIT (mts->start_date_edit)->cal_label); - gtk_table_attach (GTK_TABLE (table), mts->start_date_edit, - 1, 2, 0, 1, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->start_date_edit); - gtk_signal_connect (GTK_OBJECT (mts->start_date_edit), "date_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (mts->start_date_edit), "time_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->start_date_edit)->date_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->start_date_edit)->time_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_widget_add_accelerator (GNOME_DATE_EDIT (mts->start_date_edit)->date_entry, - "grab_focus", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _end time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 1, 2, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->end_date_edit = gnome_date_edit_new (0, TRUE, TRUE); - gtk_widget_hide (GNOME_DATE_EDIT (mts->end_date_edit)->cal_label); - gtk_table_attach (GTK_TABLE (table), mts->end_date_edit, - 1, 2, 1, 2, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->end_date_edit); - gtk_signal_connect (GTK_OBJECT (mts->end_date_edit), "date_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (mts->end_date_edit), "time_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->end_date_edit)->date_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->end_date_edit)->time_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_widget_add_accelerator (GNOME_DATE_EDIT (mts->end_date_edit)->date_entry, - "grab_focus", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - gtk_table_set_col_spacing (GTK_TABLE (mts), 0, 4); - gtk_table_set_row_spacing (GTK_TABLE (mts), 4, 12); - - /* Allocate the colors. */ - visual = gtk_widget_get_visual (GTK_WIDGET (mts)); - colormap = gtk_widget_get_colormap (GTK_WIDGET (mts)); - mts->color_context = gdk_color_context_new (visual, colormap); - e_meeting_time_selector_alloc_named_color (mts, "gray75", &mts->bg_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->all_attendees_bg_color); - gdk_color_black (colormap, &mts->grid_color); - gdk_color_white (colormap, &mts->grid_shadow_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->grid_unused_color); - gdk_color_white (colormap, &mts->meeting_time_bg_color); - gdk_color_white (colormap, &mts->stipple_bg_color); - gdk_color_white (colormap, &mts->attendee_list_bg_color); - - e_meeting_time_selector_alloc_named_color (mts, "LightSkyBlue2", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE]); - e_meeting_time_selector_alloc_named_color (mts, "blue", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_BUSY]); - e_meeting_time_selector_alloc_named_color (mts, "HotPink3", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE]); - - /* Create the stipple, for attendees with no data. */ - mts->stipple = gdk_bitmap_create_from_data (NULL, (gchar*)stipple_bits, - 8, 8); - - /* Connect handlers to the adjustments in the main canvas, so we can - scroll the other 2 canvases. */ - gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (mts->display_main)->hadjustment), "value_changed", GTK_SIGNAL_FUNC (e_meeting_time_selector_hadjustment_changed), mts); - gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (mts->display_main)->vadjustment), "value_changed", GTK_SIGNAL_FUNC (e_meeting_time_selector_vadjustment_changed), mts); - - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_ensure_meeting_time_shown (mts); - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -/* This adds a color to the color key beneath the main display. If color is - NULL, it displays the No Info stipple instead. */ -static void -e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, GdkColor *color) -{ - GtkWidget *child_hbox, *darea, *label; - - child_hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), child_hbox, TRUE, TRUE, 0); - gtk_widget_show (child_hbox); - - darea = gtk_drawing_area_new (); - gtk_box_pack_start (GTK_BOX (child_hbox), darea, FALSE, FALSE, 0); - gtk_object_set_user_data (GTK_OBJECT (darea), mts); - gtk_widget_set_usize (darea, 14, 14); - gtk_widget_show (darea); - - label = gtk_label_new (label_text); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - - gtk_signal_connect (GTK_OBJECT (darea), "expose_event", - GTK_SIGNAL_FUNC (e_meeting_time_selector_expose_key_color), - color); -} - - -static gint -e_meeting_time_selector_expose_title_bar (GtkWidget *widget, - GdkEventExpose *event, - gpointer data) -{ - EMeetingTimeSelector * mts; - GdkFont *font; - - mts = E_MEETING_TIME_SELECTOR (data); - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_OUT, 0, 0, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 1, - widget->allocation.height); - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_OUT, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 1, 0, - widget->allocation.width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - 1, - widget->allocation.height); - - font = widget->style->font; - gdk_draw_string (widget->window, font, - widget->style->fg_gc[GTK_STATE_NORMAL], - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 4, - 4 + font->ascent, _("All Attendees")); - - return FALSE; -} - - -static gint -e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color) -{ - EMeetingTimeSelector * mts; - GdkGC *gc; - gint width, height; - - mts = gtk_object_get_user_data (GTK_OBJECT (darea)); - gc = mts->color_key_gc; - width = darea->allocation.width; - height = darea->allocation.height; - - gtk_draw_shadow (darea->style, darea->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, 0, 0, width, height); - - if (color) { - gdk_gc_set_foreground (gc, color); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - } else { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_background (gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (gc, mts->stipple); - gdk_gc_set_fill (gc, GDK_OPAQUE_STIPPLED); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - gdk_gc_set_fill (gc, GDK_SOLID); - } - - return TRUE; -} - - -static void -e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c) -{ - int failed; - - g_return_if_fail (name != NULL); - g_return_if_fail (c != NULL); - - gdk_color_parse (name, c); - c->pixel = 0; - c->pixel = gdk_color_context_get_pixel (mts->color_context, - c->red, c->green, c->blue, - &failed); - if (failed) - g_warning ("Failed to allocate color: %s\n", name); -} - - -static void -e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->options_menu == (GtkWidget*) menu); - - mts->options_menu = NULL; -} - - -static void -e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->autopick_menu == (GtkWidget*) menu); - - mts->autopick_menu = NULL; -} - - -GtkWidget * -e_meeting_time_selector_new (void) -{ - GtkWidget *mts; - - mts = GTK_WIDGET (gtk_type_new (e_meeting_time_selector_get_type ())); - - return mts; -} - - -static void -e_meeting_time_selector_destroy (GtkObject *object) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - gint row; - - mts = E_MEETING_TIME_SELECTOR (object); - - e_meeting_time_selector_remove_timeout (mts); - - gdk_color_context_free (mts->color_context); - gdk_bitmap_unref (mts->stipple); - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_free (attendee->name); - g_array_free (attendee->busy_periods, TRUE); - } - - g_array_free (mts->attendees, TRUE); - - if (GTK_OBJECT_CLASS (e_meeting_time_selector_parent_class)->destroy) - (*GTK_OBJECT_CLASS (e_meeting_time_selector_parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_realize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - if (GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->realize) - (*GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->realize)(widget); - - mts = E_MEETING_TIME_SELECTOR (widget); - - mts->color_key_gc = gdk_gc_new (widget->window); -} - - -static void -e_meeting_time_selector_unrealize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - gdk_gc_unref (mts->color_key_gc); - mts->color_key_gc = NULL; - - if (GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->unrealize) - (*GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->unrealize)(widget); -} - - -static void -e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime saved_time; - GdkFont *font; - gint hour, max_hour_width; - - if (GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->style_set) - (*GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->style_set)(widget, previous_style); - - mts = E_MEETING_TIME_SELECTOR (widget); - font = widget->style->font; - - /* Calculate the widths of the hour strings in the style's font. */ - max_hour_width = 0; - for (hour = 0; hour < 24; hour++) { - mts->hour_widths[hour] = gdk_string_width (font, EMeetingTimeSelectorHours[hour]); - max_hour_width = MAX (max_hour_width, mts->hour_widths[hour]); - } - - /* The row height really depends on the requested height of the - GtkEntry widgets in the list on the left, so we really need to - call size_request on them, AFTER their style has been set. */ - /* FIXME: This uses the default style ythickness of 2, though it won't - be needed when we switch to Miguel's new editable GtkCList widget - so I won't worry about it. */ - mts->row_height = font->ascent + font->descent - + E_MEETING_TIME_SELECTOR_ENTRY_INNER_BORDER * 2 - + 2 * 2; - mts->col_width = max_hour_width + 4; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_set_usize (mts->display_top, -1, mts->row_height * 3); - gtk_widget_set_usize (mts->attendees_title_bar, -1, mts->row_height); - - GTK_LAYOUT (mts->display_main)->hadjustment->step_increment = mts->col_width; - GTK_LAYOUT (mts->display_main)->vadjustment->step_increment = mts->row_height; -} - - -/* This draws a shadow around the top display and main display. */ -static gint -e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - EMeetingTimeSelector *mts; - gint x, y, w, h; - - mts = E_MEETING_TIME_SELECTOR (widget); - - /* Draw the shadow around the attendees title bar and list. */ - x = mts->attendees_title_bar->allocation.x - 2; - y = mts->attendees_title_bar->allocation.y - 2; - w = mts->attendees_title_bar->allocation.width + 4; - h = mts->attendees_title_bar->allocation.height + mts->attendees_list->allocation.height + 4; - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, x, y, w, h); - - /* Draw the shadow around the graphical displays. */ - x = mts->display_top->allocation.x - 2; - y = mts->display_top->allocation.y - 2; - w = mts->display_top->allocation.width + 4; - h = mts->display_top->allocation.height + mts->display_main->allocation.height + 4; - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, x, y, w, h); - - if (GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->expose_event) - (*GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->expose_event)(widget, event); - - return FALSE; -} - - -/* When the main canvas scrolls, we scroll the other canvases. */ -static void -e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->display_top)->hadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); - } -} - - -static void -e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->attendees_list)->vadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); - } -} - - -void -e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute) -{ - *start_year = g_date_year (&mts->meeting_start_time.date); - *start_month = g_date_month (&mts->meeting_start_time.date); - *start_day = g_date_day (&mts->meeting_start_time.date); - *start_hour = mts->meeting_start_time.hour; - *start_minute = mts->meeting_start_time.minute; - - *end_year = g_date_year (&mts->meeting_end_time.date); - *end_month = g_date_month (&mts->meeting_end_time.date); - *end_day = g_date_day (&mts->meeting_end_time.date); - *end_hour = mts->meeting_end_time.hour; - *end_minute = mts->meeting_end_time.minute; -} - - -gboolean -e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute) -{ - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year) - || !g_date_valid_dmy (end_day, end_month, end_year) - || start_hour < 0 || start_hour > 23 - || end_hour < 0 || end_hour > 23 - || start_minute < 0 || start_minute > 59 - || end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_set_dmy (&mts->meeting_start_time.date, start_day, start_month, - start_year); - mts->meeting_start_time.hour = start_hour; - mts->meeting_start_time.minute = start_minute; - g_date_set_dmy (&mts->meeting_end_time.date, end_day, end_month, - end_year); - mts->meeting_end_time.hour = end_hour; - mts->meeting_end_time.minute = end_minute; - - mts->meeting_positions_valid = FALSE; - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the GnomeDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - - return TRUE; -} - - -void -e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->working_hours_only == working_hours_only) - return; - - mts->working_hours_only = working_hours_only; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->day_start_hour == day_start_hour - && mts->day_start_minute == day_start_minute - && mts->day_end_hour == day_end_hour - && mts->day_end_minute == day_end_minute) - return; - - mts->day_start_hour = day_start_hour; - mts->day_start_minute = day_start_minute; - mts->day_end_hour = day_end_hour; - mts->day_end_minute = day_end_minute; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->zoomed_out == zoomed_out) - return; - - mts->zoomed_out = zoomed_out; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -EMeetingTimeSelectorAutopickOption -e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts) -{ - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES; - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE; - if (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item)->active) - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE; - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE; -} - - -void -e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option) -{ - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - switch (autopick_option) { - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_one_resource_item), TRUE); - break; - } -} - - -/* Adds an attendee to the list, returning the row. The data is meant for - something like an address book id, though if the user edits the name this - will become invalid. We'll probably have to handle address book lookup - ourself. */ -gint -e_meeting_time_selector_attendee_add (EMeetingTimeSelector *mts, - gchar *attendee_name, - gpointer data) -{ - EMeetingTimeSelectorAttendee attendee; - GtkWidget *entry; - gint list_width, item_width; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (attendee_name != NULL, -1); - - attendee.name = g_strdup (attendee_name); - attendee.type = E_MEETING_TIME_SELECTOR_REQUIRED_PERSON; - attendee.has_calendar_info = FALSE; - attendee.send_meeting_to = TRUE; - attendee.busy_periods = g_array_new (FALSE, FALSE, - sizeof (EMeetingTimeSelectorPeriod)); - attendee.busy_periods_sorted = TRUE; - attendee.longest_period_in_days = 0; - attendee.data = data; - - /* Add to the list on the left. */ - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), attendee_name); - gtk_widget_show (entry); - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - item_width = MAX (1, list_width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH); - attendee.text_item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->attendees_list)->root), - gnome_canvas_widget_get_type (), - "GnomeCanvasWidget::widget", entry, - "GnomeCanvasWidget::size_pixels", TRUE, - "GnomeCanvasWidget::x", (gdouble) E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH, - "GnomeCanvasWidget::y", (gdouble) (mts->attendees->len * mts->row_height), - "GnomeCanvasWidget::width", (gdouble) item_width, - "GnomeCanvasWidget::height", (gdouble) mts->row_height, - NULL); - gnome_canvas_item_hide (attendee.text_item); - - g_array_append_val (mts->attendees, attendee); - - /* Update the scroll region. */ - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - /* Redraw the canvases. */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - - return mts->attendees->len - 1; -} - - -gint -e_meeting_time_selector_attendee_find_by_name (EMeetingTimeSelector *mts, - gchar *attendee_name, - gint start_row) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (start_row >= 0, -1); - g_return_val_if_fail (start_row < mts->attendees->len, -1); - - for (row = start_row; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (!strcmp (attendee->name, attendee_name)) - return row; - } - - return -1; -} - - -gint -e_meeting_time_selector_attendee_find_by_data (EMeetingTimeSelector *mts, - gpointer data, - gint start_row) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (start_row >= 0, -1); - g_return_val_if_fail (start_row < mts->attendees->len, -1); - - for (row = start_row; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (attendee->data == data) - return row; - } - - return -1; -} - - -void -e_meeting_time_selector_attendee_remove (EMeetingTimeSelector *mts, - gint row) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - g_free (attendee->name); - g_array_free (attendee->busy_periods, TRUE); - - /* Destroy the GtkEntry in the list. */ - gtk_object_destroy (GTK_OBJECT (attendee->text_item)); - - g_array_remove_index (mts->attendees, row); - - /* Update the positions of all the other GtkEntry widgets. */ - e_meeting_time_selector_update_attendees_list_positions (mts); - - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -void -e_meeting_time_selector_attendee_set_type (EMeetingTimeSelector *mts, - gint row, - EMeetingTimeSelectorAttendeeType type) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->type = type; -} - - -void -e_meeting_time_selector_attendee_set_has_calendar_info (EMeetingTimeSelector *mts, - gint row, - gboolean has_calendar_info) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->has_calendar_info = has_calendar_info; -} - - -void -e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->send_meeting_to = send_meeting_to; -} - - -/* Clears all busy times for the given attendee. */ -void -e_meeting_time_selector_attendee_clear_busy_periods (EMeetingTimeSelector *mts, - gint row) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - g_array_set_size (attendee->busy_periods, 0); - attendee->busy_periods_sorted = TRUE; - attendee->longest_period_in_days = 0; -} - - -/* Adds one busy time for the given attendee. It returns FALSE if the date - or time is invalid. Months and days count from 1. */ -gboolean -e_meeting_time_selector_attendee_add_busy_period (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingTimeSelectorBusyType busy_type) -{ - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod period; - gint period_in_days; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - g_return_val_if_fail (row >= 0, FALSE); - g_return_val_if_fail (row < mts->attendees->len, FALSE); - g_return_val_if_fail (busy_type >= 0, FALSE); - g_return_val_if_fail (busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST, FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year)) - return FALSE; - if (!g_date_valid_dmy (end_day, end_month, end_year)) - return FALSE; - if (start_hour < 0 || start_hour > 23) - return FALSE; - if (end_hour < 0 || end_hour > 23) - return FALSE; - if (start_minute < 0 || start_minute > 59) - return FALSE; - if (end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_clear (&period.start.date, 1); - g_date_clear (&period.end.date, 1); - g_date_set_dmy (&period.start.date, start_day, start_month, start_year); - g_date_set_dmy (&period.end.date, end_day, end_month, end_year); - period.start.hour = start_hour; - period.start.minute = start_minute; - period.end.hour = end_hour; - period.end.minute = end_minute; - period.busy_type = busy_type; - - /* Check that the start time is before or equal to the end time. */ - if (e_meeting_time_selector_compare_times (&period.start, &period.end) > 0) - return FALSE; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_array_append_val (attendee->busy_periods, period); - attendee->has_calendar_info = TRUE; - attendee->busy_periods_sorted = FALSE; - - period_in_days = g_date_julian (&period.end.date) - g_date_julian (&period.start.date) + 1; - attendee->longest_period_in_days = MAX (attendee->longest_period_in_days, period_in_days); - - return TRUE; -} - - -void -e_meeting_time_selector_attendee_ensure_periods_sorted (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee) -{ - if (attendee->busy_periods_sorted) - return; - - qsort (attendee->busy_periods->data, attendee->busy_periods->len, - sizeof (EMeetingTimeSelectorPeriod), - e_meeting_time_selector_compare_period_starts); - attendee->busy_periods_sorted = TRUE; -} - - -/* This compares two time periods, using their end times. */ -static gint -e_meeting_time_selector_compare_period_starts (const void *arg1, - const void *arg2) -{ - EMeetingTimeSelectorPeriod *period1, *period2; - - period1 = (EMeetingTimeSelectorPeriod *) arg1; - period2 = (EMeetingTimeSelectorPeriod *) arg2; - - return e_meeting_time_selector_compare_times (&period1->start, - &period2->start); -} - - -/* This compares two time periods, using start and end times, mainly to see if - they overlap at all. If they overlap it returns 0. Or -1 if arg1 < arg2. - Or 1 if arg1 > arg2. */ -/* Currently unused. */ -#if 0 -static gint -e_meeting_time_selector_compare_periods (const void *arg1, - const void *arg2) -{ - EMeetingTimeSelectorPeriod *period1, *period2; - - period1 = (EMeetingTimeSelectorPeriod *) arg1; - period2 = (EMeetingTimeSelectorPeriod *) arg2; - - /* If period 2 starts after period 1 ends, return 1. */ - if (e_meeting_time_selector_compare_times (&period2->start, &period1->end) >= 0) - return 1; - - /* If period 1 starts after period 2 ends, return -1. */ - if (e_meeting_time_selector_compare_times (&period1->start, &period2->end) >= 0) - return -1; - - /* They must overlap so return 0. */ - return 0; -} -#endif - - -static gint -e_meeting_time_selector_compare_times (EMeetingTimeSelectorTime *time1, - EMeetingTimeSelectorTime *time2) -{ - gint day_comparison; - - day_comparison = g_date_compare (&time1->date, - &time2->date); - if (day_comparison != 0) - return day_comparison; - - if (time1->hour < time2->hour) - return -1; - if (time1->hour > time2->hour) - return 1; - - if (time1->minute < time2->minute) - return -1; - if (time1->minute > time2->minute) - return 1; - - /* The start times are exactly the same. */ - return 0; -} - - -/* - * DEBUGGING ROUTINES - functions to output various bits of data. - */ - -#ifdef E_MEETING_TIME_SELECTOR_DEBUG - -/* Debugging function to dump information on all attendees. */ -void -e_meeting_time_selector_dump (EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - gint row, period_num; - gchar buffer[128]; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - g_print ("\n\nAttendee Information:\n"); - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_print ("Attendee: %s\n", attendee->name); - g_print (" Longest Busy Period: %i days\n", - attendee->longest_period_in_days); - - e_meeting_time_selector_attendee_ensure_periods_sorted (mts, attendee); -#if 1 - for (period_num = 0; - period_num < attendee->busy_periods->len; - period_num++) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, - period_num); - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", - &period->start.date); - g_print (" Start: %s %i:%02i\n", buffer, - period->start.hour, period->start.minute); - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", - &period->end.date); - g_print (" End : %s %i:%02i\n", buffer, - period->end.hour, period->end.minute); - } -#endif - } - -} - - -/* This formats a EMeetingTimeSelectorTime in a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_time (EMeetingTimeSelectorTime *mtstime) -{ - static gchar buffer[128]; - - gchar buffer2[128]; - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", &mtstime->date); - sprintf (buffer2, " at %i:%02i", (gint) mtstime->hour, - (gint) mtstime->minute); - strcat (buffer, buffer2); - - return buffer; -} - - -/* This formats a GDate in a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_date (GDate *date) -{ - static gchar buffer[128]; - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", date); - return buffer; -} - -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -static void -e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - - -} - - -static void -e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->options_menu), NULL, NULL, - e_meeting_time_selector_options_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->options_button->window, x, y); - *y += mts->options_button->allocation.height; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->options_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - - -static void -e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); -} - - -static void -e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->autopick_menu), NULL, NULL, - e_meeting_time_selector_autopick_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->autopick_button->window, x, y); - *y += mts->autopick_button->allocation.height; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->autopick_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - - -static void -e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->autopick_menu)) - gtk_menu_popdown (GTK_MENU (mts->autopick_menu)); -} - - -static void -e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, FALSE); -} - - -static void -e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, TRUE); -} - - -/* This tries to find the previous or next meeting time for which all - attendees will be available. */ -static void -e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward) -{ - EMeetingTimeSelectorTime start_time, end_time, *resource_free; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - EMeetingTimeSelectorAutopickOption autopick_option; - gint duration_days, duration_hours, duration_minutes, row; - gboolean meeting_time_ok, skip_optional = FALSE; - gboolean need_one_resource = FALSE, found_resource; - - /* Get the current meeting duration in days + hours + minutes. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Find the first appropriate start time. */ - start_time = mts->meeting_start_time; - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - - /* Determine if we can skip optional people and if we only need one - resource based on the autopick option. */ - autopick_option = e_meeting_time_selector_get_autopick_option (mts); - if (autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - skip_optional = TRUE; - if (autopick_option == E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - need_one_resource = TRUE; - - /* Keep moving forward or backward until we find a possible meeting - time. */ - for (;;) { - meeting_time_ok = TRUE; - found_resource = FALSE; - resource_free = NULL; - - /* Step through each attendee, checking if the meeting time - intersects one of the attendees busy periods. */ - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, - row); - - /* Skip optional people if they don't matter. */ - if (skip_optional && attendee->type == E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON) - continue; - - period = e_meeting_time_selector_find_time_clash (mts, attendee, &start_time, &end_time); - - if (need_one_resource && attendee->type == E_MEETING_TIME_SELECTOR_RESOURCE) { - if (period) { - /* We want to remember the closest - prev/next time that one resource is - available, in case we don't find any - free resources. */ - if (forward) { - if (!resource_free || e_meeting_time_selector_compare_times (resource_free, &period->end) > 0) - resource_free = &period->end; - } else { - if (!resource_free || e_meeting_time_selector_compare_times (resource_free, &period->start) < 0) - resource_free = &period->start; - } - - } else { - found_resource = TRUE; - } - } else if (period) { - /* Skip the period which clashed. */ - if (forward) { - start_time = period->end; - } else { - start_time = period->start; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - break; - } - } - - /* Check that we found one resource if necessary. If not, skip - to the closest time that a resource is free. Note that if - there are no resources, resource_free will never get set, - so we assume the meeting time is OK. */ - if (meeting_time_ok && need_one_resource && !found_resource - && resource_free) { - if (forward) { - start_time = *resource_free; - } else { - start_time = *resource_free; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - } - - if (meeting_time_ok) { - mts->meeting_start_time = start_time; - mts->meeting_end_time = end_time; - mts->meeting_positions_valid = FALSE; - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Make sure the time is shown. */ - e_meeting_time_selector_ensure_meeting_time_shown (mts); - - /* Set the times in the GnomeDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - return; - } - - /* Move forward to the next possible interval. */ - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - } -} - - -static void -e_meeting_time_selector_calculate_time_difference (EMeetingTimeSelectorTime *start, - EMeetingTimeSelectorTime *end, - gint *days, - gint *hours, - gint *minutes) -{ - *days = g_date_julian (&end->date) - g_date_julian (&start->date); - *hours = end->hour - start->hour; - *minutes = end->minute - start->minute; - if (*minutes < 0) { - *minutes += 60; - *hours = *hours - 1; - } - if (*hours < 0) { - *hours += 24; - *days = *days - 1; - } -} - - -/* This moves the given time forward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins) -{ - gint minutes_shown; - gboolean set_to_start_of_working_day = FALSE; - - if (mts->zoomed_out) { - start_time->hour++; - start_time->minute = 0; - } else { - start_time->minute += 30; - start_time->minute -= start_time->minute % 30; - } - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - onto the start of the next working day. If the meeting time starts - before the working day, move it on as well. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - g_date_add_days (&start_time->date, 1); - set_to_start_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - set_to_start_of_working_day = TRUE; - } - - if (set_to_start_of_working_day) { - start_time->hour = mts->day_start_hour; - start_time->minute = mts->day_start_minute; - - if (mts->zoomed_out) { - if (start_time->minute > 0) { - start_time->hour++; - start_time->minute = 0; - } - } else { - start_time->minute += 29; - start_time->minute -= start_time->minute % 30; - } - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This moves the given time backward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins) -{ - gint new_hour, minutes_shown; - gboolean set_to_end_of_working_day = FALSE; - - new_hour = start_time->hour; - if (mts->zoomed_out) { - if (start_time->minute == 0) - new_hour--; - start_time->minute = 0; - } else { - if (start_time->minute == 0) { - start_time->minute = 30; - new_hour--; - } else if (start_time->minute <= 30) - start_time->minute = 0; - else - start_time->minute = 30; - } - if (new_hour < 0) { - new_hour += 24; - g_date_subtract_days (&start_time->date, 1); - } - start_time->hour = new_hour; - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - back to the end of the working day. If the meeting time starts - before the working day, move it back to the end of the previous - working day. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - set_to_end_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - g_date_subtract_days (&end_time->date, 1); - set_to_end_of_working_day = TRUE; - } - - if (set_to_end_of_working_day) { - end_time->hour = mts->day_end_hour; - end_time->minute = mts->day_end_minute; - *start_time = *end_time; - e_meeting_time_selector_adjust_time (start_time, -days, -hours, -mins); - - if (mts->zoomed_out) { - start_time->minute = 0; - } else { - start_time->minute -= start_time->minute % 30; - } - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This adds on the given days, hours & minutes to a EMeetingTimeSelectorTime. - It is used to calculate the end of a period given a start & duration. - Days, hours & minutes can be negative, to move backwards, but they should - be within normal ranges, e.g. hours should be between -23 and 23. */ -static void -e_meeting_time_selector_adjust_time (EMeetingTimeSelectorTime *mtstime, - gint days, gint hours, gint minutes) -{ - gint new_hours, new_minutes; - - /* We have to handle negative values for hous and minutes here, since - EMeetingTimeSelectorTime uses guint8s to store them. */ - new_minutes = mtstime->minute + minutes; - if (new_minutes < 0) { - new_minutes += 60; - hours -= 1; - } - - new_hours = mtstime->hour + hours; - if (new_hours < 0) { - new_hours += 24; - days -= 1; - } - - g_date_add_days (&mtstime->date, days); - mtstime->hour = new_hours; - mtstime->minute = new_minutes; - - e_meeting_time_selector_fix_time_overflows (mtstime); -} - - -/* This looks for any busy period of the given attendee which clashes with - the start and end time. It uses a binary search. */ -static EMeetingTimeSelectorPeriod* -e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time) -{ - EMeetingTimeSelectorPeriod *period; - gint period_num; - - period_num = e_meeting_time_selector_find_first_busy_period (mts, attendee, &start_time->date); - - if (period_num == -1) - return NULL; - - /* Step forward through the busy periods until we find a clash or we - go past the end_time. */ - while (period_num < attendee->busy_periods->len) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, - period_num); - - /* If the period starts at or after the end time, there is no - clash and we are finished. The busy periods are sorted by - their start times, so all the rest will be later. */ - if (e_meeting_time_selector_compare_times (&period->start, - end_time) >= 0) - return NULL; - - /* If the period ends after the start time, we have found a - clash. From the above test we already know the busy period - isn't completely after the meeting time. */ - if (e_meeting_time_selector_compare_times (&period->end, - start_time) > 0) { - return period; - } - - period_num++; - } - - return NULL; -} - - -/* This subtracts the attendees longest_period_in_days from the given date, - and does a binary search of the attendee's busy periods array to find the - first one which could possible end on the given day or later. - If none are found it returns -1. */ -gint -e_meeting_time_selector_find_first_busy_period (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - GDate *date) -{ - EMeetingTimeSelectorPeriod *period; - gint lower, upper, middle, cmp = 0; - GDate tmp_date; - - /* Make sure the busy periods have been sorted. */ - e_meeting_time_selector_attendee_ensure_periods_sorted (mts, attendee); - - /* Calculate the first day which could have a busy period which - continues onto our given date. */ - tmp_date = *date; - g_date_subtract_days (&tmp_date, attendee->longest_period_in_days); - - /* We want the first busy period which starts on tmp_date. */ - lower = 0; - upper = attendee->busy_periods->len; - - if (upper == 0) - return -1; - - while (lower < upper) { - middle = (lower + upper) >> 1; - - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, middle); - - cmp = g_date_compare (&tmp_date, &period->start.date); - - if (cmp == 0) - break; - else if (cmp < 0) - upper = middle; - else - lower = middle + 1; - } - - /* There may be several busy periods on the same day so we step - backwards to the first one. */ - if (cmp == 0) { - while (middle > 0) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, middle - 1); - if (g_date_compare (&tmp_date, &period->start.date) != 0) - break; - middle--; - } - } else if (cmp > 0) { - /* This means we couldn't find a period on the given day, and - the last one we looked at was before it, so if there are - any more periods after this one we return it. */ - middle++; - if (attendee->busy_periods->len <= middle) - return -1; - } - - return middle; -} - - -static void -e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_zoomed_out (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -static void -e_meeting_time_selector_on_working_hours_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_working_hours_only (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -/* This recalculates day_width, first_hour_shown and last_hour_shown. */ -static void -e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts) -{ - if (mts->working_hours_only) { - mts->first_hour_shown = mts->day_start_hour; - mts->last_hour_shown = mts->day_end_hour; - if (mts->day_end_minute != 0) - mts->last_hour_shown += 1; - } else { - mts->first_hour_shown = 0; - mts->last_hour_shown = 24; - } - - /* In the brief view we use the nearest hours divisible by 3. */ - if (mts->zoomed_out) { - mts->first_hour_shown -= mts->first_hour_shown % 3; - mts->last_hour_shown += 2; - mts->last_hour_shown -= mts->last_hour_shown % 3; - } - - mts->day_width = mts->col_width * (mts->last_hour_shown - mts->first_hour_shown); - if (mts->zoomed_out) - mts->day_width /= 3; - - /* Add one pixel for the extra vertical grid line. */ - mts->day_width++; - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_recalc_date_format (mts); - mts->meeting_positions_valid = FALSE; -} - - -/* This saves the first visible time in the given EMeetingTimeSelectorTime. */ -static void -e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - e_meeting_time_selector_calculate_time (mts, scroll_x, mtstime); -} - - -/* This restores a saved position. */ -static void -e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint scroll_x, scroll_y, new_scroll_x; - - new_scroll_x = e_meeting_time_selector_calculate_time_position (mts, - mtstime); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This returns the x pixel coords of the meeting time in the entire scroll - region. It recalculates them if they have been marked as invalid. - If it returns FALSE then no meeting time is set or the meeting time is - not visible in the current scroll area. */ -gboolean -e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x) -{ - if (mts->meeting_positions_valid) { - if (mts->meeting_positions_in_scroll_area) { - *start_x = mts->meeting_start_x; - *end_x = mts->meeting_end_x; - return TRUE; - } else { - return FALSE; - } - } - - mts->meeting_positions_valid = TRUE; - - /* Check if the days aren't in our current range. */ - if (g_date_compare (&mts->meeting_start_time.date, &mts->last_date_shown) > 0 - || g_date_compare (&mts->meeting_end_time.date, &mts->first_date_shown) < 0) { - mts->meeting_positions_in_scroll_area = FALSE; - return FALSE; - } - - mts->meeting_positions_in_scroll_area = TRUE; - *start_x = mts->meeting_start_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_start_time); - *end_x = mts->meeting_end_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_end_time); - - return TRUE; -} - - -/* This recalculates the date format to used, by computing the width of the - longest date strings in the widget's font and seeing if they fit. */ -static void -e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts) -{ - GDate date; - gint max_date_width, base_width, max_weekday_width, max_month_width; - gint weekday, month; - gchar buffer[128]; - GdkFont *font; - - font = GTK_WIDGET (mts)->style->font; - - /* Check if we will be able to display the full date strings. */ - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_SHORT; - g_date_clear (&date, 1); - g_date_set_dmy (&date, 20, 1, 2000); - - /* Calculate the maximum date width we can fit into the display. */ - max_date_width = mts->day_width - 2; - - /* First compute the width of the date string without the day or - month names. */ - g_date_strftime (buffer, 128, ", %d, %Y", &date); - base_width = gdk_string_width (font, buffer); - - /* If that doesn't fit just return. We have to use the short format. - If that doesn't fit it will just be clipped. */ - if (gdk_string_width (font, buffer) > max_date_width) - return; - - /* Now find the biggest weekday name. We start on any day and just - go through seven days. */ - max_weekday_width = 0; - for (weekday = 1; weekday <= 7; weekday++) { - g_date_strftime (buffer, 128, "%A", &date); - max_weekday_width = MAX (max_weekday_width, - gdk_string_width (font, buffer)); - g_date_add_days (&date, 1); - } - - /* Now find the biggest month name. */ - max_month_width = 0; - for (month = 1; month <= 12; month++) { - g_date_set_month (&date, month); - g_date_strftime (buffer, 128, "%B", &date); - max_month_width = MAX (max_month_width, - gdk_string_width (font, buffer)); - } - - /* See if we can use the full date. */ - if (base_width + max_month_width + max_weekday_width <= max_date_width) { - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_FULL; - return; - } - - /* Now try it with abbreviated weekday names. */ - g_date_strftime (buffer, 128, " %x", &date); - base_width = gdk_string_width (font, buffer); - - max_weekday_width = 0; - for (weekday = 1; weekday <= 7; weekday++) { - g_date_strftime (buffer, 128, "%a", &date); - max_weekday_width = MAX (max_weekday_width, - gdk_string_width (font, buffer)); - g_date_add_days (&date, 1); - } - - if (base_width + max_weekday_width <= max_date_width) - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY; -} - - -/* Turn off the background of the canvas windows. This reduces flicker - considerably when scrolling. (Why isn't it in GnomeCanvas?). */ -static void -e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, - NULL, FALSE); -} - - -/* This is called when the meeting start time GnomeDateEdit is changed, - either via the "date_changed". "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gint duration_days, duration_hours, duration_minutes; - EMeetingTimeSelectorTime mtstime; - time_t newtime; - struct tm *newtime_tm; - - newtime = gnome_date_edit_get_date (GNOME_DATE_EDIT (mts->start_date_edit)); - newtime_tm = localtime (&newtime); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - mtstime.hour = newtime_tm->tm_hour; - mtstime.minute = newtime_tm->tm_min; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_start_time) == 0) - return; - - /* Calculate the current meeting duration. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Set the new start time. */ - mts->meeting_start_time = mtstime; - - /* Update the end time so the meeting duration stays the same. */ - mts->meeting_end_time = mts->meeting_start_time; - e_meeting_time_selector_adjust_time (&mts->meeting_end_time, duration_days, duration_hours, duration_minutes); - e_meeting_time_selector_update_end_date_edit (mts); - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -/* This is called when the meeting end time GnomeDateEdit is changed, - either via the "date_changed", "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorTime mtstime; - time_t newtime; - struct tm *newtime_tm; - - newtime = gnome_date_edit_get_date (GNOME_DATE_EDIT (mts->end_date_edit)); - newtime_tm = localtime (&newtime); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - mtstime.hour = newtime_tm->tm_hour; - mtstime.minute = newtime_tm->tm_min; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_end_time) == 0) - return; - - /* Set the new end time. */ - mts->meeting_end_time = mtstime; - - /* If the start time is after the end time, set it to the same time. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_start_time) < 0) { - /* We set it first, before updating the widget, so the signal - handler will just return. */ - mts->meeting_start_time = mtstime; - e_meeting_time_selector_update_start_date_edit (mts); - } - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -/* This updates the ranges shown in the GnomeDateEdit popup menus, according - to working_hours_only etc. */ -static void -e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts) -{ - GnomeDateEdit *start_edit, *end_edit; - gint low_hour, high_hour; - - start_edit = GNOME_DATE_EDIT (mts->start_date_edit); - end_edit = GNOME_DATE_EDIT (mts->end_date_edit); - - if (mts->working_hours_only) { - low_hour = mts->day_start_hour; - high_hour = mts->day_end_hour; - } else { - low_hour = 0; - high_hour = 23; - } - - gnome_date_edit_set_popup_range (start_edit, low_hour, high_hour); - gnome_date_edit_set_popup_range (end_edit, low_hour, high_hour); -} - - -static void -e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_ensure_meeting_time_shown (mts); -} - - -static void -e_meeting_time_selector_on_attendees_list_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_attendees_list_positions (mts); -} - - -/* This updates the list canvas scroll region according to the number of - attendees. If the total height needed is less than the height of the canvas, - we must use the height of the canvas, or it causes problems. */ -static void -e_meeting_time_selector_update_attendees_list_scroll_region (EMeetingTimeSelector *mts) -{ - gint height, canvas_width, canvas_height; - - height = mts->row_height * mts->attendees->len; - canvas_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - canvas_height = GTK_WIDGET (mts->attendees_list)->allocation.height; - - height = MAX (height, canvas_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->attendees_list), - 0, 0, - canvas_width, - height); -} - - -/* This updates the canvas scroll regions according to the number of attendees. - If the total height needed is less than the height of the canvas, we must - use the height of the canvas, or it causes problems. */ -static void -e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts) -{ - gint height, canvas_height, list_width; - - height = mts->row_height * mts->attendees->len; - canvas_height = GTK_WIDGET (mts->display_main)->allocation.height; - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - - height = MAX (height, canvas_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->attendees_list), - 0, 0, - list_width, - height); - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_main), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - height); -} - - -/* This changes the meeting time based on the given x coordinate and whether - we are dragging the start or end bar. It returns the new position, which - will be swapped if the start bar is dragged past the end bar or vice versa. - It make sure the meeting time is never dragged outside the visible canvas - area. */ -void -e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x) -{ - EMeetingTimeSelectorTime first_time, last_time, drag_time, *time_to_set; - gint scroll_x, scroll_y, canvas_width; - gboolean set_both_times = FALSE; - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Save the x coordinate for the timeout handler. */ - mts->last_drag_x = (x < scroll_x) ? x - scroll_x - : x - scroll_x - canvas_width + 1; - - /* Check if the mouse is off the edge of the canvas. */ - if (x < scroll_x || x > scroll_x + canvas_width) { - /* If we haven't added a timeout function, add one. */ - if (mts->auto_scroll_timeout_id == 0) { - mts->auto_scroll_timeout_id = g_timeout_add (60, e_meeting_time_selector_timeout_handler, mts); - mts->scroll_count = 0; - - /* Call the handler to start scrolling now. */ - e_meeting_time_selector_timeout_handler (mts); - return; - } - } else { - e_meeting_time_selector_remove_timeout (mts); - } - - /* Calculate the minimum & maximum times we can use, based on the - scroll offsets and whether zoomed_out is set. */ - e_meeting_time_selector_calculate_time (mts, scroll_x, &first_time); - e_meeting_time_selector_calculate_time (mts, scroll_x + canvas_width - 1, - &last_time); - if (mts->zoomed_out) { - if (first_time.minute > 30) - first_time.hour++; - first_time.minute = 0; - last_time.minute = 0; - } else { - first_time.minute += 15; - first_time.minute -= first_time.minute % 30; - last_time.minute -= last_time.minute % 30; - } - e_meeting_time_selector_fix_time_overflows (&first_time); - e_meeting_time_selector_fix_time_overflows (&last_time); - - /* Calculate the time from x coordinate. */ - e_meeting_time_selector_calculate_time (mts, x, &drag_time); - - /* Calculate the nearest half-hour or hour, depending on whether - zoomed_out is set. */ - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Now make sure we are between first_time & last_time. */ - if (e_meeting_time_selector_compare_times (&drag_time, &first_time) < 0) - drag_time = first_time; - if (e_meeting_time_selector_compare_times (&drag_time, &last_time) > 0) - drag_time = last_time; - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_selector_compare_times (time_to_set, &drag_time) == 0) - return; - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_selector_compare_times (&mts->meeting_start_time, - &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Redraw the canvases. */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); -} - - -/* This is the timeout function which handles auto-scrolling when the user is - dragging one of the meeting time vertical bars outside the left or right - edge of the canvas. */ -static gboolean -e_meeting_time_selector_timeout_handler (gpointer data) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime drag_time, *time_to_set; - gint scroll_x, max_scroll_x, scroll_y, canvas_width; - gint scroll_speed, scroll_offset; - gboolean set_both_times = FALSE; - - mts = E_MEETING_TIME_SELECTOR (data); - - GDK_THREADS_ENTER (); - - /* Return if we don't need to scroll yet. */ - if (mts->scroll_count-- > 0) { - GDK_THREADS_LEAVE (); - return TRUE; - } - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Calculate the scroll delay, between 0 and MAX_SCROLL_SPEED. */ - scroll_speed = abs (mts->last_drag_x / E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH); - scroll_speed = MIN (scroll_speed, - E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED); - - /* Reset the scroll count. */ - mts->scroll_count = E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED - scroll_speed; - - /* Calculate how much we need to scroll. */ - if (mts->last_drag_x >= 0) - scroll_offset = mts->col_width; - else - scroll_offset = -mts->col_width; - - scroll_x += scroll_offset; - max_scroll_x = (mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN) - - canvas_width; - scroll_x = CLAMP (scroll_x, 0, max_scroll_x); - - /* Calculate the minimum or maximum visible time in the canvas, which - we will now set the dragged time to. */ - if (scroll_offset > 0) { - e_meeting_time_selector_calculate_time (mts, - scroll_x + canvas_width - 1, - &drag_time); - if (mts->zoomed_out) { - drag_time.minute = 0; - } else { - drag_time.minute -= drag_time.minute % 30; - } - } else { - e_meeting_time_selector_calculate_time (mts, scroll_x, - &drag_time); - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_selector_compare_times (time_to_set, &drag_time) == 0) { - GDK_THREADS_LEAVE (); - return TRUE; - } - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_selector_compare_times (&mts->meeting_start_time, &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); - - /* Redraw the canvases. We freeze and thaw the layouts so that they - get redrawn completely. Otherwise the pixels get scrolled left or - right which is not good for us (since our vertical bars have been - moved) and causes flicker. */ - gtk_layout_freeze (GTK_LAYOUT (mts->display_main)); - gtk_layout_freeze (GTK_LAYOUT (mts->display_top)); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - scroll_x, scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_top), - scroll_x, scroll_y); - gtk_layout_thaw (GTK_LAYOUT (mts->display_main)); - gtk_layout_thaw (GTK_LAYOUT (mts->display_top)); - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -/* This removes our auto-scroll timeout function, if we have one installed. */ -void -e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts) -{ - if (mts->auto_scroll_timeout_id) { - g_source_remove (mts->auto_scroll_timeout_id); - mts->auto_scroll_timeout_id = 0; - } -} - - -/* This updates the GnomeDateEdit widget displaying the meeting start time. */ -static void -e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts) -{ - struct tm start_tm; - time_t start_time_t; - - g_date_to_struct_tm (&mts->meeting_start_time.date, &start_tm); - start_tm.tm_hour = mts->meeting_start_time.hour; - start_tm.tm_min = mts->meeting_start_time.minute; - start_time_t = mktime (&start_tm); - gnome_date_edit_set_time (GNOME_DATE_EDIT (mts->start_date_edit), - start_time_t); -} - - -/* This updates the GnomeDateEdit widget displaying the meeting end time. */ -static void -e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts) -{ - struct tm end_tm; - time_t end_time_t; - - g_date_to_struct_tm (&mts->meeting_end_time.date, &end_tm); - end_tm.tm_hour = mts->meeting_end_time.hour; - end_tm.tm_min = mts->meeting_end_time.minute; - end_time_t = mktime (&end_tm); - gnome_date_edit_set_time (GNOME_DATE_EDIT (mts->end_date_edit), - end_time_t); -} - - -/* This ensures that the meeting time is shown on screen, by scrolling the - canvas and possibly by changing the range of dates shown in the canvas. */ -static void -e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts) -{ - gint start_x, end_x, scroll_x, scroll_y, canvas_width; - gint new_scroll_x; - gboolean fits_in_canvas; - - /* Check if we need to change the range of dates shown. */ - if (g_date_compare (&mts->meeting_start_time.date, - &mts->first_date_shown) < 0 - || g_date_compare (&mts->meeting_end_time.date, - &mts->last_date_shown) > 0) { - e_meeting_time_selector_update_dates_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - } - - /* If all of the meeting time is visible, just return. */ - e_meeting_time_selector_get_meeting_time_positions (mts, &start_x, - &end_x); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - if (start_x > scroll_x && end_x <= scroll_x + canvas_width) - return; - - fits_in_canvas = end_x - start_x < canvas_width ? TRUE : FALSE; - - /* If the meeting is not entirely visible, either center it if it is - smaller than the canvas, or show the start of it if it is big. */ - if (fits_in_canvas) { - new_scroll_x = (start_x + end_x - canvas_width) / 2; - } else { - new_scroll_x = start_x; - } - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This updates the range of dates shown in the canvas, to make sure that the - currently selected meeting time is in the range. */ -static void -e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts) -{ - mts->first_date_shown = mts->meeting_start_time.date; - g_date_subtract_days (&mts->first_date_shown, 60); - - mts->last_date_shown = mts->first_date_shown; - g_date_add_days (&mts->last_date_shown, E_MEETING_TIME_SELECTOR_DAYS_SHOWN - 1); -} - - -/* This checks if the time's hour is over 24 or its minute is over 60 and if - so it updates the day/hour appropriately. Note that hours and minutes are - stored in guint8's so they can't overflow by much. */ -void -e_meeting_time_selector_fix_time_overflows (EMeetingTimeSelectorTime *mtstime) -{ - gint hours_to_add, days_to_add; - - hours_to_add = mtstime->minute / 60; - if (hours_to_add > 0) { - mtstime->minute -= hours_to_add * 60; - mtstime->hour += hours_to_add; - } - - days_to_add = mtstime->hour / 24; - if (days_to_add > 0) { - mtstime->hour -= days_to_add * 24; - g_date_add_days (&mtstime->date, days_to_add); - } -} - - -static void -e_meeting_time_selector_update_attendees_list_positions (EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - gint list_width, item_width; - gint row; - - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - item_width = MAX (1, list_width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH); - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - gnome_canvas_item_set (attendee->text_item, - "GnomeCanvasWidget::y", (gdouble) (row * mts->row_height), - "GnomeCanvasWidget::width", (gdouble) item_width, - "GnomeCanvasWidget::height", (gdouble) (mts->row_height), - NULL); - - gnome_canvas_item_show (attendee->text_item); - } - -} - - -/* - * CONVERSION ROUTINES - functions to convert between different coordinate - * spaces and dates. - */ - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the date in which it falls. If day_position is not NULL it also - returns the x coordinate within the date, relative to the visible part of - the canvas. It is used when painting the days in the item_draw function. - Note that it must handle negative x coordinates in case we are dragging off - the edge of the canvas. */ -void -e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position) -{ - gint days_from_first_shown; - - *date = mts->first_date_shown; - - if (x >= 0) { - days_from_first_shown = x / mts->day_width; - g_date_add_days (date, days_from_first_shown); - if (day_position) - *day_position = - x % mts->day_width; - } else { - days_from_first_shown = -x / mts->day_width + 1; - g_date_subtract_days (date, days_from_first_shown); - if (day_position) - *day_position = -mts->day_width - x % mts->day_width; - } -} - - -/* This takes an x pixel coordinate within a day, and converts it to hours - and minutes, depending on working_hours_only and zoomed_out. */ -void -e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes) -{ - if (mts->zoomed_out) - day_position *= 3; - - /* Calculate the hours & minutes from the first displayed. */ - *hours = day_position / mts->col_width; - *minutes = (day_position % mts->col_width) * 60 / mts->col_width; - - /* Now add on the first hour shown. */ - *hours += mts->first_hour_shown; -} - - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the time in which it falls. Note that it won't be extremely - accurate since hours may only be a few pixels wide in the display. - With zoomed_out set each pixel may represent 5 minutes or more, depending - on how small the font is. */ -void -e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTimeSelectorTime *time) -{ - gint day_position; - - /* First get the day and the x position within the day. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, &time->date, - NULL); - - /* Now convert the day_position into an hour and minute. */ - if (x >= 0) - day_position = x % mts->day_width; - else - day_position = mts->day_width + x % mts->day_width; - - e_meeting_time_selector_convert_day_position_to_hours_and_mins (mts, day_position, &time->hour, &time->minute); -} - - -/* This takes a EMeetingTimeSelectorTime and calculates the x pixel coordinate - within the entire canvas scroll region. It is used to draw the selected - meeting time and all the busy periods. */ -gint -e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint x, date_offset, day_offset; - - /* Calculate the number of days since the first date shown in the - entire canvas scroll region. */ - date_offset = g_date_julian (&mtstime->date) - g_date_julian (&mts->first_date_shown); - - /* Calculate the x pixel coordinate of the start of the day. */ - x = date_offset * mts->day_width; - - /* Add on the hours and minutes, depending on whether zoomed_out and - working_hours_only are set. */ - day_offset = (mtstime->hour - mts->first_hour_shown) * 60 - + mtstime->minute; - /* The day width includes an extra vertical grid line so subtract 1. */ - day_offset *= (mts->day_width - 1); - day_offset /= (mts->last_hour_shown - mts->first_hour_shown) * 60; - - /* Clamp the day_offset in case the time isn't actually visible. */ - x += CLAMP (day_offset, 0, mts->day_width); - - return x; -} - - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel.h b/widgets/meeting-time-sel/e-meeting-time-sel.h deleted file mode 100644 index 6df15fe54c..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel.h +++ /dev/null @@ -1,496 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_MEETING_TIME_SELECTOR_H_ -#define _E_MEETING_TIME_SELECTOR_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EMeetingTimeSelector displays a list of attendees for a meeting and a - * graphical summary of the times which they are free and busy, allowing the - * user to select an appropriate time for a meeting. - */ - -/* Define this to include the debugging functions. */ -#undef E_MEETING_TIME_SELECTOR_DEBUG - -/* This is the width of the icon column in the attendees list. */ -#define E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH 24 - - -/* These specify the type of attendee. Either a person or a resource (e.g. a - meeting room). These are used for the Autopick options, where the user can - ask for a time when, for example, all people and one resource are free. - The default is E_MEETING_TIME_SELECTOR_REQUIRED_PERSON. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_REQUIRED_PERSON, - E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON, - E_MEETING_TIME_SELECTOR_RESOURCE -} EMeetingTimeSelectorAttendeeType; - - -/* These are used to specify whether an attendee is free or busy at a - particular time. We'll probably replace this with a global calendar type. - These should be ordered in increasing order of preference. Higher precedence - busy periods will be painted over lower precedence ones. These are also - used as for loop counters, so they should start at 0 and be ordered. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE = 0, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE = 1, - E_MEETING_TIME_SELECTOR_BUSY_BUSY = 2, - - E_MEETING_TIME_SELECTOR_BUSY_LAST = 3 -} EMeetingTimeSelectorBusyType; - - -/* This is used to specify the format used when displaying the dates. - The full format is like 'Sunday, September 12, 1999'. The abbreviated format - is like 'Sun 12/9/99'. The short format is like '12/9/99'. The actual - format used is determined in e_meeting_time_selector_style_set(), once we - know the font being used. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_DATE_FULL, - E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY, - E_MEETING_TIME_SELECTOR_DATE_SHORT -} EMeetingTimeSelectorDateFormat; - - -/* This is used to specify a position regarding the vertical bars around the - current meeting time, so we know which one is being dragged. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_POS_NONE, - E_MEETING_TIME_SELECTOR_POS_START, - E_MEETING_TIME_SELECTOR_POS_END -} EMeetingTimeSelectorPosition; - - -/* This is used to specify the autopick option, which determines how we choose - the previous/next appropriate meeting time. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES, - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE -} EMeetingTimeSelectorAutopickOption; - - -/* This is our representation of a time. We use a GDate to store the day, - and guint8s for the hours and minutes. */ -typedef struct _EMeetingTimeSelectorTime EMeetingTimeSelectorTime; -struct _EMeetingTimeSelectorTime -{ - GDate date; - guint8 hour; - guint8 minute; -}; - - -/* This represents a busy period. */ -typedef struct _EMeetingTimeSelectorPeriod EMeetingTimeSelectorPeriod; -struct _EMeetingTimeSelectorPeriod -{ - EMeetingTimeSelectorTime start; - EMeetingTimeSelectorTime end; - EMeetingTimeSelectorBusyType busy_type; -}; - - -/* This contains information on one attendee. */ -typedef struct _EMeetingTimeSelectorAttendee EMeetingTimeSelectorAttendee; -struct _EMeetingTimeSelectorAttendee -{ - gchar *name; - - /* The type of attendee, e.g. a person or a resource. */ - EMeetingTimeSelectorAttendeeType type; - - /* This is TRUE if the attendee has calendar information available. - It is set to TRUE when a busy period is added, but can also be set - to TRUE explicitly to indicate that the attendee has calendar - information available, but no current busy periods. If it is FALSE - then a diagonal stipple pattern is used to fill the entire row in - the main graphical display. */ - gboolean has_calendar_info; - - /* This is TRUE if the meeting request is sent to this attendee. */ - gboolean send_meeting_to; - - /* This is an array of EMeetingTimeSelectorPeriod elements. When it is - updated busy_periods_sorted is set to FALSE, and if a function - needs them sorted, it should call this to re-sort them if needed: - e_meeting_time_selector_attendee_ensure_periods_sorted(). Note that - they are sorted by the start times. */ - GArray *busy_periods; - gboolean busy_periods_sorted; - - /* This holds the length of the longest busy period in days, rounded - up. It is used to determine where to start looking in the - busy_periods array. If we didn't use this we'd have to go through - most of the busy_periods array every time we wanted to paint part - of the display. */ - gint longest_period_in_days; - - /* This is the canvas text item where the name is edited. */ - GnomeCanvasItem *text_item; - - /* This is supposed to be something like an address book id. */ - gpointer data; -}; - -/* An array of hour strings, "0:00" .. "23:00". */ -extern const gchar *EMeetingTimeSelectorHours[24]; - - -#define E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_CAST (obj, e_meeting_time_selector_get_type (), EMeetingTimeSelector) -#define E_MEETING_TIME_SELECTOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_meeting_time_selector_get_type (), EMeetingTimeSelectorClass) -#define IS_E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_TYPE (obj, e_meeting_time_selector_get_type ()) - - -typedef struct _EMeetingTimeSelector EMeetingTimeSelector; -typedef struct _EMeetingTimeSelectorClass EMeetingTimeSelectorClass; - -struct _EMeetingTimeSelector -{ - /* We subclass a GtkTable which makes it easy to add extra widgets - if neccesary. */ - GtkTable table; - - /* - * User Interface stuff - widgets, colors etc. - */ - - /* This contains our keyboard accelerators, which need to be added to - the toplevel window. */ - GtkAccelGroup *accel_group; - - /* The vbox in the top-left corner, containing the 'All Attendees' - title bar packed at the end. Extra widgets can be added here - with PACK_START if necessary. */ - GtkWidget *attendees_title_bar_vbox; - - /* The 'All Attendees' title bar above the list of attendees. */ - GtkWidget *attendees_title_bar; - - /* The list of attendees. */ - GtkWidget *attendees_list; - - /* The canvas displaying the dates, times, and the summary - 'All Attendees' free/busy display. */ - GtkWidget *display_top; - - /* The canvas containing the free/busy displays of individual - attendees. This is separate from display_top since it also scrolls - vertically. */ - GtkWidget *display_main; - - /* This is the 'Options' button & menu. */ - GtkWidget *options_button; - GtkWidget *options_menu; - - /* This is the 'Autopick' button, menu & radio menu items. */ - GtkWidget *autopick_button; - GtkWidget *autopick_menu; - GtkWidget *autopick_all_item; - GtkWidget *autopick_all_people_one_resource_item; - GtkWidget *autopick_required_people_item; - GtkWidget *autopick_required_people_one_resource_item; - - /* The horizontal scrollbar which scrolls display_top & display_main.*/ - GtkWidget *hscrollbar; - - /* The vertical scrollbar which scrolls attendees & display_main. */ - GtkWidget *vscrollbar; - - /* The 2 GnomeDateEdit widgets for the meeting start & end times. */ - GtkWidget *start_date_edit; - GtkWidget *end_date_edit; - - /* Colors. */ - GdkColorContext *color_context; - GdkColor bg_color; - GdkColor all_attendees_bg_color; - GdkColor meeting_time_bg_color; - GdkColor stipple_bg_color; - GdkColor attendee_list_bg_color; - GdkColor grid_color; - GdkColor grid_shadow_color; - GdkColor grid_unused_color; - GdkColor busy_colors[E_MEETING_TIME_SELECTOR_BUSY_LAST]; - - /* The stipple used for attendees with no data. */ - GdkPixmap *stipple; - - /* GC for drawing the color key. */ - GdkGC *color_key_gc; - - /* Width of the hours strings (e.g. "1:00") in the current font. */ - gint hour_widths[24]; - - /* Whether we are using the full, abbreviated or short date format. */ - EMeetingTimeSelectorDateFormat date_format; - - - /* - * Attendee Data. - */ - - /* This is an array of EMeetingTimeSelectorAttendee elements. */ - GArray *attendees; - - - /* - * Option Settings. - */ - - /* If this is TRUE we only show hours between day_start_hour and - day_end_hour, defaults to TRUE (9am-6pm). */ - gboolean working_hours_only; - gint day_start_hour; - gint day_start_minute; - gint day_end_hour; - gint day_end_minute; - - /* If TRUE, view is compressed, with one cell for every 3 hours rather - than every hour. Defaults to FALSE. */ - gboolean zoomed_out; - - - /* - * Internal Data. - */ - - /* These are the first & last dates shown in the current scroll area. - We show E_MEETING_TIME_SELECTOR_DAYS_SHOWN days at a time. */ - GDate first_date_shown; - GDate last_date_shown; - - /* This is the current selection of the meeting time. */ - EMeetingTimeSelectorTime meeting_start_time; - EMeetingTimeSelectorTime meeting_end_time; - - /* These are the x pixel coordinates in the entire scroll region of - the start and end times. Set to meeting_positions_valid to FALSE to - invalidate. They will then be recomputed when needed. Always access - with e_meeting_time_selector_get_meeting_time_positions(). */ - gint meeting_positions_valid; - gint meeting_positions_in_scroll_area; - gint meeting_start_x; - gint meeting_end_x; - - /* These are the width and height of the cells, including the grid - lines which are displayed on the right and top or bottom of cells.*/ - gint row_height; - gint col_width; - - /* This is the width of a day in the display, which depends on - col_width, working_hours_only and zoomed_out. */ - gint day_width; - - /* These are the first and last hour of each day we display, depending - on working_hours_only and zoomed_out. */ - gint first_hour_shown; - gint last_hour_shown; - - /* The id of the source function for auto-scroll timeouts. */ - guint auto_scroll_timeout_id; - - /* This specifies if we are dragging one of the vertical bars around - the meeting time. */ - EMeetingTimeSelectorPosition dragging_position; - - /* The last x coordinate of the mouse, relative to either the left or - right edge of the canvas. Used in the auto_scroll_timeout function - to determine which way to scroll and how fast. */ - gint last_drag_x; - - /* This is used to determine the delay between scrolls. */ - gint scroll_count; -}; - - -struct _EMeetingTimeSelectorClass -{ - GtkTableClass parent_class; -}; - - -/* - * PUBLIC INTERFACE - note that this interface will probably change, when I - * know where the data is coming from. This is mainly just for testing for now. - */ - -GtkType e_meeting_time_selector_get_type (void); -GtkWidget* e_meeting_time_selector_new (void); - -/* This returns the currently selected meeting time. - Note that months are 1-12 and days are 1-31. The start time is guaranteed to - be before or equal to the end time. You may want to check if they are equal - if that if it is a problem. */ -void e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute); - -/* This sets the meeting time, returning TRUE if it is valid. */ -gboolean e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute); - -void e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only); -void e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute); - -void e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out); - -EMeetingTimeSelectorAutopickOption e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts); -void e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option); - -/* Adds an attendee to the list, returning the row. The data is meant for - something like an address book id, though if the user edits the name this - will become invalid. We'll probably have to handle address book lookup - ourself. */ -gint e_meeting_time_selector_attendee_add (EMeetingTimeSelector *mts, - gchar *attendee_name, - gpointer data); -gint e_meeting_time_selector_attendee_find_by_name (EMeetingTimeSelector *mts, - gchar *attendee_name, - gint start_row); -gint e_meeting_time_selector_attendee_find_by_data (EMeetingTimeSelector *mts, - gpointer data, - gint start_row); -void e_meeting_time_selector_attendee_remove (EMeetingTimeSelector *mts, - gint row); - -void e_meeting_time_selector_attendee_set_type (EMeetingTimeSelector *mts, - gint row, - EMeetingTimeSelectorAttendeeType type); -void e_meeting_time_selector_attendee_set_has_calendar_info (EMeetingTimeSelector *mts, - gint row, - gboolean has_calendar_info); -void e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to); - -/* Clears all busy times for the given attendee. */ -void e_meeting_time_selector_attendee_clear_busy_periods (EMeetingTimeSelector *mts, - gint row); -/* Adds one busy time for the given attendee. */ -gboolean e_meeting_time_selector_attendee_add_busy_period (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingTimeSelectorBusyType busy_type); - - - -/* - * INTERNAL ROUTINES - functions to communicate with the canvas items within - * the EMeetingTimeSelector. - */ - -/* This returns the x pixel coordinates of the meeting start and end times, - in the entire canvas scroll area. If it returns FALSE, then the meeting - time isn't in the current scroll area (which shouldn't really happen). */ -gboolean e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x); - -void e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x); - -void e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts); - -void e_meeting_time_selector_fix_time_overflows (EMeetingTimeSelectorTime *mtstime); - -gint e_meeting_time_selector_find_first_busy_period (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - GDate *date); - -/* Makes sure the busy periods are sorted, so we can do binary searches. */ -void e_meeting_time_selector_attendee_ensure_periods_sorted (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee); - -void e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position); -void e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes); -void e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTimeSelectorTime *time); -gint e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); - -/* Debugging function to dump information on all attendees. */ -#ifdef E_MEETING_TIME_SELECTOR_DEBUG -void e_meeting_time_selector_dump (EMeetingTimeSelector *mts); -gchar* e_meeting_time_selector_dump_time (EMeetingTimeSelectorTime *mtstime); -gchar* e_meeting_time_selector_dump_date (GDate *date); -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_TIME_SELECTOR_H_ */ diff --git a/widgets/meeting-time-sel/test-meeting-time-sel.c b/widgets/meeting-time-sel/test-meeting-time-sel.c deleted file mode 100644 index debe4e8f40..0000000000 --- a/widgets/meeting-time-sel/test-meeting-time-sel.c +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include -#include -#include "e-meeting-time-sel.h" - -void add_random_attendee_test_data (EMeetingTimeSelector *mts); -void add_simple_attendee_test_data (EMeetingTimeSelector *mts); -gint get_random_int (gint max); - -int -main (int argc, char *argv[]) -{ - GtkWidget *window, *mts; - gint i; - - gnome_init ("test-meeting-time-selector", "0.1", argc, argv); - - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - - window = gnome_dialog_new ("Plan a Meeting", "Make Meeting", - GNOME_STOCK_BUTTON_CLOSE, NULL); - gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); - gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE); - - mts = e_meeting_time_selector_new (); - gtk_container_add (GTK_CONTAINER (GNOME_DIALOG (window)->vbox), mts); - gtk_window_add_accel_group (GTK_WINDOW (window), - E_MEETING_TIME_SELECTOR (mts)->accel_group); - gtk_widget_show (mts); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - i = 0; -#if 1 - for (i = 0; i < 20; i++) { - add_random_attendee_test_data (E_MEETING_TIME_SELECTOR (mts)); - } -#else - for (i = 0; i < 1; i++) { - add_simple_attendee_test_data (E_MEETING_TIME_SELECTOR (mts)); - } -#endif - -#if 0 - e_meeting_time_selector_dump (E_MEETING_TIME_SELECTOR (mts)); -#endif - - gnome_dialog_run (GNOME_DIALOG (window)); - - gtk_main (); - return 0; -} - - -/* Adds an attendee and a lot of random busy periods. The periods start 60 - days before the current date and extend over 365 days, to match the range - that EMeetingTimeSelector currently displays. We generate a time_t and an - interval and then convert them into a struct tm which provides everything - we need. */ -void -add_random_attendee_test_data (EMeetingTimeSelector *mts) -{ - gchar buffer[128], *name; - gint row, num_periods, busy_period, random_num, duration; - EMeetingTimeSelectorAttendeeType type; - EMeetingTimeSelectorBusyType busy_type; - time_t range_start; - time_t period_start; - time_t period_end; - struct tm *tmp_tm; - struct tm tm1; - struct tm tm2; - - /* Determine the type of attendee. */ - random_num = get_random_int (10); - if (random_num < 4) { - type = E_MEETING_TIME_SELECTOR_REQUIRED_PERSON; - name = "Req. Attendee"; - } else if (random_num < 7) { - type = E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON; - name = "Opt. Attendee"; - } else { - type = E_MEETING_TIME_SELECTOR_RESOURCE; - name = "Resource"; - } - - sprintf (buffer, "%s %i", name, mts->attendees->len + 1); - row = e_meeting_time_selector_attendee_add (mts, buffer, NULL); - e_meeting_time_selector_attendee_set_type (mts, row, type); - - /* Don't send the meeting request to some attendees. */ - if (get_random_int (10) <= 2) - e_meeting_time_selector_attendee_set_send_meeting_to (mts, row, - FALSE); - - /* Some attendees have no calendar information. */ - if (get_random_int (10) == 2) - return; - - range_start = time (NULL) - 61 * 24 * 60 * 60; - num_periods = get_random_int (1000); -#if 0 - g_print ("num_periods: %i\n", num_periods); -#endif - for (busy_period = 0; busy_period < num_periods; busy_period++) { - - period_start = range_start + get_random_int (365 * 24 * 60 * 60); - - /* Make busy periods mainly 30 mins to a few hours, with a - couple of week/fortnight periods as well. */ - random_num = get_random_int (10000); - if (random_num < 2000) - duration = 30; - else if (random_num < 5000) - duration = 60; - else if (random_num < 7500) - duration = 90; - else if (random_num < 9995) - duration = 120; - else if (random_num < 9998) - duration = 60 * 24 * 7; - else - duration = 60 * 24 * 14; -#if 0 - g_print ("random_num: %i, duration: %i\n", - random_num, duration); -#endif - period_end = period_start + duration * 60; - - tmp_tm = localtime (&period_start); - tm1 = *tmp_tm; - tmp_tm = localtime (&period_end); - tm2 = *tmp_tm; - - /* A hack to avoid daylight-saving time problems. */ - if (tm2.tm_hour == tm1.tm_hour && tm2.tm_min < tm1.tm_min) - tm2.tm_hour++; - - busy_type = get_random_int (E_MEETING_TIME_SELECTOR_BUSY_LAST); - - if (!e_meeting_time_selector_attendee_add_busy_period (mts, row, tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm2.tm_year + 1900, tm2.tm_mon + 1, tm2.tm_mday, tm2.tm_hour, tm2.tm_min, busy_type)) - { - g_print ("Invalid busy period %i/%i/%i %i:%i to %i/%i/%i %i:%i\n", tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm2.tm_year + 1900, tm2.tm_mon + 1, tm2.tm_mday, tm2.tm_hour, tm2.tm_min); - g_print ("random_num: %i, duration: %i\n", - random_num, duration); - } - } -} - - -/* Returns a random integer between 0 and max - 1. */ -gint -get_random_int (gint max) -{ - gint random_num; - - random_num = (int) (max * (rand () / (RAND_MAX + 1.0))); -#if 0 - g_print ("Random num (%i): %i\n", max, random_num); -#endif - return random_num; -} - - -void -add_simple_attendee_test_data (EMeetingTimeSelector *mts) -{ - gint row; - - row = e_meeting_time_selector_attendee_add (mts, "John Smith", NULL); - if (!e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 14, 30, - 1999, 11, 7, 16, 30, - E_MEETING_TIME_SELECTOR_BUSY_BUSY)) - g_warning ("Invalid busy period"); - - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 10, 30, - 1999, 11, 7, 11, 30, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 4, 10, 30, - 1999, 11, 7, 11, 30, - E_MEETING_TIME_SELECTOR_BUSY_BUSY); - row = e_meeting_time_selector_attendee_add (mts, "Dave Jones", NULL); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 15, 30, - 1999, 11, 7, 18, 30, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 11, 00, - 1999, 11, 7, 12, 00, - E_MEETING_TIME_SELECTOR_BUSY_BUSY); - - row = e_meeting_time_selector_attendee_add (mts, "Andrew Carlisle", NULL); - e_meeting_time_selector_attendee_set_send_meeting_to (mts, row, FALSE); - - row = e_meeting_time_selector_attendee_add (mts, "Michael Cain", NULL); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 15, 30, - 1999, 11, 7, 18, 30, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 12, 30, - 1999, 11, 7, 13, 30, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 11, 00, - 1999, 11, 7, 12, 00, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); -} diff --git a/widgets/misc/e-canvas-utils.c b/widgets/misc/e-canvas-utils.c deleted file mode 100644 index 2b50248124..0000000000 --- a/widgets/misc/e-canvas-utils.c +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas-utils.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 "e-canvas-utils.h" - -void -e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy) -{ - double translate[6]; - - g_return_if_fail (item != NULL); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - - art_affine_translate (translate, dx, dy); - - gnome_canvas_item_affine_absolute (item, translate); -} diff --git a/widgets/misc/e-canvas-utils.h b/widgets/misc/e-canvas-utils.h deleted file mode 100644 index 13ec43117c..0000000000 --- a/widgets/misc/e-canvas-utils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas-utils.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -void e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy); diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c deleted file mode 100644 index 850e438386..0000000000 --- a/widgets/misc/e-canvas.c +++ /dev/null @@ -1,301 +0,0 @@ -/* -*- 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 - * - * 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 -#include "e-canvas.h" -static void e_canvas_init (ECanvas *card); -static void e_canvas_class_init (ECanvasClass *klass); -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; - -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 ()); - - 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; -} - -static void -e_canvas_init (ECanvas *canvas) -{ -} - -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 (ev.type) { - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - gnome_canvas_window_to_world (canvas, - ev.crossing.x, ev.crossing.y, - &ev.crossing.x, &ev.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, - ev.motion.x, ev.motion.y, - &ev.motion.x, &ev.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", - &ev, - &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; - gtk_widget_grab_focus (GTK_WIDGET (item->canvas)); -} - -/* Focus in handler for the canvas */ -static gint -e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - GnomeCanvas *canvas; - - canvas = GNOME_CANVAS (widget); - - 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; - - canvas = GNOME_CANVAS (widget); - - if (canvas->focused_item) - return emit_event (canvas, (GdkEvent *) event); - else - return FALSE; -} diff --git a/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h deleted file mode 100644 index 0ece5ae3b4..0000000000 --- a/widgets/misc/e-canvas.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-canvas.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_CANVAS_H__ -#define __E_CANVAS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ECanvas - A class derived from canvas for the purpose of adding - * evolution specific canvas hacks. - */ - -#define E_CANVAS_TYPE (e_canvas_get_type ()) -#define E_CANVAS(obj) (GTK_CHECK_CAST ((obj), E_CANVAS_TYPE, ECanvas)) -#define E_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_CANVAS_TYPE, ECanvasClass)) -#define E_IS_CANVAS(obj) (GTK_CHECK_TYPE ((obj), E_CANVAS_TYPE)) -#define E_IS_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CANVAS_TYPE)) - - -typedef struct _ECanvas ECanvas; -typedef struct _ECanvasClass ECanvasClass; - -struct _ECanvas -{ - GnomeCanvas parent; - - /* item specific fields */ -}; - -struct _ECanvasClass -{ - GnomeCanvasClass parent_class; -}; - - -GtkType e_canvas_get_type (void); -GtkWidget *e_canvas_new (void); - -/* Used to send all of the keystroke events to a specific item as well as - * GDK_FOCUS_CHANGE events. - */ -void e_canvas_item_grab_focus (GnomeCanvasItem *item); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_CANVAS_H__ */ diff --git a/widgets/misc/e-colors.c b/widgets/misc/e-colors.c deleted file mode 100644 index 3f1de73784..0000000000 --- a/widgets/misc/e-colors.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * color.c: Color allocation on the Gnumeric spreadsheet - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * We keep our own color context, as the color allocation might take place - * before any of our Canvases are realized. - */ -#include -#include -#include "color.h" - -static int color_inited; -static GdkColorContext *gnumeric_color_context; - -/* Public colors: shared by all of our items in Gnumeric */ -GdkColor gs_white, gs_black, gs_light_gray, gs_dark_gray, gs_red; - -int -color_alloc (gushort red, gushort green, gushort blue) -{ - int failed; - - if (!color_inited) - color_init (); - - return gdk_color_context_get_pixel (gnumeric_color_context, - red, green, blue, &failed); -} - -void -color_alloc_gdk (GdkColor *c) -{ - int failed; - - g_return_if_fail (c != NULL); - - c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed); -} - -void -color_alloc_name (const char *name, GdkColor *c) -{ - int failed; - - g_return_if_fail (name != NULL); - g_return_if_fail (c != NULL); - - gdk_color_parse (name, c); - c->pixel = 0; - c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed); -} - -void -color_init (void) -{ - GdkColormap *colormap = gtk_widget_get_default_colormap (); - - /* Initialize the color context */ - gnumeric_color_context = gdk_color_context_new ( - gtk_widget_get_default_visual (), colormap); - - /* Allocate the default colors */ - gdk_color_white (colormap, &gs_white); - gdk_color_black (colormap, &gs_black); - - color_alloc_name ("gray78", &gs_light_gray); - color_alloc_name ("gray20", &gs_dark_gray); - color_alloc_name ("red", &gs_red); - - color_inited = 1; -} diff --git a/widgets/misc/e-colors.h b/widgets/misc/e-colors.h deleted file mode 100644 index b2755a5c6a..0000000000 --- a/widgets/misc/e-colors.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GNUMERIC_COLOR_H -#define GNUMERIC_COLOR_H - -void color_init (void); - -/* Return the pixel value for the given red, green and blue */ -int color_alloc (gushort red, gushort green, gushort blue); -void color_alloc_name (const char *name, GdkColor *color); -void color_alloc_gdk (GdkColor *color); - -/* Colors used by any GnumericSheet item */ -extern GdkColor gs_white, gs_light_gray, gs_dark_gray, gs_black, gs_red; - -#endif /* GNUMERIC_COLOR_H */ diff --git a/widgets/misc/e-cursors.c b/widgets/misc/e-cursors.c deleted file mode 100644 index 597c3c1787..0000000000 --- a/widgets/misc/e-cursors.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GNUMERIC_CURSORS_H -#define GNUMERIC_CURSORS_H - -typedef enum { - GNUMERIC_CURSOR_FAT_CROSS, - GNUMERIC_CURSOR_THIN_CROSS, - GNUMERIC_CURSOR_ARROW, - GNUMERIC_CURSOR_MOVE, - GNUMERIC_CURSOR_ZOOM_IN, - GNUMERIC_CURSOR_ZOOM_OUT, - GNUMERIC_CURSOR_SIZE_X, - GNUMERIC_CURSOR_SIZE_Y, - GNUMERIC_CURSOR_SIZE_TL, - GNUMERIC_CURSOR_SIZE_TR, - GNUMERIC_CURSOR_PRESS, - GNUMERIC_CURSOR_HAND_OPEN, - GNUMERIC_CURSOR_HAND_CLOSED, - GNUMERIC_CURSOR_NUM_CURSORS -} CursorType; - -void cursors_init (void); -void cursors_shutdown (void); - -#define cursor_set(win, c) \ -G_STMT_START { \ - if (win) \ - gdk_window_set_cursor (win, cursor_get (c)); \ -} G_STMT_END - -#define cursor_set_widget(w, c) \ -G_STMT_START { \ - if (GTK_WIDGET (w)->window) \ - gdk_window_set_cursor (GTK_WIDGET (w)->window, cursor_get (c)); \ -} G_STMT_END - -GdkCursor *cursor_get (CursorType type); - -#endif /* GNUMERIC_CURSORS_H */ diff --git a/widgets/misc/e-cursors.h b/widgets/misc/e-cursors.h deleted file mode 100644 index 597c3c1787..0000000000 --- a/widgets/misc/e-cursors.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GNUMERIC_CURSORS_H -#define GNUMERIC_CURSORS_H - -typedef enum { - GNUMERIC_CURSOR_FAT_CROSS, - GNUMERIC_CURSOR_THIN_CROSS, - GNUMERIC_CURSOR_ARROW, - GNUMERIC_CURSOR_MOVE, - GNUMERIC_CURSOR_ZOOM_IN, - GNUMERIC_CURSOR_ZOOM_OUT, - GNUMERIC_CURSOR_SIZE_X, - GNUMERIC_CURSOR_SIZE_Y, - GNUMERIC_CURSOR_SIZE_TL, - GNUMERIC_CURSOR_SIZE_TR, - GNUMERIC_CURSOR_PRESS, - GNUMERIC_CURSOR_HAND_OPEN, - GNUMERIC_CURSOR_HAND_CLOSED, - GNUMERIC_CURSOR_NUM_CURSORS -} CursorType; - -void cursors_init (void); -void cursors_shutdown (void); - -#define cursor_set(win, c) \ -G_STMT_START { \ - if (win) \ - gdk_window_set_cursor (win, cursor_get (c)); \ -} G_STMT_END - -#define cursor_set_widget(w, c) \ -G_STMT_START { \ - if (GTK_WIDGET (w)->window) \ - gdk_window_set_cursor (GTK_WIDGET (w)->window, cursor_get (c)); \ -} G_STMT_END - -GdkCursor *cursor_get (CursorType type); - -#endif /* GNUMERIC_CURSORS_H */ diff --git a/widgets/misc/e-gui-utils.c b/widgets/misc/e-gui-utils.c deleted file mode 100644 index 7d9f4d49d9..0000000000 --- a/widgets/misc/e-gui-utils.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * GUI utility functions - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * - * (C) 1999 Miguel de Icaza - * (C) 2000 Helix Code, Inc. - */ -#include -#include -#include -#include -#include "e-gui-utils.h" - -void -e_notice (GtkWindow *window, const char *type, const char *str) -{ - GtkWidget *dialog; - - dialog = gnome_message_box_new (str, type, GNOME_STOCK_BUTTON_OK, NULL); - - if (window) - gnome_dialog_set_parent (GNOME_DIALOG (dialog), window); - - gnome_dialog_run (GNOME_DIALOG (dialog)); -} - -static void -kill_popup_menu (GtkWidget *widget, GtkMenu *menu) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - gtk_object_unref (GTK_OBJECT (menu)); -} - -void -e_auto_kill_popup_menu_on_hide (GtkMenu *menu) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - gtk_signal_connect (GTK_OBJECT (menu), "hide", - GTK_SIGNAL_FUNC (kill_popup_menu), menu); -} - -void -e_popup_menu (GtkMenu *menu, GdkEventButton *event) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - e_auto_kill_popup_menu_on_hide (menu); - gtk_menu_popup (menu, NULL, NULL, 0, NULL, event->button, event->time); -} - - diff --git a/widgets/misc/e-gui-utils.h b/widgets/misc/e-gui-utils.h deleted file mode 100644 index 95b8f0b5a1..0000000000 --- a/widgets/misc/e-gui-utils.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef E_GUI_UTILS_H -#define E_GUI_UTILS_H - -#include -#include - -void e_popup_menu (GtkMenu *menu, GdkEventButton *event); -void e_auto_kill_popup_menu_on_hide (GtkMenu *menu); -void e_notice (GtkWindow *window, const char *type, const char *str); - - -#endif /* E_GUI_UTILS_H */ diff --git a/widgets/misc/e-reflow.c b/widgets/misc/e-reflow.c deleted file mode 100644 index c1022f8f78..0000000000 --- a/widgets/misc/e-reflow.c +++ /dev/null @@ -1,787 +0,0 @@ -/* -*- 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 - * - * 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 -#include -#include "e-reflow.h" -#include "e-canvas-utils.h" -static void e_reflow_init (EReflow *card); -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 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 _update_reflow ( EReflow *reflow ); -static void _resize( GtkObject *object, gpointer data ); -static void _queue_reflow(EReflow *e_reflow); - -#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; - -enum { - E_REFLOW_RESIZE, - E_REFLOW_LAST_SIGNAL -}; - -static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT -}; - -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 ()); - - e_reflow_signals[E_REFLOW_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EReflowClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); - - 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); - - 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->card = NULL;*/ - reflow->items = NULL; - reflow->columns = NULL; - reflow->column_width = 150; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - reflow->idle = 0; - - 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; -} - -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); - _queue_reflow(e_reflow); - break; - case ARG_MINIMUM_WIDTH: - e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg); - _queue_reflow(e_reflow); - break; - } -} - -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; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -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); - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - } - - _queue_reflow( e_reflow ); - - 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); - - g_list_free (e_reflow->items); - g_list_free (e_reflow->columns); - - 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); - gboolean 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", TRUE, - NULL); - return 1; - } else { - return 0; - } - } - } - } - break; - case GDK_BUTTON_PRESS: - switch(event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - double n_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)); - if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) { - 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); - _queue_reflow(e_reflow); - } else { - 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; - 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)); - if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->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->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; - 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->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; -} - -void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - e_reflow->items = g_list_append(e_reflow->items, item); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - gtk_signal_connect(GTK_OBJECT(item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_reflow); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - _queue_reflow(e_reflow); - } - -} - -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 double -e_reflow_point (GnomeCanvasItem *item, - double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - EReflow *e_reflow = E_REFLOW(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 = 1; - 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 -_update_reflow( EReflow *e_reflow ) -{ - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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_set (GTK_OBJECT(list->data), - "width", e_reflow->column_width, - NULL); - 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) - gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); - } -} - - -static gboolean -_idle_reflow(gpointer data) -{ - EReflow *e_reflow = E_REFLOW(data); - _update_reflow(e_reflow); - e_reflow->need_height_update = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(e_reflow)); - e_reflow->idle = 0; - return FALSE; -} - -static void -_queue_reflow(EReflow *e_reflow) -{ - if (e_reflow->idle == 0) - e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); -} - -static void -_resize( GtkObject *object, gpointer data ) -{ - _queue_reflow(E_REFLOW(data)); -} diff --git a/widgets/misc/e-reflow.h b/widgets/misc/e-reflow.h deleted file mode 100644 index 3a731474cb..0000000000 --- a/widgets/misc/e-reflow.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_REFLOW_H__ -#define __E_REFLOW_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflow - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_TYPE (e_reflow_get_type ()) -#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) -#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) -#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) -#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) - - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; - -struct _EReflow -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - /* EBook *book; */ - - GList *items; /* Of type GnomeCanvasItem */ - GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ - gint column_count; /* Number of columnns */ - - double minimum_width; - double width; - double height; - - double column_width; - - int idle; - - /* These are all for when the column is being dragged. */ - gboolean column_drag; - gdouble start_x; - gint which_column_dragged; - double temp_column_width; - double previous_temp_column_width; - - guint need_height_update : 1; - guint need_column_resize : 1; - - guint default_cursor_shown : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - void (* resize) (EReflow *reflow); -}; - -/* To be added to a reflow, an item must have the arguments "x", "y", - and "width" as Read/Write arguments and "height" as a Read Only - argument. It must also have a "resize" signal. */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_REFLOW_H__ */ diff --git a/widgets/misc/pixmaps/cursor_cross.xpm b/widgets/misc/pixmaps/cursor_cross.xpm deleted file mode 100644 index cf9d0aca33..0000000000 --- a/widgets/misc/pixmaps/cursor_cross.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_cross_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ....... ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" ......+++++...... ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" ......+++++....... ", -" .....+++++....... ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" ........ ", -" ....... ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_hand_closed.xpm b/widgets/misc/pixmaps/cursor_hand_closed.xpm deleted file mode 100644 index 61a6de4b88..0000000000 --- a/widgets/misc/pixmaps/cursor_hand_closed.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_hand_closed_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ", -" .. ", -" ..++... ", -" .+++++++.. ", -" .+++++++++. ", -" ...+++++++++. ", -" .++.+++++++++. ", -" .++++++++++++. ", -" .+++++++++++. ", -" .++++++++++. ", -" .+++++++++. ", -" .+++++++. ", -" .++++++. ", -" .++++++. ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_hand_open.xpm b/widgets/misc/pixmaps/cursor_hand_open.xpm deleted file mode 100644 index 048acc8054..0000000000 --- a/widgets/misc/pixmaps/cursor_hand_open.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_hand_open_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" .. ", -" .. .++... ", -" .++..++.++. ", -" .++..++.++. . ", -" .++.++.++..+. ", -" .++.++.++.++. ", -" .. .+++++++.++. ", -" .++..++++++++++. ", -" .+++.+++++++++. ", -" .++++++++++++. ", -" .+++++++++++. ", -" .++++++++++. ", -" .+++++++++. ", -" .+++++++. ", -" .++++++. ", -" .++++++. ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_zoom_in.xpm b/widgets/misc/pixmaps/cursor_zoom_in.xpm deleted file mode 100644 index 1caf9e3e2a..0000000000 --- a/widgets/misc/pixmaps/cursor_zoom_in.xpm +++ /dev/null @@ -1,37 +0,0 @@ -/* XPM */ -static char * cursor_zoom_in_xpm[] = { -"32 32 2 1", -" c None", -". c #000000", -" ", -" ", -" ", -" ", -" ", -" ", -" ...... ", -" .. .. ", -" .. .. ", -" . . ", -" . ... . ", -" . ... . ", -" . ....... . ", -" . ....... . ", -" . ... . ", -" . ... .. ", -" .. . . ", -" .. . . . ", -" ........ . . ", -" ..... . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . ", -" . . ", -" .. ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_zoom_out.xpm b/widgets/misc/pixmaps/cursor_zoom_out.xpm deleted file mode 100644 index af1b698521..0000000000 --- a/widgets/misc/pixmaps/cursor_zoom_out.xpm +++ /dev/null @@ -1,37 +0,0 @@ -/* XPM */ -static char * cursor_zoom_out_xpm[] = { -"32 32 2 1", -" c None", -". c #000000", -" ", -" ", -" ", -" ", -" ", -" ", -" ...... ", -" .. .. ", -" .. .. ", -" . . ", -" . . ", -" . . ", -" . ....... . ", -" . ....... . ", -" . . ", -" . .. ", -" .. . . ", -" .. . . . ", -" ........ . . ", -" ..... . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . ", -" . . ", -" .. ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/shortcut-bar/.cvsignore b/widgets/shortcut-bar/.cvsignore deleted file mode 100644 index 41439d256d..0000000000 --- a/widgets/shortcut-bar/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -*.o -libshortcut-bar.a -Makefile -Makefile.in -.deps -.libs -test-shortcut-bar diff --git a/widgets/shortcut-bar/LICENSE b/widgets/shortcut-bar/LICENSE deleted file mode 100644 index f58649ad9b..0000000000 --- a/widgets/shortcut-bar/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is licensed under the terms of the GNU GPL \ No newline at end of file diff --git a/widgets/shortcut-bar/Makefile.am b/widgets/shortcut-bar/Makefile.am deleted file mode 100644 index ac81f2e2e6..0000000000 --- a/widgets/shortcut-bar/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ - -noinst_LIBRARIES = libshortcut-bar.a -noinst_PROGRAMS = test-shortcut-bar - -INCLUDES = \ - -DEVOLUTION_VERSION=\""$(VERSION)"\" \ - $(EXTRA_GNOME_CFLAGS) - -libshortcut_bar_a_SOURCES = \ - e-clipped-label.c \ - e-clipped-label.h \ - e-group-bar.c \ - e-group-bar.h \ - e-icon-bar-bg-item.c \ - e-icon-bar-bg-item.h \ - e-icon-bar-text-item.c \ - e-icon-bar-text-item.h \ - e-icon-bar.c \ - e-icon-bar.h \ - e-shortcut-bar.c \ - e-shortcut-bar.h \ - e-vscrolled-bar.c \ - e-vscrolled-bar.h - -test_shortcut_bar_SOURCES = \ - test-shortcut-bar.c - -test_shortcut_bar_LDADD = \ - ./libshortcut-bar.a \ - $(EXTRA_GNOME_LIBS) - -test_shortcut_bar_LDFLAGS = \ - `gnome-config --libs gdk_pixbuf gnomecanvaspixbuf` diff --git a/widgets/shortcut-bar/e-clipped-label.c b/widgets/shortcut-bar/e-clipped-label.c deleted file mode 100644 index 0b595f6063..0000000000 --- a/widgets/shortcut-bar/e-clipped-label.c +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This is similar to GtkLabel but clips itself and displays '...' if it - * can't fit inside its allocated area. The intended use is for inside buttons - * that are a fixed size. The GtkLabel would normally display only the middle - * part of the text, which doesn't look very good. This only supports one line - * of text (so no wrapping/justification), without underlined characters. - */ - -#include - -#include -#include -#include - -#include "e-clipped-label.h" - - -static void e_clipped_label_class_init (EClippedLabelClass *class); -static void e_clipped_label_init (EClippedLabel *label); -static void e_clipped_label_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_clipped_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_clipped_label_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_clipped_label_recalc_chars_displayed (EClippedLabel *label); - - -static GtkMiscClass *parent_class; - -/* This is the string to draw when the label is clipped, e.g. '...'. */ -static gchar *e_clipped_label_ellipsis; - -/* Flags used in chars_displayed field. Must be negative. */ -#define E_CLIPPED_LABEL_NEED_RECALC -1 -#define E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL -2 - - -GtkType -e_clipped_label_get_type (void) -{ - static GtkType e_clipped_label_type = 0; - - if (!e_clipped_label_type){ - GtkTypeInfo e_clipped_label_info = { - "EClippedLabel", - sizeof (EClippedLabel), - sizeof (EClippedLabelClass), - (GtkClassInitFunc) e_clipped_label_class_init, - (GtkObjectInitFunc) e_clipped_label_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_MISC); - e_clipped_label_type = gtk_type_unique (GTK_TYPE_MISC, - &e_clipped_label_info); - } - - return e_clipped_label_type; -} - - -static void -e_clipped_label_class_init (EClippedLabelClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - /* Method override */ - widget_class->size_request = e_clipped_label_size_request; - widget_class->size_allocate = e_clipped_label_size_allocate; - widget_class->expose_event = e_clipped_label_expose; - - e_clipped_label_ellipsis = _("..."); -} - - -static void -e_clipped_label_init (EClippedLabel *label) -{ - GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW); - - label->label = NULL; - label->label_wc = NULL; - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; -} - - -/** - * e_clipped_label_new: - * - * @text: The label text. - * @Returns: A new #EClippedLabel. - * - * Creates a new #EClippedLabel with the given text. - **/ -GtkWidget * -e_clipped_label_new (const gchar *text) -{ - GtkWidget *label; - - label = GTK_WIDGET (gtk_type_new (e_clipped_label_get_type ())); - - if (text && *text) - e_clipped_label_set_text (E_CLIPPED_LABEL (label), text); - - return label; -} - - -static void -e_clipped_label_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EClippedLabel *label; - GdkFont *font; - - g_return_if_fail (E_IS_CLIPPED_LABEL (widget)); - g_return_if_fail (requisition != NULL); - - label = E_CLIPPED_LABEL (widget); - font = widget->style->font; - - requisition->width = 0; - requisition->height = font->ascent + font->descent - + 2 * GTK_MISC (widget)->ypad; -} - - -static void -e_clipped_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EClippedLabel *label; - - label = E_CLIPPED_LABEL (widget); - - widget->allocation = *allocation; - - /* Flag that we need to recalculate how many characters to display. */ - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; -} - - -static gint -e_clipped_label_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - EClippedLabel *label; - GtkMisc *misc; - gint x, y; - GdkFont *font; - gchar *tmp_str, tmp_ch; - - g_return_val_if_fail (E_IS_CLIPPED_LABEL (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - label = E_CLIPPED_LABEL (widget); - misc = GTK_MISC (widget); - font = widget->style->font; - - /* If the label isn't visible or has no text, just return. */ - if (!GTK_WIDGET_VISIBLE (widget) || !GTK_WIDGET_MAPPED (widget) - || !label->label || (*label->label == '\0')) - return TRUE; - - /* Recalculate the number of characters displayed, if necessary. */ - if (label->chars_displayed == E_CLIPPED_LABEL_NEED_RECALC) - e_clipped_label_recalc_chars_displayed (label); - - /* - * GC Clipping - */ - gdk_gc_set_clip_rectangle (widget->style->white_gc, - &event->area); - gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state], - &event->area); - - y = floor (widget->allocation.y + (gint)misc->ypad - + (((gint)widget->allocation.height - 2 * (gint)misc->ypad - - (gint)font->ascent - font->descent) - * misc->yalign) + 0.5) + font->ascent; - - if (label->chars_displayed == E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL) { - x = floor (widget->allocation.x + (gint)misc->xpad - + (((gint)widget->allocation.width - - (gint)label->label_width - 2 * (gint)misc->xpad) - * misc->xalign) + 0.5); - - gtk_paint_string (widget->style, widget->window, widget->state, - &event->area, widget, "label", - x, y, label->label); - } else { - x = widget->allocation.x + (gint)misc->xpad; - - tmp_ch = label->label_wc[label->chars_displayed]; - label->label_wc[label->chars_displayed] = '\0'; - tmp_str = gdk_wcstombs (label->label_wc); - if (tmp_str) { - gtk_paint_string (widget->style, widget->window, - widget->state, &event->area, - widget, "label", - x, y, tmp_str); - g_free (tmp_str); - } - label->label_wc[label->chars_displayed] = tmp_ch; - - x = widget->allocation.x + (gint)misc->xpad - + label->ellipsis_x; - gtk_paint_string (widget->style, widget->window, widget->state, - &event->area, widget, "label", - x, y, e_clipped_label_ellipsis); - } - - gdk_gc_set_clip_mask (widget->style->white_gc, NULL); - gdk_gc_set_clip_mask (widget->style->fg_gc[widget->state], NULL); - - return TRUE; -} - - -/** - * e_clipped_label_get_text: - * - * @label: An #EClippedLabel. - * @Return: The label text. - * - * Returns the label text, or NULL. - **/ -gchar* -e_clipped_label_get_text (EClippedLabel *label) -{ - g_return_val_if_fail (E_IS_CLIPPED_LABEL (label), NULL); - - return label->label; -} - - -/** - * e_clipped_label_set_text: - * - * @label: An #EClippedLabel. - * @text: The new label text. - * - * Sets the label text. - **/ -void -e_clipped_label_set_text (EClippedLabel *label, - const gchar *text) -{ - gint len; - - g_return_if_fail (E_IS_CLIPPED_LABEL (label)); - - if (label->label != text || !label->label || !text - || strcmp (label->label, text)) { - g_free (label->label); - g_free (label->label_wc); - label->label = NULL; - label->label_wc = NULL; - - if (text) { - label->label = g_strdup (text); - len = strlen (text); - label->label_wc = g_new (GdkWChar, len + 1); - label->wc_len = gdk_mbstowcs (label->label_wc, - label->label, len + 1); - label->label_wc[label->wc_len] = '\0'; - } - - /* Reset the number of characters displayed, so it is - recalculated when needed. */ - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; - - /* We don't queue a resize, since the label should not affect - the widget size, but we queue a draw. */ - gtk_widget_queue_draw (GTK_WIDGET (label)); - } -} - - -static void -e_clipped_label_recalc_chars_displayed (EClippedLabel *label) -{ - GdkFont *font; - gint max_width, width, ch, last_width; - - font = GTK_WIDGET (label)->style->font; - - max_width = GTK_WIDGET (label)->allocation.width - - 2 * GTK_MISC (label)->xpad; - - if (!label->label) { - label->chars_displayed = 0; - return; - } - - /* See if the entire label fits in the allocated width. */ - label->label_width = gdk_string_width (font, label->label); - if (label->label_width <= max_width) { - label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL; - return; - } - - /* Calculate the width of the ellipsis string. */ - max_width -= gdk_string_measure (font, e_clipped_label_ellipsis); - - if (max_width <= 0) { - label->chars_displayed = 0; - label->ellipsis_x = 0; - return; - } - - /* Step through the wide-char label, adding on the widths of the - characters, until we can't fit any more in. */ - width = last_width = 0; - for (ch = 0; ch < label->wc_len; ch++) { - width += gdk_char_width_wc (font, label->label_wc[ch]); - - if (width > max_width) { - label->chars_displayed = ch; - label->ellipsis_x = last_width; - return; - } - - last_width = width; - } - - g_warning ("Clipped label width not exceeded as expected"); - label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL; -} - diff --git a/widgets/shortcut-bar/e-clipped-label.h b/widgets/shortcut-bar/e-clipped-label.h deleted file mode 100644 index b94d261c11..0000000000 --- a/widgets/shortcut-bar/e-clipped-label.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This is similar to GtkLabel but clips itself and displays '...' if it - * can't fit inside its allocated area. The intended use is for inside buttons - * that are a fixed size. The GtkLabel would normally display only the middle - * part of the text, which doesn't look very good. This only supports one line - * of text (so no wrapping/justification), without underlined characters. - */ -#ifndef _E_CLIPPED_LABEL_H_ -#define _E_CLIPPED_LABEL_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_CLIPPED_LABEL(obj) GTK_CHECK_CAST (obj, e_clipped_label_get_type (), EClippedLabel) -#define E_CLIPPED_LABEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_clipped_label_get_type (), EClippedLabelClass) -#define E_IS_CLIPPED_LABEL(obj) GTK_CHECK_TYPE (obj, e_clipped_label_get_type ()) - - -typedef struct _EClippedLabel EClippedLabel; -typedef struct _EClippedLabelClass EClippedLabelClass; - -struct _EClippedLabel -{ - GtkMisc misc; - - gchar *label; - GdkWChar *label_wc; - - /* This is the number of wide characters in the label. */ - gint wc_len; - - /* This is the width of the entire label string, in pixels. */ - gint label_width; - - /* This is the number of characters we can fit in, or - E_CLIPPED_LABEL_NEED_RECALC if it needs to be recalculated, or - E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL to show the entire label. */ - gint chars_displayed; - - /* This is the x position to display the ellipsis string, e.g. '...', - relative to the start of the label. */ - gint ellipsis_x; -}; - -struct _EClippedLabelClass -{ - GtkMiscClass parent_class; -}; - - -GtkType e_clipped_label_get_type (void); -GtkWidget* e_clipped_label_new (const gchar *text); - -gchar* e_clipped_label_get_text (EClippedLabel *label); -void e_clipped_label_set_text (EClippedLabel *label, - const gchar *text); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CLIPPED_LABEL_H_ */ diff --git a/widgets/shortcut-bar/e-group-bar.c b/widgets/shortcut-bar/e-group-bar.c deleted file mode 100644 index ac3a8d62ab..0000000000 --- a/widgets/shortcut-bar/e-group-bar.c +++ /dev/null @@ -1,1496 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * ShortcutBar displays a vertical bar with a number of Groups, each of which - * contains any number of icons. It is used on the left of the main application - * window so users can easily access items such as folders and files. - */ - -#include - -#include - -#include "e-group-bar.h" - -#define E_GROUP_BAR_SCROLL_TIMEOUT 10 -#define E_GROUP_BAR_MIN_STEP_SIZE 4 - -#define E_GROUP_BAR_AUTO_SHOW_TIMEOUT 300 - - -static void e_group_bar_class_init (EGroupBarClass *class); -static void e_group_bar_init (EGroupBar *group_bar); -static void e_group_bar_destroy (GtkObject *object); -static void e_group_bar_realize (GtkWidget *widget); -static void e_group_bar_unrealize (GtkWidget *widget); -static void e_group_bar_map (GtkWidget *widget); -static void e_group_bar_unmap (GtkWidget *widget); -static void e_group_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_group_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_group_bar_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_group_bar_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_group_bar_add (GtkContainer *container, - GtkWidget *widget); -static void e_group_bar_remove (GtkContainer *container, - GtkWidget *widget); -static void e_group_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void e_group_bar_create_group_button_window (EGroupBar *group_bar, - gint group_num); -static void e_group_bar_create_group_child_window (EGroupBar *group_bar, - gint group_num); -static gint e_group_bar_get_group_button_position (EGroupBar *group_bar, - gint group_num); -static gint e_group_bar_sum_button_heights (EGroupBar *group_bar, - gint first, - gint last); -static gint e_group_bar_get_child_height (EGroupBar *group_bar); -static gint e_group_bar_get_group_child_position (EGroupBar *group_bar, - gint group_num); - -static void e_group_bar_on_button_clicked (GtkWidget *group_button, - EGroupBar *group_bar); -static gint e_group_bar_find_button (EGroupBar *group_bar, - GtkWidget *group_button); -static void e_group_bar_start_animation (EGroupBar *group_bar, - gint group_num); -static gboolean e_group_bar_timeout_handler (gpointer data); -static gint e_group_bar_get_increment (EGroupBar *group_bar, - gint window_y, - gint window_target_y); -static gboolean e_group_bar_on_button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EGroupBar *group_bar); -static void e_group_bar_on_button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EGroupBar *group_bar); -static gboolean e_group_bar_auto_show (gpointer data); -static void e_group_bar_stop_all_animation (EGroupBar *group_bar); - - -static GtkContainerClass *parent_class; - - -GtkType -e_group_bar_get_type (void) -{ - static GtkType e_group_bar_type = 0; - - if (!e_group_bar_type){ - GtkTypeInfo e_group_bar_info = { - "EGroupBar", - sizeof (EGroupBar), - sizeof (EGroupBarClass), - (GtkClassInitFunc) e_group_bar_class_init, - (GtkObjectInitFunc) e_group_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - e_group_bar_type = gtk_type_unique (GTK_TYPE_CONTAINER, - &e_group_bar_info); - } - - return e_group_bar_type; -} - - -static void -e_group_bar_class_init (EGroupBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - /* Method override */ - object_class->destroy = e_group_bar_destroy; - - widget_class->realize = e_group_bar_realize; - widget_class->unrealize = e_group_bar_unrealize; - widget_class->map = e_group_bar_map; - widget_class->unmap = e_group_bar_unmap; - widget_class->size_request = e_group_bar_size_request; - widget_class->size_allocate = e_group_bar_size_allocate; - widget_class->expose_event = e_group_bar_expose; - widget_class->draw = e_group_bar_draw; - - container_class->add = e_group_bar_add; - container_class->remove = e_group_bar_remove; - container_class->forall = e_group_bar_forall; -} - - -static void -e_group_bar_init (EGroupBar *group_bar) -{ - - GTK_WIDGET_UNSET_FLAGS (group_bar, GTK_NO_WINDOW); - - /* We don't want child resizes to propagate up to the parent. */ - gtk_container_set_resize_mode (GTK_CONTAINER (group_bar), - GTK_RESIZE_QUEUE); - - group_bar->children = g_array_new (FALSE, FALSE, - sizeof (EGroupBarChild)); - - group_bar->current_group_num = -1; - group_bar->buttons_homogeneous = TRUE; - group_bar->max_button_height = 0; - group_bar->animation_timeout_id = 0; -} - - -/** - * e_group_bar_new: - * @Returns: a new #EGroupBar. - * - * Creates a new #EGroupBar. - **/ -GtkWidget * -e_group_bar_new (void) -{ - GtkWidget *group_bar; - - group_bar = GTK_WIDGET (gtk_type_new (e_group_bar_get_type ())); - - return group_bar; -} - - -static void -e_group_bar_destroy (GtkObject *object) -{ - EGroupBar *group_bar; - - group_bar = E_GROUP_BAR (object); - - e_group_bar_stop_all_animation (group_bar); - - /* The parent GtkContainer class will automatically destroy all the - child widgets, but it calls gtk_container_foreach() so we must not - destroy our children array until after. */ - GTK_OBJECT_CLASS (parent_class)->destroy (object); - - g_array_free (group_bar->children, TRUE); -} - - -static void -e_group_bar_realize (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - GdkWindowAttr attributes; - gint attributes_mask; - gint border_width, group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x + border_width; - attributes.y = widget->allocation.y + border_width; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = widget->allocation.height - 2 * border_width; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, - GTK_STATE_NORMAL); - - gdk_window_set_back_pixmap (widget->window, NULL, TRUE); - - /* Create windows for all the buttons & group canvases. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - e_group_bar_create_group_button_window (group_bar, group_num); - e_group_bar_create_group_child_window (group_bar, group_num); - } -} - - -static void -e_group_bar_unrealize (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - /* Destroy the windows for all the buttons & group canvases. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_set_user_data (group->button_window, NULL); - gdk_window_destroy (group->button_window); - group->button_window = NULL; - } - if (group->child_window) { - gdk_window_set_user_data (group->child_window, NULL); - gdk_window_destroy (group->child_window); - group->child_window = NULL; - } - } - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - - -static void -e_group_bar_map (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - - /* We do this in reverse order, and lower all the child windows, so - the stacking order ends up correct. */ - for (group_num = group_bar->children->len - 1; - group_num >= 0; - group_num--) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_show (group->button_window); - } - - if (group->button - && GTK_WIDGET_VISIBLE (group->button) - && !GTK_WIDGET_MAPPED (group->button)) { - gtk_widget_map (group->button); - } - - if (group->child_window) { - gdk_window_show (group->child_window); - gdk_window_lower (group->child_window); - } - - if (group->child - && GTK_WIDGET_VISIBLE (group->child) - && !GTK_WIDGET_MAPPED (group->child)) - gtk_widget_map (group->child); - } - - gdk_window_show (widget->window); -} - - -static void -e_group_bar_unmap (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_hide (group->button_window); - } - - if (group->button - && GTK_WIDGET_MAPPED (group->button)) - gtk_widget_unmap (group->button); - - if (group->child_window) { - gdk_window_hide (group->child_window); - } - - if (group->child - && GTK_WIDGET_MAPPED (group->child)) - gtk_widget_unmap (group->child); - } - - gdk_window_hide (widget->window); -} - - -static void -e_group_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, max_child_height; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - g_return_if_fail (requisition != NULL); - - group_bar = E_GROUP_BAR (widget); - - /* We set the requisition width to the largest requested width of the - child widgets. The requisition height is set to the sum of all the - button heights plus the height of the largest child. */ - requisition->width = 0; - requisition->height = 0; - - /* We have to call size_request on all children, even though we don't - use the results, since some widgets like GtkLabel depend on it. */ - group_bar->max_button_height = 0; - max_child_height = 0; - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button) { - gtk_widget_size_request (group->button, - &child_requisition); - group->button_height = child_requisition.height; - } else { - group->button_height = 0; - } - - group_bar->max_button_height = MAX (group_bar->max_button_height, group->button_height); - requisition->height += child_requisition.height; - - if (group->child) { - gtk_widget_size_request (group->child, - &child_requisition); - max_child_height = MAX (max_child_height, - child_requisition.height); - requisition->width = MAX (requisition->width, - child_requisition.width); - } - } - - requisition->height += max_child_height; - - /* Add on the standard container border widths. */ - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; -} - - -static void -e_group_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, border_width, width, height, child_height, y; - GtkAllocation button_allocation, child_allocation; - - group_bar = E_GROUP_BAR (widget); - - /* All child & button windows and widgets use the same width as the - group bar minus the border width. */ - border_width = GTK_CONTAINER (widget)->border_width; - width = allocation->width - border_width * 2; - height = allocation->height - border_width * 2; - - widget->allocation = *allocation; - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x + border_width, - allocation->y + border_width, - width, height); - - /* All the child widgets use the same height. */ - child_height = e_group_bar_get_child_height (group_bar); - - /* The buttons are always in the top-left of the button windows, and - all have the same width. The height is calculated for each group. */ - button_allocation.x = 0; - button_allocation.y = 0; - button_allocation.width = width; - - /* The child widgets are always in the top-left of the child windows, - and all have the same width and height. */ - child_allocation.x = 0; - child_allocation.y = 0; - child_allocation.width = width; - child_allocation.height = child_height; - - /* Step through the groups, placing the windows as necessary, and - allocating the areas for the child widgets. Note that if a button - or child window is in the middle of an animation, we just resize it - and update the target position, and let the animation continue. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Calculate the y position of the button, which depends on - the currently selected group and the button heights. */ - y = e_group_bar_get_group_button_position (group_bar, group_num); - button_allocation.height = group_bar->buttons_homogeneous ? group_bar->max_button_height : group->button_height; - - if (GTK_WIDGET_REALIZED (group->button)) { - if (group->button_window_in_animation) { - gdk_window_resize (group->button_window, - width, button_allocation.height); - group->button_window_target_y = y; - } else { - gdk_window_move_resize (group->button_window, - 0, y, width, button_allocation.height); - } - } - gtk_widget_size_allocate (group->button, &button_allocation); - - if (GTK_WIDGET_REALIZED (group->child)) { - if (group->child_window_in_animation) { - gdk_window_resize (group->child_window, - width, child_height); - group->child_window_target_y = y + button_allocation.height; - } else { - gdk_window_move_resize (group->child_window, - 0, y + button_allocation.height, - width, child_height); - } - } - gtk_widget_size_allocate (group->child, &child_allocation); - } -} - - -static gint -e_group_bar_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - GdkEventExpose child_event; - gint group_num; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_GROUP_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (GTK_WIDGET_DRAWABLE (widget)) { - group_bar = E_GROUP_BAR (widget); - - child_event = *event; - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (event->window == group->button_window - && GTK_WIDGET_DRAWABLE (group->button) - && GTK_WIDGET_NO_WINDOW (group->button) - && gtk_widget_intersect (group->button, &event->area, &child_event.area)) - gtk_widget_event (group->button, (GdkEvent*) &child_event); - - if (event->window == group->child_window - && GTK_WIDGET_DRAWABLE (group->child) - && GTK_WIDGET_NO_WINDOW (group->child) - && gtk_widget_intersect (group->child, &event->area, &child_event.area)) - gtk_widget_event (group->child, (GdkEvent*) &child_event); - } - } - - return FALSE; -} - - -static void -e_group_bar_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - if (GTK_WIDGET_DRAWABLE (widget)) { - group_bar = E_GROUP_BAR (widget); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (GTK_WIDGET_DRAWABLE (group->button) - && gtk_widget_intersect (group->button, area, &child_area)) - gtk_widget_draw (group->button, &child_area); - - if (GTK_WIDGET_DRAWABLE (group->child) - && gtk_widget_intersect (group->child, area, &child_area)) - gtk_widget_draw (group->child, &child_area); - } - } -} - - -static void -e_group_bar_add (GtkContainer *container, - GtkWidget *widget) -{ - EGroupBar *group_bar; - GtkWidget *button; - gchar buffer[32]; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (widget != NULL); - - g_snprintf (buffer, sizeof (buffer), _("Group %i"), - group_bar->children->len + 1); - button = gtk_button_new_with_label (buffer); - gtk_widget_show (button); - - e_group_bar_add_group (group_bar, widget, button, -1); -} - - -static void -e_group_bar_remove (GtkContainer *container, - GtkWidget *widget) -{ - EGroupBar *group_bar; - gint group_num; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (widget != NULL); - - group_bar = E_GROUP_BAR (container); - - group_num = e_group_bar_get_group_num (group_bar, widget); - e_group_bar_remove_group (group_bar, group_num); -} - - -static void -e_group_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - GList *tmp_list; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (callback != NULL); - - group_bar = E_GROUP_BAR (container); - - /* Note that drag-and-drop does not check the Z-order of widgets, so - we have to iterate through them from top to bottom, or it will - not work properly. We also have to use temporary lists so widgets - can be safely destroyed while iterating. */ - - if (include_internals) { - tmp_list = NULL; - for (group_num = group_bar->children->len - 1; - group_num >= 0; - group_num--) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button) - tmp_list = g_list_prepend (tmp_list, - group->button); - } - - g_list_foreach (tmp_list, (GFunc) callback, callback_data); - g_list_free (tmp_list); - } - - tmp_list = NULL; - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->child) - tmp_list = g_list_prepend (tmp_list, group->child); - } - g_list_foreach (tmp_list, (GFunc) callback, callback_data); - g_list_free (tmp_list); -} - - -static void -e_group_bar_create_group_button_window (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - GtkWidget *widget; - GdkWindowAttr attributes; - gint attributes_mask; - gint y, height, border_width; - - widget = GTK_WIDGET (group_bar); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y = e_group_bar_get_group_button_position (group_bar, group_num); - height = group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = 0; - attributes.y = y; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - group->button_window = gdk_window_new (widget->window, &attributes, - attributes_mask); - gdk_window_set_user_data (group->button_window, widget); - - gtk_widget_set_parent_window (group->button, - group->button_window); - gdk_window_set_back_pixmap (group->button_window, NULL, TRUE); -} - - -static void -e_group_bar_create_group_child_window (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - GtkWidget *widget; - GdkWindowAttr attributes; - gint attributes_mask; - gint y, height, border_width; - - widget = GTK_WIDGET (group_bar); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y = e_group_bar_get_group_button_position (group_bar, group_num); - y += group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - height = e_group_bar_get_child_height (group_bar); - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = 0; - attributes.y = y; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - group->child_window = gdk_window_new (widget->window, &attributes, - attributes_mask); - gdk_window_set_user_data (group->child_window, widget); - - gtk_widget_set_parent_window (GTK_WIDGET (group->child), - group->child_window); - gdk_window_set_back_pixmap (group->child_window, NULL, TRUE); -} - - -/* This returns the y position of a group's button within the EGroupBar window. - */ -static gint -e_group_bar_get_group_button_position (EGroupBar *group_bar, - gint group_num) -{ - gint border_width, window_height, y; - - border_width = GTK_CONTAINER (group_bar)->border_width; - window_height = GTK_WIDGET (group_bar)->allocation.height - 2 * border_width; - - if (group_num <= group_bar->current_group_num) - y = e_group_bar_sum_button_heights (group_bar, 0, group_num - 1); - else - y = window_height - e_group_bar_sum_button_heights (group_bar, group_num, group_bar->children->len - 1); - - return y; -} - - -/* This returns the sum of all the buttons from first to last inclusive. */ -static gint -e_group_bar_sum_button_heights (EGroupBar *group_bar, gint first, gint last) -{ - EGroupBarChild *group; - gint height, group_num; - - height = 0; - - if (group_bar->buttons_homogeneous) - return (last - first + 1) * group_bar->max_button_height; - - for (group_num = first; group_num <= last; group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - height += group->button_height; - } - - return height; -} - - -static gint -e_group_bar_get_group_child_position (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - gint y; - - y = e_group_bar_get_group_button_position (group_bar, group_num); - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y += group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - - return y; -} - - -static gint -e_group_bar_get_child_height (EGroupBar *group_bar) -{ - EGroupBarChild *group; - gint group_num; - - /* Start with the allocated height of the EGroupBar, less the border.*/ - group_bar->child_height = GTK_WIDGET (group_bar)->allocation.height; - group_bar->child_height -= 2 * GTK_CONTAINER (group_bar)->border_width; - - /* Now subtract the heights of all the buttons. */ - if (group_bar->buttons_homogeneous) { - group_bar->child_height -= group_bar->children->len * group_bar->max_button_height; - } else { - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group_bar->child_height -= group->button_height; - } - } - - return group_bar->child_height; -} - - -/* - * Insertion, reordering and deletion of items. - */ - -/** - * e_group_bar_add_group: - * @group_bar: an #EGroupBar. - * @child: the child widget to add. - * @button: the button used to show the child widget. - * @position: the new group's position, or -1 to place it last. - * @Returns: the position of the new group. - * - * Adds a new group to a #EGroupBar at the given position. - **/ -gint -e_group_bar_add_group (EGroupBar *group_bar, - GtkWidget *child, - GtkWidget *button, - gint position) -{ - EGroupBarChild *group, empty_group, *tmp_group; - gint group_num, tmp_group_num; - - g_return_val_if_fail (group_bar != NULL, -1); - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - g_return_val_if_fail (child != NULL, -1); - g_return_val_if_fail (button != NULL, -1); - g_return_val_if_fail (GTK_IS_BUTTON (button), -1); - - /* Append an empty group to the children array and get a pointer to - it, so we can use it like a normal group. */ - group_num = group_bar->children->len; - g_array_append_val (group_bar->children, empty_group); - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Initialize the group. */ - group->button = button; - group->button_window = NULL; - group->child = child; - group->child_window = NULL; - group->button_window_in_animation = FALSE; - group->child_window_in_animation = FALSE; - group->button_window_target_y = 0; - group->child_window_target_y = 0; - - /* If we don't have a current group, set it to the first one. */ - if (group_bar->current_group_num == -1) - group_bar->current_group_num = 0; - - /* If the EGroupBar widget is realize, we need to create the child - windows to put the button & child in. */ - if (GTK_WIDGET_REALIZED (group_bar)) { - e_group_bar_create_group_button_window (group_bar, group_num); - e_group_bar_create_group_child_window (group_bar, group_num); - - /* We need to lower all the child windows of the previous - groups, in reverse order, to keep the stacking order - correct. */ - for (tmp_group_num = group_num - 1; - tmp_group_num >= 0; - tmp_group_num--) { - tmp_group = &g_array_index (group_bar->children, - EGroupBarChild, - tmp_group_num); - gdk_window_lower (group->child_window); - } - } - - gtk_widget_set_parent (group->button, GTK_WIDGET (group_bar)); - gtk_widget_set_parent (group->child, GTK_WIDGET (group_bar)); - - if (GTK_WIDGET_REALIZED (group_bar)) { - gtk_widget_realize (group->button); - gtk_widget_realize (group->child); - } - - if (GTK_WIDGET_VISIBLE (group_bar) - && GTK_WIDGET_MAPPED (group_bar)) { - if (group->button - && GTK_WIDGET_VISIBLE (group->button) - && !GTK_WIDGET_MAPPED (group->button)) { - gtk_widget_map (group->button); - gtk_widget_queue_resize (group->button); - } - if (group->child - && GTK_WIDGET_VISIBLE (group->child) - && !GTK_WIDGET_MAPPED (group->child)) { - gtk_widget_map (group->child); - gtk_widget_queue_resize (group->child); - } - } - - gtk_signal_connect (GTK_OBJECT (group->button), "clicked", - GTK_SIGNAL_FUNC (e_group_bar_on_button_clicked), - group_bar); - - gtk_signal_connect (GTK_OBJECT (group->button), "drag_motion", - GTK_SIGNAL_FUNC (e_group_bar_on_button_drag_motion), - group_bar); - gtk_signal_connect (GTK_OBJECT (group->button), "drag_leave", - GTK_SIGNAL_FUNC (e_group_bar_on_button_drag_leave), - group_bar); - - return group_num; -} - - -/** - * e_group_bar_reorder_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to move. - * @new_position: the new position of the group. - * - * Moves a group to a new position within the #EGroupBar. - **/ -void -e_group_bar_reorder_group (EGroupBar *group_bar, - gint group_num, - gint new_position) -{ - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - -} - - -/** - * e_group_bar_remove_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to remove. - * - * Removes a group from an #EGroupBar. - **/ -void -e_group_bar_remove_group (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < group_bar->children->len); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Stop any animation. */ - e_group_bar_stop_all_animation (group_bar); - - gtk_widget_unparent (group->child); - if (group->button) - gtk_widget_unparent (group->button); - - if (group->button_window) { - gdk_window_set_user_data (group->button_window, NULL); - gdk_window_destroy (group->button_window); - } - if (group->child_window) { - gdk_window_set_user_data (group->child_window, NULL); - gdk_window_destroy (group->child_window); - } - - g_array_remove_index (group_bar->children, group_num); - - /* Make sure the current group is valid. */ - if (group_bar->current_group_num >= group_bar->children->len) - group_bar->current_group_num = group_bar->children->len - 1; - - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); -} - - -/* - * Getting & setting the current group. - */ - -/** - * e_group_bar_get_current_group_num: - * @group_bar: an #EGroupBar. - * @Returns: the index of the group currently displayed. - * - * Returns the index of the group currently displayed. - **/ -gint -e_group_bar_get_current_group_num (EGroupBar *group_bar) -{ - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - - return group_bar->current_group_num; -} - - -/** - * e_group_bar_set_current_group_num: - * @group_bar: an #EGroupBar. - * @Returns: the index of the group to display. - * - * Sets the group to display. - **/ -/* FIXME: animate option? May want to set group without animation. */ -void -e_group_bar_set_current_group_num (EGroupBar *group_bar, - gint group_num) -{ - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - - /* If that already is the current group, just return. */ - if (group_bar->current_group_num == group_num) - return; - - /* FIXME: Set the target positions of the old current group and the - new current group, map the new group's child window, and create the - animation timeout, if we haven't already got one. */ - - group_bar->current_group_num = group_num; - -} - - -/* - * Getting groups and group numbers. - */ - -/** - * e_group_bar_get_nth_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to get. - * @Returns: the child widget at the given index. - * - * Returns the child widget at the given index. - **/ -GtkWidget* -e_group_bar_get_nth_group (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), NULL); - g_return_val_if_fail (group_num >= 0, NULL); - g_return_val_if_fail (group_num < group_bar->children->len, NULL); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - return group->child; -} - - -/** - * e_group_bar_get_group_num: - * @group_bar: an #EGroupBar. - * @child: the child widget to find. - * @Returns: the index of the group containing the given widget. - * - * Returns the index of the group containing the given child widget. - **/ -gint -e_group_bar_get_group_num (EGroupBar *group_bar, - GtkWidget *child) -{ - EGroupBarChild *group; - gint group_num; - - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - g_return_val_if_fail (child != NULL, -1); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->child == child) - return group_num; - } - - return -1; -} - - -/** - * e_group_bar_set_group_button_label: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group. - * @label: the label widget to place in the group's button. - * - * Sets the label widget for the given group's button, replacing any existing - * widget in the button. - **/ -void -e_group_bar_set_group_button_label (EGroupBar *group_bar, - gint group_num, - GtkWidget *label) -{ - EGroupBarChild *group; - GtkWidget *button_child; - - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < group_bar->children->len); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - button_child = GTK_BIN (group->button)->child; - if (button_child) { - gtk_container_remove (GTK_CONTAINER (group->button), - button_child); - } - - if (label) - gtk_container_add (GTK_CONTAINER (group->button), label); -} - - -/* - * Getting & setting the EGroupBar options. - */ - -/** - * e_group_bar_get_buttons_homogeneous: - * @group_bar: an #EGroupBar. - * @Returns: TRUE if the buttons are homoegeneous. - * - * Returns TRUE if the buttons are homogeneous (i.e. all have the same height). - **/ -gboolean -e_group_bar_get_buttons_homogeneous (EGroupBar *group_bar) -{ - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), TRUE); - - return group_bar->buttons_homogeneous; -} - - -/** - * e_group_bar_set_buttons_homogeneous: - * @group_bar: an #EGroupBar. - * @homogeneous: TRUE if the buttons should be homoegeneous. - * - * Specifies whether the buttons should be homogeneous. When set to TRUE all - * the group buttons will be set to the same height (equal to the largest - * requested height). When set to FALSE the buttons will use their own - * individual requested heights. - **/ -void -e_group_bar_set_buttons_homogeneous (EGroupBar *group_bar, - gboolean homogeneous) -{ - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - - /* Just return if the setting hasn't changed. */ - if (group_bar->buttons_homogeneous == homogeneous) - return; - - group_bar->buttons_homogeneous = homogeneous; - - /* Update the position & sizes of the buttons. */ - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); -} - - -static void -e_group_bar_on_button_clicked (GtkWidget *group_button, - EGroupBar *group_bar) -{ - gint group_num; - - /* Determine which group button was clicked. */ - group_num = e_group_bar_find_button (group_bar, group_button); - - if (group_num != -1) - e_group_bar_start_animation (group_bar, group_num); -} - - -/* This returns the group containing the given button, or -1 if not found. */ -static gint -e_group_bar_find_button (EGroupBar *group_bar, - GtkWidget *group_button) -{ - EGroupBarChild *group; - gint group_num; - - /* Determine which group button was clicked. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - if (group->button == group_button) - return group_num; - } - - return -1; -} - - -static void -e_group_bar_start_animation (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group, *old_group; - gint old_group_num, step; - - old_group_num = group_bar->current_group_num; - - /* Return if it is already the current group. */ - if (old_group_num == group_num) - return; - - group_bar->current_group_num = group_num; - - /* Calculate the target y position of the new current group button - and child, and map the child. */ - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, group_num); - group->button_window_in_animation = TRUE; - - group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, group_num); - group->child_window_in_animation = TRUE; - - /* Calculate the target y position of the current group button and - child. */ - old_group = &g_array_index (group_bar->children, - EGroupBarChild, old_group_num); - old_group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, old_group_num); - old_group->button_window_in_animation = TRUE; - - old_group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, old_group_num); - old_group->child_window_in_animation = TRUE; - - /* We also need to animate the buttons in between the old group and the - new group. */ - step = (old_group_num < group_num) ? 1 : -1; - old_group_num += step; - while (old_group_num != group_num) { - old_group = &g_array_index (group_bar->children, - EGroupBarChild, old_group_num); - old_group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, old_group_num); - old_group->button_window_in_animation = TRUE; - - old_group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, old_group_num); - old_group->child_window_in_animation = TRUE; - - old_group_num += step; - } - - /* Add a timeout handler if we haven't already got one. */ - if (group_bar->animation_timeout_id == 0) { - group_bar->animation_timeout_id = g_timeout_add (E_GROUP_BAR_SCROLL_TIMEOUT, e_group_bar_timeout_handler, group_bar); - } -} - - -static gboolean -e_group_bar_timeout_handler (gpointer data) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, button_window_y, child_window_y; - gboolean finished = TRUE; - - g_return_val_if_fail (E_IS_GROUP_BAR (data), FALSE); - - group_bar = E_GROUP_BAR (data); - - GDK_THREADS_ENTER (); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window_in_animation) { - gdk_window_get_position (group->button_window, NULL, - &button_window_y); - button_window_y += e_group_bar_get_increment (group_bar, button_window_y, group->button_window_target_y); - if (button_window_y == group->button_window_target_y) - group->button_window_in_animation = FALSE; - else - finished = FALSE; - gdk_window_move (group->button_window, - 0, button_window_y); - } - if (group->child_window_in_animation) { - gdk_window_get_position (group->child_window, NULL, - &child_window_y); - child_window_y += e_group_bar_get_increment (group_bar, child_window_y, group->child_window_target_y); - if (child_window_y == group->child_window_target_y) - group->child_window_in_animation = FALSE; - else - finished = FALSE; - gdk_window_move (group->child_window, - 0, child_window_y); - } - - } - - if (finished) - group_bar->animation_timeout_id = 0; - - GDK_THREADS_LEAVE (); - - return !finished; -} - - -static gint -e_group_bar_get_increment (EGroupBar *group_bar, - gint window_y, - gint window_target_y) -{ - gdouble percentage; - gint distance, total_distance, step; - - total_distance = group_bar->child_height; - distance = MIN (abs (window_target_y - window_y), total_distance); - - /* Convert the distance into an angle between -PI/2 and PI/2, so we can - then do a cosine of it. */ - percentage = cos (M_PI * ((gdouble)distance / (gdouble)total_distance) - M_PI / 2); - - /* Now multiply by our maximum step size to get the step size. */ - step = percentage * total_distance / 6; - - /* Add it to the minimum step size, but don't go too far. */ - step = step + E_GROUP_BAR_MIN_STEP_SIZE; - step = MIN (step, distance); - - if (window_target_y > window_y) - return step; - else - return -step; -} - - -static gboolean -e_group_bar_on_button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EGroupBar *group_bar) -{ - gint group_num; - - if (!group_bar->auto_show_timeout_id) { - group_num = e_group_bar_find_button (group_bar, widget); - if (group_num != -1) { - group_bar->auto_show_timeout_id = gtk_timeout_add (E_GROUP_BAR_AUTO_SHOW_TIMEOUT, e_group_bar_auto_show, group_bar); - group_bar->auto_show_group_num = group_num; - } - } - return TRUE; -} - - -static void -e_group_bar_on_button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EGroupBar *group_bar) -{ - if (group_bar->auto_show_timeout_id) { - gtk_timeout_remove (group_bar->auto_show_timeout_id); - group_bar->auto_show_timeout_id = 0; - } -} - - -static gboolean -e_group_bar_auto_show (gpointer data) -{ - EGroupBar *group_bar; - - g_return_val_if_fail (E_IS_GROUP_BAR (data), FALSE); - - group_bar = E_GROUP_BAR (data); - - GDK_THREADS_ENTER (); - - e_group_bar_start_animation (group_bar, - group_bar->auto_show_group_num); - - group_bar->auto_show_timeout_id = 0; - - GDK_THREADS_LEAVE (); - - return FALSE; -} - - -/* This removes all timeouts and sets all 'in_animation' flags to FALSE. */ -static void -e_group_bar_stop_all_animation (EGroupBar *group_bar) -{ - EGroupBarChild *group; - gint group_num; - - if (group_bar->animation_timeout_id) { - g_source_remove (group_bar->animation_timeout_id); - group_bar->animation_timeout_id = 0; - } - if (group_bar->auto_show_timeout_id) { - g_source_remove (group_bar->auto_show_timeout_id); - group_bar->auto_show_timeout_id = 0; - } - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group->button_window_in_animation = FALSE; - group->child_window_in_animation = FALSE; - } -} - diff --git a/widgets/shortcut-bar/e-group-bar.h b/widgets/shortcut-bar/e-group-bar.h deleted file mode 100644 index 9a6f83b461..0000000000 --- a/widgets/shortcut-bar/e-group-bar.h +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_GROUP_BAR_H_ -#define _E_GROUP_BAR_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EGroupBar displays a vertical bar with a number of Groups, which are viewed - * one at a time by selecting the Group's button. When a different Group is - * selected, it slides into view, and the old Group slides out. - * It is typically used on the left of the main application window so users - * can easily access particular features. - * - * It is implemented like GtkNotebook, i.e. the main widgets are the children - * of the EGroupBar and the button widgets are treated specially like the - * GtkNotebook tab labels. - */ - -/* This contains information on one item. */ -typedef struct _EGroupBarChild EGroupBarChild; -struct _EGroupBarChild -{ - /* This is the button used to select the group, and the window we use - to move it around easily. */ - GtkWidget *button; - GdkWindow *button_window; - gint button_height; - - /* This is the child widget, which can be any widget added by the - application, and the window we use to move it around easily. */ - GtkWidget *child; - GdkWindow *child_window; - - /* These are TRUE if we are currently animating the windows. */ - gboolean button_window_in_animation; - gboolean child_window_in_animation; - - /* These are the target y positions that the windows should eventually - move to, used for animation. If we get a size_allocate we just - update these and the animation can continue as normal. - When a child window reaches its target position, it is unmapped if - if it is not the current group (i.e. it has slid off screen). */ - gint button_window_target_y; - gint child_window_target_y; -}; - - -#define E_GROUP_BAR(obj) GTK_CHECK_CAST (obj, e_group_bar_get_type (), EGroupBar) -#define E_GROUP_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_group_bar_get_type (), EGroupBarClass) -#define E_IS_GROUP_BAR(obj) GTK_CHECK_TYPE (obj, e_group_bar_get_type ()) - - -typedef struct _EGroupBar EGroupBar; -typedef struct _EGroupBarClass EGroupBarClass; - -struct _EGroupBar -{ - GtkContainer container; - - /* This is an array of EGroupBarChild elements. */ - GArray *children; - - /* This is the group currently shown. */ - gint current_group_num; - - /* This is TRUE if all the buttons are allocated the same height. */ - gboolean buttons_homogeneous; - - /* This is the biggest requested height of all the buttons, which we - use for all buttons when buttons_homogeneous is set. */ - gint max_button_height; - - /* This is the height of all the child windows & widgets. */ - gint child_height; - - /* The id of the source function for animation timeouts. If this is - not 0 then we are in the middle of an animation. */ - guint animation_timeout_id; - - /* The id of the source function for automatically showing groups when - the user drags over the group button, and the group to show. */ - guint auto_show_timeout_id; - gint auto_show_group_num; -}; - -struct _EGroupBarClass -{ - GtkContainerClass parent_class; -}; - - -GtkType e_group_bar_get_type (void); -GtkWidget* e_group_bar_new (void); - -/* - * Insertion, reordering and deletion of items. - */ - -/* Adds a new group at the given position. If position is -1 it adds it as - the last group. It returns the group number. */ -gint e_group_bar_add_group (EGroupBar *group_bar, - GtkWidget *child, - GtkWidget *button, - gint position); -void e_group_bar_reorder_group (EGroupBar *group_bar, - gint group_num, - gint new_position); -void e_group_bar_remove_group (EGroupBar *group_bar, - gint group_num); - -/* - * Getting & setting the current group. - */ -gint e_group_bar_get_current_group_num (EGroupBar *group_bar); -void e_group_bar_set_current_group_num (EGroupBar *group_bar, - gint group_num); - -/* - * Getting groups and group numbers. - */ -GtkWidget* e_group_bar_get_nth_group (EGroupBar *group_bar, - gint group_num); -gint e_group_bar_get_group_num (EGroupBar *group_bar, - GtkWidget *child); - -/* - * Setting the group button label. - */ -void e_group_bar_set_group_button_label (EGroupBar *group_bar, - gint group_num, - GtkWidget *label); - -/* - * Getting & setting the EGroupBar options. - */ -gboolean e_group_bar_get_buttons_homogeneous (EGroupBar *group_bar); -void e_group_bar_set_buttons_homogeneous (EGroupBar *group_bar, - gboolean homogeneous); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_GROUP_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-icon-bar-bg-item.c b/widgets/shortcut-bar/e-icon-bar-bg-item.c deleted file mode 100644 index 1bdb7a308d..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-bg-item.c +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar. - * It paints the rectangles around items when the mouse moves over them, and - * the lines between items when dragging. - */ - -#include "e-icon-bar-bg-item.h" -#include "e-icon-bar.h" - -/* This is the size of the border around the icons, for the shadow. */ -#define E_ICON_BAR_LARGE_ICON_SHADOW_BORDER 2 -#define E_ICON_BAR_SMALL_ICON_SHADOW_BORDER 2 - -/* These are for the horzontal bar when dragging. */ -#define E_ICON_BAR_BG_ITEM_BAR_HEIGHT 1 -#define E_ICON_BAR_BG_ITEM_BAR_OFFSET 2 -#define E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT 8 -#define E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT 4 - -static void e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class); -static void e_icon_bar_bg_item_init (EIconBarBgItem *ibitem); - -static void e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_icon_bar_bg_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_icon_bar_bg_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_icon_bar_bg_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_icon_bar_bg_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gint e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem, - GdkEvent *event); -static gint e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem, - GdkEvent *event); -static gint e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem, - GdkEvent *event); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_ICON_BAR -}; - - -GtkType -e_icon_bar_bg_item_get_type (void) -{ - static GtkType e_icon_bar_bg_item_type = 0; - - if (!e_icon_bar_bg_item_type) { - GtkTypeInfo e_icon_bar_bg_item_info = { - "EIconBarBgItem", - sizeof (EIconBarBgItem), - sizeof (EIconBarBgItemClass), - (GtkClassInitFunc) e_icon_bar_bg_item_class_init, - (GtkObjectInitFunc) e_icon_bar_bg_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_icon_bar_bg_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_icon_bar_bg_item_info); - } - - return e_icon_bar_bg_item_type; -} - - -static void -e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EIconBarBgItem::icon_bar", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_ICON_BAR); - - object_class->set_arg = e_icon_bar_bg_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_icon_bar_bg_item_update; - item_class->draw = e_icon_bar_bg_item_draw; - item_class->point = e_icon_bar_bg_item_point; - item_class->event = e_icon_bar_bg_item_event; -} - - -static void -e_icon_bar_bg_item_init (EIconBarBgItem *ibitem) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (ibitem); - - ibitem->icon_bar = NULL; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EIconBarBgItem *ibitem; - - item = GNOME_CANVAS_ITEM (o); - ibitem = E_ICON_BAR_BG_ITEM (o); - - switch (arg_id){ - case ARG_ICON_BAR: - ibitem->icon_bar = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_icon_bar_bg_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The grid covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_icon_bar_bg_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EIconBar *icon_bar; - EIconBarItem *item; - EIconBarBgItem *ibitem; - GtkStyle *style; - GdkGC *gc; - GtkShadowType shadow; - gint item_num, border, bar_x, bar_y, bar_w, i, arrow_height; - - ibitem = E_ICON_BAR_BG_ITEM (canvas_item); - icon_bar = ibitem->icon_bar; - g_return_if_fail (icon_bar != NULL); - style = GTK_WIDGET (icon_bar)->style; - - /* Draw the highlight around the current highlight item. */ - item_num = -1; - if (icon_bar->editing_item_num == -1) { - if (icon_bar->pressed_item_num != -1) { - item_num = icon_bar->pressed_item_num; - if (icon_bar->pressed_item_num == icon_bar->mouse_over_item_num) - shadow = GTK_SHADOW_IN; - else - shadow = GTK_SHADOW_OUT; - } else if (icon_bar->mouse_over_item_num != -1) { - item_num = icon_bar->mouse_over_item_num; - shadow = GTK_SHADOW_OUT; - } - } - - if (item_num != -1) { - item = &g_array_index (icon_bar->items, EIconBarItem, - item_num); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) - border = E_ICON_BAR_LARGE_ICON_SHADOW_BORDER; - else - border = E_ICON_BAR_SMALL_ICON_SHADOW_BORDER; - - gtk_draw_shadow (style, drawable, GTK_STATE_NORMAL, shadow, - icon_bar->icon_x - border - x, - item->icon_y - border - y, - icon_bar->icon_w + border * 2 - 1, - icon_bar->icon_h + border * 2 - 1); - } - - /* Draw the bar between items when dragging, if needed. */ - if (icon_bar->in_drag && icon_bar->dragging_before_item_num != -1) { - if (icon_bar->dragging_before_item_num < icon_bar->items->len) { - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->dragging_before_item_num); - bar_y = 0; - } else { - /* We need to draw the bar after the last item. */ - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->items->len - 1); - bar_y = item->item_height + icon_bar->spacing; - } - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - bar_y += item->icon_y; - } else { - bar_y += MIN (item->icon_y, item->text_y); - } - bar_y -= y + icon_bar->spacing / 2; - - bar_x = E_ICON_BAR_BG_ITEM_BAR_OFFSET - x; - bar_w = GTK_WIDGET (icon_bar)->allocation.width - 2 * E_ICON_BAR_BG_ITEM_BAR_OFFSET - 1; - - gc = GTK_WIDGET (icon_bar)->style->fg_gc[GTK_STATE_NORMAL]; - - /* Draw the horizontal bar. */ - gdk_draw_rectangle (drawable, gc, TRUE, - bar_x, bar_y, - bar_w, E_ICON_BAR_BG_ITEM_BAR_HEIGHT); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) - arrow_height = E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT / 2; - else - arrow_height = E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT / 2; - - /* Draw the arrows at the end of the lines. We use - gdk_draw_line() to draw a series of vertical lines, since - gdk_draw_polygon() produces odd results. */ - i = 0; - while (arrow_height > 0) { - gdk_draw_line (drawable, gc, - bar_x + i, - bar_y - arrow_height, - bar_x + i, - bar_y + arrow_height); - gdk_draw_line (drawable, gc, - bar_x + bar_w - i - 1, - bar_y - arrow_height, - bar_x + bar_w - i - 1, - bar_y + arrow_height); - arrow_height--; - i++; - } - } -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_icon_bar_bg_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_icon_bar_bg_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EIconBarBgItem *ibitem; - - ibitem = E_ICON_BAR_BG_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_icon_bar_bg_item_button_press (ibitem, event); - case GDK_BUTTON_RELEASE: - return e_icon_bar_bg_item_button_release (ibitem, event); - case GDK_MOTION_NOTIFY: - return e_icon_bar_bg_item_motion_notify (ibitem, event); - default: - break; - } - - return FALSE; -} - - -static gint -e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_pressed (ibitem->icon_bar, item_num, event); - return TRUE; -} - - -static gint -e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_released (ibitem->icon_bar, item_num, event); - return TRUE; -} - - -static gint -e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->motion.x, - event->motion.y, - NULL); - e_icon_bar_item_motion (ibitem->icon_bar, item_num, event); - return TRUE; -} diff --git a/widgets/shortcut-bar/e-icon-bar-bg-item.h b/widgets/shortcut-bar/e-icon-bar-bg-item.h deleted file mode 100644 index ae25e987d7..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-bg-item.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar. - * It paints the rectangles around items when the mouse moves over them, and - * the lines between items when dragging. - */ - -#ifndef _E_ICON_BAR_BG_ITEM_H_ -#define _E_ICON_BAR_BG_ITEM_H_ - -#include - -#include "e-icon-bar.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_ICON_BAR_BG_ITEM(obj) (GTK_CHECK_CAST((obj), e_icon_bar_bg_item_get_type (), EIconBarBgItem)) -#define E_ICON_BAR_BG_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_icon_bar_bg_item_get_type (), EIconBarBgItemClass)) -#define E_IS_ICON_BAR_BG_ITEM(o) (GTK_CHECK_TYPE((o), e_icon_bar_bg_item_get_type ())) - - -typedef struct _EIconBarBgItem EIconBarBgItem; -typedef struct _EIconBarBgItemClass EIconBarBgItemClass; - -struct _EIconBarBgItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EIconBar widget. */ - EIconBar *icon_bar; -}; - - -struct _EIconBarBgItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_icon_bar_bg_item_get_type (void); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ICON_BAR_BG_ITEM_H_ */ diff --git a/widgets/shortcut-bar/e-icon-bar-text-item.c b/widgets/shortcut-bar/e-icon-bar-text-item.c deleted file mode 100644 index 5548c630b3..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-text-item.c +++ /dev/null @@ -1,1696 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * Based on gnome-icon-text-item: an editable text block with word wrapping - * for the GNOME canvas. - * - * Copyright (C) 1998, 1999 The Free Software Foundation - * - * Authors: Miguel de Icaza - * Federico Mena - */ - -/* - * EIconBarTextItem - An editable canvas text item for the EIconBar. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "e-icon-bar-text-item.h" - - -/* Margins used to display the information */ -#define MARGIN_X 2 -#define MARGIN_Y 2 - -/* Default fontset to be used if the user specified fontset is not found */ -#define DEFAULT_FONT_NAME "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*," \ - "-*-*-medium-r-normal--10-*-*-*-*-*-*-*,*" - -/* Separators for text layout */ -#define DEFAULT_SEPARATORS " \t-.[]#" - -/* This is the string to draw when the text is clipped, e.g. '...'. */ -static gchar *e_icon_bar_text_item_ellipsis; - -/* Aliases to minimize screen use in my laptop */ -#define ITI(x) E_ICON_BAR_TEXT_ITEM (x) -#define ITI_CLASS(x) E_ICON_BAR_TEXT_ITEM_CLASS (x) -#define IS_ITI(x) E_IS_ICON_BAR_TEXT_ITEM (x) - - -typedef EIconBarTextItem Iti; - -/* Private part of the EIconBarTextItem structure */ -typedef struct { - /* Font */ - GdkFont *font; - - /* Hack: create an offscreen window and place an entry inside it */ - GtkEntry *entry; - GtkWidget *entry_top; - - /* Whether the user pressed the mouse while the item was unselected */ - guint unselected_click : 1; - - /* Whether we need to update the position */ - guint need_pos_update : 1; - - /* Whether we need to update the font */ - guint need_font_update : 1; - - /* Whether we need to update the text */ - guint need_text_update : 1; - - /* Whether we need to update because the editing/selected state changed */ - guint need_state_update : 1; -} ItiPrivate; - -typedef struct _EIconBarTextItemInfoRow EIconBarTextItemInfoRow; - -struct _EIconBarTextItemInfoRow { - gchar *text; - gint width; - GdkWChar *text_wc; /* text in wide characters */ - gint text_length; /* number of characters */ -}; - -struct _EIconBarTextItemInfo { - GList *rows; - GdkFont *font; - gint width; - gint height; - gint baseline_skip; -}; - -static GnomeCanvasItemClass *parent_class; - -enum { - ARG_0, - ARG_XALIGN, - ARG_JUSTIFY, - ARG_MAX_LINES, - ARG_SHOW_ELLIPSIS -}; - -enum { - TEXT_CHANGED, - HEIGHT_CHANGED, - WIDTH_CHANGED, - EDITING_STARTED, - EDITING_STOPPED, - SELECTION_STARTED, - SELECTION_STOPPED, - LAST_SIGNAL -}; - -static guint iti_signals [LAST_SIGNAL] = { 0 }; - -static GdkFont *default_font; - -static void e_icon_bar_text_item_free_info (EIconBarTextItemInfo *ti); -static EIconBarTextItemInfo *e_icon_bar_text_item_layout_text (EIconBarTextItem *iti, GdkFont *font, const gchar *text, const gchar *separators, gint max_width, gboolean confine); -static void e_icon_bar_text_item_paint_text (EIconBarTextItem *iti, - EIconBarTextItemInfo *ti, - GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - GtkJustification just); - - -/* Stops the editing state of an icon text item */ -static void -iti_stop_editing (Iti *iti) -{ - ItiPrivate *priv; - - priv = iti->priv; - - iti->editing = FALSE; - - gtk_widget_destroy (priv->entry_top); - priv->entry = NULL; - priv->entry_top = NULL; - - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); - - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[EDITING_STOPPED]); -} - -/* Lays out the text in an icon item */ -static void -layout_text (Iti *iti) -{ - ItiPrivate *priv; - char *text; - int old_width, old_height; - int width, height; - - priv = iti->priv; - - /* Save old size */ - - if (iti->ti) { - old_width = iti->ti->width + 2 * MARGIN_X; - old_height = iti->ti->height + 2 * MARGIN_Y; - - e_icon_bar_text_item_free_info (iti->ti); - } else { - old_width = 2 * MARGIN_X; - old_height = 2 * MARGIN_Y; - } - - /* Change the text layout */ - - if (iti->editing) - text = gtk_entry_get_text (priv->entry); - else - text = iti->text; - - iti->ti = e_icon_bar_text_item_layout_text (iti, priv->font, - text, - DEFAULT_SEPARATORS, - iti->width - 2 * MARGIN_X, - TRUE); - - /* Check the sizes and see if we need to emit any signals */ - - width = iti->ti->width + 2 * MARGIN_X; - height = iti->ti->height + 2 * MARGIN_Y; - - if (width != old_width) - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[WIDTH_CHANGED]); - - if (height != old_height) - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[HEIGHT_CHANGED]); -} - -/* Accepts the text in the off-screen entry of an icon text item */ -static void -iti_edition_accept (Iti *iti) -{ - ItiPrivate *priv; - gboolean accept; - - priv = iti->priv; - accept = TRUE; - - gtk_signal_emit (GTK_OBJECT (iti), iti_signals [TEXT_CHANGED], &accept); - - if (iti->editing){ - if (accept) { - if (iti->is_text_allocated) - g_free (iti->text); - - iti->text = g_strdup (gtk_entry_get_text (priv->entry)); - iti->is_text_allocated = 1; - } - - iti_stop_editing (iti); - } - - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/* Callback used when the off-screen entry of an icon text item is activated. - * When this happens, we have to accept edition. - */ -static void -iti_entry_activate (GtkWidget *entry, Iti *iti) -{ - iti_edition_accept (iti); -} - -/* Starts the editing state of an icon text item */ -static void -iti_start_editing (Iti *iti) -{ - ItiPrivate *priv; - - priv = iti->priv; - - if (iti->editing) - return; - - /* Trick: The actual edition of the entry takes place in a GtkEntry - * which is placed offscreen. That way we get all of the advantages - * from GtkEntry without duplicating code. Yes, this is a hack. - */ - priv->entry = (GtkEntry *) gtk_entry_new (); - gtk_entry_set_text (priv->entry, iti->text); - gtk_signal_connect (GTK_OBJECT (priv->entry), "activate", - GTK_SIGNAL_FUNC (iti_entry_activate), iti); - - priv->entry_top = gtk_window_new (GTK_WINDOW_POPUP); - gtk_container_add (GTK_CONTAINER (priv->entry_top), GTK_WIDGET (priv->entry)); - gtk_widget_set_uposition (priv->entry_top, 20000, 20000); - gtk_widget_show_all (priv->entry_top); - - gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1); - - iti->editing = TRUE; - - priv->need_text_update = TRUE; - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); - - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[EDITING_STARTED]); -} - -/* Destroy method handler for the icon text item */ -static void -iti_destroy (GtkObject *object) -{ - Iti *iti; - ItiPrivate *priv; - GnomeCanvasItem *item; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_ITI (object)); - - iti = ITI (object); - priv = iti->priv; - item = GNOME_CANVAS_ITEM (object); - - /* FIXME: stop selection and editing */ - - /* Queue redraw of bounding box */ - - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - - /* Free everything */ - - if (iti->fontname) - g_free (iti->fontname); - - if (iti->text && iti->is_text_allocated) - g_free (iti->text); - - if (iti->ti) - e_icon_bar_text_item_free_info (iti->ti); - - if (priv->font) - gdk_font_unref (priv->font); - - if (priv->entry_top) - gtk_widget_destroy (priv->entry_top); - - g_free (priv); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -/* set_arg handler for the icon text item */ -static void -iti_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - Iti *iti; - GnomeCanvasItem *item; - ItiPrivate *priv; - gfloat xalign; - gint max_lines; - gboolean show_ellipsis; - GtkJustification justification; - - iti = ITI (object); - item = GNOME_CANVAS_ITEM (object); - priv = iti->priv; - - switch (arg_id) { - case ARG_XALIGN: - xalign = GTK_VALUE_FLOAT (*arg); - if (iti->xalign != xalign) { - iti->xalign = xalign; - priv->need_pos_update = TRUE; - gnome_canvas_item_request_update (item); - } - break; - case ARG_JUSTIFY: - justification = GTK_VALUE_ENUM (*arg); - if (iti->justification != justification) { - iti->justification = justification; - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (item); - } - break; - case ARG_MAX_LINES: - max_lines = GTK_VALUE_INT (*arg); - if (iti->max_lines != max_lines) { - iti->max_lines = max_lines; - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (item); - } - break; - case ARG_SHOW_ELLIPSIS: - show_ellipsis = GTK_VALUE_BOOL (*arg); - if (iti->show_ellipsis != show_ellipsis) { - iti->show_ellipsis = show_ellipsis; - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (item); - } - break; - default: - break; - } -} - -static void -iti_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - Iti *iti; - ItiPrivate *priv; - - iti = ITI (object); - priv = iti->priv; - - switch (arg_id) { - case ARG_XALIGN: - GTK_VALUE_FLOAT (*arg) = iti->xalign; - break; - case ARG_JUSTIFY: - GTK_VALUE_ENUM (*arg) = iti->justification; - break; - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = iti->max_lines; - break; - case ARG_SHOW_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = iti->show_ellipsis; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Loads the default font for icon text items if necessary */ -static GdkFont * -get_default_font (void) -{ - if (!default_font) { - /* FIXME: this is never unref-ed */ - default_font = gdk_fontset_load (DEFAULT_FONT_NAME); - g_assert (default_font != NULL); - } - - return gdk_font_ref (default_font); -} - -/* Recomputes the bounding box of an icon text item */ -static void -recompute_bounding_box (Iti *iti) -{ - GnomeCanvasItem *item; - double affine[6]; - ArtPoint p, q; - int x1, y1, x2, y2; - int width, height; - - item = GNOME_CANVAS_ITEM (iti); - - /* Compute width, height, position */ - - width = iti->ti->width + 2 * MARGIN_X; - height = iti->ti->height + 2 * MARGIN_Y; - - x1 = iti->x + (iti->width - width) * iti->xalign; - y1 = iti->y; - x2 = x1 + width; - y2 = y1 + height; - - /* Translate to world coordinates */ - - gnome_canvas_item_i2w_affine (item, affine); - - p.x = x1; - p.y = y1; - art_affine_point (&q, &p, affine); - item->x1 = q.x; - item->y1 = q.y; - - p.x = x2; - p.y = y2; - art_affine_point (&q, &p, affine); - item->x2 = q.x; - item->y2 = q.y; -} - -/* Update method for the icon text item */ -static void -iti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - Iti *iti; - ItiPrivate *priv; - - iti = ITI (item); - priv = iti->priv; - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - /* If necessary, queue a redraw of the old bounding box */ - - if ((flags & GNOME_CANVAS_UPDATE_VISIBILITY) - || (flags & GNOME_CANVAS_UPDATE_AFFINE) - || priv->need_pos_update - || priv->need_font_update - || priv->need_text_update) - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - - if (priv->need_text_update) - layout_text (iti); - - /* Compute new bounds */ - - if (priv->need_pos_update - || priv->need_font_update - || priv->need_text_update) - recompute_bounding_box (iti); - - /* Queue redraw */ - - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - - priv->need_pos_update = FALSE; - priv->need_font_update = FALSE; - priv->need_text_update = FALSE; - priv->need_state_update = FALSE; -} - -/* Draw the icon text item's text when it is being edited */ -static void -iti_paint_text (Iti *iti, GdkDrawable *drawable, int x, int y) -{ - ItiPrivate *priv; - EIconBarTextItemInfoRow *row; - EIconBarTextItemInfo *ti; - GtkStyle *style; - GdkGC *fg_gc, *bg_gc; - GdkGC *gc, *bgc, *sgc, *bsgc; - GList *item; - int xpos, len; - - priv = iti->priv; - style = GTK_WIDGET (GNOME_CANVAS_ITEM (iti)->canvas)->style; - - ti = iti->ti; - len = 0; - y += ti->font->ascent; - - /* - * Pointers to all of the GCs we use - */ - gc = style->black_gc; - bgc = style->white_gc; - sgc = style->fg_gc [GTK_STATE_SELECTED]; - bsgc = style->bg_gc [GTK_STATE_SELECTED]; - - for (item = ti->rows; item; item = item->next, len += (row ? row->text_length : 0)) { - GdkWChar *text_wc; - int text_length; - int cursor, offset, i; - int sel_start, sel_end; - - row = item->data; - - if (!row) { - y += ti->baseline_skip; - continue; - } - - text_wc = row->text_wc; - text_length = row->text_length; - - switch (iti->justification) { - case GTK_JUSTIFY_LEFT: - xpos = 0; - break; - - case GTK_JUSTIFY_RIGHT: - xpos = ti->width - row->width; - break; - - case GTK_JUSTIFY_CENTER: - xpos = (ti->width - row->width) / 2; - break; - - default: - /* Anyone care to implement GTK_JUSTIFY_FILL? */ - g_warning ("Justification type %d not supported. Using left-justification.", - (int) iti->justification); - xpos = 0; - } - - sel_start = GTK_EDITABLE (priv->entry)->selection_start_pos - len; - sel_end = GTK_EDITABLE (priv->entry)->selection_end_pos - len; - offset = 0; - cursor = GTK_EDITABLE (priv->entry)->current_pos - len; - - for (i = 0; *text_wc; text_wc++, i++) { - int size, px; - - size = gdk_text_width_wc (ti->font, text_wc, 1); - - if (i >= sel_start && i < sel_end) { - fg_gc = sgc; - bg_gc = bsgc; - } else { - fg_gc = gc; - bg_gc = bgc; - } - - px = x + xpos + offset; - gdk_draw_rectangle (drawable, - bg_gc, - TRUE, - px, - y - ti->font->ascent, - size, ti->baseline_skip); - - gdk_draw_text_wc (drawable, - ti->font, - fg_gc, - px, y, - text_wc, 1); - - if (cursor == i) - gdk_draw_line (drawable, - gc, - px - 1, - y - ti->font->ascent, - px - 1, - y + ti->font->descent - 1); - - offset += size; - } - - if (cursor == i) { - int px = x + xpos + offset; - - gdk_draw_line (drawable, - gc, - px - 1, - y - ti->font->ascent, - px - 1, - y + ti->font->descent - 1); - } - - y += ti->baseline_skip; - } -} - -/* Draw method handler for the icon text item */ -static void -iti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - Iti *iti; - GtkStyle *style; - int w, h; - int xofs, yofs; - - iti = ITI (item); - - if (iti->ti) { - w = iti->ti->width + 2 * MARGIN_X; - h = iti->ti->height + 2 * MARGIN_Y; - } else { - w = 2 * MARGIN_X; - h = 2 * MARGIN_Y; - } - - xofs = item->x1 - x; - yofs = item->y1 - y; - - style = GTK_WIDGET (item->canvas)->style; - - if (iti->selected && !iti->editing) - gdk_draw_rectangle (drawable, - style->bg_gc[GTK_STATE_SELECTED], - TRUE, - xofs, yofs, - w, h); - - if (iti->editing) { - gdk_draw_rectangle (drawable, - style->white_gc, - TRUE, - xofs + 1, yofs + 1, - w - 2, h - 2); - gdk_draw_rectangle (drawable, - style->black_gc, - FALSE, - xofs, yofs, - w - 1, h - 1); - - iti_paint_text (iti, drawable, xofs + MARGIN_X, yofs + MARGIN_Y); - } else - e_icon_bar_text_item_paint_text (iti, iti->ti, - drawable, - style->fg_gc[(iti->selected - ? GTK_STATE_SELECTED - : GTK_STATE_NORMAL)], - xofs + MARGIN_X, - yofs + MARGIN_Y, - iti->justification); -} - -/* Point method handler for the icon text item */ -static double -iti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item) -{ - double dx, dy; - - *actual_item = item; - - if (cx < item->x1) - dx = item->x1 - cx; - else if (cx > item->x2) - dx = cx - item->x2; - else - dx = 0.0; - - if (cy < item->y1) - dy = item->y1 - cy; - else if (cy > item->y2) - dy = cy - item->y2; - else - dy = 0.0; - - return sqrt (dx * dx + dy * dy); -} - -/* Given X, Y, a mouse position, return a valid index inside the edited text */ -static int -iti_idx_from_x_y (Iti *iti, int x, int y) -{ - ItiPrivate *priv; - EIconBarTextItemInfoRow *row; - int lines; - int line, col, i, idx; - GList *l; - - priv = iti->priv; - - if (iti->ti->rows == NULL) - return 0; - - lines = g_list_length (iti->ti->rows); - line = y / iti->ti->baseline_skip; - - if (line < 0) - line = 0; - else if (lines < line + 1) - line = lines - 1; - - /* Compute the base index for this line */ - for (l = iti->ti->rows, idx = i = 0; i < line; l = l->next, i++) { - row = l->data; - idx += row->text_length; - } - - row = g_list_nth (iti->ti->rows, line)->data; - col = 0; - if (row != NULL) { - int first_char; - int last_char; - - first_char = (iti->ti->width - row->width) / 2; - last_char = first_char + row->width; - - if (x < first_char) { - /* nothing */ - } else if (x > last_char) { - col = row->text_length; - } else { - GdkWChar *s = row->text_wc; - int pos = first_char; - - while (pos < last_char) { - pos += gdk_text_width_wc (iti->ti->font, s, 1); - if (pos > x) - break; - col++; - s++; - } - } - } - - idx += col; - - g_assert (idx <= priv->entry->text_size); - - return idx; -} - -/* Starts the selection state in the icon text item */ -static void -iti_start_selecting (Iti *iti, int idx, guint32 event_time) -{ - ItiPrivate *priv; - GtkEditable *e; - GdkCursor *ibeam; - - priv = iti->priv; - e = GTK_EDITABLE (priv->entry); - - gtk_editable_select_region (e, idx, idx); - gtk_editable_set_position (e, idx); - ibeam = gdk_cursor_new (GDK_XTERM); - gnome_canvas_item_grab (GNOME_CANVAS_ITEM (iti), - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK, - ibeam, event_time); - gdk_cursor_destroy (ibeam); - - gtk_editable_select_region (e, idx, idx); - e->current_pos = e->selection_start_pos; - e->has_selection = TRUE; - iti->selecting = TRUE; - - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); - - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[SELECTION_STARTED]); -} - -/* Stops the selection state in the icon text item */ -static void -iti_stop_selecting (Iti *iti, guint32 event_time) -{ - ItiPrivate *priv; - GnomeCanvasItem *item; - GtkEditable *e; - - priv = iti->priv; - item = GNOME_CANVAS_ITEM (iti); - e = GTK_EDITABLE (priv->entry); - - gnome_canvas_item_ungrab (item, event_time); - e->has_selection = FALSE; - iti->selecting = FALSE; - - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); - gtk_signal_emit (GTK_OBJECT (iti), iti_signals[SELECTION_STOPPED]); -} - -/* Handles selection range changes on the icon text item */ -static void -iti_selection_motion (Iti *iti, int idx) -{ - ItiPrivate *priv; - GtkEditable *e; - - priv = iti->priv; - e = GTK_EDITABLE (priv->entry); - - if (idx < e->current_pos) { - e->selection_start_pos = idx; - e->selection_end_pos = e->current_pos; - } else { - e->selection_start_pos = e->current_pos; - e->selection_end_pos = idx; - } - - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/* Event handler for icon text items */ -static gint -iti_event (GnomeCanvasItem *item, GdkEvent *event) -{ - Iti *iti; - ItiPrivate *priv; - int idx; - double x, y; - - iti = ITI (item); - priv = iti->priv; - - switch (event->type) { - case GDK_KEY_PRESS: - if (!iti->editing) - break; - - if (event->key.keyval == GDK_Escape) - iti_stop_editing (iti); - else - gtk_widget_event (GTK_WIDGET (priv->entry), event); - - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (item); - return TRUE; - - case GDK_BUTTON_PRESS: - if (!iti->editing) - break; - - if (iti->editing && event->button.button == 1) { - x = event->button.x - (item->x1 + MARGIN_X); - y = event->button.y - (item->y1 + MARGIN_Y); - idx = iti_idx_from_x_y (iti, x, y); - - iti_start_selecting (iti, idx, event->button.time); - } - - return TRUE; - - case GDK_MOTION_NOTIFY: - if (!iti->selecting) - break; - - x = event->motion.x - (item->x1 + MARGIN_X); - y = event->motion.y - (item->y1 + MARGIN_Y); - idx = iti_idx_from_x_y (iti, x, y); - iti_selection_motion (iti, idx); - return TRUE; - - case GDK_BUTTON_RELEASE: - if (iti->selecting && event->button.button == 1) - iti_stop_selecting (iti, event->button.time); - else - break; - - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Bounds method handler for the icon text item */ -static void -iti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - Iti *iti; - ItiPrivate *priv; - int width, height; - - iti = ITI (item); - priv = iti->priv; - - if (priv->need_text_update) { - layout_text (iti); - priv->need_text_update = FALSE; - } - - if (iti->ti) { - width = iti->ti->width + 2 * MARGIN_X; - height = iti->ti->height + 2 * MARGIN_Y; - } else { - width = 2 * MARGIN_X; - height = 2 * MARGIN_Y; - } - - *x1 = iti->x + (iti->width - width) * iti->xalign; - *y1 = iti->y; - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -/* Class initialization function for the icon text item */ -static void -iti_class_init (EIconBarTextItemClass *text_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) text_item_class; - item_class = (GnomeCanvasItemClass *) text_item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - gtk_object_add_arg_type ("EIconBarTextItem::xalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_XALIGN); - gtk_object_add_arg_type ("EIconBarTextItem::justify", GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFY); - gtk_object_add_arg_type ("EIconBarTextItem::max_lines", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - gtk_object_add_arg_type ("EIconBarTextItem::show_ellipsis", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SHOW_ELLIPSIS); - - iti_signals [TEXT_CHANGED] = - gtk_signal_new ( - "text_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, text_changed), - gtk_marshal_BOOL__NONE, - GTK_TYPE_BOOL, 0); - - iti_signals [HEIGHT_CHANGED] = - gtk_signal_new ( - "height_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, height_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - iti_signals [WIDTH_CHANGED] = - gtk_signal_new ( - "width_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, width_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - iti_signals[EDITING_STARTED] = - gtk_signal_new ( - "editing_started", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, editing_started), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - iti_signals[EDITING_STOPPED] = - gtk_signal_new ( - "editing_stopped", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, editing_stopped), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - iti_signals[SELECTION_STARTED] = - gtk_signal_new ( - "selection_started", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, selection_started), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - iti_signals[SELECTION_STOPPED] = - gtk_signal_new ( - "selection_stopped", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarTextItemClass, selection_stopped), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, iti_signals, LAST_SIGNAL); - - object_class->destroy = iti_destroy; - object_class->get_arg = iti_get_arg; - object_class->set_arg = iti_set_arg; - - item_class->update = iti_update; - item_class->draw = iti_draw; - item_class->point = iti_point; - item_class->bounds = iti_bounds; - item_class->event = iti_event; - - e_icon_bar_text_item_ellipsis = _("..."); -} - -/* Object initialization function for the icon text item */ -static void -iti_init (EIconBarTextItem *iti) -{ - ItiPrivate *priv; - - priv = g_new0 (ItiPrivate, 1); - iti->priv = priv; - - iti->xalign = 0.5; - iti->justification = GTK_JUSTIFY_CENTER; - iti->max_lines = -1; - iti->show_ellipsis = TRUE; -} - -/** - * e_icon_bar_text_item_configure: - * @iti: An #EIconBarTextItem. - * @x: X position in which to place the item. - * @y: Y position in which to place the item. - * @width: Maximum width allowed for this item, to be used for word wrapping. - * @fontname: Name of the fontset that should be used to display the text. - * @text: Text that is going to be displayed. - * @is_static: Whether @text points to a static string or not. - * - * This routine is used to configure an #EIconBarTextItem. - * - * @x and @y specify the coordinates where the item is placed in the canvas. - * The @x coordinate should be the leftmost position that the item can - * assume at any one time, that is, the left margin of the column in which the - * icon is to be placed. The @y coordinate specifies the top of the item. - * - * @width is the maximum width allowed for this icon text item. The coordinates - * define the upper-left corner of an item with maximum width; this may - * actually be outside the bounding box of the item if the text is narrower - * than the maximum width. - * - * If @is_static is true, it means that there is no need for the item to - * allocate memory for the string (it is a guarantee that the text is allocated - * by the caller and it will not be deallocated during the lifetime of this - * item). This is an optimization to reduce memory usage for large icon sets. - */ -void -e_icon_bar_text_item_configure (EIconBarTextItem *iti, int x, int y, - int width, const char *fontname, - const char *text, - gboolean is_static) -{ - ItiPrivate *priv; - - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - g_return_if_fail (width > 2 * MARGIN_X); - g_return_if_fail (text != NULL); - - priv = iti->priv; - - iti->x = x; - iti->y = y; - iti->width = width; - - if (iti->text && iti->is_text_allocated) - g_free (iti->text); - - iti->is_text_allocated = !is_static; - - /* This cast is to shut up the compiler */ - if (is_static) - iti->text = (char *) text; - else - iti->text = g_strdup (text); - - if (iti->fontname) - g_free (iti->fontname); - - iti->fontname = g_strdup (fontname ? fontname : DEFAULT_FONT_NAME); - - if (priv->font) - gdk_font_unref (priv->font); - - priv->font = NULL; - if (fontname) - priv->font = gdk_fontset_load (iti->fontname); - if (!priv->font) - priv->font = get_default_font (); - - /* Request update */ - - priv->need_pos_update = TRUE; - priv->need_font_update = TRUE; - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/** - * e_icon_bar_text_item_set_width: - * @iti: An #EIconBarTextItem. - * @width: Maximum width allowed for this item, to be used for word wrapping. - * - * This routine is used to set the maximum width of an #EIconBarTextItem. - */ -void -e_icon_bar_text_item_set_width (EIconBarTextItem *iti, int width) -{ - ItiPrivate *priv; - - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - g_return_if_fail (width > 2 * MARGIN_X); - - priv = iti->priv; - - if (iti->width == width) - return; - - iti->width = width; - - /* Request update */ - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/** - * e_icon_bar_text_item_setxy: - * @iti: An #EIconBarTextItem. - * @x: X position. - * @y: Y position. - * - * Sets the coordinates at which the #EIconBarTextItem should be placed. - * - * See also: e_icon_bar_text_item_configure(). - */ -void -e_icon_bar_text_item_setxy (EIconBarTextItem *iti, int x, int y) -{ - ItiPrivate *priv; - - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - - priv = iti->priv; - - iti->x = x; - iti->y = y; - - priv->need_pos_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/** - * e_icon_bar_text_item_select: - * @iti: An #EIconBarTextItem. - * @sel: Whether the item should be displayed as selected. - * - * This function is used to control whether an icon text item is displayed as - * selected or not. Mouse events are ignored by the item when it is unselected; - * when the user clicks on a selected icon text item, it will start the text - * editing process. - */ -void -e_icon_bar_text_item_select (EIconBarTextItem *iti, int sel) -{ - ItiPrivate *priv; - - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - - priv = iti->priv; - - if (!iti->selected == !sel) - return; - - iti->selected = sel ? TRUE : FALSE; - - if (!iti->selected && iti->editing) - iti_edition_accept (iti); - - priv->need_state_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - -/** - * e_icon_bar_text_item_get_text: - * @iti: An #EIconBarTextItem. - * - * Returns the current text. The client should not free this string, as it is - * internal to the #EIconBarTextItem. - */ -char * -e_icon_bar_text_item_get_text (EIconBarTextItem *iti) -{ - ItiPrivate *priv; - - g_return_val_if_fail (iti != NULL, NULL); - g_return_val_if_fail (IS_ITI (iti), NULL); - - priv = iti->priv; - - if (iti->editing) - return gtk_entry_get_text (priv->entry); - else - return iti->text; -} - - -/** - * e_icon_bar_text_item_set_text: - * @iti: An #EIconBarTextItem. - * @text: Text that is going to be displayed. - * @is_static: Whether @text points to a static string or not. - * - * If @is_static is true, it means that there is no need for the item to - * allocate memory for the string (it is a guarantee that the text is allocated - * by the caller and it will not be deallocated during the lifetime of this - * item). This is an optimization to reduce memory usage for large icon sets. - */ -void -e_icon_bar_text_item_set_text (EIconBarTextItem *iti, const char *text, - gboolean is_static) -{ - ItiPrivate *priv; - - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - g_return_if_fail (text != NULL); - - priv = iti->priv; - - if (iti->text && iti->is_text_allocated) - g_free (iti->text); - - iti->is_text_allocated = !is_static; - - /* This cast is to shut up the compiler */ - if (is_static) - iti->text = (char *) text; - else - iti->text = g_strdup (text); - - /* Request update */ - - priv->need_text_update = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti)); -} - - -/** - * e_icon_bar_text_item_start_editing: - * @iti: An #EIconBarTextItem. - * - * Starts the editing state of an #EIconBarTextItem. - **/ -void -e_icon_bar_text_item_start_editing (EIconBarTextItem *iti) -{ - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - - if (iti->editing) - return; - - iti->selected = TRUE; /* Ensure that we are selected */ - gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (iti)); - iti_start_editing (iti); -} - -/** - * e_icon_bar_text_item_stop_editing: - * @iti: An #EIconBarTextItem. - * @accept: Whether to accept the current text or to discard it. - * - * Terminates the editing state of an icon text item. The @accept argument - * controls whether the item's current text should be accepted or discarded. - * If it is discarded, then the icon's original text will be restored. - **/ -void -e_icon_bar_text_item_stop_editing (EIconBarTextItem *iti, - gboolean accept) -{ - g_return_if_fail (iti != NULL); - g_return_if_fail (IS_ITI (iti)); - - if (!iti->editing) - return; - - if (accept) - iti_edition_accept (iti); - else - iti_stop_editing (iti); -} - - -/** - * e_icon_bar_text_item_get_type: - * - * Registers the &EIconBarTextItem class if necessary, and returns the type ID - * associated to it. - * - * Return value: the type ID of the #EIconBarTextItem class. - **/ -GtkType -e_icon_bar_text_item_get_type (void) -{ - static GtkType iti_type = 0; - - if (!iti_type) { - static const GtkTypeInfo iti_info = { - "EIconBarTextItem", - sizeof (EIconBarTextItem), - sizeof (EIconBarTextItemClass), - (GtkClassInitFunc) iti_class_init, - (GtkObjectInitFunc) iti_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - iti_type = gtk_type_unique (gnome_canvas_item_get_type (), &iti_info); - } - - return iti_type; -} - - -static void -free_row (gpointer data, gpointer user_data) -{ - EIconBarTextItemInfoRow *row; - - if (data) { - row = data; - g_free (row->text); - g_free (row->text_wc); - g_free (row); - } -} - -/* - * e_icon_bar_text_item_free_info: - * @ti: An icon text info structure. - * - * Frees a &EIconBarTextItemInfo structure. You should call this instead of - * freeing the structure yourself. - */ -static void -e_icon_bar_text_item_free_info (EIconBarTextItemInfo *ti) -{ - g_list_foreach (ti->rows, free_row, NULL); - g_list_free (ti->rows); - g_free (ti); -} - -/* - * e_icon_bar_text_item_layout_text: - * @font: Name of the font that will be used to render the text. - * @text: Text to be formatted. - * @separators: Separators used for word wrapping, can be NULL. - * @max_width: Width in pixels to be used for word wrapping. - * @confine: Whether it is mandatory to wrap at @max_width. - * - * Creates a new &EIconBarTextItemInfo structure by wrapping the specified - * text. If non-NULL, the @separators argument defines a set of characters - * to be used as word delimiters for performing word wrapping. If it is - * NULL, then only spaces will be used as word delimiters. - * - * The @max_width argument is used to specify the width at which word - * wrapping will be performed. If there is a very long word that does not - * fit in a single line, the @confine argument can be used to specify - * whether the word should be unconditionally split to fit or whether - * the maximum width should be increased as necessary. - * - * Return value: A newly-created &EIconBarTextItemInfo structure. - */ -static EIconBarTextItemInfo * -e_icon_bar_text_item_layout_text (EIconBarTextItem *iti, GdkFont *font, - const gchar *text, const gchar *separators, - gint max_width, gboolean confine) -{ - EIconBarTextItemInfo *ti; - EIconBarTextItemInfoRow *row; - GdkWChar *row_end; - GdkWChar *s, *word_start, *word_end, *old_word_end; - GdkWChar *sub_text; - int i, w_len, w; - GdkWChar *text_wc, *text_iter, *separators_wc; - int text_len_wc, separators_len_wc; - gboolean restrict_lines; - int lines; - - g_return_val_if_fail (font != NULL, NULL); - g_return_val_if_fail (text != NULL, NULL); - - if (!separators) - separators = " "; - - text_wc = g_new (GdkWChar, strlen (text) + 1); - text_len_wc = gdk_mbstowcs (text_wc, text, strlen (text)); - if (text_len_wc < 0) text_len_wc = 0; - text_wc[text_len_wc] = 0; - - separators_wc = g_new (GdkWChar, strlen (separators) + 1); - separators_len_wc = gdk_mbstowcs (separators_wc, separators, strlen (separators)); - if (separators_len_wc < 0) separators_len_wc = 0; - separators_wc[separators_len_wc] = 0; - - ti = g_new (EIconBarTextItemInfo, 1); - - ti->rows = NULL; - ti->font = font; - ti->width = 0; - ti->height = 0; - ti->baseline_skip = font->ascent + font->descent; - - word_end = NULL; - - if (!iti->editing && iti->max_lines != -1) - restrict_lines = TRUE; - else - restrict_lines = FALSE; - - text_iter = text_wc; - lines = 0; - while (*text_iter) { - /* If we are restricting the height, and this is the last line, - and we are displaying the ellipsis, then subtract the width - of the ellipsis from our max_width. */ - if (restrict_lines && lines == iti->max_lines - 1 - && iti->show_ellipsis) { - max_width -= gdk_string_measure (font, e_icon_bar_text_item_ellipsis); - } - - for (row_end = text_iter; *row_end != 0 && *row_end != '\n'; row_end++); - - /* Accumulate words from this row until they don't fit in the max_width */ - - s = text_iter; - - while (s < row_end) { - word_start = s; - old_word_end = word_end; - for (word_end = word_start; *word_end; word_end++) { - GdkWChar *p; - for (p = separators_wc; *p; p++) { - if (*word_end == *p) - goto found; - } - } - found: - if (word_end < row_end) - word_end++; - - if (gdk_text_width_wc (font, text_iter, word_end - text_iter) > max_width) { - if (word_start == text_iter - || (restrict_lines - && lines == iti->max_lines - 1)) { - if (confine) { - /* We must force-split the word. Look for a proper - * place to do it. - */ - - w_len = word_end - text_iter; - - for (i = 1; i < w_len; i++) { - w = gdk_text_width_wc (font, text_iter, i); - if (w > max_width) { - if (i == 1) - /* Shit, not even a single character fits */ - max_width = w; - else - break; - } - } - - /* Create sub-row with the chars that fit */ - - sub_text = g_new (GdkWChar, i); - memcpy (sub_text, text_iter, (i - 1) * sizeof (GdkWChar)); - sub_text[i - 1] = 0; - - row = g_new (EIconBarTextItemInfoRow, 1); - row->text_wc = sub_text; - row->text_length = i - 1; - row->width = gdk_text_width_wc (font, sub_text, i - 1); - row->text = gdk_wcstombs(sub_text); - if (row->text == NULL) - row->text = g_strdup(""); - - ti->rows = g_list_append (ti->rows, row); - - if (row->width > ti->width) - ti->width = row->width; - - ti->height += ti->baseline_skip; - - /* Bump the text pointer */ - - text_iter += i - 1; - s = text_iter; - - lines++; - if (restrict_lines - && lines >= iti->max_lines) - break; - - continue; - } else - max_width = gdk_text_width_wc (font, word_start, word_end - word_start); - - continue; /* Retry split */ - } else { - word_end = old_word_end; /* Restore to region that does fit */ - break; /* Stop the loop because we found something that doesn't fit */ - } - } - - s = word_end; - } - - if (restrict_lines && lines >= iti->max_lines) - break; - - /* Append row */ - - if (text_iter == row_end) { - /* We are on a newline, so append an empty row */ - - ti->rows = g_list_append (ti->rows, NULL); - ti->height += ti->baseline_skip; - - /* Next! */ - - text_iter = row_end + 1; - - lines++; - if (restrict_lines && lines >= iti->max_lines) - break; - - } else { - /* Create subrow and append it to the list */ - - int sub_len; - sub_len = word_end - text_iter; - - sub_text = g_new (GdkWChar, sub_len + 1); - memcpy (sub_text, text_iter, sub_len * sizeof (GdkWChar)); - sub_text[sub_len] = 0; - - row = g_new (EIconBarTextItemInfoRow, 1); - row->text_wc = sub_text; - row->text_length = sub_len; - row->width = gdk_text_width_wc (font, sub_text, sub_len); - row->text = gdk_wcstombs(sub_text); - if (row->text == NULL) - row->text = g_strdup(""); - - ti->rows = g_list_append (ti->rows, row); - - if (row->width > ti->width) - ti->width = row->width; - - ti->height += ti->baseline_skip; - - /* Next! */ - - text_iter = word_end; - - lines++; - if (restrict_lines && lines >= iti->max_lines) - break; - } - } - - /* Check if we've had to clip the text. */ - iti->is_clipped = *text_iter ? TRUE : FALSE; - - g_free (text_wc); - g_free (separators_wc); - return ti; -} - -/* - * e_icon_bar_text_item_paint_text: - * @ti: An icon text info structure. - * @drawable: Target drawable. - * @gc: GC used to render the string. - * @x: Left coordinate for text. - * @y: Upper coordinate for text. - * @just: Justification for text. - * - * Paints the formatted text in the icon text info structure onto a drawable. - * This is just a sample implementation; applications can choose to use other - * rendering functions. - */ -static void -e_icon_bar_text_item_paint_text (EIconBarTextItem *iti, - EIconBarTextItemInfo *ti, - GdkDrawable *drawable, GdkGC *gc, - gint x, gint y, GtkJustification just) -{ - GList *item; - EIconBarTextItemInfoRow *row; - int xpos, line, width; - gboolean show_ellipsis; - - g_return_if_fail (ti != NULL); - g_return_if_fail (drawable != NULL); - g_return_if_fail (gc != NULL); - - y += ti->font->ascent; - - for (item = ti->rows, line = 1; item; item = item->next, line++) { - - if (item->data) { - row = item->data; - width = row->width; - } - - /* If this is the last line, and the text has been clipped, - and show_ellipsis is TRUE, display '...' */ - if (line == iti->max_lines && iti->is_clipped) { - show_ellipsis = TRUE; - width += gdk_string_measure (ti->font, e_icon_bar_text_item_ellipsis); - } else { - show_ellipsis = FALSE; - } - - switch (just) { - case GTK_JUSTIFY_LEFT: - xpos = 0; - break; - - case GTK_JUSTIFY_RIGHT: - xpos = ti->width - width; - break; - - case GTK_JUSTIFY_CENTER: - xpos = (ti->width - width) / 2; - break; - - default: - /* Anyone care to implement GTK_JUSTIFY_FILL? */ - g_warning ("Justification type %d not supported. Using left-justification.", - (int) just); - xpos = 0; - } - - if (item->data) - gdk_draw_text_wc (drawable, ti->font, gc, x + xpos, y, row->text_wc, row->text_length); - - if (show_ellipsis) - gdk_draw_string (drawable, ti->font, gc, - x + xpos + row->width, y, - e_icon_bar_text_item_ellipsis); - - y += ti->baseline_skip; - } -} diff --git a/widgets/shortcut-bar/e-icon-bar-text-item.h b/widgets/shortcut-bar/e-icon-bar-text-item.h deleted file mode 100644 index 7c0380c87b..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-text-item.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * Based on gnome-icon-text-item: an editable text block with word wrapping - * for the GNOME canvas. - * - * Copyright (C) 1998, 1999 The Free Software Foundation - * - * Authors: Miguel de Icaza - * Federico Mena - */ - -/* - * EIconBarTextItem - An editable canvas text item for the EIconBar. - */ - -#ifndef _E_ICON_BAR_TEXT_ITEM_H_ -#define _E_ICON_BAR_TEXT_ITEM_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_ICON_BAR_TEXT_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_icon_bar_text_item_get_type (), EIconBarTextItem)) -#define E_ICON_BAR_TEXT_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_icon_bar_text_item_get_type ())) -#define E_IS_ICON_BAR_TEXT_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_icon_bar_text_item_get_type ())) - -typedef struct _EIconBarTextItemInfo EIconBarTextItemInfo; - -typedef struct { - GnomeCanvasItem canvas_item; - - /* Size and maximum allowed width */ - int x, y; - int width; - - /* Font name */ - char *fontname; - - /* Private data */ - gpointer priv; /* was GtkEntry *entry */ - - /* Actual text */ - char *text; - - /* Text layout information */ - EIconBarTextItemInfo *ti; - - /* Whether the text is being edited */ - unsigned int editing : 1; - - /* Whether the text item is selected */ - unsigned int selected : 1; - - /* Whether the user is select-dragging a block of text */ - unsigned int selecting : 1; - - /* Whether the text is editable */ - unsigned int is_editable : 1; - - /* Whether the text is allocated by us (FALSE if allocated by the client) */ - unsigned int is_text_allocated : 1; - - - /* The horizontal alignment of the text (default 0.5). */ - gfloat xalign; - - /* The justification of the text (default is centered). */ - GtkJustification justification; - - /* The max number of lines of text shown, or -1 for all (default). */ - gint max_lines; - - /* If '...' is displayed if the text doesn't all fit (default TRUE). */ - gboolean show_ellipsis; - - /* This is TRUE if we couldn't fit all the text in. */ - gboolean is_clipped; -} EIconBarTextItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - /* Signals we emit */ - int (* text_changed) (EIconBarTextItem *iti); - void (* height_changed) (EIconBarTextItem *iti); - void (* width_changed) (EIconBarTextItem *iti); - void (* editing_started) (EIconBarTextItem *iti); - void (* editing_stopped) (EIconBarTextItem *iti); - void (* selection_started) (EIconBarTextItem *iti); - void (* selection_stopped) (EIconBarTextItem *iti); -} EIconBarTextItemClass; - -GtkType e_icon_bar_text_item_get_type (void); - -void e_icon_bar_text_item_configure (EIconBarTextItem *iti, - int x, - int y, - int width, - const char *fontname, - const char *text, - gboolean is_static); - -void e_icon_bar_text_item_set_width (EIconBarTextItem *iti, - int width); - -void e_icon_bar_text_item_setxy (EIconBarTextItem *iti, - int x, - int y); - -void e_icon_bar_text_item_select (EIconBarTextItem *iti, - int sel); - -char* e_icon_bar_text_item_get_text (EIconBarTextItem *iti); -void e_icon_bar_text_item_set_text (EIconBarTextItem *iti, - const char *text, - gboolean is_static); - -void e_icon_bar_text_item_start_editing (EIconBarTextItem *iti); -void e_icon_bar_text_item_stop_editing (EIconBarTextItem *iti, - gboolean accept); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ICON_BAR_TEXT_ITEM_H_ */ - diff --git a/widgets/shortcut-bar/e-icon-bar.c b/widgets/shortcut-bar/e-icon-bar.c deleted file mode 100644 index 1c87453507..0000000000 --- a/widgets/shortcut-bar/e-icon-bar.c +++ /dev/null @@ -1,1449 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBar is a subclass of GnomeCanvas for displaying a vertical column of - * icons and descriptions. It provides 2 views - large icons and small icons. - */ - -#include -#include -#include -#include "e-icon-bar.h" -#include "e-icon-bar-bg-item.h" -#include "e-icon-bar-text-item.h" - -/* These are the offsets of the icons & text in both views. Note that the - shadow around icons is drawn in the space between items (as is the - horizontal bar when dragging). */ -#define E_ICON_BAR_LARGE_ICON_SPACING 8 /* Spacing between items. */ -#define E_ICON_BAR_LARGE_ICON_WIDTH 48 -#define E_ICON_BAR_LARGE_ICON_HEIGHT 48 -#define E_ICON_BAR_LARGE_ICON_TEXT_X 4 -#define E_ICON_BAR_LARGE_ICON_TEXT_Y (E_ICON_BAR_LARGE_ICON_HEIGHT + 4) - -#define E_ICON_BAR_SMALL_ICON_SPACING 4 /* Spacing between items. */ -#define E_ICON_BAR_SMALL_ICON_WIDTH 24 -#define E_ICON_BAR_SMALL_ICON_HEIGHT 24 -#define E_ICON_BAR_SMALL_ICON_X 4 -#define E_ICON_BAR_SMALL_ICON_TEXT_X (E_ICON_BAR_SMALL_ICON_WIDTH + 4) - -/* The space we leave at the top or bottom of the bar when position an item - while it is being edited. This is used since the EIconBar may be in a - EScrolledBar which may show buttons at the top or bottom. */ -#define E_ICON_BAR_V_SPACE 22 - -/* The number of pixels the mouse has to be moved with the button down before - we start a drag. */ -#define E_ICON_BAR_DRAG_START_OFFSET 4 - -/* This is the area at the top & bottom of the bar where we auto-scroll if the - mouse goes into during a drag-and-drop operation. */ -#define E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET 16 - -/* This is the time between each auto-scroll, when dragging. */ -#define E_ICON_BAR_SCROLL_TIMEOUT 30 - -/* This is the number of timeouts we skip before we start scrolling. */ -#define E_ICON_BAR_SCROLL_DELAY 12 - - -static void e_icon_bar_class_init (EIconBarClass *class); -static void e_icon_bar_init (EIconBar *icon_bar); -static void e_icon_bar_destroy (GtkObject *object); -static void e_icon_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_icon_bar_leave_notify_event (GtkWidget *widget, - GdkEventCrossing *event); -static gint e_icon_bar_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_icon_bar_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static gint e_icon_bar_key_event (GtkWidget *widget, GdkEventKey *event); - -static gint e_icon_bar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); -static void e_icon_bar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time); -static void e_icon_bar_set_dragging_before_item (EIconBar *icon_bar, - gint before_item); -static gboolean e_icon_bar_timeout_handler (gpointer data); - -static void e_icon_bar_recalc_common_positions (EIconBar *icon_bar); -static gint e_icon_bar_recalc_item_positions (EIconBar *icon_bar); -static void e_icon_bar_on_text_height_changed (GnomeCanvasItem *text_item, - EIconBar *icon_bar); -static gint e_icon_bar_find_item (EIconBar *icon_bar, - GnomeCanvasItem *text_item); -static gboolean e_icon_bar_on_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EIconBar *icon_bar); - -static gboolean e_icon_bar_large_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_large_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_small_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_small_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static void e_icon_bar_on_text_item_editing_started (EIconBarTextItem *text_item, - EIconBar *icon_bar); -static void e_icon_bar_on_text_item_editing_stopped (EIconBarTextItem *text_item, - EIconBar *icon_bar); -static void e_icon_bar_ensure_edited_item_visible (EIconBar *icon_bar); -static void e_icon_bar_update_highlight (EIconBar *icon_bar); - -enum -{ - ITEM_SELECTED, - ITEM_DRAGGED, - LAST_SIGNAL -}; - -static guint e_icon_bar_signals[LAST_SIGNAL] = {0}; - -static GnomeCanvasClass *parent_class; - - -GtkType -e_icon_bar_get_type (void) -{ - static GtkType e_icon_bar_type = 0; - - if (!e_icon_bar_type){ - GtkTypeInfo e_icon_bar_info = { - "EIconBar", - sizeof (EIconBar), - sizeof (EIconBarClass), - (GtkClassInitFunc) e_icon_bar_class_init, - (GtkObjectInitFunc) e_icon_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - e_icon_bar_type = gtk_type_unique (gnome_canvas_get_type (), - &e_icon_bar_info); - } - - return e_icon_bar_type; -} - - -static void -e_icon_bar_class_init (EIconBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - e_icon_bar_signals[ITEM_SELECTED] = - gtk_signal_new ("item_selected", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarClass, - selected_item), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT); - e_icon_bar_signals[ITEM_DRAGGED] = - gtk_signal_new ("item_dragged", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarClass, - dragged_item), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_icon_bar_signals, - LAST_SIGNAL); - - /* Method override */ - object_class->destroy = e_icon_bar_destroy; - - widget_class->size_allocate = e_icon_bar_size_allocate; - widget_class->leave_notify_event = e_icon_bar_leave_notify_event; - widget_class->focus_in_event = e_icon_bar_focus_in; - widget_class->focus_out_event = e_icon_bar_focus_out; - widget_class->key_press_event = e_icon_bar_key_event; - widget_class->key_release_event = e_icon_bar_key_event; - widget_class->drag_motion = e_icon_bar_drag_motion; - widget_class->drag_leave = e_icon_bar_drag_leave; - - class->selected_item = NULL; -} - - -static void -e_icon_bar_init (EIconBar *icon_bar) -{ - icon_bar->view_type = E_ICON_BAR_LARGE_ICONS; - icon_bar->items = g_array_new (FALSE, FALSE, sizeof (EIconBarItem)); - icon_bar->pressed_item_num = -1; - icon_bar->mouse_over_item_num = -1; - icon_bar->editing_item_num = -1; - icon_bar->in_drag = FALSE; - icon_bar->dragging_before_item_num = -1; - icon_bar->icon_x = 0; - icon_bar->icon_w = 0; - icon_bar->icon_h = 0; - icon_bar->text_x = 0; - icon_bar->text_w = 5; - icon_bar->auto_scroll_timeout_id = 0; - - /* Create the background item in the canvas, which handles selections - and drag-and-drop. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - e_icon_bar_bg_item_get_type (), - "EIconBarBgItem::icon_bar", icon_bar, - NULL); -} - - -/** - * e_icon_bar_new: - * @Returns: A new #EIconBar. - * - * Creates a new #EIconBar. - **/ -GtkWidget * -e_icon_bar_new (void) -{ - GtkWidget *icon_bar; - - icon_bar = GTK_WIDGET (gtk_type_new (e_icon_bar_get_type ())); - GNOME_CANVAS(icon_bar)->aa = 1; - return icon_bar; -} - - -static void -e_icon_bar_destroy (GtkObject *object) -{ - EIconBar *icon_bar; - - icon_bar = E_ICON_BAR (object); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); - - g_array_free (icon_bar->items, TRUE); - - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } -} - - -static void -e_icon_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EIconBar *icon_bar; - gint canvas_width, canvas_height, height; - - icon_bar = E_ICON_BAR (widget); - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - canvas_width = GTK_WIDGET (icon_bar)->allocation.width; - canvas_height = GTK_WIDGET (icon_bar)->allocation.height; - - /* Reset the y position and widths of all the items to the width of - the canvas, and reset the button labels, so they fit. */ - e_icon_bar_recalc_common_positions (icon_bar); - height = e_icon_bar_recalc_item_positions (icon_bar); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, canvas_width, - MAX (height, canvas_height - 1)); - - /* If we are editing an item, make sure it is visible. */ - e_icon_bar_ensure_edited_item_visible (icon_bar); - - GTK_LAYOUT (widget)->vadjustment->step_increment = 16; - - e_icon_bar_update_highlight (icon_bar); -} - - -/* This sets all the item positions which are the same for all items in the - group. */ -static void -e_icon_bar_recalc_common_positions (EIconBar *icon_bar) -{ - gint canvas_width; - - canvas_width = GTK_WIDGET (icon_bar)->allocation.width; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - icon_bar->icon_x = (canvas_width - E_ICON_BAR_LARGE_ICON_WIDTH) / 2; - icon_bar->icon_w = E_ICON_BAR_LARGE_ICON_WIDTH; - icon_bar->icon_h = E_ICON_BAR_LARGE_ICON_HEIGHT; - - icon_bar->text_x = E_ICON_BAR_LARGE_ICON_TEXT_X; - icon_bar->text_w = MAX (canvas_width - (E_ICON_BAR_LARGE_ICON_TEXT_X * 2), 5); - - icon_bar->spacing = E_ICON_BAR_LARGE_ICON_SPACING; - } else { - icon_bar->icon_x = E_ICON_BAR_SMALL_ICON_X; - icon_bar->icon_w = E_ICON_BAR_SMALL_ICON_WIDTH; - icon_bar->icon_h = E_ICON_BAR_SMALL_ICON_HEIGHT; - - icon_bar->text_x = E_ICON_BAR_SMALL_ICON_TEXT_X; - icon_bar->text_w = MAX (canvas_width - E_ICON_BAR_SMALL_ICON_TEXT_X, 5); - - icon_bar->spacing = E_ICON_BAR_SMALL_ICON_SPACING; - } -} - - -/* This recalculates the positions of all the items, according to the current - view type and the height of the text items. */ -static gint -e_icon_bar_recalc_item_positions (EIconBar *icon_bar) -{ - EIconBarItem *item; - gint y, item_num; - gdouble x1, y1, x2, y2, xalign; - GtkJustification justify; - gint max_lines; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - xalign = 0.5; - justify = GTK_JUSTIFY_CENTER; - max_lines = 2; - } else { - xalign = 0.0; - justify = GTK_JUSTIFY_LEFT; - max_lines = 1; - } - - /* Now step through the items, setting the y positions. */ - y = icon_bar->spacing; - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - e_icon_bar_text_item_set_width (E_ICON_BAR_TEXT_ITEM (item->text), - icon_bar->text_w); - - /* Get the text item's height. */ - gnome_canvas_item_get_bounds (item->text, &x1, &y1, &x2, &y2); - item->text_width = x2 - x1; - item->text_height = y2 - y1; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - item->icon_y = y; - item->text_y = y + E_ICON_BAR_LARGE_ICON_TEXT_Y; - - item->item_height = E_ICON_BAR_LARGE_ICON_TEXT_Y - + item->text_height; - } else { - item->item_height = MAX (item->text_height, E_ICON_BAR_SMALL_ICON_HEIGHT); - item->icon_y = y + (item->item_height - E_ICON_BAR_SMALL_ICON_HEIGHT) / 2; - item->text_y = y + (item->item_height - item->text_height) / 2; - } - - e_icon_bar_text_item_setxy (E_ICON_BAR_TEXT_ITEM (item->text), - icon_bar->text_x, item->text_y); - - /* We need to get the bounds again, in case it has moved. */ - gnome_canvas_item_get_bounds (item->text, &x1, &y1, &x2, &y2); - item->text_x = x1; - - gnome_canvas_item_set (item->text, - "EIconBarTextItem::xalign", xalign, - "EIconBarTextItem::justify", justify, - "EIconBarTextItem::max_lines", max_lines, - NULL); - - gnome_canvas_item_set (item->image, - "GnomeCanvasPixbuf::x", (gdouble)icon_bar->icon_x, - "GnomeCanvasPixbuf::y", (gdouble)item->icon_y, - "GnomeCanvasPixbuf::width", (gdouble)icon_bar->icon_w, - "GnomeCanvasPixbuf::height", (gdouble)icon_bar->icon_h, - NULL); - - y += item->item_height + icon_bar->spacing; - } - - return y; -} - - -static gint -e_icon_bar_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event) -{ - EIconBar *icon_bar; - - icon_bar = E_ICON_BAR (widget); - - GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event); - - /* Make sure no items are highlighted. */ - e_icon_bar_item_motion (icon_bar, -1, NULL); - - return FALSE; -} - - -static gint -e_icon_bar_focus_in (GtkWidget *widget, - GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_CLASS (parent_class)->focus_in_event (widget, event); - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - return FALSE; -} - - -static gint -e_icon_bar_focus_out (GtkWidget *widget, - GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_CLASS (parent_class)->focus_out_event (widget, event); - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - return FALSE; -} - - -/* Key event handler for the canvas. - FIXME: GnomeCanvas bug workaround - I needed to override this to stop the - canvas ignoring key events from other windows. */ -static gint -e_icon_bar_key_event (GtkWidget *widget, GdkEventKey *event) -{ - GnomeCanvas *canvas; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - canvas = GNOME_CANVAS (widget); - - if (event->window != canvas->layout.bin_window) { - /* We change the window in the event struct so the canvas - doesn't ignore the event. Note that windows are ref-counted - in the event struct. */ - if (event->window) - gdk_window_unref (event->window); - event->window = canvas->layout.bin_window; - gdk_window_ref (event->window); - } - - /* These both call the same function at present, but we'll do it - properly just in case that changes. */ - if (event->type == GDK_KEY_PRESS) - return (*GTK_WIDGET_CLASS (parent_class)->key_press_event)(widget, event); - else - return (*GTK_WIDGET_CLASS (parent_class)->key_release_event)(widget, event); -} - - -/** - * e_icon_bar_set_view_type: - * @icon_bar: An #EIconBar. - * @view_type: The new view type, %E_ICON_BAR_LARGE_ICONS or - * %E_ICON_BAR_SMALL_ICONS. - * - * Sets the view type of the #EIconBar. - **/ -void -e_icon_bar_set_view_type (EIconBar *icon_bar, - EIconBarViewType view_type) -{ - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - - if (icon_bar->view_type == view_type) - return; - - icon_bar->view_type = view_type; - - /* Queue a resize of the canvas, so everything is put in the right - positions based on the new view type. */ - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/** - * e_icon_bar_add_item: - * @icon_bar: An #EIconBar. - * @image: the new item's icon. - * @text: the new item's text. - * @position: the position to place the new item, or -1 to place it last. - * - * Adds an item to the #EIconBar at the given position. - **/ -gint -e_icon_bar_add_item (EIconBar *icon_bar, - GdkPixbuf *image, - gchar *text, - gint position) -{ - EIconBarItem item; - gfloat xalign; - GtkJustification justify; - gint max_lines, retval; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), -1); - g_return_val_if_fail (text != NULL, -1); - g_return_val_if_fail (position >= -1, -1); - g_return_val_if_fail (position <= (gint)icon_bar->items->len, -1); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - xalign = 0.5; - justify = GTK_JUSTIFY_CENTER; - max_lines = 2; - } else { - xalign = 0.0; - justify = GTK_JUSTIFY_LEFT; - max_lines = 1; - } - - item.text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - e_icon_bar_text_item_get_type (), - "EIconBarTextItem::xalign", xalign, - "EIconBarTextItem::justify", justify, - "EIconBarTextItem::max_lines", max_lines, - NULL); - e_icon_bar_text_item_configure (E_ICON_BAR_TEXT_ITEM (item.text), - icon_bar->text_x, 0, - icon_bar->text_w, NULL, - text, FALSE); - gtk_signal_connect (GTK_OBJECT (item.text), "height_changed", - GTK_SIGNAL_FUNC (e_icon_bar_on_text_height_changed), icon_bar); - gtk_signal_connect (GTK_OBJECT (item.text), "event", - GTK_SIGNAL_FUNC (e_icon_bar_on_item_event), - icon_bar); - gtk_signal_connect (GTK_OBJECT (item.text), "editing_started", - GTK_SIGNAL_FUNC (e_icon_bar_on_text_item_editing_started), - icon_bar); - gtk_signal_connect (GTK_OBJECT (item.text), "editing_stopped", - GTK_SIGNAL_FUNC (e_icon_bar_on_text_item_editing_stopped), - icon_bar); - - item.image = gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - gnome_canvas_pixbuf_get_type (), - "GnomeCanvasPixbuf::pixbuf", image, - "GnomeCanvasPixbuf::width", (gdouble) icon_bar->icon_w, - "GnomeCanvasPixbuf::height", (gdouble) icon_bar->icon_h, - NULL); - gtk_signal_connect (GTK_OBJECT (item.image), "event", - GTK_SIGNAL_FUNC (e_icon_bar_on_item_event), - icon_bar); - - item.data = NULL; - item.destroy = NULL; - - if (position == -1) { - g_array_append_val (icon_bar->items, item); - retval = icon_bar->items->len - 1; - } else { - g_array_insert_val (icon_bar->items, position, item); - retval = position; - - /* FIXME: Should possibly update other indices. */ - if (icon_bar->dragged_item_num >= position) - icon_bar->dragged_item_num++; - } - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); - - return retval; -} - - -/** - * e_icon_bar_reorder_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item to move. - * @new_position: The new position of the item, which is used after the item - * has been removed from its current position. If @new_position is -1, the item - * is placed last. - * - * Moves an item to a new position within the #EIconBar. - **/ -void -e_icon_bar_reorder_item (EIconBar *icon_bar, - gint item_num, - gint new_position) -{ - EIconBarItem tmp_item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - g_return_if_fail (new_position >= -1); - g_return_if_fail (new_position < icon_bar->items->len); - - tmp_item = g_array_index (icon_bar->items, EIconBarItem, item_num); - g_array_remove_index (icon_bar->items, item_num); - - if (new_position == -1) - g_array_append_val (icon_bar->items, tmp_item); - else - g_array_insert_val (icon_bar->items, new_position, tmp_item); - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/** - * e_icon_bar_remove_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item to remove. - * - * Removes an item from the #EIconBar. - **/ -void -e_icon_bar_remove_item (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - - if (item->destroy) - item->destroy (item->data); - - gtk_object_destroy (GTK_OBJECT (item->text)); - gtk_object_destroy (GTK_OBJECT (item->image)); - - g_array_remove_index (icon_bar->items, item_num); - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/** - * e_icon_bar_get_item_image: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The icon of the given item. - * - * Returns the icon used for the given item. - **/ -GdkPixbuf * -e_icon_bar_get_item_image (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - GdkPixbuf *image = NULL; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gtk_object_get (GTK_OBJECT (item->image), - "GnomeCanvasPixbuf::pixbuf", image, - NULL); - return image; -} - - -/** - * e_icon_bar_set_item_image: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @image: The new icon to use for the given item. - * - * Sets the icon to use for the given item. - **/ -void -e_icon_bar_set_item_image (EIconBar *icon_bar, - gint item_num, - GdkPixbuf *image) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gnome_canvas_item_set (item->image, - "GnomeCanvasPixbuf::pixbuf", image, - NULL); -} - - -/** - * e_icon_bar_get_item_text: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The text of the given item. - * - * Returns the text of the given item. - **/ -gchar* -e_icon_bar_get_item_text (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - return e_icon_bar_text_item_get_text (E_ICON_BAR_TEXT_ITEM (item->text)); -} - - -/** - * e_icon_bar_set_item_text: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @text: The new text for the given item. - * - * Sets the text of the given item. - **/ -void -e_icon_bar_set_item_text (EIconBar *icon_bar, - gint item_num, - gchar *text) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - e_icon_bar_text_item_set_text (E_ICON_BAR_TEXT_ITEM (item->text), - text, FALSE); -} - - -/** - * e_icon_bar_get_item_data: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The user data associated with the given item. - * - * Returns the user data associated with the given item. - **/ -gpointer -e_icon_bar_get_item_data (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - return item->data; -} - - -/** - * e_icon_bar_set_item_data: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @data: The user data to set for the given item. - * - * Sets the user data of the given item. - **/ -void -e_icon_bar_set_item_data (EIconBar *icon_bar, - gint item_num, - gpointer data) -{ - e_icon_bar_set_item_data_full (icon_bar, item_num, data, NULL); -} - - -/** - * e_icon_bar_set_item_data_full: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @data: The user data to set for the given item. - * @destroy: The function to free @data when the item is destroyed. - * - * Sets the user data of the given item, and the function to free the data - * when the item is destroyed. - **/ -void -e_icon_bar_set_item_data_full (EIconBar *icon_bar, - gint item_num, - gpointer data, - GtkDestroyNotify destroy) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - - if (item->destroy) - item->destroy (item->data); - - item->data = data; - item->destroy = destroy; -} - - -static void -e_icon_bar_on_text_height_changed (GnomeCanvasItem *text_item, - EIconBar *icon_bar) -{ - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/* This returns the index of the given item, or -1 if it isn't found. */ -static gint -e_icon_bar_find_item (EIconBar *icon_bar, - GnomeCanvasItem *canvas_item) -{ - EIconBarItem *item; - gint item_num; - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - if (item->text == canvas_item || item->image == canvas_item) { - return item_num; - } - } - - return -1; -} - - -/* When an item has a grab, it will get all events, so we need to use the - position to find the real item. */ -static gboolean -e_icon_bar_on_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EIconBar *icon_bar) -{ - gint item_num; - - switch (event->type) { - case GDK_BUTTON_PRESS: - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_pressed (icon_bar, item_num, event); - return TRUE; - case GDK_BUTTON_RELEASE: - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_released (icon_bar, item_num, event); - return TRUE; - case GDK_MOTION_NOTIFY: - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->motion.x, - event->motion.y, - NULL); - e_icon_bar_item_motion (icon_bar, item_num, event); - return TRUE; - default: - break; - } - - return FALSE; -} - - -void -e_icon_bar_item_pressed (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - EIconBarItem *item; - gint button; - - /* If we are editing an item, and a different item (or anywhere outside - an item) is clicked, stop the edit. If the item being edited is - clicked we just return, since the user may be selecting text. */ - if (icon_bar->editing_item_num != -1) { - if (icon_bar->editing_item_num == item_num) { - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->editing_item_num); - if (!GTK_WIDGET_HAS_FOCUS (item->text->canvas) - || item->text->canvas->focused_item != item->text) - gnome_canvas_item_grab_focus (item->text); - } else { - e_icon_bar_stop_editing_item (icon_bar, TRUE); - } - - return; - } - - button = event->button.button; - - if (button == 1 && item_num != -1) { - icon_bar->pressed_item_num = item_num; - icon_bar->pressed_x = event->button.x; - icon_bar->pressed_y = event->button.y; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } else if (button == 3) { - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_SELECTED], - event, item_num); - } -} - - -void -e_icon_bar_item_released (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - gint button; - - /* If we are editing an item, just return. */ - if (icon_bar->editing_item_num != -1) - return; - - button = event->button.button; - - if (button == 1) { - if (icon_bar->pressed_item_num != -1 - && icon_bar->pressed_item_num == icon_bar->mouse_over_item_num) { - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_SELECTED], - event, item_num); - } - - icon_bar->pressed_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } -} - - -void -e_icon_bar_item_motion (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - gboolean need_redraw = TRUE; - - if (event && event->motion.state & GDK_BUTTON1_MASK - && icon_bar->pressed_item_num != -1) { - if (abs (event->motion.x - icon_bar->pressed_x) > E_ICON_BAR_DRAG_START_OFFSET - || abs (event->motion.y - icon_bar->pressed_y) > E_ICON_BAR_DRAG_START_OFFSET) { - icon_bar->dragged_item_num = icon_bar->pressed_item_num; - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_DRAGGED], - event, icon_bar->dragged_item_num); - - /* Don't show the button as pressed while dragging. */ - icon_bar->pressed_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } - - return; - } - - if (icon_bar->mouse_over_item_num == item_num) - return; - - /* If we are editing an item, items aren't highlighted so we don't - need a redraw. Also if an item is pressed, we only need a redraw if - item_num or the old mouse_over_item_num is the pressed item. */ - if (icon_bar->editing_item_num != -1) { - need_redraw = FALSE; - } else if (icon_bar->pressed_item_num != -1) { - if (icon_bar->pressed_item_num != item_num - && icon_bar->pressed_item_num != icon_bar->mouse_over_item_num) - need_redraw = FALSE; - } - - icon_bar->mouse_over_item_num = item_num; - - if (need_redraw) - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); -} - - -/* This returns the index of the item at the given position on the EIconBar, - or -1 if no item is found. If before_item is not NULL, it returns the - item which the mouse is before, or -1 (for dragging). */ -gint -e_icon_bar_find_item_at_position (EIconBar *icon_bar, - gint x, - gint y, - gint *before_item) -{ - EIconBarItem *item = NULL; - gint item_num; - - if (before_item) - *before_item = -1; - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - if (e_icon_bar_large_icons_intersects (icon_bar, item, - x, y)) - return item_num; - - if (before_item - && e_icon_bar_large_icons_is_before (icon_bar, - item, x, y)) { - *before_item = item_num; - return -1; - } - } else { - if (e_icon_bar_small_icons_intersects (icon_bar, item, - x, y)) - return item_num; - - if (before_item - && e_icon_bar_small_icons_is_before (icon_bar, - item, x, y)) { - *before_item = item_num; - return -1; - } - - } - - } - - /* If the mouse is below all the items, but inside the items' width, - and before_item is not NULL, we set it to the number of items, so - the dropped item would be added at the end. Note that this assumes - that the item variable points to the last item in the EIconBar. */ - if (before_item) { - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - if (x < icon_bar->text_x - || x >= icon_bar->text_x + icon_bar->text_w) - return -1; - - if (item == NULL - || y > item->icon_y + item->item_height) - *before_item = icon_bar->items->len; - } else { - if (x < icon_bar->icon_x - || x >= icon_bar->text_x + icon_bar->text_w) - return -1; - - if (item == NULL) { - *before_item = icon_bar->items->len; - } else { - gint max_y; - max_y = MAX (item->icon_y + icon_bar->icon_h, - item->text_y + item->text_height); - if (y > max_y) - *before_item = icon_bar->items->len; - } - } - } - - return -1; -} - - -static gboolean -e_icon_bar_large_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - if (y < item->icon_y || y >= item->text_y + item->text_height) - return FALSE; - - if (y < item->icon_y + icon_bar->icon_h) { - if (x < icon_bar->icon_x - || x >= icon_bar->icon_x + icon_bar->icon_w) - return FALSE; - } else { - if (x < item->text_x - || x >= item->text_x + item->text_width) - return FALSE; - } - - return TRUE; -} - - -static gboolean -e_icon_bar_large_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - if (y < item->icon_y - icon_bar->spacing - || y >= item->icon_y) - return FALSE; - - if (x < icon_bar->text_x || x >= icon_bar->text_x + icon_bar->text_w) - return FALSE; - - return TRUE; -} - - -static gboolean -e_icon_bar_small_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - gint min_y, max_y; - - min_y = MIN (item->icon_y, item->text_y); - max_y = MAX (item->icon_y + icon_bar->icon_h, - item->text_y + item->text_height); - - if (y < min_y || y >= max_y) - return FALSE; - - if (x < icon_bar->icon_x || x >= item->text_x + item->text_width) - return FALSE; - - return TRUE; -} - - -static gboolean -e_icon_bar_small_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - gint min_y, max_y; - - max_y = MIN (item->icon_y, item->text_y); - min_y = max_y - icon_bar->spacing; - - if (y < min_y || y >= max_y) - return FALSE; - - if (x < icon_bar->icon_x || x >= icon_bar->text_x + icon_bar->text_w) - return FALSE; - - return TRUE; -} - - -/** - * e_icon_bar_start_editing_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * - * Turns the item into an editable text field so the user can rename it. - * Editing is stopped automatically when the user hits 'Return' or clicks - * outside the item. It can also be stopped explicitly by calling - * e_icon_bar_stop_editing_item(). - **/ -void -e_icon_bar_start_editing_item (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - e_icon_bar_text_item_start_editing (E_ICON_BAR_TEXT_ITEM (item->text)); -} - - -/** - * e_icon_bar_stop_editing_item: - * @icon_bar: An #EIconBar. - * @accept: TRUE if the changes should be accepted, FALSE if the text should be - * changed back to its state before the editing started. - * - * Stops the editing of the items, if any were being edited. - **/ -void -e_icon_bar_stop_editing_item (EIconBar *icon_bar, - gboolean accept) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - - if (icon_bar->editing_item_num != -1) { - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->editing_item_num); - e_icon_bar_text_item_stop_editing (E_ICON_BAR_TEXT_ITEM (item->text), accept); - } -} - - -static void -e_icon_bar_on_text_item_editing_started (EIconBarTextItem *text_item, - EIconBar *icon_bar) -{ - gint item_num; - - item_num = e_icon_bar_find_item (icon_bar, - GNOME_CANVAS_ITEM (text_item)); - g_return_if_fail (item_num != -1); - - /* Turn off any highlighted item. */ - e_icon_bar_item_motion (icon_bar, -1, NULL); - - icon_bar->editing_item_num = item_num; - - e_icon_bar_ensure_edited_item_visible (icon_bar); -} - - -static void -e_icon_bar_on_text_item_editing_stopped (EIconBarTextItem *text_item, - EIconBar *icon_bar) -{ - gint item_num; - - item_num = e_icon_bar_find_item (icon_bar, - GNOME_CANVAS_ITEM (text_item)); - g_return_if_fail (item_num != -1); - - e_icon_bar_text_item_select (text_item, FALSE); - - icon_bar->editing_item_num = -1; - - e_icon_bar_update_highlight (icon_bar); -} - - -static void -e_icon_bar_ensure_edited_item_visible (EIconBar *icon_bar) -{ - EIconBarItem *item; - gint scroll_x, scroll_y, min_scroll_y, max_scroll_y, new_scroll_y; - - if (icon_bar->editing_item_num == -1) - return; - - item = &g_array_index (icon_bar->items, - EIconBarItem, icon_bar->editing_item_num); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - - /* The minimum scroll y position is with the text right on the bottom - of the display. */ - min_scroll_y = item->text_y + item->text_height + E_ICON_BAR_V_SPACE - - GTK_WIDGET (icon_bar)->allocation.height; - /* The maximum scroll y position is with the text at the top. */ - max_scroll_y = item->text_y - E_ICON_BAR_V_SPACE; - - new_scroll_y = MAX (scroll_y, min_scroll_y); - new_scroll_y = MIN (new_scroll_y, max_scroll_y); - - if (new_scroll_y != scroll_y) - gnome_canvas_scroll_to (GNOME_CANVAS (icon_bar), - scroll_x, new_scroll_y); -} - - -/* This gets the mouse position and updates the highlight if necessary. - It is called after items are added/deleted/scrolled/edited. */ -static void -e_icon_bar_update_highlight (EIconBar *icon_bar) -{ - GtkWidget *widget; - gint x, y, item_num; - - widget = GTK_WIDGET (icon_bar); - - if (!widget->window) - return; - - gdk_window_get_pointer (widget->window, &x, &y, NULL); - - if (x < 0 || y < 0 - || x > widget->allocation.width || y > widget->allocation.height) - return; - - item_num = e_icon_bar_find_item_at_position (icon_bar, x, y, NULL); - e_icon_bar_item_motion (icon_bar, item_num, NULL); -} - - -static gint -e_icon_bar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - EIconBar *icon_bar; - gint item_num, before_item, scroll_x, scroll_y; - - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - - icon_bar = E_ICON_BAR (widget); - - icon_bar->in_drag = TRUE; - - /* Check if the mouse is over or between items, and if so highlight. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - item_num = e_icon_bar_find_item_at_position (icon_bar, - x + scroll_x, - y + scroll_y, - &before_item); - e_icon_bar_item_motion (icon_bar, item_num, NULL); - e_icon_bar_set_dragging_before_item (icon_bar, before_item); - - /* Check if the mouse is at the top or bottom of the bar, and if it is - scroll up/down. */ - if (y < E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET) - icon_bar->scrolling_up = TRUE; - else if (y >= widget->allocation.height - E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET) - icon_bar->scrolling_up = FALSE; - else { - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } - return FALSE; - } - - if (icon_bar->auto_scroll_timeout_id == 0) { - icon_bar->auto_scroll_timeout_id = g_timeout_add (E_ICON_BAR_SCROLL_TIMEOUT, e_icon_bar_timeout_handler, icon_bar); - icon_bar->auto_scroll_delay = E_ICON_BAR_SCROLL_DELAY; - } - - return FALSE; -} - - -static void -e_icon_bar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time) -{ - EIconBar *icon_bar; - - g_return_if_fail (E_IS_ICON_BAR (widget)); - - icon_bar = E_ICON_BAR (widget); - - icon_bar->in_drag = FALSE; - - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } - - if (icon_bar->mouse_over_item_num != -1) { - icon_bar->mouse_over_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } -} - - -static void -e_icon_bar_set_dragging_before_item (EIconBar *icon_bar, - gint before_item) -{ - if (icon_bar->dragging_before_item_num == before_item) - return; - - icon_bar->dragging_before_item_num = before_item; - - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); -} - - -static gboolean -e_icon_bar_timeout_handler (gpointer data) -{ - EIconBar *icon_bar; - gint scroll_x, scroll_y, new_scroll_y; - GtkAdjustment *adj; - - g_return_val_if_fail (E_IS_ICON_BAR (data), FALSE); - - icon_bar = E_ICON_BAR (data); - - GDK_THREADS_ENTER (); - - if (icon_bar->auto_scroll_delay > 0) { - icon_bar->auto_scroll_delay--; - GDK_THREADS_LEAVE (); - return TRUE; - } - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - - adj = GTK_LAYOUT (icon_bar)->vadjustment; - - if (icon_bar->scrolling_up) - new_scroll_y = MAX (scroll_y - adj->step_increment, 0); - else - new_scroll_y = MIN (scroll_y + adj->step_increment, - adj->upper - adj->page_size); - - if (new_scroll_y != scroll_y) - gnome_canvas_scroll_to (GNOME_CANVAS (icon_bar), - scroll_x, new_scroll_y); - - GDK_THREADS_LEAVE (); - return TRUE; -} diff --git a/widgets/shortcut-bar/e-icon-bar.h b/widgets/shortcut-bar/e-icon-bar.h deleted file mode 100644 index 65ab69f23f..0000000000 --- a/widgets/shortcut-bar/e-icon-bar.h +++ /dev/null @@ -1,222 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_ICON_BAR_H_ -#define _E_ICON_BAR_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EIconBar is a subclass of GnomeCanvas for displaying a vertical column of - * icons and descriptions. It provides 2 views - large icons and small icons. - */ - - -/* This contains information on one item. */ -typedef struct _EIconBarItem EIconBarItem; -struct _EIconBarItem -{ - GnomeCanvasItem *text; - GnomeCanvasItem *image; - - /* This is user data attached to the item, e.g. a URL. */ - gpointer data; - GtkDestroyNotify destroy; - - /* This is the height of the item. */ - gint item_height; - - /* This is the actual x, width and height of the text, rather than - the maximum allowed area. */ - gint text_x; - gint text_width; - gint text_height; - - gint icon_y, text_y; -}; - - -/* These are the view types. Defaults to LARGE_ICONS. */ -typedef enum -{ - E_ICON_BAR_LARGE_ICONS, - E_ICON_BAR_SMALL_ICONS -} EIconBarViewType; - - -#define E_ICON_BAR(obj) GTK_CHECK_CAST (obj, e_icon_bar_get_type (), EIconBar) -#define E_ICON_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_icon_bar_get_type (), EIconBarClass) -#define E_IS_ICON_BAR(obj) GTK_CHECK_TYPE (obj, e_icon_bar_get_type ()) - - -typedef struct _EIconBar EIconBar; -typedef struct _EIconBarClass EIconBarClass; - -struct _EIconBar -{ - GnomeCanvas canvas; - - /* This specifies if we are using large icons or small icons. */ - EIconBarViewType view_type; - - /* This is an array of EIconBarItem elements. */ - GArray *items; - - /* This is the index of the item which has been pressed, or -1. - It will be shown as pressed in while the mouse is over it. */ - gint pressed_item_num; - - /* This is the coordinates of where the button was pressed. If the - mouse moves a certain distance with the button still pressed, we - start a drag. */ - gint pressed_x; - gint pressed_y; - - /* This is the index of the item the mouse is currently over, or -1. - It will be highlighted unless one of the items is pressed. */ - gint mouse_over_item_num; - - /* This is the item that we are currently editing, or -1. */ - gint editing_item_num; - - /* This is the index of the item which is being dragged, or -1. - If the drag results in a move it will be deleted. */ - gint dragged_item_num; - - /* This is TRUE if we are dragging over this EIconBar. */ - gboolean in_drag; - - /* This is used in drag-and-drop to indicate the item which the mouse - is currently before, e.g. if it is 1 then a dropped item would be - inserted between items 0 and 1. It ranges from 0 to the number of - items, or is -1 when the mouse is not dragging between items. */ - gint dragging_before_item_num; - - /* These are the common positions of all the items in the EIconBar. */ - gint icon_x, icon_w, icon_h, text_x, text_w, spacing; - - /* This is the source id of our auto-scroll timeout handler, used when - in the middle of drag-and-drop operations. */ - gint auto_scroll_timeout_id; - gint auto_scroll_delay; - gboolean scrolling_up; -}; - -struct _EIconBarClass -{ - GnomeCanvasClass parent_class; - - void (*selected_item) (EIconBar *icon_bar, - GdkEvent *event, - gint item_num); - void (*dragged_item) (EIconBar *icon_bar, - GdkEvent *event, - gint item_num); -}; - - -GtkType e_icon_bar_get_type (void); -GtkWidget* e_icon_bar_new (void); - -/* Sets the view type. */ -void e_icon_bar_set_view_type (EIconBar *icon_bar, - EIconBarViewType view_type); - -/* Adds a new item to a group at the given position. If position is -1 it is - added at the end. It returns the index of the item. */ -gint e_icon_bar_add_item (EIconBar *icon_bar, - GdkPixbuf *image, - gchar *text, - gint position); - -/* Reorders an item. Note that position refers to the new position to add the - item after removing it from its current position. If position is -1 it is - moved to the end of the bar. */ -void e_icon_bar_reorder_item (EIconBar *icon_bar, - gint item_num, - gint new_position); -void e_icon_bar_remove_item (EIconBar *icon_bar, - gint item_num); - -GdkPixbuf * e_icon_bar_get_item_image (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_image (EIconBar *icon_bar, - gint item_num, - GdkPixbuf *image); - -gchar* e_icon_bar_get_item_text (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_text (EIconBar *icon_bar, - gint item_num, - gchar *text); - -gpointer e_icon_bar_get_item_data (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_data (EIconBar *icon_bar, - gint item_num, - gpointer data); -void e_icon_bar_set_item_data_full (EIconBar *icon_bar, - gint item_num, - gpointer data, - GtkDestroyNotify destroy); - -void e_icon_bar_start_editing_item (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_stop_editing_item (EIconBar *icon_bar, - gboolean accept); - - - -/* - * INTERNAL FUNCTIONS - for use by EIconBarBgItem. - */ - -/* This returns the index of the item at the given position on the EIconBar, - or -1 if no item is found. If before_item is not NULL, it returns the - item which the mouse is before, or -1 (this is used for dragging). */ -gint e_icon_bar_find_item_at_position (EIconBar *icon_bar, - gint x, - gint y, - gint *before_item); - -void e_icon_bar_item_pressed (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); -void e_icon_bar_item_released (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); -void e_icon_bar_item_motion (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ICON_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-shortcut-bar.c b/widgets/shortcut-bar/e-shortcut-bar.c deleted file mode 100644 index 842a8927f9..0000000000 --- a/widgets/shortcut-bar/e-shortcut-bar.c +++ /dev/null @@ -1,562 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * ShortcutBar displays a vertical bar with a number of Groups, each of which - * contains any number of icons. It is used on the left of the main application - * window so users can easily access items such as folders and files. - */ - -#include -#include - -#include "e-shortcut-bar.h" -#include "e-clipped-label.h" -#include "e-vscrolled-bar.h" - -/* Drag and Drop stuff. */ -enum { - TARGET_SHORTCUT -}; -static GtkTargetEntry target_table[] = { - { "E-SHORTCUT", 0, TARGET_SHORTCUT } -}; -static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); - -typedef struct _EShortcutBarBuiltinType EShortcutBarBuiltinType; -struct _EShortcutBarBuiltinType { - gchar *name; - gchar *filename; - GdkPixbuf *image; -}; - -EShortcutBarBuiltinType e_shortcut_bar_builtin_types[] = { - { "folder:", "gnome-word.png", NULL }, - { "calendar:", "gnome-calendar.png", NULL }, - { "todo:", "gnome-cromagnon.png", NULL }, - { "contacts:", "gnome-ccthemes.png", NULL } -}; -static gint e_shortcut_bar_num_builtin_types = sizeof (e_shortcut_bar_builtin_types) / sizeof (EShortcutBarBuiltinType); - -gboolean e_shortcut_bar_default_type_image_loaded = FALSE; -GdkPixbuf *e_shortcut_bar_default_type_image = NULL; -gchar *e_shortcut_bar_default_type_filename = "gnome-balsa2.png"; - -static void e_shortcut_bar_class_init (EShortcutBarClass *class); -static void e_shortcut_bar_init (EShortcutBar *shortcut_bar); -static void e_shortcut_bar_destroy (GtkObject *object); -static void e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar, - GtkWidget *canvas); -static void e_shortcut_bar_item_selected (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_item_dragged (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_stop_editing (GtkWidget *button, - EShortcutBar *shortcut_bar); -static GdkPixbuf* e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar, - gchar *item_url); -static GdkPixbuf* e_shortcut_bar_load_image (gchar *filename); - - -enum -{ - ITEM_SELECTED, - LAST_SIGNAL -}; - -static guint e_shortcut_bar_signals[LAST_SIGNAL] = {0}; - -static EGroupBarClass *parent_class; - - -GtkType -e_shortcut_bar_get_type (void) -{ - static GtkType e_shortcut_bar_type = 0; - - if (!e_shortcut_bar_type){ - GtkTypeInfo e_shortcut_bar_info = { - "EShortcutBar", - sizeof (EShortcutBar), - sizeof (EShortcutBarClass), - (GtkClassInitFunc) e_shortcut_bar_class_init, - (GtkObjectInitFunc) e_shortcut_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (e_group_bar_get_type ()); - e_shortcut_bar_type = gtk_type_unique (e_group_bar_get_type (), - &e_shortcut_bar_info); - } - - return e_shortcut_bar_type; -} - - -static void -e_shortcut_bar_class_init (EShortcutBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - e_shortcut_bar_signals[ITEM_SELECTED] = - gtk_signal_new ("item_selected", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutBarClass, - selected_item), - gtk_marshal_NONE__POINTER_INT_INT, - GTK_TYPE_NONE, 3, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_shortcut_bar_signals, - LAST_SIGNAL); - - /* Method override */ - object_class->destroy = e_shortcut_bar_destroy; -} - - -static void -e_shortcut_bar_init (EShortcutBar *shortcut_bar) -{ - shortcut_bar->groups = g_array_new (FALSE, FALSE, - sizeof (EShortcutBarGroup)); -} - - -GtkWidget * -e_shortcut_bar_new (void) -{ - GtkWidget *shortcut_bar; - - shortcut_bar = GTK_WIDGET (gtk_type_new (e_shortcut_bar_get_type ())); - - return shortcut_bar; -} - - -static void -e_shortcut_bar_destroy (GtkObject *object) -{ - EShortcutBar *shortcut_bar; - - shortcut_bar = E_SHORTCUT_BAR (object); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); - - g_array_free (shortcut_bar->groups, TRUE); -} - - -gint -e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, gchar *group_name) -{ - EShortcutBarGroup *group, tmp_group; - gint group_num; - GtkWidget *button, *label; - - g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1); - g_return_val_if_fail (group_name != NULL, -1); - - group_num = shortcut_bar->groups->len; - g_array_append_val (shortcut_bar->groups, tmp_group); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - group->vscrolled_bar = e_vscrolled_bar_new (NULL); - gtk_widget_show (group->vscrolled_bar); - gtk_signal_connect (GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->up_button), "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar); - gtk_signal_connect (GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->down_button), "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar); - - group->icon_bar = e_icon_bar_new (); - gtk_widget_show (group->icon_bar); - gtk_container_add (GTK_CONTAINER (group->vscrolled_bar), - group->icon_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_selected", - GTK_SIGNAL_FUNC (e_shortcut_bar_item_selected), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_dragged", - GTK_SIGNAL_FUNC (e_shortcut_bar_item_dragged), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_get", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_get), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_received", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_received), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_delete", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_delete), - shortcut_bar); - - e_shortcut_bar_set_canvas_style (shortcut_bar, group->icon_bar); - - button = gtk_button_new (); - label = e_clipped_label_new (group_name); - gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); - gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER (button), label); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), - shortcut_bar); - - gtk_drag_dest_set (GTK_WIDGET (group->icon_bar), - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_dest_set (GTK_WIDGET (button), - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - - e_group_bar_add_group (E_GROUP_BAR (shortcut_bar), - group->vscrolled_bar, button, -1); - - - return group_num; -} - - -void -e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, - gint group_num) -{ - e_group_bar_remove_group (E_GROUP_BAR (shortcut_bar), group_num); - g_array_remove_index (shortcut_bar->groups, group_num); -} - - -gint -e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, gint group_num, - gchar *item_url, gchar *item_name) -{ - EShortcutBarGroup *group; - GdkPixbuf *image; - gint item_num; - - g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1); - g_return_val_if_fail (group_num >= 0, -1); - g_return_val_if_fail (group_num < shortcut_bar->groups->len, -1); - g_return_val_if_fail (item_url != NULL, -1); - g_return_val_if_fail (item_name != NULL, -1); - - image = e_shortcut_bar_get_image_from_url (shortcut_bar, item_url); - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar), - image, item_name, -1); - e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), item_num, - g_strdup (item_url), g_free); - return item_num; -} - - -void -e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_remove_item (E_ICON_BAR (group->icon_bar), item_num); -} - - -static void -e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar, - GtkWidget *canvas) -{ - GtkRcStyle *rc_style; - - rc_style = gtk_rc_style_new (); - - rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG; - rc_style->fg[GTK_STATE_NORMAL].red = 65535; - rc_style->fg[GTK_STATE_NORMAL].green = 65535; - rc_style->fg[GTK_STATE_NORMAL].blue = 65535; - - rc_style->bg[GTK_STATE_NORMAL].red = 32512; - rc_style->bg[GTK_STATE_NORMAL].green = 32512; - rc_style->bg[GTK_STATE_NORMAL].blue = 32512; - - gtk_widget_modify_style (GTK_WIDGET (canvas), rc_style); - gtk_rc_style_unref (rc_style); -} - - -void -e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, - gint group_num, - EIconBarViewType view_type) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_set_view_type (E_ICON_BAR (group->icon_bar), view_type); -} - - -static void -e_shortcut_bar_item_selected (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar) -{ - gint group_num; - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - - gtk_signal_emit (GTK_OBJECT (shortcut_bar), - e_shortcut_bar_signals[ITEM_SELECTED], - event, group_num, item_num); -} - - -static void -e_shortcut_bar_item_dragged (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar) -{ - GtkTargetList *target_list; - gint group_num; - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - - /* FIXME: free somewhere - drag_end? */ - shortcut_bar->dragged_url = g_strdup (e_icon_bar_get_item_data (icon_bar, item_num)); - shortcut_bar->dragged_name = g_strdup (e_icon_bar_get_item_text (icon_bar, item_num)); - - target_list = gtk_target_list_new (target_table, n_targets); - gtk_drag_begin (GTK_WIDGET (icon_bar), target_list, - GDK_ACTION_COPY | GDK_ACTION_MOVE, - 1, event); - gtk_target_list_unref (target_list); -} - - -static void -e_shortcut_bar_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EShortcutBar *shortcut_bar) -{ - gchar *data; - - if (info == TARGET_SHORTCUT) { - data = g_strdup_printf ("%s%c%s", shortcut_bar->dragged_name, - '\0', shortcut_bar->dragged_url); - gtk_selection_data_set (selection_data, selection_data->target, - 8, data, - strlen (shortcut_bar->dragged_name) - + strlen (shortcut_bar->dragged_url) - + 2); - g_free (data); - } -} - - -static void -e_shortcut_bar_on_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EShortcutBar *shortcut_bar) -{ - EShortcutBarGroup *group; - gchar *item_name, *item_url; - EIconBar *icon_bar; - GdkPixbuf *image; - gint group_num, item_num; - - icon_bar = E_ICON_BAR (widget); - - if ((data->length >= 0) && (data->format == 8) - && icon_bar->dragging_before_item_num != -1) { - item_name = data->data; - item_url = item_name + strlen (item_name) + 1; - - image = e_shortcut_bar_get_image_from_url (shortcut_bar, - item_url); - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar), image, item_name, icon_bar->dragging_before_item_num); - e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), - item_num, g_strdup (item_url), - g_free); - - gtk_drag_finish (context, TRUE, TRUE, time); - return; - } - - gtk_drag_finish (context, FALSE, FALSE, time); -} - - -static void -e_shortcut_bar_on_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar) -{ - EIconBar *icon_bar; - - icon_bar = E_ICON_BAR (widget); - - e_icon_bar_remove_item (icon_bar, icon_bar->dragged_item_num); -} - - -void -e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_start_editing_item (E_ICON_BAR (group->icon_bar), item_num); -} - - -/* We stop editing any item when a scroll button is pressed. */ -static void -e_shortcut_bar_stop_editing (GtkWidget *button, - EShortcutBar *shortcut_bar) -{ - EShortcutBarGroup *group; - gint group_num; - - for (group_num = 0; - group_num < shortcut_bar->groups->len; - group_num++) { - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - e_icon_bar_stop_editing_item (E_ICON_BAR (group->icon_bar), - TRUE); - } -} - - -static GdkPixbuf * -e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar, - gchar *item_url) -{ - gchar *method_terminator; - gint method_len, i; - - method_terminator = strchr (item_url, ':'); - if (method_terminator) { - method_len = method_terminator - item_url + 1; - - /* Check if it is a builtin type. */ - for (i = 0; i < e_shortcut_bar_num_builtin_types; i++) { - if (!strncmp (item_url, e_shortcut_bar_builtin_types[i].name, method_len)) { - if (!e_shortcut_bar_builtin_types[i].image) - e_shortcut_bar_builtin_types[i].image = e_shortcut_bar_load_image (e_shortcut_bar_builtin_types[i].filename); - return e_shortcut_bar_builtin_types[i].image; - } - } - } - - if (!e_shortcut_bar_default_type_image_loaded) { - e_shortcut_bar_default_type_image_loaded = TRUE; - e_shortcut_bar_default_type_image = e_shortcut_bar_load_image (e_shortcut_bar_default_type_filename); - } - return e_shortcut_bar_default_type_image; -} - - -static GdkPixbuf * -e_shortcut_bar_load_image (gchar *filename) -{ - gchar *pathname; - GdkPixbuf *image = NULL; - - pathname = gnome_pixmap_file (filename); - if (pathname) - image = gdk_pixbuf_new_from_file (pathname); - else - g_warning ("Couldn't find pixmap: %s", filename); - - return image; -} diff --git a/widgets/shortcut-bar/e-shortcut-bar.h b/widgets/shortcut-bar/e-shortcut-bar.h deleted file mode 100644 index 1bbdfb6754..0000000000 --- a/widgets/shortcut-bar/e-shortcut-bar.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_SHORTCUT_BAR_H_ -#define _E_SHORTCUT_BAR_H_ - -#include "e-group-bar.h" -#include "e-icon-bar.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EShortcutBar displays a vertical bar with a number of Groups, each of which - * contains any number of icons. It is used on the left of the main application - * window so users can easily access items such as folders and files. - */ - - -/* This contains information on one group. */ -typedef struct _EShortcutBarGroup EShortcutBarGroup; -struct _EShortcutBarGroup -{ - /* This is the EVScrolledBar which scrolls the group. */ - GtkWidget *vscrolled_bar; - - /* This is the icon bar containing the child items. */ - GtkWidget *icon_bar; -}; - - -#define E_SHORTCUT_BAR(obj) GTK_CHECK_CAST (obj, e_shortcut_bar_get_type (), EShortcutBar) -#define E_SHORTCUT_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_bar_get_type (), EShortcutBarClass) -#define E_IS_SHORTCUT_BAR(obj) GTK_CHECK_TYPE (obj, e_shortcut_bar_get_type ()) - - -typedef struct _EShortcutBar EShortcutBar; -typedef struct _EShortcutBarClass EShortcutBarClass; - -struct _EShortcutBar -{ - EGroupBar group_bar; - - /* This is an array of EShortcutBarGroup elements. */ - GArray *groups; - - gchar *dragged_url; - gchar *dragged_name; -}; - -struct _EShortcutBarClass -{ - EGroupBarClass parent_class; - - void (*selected_item) (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); -}; - - -GtkType e_shortcut_bar_get_type (void); -GtkWidget* e_shortcut_bar_new (void); - -/* Adds a new group, returning the index. */ -gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, - gchar *group_name); -void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, - gint group_num); - -/* Sets the view type for the group. */ -void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, - gint group_num, - EIconBarViewType view_type); - -/* Adds a new item to a group, returning the index within the group. */ -gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, - gint group_num, - gchar *item_url, - gchar *item_name); - -void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); -void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_SHORTCUT_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-vscrolled-bar.c b/widgets/shortcut-bar/e-vscrolled-bar.c deleted file mode 100644 index 5d5f0ab2e2..0000000000 --- a/widgets/shortcut-bar/e-vscrolled-bar.c +++ /dev/null @@ -1,652 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget - * vertically. It is intended for scrolling narrow vertical bars. - */ - -#include -#include -#include - -#include "e-vscrolled-bar.h" - -/* These are the offsets of the up & down buttons from the right and top/bottom - of the widget. */ -#define E_VSCROLLED_BAR_BUTTON_X_OFFSET 2 -#define E_VSCROLLED_BAR_BUTTON_Y_OFFSET 2 - -/* This is the time between scrolls. */ -#define E_VSCROLLED_BAR_SCROLL_TIMEOUT 20 - -static void e_vscrolled_bar_class_init (EVScrolledBarClass *class); -static void e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_destroy (GtkObject *object); -static void e_vscrolled_bar_finalize (GtkObject *object); -static void e_vscrolled_bar_map (GtkWidget *widget); -static void e_vscrolled_bar_unmap (GtkWidget *widget); -static void e_vscrolled_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_vscrolled_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void e_vscrolled_bar_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_vscrolled_bar_add (GtkContainer *container, - GtkWidget *child); -static void e_vscrolled_bar_remove (GtkContainer *container, - GtkWidget *child); -static void e_vscrolled_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static void e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment, - gpointer data); -static void e_vscrolled_bar_button_pressed (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_button_released (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_button_clicked (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static gboolean e_vscrolled_bar_timeout_handler (gpointer data); - - -static GtkBinClass *parent_class; - - -GtkType -e_vscrolled_bar_get_type (void) -{ - static GtkType e_vscrolled_bar_type = 0; - - if (!e_vscrolled_bar_type) { - GtkTypeInfo e_vscrolled_bar_info = { - "EVScrolledBar", - sizeof (EVScrolledBar), - sizeof (EVScrolledBarClass), - (GtkClassInitFunc) e_vscrolled_bar_class_init, - (GtkObjectInitFunc) e_vscrolled_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_BIN); - e_vscrolled_bar_type = gtk_type_unique (GTK_TYPE_BIN, - &e_vscrolled_bar_info); - } - - return e_vscrolled_bar_type; -} - - -static void -e_vscrolled_bar_class_init (EVScrolledBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - /* Method override */ - object_class->destroy = e_vscrolled_bar_destroy; - object_class->finalize = e_vscrolled_bar_finalize; - - widget_class->map = e_vscrolled_bar_map; - widget_class->unmap = e_vscrolled_bar_unmap; - widget_class->size_request = e_vscrolled_bar_size_request; - widget_class->size_allocate = e_vscrolled_bar_size_allocate; - widget_class->draw = e_vscrolled_bar_draw; - - container_class->add = e_vscrolled_bar_add; - container_class->remove = e_vscrolled_bar_remove; - container_class->forall = e_vscrolled_bar_forall; -} - - -static void -e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar) -{ - GtkWidget *arrow; - - GTK_WIDGET_SET_FLAGS (vscrolled_bar, GTK_NO_WINDOW); - - gtk_container_set_resize_mode (GTK_CONTAINER (vscrolled_bar), - GTK_RESIZE_QUEUE); - - gtk_widget_push_composite_child (); - - vscrolled_bar->up_button = gtk_button_new (); - gtk_widget_set_composite_name (vscrolled_bar->up_button, - "up_button"); - gtk_widget_set_parent (vscrolled_bar->up_button, - GTK_WIDGET (vscrolled_bar)); - arrow = gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_OUT); - gtk_misc_set_padding (GTK_MISC (arrow), 1, 1); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (vscrolled_bar->up_button), arrow); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar); - gtk_signal_connect (GTK_OBJECT (vscrolled_bar->up_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar); - - vscrolled_bar->down_button = gtk_button_new (); - gtk_widget_set_composite_name (vscrolled_bar->up_button, - "down_button"); - gtk_widget_set_parent (vscrolled_bar->down_button, - GTK_WIDGET (vscrolled_bar)); - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_misc_set_padding (GTK_MISC (arrow), 1, 1); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (vscrolled_bar->down_button), arrow); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar); - gtk_signal_connect (GTK_OBJECT (vscrolled_bar->down_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar); - - gtk_widget_pop_composite_child (); - - vscrolled_bar->adjustment = NULL; - vscrolled_bar->timeout_id = 0; - vscrolled_bar->scrolling_up = FALSE; - vscrolled_bar->min_distance = -1.0; - vscrolled_bar->button_pressed = FALSE; -} - - -/** - * e_vscrolled_bar_new: - * - * @adjustment: The #GtkAdjustment to use for scrolling, or NULL. - * @Return: A new #EVScrolledBar. - * - * Creates a new #EVScrolledBar with the given adjustment. - **/ -GtkWidget * -e_vscrolled_bar_new (GtkAdjustment *adjustment) -{ - GtkWidget *vscrolled_bar; - - vscrolled_bar = GTK_WIDGET (gtk_type_new (e_vscrolled_bar_get_type ())); - e_vscrolled_bar_set_adjustment (E_VSCROLLED_BAR (vscrolled_bar), - adjustment); - - return vscrolled_bar; -} - - -static void -e_vscrolled_bar_destroy (GtkObject *object) -{ - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (object); - - if (vscrolled_bar->timeout_id) { - g_source_remove (vscrolled_bar->timeout_id); - vscrolled_bar->timeout_id = 0; - } - - gtk_widget_unparent (vscrolled_bar->up_button); - gtk_widget_unparent (vscrolled_bar->down_button); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_vscrolled_bar_finalize (GtkObject *object) -{ - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (object); - - gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment)); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - - -static void -e_vscrolled_bar_map (GtkWidget *widget) -{ - EVScrolledBar *vscrolled_bar; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - - /* chain parent class handler to map self and child */ - GTK_WIDGET_CLASS (parent_class)->map (widget); - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->up_button) && - !GTK_WIDGET_MAPPED (vscrolled_bar->up_button)) - gtk_widget_map (vscrolled_bar->up_button); - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->down_button) && - !GTK_WIDGET_MAPPED (vscrolled_bar->down_button)) - gtk_widget_map (vscrolled_bar->down_button); -} - - -static void -e_vscrolled_bar_unmap (GtkWidget *widget) -{ - EVScrolledBar *vscrolled_bar; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - - /* chain parent class handler to unmap self and child */ - GTK_WIDGET_CLASS (parent_class)->unmap (widget); - - if (GTK_WIDGET_MAPPED (vscrolled_bar->up_button)) - gtk_widget_unmap (vscrolled_bar->up_button); - - if (GTK_WIDGET_MAPPED (vscrolled_bar->down_button)) - gtk_widget_unmap (vscrolled_bar->down_button); -} - - -static void -e_vscrolled_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (requisition != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - requisition->width = 0; - requisition->height = 0; - - /* We just return the requisition of the child widget, plus the - border width. */ - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { - gtk_widget_size_request (bin->child, &child_requisition); - *requisition = child_requisition; - } - - /* We remember the requested heights of the up & down buttons. */ - gtk_widget_size_request (vscrolled_bar->up_button, - &child_requisition); - vscrolled_bar->up_button_width = child_requisition.width; - vscrolled_bar->up_button_height = child_requisition.height; - - gtk_widget_size_request (vscrolled_bar->down_button, - &child_requisition); - vscrolled_bar->down_button_width = child_requisition.width; - vscrolled_bar->down_button_height = child_requisition.height; - - /* Add on the standard container border widths. */ - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; -} - - -static void -e_vscrolled_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GtkAllocation button_allocation, child_allocation; - gint border_width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (allocation != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - widget->allocation = *allocation; - - border_width = GTK_CONTAINER (widget)->border_width; - - child_allocation.x = border_width; - child_allocation.y = border_width; - child_allocation.width = allocation->width - 2 * border_width; - child_allocation.height = allocation->height - 2 * border_width; - gtk_widget_size_allocate (bin->child, &child_allocation); - - button_allocation.x = allocation->width - border_width - - vscrolled_bar->up_button_width - - E_VSCROLLED_BAR_BUTTON_X_OFFSET; - button_allocation.y = border_width + E_VSCROLLED_BAR_BUTTON_Y_OFFSET; - button_allocation.width = vscrolled_bar->up_button_width; - button_allocation.height = vscrolled_bar->up_button_height; - gtk_widget_size_allocate (vscrolled_bar->up_button, - &button_allocation); - - button_allocation.x = allocation->width - border_width - - vscrolled_bar->down_button_width - - E_VSCROLLED_BAR_BUTTON_X_OFFSET; - button_allocation.y = allocation->height - border_width - - vscrolled_bar->down_button_height - - E_VSCROLLED_BAR_BUTTON_Y_OFFSET; - button_allocation.width = vscrolled_bar->down_button_width; - button_allocation.height = vscrolled_bar->down_button_height; - gtk_widget_size_allocate (vscrolled_bar->down_button, - &button_allocation); -} - - -static void -e_vscrolled_bar_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (area != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child) && - gtk_widget_intersect (bin->child, area, &child_area)) - gtk_widget_draw (bin->child, &child_area); - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->up_button) && - gtk_widget_intersect (vscrolled_bar->up_button, area, &child_area)) - gtk_widget_draw (vscrolled_bar->up_button, &child_area); - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->down_button) && - gtk_widget_intersect (vscrolled_bar->down_button, area, &child_area)) - gtk_widget_draw (vscrolled_bar->down_button, &child_area); -} - - -static void -e_vscrolled_bar_add (GtkContainer *container, - GtkWidget *child) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - - vscrolled_bar = E_VSCROLLED_BAR (container); - bin = GTK_BIN (container); - - g_return_if_fail (bin->child == NULL); - - bin->child = child; - gtk_widget_set_parent (child, GTK_WIDGET (bin)); - - gtk_widget_set_scroll_adjustments (child, NULL, - vscrolled_bar->adjustment); - - if (GTK_WIDGET_REALIZED (child->parent)) - gtk_widget_realize (child); - - if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { - if (GTK_WIDGET_MAPPED (child->parent)) - gtk_widget_map (child); - - gtk_widget_queue_resize (child); - } -} - - -static void -e_vscrolled_bar_remove (GtkContainer *container, - GtkWidget *child) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - g_return_if_fail (child != NULL); - g_return_if_fail (GTK_BIN (container)->child == child); - - gtk_widget_set_scroll_adjustments (child, NULL, NULL); - - /* chain parent class handler to remove child */ - GTK_CONTAINER_CLASS (parent_class)->remove (container, child); -} - - -static void -e_vscrolled_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - g_return_if_fail (callback != NULL); - - GTK_CONTAINER_CLASS (parent_class)->forall (container, - include_internals, - callback, - callback_data); - if (include_internals) { - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (container); - - if (vscrolled_bar->up_button) - callback (vscrolled_bar->up_button, callback_data); - if (vscrolled_bar->down_button) - callback (vscrolled_bar->down_button, callback_data); - } -} - - -/** - * e_vscrolled_bar_get_adjustment: - * - * @vscrolled_bar: An #EVScrolledBar. - * @Return: The #GtkAdjustment used for scrolling @vscrolled_bar. - * - * Returns the #GtkAdjustment used for scrolling the #EVscrolledBar. - **/ -GtkAdjustment* -e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar) -{ - g_return_val_if_fail (vscrolled_bar != NULL, NULL); - g_return_val_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar), NULL); - - return vscrolled_bar->adjustment; -} - - -/** - * e_vscrolled_bar_set_adjustment: - * - * @vscrolled_bar: An #EVScrolledBar. - * @adjustment: The #GtkAdjustment to use for scrolling @vscrolled_bar. - * - * Sets the #GtkAdjustment to use for scrolling the #EVscrolledBar. - **/ -void -e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar, - GtkAdjustment *adjustment) -{ - g_return_if_fail (vscrolled_bar != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar)); - - if (adjustment) - g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); - else - adjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL); - - if (vscrolled_bar->adjustment == adjustment) - return; - - if (vscrolled_bar->adjustment) { - gtk_signal_disconnect_by_func (GTK_OBJECT (vscrolled_bar->adjustment), - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment)); - } - - vscrolled_bar->adjustment = adjustment; - gtk_object_ref (GTK_OBJECT (vscrolled_bar->adjustment)); - gtk_object_sink (GTK_OBJECT (vscrolled_bar->adjustment)); - - /* I've used connect_after here to avoid a problem when using a - GnomeCanvas as the child widget. When just using connect it would - leave a blank space when one of the buttons is hidden. We want - the GtkLayout to handle the scrolling before we hide any buttons. */ - gtk_signal_connect_after (GTK_OBJECT (adjustment), "changed", - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (adjustment), "value_changed", - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - - e_vscrolled_bar_adjustment_changed (adjustment, vscrolled_bar); - - if (GTK_BIN (vscrolled_bar)->child) - gtk_widget_set_scroll_adjustments (GTK_BIN (vscrolled_bar)->child, NULL, adjustment); -} - - -static void -e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment, - gpointer data) -{ - EVScrolledBar *vscrolled_bar; - - g_return_if_fail (adjustment != NULL); - g_return_if_fail (data != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (data); - - /* If the adjustment value is not 0, show the up button. */ - if (adjustment->value != 0) - gtk_widget_show (vscrolled_bar->up_button); - else - gtk_widget_hide (vscrolled_bar->up_button); - - /* If the adjustment value is less than the maximum value, show the - down button. */ - if (adjustment->value < adjustment->upper - adjustment->page_size) - gtk_widget_show (vscrolled_bar->down_button); - else - gtk_widget_hide (vscrolled_bar->down_button); -} - - -static void -e_vscrolled_bar_button_pressed (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - if (vscrolled_bar->timeout_id != 0) - g_source_remove (vscrolled_bar->timeout_id); - - vscrolled_bar->timeout_id = g_timeout_add (E_VSCROLLED_BAR_SCROLL_TIMEOUT, e_vscrolled_bar_timeout_handler, vscrolled_bar); - vscrolled_bar->scrolling_up = (button == vscrolled_bar->up_button) ? TRUE : FALSE; - vscrolled_bar->min_distance = vscrolled_bar->adjustment->page_size / 4; - vscrolled_bar->button_pressed = TRUE; - - e_vscrolled_bar_timeout_handler (vscrolled_bar); -} - - -static void -e_vscrolled_bar_button_released (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - vscrolled_bar->button_pressed = FALSE; -} - - -/* This will be called when the user hits the space key to activate the button. - It will also be called just before button_released() is called, but since - we already handle that we simply return if the button is pressed. */ -static void -e_vscrolled_bar_button_clicked (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - if (vscrolled_bar->button_pressed) - return; - - /* We act as if the button is pressed and released immediately. */ - e_vscrolled_bar_button_pressed (button, vscrolled_bar); - vscrolled_bar->button_pressed = FALSE; -} - - -static gboolean -e_vscrolled_bar_timeout_handler (gpointer data) -{ - EVScrolledBar *vscrolled_bar; - GtkAdjustment *adjustment; - gfloat new_value; - gboolean retval = TRUE; - - vscrolled_bar = E_VSCROLLED_BAR (data); - adjustment = vscrolled_bar->adjustment; - - GDK_THREADS_ENTER (); - - /* Check if the user has released the button and we have already - scrolled the minimum distance. */ - if (vscrolled_bar->button_pressed == FALSE - && vscrolled_bar->min_distance <= 0) { - GDK_THREADS_LEAVE (); - return FALSE; - } - - vscrolled_bar->min_distance -= adjustment->step_increment; - - if (vscrolled_bar->scrolling_up) { - new_value = adjustment->value - adjustment->step_increment; - if (new_value <= adjustment->lower) { - new_value = adjustment->lower; - retval = FALSE; - } - } else { - new_value = adjustment->value + adjustment->step_increment; - if (new_value >= adjustment->upper - adjustment->page_size) { - new_value = adjustment->upper - adjustment->page_size; - retval = FALSE; - } - } - - if (adjustment->value != new_value) { - adjustment->value = new_value; - gtk_signal_emit_by_name (GTK_OBJECT (adjustment), - "value_changed"); - } - - GDK_THREADS_LEAVE (); - return retval; -} diff --git a/widgets/shortcut-bar/e-vscrolled-bar.h b/widgets/shortcut-bar/e-vscrolled-bar.h deleted file mode 100644 index d3273e6685..0000000000 --- a/widgets/shortcut-bar/e-vscrolled-bar.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_VSCROLLED_BAR_H_ -#define _E_VSCROLLED_BAR_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget - * vertically. It is intended for scrolling narrow vertical bars. - */ - - -#define E_VSCROLLED_BAR(obj) GTK_CHECK_CAST (obj, e_vscrolled_bar_get_type (), EVScrolledBar) -#define E_VSCROLLED_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_vscrolled_bar_get_type (), EVScrolledBarClass) -#define E_IS_VSCROLLED_BAR(obj) GTK_CHECK_TYPE (obj, e_vscrolled_bar_get_type ()) - - -typedef struct _EVScrolledBar EVScrolledBar; -typedef struct _EVScrolledBarClass EVScrolledBarClass; - -struct _EVScrolledBar -{ - GtkBin bin; - - GtkWidget *up_button; - GtkWidget *down_button; - - GtkAdjustment *adjustment; - - gint up_button_width; - gint up_button_height; - gint down_button_width; - gint down_button_height; - - /* The GTK+ event source ID of our timeout handler. */ - gint timeout_id; - - /* TRUE if we are scrolling up, FALSE if scrolling down. */ - gboolean scrolling_up; - - /* The minimum distance left to scroll. If the user just clicks a - button we scroll a minimum amount. This is reduced after each - scroll. */ - gfloat min_distance; - - /* TRUE if the button is still pressed. When the up/down button is - released, this gets set to FALSE, and we scroll until the minimum - distance falls below 0. */ - gboolean button_pressed; -}; - -struct _EVScrolledBarClass -{ - GtkBinClass parent_class; -}; - - -GtkType e_vscrolled_bar_get_type (void); -GtkWidget* e_vscrolled_bar_new (GtkAdjustment *adjustment); - -GtkAdjustment* e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar); -void e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar, - GtkAdjustment *adjustment); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_VSCROLLED_BAR_H_ */ diff --git a/widgets/shortcut-bar/test-shortcut-bar.c b/widgets/shortcut-bar/test-shortcut-bar.c deleted file mode 100644 index a86ec2a772..0000000000 --- a/widgets/shortcut-bar/test-shortcut-bar.c +++ /dev/null @@ -1,445 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin - * - * Copyright 1999, Helix Code, Inc. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This tests the ShortcutBar widget. - */ - -#include - -#include "e-shortcut-bar.h" - -#define NUM_SHORTCUT_TYPES 5 -gchar *shortcut_types[] = { - "folder:", "file:", "calendar:", "todo:", "contacts:" -}; - -GtkWidget *main_label; - -static void quit (GtkWidget *window, GdkEvent *event, gpointer data); -static void add_test_groups (EShortcutBar *shortcut_bar); -static void add_test_group (EShortcutBar *shortcut_bar, gint i, - gchar *group_name); -static gint get_random_int (gint max); - -static void on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); -static void show_standard_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num); -static void show_context_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); - -static void set_large_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void set_small_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void remove_group (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); - -static void rename_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void remove_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); - -int -main (int argc, char *argv[]) -{ - GtkWidget *window, *hpaned, *shortcut_bar; - - gnome_init ("test-shortcut-bar", "0.1", argc, argv); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - window = gnome_app_new ("TestShortcutBar", "TestShortCutBar"); - gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); - gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE); - - gtk_signal_connect (GTK_OBJECT (window), "delete-event", - GTK_SIGNAL_FUNC (quit), NULL); - - hpaned = gtk_hpaned_new (); - gnome_app_set_contents (GNOME_APP (window), hpaned); - gtk_widget_show (hpaned); - - shortcut_bar = e_shortcut_bar_new (); - gtk_paned_pack1 (GTK_PANED (hpaned), shortcut_bar, FALSE, TRUE); - gtk_widget_show (shortcut_bar); - -#if 0 - gtk_container_set_border_width (GTK_CONTAINER (shortcut_bar), 4); -#endif - - gtk_paned_set_position (GTK_PANED (hpaned), 100); - /*gtk_paned_set_gutter_size (GTK_PANED (hpaned), 12);*/ - - main_label = gtk_label_new ("Main Application Window Goes Here"); - gtk_paned_pack2 (GTK_PANED (hpaned), main_label, TRUE, TRUE); - gtk_widget_show (main_label); - - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - add_test_groups (E_SHORTCUT_BAR (shortcut_bar)); - - gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_selected", - GTK_SIGNAL_FUNC (on_shortcut_bar_item_selected), - NULL); - - gtk_widget_show (window); - gtk_main (); - return 0; -} - - -static void -quit (GtkWidget *window, GdkEvent *event, gpointer data) -{ - gtk_widget_destroy (window); - gtk_exit (0); -} - - -static void -add_test_groups (EShortcutBar *shortcut_bar) -{ - add_test_group (shortcut_bar, 1, "Shortcuts"); - add_test_group (shortcut_bar, 2, "My Shortcuts"); - add_test_group (shortcut_bar, 3, "Longer Shortcuts"); - add_test_group (shortcut_bar, 4, "Very Long Shortcuts"); - add_test_group (shortcut_bar, 5, "Incredibly Long Shortcuts"); -} - - -static void -add_test_group (EShortcutBar *shortcut_bar, gint i, gchar *group_name) -{ - gint group_num, item_num, num_items; - gchar buffer[128]; - gint shortcut_type, j; - - group_num = e_shortcut_bar_add_group (E_SHORTCUT_BAR (shortcut_bar), - group_name); - - if (group_num % 2) - e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (shortcut_bar), - group_num, - E_ICON_BAR_SMALL_ICONS); - - num_items = get_random_int (5) + 3; - for (j = 1; j <= num_items; j++) { - if (j == 1) - sprintf (buffer, "A very long shortcut with proper words so I can test the wrapping and ellipsis behaviour"); - else if (j == 2) - sprintf (buffer, "A very long shortcut with averylongworkinthemiddlesoIcantestthewrappingandellipsisbehaviour"); - else - sprintf (buffer, "Item %i:%i\n", i, j); - - shortcut_type = get_random_int (NUM_SHORTCUT_TYPES); - item_num = e_shortcut_bar_add_item (E_SHORTCUT_BAR (shortcut_bar), group_num, shortcut_types[shortcut_type], buffer); - } -} - - -/* Returns a random integer between 0 and max - 1. */ -static gint -get_random_int (gint max) -{ - gint random_num; - - random_num = (int) (max * (rand () / (RAND_MAX + 1.0))); -#if 0 - g_print ("Random num (%i): %i\n", max, random_num); -#endif - return random_num; -} - - -static void -on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar, - GdkEvent *event, gint group_num, gint item_num) -{ - gchar buffer[256]; - - if (event->button.button == 1) { - sprintf (buffer, "Item Selected - %i:%i", - group_num + 1, item_num + 1); - gtk_label_set_text (GTK_LABEL (main_label), buffer); - } else if (event->button.button == 3) { - if (item_num == -1) - show_standard_popup (shortcut_bar, event, group_num); - else - show_context_popup (shortcut_bar, event, group_num, - item_num); - } -} - - -static void -show_standard_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num) -{ - GtkWidget *menu, *menuitem; - - /* We don't have any commands if there aren't any groups yet. */ - if (group_num == -1) - return; - - menu = gtk_menu_new (); - - menuitem = gtk_menu_item_new_with_label ("Large Icons"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (set_large_icons), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Small Icons"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (set_small_icons), shortcut_bar); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Add New Group"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Remove Group"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (remove_group), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Rename Group"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Add Shortcut..."); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Hide Shortcut Bar"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - /* Save the group num so we can get it in the callbacks. */ - gtk_object_set_data (GTK_OBJECT (menu), "group_num", - GINT_TO_POINTER (group_num)); - - /* FIXME: Destroy menu when finished with it somehow? */ - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button.button, event->button.time); -} - - -static void -set_large_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_bar_set_view_type (shortcut_bar, group_num, - E_ICON_BAR_LARGE_ICONS); -} - - -static void -set_small_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_bar_set_view_type (shortcut_bar, group_num, - E_ICON_BAR_SMALL_ICONS); -} - - -static void -remove_group (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_bar_remove_group (shortcut_bar, group_num); -} - - -static void -show_context_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num) -{ - GtkWidget *menu, *menuitem, *label, *pixmap; - - menu = gtk_menu_new (); - - menuitem = gtk_pixmap_menu_item_new (); - label = gtk_label_new ("Open Folder"); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER (menuitem), label); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - pixmap = gnome_stock_pixmap_widget (menu, GNOME_STOCK_MENU_OPEN); - if (pixmap) { - gtk_widget_show(pixmap); - gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menuitem), pixmap); - } - - menuitem = gtk_menu_item_new_with_label ("Open in New Window"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Advanced Find"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Remove from Shortcut Bar"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (remove_item), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Rename Shortcut"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (rename_item), shortcut_bar); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Properties"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - - /* Save the group & item nums so we can get them in the callbacks. */ - gtk_object_set_data (GTK_OBJECT (menu), "group_num", - GINT_TO_POINTER (group_num)); - gtk_object_set_data (GTK_OBJECT (menu), "item_num", - GINT_TO_POINTER (item_num)); - - /* FIXME: Destroy menu when finished with it somehow? */ - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button.button, event->button.time); -} - - -static void -rename_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num, item_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "item_num")); - - e_shortcut_bar_start_editing_item (shortcut_bar, group_num, item_num); -} - - -static void -remove_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num, item_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "item_num")); - - e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num); -} - - diff --git a/widgets/table/.cvsignore b/widgets/table/.cvsignore deleted file mode 100644 index 0963d457d9..0000000000 --- a/widgets/table/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -table-test diff --git a/widgets/table/add-col.xpm b/widgets/table/add-col.xpm deleted file mode 100644 index 9c5f314c8e..0000000000 --- a/widgets/table/add-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * add_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" ....+++....... ", -" .+. ", -" . ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/table/check-empty.xpm b/widgets/table/check-empty.xpm deleted file mode 100644 index 2dd873e137..0000000000 --- a/widgets/table/check-empty.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static char * check_empty_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/check-filled.xpm b/widgets/table/check-filled.xpm deleted file mode 100644 index 689d7a7967..0000000000 --- a/widgets/table/check-filled.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static char * check_filled_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . . ", -" . .. . ", -" . ... . ", -" . . ... . ", -" . .. ... . ", -" . ..... . ", -" . ... . ", -" . . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/e-cell-checkbox.c b/widgets/table/e-cell-checkbox.c deleted file mode 100644 index 431c1663d1..0000000000 --- a/widgets/table/e-cell-checkbox.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * e-cell-checkbox.c: Checkbox cell renderer - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-checkbox.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -#define PARENT_TYPE e_cell_toggle_get_type() - -static GdkPixbuf *checks [2]; - -static void -e_cell_checkbox_class_init (GtkObjectClass *object_class) -{ - checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_checkbox_new (void) -{ - ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - - e_cell_toggle_construct (E_CELL_TOGGLE (eccb), 2, 2, checks); - - return (ECell *) eccb; -} diff --git a/widgets/table/e-cell-checkbox.h b/widgets/table/e-cell-checkbox.h deleted file mode 100644 index 969e4a5edc..0000000000 --- a/widgets/table/e-cell-checkbox.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include "e-cell-toggle.h" - -#define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_CHECKBOX_TYPE, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(o) (GTK_CHECK_TYPE ((o), E_CELL_CHECKBOX_TYPE)) -#define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) - -typedef struct { - ECellToggle parent; -} ECellCheckbox; - -typedef struct { - ECellToggleClass parent_class; -} ECellCheckboxClass; - -GtkType e_cell_checkbox_get_type (void); -ECell *e_cell_checkbox_new (void); - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/table/e-cell-string.c b/widgets/table/e-cell-string.c deleted file mode 100644 index 992b1bd10e..0000000000 --- a/widgets/table/e-cell-string.c +++ /dev/null @@ -1,9 +0,0 @@ -ECell * -e_cell_string_new (void) -{ - ECell *ecell; - - ecell = gtk_type_new (ecell); - - return ecell; -} diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c deleted file mode 100644 index 6e5b28b8a1..0000000000 --- a/widgets/table/e-cell-text.c +++ /dev/null @@ -1,1843 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-text.c - Text cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Authors: Miguel de Icaza (miguel@kernel.org) - * Chris Lahey - * - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-text.h" -#include "e-util/e-util.h" -#include "e-table-item.h" -#include "e-text-event-processor-emacs-like.h" - -#include /* for BlackPixel */ -#include -#include - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -static GdkAtom clipboard_atom = GDK_NONE; - - - -#define PARENT_TYPE e_cell_get_type() - -#define TEXT_PAD 2 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - int max_width; - int ref_count; -} ECellTextLineBreaks; - - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GdkFont *font; - GdkCursor *default_cursor; - GdkCursor *i_cursor; - GdkBitmap *stipple; /* Stipple for text */ - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - - int xofs, yofs; /* This gets added to the x - and y for the cell text. */ - double ellipsis_width; /* The width of the ellipsis. */ - -} ECellTextView; - -typedef struct _CurrentCell{ - - ECellTextView *text_view; - int width; - gchar *text; - int model_col, view_col, row; - ECellTextLineBreaks *breaks; -} CurrentCell; - -#define CURRENT_CELL(x) ((CurrentCell *)(x)) - -struct _CellEdit { - CurrentCell cell; - - char *old_text; - - /* - * Where the editing is taking place - */ - - int xofs_edit, yofs_edit; /* Offset because of editing. - This is negative compared - to the other offsets. */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - /* Cursor handling. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; - guint default_cursor_shown : 1; -}; - -static void e_cell_text_view_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_cell_text_view_get_selection(CellEdit *edit, GdkAtom selection, guint32 time); -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, guchar *data, gint length); - -static GtkWidget *e_cell_text_view_get_invisible(CellEdit *edit); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit); -static void split_into_lines (CurrentCell *cell); -static void unref_lines(CurrentCell *cell); -static void calc_line_widths (CurrentCell *cell); -static int get_line_ypos (CurrentCell *cell, struct line *line); -static int get_line_xpos (CurrentCell *cell, struct line *line); -static void _get_tep(CellEdit *edit); - -static gint _get_position_from_xy (CurrentCell *cell, gint x, gint y); -static void _get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp); -static gboolean _blink_scroll_timeout (gpointer data); - -static void build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row); - -static ECellClass *parent_class; - -static void -ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Accept the currently edited text - */ -static void -ect_accept_edits (ECellTextView *text_view) -{ - CurrentCell *cell = (CurrentCell *) text_view->edit; - - e_table_model_set_value_at (text_view->cell_view.e_table_model, cell->model_col, cell->row, cell->text); -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - - g_free (edit->old_text); - edit->old_text = NULL; - g_free (edit->cell.text); - edit->cell.text = NULL; - if (edit->invisible) - gtk_widget_unref (edit->invisible); - if (edit->tep) - gtk_object_unref (GTK_OBJECT(edit->tep)); - if (edit->primary_selection) - g_free(edit->primary_selection); - if (edit->clipboard_selection) - g_free(edit->clipboard_selection); - - g_free (edit); - - text_view->edit = NULL; - - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view); - ect_queue_redraw (text_view, text_view->edit->cell.view_col, text_view->edit->cell.row); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *text_view = g_new0 (ECellTextView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - text_view->cell_view.ecell = ecell; - text_view->cell_view.e_table_model = table_model; - text_view->cell_view.e_table_item_view = e_table_item_view; - - if (ect->font_name){ - GdkFont *f; - - f = gdk_fontset_load (ect->font_name); - text_view->font = f; - } - if (!text_view->font){ - text_view->font = GTK_WIDGET (canvas)->style->font; - - gdk_font_ref (text_view->font); - } - - text_view->canvas = canvas; - - text_view->xofs = 0.0; - text_view->yofs = 0.0; - - return (ECellView *)text_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->gc = gdk_gc_new (GTK_WIDGET (text_view->canvas)->window); - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - text_view->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - gdk_gc_unref (text_view->gc); - text_view->gc = NULL; - - if (text_view->font) - gdk_font_unref (text_view->font); - - if (text_view->stipple) - gdk_bitmap_unref (text_view->stipple); - - gdk_cursor_destroy (text_view->i_cursor); - gdk_cursor_destroy (text_view->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - /* New ECellText */ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *text_view = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GdkFont *font = text_view->font; - const int height = font->ascent + font->descent; - CellEdit *edit = text_view->edit; - gboolean edit_display = FALSE; - ECellTextLineBreaks *linebreaks; - - - if (edit){ - - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) - edit_display = TRUE; - fg_gc = canvas->style->fg_gc[edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - } else { - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if ( edit_display ) { - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - cell->width = x2 - x1; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - ypos = get_line_ypos (cell, lines); - ypos += font->ascent; - ypos -= edit->yofs_edit; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (cell, lines); - xpos -= edit->xofs_edit; - start_char = lines->text - cell->text; - end_char = start_char + lines->length; - sel_start = edit->selection_start; - sel_end = edit->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char); - sel_rect.y = ypos + y1 - font->ascent; - sel_rect.width = gdk_text_width (font, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = height; - gtk_paint_flat_box(canvas->style, - drawable, - edit->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - canvas, - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - sel_start - start_char); - gdk_draw_text (drawable, - font, - fg_gc, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char), - ypos + y1, - lines->text + sel_start - start_char, - sel_end - sel_start); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_end - start_char), - ypos + y1, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); - } - if (edit->selection_start == edit->selection_end && - edit->selection_start >= start_char && - edit->selection_start <= end_char && - edit->show_cursor) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - xpos + x1 + gdk_text_width (font, - lines->text, - sel_start - start_char), - ypos + y1 - font->ascent, - 1, - height); - } - } - unref_lines(cell); - } else { - - ECellTextLineBreaks *linebreaks; - CurrentCell cell; - build_current_cell ( &cell, text_view, model_col, view_col, row ); - - cell.width = x2 - x1; - - split_into_lines(&cell); - - linebreaks = cell.breaks; - lines = linebreaks->lines; - ypos = get_line_ypos(&cell, lines); - ypos += font->ascent; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (&cell, lines); - if ( ect->use_ellipsis && lines->ellipsis_length < lines->length) { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->ellipsis_length); - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1 + - lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } else { - gdk_draw_text (drawable, - font, - text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); - } - } - - ypos += height; - lines++; - unref_lines(&cell); - } - - gdk_gc_set_clip_rectangle (text_view->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); -#if 0 - /* Old ECellText */ - - int xoff; - gboolean edit_display = FALSE; - - /* - * Figure if this cell is being edited - */ - if (edit_display){ - CellEdit *edit = text_view->edit; - const char *text = gtk_entry_get_text (edit->entry); - GdkWChar *p, *text_wc = g_new (GdkWChar, strlen (text) + 1); - int text_wc_len = gdk_mbstowcs (text_wc, text, strlen (text)); - const int cursor_pos = GTK_EDITABLE (edit->entry)->current_pos; - const int left_len = gdk_text_width_wc (text_view->font, text_wc, cursor_pos); - - text_wc [text_wc_len] = 0; - /* - * Paint - */ - gdk_gc_set_foreground (text_view->gc, &w->style->base [GTK_STATE_NORMAL]); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, &w->style->text [GTK_STATE_NORMAL]); - - { - GdkGC *gc = text_view->gc; - const int y = y2 - font->descent - ((y2-y1-height)/2); - int px, i; - - /* - * Border - */ - x1 += 2; - x2--; - - px = x1; - - /* - * If the cursor is outside the visible range - * - * FIXME: we really want a better behaviour. - */ - if ((px + left_len) > x2) - px -= left_len - (x2-x1); - - /* - * Draw - */ - for (i = 0, p = text_wc; *p; p++, i++){ - gdk_draw_text_wc ( - drawable, font, gc, px, y, p, 1); - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - - px += gdk_text_width_wc (font, p, 1); - } - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - } - g_free (text_wc); - } else { - /* - * Regular cell - */ - GdkColor *background, *foreground; - int width; - - /* - * Border - */ - x1++; - x2--; - - /* - * Compute draw mode - */ - switch (ect->justify){ - case GTK_JUSTIFY_LEFT: - xoff = 1; - break; - - case GTK_JUSTIFY_RIGHT: - width = 1 + gdk_text_width (font, str, strlen (str)); - xoff = (x2 - x1) - width; - break; - - case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (font, str, strlen (str))) / 2; - break; - default: - xoff = 0; - g_warning ("Can not handle GTK_JUSTIFY_FILL"); - break; - } - - - if (selected){ - background = &w->style->bg [GTK_STATE_SELECTED]; - foreground = &w->style->text [GTK_STATE_SELECTED]; - } else { - background = &w->style->base [GTK_STATE_NORMAL]; - foreground = &w->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (text_view->gc, background); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, foreground); - - gdk_draw_string ( - drawable, font, text_view->gc, - x1 + xoff, - y2 - font->descent - ((y2-y1-height)/2), str); - } -#endif -} - -/* - * Selects the entire string - */ -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_assert (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen(text_view->edit->cell.text); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - - CurrentCell cell, *cellptr; - build_current_cell ( &cell, text_view, model_col, view_col, row ); - - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - cellptr = CURRENT_CELL(edit); - } else { - cellptr = &cell; - } - } else { - cellptr = &cell; - } - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (ect->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!edit_display) { -#if 0 - if ( edit->pointer_in ) { - if ( edit->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } -#endif - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - edit->xofs_edit = 0; - edit->yofs_edit = 0; - if (edit->timeout_id == 0) - edit->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text_view); - edit->timer = g_timer_new(); - g_timer_elapsed(edit->timer, &(edit->scroll_start)); - g_timer_start(edit->timer); - } - } else { - if ( ! edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->default_cursor); - edit->default_cursor_shown = TRUE; - } - if (edit->timeout_id) { - g_source_remove(edit->timeout_id); - edit->timeout_id = 0; - } - if (edit->timer) { - g_timer_stop(edit->timer); - g_timer_destroy(edit->timer); - edit->timer = NULL; - } - } - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (edit_display) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(edit); - return e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (edit_display) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(cellptr, button.x, button.y); - _get_tep(edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - } else if (ect->editable && event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - return 1; - } - break; - case GDK_MOTION_NOTIFY: - if (edit) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(cellptr, motion.x, motion.y); - _get_tep(edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->lastx = motion.x; - edit->lasty = motion.y; - edit->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: -#if 0 - edit->pointer_in = TRUE; -#endif - if (edit) { - if ( edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: -#if 0 - text_view->pointer_in = FALSE; -#endif - if (edit) { - if ( ! edit->default_cursor_shown ) { - gdk_window_set_cursor(canvas->window, text_view->default_cursor); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; -#if 0 - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); -#endif - else - return 0; - -#if 0 - switch (event->type){ - case GDK_BUTTON_PRESS: - /* - * Adjust for the border we use - */ - event->button.x++; - - printf ("Button pressed at %g %g\n", event->button.x, event->button.y); - if (text_view->edit){ - printf ("FIXME: Should handle click here\n"); - } else - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - break; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return TRUE; - } - - if (!text_view->edit){ - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - } - - gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event); - ect_queue_redraw (text_view, view_col, row); - break; -#endif -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CurrentCell cell; - int return_val; - - build_current_cell ( &cell, text_view, model_col, view_col, row ); - split_into_lines( &cell ); - - return_val = (text_view->font->ascent + text_view->font->descent) * cell.breaks->num_lines + TEXT_PAD; - - unref_lines( &cell ); - - return return_val; -} - -/* - * Callback: invoked when the user pressed "enter" on the GtkEntry - */ -static void -ect_entry_activate (GtkEntry *entry, ECellTextView *text_view) -{ - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - const char *str = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - CellEdit *edit; - - edit = g_new (CellEdit, 1); - text_view->edit = edit; - - build_current_cell ( CURRENT_CELL(edit), text_view, model_col, view_col, row ); - - edit->xofs_edit = 0.0; - edit->yofs_edit = 0.0; - - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - - edit->timeout_id = 0; - edit->timer = NULL; - - edit->lastx = 0; - edit->lasty = 0; - edit->last_state = 0; - - edit->scroll_start = 0; - edit->show_cursor = TRUE; - edit->button_down = FALSE; - - edit->tep = NULL; - - edit->has_selection = FALSE; - - edit->invisible = NULL; - edit->primary_selection = NULL; - edit->primary_length = 0; - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - - edit->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - edit->old_text = g_strdup (str); - edit->cell.text = g_strdup (str); - - ect_queue_redraw (text_view, view_col, row); - - return NULL; -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - if (text_view->edit){ - ect_accept_edits (text_view); - ect_stop_editing (text_view); - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_text_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - - parent_class = gtk_type_class (PARENT_TYPE); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) -{ - ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - - ect->ellipsis = NULL; - ect->use_ellipsis = FALSE; - - ect->editable = TRUE; - - ect->font_name = g_strdup (fontname); - ect->justify = justify; - - return (ECell *) ect; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (CurrentCell *cell, struct line *line) -{ - int x; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - - x = text_view->xofs + ect->x; - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - x += cell->width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (cell->width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_ypos (CurrentCell *cell, struct line *line) -{ - int y; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - - struct line *lines = linebreaks->lines; - - y = text_view->yofs + ect->y; - y += (line - lines) * (text_view->font->ascent + text_view->font->descent); - - return y; -} - -static void -_get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - ECellTextView *text_view = cell->text_view; - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - lines = linebreaks->lines; - - x = get_line_xpos (cell, lines); - y = get_line_ypos (cell, lines); - for (j = 0, lines = linebreaks->lines; j < linebreaks->num_lines; lines++, j++) { - if (lines->text > cell->text + position) - break; - y += font->ascent + font->descent; - } - lines --; - y -= font->descent; - - x += gdk_text_width (font, - lines->text, - position - (lines->text - cell->text)); - if ( (CellEdit *) cell == cell->text_view->edit ) { - x -= ((CellEdit *)cell)->xofs_edit; - y -= ((CellEdit *)cell)->yofs_edit; - } - if (xp) - *xp = x; - if (yp) - *yp = y; - unref_lines(cell); - } -} - -static gint -_get_position_from_xy (CurrentCell *cell, gint x, gint y) -{ - int i, j; - int xpos, ypos; - struct line *lines; - int return_val; - - ECellTextView *text_view = cell->text_view; - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - - if ( (CellEdit *) cell == cell->text_view->edit ) { - x += ((CellEdit *)cell)->xofs_edit; - y += ((CellEdit *)cell)->yofs_edit; - } - - ypos = get_line_ypos (cell, linebreaks->lines); - j = 0; - while (y > ypos) { - ypos += font->ascent + font->descent; - j ++; - } - j--; - if (j >= linebreaks->num_lines) - j = linebreaks->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - - lines += j; - xpos = get_line_xpos (cell, lines); - for(i = 0; i < lines->length; i++) { - int charwidth = gdk_text_width(font, - lines->text + i, - 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - - return_val = lines->text + i - cell->text; - - unref_lines(cell); - - return return_val; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - CurrentCell *cell = CURRENT_CELL(data); - ECellTextView *text_view = (ECellTextView *) data; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - CellEdit *edit = text_view->edit; - ECellTextLineBreaks *linebreaks = cell->breaks; - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(edit->timer, ¤t_time); - - if (edit->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > edit->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < edit->scroll_start) - scroll = TRUE; - } else { - if (current_time > edit->scroll_start + SCROLL_WAIT_TIME || - current_time < edit->scroll_start) - scroll = TRUE; - } - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > cell->width && - edit->xofs_edit < linebreaks->max_width - cell->width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > linebreaks->max_width - cell->width + 1) - edit->xofs_edit = linebreaks->max_width - cell->width + 1; - redraw = TRUE; - } - if (edit->lastx - ect->x < 0 && - edit->xofs_edit > 0) { - edit->xofs_edit -= 4; - if (edit->xofs_edit < 0) - edit->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = edit->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(cell, edit->lastx, edit->lasty); - _get_tep(edit); - e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!edit->show_cursor) - redraw = TRUE; - edit->show_cursor = TRUE; - } else { - if (edit->show_cursor) - redraw = TRUE; - edit->show_cursor = FALSE; - } -#if 0 - if (redraw) - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - return TRUE; -} - -static int -_get_position(ECellTextView *text_view, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return edit->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return strlen(cell->text); - - case E_TEP_START_OF_LINE: - for (i = edit->selection_end - 2; i > 0; i--) - if (cell->text[i] == '\n') { - i++; - break; - } - return i; - case E_TEP_END_OF_LINE: - length = strlen(cell->text); - for (i = edit->selection_end + 1; i < length; i++) - if (cell->text[i] == '\n') { - break; - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = strlen(cell->text); - i = edit->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = edit->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = strlen(cell->text); - for (i = edit->selection_end + 1; i < length; i++) - if (isspace(cell->text[i])) { - break; - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = edit->selection_end - 2; i > 0; i--) - if (isspace(cell->text[i])) { - i++; - break; - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(cell, edit->selection_end, &x, &y); - y += text_view->font->ascent + text_view->font->descent; - return _get_position_from_xy(cell, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(cell, edit->selection_end, &x, &y); - y -= text_view->font->ascent + text_view->font->descent; - return _get_position_from_xy(cell, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return edit->selection_end; - default: - return edit->selection_end; - } -} - -static void -_delete_selection(ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length = strlen(cell->text); - if (edit->selection_end == edit->selection_start) - return; - if (edit->selection_end < edit->selection_start) { - edit->selection_end ^= edit->selection_start; - edit->selection_start ^= edit->selection_end; - edit->selection_end ^= edit->selection_start; - } - memmove( cell->text + edit->selection_start, - cell->text + edit->selection_end, - length - edit->selection_end + 1 ); - length -= edit->selection_end - edit->selection_start; - edit->selection_end = edit->selection_start; -} - -static void -_insert(ECellTextView *text_view, char *string, int value) -{ - if (value > 0) { - char *temp; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length = strlen(cell->text); - temp = g_new(gchar, length + value + 1); - strncpy(temp, cell->text, edit->selection_start); - strncpy(temp + edit->selection_start, string, value); - strcpy(temp + edit->selection_start + value, cell->text + edit->selection_start); - g_free(cell->text); - cell->text = temp; - edit->selection_start += value; - edit->selection_end = edit->selection_start; - } -} - -static void -e_cell_text_view_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - CurrentCell *cell = CURRENT_CELL(edit); - ECellTextView *text_view = cell->text_view; - - gboolean change = FALSE; - gboolean redraw = FALSE; - - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - edit->selection_start = _get_position(text_view, command); - edit->selection_end = edit->selection_start; - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - break; - case E_TEP_SELECT: - edit->selection_end = _get_position(text_view, command); - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, GDK_SELECTION_PRIMARY, cell->text + sel_start, sel_end - sel_start); - } else if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - break; - case E_TEP_DELETE: - if (edit->selection_end == edit->selection_start) { - edit->selection_end = _get_position(text_view, command); - } - _delete_selection(text_view); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - - case E_TEP_INSERT: - if (edit->selection_end != edit->selection_start) { - _delete_selection(text_view); - } - _insert(text_view, command->string, command->value); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_COPY: - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, clipboard_atom, cell->text + sel_start, sel_end - sel_start); - } - if (edit->timer) { - g_timer_reset(edit->timer); - } - break; - case E_TEP_PASTE: - e_cell_text_view_get_selection (edit, clipboard_atom, command->time); - if (edit->timer) { - g_timer_reset(edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_GET_SELECTION: - e_cell_text_view_get_selection (edit, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - if (edit->timer) { - g_timer_reset(edit->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - edit->select_by_word = command->value; - break; - case E_TEP_GRAB: - case E_TEP_UNGRAB: -#if 0 - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text_view->i_cursor, - command->time); - break; - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; -#endif - case E_TEP_NOP: - break; - } - - if (!edit->button_down) { - int x; - int i; - struct line *lines; - ECellTextLineBreaks *linebreaks; - - split_into_lines(cell); - - linebreaks = cell->breaks; - - for (lines = linebreaks->lines, i = 0; i < linebreaks->num_lines ; i++, lines ++) { - if (lines->text - cell->text > edit->selection_end) { - break; - } - } - lines --; - x = gdk_text_width(text_view->font, - lines->text, - edit->selection_end - (lines->text - cell->text)); - - - if (x < edit->xofs_edit) { - edit->xofs_edit = x; - redraw = TRUE; - } - - if (2 + x - cell->width > edit->xofs_edit) { - edit->xofs_edit = 2 + x - cell->width; - redraw = TRUE; - } - unref_lines(cell); - } - - if ( redraw ) { - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif -} - -static void _invisible_destroy (GtkInvisible *invisible, - CellEdit *edit) -{ - edit->invisible = NULL; -} - -static GtkWidget *e_cell_text_view_get_invisible(CellEdit *edit) -{ - GtkWidget *invisible; - if (edit->invisible) { - invisible = edit->invisible; - } else { - invisible = gtk_invisible_new(); - edit->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - edit); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - edit); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (edit->primary_selection); - edit->primary_selection = NULL; - edit->primary_length = 0; - - edit->has_selection = FALSE; -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - - } else if (event->selection == clipboard_atom) { - g_free (edit->clipboard_selection); - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->primary_selection, edit->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->clipboard_selection, edit->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_cell_text_view_command(edit->tep, &command, edit); - } -} - -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_cell_text_view_get_invisible(edit); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (edit->primary_selection) { - g_free (edit->primary_selection); - } - edit->primary_selection = g_strndup(data, length); - edit->primary_length = length; - } else if (selection == clipboard_atom) { - if (edit->clipboard_selection) { - g_free (edit->clipboard_selection); - } - edit->clipboard_selection = g_strndup(data, length); - edit->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - edit->has_selection = successful; -} - -static void -e_cell_text_view_get_selection(CellEdit *edit, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_cell_text_view_get_invisible(edit); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -static void -_get_tep(CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (edit->tep)); - gtk_object_sink (GTK_OBJECT (edit->tep)); - gtk_signal_connect(GTK_OBJECT(edit->tep), - "command", - GTK_SIGNAL_FUNC(e_cell_text_view_command), - (gpointer) edit); - } -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (CurrentCell *cell) -{ - char *p; - struct line *lines; - int len; - - gchar *text = cell->text; - ECellTextLineBreaks *linebreaks = cell->breaks; - - if (! cell->breaks) { - cell->breaks = g_new(ECellTextLineBreaks, 1); - cell->breaks->ref_count = 1; - } else { - cell->breaks->ref_count ++; - return; - } - linebreaks = cell->breaks; - - /* Check if already split. */ - - linebreaks->lines = NULL; - linebreaks->num_lines = 0; - - if (!text) - return; - - /* First, count the number of lines */ - - for (p = text; *p; p++) - if (*p == '\n') - linebreaks->num_lines++; - - linebreaks->num_lines++; - - /* Allocate array of lines and calculate split positions */ - - linebreaks->lines = lines = g_new0 (struct line, linebreaks->num_lines); - len = 0; - - for (p = text; *p; p++) { - if (len == 0) - lines->text = p; - if (*p == '\n') { - lines->length = len; - lines++; - len = 0; - } else - len++; - } - - if (len == 0) - lines->text = p; - lines->length = len; - - calc_line_widths (cell); -} - -/* Free lines structure. */ -static void -unref_lines(CurrentCell *cell) -{ - if ( cell->breaks ) { - cell->breaks->ref_count --; - if ( cell->breaks->ref_count <= 0 ) { - g_free(cell->breaks->lines); - g_free(cell->breaks); - cell->breaks = NULL; - } - } -} - -static void -calc_ellipsis (ECellTextView *text_view) -{ - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - if (text_view->font) - text_view->ellipsis_width = - gdk_text_width (text_view->font, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (CurrentCell *cell) -{ - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - GdkFont *font = text_view->font; - ECellTextLineBreaks *linebreaks = cell->breaks; - struct line *lines; - int i; - int j; - - - - lines = linebreaks->lines; - linebreaks->max_width = 0; - - if (!lines) - return; - - for (i = 0; i < linebreaks->num_lines; i++) { - if (lines->length != 0) { - if (font) { - lines->width = gdk_text_width (font, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (ect->use_ellipsis && - ! text_view->edit && - lines->width > cell->width) { - if (font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (font, lines->text, j) + text_view->ellipsis_width <= cell->width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = gdk_text_width (font, lines->text, lines->ellipsis_length) + - text_view->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > linebreaks->max_width) - linebreaks->max_width = lines->width; - } else { - lines->width = 0; - lines->ellipsis_length = 0; - } - - lines++; - } -} - -static void -build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row) -{ - ECellView *ecell_view = (ECellView *) text_view; - cell->text_view = text_view; - cell->model_col = model_col; - cell->view_col = view_col; - cell->row = row; - cell->breaks = NULL; - cell->text = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - cell->width = e_table_header_get_column(((ETableItem *)ecell_view->e_table_item_view)->header, view_col)->width; -} diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h deleted file mode 100644 index 379ccf30a8..0000000000 --- a/widgets/table/e-cell-text.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellText - Text item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * Drawing and event handling from: - * - * EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ -#ifndef _E_CELL_TEXT_H_ -#define _E_CELL_TEXT_H_ - -#include -#include "e-cell.h" -#include "e-text-event-processor.h" - -#define E_CELL_TEXT_TYPE (e_cell_text_get_type ()) -#define E_CELL_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_TEXT_TYPE, ECellText)) -#define E_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TEXT_TYPE, ECellTextClass)) -#define E_IS_CELL_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_TEXT_TYPE)) -#define E_IS_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TEXT_TYPE)) - -typedef struct { - ECell parent; - - GtkJustification justify; - char *font_name; - - double x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - guint editable : 1; /* Item is editable */ -} ECellText; - -typedef struct { - ECellClass parent_class; -} ECellTextClass; - -GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); - -#endif /* _E_CELL_TEXT_H_ */ - - diff --git a/widgets/table/e-cell-toggle.c b/widgets/table/e-cell-toggle.c deleted file mode 100644 index 679d04a0ca..0000000000 --- a/widgets/table/e-cell-toggle.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * e-cell-toggle.c: Multi-state image toggle cell object. - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-cell-toggle.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#define PARENT_TYPE e_cell_get_type() - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; -} ECellToggleView; - -static ECellClass *parent_class; - -static void -etog_queue_redraw (ECellToggleView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * ECell::realize method - */ -static ECellView * -etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - toggle_view->cell_view.ecell = ecell; - toggle_view->cell_view.e_table_model = table_model; - toggle_view->cell_view.e_table_item_view = e_table_item_view; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -etog_kill_view (ECellView *ecell_view) -{ - g_free (ecell_view); -} - -static void -etog_realize (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - toggle_view->gc = gdk_gc_new (GTK_WIDGET (toggle_view->canvas)->window); -} - -/* - * ECell::unrealize method - */ -static void -etog_unrealize (ECellView *ecv) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecv; - - gdk_gc_unref (toggle_view->gc); - toggle_view->gc = NULL; -} - -/* - * ECell::draw method - */ -static void -etog_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - GdkPixbuf *image; - ArtPixBuf *art; - int x, y, width, height; - const int value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - if (value >= toggle->n_states){ - g_warning ("Value from the table model is %d, the states we support are [0..%d)\n", - value, toggle->n_states); - return; - } - - /* - * Paint the background - */ - gdk_draw_rectangle (drawable, GTK_WIDGET (toggle_view->canvas)->style->white_gc, TRUE, x1, y1, x2 - x1, y2 - y1); - - image = toggle->images [value]; - art = image->art_pixbuf; - - if ((x2 - x1) < art->width){ - x = x1; - width = x2 - x1; - } else { - x = x1 + ((x2 - x1) - art->width) / 2; - width = art->width; - } - - if ((y2 - y1) < art->height){ - y = y1; - height = y2 - y1; - } else { - y = y1 + ((y2 - y1) - art->height) / 2; - height = art->height; - } - - width = y2 - y1; - - if (image->art_pixbuf->has_alpha){ - GdkColor background; - guchar *buffer; - int alpha, ix, iy; - - buffer = g_malloc (art->rowstride * art->height * 3); - - background.red = 255; - background.green = 255; - background.blue = 255; - - for (iy = 0; iy < art->height; iy++){ - unsigned char *dest; - unsigned char *src; - - dest = buffer + (iy * art->rowstride); - src = art->pixels + (iy * art->rowstride); - - for (ix = 0; ix < art->width; ix++){ - alpha = src [3]; - if (alpha == 0){ - *dest++ = background.red; - *dest++ = background.green; - *dest++ = background.blue; - src += 3; - } else if (alpha == 255){ - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - } else { - *dest++ = (background.red + ((*src++ - background.red) * alpha + 0x80)) >> 8; - *dest++ = (background.green + ((*src++ - background.green) * alpha + 0x80)) >> 8; - *dest++ = (background.blue + ((*src++ - background.blue) * alpha + 0x80)) >> 8; - } - src++; - } - } - - gdk_draw_rgb_image_dithalign ( - drawable, toggle_view->gc, x, y, width, height, - GDK_RGB_DITHER_NORMAL, buffer, art->rowstride, 0, 0); - - g_free (buffer); - } else - gdk_draw_rgb_image_dithalign ( - drawable, toggle_view->gc, x, y, width, height, - GDK_RGB_DITHER_NORMAL, art->pixels, art->rowstride, 0, 0); -} - -static void -etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) -{ - ECell *ecell = toggle_view->cell_view.ecell; - ECellToggle *toggle = E_CELL_TOGGLE (ecell); - - if (value >= toggle->n_states) - value = 0; - - e_table_model_set_value_at (toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); - etog_queue_redraw (toggle_view, view_col, row); -} - -/* - * ECell::event method - */ -static gint -etog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - const int value = GPOINTER_TO_INT (_value); - - switch (event->type){ - case GDK_BUTTON_RELEASE: - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_space){ - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - } - return FALSE; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -etog_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - - return toggle->height; -} - -static void -etog_destroy (GtkObject *object) -{ - ECellToggle *etog = E_CELL_TOGGLE (object); - int i; - - for (i = 0; i < etog->n_states; i++) - gdk_pixbuf_unref (etog->images [i]); - - g_free (etog->images); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_toggle_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = etog_destroy; - - ecc->new_view = etog_new_view; - ecc->kill_view = etog_kill_view; - ecc->realize = etog_realize; - ecc->unrealize = etog_unrealize; - ecc->draw = etog_draw; - ecc->event = etog_event; - ecc->height = etog_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); - -void -e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf **images) -{ - int max_height = 0; - int i; - - etog->border = border; - etog->n_states = n_states; - - etog->images = g_new (GdkPixbuf *, n_states); - - for (i = 0; i < n_states; i++){ - etog->images [i] = images [i]; - gdk_pixbuf_ref (images [i]); - - if (images [i]->art_pixbuf->height > max_height) - max_height = images [i]->art_pixbuf->height; - } - - etog->height = max_height; -} - -ECell * -e_cell_toggle_new (int border, int n_states, GdkPixbuf **images) -{ - ECellToggle *etog = gtk_type_new (e_cell_toggle_get_type ()); - - e_cell_toggle_construct (etog, border, n_states, images); - - return (ECell *) etog; -} - - diff --git a/widgets/table/e-cell-toggle.h b/widgets/table/e-cell-toggle.h deleted file mode 100644 index d5773b454a..0000000000 --- a/widgets/table/e-cell-toggle.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _E_CELL_TOGGLE_H_ -#define _E_CELL_TOGGLE_H_ - -#include -#include -#include "e-cell.h" - -#define E_CELL_TOGGLE_TYPE (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(o) (GTK_CHECK_CAST ((o), E_CELL_TOGGLE_TYPE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TOGGLE_TYPE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(o) (GTK_CHECK_TYPE ((o), E_CELL_TOGGLE_TYPE)) -#define E_IS_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TOGGLE_TYPE)) - -typedef struct { - ECell parent; - - int border; - int n_states; - GdkPixbuf **images; - - int height; -} ECellToggle; - -typedef struct { - ECellClass parent_class; -} ECellToggleClass; - -GtkType e_cell_toggle_get_type (void); -ECell *e_cell_toggle_new (int border, int n_states, GdkPixbuf **images); -void e_cell_toggle_construct (ECellToggle *etog, int border, - int n_states, GdkPixbuf **images); - -#endif /* _E_CELL_TOGGLE_H_ */ - - diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c deleted file mode 100644 index f1345e8c6b..0000000000 --- a/widgets/table/e-cell.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * e-cell.c: base class for cell renderers in e-table - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include "e-cell.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE gtk_object_get_type() - -static ECellView * -ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return NULL; -} - -static void -ec_realize (ECellView *e_cell) -{ -} - -static void -ec_kill_view (ECellView *ecell_view) -{ -} - -static void -ec_unrealize (ECellView *e_cell) -{ -} - -static void -ec_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - g_error ("e-cell-draw invoked\n"); -} - -static gint -ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static gint -ec_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static void -ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2) -{ - ecell_view->focus_col = view_col; - ecell_view->focus_row = row; - ecell_view->focus_x1 = x1; - ecell_view->focus_y1 = y1; - ecell_view->focus_x2 = x2; - ecell_view->focus_y2 = y2; -} - -static void -ec_unfocus (ECellView *ecell_view) -{ - ecell_view->focus_col = -1; - ecell_view->focus_row = -1; - ecell_view->focus_x1 = -1; - ecell_view->focus_y1 = -1; - ecell_view->focus_x2 = -1; - ecell_view->focus_y2 = -1; -} - -static void * -ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context) -{ -} - -static void -e_cell_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = ec_realize; - ecc->unrealize = ec_unrealize; - ecc->new_view = ec_new_view; - ecc->kill_view = ec_kill_view; - ecc->draw = ec_draw; - ecc->event = ec_event; - ecc->focus = ec_focus; - ecc->unfocus = ec_unfocus; - ecc->height = ec_height; - ecc->enter_edit = ec_enter_edit; - ecc->leave_edit = ec_leave_edit; -} - -static void -e_cell_init (GtkObject *object) -{ -} - -E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE); - - -void -e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event ( - ecell_view, event, model_col, view_col, row); -} - -ECellView * -e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view ( - ecell, table_model, e_table_item_view); -} - -void -e_cell_view_realize (ECellView *ecell_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view); -} - -void -e_cell_kill_view (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view); -} - -void -e_cell_unrealize (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view); -} - -void -e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, int x1, int y1, int x2, int y2) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw ( - ecell_view, drawable, model_col, view_col, row, selected, x1, y1, x2, y2); -} - -int -e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( - ecell_view, model_col, view_col, row); -} - -void * -e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit ( - ecell_view, model_col, view_col, row); -} - -void -e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit ( - ecell_view, model_col, view_col, row, edit_context); -} diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h deleted file mode 100644 index 3c258689e4..0000000000 --- a/widgets/table/e-cell.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include -#include "e-table-model.h" - -#define E_CELL_TYPE (e_cell_get_type ()) -#define E_CELL(o) (GTK_CHECK_CAST ((o), E_CELL_TYPE, ECell)) -#define E_CELL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TYPE, ECellClass)) -#define E_IS_CELL(o) (GTK_CHECK_TYPE ((o), E_CELL_TYPE)) -#define E_IS_CELL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TYPE)) - -typedef struct _ECell ECell; -typedef struct _ECellView ECellView; - -struct _ECell { - GtkObject object; -}; - -struct _ECellView { - ECell *ecell; - ETableModel *e_table_model; - void *e_table_item_view; - - gint focus_x1, focus_y1, focus_x2, focus_y2; - gint focus_col, focus_row; -}; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -typedef struct { - GtkObjectClass parent_class; - - ECellView *(*new_view) (ECell *ecell, ETableModel *table_model, void *e_table_item_view); - void (*kill_view) (ECellView *ecell_view); - - void (*realize) (ECellView *ecell_view); - void (*unrealize) (ECellView *ecell_view); - - void (*draw) (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, - gboolean selected, int x1, int y1, int x2, int y2); - gint (*event) (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - void (*focus) (ECellView *ecell_view, int model_col, int view_col, - int row, int x1, int y1, int x2, int y2); - void (*unfocus) (ECellView *ecell_view); - int (*height) (ECellView *ecell_view, int model_col, int view_col, int row); - - void *(*enter_edit)(ECellView *ecell_view, int model_col, int view_col, int row); - void (*leave_edit)(ECellView *ecell_view, int model_col, int view_col, int row, void *context); -} ECellClass; - -GtkType e_cell_get_type (void); -ECellView *e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -void e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - -void e_cell_realize (ECellView *ecell_view); -void e_cell_unrealize (ECellView *ecell_view); - -void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2); -void e_cell_focus (ECellView *ecell_view, int model_col, int view_col, int row, - int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell_view); -int e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row); - -void *e_cell_enter_edit(ECellView *ecell_view, int model_col, int view_col, int row); -void e_cell_leave_edit(ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context); - -#endif /* _E_CELL_H_ */ diff --git a/widgets/table/e-table-col-dnd.h b/widgets/table/e-table-col-dnd.h deleted file mode 100644 index c1c26175c7..0000000000 --- a/widgets/table/e-table-col-dnd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -#endif /* _E_TABLE_COL_DND_H_ */ diff --git a/widgets/table/e-table-col.c b/widgets/table/e-table-col.c deleted file mode 100644 index 6f475158a5..0000000000 --- a/widgets/table/e-table-col.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * E-table-col.c: ETableCol implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include "e-table-col.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - -static void -etc_destroy (GtkObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - g_free (etc->text); - - (*parent_class->destroy)(object); -} - -static void -e_table_col_class_init (GtkObjectClass *object_class) -{ - parent_class = gtk_type_class (PARENT_TYPE); - object_class->destroy = etc_destroy; -} - -E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, NULL, PARENT_TYPE); - -ETableCol * -e_table_col_new (int col_idx, const char *text, int width, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (width >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (width >= min_width, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->col_idx = col_idx; - etc->text = g_strdup (text); - etc->width = width; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->selected = 0; - etc->resizeable = resizable; - - return etc; -} - - diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h deleted file mode 100644 index 54f03ae237..0000000000 --- a/widgets/table/e-table-col.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _E_TABLE_COL_H_ -#define _E_TABLE_COL_H_ - -#include "e-cell.h" - -#define E_TABLE_COL_TYPE (e_table_col_get_type ()) -#define E_TABLE_COL(o) (GTK_CHECK_CAST ((o), E_TABLE_COL_TYPE, ETableCol)) -#define E_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COL_TYPE, ETableColClass)) -#define E_IS_TABLE_COL(o) (GTK_CHECK_TYPE ((o), E_TABLE_COL_TYPE)) -#define E_IS_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COL_TYPE)) - -typedef struct _ETableCol ETableCol; - -/* - * Information about a single column - */ -struct _ETableCol { - GtkObject base; - char *text; - short width; - short min_width; - short x; - GCompareFunc compare; - unsigned int selected:1; - unsigned int resizeable:1; - int col_idx; - - ECell *ecell; -}; - -typedef struct { - GtkObjectClass parent_class; -} ETableColClass; - -GtkType e_table_col_get_type (void); -ETableCol *e_table_col_new (int col_idx, const char *text, - int width, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -void e_table_col_destroy (ETableCol *etc); - - -#endif /* _E_TABLE_COL_H_ */ - diff --git a/widgets/table/e-table-column-item.c b/widgets/table/e-table-column-item.c deleted file mode 100644 index 0616327a93..0000000000 --- a/widgets/table/e-table-column-item.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * E-table-column-view.c: A canvas view of the TableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include "e-table-column.h" -#include "e-table-column-view.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -static GnomeCanvasItemClass *etci_parent_class; - -enum { - ARG_0, - ARG_TABLE_COLUMN -}; - -static void -etci_destroy (GtkObject *object) -{ - ETableColumnItem *etcv = E_TABLE_COLUMN_VIEW (object); - - gtk_object_unref (GTK_OBJECT (etcv)); - - if (GTK_OBJECT_CLASS (etcv_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etcv_parent_class)->destroy) (object); -} - -static void -etci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update)(item, affine, clip_path, flags); - - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableColumnItem *etci; - int v; - - item = GNOME_CANVAS_ITEM (o); - etci = E_TABLE_COLUMN_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_COLUMN: - etci->etci = GTK_VALUE_POINTER (*arg); - break; - } - etci_update (item, NULL, NULL, 0); -} - -static void -etci_realize (GnomeCanvasItem *item) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - GdkWindow *window; - GdkColor c; - - if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - etci->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (etci->gc, &c); - - etci->normal_cursor = gdk_cursor_new (GDK_ARROW); -} - -static void -etci_unrealize (GnomeCanvasItem *item) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - - gdk_gc_unref (etci->gc); - etci->gc = NULL; - - gdk_cursor_destroy (etci->change_cursor); - etci->change_cursor = NULL; - - gdk_cursor_destroy (etci->normal_cursor); - etci->normal_cursor = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize)(item); -} - -static void -etci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int width, int height) -{ - ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_column_count (etci->etc); - int x2 = x1 + width; - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *col = e_table_column_get_column (etci->etc, col); - const int col_width = col->width; - - if (x1 > total + col_width) - continue; - - if (x2 < total) - return; - - gc = canvas->style->bg_gc [GTK_STATE_ACTIVE]; - gdk_draw_rectangle (drawble, gc, TRUE, - gtk_draw_shadow (canvas->style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x, y, width, height - } -} - -static double -etci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = *item; - return 0.0; -} - -static void -etci_event (GnomeCanvasItem *item, GdkEvent *e) -{ - switch (e->type){ - default: - return FALSE; - } - return TRUE; -} - -static void -etci_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - object_class->destroy = etci_destroy; - object_class->set_arg = etci_set_arg; - - item_class->update = etci_update; - item_class->realize = etci_realize; - item_class->unrealize = etci_unrealize; - item_class->draw = etci_draw; - item_class->point = etci_point; - item_class->event = etci_event; - - gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_COLUMN); -} - -static void -etci_init (GnomeCanvasItem *item) -{ - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - -GtkType -e_table_column_view_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumnItem", - sizeof (ETableColumnItem), - sizeof (ETableColumnItemClass), - (GtkClassInitFunc) etci_class_init, - (GtkObjectInitFunc) etci_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - - - diff --git a/widgets/table/e-table-column-item.h b/widgets/table/e-table-column-item.h deleted file mode 100644 index fd38681a73..0000000000 --- a/widgets/table/e-table-column-item.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _E_TABLE_COLUMN_VIEW_H -#defein _E_TABLE_COLUMN_VIEW_H - -#include "e-table-column.h" - -typedef struct { - GnomeCanvasItem parent; - ETableColumn *etc; - - GdkGC *gc; - GdkCursor *change_cursor, *normal_cursor; -} ETableColumnView; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableColumnViewClass; - -GtkType e_table_column_item_get_type (void); - -#endif /* _E_TABLE_COLUMN_VIEW_H */ diff --git a/widgets/table/e-table-column-model.h b/widgets/table/e-table-column-model.h deleted file mode 100644 index 043dd783ca..0000000000 --- a/widgets/table/e-table-column-model.h +++ /dev/null @@ -1,5 +0,0 @@ - -class ETableColumnModel { - virtual void add_column (ETableCol *et) = 0; - virtual ETableCol *get_column (int column); - virtual diff --git a/widgets/table/e-table-column.c b/widgets/table/e-table-column.c deleted file mode 100644 index d17a285321..0000000000 --- a/widgets/table/e-table-column.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-table-column.c: TableColumn implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include "e-table-column.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint etc_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_column_parent_class; - -static void -e_table_column_destroy (GtkObject *object) -{ - ETableColumn *etc = E_TABLE_COLUMN (object); - const int cols = etc->col_count; - - /* - * Destroy listeners - */ - for (l = etc->listeners; l; l = l->next) - g_free (l->data); - g_slist_free (etc->listeners); - etc->listeners = NULL; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++) - e_table_column_remove (etc, i); - - if (e_table_column_parent_class->destroy) - e_table_column_parent_class->destroy (object); -} - -static void -e_table_column_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_column_destroy; - - e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ())); - - etc_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - etc_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etc_signals, LAST_SIGNAL); -} - -GtkType -e_table_column_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumn", - sizeof (ETableColumn), - sizeof (ETableColumnClass), - (GtkClassInitFunc) e_table_column_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -static void -etc_do_insert (ETableColumn *etc, int pos, ETableCol *val) -{ - memcpy (&etc->columns [pos+1], &etc->columns [pos], - sizeof (ETableCol *) * (etc->col_count - pos)); - etc->columns [pos] = val; -} - -void -e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos) -{ - ETableCol **new_ptr; - - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (tc != NULL); - g_return_if_fail (pos >= 0 && pos < etc->col_count); - - if (pos == -1) - pos = etc->col_count; - etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1)); - etc_do_insert (etc, pos, tc); - etc->col_count++; - - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_column_get_column (ETableColumn *etc, int column) -{ - g_return_val_if_fail (etc != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL); - - if (column < 0) - return NULL; - - if (column >= etc->col_count) - return NULL; - - return etc->columns [column]; -} - -int -e_table_column_count (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - return etc->col_count; -} - -int -e_table_column_index (ETableColumn *etc, const char *identifier) -{ - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - for (i = 0; i < etc->col_count; i++){ - ETableCol *tc = etc->columns [i]; - - if (strcmp (i->id, identifier) == 0) - return i; - } - - return -1; -} - -int -e_table_column_get_index_at (ETableColumn *etc, int x_offset) -{ - int i, total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - total = 0; - for (i = 0; i < etc->col_count; i++){ - total += etc->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_column_get_columns (ETableColumn *etc) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - ret = g_new (ETableCol *, etc->col_count + 1); - memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count); - ret [etc->col_count] = NULL; - - return ret; -} - -gboolean -e_table_column_selection_ok (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE); - - return etc->selectable; -} - -int -ve_table_column_get_selected (ETableColumn *etc) -{ - int i; - int selected = 0; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - for (i = 0; i < etc->col_count; i++){ - if (etc->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_column_total_width (ETableColumn *etc) -{ - int total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - total = 0; - for (i = 0; i < etc->col_count; i++) - total += etc->columns [i].width; - - return total; -} - -static void -etc_do_remove (ETableColumn *etc, int idx) -{ - memcpy (&etc->columns [idx], &etc->columns [idx+1], - sizeof (ETableCol *) * etc->col_count - idx); - etc->col_count--; -} - -void -e_table_column_move (ETableColumn *etc, int source_index, int target_index) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < etc->col_count); - g_return_if_fail (target_index < etc->col_count); - - old = etc->columns [source_index]; - etc_do_remove (etc, source_index); - etc_do_insert (etc, target_index, old); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_remove (ETableColumn *etc, int idx) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - - etc_do_remove (etc, idx); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection); -{ -} - -void -e_table_column_set_size (ETableColumn *etc, int idx, int size) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - g_return_if_fail (size > 0); - - etc->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx); -} diff --git a/widgets/table/e-table-group.c b/widgets/table/e-table-group.c deleted file mode 100644 index 5652d2623f..0000000000 --- a/widgets/table/e-table-group.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@gnu.org() - * - * Copyright 1999, Helix Code, Inc. - */ - -#include -#include -#include "e-table-group.h" -#include "e-table-item.h" -#include -#include "e-util/e-util.h" - -#define TITLE_HEIGHT 16 -#define GROUP_INDENT 10 - -#define PARENT_TYPE gnome_canvas_group_get_type () - -static GnomeCanvasGroupClass *etg_parent_class; - -enum { - HEIGHT_CHANGED, - LAST_SIGNAL -}; - -static gint etg_signals [LAST_SIGNAL] = { 0, }; - -static void -etg_destroy (GtkObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - - GTK_OBJECT_CLASS (etg_parent_class)->destroy (object); -} - -static void -etg_dim (ETableGroup *etg, int *width, int *height) -{ - GSList *l; - - *width = *height = 0; - - for (l = etg->children; l; l = l->next){ - GnomeCanvasItem *child = l->data; - - *height += child->y2 - child->y1; - *width += child->x2 - child->x1; - } - - if (!etg->transparent){ - *height += TITLE_HEIGHT; - *width += GROUP_INDENT; - } -} - -void -e_table_group_construct (GnomeCanvasGroup *parent, ETableGroup *etg, - ETableCol *ecol, gboolean open, - gboolean transparent) -{ - gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL); - - etg->ecol = ecol; - etg->open = open; - etg->transparent = transparent; - - etg_dim (etg, &etg->width, &etg->height); - - if (!etg->transparent) - etg->rect = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (etg), - gnome_canvas_rect_get_type (), - "fill_color", "gray", - "outline_color", "gray20", - "x1", 0.0, - "y1", 0.0, - "x2", (double) etg->width, - "y2", (double) etg->height, - NULL); - -#if 0 - /* - * Reparent the child into our space. - */ - gnome_canvas_item_reparent (child, GNOME_CANVAS_GROUP (etg)); - - gnome_canvas_item_set ( - child, - "x", (double) GROUP_INDENT, - "y", (double) TITLE_HEIGHT, - NULL); - - /* - * Force dimension computation - */ - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->update ( - GNOME_CANVAS_ITEM (etg), NULL, NULL, GNOME_CANVAS_UPDATE_REQUESTED); -#endif -} - -GnomeCanvasItem * -e_table_group_new (GnomeCanvasGroup *parent, ETableCol *ecol, - gboolean open, gboolean transparent) -{ - ETableGroup *etg; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (ecol != NULL, NULL); - - etg = gtk_type_new (e_table_group_get_type ()); - - e_table_group_construct (parent, etg, ecol, open, transparent); - - return GNOME_CANVAS_ITEM (etg); -} - -static void -etg_relayout (GnomeCanvasItem *eti, ETableGroup *etg) -{ - GSList *l; - int height = etg->transparent ? 0 : GROUP_INDENT; - gboolean move = FALSE; - - printf ("Relaying out\n"); - - for (l = etg->children; l->next; l = l->next){ - GnomeCanvasItem *child = l->data; - - height += child->y2 - child->y1; - - if (child == eti) - move = TRUE; - - if (move){ - printf ("Moving item %p\n", child); - gnome_canvas_item_set ( - child, - "y", (double) height, - NULL); - } - } - if (height != etg->height){ - etg->height = height; - gtk_signal_emit (GTK_OBJECT (etg), etg_signals [HEIGHT_CHANGED]); - } -} - -void -e_table_group_add (ETableGroup *etg, GnomeCanvasItem *item) -{ - double x1, y1, x2, y2; - - g_return_if_fail (etg != NULL); - g_return_if_fail (item != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - - etg->children = g_slist_append (etg->children, item); - - GNOME_CANVAS_ITEM_CLASS (GTK_OBJECT (etg)->klass)->bounds (etg, &x1, &y1, &x2, &y2); - - if (GTK_OBJECT (etg)->flags & GNOME_CANVAS_ITEM_REALIZED){ - GSList *l; - int height = etg->transparent ? 0 : TITLE_HEIGHT; - int x = etg->transparent ? 0 : GROUP_INDENT; - - for (l = etg->children; l->next; l = l->next){ - GnomeCanvasItem *child = l->data; - - height += child->y2 - child->y1; - - printf ("Height\n"); - if (E_IS_TABLE_ITEM (item)){ - printf (" Item: "); - } else { - printf (" Group: "); - } - printf ("%d\n", child->y2-child->y1); - } - - gnome_canvas_item_set ( - item, - "y", (double) height, - "x", (double) x, - NULL); - - - if (E_IS_TABLE_ITEM (item)){ - - printf ("Table item! ---------\n"); - gtk_signal_connect (GTK_OBJECT (item), "height_changed", - GTK_SIGNAL_FUNC (etg_relayout), etg); - } - } -} - -static void -etg_realize (GnomeCanvasItem *item) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - GSList *l; - int height = 0; - - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->realize (item); - - for (l = etg->children; l; l = l->next){ - GnomeCanvasItem *child = l->data; - - printf ("During realization for child %p -> %d\n", child, height); - gnome_canvas_item_set ( - child, - "y", (double) height, - NULL); - - height += child->y2 - child->y1; - } -} - -static void -etg_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - - GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->update (item, affine, clip_path, flags); - - if (!etg->transparent){ - int current_width, current_height; - - etg_dim (etg, ¤t_width, ¤t_height); - - if ((current_height != etg->height) || (current_width != etg->width)){ - etg->width = current_width; - etg->height = current_height; - - gnome_canvas_item_set ( - etg->rect, - "x1", 0.0, - "y1", 0.0, - "x2", (double) etg->width, - "y2", (double) etg->height, - NULL); - } - } -} - -static void -etg_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - object_class->destroy = etg_destroy; - - item_class->realize = etg_realize; - item_class->update = etg_update; - - etg_parent_class = gtk_type_class (PARENT_TYPE); - - etg_signals [HEIGHT_CHANGED] = - gtk_signal_new ("height_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, height_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, etg_signals, LAST_SIGNAL); - -} - -E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE); - - - diff --git a/widgets/table/e-table-group.h b/widgets/table/e-table-group.h deleted file mode 100644 index 468d5dd794..0000000000 --- a/widgets/table/e-table-group.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -#include -#include "e-table-model.h" -#include "e-table-header.h" - -#define E_TABLE_GROUP_TYPE (e_table_group_get_type ()) -#define E_TABLE_GROUP(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_TYPE, ETableGroup)) -#define E_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_TYPE, ETableGroupClass)) -#define E_IS_TABLE_GROUP(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_TYPE)) -#define E_IS_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_TYPE)) - -typedef struct { - GnomeCanvasGroup group; - - /* - * The ETableCol used to group this set - */ - ETableCol *ecol; - - /* - * The canvas rectangle that contains the children - */ - GnomeCanvasItem *rect; - - /* - * Dimensions of the ETableGroup - */ - int width, height; - - /* - * State: the ETableGroup is open or closed - */ - guint open:1; - - /* - * Whether we should add indentation and open/close markers, - * or if we just act as containers of subtables. - */ - guint transparent:1; - - /* - * List of GnomeCanvasItems we stack - */ - GSList *children; -} ETableGroup; - -typedef struct { - GnomeCanvasGroupClass parent_class; - void (*height_changed) (ETableGroup *etg); -} ETableGroupClass; - -GnomeCanvasItem *e_table_group_new (GnomeCanvasGroup *parent, ETableCol *ecol, - gboolean open, gboolean transparent); -void e_table_group_construct (GnomeCanvasGroup *parent, ETableGroup *etg, - ETableCol *ecol, gboolean open, gboolean transparent); - -void e_table_group_add (ETableGroup *etg, GnomeCanvasItem *child); - -GtkType e_table_group_get_type (void); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c deleted file mode 100644 index e8f73fc432..0000000000 --- a/widgets/table/e-table-header-item.c +++ /dev/null @@ -1,795 +0,0 @@ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include -#include -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col-dnd.h" - -#include "add-col.xpm" -#include "remove-col.xpm" - -/* Padding above and below of the string in the header display */ -#define PADDING 4 - -/* Defines the tolerance for proximity of the column division to the cursor position */ -#define TOLERANCE 2 - -#define ETHI_RESIZING(x) ((x)->resize_col != -1) - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *ethi_parent_class; - -/* - * DnD icons - */ -static GdkColormap *dnd_colormap; -static GdkPixmap *remove_col_pixmap, *remove_col_mask; -static GdkPixmap *add_col_pixmap, *add_col_mask; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_X, - ARG_TABLE_Y, - ARG_TABLE_FONTSET -}; - -static GtkTargetEntry ethi_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, -}; - -static GtkTargetEntry ethi_drop_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, -}; - -static void -ethi_destroy (GtkObject *object) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - gtk_object_unref (GTK_OBJECT (ethi->eth)); - - if (GTK_OBJECT_CLASS (ethi_parent_class)->destroy) - (*GTK_OBJECT_CLASS (ethi_parent_class)->destroy) (object); -} - -static void -ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update)(item, affine, clip_path, flags); - - item->x1 = ethi->x1; - item->y1 = ethi->y1; - item->x2 = ethi->x1 + ethi->width; - item->y2 = ethi->y1 + ethi->height; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -ethi_font_load (ETableHeaderItem *ethi, char *font) -{ - if (ethi->font) - gdk_font_unref (ethi->font); - - ethi->font = gdk_fontset_load (font); - if (ethi->font == NULL) - ethi->font = gdk_font_load ("fixed"); - - ethi->height = ethi->font->ascent + ethi->font->descent + PADDING; -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GtkObject *header; - - if (!ethi->eth) - return; - - header = GTK_OBJECT (ethi->eth); - gtk_signal_disconnect (header, ethi->structure_change_id); - gtk_signal_disconnect (header, ethi->dimension_change_id); - - gtk_object_unref (header); - ethi->eth = NULL; - ethi->width = 0; -} - -static void -structure_changed (ETableHeader *header, ETableHeaderItem *ethi) -{ - ethi->width = e_table_header_total_width (header); - - ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi) -{ - ethi->width = e_table_header_total_width (header); - - ethi_update (GNOME_CANVAS_ITEM (ethi), NULL, NULL, 0); -} - -static void -ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header) -{ - ethi->eth = header; - gtk_object_ref (GTK_OBJECT (ethi->eth)); - ethi->width = e_table_header_total_width (header); - - ethi->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), ethi); - ethi->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), ethi); -} - -static void -ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (o); - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_X: - ethi->x1 = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_Y: - ethi->y1 = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_FONTSET: - ethi_font_load (ethi, GTK_VALUE_STRING (*arg)); - break; - - } - ethi_update (item, NULL, NULL, 0); -} - -static int -ethi_find_col_by_x (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = ethi->x1; - int col; - - if (x < x1) - return -1; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) - return col; - - x1 += ecol->width; - } - return -1; -} - -static void -ethi_remove_drop_marker (ETableHeaderItem *ethi) -{ - if (ethi->drag_mark == -1) - return; - - ethi->drag_mark = -1; - gtk_object_destroy (GTK_OBJECT (ethi->drag_mark_item)); - ethi->drag_mark_item = NULL; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, int col) -{ - GnomeCanvasPoints *points; - int x; - - if (ethi->drag_mark == col) - return; - - if (ethi->drag_mark_item) - gtk_object_destroy (GTK_OBJECT (ethi->drag_mark_item)); - - ethi->drag_mark = col; - - ethi->drag_mark_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_group_get_type (), - "x", 0, - "y", 0, - NULL); - - points = gnome_canvas_points_new (3); - - x = e_table_header_col_diff (ethi->eth, 0, col); - - points->coords [0] = ethi->x1 + x - 5; - points->coords [1] = ethi->y1; - points->coords [2] = points->coords [0] + 10; - points->coords [3] = points->coords [1]; - points->coords [4] = ethi->x1 + x; - points->coords [5] = ethi->y1 + 5; - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (ethi->drag_mark_item), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", "red", - NULL); - - points->coords [0] --; - points->coords [1] += ethi->height - 1; - points->coords [3] = points->coords [1]; - points->coords [5] = points->coords [1] - 6; - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (ethi->drag_mark_item), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", "red", - NULL); - - gnome_canvas_points_unref (points); -} - -#define gray50_width 2 -#define gray50_height 2 -static char gray50_bits [] = { - 0x02, 0x01, }; - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - double x1; - - if (ethi->remove_item) - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - - if (!ethi->stipple) - ethi->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - - x1 = ethi->x1 + (double) e_table_header_col_diff (ethi->eth, 0, ethi->drag_col); - ethi->remove_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_rect_get_type (), - "x1", x1 + 1, - "y1", (double) ethi->y1 + 1, - "x2", (double) x1 + e_table_header_col_diff (ethi->eth, ethi->drag_col, ethi->drag_col+1) - 2, - "y2", (double) ethi->y1 + ethi->height - 2, - "fill_color", "red", - "fill_stipple", ethi->stipple, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - ethi->remove_item = NULL; -} - -static gboolean -ethi_drag_motion (GtkObject *canvas, GdkDragContext *context, - gint x, gint y, guint time, - ETableHeaderItem *ethi) -{ - - if ((x >= ethi->x1) && (x <= (ethi->x1 + ethi->width)) && - (y >= ethi->y1) && (y <= (ethi->y1 + ethi->height))){ - int col; - - col = ethi_find_col_by_x (ethi, x); - - if (col != -1){ - ethi_remove_destroy_marker (ethi); - ethi_add_drop_marker (ethi, col); - } else { - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); - } - } else { - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); - } - - gdk_drag_status (context, context->suggested_action, time); - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, GdkDragContext *context, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; -} - -static void -ethi_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - ethi_add_destroy_marker (ethi); -} - -static void -ethi_realize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GdkWindow *window; - GdkColor c; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - ethi->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (ethi->gc, &c); - - ethi->normal_cursor = gdk_cursor_new (GDK_ARROW); - - if (!ethi->font){ - g_warning ("Font had not been set for this ETableHeader"); - ethi_font_load (ethi, "fixed"); - } - - /* - * Now, configure DnD - */ - gtk_drag_dest_set (GTK_WIDGET (item->canvas), GTK_DEST_DEFAULT_ALL, - ethi_drop_types, ELEMENTS (ethi_drop_types), - GDK_ACTION_MOVE); - - ethi->drag_motion_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_motion", - GTK_SIGNAL_FUNC (ethi_drag_motion), ethi); - - ethi->drag_leave_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_leave", - GTK_SIGNAL_FUNC (ethi_drag_leave), ethi); - - ethi->drag_end_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (ethi_drag_end), ethi); -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - gdk_gc_unref (ethi->gc); - ethi->gc = NULL; - - gdk_cursor_destroy (ethi->normal_cursor); - ethi->normal_cursor = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_motion_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_end_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_leave_id); - - if (ethi->stipple){ - gdk_bitmap_unref (ethi->stipple); - ethi->stipple = NULL; - } - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableHeaderItem *ethi, ETableCol *col, - GdkDrawable *drawable, GdkGC *gc, GtkStyle *style, - int x, int y, int width, int height) -{ - GdkRectangle clip; - int xtra; - - gdk_draw_rectangle ( - drawable, gc, TRUE, - x + 1, y + 1, width - 2, height -2); - - gtk_draw_shadow ( - style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x , y, width, height); - - clip.x = x + 2; - clip.y = y + 2; - clip.width = width - 4; - clip.height = ethi->height; - - gdk_gc_set_clip_rectangle (ethi->gc, &clip); - - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (ethi->font, col->text))/2; - - if (xtra < 0) - xtra = 0; - - /* Skip over border */ - x += xtra + 2; - - gdk_draw_text ( - drawable, ethi->font, - ethi->gc, x, y + ethi->height - PADDING, - col->text, strlen (col->text)); -} - -static void -ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_header_count (ethi->eth); - int x1, x2; - int col; - -#if 0 - printf ("My coords are: %g %g %g %g\n", - item->x1, item->y1, item->x2, item->y2); -#endif - x1 = x2 = ethi->x1; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - int col_width; - - if (col == ethi->resize_col) - col_width = ethi->resize_width; - else - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - gc = GTK_WIDGET (canvas)->style->bg_gc [GTK_STATE_ACTIVE]; - - draw_button (ethi, ecol, drawable, gc, - GTK_WIDGET (canvas)->style, - x1 - x, ethi->y1 - y, col_width, ethi->height); - } -} - -static double -ethi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * is_pointer_on_division: - * - * Returns whether @pos is a column header division; If @the_total is not NULL, - * then the actual position is returned here. If @return_ecol is not NULL, - * then the ETableCol that actually contains this point is returned here - */ -static gboolean -is_pointer_on_division (ETableHeaderItem *ethi, int pos, int *the_total, int *return_col) -{ - const int cols = e_table_header_count (ethi->eth); - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - total += ecol->width; - - if ((total - TOLERANCE < pos ) && (pos < total + TOLERANCE)){ - if (return_col) - *return_col = col; - if (the_total) - *the_total = total; - - return TRUE; - } - - if (total > pos + TOLERANCE) - return FALSE; - } - - return FALSE; -} - -#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y) - -static void -set_cursor (ETableHeaderItem *ethi, int pos) -{ - GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - - /* We might be invoked before we are realized */ - if (!canvas->window) - return; - - if (is_pointer_on_division (ethi, pos, NULL, NULL)) - e_cursor_set (canvas->window, E_CURSOR_SIZE_X); - else - e_cursor_set (canvas->window, E_CURSOR_ARROW); -} - -static void -ethi_request_redraw (ETableHeaderItem *ethi) -{ - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (ethi)->canvas; - - /* - * request a redraw - */ - gnome_canvas_request_redraw ( - canvas, ethi->x1, ethi->y1, ethi->x1 + ethi->width, ethi->x1 + ethi->height); -} - -static void -ethi_end_resize (ETableHeaderItem *ethi, int new_size) -{ - e_table_header_set_size (ethi->eth, ethi->resize_col, new_size); - - ethi->resize_col = -1; - ethi_request_redraw (ethi); -} - -static gboolean -ethi_maybe_start_drag (ETableHeaderItem *ethi, GdkEventMotion *event) -{ - if (!ethi->maybe_drag) - return FALSE; - - if (MAX (abs (ethi->click_x - event->x), - abs (ethi->click_y - event->y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - GtkTargetList *list; - GdkDragContext *context; - - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - if (ethi->drag_col == -1) - return; - - list = gtk_target_list_new (ethi_drag_types, ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - ethi->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static int -ethi_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gboolean resizing = ETHI_RESIZING (ethi); - int x, y, start, col; - - switch (e->type){ - case GDK_ENTER_NOTIFY: - convert (canvas, e->crossing.x, e->crossing.y, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); - break; - - case GDK_MOTION_NOTIFY: - convert (canvas, e->motion.x, e->motion.y, &x, &y); - if (resizing){ - int new_width; - - if (ethi->resize_guide == NULL){ - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - gnome_canvas_item_grab (item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - e_cursor_get (E_CURSOR_SIZE_X), - e->button.time); - } - - new_width = x - ethi->resize_start_pos; - if (new_width <= 0) - break; - - if (new_width < ethi->resize_min_width) - break; - - ethi_request_redraw (ethi); - - ethi->resize_width = new_width; - e_table_header_set_size (ethi->eth, ethi->resize_col, ethi->resize_width); - - ethi_request_redraw (ethi); - } else if (ethi_maybe_start_drag (ethi, &e->motion)){ - ethi_start_drag (ethi, e); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - convert (canvas, e->button.x, e->button.y, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col)){ - ETableCol *ecol; - - /* - * Record the important bits. - * - * By setting resize_pos to a non -1 value, - * we know that we are being resized (used in the - * other event handlers). - */ - ecol = e_table_header_get_column (ethi->eth, col); - - if (!ecol->resizeable) - break; - ethi->resize_col = col; - ethi->resize_width = ecol->width; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - } else { - if (e->button.button == 1){ - ethi->click_x = e->button.x; - ethi->click_y = e->button.y; - ethi->maybe_drag = TRUE; - } - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (e->button.button != 1) - break; - break; - - case GDK_BUTTON_RELEASE: { - gboolean needs_ungrab = FALSE; - - if (ethi->resize_col != -1){ - needs_ungrab = (ethi->resize_guide != NULL); - ethi_end_resize (ethi, ethi->resize_width); - } - if (needs_ungrab) - gnome_canvas_item_ungrab (item, e->button.time); - - ethi->maybe_drag = FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - ethi_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = ethi_destroy; - object_class->set_arg = ethi_set_arg; - - item_class->update = ethi_update; - item_class->realize = ethi_realize; - item_class->unrealize = ethi_unrealize; - item_class->draw = ethi_draw; - item_class->point = ethi_point; - item_class->event = ethi_event; - - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::x", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_TABLE_X); - gtk_object_add_arg_type ("ETableHeaderItem::y", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_TABLE_Y); - gtk_object_add_arg_type ("ETableHeaderItem::fontset", GTK_TYPE_STRING, - GTK_ARG_WRITABLE, ARG_TABLE_FONTSET); - - /* - * Create our pixmaps for DnD - */ - dnd_colormap = gtk_widget_get_default_colormap (); - remove_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &remove_col_mask, NULL, remove_col_xpm); - - add_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &add_col_mask, NULL, add_col_xpm); -} - -static void -ethi_init (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - ethi->resize_col = -1; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - ethi->drag_col = -1; - ethi->drag_mark = -1; -} - -GtkType -e_table_header_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeaderItem", - sizeof (ETableHeaderItem), - sizeof (ETableHeaderItemClass), - (GtkClassInitFunc) ethi_class_init, - (GtkObjectInitFunc) ethi_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h deleted file mode 100644 index 5522d24fae..0000000000 --- a/widgets/table/e-table-header-item.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include -#include "e-table-header.h" - -#define E_TABLE_HEADER_ITEM_TYPE (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkGC *gc; - GdkCursor *change_cursor, *normal_cursor; - - short x1, y1, height, width; - GdkFont *font; - - /* - * Used during resizing; Could be shorts - */ - int resize_col; - int resize_width; - int resize_start_pos; - int resize_min_width; - - GtkObject *resize_guide; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag:1; - guint dnd_ready:1; - int click_x, click_y; - int drag_col, drag_mark; - guint drag_motion_id, drag_end_id, drag_leave_id; - GnomeCanvasItem *drag_mark_item, *remove_item; - GdkBitmap *stipple; -} ETableHeaderItem; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableHeaderItemClass; - -GtkType e_table_header_item_get_type (void); - -#endif /* _E_TABLE_HEADER_ITEM_H_ */ diff --git a/widgets/table/e-table-header.c b/widgets/table/e-table-header.c deleted file mode 100644 index 7c54bd936e..0000000000 --- a/widgets/table/e-table-header.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * E-table-col-head.c: TableColHead implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include -#include -#include -#include "e-table-header.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint eth_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_header_parent_class; - -static void -e_table_header_destroy (GtkObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const int cols = eth->col_count; - int i; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++){ - e_table_header_remove (eth, i); - } - - if (e_table_header_parent_class->destroy) - e_table_header_parent_class->destroy (object); -} - -static void -e_table_header_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_header_destroy; - - e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ())); - - eth_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - eth_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL); -} - -GtkType -e_table_header_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeader", - sizeof (ETableHeader), - sizeof (ETableHeaderClass), - (GtkClassInitFunc) e_table_header_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -ETableHeader * -e_table_header_new (void) -{ - ETableHeader *eth; - - eth = gtk_type_new (e_table_header_get_type ()); - - return eth; -} - -static void -eth_do_insert (ETableHeader *eth, int pos, ETableCol *val) -{ - memcpy (ð->columns [pos+1], ð->columns [pos], - sizeof (ETableCol *) * (eth->col_count - pos)); - eth->columns [pos] = val; -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - int i; - int x = 0; - - for (i = 0; i < eth->col_count; i++){ - ETableCol *etc = eth->columns [i]; - - etc->x = x; - x += etc->width; - } -} - -void -e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (tc != NULL); - g_return_if_fail (E_IS_TABLE_COL (tc)); - g_return_if_fail (pos >= -1 && pos <= eth->col_count); - - if (pos == -1) - pos = eth->col_count; - eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1)); - - /* - * We are the primary owners of the column - */ - gtk_object_ref (GTK_OBJECT (tc)); - gtk_object_sink (GTK_OBJECT (tc)); - - eth_do_insert (eth, pos, tc); - eth->col_count++; - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -ETableCol * -e_table_header_get_column (ETableHeader *eth, int column) -{ - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - if (column < 0) - return NULL; - - if (column >= eth->col_count) - return NULL; - - return eth->columns [column]; -} - -int -e_table_header_count (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - return eth->col_count; -} - -int -e_table_header_index (ETableHeader *eth, int col) -{ - g_return_val_if_fail (eth != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), -1); - g_return_val_if_fail (col < eth->col_count, -1); - - return eth->columns [col]->col_idx; -} - -int -e_table_header_get_index_at (ETableHeader *eth, int x_offset) -{ - int i, total; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++){ - total += eth->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - ret = g_new (ETableCol *, eth->col_count + 1); - memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count); - ret [eth->col_count] = NULL; - - return ret; -} - -gboolean -e_table_header_selection_ok (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), FALSE); - - return eth->selectable; -} - -int -e_table_header_get_selected (ETableHeader *eth) -{ - int i; - int selected = 0; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - for (i = 0; i < eth->col_count; i++){ - if (eth->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_header_total_width (ETableHeader *eth) -{ - int total, i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++) - total += eth->columns [i]->width; - - return total; -} - -static void -eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref) -{ - if (do_unref) - gtk_object_unref (GTK_OBJECT (eth->columns [idx])); - - memcpy (ð->columns [idx], ð->columns [idx+1], - sizeof (ETableCol *) * eth->col_count - idx); - eth->col_count--; -} - -void -e_table_header_move (ETableHeader *eth, int source_index, int target_index) -{ - ETableCol *old; - - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < eth->col_count); - g_return_if_fail (target_index < eth->col_count); - - old = eth->columns [source_index]; - eth_do_remove (eth, source_index, FALSE); - eth_do_insert (eth, target_index, old); - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -void -e_table_header_remove (ETableHeader *eth, int idx) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - eth_do_remove (eth, idx, TRUE); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} - -void -e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection) -{ -} - -void -e_table_header_set_size (ETableHeader *eth, int idx, int size) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - g_return_if_fail (size > 0); - - eth->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE], idx); -} - -int -e_table_header_col_diff (ETableHeader *eth, int start_col, int end_col) -{ - int total, col; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - { - const int max_col = eth->col_count; - - total = 0; - for (col = start_col; col < end_col; col++){ - - if (col == max_col) - break; - total += eth->columns [col]->width; - } - } - - return total; -} diff --git a/widgets/table/e-table-header.h b/widgets/table/e-table-header.h deleted file mode 100644 index 96e65fdc2f..0000000000 --- a/widgets/table/e-table-header.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include -#include -#include "e-table-col.h" - -typedef struct _ETableHeader ETableHeader; - -#define E_TABLE_HEADER_TYPE (e_table_header_get_type ()) -#define E_TABLE_HEADER(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_TYPE, ETableHeader)) -#define E_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_TYPE, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_TYPE)) -#define E_IS_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_TYPE)) - -/* - * A Columnar header. - */ -struct _ETableHeader { - GtkObject base; - - int col_count; - ETableCol **columns; - gboolean selectable; -}; - -typedef struct { - GtkObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, int col); -} ETableHeaderClass; - -GtkType e_table_header_get_type (void); -ETableHeader *e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, int pos); -ETableCol * e_table_header_get_column (ETableHeader *eth, - int column); -int e_table_header_count (ETableHeader *eth); -int e_table_header_index (ETableHeader *eth, - int col); -int e_table_header_get_index_at (ETableHeader *eth, - int x_offset); -ETableCol **e_table_header_get_columns (ETableHeader *eth); -gboolean e_table_header_selection_ok (ETableHeader *eth); -int e_table_header_get_selected (ETableHeader *eth); -int e_table_header_total_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - int source_index, - int target_index); -void e_table_header_remove (ETableHeader *eth, int idx); -void e_table_header_set_size (ETableHeader *eth, int idx, int size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); - -int e_table_header_col_diff (ETableHeader *eth, - int start_col, int end_col); - -GList *e_table_header_get_selected_indexes(ETableHeader *eth); - - -#endif /* _E_TABLE_HEADER_H_ */ - diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c deleted file mode 100644 index 8455ed4824..0000000000 --- a/widgets/table/e-table-item.c +++ /dev/null @@ -1,1316 +0,0 @@ -/* - * E-table-item.c: A GnomeCanvasItem that is a view of an ETableModel. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - * - * TODO: - * Add a border to the thing, so that focusing works properly. - * - */ -#include -#include -#include -#include -#include -#include "e-table-item.h" -#include "e-cell.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define FOCUSED_BORDER 2 - -static GnomeCanvasItemClass *eti_parent_class; - -enum { - ROW_SELECTION, - HEIGHT_CHANGED, - LAST_SIGNAL -}; - -static gint eti_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_MODEL, - ARG_TABLE_X, - ARG_TABLE_Y, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_MODE_SPREADSHEET, - ARG_LENGHT_THRESHOLD -}; - -static gboolean -eti_editing (ETableItem *eti) -{ - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -/* - * During realization, we have to invoke the per-ecell realize routine - * (On our current setup, we have one e-cell per column. - * - * We might want to optimize this to only realize the unique e-cells: - * ie, a strings-only table, uses the same e-cell for every column, and - * we might want to avoid realizing each e-cell. - */ -static void -eti_realize_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++) - e_cell_view_realize (eti->cell_views [i], eti); - eti->cell_views_realized = 1; -} - -static void eti_compute_height (ETableItem *eti); - -static void -eti_attach_cell_views (ETableItem *eti) -{ - int i; - - g_assert (eti->header); - g_assert (eti->table_model); - - /* - * Now realize the various ECells - */ - eti->n_cells = eti->cols; - eti->cell_views = g_new (ECellView *, eti->n_cells); - - for (i = 0; i < eti->n_cells; i++){ - ETableCol *col = e_table_header_get_column (eti->header, i); - - eti->cell_views [i] = e_cell_new_view (col->ecell, eti->table_model, eti); - } - - eti_compute_height (eti); -} - -/* - * During unrealization: we invoke every e-cell (one per column in the current - * setup) to dispose all X resources allocated - */ -static void -eti_unrealize_cell_views (ETableItem *eti) -{ - int i; - - if (eti->cell_views_realized == 0) - return; - - for (i = 0; i < eti->n_cells; i++) - e_cell_unrealize (eti->cell_views [i]); - eti->cell_views_realized = 0; -} - -static void -eti_detach_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++){ - e_cell_kill_view (eti->cell_views [i]); - eti->cell_views [i] = NULL; - } - - g_free (eti->cell_views); - eti->cell_views = NULL; - eti->n_cells = 0; -} - -static void -eti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - double i2c [6]; - ArtPoint c1, c2, i1, i2; - ETableItem *eti = E_TABLE_ITEM (item); - - gnome_canvas_item_i2c_affine (item, i2c); - i1.x = eti->x1; - i1.y = eti->y1; - i2.x = eti->x1 + eti->width; - i2.y = eti->y1 + eti->height; - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; -} - - -/* - * GnomeCanvasItem::update method - */ -static void -eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, affine, clip_path, flags); - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_model (ETableItem *eti) -{ - if (!eti->table_model) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_change_id); - gtk_object_unref (GTK_OBJECT (eti->table_model)); - - eti->table_model_change_id = 0; - eti->table_model_row_change_id = 0; - eti->table_model = NULL; -} - -/* - * eti_remove_header_model: - * - * Invoked to release the header model associated with this ETableItem - */ -static void -eti_remove_header_model (ETableItem *eti) -{ - if (!eti->header) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_structure_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_dim_change_id); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - gtk_object_unref (GTK_OBJECT (eti->header)); - - - eti->header_structure_change_id = 0; - eti->header_dim_change_id = 0; - eti->header = NULL; -} - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height (ETableItem *eti, int row) -{ - const int cols = e_table_header_count (eti->header); - int col; - int h, max_h; - - g_assert (eti->cell_views); - - max_h = 0; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - h = e_cell_height (eti->cell_views [col], ecol->col_idx, col, row); - - if (h > max_h) - max_h = h; - } - return max_h; -} - -/* - * eti_get_height: - * - * Returns the height of the ETableItem. - * - * The ETableItem might compute the whole height by asking every row its - * size. There is a special mode (designed to work when there are too - * many rows in the table that performing the previous step could take - * too long) set by the ETableItem->length_threshold that would determine - * when the height is computed by using the first row as the size for - * every other row in the ETableItem. - */ -static int -eti_get_height (ETableItem *eti) -{ - const int rows = eti->rows; - int row; - int height; - - if (rows == 0) - return 0; - - if (eti->length_threshold != -1){ - if (rows > eti->length_threshold){ - height = (eti_row_height (eti, 0) + 1) * rows; - - /* - * 1 pixel at the top - */ - return height + 1; - } - } - - height = 1; - for (row = 0; row < rows; row++) - height += eti_row_height (eti, row) + 1; - - return height; -} - -static void -eti_compute_height (ETableItem *eti) -{ - int new_height = eti_get_height (eti); - - if (new_height != eti->height){ - double x1, y1, x2, y2; - printf ("Emitting!\n"); - - eti->height = new_height; - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [HEIGHT_CHANGED]); - } -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ -static void -eti_table_model_changed (ETableModel *table_model, ETableItem *eti) -{ - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->cell_views) - eti_compute_height (eti); - - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); -} - -static void -eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - ArtDRect rect; - double i2c [6]; - - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - gnome_canvas_item_i2c_affine (item, i2c); - art_drect_affine_transform (&rect, &rect, i2c); - - gnome_canvas_request_redraw (item->canvas, rect.x0, rect.y0, rect.x1, rect.y1); -} - -/* - * eti_request_redraw: - * - * Queues a canvas redraw for the entire ETableItem. - */ -static void -eti_request_redraw (ETableItem *eti) -{ - eti_item_region_redraw (eti, eti->x1, eti->y1, eti->x1 + eti->width + 1, eti->y1 + eti->height + 1); -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -static int -eti_row_diff (ETableItem *eti, int start_row, int end_row) -{ - int row, total; - - total = 0; - - for (row = start_row; row < end_row; row++) - total += eti_row_height (eti, row) + 1; - - return total; -} - -/* - * eti_request_region_redraw: - * - * Request a canvas redraw on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to redraw the first cell). - * - * The @border argument is a number of pixels around the region that should also be queued - * for redraw. This is typically used by the focus routines to queue a redraw for the - * border as well. - */ -static void -eti_request_region_redraw (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int border) -{ - int x1, y1, width, height; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - width = e_table_header_col_diff (eti->header, start_col, end_col + 1); - height = eti_row_diff (eti, start_row, end_row + 1); - - eti_item_region_redraw (eti, eti->x1 + x1 - border, - eti->y1 + y1 - border, - eti->x1 + x1 + width + 1 + border, - eti->y1 + y1 + height + 1 + border); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size){ - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols, row, 0); -} - -void -e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int border; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if ((start_col == eti->focused_col) || - (end_col == eti->focused_col) || - (start_row == eti->focused_row) || - (end_row == eti->focused_row)) - border = 2; - else - border = 0; - - eti_request_region_redraw (eti, start_col, start_row, end_col, end_row, border); -} - -static void -eti_add_table_model (ETableItem *eti, ETableModel *table_model) -{ - g_assert (eti->table_model == NULL); - - eti->table_model = table_model; - gtk_object_ref (GTK_OBJECT (eti->table_model)); - - eti->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_changed", - GTK_SIGNAL_FUNC (eti_table_model_changed), eti); - - eti->table_model_row_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_changed", - GTK_SIGNAL_FUNC (eti_table_model_row_changed), eti); - - if (eti->header){ - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - - eti_table_model_changed (table_model, eti); -} - -static void -eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti) -{ - eti_request_redraw (eti); - - eti->width = e_table_header_total_width (eti->header); - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - eti_request_redraw (eti); -} - -static void -eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) -{ - eti_request_redraw (eti); - - eti->cols = e_table_header_count (eti->header); - eti->width = e_table_header_total_width (eti->header); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - eti_realize_cell_views (eti); - } else { - if (eti->table_model){ - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - } - - eti_update (GNOME_CANVAS_ITEM (eti), NULL, NULL, 0); - - eti_request_redraw (eti); -} - -static void -eti_add_header_model (ETableItem *eti, ETableHeader *header) -{ - g_assert (eti->header == NULL); - - eti->header = header; - gtk_object_ref (GTK_OBJECT (header)); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC (eti_header_dim_changed), eti); - - eti->header_structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC (eti_header_structure_changed), eti); -} - -/* - * GtkObject::destroy method - */ -static void -eti_destroy (GtkObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - - g_slist_free (eti->selection); - - if (GTK_OBJECT_CLASS (eti_parent_class)->destroy) - (*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object); -} - -static void -eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_TABLE_X: - eti->x1 = GTK_VALUE_DOUBLE (*arg); - break; - - case ARG_TABLE_Y: - eti->y1 = GTK_VALUE_DOUBLE (*arg); - break; - - case ARG_LENGHT_THRESHOLD: - eti->length_threshold = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_DRAW_GRID: - eti->draw_grid = GTK_VALUE_BOOL (*arg); - break; - - case ARG_TABLE_DRAW_FOCUS: - eti->draw_focus = GTK_VALUE_BOOL (*arg); - break; - - case ARG_MODE_SPREADSHEET: - eti->mode_spreadsheet = GTK_VALUE_BOOL (*arg); - break; - } - eti_update (item, NULL, NULL, 0); -} - -static void -eti_init (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - eti->focused_col = -1; - eti->focused_row = -1; - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - - eti->length_threshold = -1; - eti->renderers_can_change_size = 0; - - eti->selection_mode = GTK_SELECTION_SINGLE; -} - -#define gray50_width 2 -#define gray50_height 2 -static const char gray50_bits[] = { - 0x02, 0x01, }; - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - /* - * Gdk Resource allocation - */ - window = canvas_widget->window; - - eti->fill_gc = canvas_widget->style->white_gc; - gdk_gc_ref (canvas_widget->style->white_gc); - - eti->grid_gc = gdk_gc_new (window); -#if 0 - /* This sets it to gray */ -/* gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); */ -#else - gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->black); -#endif - eti->focus_gc = gdk_gc_new (window); - gdk_gc_set_foreground (eti->focus_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); - gdk_gc_set_background (eti->focus_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); - eti->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - gdk_gc_set_ts_origin (eti->focus_gc, 0, 0); - gdk_gc_set_stipple (eti->focus_gc, eti->stipple); - gdk_gc_set_fill (eti->focus_gc, GDK_OPAQUE_STIPPLED); - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - eti_compute_height (eti); - - eti_update (item, NULL, NULL, 0); -} - -static void -eti_unrealize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - gdk_gc_unref (eti->fill_gc); - eti->fill_gc = NULL; - gdk_gc_unref (eti->grid_gc); - eti->grid_gc = NULL; - gdk_gc_unref (eti->focus_gc); - eti->focus_gc = NULL; - gdk_bitmap_unref (eti->stipple); - eti->stipple = NULL; - - eti_unrealize_cell_views (eti); - - eti->height = 0; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); -} - -static void -eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const int rows = eti->rows; - const int cols = eti->cols; - int row, col, y1, y2; - int first_col, last_col, x_offset; - int first_row, last_row, y_offset, yd; - int x1, x2; - int f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - double i2c [6]; - ArtPoint eti_base, eti_base_item; - - /* - * Clear the background - */ -#if 0 - gdk_draw_rectangle ( - drawable, eti->fill_gc, TRUE, - eti->x1 - x, eti->y1 - y, eti->width, eti->height); -#endif - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_affine (item, i2c); - eti_base_item.x = eti->x1; - eti_base_item.y = eti->y1; - art_affine_point (&eti_base, &eti_base_item, i2c); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - last_col = x_offset = 0; - x1 = x2 = floor (eti_base.x); - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - x2 = x1 + ecol->width; - - if (x1 > (x + width)) - break; - if (x2 < x) - continue; - if (first_col == -1){ - x_offset = x1 - x; - first_col = col; - } - } - last_col = col; - - /* - * Nothing to paint - */ - if (first_col == -1) - return; - - /* - * Compute row span. - */ - first_row = -1; - y_offset = 0; - y1 = y2 = floor (eti_base.y) + 1; - for (row = 0; row < rows; row++, y1 = y2){ - - y2 += eti_row_height (eti, row) + 1; - - if (y1 > y + height) - break; - - if (y2 < y) - continue; - - if (first_row == -1){ - y_offset = y1 - y; - first_row = row; - } - } - last_row = row; - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->draw_grid && first_row == 0){ - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - } - yd++; - - for (row = first_row; row < last_row; row++){ - int xd, height; - gboolean selected; - - height = eti_row_height (eti, row); - - xd = x_offset; -/* printf ("paint: %d %d\n", yd, yd + height); */ - - selected = g_slist_find (eti->selection, GINT_TO_POINTER (row)) != NULL; - - for (col = first_col; col < last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - ECellView *ecell_view = eti->cell_views [col]; - - e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, selected, - xd, yd, xd + ecol->width, yd + height); - - if (col == eti->focused_col && row == eti->focused_row){ - f_x1 = xd; - f_x2 = xd + ecol->width; - f_y1 = yd; - f_y2 = yd + height; - f_found = TRUE; - } - - xd += ecol->width; - } - yd += height; - - if (eti->draw_grid) - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - yd++; - } - - if (eti->draw_grid){ - int xd = x_offset; - - for (col = first_col; col <= last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - gdk_draw_line ( - drawable, eti->grid_gc, - xd, y_offset, xd, yd - 1); - - /* - * This looks wierd, but it is to draw the last line - */ - if (ecol) - xd += ecol->width; - } - } - - /* - * Draw focus - */ - if (f_found && eti->draw_focus){ - - if (!eti_editing (eti)) - gdk_draw_rectangle ( - drawable, eti->focus_gc, FALSE, - f_x1 + 1, f_y1, f_x2 - f_x1 - 2, f_y2 - f_y1 - 1); - } -} - -static double -eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - - return 0.0; -} - -static gboolean -find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, double *x1_res, double *y1_res) -{ - const int cols = eti->cols; - const int rows = eti->rows; - gdouble x1, y1, x2, y2; - int col, row; - - /* FIXME: this routine is inneficient, fix later */ - - x -= eti->x1; - y -= eti->y1; - - x1 = 0; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - if (x < x1) - return FALSE; - - x2 = x1 + ecol->width; - - if (x > x2) - continue; - - *col_res = col; - if (x1_res) - *x1_res = x - x1; - break; - } - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2){ - if (y < y1) - return FALSE; - - y2 += eti_row_height (eti, row) + 1; - - if (y > y2) - continue; - - *row_res = row; - if (y1_res) - *y1_res = y - y1; - break; - } - - return TRUE; -} - -static void -eti_cursor_move_left (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col - 1, eti->focused_row); -} - -static void -eti_cursor_move_right (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col + 1, eti->focused_row); -} - -static void -eti_cursor_move_up (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col, eti->focused_row - 1); -} - -static void -eti_cursor_move_down (ETableItem *eti) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->focused_col, eti->focused_row + 1); -} - -static int -eti_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - ETableCol *ecol; - - switch (e->type){ - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: { - double x1, y1; - int col, row; - - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - if (eti->focused_row == row && eti->focused_col == col){ - - ecol = e_table_header_get_column (eti->header, col); - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, ecol->col_idx, col, row); - } else { - /* - * Focus the cell, and select the row - */ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, col, row); - e_table_item_select_row (eti, row); - } - break; - } - - case GDK_MOTION_NOTIFY: { - int col, row; - double x1, y1; - - gnome_canvas_item_w2i (item, &e->motion.x, &e->motion.y); - - if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1)) - return TRUE; - - if (eti->focused_row == row && eti->focused_col == col){ - ecol = e_table_header_get_column (eti->header, col); - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->motion.x = x1; - e->motion.y = y1; - - e_cell_event (ecell_view, e, ecol->col_idx, col, row); - } - break; - } - - case GDK_KEY_PRESS: - if (eti->focused_col == -1) - return FALSE; - - switch (e->key.keyval){ - case GDK_Left: - if (!eti->mode_spreadsheet && eti_editing (eti)) - break; - - if (eti->focused_col > 0) - eti_cursor_move_left (eti); - - return TRUE; - - case GDK_Right: - if (!eti->mode_spreadsheet && eti_editing (eti)) - break; - - if ((eti->focused_col + 1) < eti->cols) - eti_cursor_move_right (eti); - return TRUE; - - case GDK_Up: - if (eti->focused_row > 0) - eti_cursor_move_up (eti); - return TRUE; - - case GDK_Down: - if ((eti->focused_row + 1) < eti->rows) - eti_cursor_move_down (eti); - - return TRUE; - - case GDK_Tab: - if ((e->key.state & GDK_SHIFT_MASK) != 0){ - /* shift tab */ - if (eti->focused_col > 0) - eti_cursor_move_left (eti); - else if (eti->focused_row > 0){ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, eti->cols - 1, eti->focused_row - 1); - } else { - /* FIXME: request focus leave backward */ - } - } else { - if ((eti->focused_col + 1) < eti->cols) - eti_cursor_move_right (eti); - else if ((eti->focused_row + 1) < eti->rows){ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, 0, eti->rows - 1); - } else { - /* FIXME: request focus leave forward */ - } - } - break; - - default: - if (!eti_editing (eti)){ - if ((e->key.state & (GDK_MOD1_MASK | GDK_CONTROL_MASK)) != 0) - return 0; - - if (!(e->key.keyval >= 0x20 && e->key.keyval <= 0xff)) - return 0; - } - } - - ecol = e_table_header_get_column (eti->header, eti->focused_col); - ecell_view = eti->cell_views [eti->focused_col]; - e_cell_event (ecell_view, e, ecol->col_idx, eti->focused_col, eti->focused_row); - break; - - case GDK_KEY_RELEASE: - if (eti->focused_col == -1) - return FALSE; - - if (eti_editing (eti)){ - ecell_view = eti->cell_views [eti->editing_col]; - ecol = e_table_header_get_column (eti->header, eti->editing_col); - e_cell_event (ecell_view, e, ecol->col_idx, eti->editing_col, eti->editing_row); - } - break; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ETableItem::row_selection method - */ -static void -eti_row_selection (ETableItem *eti, int row, gboolean selected) -{ - eti_request_region_redraw (eti, 0, row, eti->cols - 1, row, 0); - - if (selected) - eti->selection = g_slist_prepend (eti->selection, GINT_TO_POINTER (row)); - else - eti->selection = g_slist_remove (eti->selection, GINT_TO_POINTER (row)); - -} - -static void -eti_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableItemClass *eti_class = (ETableItemClass *) object_class; - - eti_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = eti_destroy; - object_class->set_arg = eti_set_arg; - - item_class->update = eti_update; - item_class->realize = eti_realize; - item_class->unrealize = eti_unrealize; - item_class->draw = eti_draw; - item_class->point = eti_point; - item_class->event = eti_event; - item_class->bounds = eti_bounds; - - eti_class->row_selection = eti_row_selection; - - gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_POINTER, - GTK_ARG_WRITABLE, ARG_TABLE_MODEL); - gtk_object_add_arg_type ("ETableItem::x", GTK_TYPE_DOUBLE, - GTK_ARG_WRITABLE, ARG_TABLE_X); - gtk_object_add_arg_type ("ETableItem::y", GTK_TYPE_DOUBLE, - GTK_ARG_WRITABLE, ARG_TABLE_Y); - gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableItem::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableItem::spreadsheet", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_MODE_SPREADSHEET); - - eti_signals [ROW_SELECTION] = - gtk_signal_new ("row_selection", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, row_selection), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - eti_signals [HEIGHT_CHANGED] = - gtk_signal_new ("height_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, height_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, eti_signals, LAST_SIGNAL); - -} - -GtkType -e_table_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableItem", - sizeof (ETableItem), - sizeof (ETableItemClass), - (GtkClassInitFunc) eti_class_init, - (GtkObjectInitFunc) eti_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_item_focus (ETableItem *eti, int col, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti->focused_col != -1) - e_table_item_unfocus (eti); - - eti->focused_col = col; - eti->focused_row = row; - - eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER); - - /* - * make sure we have the Gtk Focus - */ - gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti)); -} - -void -e_table_item_unfocus (ETableItem *eti) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti->focused_row == -1) - return; - - { - const int col = eti->focused_col; - const int row = eti->focused_row; - - eti_request_region_redraw (eti, col, row, col, row, FOCUSED_BORDER); - } - eti->focused_col = -1; - eti->focused_row = -1; -} - -const GSList * -e_table_item_get_selection (ETableItem *eti) -{ - g_return_val_if_fail (eti != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), NULL); - - return eti->selection; -} - -GtkSelectionMode -e_table_item_get_selection_mode (ETableItem *eti) -{ - g_return_val_if_fail (eti != NULL, GTK_SELECTION_SINGLE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), GTK_SELECTION_SINGLE); - - return eti->selection_mode; -} - -void -e_table_item_set_selection_mode (ETableItem *eti, GtkSelectionMode selection_mode) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (selection_mode == GTK_SELECTION_BROWSE || - selection_mode == GTK_SELECTION_EXTENDED){ - g_error ("GTK_SELECTION_BROWSE and GTK_SELECTION_EXTENDED are not implemented"); - } - - eti->selection_mode = selection_mode; -} - -gboolean -e_table_item_is_row_selected (ETableItem *eti, int row) -{ - g_return_val_if_fail (eti != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), FALSE); - - if (g_slist_find (eti->selection, GINT_TO_POINTER (row))) - return TRUE; - else - return FALSE; -} - -void -e_table_item_unselect_row (ETableItem *eti, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (e_table_item_is_row_selected (eti, row)){ - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - row, 0); - } -} - -void -e_table_item_select_row (ETableItem *eti, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - switch (eti->selection_mode){ - case GTK_SELECTION_SINGLE: - if (eti->selection){ - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GPOINTER_TO_INT (eti->selection->data), 0); - } - g_slist_free (eti->selection); - eti->selection = NULL; - - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GINT_TO_POINTER (row), 1); - break; - - case GTK_SELECTION_MULTIPLE: - if (g_slist_find (eti->selection, GINT_TO_POINTER (row))) - return; - gtk_signal_emit ( - GTK_OBJECT (eti), eti_signals [ROW_SELECTION], - GINT_TO_POINTER (row), 1); - break; - - default: - - } -} - -void -e_table_item_enter_edit (ETableItem *eti, int col, int row) -{ - ETableCol *ecol; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - eti->editing_col = col; - eti->editing_row = row; - - ecol = e_table_header_get_column (eti->header, col); - eti->edit_ctx = e_cell_enter_edit (eti->cell_views [col], ecol->col_idx, col, row); -} - -void -e_table_item_leave_edit (ETableItem *eti) -{ - ETableCol *ecol; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (!eti_editing (eti)) - return; - - ecol = e_table_header_get_column (eti->header, eti->editing_col); - e_cell_leave_edit ( - eti->cell_views [eti->editing_col], - ecol->col_idx, eti->editing_col, - eti->editing_row, eti->edit_ctx); - eti->editing_col = -1; - eti->editing_row = -1; - eti->edit_ctx = NULL; -} - diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h deleted file mode 100644 index f19819f2fc..0000000000 --- a/widgets/table/e-table-item.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include -#include "e-table-model.h" -#include "e-table-header.h" - -#define E_TABLE_ITEM_TYPE (e_table_item_get_type ()) -#define E_TABLE_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_ITEM_TYPE, ETableItem)) -#define E_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ITEM_TYPE, ETableItemClass)) -#define E_IS_TABLE_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_ITEM_TYPE)) -#define E_IS_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - int x1, y1; - int width, height; - - int cols, rows; - - /* - * Ids for the signals we connect to - */ - int header_dim_change_id; - int header_structure_change_id; - int table_model_change_id; - int table_model_row_change_id; - - GdkGC *fill_gc; - GdkGC *grid_gc; - GdkGC *focus_gc; - GdkBitmap *stipple; - - unsigned int draw_grid:1; - unsigned int draw_focus:1; - unsigned int mode_spreadsheet:1; - unsigned int renderers_can_change_size:1; - unsigned int cell_views_realized:1; - - int focused_col, focused_row; - - /* - * Realized views, per column - */ - ECellView **cell_views; - int n_cells; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - int length_threshold; - - GSList *selection; - GtkSelectionMode selection_mode; - - /* - * During edition - */ - int editing_col, editing_row; - void *edit_ctx; -} ETableItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - void (*row_selection) (ETableItem *eti, int row, gboolean selected); - void (*height_changed) (ETableItem *eti); -} ETableItemClass; - -GtkType e_table_item_get_type (void); - -/* - * Focus - */ -void e_table_item_focus (ETableItem *eti, int col, int row); -void e_table_item_unfocus (ETableItem *eti); - -/* - * Selection - */ -void e_table_item_select_row (ETableItem *e_table_Item, int row); -void e_table_item_unselect_row (ETableItem *e_table_Item, int row); - -/* - * Handling the selection - */ -const GSList*e_table_item_get_selection (ETableItem *e_table_Item); - -GtkSelectionMode e_table_item_get_selection_mode (ETableItem *e_table_Item); -void e_table_item_set_selection_mode (ETableItem *e_table_Item, - GtkSelectionMode selection_mode); -gboolean e_table_item_is_row_selected (ETableItem *e_table_Item, - int row); - -void e_table_item_leave_edit (ETableItem *eti); -void e_table_item_enter_edit (ETableItem *eti, int col, int row); - -void e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c deleted file mode 100644 index 9e397710ef..0000000000 --- a/widgets/table/e-table-model.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * e-table-model.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include "e-table-model.h" - -#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass) - -static GtkObjectClass *e_table_model_parent_class; - -enum { - MODEL_CHANGED, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint e_table_model_signals [LAST_SIGNAL] = { 0, }; - -int -e_table_model_column_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->column_count (e_table_model); -} - - -int -e_table_model_row_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->row_count (e_table_model); -} - -void * -e_table_model_value_at (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - return ETM_CLASS (e_table_model)->value_at (e_table_model, col, row); -} - -void -e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - ETM_CLASS (e_table_model)->set_value_at (e_table_model, col, row, data); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); - - /* - * Notice that "model_changed" is not emitted - */ -} - -gboolean -e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - return ETM_CLASS (e_table_model)->is_cell_editable (e_table_model, col, row); -} - -static void -e_table_model_destroy (GtkObject *object) -{ - if (e_table_model_parent_class->destroy) - (*e_table_model_parent_class->destroy)(object); -} - -static void -e_table_model_class_init (GtkObjectClass *object_class) -{ - e_table_model_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class->destroy = e_table_model_destroy; - - e_table_model_signals [MODEL_CHANGED] = - gtk_signal_new ("model_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_ROW_CHANGED] = - gtk_signal_new ("model_row_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_CELL_CHANGED] = - gtk_signal_new ("model_cell_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_cell_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); -} - -GtkType -e_table_model_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableModel", - sizeof (ETableModel), - sizeof (ETableModelClass), - (GtkClassInitFunc) e_table_model_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -void -e_table_model_changed (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CHANGED]); -} - -void -e_table_model_row_changed (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); -} - -void -e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); -} - - diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h deleted file mode 100644 index 2d08f3744e..0000000000 --- a/widgets/table/e-table-model.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include - -#define E_TABLE_MODEL_TYPE (e_table_model_get_type ()) -#define E_TABLE_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_MODEL_TYPE, ETableModel)) -#define E_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MODEL_TYPE, ETableModelClass)) -#define E_IS_TABLE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_MODEL_TYPE)) -#define E_IS_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MODEL_TYPE)) - -typedef struct { - GtkObject base; -} ETableModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Virtual methods - */ - int (*column_count) (ETableModel *etm); - int (*row_count) (ETableModel *etm); - void *(*value_at) (ETableModel *etm, int col, int row); - void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); - gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - - /* - * Signals - */ - - /* - * Major structural changes: model_changed - * Changes only in a row: row_changed - * Only changes in a cell: cell_changed - */ - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, int row); - void (*model_cell_changed) (ETableModel *etm, int col, int row); -} ETableModelClass; - -GtkType e_table_model_get_type (void); - -int e_table_model_column_count (ETableModel *e_table_model); -const char *e_table_model_column_name (ETableModel *e_table_model, int col); -int e_table_model_row_count (ETableModel *e_table_model); -void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); -void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, int row); -void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row); - -#endif /* _E_TABLE_MODEL_H_ */ diff --git a/widgets/table/e-table-render.c b/widgets/table/e-table-render.c deleted file mode 100644 index 49d742132b..0000000000 --- a/widgets/table/e-table-render.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * E-table-render.c: Various renderers - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - */ -#include -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col.h" -#include "e-table-render.h" - -void -e_table_render_string (ERenderContext *ctxt) -{ - printf ("Rendering string: %s\n", ctxt->render_data); -} - diff --git a/widgets/table/e-table-render.h b/widgets/table/e-table-render.h deleted file mode 100644 index ebc65968f0..0000000000 --- a/widgets/table/e-table-render.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef E_TABLE_RENDER_H -#define E_TABLE_RENDER_H - -#include - -struct ERenderContext { - ETableCol *etc; - int row; - int base_x, base_y; - GnomeCanvasItem *gnome_canvas_item; - GdkDrawable *drawable; - int drawable_width; - int drawable_height; - void *render_data; - void *closure; -}; - -void e_table_render_string (ERenderContext *ctxt); - - -#endif diff --git a/widgets/table/e-table-simple.c b/widgets/table/e-table-simple.c deleted file mode 100644 index 38e1dd8eb0..0000000000 --- a/widgets/table/e-table-simple.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * e-table-model.c: a simple table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include -#include "e-table-simple.h" - -#define PARENT_TYPE e_table_model_get_type() - -static int -simple_column_count (ETableModel *etm) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->col_count (etm, simple->data); -} - -static int -simple_row_count (ETableModel *etm) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->row_count (etm, simple->data); -} - -static void * -simple_value_at (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->value_at (etm, col, row, simple->data); -} - -static void -simple_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSimple *simple = (ETableSimple *)etm; - - simple->set_value_at (etm, col, row, val, simple->data); -} - -static gboolean -simple_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = (ETableSimple *)etm; - - return simple->is_cell_editable (etm, col, row, simple->data); -} - -static void -e_table_simple_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - model_class->column_count = simple_column_count; - model_class->row_count = simple_row_count; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_cell_editable = simple_is_cell_editable; -} - -GtkType -e_table_simple_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableSimple", - sizeof (ETableSimple), - sizeof (ETableSimpleClass), - (GtkClassInitFunc) e_table_simple_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - void *data) -{ - ETableSimple *et; - - et = gtk_type_new (e_table_simple_get_type ()); - - et->col_count = col_count; - et->row_count = row_count; - et->value_at = value_at; - et->set_value_at = set_value_at; - et->is_cell_editable = is_cell_editable; - et->data = data; - - return (ETableModel *) et; -} diff --git a/widgets/table/e-table-simple.h b/widgets/table/e-table-simple.h deleted file mode 100644 index d890245386..0000000000 --- a/widgets/table/e-table-simple.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _E_TABLE_SIMPLE_H_ -#define _E_TABLE_SIMPLE_H_ - -#include "e-table-model.h" - -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); - -typedef struct { - ETableModel parent; - - ETableSimpleColumnCountFn col_count; - ETableSimpleRowCountFn row_count; - ETableSimpleValueAtFn value_at; - ETableSimpleSetValueAtFn set_value_at; - ETableSimpleIsCellEditableFn is_cell_editable; - void *data; -} ETableSimple; - -typedef struct { - ETableModelClass parent_class; -} ETableSimpleClass; - -GtkType e_table_simple_get_type (void); - -ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - void *data); - -#endif /* _E_TABLE_SIMPLE_H_ */ - diff --git a/widgets/table/e-table-sorted.c b/widgets/table/e-table-sorted.c deleted file mode 100644 index 16644a45b1..0000000000 --- a/widgets/table/e-table-sorted.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include "e-util/e-util.h" -#include "e-table-sorted.h" - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -static ETableModelClass *ets_parent_class; - -static void -ets_class_init (GtkObjectClass *klass) -{ - ets_parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_table_sorted, "ETableSorted", ETableSorted, ets_class_init, NULL, PARENT_TYPE); - -static ETableSorted *sort_ets; - -static int -my_sort (const void *a, const void *b) -{ - ETableModel *source = E_TABLE_SUBSET (sort_ets)->source; - const int *ia = (const int *) a; - const int *ib = (const int *) b; - void *va, *vb; - - va = e_table_model_value_at (source, sort_ets->sort_col, *ia); - vb = e_table_model_value_at (source, sort_ets->sort_col, *ib); - - return (*sort_ets->compare) (va, vb); -} - -static void -do_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - g_assert (sort_ets == NULL); - - sort_ets = ets; - qsort (etss->map_table, etss->n_map, sizeof (unsigned int), my_sort); - sort_ets = NULL; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, int col, GCompareFunc compare) -{ - ETableSorted *ets = gtk_type_new (E_TABLE_SORTED_TYPE); - ETableSubset *etss = E_TABLE_SUBSET (ets); - const int nvals = e_table_model_row_count (source); - int i; - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (ets)); - return NULL; - } - - ets->compare = compare; - ets->sort_col = col; - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - do_sort (ets); - - return (ETableModel *) ets; -} - -void -e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare) -{ - if (col == -1 || compare == NULL) - do_sort (ets); - else { - ets->sort_col = col; - ets->compare = compare; - do_sort (ets); - } -} - diff --git a/widgets/table/e-table-sorted.h b/widgets/table/e-table-sorted.h deleted file mode 100644 index 2ec52df2e7..0000000000 --- a/widgets/table/e-table-sorted.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include -#include "e-table-model.h" -#include "e-table-subset.h" - -#define E_TABLE_SORTED_TYPE (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_TYPE, ETableSorted)) -#define E_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_TYPE, ETableSortedClass)) -#define E_IS_TABLE_SORTED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_TYPE)) -#define E_IS_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_TYPE)) - -typedef struct { - ETableSubset base; - - short sort_col; - GCompareFunc compare; -} ETableSorted; - -typedef struct { - ETableSubset parent_class; -} ETableSortedClass; - -GtkType e_table_sorted_get_type (void); -ETableModel *e_table_sorted_new (ETableModel *etm, int col, GCompareFunc compare); -void e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare); - -#endif /* _E_TABLE_SORTED_H_ */ diff --git a/widgets/table/e-table-subset.c b/widgets/table/e-table-subset.c deleted file mode 100644 index a9e4a5c5a4..0000000000 --- a/widgets/table/e-table-subset.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include -#include -#include -#include "e-util/e-util.h" -#include "e-table-subset.h" - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModelClass *etss_parent_class; - -static void -etss_destroy (GtkObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) - gtk_object_unref (GTK_OBJECT (etss->source)); - - if (etss->map_table) - free (etss->map_table); - - GTK_OBJECT_CLASS (etss_parent_class)->destroy (object); -} - -static int -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_column_count (etss->source); -} - -static int -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return etss->n_map; -} - -static void * -etss_value_at (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_at (etss->source, col, etss->map_table [row]); -} - -static void -etss_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_set_value_at (etss->source, col, etss->map_table [row], val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_is_cell_editable (etss->source, col, etss->map_table [row]); -} - -static void -etss_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - - etss_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etss_destroy; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->value_at = etss_value_at; - table_class->set_value_at = etss_set_value_at; - table_class->is_cell_editable = etss_is_cell_editable; -} - -E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, NULL, PARENT_TYPE); - -static void -etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - return; - } - } -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - return; - } - } -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals) -{ - unsigned int *buffer; - int i; - - buffer = (unsigned int *) malloc (sizeof (unsigned int) * nvals); - if (buffer == NULL) - return NULL; - etss->map_table = buffer; - etss->n_map = nvals; - etss->source = source; - gtk_object_ref (GTK_OBJECT (source)); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss); - gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_row_changed), etss); - gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_cell_changed), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, const int nvals) -{ - ETableSubset *etss = gtk_type_new (E_TABLE_SUBSET_TYPE); - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (etss)); - return NULL; - } - - return (ETableModel *) etss; -} - -ETableModel * -e_table_subset_get_toplevel (ETableSubset *table) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SUBSET (table), NULL); - - if (E_IS_TABLE_SUBSET (table->source)) - return e_table_subset_get_toplevel (E_TABLE_SUBSET (table->source)); - else - return table->source; -} diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h deleted file mode 100644 index 314f28aea6..0000000000 --- a/widgets/table/e-table-subset.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include -#include "e-table-model.h" - -#define E_TABLE_SUBSET_TYPE (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_TYPE, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_TYPE, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_TYPE)) -#define E_IS_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_TYPE)) - -typedef struct { - ETableModel base; - - ETableModel *source; - int n_map; - int *map_table; -} ETableSubset; - -typedef struct { - ETableModelClass parent_class; -} ETableSubsetClass; - -GtkType e_table_subset_get_type (void); -ETableModel *e_table_subset_new (ETableModel *etm, int n_vals); -ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals); - -ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model); - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/table/e-table-tree.h b/widgets/table/e-table-tree.h deleted file mode 100644 index e7e125a6af..0000000000 --- a/widgets/table/e-table-tree.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -typedef struct { - char *title; - - union { - ETableModel *table; - GList *children; - } u; - - guint expanded :1; - guint is_leaf :1; -} ETableGroup; - -ETableGroup *e_table_group_new (const char *title, ETableModel *table); -ETableGroup *e_table_group_new_leaf (const char *title); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c deleted file mode 100644 index efda8931d2..0000000000 --- a/widgets/table/e-table.c +++ /dev/null @@ -1,564 +0,0 @@ -/* - * E-table-view.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include "e-util/e-util.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" - -#define COLUMN_HEADER_HEIGHT 16 -#define TITLE_HEIGHT 16 -#define GROUP_INDENT 10 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *e_table_parent_class; - -static void -et_destroy (GtkObject *object) -{ - ETable *et = E_TABLE (object); - - gtk_object_unref (GTK_OBJECT (et->model)); - gtk_object_unref (GTK_OBJECT (et->full_header)); - gtk_object_unref (GTK_OBJECT (et->header)); - - g_free (et->group_spec); - - (*e_table_parent_class->destroy)(object); -} - -static void -e_table_init (GtkObject *object) -{ - ETable *e_table = E_TABLE (object); - - e_table->draw_grid = 1; - e_table->draw_focus = 1; - e_table->spreadsheet = 1; -} - -static ETableHeader * -e_table_make_header (ETable *e_table, ETableHeader *full_header, const char *cols) -{ - ETableHeader *nh; - char *copy = alloca (strlen (cols) + 1); - char *p, *state; - const int max_cols = e_table_header_count (full_header); - - nh = e_table_header_new (); - strcpy (copy, cols); - while ((p = strtok_r (copy, ",", &state)) != NULL){ - int col = atoi (p); - - copy = NULL; - if (col >= max_cols) - continue; - - e_table_header_add_column (nh, e_table_header_get_column (full_header, col), -1); - } - - return nh; -} - -static void -header_canvas_size_alocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, alloc->width, COLUMN_HEADER_HEIGHT); -} - -static void -e_table_setup_header (ETable *e_table) -{ - e_table->header_canvas = GNOME_CANVAS (gnome_canvas_new ()); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - e_table->header_item = gnome_canvas_item_new ( - gnome_canvas_root (e_table->header_canvas), - e_table_header_item_get_type (), - "ETableHeader", e_table->header, - "x", 0, - "y", 0, - NULL); - - gtk_signal_connect ( - GTK_OBJECT (e_table->header_canvas), "size_allocate", - GTK_SIGNAL_FUNC (header_canvas_size_alocate), e_table); - - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, COLUMN_HEADER_HEIGHT); - - gtk_table_attach ( - GTK_TABLE (e_table), GTK_WIDGET (e_table->header_canvas), - 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); - -} - -typedef struct { - void *value; - GArray *array; -} group_key_t; - -static GArray * -e_table_create_groups (ETableModel *etm, int key_col, GCompareFunc comp) -{ - GArray *groups; - const int rows = e_table_model_row_count (etm); - int row, i; - - groups = g_array_new (FALSE, FALSE, sizeof (group_key_t)); - - for (row = 0; row < rows; row++){ - void *val = e_table_model_value_at (etm, key_col, row); - const int n_groups = groups->len; - - /* - * Should replace this with a bsearch later - */ - for (i = 0; i < n_groups; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - - if ((*comp) (g->value, val)){ - g_array_append_val (g->array, row); - break; - } - } - if (i != n_groups) - continue; - - /* - * We need to create a new group - */ - { - group_key_t gk; - - gk.value = val; - gk.array = g_array_new (FALSE, FALSE, sizeof (int)); - - g_array_append_val (gk.array, row); - g_array_append_val (groups, gk); - } - } - - return groups; -} - -static void -e_table_destroy_groups (GArray *groups) -{ - const int n = groups->len; - int i; - - for (i = 0; i < n; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - - g_array_free (g->array, TRUE); - } - g_array_free (groups, TRUE); -} - -static ETableModel ** -e_table_make_subtables (ETableModel *model, GArray *groups) -{ - const int n_groups = groups->len; - ETableModel **tables; - int i; - - tables = g_new (ETableModel *, n_groups+1); - - for (i = 0; i < n_groups; i++){ - group_key_t *g = &g_array_index (groups, group_key_t, i); - const int sub_size = g->array->len; - ETableSubset *ss; - int j; - - tables [i] = e_table_subset_new (model, sub_size); - ss = E_TABLE_SUBSET (tables [i]); - - for (j = 0; j < sub_size; j++) - ss->map_table [j] = g_array_index (g->array, int, j); - } - tables [i] = NULL; - - return (ETableModel **) tables; -} - -typedef struct _Node Node; - -struct _Node { - Node *parent; - GnomeCanvasItem *item; - ETableModel *table_model; - GSList *children; - - guint is_leaf:1; -}; - -static Node * -leaf_new (GnomeCanvasItem *table_item, ETableModel *table_model, Node *parent) -{ - Node *node = g_new (Node, 1); - - g_assert (table_item != NULL); - g_assert (table_model != NULL); - g_assert (parent != NULL); - - node->item = table_item; - node->parent = parent; - node->table_model = table_model; - node->is_leaf = 1; - - g_assert (!parent->is_leaf); - - parent->children = g_slist_append (parent->children, node); - - e_table_group_add (E_TABLE_GROUP (parent->item), table_item); - - return node; -} - -static Node * -node_new (GnomeCanvasItem *group_item, ETableModel *table_model, Node *parent) -{ - Node *node = g_new (Node, 1); - - g_assert (table_model != NULL); - - node->children = NULL; - node->item = group_item; - node->parent = parent; - node->table_model = table_model; - node->is_leaf = 0; - - if (parent){ - parent->children = g_slist_append (parent->children, node); - - e_table_group_add (E_TABLE_GROUP (parent->item), group_item); - } - - return node; -} - -static Node * -e_table_create_leaf (ETable *e_table, ETableModel *etm, Node *parent) -{ - GnomeCanvasItem *table_item; - Node *leaf; - - table_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (parent->item), - e_table_item_get_type (), - "ETableHeader", e_table->header, - "ETableModel", etm, - "drawgrid", e_table->draw_grid, - "drawfocus", e_table->draw_focus, - "spreadsheet", e_table->spreadsheet, - NULL); - - leaf = leaf_new (table_item, etm, parent); - - return leaf; -} - -static int -leaf_height (Node *leaf) -{ - const GnomeCanvasItem *item = leaf->item; - - return item->y2 - item->y1; -} - -static int -leaf_event (GnomeCanvasItem *item, GdkEvent *event) -{ - static int last_x = -1; - static int last_y = -1; - - if (event->type == GDK_BUTTON_PRESS){ - last_x = event->button.x; - last_y = event->button.y; - } else if (event->type == GDK_BUTTON_RELEASE){ - last_x = -1; - last_y = -1; - } else if (event->type == GDK_MOTION_NOTIFY){ - if (last_x == -1) - return FALSE; - - gnome_canvas_item_move (item, event->motion.x - last_x, event->motion.y - last_y); - last_x = event->motion.x; - last_y = event->motion.y; - } else - return FALSE; - return TRUE; -} - -static Node * -e_table_create_nodes (ETable *e_table, ETableModel *model, ETableHeader *header, - GnomeCanvasGroup *root, Node *parent, int *groups_list) -{ - GArray *groups; - ETableModel **tables; - ETableCol *ecol; - int key_col, i; - GnomeCanvasItem *group_item; - Node *group; - - key_col = *groups_list; - g_assert (key_col != -1); - - /* - * Create groups - */ - ecol = e_table_header_get_column (header, key_col); - - g_assert (ecol != NULL); - - groups = e_table_create_groups (model, key_col, ecol->compare); - tables = e_table_make_subtables (e_table->model, groups); - e_table_destroy_groups (groups); - - group_item = e_table_group_new (root, ecol, TRUE, parent == NULL); - group = node_new (group_item, model, parent); - - for (i = 0; tables [i] != NULL; i++){ - /* - * Leafs - */ - if (groups_list [1] == -1){ - GnomeCanvasItem *item_leaf_header; - Node *leaf_header; - - item_leaf_header = e_table_group_new ( - GNOME_CANVAS_GROUP (group_item), ecol, TRUE, FALSE); - leaf_header = node_new (item_leaf_header, tables [i], group); - - e_table_create_leaf (e_table, tables [i], leaf_header); - } else { - e_table_create_nodes ( - e_table, tables [i], header, GNOME_CANVAS_GROUP (group_item), - group, &groups_list [1]); - } - } - - return group; -} - -static int * -group_spec_to_desc (const char *group_spec) -{ - int a_size = 10; - int *elements; - char *p, *copy, *follow; - int n_elements = 0; - - if (group_spec == NULL) - return NULL; - - elements = g_new (int, a_size); - copy = alloca (strlen (group_spec) + 1); - strcpy (copy, group_spec); - - while ((p = strtok_r (copy, ",", &follow)) != NULL){ - elements [n_elements] = atoi (p); - ++n_elements; - if (n_elements+1 == a_size){ - int *new_e; - - n_elements += 10; - new_e = g_renew (int, elements, n_elements); - if (new_e == NULL){ - g_free (elements); - return NULL; - } - elements = new_e; - } - copy = NULL; - } - - /* Tag end */ - elements [n_elements] = -1; - - return elements; -} - -/* - * The ETableCanvas object is just used to enable us to - * hook up to the realize/unrealize phases of the canvas - * initialization (as laying out the subtables requires us to - * know the actual size of the subtables we are inserting - */ - -#define E_TABLE_CANVAS_PARENT_TYPE gnome_canvas_get_type () - -typedef struct { - GnomeCanvas base; - - ETable *e_table; -} ETableCanvas; - -typedef struct { - GnomeCanvasClass base_class; -} ETableCanvasClass; - -static GnomeCanvasClass *e_table_canvas_parent_class; - -static void -e_table_canvas_realize (GtkWidget *widget) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) widget; - ETable *e_table = e_table_canvas->e_table; - int *groups; - Node *leaf; - - GTK_WIDGET_CLASS (e_table_canvas_parent_class)->realize (widget); - - groups = group_spec_to_desc (e_table->group_spec); - - leaf = e_table_create_nodes ( - e_table, e_table->model, - e_table->header, GNOME_CANVAS_GROUP (e_table->root), 0, groups); - - - if (groups) - g_free (groups); -} - -static void -e_table_canvas_unrealize (GtkWidget *widget) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) widget; - ETable *e_table = e_table_canvas->e_table; - - gtk_object_destroy (GTK_OBJECT (e_table->root)); - - GTK_WIDGET_CLASS (e_table_canvas_parent_class)->unrealize (widget); -} - -static void -e_table_canvas_class_init (GtkObjectClass *object_class) -{ - GtkWidgetClass *widget_class = (GtkWidgetClass *) object_class; - - widget_class->realize = e_table_canvas_realize; - widget_class->unrealize = e_table_canvas_unrealize; - - e_table_canvas_parent_class = gtk_type_class (E_TABLE_CANVAS_PARENT_TYPE); -} - -static void -e_table_canvas_init (GtkObject *canvas) -{ - ETableCanvas *e_table_canvas = (ETableCanvas *) (canvas); - ETable *e_table = e_table_canvas->e_table; - - GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS); - -} - -GtkType e_table_canvas_get_type (void); - -E_MAKE_TYPE (e_table_canvas, "ETableCanvas", ETableCanvas, e_table_canvas_class_init, - e_table_canvas_init, E_TABLE_CANVAS_PARENT_TYPE); - -static GnomeCanvas * -e_table_canvas_new (ETable *e_table) -{ - ETableCanvas *e_table_canvas; - - e_table_canvas = gtk_type_new (e_table_canvas_get_type ()); - e_table_canvas->e_table = e_table; - - e_table->root = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS (e_table_canvas)->root), - gnome_canvas_group_get_type (), - "x", 0.0, - "y", 0.0, - NULL); - - return GNOME_CANVAS (e_table_canvas); -} - -static void -table_canvas_size_alocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, alloc->width, alloc->height); -} - -static void -e_table_setup_table (ETable *e_table) -{ - e_table->table_canvas = e_table_canvas_new (e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "size_allocate", - GTK_SIGNAL_FUNC (table_canvas_size_alocate), e_table); - - gtk_widget_show (GTK_WIDGET (e_table->table_canvas)); - gtk_table_attach ( - GTK_TABLE (e_table), GTK_WIDGET (e_table->table_canvas), - 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0); -} - -void -e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec) -{ - GTK_TABLE (e_table)->homogeneous = FALSE; - - gtk_table_resize (GTK_TABLE (e_table), 1, 2); - - e_table->full_header = full_header; - gtk_object_ref (GTK_OBJECT (full_header)); - - e_table->model = etm; - gtk_object_ref (GTK_OBJECT (etm)); - - e_table->header = e_table_make_header (e_table, full_header, cols_spec); - - e_table_setup_header (e_table); - e_table_setup_table (e_table); - - e_table->group_spec = g_strdup (group_spec); - -} - -GtkWidget * -e_table_new (ETableHeader *full_header, ETableModel *etm, const char *cols_spec, const char *group_spec) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table_construct (e_table, full_header, etm, cols_spec, group_spec); - - return (GtkWidget *) e_table; -} - -static void -e_table_class_init (GtkObjectClass *object_class) -{ - e_table_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = et_destroy; -} - -E_MAKE_TYPE(e_table, "ETable", ETable, e_table_class_init, e_table_init, PARENT_TYPE); - diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h deleted file mode 100644 index 63c131324f..0000000000 --- a/widgets/table/e-table.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include -#include -#include "e-table-model.h" -#include "e-table-header.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_TYPE (e_table_get_type ()) -#define E_TABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_TYPE, ETable)) -#define E_TABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_TYPE, ETableClass)) -#define E_IS_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_TYPE)) -#define E_IS_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_TYPE)) - -typedef struct { - GtkTable parent; - - ETableModel *model; - - ETableHeader *full_header, *header; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - guint draw_grid:1; - guint draw_focus:1; - guint spreadsheet:1; - - char *group_spec; -} ETable; - -typedef struct { - GtkTableClass parent_class; -} ETableClass; - -GtkType e_table_get_type (void); -void e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec); -GtkWidget *e_table_new (ETableHeader *full_header, ETableModel *etm, - const char *cols_spec, const char *group_spec); - - -END_GNOME_DECLS - - #endif /* _E_TABLE_H_ */ diff --git a/widgets/table/image1.png b/widgets/table/image1.png deleted file mode 100644 index 8326ac241f..0000000000 Binary files a/widgets/table/image1.png and /dev/null differ diff --git a/widgets/table/image2.png b/widgets/table/image2.png deleted file mode 100644 index e6a4c75dbe..0000000000 Binary files a/widgets/table/image2.png and /dev/null differ diff --git a/widgets/table/image3.png b/widgets/table/image3.png deleted file mode 100644 index 50e16e8620..0000000000 Binary files a/widgets/table/image3.png and /dev/null differ diff --git a/widgets/table/remove-col.xpm b/widgets/table/remove-col.xpm deleted file mode 100644 index ff1024f0c9..0000000000 --- a/widgets/table/remove-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * remove_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FF0000", -"... ...", -".++. .++.", -".+++. .+++.", -" .+++. .+++. ", -" .+++. .+++. ", -" .+++..+++. ", -" .++++++. ", -" .++++. ", -" .++++. ", -" .++++++. ", -" .+++..+++. ", -" .+++. .+++. ", -" .+++. .+++. ", -".+++. .+++.", -".++. .++.", -"... ..."}; diff --git a/widgets/table/sample.table b/widgets/table/sample.table deleted file mode 100644 index 45c8ff0691..0000000000 --- a/widgets/table/sample.table +++ /dev/null @@ -1,11 +0,0 @@ -Col1 Col2 Address Title Dorks -c1.a c2.a a.a tit-1 DorkA -c1.b c2.b a.b tit-2 DDork -c1.c c2.c a.c tit-1 DorkB -c1.d c2.d a.d tit-2 ADork -c1.e c2.e a.e tit-1 DorkC -c1.f c2.f a.f tit-2 UDork -c1.g c2.g a.g tit-3 Dork--- -j k k tit-1 DorkA - - diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c deleted file mode 100644 index 3009297906..0000000000 --- a/widgets/table/table-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "table-test.h" - -int -main (int argc, char *argv []) -{ - - if (isatty (0)){ - int fd; - - close (0); - fd = open ("sample.table", O_RDONLY); - if (fd == -1){ - fprintf (stderr, "Could not find sample.table, try feeding a table on stdin"); - exit (1); - } - dup2 (fd, 0); - } - - gnome_init ("TableTest", "TableTest", argc, argv); - e_cursors_init (); - -#if 0 - table_browser_test (); - multi_cols_test (); - check_test (); -#endif - e_table_test (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/table/table-test.h b/widgets/table/table-test.h deleted file mode 100644 index ad8cfcc083..0000000000 --- a/widgets/table/table-test.h +++ /dev/null @@ -1,4 +0,0 @@ -void table_browser_test (void); -void multi_cols_test (void); -void check_test (void); -void e_table_test (void); diff --git a/widgets/table/test-check.c b/widgets/table/test-check.c deleted file mode 100644 index 8cc5f6834e..0000000000 --- a/widgets/table/test-check.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-util/e-cursors.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "Buy food" }, - { 1, "Breathe " }, - { 0, "Cancel gdb session with shrink" }, - { 1, "Make screenshots" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -check_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_check; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - cell_image_check = e_cell_checkbox_new (); - col_0 = e_table_col_new (0, "", 18, 18, cell_image_check, g_int_equal, TRUE); - e_table_header_add_column (e_table_header, col_0, 0); - - col_1 = e_table_col_new (1, "Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); - e_table_header_add_column (e_table_header, col_1, 1); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - -} - - - - - diff --git a/widgets/table/test-cols.c b/widgets/table/test-cols.c deleted file mode 100644 index 288e2bd408..0000000000 --- a/widgets/table/test-cols.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-toggle.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "You are not" }, - { 1, "A beautiful and unique " }, - { 0, "Snowflake" }, - { 2, "You are not your wallet" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -multi_cols_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header, *e_table_header_multiple; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_toggle; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - { - GdkPixbuf **images = g_new (GdkPixbuf *, 3); - int i; - - images [0] = gdk_pixbuf_new_from_file ("image1.png"); - images [1] = gdk_pixbuf_new_from_file ("image2.png"); - images [2] = gdk_pixbuf_new_from_file ("image3.png"); - - cell_image_toggle = e_cell_toggle_new (0, 3, images); - - for (i = 0; i < 3; i++) - gdk_pixbuf_unref (images [i]); - - g_free (images); - } - - col_1 = e_table_col_new (1, "Item Name", 180, 20, cell_left_just, g_str_equal, TRUE); - e_table_header_add_column (e_table_header, col_1, 0); - - col_0 = e_table_col_new (0, "A", 48, 48, cell_image_toggle, g_int_equal, TRUE); - e_table_header_add_column (e_table_header, col_0, 1); - - /* - * Second test - */ - e_table_header_multiple = e_table_header_new (); - e_table_header_add_column (e_table_header_multiple, col_0, 0); - e_table_header_add_column (e_table_header_multiple, col_1, 1); - e_table_header_add_column (e_table_header_multiple, col_1, 2); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header_multiple, - "x", 300, - "y", 0, - NULL); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header_multiple, - "ETableModel", e_table_model, - "x", (double) 300, - "y", (double) 30, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); - -} - - - - - diff --git a/widgets/table/test-table.c b/widgets/table/test-table.c deleted file mode 100644 index 428bb52c52..0000000000 --- a/widgets/table/test-table.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include -#include -#include -#include -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-table.h" - -#include "table-test.h" - -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () -{ - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); - exit (1); - } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - { - static int loaded; - - if (loaded) - return; - - loaded = TRUE; - } - - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -table_browser_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - GnomeCanvasItem *group; - int i; - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 80, 20, cell_left_just, - g_str_equal, TRUE); - - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = gnome_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - "x", 0, - "y", 0, - NULL); - - group = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_group_get_type (), - "x", 30.0, - "y", 30.0, - NULL); - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (group), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "x", (double) 0, - "y", (double) 0, - "drawgrid", TRUE, - "drawfocus", TRUE, - "spreadsheet", TRUE, - NULL); -} - -static void -do_e_table_demo (const char *col_spec, const char *group_spec) -{ - GtkWidget *e_table, *window, *frame; - ETableModel *e_table_model; - ECell *cell_left_just; - ETableHeader *full_header; - int i; - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, NULL); - - full_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 80, 20, cell_left_just, - g_str_equal, TRUE); - - e_table_header_add_column (full_header, ecol, i); - } - - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - frame = gtk_frame_new (NULL); - e_table = e_table_new (full_header, e_table_model, col_spec, group_spec); - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - gtk_widget_set_usize (window, 200, 200); - gtk_widget_show (e_table); - gtk_widget_show (frame); - gtk_widget_show (window); -} - -void -e_table_test (void) -{ - load_data (); - - if (getenv ("DO")){ - do_e_table_demo ("0,1,2,3,4", NULL); - do_e_table_demo ("0,1,2,3,4", "3,4"); - } - do_e_table_demo ("0,1,2,3,4", "3"); -} diff --git a/widgets/table/test.c b/widgets/table/test.c deleted file mode 100644 index 0eece34467..0000000000 --- a/widgets/table/test.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "e-table-simple.h" - -struct { - char *str; - int val; -} data [] = { - { "Miguel", 10 }, - { "Nat", 20 }, - { NULL, 0 }, -}; - -main () -{ - -} - diff --git a/widgets/text/e-text-event-processor-emacs-like.c b/widgets/text/e-text-event-processor-emacs-like.c deleted file mode 100644 index 41bcd0c31d..0000000000 --- a/widgets/text/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,357 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor-emacs-like.h" -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_BACKWARD_WORD, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - case GDK_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: command.position = E_TEP_BACKWARD_LINE; break; - case GDK_Down: command.position = E_TEP_FORWARD_LINE; break; - case GDK_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT */ - } - break; - case GDK_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/widgets/text/e-text-event-processor-emacs-like.h b/widgets/text/e-text-event-processor-emacs-like.h deleted file mode 100644 index 651bb552b3..0000000000 --- a/widgets/text/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include -#include "e-text-event-processor.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - gboolean mouse_down; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/widgets/text/e-text-event-processor-types.h b/widgets/text/e-text-event-processor-types.h deleted file mode 100644 index 32a39bf0c0..0000000000 --- a/widgets/text/e-text-event-processor-types.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include - -typedef enum _ETextEventProcessorCommandPosition ETextEventProcessorCommandPosition; -typedef enum _ETextEventProcessorCommandAction ETextEventProcessorCommandAction; -typedef struct _ETextEventProcessorCommand ETextEventProcessorCommand; - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; -typedef struct _ETextEventProcessorEventButton ETextEventProcessorEventButton; -typedef struct _ETextEventProcessorEventKey ETextEventProcessorEventKey; -typedef struct _ETextEventProcessorEventMotion ETextEventProcessorEventMotion; - -enum _ETextEventProcessorCommandPosition { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE -}; - -enum _ETextEventProcessorCommandAction { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -}; - -struct _ETextEventProcessorCommand { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -}; - -struct _ETextEventProcessorEventButton { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -}; - -struct _ETextEventProcessorEventKey { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -}; - -struct _ETextEventProcessorEventMotion { - GdkEventType type; - guint32 time; - guint state; - gint position; -}; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/widgets/text/e-text-event-processor.c b/widgets/text/e-text-event-processor.c deleted file mode 100644 index 47f028ca62..0000000000 --- a/widgets/text/e-text-event-processor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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 -#include "e-text-event-processor.h" -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - klass->event = NULL; - klass->command = NULL; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} diff --git a/widgets/text/e-text-event-processor.h b/widgets/text/e-text-event-processor.h deleted file mode 100644 index 1fc79f3f70..0000000000 --- a/widgets/text/e-text-event-processor.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey - * - * 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. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include -#include "e-text-event-processor-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c deleted file mode 100644 index b33e99194d..0000000000 --- a/widgets/text/e-text.c +++ /dev/null @@ -1,2526 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#include -#include -#include -#include "e-text.h" -#include /* for BlackPixel */ -#include -#include -#include -#include - -#include "e-text-event-processor-emacs-like.h" - -enum { - E_TEXT_RESIZE, - E_TEXT_CHANGE, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_MAX_LINES -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static guint32 e_text_get_event_time (EText *text); - -static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time); -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); - - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_RESIZE] = - gtk_signal_new ("resize", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, resize), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - e_text_signals[E_TEXT_CHANGE] = - gtk_signal_new ("change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); - - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::x", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X); - gtk_object_add_arg_type ("EText::y", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->resize = NULL; - klass->change = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->x = 0.0; - text->y = 0.0; - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = 0.0; - text->clip_height = 0.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->max_lines = -1; -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CANVAS_TEXT (object)); - - text = E_TEXT (object); - - if (text->text) - g_free (text->text); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - if (text->lines) - g_free (text->lines); - - if (text->font) - gdk_font_unref (text->font); - - if (text->suckfont) - e_suck_font_free (text->suckfont); - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = text->x; - y = text->y; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - clip_x -= text->clip_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - clip_x -= text->clip_width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - clip_y -= text->clip_height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - clip_y -= text->clip_height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - *px2 = clip_x + text->clip_width; - *py2 = clip_y + text->clip_height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = text->x; - wy = text->y; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - /* Get canvas pixel coordinates for clip rectangle position */ - - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = text->clip_width * item->canvas->pixels_per_unit; - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (text->font->ascent + text->font->descent) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -/* Recalculates the bounding box of the text item. The bounding box is defined - * by the text's extents if the clip rectangle is disabled. If it is enabled, - * the bounding box is defined by the clip rectangle itself. - */ -static void -recalc_bounds (EText *text) -{ - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (text); - - get_bounds (text, &item->x1, &item->y1, &item->x2, &item->y2); - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - gdk_text_width (text->font, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - int j; - - lines = text->lines; - text->max_width = 0; - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = gdk_text_width (text->font, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > text->clip_width) { - if (text->font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (text->font, lines->text, j) + text->ellipsis_width <= text->clip_width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = gdk_text_width (text->font, lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - char *p; - struct line *lines; - int len; - int line_num; - char *laststart; - char *lastend; - char *linestart; - - /* Free old array of lines */ - - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; - - if (!text->text) - return; - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - for (p = text->text; *p; p++) { - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - } - } - if (*p == '\n') { - text->num_lines ++; - lastend = p + 1; - laststart = p + 1; - linestart = p + 1; - } - } - - if (text->line_wrap) { - if ( laststart != lastend - && gdk_text_width(text->font, - linestart, - p - linestart) - > text->clip_width ) { - text->num_lines ++; - } - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - for (p = text->text; line_num < text->num_lines && *p; p++) { - gboolean handled = FALSE; - if (len == 0) - lines->text = p; - if (text->line_wrap && (*p == ' ' || *p == '\n')) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } else if (*p == ' ') { - laststart = p + 1; - lastend = p; - len ++; - } - handled = TRUE; - } - if ( line_num >= text->num_lines ) - break; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - line_num ++; - len = 0; - lastend = p + 1; - laststart = p + 1; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if ( gdk_text_width(text->font, - lines->text, - p - lines->text) - > text->clip_width - && laststart != lastend ) { - lines->length = lastend - lines->text; - lines++; - line_num ++; - len = p - laststart; - lines->text = laststart; - laststart = p + 1; - lastend = p; - } - } - - if (len == 0) - lines->text = p; - lines->length = strlen(lines->text); - - calc_line_widths (text); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - GdkColor c; - - if (!text->gc) - return; - - c.pixel = text->pixel; - gdk_gc_set_foreground (text->gc, &c); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_TEXT: - if (text->text) - g_free (text->text); - - text->text = g_strdup (GTK_VALUE_STRING (*arg)); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_X: - text->x = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y: - text->y = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FONT: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_font_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONTSET: - if (text->font) - gdk_font_unref (text->font); - - text->font = gdk_fontset_load (GTK_VALUE_STRING (*arg)); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_FONT_GDK: - if (text->font) - gdk_font_unref (text->font); - - text->font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (text->font); - - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - recalc_bounds (text); - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - recalc_bounds (text); - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - recalc_bounds (text); - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - gdk_color_context_query_color (item->canvas->cc, &color); - have_pixel = TRUE; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color_changed = TRUE; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - calc_line_widths (text); - recalc_bounds (text); - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - split_into_lines (text); - recalc_bounds (text); - break; - - default: - break; - } - - if (color_changed) { - if (have_pixel) - text->pixel = color.pixel; - else - text->pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba); - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - gnome_canvas_item_request_update (item); - } -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - case ARG_X: - GTK_VALUE_DOUBLE (*arg) = text->x; - break; - - case ARG_Y: - GTK_VALUE_DOUBLE (*arg) = text->y; - break; - - case ARG_FONT_GDK: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - color->pixel = text->pixel; - gdk_color_context_query_color (text->item.canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - - gnome_canvas_update_bbox (item, x1, y1, x2, y2); - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - gnome_canvas_update_bbox (item, c_bbox.x0, c_bbox.y0, c_bbox.x1, c_bbox.y1); - - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - gdk_cursor_destroy (text->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = text->x; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = text->y; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GnomeCanvas *canvas; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - - fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - - if (!text->text || !text->font) - return; - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - lines = text->lines; - ypos = text->cy + text->font->ascent; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, text->gc); - - for (i = 0; i < text->num_lines; i++) { - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = lines->text - text->text; - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - text->font->ascent; - sel_rect.width = gdk_text_width (text->font, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = text->font->ascent + text->font->descent; - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - gdk_draw_text (drawable, - text->font, - fg_gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + sel_start - start_char, - sel_end - sel_start); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + sel_end - start_char, - end_char - sel_end); - } else { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - xpos - x + gdk_text_width (text->font, - lines->text, - sel_start - start_char), - ypos - y - text->font->ascent, - 1, - text->font->ascent + text->font->descent); - } - } else { - if ( text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x + - lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? strlen (text->ellipsis) : 3); - } else - - gdk_draw_text (drawable, - text->font, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - - ypos += text->font->ascent + text->font->descent; - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (text->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - ETextSuckFont *suckfont; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = text->font->ascent + text->font->descent; - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = text->x; - *y1 = text->y; - - if (text->clip) { - width = text->clip_width; - height = text->clip_height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static void -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - x = get_line_xpos (text, lines); - y = text->cy; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += text->font->ascent + text->font->descent; - } - lines --; - y -= text->font->descent; - - x += gdk_text_width (text->font, - lines->text, - position - (lines->text - text->text)); - x -= text->xofs_edit; - if (xp) - *xp = x; - if (yp) - *yp = y; - } -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->cy; - int xpos; - struct line *lines; - j = 0; - while (y > ypos) { - ypos += text->font->ascent + text->font->descent; - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos (text, lines); - for(i = 0; i < lines->length; i++) { - int charwidth = gdk_text_width(text->font, - lines->text + i, - 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - return lines->text + i - text->text; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - return TRUE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!text->editing) { - text->editing = TRUE; - if ( text->pointer_in ) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - text->xofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); - } - } else { - text->editing = FALSE; - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - } - if ( text->line_wrap ) - split_into_lines (text); - else - calc_line_widths (text); - recalc_bounds (text); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(text); - return e_text_event_processor_handle_event (text->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->editing) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } else if (text->editable && event->type == GDK_BUTTON_RELEASE && event->button.button == 1) { - gnome_canvas_item_grab_focus (item); - return 1; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - text->pointer_in = TRUE; - if (text->editing) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - text->pointer_in = FALSE; - if (text->editing) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return text->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return strlen(text->text); - - case E_TEP_START_OF_LINE: - for (i = text->selection_end - 2; i > 0; i--) - if (text->text[i] == '\n') { - i++; - break; - } - return i; - case E_TEP_END_OF_LINE: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (text->text[i] == '\n') { - break; - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = strlen(text->text); - i = text->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = text->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = strlen(text->text); - for (i = text->selection_end + 1; i < length; i++) - if (isspace(text->text[i])) { - break; - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = text->selection_end - 2; i > 0; i--) - if (isspace(text->text[i])) { - i++; - break; - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y += text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y -= text->font->ascent + text->font->descent; - return _get_position_from_xy(text, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return text->selection_end; - default: - return text->selection_end; - } -} - -static void -_delete_selection(EText *text) -{ - gint length = strlen(text->text); - if (text->selection_end == text->selection_start) - return; - if (text->selection_end < text->selection_start) { - text->selection_end ^= text->selection_start; - text->selection_start ^= text->selection_end; - text->selection_end ^= text->selection_start; - } - memmove( text->text + text->selection_start, - text->text + text->selection_end, - length - text->selection_end + 1 ); - length -= text->selection_end - text->selection_start; - text->selection_end = text->selection_start; -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - char *temp; - gint length = strlen(text->text); - temp = g_new(gchar, length + value + 1); - strncpy(temp, text->text, text->selection_start); - strncpy(temp + text->selection_start, string, value); - strcpy(temp + text->selection_start + value, text->text + text->selection_start); - g_free(text->text); - text->text = temp; - text->selection_start += value; - text->selection_end = text->selection_start; - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SELECT: - text->selection_end = _get_position(text, command); - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, text->text + sel_start, sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - split_into_lines (text); - recalc_bounds (text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, text->text + sel_start, sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; - case E_TEP_NOP: - break; - } - - if (!text->button_down) { - int x; - int i; - struct line *lines = text->lines; - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (lines->text - text->text > text->selection_end) { - break; - } - } - lines --; - x = gdk_text_width(text->font, - lines->text, - text->selection_end - (lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - if (2 + x - text->clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - text->clip_width; - } - } - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void _invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget *e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->primary_selection, text->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->clipboard_selection, text->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } -} - -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (text->primary_selection) { - g_free (text->primary_selection); - } - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - if (text->clipboard_selection) { - g_free (text->clipboard_selection); - } - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - -/* Get the timestamp of the current event. Actually, the only thing - * we really care about below is the key event - */ -static guint32 -e_text_get_event_time (EText *text) -{ - GdkEvent *event; - guint32 tm = GDK_CURRENT_TIME; - - event = gtk_get_current_event(); - - if (event) - switch (event->type) - { - case GDK_MOTION_NOTIFY: - tm = event->motion.time; break; - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - tm = event->button.time; break; - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - tm = event->key.time; break; - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - tm = event->crossing.time; break; - case GDK_PROPERTY_NOTIFY: - tm = event->property.time; break; - case GDK_SELECTION_CLEAR: - case GDK_SELECTION_REQUEST: - case GDK_SELECTION_NOTIFY: - tm = event->selection.time; break; - case GDK_PROXIMITY_IN: - case GDK_PROXIMITY_OUT: - tm = event->proximity.time; break; - default: /* use current time */ - break; - } - gdk_event_free(event); - - return tm; -} - - - -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h deleted file mode 100644 index ef8da442d6..0000000000 --- a/widgets/text/e-text.h +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include -#include "e-text-event-processor.h" - - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * x double RW X coordinate of anchor point - * y double RW Y coordinate of anchor point - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * max_line_wrap int RW Number of lines possible when doing line wrap. - * - * These are not implemented yet: - * background boolean RW Draw a background rectangle. - * background_on_edit boolean RW Draw a background when editing. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; - -struct _EText { - GnomeCanvasItem item; - - char *text; /* Text to display */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - - double x, y; /* Position at anchor */ - GdkFont *font; /* Font for text */ - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - gulong pixel; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int height; /* Rendered text height in pixels */ - - guint clip : 1; /* Use clip rectangle? */ - - /* Antialiased specific stuff follows */ - ETextSuckFont *suckfont; /* Sucked font */ - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - gboolean use_ellipsis; /* Whether to use the ellipsis. */ - - gboolean editable; /* Item is editable */ - gboolean editing; /* Item is currently being edited */ - - int xofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - - guint line_wrap : 1; /* Do line wrap */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* resize) (EText *text); - void (* change) (EText *text); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); - - -END_GNOME_DECLS - -#endif -- cgit v1.2.3