help for bluefish



I'm a developer of bluefish, a HTML editor:
http://bluefish.openoffice.nl

We need some help to make a window for autocompletion of tags.
When a key is pressed in a GtkText widget, we must show a window with
only a clist.
The window must appear in the position of the insertion point and must
be always on top.
It must get the focus so the cursor keys change the selection in the
list.

Our program shows (or creates if it isn't) the window with the folowing
code:

void show_autocomplet_window()
{
    gint posx, posy;
    GtkWidget *tmpwin;
    GtkWidget *vbox;
    GtkWidget *scrolled_window;
    GtkWidget *toplevel;

    if (autocompletwindow == NULL) {
        autocompletwindow = gtk_window_new(GTK_WINDOW_POPUP);

gtk_container_set_border_width(GTK_CONTAINER(autocompletwindow),0);

        vbox = gtk_vbox_new(FALSE, 5);
        gtk_container_add(GTK_CONTAINER(autocompletwindow), vbox);
        gtk_widget_show(vbox);

        /* Create a scrolled window to pack the CList widget into */
        scrolled_window = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW
                                       (scrolled_window),
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
        gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE,
0);
        gtk_widget_show(scrolled_window);

        /* Create the CList */
        clist = (GtkCList *) gtk_clist_new(1);

        /* When a selection is made, we want to know about it. The
callback
         * used is selection_made, and its code can be found further
down */

        gtk_signal_connect(GTK_OBJECT(clist), "select_row",
                           GTK_SIGNAL_FUNC(selection_made_cb), NULL);

        /* Add the CList widget to the vertical box and show it. */
        gtk_container_add(GTK_CONTAINER(scrolled_window),
                          GTK_WIDGET(clist));
        gtk_widget_show(GTK_WIDGET(clist));
    }
    /* Calculate the absolute coords. of the cursor */
    /* This doesn't work well. Any help? */
    posx = GTK_TEXT(mainwindow->textbox)->cursor_pos_x;
    posy = GTK_TEXT(mainwindow->textbox)->cursor_pos_y;
    tmpwin = mainwindow->textbox;
    while (tmpwin) {
        posx += tmpwin->allocation.x;
        posy += tmpwin->allocation.y;
        tmpwin = tmpwin->parent;
    }

    gtk_widget_set_uposition(GTK_WIDGET(autocompletwindow), posx + 10,
                             posy + 10);
    gtk_widget_show(autocompletwindow);
    toplevel = gtk_widget_get_toplevel(mainwindow->textbox);
    gtk_window_set_transient_for(GTK_WINDOW(autocompletwindow),
                                 GTK_WINDOW(toplevel));
    gtk_widget_set_state(autocompletwindow, GTK_STATE_ACTIVE |
GTK_STATE_SELECTED);
    gtk_widget_grab_focus(GTK_WIDGET(clist));
}


This code doesn't work as we need in the following aspects:

a)    The window appears in the position of the insertion point only if
you don't move the main window.
When you move the main window, it appears in a wrong position. This
doesn't work well:

    /* Calculate the absolute coords. of the cursor */
    /* This doesn't work well. Any help? */
    posx = GTK_TEXT(mainwindow->textbox)->cursor_pos_x;
    posy = GTK_TEXT(mainwindow->textbox)->cursor_pos_y;
    tmpwin = mainwindow->textbox;
    while (tmpwin) {
        posx += tmpwin->allocation.x;
        posy += tmpwin->allocation.y;
        tmpwin = tmpwin->parent;
    }
    gtk_widget_set_uposition(GTK_WIDGET(autocompletwindow), posx + 10,
                             posy + 10);


b)    The window appears on top of the main window, but if you move the
main window, it doesn't move with it., and while you are moving, it
disappears. We don't want a title bar on the complet window. This
doesn't work well.

    toplevel = gtk_widget_get_toplevel(mainwindow->textbox);
    gtk_window_set_transient_for(GTK_WINDOW(autocompletwindow),
                                 GTK_WINDOW(toplevel));


c)    We want the window to autosize to the contents of the list up to a
maximum size or the edge of the screen. Please, any suggestions?

d)    We want the window to get the focus when its showed, so pressing
the arrow keys, the selection in the list change. This doesn't work

    gtk_widget_set_state(autocompletwindow, GTK_STATE_ACTIVE |
GTK_STATE_SELECTED);
    gtk_widget_grab_focus(GTK_WIDGET(clist));

e)    We would like to close the window programmatically when another
widget or a menu in the main window is clicked. Any suggestions?

f)    Every time its showed, we want it to reset the horizontal status
bar to its origin.

g)    We want to change the background color of the elements of the
clist. (the same for all, say yellow)



If you need a complete file that works, ask me for it and I'll post one.

If anyone of you knows about any program that do the same, please, tell
us where is the source.


For more information about bluefish, visit http://bluefish.openoffice.nl
or send a email to bluefish openoffice nl


Thanks very much.

Santiago Capel, programmer of Bluefish.







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