Re: [gtk-list] Misc. questions (and 'GtkSQL' announcement)



To address your points in order:
There probably never will be a get_tab_label, because the object on the
tab can be any type of container AFAIK not just a label.

I use something more like:
struct node {
            int             key;
        int             namelen;
        char    *catname;
    struct node *prev;
    struct node *next;
    int *current_key;
}

Create tempnode as a linked list of nodes, for example, and then

    for(tempnode=booklist->next;
            tempnode->key;
            tempnode=tempnode->next) {
        tempnode->current_key = current_key;
        menuitem=gtk_radio_menu_item_new_with_label(group,
                        tempnode->catname);
        gtk_signal_connect_object (GTK_OBJECT (menuitem), "activate",
                        GTK_SIGNAL_FUNC (book_set_current),
                        (gpointer) tempnode);
        group = gtk_radio_menu_item_group
                        (GTK_RADIO_MENU_ITEM (menuitem));
        gtk_menu_append (GTK_MENU(menu), menuitem);
    }

I know this is for menuitems, and it won't compile as given, because I
monkeyed it up out of a lot of bits of code from a large application I'm
writing, but it should give the idea, converting to tabs, or anything else
shouldn't be difficult. Then you have a function something like:

    15  void
    16  book_set_current(GtkWidget *widget, booklistentry *tempnode)
    17  {
    18      /* This sets the *current_key for the entire list */
    19      *(tempnode->current_key) = tempnode->key;
    20      g_print("Current key is now %d\n", *(tempnode->current_key));
    21  }

And then all you need is any list node, and you immediately know what the
current list node selected is. The base node will do. It's a parallel
structure mirroring the GTK structure to some extent, and the reason for
storing the extra pointer in each struct is so that you only have your one
void* argument to pass to the callback function.

Second, yes, there is a grab_focus or something, but it's bad manners,
IMHO. gtk_window_set_focus(). I don't guarantee this, I haven't tried it.

Third:
gtk_widget_grab_focus (entry);
I'm not totally 100% about setting a default button and a text entry, I
need to experiment. Probably, I need to set a key_press_event in the
focused text box to grep for the enter key being pressed, rather than
setting a default button, as I think the default button looks horrible.


Fourth: no idea, I with I had the time to try it. I will have a go at it
this next day or so, so if anyone else has a quick fragment to do tab
expansion in a text entry, I would also be grateful, for that and the
enter key. Else I'll write one in a day or so.

--
S.
GM/CS/MU -d+ H+>++ s+: !g p2 au0 !a w+++ v-(---) C++++$ UL++++$ UB+
US++ UI+++$ P+>++++ L++++$ 3+ E--- N+ K !W(-----) M+(-) !V -po+ Y+ t+
5++ !j !R G' !tv b+++ D++ B--- e+ u+* h++ f? r-- n---- y?


On Sat, 2 May 1998, Lionel ULMER wrote:

>   I am writing a query tool for PostgreSQL using Gtk. The home page
> for this project is at the following URL :
>              http://www.mygale.org/~bbrox/GtkSQL/
> 
>   Its main features are :
>    -  multiple SQL buffers
>    -  SQL keywords, table names and fields autocompletion
>    -  easy displaying of tables definitions
>    -  exporting of query results
> 
>   In writing this application, I had some problems :
> 
>    1) I need to have access to the tab labels in a notebook and to
>   the widget stored in it. What is the 'correct' thing to do :
>      - hope that 'gtk_notebook_get_tab_label',
>        'gtk_notebook_get_page', ... will be in a future version of Gtk
>      - use GtkNotebook's "insides" to write them yourself (it is what
>        I have done).
>      - use (for the Widgets stored in the pages) a parallel data
>        structure to store them
> 
>    2) is it possible with a gdk call to ask the window manager to put
>   one window on the foreground ?
> 
>    3) how can we create a text zone with a cursor in it ? I needed
>   this because I want to be able to do everything (well, almost
>   everything) without the mouse. If you need to click on a new text
>   zone before you can type in it, it is quite painful. To do this I
>   added 'GTK_TEXT(current_query)->has_cursor = TRUE;'
>   in my code. It works, but is it as ugly as I think it is :-) ?
> 
>    4) to do autocompletion with 'TAB', I wanted to use the
>   "key_press_event" signal. But there is apparently a bug in the Text
>   zone code. If you compile the following code, type some letters and
>   then move with the arrows, the 'gtk_text_get_point' call does NOT
>   return the position where the typed character will go...
> 
> #include <gtk/gtk.h>
> 
> GtkWidget *text;
> 
> void test(GtkWidget *widget, GdkEvent *event, gpointer data)
> {
>   g_print("%d\n", gtk_text_get_point(GTK_TEXT(text)));
> }
> 
> int main (int argc, char *argv[])
> {
>   GtkWidget *window, *vbox;
> 
>   gtk_init (&argc, &argv);
>   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>   vbox = gtk_vbox_new(FALSE, 0);
>   text = gtk_text_new (NULL, NULL);
>   gtk_text_set_editable (GTK_TEXT(text), TRUE);
>   gtk_signal_connect (GTK_OBJECT (text), "key_press_event",
> 		      GTK_SIGNAL_FUNC (test), NULL);
>   gtk_box_pack_start (GTK_BOX(vbox), text, TRUE, TRUE, 0);
>   gtk_container_add (GTK_CONTAINER (window), vbox);
>   gtk_widget_show (text);
>   gtk_widget_show (vbox);
>   gtk_widget_show (window);
>   gtk_main ();
>   
>   return 0;
> }
> 
>   Well, that's all for the moment :-)
> 
> --
>   Lionel ULMER (ulmer@email.enst.fr / bbrox@mygale.org)
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
> 



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