Ejemplo n.º 1
0
static void
gimp_device_info_constructed (GObject *object)
{
  GimpDeviceInfo *info = GIMP_DEVICE_INFO (object);
  Gimp           *gimp;

  G_OBJECT_CLASS (parent_class)->constructed (object);

  g_assert ((info->device == NULL         && info->display == NULL) ||
            (GDK_IS_DEVICE (info->device) && GDK_IS_DISPLAY (info->display)));

  gimp = GIMP_CONTEXT (object)->gimp;

  if (info->device)
    {
      g_object_set_data (G_OBJECT (info->device), GIMP_DEVICE_INFO_DATA_KEY,
                         info);

      gimp_object_set_name (GIMP_OBJECT (info), info->device->name);

      info->mode    = info->device->mode;
      info->n_axes  = info->device->num_axes;
      info->n_keys  = info->device->num_keys;
    }

  gimp_context_define_properties (GIMP_CONTEXT (object),
                                  GIMP_DEVICE_INFO_CONTEXT_MASK,
                                  FALSE);
  gimp_context_copy_properties (gimp_get_user_context (gimp),
                                GIMP_CONTEXT (object),
                                GIMP_DEVICE_INFO_CONTEXT_MASK);

  gimp_context_set_serialize_properties (GIMP_CONTEXT (object),
                                         GIMP_DEVICE_INFO_CONTEXT_MASK);

  /*  FIXME: this is ugly and needs to be done via "notify" once
   *  the contexts' properties are dynamic.
   */
  g_signal_connect (object, "foreground-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
  g_signal_connect (object, "background-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
  g_signal_connect (object, "tool-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
  g_signal_connect (object, "brush-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
  g_signal_connect (object, "pattern-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
  g_signal_connect (object, "gradient-changed",
                    G_CALLBACK (gimp_device_info_changed),
                    NULL);
}
Ejemplo n.º 2
0
static void
gimp_tool_preset_set_options (GimpToolPreset  *preset,
                              GimpToolOptions *options)
{
  if (preset->tool_options)
    {
      g_signal_handlers_disconnect_by_func (preset->tool_options,
                                            gimp_tool_preset_options_notify,
                                            preset);

       g_signal_handlers_disconnect_by_func (preset->tool_options,
                                             gimp_tool_preset_options_prop_name_changed,
                                             preset);

      g_object_unref (preset->tool_options);
      preset->tool_options = NULL;
    }

  if (options)
    {
      GimpContextPropMask serialize_props;

      preset->tool_options =
        GIMP_TOOL_OPTIONS (gimp_config_duplicate (GIMP_CONFIG (options)));

      serialize_props =
        gimp_context_get_serialize_properties (GIMP_CONTEXT (preset->tool_options));

      gimp_context_set_serialize_properties (GIMP_CONTEXT (preset->tool_options),
                                             serialize_props |
                                             GIMP_CONTEXT_TOOL_MASK);

      if (! (serialize_props & GIMP_CONTEXT_FOREGROUND_MASK))
        g_object_set (preset, "use-fg-bg", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_BRUSH_MASK))
        g_object_set (preset, "use-brush", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_DYNAMICS_MASK))
        g_object_set (preset, "use-dynamics", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_GRADIENT_MASK))
        g_object_set (preset, "use-gradient", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_PATTERN_MASK))
        g_object_set (preset, "use-pattern", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_PALETTE_MASK))
        g_object_set (preset, "use-palette", FALSE, NULL);

      if (! (serialize_props & GIMP_CONTEXT_FONT_MASK))
        g_object_set (preset, "use-font", FALSE, NULL);

      g_signal_connect (preset->tool_options, "notify",
                        G_CALLBACK (gimp_tool_preset_options_notify),
                        preset);

      g_signal_connect (preset->tool_options, "prop-name-changed",
                        G_CALLBACK (gimp_tool_preset_options_prop_name_changed),
                        preset);
    }

  g_object_notify (G_OBJECT (preset), "tool-options");
}
Ejemplo n.º 3
0
static gboolean
gimp_tool_preset_deserialize_property (GimpConfig *config,
                                       guint       property_id,
                                       GValue     *value,
                                       GParamSpec *pspec,
                                       GScanner   *scanner,
                                       GTokenType *expected)
{
  GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (config);

  switch (property_id)
    {
    case PROP_TOOL_OPTIONS:
      {
        GObject             *options;
        gchar               *type_name;
        GType                type;
        GimpContextPropMask  serialize_props;

        if (! gimp_scanner_parse_string (scanner, &type_name))
          {
            *expected = G_TOKEN_STRING;
            break;
          }

        type = g_type_from_name (type_name);

        if (! type)
          {
            g_scanner_error (scanner,
                             "unable to determine type of '%s'",
                             type_name);
            *expected = G_TOKEN_STRING;
            g_free (type_name);
            break;
          }

        if (! g_type_is_a (type, GIMP_TYPE_TOOL_OPTIONS))
          {
            g_scanner_error (scanner,
                             "'%s' is not a subclass of GimpToolOptions",
                             type_name);
            *expected = G_TOKEN_STRING;
            g_free (type_name);
            break;
          }

        g_free (type_name);

        options = g_object_new (type,
                                "gimp", tool_preset->gimp,
                                NULL);

        /*  Initialize all GimpContext object properties that can be
         *  used by presets with some non-NULL object, so loading a
         *  broken preset won't leave us with NULL objects that have
         *  bad effects. See bug #742159.
         */
        gimp_context_copy_properties (gimp_get_user_context (tool_preset->gimp),
                                      GIMP_CONTEXT (options),
                                      GIMP_CONTEXT_BRUSH_MASK    |
                                      GIMP_CONTEXT_DYNAMICS_MASK |
                                      GIMP_CONTEXT_PATTERN_MASK  |
                                      GIMP_CONTEXT_GRADIENT_MASK |
                                      GIMP_CONTEXT_PALETTE_MASK  |
                                      GIMP_CONTEXT_FONT_MASK);

        if (! GIMP_CONFIG_GET_INTERFACE (options)->deserialize (GIMP_CONFIG (options),
                                                                scanner, 1,
                                                                NULL))
          {
            g_object_unref (options);
            break;
          }

        /* we need both tool and tool-info on the options */
        if (gimp_context_get_tool (GIMP_CONTEXT (options)))
          {
            g_object_set (options,
                          "tool-info",
                          gimp_context_get_tool (GIMP_CONTEXT (options)),
                          NULL);
          }
        else if (GIMP_TOOL_OPTIONS (options)->tool_info)
          {
            g_object_set (options,
                          "tool", GIMP_TOOL_OPTIONS (options)->tool_info,
                          NULL);
          }
        else
          {
            /* if we have none, the options set_property() logic will
             * replace the NULL with its best guess
             */
            g_object_set (options,
                          "tool",      NULL,
                          "tool-info", NULL,
                          NULL);
          }

        serialize_props =
          gimp_context_get_serialize_properties (GIMP_CONTEXT (options));

        gimp_context_set_serialize_properties (GIMP_CONTEXT (options),
                                               serialize_props |
                                               GIMP_CONTEXT_TOOL_MASK);

        g_value_take_object (value, options);
      }
      break;

    default:
      return FALSE;
    }

  return TRUE;
}