Exemplo n.º 1
0
// ZRL 目前只识别缩放比例设置,将来扩展状态栏工具时再充实该函数
GtkWidget*
statusbar_features_property_proxy (MidoriWebSettings* settings,
                                   const gchar*       property,
                                   GtkWidget*         toolbar)
{
    const gchar* kind = NULL;
    GtkWidget* button = NULL;
    GtkWidget* image;
// ZRL 暂时屏蔽其他功能 2014.12.20
#if 0
    if (!strcmp (property, "auto-load-images")
     || !strcmp (property, "enable-javascript")
     || !strcmp (property, "enable-plugins"))
        kind = "toggle";
    else if (!strcmp (property, "identify-as"))
        kind = "custom-user-agent";
    else if (strstr (property, "font") != NULL)
        kind = "font";
    else if (!strcmp (property, "zoom-level"))
#else
    if (!strcmp (property, "zoom-level"))
#endif
    {
        MidoriBrowser* browser = midori_browser_get_for_widget (toolbar);
        guint i;
        button = gtk_combo_box_text_new_with_entry ();
        gtk_entry_set_width_chars (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (button))), 4);
        for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++)
            gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (button), zoom_levels[i].label);
        g_signal_connect (button, "changed",
            G_CALLBACK (statusbar_features_zoom_level_changed_cb), browser);
        g_signal_connect (browser, "notify::tab",
            G_CALLBACK (statusbar_features_browser_notify_tab_cb), button);
        statusbar_features_browser_notify_tab_cb (browser, NULL, button);
        return button;
    }

// ZRL 暂时屏蔽其他功能 2014.12.20
#if 0
    button = katze_property_proxy (settings, property, kind);
    if (GTK_IS_BIN (button))
    {
        GtkWidget* label = gtk_bin_get_child (GTK_BIN (button));
        if (GTK_IS_LABEL (label))
            gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
    }

    if (!strcmp (property, "auto-load-images"))
    {
        g_object_set_data (G_OBJECT (button), "feature-label", _("Images"));
        image = gtk_image_new_from_stock (STOCK_IMAGE, GTK_ICON_SIZE_MENU);
        gtk_button_set_image (GTK_BUTTON (button), image);
        gtk_widget_set_tooltip_text (button, _("Load images automatically"));
        statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
        g_signal_connect (toolbar, "notify::toolbar-style",
            G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
    }
    if (!strcmp (property, "enable-javascript"))
    {
        g_object_set_data (G_OBJECT (button), "feature-label", _("Scripts"));
        image = gtk_image_new_from_stock (STOCK_SCRIPT, GTK_ICON_SIZE_MENU);
        gtk_button_set_image (GTK_BUTTON (button), image);
        gtk_widget_set_tooltip_text (button, _("Enable scripts"));
        statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
        g_signal_connect (toolbar, "notify::toolbar-style",
            G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
    }
    else if (!strcmp (property, "enable-plugins"))
    {
        if (!midori_web_settings_has_plugin_support ())
            gtk_widget_hide (button);
        g_object_set_data (G_OBJECT (button), "feature-label", _("Netscape plugins"));
        image = gtk_image_new_from_stock (MIDORI_STOCK_PLUGINS, GTK_ICON_SIZE_MENU);
        gtk_button_set_image (GTK_BUTTON (button), image);
        gtk_widget_set_tooltip_text (button, _("Enable Netscape plugins"));
        statusbar_features_toolbar_notify_toolbar_style_cb (toolbar, NULL, button);
        g_signal_connect (toolbar, "notify::toolbar-style",
            G_CALLBACK (statusbar_features_toolbar_notify_toolbar_style_cb), button);
    }
#endif
    return button;
}
Exemplo n.º 2
0
Arquivo: gailbutton.c Projeto: BYC/gtk
static G_CONST_RETURN gchar*
gail_button_get_keybinding (AtkAction *action,
                            gint      i)
{
  GailButton *button;
  gchar *return_value = NULL;

  button = GAIL_BUTTON (action);
  if (button->default_is_press)
    {
      if (i == 0)
        i = 1;
      else if (i == 1)
        i = 0;
    }
  switch (i)
    {
    case 0:
      {
        /*
         * We look for a mnemonic on the label
         */
        GtkWidget *widget;
        GtkWidget *label;
        guint key_val; 

        widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (button));
        if (widget == NULL)
          /*
           * State is defunct
           */
          return NULL;

        g_return_val_if_fail (GTK_IS_BUTTON (widget), NULL);

        label = get_label_from_button (widget, 0, FALSE);
        if (GTK_IS_LABEL (label))
          {
            key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); 
            if (key_val != GDK_KEY_VoidSymbol)
              return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
          }
        if (return_value == NULL)
          {
            /* Find labelled-by relation */
            AtkRelationSet *set;
            AtkRelation *relation;
            GPtrArray *target;
            gpointer target_object;

            set = atk_object_ref_relation_set (ATK_OBJECT (action));
            if (set)
              {
                relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
                if (relation)
                  {              
                    target = atk_relation_get_target (relation);
            
                    target_object = g_ptr_array_index (target, 0);
                    label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
                  }
                g_object_unref (set);
              }

            if (GTK_IS_LABEL (label))
              {
                key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label)); 
                if (key_val != GDK_KEY_VoidSymbol)
                  return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
              }
          }
        g_free (button->click_keybinding);
        button->click_keybinding = return_value;
        break;
      }
    default:
      break;
    }
  return return_value; 
}
Exemplo n.º 3
0
static gboolean
gtk_toggle_tool_button_create_menu_proxy (GtkToolItem *item)
{
  GtkToolButton *tool_button = GTK_TOOL_BUTTON (item);
  GtkToggleToolButton *toggle_tool_button = GTK_TOGGLE_TOOL_BUTTON (item);
  GtkWidget *menu_item = NULL;
  GtkStockItem stock_item;
  gboolean use_mnemonic = TRUE;
  const char *label;
  GtkWidget *label_widget;
  const gchar *label_text;
  const gchar *stock_id;

  if (_gtk_tool_item_create_menu_proxy (item))
    return TRUE;

  label_widget = gtk_tool_button_get_label_widget (tool_button);
  label_text = gtk_tool_button_get_label (tool_button);
  stock_id = gtk_tool_button_get_stock_id (tool_button);

  if (GTK_IS_LABEL (label_widget))
    {
      label = gtk_label_get_label (GTK_LABEL (label_widget));
      use_mnemonic = gtk_label_get_use_underline (GTK_LABEL (label_widget));
    }
  else if (label_text)
    {
      label = label_text;
      use_mnemonic = gtk_tool_button_get_use_underline (tool_button);
    }
  else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
    {
      label = stock_item.label;
    }
  else
    {
      label = "";
    }
  
  if (use_mnemonic)
    menu_item = gtk_check_menu_item_new_with_mnemonic (label);
  else
    menu_item = gtk_check_menu_item_new_with_label (label);

  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
				  toggle_tool_button->priv->active);

  if (GTK_IS_RADIO_TOOL_BUTTON (toggle_tool_button))
    {
      gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (menu_item),
					     TRUE);
    }

  g_signal_connect_closure_by_id (menu_item,
				  g_signal_lookup ("activate", G_OBJECT_TYPE (menu_item)), 0,
				  g_cclosure_new_object (G_CALLBACK (menu_item_activated),
							 G_OBJECT (toggle_tool_button)),
				  FALSE);

  gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
  
  return TRUE;
}
Exemplo n.º 4
0
static G_CONST_RETURN gchar*
gail_menu_item_get_keybinding (AtkAction *action,
                               gint      i)
{
  /*
   * This function returns a string of the form A;B;C where
   * A is the keybinding for the widget; B is the keybinding to traverse
   * from the menubar and C is the accelerator.
   * The items in the keybinding to traverse from the menubar are separated
   * by ":".
   */
  GailMenuItem  *gail_menu_item;
  gchar *keybinding = NULL;
  gchar *item_keybinding = NULL;
  gchar *full_keybinding = NULL;
  gchar *accelerator = NULL;

  gail_menu_item = GAIL_MENU_ITEM (action);
  if (i == 0)
    {
      GtkWidget *item;
      GtkWidget *temp_item;
      GtkWidget *child;
      GtkWidget *parent;

      item = GTK_ACCESSIBLE (action)->widget;
      if (item == NULL)
        /* State is defunct */
        return NULL;

      temp_item = item;
      while (TRUE)
        {
          GdkModifierType mnemonic_modifier = 0;
          guint key_val;
          gchar *key, *temp_keybinding;

          child = gtk_bin_get_child (GTK_BIN (temp_item));
          if (child == NULL)
            {
              /* Possibly a tear off menu item; it could also be a menu 
               * separator generated by gtk_item_factory_create_items()
               */
              return NULL;
            }
          parent = gtk_widget_get_parent (temp_item);
          if (!parent)
            {
              /*
               * parent can be NULL when activating a window from the panel
               */
              return NULL;
            }
          g_return_val_if_fail (GTK_IS_MENU_SHELL (parent), NULL);
          if (GTK_IS_MENU_BAR (parent))
            {
              GtkWidget *toplevel;

              toplevel = gtk_widget_get_toplevel (parent);
              if (toplevel && GTK_IS_WINDOW (toplevel))
                mnemonic_modifier = gtk_window_get_mnemonic_modifier (
                                       GTK_WINDOW (toplevel));
            }
          if (GTK_IS_LABEL (child))
            {
              key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
              if (key_val != GDK_VoidSymbol)
                {
                  key = gtk_accelerator_name (key_val, mnemonic_modifier);
                  if (full_keybinding)
                    temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
                  else 
                    temp_keybinding = g_strconcat (key, NULL);
                  if (temp_item == item)
                    {
                      item_keybinding = g_strdup (key); 
                    }
                  g_free (key);
                  g_free (full_keybinding);
                  full_keybinding = temp_keybinding;
                }
              else
                {
                  /* No keybinding */
                  g_free (full_keybinding);
                  full_keybinding = NULL;
                  break;
                }        
            }        
          if (GTK_IS_MENU_BAR (parent))
            /* We have reached the menu bar so we are finished */
            break;
          g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
          temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
          if (!GTK_IS_MENU_ITEM (temp_item))
            {
              /* 
               * Menu is attached to something other than a menu item;
               * probably an option menu
               */
              g_free (full_keybinding);
              full_keybinding = NULL;
              break;
            }
        }

      parent = gtk_widget_get_parent (item);
      if (GTK_IS_MENU (parent))
        {
          GtkAccelGroup *group; 
          GtkAccelKey *key;

          group = gtk_menu_get_accel_group (GTK_MENU (parent));

          if (group)
            {
              key = gtk_accel_group_find (group, find_accel, item);
            }
          else
            {
              /*
               * If the menu item is created using GtkAction and GtkUIManager
               * we get here.
               */
              key = NULL;
              child = GTK_BIN (item)->child;
              if (GTK_IS_ACCEL_LABEL (child))
                {
                  GtkAccelLabel *accel_label;

                  accel_label = GTK_ACCEL_LABEL (child);
                  if (accel_label->accel_closure)
                    {
                      key = gtk_accel_group_find (accel_label->accel_group,
                                                  find_accel_new,
                                                  accel_label->accel_closure);
                    }
               
                }
            }

          if (key)
            {           
              accelerator = gtk_accelerator_name (key->accel_key,
                                                  key->accel_mods);
            }
        }
    }
  /*
   * Concatenate the bindings
   */
  if (item_keybinding || full_keybinding || accelerator)
    {
      gchar *temp;
      if (item_keybinding)
        {
          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
          g_free (item_keybinding);
        }
      else
        keybinding = g_strconcat (KEYBINDING_SEPARATOR, NULL);

      if (full_keybinding)
        {
          temp = g_strconcat (keybinding, full_keybinding, 
                              KEYBINDING_SEPARATOR, NULL);
          g_free (full_keybinding);
        }
      else
        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);

      g_free (keybinding);
      keybinding = temp;
      if (accelerator)
        {
          temp = g_strconcat (keybinding, accelerator, NULL);
          g_free (accelerator);
          g_free (keybinding);
          keybinding = temp;
      }
    }
  g_free (gail_menu_item->click_keybinding);
  gail_menu_item->click_keybinding = keybinding;
  return keybinding;
}
static gboolean _cairo_dock_search_words_in_frame_title (gchar **pKeyWords, GtkWidget *pCurrentFrame, gboolean bAllWords, gboolean bHighLightText, gboolean bHideOther)
{
    //\______________ On recupere son titre.
    GtkWidget *pFrameLabel = NULL;
    GtkWidget *pLabelContainer = (GTK_IS_FRAME (pCurrentFrame) ?
                                  gtk_frame_get_label_widget (GTK_FRAME (pCurrentFrame)) :
                                  gtk_expander_get_label_widget (GTK_EXPANDER (pCurrentFrame)));
    //g_print ("pLabelContainer : %x\n", pLabelContainer);
    if (GTK_IS_LABEL (pLabelContainer))
    {
        pFrameLabel = pLabelContainer;
    }
    else if (pLabelContainer != NULL)
    {
        GList *pChildList = gtk_container_get_children (GTK_CONTAINER (pLabelContainer));
        if (pChildList != NULL && pChildList->next != NULL)
            pFrameLabel = pChildList->next->data;
    }

    //\______________ On cherche les mots-cles dedans.
    gchar *cModifiedText = NULL, *str = NULL, *cKeyWord;
    gboolean bFoundInFrameTitle = FALSE;
    if (pFrameLabel != NULL)
    {
        const gchar *cFrameTitle = gtk_label_get_text (GTK_LABEL (pFrameLabel));
        int i;
        for (i = 0; pKeyWords[i] != NULL; i ++)
        {
            cKeyWord = pKeyWords[i];
            _copy_string_to_buffer (cFrameTitle);
            if (bHighLightText)
                cModifiedText = cairo_dock_highlight_key_word (cFrameTitle, cKeyWord, TRUE);
            else
                str = _search_in_buffer (cKeyWord);
            if (cModifiedText != NULL || str != NULL)  // on a trouve ce mot.
            {
                //g_print ("  on a trouve %s dans le titre\n", cKeyWord);
                bFoundInFrameTitle = TRUE;
                if (cModifiedText != NULL)
                {
                    gtk_label_set_markup (GTK_LABEL (pFrameLabel), cModifiedText);
                    cFrameTitle = gtk_label_get_label (GTK_LABEL (pFrameLabel));  // Pango inclus.
                    g_free (cModifiedText);
                    cModifiedText = NULL;
                }
                else
                    str = NULL;
                if (! bAllWords)
                    break ;
            }
            else if (bAllWords)
            {
                bFoundInFrameTitle = FALSE;
                break ;
            }
        }
        if (! bFoundInFrameTitle)  // on remet le texte par defaut.
        {
            cModifiedText = g_strdup_printf ("<b>%s</b>", cFrameTitle);
            gtk_label_set_markup (GTK_LABEL (pFrameLabel), cModifiedText);
            g_free (cModifiedText);
            cModifiedText = NULL;
        }
    }
    return bFoundInFrameTitle;
}
Exemplo n.º 6
0
/* This function returns a string of the form A;B;C where A is
 * the keybinding for the widget; B is the keybinding to traverse
 * from the menubar and C is the accelerator. The items in the
 * keybinding to traverse from the menubar are separated by ":".
 */
static const gchar *
gtk_menu_item_accessible_get_keybinding (AtkAction *action,
                                         gint       i)
{
  gchar *keybinding = NULL;
  gchar *item_keybinding = NULL;
  gchar *full_keybinding = NULL;
  gchar *accelerator = NULL;
  GtkWidget *item;
  GtkWidget *temp_item;
  GtkWidget *child;
  GtkWidget *parent;

  item = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
  if (item == NULL)
    return NULL;

  if (i != 0)
    return NULL;

  temp_item = item;
  while (TRUE)
    {
      GdkModifierType mnemonic_modifier = 0;
      guint key_val;
      gchar *key, *temp_keybinding;

      child = gtk_bin_get_child (GTK_BIN (temp_item));
      if (child == NULL)
        return NULL;

      parent = gtk_widget_get_parent (temp_item);
      if (!parent)
        /* parent can be NULL when activating a window from the panel */
        return NULL;

      if (GTK_IS_MENU_BAR (parent))
        {
          GtkWidget *toplevel;

          toplevel = gtk_widget_get_toplevel (parent);
          if (toplevel && GTK_IS_WINDOW (toplevel))
            mnemonic_modifier =
              gtk_window_get_mnemonic_modifier (GTK_WINDOW (toplevel));
        }

      if (GTK_IS_LABEL (child))
        {
          key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (child));
          if (key_val != GDK_KEY_VoidSymbol)
            {
              key = gtk_accelerator_name (key_val, mnemonic_modifier);
              if (full_keybinding)
                temp_keybinding = g_strconcat (key, ":", full_keybinding, NULL);
              else
                temp_keybinding = g_strdup (key);

              if (temp_item == item)
                item_keybinding = g_strdup (key);

              g_free (key);
              g_free (full_keybinding);
              full_keybinding = temp_keybinding;
            }
          else
            {
              /* No keybinding */
              g_free (full_keybinding);
              full_keybinding = NULL;
              break;
            }
        }

      /* We have reached the menu bar so we are finished */
      if (GTK_IS_MENU_BAR (parent))
        break;

      g_return_val_if_fail (GTK_IS_MENU (parent), NULL);
      temp_item = gtk_menu_get_attach_widget (GTK_MENU (parent));
      if (!GTK_IS_MENU_ITEM (temp_item))
        {
          /* Menu is attached to something other than a menu item;
           * probably an option menu
           */
          g_free (full_keybinding);
          full_keybinding = NULL;
          break;
        }
    }

  parent = gtk_widget_get_parent (item);
  if (GTK_IS_MENU (parent))
    {
      GtkAccelGroup *group;
      GtkAccelKey *key;

      group = gtk_menu_get_accel_group (GTK_MENU (parent));
      if (group)
        key = gtk_accel_group_find (group, find_accel_by_widget, item);
      else
        {
          key = NULL;
          child = gtk_bin_get_child (GTK_BIN (item));
          if (GTK_IS_ACCEL_LABEL (child))
            {
              GtkAccelLabel *accel_label;
              GClosure      *accel_closure;

              accel_label = GTK_ACCEL_LABEL (child);
              g_object_get (accel_label, "accel-closure", &accel_closure, NULL);
              if (accel_closure)
                {
                  key = gtk_accel_group_find (gtk_accel_group_from_accel_closure (accel_closure),
                                              find_accel_by_closure,
                                              accel_closure);
                  g_closure_unref (accel_closure);
                }
            }
        }

     if (key)
       accelerator = gtk_accelerator_name (key->accel_key, key->accel_mods);
   }

  /* Concatenate the bindings */
  if (item_keybinding || full_keybinding || accelerator)
    {
      gchar *temp;
      if (item_keybinding)
        {
          keybinding = g_strconcat (item_keybinding, KEYBINDING_SEPARATOR, NULL);
          g_free (item_keybinding);
        }
      else
        keybinding = g_strdup (KEYBINDING_SEPARATOR);

      if (full_keybinding)
        {
          temp = g_strconcat (keybinding, full_keybinding,
                              KEYBINDING_SEPARATOR, NULL);
          g_free (full_keybinding);
        }
      else
        temp = g_strconcat (keybinding, KEYBINDING_SEPARATOR, NULL);

      g_free (keybinding);
      keybinding = temp;
      if (accelerator)
        {
          temp = g_strconcat (keybinding, accelerator, NULL);
          g_free (accelerator);
          g_free (keybinding);
          keybinding = temp;
      }
    }

  return keybinding;
}
Exemplo n.º 7
0
/**
 * gimp_label_set_attributes:
 * @label: a #GtkLabel
 * @...:   a list of PangoAttrType and value pairs terminated by -1.
 *
 * Sets Pango attributes on a #GtkLabel in a more convenient way than
 * gtk_label_set_attributes().
 *
 * This function is useful if you want to change the font attributes
 * of a #GtkLabel. This is an alternative to using PangoMarkup which
 * is slow to parse and akward to handle in an i18n-friendly way.
 *
 * The attributes are set on the complete label, from start to end. If
 * you need to set attributes on part of the label, you will have to
 * use the PangoAttributes API directly.
 *
 * Since: 2.2
 **/
void
gimp_label_set_attributes (GtkLabel *label,
                           ...)
{
  PangoAttribute *attr  = NULL;
  PangoAttrList  *attrs;
  va_list         args;

  g_return_if_fail (GTK_IS_LABEL (label));

  attrs = pango_attr_list_new ();

  va_start (args, label);

  do
    {
      PangoAttrType attr_type = va_arg (args, PangoAttrType);

      if (attr_type == -1)
        attr_type = PANGO_ATTR_INVALID;

      switch (attr_type)
        {
        case PANGO_ATTR_LANGUAGE:
          attr = pango_attr_language_new (va_arg (args, PangoLanguage *));
          break;

        case PANGO_ATTR_FAMILY:
          attr = pango_attr_family_new (va_arg (args, const gchar *));
          break;

        case PANGO_ATTR_STYLE:
          attr = pango_attr_style_new (va_arg (args, PangoStyle));
          break;

        case PANGO_ATTR_WEIGHT:
          attr = pango_attr_weight_new (va_arg (args, PangoWeight));
          break;

        case PANGO_ATTR_VARIANT:
          attr = pango_attr_variant_new (va_arg (args, PangoVariant));
          break;

        case PANGO_ATTR_STRETCH:
          attr = pango_attr_stretch_new (va_arg (args, PangoStretch));
          break;

        case PANGO_ATTR_SIZE:
          attr = pango_attr_size_new (va_arg (args, gint));
          break;

        case PANGO_ATTR_FONT_DESC:
          attr = pango_attr_font_desc_new (va_arg (args,
                                                   const PangoFontDescription *));
          break;

        case PANGO_ATTR_FOREGROUND:
          {
            const PangoColor *color = va_arg (args, const PangoColor *);

            attr = pango_attr_foreground_new (color->red,
                                              color->green,
                                              color->blue);
          }
          break;

        case PANGO_ATTR_BACKGROUND:
          {
            const PangoColor *color = va_arg (args, const PangoColor *);

            attr = pango_attr_background_new (color->red,
                                              color->green,
                                              color->blue);
          }
          break;

        case PANGO_ATTR_UNDERLINE:
          attr = pango_attr_underline_new (va_arg (args, PangoUnderline));
          break;

        case PANGO_ATTR_STRIKETHROUGH:
          attr = pango_attr_strikethrough_new (va_arg (args, gboolean));
          break;

        case PANGO_ATTR_RISE:
          attr = pango_attr_rise_new (va_arg (args, gint));
          break;

        case PANGO_ATTR_SCALE:
          attr = pango_attr_scale_new (va_arg (args, gdouble));
          break;

        default:
          g_warning ("%s: invalid PangoAttribute type %d",
                     G_STRFUNC, attr_type);
        case PANGO_ATTR_INVALID:
          attr = NULL;
          break;
        }

      if (attr)
        {
          attr->start_index = 0;
          attr->end_index   = -1;
          pango_attr_list_insert (attrs, attr);
        }
    }
  while (attr);

  va_end (args);

  gtk_label_set_attributes (label, attrs);
  pango_attr_list_unref (attrs);
}
Exemplo n.º 8
0
static void
gtk_tool_button_construct_contents (GtkToolItem *tool_item)
{
  GtkToolButton *button = GTK_TOOL_BUTTON (tool_item);
  GtkWidget *child;
  GtkWidget *label = NULL;
  GtkWidget *icon = NULL;
  GtkToolbarStyle style;
  gboolean need_label = FALSE;
  gboolean need_icon = FALSE;
  GtkIconSize icon_size;
  GtkWidget *box = NULL;
  guint icon_spacing;
  GtkOrientation text_orientation = GTK_ORIENTATION_HORIZONTAL;
  GtkSizeGroup *size_group = NULL;
  GtkWidget *parent;

  button->priv->contents_invalid = FALSE;

  gtk_widget_style_get (GTK_WIDGET (tool_item), 
			"icon-spacing", &icon_spacing,
			NULL);

  if (button->priv->icon_widget)
    {
      parent = gtk_widget_get_parent (button->priv->icon_widget);
      if (parent)
        {
          gtk_container_remove (GTK_CONTAINER (parent),
                                button->priv->icon_widget);
        }
    }

  if (button->priv->label_widget)
    {
      parent = gtk_widget_get_parent (button->priv->label_widget);
      if (parent)
        {
          gtk_container_remove (GTK_CONTAINER (parent),
                                button->priv->label_widget);
        }
    }

  child = gtk_bin_get_child (GTK_BIN (button->priv->button));
  if (child)
    {
      /* Note: we are not destroying the label_widget or icon_widget
       * here because they were removed from their containers above
       */
      gtk_widget_destroy (child);
    }

  style = gtk_tool_item_get_toolbar_style (GTK_TOOL_ITEM (button));
  
  if (style != GTK_TOOLBAR_TEXT)
    need_icon = TRUE;

  if (style != GTK_TOOLBAR_ICONS && style != GTK_TOOLBAR_BOTH_HORIZ)
    need_label = TRUE;

  if (style == GTK_TOOLBAR_BOTH_HORIZ &&
      (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)) ||
       gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL ||
       gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL))
    {
      need_label = TRUE;
    }
  
  if (style != GTK_TOOLBAR_TEXT && button->priv->icon_widget == NULL &&
      button->priv->stock_id == NULL && button->priv->icon_name == NULL)
    {
      need_label = TRUE;
      need_icon = FALSE;
      style = GTK_TOOLBAR_TEXT;
    }

  if (style == GTK_TOOLBAR_TEXT && button->priv->label_widget == NULL &&
      button->priv->stock_id == NULL && button->priv->label_text == NULL)
    {
      need_label = FALSE;
      need_icon = TRUE;
      style = GTK_TOOLBAR_ICONS;
    }

  if (need_label)
    {
      if (button->priv->label_widget)
	{
	  label = button->priv->label_widget;
	}
      else
	{
	  GtkStockItem stock_item;
	  gboolean elide;
	  gchar *label_text;

          G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

	  if (button->priv->label_text)
	    {
	      label_text = button->priv->label_text;
	      elide = button->priv->use_underline;
	    }
	  else if (button->priv->stock_id && gtk_stock_lookup (button->priv->stock_id, &stock_item))
	    {
	      label_text = stock_item.label;
	      elide = TRUE;
	    }
	  else
	    {
	      label_text = "";
	      elide = FALSE;
	    }

          G_GNUC_END_IGNORE_DEPRECATIONS;

	  if (elide)
	    label_text = _gtk_toolbar_elide_underscores (label_text);
	  else
	    label_text = g_strdup (label_text);

	  label = gtk_label_new (label_text);

	  g_free (label_text);
	  
	  gtk_widget_show (label);
	}

      if (GTK_IS_LABEL (label))
        {
          gtk_label_set_ellipsize (GTK_LABEL (label),
			           gtk_tool_item_get_ellipsize_mode (GTK_TOOL_ITEM (button)));
          text_orientation = gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button));
          if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
	    {
              gfloat align;

              gtk_label_set_angle (GTK_LABEL (label), 0);
              align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
              if (align < 0.4)
                gtk_widget_set_halign (label, GTK_ALIGN_START);
              else if (align > 0.6)
                gtk_widget_set_halign (label, GTK_ALIGN_END);
              else
                gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
            }
          else
            {
              gfloat align;

              gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_NONE);
	      if (gtk_widget_get_direction (GTK_WIDGET (tool_item)) == GTK_TEXT_DIR_RTL)
	        gtk_label_set_angle (GTK_LABEL (label), -90);
	      else
	        gtk_label_set_angle (GTK_LABEL (label), 90);
              align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
              if (align < 0.4)
                gtk_widget_set_valign (label, GTK_ALIGN_END);
              else if (align > 0.6)
                gtk_widget_set_valign (label, GTK_ALIGN_START);
              else
                gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
            }
        }
    }

  icon_size = gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (button));
  if (need_icon)
    {
      GtkIconSet *icon_set = NULL;

      if (button->priv->stock_id)
        {
          G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
          icon_set = gtk_icon_factory_lookup_default (button->priv->stock_id);
          G_GNUC_END_IGNORE_DEPRECATIONS;
        }

      if (button->priv->icon_widget)
	{
	  icon = button->priv->icon_widget;
	  
	  if (GTK_IS_IMAGE (icon))
	    {
	      g_object_set (button->priv->icon_widget,
			    "icon-size", icon_size,
			    NULL);
	    }
	}
      else if (icon_set != NULL)
	{
          G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
	  icon = gtk_image_new_from_stock (button->priv->stock_id, icon_size);
          G_GNUC_END_IGNORE_DEPRECATIONS;
	  gtk_widget_show (icon);
	}
      else if (button->priv->icon_name)
	{
	  icon = gtk_image_new_from_icon_name (button->priv->icon_name, icon_size);
	  gtk_widget_show (icon);
	}

      if (icon)
	{
          if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
            {
              gfloat align;

              align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
              if (align > 0.6) 
                gtk_widget_set_halign (icon, GTK_ALIGN_START);
              else if (align < 0.4)
                gtk_widget_set_halign (icon, GTK_ALIGN_END);
              else
                gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
            }
          else
            {
              gfloat align;

              align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
              if (align > 0.6) 
                gtk_widget_set_valign (icon, GTK_ALIGN_END);
              else if (align < 0.4)
                gtk_widget_set_valign (icon, GTK_ALIGN_START);
              else
               gtk_widget_set_valign (icon, GTK_ALIGN_CENTER);
            }

	  size_group = gtk_tool_item_get_text_size_group (GTK_TOOL_ITEM (button));
	  if (size_group != NULL)
	    gtk_size_group_add_widget (size_group, icon);
	}
    }

  switch (style)
    {
    case GTK_TOOLBAR_ICONS:
      if (icon)
        gtk_container_add (GTK_CONTAINER (button->priv->button), icon);
      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
      break;

    case GTK_TOOLBAR_BOTH:
      if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
	box = gtk_box_new (GTK_ORIENTATION_VERTICAL, icon_spacing);
      else
	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, icon_spacing);
      if (icon)
	gtk_box_pack_start (GTK_BOX (box), icon, TRUE, TRUE, 0);
      gtk_box_pack_end (GTK_BOX (box), label, FALSE, TRUE, 0);
      gtk_container_add (GTK_CONTAINER (button->priv->button), box);
      break;

    case GTK_TOOLBAR_BOTH_HORIZ:
      if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
	{
	  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, icon_spacing);
	  if (icon)
	    gtk_box_pack_start (GTK_BOX (box), icon, label? FALSE : TRUE, TRUE, 0);
	  if (label)
	    gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);
	}
      else
	{
	  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, icon_spacing);
	  if (icon)
	    gtk_box_pack_end (GTK_BOX (box), icon, label ? FALSE : TRUE, TRUE, 0);
	  if (label)
	    gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
	}
      gtk_container_add (GTK_CONTAINER (button->priv->button), box);
      break;

    case GTK_TOOLBAR_TEXT:
      gtk_container_add (GTK_CONTAINER (button->priv->button), label);
      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
      break;
    }

  if (box)
    gtk_widget_show (box);

  gtk_button_set_relief (GTK_BUTTON (button->priv->button),
			 gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (button)));

  gtk_tool_item_rebuild_menu (tool_item);
  
  gtk_widget_queue_resize (GTK_WIDGET (button));
}
Exemplo n.º 9
0
static gboolean
gtk_tool_button_create_menu_proxy (GtkToolItem *item)
{
  GtkToolButton *button = GTK_TOOL_BUTTON (item);
  GtkWidget *menu_item;
  GtkWidget *menu_image = NULL;
  GtkStockItem stock_item;
  gboolean use_mnemonic = TRUE;
  const char *label;

  if (_gtk_tool_item_create_menu_proxy (item))
    return TRUE;

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

  if (GTK_IS_LABEL (button->priv->label_widget))
    {
      label = gtk_label_get_label (GTK_LABEL (button->priv->label_widget));
      use_mnemonic = gtk_label_get_use_underline (GTK_LABEL (button->priv->label_widget));
    }
  else if (button->priv->label_text)
    {
      label = button->priv->label_text;
      use_mnemonic = button->priv->use_underline;
    }
  else if (button->priv->stock_id && gtk_stock_lookup (button->priv->stock_id, &stock_item))
    {
      label = stock_item.label;
    }
  else
    {
      label = "";
    }

  if (use_mnemonic)
    menu_item = gtk_image_menu_item_new_with_mnemonic (label);
  else
    menu_item = gtk_image_menu_item_new_with_label (label);

  if (GTK_IS_IMAGE (button->priv->icon_widget))
    {
      menu_image = clone_image_menu_size (GTK_IMAGE (button->priv->icon_widget));
    }
  else if (button->priv->stock_id)
    {
      menu_image = gtk_image_new_from_stock (button->priv->stock_id, GTK_ICON_SIZE_MENU);
    }

  if (menu_image)
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), menu_image);

  G_GNUC_END_IGNORE_DEPRECATIONS;

  g_signal_connect_closure_by_id (menu_item,
				  g_signal_lookup ("activate", G_OBJECT_TYPE (menu_item)), 0,
				  g_cclosure_new_object_swap (G_CALLBACK (gtk_button_clicked),
							      G_OBJECT (GTK_TOOL_BUTTON (button)->priv->button)),
				  FALSE);

  gtk_tool_item_set_proxy_menu_item (GTK_TOOL_ITEM (button), MENU_ID, menu_item);
  
  return TRUE;
}
Exemplo n.º 10
0
static void
append_widget(GtkTreeStore *model,
              GtkWidget *widget,
              GtkTreeIter *parent_iter)
{
    GtkTreeIter iter;
    const char *class_name = G_OBJECT_CLASS_NAME(GTK_WIDGET_GET_CLASS(widget));
    const char *name;
    char *row_color = NULL;
    char *window_info;
    char *address;
    gboolean realized;
    gboolean mapped;
    gboolean visible;
    GList *l;

    name = gtk_widget_get_name(widget);
    if (name == NULL || strcmp(name, class_name) == 0) {
        if (GTK_IS_LABEL(widget))
        {
            name = gtk_label_get_text(GTK_LABEL(widget));
        }
        else if (GTK_IS_BUTTON(widget))
        {
            name = gtk_button_get_label(GTK_BUTTON(widget));
        }
        else if (GTK_IS_WINDOW(widget))
        {
            name = gtk_window_get_title(GTK_WINDOW(widget));
        }
        else
        {
            name = "";
        }
    }

    if (gtk_widget_get_window(widget))
    {
#if HAVE_X11
	window_info = g_strdup_printf("%p (XID 0x%x)", widget->window,
	                              (int)GDK_WINDOW_XID(widget->window));
#else
	window_info = g_strdup("");
#endif
    }
    else
    {
        window_info = g_strdup("");
    }

    address = g_strdup_printf("%p", widget);

    realized = gtk_widget_get_realized(widget);
    mapped = gtk_widget_get_mapped(widget);
    visible = gtk_widget_get_visible(widget);

    if (!realized || !mapped || !visible)
    {
        GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(widget));
        GdkColor color = style->fg[GTK_STATE_INSENSITIVE];

        row_color = gdk_color_to_string(&color);
    }

    gtk_tree_store_append(model, &iter, parent_iter);
    gtk_tree_store_set(model, &iter,
                       WIDGET, widget,
                       WIDGET_TYPE, class_name,
                       WIDGET_NAME, name,
                       WIDGET_REALIZED, realized,
                       WIDGET_MAPPED, mapped,
                       WIDGET_VISIBLE, visible,
                       WIDGET_WINDOW, window_info,
                       WIDGET_ADDRESS, address,
                       ROW_COLOR, row_color,
                       -1);

    g_free(window_info);
    g_free(address);
    g_free(row_color);

    if (GTK_IS_CONTAINER(widget))
    {
        GList* children = NULL;

        /* Pick up all children, including those that are internal. */
        gtk_container_forall(GTK_CONTAINER(widget),
                             on_container_forall, &children);

        for (l = children; l != NULL; l = l->next)
        {
            append_widget(model, GTK_WIDGET(l->data), &iter);
        }

        g_list_free(children);
    }
}
Exemplo n.º 11
0
static G_CONST_RETURN gchar*
gail_window_get_name (AtkObject *accessible)
{
  G_CONST_RETURN gchar* name;

  name = ATK_OBJECT_CLASS (gail_window_parent_class)->get_name (accessible);
  if (name == NULL)
    {
      /*
       * Get the window title if it exists
       */
      GtkWidget* widget = GTK_ACCESSIBLE (accessible)->widget; 

      if (widget == NULL)
        /*
         * State is defunct
         */
        return NULL;

      gail_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);

      if (GTK_IS_WINDOW (widget))
        {
          GtkWindow *window = GTK_WINDOW (widget);
 
          name = gtk_window_get_title (window);
          if (name == NULL &&
              accessible->role == ATK_ROLE_TOOL_TIP)
            {
              GtkWidget *child;

              child = gtk_bin_get_child (GTK_BIN (window));
              /* could be some kind of egg notification bubble thingy? */

              /* Handle new GTK+ GNOME 2.20 tooltips */
              if (GTK_IS_ALIGNMENT(child))
                {
                  child = gtk_bin_get_child (GTK_BIN (child));
                  if (GTK_IS_BOX(child)) 
                    {
                      GList *children;
                      guint count;
                      children = gtk_container_get_children (GTK_CONTAINER (child));
                      count = g_list_length (children);
                      if (count == 2) 
                        {
                          child = (GtkWidget *) g_list_nth_data (children, 1);
                        }
                      g_list_free (children);                
                    }
                }

              if (!GTK_IS_LABEL (child)) 
              { 
                  g_message ("ATK_ROLE_TOOLTIP object found, but doesn't look like a tooltip.");
                  return NULL;
              }
              name = gtk_label_get_text (GTK_LABEL (child));
            }
        }
    }
  return name;
}
static void
brasero_project_type_chooser_build_recent (BraseroProjectTypeChooser *self,
					   GtkRecentManager *recent)
{
	GtkSizeGroup *image_group;
	GtkSizeGroup *group;
	GList *list = NULL;
	gchar *filename;
	GList *recents;
	GList *iter;

	recents = gtk_recent_manager_get_items (recent);
	for (iter = recents; iter; iter = iter->next) {
		GtkRecentInfo *info;
		const gchar *mime;

		info = iter->data;
		mime = gtk_recent_info_get_mime_type (info);
		if (!mime)
			continue;

		/* filter those we want */
		if (strcmp (mime, "application/x-brasero")
		&&  strcmp (mime, "application/x-cd-image")
		&&  strcmp (mime, "application/x-cdrdao-toc")
		&&  strcmp (mime, "application/x-toc")
		&&  strcmp (mime, "application/x-cue")
		&&  strcmp (mime, "audio/x-scpls")
		&&  strcmp (mime, "audio/x-ms-asx")
		&&  strcmp (mime, "audio/x-mp3-playlist")
		&&  strcmp (mime, "audio/x-mpegurl"))
			continue;

		/* sort */
		list = g_list_insert_sorted (list,
					     info,
					     brasero_project_type_chooser_sort_recent);
		if (g_list_length (list) > 5)
			list = g_list_delete_link (list, g_list_last (list));
	}

	group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
	image_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);

	/* If a project was left unfinished last time then add another entry */
	filename = g_build_filename (g_get_user_config_dir (),
				     "brasero",
				     BRASERO_SESSION_TMP_PROJECT_PATH,
				     NULL);
	if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
		gchar *uri;
		GtkWidget *link;
		GtkWidget *image;

		uri = g_filename_to_uri (filename, NULL, NULL);

		image = gtk_image_new_from_icon_name ("brasero", GTK_ICON_SIZE_BUTTON);
		gtk_size_group_add_widget (image_group, image);

		link = gtk_button_new_with_label (_("Last _Unsaved Project"));
		g_object_set_data_full (G_OBJECT (link),
					"BraseroButtonURI", uri,
					g_free);

		gtk_button_set_relief (GTK_BUTTON (link), GTK_RELIEF_NONE);
		gtk_button_set_alignment (GTK_BUTTON (link), 0.0, 0.5);
		gtk_button_set_focus_on_click (GTK_BUTTON (link), FALSE);
		gtk_button_set_image (GTK_BUTTON (link), image);
		gtk_button_set_use_underline (GTK_BUTTON (link), TRUE);
		g_signal_connect (link,
				  "clicked",
				  G_CALLBACK (brasero_project_type_chooser_last_unsaved_clicked_cb),
				  self);

		gtk_widget_show (link);
		gtk_widget_set_tooltip_text (link, _("Load the last project that was not burned and not saved"));
		gtk_box_pack_start (GTK_BOX (self->priv->recent_box), link, FALSE, TRUE, 0);

		gtk_size_group_add_widget (group, link);
	}
	g_free (filename);

	for (iter = list; iter; iter = iter->next) {
		GtkRecentInfo *info;
		GList *child_iter;
		const gchar *name;
		GIcon *icon;
		GtkWidget *image;
		const gchar *uri;
		GtkWidget *child;
		GtkWidget *link;
		GList *children;
		gchar *tooltip;

		info = iter->data;

		tooltip = gtk_recent_info_get_uri_display (info);

		icon = gtk_recent_info_get_gicon (info);
		image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON);
		g_object_unref (icon);
		gtk_size_group_add_widget (image_group, image);

		gtk_widget_show (image);
		gtk_widget_set_tooltip_text (image, tooltip);

		name = gtk_recent_info_get_display_name (info);
		uri = gtk_recent_info_get_uri (info);

		/* Don't use mnemonics with filenames */
		link = gtk_button_new_with_label (name);
		g_object_set_data_full (G_OBJECT (link),
					"BraseroButtonURI", g_strdup (uri),
					g_free);

		gtk_button_set_relief (GTK_BUTTON (link), GTK_RELIEF_NONE);
		gtk_button_set_image (GTK_BUTTON (link), image);
		gtk_button_set_alignment (GTK_BUTTON (link), 0.0, 0.5);
		gtk_button_set_focus_on_click (GTK_BUTTON (link), FALSE);
		g_signal_connect (link,
				  "clicked",
				  G_CALLBACK (brasero_project_type_chooser_recent_clicked_cb),
				  self);
		gtk_widget_show (link);

		gtk_widget_set_tooltip_text (link, tooltip);
		gtk_box_pack_start (GTK_BOX (self->priv->recent_box), link, FALSE, TRUE, 0);

		g_free (tooltip);

		gtk_size_group_add_widget (group, link);

		/* That's a tedious hack to avoid mnemonics which are hardcoded
		 * when you add an image to a button. BUG? */
		if (!GTK_IS_BIN (link))
			continue;

		child = gtk_bin_get_child (GTK_BIN (link));
		if (!GTK_IS_ALIGNMENT (child))
			continue;

		gtk_alignment_set (GTK_ALIGNMENT (child),
				   0.0,
				   0.5,
				   1.0,
				   1.0);

		child = gtk_bin_get_child (GTK_BIN (child));
		if (!GTK_IS_BOX (child))
			continue;

		children = gtk_container_get_children (GTK_CONTAINER (child));
		for (child_iter = children; child_iter; child_iter = child_iter->next) {
			GtkWidget *widget;

			widget = child_iter->data;
			if (GTK_IS_LABEL (widget)) {
				gtk_label_set_use_underline (GTK_LABEL (widget), FALSE);
				gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);

				/* Make sure that the name is not too long */
				gtk_box_set_child_packing (GTK_BOX (child),
							   widget,
							   TRUE,
							   TRUE,
							   0,
							   GTK_PACK_START);
				gtk_label_set_ellipsize (GTK_LABEL (widget),
							 PANGO_ELLIPSIZE_END);
				break;
			}
		}
		g_list_free (children);
	}
	g_object_unref (image_group);
	g_object_unref (group);

	if (!g_list_length (list)) {
		GtkWidget *label;
		gchar *string;

		string = g_strdup_printf ("<i>%s</i>", _("No recently used project"));
		label = gtk_label_new (string);
		gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
		g_free (string);

		gtk_widget_show (label);
		gtk_box_pack_start (GTK_BOX (self->priv->recent_box), label, FALSE, FALSE, 0);
	}

	g_list_free (list);

	g_list_foreach (recents, (GFunc) gtk_recent_info_unref, NULL);
	g_list_free (recents);
}
Exemplo n.º 13
0
static void
gimp_action_set_proxy (GimpAction *action,
                       GtkWidget  *proxy)
{
  if (! GTK_IS_IMAGE_MENU_ITEM (proxy))
    return;

  if (action->color)
    {
      GtkWidget *area;

      area = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));

      if (GIMP_IS_COLOR_AREA (area))
        {
          gimp_color_area_set_color (GIMP_COLOR_AREA (area), action->color);
        }
      else
        {
          gint width, height;

          area = gimp_color_area_new (action->color,
                                      GIMP_COLOR_AREA_SMALL_CHECKS, 0);
          gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE);

          gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (proxy),
                                             GTK_ICON_SIZE_MENU,
                                             &width, &height);

          gtk_widget_set_size_request (area, width, height);
          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), area);
          gtk_widget_show (area);
        }
    }
  else if (action->viewable)
    {
      GtkWidget *view;

      view = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));

      if (GIMP_IS_VIEW (view) &&
          g_type_is_a (G_TYPE_FROM_INSTANCE (action->viewable),
                       GIMP_VIEW (view)->renderer->viewable_type))
        {
          gimp_view_set_viewable (GIMP_VIEW (view), action->viewable);
        }
      else
        {
          GtkIconSize size;
          gint        width, height;
          gint        border_width;

          if (GIMP_IS_IMAGEFILE (action->viewable))
            {
              size         = GTK_ICON_SIZE_LARGE_TOOLBAR;
              border_width = 0;
            }
          else
            {
              size         = GTK_ICON_SIZE_MENU;
              border_width = 1;
            }

          gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (proxy),
                                             size, &width, &height);

          view = gimp_view_new_full (action->context, action->viewable,
                                     width, height, border_width,
                                     FALSE, FALSE, FALSE);
          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), view);
          gtk_widget_show (view);
        }
    }
  else
    {
      GtkWidget *image;

      image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));

      if (GIMP_IS_VIEW (image) || GIMP_IS_COLOR_AREA (image))
        {
          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), NULL);
          g_object_notify (G_OBJECT (action), "stock-id");
        }
    }

  {
    GtkWidget *child = gtk_bin_get_child (GTK_BIN (proxy));

    if (GTK_IS_LABEL (child))
      {
        GtkLabel *label = GTK_LABEL (child);

        gtk_label_set_ellipsize (label, action->ellipsize);
        gtk_label_set_max_width_chars (label, action->max_width_chars);
      }
  }
}
Exemplo n.º 14
0
/*!
  \brief bind_data() is a recursive function that is called for every container
  widget in a glade frame and it's purpose is to search the datamap file passed
  for the widget names in the glade file and if it's fond in the datamap to
  load all the attribues listed and bind them to the object using GTK+'s
  object model.
  \param widget is the widget passed to load attributes on
  \param user_data is the pointer to a BingGroup structure.
  */
G_MODULE_EXPORT void bind_data(GtkWidget *widget, gpointer user_data)
{
	BindGroup *bindgroup = (BindGroup *)user_data;
	ConfigFile *cfgfile = bindgroup->cfgfile;
	GHashTable *groups = bindgroup->groups;
	gchar * tmpbuf = NULL;
	gchar * section = NULL;
	gchar ** keys = NULL;
	gint num_keys = 0;
	gint offset = 0;
	gint page = 0;
	gint index = 0;
	gchar * initializer = NULL;
	GdkColor color;
	gchar *size = NULL;
	gint count = 0;
	gint tmpi = 0;
	gboolean hidden = FALSE;
	gchar *ptr = NULL;
	gchar **vector = NULL;
	gchar **vec2 = NULL;
	void (*func)(void) = NULL;
	GList *list = NULL;
	GList *list2 = NULL;
	const gchar *name = NULL;
	gboolean indexed = FALSE;
	Firmware_Details *firmware = NULL;
	GList ***ecu_widgets = NULL;
	GList *tab_widgets = NULL;
	void (*load_dep_obj)(GObject *, ConfigFile *,const gchar *,const gchar *) = NULL;

	ENTER();
	MTXDBG(TABLOADER,_("Entered"));
	ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(ecu_widgets);
	g_return_if_fail(firmware);

	if (!GTK_IS_WIDGET(widget))
	{
		EXIT();
		return;
	}

	if (GTK_IS_WIDGET(widget))
		if (GTK_IS_CONTAINER(widget))
			gtk_container_foreach(GTK_CONTAINER(widget),bind_data,user_data);
	name = gtk_widget_get_name(widget);
	if (!name)
	{
		EXIT();
		return;
	}

	if (NULL != (ptr = g_strrstr_len(name,strlen(name),"_of_")))
	{
		indexed = TRUE;
		ptr = g_strrstr_len(name,ptr-name,"_");
		tmpbuf = g_strdelimit(g_strdup(ptr),"_",' ');
		section = g_strndup(name,ptr-name);
		/*printf("(indexed) section is %s\n",section);*/
		gint result = sscanf(tmpbuf,"%d of %d",&index,&count);
		/*printf("sscanf result %i\n",result);*
		* printf("Found indexed value for \"%s\", index %i, count %i\n",tmpbuf,index,count);
		*/
		g_free(tmpbuf);
	}
	else
		section = g_strdup(name);

	if(cfg_read_string(cfgfile, section, "keys", &tmpbuf))
	{
		keys = parse_keys(tmpbuf,&num_keys,",");
		MTXDBG(TABLOADER,_("Number of keys for %s is %i\n"),section,num_keys);
		g_free(tmpbuf);
	}
	else 
	{
		g_free(section);
		EXIT();
		return;
	}

	page = -1;
	/* Store ptr to self in qdata, needed for bind_to_lists from groups*/
	OBJ_SET(widget,"self",widget);
	/* Bind the data in the "defaults" group per tab to EVERY var in that
	 * tab
	 */
	page = bind_group_data(cfgfile, G_OBJECT(widget), groups, "defaults");

	if(cfg_read_string(cfgfile, section, "group", &tmpbuf))
	{
		page = bind_group_data(cfgfile,G_OBJECT(widget),groups,tmpbuf);
		g_free(tmpbuf);
	}

	if ((!cfg_read_int(cfgfile, section, "page", &page)) && (page == -1))
	{
		MTXDBG(TABLOADER|CRITICAL,_("Object %s doesn't have a page assigned!!!!\n"),section);	

	}
	/* Bind widgets to lists if they have the bind_to_list flag set...
	 */
	tmpbuf = NULL;
	if (cfg_read_string(cfgfile, section, "bind_to_list", &tmpbuf))
	{
		bind_to_lists(widget, tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"ellipsize",&tmpi))
	{
		if ((GTK_IS_LABEL(widget)) && (tmpi))
		{
			OBJ_SET(widget,"ellipsize_preferred",GINT_TO_POINTER(TRUE));
			if (DATA_GET(global_data,"ellipsize_tabs"))
				gtk_label_set_ellipsize(GTK_LABEL(widget),PANGO_ELLIPSIZE_END);
		}
	}

	/* Color selections */
	if (cfg_read_string(cfgfile, section, "active_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile, section, "inactive_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_INSENSITIVE, &color);
		g_free(tmpbuf);
	}

	/* If this widget has a "depend_on" tag we need to load the dependancy
	 * information  and store it for use when needed...
	 */
	if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf))
	{
		if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj))
			load_dep_obj(G_OBJECT(widget),cfgfile,section,"depend_on");
		g_free(tmpbuf);
	}

	/* If this widget (a textview) has "create_tags" we call a special
	 * handler just for that..
	 */
	if (cfg_read_string(cfgfile,section,"create_tags",&tmpbuf))
	{
		load_tags(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	/* If this widget has "tooltip" set the tip on the widget */
	if (cfg_read_string(cfgfile,section,"tooltip",&tmpbuf))
	{
		gtk_widget_set_tooltip_text(widget,tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget (a label) has "set_label" we set the label on it
	 */
	if (cfg_read_string(cfgfile,section,"set_label",&tmpbuf))
	{
/*		printf("setting label on %s to \"%s\"\n",glade_get_widget_name(widget),tmpbuf);*/
		gtk_label_set_text(GTK_LABEL(widget),tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget is temp dependant, set the current units on it 
	 */
	if (cfg_read_string(cfgfile,section,"temp_dep",&tmpbuf))
	{
		OBJ_SET(widget,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
		g_free(tmpbuf);
	}

	/* If this widget has "register_as", register it with the supplied name
	 */
	if (cfg_read_string(cfgfile,section,"register_as",&tmpbuf))
	{
		register_widget(tmpbuf,widget);
		g_free(tmpbuf);
	}
	/* If this widget has visible_functions defined */
	if (cfg_read_string(cfgfile,section,"visible_functions",&tmpbuf))
	{
		vector = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
		for (guint i=0;i<g_strv_length(vector);i++)
		{
			vec2 = g_strsplit(vector[i],":",2);
			if (g_strv_length(vec2) != 2)
			{
				printf("ERROR in %s, visible_functions param is missing the framerate parameter (func:fps)\n",cfgfile->filename);
				g_strfreev(vec2);
				continue;
			}
			gint fps = (GINT)g_strtod(vec2[1],NULL);
			get_symbol(vec2[0],(void **)&func);
			if (func)
			{
				list = g_list_prepend(list,(gpointer)func);
				list2 = g_list_prepend(list2,GINT_TO_POINTER(fps));
			}
			g_strfreev(vec2);
		}
		g_strfreev(vector);
		OBJ_SET_FULL(widget,"func_list",list,g_list_free);
		OBJ_SET_FULL(widget,"func_fps_list",list2,g_list_free);
	}

	/* If this widget has "initializer" there's a global variable 
	 * with it's name on it 
	 */
	if (cfg_read_string(cfgfile,section,"initializer",&initializer))
	{
		gint widget_type = 0;
		if (!cfg_read_string(cfgfile,section,"widget_type",&tmpbuf))
			MTXDBG(TABLOADER|CRITICAL,_("Object %s has initializer, but no widget_type!!!!\n"),section);
		else
			widget_type = translate_string(tmpbuf);
		g_free(tmpbuf);
		switch (widget_type)
		{
			case MTX_RANGE:
				gtk_range_set_value(GTK_RANGE(widget),(GINT)DATA_GET(global_data,initializer));
				break;

			case MTX_SPINBUTTON:
				gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(GINT)DATA_GET(global_data,initializer));
				break;
			case MTX_ENTRY:
				gtk_entry_set_text(GTK_ENTRY(widget),(gchar *)DATA_GET(global_data,initializer));

			default:
				break;

		}
		g_free(initializer);
	}
	/* Hidden widgets have special handlers and should NOT be updated normally */
	cfg_read_boolean(cfgfile,section, "hidden", &hidden);
	offset = -1;
	cfg_read_int(cfgfile,section, "offset", &offset);
	if (offset >= 0 && indexed)
	{
		/*printf("indexed widget %s\n",name); */
		if (cfg_read_string(cfgfile, section, "size", &size))
		{
			offset += index * get_multiplier ((DataSize)translate_string (size));
			g_free(size);
		}
		else
		{
			if(OBJ_GET(widget, "size"))
			{
				offset += index * get_multiplier ((DataSize)(GINT)OBJ_GET(widget, "size"));
			}
			else
			{
				MTXDBG(TABLOADER|CRITICAL,_("Indexed Object %s has index and offset, but no size!!!!\n"),section);
				g_free(section);
				EXIT();
				return;
			}
		}
		/*printf("widget %s, offset %i\n",name,offset);*/
		OBJ_SET(widget,"offset",GINT_TO_POINTER(offset));
	}
	if (offset >= 0)
	{
		/* The way we do it now is to STORE widgets in LISTS for each
		 * offset, thus we can have multiple on screen controls bound
		 * to single data offset in the ECU
		 */
		if (page < 0)
		{
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, page %i, at offset %i...\n\n"),section,page,offset);
			g_free(section);
			EXIT();
			return;
		}
		if (page < firmware->total_pages)
		{
			if (offset >= firmware->page_params[page]->length)
				MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, at offset %i...\n\n"),section,offset);
			else if (!hidden)
			{

				tab_widgets = OBJ_GET(bindgroup->topframe,"tab_widgets");
				tab_widgets = g_list_prepend(tab_widgets, widget);
				OBJ_SET(bindgroup->topframe,"tab_widgets",tab_widgets);
				ecu_widgets[page][offset] = g_list_prepend(
						ecu_widgets[page][offset],
						(gpointer)widget);
			}
		}
		else
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap for widget %s, at page %i offset %i...\n\n"),section,page,offset);
	}

	/* If there is a "group" key in a section it means that it gets the
	 * rest of it's setting from the groupname listed.  This reduces
	 * redundant keys all throughout the file...
	 */
	bind_keys(G_OBJECT(widget), cfgfile, section, keys, num_keys);
	g_strfreev(keys);

	/* If this widget has the "choices" key (combobox)
	 */
	if (cfg_read_string(cfgfile,section,"choices",&tmpbuf))
	{
		combo_setup(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	if (cfg_read_string(cfgfile,section,"post_functions_with_arg",&tmpbuf))
	{
		run_post_functions_with_arg(tmpbuf,widget);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile,section,"post_functions",&tmpbuf))
	{
		run_post_functions(tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"show_widget",&tmpi))
	{
		if (tmpi)
			gtk_widget_show(widget);
		else
			gtk_widget_hide(widget);
	}
	if (cfg_read_string(cfgfile,section,"set_tab_labels",&tmpbuf))
	{
		if (GTK_IS_NOTEBOOK(widget))
		{
			vector=g_strsplit(tmpbuf,",",-1);
			if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)) == g_strv_length(vector))
			{
				for (int i=0;i<g_strv_length(vector);i++)
				{
					gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(widget),
							gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget),i),
							vector[i]);
				}
			}
			g_strfreev(vector);
		}
		g_free(tmpbuf);
	}
	g_free(section);
	MTXDBG(TABLOADER,_("Leaving"));
	EXIT();
	return;
}
Exemplo n.º 15
0
extern void _change_cluster_main(GtkComboBox *combo, gpointer extra)
{
	GtkTreeModel *model;
	display_data_t *display_data;
	GtkTreeIter iter;
	slurmdb_cluster_rec_t *cluster_rec = NULL;
	char *tmp, *ui_description;
	GError *error = NULL;
	GtkWidget *node_tab = NULL;
	int rc;
	bool got_grid = 0;

	if (!gtk_combo_box_get_active_iter(combo, &iter)) {
		g_print("nothing selected\n");
		return;
	}
	model = gtk_combo_box_get_model(combo);
	if (!model) {
		g_print("nothing selected\n");
		return;
	}

	gtk_tree_model_get(model, &iter, 1, &cluster_rec, -1);
	if (!cluster_rec) {
		g_print("no cluster_rec pointer here!");
		return;
	}

	/* From testing it doesn't appear you can get here without a
	   legitimate change, so there isn't a need to check if we are
	   going back to the same cluster we were just at.
	*/
	/* if (working_cluster_rec) { */
	/*	if (!xstrcmp(cluster_rec->name, working_cluster_rec->name)) */
	/*		return; */
	/* } */

	/* free old info under last cluster */
	slurm_free_block_info_msg(g_block_info_ptr);
	g_block_info_ptr = NULL;
	slurm_free_front_end_info_msg(g_front_end_info_ptr);
	g_front_end_info_ptr = NULL;
	slurm_free_burst_buffer_info_msg(g_bb_info_ptr);
	g_bb_info_ptr = NULL;
	slurm_free_job_info_msg(g_job_info_ptr);
	g_job_info_ptr = NULL;
	slurm_free_node_info_msg(g_node_info_ptr);
	g_node_info_ptr = NULL;
	slurm_free_partition_info_msg(g_part_info_ptr);
	g_part_info_ptr = NULL;
	slurm_free_reservation_info_msg(g_resv_info_ptr);
	g_resv_info_ptr = NULL;
	slurm_free_ctl_conf(g_ctl_info_ptr);
	g_ctl_info_ptr = NULL;
	slurm_free_job_step_info_response_msg(g_step_info_ptr);
	g_step_info_ptr = NULL;
	slurm_free_topo_info_msg(g_topo_info_msg_ptr);
	g_topo_info_msg_ptr = NULL;

	/* set up working_cluster_rec */
	if (cluster_dims > 1) {
		/* reset from a multi-dim cluster */
		working_sview_config.grid_x_width =
			default_sview_config.grid_x_width;
		working_sview_config.grid_hori = default_sview_config.grid_hori;
		working_sview_config.grid_vert = default_sview_config.grid_vert;
	}
	gtk_table_set_col_spacings(main_grid_table, 0);
	gtk_table_set_row_spacings(main_grid_table, 0);

	if (!orig_cluster_name)
		orig_cluster_name = slurm_get_cluster_name();
	if (!xstrcmp(cluster_rec->name, orig_cluster_name))
		working_cluster_rec = NULL;
	else
		working_cluster_rec = cluster_rec;
	cluster_dims = slurmdb_setup_cluster_dims();
	cluster_flags = slurmdb_setup_cluster_flags();

	display_data = main_display_data;
	while (display_data++) {
		if (display_data->id == -1)
			break;
		if (cluster_flags & CLUSTER_FLAG_BG) {
			switch(display_data->id) {
			case BLOCK_PAGE:
				display_data->show = true;
				break;
			case NODE_PAGE:
				display_data->name = "Midplanes";
				break;
			default:
				break;
			}
		} else {
			switch(display_data->id) {
			case BLOCK_PAGE:
				display_data->show = false;
				break;
			case NODE_PAGE:
				display_data->name = "Nodes";
				break;
			default:
				break;
			}
		}
	}

	/* set up menu */
	ui_description = _get_ui_description();
	gtk_ui_manager_remove_ui(g_ui_manager, g_menu_id);
	if (!(g_menu_id = gtk_ui_manager_add_ui_from_string(
		      g_ui_manager, ui_description, -1, &error))) {
		xfree(ui_description);
		g_error("building menus failed: %s", error->message);
		g_error_free (error);
		exit (0);
	}
	xfree(ui_description);

	/* make changes for each object */
	cluster_change_block();
	cluster_change_front_end();
	cluster_change_resv();
	cluster_change_part();
	cluster_change_job();
	cluster_change_node();
	cluster_change_bb();

	/* destroy old stuff */
	if (grid_button_list) {
		FREE_NULL_LIST(grid_button_list);
		got_grid = 1;
	}

	select_g_ba_fini();

	/* sorry popups can't survive a cluster change */
	if (popup_list)
		list_flush(popup_list);
	if (signal_params_list)
		list_flush(signal_params_list);
	if (signal_params_list)
		list_flush(signal_params_list);
	if (g_switch_nodes_maps)
		free_switch_nodes_maps(g_switch_nodes_maps);

	/* change the node tab name if needed */
	node_tab = gtk_notebook_get_nth_page(
		GTK_NOTEBOOK(main_notebook), NODE_PAGE);
	node_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(main_notebook),
					      node_tab);
#ifdef GTK2_USE_GET_FOCUS

	/* ok, now we have a table which we have set up to contain an
	 * event_box which contains the label we are interested.  We
	 * setup this label to be the focus child of the table, so all
	 * we have to do is grab that and we are set. */
	node_tab = gtk_container_get_focus_child(GTK_CONTAINER(node_tab));
#else
	/* See above comment.  Since gtk_container_get_focus_child
	 * doesn't exist yet we will just traverse the children until
	 * we find the label widget and then break.
	 */
	{
		int i = 0;
		GList *children = gtk_container_get_children(
			GTK_CONTAINER(node_tab));
		while ((node_tab = g_list_nth_data(children, i++))) {
			int j = 0;
			GList *children2 = gtk_container_get_children(
				GTK_CONTAINER(node_tab));
			while ((node_tab = g_list_nth_data(children2, j++))) {
				if (GTK_IS_LABEL(node_tab))
					break;
			}
			g_list_free(children2);
			if (node_tab)
				break;
		}
		g_list_free(children);
	}
#endif
	if (node_tab)
		gtk_label_set_text(GTK_LABEL(node_tab),
				   main_display_data[NODE_PAGE].name);

	/* The name in the visible tabs is easier since it is really
	   just a button with a label on it.
	*/
	if (default_sview_config.page_check_widget[NODE_PAGE]) {
		gtk_button_set_label(GTK_BUTTON(default_sview_config.
						page_check_widget[NODE_PAGE]),
				     main_display_data[NODE_PAGE].name);
	}

	/* reinit */
	rc = get_system_stats(main_grid_table);

	if (rc == SLURM_SUCCESS) {
		/* It turns out if we didn't have the grid (cluster
		   not responding) before the
		   new grid doesn't get set up correctly.  Redoing the
		   system_stats fixes it.  There is probably a better
		   way of doing this, but it doesn't happen very often
		   and isn't that bad to handle every once in a while.
		*/
		if (!got_grid) {
			/* I know we just did this before, but it
			   needs to be done again here.
			*/
			FREE_NULL_LIST(grid_button_list);
			get_system_stats(main_grid_table);
		}

		refresh_main(NULL, NULL);
	}

	tmp = g_strdup_printf("Cluster changed to %s", cluster_rec->name);
	display_edit_note(tmp);
	g_free(tmp);
}
Exemplo n.º 16
0
/*!
  \brief updates the ms2 user_outputs controls which are a bit special purpose
  \param widget is the pointer to the widget to update
  */
G_MODULE_EXPORT void update_ms2_user_outputs(GtkWidget *widget)
{
	GtkTreeModel *model = NULL;
	DataSize size = MTX_U08;
	GtkTreeIter iter;
	gint tmpi = 0;
	gint t_bitval = 0;
	gboolean valid = FALSE;
	gfloat * multiplier = NULL;
	gfloat * adder = NULL;
	gchar *lower = NULL;
	gchar *upper = NULL;
	gchar *range = NULL;
	gchar *tempc_range = NULL;
	gchar *tempf_range = NULL;
	gchar *tempk_range = NULL;
	gchar *tmpbuf = NULL;
	gchar *tmpstr = NULL;
	gint bitmask = 0;
	gint bitshift = 0;
	gfloat tmpf = 0.0;
	gfloat tmpf2 = 0.0;
	gfloat value = 0.0;
	gboolean temp_dep = FALSE;
	gint i = 0;
	gint precision = 0;
	void *eval = NULL;
	GtkWidget *tmpwidget = NULL;

	ENTER();
	/*printf("update_ms2_user_outputs widget %s %p\n",glade_get_widget_name(widget),(void *)widget);*/
	get_essential_bits_f(widget, NULL, NULL, NULL, NULL, &bitmask, &bitshift);

	value = convert_after_upload_f(widget);
	tmpi = ((GINT)value & bitmask) >> bitshift;
	model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model),&iter);
	i = 0;
	while (valid)
	{
		gtk_tree_model_get(GTK_TREE_MODEL(model),&iter,UO_BITVAL_COL,&t_bitval,-1);
		if (tmpi == t_bitval)
		{
			/* Get the rest of the data from the combo */
			gtk_tree_model_get(GTK_TREE_MODEL(model),&iter,
					UO_TEMP_DEP_COL,&temp_dep,
					UO_SIZE_COL,&size,
					UO_RAW_LOWER_COL,&lower,
					UO_RAW_UPPER_COL,&upper,
					UO_RANGE_COL,&range,
					UO_RANGE_TEMPC_COL,&tempc_range,
					UO_RANGE_TEMPF_COL,&tempf_range,
					UO_RANGE_TEMPK_COL,&tempk_range,
					UO_PRECISION_COL,&precision,
					UO_FROMECU_MULT_COL,&multiplier,
					UO_FROMECU_ADD_COL,&adder,-1);
			/*
			if (temp_dep)
			{
				printf("THIS WIDGET IS TEMP DEPENDENT\n");
				printf("raw_lower %s, raw_upper %s in treemodel\n",lower,upper);
				if (multiplier)
					printf("multiplier %f\n",*multiplier);
				if (adder)
					printf("adder %f\n",*adder);
				printf("size %i, precision %i, temp_dep %i\n",(gint)size,precision,(gint)temp_dep);
			}
			*/
			tmpbuf = (gchar *)OBJ_GET(widget,"range_label");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_LABEL(tmpwidget))
			{
				if (temp_dep)
				{
					OBJ_SET(tmpwidget,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
					OBJ_SET(tmpwidget,"c_label",tempc_range);
					OBJ_SET(tmpwidget,"f_label",tempf_range);
					OBJ_SET(tmpwidget,"k_label",tempk_range);
					bind_to_lists_f(tmpwidget,"temperature");
					gtk_label_set_text(GTK_LABEL(tmpwidget),tempf_range);
					convert_temps_f(tmpwidget,DATA_GET(global_data,"mtx_temp_units"));
				}
				else
				{
					remove_from_lists_f("temperature",tmpwidget);
					OBJ_SET(tmpwidget,"widget_temp",NULL);
					OBJ_SET(tmpwidget,"temp_dep",NULL);
					/*OBJ_SET(tmpwidget,"c_label",NULL);
					  OBJ_SET(tmpwidget,"f_label",NULL);
					  OBJ_SET(tmpwidget,"k_label",NULL);
					  */
					gtk_label_set_text(GTK_LABEL(tmpwidget),range);
				}
			}
			tmpbuf = (gchar *)OBJ_GET(widget,"thresh_widget");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_WIDGET(tmpwidget))
			{
				if (temp_dep)
				{
					OBJ_SET(tmpwidget,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
					OBJ_SET(tmpwidget,"temp_dep",GINT_TO_POINTER(temp_dep));
					bind_to_lists_f(tmpwidget,"temperature");
				}
				else
				{
					OBJ_SET(tmpwidget,"widget_temp",NULL);
					OBJ_SET(tmpwidget,"temp_dep",NULL);
					remove_from_lists_f("temperature",tmpwidget);
				}
				OBJ_SET(tmpwidget,"size",GINT_TO_POINTER(size));
				OBJ_SET(tmpwidget,"precision",GINT_TO_POINTER(precision));
				OBJ_SET(tmpwidget,"raw_lower",lower);
				OBJ_SET(tmpwidget,"raw_upper",upper);
				if (multiplier)
					OBJ_SET(tmpwidget,"fromecu_mult",multiplier);
				else
					OBJ_SET(tmpwidget,"fromecu_mult",NULL);
				if (adder)
					OBJ_SET(tmpwidget,"fromecu_add",adder);
				else
					OBJ_SET(tmpwidget,"fromecu_add",NULL);
				//convert_temps_f(tmpwidget,DATA_GET(global_data,"mtx_temp_units"));
				update_widget_f(tmpwidget,NULL);
			}
			tmpbuf = (gchar *)OBJ_GET(widget,"hyst_widget");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_WIDGET(tmpwidget))
			{
				OBJ_SET(tmpwidget,"size",GINT_TO_POINTER(size));
				OBJ_SET(tmpwidget,"precision",GINT_TO_POINTER(precision));
				OBJ_SET(tmpwidget,"raw_lower",lower);
				OBJ_SET(tmpwidget,"raw_upper",upper);
				if (multiplier)
					OBJ_SET(tmpwidget,"fromecu_mult",multiplier);
				else
					OBJ_SET(tmpwidget,"fromecu_mult",NULL);
				if (adder)
					OBJ_SET(tmpwidget,"fromecu_add",adder);
				else
					OBJ_SET(tmpwidget,"fromecu_add",NULL);
				update_widget_f(tmpwidget,NULL);
			}
			g_free(range);
		}
		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
		i++;
	}
	EXIT();
	return;
}
Exemplo n.º 17
0
static G_CONST_RETURN gchar*
gail_item_get_name (AtkObject *obj)
{
  G_CONST_RETURN gchar* name;

  g_return_val_if_fail (GAIL_IS_ITEM (obj), NULL);

  name = ATK_OBJECT_CLASS (parent_class)->get_name (obj);
  if (name == NULL)
    {
      /*
       * Get the label child
       */
      GtkWidget *widget;
      GtkWidget *label;

      widget = GTK_ACCESSIBLE (obj)->widget;
      if (widget == NULL)
        /*
         * State is defunct
         */
        return NULL;

      label = get_label_from_container (widget);
      if (GTK_IS_LABEL (label))
	return gtk_label_get_text (GTK_LABEL(label));
      /*
       * If we have a menu item in a menu attached to a GtkOptionMenu
       * the label of the selected item is detached from the menu item
       */
      else if (GTK_IS_MENU_ITEM (widget))
        {
          GtkWidget *parent;
          GtkWidget *attach;
          GList *list;
          AtkObject *parent_obj;
          gint index;

          parent = gtk_widget_get_parent (widget);
          if (GTK_IS_MENU (parent))
            {
              attach = gtk_menu_get_attach_widget (GTK_MENU (parent)); 

              if (GTK_IS_OPTION_MENU (attach))
                {
                  label = get_label_from_container (attach);
                  if (GTK_IS_LABEL (label))
	            return gtk_label_get_text (GTK_LABEL(label));
                }
              list = gtk_container_get_children (GTK_CONTAINER (parent));
              index = g_list_index (list, widget);

              if (index < 0 || index > g_list_length (list))
                {
                  g_list_free (list);
                  return NULL;
                }
              g_list_free (list);

              parent_obj = atk_object_get_parent (gtk_widget_get_accessible (parent));
              if (GTK_IS_ACCESSIBLE (parent_obj))
                {
                  parent = GTK_ACCESSIBLE (parent_obj)->widget;
                  if (GTK_IS_COMBO_BOX (parent))
                    {
                      GtkTreeModel *model;
                      GtkTreeIter iter;
                      GailItem *item;
                      gint n_columns, i;

                      model = gtk_combo_box_get_model (GTK_COMBO_BOX (parent));                       
                      item = GAIL_ITEM (obj);
                      if (gtk_tree_model_iter_nth_child (model, &iter, NULL, index))
                        {
                          n_columns = gtk_tree_model_get_n_columns (model);
                          for (i = 0; i < n_columns; i++)
                            {
                              GValue value = { 0, };

                               gtk_tree_model_get_value (model, &iter, i, &value);
                               if (G_VALUE_HOLDS_STRING (&value))
                                 {
				   g_free (item->text);
                                   item->text =  (gchar *) g_value_dup_string (&value);
                                   g_value_unset (&value);
                                   break;
                                 }
                            }
                        }
                      name = item->text;
                    }
                }
            }
        }
    }
  return name;
}
Exemplo n.º 18
0
static void
append_widget(GtkTreeStore *model,
              GtkWidget *widget,
              GtkTreeIter *parent_iter)
{
    GtkTreeIter iter;
    const char *class_name = G_OBJECT_CLASS_NAME(GTK_WIDGET_GET_CLASS(widget));
    const char *name;
    const char *row_color;
    GdkWindow *window;
    char *window_info;
    char *address;
    gboolean realized;
    gboolean mapped;
    gboolean visible;
    GList *l;

    name = gtk_widget_get_name(widget);
    if (name == NULL || strcmp(name, class_name) == 0) {
        if (GTK_IS_LABEL(widget))
        {
            name = gtk_label_get_text(GTK_LABEL(widget));
        }
        else if (GTK_IS_BUTTON(widget))
        {
            name = gtk_button_get_label(GTK_BUTTON(widget));
        }
        else if (GTK_IS_WINDOW(widget))
        {
            name = gtk_window_get_title(GTK_WINDOW(widget));
        }
        else
        {
            name = "";
        }
    }

    window = gtk_widget_get_window (widget);
    if (window_info)
    {
#if HAVE_X11
	window_info = g_strdup_printf("%p (XID 0x%x)", window,
	                              (int)GDK_WINDOW_XID(window));
#else
	window_info = g_strdup("");
#endif
    }
    else
    {
        window_info = g_strdup("");
    }

    address = g_strdup_printf("%p", widget);

    realized = gtk_widget_get_realized (widget);
    mapped = gtk_widget_get_mapped (widget);
    visible = gtk_widget_get_visible (widget);

    row_color = (realized && mapped && visible) ? "black" : "grey";

    gtk_tree_store_append(model, &iter, parent_iter);
    gtk_tree_store_set(model, &iter,
                       WIDGET, widget,
                       WIDGET_TYPE, class_name,
                       WIDGET_NAME, name,
                       WIDGET_REALIZED, realized,
                       WIDGET_MAPPED, mapped,
                       WIDGET_VISIBLE, visible,
                       WIDGET_WINDOW, window_info,
                       WIDGET_ADDRESS, address,
                       ROW_COLOR, row_color,
                       -1);

    g_free(window_info);
    g_free(address);

    if (GTK_IS_CONTAINER(widget))
    {
        for (l = gtk_container_get_children(GTK_CONTAINER(widget));
             l != NULL;
             l = l->next)
        {
            append_widget(model, GTK_WIDGET(l->data), &iter);
        }
    }
}
Exemplo n.º 19
0
static void
e_contact_editor_fullname_set_property (GObject *object,
                                        guint property_id,
                                        const GValue *value,
                                        GParamSpec *pspec)
{
	EContactEditorFullname *e_contact_editor_fullname;

	e_contact_editor_fullname = E_CONTACT_EDITOR_FULLNAME (object);

	switch (property_id) {
	case PROP_NAME:
		e_contact_name_free (e_contact_editor_fullname->name);

		if (g_value_get_pointer (value) != NULL) {
			e_contact_editor_fullname->name =
				e_contact_name_copy (
				g_value_get_pointer (value));
			fill_in_info (e_contact_editor_fullname);
		}
		else {
			e_contact_editor_fullname->name = NULL;
		}
		break;
	case PROP_EDITABLE: {
		gboolean editable;
		gint i;

		const gchar *widget_names[] = {
			"comboentry-title",
			"comboentry-suffix",
			"entry-first",
			"entry-middle",
			"entry-last",
			"label-title",
			"label-suffix",
			"label-first",
			"label-middle",
			"label-last",
			NULL
		};

		editable = g_value_get_boolean (value);
		e_contact_editor_fullname->editable = editable;

		for (i = 0; widget_names[i] != NULL; i++) {
			GtkWidget *widget;

			widget = e_builder_get_widget (
				e_contact_editor_fullname->builder,
				widget_names[i]);

			if (GTK_IS_ENTRY (widget)) {
				gtk_editable_set_editable (
					GTK_EDITABLE (widget), editable);

			} else if (GTK_IS_COMBO_BOX (widget)) {
				GtkWidget *child;

				child = gtk_bin_get_child (GTK_BIN (widget));

				gtk_editable_set_editable (
					GTK_EDITABLE (child), editable);
				gtk_widget_set_sensitive (widget, editable);

			} else if (GTK_IS_LABEL (widget)) {
				gtk_widget_set_sensitive (widget, editable);
			}
		}
		break;
	}
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
Exemplo n.º 20
0
static gboolean gtkdial_signal_emission_hook(GSignalInvocationHint *ihint,
		guint n_param_values,
		const GValue *param_values,
		gpointer data)
{
	GObject *p = G_OBJECT(g_value_peek_pointer(param_values+0));
	GtkMenu *m = GTK_MENU(g_value_peek_pointer(param_values+1));
	GtkClipboard *c = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
	GObject *o = gtk_clipboard_get_owner(c);
	GtkTextBuffer *b = GTK_IS_TEXT_VIEW(p) ? gtk_text_view_get_buffer(GTK_TEXT_VIEW(p)) : NULL;
	const gchar *text = NULL;
	int out[3];

	if (o && (p == o || (gpointer)b == o)) {
		/* text is local; should be fast */
		text = gtk_clipboard_wait_for_text(c);
	} else if (GTK_IS_ENTRY(p)) {
		text = gtk_entry_get_text(GTK_ENTRY(p));
	} else if (GTK_IS_LABEL(p)) {
		text = gtk_label_get_label(GTK_LABEL(p));
	}

	if (text != NULL && pcre_exec(regexp_phone, regexp_phone_extra, text, strlen(text),
						0, 0, out, 3) && out[1] > out[0]) {
		gchar *label;
		int need, len = out[1] - out[0];
		const char *str = text + out[0];
	
		free(last_phone_number);
		last_phone_number = NULL;
		if ((need = gtkdial_make_canonical(NULL, str, len)) > 1) {
			last_phone_number = malloc(1 + need);
			gtkdial_make_canonical(last_phone_number, str, len);
			last_phone_number[need] = '\0';
		}

		if (last_phone_number != NULL && asprintf(&label, "Dial: %s", last_phone_number)) {
			GtkIconSet *icon_set = gtk_style_lookup_icon_set(gtk_widget_get_style(GTK_WIDGET(m)),
						"call-start");
			GtkImageMenuItem *item;
			GtkImage *icon;

			if (!icon_set) {
				icon = GTK_IMAGE(gtk_image_new_from_file("/usr/share/icons/gnome-human/16x16/actions/call-start.png"));
			} else {
				icon = GTK_IMAGE(gtk_image_new_from_icon_set(icon_set, GTK_ICON_SIZE_MENU));
			}

			item = GTK_IMAGE_MENU_ITEM(gtk_image_menu_item_new());
			gtk_image_menu_item_set_image(item, GTK_WIDGET(icon));
			gtk_menu_item_set_label(GTK_MENU_ITEM(item), label);
			free(label);

			g_signal_connect(G_OBJECT(item), "activate", (void*)gtkdial_doit, NULL);
			gtk_widget_show(GTK_WIDGET(item));
			gtk_menu_prepend(m, GTK_WIDGET(item));
		}
	}

	return TRUE;
}
Exemplo n.º 21
0
static void
gal_define_views_dialog_set_collection(GalDefineViewsDialog *dialog,
				       GalViewCollection *collection)
{
	int i;
	GtkListStore *store;
	GtkCellRenderer *renderer;
	dialog->collection = collection;

	store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);

	for (i=0; i<collection->view_count; i++) {
		GalViewCollectionItem *item = collection->view_data[i];
		GtkTreeIter iter;

		/* hide built in views */
		/*if (item->built_in == 1)
			continue;*/

		char *title = NULL;
		title = e_str_without_underscores (item->title);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    COL_GALVIEW_NAME, title,
				    COL_GALVIEW_DATA, item,
				    -1);

		g_free (title);
	}

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
					      COL_GALVIEW_NAME, GTK_SORT_ASCENDING);

	/* attaching treeview to model */
	gtk_tree_view_set_model (dialog->treeview, GTK_TREE_MODEL (store));
	gtk_tree_view_set_search_column (dialog->treeview, COL_GALVIEW_NAME);

	dialog->model = GTK_TREE_MODEL (store);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (dialog->treeview,
						    COL_GALVIEW_NAME, _("Name"),
						    renderer, "text", COL_GALVIEW_NAME,
						    NULL);

	/* set sort column */
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->model),
					      COL_GALVIEW_NAME, GTK_SORT_ASCENDING);

	if (dialog->gui) {
		GtkWidget *widget = glade_xml_get_widget(dialog->gui, "label-views");
		if (widget && GTK_IS_LABEL (widget)) {
			if (collection->title) {
				char *text = g_strdup_printf (_("Define Views for %s"),
							      collection->title);
				gtk_label_set_text (GTK_LABEL (widget),
						    text);
				gtk_window_set_title (GTK_WINDOW (dialog), text);
				g_free (text);
			} else {
				gtk_label_set_text (GTK_LABEL (widget),
						    _("Define Views"));
				gtk_window_set_title (GTK_WINDOW (dialog),
						      _("Define Views"));
			}
		}
	}
}
Exemplo n.º 22
0
static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width)
{
  ColumnsChild *child;
  GList *children;
  gint i, ncols, colspan, retwidth, childwidth;
  const gint *percentages;
  static const gint onecol[] = {100};

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
  printf("compute_width(%p): start\n", cols);
#endif

  retwidth = 0;

  ncols = 1;
  percentages = onecol;

  for (children = cols->children; children && (child = children->data);
       children = children->next) {

    if (!child->widget) {
      /* Column reconfiguration. */
      ncols = child->ncols;
      percentages = child->percentages;
      continue;
    }

    /* Only take visible widgets into account. */
    if (!gtk_widget_get_visible(child->widget))
      continue;

    childwidth = get_width(child);
    colspan = child->colspan ? child->colspan : ncols - child->colstart;

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
    printf("compute_width(%p): ", cols);
    if (GTK_IS_LABEL(child->widget))
      printf("label %p '%s' wrap=%s: ",
             child->widget,
             gtk_label_get_text(GTK_LABEL(child->widget)),
             (gtk_label_get_line_wrap(GTK_LABEL(child->widget)) ? "TRUE"
                                                                : "FALSE"));
    else
      printf("widget %p: ", child->widget);
    {
      gint min, nat;
      gtk_widget_get_preferred_width(child->widget, &min, &nat);
      printf("minwidth=%d natwidth=%d ", min, nat);
    }
    printf("thiswidth=%d span=%d\n", childwidth, colspan);
#endif

    /*
     * To compute width: we know that childwidth + cols->spacing
     * needs to equal a certain percentage of the full width of
     * the container. So we work this value out, figure out how
     * wide the container will need to be to make that percentage
     * of it equal to that width, and ensure our returned width is
     * at least that much. Very simple really.
     */
    {
      int percent, thiswid, fullwid;

      percent = 0;
      for (i = 0; i < colspan; i++)
        percent += percentages[child->colstart + i];

      thiswid = childwidth + cols->spacing;
      /*
       * Since childwidth is (at least sometimes) the _minimum_
       * size the child needs, we must ensure that it gets _at
       * least_ that size. Hence, when scaling thiswid up to
       * fullwid, we must round up, which means adding percent-1
       * before dividing by percent.
       */
      fullwid = (thiswid * 100 + percent - 1) / percent;
#ifdef COLUMNS_WIDTH_DIAGNOSTICS
      printf("compute_width(%p): after %p, thiswid=%d fullwid=%d\n",
             cols,
             child->widget,
             thiswid,
             fullwid);
#endif

      /*
       * The above calculation assumes every widget gets
       * cols->spacing on the right. So we subtract
       * cols->spacing here to account for the extra load of
       * spacing on the right.
       */
      if (retwidth < fullwid - cols->spacing)
        retwidth = fullwid - cols->spacing;
    }
  }

  retwidth += 2 * gtk_container_get_border_width(GTK_CONTAINER(cols));

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
  printf("compute_width(%p): done, returning %d\n", cols, retwidth);
#endif

  return retwidth;
}
Exemplo n.º 23
0
/*
 * Writes the source code needed to create this widget.
 * You have to output everything necessary to create the widget here, though
 * there are some convenience functions to help.
 */
static void
gb_radio_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  GtkWidget *child = GTK_BUTTON (widget)->child;
  gchar *label_text;
  gchar buffer[256];

  gchar *group_name = gtk_object_get_data (GTK_OBJECT (widget), Group);
  if (!group_name)
    group_name = gtk_widget_get_name (widget->parent);

  if (data->create_widget)
    {
      if (gb_toolbar_is_toolbar_button (widget))
	{
	  gb_toolbar_write_toolbar_button_source (widget, data);
	}
      else
	{
	  /* Make sure the temporary group list variable is declared. */
	  group_name = source_create_valid_identifier (group_name);
	  sprintf (buffer, "  GSList *%s_group = NULL;\n", group_name);
	  source_ensure_decl (data, buffer);

	  if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child))
	    {
	      label_text = glade_util_get_label_text (GTK_BIN (widget)->child);
	      /* If there is an underlined accelerator, set up the signal. */
	      if (strchr (label_text, '_'))
		{
		  source_add (data,
			      "  %s = gtk_radio_button_new_with_label (%s_group, \"\");\n",
			      data->wname, group_name);
		  gb_button_write_uline_accel_source (widget, data,
						      label_text);
		}
	      else
		{
		  source_add (data,
			      "  %s = gtk_radio_button_new_with_label (%s_group, %s);\n",
			      data->wname, group_name,
			      source_make_string (label_text,
						  data->use_gettext));
		}
	      g_free (label_text);
	    }
	  else
	    {
	      source_add (data, "  %s = gtk_radio_button_new (%s_group);\n",
			  data->wname, group_name);
	    }
	  source_add (data,
		      "  %s_group = gtk_radio_button_group (GTK_RADIO_BUTTON (%s));\n",
		      group_name, data->wname);
	  g_free (group_name);
	}
    }
  gb_widget_write_standard_source (widget, data);

  if (data->widget_data->flags & GLADE_ACTIVE)
    {
      source_add (data,
	  "  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (%s), TRUE);\n",
		  data->wname);
    }
  if (!GTK_TOGGLE_BUTTON (widget)->draw_indicator)
    {
      source_add (data,
	  "  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (%s), FALSE);\n",
		  data->wname);
    }
}
Exemplo n.º 24
0
/*!
  \brief updates the ms2 user_outputs controls which are a bit special purpose
  \param widget is the pointer to the widget to update
  */
G_MODULE_EXPORT void update_ms2_user_outputs(GtkWidget *widget)
{
	GtkTreeModel *model = NULL;
	DataSize size = MTX_U08;
	GtkTreeIter iter;
	gint tmpi = 0;
	gint t_bitval = 0;
	gboolean valid = FALSE;
	gfloat * multiplier = NULL;
	gfloat * adder = NULL;
	gchar *lower = NULL;
	gchar *upper = NULL;
	gchar *range = NULL;
	gchar *tmpbuf = NULL;
	gint bitmask = 0;
	gint bitshift = 0;
	gfloat tmpf = 0.0;
	gfloat tmpf2 = 0.0;
	gfloat value = 0.0;
	gint i = 0;
	gint precision = 0;
	void *eval = NULL;
	GtkWidget *tmpwidget = NULL;

	ENTER();
	get_essential_bits_f(widget, NULL, NULL, NULL, NULL, &bitmask, &bitshift);

	value = convert_after_upload_f(widget);
	tmpi = ((GINT)value & bitmask) >> bitshift;
	model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model),&iter);
	i = 0;
	while (valid)
	{
		gtk_tree_model_get(GTK_TREE_MODEL(model),&iter,UO_BITVAL_COL,&t_bitval,-1);
		if (tmpi == t_bitval)
		{
			/* Get the rest of the data from the combo */
			gtk_tree_model_get(GTK_TREE_MODEL(model),&iter,UO_SIZE_COL,&size,UO_RAW_LOWER_COL,&lower,UO_RAW_UPPER_COL,&upper,UO_RANGE_COL,&range,UO_PRECISION_COL,&precision,UO_FROMECU_MULT_COL,&multiplier,UO_FROMECU_ADD_COL,&adder,-1);
			tmpbuf = (gchar *)OBJ_GET(widget,"range_label");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_LABEL(tmpwidget))
				gtk_label_set_text(GTK_LABEL(tmpwidget),range);
			tmpbuf = (gchar *)OBJ_GET(widget,"thresh_widget");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_WIDGET(tmpwidget))
			{
				OBJ_SET(tmpwidget,"size",GINT_TO_POINTER(size));
				OBJ_SET(tmpwidget,"precision",GINT_TO_POINTER(precision));
				OBJ_SET(tmpwidget,"raw_lower",lower);
				OBJ_SET(tmpwidget,"raw_upper",upper);
				if (multiplier)
					OBJ_SET(tmpwidget,"fromecu_mult",multiplier);
				else
					OBJ_SET(tmpwidget,"fromecu_mult",NULL);
				if (adder)
					OBJ_SET(tmpwidget,"fromecu_add",adder);
				else
					OBJ_SET(tmpwidget,"fromecu_add",NULL);
				update_widget_f(tmpwidget,NULL);
			}
			tmpbuf = (gchar *)OBJ_GET(widget,"hyst_widget");
			if (tmpbuf)
				tmpwidget = lookup_widget_f(tmpbuf);
			if (GTK_IS_WIDGET(tmpwidget))
			{
				OBJ_SET(tmpwidget,"size",GINT_TO_POINTER(size));
				OBJ_SET(tmpwidget,"precision",GINT_TO_POINTER(precision));
				OBJ_SET(tmpwidget,"raw_lower",lower);
				OBJ_SET(tmpwidget,"raw_upper",upper);
				if (multiplier)
					OBJ_SET(tmpwidget,"fromecu_mult",multiplier);
				else
					OBJ_SET(tmpwidget,"fromecu_mult",NULL);
				if (adder)
					OBJ_SET(tmpwidget,"fromecu_add",adder);
				else
					OBJ_SET(tmpwidget,"fromecu_add",NULL);
				update_widget_f(tmpwidget,NULL);
			}
			g_free(range);
			g_free(lower);
			g_free(upper);
		}
		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
		i++;
	}
	EXIT();
	return;
}
Exemplo n.º 25
0
/*!
 \brief convert_temps() changes the values of controls based on the currently
 selected temperature scale.  IT works for labels, spinbuttons, etc...
 \param widget (gpointer) pointer to the widget that contains the necessary
 paramaters re temp (Alt label, etc)
 \param units (gpointer) the temp scale selected
 */
G_MODULE_EXPORT void convert_temps(gpointer widget, gpointer units)
{
	static void (*update_widget_f)(gpointer, gpointer);
	static gboolean (*check_deps)(gconstpointer *) = NULL;
	gconstpointer *dep_obj = NULL;
	gfloat upper = 0.0;
	gfloat lower = 0.0;
	gfloat value = 0.0;
	gchar * text = NULL;
	GtkAdjustment * adj = NULL;
	gboolean state = FALSE;
	gint widget_temp = -1;
	/*extern GdkColor black;*/
	extern gconstpointer *global_data;

	/* If this widgt depends on anything call check_dependancy which will
	 * return TRUE/FALSE.  True if what it depends on is in the matching
	 * state, FALSE otherwise...
	 */
	if ((!widget) || (DATA_GET(global_data,"leaving")))
		return;
	if (!check_deps)
		if (!get_symbol("check_dependancies",(void *)&check_deps))
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tCan NOT locate \"check_dependancies\" function pointer in plugins, BUG!\n"));
	if (!update_widget_f)
		if(!get_symbol("update_widget",(void *)&update_widget_f))
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tCan NOT locate \"update_widget\" function pointer in plugins, BUG!\n"));
	dep_obj = (gconstpointer *)OBJ_GET(widget,"dep_object");
	widget_temp = (GINT)OBJ_GET(widget,"widget_temp");
	if (dep_obj)
	{
		if (check_deps)
			state = check_deps(dep_obj);
		else
			dbg_func(CRITICAL|CONVERSIONS,g_strdup_printf(__FILE__": convert_temps()\n\tWidget %s has dependant object bound but can't locate function ptr for \"check_dependancies\" from plugins, BUG!\n",glade_get_widget_name(widget)));
	}

	switch ((TempUnits)units)
	{
		case FAHRENHEIT:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_f_label");
				else
					text = (gchar *)OBJ_GET(widget,"f_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != FAHRENHEIT))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == CELSIUS)
				{
					adj->value = c_to_f(value);
					adj->lower = c_to_f(lower);
					adj->upper = c_to_f(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_f(value);
					adj->lower = k_to_f(lower);
					adj->upper = k_to_f(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != FAHRENHEIT))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != FAHRENHEIT))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == CELSIUS)
				{
					adj->value = c_to_f(value);
					adj->lower = c_to_f(lower);
					adj->upper = c_to_f(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_f(value);
					adj->lower = k_to_f(lower);
					adj->upper = k_to_f(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
		case CELSIUS:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_c_label");
				else
					text = (gchar *)OBJ_GET(widget,"c_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != CELSIUS))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_c(value);
					adj->lower = f_to_c(lower);
					adj->upper = f_to_c(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_c(value);
					adj->lower = k_to_c(lower);
					adj->upper = k_to_c(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != CELSIUS))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != CELSIUS))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_c(value);
					adj->lower = f_to_c(lower);
					adj->upper = f_to_c(upper);
				}
				else /* Previous is kelvin */
				{
					adj->value = k_to_c(value);
					adj->lower = k_to_c(lower);
					adj->upper = k_to_c(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
		case KELVIN:
			/*printf("fahr %s\n",glade_get_widget_name(widget));*/
			if (GTK_IS_LABEL(widget))
			{
				if ((dep_obj) && (state))	
					text = (gchar *)OBJ_GET(widget,"alt_k_label");
				else
					text = (gchar *)OBJ_GET(widget,"k_label");
				gtk_label_set_text(GTK_LABEL(widget),text);
				//gtk_widget_modify_text(widget,GTK_STATE_NORMAL,&black);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));

			}
			if ((GTK_IS_SPIN_BUTTON(widget)) && (widget_temp != KELVIN))
			{

				adj = (GtkAdjustment *) gtk_spin_button_get_adjustment(
						GTK_SPIN_BUTTON(widget));
				upper = adj->upper;
				value = adj->value;
				lower = adj->lower;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_k(value);
					adj->lower = f_to_k(lower);
					adj->upper = f_to_k(upper);
				}
				else /* Previous is celsius */
				{
					adj->value = c_to_k(value);
					adj->lower = c_to_k(lower);
					adj->upper = c_to_k(upper);
				}

				gtk_adjustment_changed(adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_ENTRY(widget)) && (widget_temp != KELVIN))
			{
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
				update_widget_f(widget,NULL);
			}
			if ((GTK_IS_RANGE(widget)) && (widget_temp != KELVIN))
			{
				adj = (GtkAdjustment *) gtk_range_get_adjustment(
						GTK_RANGE(widget));
				upper = adj->upper;
				lower = adj->lower;
				value = adj->value;
				if (widget_temp == FAHRENHEIT)
				{
					adj->value = f_to_k(value);
					adj->lower = f_to_k(lower);
					adj->upper = f_to_k(upper);
				}
				else /* Previous is celsius */
				{
					adj->value = c_to_k(value);
					adj->lower = c_to_k(lower);
					adj->upper = c_to_k(upper);
				}

				gtk_range_set_adjustment(GTK_RANGE(widget),adj);
				OBJ_SET(widget,"widget_temp",GINT_TO_POINTER(units));
			}
			break;
	}
}
Exemplo n.º 26
0
Arquivo: gailbutton.c Projeto: BYC/gtk
static GtkWidget*
find_label_child (GtkContainer *container,
                  gint         *index,
                  gboolean     allow_many)
{
  GList *children, *tmp_list;
  GtkWidget *child;
 
  children = gtk_container_get_children (container);

  child = NULL;
  for (tmp_list = children; tmp_list != NULL; tmp_list = tmp_list->next) 
    {
      if (GTK_IS_LABEL (tmp_list->data))
        {
          if (!allow_many)
            {
              if (child)
                {
                  child = NULL;
                  break;
                }
              child = GTK_WIDGET (tmp_list->data);
            }
          else
            {
              if (*index == 0)
                {
                  child = GTK_WIDGET (tmp_list->data);
                  break;
                }
              (*index)--;
	    }
        }
       /*
        * Label for button which are GtkTreeView column headers are in a 
        * GtkHBox in a GtkAlignment.
        */
      else if (GTK_IS_ALIGNMENT (tmp_list->data))
        {
          GtkWidget *widget;

          widget = gtk_bin_get_child (GTK_BIN (tmp_list->data));
          if (GTK_IS_LABEL (widget))
            {
              if (!allow_many)
                {
                  if (child)
                    {
                      child = NULL;
                      break;
                    }
                  child = widget;
                }
              else
                {
                  if (*index == 0)
                    {
	              child = widget;
                      break;
                    }
                  (*index)--;
	        }
	    }
        }
      else if (GTK_IS_CONTAINER (tmp_list->data))
        {
          child = find_label_child (GTK_CONTAINER (tmp_list->data), index, allow_many);
          if (child)
            break;
        } 
    }
  g_list_free (children);
  return child;
}