Re: [gtk-list] Wanted: CList with Popup menu sample code
- From: José Miguel Rodríguez <jmiguel ceselsa es>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Wanted: CList with Popup menu sample code
- Date: Thu, 07 Oct 1999 14:50:25 +0100
robert_gasch@peoplesoft.com wrote:
>
> Hi,
>
> after some putzing around, I'm still having trouble creating a clist which
> displays a popup window when an item in the CList is selected. If anybody
> knows of some sample code which does this, I'd appreciate a pointer ...
>
> Thanks a lot
> --> Robert
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
You can see this (ESQL-C) example. It works, but you must remove sql code.
The code is incomplete, and the style is bad.
Good luck!
- José Miguel
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE SQLDA;
extern GtkWidget *TableField(GtkWidget *parent, gchar *tit, gint ncols, gchar *cols[]);
extern void frTableDescr(char *);
extern void frTableQuery(char *);
extern long SQLCheckError();
extern char *NombreBD;
extern GtkWidget *top;
void cbMenuTables(GtkWidget *item, int *numero);
/*
El Tema de los menús es para volverse loco.
De una manera o de otra, siempre es necesario tener
datos globales.
*/
static struct POPUP_ITEMS {
gchar *texto;
GtkSignalFunc cb;
gint data;
GtkWidget *menuItem;
} popm[] = {
{"Descripción", cbMenuTables, 0, NULL},
{"Más Datos", cbMenuTables, 1, NULL},
{"Query", cbMenuTables, 2, NULL},
{"Borrar la Tabla", cbMenuTables, 3, NULL}
};
static struct BUTTS {
char *label;
GtkWidget *but;
struct BUTDATA {
int butNumber;
GtkWidget *lista;
} data;
} botones[] = {
{"$ingres", NULL, {0, NULL}},
{"I", NULL, {1, NULL}},
{"T", NULL, {2, NULL}},
{"V", NULL, {3, NULL}},
{NULL, NULL, {0, NULL}}
};
struct LOADFLAGS {
char allUsers:1;
char I:1;
char T:1;
char V:1;
};
/* */
void loadTableList(struct LOADFLAGS flags, GtkWidget *lista) {
EXEC SQL BEGIN DECLARE SECTION;
char name[33], owner[33], type[2];
EXEC SQL END DECLARE SECTION;
char *linea[3] = {name, owner, type};
gtk_clist_clear(GTK_CLIST(lista));
if(flags.allUsers) {
EXEC SQL
SELECT SQUEEZE(table_name), table_owner, table_type
INTO :name, :owner, :type
FROM iitables
ORDER BY 2, 1;
EXEC SQL BEGIN;
gtk_clist_append(GTK_CLIST(lista), linea);
EXEC SQL END;
SQLCheckError();
} else {
EXEC SQL
SELECT SQUEEZE(table_name), table_owner, table_type
INTO :name, :owner, :type
FROM iitables
WHERE table_owner != '$ingres'
ORDER BY 2, 1;
EXEC SQL BEGIN;
gtk_clist_append(GTK_CLIST(lista), linea);
EXEC SQL END;
SQLCheckError();
}
}
/* */
void menuPos(GtkMenu *menu, gint *x, gint *y, gpointer data) {
gtk_object_set_data(GTK_OBJECT(menu), "NombreTabla", data);
}
/* */
void cbMenuTables(GtkWidget *item, int *numero) {
char *tabla;
tabla = gtk_object_get_data(GTK_OBJECT(item->parent), "NombreTabla");
switch(*numero) {
case 0:
/* Descripción */
frTableDescr(tabla);
break;
case 1:
/* Más Datos */
break;
case 2:
/* Query */
frTableQuery(tabla);
break;
case 3:
/* Borrar la Tabla */
break;
}
}
/* */
void cbSelectColumn(GtkWidget *lista, gint column, gpointer data) {
gtk_clist_set_sort_column(GTK_CLIST(lista), column);
gtk_clist_sort(GTK_CLIST(lista));
}
/* */
int cbSelectTable(GtkWidget *lista, int row, int col, GdkEventButton *ev, gpointer data) {
char *tabla, *tipo;
GtkWidget *menu;
gtk_clist_get_text(GTK_CLIST(lista), row, 0, &tabla);
gtk_clist_get_text(GTK_CLIST(lista), row, 2, &tipo);
switch(ev->button) {
case 1: /* Left */
frTableDescr(tabla);
break;
case 3: /* Right */
menu = gtk_object_get_data(GTK_OBJECT(lista), "PopupMenu");
if(menu) {
if(popm[2].menuItem) {
/*
if(tipo[0] == 'T') {
gtk_widget_set_sensitive(popm[2].menuItem, TRUE);
} else {
gtk_widget_set_sensitive(popm[2].menuItem, FALSE);
}
*/
}
gtk_menu_set_title(GTK_MENU(menu), tabla);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, menuPos, (gpointer)tabla, NULL, NULL);
}
}
}
/* */
int cbUserButton(GtkWidget *button, gpointer data) {
GtkWidget *lista = (GtkWidget*)data;
struct LOADFLAGS flags;
int i;
for(i = 0; botones[i].label; i++) {
if(GTK_TOGGLE_BUTTON(button)->active) {
flags.allUsers = TRUE;
} else {
flags.allUsers = FALSE;
}
}
loadTableList(flags, lista);
}
/* */
void frTables() {
char *titles[] = {"Nombre:", "Propietario:", "Tipo:"};
int i;
struct LOADFLAGS flags;
GtkWidget *box, *bbox, *tableField, *lista, *menu;
gtk_widget_show((box = gtk_vbox_new(FALSE, 2)));
gtk_widget_show((bbox = gtk_hbox_new(FALSE, 2)));
for(i = 0; botones[i].label; i++) {
botones[i].but = gtk_check_button_new_with_label(botones[i].label);
gtk_widget_show(botones[i].but);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(botones[i].but), TRUE);
gtk_box_pack_start(GTK_BOX(bbox), botones[i].but, FALSE, TRUE, 0);
GTK_WIDGET_UNSET_FLAGS(botones[i].but, GTK_CAN_FOCUS);
gtk_signal_connect(GTK_OBJECT(botones[i].but), "toggled",
GTK_SIGNAL_FUNC(cbUserButton), (gpointer)&botones[i].data);
}
gtk_container_add(GTK_CONTAINER(top), box);
gtk_box_pack_start(GTK_BOX(box), bbox, FALSE, TRUE, 0);
tableField = TableField(NULL, "Tablas en la Base de Datos", 3, titles);
gtk_signal_connect(GTK_OBJECT(tableField), "destroy", GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
gtk_box_pack_end(GTK_BOX(box), tableField, TRUE, TRUE, 0);
gtk_widget_show_all(top);
lista = gtk_object_get_data(GTK_OBJECT(tableField), "TFList");
for(i = 0; botones[i].label; i++) {
botones[i].data.lista = lista;
}
flags.allUsers = TRUE;
loadTableList(flags, lista);
gtk_clist_columns_autosize(GTK_CLIST(lista));
gtk_clist_set_button_actions(GTK_CLIST(lista), 2, GTK_BUTTON_SELECTS);
gtk_signal_connect_after(GTK_OBJECT(lista), "select_row", GTK_SIGNAL_FUNC(cbSelectTable), NULL); gtk_signal_connect(GTK_OBJECT(lista), "click_column", GTK_SIGNAL_FUNC(cbSelectColumn), NULL);
menu = gtk_menu_new();
for(i = 0; i < 4; i++) {
gtk_widget_show((popm[i].menuItem = gtk_menu_item_new_with_label(popm[i].texto)));
gtk_menu_append(GTK_MENU(menu), popm[i].menuItem);
gtk_signal_connect(GTK_OBJECT(popm[i].menuItem), "activate", popm[i].cb, (gpointer)&popm[i].data);
}
gtk_object_set_data(GTK_OBJECT(lista), "PopupMenu", menu);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]