1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
|
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "gimpdevices.h"
#include "gimpdialogfactory.h"
#include "gimphelp-ids.h"
#include "gimptoolbox.h"
#include "gimptoolbox-color-area.h"
#include "gimptoolbox-dnd.h"
#include "gimptoolbox-image-area.h"
#include "gimptoolbox-indicator-area.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
#include "gtkhwrapbox.h"
#include "gimp-intl.h"
#define DEFAULT_TOOL_ICON_SIZE GTK_ICON_SIZE_BUTTON
#define DEFAULT_BUTTON_RELIEF GTK_RELIEF_NONE
#define TOOL_BUTTON_DATA_KEY "gimp-tool-button"
#define TOOL_INFO_DATA_KEY "gimp-tool-info"
/* local function prototypes */
static void gimp_toolbox_class_init (GimpToolboxClass *klass);
static void gimp_toolbox_init (GimpToolbox *toolbox);
static GObject * gimp_toolbox_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static gboolean gimp_toolbox_delete_event (GtkWidget *widget,
GdkEventAny *event);
static void gimp_toolbox_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gimp_toolbox_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static void gimp_toolbox_book_added (GimpDock *dock,
GimpDockbook *dockbook);
static void gimp_toolbox_book_removed (GimpDock *dock,
GimpDockbook *dockbook);
static void gimp_toolbox_set_geometry (GimpToolbox *toolbox);
static void toolbox_create_tools (GimpToolbox *toolbox,
GimpContext *context);
static GtkWidget * toolbox_create_color_area (GimpToolbox *toolbox,
GimpContext *context);
static GtkWidget * toolbox_create_foo_area (GimpToolbox *toolbox,
GimpContext *context);
static GtkWidget * toolbox_create_image_area (GimpToolbox *toolbox,
GimpContext *context);
static void toolbox_area_notify (GimpGuiConfig *config,
GParamSpec *pspec,
GtkWidget *area);
static void toolbox_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
gpointer data);
static void toolbox_tool_reorder (GimpContainer *container,
GimpToolInfo *tool_info,
gint index,
GtkWidget *wrap_box);
static void toolbox_tool_visible_notify (GimpToolInfo *tool_info,
GParamSpec *pspec,
GtkWidget *button);
static void toolbox_tool_button_toggled (GtkWidget *widget,
GimpToolInfo *tool_info);
static gboolean toolbox_tool_button_press (GtkWidget *widget,
GdkEventButton *bevent,
GimpToolbox *toolbox);
static gboolean toolbox_check_device (GtkWidget *widget,
GdkEvent *event,
Gimp *gimp);
/* local variables */
static GimpDockClass *parent_class = NULL;
GType
gimp_toolbox_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo type_info =
{
sizeof (GimpToolboxClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_toolbox_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpToolbox),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_toolbox_init,
};
type = g_type_register_static (GIMP_TYPE_DOCK,
"GimpToolbox",
&type_info, 0);
}
return type;
}
static void
gimp_toolbox_class_init (GimpToolboxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpDockClass *dock_class = GIMP_DOCK_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_toolbox_constructor;
widget_class->delete_event = gimp_toolbox_delete_event;
widget_class->size_allocate = gimp_toolbox_size_allocate;
widget_class->style_set = gimp_toolbox_style_set;
dock_class->book_added = gimp_toolbox_book_added;
dock_class->book_removed = gimp_toolbox_book_removed;
gtk_widget_class_install_style_property
(widget_class, g_param_spec_enum ("tool_icon_size",
NULL, NULL,
GTK_TYPE_ICON_SIZE,
DEFAULT_TOOL_ICON_SIZE,
G_PARAM_READABLE));
gtk_widget_class_install_style_property
(widget_class, g_param_spec_enum ("button_relief",
NULL, NULL,
GTK_TYPE_RELIEF_STYLE,
DEFAULT_BUTTON_RELIEF,
G_PARAM_READABLE));
}
static void
gimp_toolbox_init (GimpToolbox *toolbox)
{
gtk_window_set_role (GTK_WINDOW (toolbox), "gimp-toolbox");
gimp_help_connect (GTK_WIDGET (toolbox), gimp_standard_help_func,
GIMP_HELP_TOOLBOX, NULL);
}
static GObject *
gimp_toolbox_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpToolbox *toolbox;
GimpContext *context;
GimpGuiConfig *config;
GimpUIManager *manager;
GtkWidget *main_vbox;
GtkWidget *vbox;
GdkDisplay *display;
GList *list;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
toolbox = GIMP_TOOLBOX (object);
context = GIMP_DOCK (toolbox)->context;
config = GIMP_GUI_CONFIG (context->gimp->config);
gimp_window_set_hint (GTK_WINDOW (toolbox), config->toolbox_window_hint);
main_vbox = GIMP_DOCK (toolbox)->main_vbox;
vbox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (main_vbox), vbox, 0);
gtk_widget_show (vbox);
manager = gimp_ui_managers_from_name ("<Image>")->data;
toolbox->menu_bar = gimp_ui_manager_ui_get (manager, "/toolbox-menubar");
if (toolbox->menu_bar)
{
gtk_box_pack_start (GTK_BOX (vbox), toolbox->menu_bar, FALSE, FALSE, 0);
gtk_widget_show (toolbox->menu_bar);
}
gtk_window_add_accel_group (GTK_WINDOW (toolbox),
gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (manager)));
toolbox->tool_wbox = gtk_hwrap_box_new (FALSE);
gtk_wrap_box_set_justify (GTK_WRAP_BOX (toolbox->tool_wbox), GTK_JUSTIFY_TOP);
gtk_wrap_box_set_line_justify (GTK_WRAP_BOX (toolbox->tool_wbox),
GTK_JUSTIFY_LEFT);
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (toolbox->tool_wbox), 5.0 / 6.0);
gtk_box_pack_start (GTK_BOX (vbox), toolbox->tool_wbox, FALSE, FALSE, 0);
gtk_widget_show (toolbox->tool_wbox);
toolbox->area_wbox = gtk_hwrap_box_new (FALSE);
gtk_wrap_box_set_justify (GTK_WRAP_BOX (toolbox->area_wbox), GTK_JUSTIFY_TOP);
gtk_wrap_box_set_line_justify (GTK_WRAP_BOX (toolbox->area_wbox),
GTK_JUSTIFY_LEFT);
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (toolbox->area_wbox), 5.0 / 6.0);
gtk_box_pack_start (GTK_BOX (vbox), toolbox->area_wbox, FALSE, FALSE, 0);
gtk_widget_show (toolbox->area_wbox);
/* We need to know when the current device changes, so we can update
* the correct tool - to do this we connect to motion events.
* We can't just use EXTENSION_EVENTS_CURSOR though, since that
* would get us extension events for the mouse pointer, and our
* device would change to that and not change back. So we check
* manually that all devices have a cursor, before establishing the check.
*/
display = gtk_widget_get_display (GTK_WIDGET (toolbox));
for (list = gdk_display_list_devices (display); list; list = list->next)
{
if (! ((GdkDevice *) (list->data))->has_cursor)
break;
}
if (! list) /* all devices have cursor */
{
g_signal_connect (toolbox, "motion_notify_event",
G_CALLBACK (toolbox_check_device),
context->gimp);
gtk_widget_add_events (GTK_WIDGET (toolbox), GDK_POINTER_MOTION_MASK);
gtk_widget_set_extension_events (GTK_WIDGET (toolbox),
GDK_EXTENSION_EVENTS_CURSOR);
}
toolbox_create_tools (toolbox, context);
toolbox->color_area = toolbox_create_color_area (toolbox, context);
gtk_wrap_box_pack_wrapped (GTK_WRAP_BOX (toolbox->area_wbox),
toolbox->color_area,
TRUE, TRUE, FALSE, TRUE, TRUE);
if (config->toolbox_color_area)
gtk_widget_show (toolbox->color_area);
g_signal_connect_object (config, "notify::toolbox-color-area",
G_CALLBACK (toolbox_area_notify),
toolbox->color_area, 0);
toolbox->foo_area = toolbox_create_foo_area (toolbox, context);
gtk_wrap_box_pack (GTK_WRAP_BOX (toolbox->area_wbox), toolbox->foo_area,
TRUE, TRUE, FALSE, TRUE);
if (config->toolbox_foo_area)
gtk_widget_show (toolbox->foo_area);
g_signal_connect_object (config, "notify::toolbox-foo-area",
G_CALLBACK (toolbox_area_notify),
toolbox->foo_area, 0);
toolbox->image_area = toolbox_create_image_area (toolbox, context);
gtk_wrap_box_pack (GTK_WRAP_BOX (toolbox->area_wbox), toolbox->image_area,
TRUE, TRUE, FALSE, TRUE);
if (config->toolbox_image_area)
gtk_widget_show (toolbox->image_area);
g_signal_connect_object (config, "notify::toolbox-image-area",
G_CALLBACK (toolbox_area_notify),
toolbox->image_area, 0);
g_signal_connect_object (context, "tool-changed",
G_CALLBACK (toolbox_tool_changed),
toolbox->tool_wbox,
0);
gimp_toolbox_dnd_init (GIMP_TOOLBOX (toolbox));
gimp_toolbox_style_set (GTK_WIDGET (toolbox), GTK_WIDGET (toolbox)->style);
return object;
}
static gboolean
gimp_toolbox_delete_event (GtkWidget *widget,
GdkEventAny *event)
{
gimp_exit (GIMP_DOCK (widget)->context->gimp, FALSE);
return TRUE;
}
static void
gimp_toolbox_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GimpToolbox *toolbox = GIMP_TOOLBOX (widget);
Gimp *gimp;
GimpGuiConfig *config;
GimpToolInfo *tool_info;
GtkWidget *tool_button;
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
if (! GIMP_DOCK (widget)->context)
return;
gimp = GIMP_DOCK (widget)->context->gimp;
config = GIMP_GUI_CONFIG (gimp->config);
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimp->tool_info_list,
"gimp-rect-select-tool");
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
if (tool_button)
{
GtkRequisition button_requisition;
GList *list;
gint n_tools;
gint tool_rows;
gint tool_columns;
gtk_widget_size_request (tool_button, &button_requisition);
for (list = GIMP_LIST (gimp->tool_info_list)->list, n_tools = 0;
list;
list = list->next)
{
tool_info = (GimpToolInfo *) list->data;
if (tool_info->visible)
n_tools++;
}
tool_columns = MAX (1, (allocation->width / button_requisition.width));
tool_rows = n_tools / tool_columns;
if (n_tools % tool_columns)
tool_rows++;
if (toolbox->tool_rows != tool_rows ||
toolbox->tool_columns != tool_columns)
{
toolbox->tool_rows = tool_rows;
toolbox->tool_columns = tool_columns;
gtk_widget_set_size_request (toolbox->tool_wbox, -1,
tool_rows * button_requisition.height);
}
}
{
GtkRequisition color_requisition;
GtkRequisition foo_requisition;
GtkRequisition image_requisition;
gint width;
gint height;
gint n_areas;
gint area_rows;
gint area_columns;
gtk_widget_size_request (toolbox->color_area, &color_requisition);
gtk_widget_size_request (toolbox->foo_area, &foo_requisition);
gtk_widget_size_request (toolbox->image_area, &image_requisition);
width = MAX (color_requisition.width,
MAX (foo_requisition.width,
image_requisition.width));
height = MAX (color_requisition.height,
MAX (foo_requisition.height,
image_requisition.height));
n_areas = (config->toolbox_color_area +
config->toolbox_foo_area +
config->toolbox_image_area);
area_columns = MAX (1, (allocation->width / width));
area_rows = n_areas / area_columns;
if (n_areas % area_columns)
area_rows++;
if (toolbox->area_rows != area_rows ||
toolbox->area_columns != area_columns)
{
toolbox->area_rows = area_rows;
toolbox->area_columns = area_columns;
gtk_widget_set_size_request (toolbox->area_wbox, -1,
area_rows * height);
}
}
}
static void
gimp_toolbox_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
Gimp *gimp;
GtkIconSize tool_icon_size;
GtkReliefStyle relief;
GList *list;
if (GTK_WIDGET_CLASS (parent_class)->style_set)
GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
if (! GIMP_DOCK (widget)->context)
return;
gimp = GIMP_DOCK (widget)->context->gimp;
gtk_widget_style_get (widget,
"tool_icon_size", &tool_icon_size,
"button_relief", &relief,
NULL);
for (list = GIMP_LIST (gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info = list->data;
GtkWidget *tool_button;
tool_button = g_object_get_data (G_OBJECT (tool_info),
TOOL_BUTTON_DATA_KEY);
if (tool_button)
{
GtkImage *image;
gchar *stock_id;
image = GTK_IMAGE (GTK_BIN (tool_button)->child);
gtk_image_get_stock (image, &stock_id, NULL);
gtk_image_set_from_stock (image, stock_id, tool_icon_size);
gtk_button_set_relief (GTK_BUTTON (tool_button), relief);
}
}
gimp_toolbox_set_geometry (GIMP_TOOLBOX (widget));
}
static void
gimp_toolbox_book_added (GimpDock *dock,
GimpDockbook *dockbook)
{
if (g_list_length (dock->dockbooks) == 1)
gimp_toolbox_set_geometry (GIMP_TOOLBOX (dock));
}
static void
gimp_toolbox_book_removed (GimpDock *dock,
GimpDockbook *dockbook)
{
if (dock->dockbooks == NULL &&
! (GTK_OBJECT_FLAGS (dock) & GTK_IN_DESTRUCTION))
gimp_toolbox_set_geometry (GIMP_TOOLBOX (dock));
}
static void
gimp_toolbox_set_geometry (GimpToolbox *toolbox)
{
Gimp *gimp;
GimpToolInfo *tool_info;
GtkWidget *tool_button;
gimp = GIMP_DOCK (toolbox)->context->gimp;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimp->tool_info_list,
"gimp-rect-select-tool");
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
if (tool_button)
{
GtkWidget *main_vbox;
GtkRequisition menubar_requisition = { 0, 0 };
GtkRequisition button_requisition;
gint border_width;
GdkGeometry geometry;
main_vbox = GIMP_DOCK (toolbox)->main_vbox;
if (toolbox->menu_bar)
gtk_widget_size_request (toolbox->menu_bar, &menubar_requisition);
gtk_widget_size_request (tool_button, &button_requisition);
border_width = gtk_container_get_border_width (GTK_CONTAINER (main_vbox));
geometry.min_width = (2 * border_width +
2 * button_requisition.width);
geometry.min_height = -1;
geometry.width_inc = button_requisition.width;
geometry.height_inc = (GIMP_DOCK (toolbox)->dockbooks ?
1 : button_requisition.height);
gtk_window_set_geometry_hints (GTK_WINDOW (toolbox),
NULL,
&geometry,
GDK_HINT_MIN_SIZE |
GDK_HINT_RESIZE_INC |
GDK_HINT_USER_POS);
}
}
GtkWidget *
gimp_toolbox_new (GimpDialogFactory *dialog_factory,
Gimp *gimp)
{
GimpToolbox *toolbox;
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
toolbox = g_object_new (GIMP_TYPE_TOOLBOX,
"title", _("The GIMP"),
"context", gimp_get_user_context (gimp),
"dialog-factory", dialog_factory,
NULL);
return GTK_WIDGET (toolbox);
}
/* private functions */
static gboolean
gimp_toolbox_button_accel_find_func (GtkAccelKey *key,
GClosure *closure,
gpointer data)
{
return (GClosure *) data == closure;
}
static void
gimp_toolbox_substitute_underscores (gchar *str)
{
gchar *p;
for (p = str; *p; p++)
if (*p == '_')
*p = ' ';
}
static void
gimp_toolbox_button_accel_changed (GtkAccelGroup *accel_group,
guint unused1,
GdkModifierType unused2,
GClosure *accel_closure,
GtkWidget *tool_button)
{
GClosure *button_closure;
button_closure = g_object_get_data (G_OBJECT (tool_button),
"toolbox-accel-closure");
if (accel_closure == button_closure)
{
GimpToolInfo *tool_info;
GtkAccelKey *accel_key;
gchar *tooltip;
tool_info = g_object_get_data (G_OBJECT (tool_button), TOOL_INFO_DATA_KEY);
accel_key = gtk_accel_group_find (accel_group,
gimp_toolbox_button_accel_find_func,
accel_closure);
if (accel_key &&
accel_key->accel_key &&
accel_key->accel_flags & GTK_ACCEL_VISIBLE)
{
/* mostly taken from gtk-2-0/gtk/gtkaccellabel.c:1.46
*/
GtkAccelLabelClass *accel_label_class;
GString *gstring;
gboolean seen_mod = FALSE;
gunichar ch;
accel_label_class = g_type_class_peek (GTK_TYPE_ACCEL_LABEL);
gstring = g_string_new (tool_info->help);
g_string_append (gstring, " ");
if (accel_key->accel_mods & GDK_SHIFT_MASK)
{
g_string_append (gstring, accel_label_class->mod_name_shift);
seen_mod = TRUE;
}
if (accel_key->accel_mods & GDK_CONTROL_MASK)
{
if (seen_mod)
g_string_append (gstring, accel_label_class->mod_separator);
g_string_append (gstring, accel_label_class->mod_name_control);
seen_mod = TRUE;
}
if (accel_key->accel_mods & GDK_MOD1_MASK)
{
if (seen_mod)
g_string_append (gstring, accel_label_class->mod_separator);
g_string_append (gstring, accel_label_class->mod_name_alt);
seen_mod = TRUE;
}
if (seen_mod)
g_string_append (gstring, accel_label_class->mod_separator);
ch = gdk_keyval_to_unicode (accel_key->accel_key);
if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
(ch < 0x80 || accel_label_class->latin1_to_char))
{
switch (ch)
{
case ' ':
g_string_append (gstring, "Space");
break;
case '\\':
g_string_append (gstring, "Backslash");
break;
default:
g_string_append_unichar (gstring, g_unichar_toupper (ch));
break;
}
}
else
{
gchar *tmp;
tmp = gtk_accelerator_name (accel_key->accel_key, 0);
if (tmp[0] != 0 && tmp[1] == 0)
tmp[0] = g_ascii_toupper (tmp[0]);
gimp_toolbox_substitute_underscores (tmp);
g_string_append (gstring, tmp);
g_free (tmp);
}
tooltip = g_string_free (gstring, FALSE);
}
else
{
tooltip = g_strdup (tool_info->help);
}
gimp_help_set_help_data (tool_button, tooltip, tool_info->help_id);
g_free (tooltip);
}
}
static void
toolbox_create_tools (GimpToolbox *toolbox,
GimpContext *context)
{
GimpUIManager *ui_manager;
GimpToolInfo *active_tool;
GList *list;
GSList *group = NULL;
ui_manager = gimp_ui_managers_from_name ("<Image>")->data;
if (ui_manager)
gimp_ui_manager_ui_get (ui_manager, "/dummy-menubar");
active_tool = gimp_context_get_tool (context);
for (list = GIMP_LIST (context->gimp->tool_info_list)->list;
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info;
GtkWidget *button;
GtkWidget *image;
const gchar *stock_id;
tool_info = (GimpToolInfo *) list->data;
button = gtk_radio_button_new (group);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
gtk_wrap_box_pack (GTK_WRAP_BOX (toolbox->tool_wbox), button,
FALSE, FALSE, FALSE, FALSE);
if (tool_info->visible)
gtk_widget_show (button);
g_signal_connect_object (tool_info, "notify::visible",
G_CALLBACK (toolbox_tool_visible_notify),
button, 0);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);
g_object_set_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY, button);
g_object_set_data (G_OBJECT (button), TOOL_INFO_DATA_KEY, tool_info);
if (tool_info == active_tool)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_signal_connect (button, "toggled",
G_CALLBACK (toolbox_tool_button_toggled),
tool_info);
g_signal_connect (button, "button_press_event",
G_CALLBACK (toolbox_tool_button_press),
toolbox);
if (ui_manager)
{
GtkAction *action;
const gchar *identifier;
gchar *tmp;
gchar *name;
GClosure *accel_closure = NULL;
identifier = gimp_object_get_name (GIMP_OBJECT (tool_info));
tmp = g_strndup (identifier + strlen ("gimp-"),
strlen (identifier) - strlen ("gimp--tool"));
name = g_strdup_printf ("tools-%s", tmp);
g_free (tmp);
action = gimp_ui_manager_find_action (ui_manager, "tools", name);
g_free (name);
#if HAVE_GTK_ACTION_GET_ACCEL_CLOSURE
accel_closure = gtk_action_get_accel_closure (action);
#else
{
GSList *list;
for (list = gtk_action_get_proxies (action);
list;
list = g_slist_next (list))
{
if (GTK_IS_MENU_ITEM (list->data))
{
GtkWidget *label = GTK_BIN (list->data)->child;
if (GTK_IS_ACCEL_LABEL (label))
{
g_object_get (label,
"accel-closure", &accel_closure,
NULL);
if (accel_closure)
break;
}
}
}
}
#endif
if (accel_closure)
{
GtkAccelGroup *accel_group;
g_object_set_data (G_OBJECT (button), "toolbox-accel-closure",
accel_closure);
accel_group =
gtk_accel_group_from_accel_closure (accel_closure);
g_signal_connect_object (accel_group, "accel_changed",
G_CALLBACK (gimp_toolbox_button_accel_changed),
button, 0);
gimp_toolbox_button_accel_changed (accel_group,
0, 0,
accel_closure,
button);
}
else
{
gimp_help_set_help_data (button,
tool_info->help, tool_info->help_id);
}
}
}
g_signal_connect_object (context->gimp->tool_info_list, "reorder",
G_CALLBACK (toolbox_tool_reorder),
toolbox->tool_wbox, 0);
}
static GtkWidget *
toolbox_create_color_area (GimpToolbox *toolbox,
GimpContext *context)
{
GtkWidget *frame;
GtkWidget *alignment;
GtkWidget *col_area;
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
gtk_container_add (GTK_CONTAINER (frame), alignment);
gtk_widget_show (alignment);
gimp_help_set_help_data (alignment, NULL, GIMP_HELP_TOOLBOX_COLOR_AREA);
col_area = gimp_toolbox_color_area_create (toolbox, 54, 42);
gtk_container_add (GTK_CONTAINER (alignment), col_area);
gtk_widget_show (col_area);
gimp_help_set_help_data
(col_area, _("Foreground & background colors. The black and white squares "
"reset colors. The arrows swap colors. Double click to open "
"the color selection dialog."), NULL);
return frame;
}
static GtkWidget *
toolbox_create_foo_area (GimpToolbox *toolbox,
GimpContext *context)
{
GtkWidget *frame;
GtkWidget *alignment;
GtkWidget *foo_area;
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
gtk_container_add (GTK_CONTAINER (frame), alignment);
gtk_widget_show (alignment);
gimp_help_set_help_data (alignment, NULL, GIMP_HELP_TOOLBOX_INDICATOR_AREA);
foo_area = gimp_toolbox_indicator_area_create (toolbox);
gtk_container_add (GTK_CONTAINER (alignment), foo_area);
gtk_widget_show (foo_area);
return frame;
}
static GtkWidget *
toolbox_create_image_area (GimpToolbox *toolbox,
GimpContext *context)
{
GtkWidget *frame;
GtkWidget *alignment;
GtkWidget *image_area;
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
gtk_container_add (GTK_CONTAINER (frame), alignment);
gtk_widget_show (alignment);
gimp_help_set_help_data (alignment, NULL, GIMP_HELP_TOOLBOX_IMAGE_AREA);
image_area = gimp_toolbox_image_area_create (toolbox, 52, 42);
gtk_container_add (GTK_CONTAINER (alignment), image_area);
gtk_widget_show (image_area);
return frame;
}
static void
toolbox_area_notify (GimpGuiConfig *config,
GParamSpec *pspec,
GtkWidget *area)
{
gboolean visible;
if (config->toolbox_color_area ||
config->toolbox_foo_area ||
config->toolbox_image_area)
{
GtkRequisition req;
gtk_widget_show (area->parent);
/* HACK HACK HACK */
gtk_widget_size_request (area, &req);
gtk_widget_set_size_request (area->parent, req.width, req.height);
}
else
{
gtk_widget_hide (area->parent);
gtk_widget_set_size_request (area->parent, -1, -1);
}
g_object_get (config, pspec->name, &visible, NULL);
g_object_set (area, "visible", visible, NULL);
}
static void
toolbox_tool_changed (GimpContext *context,
GimpToolInfo *tool_info,
gpointer data)
{
if (tool_info)
{
GtkWidget *toolbox_button = g_object_get_data (G_OBJECT (tool_info),
TOOL_BUTTON_DATA_KEY);
if (toolbox_button && ! GTK_TOGGLE_BUTTON (toolbox_button)->active)
{
g_signal_handlers_block_by_func (toolbox_button,
toolbox_tool_button_toggled,
tool_info);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toolbox_button),
TRUE);
g_signal_handlers_unblock_by_func (toolbox_button,
toolbox_tool_button_toggled,
tool_info);
}
}
}
static void
toolbox_tool_reorder (GimpContainer *container,
GimpToolInfo *tool_info,
gint index,
GtkWidget *wrap_box)
{
if (tool_info)
{
GtkWidget *button = g_object_get_data (G_OBJECT (tool_info),
TOOL_BUTTON_DATA_KEY);
gtk_wrap_box_reorder_child (GTK_WRAP_BOX (wrap_box), button, index);
}
}
static void
toolbox_tool_visible_notify (GimpToolInfo *tool_info,
GParamSpec *pspec,
GtkWidget *button)
{
if (tool_info->visible)
gtk_widget_show (button);
else
gtk_widget_hide (button);
}
static void
toolbox_tool_button_toggled (GtkWidget *widget,
GimpToolInfo *tool_info)
{
if (GTK_TOGGLE_BUTTON (widget)->active)
gimp_context_set_tool (gimp_get_user_context (tool_info->gimp), tool_info);
}
static gboolean
toolbox_tool_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpToolbox *toolbox)
{
if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1))
{
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toolbox)->dialog_factory,
gtk_widget_get_screen (widget),
"gimp-tool-options",
-1);
}
return FALSE;
}
static gboolean
toolbox_check_device (GtkWidget *widget,
GdkEvent *event,
Gimp *gimp)
{
gimp_devices_check_change (gimp, event);
return FALSE;
}
|