summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--navit/gui/internal/gui_internal.c34
-rw-r--r--navit/gui/internal/gui_internal_menu.c164
-rw-r--r--navit/gui/internal/gui_internal_menu.h5
-rw-r--r--navit/gui/internal/gui_internal_widget.c67
-rw-r--r--navit/gui/internal/gui_internal_widget.h8
5 files changed, 217 insertions, 61 deletions
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index 39e0b6d18..23b1ba007 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -476,7 +476,7 @@ gui_internal_time_help(struct gui_priv *this) {
/**
* Applies the configuration values to this based on the settings
* specified in the configuration file (this->config) and
- * the most approriate default profile based on screen resolution.
+ * the most appropriate default profile based on screen resolution.
*
* This function should be run after this->root is setup and could
* be rerun after the window is resized.
@@ -2684,15 +2684,18 @@ static void gui_internal_setup(struct gui_priv *this) {
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gui_internal_resize(void *data, int w, int h) {
+static void gui_internal_resize(void *data, int wnew, int hnew) {
+ GList *l;
+ struct widget *w;
+
struct gui_priv *this=data;
int changed=0;
gui_internal_setup(this);
- if (this->root.w != w || this->root.h != h) {
- this->root.w=w;
- this->root.h=h;
+ if (this->root.w != wnew || this->root.h != hnew) {
+ this->root.w=wnew;
+ this->root.h=hnew;
changed=1;
}
/*
@@ -2701,11 +2704,26 @@ static void gui_internal_resize(void *data, int w, int h) {
*/
if (!changed && this->gra && graphics_get_data(this->gra, "padding"))
changed = 1;
- dbg(lvl_debug,"w=%d h=%d children=%p", w, h, this->root.children);
- navit_handle_resize(this->nav, w, h);
+ dbg(lvl_debug,"w=%d h=%d children=%p", wnew, hnew, this->root.children);
+ navit_handle_resize(this->nav, wnew, hnew);
if (this->root.children) {
if (changed) {
- gui_internal_html_main_menu(this);
+ l = g_list_last(this->root.children);
+ if (l) {
+ w=l->data;
+ void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
+ redisplay=w->menu_data->redisplay;
+ dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'=');
+ if (!gui_internal_widget_reload_href(this, w)) {
+ dbg(lvl_error, "Current GUI displayed is not a menu");
+ dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew)
+ gui_internal_menu_resize(this, wnew, hnew);
+ gui_internal_menu_render(this);
+ }
+ }
+ else {
+ dbg(lvl_error,"Current GUI displayed is a menu");
+ }
} else {
gui_internal_menu_render(this);
}
diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c
index 9da7f2e4c..4b9512b0a 100644
--- a/navit/gui/internal/gui_internal_menu.c
+++ b/navit/gui/internal/gui_internal_menu.c
@@ -17,7 +17,7 @@
extern char *version;
-static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
+void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
struct menu_data *menu_data=w->menu_data;
if (menu_data) {
if (menu_data->refresh_callback_obj.type) {
@@ -36,11 +36,53 @@ static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
this->root.children=g_list_remove(this->root.children, w);
}
+/**
+ * @brief Retrieve then html anchor (href) from a menu widger
+ *
+ * @param w A widget corresponding to a menu (this widget should be an html menu)
+ *
+ * @return the string for the href, or NULL if this menu has no href (or the widget is not a menu)
+ */
+static char *gui_internal_widget_get_href(struct widget *w) {
+ if (w && w->menu_data)
+ return w->menu_data->href;
+ else
+ return NULL;
+}
+
+/**
+ * @brief Reload a menu from its anchor (href)
+ *
+ * @param this The internal GUI context
+ * @param w A widget corresponding to the menu to redraw (this widget should be an html menu, thus it should have a href)
+ *
+ * @return 1 in case of success, 0 if no menu could be reloaded
+ * @note If the widget provided in @p w has no href, we will return 0
+ */
+int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w) {
+ char *ohref = gui_internal_widget_get_href(w);
+ if (ohref) {
+ char *href=g_strdup(ohref);
+ gui_internal_menu_destroy(this, w);
+ gui_internal_html_load_href(this, href, 0);
+ g_free(href);
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * @brief Destroy (discard) all menu screens that have been placed after widget @p w
+ *
+ * @param this The internal GUI context
+ * @param w A widget corresponding to the last menu to keep (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed.
+ * @param render whether we should render the menu indicated by widget w (render!=0) or not (render==0)
+ */
static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render) {
GList *l;
struct widget *wr,*wd;
gui_internal_search_idle_end(this);
- while ((l = g_list_last(this->root.children))) {
+ while ((l = g_list_last(this->root.children))) { /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */
wd=l->data;
if (wd == w) {
void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
@@ -49,7 +91,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w,
gui_internal_say(this, w, 0);
redisplay=w->menu_data->redisplay;
wr=w->menu_data->redisplay_widget;
- if (!w->menu_data->redisplay && !w->menu_data->href) {
+ if (!redisplay && !gui_internal_widget_get_href(w)) {
gui_internal_widget_render(this, w);
return;
}
@@ -57,10 +99,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w,
gui_internal_menu_destroy(this, w);
redisplay(this, wr, wr->data);
} else {
- char *href=g_strdup(w->menu_data->href);
- gui_internal_menu_destroy(this, w);
- gui_internal_html_load_href(this, href, 0);
- g_free(href);
+ gui_internal_widget_reload_href(this, w);
}
return;
}
@@ -83,6 +122,30 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
}
}
+void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ w->w=neww;
+ w->h=newh;
+}
+
+void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ struct padding *padding = NULL;
+
+ if (this->gra) {
+ padding = graphics_get_data(this->gra, "padding");
+ } else
+ dbg(lvl_warning, "cannot get padding: this->gra is NULL");
+ if (padding) {
+ w->p.x = padding->left;
+ w->p.y = padding->top;
+ w->w = neww - padding->left - padding->right;
+ w->h = newh - padding->top - padding->bottom;
+ } else {
+ w->p.x = 0;
+ w->p.y = 0;
+ w->w = neww;
+ w->h = newh;
+ }
+}
/**
* @brief Initializes a GUI screen
@@ -101,31 +164,15 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
struct widget *
gui_internal_menu(struct gui_priv *this, const char *label) {
struct widget *menu,*w,*w1,*topbox;
- struct padding *padding = NULL;
-
- if (this->gra) {
- padding = graphics_get_data(this->gra, "padding");
- } else
- dbg(lvl_warning, "cannot get padding: this->gra is NULL");
gui_internal_search_idle_end(this);
topbox=gui_internal_box_new_with_label(this, 0, label);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
+ topbox->on_resize=gui_internal_menu_topbox_resize;
gui_internal_widget_append(&this->root, topbox);
menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
-
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ menu->on_resize=gui_internal_menu_menu_resize;
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
menu->background=this->background;
gui_internal_apply_config(this);
topbox->menu_data=g_new0(struct menu_data, 1);
@@ -156,17 +203,8 @@ gui_internal_menu(struct gui_priv *this, const char *label) {
}
if (this->flags & 192) {
menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ menu->on_resize=gui_internal_menu_menu_resize;
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
w1=gui_internal_time_help(this);
gui_internal_widget_append(menu, w1);
w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
@@ -176,19 +214,10 @@ gui_internal_menu(struct gui_priv *this, const char *label) {
}
gui_internal_widget_pack(this, topbox);
gui_internal_widget_reset_pack(this, topbox);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ if (topbox->on_resize)
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
+ if (menu->on_resize)
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
return w;
}
@@ -211,6 +240,14 @@ void gui_internal_menu_reset_pack(struct gui_priv *this) {
gui_internal_widget_reset_pack(this, top_box);
}
+/**
+ * @brief Renders a menu GUI on the display
+ *
+ * @note The whole sequence of menus is kept in this->root.children (when going back one page, we just move to the previous child in the list)
+ * Thus, only the last child of this->root.children is actually displayed
+ *
+ * @param this The internal GUI context
+ */
void gui_internal_menu_render(struct gui_priv *this) {
GList *l;
struct widget *menu;
@@ -222,6 +259,31 @@ void gui_internal_menu_render(struct gui_priv *this) {
gui_internal_widget_render(this, menu);
}
+void gui_internal_menu_resize(struct gui_priv *this, int w, int h) {
+ GList *l;
+ struct widget *menu;
+ struct widget *topbox;
+ struct widget *wb;
+
+ gui_internal_apply_config(this);
+ l=g_list_last(this->root.children);
+ menu=l->data;
+ /* Search for the topbox widget */
+ l=g_list_first(menu->children);
+ topbox=l->data;
+ if (menu->on_resize)
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
+ if (topbox->on_resize)
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
+ l=topbox->children;
+ while (l) {
+ wb=l->data;
+ if (wb->on_resize)
+ wb->on_resize(this, wb, NULL, topbox->w, topbox->h);
+ l=g_list_next(l);
+ }
+}
+
struct widget *
gui_internal_top_bar(struct gui_priv *this) {
struct widget *w,*wm,*wh,*wc,*wcn;
diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h
index 57e37d91c..7bbf7892a 100644
--- a/navit/gui/internal/gui_internal_menu.h
+++ b/navit/gui/internal/gui_internal_menu.h
@@ -2,11 +2,16 @@
struct gui_priv;
struct menu_data;
struct widget;
+void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w);
+int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w);
void gui_internal_prune_menu(struct gui_priv *this, struct widget *w);
void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render);
+void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh);
+void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh);
struct widget *gui_internal_menu(struct gui_priv *this, const char *label);
struct menu_data *gui_internal_menu_data(struct gui_priv *this);
void gui_internal_menu_reset_pack(struct gui_priv *this);
void gui_internal_menu_render(struct gui_priv *this);
+void gui_internal_menu_resize(struct gui_priv *this, int w, int h);
struct widget *gui_internal_top_bar(struct gui_priv *this);
/* end of prototypes */
diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c
index aa4c9eeef..3e9d9e123 100644
--- a/navit/gui/internal/gui_internal_widget.c
+++ b/navit/gui/internal/gui_internal_widget.c
@@ -12,6 +12,7 @@
#include "gui_internal_menu.h"
static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb);
+void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew);
static void gui_internal_background_render(struct gui_priv *this, struct widget *w) {
struct point pnt=w->p;
@@ -134,6 +135,15 @@ static void gui_internal_label_render(struct gui_priv *this, struct widget *w) {
}
/**
+ * @brief Resize a label.
+ *
+ * @param this The internal GUI instance
+ * @param w The widget to render
+ */
+static void gui_internal_label_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) {
+}
+
+/**
* @brief Creates a text box.
*
* A text box is a widget that renders a text string containing newlines.
@@ -325,7 +335,6 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w) {
gui_internal_widget_render(this, w->scroll_buttons->button_box);
}
-
/**
* @brief Computes the size and location for the widget.
*
@@ -599,6 +608,21 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
}
}
+static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) {
+ GList *l;
+
+ gui_internal_widget_reset_pack(this, w);
+ w->w = wnew;
+ w->h = hnew;
+ if (w->on_resize)
+ w->on_resize(this, w, NULL, wnew, hnew);
+
+ gui_internal_box_pack(this, w);
+ if (w->on_resize)
+ w->on_resize(this, w, NULL, wnew, hnew);
+ /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */
+}
+
void gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w) {
struct widget *wc;
GList *l;
@@ -739,6 +763,31 @@ void gui_internal_widget_render(struct gui_priv *this, struct widget *w) {
}
}
+void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) {
+ if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE)
+ return;
+
+ switch (w->type) {
+ case widget_box:
+ dbg(lvl_error, "Resizing box at %p to w=%d, h=%d", w, wnew, hnew);
+ gui_internal_box_resize(this, w, wnew, hnew);
+ break;
+ case widget_label:
+ dbg(lvl_error, "Resizing label at %p to w=%d, h=%d (text=\"%s\")", w, wnew, hnew, w->text);
+ gui_internal_label_resize(this, w, wnew, hnew);
+ break;
+ case widget_image:
+ dbg(lvl_error, "resize not yet implemented for widget_image");
+ break;
+ case widget_table:
+ dbg(lvl_error, "Not resizing table at %p to w=%d, h=%d", w, wnew, hnew);
+ //gui_internal_table_resize(this, w, wnew, hnew);
+ break;
+ default:
+ break;
+ }
+}
+
void gui_internal_widget_pack(struct gui_priv *this, struct widget *w) {
switch (w->type) {
case widget_box:
@@ -1309,6 +1358,22 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w) {
}
/**
+ * @brief Resize a table widget.
+ *
+ * @param this The graphics context
+ * @param w The table widget to render.
+ */
+void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew) {
+
+
+ w->w = wnew;
+ w->h = hnew;
+
+ gui_internal_widget_reset_pack(this, w);
+ gui_internal_table_pack(this, w);
+}
+
+/**
* @brief Handles the 'next page' table event.
*
* A callback function that is invoked when the 'next page' button is pressed
diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h
index c1cc030f8..383eeaded 100644
--- a/navit/gui/internal/gui_internal_widget.h
+++ b/navit/gui/internal/gui_internal_widget.h
@@ -18,10 +18,15 @@ struct widget {
struct graphics_image *img;
/**
* A function to be invoked on actions.
- * @li widget The widget that is receiving the button press.
+ * @param widget The widget that is receiving the button press.
*
*/
void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
+ /**
+ * A function to be invoked on resize or move
+ * @param widged The widget that is resized
+ */
+ void (*on_resize)(struct gui_priv *priv, struct widget
enum gui_internal_reason reason;
int datai;
void *data;
@@ -177,6 +182,7 @@ void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *chi
void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w);
void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
+void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew);
void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
struct widget *gui_internal_button_label(struct gui_priv *this, const char *label, int mode);
struct widget *gui_internal_widget_table_new(struct gui_priv *this, enum flags flags, int buttons);