gimptoolwidgetgroup.c 28.8 KB
Newer Older
Ell's avatar
Ell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimptoolwidgetgroup.c
 * Copyright (C) 2018 Ell
 *
 * 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 3 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
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
Ell's avatar
Ell committed
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
 */

#include "config.h"

#include <gegl.h>
#include <gtk/gtk.h>

#include "display-types.h"

#include "core/gimpcontainer.h"
#include "core/gimplist.h"

#include "gimpcanvasgroup.h"
#include "gimpdisplayshell.h"
#include "gimptoolwidgetgroup.h"


struct _GimpToolWidgetGroupPrivate
{
  GimpContainer  *children;

  GimpToolWidget *focus_widget;
  GimpToolWidget *hover_widget;

  gboolean        auto_raise;
};


/*  local function prototypes  */

static void             gimp_tool_widget_group_finalize            (GObject               *object);

static void             gimp_tool_widget_group_focus_changed       (GimpToolWidget        *widget);
static gint             gimp_tool_widget_group_button_press        (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    guint32                time,
                                                                    GdkModifierType        state,
                                                                    GimpButtonPressType    press_type);
static void             gimp_tool_widget_group_button_release      (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    guint32                time,
                                                                    GdkModifierType        state,
                                                                    GimpButtonReleaseType  release_type);
static void             gimp_tool_widget_group_motion              (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    guint32                time,
                                                                    GdkModifierType        state);
static GimpHit          gimp_tool_widget_group_hit                 (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    GdkModifierType        state,
                                                                    gboolean               proximity);
static void             gimp_tool_widget_group_hover               (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    GdkModifierType        state,
                                                                    gboolean               proximity);
static void             gimp_tool_widget_group_leave_notify        (GimpToolWidget        *widget);
static gboolean         gimp_tool_widget_group_key_press           (GimpToolWidget        *widget,
                                                                    GdkEventKey           *kevent);
static gboolean         gimp_tool_widget_group_key_release         (GimpToolWidget        *widget,
                                                                    GdkEventKey           *kevent);
static void             gimp_tool_widget_group_motion_modifier     (GimpToolWidget        *widget,
                                                                    GdkModifierType        key,
                                                                    gboolean               press,
                                                                    GdkModifierType        state);
static void             gimp_tool_widget_group_hover_modifier      (GimpToolWidget        *widget,
                                                                    GdkModifierType        key,
                                                                    gboolean               press,
                                                                    GdkModifierType        state);
static gboolean         gimp_tool_widget_group_get_cursor          (GimpToolWidget        *widget,
                                                                    const GimpCoords      *coords,
                                                                    GdkModifierType        state,
                                                                    GimpCursorType        *cursor,
                                                                    GimpToolCursorType    *tool_cursor,
                                                                    GimpCursorModifier    *modifier);

static void             gimp_tool_widget_group_children_add        (GimpContainer         *container,
                                                                    GimpToolWidget        *child,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_children_remove     (GimpContainer         *container,
                                                                    GimpToolWidget        *child,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_children_reorder    (GimpContainer         *container,
                                                                    GimpToolWidget        *child,
                                                                    gint                   new_index,
                                                                    GimpToolWidgetGroup   *group);

static void             gimp_tool_widget_group_child_changed       (GimpToolWidget        *child,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_child_response      (GimpToolWidget        *child,
                                                                    gint                   response_id,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_child_snap_offsets  (GimpToolWidget        *child,
                                                                    gint                   offset_x,
                                                                    gint                   offset_y,
                                                                    gint                   width,
                                                                    gint                   height,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_child_status        (GimpToolWidget        *child,
                                                                    const gchar           *status,
                                                                    GimpToolWidgetGroup   *group);
static void             gimp_tool_widget_group_child_status_coords (GimpToolWidget        *child,
                                                                    const gchar           *title,
                                                                    gdouble                x,
                                                                    const gchar           *separator,
                                                                    gdouble                y,
                                                                    const gchar           *help,
                                                                    GimpToolWidgetGroup   *group);
126 127 128
static void             gimp_tool_widget_group_child_message       (GimpToolWidget        *child,
                                                                    const gchar           *message,
                                                                    GimpToolWidgetGroup   *group);
Ell's avatar
Ell committed
129 130 131 132 133 134 135 136 137 138
static void             gimp_tool_widget_group_child_focus_changed (GimpToolWidget        *child,
                                                                    GimpToolWidgetGroup   *group);

static GimpToolWidget * gimp_tool_widget_group_get_hover_widget    (GimpToolWidgetGroup   *group,
                                                                    const GimpCoords      *coords,
                                                                    GdkModifierType        state,
                                                                    gboolean               proximity,
                                                                    GimpHit               *hit);


139 140
G_DEFINE_TYPE_WITH_PRIVATE (GimpToolWidgetGroup, gimp_tool_widget_group,
                            GIMP_TYPE_TOOL_WIDGET)
Ell's avatar
Ell committed
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

#define parent_class gimp_tool_widget_group_parent_class


/*  priv functions  */


static void
gimp_tool_widget_group_class_init (GimpToolWidgetGroupClass *klass)
{
  GObjectClass        *object_class = G_OBJECT_CLASS (klass);
  GimpToolWidgetClass *widget_class = GIMP_TOOL_WIDGET_CLASS (klass);

  object_class->finalize        = gimp_tool_widget_group_finalize;

  widget_class->focus_changed   = gimp_tool_widget_group_focus_changed;
  widget_class->button_press    = gimp_tool_widget_group_button_press;
  widget_class->button_release  = gimp_tool_widget_group_button_release;
  widget_class->motion          = gimp_tool_widget_group_motion;
  widget_class->hit             = gimp_tool_widget_group_hit;
  widget_class->hover           = gimp_tool_widget_group_hover;
  widget_class->leave_notify    = gimp_tool_widget_group_leave_notify;
  widget_class->key_press       = gimp_tool_widget_group_key_press;
  widget_class->key_release     = gimp_tool_widget_group_key_release;
  widget_class->motion_modifier = gimp_tool_widget_group_motion_modifier;
  widget_class->hover_modifier  = gimp_tool_widget_group_hover_modifier;
  widget_class->get_cursor      = gimp_tool_widget_group_get_cursor;
}

static void
gimp_tool_widget_group_init (GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv;

175
  priv = group->priv = gimp_tool_widget_group_get_instance_private (group);
Ell's avatar
Ell committed
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

  priv->children = g_object_new (GIMP_TYPE_LIST,
                                 "children-type", GIMP_TYPE_TOOL_WIDGET,
                                 "append",        TRUE,
                                 NULL);

  g_signal_connect (priv->children, "add",
                    G_CALLBACK (gimp_tool_widget_group_children_add),
                    group);
  g_signal_connect (priv->children, "remove",
                    G_CALLBACK (gimp_tool_widget_group_children_remove),
                    group);
  g_signal_connect (priv->children, "reorder",
                    G_CALLBACK (gimp_tool_widget_group_children_reorder),
                    group);

  gimp_container_add_handler (priv->children, "changed",
                              G_CALLBACK (gimp_tool_widget_group_child_changed),
                              group);
  gimp_container_add_handler (priv->children, "response",
                              G_CALLBACK (gimp_tool_widget_group_child_response),
                              group);
  gimp_container_add_handler (priv->children, "snap-offsets",
                              G_CALLBACK (gimp_tool_widget_group_child_snap_offsets),
                              group);
  gimp_container_add_handler (priv->children, "status",
                              G_CALLBACK (gimp_tool_widget_group_child_status),
                              group);
  gimp_container_add_handler (priv->children, "status-coords",
                              G_CALLBACK (gimp_tool_widget_group_child_status_coords),
                              group);
207 208 209
  gimp_container_add_handler (priv->children, "message",
                              G_CALLBACK (gimp_tool_widget_group_child_message),
                              group);
Ell's avatar
Ell committed
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
  gimp_container_add_handler (priv->children, "focus-changed",
                              G_CALLBACK (gimp_tool_widget_group_child_focus_changed),
                              group);
}

static void
gimp_tool_widget_group_finalize (GObject *object)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (object);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  g_clear_object (&priv->children);

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static gint
gimp_tool_widget_group_button_press (GimpToolWidget      *widget,
                                     const GimpCoords    *coords,
                                     guint32              time,
                                     GdkModifierType      state,
                                     GimpButtonPressType  press_type)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

236 237
  gimp_tool_widget_group_hover (widget, coords, state, TRUE);

Ell's avatar
Ell committed
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
  if (priv->focus_widget != priv->hover_widget)
    {
      if (priv->hover_widget)
        gimp_tool_widget_set_focus (priv->hover_widget, TRUE);
      else if (priv->focus_widget)
        gimp_tool_widget_set_focus (priv->focus_widget, FALSE);
    }

  if (priv->hover_widget)
    {
      if (priv->auto_raise)
        {
          gimp_container_reorder (priv->children,
                                  GIMP_OBJECT (priv->hover_widget), -1);
        }

      return gimp_tool_widget_button_press (priv->hover_widget,
                                            coords, time, state, press_type);
    }

  return FALSE;
}

static void
gimp_tool_widget_group_focus_changed (GimpToolWidget *widget)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->focus_widget)
    {
      GimpToolWidget *focus_widget = priv->focus_widget;

      gimp_tool_widget_set_focus (priv->focus_widget,
                                  gimp_tool_widget_get_focus (widget));

      priv->focus_widget = focus_widget;
    }
}

static void
gimp_tool_widget_group_button_release (GimpToolWidget        *widget,
                                       const GimpCoords      *coords,
                                       guint32                time,
                                       GdkModifierType        state,
                                       GimpButtonReleaseType  release_type)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->hover_widget)
    {
      gimp_tool_widget_button_release (priv->hover_widget,
                                       coords, time, state, release_type);
    }
}

static void
gimp_tool_widget_group_motion (GimpToolWidget   *widget,
                        const GimpCoords *coords,
                        guint32           time,
                        GdkModifierType   state)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv = group->priv;

  if (priv->hover_widget)
    gimp_tool_widget_motion (priv->hover_widget, coords, time, state);
}

static GimpHit
gimp_tool_widget_group_hit (GimpToolWidget   *widget,
                            const GimpCoords *coords,
                            GdkModifierType   state,
                            gboolean          proximity)
{
  GimpToolWidgetGroup *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpHit              hit;

  gimp_tool_widget_group_get_hover_widget (group,
                                           coords, state, proximity,
                                           &hit);

  return hit;
}

static void
gimp_tool_widget_group_hover (GimpToolWidget   *widget,
                              const GimpCoords *coords,
                              GdkModifierType   state,
                              gboolean          proximity)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;
  GimpToolWidget             *hover_widget;

  hover_widget =
    gimp_tool_widget_group_get_hover_widget (group,
                                             coords, state, proximity,
                                             NULL);

  if (priv->hover_widget && priv->hover_widget != hover_widget)
    gimp_tool_widget_leave_notify (priv->hover_widget);

  priv->hover_widget = hover_widget;

  if (priv->hover_widget)
    gimp_tool_widget_hover (priv->hover_widget, coords, state, proximity);
}

static void
gimp_tool_widget_group_leave_notify (GimpToolWidget *widget)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->hover_widget)
    {
      gimp_tool_widget_leave_notify (priv->hover_widget);

      priv->hover_widget = NULL;
    }

  GIMP_TOOL_WIDGET_CLASS (parent_class)->leave_notify (widget);
}

static gboolean
gimp_tool_widget_group_key_press (GimpToolWidget *widget,
                                  GdkEventKey    *kevent)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->focus_widget)
    return gimp_tool_widget_key_press (priv->focus_widget, kevent);

  return GIMP_TOOL_WIDGET_CLASS (parent_class)->key_press (widget, kevent);
}

static gboolean
gimp_tool_widget_group_key_release (GimpToolWidget *widget,
                                    GdkEventKey    *kevent)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->focus_widget)
    return gimp_tool_widget_key_release (priv->focus_widget, kevent);

  return FALSE;
}

static void
gimp_tool_widget_group_motion_modifier (GimpToolWidget  *widget,
                                        GdkModifierType  key,
                                        gboolean         press,
                                        GdkModifierType  state)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->hover_widget)
    gimp_tool_widget_motion_modifier (priv->hover_widget, key, press, state);
}

static void
gimp_tool_widget_group_hover_modifier (GimpToolWidget  *widget,
                                       GdkModifierType  key,
                                       gboolean         press,
                                       GdkModifierType  state)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;
  GList                      *iter;

  for (iter = g_queue_peek_head_link (GIMP_LIST (priv->children)->queue);
       iter;
       iter = g_list_next (iter))
    {
      gimp_tool_widget_hover_modifier (iter->data, key, press, state);
    }
}

static gboolean
gimp_tool_widget_group_get_cursor (GimpToolWidget     *widget,
                                   const GimpCoords   *coords,
                                   GdkModifierType     state,
                                   GimpCursorType     *cursor,
                                   GimpToolCursorType *tool_cursor,
                                   GimpCursorModifier *modifier)
{
  GimpToolWidgetGroup        *group = GIMP_TOOL_WIDGET_GROUP (widget);
  GimpToolWidgetGroupPrivate *priv  = group->priv;

  if (priv->hover_widget)
    {
      return gimp_tool_widget_get_cursor (priv->hover_widget,
                                          coords, state,
                                          cursor, tool_cursor, modifier);
    }

  return FALSE;
}

static void
gimp_tool_widget_group_children_add (GimpContainer       *container,
                                     GimpToolWidget      *child,
                                     GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);
  GimpCanvasGroup            *canvas_group;

  canvas_group = GIMP_CANVAS_GROUP (gimp_tool_widget_get_item (widget));

  gimp_canvas_group_add_item (canvas_group,
                              gimp_tool_widget_get_item (child));

456 457 458 459 460 461 462
  if (gimp_tool_widget_get_focus (child) && priv->focus_widget)
    {
      gimp_tool_widget_set_focus (priv->focus_widget, FALSE);

      priv->focus_widget = NULL;
    }

Ell's avatar
Ell committed
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
  if (! priv->focus_widget)
    {
      priv->focus_widget = child;

      gimp_tool_widget_set_focus (child, gimp_tool_widget_get_focus (widget));
    }

  gimp_tool_widget_changed (widget);
}

static void
gimp_tool_widget_group_children_remove (GimpContainer       *container,
                                        GimpToolWidget      *child,
                                        GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);
  GimpCanvasGroup            *canvas_group;

  canvas_group = GIMP_CANVAS_GROUP (gimp_tool_widget_get_item (widget));

  if (priv->focus_widget == child)
    {
      gimp_tool_widget_set_focus (child, FALSE);

      priv->focus_widget = NULL;
    }

  if (priv->hover_widget == child)
    {
      gimp_tool_widget_leave_notify (child);

      priv->hover_widget = NULL;
    }

498 499 500
  if (! priv->focus_widget)
    {
      priv->focus_widget =
501
        GIMP_TOOL_WIDGET (gimp_container_get_last_child (container));
502 503 504 505 506

      if (priv->focus_widget)
        gimp_tool_widget_set_focus (priv->focus_widget, TRUE);
    }

Ell's avatar
Ell committed
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
  gimp_canvas_group_remove_item (canvas_group,
                                 gimp_tool_widget_get_item (child));

  gimp_tool_widget_changed (widget);
}

static void
gimp_tool_widget_group_children_reorder (GimpContainer       *container,
                                         GimpToolWidget      *child,
                                         gint                 new_index,
                                         GimpToolWidgetGroup *group)
{
  GimpToolWidget  *widget = GIMP_TOOL_WIDGET (group);
  GimpCanvasGroup *canvas_group;
  GList           *iter;

  canvas_group = GIMP_CANVAS_GROUP (gimp_tool_widget_get_item (widget));

  for (iter = g_queue_peek_head_link (GIMP_LIST (container)->queue);
       iter;
       iter = g_list_next (iter))
    {
      GimpCanvasItem *item = gimp_tool_widget_get_item (iter->data);

      gimp_canvas_group_remove_item (canvas_group, item);
      gimp_canvas_group_add_item    (canvas_group, item);
    }

  gimp_tool_widget_changed (widget);
}

static void
gimp_tool_widget_group_child_changed (GimpToolWidget      *child,
                                      GimpToolWidgetGroup *group)
{
  GimpToolWidget *widget = GIMP_TOOL_WIDGET (group);

  gimp_tool_widget_changed (widget);
}

static void
gimp_tool_widget_group_child_response (GimpToolWidget      *child,
                                       gint                 response_id,
                                       GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (priv->focus_widget == child)
    gimp_tool_widget_response (widget, response_id);
}

static void
gimp_tool_widget_group_child_snap_offsets (GimpToolWidget      *child,
                                           gint                 offset_x,
                                           gint                 offset_y,
                                           gint                 width,
                                           gint                 height,
                                           GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (priv->hover_widget == child)
    {
      gimp_tool_widget_set_snap_offsets (widget,
                                         offset_x, offset_y, width, height);
    }
}

static void
gimp_tool_widget_group_child_status (GimpToolWidget      *child,
                                     const gchar         *status,
                                     GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (priv->hover_widget == child)
    gimp_tool_widget_set_status (widget, status);
}

static void
gimp_tool_widget_group_child_status_coords (GimpToolWidget      *child,
                                            const gchar         *title,
                                            gdouble              x,
                                            const gchar         *separator,
                                            gdouble              y,
                                            const gchar         *help,
                                            GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (priv->hover_widget == child)
    gimp_tool_widget_set_status_coords (widget, title, x, separator, y, help);
}

605 606 607 608 609 610 611 612 613 614 615 616
static void
gimp_tool_widget_group_child_message (GimpToolWidget      *child,
                                      const gchar         *message,
                                      GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (priv->focus_widget == child)
    gimp_tool_widget_message_literal (widget, message);
}

Ell's avatar
Ell committed
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
static void
gimp_tool_widget_group_child_focus_changed (GimpToolWidget      *child,
                                            GimpToolWidgetGroup *group)
{
  GimpToolWidgetGroupPrivate *priv   = group->priv;
  GimpToolWidget             *widget = GIMP_TOOL_WIDGET (group);

  if (gimp_tool_widget_get_focus (child))
    {
      if (priv->focus_widget && priv->focus_widget != child)
        gimp_tool_widget_set_focus (priv->focus_widget, FALSE);

      priv->focus_widget = child;

      gimp_tool_widget_set_focus (widget, TRUE);
    }
  else
    {
      if (priv->focus_widget == child)
        priv->focus_widget = NULL;
    }
}

static GimpToolWidget *
gimp_tool_widget_group_get_hover_widget (GimpToolWidgetGroup *group,
                                         const GimpCoords    *coords,
                                         GdkModifierType      state,
                                         gboolean             proximity,
                                         GimpHit             *hit)
{
  GimpToolWidgetGroupPrivate *priv           = group->priv;
  GimpToolWidget             *indirect_child = NULL;
  gboolean                    indirect       = FALSE;
  GList                      *iter;

  for (iter = g_queue_peek_tail_link (GIMP_LIST (priv->children)->queue);
       iter;
       iter = g_list_previous (iter))
    {
      GimpToolWidget *child = iter->data;

      switch (gimp_tool_widget_hit (child, coords, state, proximity))
        {
        case GIMP_HIT_DIRECT:
          if (hit) *hit = GIMP_HIT_DIRECT;

          return child;

        case GIMP_HIT_INDIRECT:
          if (! indirect || child == priv->focus_widget)
            indirect_child = child;
          else if (indirect_child != priv->focus_widget)
            indirect_child = NULL;

          indirect = TRUE;

          break;

        case GIMP_HIT_NONE:
          break;
        }
    }

  if (hit) *hit = indirect_child ? GIMP_HIT_INDIRECT : GIMP_HIT_NONE;

  return indirect_child;
}


/*  public functions  */


GimpToolWidget *
gimp_tool_widget_group_new (GimpDisplayShell *shell)
{
  g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);

  return g_object_new (GIMP_TYPE_TOOL_WIDGET_GROUP,
                       "shell", shell,
                       NULL);
}

GimpContainer *
gimp_tool_widget_group_get_children (GimpToolWidgetGroup *group)
{
  g_return_val_if_fail (GIMP_IS_TOOL_WIDGET_GROUP (group), NULL);

  return group->priv->children;
}

GimpToolWidget *
gimp_tool_widget_group_get_focus_widget (GimpToolWidgetGroup *group)
{
  g_return_val_if_fail (GIMP_IS_TOOL_WIDGET_GROUP (group), NULL);

  return group->priv->focus_widget;
}

void
gimp_tool_widget_group_set_auto_raise (GimpToolWidgetGroup *group,
                                       gboolean             auto_raise)
{
  g_return_if_fail (GIMP_IS_TOOL_WIDGET_GROUP (group));

  group->priv->auto_raise = auto_raise;
}

gboolean
gimp_tool_widget_group_get_auto_raise (GimpToolWidgetGroup *group)
{
  g_return_val_if_fail (GIMP_IS_TOOL_WIDGET_GROUP (group), FALSE);

  return group->priv->auto_raise;
}