Re: Focus problem



Hi Michael

I paste the code:

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

static GtkWidget *window;
static GtkWidget *view;
static GtkWidget *popup;
static GtkWidget *popup_view;
static gboolean set_focus = FALSE;

static void
destroy_cb(GtkObject *object,gpointer   user_data)
{
        gtk_main_quit ();
}

static gboolean
focus_window(gpointer win)
{
        g_debug("focus win");
        gtk_window_present_with_time(GTK_WINDOW(win),GDK_CURRENT_TIME);
        gtk_window_activate_focus(GTK_WINDOW(win));
        gtk_widget_grab_focus(GTK_WIDGET(win));
        return FALSE;
}


static void
show_cb(GtkWidget *widget, gpointer user_data)
{
        g_debug("show popup");
        focus_window(window);
}

static void
realize_cb(GtkWidget *widget, gpointer user_data)
{
        g_debug("realize popup");
        focus_window(window);
}

static void
focus_in_cb(GtkWidget *widget, gpointer user_data)
{
        g_debug("focus-in");
        //focus_window(window);
}

static void
focus_out_win_cb(GtkWidget *widget, gpointer user_data)
{
        g_debug("focus-out-win");
/*      if (!set_focus)
                focus_window(window);
        else
                set_focus = FALSE;
*/
}

static void
map_cb(GtkWidget *widget, gpointer user_data)
{
        g_debug("map popup");
        focus_window(window);
}

static gboolean
key_press(GtkWidget   *widget,
        GdkEventKey *event,
        gpointer     user_data)
{
        if (event->keyval == GDK_F5)
        {
                if (GTK_WIDGET_VISIBLE(GTK_WIDGET(popup)))
                {
                        gtk_widget_hide(popup);
                }
                else
                {
                        gtk_widget_show_all(popup);
                        focus_window(window);
                        
                        //g_timeout_add(2000,focus_window,window);
                }
        }
        else if (event->keyval == GDK_F6)
        {
                if (GTK_WIDGET_VISIBLE(GTK_WIDGET(popup)))
                {
                        g_debug("focus al popup");
                        set_focus = TRUE;
                        focus_window(popup);
                        gtk_widget_grab_focus(popup_view);
                }
        }

        return FALSE;
}

GtkWidget*
create_popup (void)
{
        popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_transient_for(GTK_WINDOW(popup),GTK_WINDOW(window));
        gtk_window_set_focus_on_map(GTK_WINDOW(popup), FALSE);
        gtk_window_set_type_hint(GTK_WINDOW(popup),
                GDK_WINDOW_TYPE_HINT_TOOLTIP);
        gtk_window_set_decorated(GTK_WINDOW(popup),FALSE);
        gtk_container_set_border_width(GTK_CONTAINER(popup),2);
        gtk_window_resize(GTK_WINDOW(popup),200,200);
        popup_view = gtk_text_view_new();
        GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
        gtk_container_add(GTK_CONTAINER(scroll),popup_view);
        gtk_container_add(GTK_CONTAINER(popup),scroll);
        
        /*g_signal_connect(popup, "show", G_CALLBACK(show_cb), NULL);
        g_signal_connect(popup, "realize", G_CALLBACK(realize_cb),
NULL); g_signal_connect(popup, "map", G_CALLBACK(map_cb), NULL);
        g_signal_connect(popup, "focus-in-event",
G_CALLBACK(focus_in_cb), NULL); */
        
        return popup;
}

GtkWidget*
create_window (void)
{
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_resize(GTK_WINDOW(window),800,600);
        view = gtk_text_view_new();
        gtk_window_set_default(GTK_WINDOW(window),view);
        GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
        gtk_container_add(GTK_CONTAINER(scroll),view);
        gtk_container_add(GTK_CONTAINER(window),scroll);
        g_signal_connect(view, "key-release-event",
G_CALLBACK(key_press), NULL); 
        g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb),
NULL); g_signal_connect(window, "focus-out-event",
G_CALLBACK(focus_out_win_cb), NULL); 
        return window;
}

int
main (int argc, char *argv[])
{
        GtkWidget *window;
        
        gtk_set_locale ();
        gtk_init (&argc, &argv);

        window = create_window ();
        popup = create_popup();
        gtk_widget_show_all (window);

        gtk_main ();
        return 0;
}





El Sat, 29 Nov 2008 16:50:09 -0600
Michael Cronenworth <mike cchtml com> escribiÃ:

Perriman wrote:

Can you help me?? (I attach the example)


  

Sorry, I don't see the example.



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