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
|
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */
/**
* gdl-dock-item-grip.c
*
* Based on bonobo-dock-item-grip. Original copyright notice follows.
*
* Author:
* Michael Meeks
*
* Copyright (C) 2002 Sun Microsystems, Inc.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "gdl-i18n.h"
#include <string.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gdl-dock-item.h"
#include "gdl-dock-item-grip.h"
#include "gdl-stock.h"
#include "gdl-tools.h"
#define ALIGN_BORDER 5
enum {
PROP_0,
PROP_ITEM
};
struct _GdlDockItemGripPrivate {
GtkWidget *close_button;
GtkWidget *iconify_button;
GtkTooltips *tooltips;
gboolean icon_pixbuf_valid;
GdkPixbuf *icon_pixbuf;
gchar *title;
PangoLayout *title_layout;
};
GDL_CLASS_BOILERPLATE (GdlDockItemGrip, gdl_dock_item_grip,
GtkContainer, GTK_TYPE_CONTAINER);
/* must be called after size_allocate */
static void
gdl_dock_item_grip_get_title_area (GdlDockItemGrip *grip,
GdkRectangle *area)
{
GtkWidget *widget = GTK_WIDGET (grip);
gint border = GTK_CONTAINER (grip)->border_width;
gint alloc_height;
area->width = (widget->allocation.width - 2 * border - ALIGN_BORDER);
pango_layout_get_pixel_size (grip->_priv->title_layout, NULL, &alloc_height);
alloc_height = MAX (grip->_priv->close_button->allocation.height, alloc_height);
alloc_height = MAX (grip->_priv->iconify_button->allocation.height, alloc_height);
if (GTK_WIDGET_VISIBLE (grip->_priv->close_button)) {
area->width -= grip->_priv->close_button->allocation.width;
}
if (GTK_WIDGET_VISIBLE (grip->_priv->iconify_button)) {
area->width -= grip->_priv->iconify_button->allocation.width;
}
area->x = widget->allocation.x + border + ALIGN_BORDER;
area->y = widget->allocation.y + border;
area->height = alloc_height;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
area->x += (widget->allocation.width - 2 * border) - area->width;
}
static void
ensure_title_and_icon_pixbuf (GdlDockItemGrip *grip)
{
gchar *stock_id;
GdkPixbuf *pixbuf;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (grip));
/* get long name property from the dock object */
if (!grip->_priv->title) {
g_object_get (G_OBJECT (grip->item), "long-name", &grip->_priv->title, NULL);
if (!grip->_priv->title)
grip->_priv->title = g_strdup ("");
}
/* retrieve stock pixbuf, if any */
if (!grip->_priv->icon_pixbuf_valid) {
g_object_get (G_OBJECT (grip->item), "stock-id", &stock_id, NULL);
if (stock_id) {
grip->_priv->icon_pixbuf = gtk_widget_render_icon (GTK_WIDGET (grip),
stock_id,
GTK_ICON_SIZE_MENU, "");
g_free (stock_id);
grip->_priv->icon_pixbuf_valid = TRUE;
}
}
/* retrieve pixbuf icon, if any */
if (!grip->_priv->icon_pixbuf_valid) {
g_object_get (G_OBJECT (grip->item), "pixbuf-icon", &pixbuf, NULL);
if (pixbuf) {
grip->_priv->icon_pixbuf = pixbuf;
grip->_priv->icon_pixbuf_valid = TRUE;
}
}
/* create layout: the actual text is reset at size_allocate */
if (!grip->_priv->title_layout) {
grip->_priv->title_layout = gtk_widget_create_pango_layout (GTK_WIDGET (grip),
grip->_priv->title);
pango_layout_set_single_paragraph_mode (grip->_priv->title_layout, TRUE);
}
}
static gint
gdl_dock_item_grip_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GdlDockItemGrip *grip;
GdkRectangle title_area;
GdkRectangle expose_area;
GtkStyle *bg_style;
gint layout_width;
gint layout_height;
gint text_x;
gint text_y;
gboolean item_or_child_has_focus;
grip = GDL_DOCK_ITEM_GRIP (widget);
gdl_dock_item_grip_get_title_area (grip, &title_area);
/* draw background, highlight it if the dock item or any of its
* descendants have focus */
bg_style = (gdl_dock_item_or_child_has_focus (grip->item) ?
gtk_widget_get_style (widget)->dark_gc[widget->state] :
gtk_widget_get_style (widget)->mid_gc[widget->state]);
gdk_draw_rectangle (GDK_DRAWABLE (widget->window), bg_style, TRUE,
1, 0, widget->allocation.width - 1, widget->allocation.height);
if (grip->_priv->icon_pixbuf) {
GdkRectangle pixbuf_rect;
pixbuf_rect.width = gdk_pixbuf_get_width (grip->_priv->icon_pixbuf);
pixbuf_rect.height = gdk_pixbuf_get_height (grip->_priv->icon_pixbuf);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) {
pixbuf_rect.x = title_area.x + title_area.width - pixbuf_rect.width;
} else {
pixbuf_rect.x = title_area.x;
title_area.x += pixbuf_rect.width + 1;
}
/* shrink title area by the pixbuf width plus a 1px spacing */
title_area.width -= pixbuf_rect.width + 1;
pixbuf_rect.y = title_area.y + (title_area.height - pixbuf_rect.height) / 2;
if (gdk_rectangle_intersect (&event->area, &pixbuf_rect, &expose_area)) {
GdkGC *gc;
GtkStyle *style;
style = gtk_widget_get_style (widget);
gc = style->bg_gc[widget->state];
gdk_draw_pixbuf (GDK_DRAWABLE (widget->window), gc,
grip->_priv->icon_pixbuf,
0, 0, pixbuf_rect.x, pixbuf_rect.y,
pixbuf_rect.width, pixbuf_rect.height,
GDK_RGB_DITHER_NONE, 0, 0);
}
}
if (gdk_rectangle_intersect (&title_area, &event->area, &expose_area)) {
pango_layout_get_pixel_size (grip->_priv->title_layout, &layout_width,
&layout_height);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
text_x = title_area.x + title_area.width - layout_width;
else
text_x = title_area.x;
text_y = title_area.y + (title_area.height - layout_height) / 2;
gtk_paint_layout (widget->style, widget->window, widget->state, TRUE,
&expose_area, widget, NULL, text_x, text_y,
grip->_priv->title_layout);
}
return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
}
static void
gdl_dock_item_grip_item_notify (GObject *master,
GParamSpec *pspec,
gpointer data)
{
GdlDockItemGrip *grip;
gboolean cursor;
grip = GDL_DOCK_ITEM_GRIP (data);
if (strcmp (pspec->name, "stock-id") == 0) {
if (grip->_priv->icon_pixbuf) {
g_object_unref (grip->_priv->icon_pixbuf);
grip->_priv->icon_pixbuf = NULL;
}
grip->_priv->icon_pixbuf_valid = FALSE;
ensure_title_and_icon_pixbuf (grip);
} else if (strcmp (pspec->name, "long-name") == 0) {
g_free (grip->_priv->title);
g_object_unref (grip->_priv->title_layout);
grip->_priv->title_layout = NULL;
grip->_priv->title = NULL;
ensure_title_and_icon_pixbuf (grip);
gtk_widget_queue_draw (GTK_WIDGET (grip));
} else if (strcmp (pspec->name, "behavior") == 0) {
cursor = FALSE;
if (grip->_priv->close_button) {
if (GDL_DOCK_ITEM_CANT_CLOSE (grip->item)) {
gtk_widget_hide (GTK_WIDGET (grip->_priv->close_button));
} else {
gtk_widget_show (GTK_WIDGET (grip->_priv->close_button));
cursor = TRUE;
}
}
if (grip->_priv->iconify_button) {
if (GDL_DOCK_ITEM_CANT_ICONIFY (grip->item)) {
gtk_widget_hide (GTK_WIDGET (grip->_priv->iconify_button));
} else {
gtk_widget_show (GTK_WIDGET (grip->_priv->iconify_button));
cursor = TRUE;
}
}
if (grip->title_window && !cursor)
gdk_window_set_cursor (grip->title_window, NULL);
}
}
static void
gdl_dock_item_grip_destroy (GtkObject *object)
{
GdlDockItemGrip *grip = GDL_DOCK_ITEM_GRIP (object);
if (grip->_priv) {
GdlDockItemGripPrivate *priv = grip->_priv;
if (priv->title_layout) {
g_object_unref (priv->title_layout);
priv->title_layout = NULL;
}
g_free (priv->title);
priv->title = NULL;
if (priv->icon_pixbuf) {
g_object_unref (priv->icon_pixbuf);
priv->icon_pixbuf = NULL;
}
if (priv->tooltips) {
g_object_unref (priv->tooltips);
priv->tooltips = NULL;
}
if (grip->item)
g_signal_handlers_disconnect_by_func (grip->item,
gdl_dock_item_grip_item_notify,
grip);
grip->item = NULL;
grip->_priv = NULL;
g_free (priv);
}
GDL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
static void
gdl_dock_item_grip_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GdlDockItemGrip *grip;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (object));
grip = GDL_DOCK_ITEM_GRIP (object);
switch (prop_id) {
case PROP_ITEM:
grip->item = g_value_get_object (value);
if (grip->item) {
g_signal_connect (grip->item, "notify::long_name",
G_CALLBACK (gdl_dock_item_grip_item_notify),
grip);
g_signal_connect (grip->item, "notify::stock_id",
G_CALLBACK (gdl_dock_item_grip_item_notify),
grip);
g_signal_connect (grip->item, "notify::behavior",
G_CALLBACK (gdl_dock_item_grip_item_notify),
grip);
if (!GDL_DOCK_ITEM_CANT_CLOSE (grip->item) && grip->_priv->close_button)
gtk_widget_show (grip->_priv->close_button);
if (!GDL_DOCK_ITEM_CANT_ICONIFY (grip->item) && grip->_priv->iconify_button)
gtk_widget_show (grip->_priv->iconify_button);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gdl_dock_item_grip_close_clicked (GtkWidget *widget,
GdlDockItemGrip *grip)
{
g_return_if_fail (grip->item != NULL);
gdl_dock_item_hide_item (grip->item);
}
static void
gdl_dock_item_grip_iconify_clicked (GtkWidget *widget,
GdlDockItemGrip *grip)
{
g_return_if_fail (grip->item != NULL);
gdl_dock_item_iconify_item (grip->item);
/* Workaround to unhighlight the iconify button. */
GTK_BUTTON (grip->_priv->iconify_button)->in_button = FALSE;
gtk_button_leave (GTK_BUTTON (grip->_priv->iconify_button));
}
static void
gdl_dock_item_grip_instance_init (GdlDockItemGrip *grip)
{
GtkWidget *image;
GTK_WIDGET_SET_FLAGS (grip, GTK_NO_WINDOW);
grip->_priv = g_new0 (GdlDockItemGripPrivate, 1);
grip->_priv->icon_pixbuf_valid = FALSE;
grip->_priv->icon_pixbuf = NULL;
grip->_priv->title_layout = NULL;
gtk_widget_push_composite_child ();
grip->_priv->close_button = gtk_button_new ();
gtk_widget_pop_composite_child ();
GTK_WIDGET_UNSET_FLAGS (grip->_priv->close_button, GTK_CAN_FOCUS);
gtk_widget_set_parent (grip->_priv->close_button, GTK_WIDGET (grip));
gtk_button_set_relief (GTK_BUTTON (grip->_priv->close_button), GTK_RELIEF_NONE);
gtk_widget_show (grip->_priv->close_button);
image = gtk_image_new_from_stock (GDL_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (grip->_priv->close_button), image);
gtk_widget_show (image);
g_signal_connect (G_OBJECT (grip->_priv->close_button), "clicked",
G_CALLBACK (gdl_dock_item_grip_close_clicked), grip);
gtk_widget_push_composite_child ();
grip->_priv->iconify_button = gtk_button_new ();
gtk_widget_pop_composite_child ();
GTK_WIDGET_UNSET_FLAGS (grip->_priv->iconify_button, GTK_CAN_FOCUS);
gtk_widget_set_parent (grip->_priv->iconify_button, GTK_WIDGET (grip));
gtk_button_set_relief (GTK_BUTTON (grip->_priv->iconify_button), GTK_RELIEF_NONE);
gtk_widget_show (grip->_priv->iconify_button);
image = gtk_image_new_from_stock (GDL_STOCK_MENU_RIGHT, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (grip->_priv->iconify_button), image);
gtk_widget_show (image);
g_signal_connect (G_OBJECT (grip->_priv->iconify_button), "clicked",
G_CALLBACK (gdl_dock_item_grip_iconify_clicked), grip);
grip->_priv->tooltips = gtk_tooltips_new ();
g_object_ref (grip->_priv->tooltips);
gtk_object_sink (GTK_OBJECT (grip->_priv->tooltips));
gtk_tooltips_set_tip (grip->_priv->tooltips, grip->_priv->iconify_button,
_("Iconify"), _("Iconify this dock"));
gtk_tooltips_set_tip (grip->_priv->tooltips, grip->_priv->close_button,
_("Close"), _("Close this dock"));
}
static void
gdl_dock_item_grip_realize (GtkWidget *widget)
{
GdlDockItemGrip *grip = GDL_DOCK_ITEM_GRIP (widget);
GTK_WIDGET_CLASS (parent_class)->realize (widget);
if (!grip->title_window) {
GdkWindowAttr attributes;
GdkRectangle area;
GdkCursor *cursor;
ensure_title_and_icon_pixbuf (grip);
gdl_dock_item_grip_get_title_area (grip, &area);
attributes.x = area.x;
attributes.y = area.y;
attributes.width = area.width;
attributes.height = area.height;
attributes.window_type = GDK_WINDOW_TEMP;
attributes.wclass = GDK_INPUT_ONLY;
attributes.override_redirect = TRUE;
attributes.event_mask = (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON_MOTION_MASK |
gtk_widget_get_events (widget));
grip->title_window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes,
(GDK_WA_X |
GDK_WA_Y |
GDK_WA_NOREDIR));
gdk_window_set_user_data (grip->title_window, widget);
if (GDL_DOCK_ITEM_CANT_CLOSE (grip->item))
cursor = NULL;
else if (GDL_DOCK_ITEM_CANT_ICONIFY (grip->item))
cursor = NULL;
else
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
GDK_HAND2);
gdk_window_set_cursor (grip->title_window, cursor);
if (cursor)
gdk_cursor_unref (cursor);
}
}
static void
gdl_dock_item_grip_unrealize (GtkWidget *widget)
{
GdlDockItemGrip *grip = GDL_DOCK_ITEM_GRIP (widget);
if (grip->title_window) {
gdk_window_set_user_data (grip->title_window, NULL);
gdk_window_destroy (grip->title_window);
grip->title_window = NULL;
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
static void
gdl_dock_item_grip_map (GtkWidget *widget)
{
GdlDockItemGrip *grip = GDL_DOCK_ITEM_GRIP (widget);
GTK_WIDGET_CLASS (parent_class)->map (widget);
if (grip->title_window)
gdk_window_show (grip->title_window);
}
static void
gdl_dock_item_grip_unmap (GtkWidget *widget)
{
GdlDockItemGrip *grip = GDL_DOCK_ITEM_GRIP (widget);
if (grip->title_window)
gdk_window_hide (grip->title_window);
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
}
static void
gdl_dock_item_grip_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkRequisition child_requisition;
GtkContainer *container;
GdlDockItemGrip *grip;
gint layout_height;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
g_return_if_fail (requisition != NULL);
container = GTK_CONTAINER (widget);
grip = GDL_DOCK_ITEM_GRIP (widget);
requisition->width = container->border_width * 2 + ALIGN_BORDER;
requisition->height = container->border_width * 2;
ensure_title_and_icon_pixbuf (grip);
pango_layout_get_pixel_size (grip->_priv->title_layout, NULL, &layout_height);
gtk_widget_size_request (grip->_priv->close_button, &child_requisition);
requisition->width += child_requisition.width;
layout_height = MAX (layout_height, child_requisition.height);
gtk_widget_size_request (grip->_priv->iconify_button, &child_requisition);
requisition->width += child_requisition.width;
layout_height = MAX (layout_height, child_requisition.height);
requisition->height += layout_height;
if (grip->_priv->icon_pixbuf) {
requisition->width += gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
}
}
#define ELLIPSIS "..."
static void
ellipsize_layout (PangoLayout *layout, gint width)
{
PangoLayoutLine *line;
PangoLayout *ell;
gint h, w, ell_w, x;
GString *text;
if (width <= 0) {
pango_layout_set_text (layout, "", -1);
return;
}
pango_layout_get_pixel_size (layout, &w, &h);
if (w <= width) return;
/* calculate ellipsis width */
ell = pango_layout_copy (layout);
pango_layout_set_text (ell, ELLIPSIS, -1);
pango_layout_get_pixel_size (ell, &ell_w, NULL);
g_object_unref (ell);
if (width < ell_w) {
/* not even ellipsis fits, so hide the text */
pango_layout_set_text (layout, "", -1);
return;
}
/* shrink total available width by the width of the ellipsis */
width -= ell_w;
line = pango_layout_get_line (layout, 0);
text = g_string_new (pango_layout_get_text (layout));
if (pango_layout_line_x_to_index (line, width * PANGO_SCALE, &x, NULL)) {
g_string_set_size (text, x);
g_string_append (text, ELLIPSIS);
pango_layout_set_text (layout, text->str, -1);
}
g_string_free (text, TRUE);
}
static void
gdl_dock_item_grip_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GdlDockItemGrip *grip;
GtkContainer *container;
GtkRequisition button_requisition = { 0, };
GtkAllocation child_allocation;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
g_return_if_fail (allocation != NULL);
grip = GDL_DOCK_ITEM_GRIP (widget);
container = GTK_CONTAINER (widget);
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x = allocation->x + container->border_width + ALIGN_BORDER;
else
child_allocation.x = allocation->x + allocation->width - container->border_width;
child_allocation.y = allocation->y + container->border_width;
gtk_widget_size_request (grip->_priv->close_button, &button_requisition);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL)
child_allocation.x -= button_requisition.width;
child_allocation.width = button_requisition.width;
child_allocation.height = button_requisition.height;
gtk_widget_size_allocate (grip->_priv->close_button, &child_allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x += button_requisition.width;
gtk_widget_size_request (grip->_priv->iconify_button, &button_requisition);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL)
child_allocation.x -= button_requisition.width;
child_allocation.width = button_requisition.width;
child_allocation.height = button_requisition.height;
gtk_widget_size_allocate (grip->_priv->iconify_button, &child_allocation);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x += button_requisition.width;
if (grip->title_window) {
GdkRectangle area;
/* set layout text */
ensure_title_and_icon_pixbuf (grip);
pango_layout_set_text (grip->_priv->title_layout, grip->_priv->title, -1);
gdl_dock_item_grip_get_title_area (grip, &area);
gdk_window_move_resize (grip->title_window,
area.x, area.y, area.width, area.height);
if (grip->_priv->icon_pixbuf)
area.width -= gdk_pixbuf_get_width (grip->_priv->icon_pixbuf) + 1;
/* ellipsize title if it doesn't fit the title area */
ellipsize_layout (grip->_priv->title_layout, area.width);
}
}
static void
gdl_dock_item_grip_add (GtkContainer *container,
GtkWidget *widget)
{
g_warning ("gtk_container_add not implemented for GdlDockItemGrip");
}
static void
gdl_dock_item_grip_remove (GtkContainer *container,
GtkWidget *widget)
{
g_warning ("gtk_container_remove not implemented for GdlDockItemGrip");
}
static void
gdl_dock_item_grip_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
GdlDockItemGrip *grip;
g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (container));
grip = GDL_DOCK_ITEM_GRIP (container);
if (include_internals) {
(* callback) (grip->_priv->close_button, callback_data);
(* callback) (grip->_priv->iconify_button, callback_data);
}
}
static GtkType
gdl_dock_item_grip_child_type (GtkContainer *container)
{
return G_TYPE_NONE;
}
static void
gdl_dock_item_grip_class_init (GdlDockItemGripClass *klass)
{
GObjectClass *gobject_class;
GtkObjectClass *gtk_object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gtk_object_class = GTK_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
container_class = GTK_CONTAINER_CLASS (klass);
gobject_class->set_property = gdl_dock_item_grip_set_property;
gtk_object_class->destroy = gdl_dock_item_grip_destroy;
widget_class->expose_event = gdl_dock_item_grip_expose;
widget_class->realize = gdl_dock_item_grip_realize;
widget_class->unrealize = gdl_dock_item_grip_unrealize;
widget_class->map = gdl_dock_item_grip_map;
widget_class->unmap = gdl_dock_item_grip_unmap;
widget_class->size_request = gdl_dock_item_grip_size_request;
widget_class->size_allocate = gdl_dock_item_grip_size_allocate;
container_class->add = gdl_dock_item_grip_add;
container_class->remove = gdl_dock_item_grip_remove;
container_class->forall = gdl_dock_item_grip_forall;
container_class->child_type = gdl_dock_item_grip_child_type;
g_object_class_install_property (
gobject_class, PROP_ITEM,
g_param_spec_object ("item", _("Controlling dock item"),
_("Dockitem which 'owns' this grip"),
GDL_TYPE_DOCK_ITEM,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
/* initialize stock images */
gdl_stock_init ();
}
GtkWidget *
gdl_dock_item_grip_new (GdlDockItem *item)
{
GdlDockItemGrip *grip = g_object_new (GDL_TYPE_DOCK_ITEM_GRIP, "item", item,
NULL);
return GTK_WIDGET (grip);
}
|