Fix:graphics_gtk_drawing_area:Improved embedding
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 19 Oct 2009 13:25:16 +0000 (13:25 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 19 Oct 2009 13:25:16 +0000 (13:25 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2673 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr_def.h
navit/navit/graphics.c
navit/navit/graphics.h
navit/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
navit/navit/gui/internal/gui_internal.c
navit/navit/navit.c

index 85592c1..9f0aea3 100644 (file)
@@ -123,6 +123,7 @@ ATTR(delay)
 ATTR(lag)
 ATTR(bpp)
 ATTR(fullscreen)
+ATTR(windowid)
 ATTR2(0x00027500,type_rel_abs_begin)
 /* These attributes are int that can either hold relative              *
  * or absolute values. A relative value is indicated by                *
index 4073daa..f8605bc 100644 (file)
@@ -104,6 +104,16 @@ struct displaylist {
 static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir);
 static void graphics_process_selection(struct graphics *gra, struct displaylist *dl);
 
+int
+graphics_set_attr(struct graphics *gra, struct attr *attr)
+{
+       int ret=1;
+       dbg(0,"enter\n");
+       if (gra->meth.set_attr)
+               ret=gra->meth.set_attr(gra->priv, attr);
+        return ret != 0;
+}
+
 void
 graphics_set_rect(struct graphics *gra, struct point_rect *pr)
 {
@@ -197,6 +207,8 @@ graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, i
 */
 void graphics_init(struct graphics *this_)
 {
+       if (this_->gc[0])
+               return;
        this_->gc[0]=graphics_gc_new(this_);
        graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff});
        graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff });
index 8136dc0..11c7939 100644 (file)
@@ -68,6 +68,7 @@ struct graphics_methods {
        void (*get_text_bbox)(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate);
        void (*overlay_disable)(struct graphics_priv *gr, int disable);
        void (*overlay_resize)(struct graphics_priv *gr, struct point *p, int w, int h, int alpha, int wraparound);
+       int (*set_attr)(struct graphics_priv *gr, struct attr *attr);
 };
 
 
@@ -132,6 +133,7 @@ struct mapset;
 struct point;
 struct point_rect;
 struct transformation;
+int graphics_set_attr(struct graphics *gra, struct attr *attr);
 void graphics_set_rect(struct graphics *gra, struct point_rect *pr);
 struct graphics *graphics_new(struct attr *parent, struct attr **attrs);
 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
index 35d5145..002cb87 100644 (file)
@@ -89,6 +89,7 @@ struct graphics_priv {
        struct timeval button_press[8];
        struct timeval button_release[8];
        int timeout;
+       int delay;
 };
 
 
@@ -759,13 +760,20 @@ motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
  * * Exit navit (X pressed)
  * * @param widget active widget
  * * @param event the event (delete_event)
- * * @param nav our Navit context
+ * * @param user_data Pointer to private data structure
  * * @returns TRUE
  * */
 static gint
-delete(GtkWidget *widget, GdkEventKey *event, struct navit *nav)
+delete(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 {
-       navit_destroy(nav);
+       struct graphics_priv *this=user_data;
+       dbg(0,"enter this->win=%p\n",this->win);
+       if (this->delay & 2) {
+               if (this->win) 
+                       this->win=NULL;
+       } else {
+               navit_destroy(this->nav);
+       }
        return TRUE;
 }
 
@@ -886,6 +894,45 @@ overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int al
        }
 }
 
+static void
+get_data_window(struct graphics_priv *this, unsigned int xid)
+{
+       if (!xid)
+               this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       else
+               this->win = gtk_plug_new(xid);
+       if (!gtk_widget_get_parent(this->widget)) 
+               gtk_widget_ref(this->widget);
+       gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
+       dbg(1,"h= %i, w= %i\n",this->win_h, this->win_w);
+       gtk_window_set_title(GTK_WINDOW(this->win), "Navit");
+       gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", "Navit");
+       gtk_widget_realize(this->win);
+       if (gtk_widget_get_parent(this->widget)) 
+               gtk_widget_reparent(this->widget, this->win);
+       else
+               gtk_container_add(GTK_CONTAINER(this->win), this->widget);
+       gtk_widget_show_all(this->win);
+       GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
+               gtk_widget_set_sensitive(this->widget, TRUE);
+       gtk_widget_grab_focus(this->widget);
+       g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
+       g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this);
+}
+
+static int
+set_attr(struct graphics_priv *gr, struct attr *attr)
+{
+       dbg(0,"enter\n");
+       switch (attr->type) {
+       case attr_windowid:
+               get_data_window(gr, attr->u.num);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 static struct graphics_priv *
 overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha, int wraparound)
 {
@@ -954,7 +1001,8 @@ graphics_gtk_drawing_area_disable_suspend(struct window *w)
 #else
     dbg(1, "failed to kill() under Windows\n");
 #endif
-}              
+}
+
 
 static void *
 get_data(struct graphics_priv *this, char *type)
@@ -971,22 +1019,8 @@ get_data(struct graphics_priv *this, char *type)
                unsigned xid = 0;
                if (cp) 
                        xid = strtol(cp, NULL, 0);
-               if (!xid)
-                       this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-               else
-                       this->win = gtk_plug_new(xid);
-               gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
-               dbg(1,"h= %i, w= %i\n",this->win_h, this->win_w);
-               gtk_window_set_title(GTK_WINDOW(this->win), "Navit");
-               gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", "Navit");
-               gtk_widget_realize(this->win);
-               gtk_container_add(GTK_CONTAINER(this->win), this->widget);
-               gtk_widget_show_all(this->win);
-               GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
-               gtk_widget_set_sensitive(this->widget, TRUE);
-               gtk_widget_grab_focus(this->widget);
-               g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
-       g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this->nav);
+               if (!(this->delay & 1))
+                       get_data_window(this, xid);
                this->window.fullscreen=graphics_gtk_drawing_area_fullscreen;
                this->window.disable_suspend=graphics_gtk_drawing_area_disable_suspend;
                this->window.priv=this;
@@ -1029,6 +1063,7 @@ static struct graphics_methods graphics_methods = {
        NULL,
        overlay_disable,
        overlay_resize,
+       set_attr,
 };
 
 static struct graphics_priv *
@@ -1070,6 +1105,9 @@ graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth,
        this->timeout=100;
        if ((attr=attr_search(attrs, NULL, attr_timeout))) 
                this->timeout=attr->u.num;
+       this->delay=0;
+       if ((attr=attr_search(attrs, NULL, attr_delay))) 
+               this->delay=attr->u.num;
        this->cbl=cbl;
        this->colormap=gdk_colormap_new(gdk_visual_get_system(),FALSE);
        gtk_widget_set_events(draw, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK);
index 26576ea..ce0291f 100644 (file)
@@ -3701,6 +3701,29 @@ static void gui_internal_button(void *data, int pressed, int button, struct poin
        }
 }
 
+static void
+gui_internal_setup_gc(struct gui_priv *this)
+{
+       struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
+       struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
+       struct graphics *gra=this->gra;
+
+       if (this->background)
+               return;
+       this->background=graphics_gc_new(gra);
+       this->background2=graphics_gc_new(gra);
+       this->highlight_background=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->highlight_background, &cbh);
+       this->foreground=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->foreground, &cf);
+       this->text_background=graphics_gc_new(gra);
+       this->text_foreground=graphics_gc_new(gra);
+       graphics_gc_set_foreground(this->background, &this->background_color);
+       graphics_gc_set_foreground(this->background2, &this->background2_color);
+       graphics_gc_set_foreground(this->text_background, &this->text_background_color);
+       graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
+}
+
 //##############################################################################################################
 //# Description:
 //# Comment:
@@ -3710,6 +3733,7 @@ static void gui_internal_resize(void *data, int w, int h)
 {
        struct gui_priv *this=data;
 
+       gui_internal_setup_gc(this);
        if( this->root.w==w && this->root.h==h)
                 return;
 
@@ -3903,8 +3927,6 @@ static void gui_internal_keypress(void *data, char *key)
 static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra)
 {
        struct window *win;
-       struct color cbh={0x9fff,0x9fff,0x9fff,0xffff};
-       struct color cf={0xbfff,0xbfff,0xbfff,0xffff};
        struct transformation *trans=navit_get_trans(this->nav);
 
        win=graphics_get_data(gra, "window");
@@ -3923,18 +3945,6 @@ static int gui_internal_set_graphics(struct gui_priv *this, struct graphics *gra
        graphics_add_callback(gra, this->motion_cb);
        this->keypress_cb=callback_new_attr_1(callback_cast(gui_internal_keypress), attr_keypress, this);
        graphics_add_callback(gra, this->keypress_cb);
-       this->background=graphics_gc_new(gra);
-       this->background2=graphics_gc_new(gra);
-       this->highlight_background=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->highlight_background, &cbh);
-       this->foreground=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->foreground, &cf);
-       this->text_background=graphics_gc_new(gra);
-       this->text_foreground=graphics_gc_new(gra);
-       graphics_gc_set_foreground(this->background, &this->background_color);
-       graphics_gc_set_foreground(this->background2, &this->background2_color);
-       graphics_gc_set_foreground(this->text_background, &this->text_background_color);
-       graphics_gc_set_foreground(this->text_foreground, &this->text_foreground_color);
 
        // set fullscreen if needed
        if (this->fullscreen)
index 1decda7..c084961 100644 (file)
@@ -243,6 +243,7 @@ navit_handle_resize(struct navit *this_, int w, int h)
        sel.u.p_rect.rl.x=w;
        sel.u.p_rect.rl.y=h;
        transform_set_screen_selection(this_->trans, &sel);
+       graphics_init(this_->gra);
        this_->ready |= 2;
        graphics_set_rect(this_->gra, &sel.u.p_rect);
        if (this_->ready == 3)
@@ -1297,7 +1298,6 @@ navit_init(struct navit *this_)
                return;
        }
        dbg(2,"Initializing graphics\n");
-       graphics_init(this_->gra);
        dbg(2,"Setting Vehicle\n");
        navit_set_vehicle(this_, this_->vehicle);
        dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);