static gboolean
focus_in_site (GtkExpander      *expander,
	       FocusSite         site,
	       GtkDirectionType  direction)
{
  switch (site)
    {
    case FOCUS_WIDGET:
      gtk_widget_grab_focus (GTK_WIDGET (expander));
      return TRUE;
    case FOCUS_LABEL:
      if (expander->priv->label_widget)
	return gtk_widget_child_focus (expander->priv->label_widget, direction);
      else
	return FALSE;
    case FOCUS_CHILD:
      {
	GtkWidget *child = gtk_bin_get_child (GTK_BIN (expander));

	if (child && GTK_WIDGET_CHILD_VISIBLE (child))
	  return gtk_widget_child_focus (child, direction);
	else
	  return FALSE;
      }
    case FOCUS_NONE:
      break;
    }

  g_assert_not_reached ();
  return FALSE;
}
Exemple #2
0
static gboolean
focus_in_site (GtkEllipsis      *ellipsis,
	       FocusSite         site,
	       GtkDirectionType  direction)
{
  GtkEllipsisPrivate *priv = ellipsis->priv;
  switch (site)
    {
    case FOCUS_WIDGET:
      gtk_widget_grab_focus (GTK_WIDGET (ellipsis));
      return TRUE;
    case FOCUS_LABEL:
      if (priv->label && GTK_WIDGET_VISIBLE (priv->label))
	return gtk_widget_child_focus (priv->label, direction);
      else
	return FALSE;
    case FOCUS_CHILD:
      {
	GtkWidget *child = gtk_bin_get_child (GTK_BIN (ellipsis));

	if (child && priv->expanded)
	  return gtk_widget_child_focus (child, direction);
	else
	  return FALSE;
      }
    case FOCUS_NONE:
      break;
    }

  g_assert_not_reached ();
  return FALSE;
}
static gboolean
select_autocompletion(G_GNUC_UNUSED GtkEntryCompletion *widget,
                      GtkTreeModel *model,
                      GtkTreeIter *iter,
                      RingMainWindow *win)
{
    RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win);

    QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), iter);
    if (idx.isValid()) {
        priv->q_completion_model->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
        Call *call = priv->q_completion_model->call();
        priv->q_completion_model->callSelectedNumber();

        /* make this the currently selected call */
        QModelIndex idx = CallModel::instance().getIndex(call);
        CallModel::instance().selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);

        /* move focus away from entry so that DTMF tones can be entered via the keyboard */
        gtk_widget_child_focus(GTK_WIDGET(win), GTK_DIR_TAB_FORWARD);

        /* clear the entry */
        gtk_entry_set_text(GTK_ENTRY(priv->search_entry), "");
    } else {
        g_warning("autocompletion selection is not a valid index!");
    }
    return TRUE;
}
static gboolean
key_event (GtkWidget *listbox, GdkEvent *event, GsShellCategory *shell)
{
	GsShellCategoryPrivate *priv = shell->priv;
	guint keyval;
	gboolean handled;

	if (!gdk_event_get_keyval (event, &keyval))
		return FALSE;

	if (keyval == GDK_KEY_Page_Up ||
	    keyval == GDK_KEY_KP_Page_Up)
		g_signal_emit_by_name (priv->scrolledwindow_category, "scroll-child",
				       GTK_SCROLL_PAGE_UP, FALSE, &handled);
	else if (keyval == GDK_KEY_Page_Down ||
	    	 keyval == GDK_KEY_KP_Page_Down)
		g_signal_emit_by_name (priv->scrolledwindow_category, "scroll-child",
				       GTK_SCROLL_PAGE_DOWN, FALSE, &handled);
	else if (keyval == GDK_KEY_Tab ||
		 keyval == GDK_KEY_KP_Tab)
		gtk_widget_child_focus (priv->category_detail_grid, GTK_DIR_TAB_FORWARD);
	else
		return FALSE;

	return TRUE;
}
/* Focus handler for the scrolled ETree */
static gint
ets_focus (GtkWidget *container, GtkDirectionType direction)
{
	ETreeScrolled *ets;

	ets = E_TREE_SCROLLED (container);

	return gtk_widget_child_focus (GTK_WIDGET (ets->tree), direction);
}
Exemple #6
0
static void
drawer_focus_panel_widget (Drawer           *drawer,
                           GtkDirectionType  direction)
{
    PanelWidget *panel_widget;

    panel_widget = panel_toplevel_get_panel_widget (drawer->toplevel);

    gtk_window_present (GTK_WINDOW (drawer->toplevel));
    gtk_container_set_focus_child (GTK_CONTAINER (panel_widget), NULL);
    gtk_widget_child_focus (GTK_WIDGET (panel_widget), direction);
}
static gboolean
focus_current_site (GtkExpander      *expander,
		    GtkDirectionType  direction)
{
  GtkWidget *current_focus;

  current_focus = GTK_CONTAINER (expander)->focus_child;

  if (!current_focus)
    return FALSE;

  return gtk_widget_child_focus (current_focus, direction);
}
static CORBA_boolean
impl_MateComponent_Control_focus (PortableServer_Servant servant,
			   MateComponent_Gtk_Direction   corba_direction,
			   CORBA_Environment     *ev)
{
	MateComponentControl        *control;
	GtkDirectionType      direction;
	MateComponentControlPrivate *priv;

	control = MATECOMPONENT_CONTROL (matecomponent_object (servant));
	priv = control->priv;

	/* FIXME: this will not work for local controls. */

	if (!priv->plug)
		return FALSE;

	switch (corba_direction) {
	case MateComponent_Gtk_DirectionTabForward:
		direction = GTK_DIR_TAB_FORWARD;
		break;

	case MateComponent_Gtk_DirectionTabBackward:
		direction = GTK_DIR_TAB_BACKWARD;
		break;

	case MateComponent_Gtk_DirectionUp:
		direction = GTK_DIR_UP;
		break;

	case MateComponent_Gtk_DirectionDown:
		direction = GTK_DIR_DOWN;
		break;

	case MateComponent_Gtk_DirectionLeft:
		direction = GTK_DIR_LEFT;
		break;

	case MateComponent_Gtk_DirectionRight:
		direction = GTK_DIR_RIGHT;
		break;

	default:
		/* Hmmm, we should throw an exception. */
		return FALSE;
	}

	return gtk_widget_child_focus (GTK_WIDGET (priv->plug), direction);
}
static void
change_password_storage_icon (GtkWidget *passwd_entry, MenuItem item)
{
    const char *old_pwd;
    gboolean ask_mode;

    g_return_if_fail (item >= 0 && item <= ITEM_STORAGE_MAX);

    gtk_entry_set_icon_from_icon_name (GTK_ENTRY (passwd_entry),
                                       GTK_ENTRY_ICON_SECONDARY,
                                       icon_name_table[item]);
    gtk_entry_set_icon_tooltip_text (GTK_ENTRY (passwd_entry),
                                     GTK_ENTRY_ICON_SECONDARY,
                                     gettext (icon_desc_table[item]));

    /* We want to make entry insensitive when ITEM_STORAGE_ASK is selected
     * Unfortunately, making GtkEntry insensitive will also make the icon
     * insensitive, which prevents user from reverting the action.
     * Let's workaround that by disabling focus for entry instead of
     * sensitivity change.
    */
    ask_mode = !!g_object_get_data (G_OBJECT (passwd_entry), ASK_MODE_TAG);
    if (   (item == ITEM_STORAGE_ASK && !ask_mode)
            || item == ITEM_STORAGE_UNUSED) {
        /* Store the old password */
        old_pwd = gtk_entry_get_text (GTK_ENTRY (passwd_entry));
        if (old_pwd && *old_pwd)
            g_object_set_data_full (G_OBJECT (passwd_entry), "password-old",
                                    g_strdup (old_pwd), g_free_str0);
        gtk_entry_set_text (GTK_ENTRY (passwd_entry), "");

        if (gtk_widget_is_focus (passwd_entry))
            gtk_widget_child_focus ((gtk_widget_get_toplevel (passwd_entry)), GTK_DIR_TAB_BACKWARD);
        gtk_widget_set_can_focus (passwd_entry, FALSE);
    } else {
        /* Set the old password to the entry */
        old_pwd = g_object_get_data (G_OBJECT (passwd_entry), "password-old");
        if (old_pwd && *old_pwd)
            gtk_entry_set_text (GTK_ENTRY (passwd_entry), old_pwd);
        g_object_set_data (G_OBJECT (passwd_entry), "password-old", NULL);

        if (!gtk_widget_get_can_focus (passwd_entry)) {
            gtk_widget_set_can_focus (passwd_entry, TRUE);
            gtk_widget_grab_focus (passwd_entry);
        }
    }
}
Exemple #10
0
/**
 * Apply the current selection in the list to the entry field. Focus is also
 * moved to the next widget so that Tab key works correctly.
 * \param list_view List to process.
 * \param entry Address entry field.
 * \param move_focus Move focus to the next widget ?
 */
static void completion_window_apply_selection(GtkTreeView *list_view,
						GtkEntry *entry,
						gboolean move_focus)
{
	gchar *address = NULL, *text = NULL;
	gint   cursor_pos;
	GtkWidget *parent;
	GtkTreeSelection *selection;
	GtkTreeModel *model;
	GtkTreeIter iter;
	gboolean is_group = FALSE;
	cm_return_if_fail(list_view != NULL);
	cm_return_if_fail(entry != NULL);
	GList *grp_emails = NULL;

	selection = gtk_tree_view_get_selection(list_view);
	if (! gtk_tree_selection_get_selected(selection, &model, &iter))
		return;

	/* First remove the idler */
	if( _completionIdleID_ != 0 ) {
		g_source_remove( _completionIdleID_ );
		_completionIdleID_ = 0;
	}

	/* Process selected item */
	gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text, 
				ADDR_COMPL_ISGROUP, &is_group, 
				ADDR_COMPL_GROUPLIST, &grp_emails,
				-1);

	address = get_address_from_edit(entry, &cursor_pos);
	g_free(address);
	replace_address_in_edit(entry, text, cursor_pos, is_group, grp_emails);
	g_free(text);

	/* Move focus to next widget */
	parent = gtk_widget_get_parent(GTK_WIDGET(entry));
	if( parent && move_focus) {
		gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
	}
}
static void
ide_omni_search_display_grab_focus (GtkWidget *widget)
{
  IdeOmniSearchDisplay *self = (IdeOmniSearchDisplay *)widget;
  gsize i;

  g_return_if_fail (IDE_IS_OMNI_SEARCH_DISPLAY (self));

  for (i = 0; i < self->providers->len; i++)
    {
      ProviderEntry *ptr;

      ptr = g_ptr_array_index (self->providers, i);

      if (ide_omni_search_group_get_first (ptr->group))
        {
          gtk_widget_child_focus (GTK_WIDGET (ptr->group), GTK_DIR_DOWN);
          break;
        }
    }
}
static gboolean
video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
{
    g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
    auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);

    // if this widget already has focus, we want the focus to move to the next widget, otherwise we
    // will get stuck in a focus loop on the buttons
    if (gtk_widget_has_focus(widget))
        return FALSE;

    // otherwise we want the focus to go to and change between the call control buttons
    if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
        // selected a child, make sure call controls are shown
        mouse_moved(self);
        return TRUE;
    }

    // did not select the next child, propogate the event
    return FALSE;
}
static void
search_entry_placecall(G_GNUC_UNUSED GtkWidget *entry, gpointer win)
{
    RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(win));

    const gchar *number_entered = gtk_entry_get_text(GTK_ENTRY(priv->search_entry));

    if (number_entered && strlen(number_entered) > 0) {
        /* detect Ring hash */
        gboolean is_ring_hash = FALSE;
        if (strlen(number_entered) == 40) {
            is_ring_hash = TRUE;
            /* must be 40 chars long and alphanumeric */
            for (int i = 0; i < 40 && is_ring_hash; ++i) {
                if (!g_ascii_isalnum(number_entered[i]))
                    is_ring_hash = FALSE;
            }
        }

        QString number = QString{number_entered};

        if (is_ring_hash)
            number = "ring:" + number;

        g_debug("dialing to number: %s", number.toUtf8().constData());

        Call *call = priv->q_completion_model->call();
        call->setDialNumber(number);
        call->performAction(Call::Action::ACCEPT);

        /* make this the currently selected call */
        QModelIndex idx = CallModel::instance().getIndex(call);
        CallModel::instance().selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);

        /* move focus away from entry so that DTMF tones can be entered via the keyboard */
        gtk_widget_child_focus(GTK_WIDGET(win), GTK_DIR_TAB_FORWARD);
        /* clear the entry */
        gtk_entry_set_text(GTK_ENTRY(priv->search_entry), "");
    }
}
static gboolean
keynav_failed (GtkWidget *list, GtkDirectionType direction, CcUaPanel *self)
{
  CcUaPanelPrivate *priv = self->priv;
  GList *item, *sections;
  gdouble value, lower, upper, page;

  /* Find the list in the list of GtkListBoxes */
  if (direction == GTK_DIR_DOWN)
    sections = priv->sections;
  else
    sections = priv->sections_reverse;

  item = g_list_find (sections, list);
  g_assert (item);
  if (item->next)
    {
      gtk_widget_child_focus (GTK_WIDGET (item->next->data), direction);
      return TRUE;
    }

  value = gtk_adjustment_get_value (priv->focus_adjustment);
  lower = gtk_adjustment_get_lower (priv->focus_adjustment);
  upper = gtk_adjustment_get_upper (priv->focus_adjustment);
  page  = gtk_adjustment_get_page_size (priv->focus_adjustment);

  if (direction == GTK_DIR_UP && value > lower)
    {
      gtk_adjustment_set_value (priv->focus_adjustment, lower);
      return TRUE;
    }
  else if (direction == GTK_DIR_DOWN && value < upper - page)
    {
      gtk_adjustment_set_value (priv->focus_adjustment, upper - page);
      return TRUE;
    }

  return FALSE;
}
Exemple #15
0
static	void
GetPandaTable(
	GtkWidget	*widget,
	_Table		*data)
{
	GtkTreeModel *model;
	GtkTreeIter iter;
	int i,j,diff;
	gchar *text;
	gchar **rowdata;
ENTER_FUNC;
	gtk_widget_child_focus(widget,GTK_DIR_TAB_FORWARD);
	data->trow = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget),
		"send_data_row"));
	data->tcolumn = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget),
		"send_data_column"));
	data->tvalue = g_strdup((gchar*)g_object_get_data(G_OBJECT(widget),
		"send_data_value"));
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
	gtk_tree_model_get_iter_first(model,&iter);
	i = 0;
	do {
		rowdata = (gchar**)(g_list_nth_data(data->tabledata,i));
		for(j=0;rowdata[j]!=NULL;j++) {
			gtk_tree_model_get(model,&iter,j,&text,-1);
			diff = strcmp(rowdata[j],text);
			g_free(rowdata[j]);
			if (!diff) {
				g_free(text);
				rowdata[j] = NULL;
			} else {
				rowdata[j] = text;
			}
		}
		i+=1;
	} while(gtk_tree_model_iter_next(model,&iter));
LEAVE_FUNC;
}
static gboolean
keynav_failed (GtkWidget        *listbox,
               GtkDirectionType  direction,
               CcDateTimePanel  *self)
{
  CcDateTimePanelPrivate *priv = self->priv;
  GList *item, *listboxes;

  /* Find the listbox in the list of GtkListBoxes */
  if (direction == GTK_DIR_DOWN)
    listboxes = priv->listboxes;
  else
    listboxes = priv->listboxes_reverse;

  item = g_list_find (listboxes, listbox);
  g_assert (item);
  if (item->next)
    {
      gtk_widget_child_focus (GTK_WIDGET (item->next->data), direction);
      return TRUE;
    }

  return FALSE;
}
Exemple #17
0
AppletInfo *
panel_applet_register (GtkWidget       *applet,
		       PanelWidget     *panel,
		       PanelObjectType  type,
		       const char      *id,
		       GSettings       *settings,
		       gpointer         data,
		       GDestroyNotify   data_destroy)
{
	AppletInfo          *info;
	PanelObjectPackType  pack_type;
	int                  pack_index;
	
	g_return_val_if_fail (applet != NULL && panel != NULL, NULL);

	if (gtk_widget_get_has_window (applet))
		gtk_widget_set_events (applet, (gtk_widget_get_events (applet) |
						APPLET_EVENT_MASK) &
				       ~( GDK_POINTER_MOTION_MASK |
					  GDK_POINTER_MOTION_HINT_MASK));

	info = g_new0 (AppletInfo, 1);
	info->type         = type;
	info->widget       = applet;
	info->settings     = g_object_ref (settings);
	info->menu         = NULL;
	info->data         = data;
	info->data_destroy = data_destroy;
	info->user_menu    = NULL;
	info->id           = g_strdup (id);

	g_object_set_data (G_OBJECT (applet), "applet_info", info);

	registered_applets = g_slist_append (registered_applets, info);

	/* Find where to insert the applet */
        pack_type = g_settings_get_enum (info->settings, PANEL_OBJECT_PACK_TYPE_KEY);
        pack_index = g_settings_get_int (info->settings, PANEL_OBJECT_PACK_INDEX_KEY);

	/* Insert it */
	panel_widget_add (panel, applet, pack_type, pack_index, TRUE);

	if (BUTTON_IS_WIDGET (applet) ||
	    gtk_widget_get_has_window (applet)) {
		g_signal_connect (applet, "button_press_event",
				  G_CALLBACK (applet_button_press),
				  info);

		g_signal_connect (applet, "key_press_event",
				  G_CALLBACK (applet_key_press),
				  info);
	}

	g_signal_connect (applet, "destroy",
			  G_CALLBACK (panel_applet_destroy),
			  info);

	panel_applet_set_dnd_enabled (info, TRUE);

	gtk_widget_show (applet);

	orientation_change (info, panel);
	size_change (info, panel);
	back_change (info, panel);

	if (type != PANEL_OBJECT_APPLET)
		gtk_widget_grab_focus (applet);
	else
		gtk_widget_child_focus (applet, GTK_DIR_TAB_FORWARD);

	return info;
}
Exemple #18
0
AppletInfo *
mate_panel_applet_register (GtkWidget       *applet,
		       gpointer         data,
		       GDestroyNotify   data_destroy,
		       PanelWidget     *panel,
		       gboolean         locked,
		       gint             pos,
		       gboolean         exactpos,
		       PanelObjectType  type,
		       const char      *id)
{
	AppletInfo *info;
	gchar *path;
	gchar *locked_changed;

	g_return_val_if_fail (applet != NULL && panel != NULL, NULL);

	if (gtk_widget_get_has_window (applet))
		gtk_widget_set_events (applet, (gtk_widget_get_events (applet) |
						APPLET_EVENT_MASK) &
				       ~( GDK_POINTER_MOTION_MASK |
					  GDK_POINTER_MOTION_HINT_MASK));

	info = g_new0 (AppletInfo, 1);
	info->type         = type;
	info->widget       = applet;
	info->menu         = NULL;
	info->data         = data;
	info->data_destroy = data_destroy;
	info->user_menu    = NULL;
	info->move_item    = NULL;
	info->id           = g_strdup (id);

	path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id);
	info->settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
	g_free (path);

	g_object_set_data (G_OBJECT (applet), "applet_info", info);

	if (type != PANEL_OBJECT_APPLET)
		panel_lockdown_notify_add (G_CALLBACK (mate_panel_applet_recreate_menu),
					   info);

	locked_changed = g_strdup_printf ("changed::%s", PANEL_OBJECT_LOCKED_KEY);
	g_signal_connect (info->settings,
					  locked_changed,
					  G_CALLBACK (mate_panel_applet_locked_change_notify),
					  G_OBJECT (applet));
	g_free (locked_changed);

	if (type == PANEL_OBJECT_DRAWER) {
		Drawer *drawer = data;
		PanelWidget *assoc_panel;

		assoc_panel = panel_toplevel_get_panel_widget (drawer->toplevel);

		g_object_set_data (G_OBJECT (applet),
				   MATE_PANEL_APPLET_ASSOC_PANEL_KEY, assoc_panel);
		assoc_panel->master_widget = applet;
		g_object_add_weak_pointer (
			G_OBJECT (applet), (gpointer *) &assoc_panel->master_widget);
	}

	g_object_set_data (G_OBJECT (applet),
			   MATE_PANEL_APPLET_FORBIDDEN_PANELS, NULL);

	registered_applets = g_slist_append (registered_applets, info);

	if (panel_widget_add (panel, applet, locked, pos, exactpos) == -1 &&
	    panel_widget_add (panel, applet, locked, 0, TRUE) == -1) {
		GSList *l;

		for (l = panels; l; l = l->next) {
			panel = PANEL_WIDGET (l->data);

			if (panel_widget_add (panel, applet, locked, 0, TRUE) != -1)
				break;
		}

		if (!l) {
			g_warning (_("Cannot find an empty spot"));
			panel_profile_delete_object (info);
			return NULL;
		}
	}

	if (BUTTON_IS_WIDGET (applet) ||
	    gtk_widget_get_has_window (applet)) {
		g_signal_connect (applet, "button_press_event",
				  G_CALLBACK (applet_button_press),
				  info);

		g_signal_connect (applet, "popup_menu",
				  G_CALLBACK (applet_popup_menu),
				  info);
	}

	g_signal_connect (applet, "destroy",
			  G_CALLBACK (mate_panel_applet_destroy),
			  info);

	mate_panel_applet_set_dnd_enabled (info, !locked);

	gtk_widget_show_all (applet);

	orientation_change (info, panel);
	size_change (info, panel);
	back_change (info, panel);

	if (type != PANEL_OBJECT_APPLET)
		gtk_widget_grab_focus (applet);
	else
		gtk_widget_child_focus (applet, GTK_DIR_TAB_FORWARD);

	return info;
}
static gboolean
command_key_event (GtkEntry   *entry,
		   GdkEventKey *event,
		   MCData      *mc)
{
    guint key = event->keyval;
    char *command;
    static char current_command[MC_MAX_COMMAND_LENGTH];
    char buffer[MC_MAX_COMMAND_LENGTH];
    gboolean propagate_event = TRUE;
    const gchar *str;

    if (mc->error) { 
	   mc->error = FALSE; 
	   str = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
	   gtk_entry_set_text (entry, (gchar *) str + 3);
	   gtk_editable_set_position (GTK_EDITABLE (entry), strlen (str));
	}
    if(key == GDK_Tab
       || key == GDK_KP_Tab
       || key == GDK_ISO_Left_Tab)
        {
            if(event->state == GDK_CONTROL_MASK)
                {
                    /*
                     * Move focus to the next applet.
                     */
                    gtk_widget_child_focus (gtk_widget_get_toplevel(GTK_WIDGET(mc->applet)),
                        GTK_DIR_TAB_FORWARD);
	            propagate_event = FALSE;
                }
            else if(event->state != GDK_SHIFT_MASK)
	        {	
	                    /* tab key pressed */
	            strcpy(buffer, (char *) gtk_entry_get_text(GTK_ENTRY(entry)));
	            mc_cmd_completion (mc, buffer);
	            gtk_entry_set_text(GTK_ENTRY(entry), (gchar *) buffer);

	            propagate_event = FALSE;
	        }
	}
    else if(key == GDK_Up
	    || key == GDK_KP_Up
	    || key == GDK_ISO_Move_Line_Up
	    || key == GDK_Pointer_Up)
	{
	    /* up key pressed */
	    if(history_position == MC_HISTORY_LIST_LENGTH)
		{	    
		    /* store current command line */
		    strcpy(current_command, (char *) gtk_entry_get_text(entry));
		}
	    if(history_position > 0 && exists_history_entry(history_position - 1))
		{
		    gtk_entry_set_text(entry, (gchar *) get_history_entry(--history_position));
		}

	    propagate_event = FALSE;
	}
    else if(key == GDK_Down
	    || key == GDK_KP_Down
	    || key == GDK_ISO_Move_Line_Down
	    || key == GDK_Pointer_Down)
	{
	    /* down key pressed */
	    if(history_position <  MC_HISTORY_LIST_LENGTH - 1)
		{
		    gtk_entry_set_text(entry, (gchar *) get_history_entry(++history_position));
		}
	    else if(history_position == MC_HISTORY_LIST_LENGTH - 1)
		{	    
		    gtk_entry_set_text(entry, (gchar *) current_command);
		    ++history_position;
		}

	    propagate_event = FALSE;
	}
    else if(key == GDK_Return
	    || key == GDK_KP_Enter
	    || key == GDK_ISO_Enter
	    || key == GDK_3270_Enter)
	{
	    /* enter pressed -> exec command */
	    command = (char *) malloc(sizeof(char) * MC_MAX_COMMAND_LENGTH);
	    strcpy(command, (char *) gtk_entry_get_text(entry));
	    mc_exec_command(mc, command);

	    history_position = MC_HISTORY_LIST_LENGTH;		   
	    free(command);

	    strcpy(current_command, "");
	    propagate_event = FALSE;
	}
    else if (mc->preferences.auto_complete_history && key >= GDK_space && key <= GDK_asciitilde )
	{
            char *completed_command;
	    gint current_position = gtk_editable_get_position(GTK_EDITABLE(entry));
	    
	    if(current_position != 0)
		{
		    gtk_editable_delete_text( GTK_EDITABLE(entry), current_position, -1 );
		    completed_command = history_auto_complete(GTK_WIDGET (entry), event);
		    
		    if(completed_command != NULL)
			{
			    gtk_entry_set_text(entry, completed_command);
			    gtk_editable_set_position(GTK_EDITABLE(entry), current_position + 1);
			    propagate_event = FALSE;
			}
		}	    
	}
    
    return !propagate_event;
}
Exemple #20
0
static VALUE
rg_child_focus(VALUE self, VALUE direction)
{
    return CBOOL2RVAL(gtk_widget_child_focus(_SELF(self), RVAL2GENUM(direction, GTK_TYPE_DIRECTION_TYPE)));
}
Exemple #21
0
static gboolean on_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data)
{
  key_pressed = TRUE;
  switch (event->keyval) {
  case GDK_Escape:
    if (strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search)))
	|| gtk_widget_get_visible (search)) {
      gtk_widget_hide (search);
      mosaic_search_box_set_text (MOSAIC_SEARCH_BOX (search), "\0");
    } else {
      if (options.persistent)
        gtk_widget_hide (window);
      else
        gtk_main_quit ();
    }
    break;
  case GDK_Return:
    if(strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search))) && !filtered_size &&
       options.read_stdin && options.permissive) {
      puts (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search)));
      gtk_main_quit();
    }
    break;
  case GDK_Left:
  case GDK_Up:
  case GDK_Right:
  case GDK_Down:
    break;
  case GDK_Tab:
    tab_event(FALSE);
    return TRUE;
  case GDK_ISO_Left_Tab:
    tab_event(TRUE);
    return TRUE;
    break;
  case GDK_End:
    if (options.permissive) {
      MosaicWindowBox* box = MOSAIC_WINDOW_BOX (gtk_window_get_focus (GTK_WINDOW (window)));
      mosaic_search_box_set_text (MOSAIC_SEARCH_BOX (search), mosaic_window_box_get_name (box));
      gtk_widget_show (search);
    }
    break;
  case GDK_BackSpace:
    mosaic_search_box_remove_symbols (MOSAIC_SEARCH_BOX (search), 1);
    if (!strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search))))
      if (!options.vim_mode)
	gtk_widget_hide (search);
    break;
  default:
  {
    // Ignore Ctrl key.
    if (event->state & GDK_CONTROL_MASK) {
      if (!options.vim_mode) {
	switch (event->keyval) {
	case GDK_n:
	  gtk_widget_child_focus (layout, GTK_DIR_DOWN);
	  break;
	case GDK_p:
	  gtk_widget_child_focus (layout, GTK_DIR_UP);
	  break;
	case GDK_f:
	  gtk_widget_child_focus (layout, GTK_DIR_RIGHT);
	  break;
	case GDK_b:
	  gtk_widget_child_focus (layout, GTK_DIR_LEFT);
	  break;
	case GDK_m:
	  if(strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search))) && !filtered_size &&
	     options.read_stdin && options.permissive) {
	    puts (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search)));
	    gtk_main_quit();
	  } else {
	    g_signal_emit_by_name (gtk_window_get_focus (GTK_WINDOW (window)), "clicked", NULL);
	  }
	  break;
	case GDK_h:
	  mosaic_search_box_remove_symbols (MOSAIC_SEARCH_BOX (search), 1);
	  if (!strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search))))
	    gtk_widget_hide (search);
	  break;
	case GDK_w:
	  mosaic_search_box_kill_word (MOSAIC_SEARCH_BOX (search));
	  if (!strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search))))
	    gtk_widget_hide (search);
	  break;
	case GDK_g:
	  if (strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search)))
	      || gtk_widget_get_visible (search)) {
	    gtk_widget_hide (search);
	    mosaic_search_box_set_text (MOSAIC_SEARCH_BOX (search), "\0");
	  } else {
	    gtk_main_quit ();
	  }
	  break;
	}
      }
      return FALSE;
    }
    
    /* if(event->state & GDK_SHIFT_MASK) { */
    /*   switch(event->keyval) { */
    /*   case GDK_Tab: */
    /*     { */
    /*       g_printerr("Shift-Tab\n"); */
    /*       tab_event(TRUE); */
    /*       return TRUE; */
    /*     } */
    /*   default: */
    /*     g_printerr("keyval = %d\n", event->keyval); */
    /*   } */
    /* } */
    
    if (options.vim_mode && !gtk_widget_get_visible (search)) {
      switch (event->keyval) {
      case GDK_h:
	gtk_widget_child_focus (layout, GTK_DIR_LEFT);
	break;
      case GDK_j:
	gtk_widget_child_focus (layout, GTK_DIR_DOWN);
	break;
      case GDK_k:
	gtk_widget_child_focus (layout, GTK_DIR_UP);
	break;
      case GDK_l:
	gtk_widget_child_focus (layout, GTK_DIR_RIGHT);
	break;
      case GDK_slash:
	gtk_widget_show (search);
	g_signal_emit_by_name (G_OBJECT (search), "changed", NULL);
	break;
      }
      return TRUE;
    }

    char *key = event->string;
    if (strlen(key)) {
      mosaic_search_box_append_text (MOSAIC_SEARCH_BOX (search), key);
      int text_length = strlen (mosaic_search_box_get_text (MOSAIC_SEARCH_BOX (search)));
      if (text_length)
	gtk_widget_show (search);
      return TRUE;
    }
  }
  }
  return FALSE;
}