2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_listbox_text.h"
21 #include <hildon/hildon-gtk.h>
24 * @addtogroup IrrecoListboxText
27 * A single column, scrollable listbox with text cels.
34 * Source file of @ref IrrecoListboxText.
37 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /*static void irreco_listbox_text_tree_size_request(GtkWidget *widget,
42 GtkRequisition *requisition,
43 IrrecoListboxText *self);*/
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
58 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
59 /* Construction & Destruction */
60 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
63 * @name Construction & Destruction
67 G_DEFINE_TYPE(IrrecoListboxText
, irreco_listbox_text
, IRRECO_TYPE_LISTBOX
)
69 static void irreco_listbox_text_class_init(IrrecoListboxTextClass
*klass
)
73 static void irreco_listbox_text_init(IrrecoListboxText
*self
)
75 IrrecoListbox
*parent
;
76 GtkTreeViewColumn
*column
;
77 GtkCellRenderer
*renderer
;
81 parent
= IRRECO_LISTBOX(self
);
82 parent
->text_col_id
= TEXT_COL
;
83 parent
->data_col_id
= DATA_COL
;
85 /* Create GtkTreeStore and GtkTreeView */
86 parent
->list_store
= gtk_list_store_new(
87 N_COLUMNS
, G_TYPE_POINTER
, G_TYPE_STRING
);
88 /* parent->tree_view = gtk_tree_view_new_with_model(
89 GTK_TREE_MODEL(parent->list_store));*/
90 parent
->tree_view
= GTK_WIDGET(hildon_gtk_tree_view_new_with_model(
92 GTK_TREE_MODEL(parent
->list_store
)));
94 g_object_unref(G_OBJECT(parent
->list_store
));
97 renderer
= gtk_cell_renderer_text_new();
98 column
= gtk_tree_view_column_new_with_attributes(
99 NULL
, renderer
, "text", TEXT_COL
, NULL
);
100 gtk_tree_view_append_column(GTK_TREE_VIEW(parent
->tree_view
),
103 /* Set selection callback. */
104 parent
->tree_selection
= gtk_tree_view_get_selection(
105 GTK_TREE_VIEW(parent
->tree_view
));
106 gtk_tree_selection_set_mode(parent
->tree_selection
,
107 GTK_SELECTION_SINGLE
);
109 /* Add Widgets to GtkTable. */
110 table
= GTK_TABLE(gtk_table_new(2, 2, FALSE
));
112 gtk_table_attach_defaults(table
, parent
->tree_view
, 0 ,1, 0, 1);
114 /* parent->vscrollbar = gtk_vscrollbar_new(gtk_tree_view_get_vadjustment(
115 GTK_TREE_VIEW(parent->tree_view)));
116 gtk_table_attach(table, parent->vscrollbar, 1 ,2, 0, 1,
117 GTK_SHRINK, GTK_FILL, 0, 0);
119 parent->hscrollbar = gtk_hscrollbar_new(gtk_tree_view_get_hadjustment(
120 GTK_TREE_VIEW(parent->tree_view)));
121 gtk_table_attach(table, parent->hscrollbar, 0 ,1, 1, 2,
122 GTK_FILL, GTK_SHRINK, 0, 0);*/
124 gtk_box_pack_start(GTK_BOX(self
), GTK_WIDGET(table
), TRUE
, TRUE
, 0);
126 /* Connect signals. */
127 /*g_signal_connect(G_OBJECT(IRRECO_LISTBOX(self)->tree_view),
129 G_CALLBACK(irreco_listbox_text_tree_size_request),
135 GtkWidget
*irreco_listbox_text_new()
137 IrrecoListboxText
*self
;
140 self
= IRRECO_LISTBOX_TEXT(g_object_new(IRRECO_TYPE_LISTBOX_TEXT
, NULL
));
141 IRRECO_RETURN_PTR(GTK_WIDGET(self
));
145 * Create widgets and initialize IrrecoListboxText structure.
147 * The is no need to call destructor for IrrecoListboxText as long as you attach
148 * the returned GtkWidget to somewhere in the GTK widget tree. Gtk will then
149 * handle the destruction of the widgets when they are no longer needed. This
150 * will work fine as long as IrrecoListboxText structure is still around when the
151 * widget is destroyed.
154 * Minimum width Requisition for the widget.
156 * Minimum height Requisition for the widget.
158 GtkWidget
*irreco_listbox_text_new_with_autosize(gint min_width
,
163 IrrecoListboxText
*self
;
166 self
= IRRECO_LISTBOX_TEXT(g_object_new(IRRECO_TYPE_LISTBOX_TEXT
, NULL
));
167 irreco_listbox_set_autosize(IRRECO_LISTBOX(self
), min_width
, max_width
,
168 min_height
, max_height
);
169 IRRECO_RETURN_PTR(GTK_WIDGET(self
));
176 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
177 /* Public Functions */
178 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
181 * @name Public Functions
186 * Append text to the listbox.
188 void irreco_listbox_text_append(IrrecoListboxText
*self
,
192 IrrecoListbox
*parent
;
196 parent
= IRRECO_LISTBOX(self
);
197 gtk_list_store_append(parent
->list_store
, &iter
);
198 gtk_list_store_set(parent
->list_store
, &iter
,
199 TEXT_COL
, label
, DATA_COL
, user_data
, -1);
201 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(parent
->tree_view
));
203 if (parent
->select_new_rows
== TRUE
) {
204 gtk_tree_selection_select_iter(parent
->tree_selection
, &iter
);
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
213 /* Events and Callbacks */
214 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
217 * @name Events and Callbacks
221 /*static void irreco_listbox_text_tree_size_request(GtkWidget *widget,
222 GtkRequisition *requisition,
223 IrrecoListboxText *self)
225 IrrecoListbox *parent;
226 gboolean show_hscrollbar = TRUE;
229 parent = IRRECO_LISTBOX(self);
231 if (requisition->width <= parent->max_width - 22) {
232 show_hscrollbar = FALSE;
235 if (requisition->width < parent->min_width - 22) {
236 requisition->width = parent->min_width - 22;
237 } else if (requisition->width > parent->max_width - 22) {
238 requisition->width = parent->max_width - 22;
241 if (requisition->height < parent->min_height - 22) {
242 requisition->height = parent->min_height - 22;
243 } else if (requisition->height > parent->max_height &&
244 show_hscrollbar == FALSE) {
245 requisition->height = parent->max_height;
246 } else if (requisition->height > parent->max_height - 22) {
247 requisition->height = parent->max_height - 22;
250 if (show_hscrollbar == TRUE) {
251 gtk_widget_show(parent->hscrollbar);
253 gtk_widget_hide(parent->hscrollbar);