1/* completionitem.cc
2 *
3 * Copyright (C) 2009, 2010, 2011 Krzesimir Nowak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <gtksourceview/gtksourcecompletionitem.h>
21#include <gtkmm/stock.h>
22#include <gtk/gtk.h>
23
24namespace Gsv
25{
26
27CompletionItem::CompletionItem(const Glib::ustring& label, const Glib::ustring& text, const Glib::RefPtr<const Gdk::Pixbuf>& icon, const Glib::ustring& info) :
28  _CONSTRUCT("label", label.c_str(), "text", text.c_str(), "icon", Glib::unwrap(icon), "info", (info.empty() ? 0 : info.c_str()))
29{}
30
31CompletionItem::CompletionItem(const Markup& markup, const Glib::ustring& text, const Glib::RefPtr<const Gdk::Pixbuf>& icon, const Glib::ustring& info) :
32  _CONSTRUCT("markup", markup.get_c_str(), "text", text.c_str(), "icon", Glib::unwrap(icon), "info", (info.empty() ? 0 : info.c_str()))
33{}
34
35G_GNUC_BEGIN_IGNORE_DEPRECATIONS
36CompletionItem::CompletionItem(const Glib::ustring& label, const Glib::ustring& text, const Gtk::StockID& stock, const Glib::ustring& info) :
37  _CONSTRUCT("text", text.c_str(), "info", (info.empty() ? 0 : info.c_str()))
38{
39  GdkPixbuf* icon;
40  Glib::ustring temp_label(label);
41
42  if (stock)
43  {
44    GtkIconTheme* theme = gtk_icon_theme_get_default();
45
46    int width, height;
47    gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
48    icon = gtk_icon_theme_load_icon (theme,
49                                     stock.get_c_str(),
50                                     width,
51                                     GTK_ICON_LOOKUP_USE_BUILTIN,
52                                     0);
53
54    GtkStockItem stock_item;
55    if (temp_label.empty() && gtk_stock_lookup (stock.get_c_str(), &stock_item))
56    {
57      temp_label = stock_item.label;
58    }
59  }
60  else
61  {
62    icon = 0;
63  }
64
65  g_object_set(gobj(), "label", temp_label.c_str(), "icon", icon, static_cast<char*>(0));
66
67  if (icon)
68  {
69    g_object_unref(icon);
70  }
71}
72G_GNUC_END_IGNORE_DEPRECATIONS
73
74} // namespace Gsv
75