Back to index

im-sdk  12.3.91
Functions
quick-access-menu.c File Reference
#include <config.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <panel-applet.h>
#include <gnome.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtkradiomenuitem.h>
#include "gnome-im-switcher.h"
#include "quick-access-menu.h"
#include "language.h"
#include "iiim-interface.h"
#include "widgets.h"

Go to the source code of this file.

Functions

static void get_menu_pos (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
static void edit_languages_destroyed_callback (GtkWidget *new_profile_dialog, GimletWindow *gimlet)
static void update_langmenu_cb (GtkWidget *menuitem, GimletWindow *gimlet)
static void activate_cb (GtkWidget *menuitem, GimletWindow *gimlet)
static void edit_hotkey_destroyed_callback (GtkWidget *dialog, GimletWindow *gimlet)
static void hotkey_cb (GtkWidget *menuitem, GimletWindow *gimlet)
static void turn_off_cb (GtkWidget *menuitem, GimletWindow *gimlet)
static gint string_comp (gconstpointer a, gconstpointer b)
GSList * get_iiimf_lang_le_list (GimletWindow *gimlet, gchar *iiim_lang_name, gchar ***imelist)
static void quick_lang_menu_init (GimletWindow *gimlet)
void quick_access_menu_destroy (GimletWindow *gimlet)
void gimlet_quick_access_menu_init (GimletWindow *gimlet)
void gimlet_quick_access_menu_show (GimletWindow *gimlet)
void gimlet_quick_access_menu_hide (GimletWindow *gimlet)

Function Documentation

static void activate_cb ( GtkWidget *  menuitem,
GimletWindow *  gimlet 
) [static]

Definition at line 116 of file quick-access-menu.c.

{
  if (GTK_MENU_ITEM (menuitem))
    {
      gchar *iiim_lang;
      gchar *lename, *lang_le, *imename;
      gchar *conversion_mode;
      gchar *le_delimiter = ":";

      iiim_lang = g_strdup(g_object_get_data (G_OBJECT (menuitem), "iiim-lang-name"));
      lename = g_strdup(g_object_get_data (G_OBJECT (menuitem), "iiim-lename"));

      if (lename)
       lang_le = g_strconcat (iiim_lang, le_delimiter, lename, NULL);
      else
       lang_le = g_strdup (iiim_lang);

      gimlet_iiim_language_set (gimlet, lang_le);

      free(lang_le);

      if (gimlet->current_iiim_lang)
       g_free (gimlet->current_iiim_lang);
      gimlet->current_iiim_lang = g_strdup (iiim_lang);

      gimlet_update_lang (gimlet);

      /* set initial conversion mode */
      if (gimlet->conversion_on_start == FALSE)
       conversion_mode = "off";
      else
       conversion_mode = gimlet_language_get_conversion_mode (iiim_lang);

      gimlet_iiim_conversion_mode_set (gimlet, conversion_mode);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void edit_hotkey_destroyed_callback ( GtkWidget *  dialog,
GimletWindow *  gimlet 
) [static]

Definition at line 154 of file quick-access-menu.c.

{
  gimlet->edit_hotkey_dialog = NULL;
}

Here is the caller graph for this function:

static void edit_languages_destroyed_callback ( GtkWidget *  new_profile_dialog,
GimletWindow *  gimlet 
) [static]

Definition at line 70 of file quick-access-menu.c.

{
  gimlet->edit_languages_dialog = NULL;
}

Here is the caller graph for this function:

GSList* get_iiimf_lang_le_list ( GimletWindow *  gimlet,
gchar *  iiim_lang_name,
gchar ***  imelist 
)

Definition at line 213 of file quick-access-menu.c.

{
  const gchar *im_delimiter = ";";
  gchar **input_method_list = NULL;
  GSList *lelist = NULL;

  if (gimlet->le_list == NULL)
    return NULL;

  *imelist = NULL;

  input_method_list = g_strsplit (gimlet->le_list, im_delimiter, -1);

  if (input_method_list)
    {
      gchar **p;
      const gchar *le_delimiter = ":";
      const gchar ime_delimiter = '-';
      gchar **le = NULL;
      gchar **list = g_new0 (char *, 10); /* impossible that one language has more than ten LEs */
      int num_of_le = 0;

      for (p = input_method_list; *p; p++)
       {
         char *pime;

         le = g_strsplit (*p, le_delimiter, -1);

         /* probably 'le' consists of lename and imename which are separated by ime_delimiter */
         pime = le[1];
         while (*pime && *pime != ime_delimiter) ++pime;
         if (*pime == ime_delimiter)  *pime++ = 0x0;

         if ((strcmp ((gchar*)le[0], iiim_lang_name) == 0) &&
             !(g_slist_find_custom (lelist, le[1], (GCompareFunc)string_comp)))
            {
              lelist = g_slist_append (lelist, le[1]);
              if (*pime) list[num_of_le++] = pime;
            }
       }

       if (num_of_le)
         {
           int i;

           *imelist = g_new0 (gchar *, num_of_le + 1);

           for (i = 0; i < num_of_le; ++i)
              if (list[i]) *imelist[i] = g_strdup (list[i]);
         }

       g_free (list);
    }
  g_strfreev (input_method_list);
  return lelist;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 37 of file quick-access-menu.c.

{
  GimletWindow *curr_data = data;
  GtkRequisition  reqmenu;
  gint tempx, tempy, width, height;
  gint screen_width, screen_height;
       
  gtk_widget_size_request (GTK_WIDGET (menu), &reqmenu);
  gdk_window_get_origin (GTK_WIDGET (curr_data->applet)->window, &tempx, &tempy);
  gdk_window_get_geometry (GTK_WIDGET (curr_data->applet)->window, NULL, NULL,
                        &width, &height, NULL);
                           
  switch (panel_applet_get_orient (PANEL_APPLET (curr_data->applet))) {
  case PANEL_APPLET_ORIENT_DOWN:
    tempy += height;
    break;
  case PANEL_APPLET_ORIENT_UP:
    tempy -= reqmenu.height;
    break;
  case PANEL_APPLET_ORIENT_LEFT:
    tempx -= reqmenu.width;
    break;
  case PANEL_APPLET_ORIENT_RIGHT:
    tempx += width;
    break;
  }
  screen_width = gdk_screen_width ();
  screen_height = gdk_screen_height ();
  *x = CLAMP (tempx, 0, MAX (0, screen_width - reqmenu.width));
  *y = CLAMP (tempy, 0, MAX (0, screen_height - reqmenu.height));
}

Here is the caller graph for this function:

void gimlet_quick_access_menu_hide ( GimletWindow *  gimlet)

Definition at line 486 of file quick-access-menu.c.

{
  quick_access_menu_destroy (gimlet);

  if (gimlet->quick_access_menu)
    g_free (gimlet->quick_access_menu);
  gimlet->quick_access_menu = NULL;
}

Here is the call graph for this function:

void gimlet_quick_access_menu_init ( GimletWindow *  gimlet)

Definition at line 467 of file quick-access-menu.c.

{
  if (gimlet->quick_access_menu == NULL)
    gimlet->quick_access_menu = g_new0 (QuickAccessMenu, 1);

  quick_access_menu_destroy (gimlet);
  quick_lang_menu_init (gimlet);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gimlet_quick_access_menu_show ( GimletWindow *  gimlet)

Definition at line 477 of file quick-access-menu.c.

{
  gimlet_quick_access_menu_init (gimlet);
  gtk_menu_popup (GTK_MENU (gimlet->quick_access_menu->widget), NULL, NULL,
                get_menu_pos, gimlet,
                0, 0);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hotkey_cb ( GtkWidget *  menuitem,
GimletWindow *  gimlet 
) [static]

Definition at line 161 of file quick-access-menu.c.

{
  GtkWindow *transient_parent;
  GtkWindow *old_transient_parent;

  transient_parent = GTK_WINDOW (gimlet->applet);
  if (gimlet->edit_hotkey_dialog == NULL)
    {
      old_transient_parent = NULL;
      /* passing in transient_parent here purely for the
       * glade error dialog
       */
      gimlet->edit_hotkey_dialog =
       gimlet_hotkey_dialog_new (transient_parent, gimlet);
      if (gimlet->edit_hotkey_dialog == NULL)
       return; /* glade file missing */

      g_signal_connect (G_OBJECT (gimlet->edit_hotkey_dialog),
                     "destroy",
                     G_CALLBACK (edit_hotkey_destroyed_callback),
                     gimlet);
    }
  else
    {
      old_transient_parent = gtk_window_get_transient_for (
                               GTK_WINDOW (gimlet->edit_hotkey_dialog));
    }

  if (old_transient_parent != transient_parent)
    {
      gtk_window_set_transient_for (GTK_WINDOW (gimlet->edit_hotkey_dialog),
                                transient_parent);
      gtk_widget_hide (gimlet->edit_hotkey_dialog);
    }

  gtk_widget_show_all (gimlet->edit_hotkey_dialog);
  gtk_window_present (GTK_WINDOW (gimlet->edit_hotkey_dialog));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void quick_access_menu_destroy ( GimletWindow *  gimlet)

Definition at line 447 of file quick-access-menu.c.

{
  if (gimlet->quick_access_menu->widget)
    {
      gtk_widget_destroy (gimlet->quick_access_menu->widget);
      gimlet->quick_access_menu->widget = NULL;
    }
  if (gimlet->quick_access_menu->active_languages)
    {
      g_slist_foreach (gimlet->quick_access_menu->active_languages,
                     (GFunc) gimlet_language_free,
                     NULL);
      g_slist_free (gimlet->quick_access_menu->active_languages);
      gimlet->quick_access_menu->active_languages = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void quick_lang_menu_init ( GimletWindow *  gimlet) [static]

Definition at line 271 of file quick-access-menu.c.

{
  GtkWidget *menu;
  GtkWidget *menuitem;
  GSList *active_languages;
  GSList *tmp;
  gchar key_navi[2];
  /*
    Added underlined access keys 'A' - 'Y' for all the language items on the
    language menu for key navigation. 'Z' is used for Add or Remove...
  */
  menu = gtk_menu_new ();
  active_languages = gimlet_language_get_active_languages ();

  key_navi[0] = 'A';
  key_navi[1] = '\0';

  for (tmp = active_languages; tmp; tmp = g_slist_next (tmp))
    {
      char *name;
      char *mnemonic_label;
      char *iiim_lang_name;
      char **imelist;
      gchar *ime_seperator = ",";
      int i, len;
      GSList *lelist;

      name = gimlet_language_get_name (tmp->data);
      if (strcmp (name, "ASCII") == 0)
       continue;

      iiim_lang_name = gimlet_language_get_iiim_lang_name (tmp->data);
      lelist = get_iiimf_lang_le_list (gimlet, iiim_lang_name, &imelist);
      if (!lelist)
       continue;

      /* add keynav */
      mnemonic_label = g_strconcat (name, "(_", key_navi, ")", NULL);
      menuitem = gtk_menu_item_new_with_mnemonic (mnemonic_label);
      g_free (mnemonic_label);
      if (key_navi[0] == 'Y')
       key_navi[0] = 'A';
      else
       key_navi[0] += 1;

      len = g_slist_length (lelist);
      if (len == 1 && !imelist)
       {
            g_object_set_data (G_OBJECT (menuitem), "iiim-lang-name",
                             iiim_lang_name);
            g_object_set_data (G_OBJECT (menuitem), "iiim-display-name",
                             name);
             g_object_set_data (G_OBJECT (menuitem), "iiim-lename",
                                lelist->data);
            g_signal_connect (GTK_MENU_ITEM (menuitem), "activate",
                             G_CALLBACK (activate_cb), gimlet);
       }
      else
       {
         GtkWidget *le_submenu;
         GtkWidget *le_submenu_item;
         GSList *le;

         le_submenu = gtk_menu_new ();

         for (i = 0, le = lelist; le; le = g_slist_next (le), ++i)
           {
             if (imelist && imelist[i])
              {
                gchar **p, **ime_array = g_strsplit (imelist[i], ime_seperator, -1);

                for (p = ime_array; *p; ++p)
                 {
                    gchar *lename = g_new0 (char, strlen (le->data) + strlen (*p) + 2);
                    gchar *ime_delimiter = "-";

                    g_sprintf (lename, "%s%s%s", (char *)le->data, ime_delimiter, *p);

                     /* here 'p' refers to the name of input method engine in UTF8 */
                           le_submenu_item = gtk_menu_item_new_with_label (*p);
                      g_object_set_data (G_OBJECT (le_submenu_item), "iiim-lang-name",
                                   iiim_lang_name);
                           g_object_set_data (G_OBJECT (le_submenu_item), "iiim-display-name",
                                   name);
                      g_object_set_data (G_OBJECT (le_submenu_item), "iiim-lename",
                                   lename);

                      gtk_menu_shell_append (GTK_MENU_SHELL (le_submenu), le_submenu_item);
                      g_signal_connect (le_submenu_item, "activate",
                                   G_CALLBACK (activate_cb), gimlet);
                           gtk_widget_show (le_submenu_item);
                 }
              }
             else
              {
                  /* le->data stands for the name of LE */
                   le_submenu_item = gtk_menu_item_new_with_label (le->data);
                   g_object_set_data (G_OBJECT (le_submenu_item), "iiim-lang-name",
                                   iiim_lang_name);
                   g_object_set_data (G_OBJECT (le_submenu_item), "iiim-display-name",
                                   name);
                    g_object_set_data (G_OBJECT (le_submenu_item), "iiim-lename",
                                   le->data);
                   gtk_menu_shell_append (GTK_MENU_SHELL (le_submenu), le_submenu_item);
                   g_signal_connect (le_submenu_item, "activate",
                                   G_CALLBACK (activate_cb), gimlet);
                  gtk_widget_show (le_submenu_item);
              }
           }

         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), le_submenu);
         gtk_widget_show (le_submenu);
       }

      g_slist_free (lelist);

      if (imelist)
       {
         for (i=0; i < len; ++i) if (imelist[i]) g_free (imelist[i]);

        g_free (imelist);
       }

      gtk_widget_show (menuitem);
      gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    }

  /* add separator */
  menuitem = gtk_separator_menu_item_new ();
  gtk_widget_show (menuitem);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);

  /* off item */
  char *name;
  char *mnemonic_label;
  char *iiim_lang_name;
  name = gimlet_language_get_name (active_languages->data);
  iiim_lang_name = gimlet_language_get_iiim_lang_name (active_languages->data);
  mnemonic_label = g_strconcat (_(name), "(_0)", NULL);
  menuitem = gtk_menu_item_new_with_mnemonic (mnemonic_label);
  gtk_widget_show (menuitem);
  gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
  g_object_set_data (G_OBJECT (menuitem), "iiim-lang-name",
                   iiim_lang_name);
  g_object_set_data (G_OBJECT (menuitem), "iiim-display-name",
                   name);
  g_signal_connect (menuitem, "activate",
                  G_CALLBACK (turn_off_cb), gimlet);

  menuitem = gtk_menu_item_new_with_mnemonic (_("Add or Remove...(_Z)"));
  gtk_widget_show (menuitem);
  gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
  g_signal_connect (menuitem, "activate",
                  G_CALLBACK (update_langmenu_cb), gimlet);

// #ifdef CONFIG_HOTKEY
#if 1
  /* add separator */
  menuitem = gtk_separator_menu_item_new ();
  gtk_widget_show (menuitem);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);

  menuitem = gtk_menu_item_new_with_mnemonic (_("Configure hotkey..."));
  gtk_widget_show (menuitem);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
  g_signal_connect (menuitem, "activate",
                  G_CALLBACK (hotkey_cb), gimlet);
#endif

  gimlet->quick_access_menu->widget = menu;
  gimlet->quick_access_menu->active_languages = active_languages;
  
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gint string_comp ( gconstpointer  a,
gconstpointer  b 
) [static]

Definition at line 207 of file quick-access-menu.c.

{
  return g_strcasecmp (a, b);
}

Here is the caller graph for this function:

static void turn_off_cb ( GtkWidget *  menuitem,
GimletWindow *  gimlet 
) [static]

Definition at line 201 of file quick-access-menu.c.

{
  gimlet_iiim_conversion_mode_set (gimlet, "off");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_langmenu_cb ( GtkWidget *  menuitem,
GimletWindow *  gimlet 
) [static]

Definition at line 77 of file quick-access-menu.c.

{
  GtkWindow *transient_parent;
  GtkWindow *old_transient_parent;

  transient_parent = GTK_WINDOW (gimlet->applet);
  if (gimlet->edit_languages_dialog == NULL)
    {
      old_transient_parent = NULL;
      /* passing in transient_parent here purely for the
       * glade error dialog
       */
      gimlet->edit_languages_dialog =
       gimlet_langmenu_dialog_new (transient_parent, gimlet);
      if (gimlet->edit_languages_dialog == NULL)
        return; /* glade file missing */
      
      g_signal_connect (G_OBJECT (gimlet->edit_languages_dialog),
                        "destroy",
                        G_CALLBACK (edit_languages_destroyed_callback),
                        gimlet);
    }
  else 
    {
      old_transient_parent = gtk_window_get_transient_for (GTK_WINDOW (gimlet->edit_languages_dialog));
    }
  
  if (old_transient_parent != transient_parent)
    {
      gtk_window_set_transient_for (GTK_WINDOW (gimlet->edit_languages_dialog),
                                    transient_parent);
      gtk_widget_hide (gimlet->edit_languages_dialog); /* re-show the window on its new parent */
    }
  
  gtk_widget_show_all (gimlet->edit_languages_dialog);
  gtk_window_present (GTK_WINDOW (gimlet->edit_languages_dialog));
}

Here is the call graph for this function:

Here is the caller graph for this function: