Ejemplo n.º 1
0
void
gjs_gtk_container_child_set_property (GtkContainer *container,
                                      GtkWidget    *child,
                                      const gchar  *property,
                                      const GValue *value)
{
    GParamSpec *pspec;

    pspec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (container),
                                                     property);
    if (pspec == NULL) {
      g_warning ("%s does not have a property called %s",
                 g_type_name (G_OBJECT_TYPE (container)), property);
      return;
    }

    if ((G_VALUE_TYPE (value) == G_TYPE_POINTER) &&
        (g_value_get_pointer (value) == NULL) &&
        !g_value_type_transformable (G_VALUE_TYPE (value), pspec->value_type)) {
        /* Set an empty value. This will happen when we set a NULL value from JS.
         * Since GJS doesn't know the GParamSpec for this property, it
         * will just put NULL into a G_TYPE_POINTER GValue, which will later
         * fail when trying to transform it to the GParamSpec's GType.
         */
        GValue null_value = G_VALUE_INIT;
        g_value_init (&null_value, pspec->value_type);
        gtk_container_child_set_property (container, child,
                                          property, &null_value);
        g_value_unset (&null_value);
    } else {
        gtk_container_child_set_property (container, child,
                                          property, value);
    }
}
Ejemplo n.º 2
0
/**
 * ppg_animation_update_child_property:
 * @animation: (in): A #PpgAnimation.
 * @target: (in): A #GObject.
 * @tween: (in): A #Tween containing the property.
 * @value: (in): The new value for the property.
 *
 * Updates the value of the parent widget of the target to @value.
 *
 * Returns: None.
 * Side effects: The property of @target<!-- -->'s parent widget is updated.
 */
static void
ppg_animation_update_child_property (PpgAnimation *animation,
                                     gpointer      target,
                                     Tween        *tween,
                                     const GValue *value)
{
	GtkWidget *parent = gtk_widget_get_parent(GTK_WIDGET(target));
	gtk_container_child_set_property(GTK_CONTAINER(parent), target,
	                                 tween->pspec->name, value);
}
Ejemplo n.º 3
0
void
glade_gtk_container_replace_child (GladeWidgetAdaptor * adaptor,
                                   GtkWidget * container,
                                   GtkWidget * current, GtkWidget * new_widget)
{
  GParamSpec **param_spec;
  GladePropertyClass *pclass;
  GValue *value;
  guint nproperties;
  guint i;

  g_return_if_fail (gtk_widget_get_parent (current) == container);

  param_spec = gtk_container_class_list_child_properties
      (G_OBJECT_GET_CLASS (container), &nproperties);
  value = g_malloc0 (sizeof (GValue) * nproperties);

  for (i = 0; i < nproperties; i++)
    {
      g_value_init (&value[i], param_spec[i]->value_type);
      gtk_container_child_get_property
          (GTK_CONTAINER (container), current, param_spec[i]->name, &value[i]);
    }

  gtk_container_remove (GTK_CONTAINER (container), current);
  gtk_container_add (GTK_CONTAINER (container), new_widget);

  for (i = 0; i < nproperties; i++)
    {
      /* If the added widget is a placeholder then we
       * want to keep all the "tranfer-on-paste" properties
       * as default so that it looks fresh (transfer-on-paste
       * properties dont effect the position/slot inside a 
       * contianer)
       */
      if (GLADE_IS_PLACEHOLDER (new_widget))
        {
          pclass = glade_widget_adaptor_get_pack_property_class
              (adaptor, param_spec[i]->name);

          if (pclass && glade_property_class_transfer_on_paste (pclass))
            continue;
        }

      gtk_container_child_set_property
          (GTK_CONTAINER (container), new_widget, param_spec[i]->name,
           &value[i]);
    }

  for (i = 0; i < nproperties; i++)
    g_value_unset (&value[i]);

  g_free (param_spec);
  g_free (value);
}
Ejemplo n.º 4
0
void
glade_gtk_container_set_child_property (GladeWidgetAdaptor * adaptor,
                                        GObject * container,
                                        GObject * child,
                                        const gchar * property_name,
                                        const GValue * value)
{
  if (gtk_widget_get_parent (GTK_WIDGET (child)) == GTK_WIDGET (container))
    gtk_container_child_set_property (GTK_CONTAINER (container),
                                      GTK_WIDGET (child), property_name, value);
}
Ejemplo n.º 5
0
static void
set_property_value (GObject *object, GParamSpec *pspec, GValue *value)
{
  if (is_child_property (pspec))
    {
      GtkWidget *widget = GTK_WIDGET (object);
      GtkWidget *parent = gtk_widget_get_parent (widget);

      gtk_container_child_set_property (GTK_CONTAINER (parent),
                                        widget, pspec->name, value);
    }
  else
    g_object_set_property (object, pspec->name, value);
}
Ejemplo n.º 6
0
void
container_set_child_property (GtkContainer *aParent,
			      GtkWidget *aChild,
			      const char *aProperty,
			      OOP aValue)
{
  GParamSpec *spec;
  GValue value = {0,};

  g_return_if_fail (GTK_WIDGET (aParent) ==
		    gtk_widget_get_parent (GTK_WIDGET (aChild)));

  spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (aParent),
						  aProperty);

  g_value_init (&value, spec->value_type);
  g_value_fill_from_oop (&value, aValue);
  gtk_container_child_set_property (aParent, aChild, aProperty, &value);
}
Ejemplo n.º 7
0
static void
append_child_attrs_foreach (gpointer key, gpointer value, gpointer user_data)
{
    if (!value) {
	return;
    }

    GParamSpec *spec;
    GError *error = NULL;
    GValue gval = { 0 };

    GtkWidget *child = GTK_WIDGET (user_data);
    GtkWidget *parent = gtk_widget_get_parent (child);

    spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (parent), (char *)key);
    if (!spec ||
        G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (spec)) == G_TYPE_OBJECT) {
        return;
    }
#if 1
    g_print ("found child property %s.%s on %s\n",
             g_type_name (G_TYPE_FROM_INSTANCE (parent)),
             spec->name,
             g_type_name (G_TYPE_FROM_INSTANCE (child)));
#endif
    if (gtk_builder_value_from_string (NULL, spec,
				       g_value_get_string ((const GValue *)value),
				       &gval, &error)) {
        gtk_container_child_set_property (GTK_CONTAINER (parent), child,
                                          spec->name, &gval);
        g_value_unset (&gval);
    } else {
        g_print ("Error getting value_from_string: %s\n",
                 error->message);
	g_error_free (error);
    }
}
Ejemplo n.º 8
0
void
glade_gtk_header_bar_child_set_property (GladeWidgetAdaptor *adaptor,
                                         GObject *container,
                                         GObject *child,
                                         const gchar *property_name,
                                         const GValue *value)
{
  GladeWidget *gbox;
  gint size;

  d(g_message ("Set child prop %s %s\n", g_type_name_from_instance (child), property_name));

  gtk_container_child_set_property (GTK_CONTAINER (container),
                                    GTK_WIDGET (child),
                                    property_name,
                                    value);

  gbox = glade_widget_get_from_gobject (container);
  if (!glade_widget_superuser ())
    {
      glade_widget_property_get (gbox, "size", &size);
      glade_widget_property_set (gbox, "size", size);
    }
}
Ejemplo n.º 9
0
static void
af_transition_set_progress (AfTransition *transition,
                            gdouble       progress,
			    gpointer      user_data)
{
  GValue value = { 0, };
  GArray *properties;
  guint i;
  AfTypeTransformationFunc func;

  properties = transition->properties;
  progress = af_timeline_calculate_progress (progress, transition->type);

  for (i = 0; i < properties->len; i++)
    {
      AfPropertyRange *property_range;
      gboolean handled = FALSE;
      GType type;

      property_range = &g_array_index (properties, AfPropertyRange, i);

      if (G_UNLIKELY (G_VALUE_TYPE (&property_range->from) == G_TYPE_INVALID))
        {
          g_value_init (&property_range->from,
                        property_range->pspec->value_type);

          if (!transition->child)
            g_object_get_property (transition->object,
                                   property_range->pspec->name,
                                   &property_range->from);
          else
            gtk_container_child_get_property (GTK_CONTAINER (transition->object),
                                              GTK_WIDGET (transition->child),
                                              property_range->pspec->name,
                                              &property_range->from);
        }

      g_value_init (&value, property_range->pspec->value_type);
      type = property_range->pspec->value_type;
      
      func = transition->func;

      if (!func && transformable_types)
        func = g_hash_table_lookup (transformable_types, GSIZE_TO_POINTER (type));

      if (!func)
        {
          switch (type)
            {
              case G_TYPE_INT:
                {
                  gint from, to, val;

                  from = g_value_get_int (&property_range->from);
                  to = g_value_get_int (&property_range->to);

                  val = from + ((to - from) * progress);
                  g_value_set_int (&value, val);
                  handled = TRUE;
                }

                break;
              case G_TYPE_DOUBLE:
                {
                  gdouble from, to, val;

                  from = g_value_get_double (&property_range->from);
                  to = g_value_get_double (&property_range->to);

                  val = from + ((to - from) * progress);
                  g_value_set_double (&value, val);
                  handled = TRUE;
		}

                break;
              case G_TYPE_FLOAT:
                {
                  gfloat from, to, val;

                  from = g_value_get_float (&property_range->from);
                  to = g_value_get_float (&property_range->to);

                  val = from + ((to - from) * progress);
                  g_value_set_float (&value, val);
                  handled = TRUE;
                }

                break;
              default:
                g_warning ("Property of type '%s' not handled", g_type_name (type));
            }
        }
      else
        {
          (func) (&property_range->from,
                  &property_range->to,
                  progress,
	          user_data,
                  &value);
           handled = TRUE;
        }


      if (handled)
        {
          if (!transition->child)
            g_object_set_property (transition->object,
                                   property_range->pspec->name,
                                   &value);
          else
            gtk_container_child_set_property (GTK_CONTAINER (transition->object),
                                              GTK_WIDGET (transition->child),
                                              property_range->pspec->name,
                                              &value);
        }

      g_value_unset (&value);
    }
}
Ejemplo n.º 10
0
/**
 * Construct (or reconstruct when settings change) the window's paned layout
 *
 * It is worth noting that the string preferences only use the first character
 * to determine orientation since they are all unique (and it avoids calling
 * extra string functions).  The full strings are just for readable prefs.xml.
 *
 * @param[in] gtkblist   The Buddy List that needs a new paned window structure
 * @param[in] side       The pref where convs are placed relative to the blist
 *
 * @note This is structured to default to "right" on an invalid pref setting.
**/
void pwm_create_paned_layout(PidginBuddyList *gtkblist, const char *side)
{
	PidginWindow *
	    gtkconvwin;		/*< Conversation window merged into gtkblist */
	GtkWidget *old_paned;   /*< The existing paned layout, if it exists  */
	GtkWidget *paned;       /*< The new layout panes being created       */
	GtkWidget *placeholder; /*< Marks the conv notebook's original spot  */
	GValue value =
	    G_VALUE_INIT; /*< For passing a property value to a widget */

	gtkconvwin = pwm_blist_get_convs(gtkblist);
	old_paned = pwm_fetch(gtkblist, "paned");

	/* Create the requested vertical or horizontal paned layout. */
	if (side != NULL && (*side == 't' || *side == 'b'))
		paned = gtk_vpaned_new();
	else
		paned = gtk_hpaned_new();
	gtk_widget_show(paned);
	pwm_store(gtkblist, "paned", paned);

	/* When the size of the panes is determined, reset the Buddy List size.
	 */
	g_object_connect(G_OBJECT(paned), "signal::notify::max-position",
			 G_CALLBACK(notify_max_position_cb), gtkblist, NULL);

	/* If the Buddy List is pristine, make the panes and replace its
	 * notebook. */
	if (old_paned == NULL) {
		placeholder = gtk_label_new(NULL);
		if (side != NULL && (*side == 't' || *side == 'l')) {
			pwm_widget_replace(gtkconvwin->notebook, placeholder,
					   paned);
			pwm_widget_replace(gtkblist->notebook, paned, paned);
		} else {
			pwm_widget_replace(gtkblist->notebook, paned, paned);
			pwm_widget_replace(gtkconvwin->notebook, placeholder,
					   paned);
		}
		pwm_store(gtkblist, "placeholder", placeholder);
	}

	/* If existing panes are being replaced, define the new layout and use
	   it. */
	else {
		if (side != NULL && (*side == 't' || *side == 'l')) {
			gtk_widget_reparent(gtkconvwin->notebook, paned);
			gtk_widget_reparent(gtkblist->notebook, paned);
		} else {
			gtk_widget_reparent(gtkblist->notebook, paned);
			gtk_widget_reparent(gtkconvwin->notebook, paned);
		}
		pwm_widget_replace(old_paned, paned, NULL);
	}

	/* Make conversations resize with the window so the Buddy List is fixed.
	 */
	g_value_init(&value, G_TYPE_BOOLEAN);
	g_value_set_boolean(&value, TRUE);
	gtk_container_child_set_property(
	    GTK_CONTAINER(paned), gtkconvwin->notebook, "resize", &value);
	g_value_set_boolean(&value, FALSE);
	gtk_container_child_set_property(GTK_CONTAINER(paned),
					 gtkblist->notebook, "resize", &value);
}
Ejemplo n.º 11
0
void termit_append_tab_with_details(const struct TabInfo* ti)
{
    struct TermitTab* pTab = g_malloc0(sizeof(struct TermitTab));
    termit_style_copy(&pTab->style, &configs.style);
    if (ti->name) {
        pTab->tab_name = gtk_label_new(ti->name);
        pTab->custom_tab_name = TRUE;
    } else {
        gchar* label_text = g_strdup_printf("%s %d", configs.default_tab_name, termit.tab_max_number++);
        pTab->tab_name = gtk_label_new(label_text);
        g_free(label_text);
        pTab->custom_tab_name = FALSE;
    }
    pTab->encoding = (ti->encoding) ? g_strdup(ti->encoding) : g_strdup(configs.default_encoding);
    pTab->bksp_binding = ti->bksp_binding;
    pTab->delete_binding = ti->delete_binding;
    pTab->hbox = gtk_hbox_new(FALSE, 0);
    pTab->vte = vte_terminal_new();

    vte_terminal_set_scrollback_lines(VTE_TERMINAL(pTab->vte), configs.scrollback_lines);
    if (configs.default_word_chars)
        vte_terminal_set_word_chars(VTE_TERMINAL(pTab->vte), configs.default_word_chars);
    vte_terminal_set_mouse_autohide(VTE_TERMINAL(pTab->vte), TRUE);
    vte_terminal_set_backspace_binding(VTE_TERMINAL(pTab->vte), pTab->bksp_binding);
    vte_terminal_set_delete_binding(VTE_TERMINAL(pTab->vte), pTab->delete_binding);
#ifdef TERMIT_ENABLE_SEARCH
    vte_terminal_search_set_wrap_around(VTE_TERMINAL(pTab->vte), TRUE);
#endif // TERMIT_ENABLE_SEARCH

    /* parse command */
    gchar **cmd_argv;
    GError *cmd_err = NULL;
    gchar *cmd_path = NULL;
    gchar *cmd_file = NULL;

    pTab->command = (ti->command) ? g_strdup(ti->command) : g_strdup(configs.default_command);
    if (!g_shell_parse_argv(pTab->command, NULL, &cmd_argv, &cmd_err)) {
        ERROR("%s", _("Cannot parse command. Creating tab with shell"));
        g_error_free(cmd_err);
    } else {
        cmd_path = g_find_program_in_path(cmd_argv[0]);
        cmd_file = g_path_get_basename(cmd_argv[0]);
    }

    TRACE("command=%s cmd_path=%s cmd_file=%s", pTab->command, cmd_path, cmd_file);
    if (cmd_path && cmd_file) {
        g_free(cmd_argv[0]);
        cmd_argv[0] = g_strdup(cmd_path);
#if VTE_CHECK_VERSION(0, 26, 0) > 0
        if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte),
                VTE_PTY_DEFAULT,
                ti->working_dir, 
                cmd_argv, NULL,
                0,
                NULL, NULL,
                &pTab->pid,
                &cmd_err) != TRUE) {
            ERROR("failed to open tab: %s", cmd_err->message);
            g_error_free(cmd_err);
        }
#else
        pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte),
                cmd_path, cmd_argv, NULL, ti->working_dir, TRUE, TRUE, TRUE);
#endif // version >= 0.26
    } else {
        g_free(pTab->command);
        pTab->command = g_strdup(configs.default_command);
        gchar* argv[] = {pTab->command, NULL};
        TRACE("defaults: cmd=%s working_dir=%s", pTab->command, ti->working_dir);
        /* default tab */
#if VTE_CHECK_VERSION(0, 26, 0) > 0
        if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte),
                    VTE_PTY_DEFAULT,
                    ti->working_dir,
                    argv, NULL,
                    G_SPAWN_SEARCH_PATH,
                    NULL, NULL,
                    &pTab->pid,
                    &cmd_err) != TRUE) {
            ERROR("failed to open tab: %s", cmd_err->message);
            g_error_free(cmd_err);
        }
#else
        pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte),
                pTab->command, NULL, NULL, ti->working_dir, TRUE, TRUE, TRUE);
#endif // version >= 0.26
    }

    g_strfreev(cmd_argv);
    g_free(cmd_path);
    g_free(cmd_file);

    g_signal_connect(G_OBJECT(pTab->vte), "beep", G_CALLBACK(termit_on_beep), pTab);
    g_signal_connect(G_OBJECT(pTab->vte), "focus-in-event", G_CALLBACK(termit_on_focus), pTab);
    g_signal_connect(G_OBJECT(pTab->vte), "window-title-changed", G_CALLBACK(termit_on_tab_title_changed), NULL);

    g_signal_connect(G_OBJECT(pTab->vte), "child-exited", G_CALLBACK(termit_on_child_exited), NULL);
//    g_signal_connect(G_OBJECT(pTab->vte), "eof", G_CALLBACK(termit_eof), NULL);
    g_signal_connect_swapped(G_OBJECT(pTab->vte), "button-press-event", G_CALLBACK(termit_on_popup), NULL);
    
    vte_terminal_set_encoding(VTE_TERMINAL(pTab->vte), pTab->encoding);

    pTab->matches = g_array_new(FALSE, TRUE, sizeof(struct Match));
    termit_tab_add_matches(pTab, configs.matches);
    termit_tab_set_transparency(pTab, pTab->style.transparency);
    vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font);

    gint index = gtk_notebook_append_page(GTK_NOTEBOOK(termit.notebook), pTab->hbox, pTab->tab_name);
    if (index == -1) {
        ERROR("%s", _("Cannot create a new tab"));
        return;
    }
    if (configs.fill_tabbar) {
        GValue val = {};
        g_value_init(&val, G_TYPE_BOOLEAN);
        g_value_set_boolean(&val, TRUE);
        gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-expand", &val);
        gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-fill", &val);
    }

    termit_tab_set_audible_bell(pTab, configs.audible_bell);
    termit_tab_set_visible_bell(pTab, configs.visible_bell);

    pTab->scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment(VTE_TERMINAL(pTab->vte)));

    gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->vte, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->scrollbar, FALSE, FALSE, 0);
    GtkWidget* tabWidget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(termit.notebook), index);
    if (!tabWidget) {
        ERROR("tabWidget is NULL");
        return;
    }
    g_object_set_data(G_OBJECT(tabWidget), TERMIT_TAB_DATA, pTab);

    if (index == 0) { // there is no "switch-page" signal on the first page
        termit_set_statusbar_message(index);
    }
    pTab->scrollbar_is_shown = configs.show_scrollbar;
    gtk_widget_show_all(termit.notebook);
    
    if (pTab->style.image_file == NULL) {
        vte_terminal_set_background_image(VTE_TERMINAL(pTab->vte), NULL);
    } else {
        vte_terminal_set_background_image_file(VTE_TERMINAL(pTab->vte), pTab->style.image_file);
    }
    termit_tab_apply_colors(pTab);

    gtk_notebook_set_current_page(GTK_NOTEBOOK(termit.notebook), index);
    gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(termit.notebook), pTab->hbox, TRUE);
    gtk_window_set_focus(GTK_WINDOW(termit.main_window), pTab->vte);

    termit_check_single_tab();
    termit_hide_scrollbars();
}
Ejemplo n.º 12
0
void child_set_property(Gtk::Container& container, Gtk::Widget& child, const char *property_name, bool value) {
    GValue v = {0};
    g_value_init(&v, G_TYPE_BOOLEAN);
    g_value_set_boolean(&v, value);
    gtk_container_child_set_property(container.gobj(), child.gobj(), property_name, &v);
}