Re: Treeview column width changed signal



Jeffrey Barish wrote:
Kristian Rietveld wrote:

The problem with your first suggestion is that I have to hook every
situation in which the tree view can be destroyed.  The obvious one is when
I change data sets.  Exiting the program is another.  There will be others
when I implement more of the program.  It certainly is possible to record
the column widths at each of these points, but it sure is clumsy.


I do this exact thing in an application I'm developing now. But I only do it in one place - a callback routine that is called for both the delete and destroy events.

The problem with the second suggestion is that writing a file is exactly
what I need to do.  The point of this exercise is to record in a file the
width of each column as established by the user with the mouse so that the
columns will have the same width the next time the program runs.


Again, I do the same - in my case, entries in an sqlite database. Some routines are left out, but what I have included should give you the idea.

You don't hide/delete a window often at all (well - certainly not "often" as far as the computer is concerned), and the time required isn't noticeable - period.

Hope this helps?


First, setting the handlers:

    SetSignalHandler(GTK_WIDGET(GetSWWindow()),"delete-event",
                     G_CALLBACK(HideSongWindow));
    SetSignalHandler(GTK_WIDGET(GetSWWindow()), "destroy-event",
                     G_CALLBACK(HideSongWindow));


ANd then:

static void HideSongWindow(void)
{
    SWSaveWindowPos();
    SWSetVisible(FALSE);
}

void SWSaveWindowPos(void)
{
    GList               *cols;
    int                 index = 0;

    privateOpenDatabase();
    avSaveWindowGeometry(GetSWWindow(),NULL, NULL);
    /*
    ** save the order and size data for the different columns
    */
    cols = gtk_tree_view_get_columns(GetSWTreeView());
    g_list_foreach(cols, (GFunc) SWSaveColumnData, (gpointer) &index);
    g_list_free(cols);
    privateCloseDatabase();
}

static void SWSaveColumnData(GtkTreeViewColumn *column, int *index)
{
    char                name[32],
                        value[64];
    int                 width;

    if (*index)
    {
        g_object_get(G_OBJECT(column), "width", &width, NULL);
        sprintf(name,"SongWindowListColumn%02d", *index);
        sprintf(value,"%d %d %d %s",
                gtk_tree_view_column_get_sort_column_id(column),
                gtk_tree_view_column_get_visible(column),
                width,
                gtk_tree_view_column_get_title(column));
        avStoreConfData(name, value);
    }
    (*index)++;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]