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