summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/droplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/gtklib/droplist.c')
-rw-r--r--app/wlib/gtklib/droplist.c441
1 files changed, 222 insertions, 219 deletions
diff --git a/app/wlib/gtklib/droplist.c b/app/wlib/gtklib/droplist.c
index 91406fc..a4abced 100644
--- a/app/wlib/gtklib/droplist.c
+++ b/app/wlib/gtklib/droplist.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
@@ -51,30 +51,30 @@
int
wlibDropListAddColumns(GtkWidget *dropList, int columns)
{
- int i;
- int start = 0;
- GtkCellRenderer *cell;
-
- if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) {
- start = 1;
- }
-
- /* Create cell renderer. */
- cell = gtk_cell_renderer_text_new();
-
- for (i = start; i < columns; i++) {
- /* Pack it into the droplist */
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE);
-
- /* Connect renderer to data source */
- gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList),
- cell,
- "text",
- LISTCOL_TEXT + i,
- NULL);
- }
-
- return (i);
+ int i;
+ int start = 0;
+ GtkCellRenderer *cell;
+
+ if (gtk_combo_box_get_has_entry(GTK_COMBO_BOX(dropList))) {
+ start = 1;
+ }
+
+ /* Create cell renderer. */
+ cell = gtk_cell_renderer_text_new();
+
+ for (i = start; i < columns; i++) {
+ /* Pack it into the droplist */
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropList), cell, TRUE);
+
+ /* Connect renderer to data source */
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropList),
+ cell,
+ "text",
+ LISTCOL_TEXT + i,
+ NULL);
+ }
+
+ return (i);
}
/**
@@ -86,7 +86,7 @@ wlibDropListAddColumns(GtkWidget *dropList, int columns)
wIndex_t wDropListGetCount(wList_p b)
{
- return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL));
+ return (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(b->listStore), NULL));
}
/**
@@ -99,7 +99,7 @@ wIndex_t wDropListGetCount(wList_p b)
void
wDropListClear(wList_p b)
{
- wlibListStoreClear(b->listStore);
+ wlibListStoreClear(b->listStore);
}
/**
@@ -111,22 +111,22 @@ wDropListClear(wList_p b)
void *wDropListGetItemContext(wList_p b, wIndex_t inx)
{
- GtkTreeIter iter;
- wListItem_p data = NULL;
-
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
- inx)) {
- gtk_tree_model_get(GTK_TREE_MODEL(b->listStore),
- &iter,
- LISTCOL_DATA, (void *)&data,
- -1);
- }
-
- if (data) {
- return (data->itemData);
- } else {
- return (NULL);
- }
+ GtkTreeIter iter;
+ wListItem_p data = NULL;
+
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
+ inx)) {
+ gtk_tree_model_get(GTK_TREE_MODEL(b->listStore),
+ &iter,
+ LISTCOL_DATA, (void *)&data,
+ -1);
+ }
+
+ if (data) {
+ return (data->itemData);
+ } else {
+ return (NULL);
+ }
}
/**
@@ -138,21 +138,21 @@ void *wDropListGetItemContext(wList_p b, wIndex_t inx)
*/
void wDropListAddValue(
- wList_p b,
- char *text,
- wListItem_p data)
+ wList_p b,
+ char *text,
+ wListItem_p data)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- assert(b != NULL);
- assert(text != NULL);
+ assert(b != NULL);
+ assert(text != NULL);
- gtk_list_store_append(b->listStore, &iter); // append new row to tree store
+ gtk_list_store_append(b->listStore, &iter); // append new row to tree store
- gtk_list_store_set(b->listStore, &iter,
- LISTCOL_TEXT, text,
- LISTCOL_DATA, (void *)data,
- -1);
+ gtk_list_store_set(b->listStore, &iter,
+ LISTCOL_TEXT, text,
+ LISTCOL_DATA, (void *)data,
+ -1);
}
/**
@@ -162,25 +162,25 @@ void wDropListAddValue(
*/
void wListSetValue(
- wList_p bl,
- const char * val)
+ wList_p bl,
+ const char * val)
{
- assert(bl->listStore!=NULL);
+ assert(bl->listStore!=NULL);
- bl->recursion++;
+ bl->recursion++;
- if (bl->type == B_DROPLIST) {
- bl->editted = TRUE;
- gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val);
+ if (bl->type == B_DROPLIST) {
+ bl->editted = TRUE;
+ gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget))), val);
- if (bl->action) {
- bl->action(-1, val, 0, bl->data, NULL);
- }
- } else {
- assert(FALSE);
- }
+ if (bl->action) {
+ bl->action(-1, val, 0, bl->data, NULL);
+ }
+ } else {
+ assert(FALSE);
+ }
- bl->recursion--;
+ bl->recursion--;
}
/**
@@ -195,11 +195,11 @@ void wListSetValue(
void wDropListSetIndex(wList_p b, int val)
{
- if ((b->option&BL_NONE)!=0 && val < 0) {
- gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1);
- } else {
- gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val);
- }
+ if ((b->option&BL_NONE)!=0 && val < 0) {
+ gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), -1);
+ } else {
+ gtk_combo_box_set_active(GTK_COMBO_BOX(b->widget), val);
+ }
}
/**
@@ -214,24 +214,24 @@ void wDropListSetIndex(wList_p b, int val)
*/
wBool_t wDropListSetValues(
- wList_p b,
- wIndex_t row,
- const char * labelStr,
- wIcon_p bm,
- void *itemData)
+ wList_p b,
+ wIndex_t row,
+ const char * labelStr,
+ wIcon_p bm,
+ void *itemData)
{
- GtkTreeIter iter;
-
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
- row)) {
- gtk_list_store_set(b->listStore,
- &iter,
- LISTCOL_TEXT, labelStr,
- -1);
- return (TRUE);
- } else {
- return (FALSE);
- }
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(b->listStore), &iter, NULL,
+ row)) {
+ gtk_list_store_set(b->listStore,
+ &iter,
+ LISTCOL_TEXT, labelStr,
+ -1);
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
}
/**
@@ -245,72 +245,75 @@ wBool_t wDropListSetValues(
*/
static int DropListChanged(
- GtkComboBox * comboBox,
- gpointer data)
+ GtkComboBox * comboBox,
+ gpointer data)
{
- wList_p bl = (wList_p)data;
- GtkTreeIter iter;
-
- wIndex_t inx = 0;
- gchar *string = NULL;
- wListItem_p listItemP = NULL;
-
- if (bl->recursion) {
- return 0;
- }
-
- /* Obtain currently selected item from combo box. */
- if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) {
- GtkTreeModel *model;
-
- /* Obtain data model from combo box. */
- model = gtk_combo_box_get_model(comboBox);
-
- /* get the selected row */
- string = gtk_tree_model_get_string_from_iter(model,
- &iter);
- inx = atoi(string);
- g_free(string);
- string = NULL;
-
- /* Obtain string from model. */
- gtk_tree_model_get(model, &iter,
- LISTCOL_TEXT, &string,
- LISTCOL_DATA, (void *)&listItemP,
- -1);
- bl->editted = FALSE;
-
- } else {
- /* Nothing selected, user is entering text directly */
- inx = -1;
- GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget)));
- if ( entry == NULL )
- return 0;
- const char * string1 = gtk_entry_get_text(entry);
- if ( string1 == NULL )
- return 0;
- string = g_strdup(string1);
- bl->editted = TRUE;
- }
-
- /* selection changed, store new selections and call back */
- if (bl->last != inx || bl->editted == TRUE) {
-
- bl->last = inx;
-
- if (bl->valueP) {
- *bl->valueP = inx;
- }
-
- /* selection changed -> callback */
- if (string && bl->action) {
- bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL);
- }
- }
-
- if ( string )
- g_free(string);
- return 1;
+ wList_p bl = (wList_p)data;
+ GtkTreeIter iter;
+
+ wIndex_t inx = 0;
+ gchar *string = NULL;
+ wListItem_p listItemP = NULL;
+
+ if (bl->recursion) {
+ return 0;
+ }
+
+ /* Obtain currently selected item from combo box. */
+ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(comboBox), &iter)) {
+ GtkTreeModel *model;
+
+ /* Obtain data model from combo box. */
+ model = gtk_combo_box_get_model(comboBox);
+
+ /* get the selected row */
+ string = gtk_tree_model_get_string_from_iter(model,
+ &iter);
+ inx = atoi(string);
+ g_free(string);
+ string = NULL;
+
+ /* Obtain string from model. */
+ gtk_tree_model_get(model, &iter,
+ LISTCOL_TEXT, &string,
+ LISTCOL_DATA, (void *)&listItemP,
+ -1);
+ bl->editted = FALSE;
+
+ } else {
+ /* Nothing selected, user is entering text directly */
+ inx = -1;
+ GtkEntry * entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(bl->widget)));
+ if ( entry == NULL ) {
+ return 0;
+ }
+ const char * string1 = gtk_entry_get_text(entry);
+ if ( string1 == NULL ) {
+ return 0;
+ }
+ string = g_strdup(string1);
+ bl->editted = TRUE;
+ }
+
+ /* selection changed, store new selections and call back */
+ if (bl->last != inx || bl->editted == TRUE) {
+
+ bl->last = inx;
+
+ if (bl->valueP) {
+ *bl->valueP = inx;
+ }
+
+ /* selection changed -> callback */
+ if (string && bl->action) {
+ bl->action(inx, string, 1, bl->data, listItemP?listItemP->itemData:NULL);
+ }
+ }
+
+ if ( string ) {
+ g_free(string);
+ }
+ return 1;
}
/**
@@ -324,15 +327,15 @@ static int DropListChanged(
GtkWidget *
wlibNewDropList(GtkListStore *ls, int editable)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- if (editable) {
- widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls));
- } else {
- widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls));
- }
+ if (editable) {
+ widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(ls));
+ } else {
+ widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls));
+ }
- return (widget);
+ return (widget);
}
/**
@@ -352,80 +355,80 @@ wlibNewDropList(GtkListStore *ls, int editable)
*/
wList_p wDropListCreate(
- wWin_p parent,
- wWinPix_t x,
- wWinPix_t y,
- const char * helpStr,
- const char * labelStr,
- long option,
- long number,
- wWinPix_t width,
- long *valueP,
- wListCallBack_p action,
- void *data)
+ wWin_p parent,
+ wWinPix_t x,
+ wWinPix_t y,
+ const char * helpStr,
+ const char * labelStr,
+ long option,
+ long number,
+ wWinPix_t width,
+ long *valueP,
+ wListCallBack_p action,
+ void *data)
{
- wList_p b;
+ wList_p b;
- b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data);
- b->option = option;
- b->number = number;
- b->count = 0;
- b->last = -1;
- b->valueP = valueP;
- b->action = action;
- b->listX = b->realX;
- b->colCnt = 0;
- b->colWidths = NULL;
- b->colRightJust = NULL;
- b->editable = ((option & BL_EDITABLE) != 0);
+ b = (wList_p)wlibAlloc(parent, B_DROPLIST, x, y, labelStr, sizeof *b, data);
+ b->option = option;
+ b->number = number;
+ b->count = 0;
+ b->last = -1;
+ b->valueP = valueP;
+ b->action = action;
+ b->listX = b->realX;
+ b->colCnt = 0;
+ b->colWidths = NULL;
+ b->colRightJust = NULL;
+ b->editable = ((option & BL_EDITABLE) != 0);
- assert(width != 0);
+ assert(width != 0);
- wlibComputePos((wControl_p)b);
+ wlibComputePos((wControl_p)b);
- // create tree store for storing the contents
- b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS);
+ // create tree store for storing the contents
+ b->listStore = wlibNewListStore(DROPLIST_TEXTCOLUMNS);
- if (!b->listStore) {
- abort();
- }
+ if (!b->listStore) {
+ abort();
+ }
- // create the droplist
- b->widget = wlibNewDropList(b->listStore,
- option & BL_EDITABLE);
+ // create the droplist
+ b->widget = wlibNewDropList(b->listStore,
+ option & BL_EDITABLE);
- if (b->widget == 0) {
- abort();
- }
- g_object_ref_sink(b->listStore);
- g_object_unref(G_OBJECT(b->listStore));
+ if (b->widget == 0) {
+ abort();
+ }
+ g_object_ref_sink(b->listStore);
+ g_object_unref(G_OBJECT(b->listStore));
- wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS);
+ wlibDropListAddColumns(b->widget, DROPLIST_TEXTCOLUMNS);
- gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget),
- LISTCOL_TEXT);
+ gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(b->widget),
+ LISTCOL_TEXT);
- // combo's style
- gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" ");
- gtk_widget_set_name(b->widget,"mycombo");
+ // combo's style
+ gtk_rc_parse_string("style \"my-style\" { GtkComboBox::appears-as-list = 1 } widget \"*.mycombo\" style \"my-style\" ");
+ gtk_widget_set_name(b->widget,"mycombo");
- g_signal_connect(GTK_OBJECT(b->widget), "changed",
- G_CALLBACK(DropListChanged), b);
+ g_signal_connect(GTK_OBJECT(b->widget), "changed",
+ G_CALLBACK(DropListChanged), b);
- gtk_widget_set_size_request(b->widget, width, -1);
+ gtk_widget_set_size_request(b->widget, width, -1);
- gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
- wlibControlGetSize((wControl_p)b);
+ gtk_fixed_put(GTK_FIXED(parent->widget), b->widget, b->realX, b->realY);
+ wlibControlGetSize((wControl_p)b);
- if (labelStr) {
- b->labelW = wlibAddLabel((wControl_p)b, labelStr);
- }
+ if (labelStr) {
+ b->labelW = wlibAddLabel((wControl_p)b, labelStr);
+ }
- gtk_widget_show(b->widget);
- wlibAddButton((wControl_p)b);
- wlibAddHelpString(b->widget, helpStr);
+ gtk_widget_show(b->widget);
+ wlibAddButton((wControl_p)b);
+ wlibAddHelpString(b->widget, helpStr);
- return b;
+ return b;
}