popup.c File Reference

#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <libergtk/ergtk.h>
#include <liberutils/display_utils.h>
#include "log.h"
#include "i18n.h"
#include "ipc.h"
#include "menustore.h"
#include "pixlist.h"
#include "popup.h"
Include dependency graph for popup.c:

Go to the source code of this file.

Functions

static void set_active (gboolean do_active)
static void idle_update_display (gint type)
gboolean popup_set_popup_show (const char *statestr)
 Set popup show mode.
void popup_set_popup_block (gboolean block)
gboolean popup_get_popup_block ()
static void set_menuitem_markup (GtkWidget *widget, const char *text, int state)
static void on_menu_deactivate (GtkMenuShell *menu, gpointer user_data)
static gboolean on_menu_key_press (GtkMenuShell *menu, GdkEventKey *event, gpointer user_data)
static void on_item_back_activate (GtkMenuItem *item, gpointer user_data)
static void on_item_activate (GtkMenuItem *item, gpointer menu_data)
static void on_menu_move_scroll (GtkMenu *menu, GtkScrollType arg1, gpointer user_data)
static gboolean on_menu_move_selected (GtkMenuShell *menu_shell, gint distance, gpointer user_data)
static void menu_set_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
static GtkWidget * create_item (const gchar *text, GdkPixbuf *img)
static gpointer add_popup_item (const char *name, const char *text, enum menu_state state, GdkPixbuf *img, gpointer menu_data, gpointer user_data)
static gpointer add_popup_submenu (const char *name, const char *text, enum menu_state state, GdkPixbuf *img, gpointer menu_data, gpointer user_data)
static void add_popup_separator (gpointer user_data)
static void create_menu ()
static gboolean update_display (gpointer data)

Variables

const gint MENU_OFFSET_LEFT = 12
const gint MENU_OFFSET_BOTTOM = 45
static GtkWidget * g_menu = NULL
static gboolean is_active = FALSE
static gboolean g_dont_show = FALSE

Function Documentation

static gpointer add_popup_item ( const char *  name,
const char *  text,
enum menu_state  state,
GdkPixbuf *  img,
gpointer  menu_data,
gpointer  user_data 
) [static]

Definition at line 307 of file popup.c.

References create_item(), on_item_activate(), set_menuitem_markup(), and widget.

Referenced by add_popup_submenu(), and create_menu().

00313 {
00314     GtkWidget *widget = create_item(text, img);
00315     set_menuitem_markup(widget, text, state);
00316 
00317     // add item to menu
00318     gtk_menu_shell_append(GTK_MENU_SHELL(user_data), widget);
00319 
00320     g_signal_connect(G_OBJECT(widget), "activate", G_CALLBACK(on_item_activate), menu_data);
00321     return widget;
00322 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void add_popup_separator ( gpointer  user_data  )  [static]

Definition at line 353 of file popup.c.

References widget.

Referenced by create_menu().

00354 {
00355     GtkWidget* menu = (GtkWidget*)user_data;
00356     GtkWidget *widget = gtk_separator_menu_item_new();
00357     gtk_menu_shell_append(GTK_MENU_SHELL(menu), widget);
00358     gtk_widget_show(widget);
00359 }

Here is the caller graph for this function:

static gpointer add_popup_submenu ( const char *  name,
const char *  text,
enum menu_state  state,
GdkPixbuf *  img,
gpointer  menu_data,
gpointer  user_data 
) [static]

Definition at line 325 of file popup.c.

References add_popup_item(), create_item(), on_item_back_activate(), on_menu_deactivate(), on_menu_key_press(), on_menu_move_scroll(), on_menu_move_selected(), pixlist_icon_state(), and widget.

Referenced by create_menu().

00331 {
00332     GtkWidget* widget = add_popup_item(name, text, state, img, menu_data, user_data);
00333 
00334     // add submenu to item
00335     GtkWidget *submenu = gtk_menu_new();
00336     gtk_signal_connect(GTK_OBJECT(submenu), "key-press-event", GTK_SIGNAL_FUNC(on_menu_key_press), NULL);
00337     g_signal_connect(G_OBJECT(submenu), "move-scroll", G_CALLBACK(on_menu_move_scroll), NULL);
00338     g_signal_connect(G_OBJECT(submenu), "move-selected", G_CALLBACK(on_menu_move_selected), NULL);
00339     g_signal_connect(G_OBJECT(submenu), "deactivate", G_CALLBACK(on_menu_deactivate), NULL);
00340     gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), submenu);
00341     gtk_widget_show_all(submenu);
00342 
00343     // add Back button
00344     GtkWidget *back_item = create_item(_("Back"), pixlist_icon_state("back", "normal"));
00345     g_signal_connect(G_OBJECT(back_item), "activate", G_CALLBACK(on_item_back_activate), submenu);
00346     gtk_menu_item_set_keep_active(GTK_MENU_ITEM(back_item), TRUE);
00347     gtk_menu_shell_append(GTK_MENU_SHELL(submenu), back_item);
00348 
00349     return submenu;
00350 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget* create_item ( const gchar *  text,
GdkPixbuf *  img 
) [static]

Definition at line 295 of file popup.c.

References widget.

Referenced by add_popup_item(), and add_popup_submenu().

00296 {
00297     GtkWidget *widget = gtk_image_menu_item_new_with_label(text);
00298     GtkWidget *item_image = gtk_image_new_from_pixbuf(img);
00299     gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget),item_image);
00300     gtk_widget_show(item_image);
00301     gtk_widget_show(widget);
00302     
00303     return widget;
00304 }

Here is the caller graph for this function:

static void create_menu (  )  [static]

Definition at line 362 of file popup.c.

References add_popup_item(), add_popup_separator(), add_popup_submenu(), g_menu, menustore_clear_popup_changed(), menustore_fill_menu(), menustore_popup_has_changed(), on_menu_deactivate(), on_menu_key_press(), on_menu_move_scroll(), on_menu_move_selected(), and widget.

Referenced by set_active().

00363 {
00364     if (g_menu && !menustore_popup_has_changed()) {
00365         // use cached menu
00366         return;
00367     }    
00368     menustore_clear_popup_changed();
00369 
00370     if (g_menu)
00371     {
00372         // remove existing menu
00373         gtk_widget_destroy(g_menu);
00374         g_menu = NULL;
00375     }
00376 
00377     // create main menu
00378     GtkWidget *widget = gtk_menu_new();
00379     gtk_signal_connect(GTK_OBJECT(widget), "key-press-event", GTK_SIGNAL_FUNC(on_menu_key_press), NULL);
00380     g_signal_connect(G_OBJECT(widget), "deactivate", G_CALLBACK(on_menu_deactivate), NULL);
00381     g_signal_connect(G_OBJECT(widget), "move-scroll", G_CALLBACK(on_menu_move_scroll), NULL);
00382     g_signal_connect(G_OBJECT(widget), "move-selected", G_CALLBACK(on_menu_move_selected), NULL);
00383     g_menu = widget;
00384     
00385     menustore_fill_menu(add_popup_item, add_popup_submenu, add_popup_separator, g_menu);
00386 
00387     gtk_widget_show(g_menu);
00388     // gtk_widget_realize(g_menu);
00389 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void idle_update_display ( gint  type  )  [static]

Definition at line 402 of file popup.c.

References update_display().

Referenced by on_menu_move_scroll(), on_menu_move_selected(), and set_active().

00403 {
00404     g_idle_add(update_display, (gpointer) type);
00405 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void menu_set_position ( GtkMenu *  menu,
gint *  x,
gint *  y,
gboolean *  push_in,
gpointer  user_data 
) [static]

Definition at line 273 of file popup.c.

References g_menu, MENU_OFFSET_BOTTOM, and MENU_OFFSET_LEFT.

Referenced by set_active().

00278 {
00279     g_assert(g_menu);
00280     if (menu == GTK_MENU(g_menu))
00281     {
00282         gint w, h;
00283         GtkRequisition req;
00284 
00285         gdk_window_get_geometry(gdk_get_default_root_window(), NULL, NULL, &w, &h, NULL);
00286         gtk_widget_size_request(g_menu, &req);
00287         
00288         *x = MENU_OFFSET_LEFT; 
00289         *y = h - MENU_OFFSET_BOTTOM - req.height; 
00290         //LOGPRINTF("screen w [%d] h [%d], requested w [%d] h [%d], x [%d] y [%d]", w, h, req.width, req.height, *x, *y);
00291     }
00292 }

Here is the caller graph for this function:

static void on_item_activate ( GtkMenuItem *  item,
gpointer  menu_data 
) [static]

Definition at line 247 of file popup.c.

References ipc_send_item_activated(), menustore_activate_item_iter(), and set_active().

Referenced by add_popup_item().

00248 {
00249     gboolean ok = menustore_activate_item_iter(menu_data, ipc_send_item_activated);
00250     if (ok) set_active(FALSE);
00251 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_item_back_activate ( GtkMenuItem *  item,
gpointer  user_data 
) [static]

Definition at line 238 of file popup.c.

Referenced by add_popup_submenu().

00239 {
00240     GtkWidget *menu_shell = GTK_WIDGET(user_data);
00241 
00242     // close submenu and go back to parent
00243     g_signal_emit_by_name(menu_shell, "move-current", GTK_MENU_DIR_PARENT, NULL);
00244 }

Here is the caller graph for this function:

static void on_menu_deactivate ( GtkMenuShell *  menu,
gpointer  user_data 
) [static]

Definition at line 210 of file popup.c.

References set_active().

Referenced by add_popup_submenu(), and create_menu().

00211 {
00212     set_active(FALSE);
00213 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_menu_key_press ( GtkMenuShell *  menu,
GdkEventKey *  event,
gpointer  user_data 
) [static]

Definition at line 216 of file popup.c.

References ipc_sys_standby(), LOGPRINTF, and set_active().

Referenced by add_popup_submenu(), and create_menu().

00217 {
00218     LOGPRINTF("entry: type [%d] keyval [%d]", event->type, event->keyval);
00219     
00220     if (event && (event->type == GDK_KEY_PRESS))
00221     {
00222         switch (event->keyval)
00223         {
00224         case GDK_F1:
00225             set_active(FALSE);
00226             break;
00227         case GDK_F10:
00228             ipc_sys_standby();
00229             break;
00230         default:
00231             break;
00232         }
00233     }
00234     return FALSE;
00235 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_menu_move_scroll ( GtkMenu *  menu,
GtkScrollType  arg1,
gpointer  user_data 
) [static]

Definition at line 254 of file popup.c.

References display_gain_control(), DM_HINT_CURSOR, and idle_update_display().

Referenced by add_popup_submenu(), and create_menu().

00257 {
00258     display_gain_control();
00259     idle_update_display(DM_HINT_CURSOR);
00260 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_menu_move_selected ( GtkMenuShell *  menu_shell,
gint  distance,
gpointer  user_data 
) [static]

Definition at line 263 of file popup.c.

References display_gain_control(), DM_HINT_CURSOR, and idle_update_display().

Referenced by add_popup_submenu(), and create_menu().

00266 {
00267     display_gain_control();
00268     idle_update_display(DM_HINT_CURSOR);
00269     return FALSE;
00270 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean popup_get_popup_block (  ) 

Definition at line 161 of file popup.c.

References g_dont_show.

Referenced by set_busy_show_cb().

00162 {
00163     return g_dont_show;
00164 }

Here is the caller graph for this function:

void popup_set_popup_block ( gboolean  block  ) 

Definition at line 155 of file popup.c.

References g_dont_show.

Referenced by cb_sys_usb_state(), and set_busy_show_cb().

00156 {
00157     g_dont_show = block;
00158 }

Here is the caller graph for this function:

gboolean popup_set_popup_show ( const char *  state  ) 

Set popup show mode.

File Name : popup.h

Description: Copyright (C) 2008 iRex Technologies B.V. All rights reserved.---------------------------------------------------------------------------

Name : popup_set_popup_show

Parameters:
mode New mode (show/hide/toggle)
Returns:
Returns TRUE when state was changed, FALSE otherwise

--------------------------------------------------------------------------

Definition at line 114 of file popup.c.

References ERRORPRINTF, g_dont_show, ipc_set_enabled(), is_active, and set_active().

Referenced by set_busy_show_cb(), and set_popup_show_cb().

00115 {
00116     gboolean last_active = is_active;
00117 
00118     if (g_dont_show)
00119     {
00120         return FALSE;
00121     }
00122     
00123     if (g_ascii_strcasecmp(statestr, "show") == 0)
00124     {
00125         set_active(TRUE);
00126     }
00127     else if (g_ascii_strcasecmp(statestr, "hide") == 0)
00128     {
00129         set_active(FALSE);
00130     }
00131     else if (g_ascii_strcasecmp(statestr, "toggle") == 0)
00132     {
00133         set_active(!is_active);
00134     }
00135     else if (g_ascii_strcasecmp(statestr, "block") == 0)
00136     {
00137         // close and block popup
00138         set_active(FALSE);
00139         ipc_set_enabled(FALSE);
00140     }
00141     else if (g_ascii_strcasecmp(statestr, "unblock") == 0)
00142     {
00143         set_active(FALSE);
00144         ipc_set_enabled(TRUE);
00145     }
00146     else
00147     {
00148         ERRORPRINTF("state unknown: %s", statestr);
00149     }
00150 
00151     return (last_active != is_active);
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_active ( gboolean  do_active  )  [static]

Definition at line 408 of file popup.c.

References create_menu(), display_gain_control(), DM_HINT_PARTIAL, g_menu, idle_update_display(), is_active, and menu_set_position().

Referenced by on_item_activate(), on_menu_deactivate(), on_menu_key_press(), and popup_set_popup_show().

00409 {
00410     if (do_active == is_active) return;
00411 
00412     if (do_active)
00413     {
00414 #if (TIMING_ON)
00415         start_timer();
00416 #endif        
00417         display_gain_control();
00418         create_menu();
00419         gtk_menu_popup(GTK_MENU(g_menu), NULL, NULL, menu_set_position, NULL, 0, 0);
00420         idle_update_display(DM_HINT_PARTIAL);
00421     }
00422     else
00423     {
00424         gtk_menu_popdown(GTK_MENU(g_menu));
00425     }
00426     
00427     is_active = do_active;
00428 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_menuitem_markup ( GtkWidget *  widget,
const char *  text,
int  state 
) [static]

Definition at line 167 of file popup.c.

References LOGPRINTF, MENU_STATE_DISABLED, and MENU_STATE_SELECTED.

Referenced by add_popup_item().

00168 {
00169     LOGPRINTF("text='%s'  state=%d", text, state);
00170     GtkWidget *itemlabel = gtk_bin_get_child(GTK_BIN(widget));
00171 
00172     // update text
00173     gchar *markup = NULL;
00174     if (state == MENU_STATE_SELECTED) {
00175         markup = g_markup_printf_escaped("<span weight=\"bold\">%s</span>", text);
00176     }
00177     else
00178     {
00179         markup = g_markup_escape_text(text, -1);
00180     }
00181     gtk_label_set_markup(GTK_LABEL(itemlabel), markup);
00182     g_free(markup);
00183 
00184     // update visibility
00185     if (state == MENU_STATE_DISABLED || text[0] == 0)
00186     {
00187 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00188         if (text[0] != 0) {
00189             gtk_widget_set_sensitive(widget, FALSE);
00190             gtk_widget_show(widget);
00191         } else {
00192             gtk_widget_hide(widget);
00193 
00194         }
00195 #else
00196         gtk_widget_hide(widget);
00197 #endif
00198     }
00199     else
00200     {
00201         gtk_widget_show(widget);
00202     }
00203 }

Here is the caller graph for this function:

static gboolean update_display ( gpointer  data  )  [static]

Definition at line 392 of file popup.c.

References display_update_return_control().

Referenced by idle_update_display().

00393 {
00394 #if (TIMING_ON)
00395     stop_timer(__func__);
00396 #endif    
00397     display_update_return_control( (gint) data);
00398     return FALSE; // don't call again
00399 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gboolean g_dont_show = FALSE [static]

Definition at line 64 of file popup.c.

Referenced by popup_get_popup_block(), popup_set_popup_block(), and popup_set_popup_show().

GtkWidget* g_menu = NULL [static]

Definition at line 62 of file popup.c.

Referenced by create_menu(), menu_set_position(), and set_active().

gboolean is_active = FALSE [static]
const gint MENU_OFFSET_BOTTOM = 45

Definition at line 55 of file popup.c.

Referenced by menu_set_position().

const gint MENU_OFFSET_LEFT = 12

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 54 of file popup.c.

Referenced by menu_set_position().

Generated by  doxygen 1.6.2-20100208