enum { // display states
DBNOCONN, // No DB Connection
DBDISPLAY, // DB Info Display
DBEDIT, // DB Info Edit
DBCREATE, // DB Create
TTLDBDISPSTATES
};
enum { // display state types
DISPSENS, // sensitivity
DISPVISIBLE, // visibility
DISPEDITABLE, // editable
TTLDISPTYPES
};
enum { // display state settings
OFF,
ON,
TTLDISPDIRS
};
GPtrArray *dispState[TTLDBDISPSTATES][TTLDISPTYPES][TTLDISPDIRS];
static void _setSensitive(GtkWidget *widget, gpointer s)
{
gboolean sens = (gboolean) GPOINTER_TO_INT(s);
gtk_widget_set_sensitive(widget, sens);
}
static void _setVisible(GtkWidget *widget, gpointer v)
{
gboolean vis = (gboolean) GPOINTER_TO_INT(v);
vis ? gtk_widget_show(widget) : gtk_widget_hide(widget);
}
static void _setEditable(GtkWidget *widget, gpointer e)
{
gboolean edit = (gboolean) GPOINTER_TO_INT(e);
gtk_editable_set_editable(GTK_EDITABLE(widget), edit);
}
void setDispState(int state)
{ // set all widgets ON | OFF for the requested state
int i;
for (i=0;i<TTLDISPDIRS;i++)
{
g_ptr_array_foreach(dispState[state][DISPSENS][i], (GFunc) _setSensitive, GINT_TO_POINTER(i));
g_ptr_array_foreach(dispState[state][DISPVISIBLE][i], (GFunc) _setVisible, GINT_TO_POINTER(i));
g_ptr_array_foreach(dispState[state][DISPEDITABLE][i], (GFunc) _setEditable, GINT_TO_POINTER(i));
}
}
void makeWidgets()
{
int i, j, k;
// make our display state pointer arrays
for (i=0;i<TTLDBDISPSTATES;i++)
for (j=0;j<TTLDISPTYPES;j++)
for (k=0;k<TTLDISPDIRS;k++)
dispState[i][j][k] = g_ptr_array_new();
// A Manage Button that is only displayed when no DB Connection exists, otherwise invisible
button = gtk_button_new_with_label("Manage");
g_signal_connect((button), "clicked", G_CALLBACK(servers), NULL);
g_ptr_array_add(dispState[DBNOCONN][DISPVISIBLE][ON], button);
g_ptr_array_add(dispState[DBDISPLAY][DISPVISIBLE][OFF], button);
g_ptr_array_add(dispState[DBEDIT][DISPVISIBLE][OFF], button);
g_ptr_array_add(dispState[DBCREATE][DISPVISIBLE][OFF], button);
// An Entry Area that is only editable when creating a database, otherwise read-only
entry = gtk_entry_new();
gtk_widget_set_tooltip_text(entry, "Name of the Database");
g_ptr_array_add(dispState[DBNOCONN][DISPEDITABLE][OFF], entry);
g_ptr_array_add(dispState[DBDISPLAY][DISPEDITABLE][OFF], entry);
g_ptr_array_add(dispState[DBEDIT][DISPEDITABLE][OFF], entry);
g_ptr_array_add(dispState[DBCREATE][DISPEDITABLE][ON], entry);
// A button that is sensitive only when editing a database, otherwise not selectable
button = gtk_button_new_with_label("ADD");
g_ptr_array_add(dispState[DBNOCONN][DISPSENS][OFF], button);
g_ptr_array_add(dispState[DBDISPLAY][DISPSENS][OFF], button);
g_ptr_array_add(dispState[DBEDIT][DISPSENS][ON], button);
g_ptr_array_add(dispState[DBCREATE][DISPSENS][ON], button);
// add all other widgets appropriately as they are created
//...
// Initialize Display State to NO DB Connection
setDispState(DBNOCONN);
}