libyui-gtk-pkg  2.42.9
 All Classes
ygtkpkgquerycombo.cc
1 /********************************************************************
2  * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
3  ********************************************************************/
4 /* YGtkPkgQueryCombo, an umbrella for any group of QueryWidget widgets */
5 // check the header file for information about this widget
6 
7 /*
8  Textdomain "yast2-gtk"
9  */
10 
11 #define YUILogComponent "gtk-pkg"
12 #include "YGi18n.h"
13 #include "config.h"
14 #include "YGUtils.h"
15 #include "ygtkpkgquerycombo.h"
16 #include <gtk/gtk.h>
17 
19  GtkWidget *vbox, *combo, *content;
20  Factory *factory;
21  YGtkPkgQueryWidget *child;
22 
23  Impl (Factory *factory) : factory (factory), child (NULL) {}
24 
25  ~Impl()
26  { delete child; }
27 };
28 
29 static void set_child (YGtkPkgQueryCombo *pThis, int index)
30 {
31  if (pThis->impl->child)
32  delete pThis->impl->child;
33  YGtkPkgQueryWidget *child = pThis->impl->factory->createQueryWidget (pThis, index);
34  pThis->impl->child = child;
35  child->setListener (pThis->listener);
36 
37  GtkWidget *cur_child = gtk_bin_get_child (GTK_BIN (pThis->impl->content));
38  if (cur_child)
39  gtk_container_remove (GTK_CONTAINER (pThis->impl->content), cur_child);
40  gtk_container_add (GTK_CONTAINER (pThis->impl->content), child->getWidget());
41  gtk_widget_grab_focus (child->getWidget());
42 }
43 
44 static void combo_changed_cb (GtkComboBox *combo, YGtkPkgQueryCombo *pThis)
45 {
46  Ypp::Busy busy (0);
47  set_child (pThis, gtk_combo_box_get_active (combo));
48  pThis->notify();
49 }
50 
51 YGtkPkgQueryCombo::YGtkPkgQueryCombo (Factory *factory)
52 : impl (new Impl (factory))
53 {
54  impl->combo = gtk_combo_box_text_new();
55  gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (impl->combo),
56  YGUtils::empty_row_is_separator_cb, GINT_TO_POINTER (0), NULL);
57  g_signal_connect_after (G_OBJECT (impl->combo), "changed",
58  G_CALLBACK (combo_changed_cb), this);
59  impl->content = gtk_event_box_new();
60  impl->vbox = gtk_vbox_new (FALSE, 0);
61  gtk_box_pack_start (GTK_BOX (impl->vbox), impl->combo, FALSE, TRUE, 0);
62  gtk_box_pack_start (GTK_BOX (impl->vbox), impl->content, TRUE, TRUE, 0);
63 }
64 
65 YGtkPkgQueryCombo::~YGtkPkgQueryCombo()
66 { delete impl; }
67 
68 GtkWidget *YGtkPkgQueryCombo::getWidget()
69 { return impl->vbox; }
70 
71 void YGtkPkgQueryCombo::add (const char *title)
72 {
73  GtkComboBoxText *combo = GTK_COMBO_BOX_TEXT (impl->combo);
74  gtk_combo_box_text_append (combo, NULL, title);
75 }
76 
77 void YGtkPkgQueryCombo::setActive (int index)
78 {
79  GtkComboBox *combo = GTK_COMBO_BOX (impl->combo);
80  if (gtk_combo_box_get_active (combo) != index) {
81  g_signal_handlers_block_by_func (combo, (gpointer) combo_changed_cb, this);
82  gtk_combo_box_set_active (combo, index);
83  g_signal_handlers_unblock_by_func (combo, (gpointer) combo_changed_cb, this);
84  set_child (this, index);
85  }
86 }
87 
88 bool YGtkPkgQueryCombo::begsUpdate()
89 { return impl->child->begsUpdate(); }
90 
91 void YGtkPkgQueryCombo::updateList (Ypp::List list)
92 { return impl->child->updateList (list); }
93 
94 void YGtkPkgQueryCombo::clearSelection()
95 { return impl->child->clearSelection(); }
96 
97 bool YGtkPkgQueryCombo::writeQuery (Ypp::PoolQuery &query)
98 { return impl->child->writeQuery (query); }
99 
100 void YGtkPkgQueryCombo::setListener (Listener *listener)
101 {
102  YGtkPkgQueryWidget::setListener (listener);
103  if (impl->child)
104  impl->child->setListener (listener);
105 }
106 
107 GtkWidget *YGtkPkgQueryCombo::createToolbox()
108 { return impl->child->createToolbox(); }
109