Merge branch 'wip/matthiasc/shortcut-4' into 'master'

Shortcuts

See merge request GNOME/gtk!1569
This commit is contained in:
Matthias Clasen 2020-03-26 03:40:22 +00:00
commit eaa20f5cdf
123 changed files with 8441 additions and 9740 deletions

View File

@ -210,6 +210,7 @@
<file>search_entry.c</file>
<file>search_entry2.c</file>
<file>shortcuts.c</file>
<file>shortcut_triggers.c</file>
<file>sizegroup.c</file>
<file>sidebar.c</file>
<file>sliding_puzzle.c</file>

View File

@ -140,17 +140,6 @@ update_value (GtkFontPlane *plane,
gtk_widget_queue_draw (widget);
}
static void
hold_action (GtkGestureLongPress *gesture,
gdouble x,
gdouble y,
GtkFontPlane *plane)
{
gboolean handled;
g_signal_emit_by_name (plane, "popup-menu", &handled);
}
static void
plane_drag_gesture_begin (GtkGestureDrag *gesture,
gdouble start_x,
@ -161,13 +150,6 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture,
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
if (button == GDK_BUTTON_SECONDARY)
{
gboolean handled;
g_signal_emit_by_name (plane, "popup-menu", &handled);
}
if (button != GDK_BUTTON_PRIMARY)
{
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED);
@ -218,13 +200,6 @@ gtk_font_plane_init (GtkFontPlane *plane)
G_CALLBACK (plane_drag_gesture_end), plane);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
gtk_widget_add_controller (GTK_WIDGET (plane), GTK_EVENT_CONTROLLER (gesture));
gesture = gtk_gesture_long_press_new ();
g_signal_connect (gesture, "pressed",
G_CALLBACK (hold_action), plane);
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture),
TRUE);
gtk_widget_add_controller (GTK_WIDGET (plane), GTK_EVENT_CONTROLLER (gesture));
}
static void

View File

@ -310,7 +310,6 @@ static const char *types[] =
"GtkIconView ",
"GtkCellRendererText ",
"GtkContainer ",
"GtkAccelGroup ",
"GtkPaned ",
"GtkPrintOperation ",
"GtkPrintContext ",

View File

@ -62,6 +62,7 @@ demos = files([
'search_entry.c',
'search_entry2.c',
'shortcuts.c',
'shortcut_triggers.c',
'sidebar.c',
'sizegroup.c',
'sliding_puzzle.c',

View File

@ -0,0 +1,91 @@
/* Shortcuts
*
* GtkShortcut is the abstraction used by GTK to handle shortcuts from
* keyboard or other input devices.
*
* Shortcut triggers can be used to weave complex sequences of key
* presses into sophisticated mechanisms to activate shortcuts.
*
* This demo code shows creative ways to do that.
*/
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
static gboolean
shortcut_activated (GtkWidget *widget,
GVariant *unused,
gpointer row)
{
g_print ("activated %s\n", gtk_label_get_label (row));
return TRUE;
}
static GtkShortcutTrigger *
create_ctrl_g (void)
{
return gtk_keyval_trigger_new (GDK_KEY_g, GDK_CONTROL_MASK);
}
static GtkShortcutTrigger *
create_x (void)
{
return gtk_keyval_trigger_new (GDK_KEY_x, 0);
}
struct {
const char *description;
GtkShortcutTrigger * (* create_trigger_func) (void);
} shortcuts[] = {
{ "Press Ctrl-G", create_ctrl_g },
{ "Press X", create_x },
};
GtkWidget *
do_shortcut_triggers (GtkWidget *do_widget)
{
guint i;
if (!window)
{
GtkWidget *list;
GtkEventController *controller;
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Shortcuts");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
list = gtk_list_box_new ();
g_object_set (list, "margin", 6, NULL);
gtk_container_add (GTK_CONTAINER (window), list);
for (i = 0; i < G_N_ELEMENTS (shortcuts); i++)
{
GtkShortcut *shortcut;
GtkWidget *row;
row = gtk_label_new (shortcuts[i].description);
gtk_container_add (GTK_CONTAINER (list), row);
controller = gtk_shortcut_controller_new ();
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller), GTK_SHORTCUT_SCOPE_GLOBAL);
gtk_widget_add_controller (row, controller);
shortcut = gtk_shortcut_new (shortcuts[i].create_trigger_func(),
gtk_callback_action_new (shortcut_activated, row, NULL));
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
}
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
return window;
}

View File

@ -160,47 +160,13 @@ check_solved (GtkWidget *grid)
}
static gboolean
puzzle_key_pressed (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
GtkWidget *grid)
puzzle_key_pressed (GtkWidget *grid,
GVariant *args,
gpointer unused)
{
int dx, dy;
dx = 0;
dy = 0;
switch (keyval)
{
case GDK_KEY_KP_Left:
case GDK_KEY_Left:
/* left */
dx = -1;
break;
case GDK_KEY_KP_Up:
case GDK_KEY_Up:
/* up */
dy = -1;
break;
case GDK_KEY_KP_Right:
case GDK_KEY_Right:
/* right */
dx = 1;
break;
case GDK_KEY_KP_Down:
case GDK_KEY_Down:
/* down */
dy = 1;
break;
default:
/* We return FALSE here because we didn't handle the key that was pressed */
return FALSE;
}
g_variant_get (args, "(ii)", &dx, &dy);
if (!move_puzzle (grid, dx, dy))
{
@ -276,6 +242,24 @@ puzzle_button_pressed (GtkGestureClick *gesture,
}
}
static void
add_move_binding (GtkShortcutController *controller,
guint keyval,
guint kp_keyval,
int dx,
int dy)
{
GtkShortcut *shortcut;
shortcut = gtk_shortcut_new_with_arguments (
gtk_alternative_trigger_new (gtk_keyval_trigger_new (keyval, 0),
gtk_keyval_trigger_new (kp_keyval, 0)),
gtk_callback_action_new (puzzle_key_pressed, NULL, NULL),
"(ii)", dx, dy);
gtk_shortcut_controller_add_shortcut (controller, shortcut);
g_object_unref (shortcut);
}
static void
start_puzzle (GdkPaintable *paintable)
{
@ -298,12 +282,21 @@ start_puzzle (GdkPaintable *paintable)
aspect_ratio = 1.0;
gtk_aspect_frame_set (GTK_ASPECT_FRAME (frame), 0.5, 0.5, aspect_ratio, FALSE);
/* Add a key event controller so people can use the arrow
/* Add shortcuts so people can use the arrow
* keys to move the puzzle */
controller = gtk_event_controller_key_new ();
g_signal_connect (controller, "key-pressed",
G_CALLBACK (puzzle_key_pressed),
grid);
controller = gtk_shortcut_controller_new ();
add_move_binding (GTK_SHORTCUT_CONTROLLER (controller),
GDK_KEY_Left, GDK_KEY_KP_Left,
-1, 0);
add_move_binding (GTK_SHORTCUT_CONTROLLER (controller),
GDK_KEY_Right, GDK_KEY_KP_Right,
1, 0);
add_move_binding (GTK_SHORTCUT_CONTROLLER (controller),
GDK_KEY_Up, GDK_KEY_KP_Up,
0, -1);
add_move_binding (GTK_SHORTCUT_CONTROLLER (controller),
GDK_KEY_Down, GDK_KEY_KP_Down,
0, 1);
gtk_widget_add_controller (GTK_WIDGET (grid), controller);
controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());

View File

@ -336,6 +336,16 @@
<xi:include href="xml/gtkgesturezoom.xml" />
<xi:include href="xml/gtkgesturestylus.xml" />
<xi:include href="xml/gtkpadcontroller.xml" />
<xi:include href="xml/gtkshortcutcontroller.xml" />
</chapter>
<chapter>
<title>Keyboard shortcuts</title>
<xi:include href="xml/gtkaccelgroup.xml" />
<xi:include href="xml/gtkshortcut.xml" />
<xi:include href="xml/gtkshortcuttrigger.xml" />
<xi:include href="xml/gtkshortcutaction.xml" />
<xi:include href="xml/gtkshortcutmanager.xml" />
</chapter>
<chapter>
@ -352,10 +362,7 @@
<title>GTK Core Reference</title>
<xi:include href="xml/gtkmain.xml" />
<xi:include href="xml/gtkfeatures.xml" />
<xi:include href="xml/gtkaccelgroup.xml" />
<xi:include href="xml/gtkaccelmap.xml" />
<xi:include href="xml/gtksettings.xml" />
<xi:include href="xml/gtkbindings.xml" />
<xi:include href="xml/gtkenums.xml" />
<xi:include href="xml/gtktesting.xml" />
<xi:include href="xml/filesystem.xml" />

View File

@ -53,26 +53,6 @@ gtk_about_dialog_get_type
<SECTION>
<FILE>gtkaccelgroup</FILE>
<TITLE>Keyboard Accelerators</TITLE>
GtkAccelGroup
GtkAccelGroupClass
gtk_accel_group_new
GtkAccelFlags
gtk_accel_group_connect
gtk_accel_group_connect_by_path
GtkAccelGroupActivate
GtkAccelGroupFindFunc
gtk_accel_group_disconnect
gtk_accel_group_disconnect_key
gtk_accel_group_activate
gtk_accel_group_lock
gtk_accel_group_unlock
gtk_accel_group_get_is_locked
gtk_accel_group_from_accel_closure
gtk_accel_group_get_modifier_mask
gtk_accel_groups_activate
gtk_accel_groups_from_object
gtk_accel_group_find
GtkAccelKey
gtk_accelerator_valid
gtk_accelerator_parse
gtk_accelerator_name
@ -82,52 +62,6 @@ gtk_accelerator_name_with_keycode
gtk_accelerator_get_label_with_keycode
gtk_accelerator_set_default_mod_mask
gtk_accelerator_get_default_mod_mask
<SUBSECTION Standard>
GTK_TYPE_ACCEL_GROUP
GTK_ACCEL_GROUP
GTK_IS_ACCEL_GROUP
GTK_ACCEL_GROUP_CLASS
GTK_IS_ACCEL_GROUP_CLASS
GTK_ACCEL_GROUP_GET_CLASS
<SUBSECTION Private>
GTK_ACCEL_GROUP_GET_PRIVATE
GtkAccelGroupPrivate
GtkAccelGroupEntry
gtk_accel_group_query
gtk_accel_group_get_type
</SECTION>
<SECTION>
<FILE>gtkaccelmap</FILE>
<TITLE>Accelerator Maps</TITLE>
GtkAccelMap
GtkAccelMapForeach
gtk_accel_map_add_entry
gtk_accel_map_lookup_entry
gtk_accel_map_change_entry
gtk_accel_map_load
gtk_accel_map_save
gtk_accel_map_foreach
gtk_accel_map_load_fd
gtk_accel_map_save_fd
gtk_accel_map_load_scanner
gtk_accel_map_add_filter
gtk_accel_map_foreach_unfiltered
gtk_accel_map_get
gtk_accel_map_lock_path
gtk_accel_map_unlock_path
<SUBSECTION Standard>
GTK_ACCEL_MAP
GTK_TYPE_ACCEL_MAP
GTK_IS_ACCEL_MAP
GTK_ACCEL_MAP_CLASS
GTK_IS_ACCEL_MAP_CLASS
GTK_ACCEL_MAP_GET_CLASS
GtkAccelMapClass
<SUBSECTION Private>
gtk_accel_map_get_type
</SECTION>
<SECTION>
@ -135,10 +69,6 @@ gtk_accel_map_get_type
<TITLE>GtkAccelLabel</TITLE>
GtkAccelLabel
gtk_accel_label_new
gtk_accel_label_set_accel_closure
gtk_accel_label_get_accel_closure
gtk_accel_label_get_accel_widget
gtk_accel_label_set_accel_widget
gtk_accel_label_get_accel_width
gtk_accel_label_set_accel
gtk_accel_label_get_accel
@ -4035,10 +3965,9 @@ gtk_widget_add_tick_callback
gtk_widget_remove_tick_callback
gtk_widget_size_allocate
gtk_widget_allocate
gtk_widget_add_accelerator
gtk_widget_remove_accelerator
gtk_widget_set_accel_path
gtk_widget_list_accel_closures
gtk_widget_class_add_shortcut
gtk_widget_class_add_binding
gtk_widget_class_add_binding_signal
gtk_widget_can_activate_accel
gtk_widget_activate
gtk_widget_is_focus
@ -4254,8 +4183,6 @@ gtk_window_new
gtk_window_set_title
gtk_window_set_resizable
gtk_window_get_resizable
gtk_window_add_accel_group
gtk_window_remove_accel_group
gtk_window_set_modal
gtk_window_set_default_size
gtk_window_set_hide_on_close
@ -4267,11 +4194,6 @@ gtk_window_is_active
gtk_window_is_maximized
gtk_window_get_toplevels
gtk_window_list_toplevels
gtk_window_add_mnemonic
gtk_window_remove_mnemonic
gtk_window_mnemonic_activate
gtk_window_activate_key
gtk_window_propagate_key_event
gtk_window_get_focus
gtk_window_set_focus
gtk_window_get_default_widget
@ -4281,20 +4203,13 @@ gtk_window_present_with_time
gtk_window_close
gtk_window_minimize
gtk_window_unminimize
gtk_window_stick
gtk_window_unstick
gtk_window_maximize
gtk_window_unmaximize
gtk_window_fullscreen
gtk_window_fullscreen_on_monitor
gtk_window_unfullscreen
gtk_window_set_keep_above
gtk_window_set_keep_below
gtk_window_set_decorated
gtk_window_set_deletable
gtk_window_set_mnemonic_modifier
gtk_window_set_accept_focus
gtk_window_set_focus_on_map
gtk_window_set_startup_id
gtk_window_get_decorated
gtk_window_get_deletable
@ -4302,13 +4217,10 @@ gtk_window_get_default_icon_name
gtk_window_get_default_size
gtk_window_get_destroy_with_parent
gtk_window_get_icon_name
gtk_window_get_mnemonic_modifier
gtk_window_get_modal
gtk_window_get_size
gtk_window_get_title
gtk_window_get_transient_for
gtk_window_get_accept_focus
gtk_window_get_focus_on_map
gtk_window_get_group
gtk_window_has_group
gtk_window_resize
@ -4618,26 +4530,6 @@ gtk_css_provider_error_quark
gtk_css_section_get_type
</SECTION>
<SECTION>
<FILE>gtkbindings</FILE>
<TITLE>Bindings</TITLE>
GtkBindingSet
gtk_binding_set_new
gtk_binding_set_by_class
gtk_binding_set_find
gtk_bindings_activate
gtk_bindings_activate_event
gtk_binding_set_activate
gtk_binding_entry_add_action
gtk_binding_entry_add_action_variant
GtkBindingCallback
gtk_binding_entry_add_callback
gtk_binding_entry_add_signal
gtk_binding_entry_add_signal_from_string
gtk_binding_entry_skip
gtk_binding_entry_remove
</SECTION>
<SECTION>
<FILE>gtkenums</FILE>
<TITLE>Standard Enumerations</TITLE>
@ -6062,6 +5954,140 @@ GTK_EVENT_CONTROLLER_MOTION_GET_CLASS
gtk_event_controller_motion_get_type
</SECTION>
<SECTION>
<FILE>gtkshortcuttrigger</FILE>
<TITLE>GtkShortcutTrigger</TITLE>
GtkShortcutTrigger
gtk_shortcut_trigger_ref
gtk_shortcut_trigger_unref
GtkShortcutTriggerType
gtk_shortcut_trigger_get_trigger_type
gtk_shortcut_trigger_parse_string
gtk_shortcut_trigger_trigger
gtk_shortcut_trigger_hash
gtk_shortcut_trigger_equal
gtk_shortcut_trigger_compare
gtk_shortcut_trigger_to_string
gtk_shortcut_trigger_print
gtk_shortcut_trigger_to_label
gtk_shortcut_trigger_print_label
<SUBSECTION>
gtk_keyval_trigger_new
gtk_keyval_trigger_get_modifiers
gtk_keyval_trigger_get_keyval
<SUBSECTION>
gtk_mnemonic_trigger_new
gtk_mnemonic_trigger_get_keyval
<SUBSECTION Private>
gtk_shortcut_trigger_get_type
</SECTION>
<SECTION>
<FILE>gtkshortcutaction</FILE>
<TITLE>GtkShortcutAction</TITLE>
GtkShortcutAction
gtk_shortcut_action_ref
gtk_shortcut_action_unref
GtkShortcutActionType
gtk_shortcut_action_get_action_type
gtk_shortcut_action_to_string
gtk_shortcut_action_print
gtk_shortcut_action_activate
<SUBSECTION>
gtk_nothing_action_new
<SUBSECTION>
gtk_callback_action_new
<SUBSECTION>
gtk_mnemonic_action_new
<SUBSECTION>
gtk_activate_action_new
<SUBSECTION>
gtk_signal_action_new
gtk_signal_action_get_signal_name
<SUBSECTION>
gtk_named_action_new
gtk_named_action_get_name
<SUBSECTION Private>
gtk_shortcut_action_get_type
</SECTION>
<SECTION>
<FILE>gtkshortcut</FILE>
<TITLE>GtkShortcut</TITLE>
GtkShortcut
gtk_shortcut_new
gtk_shortcut_new_with_arguments
gtk_shortcut_get_trigger
gtk_shortcut_set_trigger
gtk_shortcut_get_action
gtk_shortcut_set_action
gtk_shortcut_get_arguments
gtk_shortcut_set_arguments
<SUBSECTION Standard>
GTK_TYPE_SHORTCUT
GTK_SHORTCUT
GTK_SHORTCUT_CLASS
GTK_IS_SHORTCUT
GTK_IS_SHORTCUT_CLASS
GTK_SHORTCUT_GET_CLASS
<SUBSECTION Private>
gtk_shortcut_get_type
</SECTION>
<SECTION>
<FILE>gtkshortcutmanager</FILE>
<TITLE>GtkShortcutManager</TITLE>
GtkShortcutManager
GtkShortcutManagerInterface
</SECTION>
<SECTION>
<FILE>gtkshortcutcontroller</FILE>
<TITLE>GtkShortcutController</TITLE>
GtkShortcutController
gtk_shortcut_controller_new
gtk_shortcut_controller_new_with_model
GtkShortcutScope
GtkShortcutManager
GtkShortcutManagerInterface
gtk_shortcut_controller_set_mnemonics_modifiers
gtk_shortcut_controller_get_mnemonics_modifiers
gtk_shortcut_controller_set_scope
gtk_shortcut_controller_get_scope
gtk_shortcut_controller_add_shortcut
gtk_shortcut_controller_remove_shortcut
<SUBSECTION Standard>
GTK_TYPE_SHORTCUT_CONTROLLER
GTK_SHORTCUT_CONTROLLER
GTK_SHORTCUT_CONTROLLER_CLASS
GTK_IS_SHORTCUT_CONTROLLER
GTK_IS_SHORTCUT_CONTROLLER_CLASS
GTK_SHORTCUT_CONTROLLER_GET_CLASS
GTK_TYPE_SHORTCUT_MANAGER
GTK_SHORTCUT_MANAGER
GTK_SHORTCUT_MANAGER_CLASS
GTK_IS_SHORTCUT_MANAGER
GTK_IS_SHORTCUT_MANAGER_CLASS
GTK_SHORTCUT_MANAGER_GET_CLASS
<SUBSECTION Private>
gtk_shortcut_controller_get_type
gtk_shortcut_manager_get_type
</SECTION>
<SECTION>
<FILE>gtkeventcontrollerkey</FILE>
<TITLE>GtkEventControllerKey</TITLE>

View File

@ -2,9 +2,7 @@
#include <gtk/gtkunixprint.h>
gtk_about_dialog_get_type
gtk_accel_group_get_type
gtk_accel_label_get_type
gtk_accel_map_get_type
gtk_accessible_get_type
gtk_actionable_get_type
gtk_action_bar_get_type
@ -165,7 +163,10 @@ gtk_search_entry_get_type
gtk_selection_model_get_type
gtk_separator_get_type
gtk_settings_get_type
gtk_shortcut_get_type
gtk_shortcut_controller_get_type
gtk_shortcut_label_get_type
gtk_shortcut_manager_get_type
gtk_shortcuts_window_get_type
gtk_shortcuts_section_get_type
gtk_shortcuts_group_get_type

View File

@ -63,25 +63,19 @@
GDK translates these raw windowing system events into #GdkEvents.
Typical input events are:
<simplelist>
<member>#GdkEventButton</member>
<member>#GdkEventMotion</member>
<member>#GdkEventCrossing</member>
<member>#GdkEventKey</member>
<member>#GdkEventFocus</member>
<member>#GdkEventTouch</member>
<member>button clicks</member>
<member>pointer motion</member>
<member>key presses</member>
<member>focus changes</member>
<member>touch events</member>
</simplelist>
These are all represented as #GdkEvents, but you can differentiate
between different events by looking at their type, using
gdk_event_get_event_type().
</para>
<para>
Additionally, GDK/GTK synthesizes other signals to let know whether
grabs (system-wide or in-app) are taking input away:
<simplelist>
<member>#GdkEventGrabBroken</member>
<member>#GtkWidget::grab-notify</member>
</simplelist>
</para>
<para>
When GTK creates a GdkSurface, it connects to the ::event signal
on it, which receives all of these input events. Surfaces have
When GTK creates a GdkSurface, it connects to the #GdkSurface::event
signal on it, which receives all of these input events. Surfaces have
have signals and properties, e.g. to deal with window management
related events.
</para>
@ -96,14 +90,11 @@
</para>
<orderedlist>
<listitem><para>
Compress enter/leave notify events. If the event passed build an
enter/leave pair together with the next event (peeked from GDK), both
events are thrown away. This is to avoid a backlog of (de-)highlighting
widgets crossed by the pointer.
Find the widget which got the event.
</para></listitem>
<listitem><para>
Find the widget which got the event. If the widget cant be determined
the event is thrown away unless it belongs to a INCR transaction.
Generate crossing (i.e. enter and leave) events when the focus or hover
location change from one widget to another.
</para></listitem>
<listitem><para>
Then the event is pushed onto a stack so you can query the currently
@ -137,24 +128,6 @@
</para></listitem>
</orderedlist>
<para>
When a GDK backend produces an input event, it is tied to a #GdkDevice and
a #GdkSurface, which in turn represents a windowing system surface in the
backend. If a widget has grabbed the current input device, or all input
devices, the event is propagated to that #GtkWidget. Otherwise, it is
propagated to the the #GtkRoot which owns the #GdkSurface receiving the event.
</para>
<para>
Grabs are implemented for each input device, and globally. A grab for a
specific input device (gtk_device_grab_add()), is sent events in
preference to a global grab (gtk_grab_add()). Input grabs only have effect
within the #GtkWindowGroup containing the #GtkWidget which registered the
events #GdkSurface. If this #GtkWidget is a child of the grab widget, the
event is propagated to the child — this is the basis for propagating
events within modal dialogs.
</para>
<para>
An event is propagated down and up the widget hierarchy in three phases
(see #GtkPropagationPhase) towards a target widget.
@ -219,71 +192,75 @@
</para>
</refsect2>
<refsect2>
<title>Grabs</title>
<para>
Grabs are a method to claim all input events from a device,
they happen either implicitly on pointer and touch devices,
or explicitly. Implicit grabs happen on user interaction, when
a #GdkEventButtonPress happens, all events from then on, until
after the corresponding #GdkEventButtonRelease, will be reported
to the widget that got the first event. Likewise, on touch events,
every #GdkEventSequence will deliver only events to the widget
that received its %GDK_TOUCH_BEGIN event.
</para>
<para>
Explicit grabs happen programatically (both activation and
deactivation), and can be either system-wide (GDK grabs) or
application-wide (GTK grabs). On the windowing platforms that
support it, GDK grabs will prevent any interaction with any other
application/window/widget than the grabbing one, whereas GTK grabs
will be effective only within the application (across all its
windows), still allowing for interaction with other applications.
</para>
<para>
But one important aspect of grabs is that they may potentially
happen at any point somewhere else, even while the pointer/touch
device is already grabbed. This makes it necessary for widgets to
handle the cancellation of any ongoing interaction. Depending on
whether a GTK or GDK grab is causing this, the widget will
respectively receive a #GtkWidget::grab-notify signal, or a
#GdkEventGrabBroken event.
</para>
<para>
On gestures, these signals are handled automatically, causing the
gesture to cancel all tracked pointer/touch events, and signal
the end of recognition.
</para>
</refsect2>
<refsect2>
<title>Keyboard input</title>
<para>
Every #GtkWindow maintains a single focus location (in
the ::focus-widget property). The focus widget is the
target widget for key events sent to the window. Only
widgets which have ::can-focus set to %TRUE can become
the focus. Typically these are input controls such as
entries or text fields, but e.g. buttons can take the
focus too.
Every #GtkWindow maintains a single focus location (in the
#GtkWindow:focus-widget property). The focus widget is the target
widget for key events sent to the window. Only widgets which have
#GtkWidget:can-focus set to %TRUE can become the focus. Typically
these are input controls such as entries or text fields, but e.g.
buttons can take the focus too.
</para>
<para>
Input widgets can be given the focus by clicking on them,
but focus can also be moved around with certain key
events (this is known as “keyboard navigation”). GTK
reserves the Tab key to move the focus to the next location,
and Shift-Tab to move it back to the previous one. In addition
many containers allow “directional navigation” with the
arrow keys.
Input widgets can be given the focus by clicking on them, but focus
can also be moved around with certain key events (this is known as
“keyboard navigation”). GTK reserves the Tab key to move the focus
to the next location, and Shift-Tab to move it back to the previous
one. In addition many containers allow “directional navigation” with
the arrow keys.
</para>
<!-- mnemonics, accelerators, bindings -->
<para>
Many widgets can be “activated” to trigger and action. E.g., you can
activate a button or switch by clicking on them, but you can also
activate them with the keyboard, by using the Enter or Space keys.
</para>
<para>
Apart from keyboard navigation, activation and directly typing into
entries or text views, GTK widgets can use key events for activating
“shortcuts”. Shortcuts generally act as a quick way to move the focus
around or to activate a widget that does not currently have the focus.
</para>
<para>
GTK has traditionally supported different kinds of shortcuts:
<variablelist>
<varlistentry>
<term>Mnmemonics</term>
<listitem><para>
Mnemonics are usually triggered using Alt as a modifier for a letter.
They are used in places where a label is associated with a control,
and are indicated by underlining the letter in the label. As a special
case, inside menus (i.e. inside #GtkPopoverMenu), mnemonics can be
trigered without the modifier.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Key bindings</term>
<listitem><para>
Key bindings are specific to individual widgets, such as Ctrl-C or
Ctrl-V in an entry copy to or paste from the clipboard. They are only
triggered when the widget has focus.
</para></listitem>
</varlistentry>
<varlistentry>
<term>Accelerators</term>
<listitem><para>
Accelerators are any other shortcuts that can be activated regardless
of where the focus is, and typically trigger global actions, such as
Ctrl-Q to quit an application.
</para></listitem>
</varlistentry>
</variablelist>
</para>
<para>
Under the hood, all shortcuts are represented as instances of #GtkShortcut,
and they are managed by #GtkShortcutController.
</para>
</refsect2>
<refsect2 id="event-controllers-and-gestures">
@ -330,6 +307,13 @@
</member>
</simplelist>
</para>
<para>
Shortcuts are handled by #GtkShortcutController, which is
a complex event handler that can either activate shortcuts
itself, or propagate them to another controller, depending
on its #GtkShortcutController:scope.
</para>
</refsect2>
<refsect2>

View File

@ -281,26 +281,20 @@ create_accel_label (void)
{
WidgetInfo *info;
GtkWidget *widget, *button, *box;
GtkAccelGroup *accel_group;
widget = gtk_accel_label_new ("Accel Label");
button = gtk_button_new_with_label ("Quit");
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (widget), button);
gtk_widget_hide (button);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (box), widget);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (widget), button);
accel_group = gtk_accel_group_new();
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (widget), GDK_KEY_Q, GDK_CONTROL_MASK);
info = new_widget_info ("accel-label", box, SMALL);
gtk_widget_add_accelerator (button, "activate", accel_group, GDK_KEY_Q, GDK_CONTROL_MASK,
GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED);
return info;
}

View File

@ -75,7 +75,7 @@ const GDK_CROSSING_GRAB = 1;
const GDK_CROSSING_UNGRAB = 2;
// GdkModifierType
const GDK_SHIFT_MASK = 1 << 0;
const GDK_SHIFT_MASK = 1 << 0;
const GDK_LOCK_MASK = 1 << 1;
const GDK_CONTROL_MASK = 1 << 2;
const GDK_MOD1_MASK = 1 << 3;
@ -91,7 +91,6 @@ const GDK_BUTTON5_MASK = 1 << 12;
const GDK_SUPER_MASK = 1 << 26;
const GDK_HYPER_MASK = 1 << 27;
const GDK_META_MASK = 1 << 28;
const GDK_RELEASE_MASK = 1 << 30;
var useDataUrls = window.location.search.includes("datauri");

View File

@ -232,8 +232,7 @@ typedef enum
* @GDK_HYPER_MASK: the Hyper modifier
* @GDK_META_MASK: the Meta modifier
* @GDK_MODIFIER_RESERVED_29_MASK: A reserved bit flag; do not use in your own code
* @GDK_RELEASE_MASK: not used in GDK itself. GTK uses it to differentiate
* between (keyval, modifiers) pairs from key press and release events.
* @GDK_MODIFIER_RESERVED_30_MASK: A reserved bit flag; do not use in your own code
* @GDK_MODIFIER_MASK: a mask covering all modifier types.
*
* A set of bit-flags to indicate the state of modifier keys and mouse buttons
@ -294,12 +293,11 @@ typedef enum
GDK_META_MASK = 1 << 28,
GDK_MODIFIER_RESERVED_29_MASK = 1 << 29,
GDK_RELEASE_MASK = 1 << 30,
GDK_MODIFIER_RESERVED_30_MASK = 1 << 30,
/* Combination of GDK_SHIFT_MASK..GDK_BUTTON5_MASK + GDK_SUPER_MASK
+ GDK_HYPER_MASK + GDK_META_MASK + GDK_RELEASE_MASK */
GDK_MODIFIER_MASK = 0x5c001fff
+ GDK_HYPER_MASK + GDK_META_MASK */
GDK_MODIFIER_MASK = 0x1c001fff
} GdkModifierType;
/**
@ -624,6 +622,45 @@ typedef enum
*/
#define GDK_ACTION_ALL (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK)
/*
* GDK_DECLARE_INTERNAL_TYPE:
* @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
* @module_obj_name: The name of the new type in lowercase, with words
* separated by '_' (like 'gtk_widget')
* @MODULE: The name of the module, in all caps (like 'GTK')
* @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
* @ParentName: the name of the parent type, in camel case (like GtkWidget)
*
* A convenience macro for emitting the usual declarations in the
* header file for a type which is intended to be subclassed only
* by internal consumers.
*
* This macro differs from %G_DECLARE_DERIVABLE_TYPE and %G_DECLARE_FINAL_TYPE
* by declaring a type that is only derivable internally. Internal users can
* derive this type, assuming they have access to the instance and class
* structures; external users will not be able to subclass this type.
*/
#define GDK_DECLARE_INTERNAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
GType module_obj_name##_get_type (void); \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
typedef struct _##ModuleObjName ModuleObjName; \
typedef struct _##ModuleObjName##Class ModuleObjName##Class; \
\
_GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ModuleObjName##Class, g_type_class_unref) \
\
G_GNUC_UNUSED static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
G_GNUC_UNUSED static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_CLASS (gpointer ptr) { \
return G_TYPE_CHECK_CLASS_CAST (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
G_GNUC_UNUSED static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); } \
G_GNUC_UNUSED static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS (gpointer ptr) { \
return G_TYPE_CHECK_CLASS_TYPE (ptr, module_obj_name##_get_type ()); } \
G_GNUC_UNUSED static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_GET_CLASS (gpointer ptr) { \
return G_TYPE_INSTANCE_GET_CLASS (ptr, module_obj_name##_get_type (), ModuleObjName##Class); } \
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
#endif /* __GDK_TYPES_H__ */

View File

@ -34,7 +34,6 @@
#include <gtk/gtkaboutdialog.h>
#include <gtk/gtkaccelgroup.h>
#include <gtk/gtkaccellabel.h>
#include <gtk/gtkaccelmap.h>
#include <gtk/gtkaccessible.h>
#include <gtk/gtkactionable.h>
#include <gtk/gtkactionbar.h>
@ -49,7 +48,6 @@
#include <gtk/gtkassistant.h>
#include <gtk/gtkbin.h>
#include <gtk/gtkbinlayout.h>
#include <gtk/gtkbindings.h>
#include <gtk/gtkborder.h>
#include <gtk/gtkboxlayout.h>
#include <gtk/gtkbox.h>
@ -198,11 +196,16 @@
#include <gtk/gtkselectionmodel.h>
#include <gtk/gtkseparator.h>
#include <gtk/gtksettings.h>
#include <gtk/gtkshortcut.h>
#include <gtk/gtkshortcutaction.h>
#include <gtk/gtkshortcutcontroller.h>
#include <gtk/gtkshortcutlabel.h>
#include <gtk/gtkshortcutmanager.h>
#include <gtk/gtkshortcutsgroup.h>
#include <gtk/gtkshortcutssection.h>
#include <gtk/gtkshortcutsshortcut.h>
#include <gtk/gtkshortcutswindow.h>
#include <gtk/gtkshortcuttrigger.h>
#include <gtk/gtkshow.h>
#include <gtk/gtksingleselection.h>
#include <gtk/gtkslicelistmodel.h>

File diff suppressed because it is too large Load Diff

View File

@ -36,172 +36,17 @@
G_BEGIN_DECLS
/* --- type macros --- */
#define GTK_TYPE_ACCEL_GROUP (gtk_accel_group_get_type ())
#define GTK_ACCEL_GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_ACCEL_GROUP, GtkAccelGroup))
#define GTK_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ACCEL_GROUP, GtkAccelGroupClass))
#define GTK_IS_ACCEL_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_ACCEL_GROUP))
#define GTK_IS_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ACCEL_GROUP))
#define GTK_ACCEL_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ACCEL_GROUP, GtkAccelGroupClass))
/* --- accel flags --- */
/**
* GtkAccelFlags:
* @GTK_ACCEL_VISIBLE: Accelerator is visible
* @GTK_ACCEL_LOCKED: Accelerator not removable
* @GTK_ACCEL_MASK: Mask
*
* Accelerator flags used with gtk_accel_group_connect().
*/
typedef enum
{
GTK_ACCEL_VISIBLE = 1 << 0,
GTK_ACCEL_LOCKED = 1 << 1,
GTK_ACCEL_MASK = 0x07
} GtkAccelFlags;
/* --- typedefs & structures --- */
typedef struct _GtkAccelGroup GtkAccelGroup;
typedef struct _GtkAccelGroupClass GtkAccelGroupClass;
typedef struct _GtkAccelGroupPrivate GtkAccelGroupPrivate;
typedef struct _GtkAccelKey GtkAccelKey;
typedef struct _GtkAccelGroupEntry GtkAccelGroupEntry;
typedef gboolean (*GtkAccelGroupActivate) (GtkAccelGroup *accel_group,
GObject *acceleratable,
guint keyval,
GdkModifierType modifier);
/**
* GtkAccelGroupFindFunc:
* @key:
* @closure:
* @data: (closure):
*/
typedef gboolean (*GtkAccelGroupFindFunc) (GtkAccelKey *key,
GClosure *closure,
gpointer data);
/**
* GtkAccelGroup:
*
* An object representing and maintaining a group of accelerators.
*/
struct _GtkAccelGroup
{
GObject parent;
GtkAccelGroupPrivate *priv;
};
/**
* GtkAccelGroupClass:
* @parent_class: The parent class.
* @accel_changed: Signal emitted when an entry is added to or removed
* from the accel group.
*/
struct _GtkAccelGroupClass
{
GObjectClass parent_class;
/*< public >*/
void (*accel_changed) (GtkAccelGroup *accel_group,
guint keyval,
GdkModifierType modifier,
GClosure *accel_closure);
/*< private >*/
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
/**
* GtkAccelKey:
* @accel_key: The accelerator keyval
* @accel_mods:The accelerator modifiers
* @accel_flags: The accelerator flags
*/
struct _GtkAccelKey
{
guint accel_key;
GdkModifierType accel_mods;
guint accel_flags : 16;
};
/* -- Accelerator Groups --- */
GDK_AVAILABLE_IN_ALL
GType gtk_accel_group_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkAccelGroup* gtk_accel_group_new (void);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_group_get_is_locked (GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
GdkModifierType
gtk_accel_group_get_modifier_mask (GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
void gtk_accel_group_lock (GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
void gtk_accel_group_unlock (GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
void gtk_accel_group_connect (GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods,
GtkAccelFlags accel_flags,
GClosure *closure);
GDK_AVAILABLE_IN_ALL
void gtk_accel_group_connect_by_path (GtkAccelGroup *accel_group,
const gchar *accel_path,
GClosure *closure);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
GClosure *closure);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_group_activate (GtkAccelGroup *accel_group,
GQuark accel_quark,
GObject *acceleratable,
guint accel_key,
GdkModifierType accel_mods);
/* --- GtkActivatable glue --- */
void _gtk_accel_group_attach (GtkAccelGroup *accel_group,
GObject *object);
void _gtk_accel_group_detach (GtkAccelGroup *accel_group,
GObject *object);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_groups_activate (GObject *object,
guint accel_key,
GdkModifierType accel_mods);
GDK_AVAILABLE_IN_ALL
GSList* gtk_accel_groups_from_object (GObject *object);
GDK_AVAILABLE_IN_ALL
GtkAccelKey* gtk_accel_group_find (GtkAccelGroup *accel_group,
GtkAccelGroupFindFunc find_func,
gpointer data);
GDK_AVAILABLE_IN_ALL
GtkAccelGroup* gtk_accel_group_from_accel_closure (GClosure *closure);
/* --- Accelerators--- */
GDK_AVAILABLE_IN_ALL
gboolean gtk_accelerator_valid (guint keyval,
GdkModifierType modifiers) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
void gtk_accelerator_parse (const gchar *accelerator,
gboolean gtk_accelerator_parse (const gchar *accelerator,
guint *accelerator_key,
GdkModifierType *accelerator_mods);
GDK_AVAILABLE_IN_ALL
void gtk_accelerator_parse_with_keycode (const gchar *accelerator,
gboolean gtk_accelerator_parse_with_keycode (const gchar *accelerator,
GdkDisplay *display,
guint *accelerator_key,
guint **accelerator_codes,
GdkModifierType *accelerator_mods);
@ -227,21 +72,6 @@ GDK_AVAILABLE_IN_ALL
GdkModifierType
gtk_accelerator_get_default_mod_mask (void);
GDK_AVAILABLE_IN_ALL
GtkAccelGroupEntry* gtk_accel_group_query (GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods,
guint *n_entries);
struct _GtkAccelGroupEntry
{
GtkAccelKey key;
GClosure *closure;
GQuark accel_path_quark;
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkAccelGroup, g_object_unref)
G_END_DECLS
#endif /* __GTK_ACCEL_GROUP_H__ */

View File

@ -25,19 +25,9 @@
G_BEGIN_DECLS
struct _GtkAccelGroupPrivate
{
guint lock_count;
GdkModifierType modifier_mask;
GSList *acceleratables;
guint n_accels;
GtkAccelGroupEntry *priv_accels;
};
void _gtk_accel_group_reconnect (GtkAccelGroup *accel_group,
GQuark accel_path_quark);
GSList* _gtk_accel_group_get_accelerables (GtkAccelGroup *accel_group);
void gtk_accelerator_print_label (GString *gstring,
guint accelerator_key,
GdkModifierType accelerator_mods);
G_END_DECLS
#endif /* __GTK_ACCEL_GROUP_PRIVATE_H__ */

View File

@ -29,9 +29,7 @@
#include <string.h>
#include "gtklabel.h"
#include "gtkaccellabel.h"
#include "gtkaccellabelprivate.h"
#include "gtkaccelmap.h"
#include "gtkintl.h"
#include "gtkmain.h"
#include "gtkprivate.h"
@ -70,7 +68,6 @@
* set (see #GtkAccelFlags).
* A #GtkAccelLabel can display multiple accelerators and even signal names,
* though it is almost always used to display just one accelerator key.
* ]|
*
* # CSS nodes
*
@ -86,8 +83,6 @@
enum {
PROP_0,
PROP_ACCEL_CLOSURE,
PROP_ACCEL_WIDGET,
PROP_LABEL,
PROP_USE_UNDERLINE,
LAST_PROP
@ -114,10 +109,6 @@ struct _GtkAccelLabelPrivate
GtkWidget *text_label;
GtkWidget *accel_label;
GtkWidget *accel_widget; /* done */
GClosure *accel_closure; /* has set function */
GtkAccelGroup *accel_group; /* set by set_accel_closure() */
guint accel_key; /* manual accel key specification if != 0 */
GdkModifierType accel_mods;
};
@ -132,7 +123,6 @@ static void gtk_accel_label_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_accel_label_destroy (GtkWidget *widget);
static void gtk_accel_label_finalize (GObject *object);
G_DEFINE_TYPE_WITH_PRIVATE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_WIDGET)
@ -147,56 +137,8 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
gobject_class->set_property = gtk_accel_label_set_property;
gobject_class->get_property = gtk_accel_label_get_property;
widget_class->destroy = gtk_accel_label_destroy;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ACCEL_LABEL);
#ifndef GDK_WINDOWING_QUARTZ
/* This is the text that should appear next to menu accelerators
* that use the shift key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
/* This is the text that should appear next to menu accelerators
* that use the control key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
/* This is the text that should appear next to menu accelerators
* that use the alt key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
class->mod_separator = g_strdup ("+");
#else /* GDK_WINDOWING_QUARTZ */
/* U+21E7 UPWARDS WHITE ARROW */
class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
/* U+2303 UP ARROWHEAD */
class->mod_name_control = g_strdup ("\xe2\x8c\x83");
/* U+2325 OPTION KEY */
class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
class->mod_separator = g_strdup ("");
#endif /* GDK_WINDOWING_QUARTZ */
props[PROP_ACCEL_CLOSURE] =
g_param_spec_boxed ("accel-closure",
P_("Accelerator Closure"),
P_("The closure to be monitored for accelerator changes"),
G_TYPE_CLOSURE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
props[PROP_ACCEL_WIDGET] =
g_param_spec_object ("accel-widget",
P_("Accelerator Widget"),
P_("The widget to be monitored for accelerator changes"),
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
props[PROP_LABEL] =
g_param_spec_string ("label",
P_("Label"),
@ -229,12 +171,6 @@ gtk_accel_label_set_property (GObject *object,
switch (prop_id)
{
case PROP_ACCEL_CLOSURE:
gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
break;
case PROP_ACCEL_WIDGET:
gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
break;
case PROP_LABEL:
gtk_accel_label_set_label (accel_label, g_value_get_string (value));
break;
@ -254,16 +190,9 @@ gtk_accel_label_get_property (GObject *object,
GParamSpec *pspec)
{
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
switch (prop_id)
{
case PROP_ACCEL_CLOSURE:
g_value_set_boxed (value, priv->accel_closure);
break;
case PROP_ACCEL_WIDGET:
g_value_set_object (value, priv->accel_widget);
break;
case PROP_LABEL:
g_value_set_string (value, gtk_accel_label_get_label (accel_label));
break;
@ -281,10 +210,6 @@ gtk_accel_label_init (GtkAccelLabel *accel_label)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
priv->accel_widget = NULL;
priv->accel_closure = NULL;
priv->accel_group = NULL;
priv->text_label = gtk_label_new ("");
gtk_widget_set_hexpand (priv->text_label, TRUE);
gtk_label_set_xalign (GTK_LABEL (priv->text_label), 0.0f);
@ -317,17 +242,6 @@ gtk_accel_label_new (const gchar *string)
return GTK_WIDGET (accel_label);
}
static void
gtk_accel_label_destroy (GtkWidget *widget)
{
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
gtk_accel_label_set_accel_widget (accel_label, NULL);
gtk_accel_label_set_accel_closure (accel_label, NULL);
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->destroy (widget);
}
static void
gtk_accel_label_finalize (GObject *object)
{
@ -340,26 +254,6 @@ gtk_accel_label_finalize (GObject *object)
G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
}
/**
* gtk_accel_label_get_accel_widget:
* @accel_label: a #GtkAccelLabel
*
* Fetches the widget monitored by this accelerator label. See
* gtk_accel_label_set_accel_widget().
*
* Returns: (nullable) (transfer none): the widget monitored by @accel_label,
* or %NULL if it is not monitoring a widget.
**/
GtkWidget *
gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
return priv->accel_widget;
}
/**
* gtk_accel_label_get_accel_width:
* @accel_label: a #GtkAccelLabel.
@ -384,463 +278,6 @@ gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
return min;
}
static void
refetch_widget_accel_closure (GtkAccelLabel *accel_label)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
GClosure *closure = NULL;
GList *clist, *list;
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
g_return_if_fail (GTK_IS_WIDGET (priv->accel_widget));
clist = gtk_widget_list_accel_closures (priv->accel_widget);
for (list = clist; list; list = list->next)
{
/* we just take the first closure used */
closure = list->data;
break;
}
g_list_free (clist);
gtk_accel_label_set_accel_closure (accel_label, closure);
}
static void
accel_widget_weak_ref_cb (GtkAccelLabel *accel_label,
GtkWidget *old_accel_widget)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
g_return_if_fail (GTK_IS_WIDGET (priv->accel_widget));
g_signal_handlers_disconnect_by_func (priv->accel_widget,
refetch_widget_accel_closure,
accel_label);
priv->accel_widget = NULL;
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_WIDGET]);
}
/**
* gtk_accel_label_set_accel_widget:
* @accel_label: a #GtkAccelLabel
* @accel_widget: (nullable): the widget to be monitored, or %NULL
*
* Sets the widget to be monitored by this accelerator label. Passing %NULL for
* @accel_widget will dissociate @accel_label from its current widget, if any.
*/
void
gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
GtkWidget *accel_widget)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
if (accel_widget)
g_return_if_fail (GTK_IS_WIDGET (accel_widget));
if (accel_widget != priv->accel_widget)
{
if (priv->accel_widget)
{
gtk_accel_label_set_accel_closure (accel_label, NULL);
g_signal_handlers_disconnect_by_func (priv->accel_widget,
refetch_widget_accel_closure,
accel_label);
g_object_weak_unref (G_OBJECT (priv->accel_widget),
(GWeakNotify) accel_widget_weak_ref_cb, accel_label);
}
priv->accel_widget = accel_widget;
if (priv->accel_widget)
{
g_object_weak_ref (G_OBJECT (priv->accel_widget),
(GWeakNotify) accel_widget_weak_ref_cb, accel_label);
g_signal_connect_object (priv->accel_widget, "accel-closures-changed",
G_CALLBACK (refetch_widget_accel_closure),
accel_label, G_CONNECT_SWAPPED);
refetch_widget_accel_closure (accel_label);
}
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_WIDGET]);
}
}
static void
gtk_accel_label_reset (GtkAccelLabel *accel_label)
{
gtk_accel_label_refetch (accel_label);
}
static void
check_accel_changed (GtkAccelGroup *accel_group,
guint keyval,
GdkModifierType modifier,
GClosure *accel_closure,
GtkAccelLabel *accel_label)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
if (accel_closure == priv->accel_closure)
gtk_accel_label_reset (accel_label);
}
/**
* gtk_accel_label_set_accel_closure:
* @accel_label: a #GtkAccelLabel
* @accel_closure: (nullable): the closure to monitor for accelerator changes,
* or %NULL
*
* Sets the closure to be monitored by this accelerator label. The closure
* must be connected to an accelerator group; see gtk_accel_group_connect().
* Passing %NULL for @accel_closure will dissociate @accel_label from its
* current closure, if any.
**/
void
gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
GClosure *accel_closure)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
if (accel_closure)
g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
if (accel_closure != priv->accel_closure)
{
if (priv->accel_closure)
{
g_signal_handlers_disconnect_by_func (priv->accel_group,
check_accel_changed,
accel_label);
priv->accel_group = NULL;
g_closure_unref (priv->accel_closure);
}
priv->accel_closure = accel_closure;
if (priv->accel_closure)
{
g_closure_ref (priv->accel_closure);
priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
g_signal_connect_object (priv->accel_group, "accel-changed", G_CALLBACK (check_accel_changed),
accel_label, 0);
}
gtk_accel_label_reset (accel_label);
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_CLOSURE]);
}
}
/**
* gtk_accel_label_get_accel_closure:
* @accel_label: a #GtkAccelLabel
*
* Fetches the closure monitored by this accelerator label. See
* gtk_accel_label_set_accel_closure().
*
* Returns: (nullable) (transfer none): the closure monitored by @accel_label,
* or %NULL if it is not monitoring a closure.
*/
GClosure *
gtk_accel_label_get_accel_closure (GtkAccelLabel *accel_label)
{
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
return priv->accel_closure;
}
static gboolean
find_accel (GtkAccelKey *key,
GClosure *closure,
gpointer data)
{
return data == (gpointer) closure;
}
/* Underscores in key names are better displayed as spaces
* E.g., Page_Up should be Page Up.
*
* Some keynames also have prefixes that are not suitable
* for display, e.g XF86AudioMute, so strip those out, too.
*
* This function is only called on untranslated keynames,
* so no need to be UTF-8 safe.
*/
static void
append_without_underscores (GString *s,
const char *str)
{
const char *p;
if (g_str_has_prefix (str, "XF86"))
p = str + 4;
else if (g_str_has_prefix (str, "ISO_"))
p = str + 4;
else
p = str;
for ( ; *p; p++)
{
if (*p == '_')
g_string_append_c (s, ' ');
else
g_string_append_c (s, *p);
}
}
/* On Mac, if the key has symbolic representation (e.g. arrow keys),
* append it to gstring and return TRUE; otherwise return FALSE.
* See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
* for the list of special keys. */
static gboolean
append_keyval_symbol (guint accelerator_key,
GString *gstring)
{
#ifdef GDK_WINDOWING_QUARTZ
switch (accelerator_key)
{
case GDK_KEY_Return:
/* U+21A9 LEFTWARDS ARROW WITH HOOK */
g_string_append (gstring, "\xe2\x86\xa9");
return TRUE;
case GDK_KEY_ISO_Enter:
/* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
g_string_append (gstring, "\xe2\x8c\xa4");
return TRUE;
case GDK_KEY_Left:
/* U+2190 LEFTWARDS ARROW */
g_string_append (gstring, "\xe2\x86\x90");
return TRUE;
case GDK_KEY_Up:
/* U+2191 UPWARDS ARROW */
g_string_append (gstring, "\xe2\x86\x91");
return TRUE;
case GDK_KEY_Right:
/* U+2192 RIGHTWARDS ARROW */
g_string_append (gstring, "\xe2\x86\x92");
return TRUE;
case GDK_KEY_Down:
/* U+2193 DOWNWARDS ARROW */
g_string_append (gstring, "\xe2\x86\x93");
return TRUE;
case GDK_KEY_Page_Up:
/* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
g_string_append (gstring, "\xe2\x87\x9e");
return TRUE;
case GDK_KEY_Page_Down:
/* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
g_string_append (gstring, "\xe2\x87\x9f");
return TRUE;
case GDK_KEY_Home:
/* U+2196 NORTH WEST ARROW */
g_string_append (gstring, "\xe2\x86\x96");
return TRUE;
case GDK_KEY_End:
/* U+2198 SOUTH EAST ARROW */
g_string_append (gstring, "\xe2\x86\x98");
return TRUE;
case GDK_KEY_Escape:
/* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
g_string_append (gstring, "\xe2\x8e\x8b");
return TRUE;
case GDK_KEY_BackSpace:
/* U+232B ERASE TO THE LEFT */
g_string_append (gstring, "\xe2\x8c\xab");
return TRUE;
case GDK_KEY_Delete:
/* U+2326 ERASE TO THE RIGHT */
g_string_append (gstring, "\xe2\x8c\xa6");
return TRUE;
default:
return FALSE;
}
#else /* !GDK_WINDOWING_QUARTZ */
return FALSE;
#endif
}
gchar *
_gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
guint accelerator_key,
GdkModifierType accelerator_mods)
{
GString *gstring;
gboolean seen_mod = FALSE;
gunichar ch;
gstring = g_string_sized_new (10); /* ~len('backspace') */
if (accelerator_mods & GDK_SHIFT_MASK)
{
g_string_append (gstring, klass->mod_name_shift);
seen_mod = TRUE;
}
if (accelerator_mods & GDK_CONTROL_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, klass->mod_name_control);
seen_mod = TRUE;
}
if (accelerator_mods & GDK_MOD1_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, klass->mod_name_alt);
seen_mod = TRUE;
}
if (accelerator_mods & GDK_MOD2_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, "Mod2");
seen_mod = TRUE;
}
if (accelerator_mods & GDK_MOD3_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, "Mod3");
seen_mod = TRUE;
}
if (accelerator_mods & GDK_MOD4_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, "Mod4");
seen_mod = TRUE;
}
if (accelerator_mods & GDK_MOD5_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
g_string_append (gstring, "Mod5");
seen_mod = TRUE;
}
if (accelerator_mods & GDK_SUPER_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
/* This is the text that should appear next to menu accelerators
* that use the super key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
g_string_append (gstring, C_("keyboard label", "Super"));
seen_mod = TRUE;
}
if (accelerator_mods & GDK_HYPER_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
/* This is the text that should appear next to menu accelerators
* that use the hyper key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
g_string_append (gstring, C_("keyboard label", "Hyper"));
seen_mod = TRUE;
}
if (accelerator_mods & GDK_META_MASK)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
#ifndef GDK_WINDOWING_QUARTZ
/* This is the text that should appear next to menu accelerators
* that use the meta key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
*/
g_string_append (gstring, C_("keyboard label", "Meta"));
#else
/* Command key symbol U+2318 PLACE OF INTEREST SIGN */
g_string_append (gstring, "\xe2\x8c\x98");
#endif
seen_mod = TRUE;
}
ch = gdk_keyval_to_unicode (accelerator_key);
if (ch && (ch == ' ' || g_unichar_isgraph (ch)))
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
switch (ch)
{
case ' ':
g_string_append (gstring, C_("keyboard label", "Space"));
break;
case '\\':
g_string_append (gstring, C_("keyboard label", "Backslash"));
break;
default:
g_string_append_unichar (gstring, g_unichar_toupper (ch));
break;
}
}
else if (!append_keyval_symbol (accelerator_key, gstring))
{
const char *tmp;
tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
if (tmp != NULL)
{
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
if (tmp[0] != 0 && tmp[1] == 0)
g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
else
{
const gchar *str;
str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
if (str == tmp)
append_without_underscores (gstring, tmp);
else
g_string_append (gstring, str);
}
}
}
return g_string_free (gstring, FALSE);
}
/**
* gtk_accel_label_refetch:
* @accel_label: a #GtkAccelLabel.
@ -864,7 +301,7 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
"gtk-enable-accels", &enable_accels,
NULL);
if (enable_accels && (priv->accel_closure || priv->accel_key))
if (enable_accels && priv->accel_key)
{
gboolean have_accel = FALSE;
guint accel_key;
@ -878,30 +315,9 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
have_accel = TRUE;
}
/* If we don't have a hardcoded value, check the accel group */
if (!have_accel)
{
GtkAccelKey *key;
key = gtk_accel_group_find (priv->accel_group, find_accel, priv->accel_closure);
if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
{
accel_key = key->accel_key;
accel_mods = key->accel_mods;
have_accel = TRUE;
}
}
/* If we found a key using either method, set it */
if (have_accel)
{
GtkAccelLabelClass *klass;
klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
accel_string = _gtk_accel_label_class_get_accelerator_label (klass, accel_key, accel_mods);
}
accel_string = gtk_accelerator_get_label (accel_key, accel_mods);
else
/* Otherwise we have a closure with no key. Show "-/-". */
accel_string = g_strdup ("-/-");
@ -943,7 +359,7 @@ gtk_accel_label_set_accel (GtkAccelLabel *accel_label,
priv->accel_key = accelerator_key;
priv->accel_mods = accelerator_mods;
gtk_accel_label_reset (accel_label);
gtk_accel_label_refetch (accel_label);
}
/**

View File

@ -46,18 +46,8 @@ GType gtk_accel_label_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget *gtk_accel_label_new (const gchar *string);
GDK_AVAILABLE_IN_ALL
GtkWidget *gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label);
GDK_AVAILABLE_IN_ALL
guint gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label);
GDK_AVAILABLE_IN_ALL
void gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
GtkWidget *accel_widget);
GDK_AVAILABLE_IN_ALL
void gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
GClosure *accel_closure);
GDK_AVAILABLE_IN_ALL
GClosure * gtk_accel_label_get_accel_closure (GtkAccelLabel *accel_label);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_label_refetch (GtkAccelLabel *accel_label);
GDK_AVAILABLE_IN_ALL
void gtk_accel_label_set_accel (GtkAccelLabel *accel_label,

File diff suppressed because it is too large Load Diff

View File

@ -1,109 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1998, 2001 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_ACCEL_MAP_H__
#define __GTK_ACCEL_MAP_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkaccelgroup.h>
G_BEGIN_DECLS
/* --- global GtkAccelMap object --- */
#define GTK_TYPE_ACCEL_MAP (gtk_accel_map_get_type ())
#define GTK_ACCEL_MAP(accel_map) (G_TYPE_CHECK_INSTANCE_CAST ((accel_map), GTK_TYPE_ACCEL_MAP, GtkAccelMap))
#define GTK_ACCEL_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ACCEL_MAP, GtkAccelMapClass))
#define GTK_IS_ACCEL_MAP(accel_map) (G_TYPE_CHECK_INSTANCE_TYPE ((accel_map), GTK_TYPE_ACCEL_MAP))
#define GTK_IS_ACCEL_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ACCEL_MAP))
#define GTK_ACCEL_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ACCEL_MAP, GtkAccelMapClass))
typedef struct _GtkAccelMap GtkAccelMap;
typedef struct _GtkAccelMapClass GtkAccelMapClass;
/* --- notifier --- */
/**
* GtkAccelMapForeach:
* @data: User data passed to gtk_accel_map_foreach() or
* gtk_accel_map_foreach_unfiltered()
* @accel_path: Accel path of the current accelerator
* @accel_key: Key of the current accelerator
* @accel_mods: Modifiers of the current accelerator
* @changed: Changed flag of the accelerator (if %TRUE, accelerator has changed
* during runtime and would need to be saved during an accelerator dump)
*/
typedef void (*GtkAccelMapForeach) (gpointer data,
const gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods,
gboolean changed);
/* --- public API --- */
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_add_entry (const gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_map_lookup_entry (const gchar *accel_path,
GtkAccelKey *key);
GDK_AVAILABLE_IN_ALL
gboolean gtk_accel_map_change_entry (const gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods,
gboolean replace);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_load (const gchar *file_name);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_save (const gchar *file_name);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_foreach (gpointer data,
GtkAccelMapForeach foreach_func);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_load_fd (gint fd);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_load_scanner (GScanner *scanner);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_save_fd (gint fd);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_lock_path (const gchar *accel_path);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_unlock_path (const gchar *accel_path);
/* --- filter functions --- */
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_add_filter (const gchar *filter_pattern);
GDK_AVAILABLE_IN_ALL
void gtk_accel_map_foreach_unfiltered (gpointer data,
GtkAccelMapForeach foreach_func);
/* --- notification --- */
GDK_AVAILABLE_IN_ALL
GType gtk_accel_map_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkAccelMap *gtk_accel_map_get (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkAccelMap, g_object_unref)
G_END_DECLS
#endif /* __GTK_ACCEL_MAP_H__ */

View File

@ -1,39 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1998, 2001 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_ACCEL_MAP_PRIVATE_H__
#define __GTK_ACCEL_MAP_PRIVATE_H__
#include <gtk/gtkaccelmap.h>
G_BEGIN_DECLS
void _gtk_accel_map_init (void);
void _gtk_accel_map_add_group (const gchar *accel_path,
GtkAccelGroup *accel_group);
void _gtk_accel_map_remove_group (const gchar *accel_path,
GtkAccelGroup *accel_group);
gboolean _gtk_accel_path_is_valid (const gchar *accel_path);
gchar * _gtk_accel_path_for_action (const gchar *action_name,
GVariant *parameter);
G_END_DECLS
#endif /* __GTK_ACCEL_MAP_PRIVATE_H__ */

View File

@ -37,7 +37,6 @@
#include "gtkmarshalers.h"
#include "gtkmain.h"
#include "gtkrecentmanager.h"
#include "gtkaccelmapprivate.h"
#include "gtkicontheme.h"
#include "gtkbuilder.h"
#include "gtkshortcutswindow.h"

View File

@ -22,134 +22,28 @@
#include "config.h"
#include "gtkapplicationaccelsprivate.h"
#include "gtkactionmuxerprivate.h"
#include <string.h>
typedef struct
{
guint key;
GdkModifierType modifier;
} AccelKey;
#include "gtkshortcut.h"
#include "gtkshortcutaction.h"
#include "gtkshortcuttrigger.h"
struct _GtkApplicationAccels
{
GObject parent;
GHashTable *action_to_accels;
GHashTable *accel_to_actions;
GListModel *shortcuts;
};
G_DEFINE_TYPE (GtkApplicationAccels, gtk_application_accels, G_TYPE_OBJECT)
static AccelKey *
accel_key_copy (const AccelKey *source)
{
AccelKey *dest;
dest = g_slice_new (AccelKey);
dest->key = source->key;
dest->modifier = source->modifier;
return dest;
}
static void
accel_key_free (gpointer data)
{
AccelKey *key = data;
g_slice_free (AccelKey, key);
}
static guint
accel_key_hash (gconstpointer data)
{
const AccelKey *key = data;
return key->key + (key->modifier << 16);
}
static gboolean
accel_key_equal (gconstpointer a,
gconstpointer b)
{
const AccelKey *ak = a;
const AccelKey *bk = b;
return ak->key == bk->key && ak->modifier == bk->modifier;
}
static void
add_entry (GtkApplicationAccels *accels,
AccelKey *key,
const gchar *action_and_target)
{
const gchar **old;
const gchar **new;
gint n;
old = g_hash_table_lookup (accels->accel_to_actions, key);
if (old != NULL)
for (n = 0; old[n]; n++) /* find the length */
;
else
n = 0;
new = g_renew (const gchar *, old, n + 1 + 1);
new[n] = action_and_target;
new[n + 1] = NULL;
g_hash_table_insert (accels->accel_to_actions, accel_key_copy (key), new);
}
static void
remove_entry (GtkApplicationAccels *accels,
AccelKey *key,
const gchar *action_and_target)
{
const gchar **old;
const gchar **new;
gint n, i;
/* if we can't find the entry then something has gone very wrong... */
old = g_hash_table_lookup (accels->accel_to_actions, key);
g_assert (old != NULL);
for (n = 0; old[n]; n++) /* find the length */
;
g_assert_cmpint (n, >, 0);
if (n == 1)
{
/* The simple case of removing the last action for an accel. */
g_assert_cmpstr (old[0], ==, action_and_target);
g_hash_table_remove (accels->accel_to_actions, key);
return;
}
for (i = 0; i < n; i++)
if (g_str_equal (old[i], action_and_target))
break;
/* We must have found it... */
g_assert_cmpint (i, <, n);
new = g_new (const gchar *, n - 1 + 1);
memcpy (new, old, i * sizeof (const gchar *));
memcpy (new + i, old + i + 1, (n - (i + 1)) * sizeof (const gchar *));
new[n - 1] = NULL;
g_hash_table_insert (accels->accel_to_actions, accel_key_copy (key), new);
}
static void
gtk_application_accels_finalize (GObject *object)
{
GtkApplicationAccels *accels = GTK_APPLICATION_ACCELS (object);
g_hash_table_unref (accels->accel_to_actions);
g_hash_table_unref (accels->action_to_accels);
g_list_store_remove_all (G_LIST_STORE (accels->shortcuts));
g_object_unref (accels->shortcuts);
G_OBJECT_CLASS (gtk_application_accels_parent_class)->finalize (object);
}
@ -165,9 +59,7 @@ gtk_application_accels_class_init (GtkApplicationAccelsClass *klass)
static void
gtk_application_accels_init (GtkApplicationAccels *accels)
{
accels->accel_to_actions = g_hash_table_new_full (accel_key_hash, accel_key_equal,
accel_key_free, g_free);
accels->action_to_accels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
accels->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
}
GtkApplicationAccels *
@ -181,54 +73,96 @@ gtk_application_accels_set_accels_for_action (GtkApplicationAccels *accels,
const gchar *detailed_action_name,
const gchar * const *accelerators)
{
gchar *action_and_target;
AccelKey *keys, *old_keys;
gint i, n;
gchar *action_name;
GVariant *target;
GtkShortcut *shortcut;
GtkShortcutTrigger *trigger = NULL;
GError *error = NULL;
guint i;
action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
n = accelerators ? g_strv_length ((gchar **) accelerators) : 0;
if (n > 0)
if (!g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error))
{
keys = g_new0 (AccelKey, n + 1);
g_critical ("Error parsing action name: %s", error->message);
g_error_free (error);
return;
}
for (i = 0; i < n; i++)
/* remove the accelerator if it already exists */
for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
{
GtkShortcut *shortcut_i = g_list_model_get_item (accels->shortcuts, i);
GtkShortcutAction *action = gtk_shortcut_get_action (shortcut_i);
GVariant *args = gtk_shortcut_get_arguments (shortcut_i);
if (!GTK_IS_NAMED_ACTION (action) ||
!g_str_equal (gtk_named_action_get_action_name (GTK_NAMED_ACTION (action)), action_name))
continue;
if ((target == NULL && args != NULL) ||
(target != NULL && (args == NULL || !g_variant_equal (target, args))))
continue;
g_list_store_remove (G_LIST_STORE (accels->shortcuts), i);
break;
}
if (accelerators == NULL)
goto out;
for (i = 0; accelerators[i]; i++)
{
GtkShortcutTrigger *new_trigger;
guint key, modifier;
if (!gtk_accelerator_parse (accelerators[i], &key, &modifier))
{
gtk_accelerator_parse (accelerators[i], &keys[i].key, &keys[i].modifier);
if (keys[i].key == 0)
{
g_warning ("Unable to parse accelerator '%s': ignored request to install %d accelerators",
accelerators[i], n);
g_free (action_and_target);
g_free (keys);
return;
}
g_critical ("Unable to parse accelerator '%s': ignored request to install accelerators",
accelerators[i]);
g_clear_object (&trigger);
goto out;
}
new_trigger = gtk_keyval_trigger_new (key, modifier);
if (trigger)
trigger = gtk_alternative_trigger_new (trigger, new_trigger);
else
trigger = new_trigger;
}
else
keys = NULL;
if (trigger == NULL)
goto out;
old_keys = g_hash_table_lookup (accels->action_to_accels, action_and_target);
if (old_keys)
shortcut = gtk_shortcut_new (trigger, gtk_named_action_new (action_name));
gtk_shortcut_set_arguments (shortcut, target);
g_list_store_append (G_LIST_STORE (accels->shortcuts), shortcut);
g_object_unref (shortcut);
out:
g_free (action_name);
if (target)
g_variant_unref (target);
}
static void
append_accelerators (GPtrArray *accels,
GtkShortcutTrigger *trigger)
{
if (GTK_IS_KEYVAL_TRIGGER (trigger))
{
/* We need to remove accel entries from existing keys */
for (i = 0; old_keys[i].key; i++)
remove_entry (accels, &old_keys[i], action_and_target);
GtkKeyvalTrigger *kt = GTK_KEYVAL_TRIGGER (trigger);
guint keyval = gtk_keyval_trigger_get_keyval (kt);
GdkModifierType mods = gtk_keyval_trigger_get_modifiers (kt);
g_ptr_array_add (accels, gtk_accelerator_name (keyval, mods));
return;
}
if (keys)
else if (GTK_IS_ALTERNATIVE_TRIGGER (trigger))
{
g_hash_table_replace (accels->action_to_accels, action_and_target, keys);
GtkAlternativeTrigger *at = GTK_ALTERNATIVE_TRIGGER (trigger);
GtkShortcutTrigger *first = gtk_alternative_trigger_get_first (at);
GtkShortcutTrigger *second = gtk_alternative_trigger_get_second (at);
for (i = 0; i < n; i++)
add_entry (accels, &keys[i], action_and_target);
}
else
{
g_hash_table_remove (accels->action_to_accels, action_and_target);
g_free (action_and_target);
append_accelerators (accels, first);
append_accelerators (accels, second);
return;
}
}
@ -236,223 +170,141 @@ gchar **
gtk_application_accels_get_accels_for_action (GtkApplicationAccels *accels,
const gchar *detailed_action_name)
{
gchar *action_and_target;
AccelKey *keys;
gchar **result;
gint n, i = 0;
GPtrArray *result;
char *action_name;
GVariant *target;
GError *error = NULL;
guint i;
action_and_target = gtk_normalise_detailed_action_name (detailed_action_name);
result = g_ptr_array_new ();
keys = g_hash_table_lookup (accels->action_to_accels, action_and_target);
if (!keys)
if (!g_action_parse_detailed_name (detailed_action_name, &action_name, &target, &error))
{
g_free (action_and_target);
return g_new0 (gchar *, 0 + 1);
g_critical ("Error parsing action name: %s", error->message);
g_error_free (error);
g_ptr_array_add (result, NULL);
return (gchar **) g_ptr_array_free (result, FALSE);
}
for (n = 0; keys[n].key; n++)
;
for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
{
GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
GtkShortcutAction *action = gtk_shortcut_get_action (shortcut);
GVariant *args = gtk_shortcut_get_arguments (shortcut);
result = g_new0 (gchar *, n + 1);
if (!GTK_IS_NAMED_ACTION (action) ||
!g_str_equal (gtk_named_action_get_action_name (GTK_NAMED_ACTION (action)), action_name))
continue;
for (i = 0; i < n; i++)
result[i] = gtk_accelerator_name (keys[i].key, keys[i].modifier);
if ((target == NULL && args != NULL) ||
(target != NULL && (args == NULL || !g_variant_equal (target, args))))
continue;
g_free (action_and_target);
return result;
append_accelerators (result, gtk_shortcut_get_trigger (shortcut));
break;
}
g_free (action_name);
if (target)
g_variant_unref (target);
g_ptr_array_add (result, NULL);
return (gchar **) g_ptr_array_free (result, FALSE);
}
static gboolean
trigger_matches_accel (GtkShortcutTrigger *trigger,
guint keyval,
GdkModifierType modifiers)
{
if (GTK_IS_KEYVAL_TRIGGER (trigger))
{
GtkKeyvalTrigger *kt = GTK_KEYVAL_TRIGGER (trigger);
return gtk_keyval_trigger_get_keyval (kt) == keyval
&& gtk_keyval_trigger_get_modifiers (kt) == modifiers;
}
else if (GTK_IS_ALTERNATIVE_TRIGGER (trigger))
{
GtkAlternativeTrigger *at = GTK_ALTERNATIVE_TRIGGER (trigger);
return trigger_matches_accel (gtk_alternative_trigger_get_first (at), keyval, modifiers)
|| trigger_matches_accel (gtk_alternative_trigger_get_second (at), keyval, modifiers);
}
else
{
return FALSE;
}
}
static char *
get_detailed_name_for_shortcut (GtkShortcut *shortcut)
{
GtkShortcutAction *action = gtk_shortcut_get_action (shortcut);
if (!GTK_IS_NAMED_ACTION (action))
return NULL;
return g_action_print_detailed_name (gtk_named_action_get_action_name (GTK_NAMED_ACTION (action)),
gtk_shortcut_get_arguments (shortcut));
}
gchar **
gtk_application_accels_get_actions_for_accel (GtkApplicationAccels *accels,
const gchar *accel)
{
const gchar * const *actions_and_targets;
gchar **detailed_actions;
AccelKey accel_key;
guint i, n;
GPtrArray *result;
guint key, modifiers;
guint i;
gtk_accelerator_parse (accel, &accel_key.key, &accel_key.modifier);
if (accel_key.key == 0)
if (!gtk_accelerator_parse (accel, &key, &modifiers))
{
g_critical ("invalid accelerator string '%s'", accel);
g_return_val_if_fail (accel_key.key != 0, NULL);
return NULL;
}
actions_and_targets = g_hash_table_lookup (accels->accel_to_actions, &accel_key);
n = actions_and_targets ? g_strv_length ((gchar **) actions_and_targets) : 0;
detailed_actions = g_new0 (gchar *, n + 1);
for (i = 0; i < n; i++)
result = g_ptr_array_new ();
for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
{
const gchar *action_and_target = actions_and_targets[i];
const gchar *sep;
GVariant *target;
GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
char *detailed_name;
sep = strrchr (action_and_target, '|');
target = g_variant_parse (NULL, action_and_target, sep, NULL, NULL);
detailed_actions[i] = g_action_print_detailed_name (sep + 1, target);
if (target)
g_variant_unref (target);
if (!trigger_matches_accel (gtk_shortcut_get_trigger (shortcut), key, modifiers))
continue;
detailed_name = get_detailed_name_for_shortcut (shortcut);
if (detailed_name)
g_ptr_array_add (result, detailed_name);
}
detailed_actions[n] = NULL;
return detailed_actions;
g_ptr_array_add (result, NULL);
return (gchar **) g_ptr_array_free (result, FALSE);
}
gchar **
gtk_application_accels_list_action_descriptions (GtkApplicationAccels *accels)
{
GHashTableIter iter;
gchar **result;
gint n, i = 0;
gpointer key;
GPtrArray *result;
guint i;
n = g_hash_table_size (accels->action_to_accels);
result = g_new (gchar *, n + 1);
g_hash_table_iter_init (&iter, accels->action_to_accels);
while (g_hash_table_iter_next (&iter, &key, NULL))
result = g_ptr_array_new ();
for (i = 0; i < g_list_model_get_n_items (accels->shortcuts); i++)
{
const gchar *action_and_target = key;
const gchar *sep;
GVariant *target;
GtkShortcut *shortcut = g_list_model_get_item (accels->shortcuts, i);
char *detailed_name;
sep = strrchr (action_and_target, '|');
target = g_variant_parse (NULL, action_and_target, sep, NULL, NULL);
result[i++] = g_action_print_detailed_name (sep + 1, target);
if (target)
g_variant_unref (target);
detailed_name = get_detailed_name_for_shortcut (shortcut);
if (detailed_name)
g_ptr_array_add (result, detailed_name);
}
g_assert_cmpint (i, ==, n);
result[i] = NULL;
return result;
g_ptr_array_add (result, NULL);
return (gchar **) g_ptr_array_free (result, FALSE);
}
void
gtk_application_accels_foreach_key (GtkApplicationAccels *accels,
GtkWindow *window,
GtkWindowKeysForeachFunc callback,
gpointer user_data)
GListModel *
gtk_application_accels_get_shortcuts (GtkApplicationAccels *accels)
{
GHashTableIter iter;
gpointer key;
g_hash_table_iter_init (&iter, accels->accel_to_actions);
while (g_hash_table_iter_next (&iter, &key, NULL))
{
AccelKey *accel_key = key;
(* callback) (window, accel_key->key, accel_key->modifier, FALSE, user_data);
}
}
gboolean
gtk_application_accels_activate (GtkApplicationAccels *accels,
GActionGroup *action_group,
guint key,
GdkModifierType modifier)
{
AccelKey accel_key = { key, modifier };
const gchar **actions;
gint i;
actions = g_hash_table_lookup (accels->accel_to_actions, &accel_key);
if (actions == NULL)
return FALSE;
/* We may have more than one action on a given accel. This could be
* the case if we have different types of windows with different
* actions in each.
*
* Find the first one that will successfully activate and use it.
*/
for (i = 0; actions[i]; i++)
{
const GVariantType *parameter_type;
const gchar *action_name;
const gchar *sep;
gboolean enabled;
GVariant *target;
sep = strrchr (actions[i], '|');
action_name = sep + 1;
if (!g_action_group_query_action (action_group, action_name, &enabled, &parameter_type, NULL, NULL, NULL))
continue;
if (!enabled)
continue;
/* We found an action with the correct name and it's enabled.
* This is the action that we are going to try to invoke.
*
* There is still the possibility that the target value doesn't
* match the expected parameter type. In that case, we will print
* a warning.
*
* Note: we want to hold a ref on the target while we're invoking
* the action to prevent trouble if someone uninstalls the accel
* from the handler. That's not a problem since we're parsing it.
*/
if (actions[i] != sep) /* if it has a target... */
{
GError *error = NULL;
if (parameter_type == NULL)
{
gchar *accel_str = gtk_accelerator_name (key, modifier);
g_warning ("Accelerator '%s' tries to invoke action '%s' with target, but action has no parameter",
accel_str, action_name);
g_free (accel_str);
return TRUE;
}
target = g_variant_parse (NULL, actions[i], sep, NULL, &error);
g_assert_no_error (error);
g_assert (target);
if (!g_variant_is_of_type (target, parameter_type))
{
gchar *accel_str = gtk_accelerator_name (key, modifier);
gchar *typestr = g_variant_type_dup_string (parameter_type);
gchar *targetstr = g_variant_print (target, TRUE);
g_warning ("Accelerator '%s' tries to invoke action '%s' with target '%s',"
" but action expects parameter with type '%s'", accel_str, action_name, targetstr, typestr);
g_variant_unref (target);
g_free (targetstr);
g_free (accel_str);
g_free (typestr);
return TRUE;
}
}
else
{
if (parameter_type != NULL)
{
gchar *accel_str = gtk_accelerator_name (key, modifier);
gchar *typestr = g_variant_type_dup_string (parameter_type);
g_warning ("Accelerator '%s' tries to invoke action '%s' without target,"
" but action expects parameter with type '%s'", accel_str, action_name, typestr);
g_free (accel_str);
g_free (typestr);
return TRUE;
}
target = NULL;
}
g_action_group_activate_action (action_group, action_name, target);
if (target)
g_variant_unref (target);
return TRUE;
}
return FALSE;
return accels->shortcuts;
}

View File

@ -47,15 +47,7 @@ gchar ** gtk_application_accels_get_actions_for_accel (GtkApplicat
gchar ** gtk_application_accels_list_action_descriptions (GtkApplicationAccels *accels);
void gtk_application_accels_foreach_key (GtkApplicationAccels *accels,
GtkWindow *window,
GtkWindowKeysForeachFunc callback,
gpointer user_data);
gboolean gtk_application_accels_activate (GtkApplicationAccels *accels,
GActionGroup *action_group,
guint key,
GdkModifierType modifier);
GListModel * gtk_application_accels_get_shortcuts (GtkApplicationAccels *accels);
G_END_DECLS

View File

@ -65,7 +65,6 @@
#include "gtkassistant.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkbuildable.h"
#include "gtkbutton.h"
@ -510,7 +509,6 @@ gtk_assistant_class_init (GtkAssistantClass *class)
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkWindowClass *window_class;
GtkBindingSet *binding_set;
gobject_class = (GObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
@ -619,8 +617,10 @@ gtk_assistant_class_init (GtkAssistantClass *class)
NULL,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "escape", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"escape",
NULL);
/**
* GtkAssistant:use-header-bar:

File diff suppressed because it is too large Load Diff

View File

@ -1,124 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GtkBindingSet: Keybinding manager for GObjects.
* Copyright (C) 1998 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_BINDINGS_H__
#define __GTK_BINDINGS_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkenums.h>
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
typedef struct _GtkBindingSet GtkBindingSet;
/**
* GtkBindingCallback:
* @widget: The object to invoke the callback on
* @args: (allow-none): The arguments or %NULL if none
* @user_data: The user data passed when registering the callback
*
* Prototype of the callback function registered with
* gtk_binding_entry_add_callback.
*/
typedef void (* GtkBindingCallback) (GtkWidget *widget,
GVariant *args,
gpointer user_data);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_new (const gchar *set_name);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_by_class (gpointer object_class);
GDK_AVAILABLE_IN_ALL
GtkBindingSet *gtk_binding_set_find (const gchar *set_name);
GDK_AVAILABLE_IN_ALL
gboolean gtk_bindings_activate (GObject *object,
guint keyval,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
gboolean gtk_bindings_activate_event (GObject *object,
GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gtk_binding_set_activate (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
GObject *object);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_skip (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_signal (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const gchar *signal_name,
guint n_args,
...);
GDK_AVAILABLE_IN_ALL
GTokenType gtk_binding_entry_add_signal_from_string
(GtkBindingSet *binding_set,
const gchar *signal_desc);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_action_variant
(GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const char *action_name,
GVariant *args);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_action (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
const char *action_name,
const char *format_string,
...);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_add_callback(GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
GtkBindingCallback callback,
GVariant *args,
gpointer user_data,
GDestroyNotify user_destroy);
GDK_AVAILABLE_IN_ALL
void gtk_binding_entry_remove (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers);
G_END_DECLS
#endif /* __GTK_BINDINGS_H__ */

View File

@ -215,12 +215,17 @@
#include "gtkbuilderprivate.h"
#include "gdkpixbufutilsprivate.h"
#include "gtkbuildable.h"
#include "gtkbuilderscopeprivate.h"
#include "gtkdebug.h"
#include "gtkmain.h"
#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkshortcutactionprivate.h"
#include "gtkshortcuttrigger.h"
#include "gtktestutils.h"
#include "gtktypebuiltins.h"
#include "gtkicontheme.h"
#include "gtkiconthemeprivate.h"
@ -2092,6 +2097,29 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
ret = FALSE;
}
}
else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
{
GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
if (trigger)
g_value_take_object (value, trigger);
else
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Could not parse shortcut trigger '%s'",
string);
ret = FALSE;
}
}
else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_ACTION))
{
GtkShortcutAction *action = gtk_shortcut_action_parse_builder (builder, string, error);
/* Works for success and failure (NULL) case */
g_value_take_object (value, action);
}
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
{
gchar **vector = g_strsplit (string, "\n", 0);

View File

@ -189,35 +189,44 @@ dismiss_current_popup (GtkColorEditor *editor)
}
static void
popup_edit (GtkWidget *widget,
GtkColorEditor *editor)
popup_edit (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
GtkColorEditor *editor = GTK_COLOR_EDITOR (widget);
GtkWidget *popup = NULL;
GtkRoot *root;
GtkWidget *focus;
gint position;
gint s, e;
const char *param;
if (widget == editor->priv->sv_plane)
param = g_variant_get_string (parameters, NULL);
if (strcmp (param, "sv") == 0)
{
popup = editor->priv->sv_popup;
focus = editor->priv->s_entry;
position = 0;
}
else if (widget == editor->priv->h_slider)
else if (strcmp (param, "h") == 0)
{
popup = editor->priv->h_popup;
focus = editor->priv->h_entry;
gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e);
position = (s + e) / 2;
}
else if (widget == editor->priv->a_slider)
else if (strcmp (param, "a") == 0)
{
popup = editor->priv->a_popup;
focus = editor->priv->a_entry;
gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e);
position = (s + e) / 2;
}
else
{
g_warning ("unsupported popup_edit parameter %s", param);
}
if (popup == editor->priv->current_popup)
dismiss_current_popup (editor);
@ -544,8 +553,12 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
gtk_widget_class_bind_template_callback (widget_class, entry_text_changed);
gtk_widget_class_bind_template_callback (widget_class, entry_apply);
gtk_widget_class_bind_template_callback (widget_class, entry_focus_changed);
gtk_widget_class_bind_template_callback (widget_class, popup_edit);
gtk_widget_class_bind_template_callback (widget_class, pick_color);
gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
}
static void

View File

@ -28,6 +28,10 @@
#include "gtksnapshot.h"
#include "gtkprivate.h"
#include "gtkeventcontrollerkey.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
struct _GtkColorPlanePrivate
{
@ -244,11 +248,11 @@ static void
hold_action (GtkGestureLongPress *gesture,
gdouble x,
gdouble y,
GtkColorPlane *plane)
GtkWidget *plane)
{
gboolean handled;
g_signal_emit_by_name (plane, "popup-menu", &handled);
gtk_widget_activate_action (plane,
"color.edit",
"s", gtk_widget_get_name (plane));
}
static void
@ -344,7 +348,7 @@ static void
plane_drag_gesture_begin (GtkGestureDrag *gesture,
gdouble start_x,
gdouble start_y,
GtkColorPlane *plane)
GtkWidget *plane)
{
guint button;
@ -352,9 +356,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture,
if (button == GDK_BUTTON_SECONDARY)
{
gboolean handled;
g_signal_emit_by_name (plane, "popup-menu", &handled);
gtk_widget_activate_action (plane,
"color.edit",
"s", gtk_widget_get_name (plane));
}
if (button != GDK_BUTTON_PRIMARY)
@ -363,9 +367,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture,
return;
}
set_cross_cursor (GTK_WIDGET (plane), TRUE);
update_color (plane, start_x, start_y);
gtk_widget_grab_focus (GTK_WIDGET (plane));
set_cross_cursor (plane, TRUE);
update_color (GTK_COLOR_PLANE (plane), start_x, start_y);
gtk_widget_grab_focus (plane);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
}
@ -397,6 +401,9 @@ gtk_color_plane_init (GtkColorPlane *plane)
GtkEventController *controller;
GtkGesture *gesture;
AtkObject *atk_obj;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkShortcut *shortcut;
plane->priv = gtk_color_plane_get_instance_private (plane);
@ -430,6 +437,14 @@ gtk_color_plane_init (GtkColorPlane *plane)
g_signal_connect (controller, "key-pressed",
G_CALLBACK (key_controller_key_pressed), plane);
gtk_widget_add_controller (GTK_WIDGET (plane), controller);
controller = gtk_shortcut_controller_new ();
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
action = gtk_named_action_new ("color.edit");
shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv");
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (plane), controller);
}
static void

View File

@ -29,6 +29,10 @@
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtksnapshot.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
#include <math.h>
@ -48,7 +52,7 @@ enum
static void hold_action (GtkGestureLongPress *gesture,
gdouble x,
gdouble y,
GtkColorScale *scale);
GtkWidget *scale);
G_DEFINE_TYPE_WITH_PRIVATE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE)
@ -160,6 +164,29 @@ gtk_color_scale_init (GtkColorScale *scale)
gtk_widget_add_css_class (GTK_WIDGET (scale), "color");
}
static void
scale_constructed (GObject *object)
{
GtkColorScale *scale = GTK_COLOR_SCALE (object);
GtkColorScalePrivate *priv = gtk_color_scale_get_instance_private (scale);
GtkEventController *controller;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkShortcut *shortcut;
controller = gtk_shortcut_controller_new ();
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
action = gtk_named_action_new ("color.edit");
shortcut = gtk_shortcut_new_with_arguments (trigger,
action,
"s",
priv->type == GTK_COLOR_SCALE_ALPHA
? "a" : "h");
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (scale), controller);
}
static void
scale_get_property (GObject *object,
guint prop_id,
@ -223,11 +250,11 @@ static void
hold_action (GtkGestureLongPress *gesture,
gdouble x,
gdouble y,
GtkColorScale *scale)
GtkWidget *scale)
{
gboolean handled;
g_signal_emit_by_name (scale, "popup-menu", &handled);
gtk_widget_activate_action (scale,
"color.edit",
"s", gtk_widget_get_name (scale));
}
static void
@ -245,6 +272,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->constructed = scale_constructed;
object_class->finalize = scale_finalize;
object_class->get_property = scale_get_property;
object_class->set_property = scale_set_property;
@ -253,6 +281,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"),
0, 1, 0,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
void

View File

@ -348,13 +348,12 @@ gtk_color_swatch_measure (GtkWidget *widget,
*natural = MAX (*natural, min);
}
static gboolean
swatch_popup_menu (GtkWidget *widget)
static void
swatch_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
do_popup (GTK_COLOR_SWATCH (widget));
return TRUE;
}
static void
@ -480,7 +479,6 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
widget_class->measure = gtk_color_swatch_measure;
widget_class->snapshot = swatch_snapshot;
widget_class->popup_menu = swatch_popup_menu;
widget_class->size_allocate = swatch_size_allocate;
widget_class->state_flags_changed = swatch_state_flags_changed;
@ -497,6 +495,17 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"),
FALSE, GTK_PARAM_READWRITE));
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, swatch_popup_menu);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("colorswatch"));
}

View File

@ -19,12 +19,12 @@
#include "gtkcomboboxprivate.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkcellareabox.h"
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkcellview.h"
#include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkframe.h"
#include "gtkbuiltiniconprivate.h"
@ -33,10 +33,11 @@
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkshortcutcontroller.h"
#include "gtktogglebutton.h"
#include "gtktreepopoverprivate.h"
#include "gtktypebuiltins.h"
#include "gtkeventcontrollerkey.h"
#include "gtkwidgetprivate.h"
#include "a11y/gtkcomboboxaccessible.h"
@ -409,7 +410,6 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
GObjectClass *object_class;
GtkContainerClass *container_class;
GtkWidgetClass *widget_class;
GtkBindingSet *binding_set;
container_class = (GtkContainerClass *)klass;
container_class->forall = gtk_combo_box_forall;
@ -560,57 +560,77 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
G_TYPE_STRING, 1, G_TYPE_STRING);
/* key bindings */
binding_set = gtk_binding_set_by_class (widget_class);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Down, GDK_MOD1_MASK,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Down, GDK_MOD1_MASK,
"popup",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, GDK_MOD1_MASK,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, GDK_MOD1_MASK,
"popup", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Up, GDK_MOD1_MASK,
"popdown",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Up, GDK_MOD1_MASK,
"popdown",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"popdown",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK,
"popdown", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, GDK_MOD1_MASK,
"popdown", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
"popdown", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Up, 0,
"move-active",
"(i)", GTK_SCROLL_STEP_UP);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Up, 0,
"move-active",
"(i)", GTK_SCROLL_STEP_UP);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, 0,
"move-active",
"(i)", GTK_SCROLL_PAGE_UP);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Page_Up, 0,
"move-active",
"(i)", GTK_SCROLL_PAGE_UP);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Home, 0,
"move-active",
"(i)", GTK_SCROLL_START);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Home, 0,
"move-active",
"(i)", GTK_SCROLL_START);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
"move-active", 1,
GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Down, 0,
"move-active",
"(i)", GTK_SCROLL_STEP_DOWN);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Down, 0,
"move-active",
"(i)", GTK_SCROLL_STEP_DOWN);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Down, 0,
"move-active",
"(i)", GTK_SCROLL_PAGE_DOWN);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Page_Down, 0,
"move-active",
"(i)", GTK_SCROLL_PAGE_DOWN);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_End, 0,
"move-active",
"(i)", GTK_SCROLL_END);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_End, 0,
"move-active",
"(i)", GTK_SCROLL_END);
/* properties */
g_object_class_override_property (object_class,
@ -826,6 +846,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
{
GtkComboBoxPrivate *priv = gtk_combo_box_get_instance_private (combo_box);
GtkEventController *controller;
GList *controllers, *list;
priv->active = -1;
priv->active_row = NULL;
@ -860,6 +881,19 @@ gtk_combo_box_init (GtkComboBox *combo_box)
G_CALLBACK (gtk_combo_box_scroll_controller_scroll),
combo_box);
gtk_widget_add_controller (GTK_WIDGET (combo_box), controller);
controllers = gtk_widget_list_controllers (priv->popup_widget, GTK_PHASE_BUBBLE);
for (list = controllers; list; list = list->next)
{
if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
{
g_object_ref (list->data);
gtk_widget_remove_controller (priv->popup_widget, list->data);
gtk_widget_add_controller (priv->popup_widget, list->data);
break;
}
}
g_list_free (controllers);
}
static void
@ -1789,18 +1823,7 @@ gtk_combo_box_menu_key (GtkEventControllerKey *key,
GdkModifierType modifiers,
GtkComboBox *combo_box)
{
GtkWidget *widget;
GdkEvent *event;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key));
event = gtk_get_current_event ();
if (!gtk_bindings_activate_event (G_OBJECT (widget), event))
{
gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box));
}
gdk_event_unref (event);
gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box));
return TRUE;
}

View File

@ -38,7 +38,6 @@
#include "gtkcontainerprivate.h"
#include "gtkmain.h"
#include "gtkintl.h"
#include "gtkbindings.h"
#include "gtkprivate.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
@ -490,7 +489,6 @@ gtk_dialog_class_init (GtkDialogClass *class)
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkWindowClass *window_class;
GtkBindingSet *binding_set;
gobject_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
@ -565,8 +563,7 @@ gtk_dialog_class_init (GtkDialogClass *class)
-1, 1, -1,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Escape, 0, "close", NULL);
/* Bind class to template
*/

View File

@ -119,12 +119,39 @@ gtk_emoji_chooser_child_focus (GtkWidget *widget,
return GTK_WIDGET_CLASS (gtk_emoji_chooser_child_parent_class)->focus (widget, direction);
}
static void show_variations (GtkEmojiChooser *chooser,
GtkWidget *child);
static void
gtk_emoji_chooser_child_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *paramters)
{
GtkWidget *chooser;
chooser = gtk_widget_get_ancestor (widget, GTK_TYPE_EMOJI_CHOOSER);
show_variations (GTK_EMOJI_CHOOSER (chooser), widget);
}
static void
gtk_emoji_chooser_child_class_init (GtkEmojiChooserChildClass *class)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
widget_class->size_allocate = gtk_emoji_chooser_child_size_allocate;
widget_class->focus = gtk_emoji_chooser_child_focus;
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_emoji_chooser_child_popup_menu);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
gtk_widget_class_set_css_name (widget_class, "emoji");
}
@ -421,16 +448,6 @@ pressed_cb (GtkGesture *gesture,
show_variations (chooser, child);
}
static gboolean
popup_menu (GtkWidget *widget,
gpointer data)
{
GtkEmojiChooser *chooser = data;
show_variations (chooser, widget);
return TRUE;
}
static void
add_emoji (GtkWidget *box,
gboolean prepend,
@ -488,9 +505,6 @@ add_emoji (GtkWidget *box,
if (modifier != 0)
g_object_set_data (G_OBJECT (child), "modifier", GUINT_TO_POINTER (modifier));
if (chooser)
g_signal_connect (child, "popup-menu", G_CALLBACK (popup_menu), chooser);
gtk_container_add (GTK_CONTAINER (child), label);
gtk_flow_box_insert (GTK_FLOW_BOX (box), child, prepend ? 0 : -1);
}

View File

@ -972,6 +972,25 @@ typedef enum
GTK_PAN_DIRECTION_DOWN
} GtkPanDirection;
/**
* GtkShortcutScope:
* @GTK_SHORTCUT_SCOPE_LOCAL: Shortcuts are handled inside
* the widget the controller belongs to.
* @GTK_SHORTCUT_SCOPE_MANAGED: Shortcuts are handled by
* the first ancestor that is a #GtkShortcutManager
* @GTK_SHORTCUT_SCOPE_GLOBAL: Shortcuts are handled by
* the root widget.
*
* Describes where #GtkShortcuts added to a
* #GtkShortcutController get handled.
*/
typedef enum
{
GTK_SHORTCUT_SCOPE_LOCAL,
GTK_SHORTCUT_SCOPE_MANAGED,
GTK_SHORTCUT_SCOPE_GLOBAL
} GtkShortcutScope;
/**
* GtkPopoverConstraint:
* @GTK_POPOVER_CONSTRAINT_NONE: Don't constrain the popover position

View File

@ -35,7 +35,6 @@
#include "gtkwidgetprivate.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkeventcontrollerkey.h"
#include "gtkbindings.h"
#include "gtkenums.h"
#include "gtkmain.h"
#include "gtktypebuiltins.h"
@ -368,9 +367,6 @@ gtk_event_controller_key_forward (GtkEventControllerKey *controller,
GTK_PHASE_BUBBLE))
return TRUE;
if (gtk_bindings_activate_event (G_OBJECT (widget), controller->current_event))
return TRUE;
return FALSE;
}

View File

@ -23,7 +23,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkbookmarksmanagerprivate.h"
#include "gtkbindings.h"
#include "gtkbutton.h"
#include "gtkcelllayout.h"
#include "gtkcellrendererpixbuf.h"
@ -86,6 +85,10 @@
#include "gtkwidgetprivate.h"
#include "gtkpopovermenuprivate.h"
#include "gtknative.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
#include <cairo-gobject.h>
@ -1191,125 +1194,22 @@ places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
}
static gboolean
should_trigger_location_entry (GtkFileChooserWidget *impl,
guint keyval,
GdkModifierType state,
const char **string)
trigger_location_entry (GtkWidget *widget,
GVariant *arguments,
gpointer unused)
{
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
GdkModifierType no_text_input_mask;
if (priv->operation_mode == OPERATION_MODE_SEARCH)
return FALSE;
no_text_input_mask =
gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
if (state & no_text_input_mask)
if (priv->action != GTK_FILE_CHOOSER_ACTION_OPEN &&
priv->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
return FALSE;
switch (keyval)
{
case GDK_KEY_slash:
case GDK_KEY_KP_Divide:
*string = "/";
return TRUE;
case GDK_KEY_period:
*string = ".";
return TRUE;
case GDK_KEY_asciitilde:
*string = "~";
return TRUE;
default:
return FALSE;
}
}
/* Handles key press events on the file list, so that we can trap Enter to
* activate the default button on our own. Also, checks to see if / has been
* pressed.
*/
static gboolean
treeview_key_press_cb (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
gpointer data)
{
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
const char *string;
if (should_trigger_location_entry (impl, keyval, state, &string) &&
(priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
{
location_popup_handler (impl, string);
return GDK_EVENT_STOP;
}
if ((keyval == GDK_KEY_Return ||
keyval == GDK_KEY_ISO_Enter ||
keyval == GDK_KEY_KP_Enter ||
keyval == GDK_KEY_space ||
keyval == GDK_KEY_KP_Space) &&
!(state & gtk_accelerator_get_default_mod_mask ()) &&
priv->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
{
gtk_widget_activate_default (GTK_WIDGET (impl));
return GDK_EVENT_STOP;
}
if (keyval == GDK_KEY_Escape &&
priv->operation_mode == OPERATION_MODE_SEARCH)
{
return gtk_event_controller_key_forward (controller,
GTK_WIDGET (gtk_search_entry_get_text_widget (GTK_SEARCH_ENTRY (priv->search_entry))));
}
return GDK_EVENT_PROPAGATE;
}
static gboolean
widget_key_press_cb (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
gpointer data)
{
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
gboolean handled = FALSE;
const char *string;
if (should_trigger_location_entry (impl, keyval, state, &string))
{
if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
{
location_popup_handler (impl, string);
handled = TRUE;
}
}
else
{
priv->starting_search = TRUE;
if (gtk_event_controller_key_forward (controller, priv->search_entry))
{
gtk_widget_grab_focus (priv->search_entry);
if (priv->operation_mode != OPERATION_MODE_SEARCH &&
priv->starting_search)
operation_mode_set (impl, OPERATION_MODE_SEARCH);
handled = TRUE;
}
}
return handled;
location_popup_handler (impl, g_variant_get_string (arguments, NULL));
return TRUE;
}
/* Callback used from gtk_tree_selection_selected_foreach(); adds a bookmark for
@ -2143,6 +2043,36 @@ file_list_show_popover (GtkFileChooserWidget *impl,
gtk_popover_popup (GTK_POPOVER (priv->browse_files_popover));
}
static gboolean
list_popup_menu_cb (GtkWidget *widget,
GVariant *args,
gpointer user_data)
{
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (user_data);
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
graphene_rect_t bounds;
if (gtk_widget_compute_bounds (priv->browse_files_tree_view,
priv->browse_files_tree_view,
&bounds))
{
file_list_show_popover (impl, 0.5 * bounds.size.width, 0.5 * bounds.size.height);
return TRUE;
}
return FALSE;
}
static void
files_list_clicked (GtkGesture *gesture,
int n_press,
double x,
double y,
GtkFileChooserWidget *impl)
{
list_popup_menu_cb (NULL, NULL, impl);
}
/* Callback used when a button is pressed on the file list. We trap button 3 to
* bring up a popup menu.
*/
@ -7458,18 +7388,20 @@ show_hidden_handler (GtkFileChooserWidget *impl)
}
static void
add_normal_and_shifted_binding (GtkBindingSet *binding_set,
add_normal_and_shifted_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType modifiers,
const gchar *signal_name)
{
gtk_binding_entry_add_signal (binding_set,
keyval, modifiers,
signal_name, 0);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modifiers,
signal_name,
NULL);
gtk_binding_entry_add_signal (binding_set,
keyval, modifiers | GDK_SHIFT_MASK,
signal_name, 0);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modifiers | GDK_SHIFT_MASK,
signal_name,
NULL);
}
static void
@ -7496,7 +7428,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
};
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkBindingSet *binding_set;
gint i;
gobject_class->finalize = gtk_file_chooser_widget_finalize;
@ -7778,71 +7709,84 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
NULL,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (class);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_l, GDK_CONTROL_MASK,
"location-toggle-popup",
NULL);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_l, GDK_CONTROL_MASK,
"location-toggle-popup",
0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_v, GDK_CONTROL_MASK,
"location-popup-on-paste",
NULL);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_v, GDK_CONTROL_MASK,
"location-popup-on-paste",
0);
add_normal_and_shifted_binding (binding_set,
add_normal_and_shifted_binding (widget_class,
GDK_KEY_Up, GDK_MOD1_MASK,
"up-folder");
add_normal_and_shifted_binding (binding_set,
add_normal_and_shifted_binding (widget_class,
GDK_KEY_KP_Up, GDK_MOD1_MASK,
"up-folder");
add_normal_and_shifted_binding (binding_set,
add_normal_and_shifted_binding (widget_class,
GDK_KEY_Down, GDK_MOD1_MASK,
"down-folder");
add_normal_and_shifted_binding (binding_set,
add_normal_and_shifted_binding (widget_class,
GDK_KEY_KP_Down, GDK_MOD1_MASK,
"down-folder");
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Home, GDK_MOD1_MASK,
"home-folder",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_Home, GDK_MOD1_MASK,
"home-folder",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_d, GDK_MOD1_MASK,
"desktop-folder",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_h, GDK_CONTROL_MASK,
"show-hidden",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_s, GDK_MOD1_MASK,
"search-shortcut",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_f, GDK_CONTROL_MASK,
"search-shortcut",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_r, GDK_MOD1_MASK,
"recent-shortcut",
0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_p, GDK_MOD1_MASK,
"places-shortcut",
0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Home, GDK_MOD1_MASK,
"home-folder",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Home, GDK_MOD1_MASK,
"home-folder",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_d, GDK_MOD1_MASK,
"desktop-folder",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_h, GDK_CONTROL_MASK,
"show-hidden",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_s, GDK_MOD1_MASK,
"search-shortcut",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_f, GDK_CONTROL_MASK,
"search-shortcut",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_r, GDK_MOD1_MASK,
"recent-shortcut",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_p, GDK_MOD1_MASK,
"places-shortcut",
NULL);
gtk_widget_class_add_binding (widget_class,
GDK_KEY_slash, 0,
trigger_location_entry,
"s", "/");
gtk_widget_class_add_binding (widget_class,
GDK_KEY_KP_Divide, 0,
trigger_location_entry,
"s", "/");
gtk_widget_class_add_binding (widget_class,
GDK_KEY_period, 0,
trigger_location_entry,
"s", ".");
gtk_widget_class_add_binding (widget_class,
GDK_KEY_asciitilde, 0,
trigger_location_entry,
"s", "~");
for (i = 0; i < 10; i++)
gtk_binding_entry_add_signal (binding_set,
quick_bookmark_keyvals[i], GDK_MOD1_MASK,
"quick-bookmark",
1, G_TYPE_INT, i);
for (i = 0; i < G_N_ELEMENTS (quick_bookmark_keyvals); i++)
gtk_widget_class_add_binding_signal (widget_class,
quick_bookmark_keyvals[i], GDK_MOD1_MASK,
"quick-bookmark",
"(i)", i);
g_object_class_install_property (gobject_class, PROP_SEARCH_MODE,
g_param_spec_boolean ("search-mode",
@ -7926,8 +7870,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, rename_file_end);
gtk_widget_class_bind_template_callback (widget_class, click_cb);
gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
gtk_widget_class_bind_template_callback (widget_class, treeview_key_press_cb);
gtk_widget_class_bind_template_callback (widget_class, widget_key_press_cb);
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
@ -7943,6 +7885,11 @@ post_process_ui (GtkFileChooserWidget *impl)
GList *cells;
GFile *file;
GtkDropTarget *target;
GtkGesture *gesture;
GtkEventController *controller;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkShortcut *shortcut;
/* Setup file list treeview */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
@ -8004,6 +7951,19 @@ post_process_ui (GtkFileChooserWidget *impl)
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (priv->search_entry), priv->search_entry);
gtk_widget_set_parent (priv->rename_file_popover, GTK_WIDGET (impl));
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
g_signal_connect (gesture, "pressed", G_CALLBACK (files_list_clicked), impl);
gtk_widget_add_controller (GTK_WIDGET (priv->browse_files_tree_view), GTK_EVENT_CONTROLLER (gesture));
controller = gtk_shortcut_controller_new ();
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
action = gtk_callback_action_new (list_popup_menu_cb, impl, NULL);
shortcut = gtk_shortcut_new (trigger, action);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (priv->browse_files_tree_view), controller);
}
void

View File

@ -78,7 +78,6 @@
#include "gtkflowbox.h"
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkcontainerprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssnodeprivate.h"
@ -2987,7 +2986,7 @@ gtk_flow_box_focus (GtkWidget *widget,
}
static void
gtk_flow_box_add_move_binding (GtkBindingSet *binding_set,
gtk_flow_box_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType modmask,
GtkMovementStep step,
@ -2998,7 +2997,7 @@ gtk_flow_box_add_move_binding (GtkBindingSet *binding_set,
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
display = gdk_display_get_default ();
if (display)
if (display != NULL)
{
extend_mod_mask = gdk_keymap_get_modifier_mask (gdk_display_get_keymap (display),
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
@ -3006,26 +3005,22 @@ gtk_flow_box_add_move_binding (GtkBindingSet *binding_set,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | modify_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask | modify_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | extend_mod_mask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | modify_mod_mask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | extend_mod_mask | modify_mod_mask,
"move-cursor",
"(ii)", step, count);
}
static void
@ -3387,7 +3382,6 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
GtkBindingSet *binding_set;
object_class->finalize = gtk_flow_box_finalize;
object_class->get_property = gtk_flow_box_get_property;
@ -3664,50 +3658,57 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
widget_class->activate_signal = signals[ACTIVATE_CURSOR_CHILD];
binding_set = gtk_binding_set_by_class (class);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Home, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_End, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Up, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Down, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Right, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_Left, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_flow_box_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
gtk_flow_box_add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-child", 0, NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-child", 0, NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-child",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-child",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"select-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
"select-all",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all",
NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_FLOW_BOX_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("flowbox"));

View File

@ -21,7 +21,6 @@
#include "gtkaccessible.h"
#include "gtkadjustmentprivate.h"
#include "gtkbindings.h"
#include "gtkcellareabox.h"
#include "gtkcellareacontext.h"
#include "gtkcelllayout.h"
@ -235,7 +234,7 @@ static gboolean gtk_icon_view_unselect_all_internal (GtkIco
static void gtk_icon_view_update_rubberband (GtkIconView *icon_view);
static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
static void gtk_icon_view_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
GtkMovementStep step,
@ -337,16 +336,9 @@ G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
static void
gtk_icon_view_class_init (GtkIconViewClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
binding_set = gtk_binding_set_by_class (klass);
gobject_class = (GObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
container_class = (GtkContainerClass *) klass;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
gobject_class->constructed = gtk_icon_view_constructed;
gobject_class->dispose = gtk_icon_view_dispose;
@ -813,70 +805,88 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
_gtk_marshal_BOOLEAN__ENUM_INTv);
/* Key bindings */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"select-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-item", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
"select-all",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-item",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-item",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate-cursor-item", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate-cursor-item", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, 0,
"activate-cursor-item",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, 0,
"activate-cursor-item",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Return, 0,
"activate-cursor-item",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_ISO_Enter, 0,
"activate-cursor-item",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Enter, 0,
"activate-cursor-item",
NULL);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_p, GDK_CONTROL_MASK,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_n, GDK_CONTROL_MASK,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
gtk_icon_view_add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
@ -3405,35 +3415,35 @@ gtk_icon_view_build_items (GtkIconView *icon_view)
}
static void
gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
gtk_icon_view_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
GtkMovementStep step,
gint count)
{
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
I_("move-cursor"), 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
I_("move-cursor"),
"(ii)", step, count);
gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_SHIFT_MASK,
"move-cursor",
"(ii)", step, count);
if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
return;
gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"move-cursor",
"(ii)", step, count);
gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", step, count);
}
static gboolean

View File

@ -39,7 +39,6 @@
#include "gtklabel.h"
#include "gtkbutton.h"
#include "gtkenums.h"
#include "gtkbindings.h"
#include "gtkdialog.h"
#include "gtkrevealer.h"
#include "gtkintl.h"
@ -378,14 +377,9 @@ gtk_info_bar_dispose (GObject *object)
static void
gtk_info_bar_class_init (GtkInfoBarClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
container_class = GTK_CONTAINER_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
object_class->get_property = gtk_info_bar_get_property;
object_class->set_property = gtk_info_bar_set_property;
@ -469,9 +463,10 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
NULL,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"close",
NULL);
gtk_widget_class_set_css_name (widget_class, I_("infobar"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);

View File

@ -1,580 +0,0 @@
/* gtkkeyhash.c: Keymap aware matching of key bindings
*
* GTK - The GIMP Toolkit
* Copyright (C) 2002, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkdebug.h"
#include "gtkkeyhash.h"
#include "gtkprivate.h"
typedef struct _GtkKeyHashEntry GtkKeyHashEntry;
struct _GtkKeyHashEntry
{
guint keyval;
GdkModifierType modifiers;
gpointer value;
/* Set as a side effect of generating key_hash->keycode_hash
*/
GdkKeymapKey *keys;
gint n_keys;
};
struct _GtkKeyHash
{
GdkKeymap *keymap;
GHashTable *keycode_hash;
GHashTable *reverse_hash;
GList *entries_list;
GDestroyNotify destroy_notify;
};
static void
key_hash_clear_keycode (gpointer key,
gpointer value,
gpointer data)
{
GSList *keys = value;
g_slist_free (keys);
}
static void
key_hash_insert_entry (GtkKeyHash *key_hash,
GtkKeyHashEntry *entry)
{
gint i;
g_free (entry->keys);
gdk_keymap_get_entries_for_keyval (key_hash->keymap,
entry->keyval,
&entry->keys, &entry->n_keys);
for (i = 0; i < entry->n_keys; i++)
{
GSList *old_keys = g_hash_table_lookup (key_hash->keycode_hash,
GUINT_TO_POINTER (entry->keys[i].keycode));
old_keys = g_slist_prepend (old_keys, entry);
g_hash_table_insert (key_hash->keycode_hash,
GUINT_TO_POINTER (entry->keys[i].keycode),
old_keys);
}
}
static GHashTable *
key_hash_get_keycode_hash (GtkKeyHash *key_hash)
{
if (!key_hash->keycode_hash)
{
GList *tmp_list;
key_hash->keycode_hash = g_hash_table_new (g_direct_hash, NULL);
/* Preserve the original insertion order
*/
for (tmp_list = g_list_last (key_hash->entries_list);
tmp_list;
tmp_list = tmp_list->prev)
key_hash_insert_entry (key_hash, tmp_list->data);
}
return key_hash->keycode_hash;
}
static void
key_hash_keys_changed (GdkKeymap *keymap,
GtkKeyHash *key_hash)
{
/* The keymap changed, so we have to regenerate the keycode hash
*/
if (key_hash->keycode_hash)
{
g_hash_table_foreach (key_hash->keycode_hash, key_hash_clear_keycode, NULL);
g_hash_table_destroy (key_hash->keycode_hash);
key_hash->keycode_hash = NULL;
}
}
/**
* _gtk_key_hash_new:
* @keymap: a #GdkKeymap
* @item_destroy_notify: function to be called when items are removed
* from the hash or %NULL.
*
* Create a new key hash object for doing binding resolution.
*
* Returns: the newly created object. Free with _gtk_key_hash_free().
**/
GtkKeyHash *
_gtk_key_hash_new (GdkKeymap *keymap,
GDestroyNotify item_destroy_notify)
{
GtkKeyHash *key_hash = g_new (GtkKeyHash, 1);
key_hash->keymap = keymap;
g_signal_connect (keymap, "keys-changed",
G_CALLBACK (key_hash_keys_changed), key_hash);
key_hash->entries_list = NULL;
key_hash->keycode_hash = NULL;
key_hash->reverse_hash = g_hash_table_new (g_direct_hash, NULL);
key_hash->destroy_notify = item_destroy_notify;
return key_hash;
}
static void
key_hash_free_entry (GtkKeyHash *key_hash,
GtkKeyHashEntry *entry)
{
if (key_hash->destroy_notify)
(*key_hash->destroy_notify) (entry->value);
g_free (entry->keys);
g_slice_free (GtkKeyHashEntry, entry);
}
static void
key_hash_free_entry_foreach (gpointer value,
gpointer data)
{
GtkKeyHashEntry *entry = value;
GtkKeyHash *key_hash = data;
key_hash_free_entry (key_hash, entry);
}
/**
* gtk_key_hash_free:
* @key_hash: a #GtkKeyHash
*
* Destroys a key hash created with gtk_key_hash_new()
**/
void
_gtk_key_hash_free (GtkKeyHash *key_hash)
{
g_signal_handlers_disconnect_by_func (key_hash->keymap,
key_hash_keys_changed,
key_hash);
if (key_hash->keycode_hash)
{
g_hash_table_foreach (key_hash->keycode_hash, key_hash_clear_keycode, NULL);
g_hash_table_destroy (key_hash->keycode_hash);
}
g_hash_table_destroy (key_hash->reverse_hash);
g_list_foreach (key_hash->entries_list, key_hash_free_entry_foreach, key_hash);
g_list_free (key_hash->entries_list);
g_free (key_hash);
}
/**
* _gtk_key_hash_add_entry:
* @key_hash: a #GtkKeyHash
* @keyval: key symbol for this binding
* @modifiers: modifiers for this binding
* @value: value to insert in the key hash
*
* Inserts a pair of key symbol and modifier mask into the key hash.
**/
void
_gtk_key_hash_add_entry (GtkKeyHash *key_hash,
guint keyval,
GdkModifierType modifiers,
gpointer value)
{
GtkKeyHashEntry *entry = g_slice_new (GtkKeyHashEntry);
entry->value = value;
entry->keyval = keyval;
entry->modifiers = modifiers;
entry->keys = NULL;
key_hash->entries_list = g_list_prepend (key_hash->entries_list, entry);
g_hash_table_insert (key_hash->reverse_hash, value, key_hash->entries_list);
if (key_hash->keycode_hash)
key_hash_insert_entry (key_hash, entry);
}
/**
* _gtk_key_hash_remove_entry:
* @key_hash: a #GtkKeyHash
* @value: value previously added with _gtk_key_hash_add_entry()
*
* Removes a value previously added to the key hash with
* _gtk_key_hash_add_entry().
**/
void
_gtk_key_hash_remove_entry (GtkKeyHash *key_hash,
gpointer value)
{
GList *entry_node = g_hash_table_lookup (key_hash->reverse_hash, value);
if (entry_node)
{
GtkKeyHashEntry *entry = entry_node->data;
if (key_hash->keycode_hash)
{
gint i;
for (i = 0; i < entry->n_keys; i++)
{
GSList *old_keys = g_hash_table_lookup (key_hash->keycode_hash,
GUINT_TO_POINTER (entry->keys[i].keycode));
GSList *new_keys = g_slist_remove (old_keys, entry);
if (new_keys != old_keys)
{
if (new_keys)
g_hash_table_insert (key_hash->keycode_hash,
GUINT_TO_POINTER (entry->keys[i].keycode),
new_keys);
else
g_hash_table_remove (key_hash->keycode_hash,
GUINT_TO_POINTER (entry->keys[i].keycode));
}
}
}
g_hash_table_remove (key_hash->reverse_hash, entry_node);
key_hash->entries_list = g_list_delete_link (key_hash->entries_list, entry_node);
key_hash_free_entry (key_hash, entry);
}
}
static gint
lookup_result_compare (gconstpointer a,
gconstpointer b)
{
const GtkKeyHashEntry *entry_a = a;
const GtkKeyHashEntry *entry_b = b;
guint modifiers;
gint n_bits_a = 0;
gint n_bits_b = 0;
modifiers = entry_a->modifiers;
while (modifiers)
{
if (modifiers & 1)
n_bits_a++;
modifiers >>= 1;
}
modifiers = entry_b->modifiers;
while (modifiers)
{
if (modifiers & 1)
n_bits_b++;
modifiers >>= 1;
}
return n_bits_a < n_bits_b ? -1 : (n_bits_a == n_bits_b ? 0 : 1);
}
/* Sort a list of results so that matches with less modifiers come
* before matches with more modifiers
*/
static GSList *
sort_lookup_results (GSList *slist)
{
return g_slist_sort (slist, lookup_result_compare);
}
static gint
lookup_result_compare_by_keyval (gconstpointer a,
gconstpointer b)
{
const GtkKeyHashEntry *entry_a = a;
const GtkKeyHashEntry *entry_b = b;
if (entry_a->keyval < entry_b->keyval)
return -1;
else if (entry_a->keyval > entry_b->keyval)
return 1;
else
return 0;
}
static GSList *
sort_lookup_results_by_keyval (GSList *slist)
{
return g_slist_sort (slist, lookup_result_compare_by_keyval);
}
/* Return true if keyval is defined in keyboard group
*/
static gboolean
keyval_in_group (GdkKeymap *keymap,
guint keyval,
gint group)
{
GtkKeyHashEntry entry;
gint i;
gdk_keymap_get_entries_for_keyval (keymap,
keyval,
&entry.keys, &entry.n_keys);
for (i = 0; i < entry.n_keys; i++)
{
if (entry.keys[i].group == group)
{
g_free (entry.keys);
return TRUE;
}
}
g_free (entry.keys);
return FALSE;
}
/**
* _gtk_key_hash_lookup:
* @key_hash: a #GtkKeyHash
* @hardware_keycode: hardware keycode field from a #GdkEvent
* @state: state field from a #GdkEvent
* @mask: mask of modifiers to consider when matching against the
* modifiers in entries.
* @group: group field from a #GdkEvent
*
* Looks up the best matching entry or entries in the hash table for
* a given event. The results are sorted so that entries with less
* modifiers come before entries with more modifiers.
*
* The matches returned by this function can be exact (i.e. keycode, level
* and group all match) or fuzzy (i.e. keycode and level match, but group
* does not). As long there are any exact matches, only exact matches
* are returned. If there are no exact matches, fuzzy matches will be
* returned, as long as they are not shadowing a possible exact match.
* This means that fuzzy matches wont be considered if their keyval is
* present in the current group.
*
* Returns: A newly-allocated #GSList of matching entries.
* Free with g_slist_free() when no longer needed.
*/
GSList *
_gtk_key_hash_lookup (GtkKeyHash *key_hash,
guint16 hardware_keycode,
GdkModifierType state,
GdkModifierType mask,
gint group)
{
GHashTable *keycode_hash = key_hash_get_keycode_hash (key_hash);
GSList *keys = g_hash_table_lookup (keycode_hash, GUINT_TO_POINTER ((guint)hardware_keycode));
GSList *results = NULL;
GSList *l;
gboolean have_exact = FALSE;
guint keyval;
gint effective_group;
gint level;
GdkModifierType modifiers;
GdkModifierType consumed_modifiers;
GdkModifierType shift_group_mask;
gboolean group_mod_is_accel_mod = FALSE;
const GdkModifierType xmods = GDK_MOD2_MASK|GDK_MOD3_MASK|GDK_MOD4_MASK|GDK_MOD5_MASK;
const GdkModifierType vmods = GDK_SUPER_MASK|GDK_HYPER_MASK|GDK_META_MASK;
/* We don't want Caps_Lock to affect keybinding lookups.
*/
state &= ~GDK_LOCK_MASK;
_gtk_translate_keyboard_accel_state (key_hash->keymap,
hardware_keycode, state, mask, group,
&keyval,
&effective_group, &level, &consumed_modifiers);
/* if the group-toggling modifier is part of the default accel mod
* mask, and it is active, disable it for matching
*/
shift_group_mask = gdk_keymap_get_modifier_mask (key_hash->keymap,
GDK_MODIFIER_INTENT_SHIFT_GROUP);
if (mask & shift_group_mask)
group_mod_is_accel_mod = TRUE;
gdk_keymap_map_virtual_modifiers (key_hash->keymap, &mask);
gdk_keymap_add_virtual_modifiers (key_hash->keymap, &state);
GTK_NOTE (KEYBINDINGS,
g_message ("Looking up keycode = %u, modifiers = 0x%04x,\n"
" keyval = %u, group = %d, level = %d, consumed_modifiers = 0x%04x",
hardware_keycode, state, keyval, effective_group, level, consumed_modifiers));
if (keys)
{
GSList *tmp_list = keys;
while (tmp_list)
{
GtkKeyHashEntry *entry = tmp_list->data;
/* If the virtual Super, Hyper or Meta modifiers are present,
* they will also be mapped to some of the Mod2 - Mod5 modifiers,
* so we compare them twice, ignoring either set.
* We accept combinations involving virtual modifiers only if they
* are mapped to separate modifiers; i.e. if Super and Hyper are
* both mapped to Mod4, then pressing a key that is mapped to Mod4
* will not match a Super+Hyper entry.
*/
modifiers = entry->modifiers;
if (gdk_keymap_map_virtual_modifiers (key_hash->keymap, &modifiers) &&
((modifiers & ~consumed_modifiers & mask & ~vmods) == (state & ~consumed_modifiers & mask & ~vmods) ||
(modifiers & ~consumed_modifiers & mask & ~xmods) == (state & ~consumed_modifiers & mask & ~xmods)))
{
gint i;
if (keyval == entry->keyval && /* Exact match */
/* but also match for group if it is an accel mod, because
* otherwise we can get multiple exact matches, some being
* bogus */
(!group_mod_is_accel_mod ||
(state & shift_group_mask) == (entry->modifiers & shift_group_mask)))
{
GTK_NOTE (KEYBINDINGS,
g_message (" found exact match, keyval = %u, modifiers = 0x%04x",
entry->keyval, entry->modifiers));
if (!have_exact)
{
g_slist_free (results);
results = NULL;
}
have_exact = TRUE;
results = g_slist_prepend (results, entry);
}
if (!have_exact)
{
for (i = 0; i < entry->n_keys; i++)
{
if (entry->keys[i].keycode == hardware_keycode &&
entry->keys[i].level == level &&
/* Only match for group if it's an accel mod */
(!group_mod_is_accel_mod ||
entry->keys[i].group == effective_group))
{
GTK_NOTE (KEYBINDINGS,
g_message (" found group = %d, level = %d",
entry->keys[i].group, entry->keys[i].level));
results = g_slist_prepend (results, entry);
break;
}
}
}
}
tmp_list = tmp_list->next;
}
}
if (!have_exact && results)
{
/* If there are fuzzy matches, check that the current group doesn't also
* define these keyvals; if yes, discard results because a widget up in
* the stack may have an exact match and we don't want to 'steal' it.
*/
guint oldkeyval = 0;
GtkKeyHashEntry *keyhashentry;
results = sort_lookup_results_by_keyval (results);
for (l = results; l; l = l->next)
{
keyhashentry = l->data;
if (l == results || oldkeyval != keyhashentry->keyval)
{
oldkeyval = keyhashentry->keyval;
if (keyval_in_group (key_hash->keymap, oldkeyval, group))
{
g_slist_free (results);
return NULL;
}
}
}
}
results = sort_lookup_results (results);
for (l = results; l; l = l->next)
l->data = ((GtkKeyHashEntry *)l->data)->value;
return results;
}
/**
* _gtk_key_hash_lookup_keyval:
* @key_hash: a #GtkKeyHash
* @event: a #GtkEvent
*
* Looks up the best matching entry or entries in the hash table for a
* given keyval/modifiers pair. Its better to use
* _gtk_key_hash_lookup() if you have the original #GdkEvent
* available. The results are sorted so that entries with less
* modifiers come before entries with more modifiers.
*
* Returns: A #GSList of all matching entries.
**/
GSList *
_gtk_key_hash_lookup_keyval (GtkKeyHash *key_hash,
guint keyval,
GdkModifierType modifiers)
{
GdkKeymapKey *keys;
gint n_keys;
GSList *results = NULL;
GSList *l;
if (!keyval) /* Key without symbol */
return NULL;
/* Find some random keycode for this keyval
*/
gdk_keymap_get_entries_for_keyval (key_hash->keymap, keyval,
&keys, &n_keys);
if (n_keys)
{
GHashTable *keycode_hash = key_hash_get_keycode_hash (key_hash);
GSList *entries = g_hash_table_lookup (keycode_hash, GUINT_TO_POINTER (keys[0].keycode));
while (entries)
{
GtkKeyHashEntry *entry = entries->data;
if (entry->keyval == keyval && entry->modifiers == modifiers)
results = g_slist_prepend (results, entry);
entries = entries->next;
}
}
g_free (keys);
results = sort_lookup_results (results);
for (l = results; l; l = l->next)
l->data = ((GtkKeyHashEntry *)l->data)->value;
return results;
}

View File

@ -1,49 +0,0 @@
/* gtkkeyhash.h: Keymap aware matching of key bindings
*
* GTK - The GIMP Toolkit
* Copyright (C) 2002, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_KEY_HASH_H__
#define __GTK_KEY_HASH_H__
#include <gdk/gdk.h>
G_BEGIN_DECLS
typedef struct _GtkKeyHash GtkKeyHash;
GtkKeyHash *_gtk_key_hash_new (GdkKeymap *keymap,
GDestroyNotify item_destroy_notify);
void _gtk_key_hash_add_entry (GtkKeyHash *key_hash,
guint keyval,
GdkModifierType modifiers,
gpointer value);
void _gtk_key_hash_remove_entry (GtkKeyHash *key_hash,
gpointer value);
GSList * _gtk_key_hash_lookup (GtkKeyHash *key_hash,
guint16 hardware_keycode,
GdkModifierType state,
GdkModifierType mask,
gint group);
GSList * _gtk_key_hash_lookup_keyval (GtkKeyHash *key_hash,
guint keyval,
GdkModifierType modifiers);
void _gtk_key_hash_free (GtkKeyHash *key_hash);
G_END_DECLS
#endif /* __GTK_KEY_HASH_H__ */

View File

@ -26,7 +26,6 @@
#include "gtklabelprivate.h"
#include "gtkbindings.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
#include "gtkcssnodeprivate.h"
@ -42,6 +41,9 @@
#include "gtknotebook.h"
#include "gtkpango.h"
#include "gtkprivate.h"
#include "gtkshortcut.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshow.h"
#include "gtksnapshot.h"
#include "gtkstylecontextprivate.h"
@ -276,7 +278,7 @@ struct _GtkLabelPrivate
{
GtkLabelSelectionInfo *select_info;
GtkWidget *mnemonic_widget;
GtkWindow *mnemonic_window;
GtkEventController *mnemonic_controller;
PangoAttrList *attrs;
PangoAttrList *markup_attrs;
@ -414,7 +416,6 @@ static GParamSpec *label_props[NUM_PROPERTIES] = { NULL, };
static guint signals[LAST_SIGNAL] = { 0 };
static GQuark quark_shortcuts_connected;
static GQuark quark_mnemonic_menu;
static GQuark quark_mnemonics_visible_connected;
static GQuark quark_gtk_signal;
static GQuark quark_link;
@ -479,7 +480,9 @@ static void gtk_label_set_markup_internal (GtkLabel *label,
static void gtk_label_recalculate (GtkLabel *label);
static void gtk_label_root (GtkWidget *widget);
static void gtk_label_unroot (GtkWidget *widget);
static gboolean gtk_label_popup_menu (GtkWidget *widget);
static void gtk_label_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_label_do_popup (GtkLabel *label,
double x,
double y);
@ -499,9 +502,7 @@ static void gtk_label_update_active_link (GtkWidget *widget,
static gboolean gtk_label_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
static void gtk_label_setup_mnemonic (GtkLabel *label,
GtkWidget *toplevel,
guint last_key);
static void gtk_label_setup_mnemonic (GtkLabel *label);
static void gtk_label_buildable_interface_init (GtkBuildableIface *iface);
static gboolean gtk_label_buildable_custom_tag_start (GtkBuildable *buildable,
@ -606,7 +607,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkLabel, gtk_label, GTK_TYPE_WIDGET,
gtk_label_buildable_interface_init))
static void
add_move_binding (GtkBindingSet *binding_set,
add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
GtkMovementStep step,
@ -614,18 +615,16 @@ add_move_binding (GtkBindingSet *binding_set,
{
g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(iib)", step, count, FALSE);
/* Selection-extending version */
gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | GDK_SHIFT_MASK,
"move-cursor",
"(iib)", step, count, TRUE);
}
static void
@ -633,7 +632,6 @@ gtk_label_class_init (GtkLabelClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkBindingSet *binding_set;
gobject_class->set_property = gtk_label_set_property;
gobject_class->get_property = gtk_label_get_property;
@ -649,7 +647,6 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->root = gtk_label_root;
widget_class->unroot = gtk_label_unroot;
widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
widget_class->popup_menu = gtk_label_popup_menu;
widget_class->grab_focus = gtk_label_grab_focus;
widget_class->focus = gtk_label_focus;
widget_class->get_request_mode = gtk_label_get_request_mode;
@ -1026,127 +1023,127 @@ gtk_label_class_init (GtkLabelClass *class)
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_label_popup_menu);
/*
* Key bindings
*/
binding_set = gtk_binding_set_by_class (class);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */
add_move_binding (binding_set, GDK_KEY_Right, 0,
add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_Left, 0,
add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_f, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_f, GDK_CONTROL_MASK,
GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_b, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_b, GDK_CONTROL_MASK,
GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
/* select all */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
(GtkShortcutFunc) gtk_label_select_all,
NULL);
gtk_widget_class_add_binding (widget_class,
GDK_KEY_slash, GDK_CONTROL_MASK,
(GtkShortcutFunc) gtk_label_select_all,
NULL);
/* unselect all */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor",
"(iib)", GTK_MOVEMENT_PARAGRAPH_ENDS, 0, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
"move-cursor", 3,
G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_backslash, GDK_CONTROL_MASK,
"move-cursor",
"(iib)", GTK_MOVEMENT_PARAGRAPH_ENDS, 0, FALSE);
add_move_binding (binding_set, GDK_KEY_f, GDK_MOD1_MASK,
add_move_binding (widget_class, GDK_KEY_f, GDK_MOD1_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_b, GDK_MOD1_MASK,
add_move_binding (widget_class, GDK_KEY_b, GDK_MOD1_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_Home, 0,
add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, 0,
add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, 0,
add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
/* copy */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate-current-link", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate-current-link", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate-current-link", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Return, 0,
"activate-current-link",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_ISO_Enter, 0,
"activate-current-link",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Enter, 0,
"activate-current-link",
NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LABEL_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("label"));
quark_shortcuts_connected = g_quark_from_static_string ("gtk-label-shortcuts-connected");
quark_mnemonic_menu = g_quark_from_static_string ("gtk-mnemonic-menu");
quark_mnemonics_visible_connected = g_quark_from_static_string ("gtk-label-mnemonics-visible-connected");
quark_gtk_signal = g_quark_from_static_string ("gtk-signal");
quark_link = g_quark_from_static_string ("link");
@ -1349,7 +1346,6 @@ gtk_label_init (GtkLabel *label)
priv->attrs = NULL;
priv->mnemonic_widget = NULL;
priv->mnemonic_window = NULL;
priv->mnemonics_visible = FALSE;
}
@ -1817,30 +1813,41 @@ gtk_label_mnemonic_activate (GtkWidget *widget,
}
static void
gtk_label_setup_mnemonic (GtkLabel *label,
GtkWidget *toplevel,
guint last_key)
gtk_label_setup_mnemonic (GtkLabel *label)
{
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
GtkWidget *widget = GTK_WIDGET (label);
GtkShortcut *shortcut;
if (last_key != GDK_KEY_VoidSymbol)
if (priv->mnemonic_keyval == GDK_KEY_VoidSymbol)
{
if (priv->mnemonic_window)
{
gtk_window_remove_mnemonic (priv->mnemonic_window,
last_key,
widget);
priv->mnemonic_window = NULL;
}
if (priv->mnemonic_controller)
{
gtk_widget_remove_controller (widget, priv->mnemonic_controller);
priv->mnemonic_controller = NULL;
}
return;
}
if (priv->mnemonic_keyval == GDK_KEY_VoidSymbol)
goto done;
if (priv->mnemonic_controller == NULL)
{
priv->mnemonic_controller = gtk_shortcut_controller_new ();
gtk_event_controller_set_propagation_phase (priv->mnemonic_controller, GTK_PHASE_CAPTURE);
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (priv->mnemonic_controller), GTK_SHORTCUT_SCOPE_MANAGED);
shortcut = gtk_shortcut_new (gtk_mnemonic_trigger_new (priv->mnemonic_keyval),
g_object_ref (gtk_mnemonic_action_get ()));
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (priv->mnemonic_controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (label), priv->mnemonic_controller);
g_object_unref (shortcut);
}
else
{
shortcut = g_list_model_get_item (G_LIST_MODEL (priv->mnemonic_controller), 0);
gtk_shortcut_set_trigger (shortcut, gtk_mnemonic_trigger_new (priv->mnemonic_keyval));
g_object_unref (shortcut);
}
connect_mnemonics_visible_notify (GTK_LABEL (widget));
done:;
}
static void
@ -1883,13 +1890,12 @@ static void
gtk_label_root (GtkWidget *widget)
{
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
GtkSettings *settings;
gboolean shortcuts_connected;
GTK_WIDGET_CLASS (gtk_label_parent_class)->root (widget);
gtk_label_setup_mnemonic (label, GTK_WIDGET (gtk_widget_get_root (widget)), priv->mnemonic_keyval);
gtk_label_setup_mnemonic (label);
/* The PangoContext is replaced when the display changes, so clear the layouts */
gtk_label_clear_layout (GTK_LABEL (widget));
@ -1916,9 +1922,8 @@ static void
gtk_label_unroot (GtkWidget *widget)
{
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
gtk_label_setup_mnemonic (label, NULL, priv->mnemonic_keyval);
gtk_label_setup_mnemonic (label);
GTK_WIDGET_CLASS (gtk_label_parent_class)->unroot (widget);
}
@ -1946,20 +1951,23 @@ _gtk_label_mnemonics_visible_apply_recursively (GtkWidget *widget,
child;
child = gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
continue;
_gtk_label_mnemonics_visible_apply_recursively (child, visible);
}
}
}
static void
label_mnemonics_visible_changed (GtkWindow *window,
label_mnemonics_visible_changed (GtkWidget *widget,
GParamSpec *pspec,
gpointer data)
{
gboolean visible;
g_object_get (window, "mnemonics-visible", &visible, NULL);
_gtk_label_mnemonics_visible_apply_recursively (GTK_WIDGET (window), visible);
g_object_get (widget, "mnemonics-visible", &visible, NULL);
_gtk_label_mnemonics_visible_apply_recursively (widget, visible);
}
static void
@ -2166,7 +2174,7 @@ gtk_label_recalculate (GtkLabel *label)
if (keyval != priv->mnemonic_keyval)
{
gtk_label_setup_mnemonic (label, GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (label))), keyval);
gtk_label_setup_mnemonic (label);
g_object_notify_by_pspec (G_OBJECT (label), label_props[PROP_MNEMONIC_KEYVAL]);
}
@ -4562,28 +4570,29 @@ static void
connect_mnemonics_visible_notify (GtkLabel *label)
{
GtkLabelPrivate *priv = gtk_label_get_instance_private (label);
GtkRoot *root;
GtkNative *native;
gboolean connected;
gboolean mnemonics_visible;
root = gtk_widget_get_root (GTK_WIDGET (label));
native = gtk_widget_get_native (GTK_WIDGET (label));
if (!GTK_IS_WINDOW (root))
if (!GTK_IS_WINDOW (native) && !GTK_IS_POPOVER (native))
return;
/* always set up this widgets initial value */
priv->mnemonics_visible =
gtk_window_get_mnemonics_visible (GTK_WINDOW (root));
g_object_get (native, "mnemonics-visible", &mnemonics_visible, NULL);
priv->mnemonics_visible = mnemonics_visible;
connected =
GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (root), quark_mnemonics_visible_connected));
GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (native), quark_mnemonics_visible_connected));
if (!connected)
{
g_signal_connect (root,
g_signal_connect (native,
"notify::mnemonics-visible",
G_CALLBACK (label_mnemonics_visible_changed),
label);
g_object_set_qdata (G_OBJECT (root),
g_object_set_qdata (G_OBJECT (native),
quark_mnemonics_visible_connected,
GINT_TO_POINTER (1));
}
@ -6066,13 +6075,14 @@ gtk_label_do_popup (GtkLabel *label,
gtk_popover_popup (GTK_POPOVER (priv->popup_menu));
}
static gboolean
gtk_label_popup_menu (GtkWidget *widget)
static void
gtk_label_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
GtkLabel *label = GTK_LABEL (widget);
gtk_label_do_popup (label, -1, -1);
return TRUE;
}
static void

View File

@ -123,7 +123,9 @@ static void gtk_link_button_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec);
static void gtk_link_button_clicked (GtkButton *button);
static gboolean gtk_link_button_popup_menu (GtkWidget *widget);
static void gtk_link_button_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static gboolean gtk_link_button_query_tooltip_cb (GtkWidget *widget,
gint x,
gint y,
@ -169,8 +171,6 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
gobject_class->get_property = gtk_link_button_get_property;
gobject_class->finalize = gtk_link_button_finalize;
widget_class->popup_menu = gtk_link_button_popup_menu;
button_class->clicked = gtk_link_button_clicked;
klass->activate_link = gtk_link_button_activate_link;
@ -230,6 +230,17 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
gtk_widget_class_install_action (widget_class, "clipboard.copy", NULL,
gtk_link_button_activate_clipboard_copy);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_link_button_popup_menu);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
}
static GMenuModel *
@ -503,11 +514,12 @@ gtk_link_button_clicked (GtkButton *button)
g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval);
}
static gboolean
gtk_link_button_popup_menu (GtkWidget *widget)
static void
gtk_link_button_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), -1, -1);
return TRUE;
}
/**

View File

@ -21,7 +21,6 @@
#include "gtkactionhelperprivate.h"
#include "gtkadjustmentprivate.h"
#include "gtkbindings.h"
#include "gtkbuildable.h"
#include "gtkcontainerprivate.h"
#include "gtkcssnodeprivate.h"
@ -232,7 +231,7 @@ static GSequenceIter * gtk_list_box_get_next_visible (GtkListBo
GSequenceIter *iter);
static void gtk_list_box_apply_filter (GtkListBox *box,
GtkListBoxRow *row);
static void gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
static void gtk_list_box_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType modmask,
GtkMovementStep step,
@ -436,9 +435,6 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LIST_BOX_ACCESSIBLE);
object_class->get_property = gtk_list_box_get_property;
object_class->set_property = gtk_list_box_set_property;
@ -611,43 +607,52 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
widget_class->activate_signal = signals[ACTIVATE_CURSOR_ROW];
binding_set = gtk_binding_set_by_class (klass);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Home, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_End, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Up, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Down, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
gtk_list_box_add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-row", 0, NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-row", 0, NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, GDK_CONTROL_MASK,
"toggle-cursor-row",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-row",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"select-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
"select-all",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"unselect-all",
NULL);
gtk_widget_class_set_css_name (widget_class, I_("list"));
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LIST_BOX_ACCESSIBLE);
}
static void
@ -1435,7 +1440,7 @@ gtk_list_box_set_accept_unpaired_release (GtkListBox *box,
}
static void
gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
gtk_list_box_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType modmask,
GtkMovementStep step,
@ -1454,26 +1459,22 @@ gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
}
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | modify_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask | modify_mod_mask,
"move-cursor", 2,
GTK_TYPE_MOVEMENT_STEP, step,
G_TYPE_INT, count,
NULL);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | extend_mod_mask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | modify_mod_mask,
"move-cursor",
"(ii)", step, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | extend_mod_mask | modify_mod_mask,
"move-cursor",
"(ii)", step, count);
}
static void

View File

@ -114,7 +114,6 @@
#include "gtkintl.h"
#include "gtkaccelmapprivate.h"
#include "gtkbox.h"
#include "gtkdebug.h"
#include "gtkdropprivate.h"
@ -663,8 +662,6 @@ do_post_parse_initialization (void)
gsk_ensure_resources ();
_gtk_ensure_resources ();
_gtk_accel_map_init ();
gtk_initialized = TRUE;
#ifdef G_OS_UNIX
@ -1649,14 +1646,11 @@ gtk_main_do_event (GdkEvent *event)
current_events = g_list_prepend (current_events, event);
if (is_pointing_event (event))
target_widget = handle_pointing_event (event);
{
target_widget = handle_pointing_event (event);
}
else if (is_key_event (event))
{
if (gdk_event_get_event_type (event) == GDK_KEY_PRESS &&
GTK_IS_WINDOW (target_widget) &&
gtk_window_activate_key (GTK_WINDOW (target_widget), event))
goto cleanup;
target_widget = handle_key_event (event);
}
else if (is_focus_event (event))

View File

@ -1,201 +0,0 @@
/* gtkmnemonichash.c: Sets of mnemonics with cycling
*
* GTK - The GIMP Toolkit
* Copyright (C) 2002, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkmnemonichash.h"
#include "gtknative.h"
struct _GtkMnemnonicHash
{
GHashTable *hash;
};
GtkMnemonicHash *
_gtk_mnemonic_hash_new (void)
{
GtkMnemonicHash *mnemonic_hash = g_new (GtkMnemonicHash, 1);
mnemonic_hash->hash = g_hash_table_new (g_direct_hash, NULL);
return mnemonic_hash;
}
static void
mnemonic_hash_free_foreach (gpointer key,
gpointer value,
gpointer user)
{
guint keyval = GPOINTER_TO_UINT (key);
GSList *targets = value;
gchar *name = gtk_accelerator_name (keyval, 0);
g_warning ("mnemonic \"%s\" wasn't removed for widget (%p)",
name, targets->data);
g_free (name);
g_slist_free (targets);
}
void
_gtk_mnemonic_hash_free (GtkMnemonicHash *mnemonic_hash)
{
g_hash_table_foreach (mnemonic_hash->hash,
mnemonic_hash_free_foreach,
NULL);
g_hash_table_destroy (mnemonic_hash->hash);
g_free (mnemonic_hash);
}
void
_gtk_mnemonic_hash_add (GtkMnemonicHash *mnemonic_hash,
guint keyval,
GtkWidget *target)
{
gpointer key = GUINT_TO_POINTER (keyval);
GSList *targets, *new_targets;
g_return_if_fail (GTK_IS_WIDGET (target));
targets = g_hash_table_lookup (mnemonic_hash->hash, key);
g_return_if_fail (g_slist_find (targets, target) == NULL);
new_targets = g_slist_append (targets, target);
if (new_targets != targets)
g_hash_table_insert (mnemonic_hash->hash, key, new_targets);
}
void
_gtk_mnemonic_hash_remove (GtkMnemonicHash *mnemonic_hash,
guint keyval,
GtkWidget *target)
{
gpointer key = GUINT_TO_POINTER (keyval);
GSList *targets, *new_targets;
g_return_if_fail (GTK_IS_WIDGET (target));
targets = g_hash_table_lookup (mnemonic_hash->hash, key);
g_return_if_fail (targets && g_slist_find (targets, target) != NULL);
new_targets = g_slist_remove (targets, target);
if (new_targets != targets)
{
if (new_targets == NULL)
g_hash_table_remove (mnemonic_hash->hash, key);
else
g_hash_table_insert (mnemonic_hash->hash, key, new_targets);
}
}
gboolean
_gtk_mnemonic_hash_activate (GtkMnemonicHash *mnemonic_hash,
guint keyval)
{
GSList *list, *targets;
GtkWidget *widget, *chosen_widget;
GdkSurface *surface;
gboolean overloaded;
targets = g_hash_table_lookup (mnemonic_hash->hash,
GUINT_TO_POINTER (keyval));
if (!targets)
return FALSE;
overloaded = FALSE;
chosen_widget = NULL;
for (list = targets; list; list = list->next)
{
widget = GTK_WIDGET (list->data);
surface = gtk_native_get_surface (gtk_widget_get_native (widget));
if (gtk_widget_is_sensitive (widget) &&
gtk_widget_get_mapped (widget) &&
surface && gdk_surface_is_viewable (surface))
{
if (chosen_widget)
{
overloaded = TRUE;
break;
}
else
chosen_widget = widget;
}
}
if (chosen_widget)
{
/* For round robin we put the activated entry on
* the end of the list after activation
*/
targets = g_slist_remove (targets, chosen_widget);
targets = g_slist_append (targets, chosen_widget);
g_hash_table_insert (mnemonic_hash->hash,
GUINT_TO_POINTER (keyval),
targets);
return gtk_widget_mnemonic_activate (chosen_widget, overloaded);
}
return FALSE;
}
GSList *
_gtk_mnemonic_hash_lookup (GtkMnemonicHash *mnemonic_hash,
guint keyval)
{
return g_hash_table_lookup (mnemonic_hash->hash, GUINT_TO_POINTER (keyval));
}
static void
mnemonic_hash_foreach_func (gpointer key,
gpointer value,
gpointer data)
{
struct {
GtkMnemonicHashForeach func;
gpointer func_data;
} *info = data;
guint keyval = GPOINTER_TO_UINT (key);
GSList *targets = value;
(*info->func) (keyval, targets, info->func_data);
}
void
_gtk_mnemonic_hash_foreach (GtkMnemonicHash *mnemonic_hash,
GtkMnemonicHashForeach func,
gpointer func_data)
{
struct {
GtkMnemonicHashForeach func;
gpointer func_data;
} info;
info.func = func;
info.func_data = func_data;
g_hash_table_foreach (mnemonic_hash->hash,
mnemonic_hash_foreach_func,
&info);
}

View File

@ -1,52 +0,0 @@
/* gtkmnemonichash.h: Sets of mnemonics with cycling
*
* GTK - The GIMP Toolkit
* Copyright (C) 2002, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_MNEMONIC_HASH_H__
#define __GTK_MNEMONIC_HASH_H__
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
typedef struct _GtkMnemnonicHash GtkMnemonicHash;
typedef void (*GtkMnemonicHashForeach) (guint keyval,
GSList *targets,
gpointer data);
GtkMnemonicHash *_gtk_mnemonic_hash_new (void);
void _gtk_mnemonic_hash_free (GtkMnemonicHash *mnemonic_hash);
void _gtk_mnemonic_hash_add (GtkMnemonicHash *mnemonic_hash,
guint keyval,
GtkWidget *target);
void _gtk_mnemonic_hash_remove (GtkMnemonicHash *mnemonic_hash,
guint keyval,
GtkWidget *target);
gboolean _gtk_mnemonic_hash_activate (GtkMnemonicHash *mnemonic_hash,
guint keyval);
GSList * _gtk_mnemonic_hash_lookup (GtkMnemonicHash *mnemonic_hash,
guint keyval);
void _gtk_mnemonic_hash_foreach (GtkMnemonicHash *mnemonic_hash,
GtkMnemonicHashForeach func,
gpointer func_data);
G_END_DECLS
#endif /* __GTK_MNEMONIC_HASH_H__ */

View File

@ -46,6 +46,9 @@
#include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollerfocus.h"
#include "gtknative.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcut.h"
/**
* SECTION:gtkmodelbutton
@ -174,6 +177,7 @@ struct _GtkModelButton
GtkSizeGroup *indicators;
char *accel;
guint open_timeout;
GtkEventController *controller;
guint active : 1;
guint centered : 1;
@ -727,7 +731,6 @@ update_accel (GtkModelButton *self,
{
guint key;
GdkModifierType mods;
GtkAccelLabelClass *accel_class;
char *str;
if (!self->accel_label)
@ -739,16 +742,48 @@ update_accel (GtkModelButton *self,
}
gtk_accelerator_parse (accel, &key, &mods);
accel_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
str = _gtk_accel_label_class_get_accelerator_label (accel_class, key, mods);
str = gtk_accelerator_get_label (key, mods);
gtk_label_set_label (GTK_LABEL (self->accel_label), str);
g_free (str);
g_type_class_unref (accel_class);
if (GTK_IS_POPOVER (gtk_widget_get_native (GTK_WIDGET (self))))
{
GtkShortcut *shortcut;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
if (self->controller)
{
while (g_list_model_get_n_items (G_LIST_MODEL (self->controller)) > 0)
{
shortcut = g_list_model_get_item (G_LIST_MODEL (self->controller), 0);
gtk_shortcut_controller_remove_shortcut (GTK_SHORTCUT_CONTROLLER (self->controller),
shortcut);
g_object_unref (shortcut);
}
}
else
{
self->controller = gtk_shortcut_controller_new ();
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (self->controller), GTK_SHORTCUT_SCOPE_MANAGED);
gtk_widget_add_controller (GTK_WIDGET (self), self->controller);
}
trigger = gtk_keyval_trigger_new (key, mods);
action = gtk_signal_action_new ("clicked");
shortcut = gtk_shortcut_new (trigger, action);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (self->controller), shortcut);
g_object_unref (shortcut);
}
}
else
{
g_clear_pointer (&self->accel_label, gtk_widget_unparent);
if (self->controller)
{
gtk_widget_remove_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (self->controller));
g_clear_object (&self->controller);
}
}
}
@ -984,48 +1019,6 @@ gtk_model_button_finalize (GObject *object)
G_OBJECT_CLASS (gtk_model_button_parent_class)->finalize (object);
}
static void
gtk_model_button_root (GtkWidget *widget)
{
GtkModelButton *self = GTK_MODEL_BUTTON (widget);
GtkRoot *root;
GtkApplication *app;
const char *action_name;
GVariant *action_target;
GTK_WIDGET_CLASS (gtk_model_button_parent_class)->root (widget);
if (!self->accel)
return;
root = gtk_widget_get_root (widget);
if (!GTK_IS_WINDOW (root))
return;
app = gtk_window_get_application (GTK_WINDOW (root));
if (!app)
return;
action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (widget));
action_target = gtk_actionable_get_action_target_value (GTK_ACTIONABLE (widget));
if (action_name)
{
char *detailed;
char **accels;
detailed = g_action_print_detailed_name (action_name, action_target);
accels = gtk_application_get_accels_for_action (app, detailed);
update_accel (self, accels[0]);
g_strfreev (accels);
g_free (detailed);
}
}
static gboolean
gtk_model_button_focus (GtkWidget *widget,
GtkDirectionType direction)
@ -1098,7 +1091,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
widget_class->state_flags_changed = gtk_model_button_state_flags_changed;
widget_class->direction_changed = gtk_model_button_direction_changed;
widget_class->focus = gtk_model_button_focus;
widget_class->root = gtk_model_button_root;
widget_class->get_accessible = gtk_model_button_get_accessible;
/**
@ -1233,6 +1225,8 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
NULL,
G_TYPE_NONE, 0);
widget_class->activate_signal = signals[SIGNAL_CLICKED];
gtk_widget_class_set_accessible_role (GTK_WIDGET_CLASS (class), ATK_ROLE_PUSH_BUTTON);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("modelbutton"));

View File

@ -57,6 +57,10 @@
#include "gtkpopover.h"
#include "gtksnapshot.h"
#include "gdktextureprivate.h"
#include "gtkshortcutcontroller.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
#include <glib/gprintf.h>
/**
@ -1458,6 +1462,7 @@ do_popup_menu_for_process_tree_view (GtkWidget *widget,
static gboolean
on_popup_menu_for_process_tree_view (GtkWidget *widget,
GVariant *args,
gpointer user_data)
{
GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
@ -1503,6 +1508,10 @@ create_show_processes_dialog (GtkMountOperation *op,
gchar *s;
gboolean use_header;
GtkGesture *gesture;
GtkEventController *controller;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkShortcut *shortcut;
priv = op->priv;
@ -1589,9 +1598,15 @@ create_show_processes_dialog (GtkMountOperation *op,
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
gtk_container_add (GTK_CONTAINER (vbox), scrolled_window);
g_signal_connect (tree_view, "popup-menu",
G_CALLBACK (on_popup_menu_for_process_tree_view),
op);
controller = gtk_shortcut_controller_new ();
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
action = gtk_callback_action_new (on_popup_menu_for_process_tree_view,
op,
NULL);
shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv");
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);

View File

@ -27,7 +27,6 @@
#include "gtknotebook.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkboxlayout.h"
#include "gtkbuildable.h"
@ -773,7 +772,9 @@ static void gtk_notebook_dispose (GObject *object);
/*** GtkWidget Methods ***/
static void gtk_notebook_destroy (GtkWidget *widget);
static void gtk_notebook_unmap (GtkWidget *widget);
static gboolean gtk_notebook_popup_menu (GtkWidget *widget);
static void gtk_notebook_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_notebook_motion (GtkEventController *controller,
double x,
double y,
@ -935,49 +936,53 @@ G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
gtk_notebook_buildable_init))
static void
add_tab_bindings (GtkBindingSet *binding_set,
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move_focus_out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move_focus_out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, modifiers,
"move_focus_out",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, modifiers,
"move_focus_out",
"(i)", direction);
}
static void
add_arrow_bindings (GtkBindingSet *binding_set,
add_arrow_bindings (GtkWidgetClass *widget_class,
guint keysym,
GtkDirectionType direction)
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
"move_focus_out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
"move_focus_out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class,
keysym, GDK_CONTROL_MASK,
"move_focus_out",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class,
keypad_keysym, GDK_CONTROL_MASK,
"move_focus_out",
"(i)", direction);
}
static void
add_reorder_bindings (GtkBindingSet *binding_set,
add_reorder_bindings (GtkWidgetClass *widget_class,
guint keysym,
GtkDirectionType direction,
gboolean move_to_last)
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keysym, GDK_MOD1_MASK,
"reorder_tab", 2,
GTK_TYPE_DIRECTION_TYPE, direction,
G_TYPE_BOOLEAN, move_to_last);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_MOD1_MASK,
"reorder_tab", 2,
GTK_TYPE_DIRECTION_TYPE, direction,
G_TYPE_BOOLEAN, move_to_last);
gtk_widget_class_add_binding_signal (widget_class,
keysym, GDK_MOD1_MASK,
"reorder_tab",
"(ib)", direction, move_to_last);
gtk_widget_class_add_binding_signal (widget_class,
keypad_keysym, GDK_MOD1_MASK,
"reorder_tab",
"(ib)", direction, move_to_last);
}
static gboolean
@ -1035,7 +1040,6 @@ gtk_notebook_class_init (GtkNotebookClass *class)
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
GtkBindingSet *binding_set;
gobject_class->set_property = gtk_notebook_set_property;
gobject_class->get_property = gtk_notebook_get_property;
@ -1044,7 +1048,6 @@ gtk_notebook_class_init (GtkNotebookClass *class)
widget_class->destroy = gtk_notebook_destroy;
widget_class->unmap = gtk_notebook_unmap;
widget_class->popup_menu = gtk_notebook_popup_menu;
widget_class->grab_notify = gtk_notebook_grab_notify;
widget_class->state_flags_changed = gtk_notebook_state_flags_changed;
widget_class->direction_changed = gtk_notebook_direction_changed;
@ -1308,67 +1311,77 @@ gtk_notebook_class_init (GtkNotebookClass *class)
G_TYPE_FROM_CLASS (gobject_class),
_gtk_marshal_OBJECT__OBJECTv);
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_space, 0,
"select-page", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_Space, 0,
"select-page", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_notebook_popup_menu);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Home, 0,
"focus-tab", 1,
GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_Home, 0,
"focus-tab", 1,
GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_FIRST);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_End, 0,
"focus-tab", 1,
GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_End, 0,
"focus-tab", 1,
GTK_TYPE_NOTEBOOK_TAB, GTK_NOTEBOOK_TAB_LAST);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, 0,
"select-page",
"(b)", FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, 0,
"select-page",
"(b)", FALSE);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Up, GDK_CONTROL_MASK,
"change-current-page", 1,
G_TYPE_INT, -1);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Down, GDK_CONTROL_MASK,
"change-current-page", 1,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Home, 0,
"focus-tab",
"(i)", GTK_NOTEBOOK_TAB_FIRST);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Home, 0,
"focus-tab",
"(i)", GTK_NOTEBOOK_TAB_FIRST);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_End, 0,
"focus-tab",
"(i)", GTK_NOTEBOOK_TAB_LAST);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_End, 0,
"focus-tab",
"(i)", GTK_NOTEBOOK_TAB_LAST);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
"change-current-page", 1,
G_TYPE_INT, -1);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
"change-current-page", 1,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, GDK_CONTROL_MASK,
"change-current-page",
"(i)", -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Down, GDK_CONTROL_MASK,
"change-current-page",
"(i)", 1);
add_reorder_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP, FALSE);
add_reorder_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN, FALSE);
add_reorder_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT, FALSE);
add_reorder_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT, FALSE);
add_reorder_bindings (binding_set, GDK_KEY_Home, GTK_DIR_LEFT, TRUE);
add_reorder_bindings (binding_set, GDK_KEY_Home, GTK_DIR_UP, TRUE);
add_reorder_bindings (binding_set, GDK_KEY_End, GTK_DIR_RIGHT, TRUE);
add_reorder_bindings (binding_set, GDK_KEY_End, GTK_DIR_DOWN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, GDK_CONTROL_MASK | GDK_MOD1_MASK,
"change-current-page",
"(i)", -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Down, GDK_CONTROL_MASK | GDK_MOD1_MASK,
"change-current-page",
"(i)", 1);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_arrow_bindings (widget_class, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (widget_class, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (widget_class, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (widget_class, GDK_KEY_Right, GTK_DIR_RIGHT);
add_reorder_bindings (widget_class, GDK_KEY_Up, GTK_DIR_UP, FALSE);
add_reorder_bindings (widget_class, GDK_KEY_Down, GTK_DIR_DOWN, FALSE);
add_reorder_bindings (widget_class, GDK_KEY_Left, GTK_DIR_LEFT, FALSE);
add_reorder_bindings (widget_class, GDK_KEY_Right, GTK_DIR_RIGHT, FALSE);
add_reorder_bindings (widget_class, GDK_KEY_Home, GTK_DIR_LEFT, TRUE);
add_reorder_bindings (widget_class, GDK_KEY_Home, GTK_DIR_UP, TRUE);
add_reorder_bindings (widget_class, GDK_KEY_End, GTK_DIR_RIGHT, TRUE);
add_reorder_bindings (widget_class, GDK_KEY_End, GTK_DIR_DOWN, TRUE);
add_tab_bindings (widget_class, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_NOTEBOOK_ACCESSIBLE);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
@ -2598,20 +2611,16 @@ gtk_notebook_gesture_pressed (GtkGestureClick *gesture,
}
}
static gboolean
gtk_notebook_popup_menu (GtkWidget *widget)
static void
gtk_notebook_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPrivate *priv = notebook->priv;
if (priv->menu)
{
gtk_popover_popup (GTK_POPOVER (priv->menu));
return TRUE;
}
return FALSE;
gtk_popover_popup (GTK_POPOVER (priv->menu));
}
static void

View File

@ -26,7 +26,6 @@
#include "gtkpaned.h"
#include "gtkbindings.h"
#include "gtkcontainerprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtkcssstylepropertyprivate.h"
@ -278,24 +277,29 @@ static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *paned_props[LAST_PROP] = { NULL, };
static void
add_tab_bindings (GtkBindingSet *binding_set,
GdkModifierType modifiers)
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"toggle-handle-focus", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"toggle-handle-focus", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, modifiers,
"toggle-handle-focus",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, modifiers,
"toggle-handle-focus",
NULL);
}
static void
add_move_binding (GtkBindingSet *binding_set,
add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mask,
GtkScrollType scroll)
{
gtk_binding_entry_add_signal (binding_set, keyval, mask,
"move-handle", 1,
GTK_TYPE_SCROLL_TYPE, scroll);
gtk_widget_class_add_binding_signal (widget_class,
keyval, mask,
"move-handle",
"(i)", scroll);
}
static void
@ -337,16 +341,9 @@ gtk_paned_handle_contains (GtkGizmo *handle,
static void
gtk_paned_class_init (GtkPanedClass *class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkPanedClass *paned_class;
GtkBindingSet *binding_set;
object_class = (GObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
container_class = (GtkContainerClass *) class;
paned_class = (GtkPanedClass *) class;
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
object_class->set_property = gtk_paned_set_property;
object_class->get_property = gtk_paned_get_property;
@ -364,12 +361,12 @@ gtk_paned_class_init (GtkPanedClass *class)
container_class->child_type = gtk_paned_child_type;
container_class->set_focus_child = gtk_paned_set_focus_child;
paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
paned_class->move_handle = gtk_paned_move_handle;
paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
paned_class->accept_position = gtk_paned_accept_position;
paned_class->cancel_position = gtk_paned_cancel_position;
class->cycle_child_focus = gtk_paned_cycle_child_focus;
class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
class->move_handle = gtk_paned_move_handle;
class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
class->accept_position = gtk_paned_accept_position;
class->cancel_position = gtk_paned_cancel_position;
paned_props[PROP_POSITION] =
@ -607,84 +604,87 @@ gtk_paned_class_init (GtkPanedClass *class)
_gtk_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
binding_set = gtk_binding_set_by_class (class);
/* F6 and friends */
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_F6, 0,
"cycle-child-focus", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_F6, GDK_SHIFT_MASK,
"cycle-child-focus", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_F6, 0,
"cycle-child-focus",
"(b)", FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_F6, GDK_SHIFT_MASK,
"cycle-child-focus",
"(b)", TRUE);
/* F8 and friends */
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_F8, 0,
"cycle-handle-focus", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_F8, 0,
"cycle-handle-focus",
"(b)", FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_F8, GDK_SHIFT_MASK,
"cycle-handle-focus",
"(b)", TRUE);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_F8, GDK_SHIFT_MASK,
"cycle-handle-focus", 1,
G_TYPE_BOOLEAN, TRUE);
add_tab_bindings (binding_set, 0);
add_tab_bindings (binding_set, GDK_CONTROL_MASK);
add_tab_bindings (binding_set, GDK_SHIFT_MASK);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
add_tab_bindings (widget_class, 0);
add_tab_bindings (widget_class, GDK_CONTROL_MASK);
add_tab_bindings (widget_class, GDK_SHIFT_MASK);
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
/* accept and cancel positions */
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Escape, 0,
"cancel-position", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"cancel-position",
NULL);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Return, 0,
"accept-position", 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_ISO_Enter, 0,
"accept-position", 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_Enter, 0,
"accept-position", 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_space, 0,
"accept-position", 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_KP_Space, 0,
"accept-position", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Return, 0,
"accept-position",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_ISO_Enter, 0,
"accept-position",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Enter, 0,
"accept-position",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, 0,
"accept-position",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, 0,
"accept-position",
NULL);
/* move handle */
add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
add_move_binding (widget_class, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
add_move_binding (widget_class, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
add_move_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
add_move_binding (widget_class, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (widget_class, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
add_move_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (widget_class, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
add_move_binding (widget_class, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_move_binding (widget_class, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
add_move_binding (widget_class, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
add_move_binding (widget_class, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
add_move_binding (widget_class, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
add_move_binding (widget_class, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (widget_class, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
add_move_binding (widget_class, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
add_move_binding (widget_class, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
add_move_binding (widget_class, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
add_move_binding (widget_class, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
add_move_binding (widget_class, GDK_KEY_Home, 0, GTK_SCROLL_START);
add_move_binding (widget_class, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
add_move_binding (widget_class, GDK_KEY_End, 0, GTK_SCROLL_END);
add_move_binding (widget_class, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PANED_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("paned"));

View File

@ -106,7 +106,15 @@ static void mount_volume (GtkPlacesView
static void on_eject_button_clicked (GtkWidget *widget,
GtkPlacesViewRow *row);
static gboolean on_row_popup_menu (GtkPlacesViewRow *row);
static gboolean on_row_popup_menu (GtkWidget *widget,
GVariant *args,
gpointer user_data);
static void click_cb (GtkGesture *gesture,
int n_press,
double x,
double y,
gpointer user_data);
static void populate_servers (GtkPlacesView *view);
@ -673,12 +681,28 @@ insert_row (GtkPlacesView *view,
gboolean is_network)
{
GtkPlacesViewPrivate *priv;
GtkEventController *controller;
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkShortcut *shortcut;
GtkGesture *gesture;
priv = gtk_places_view_get_instance_private (view);
g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network));
g_signal_connect (row, "popup-menu", G_CALLBACK (on_row_popup_menu), row);
controller = gtk_shortcut_controller_new ();
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
action = gtk_callback_action_new (on_row_popup_menu, row, NULL);
shortcut = gtk_shortcut_new (trigger, action);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (GTK_WIDGET (row), controller);
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
g_signal_connect (gesture, "pressed", G_CALLBACK (click_cb), row);
gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture));
g_signal_connect (gtk_places_view_row_get_eject_button (GTK_PLACES_VIEW_ROW (row)),
"clicked",
@ -1699,10 +1723,12 @@ get_menu_model (void)
return G_MENU_MODEL (menu);
}
static void
popup_menu (GtkPlacesViewRow *row,
GdkEventButton *event)
static gboolean
on_row_popup_menu (GtkWidget *widget,
GVariant *args,
gpointer user_data)
{
GtkPlacesViewRow *row = GTK_PLACES_VIEW_ROW (widget);
GtkPlacesViewPrivate *priv;
GtkWidget *view;
GMount *mount;
@ -1730,27 +1756,39 @@ popup_menu (GtkPlacesViewRow *row,
GMenuModel *model = get_menu_model ();
priv->popup_menu = gtk_popover_menu_new_from_model (model);
gtk_widget_set_parent (priv->popup_menu, GTK_WIDGET (view));
gtk_popover_set_position (GTK_POPOVER (priv->popup_menu), GTK_POS_BOTTOM);
gtk_popover_set_has_arrow (GTK_POPOVER (priv->popup_menu), FALSE);
gtk_widget_set_halign (priv->popup_menu, GTK_ALIGN_START);
gtk_widget_set_halign (priv->popup_menu, GTK_ALIGN_CENTER);
g_object_unref (model);
}
gtk_widget_set_halign (priv->popup_menu, GTK_ALIGN_CENTER);
if (priv->row_for_action)
g_object_set_data (G_OBJECT (priv->row_for_action), "menu", NULL);
g_object_ref (priv->popup_menu);
gtk_widget_unparent (priv->popup_menu);
gtk_widget_set_parent (priv->popup_menu, GTK_WIDGET (row));
g_object_unref (priv->popup_menu);
priv->row_for_action = row;
if (priv->row_for_action)
g_object_set_data (G_OBJECT (priv->row_for_action), "menu", priv->popup_menu);
gtk_popover_popup (GTK_POPOVER (priv->popup_menu));
return TRUE;
}
static gboolean
on_row_popup_menu (GtkPlacesViewRow *row)
static void
click_cb (GtkGesture *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
popup_menu (row, NULL);
return TRUE;
on_row_popup_menu (GTK_WIDGET (user_data), NULL, NULL);
}
static gboolean

View File

@ -35,6 +35,7 @@
#include "gtkspinner.h"
#include "gtkstack.h"
#include "gtktypebuiltins.h"
#include "gtknative.h"
#else
#include <gtk/gtk.h>
#endif
@ -193,18 +194,6 @@ measure_available_space (GtkPlacesViewRow *row)
}
}
static void
pressed_cb (GtkGesture *gesture,
int n_pressed,
double x,
double y,
GtkPlacesViewRow *row)
{
gboolean menu_activated;
g_signal_emit_by_name (row, "popup-menu", &menu_activated);
}
static void
gtk_places_view_row_finalize (GObject *object)
{
@ -320,6 +309,19 @@ gtk_places_view_row_set_property (GObject *object,
}
}
static void
gtk_places_view_row_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkWidget *menu = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "menu"));
GTK_WIDGET_CLASS (gtk_places_view_row_parent_class)->size_allocate (widget, width, height, baseline);
if (menu)
gtk_native_check_resize (GTK_NATIVE (menu));
}
static void
gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
{
@ -330,6 +332,8 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
object_class->get_property = gtk_places_view_row_get_property;
object_class->set_property = gtk_places_view_row_set_property;
widget_class->size_allocate = gtk_places_view_row_size_allocate;
properties[PROP_ICON] =
g_param_spec_object ("icon",
P_("Icon of the row"),
@ -391,8 +395,6 @@ gtk_places_view_row_class_init (GtkPlacesViewRowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, icon_image);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, name_label);
gtk_widget_class_bind_template_child (widget_class, GtkPlacesViewRow, path_label);
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
}
static void

View File

@ -102,12 +102,11 @@
#include "gtknative.h"
#include "gtkwidgetprivate.h"
#include "gtkeventcontrollerkey.h"
#include "gtkeventcontrollerfocus.h"
#include "gtkcssnodeprivate.h"
#include "gtkbindings.h"
#include "gtkbinlayout.h"
#include "gtkenums.h"
#include "gtktypebuiltins.h"
#include "gtkmnemonichash.h"
#include "gtkgizmoprivate.h"
#include "gtkintl.h"
#include "gtkprivate.h"
@ -121,6 +120,7 @@
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtksnapshot.h"
#include "gtkshortcutmanager.h"
#include "gtkrender.h"
#include "gtkstylecontextprivate.h"
@ -131,6 +131,8 @@
#include "wayland/gdkwayland.h"
#endif
#define MNEMONICS_DELAY 300 /* ms */
#define TAIL_GAP_WIDTH 24
#define TAIL_HEIGHT 12
@ -147,6 +149,10 @@ typedef struct {
GtkPositionType position;
gboolean autohide;
gboolean has_arrow;
gboolean mnemonics_visible;
gboolean disable_auto_mnemonics;
guint mnemonics_display_timeout_id;
GtkWidget *contents_widget;
GtkCssNode *arrow_node;
@ -171,15 +177,19 @@ enum {
PROP_AUTOHIDE,
PROP_DEFAULT_WIDGET,
PROP_HAS_ARROW,
PROP_MNEMONICS_VISIBLE,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL };
static void gtk_popover_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface);
static void gtk_popover_native_interface_init (GtkNativeInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkPopover, gtk_popover, GTK_TYPE_BIN,
G_ADD_PRIVATE (GtkPopover)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SHORTCUT_MANAGER,
gtk_popover_shortcut_manager_interface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_NATIVE,
gtk_popover_native_interface_init))
@ -575,18 +585,137 @@ close_menu (GtkPopover *popover)
}
}
static gboolean
gtk_popover_has_mnemonic_modifier_pressed (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
GList *seats, *s;
gboolean retval = FALSE;
seats = gdk_display_list_seats (gtk_widget_get_display (GTK_WIDGET (popover)));
for (s = seats; s; s = s->next)
{
GdkDevice *dev = gdk_seat_get_pointer (s->data);
GdkModifierType mask;
gdk_device_get_state (dev, priv->surface, NULL, &mask);
if ((mask & gtk_accelerator_get_default_mod_mask ()) == GDK_MOD1_MASK)
{
retval = TRUE;
break;
}
}
g_list_free (seats);
return retval;
}
static gboolean
schedule_mnemonics_visible_cb (gpointer data)
{
GtkPopover *popover = data;
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
priv->mnemonics_display_timeout_id = 0;
gtk_popover_set_mnemonics_visible (popover, TRUE);
return G_SOURCE_REMOVE;
}
static void
gtk_popover_schedule_mnemonics_visible (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
if (priv->mnemonics_display_timeout_id)
return;
priv->mnemonics_display_timeout_id =
g_timeout_add (MNEMONICS_DELAY, schedule_mnemonics_visible_cb, popover);
g_source_set_name_by_id (priv->mnemonics_display_timeout_id, "[gtk] popover_schedule_mnemonics_visible_cb");
}
static void
gtk_popover_focus_in (GtkWidget *widget)
{
GtkPopover *popover = GTK_POPOVER (widget);
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
if (priv->disable_auto_mnemonics)
return;
if (gtk_widget_get_visible (widget))
{
if (gtk_popover_has_mnemonic_modifier_pressed (popover))
gtk_popover_schedule_mnemonics_visible (popover);
}
}
static void
gtk_popover_focus_out (GtkWidget *widget)
{
GtkPopover *popover = GTK_POPOVER (widget);
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
if (priv->disable_auto_mnemonics)
return;
gtk_popover_set_mnemonics_visible (popover, FALSE);
}
static void
update_mnemonics_visible (GtkPopover *popover,
guint keyval,
GdkModifierType state,
gboolean visible)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
if (priv->disable_auto_mnemonics)
return;
if ((keyval == GDK_KEY_Alt_L || keyval == GDK_KEY_Alt_R) &&
((state & (gtk_accelerator_get_default_mod_mask ()) & ~(GDK_MOD1_MASK)) == 0))
{
if (visible)
gtk_popover_schedule_mnemonics_visible (popover);
else
gtk_popover_set_mnemonics_visible (popover, FALSE);
}
}
static gboolean
gtk_popover_key_pressed (GtkWidget *widget,
guint keyval,
guint keycode,
GdkModifierType state)
{
GtkPopover *popover = GTK_POPOVER (widget);
if (keyval == GDK_KEY_Escape)
{
close_menu (GTK_POPOVER (widget));
close_menu (popover);
return TRUE;
}
update_mnemonics_visible (popover, keyval, state, TRUE);
return FALSE;
}
static gboolean
gtk_popover_key_released (GtkWidget *widget,
guint keyval,
guint keycode,
GdkModifierType state)
{
GtkPopover *popover = GTK_POPOVER (widget);
update_mnemonics_visible (popover, keyval, state, FALSE);
return FALSE;
}
@ -705,8 +834,14 @@ gtk_popover_init (GtkPopover *popover)
controller = gtk_event_controller_key_new ();
g_signal_connect_swapped (controller, "key-pressed", G_CALLBACK (gtk_popover_key_pressed), popover);
g_signal_connect_swapped (controller, "key-released", G_CALLBACK (gtk_popover_key_released), popover);
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
controller = gtk_event_controller_focus_new ();
g_signal_connect_swapped (controller, "enter", G_CALLBACK (gtk_popover_focus_in), popover);
g_signal_connect_swapped (controller, "leave", G_CALLBACK (gtk_popover_focus_out), popover);
gtk_widget_add_controller (widget, controller);
priv->arrow_node = gtk_css_node_new ();
gtk_css_node_set_name (priv->arrow_node, g_quark_from_static_string ("arrow"));
gtk_css_node_set_parent (priv->arrow_node, gtk_widget_get_css_node (widget));
@ -793,6 +928,7 @@ gtk_popover_show (GtkWidget *widget)
static void
gtk_popover_hide (GtkWidget *widget)
{
gtk_popover_set_mnemonics_visible (GTK_POPOVER (widget), FALSE);
_gtk_widget_set_visible_flag (widget, FALSE);
gtk_widget_unmap (widget);
g_signal_emit (widget, signals[CLOSED], 0);
@ -895,6 +1031,12 @@ gtk_popover_finalize (GObject *object)
g_clear_pointer (&priv->layout, gdk_popup_layout_unref);
if (priv->mnemonics_display_timeout_id)
{
g_source_remove (priv->mnemonics_display_timeout_id);
priv->mnemonics_display_timeout_id = 0;
}
G_OBJECT_CLASS (gtk_popover_parent_class)->finalize (object);
}
@ -1380,6 +1522,10 @@ gtk_popover_set_property (GObject *object,
gtk_popover_set_has_arrow (popover, g_value_get_boolean (value));
break;
case PROP_MNEMONICS_VISIBLE:
gtk_popover_set_mnemonics_visible (popover, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1417,6 +1563,10 @@ gtk_popover_get_property (GObject *object,
g_value_set_boolean (value, priv->has_arrow);
break;
case PROP_MNEMONICS_VISIBLE:
g_value_set_boolean (value, priv->mnemonics_visible);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1445,37 +1595,41 @@ gtk_popover_remove (GtkContainer *container,
}
static void
add_tab_bindings (GtkBindingSet *binding_set,
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Tab, modifiers,
"move-focus",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Tab, modifiers,
"move-focus",
"(i)", direction);
}
static void
add_arrow_bindings (GtkBindingSet *binding_set,
add_arrow_bindings (GtkWidgetClass *widget_class,
guint keysym,
GtkDirectionType direction)
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keysym, 0,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class, keysym, 0,
"move-focus",
"(i)",
direction);
gtk_widget_class_add_binding_signal (widget_class, keysym, GDK_CONTROL_MASK,
"move-focus",
"(i)",
direction);
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, 0,
"move-focus",
"(i)",
direction);
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, GDK_CONTROL_MASK,
"move-focus",
"(i)",
direction);
}
static void
@ -1484,7 +1638,6 @@ gtk_popover_class_init (GtkPopoverClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
object_class->dispose = gtk_popover_dispose;
object_class->finalize = gtk_popover_finalize;
@ -1541,6 +1694,13 @@ gtk_popover_class_init (GtkPopoverClass *klass)
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_MNEMONICS_VISIBLE] =
g_param_spec_boolean ("mnemonics-visible",
P_("Mnemonics visible"),
P_("Whether mnemonics are currently visible in this popover"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
signals[CLOSED] =
@ -1563,24 +1723,22 @@ gtk_popover_class_init (GtkPopoverClass *klass)
G_TYPE_NONE,
0);
binding_set = gtk_binding_set_by_class (klass);
add_arrow_bindings (widget_class, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (widget_class, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (widget_class, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (widget_class, GDK_KEY_Right, GTK_DIR_RIGHT);
add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
add_tab_bindings (widget_class, 0, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate-default", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
"activate-default", NULL);
gtk_widget_class_set_css_name (widget_class, "popover");
}
@ -1621,6 +1779,11 @@ gtk_popover_set_default_widget (GtkPopover *popover,
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_DEFAULT_WIDGET]);
}
static void
gtk_popover_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface)
{
}
static void
gtk_popover_native_interface_init (GtkNativeInterface *iface)
{
@ -1890,3 +2053,59 @@ gtk_popover_get_has_arrow (GtkPopover *popover)
return priv->has_arrow;
}
/**
* gtk_popover_set_mnemonics_visible:
* @popover: a #GtkPopover
* @mnemonics_visible: the new value
*
* Sets the #GtkPopover:mnemonics-visible property.
*/
void
gtk_popover_set_mnemonics_visible (GtkPopover *popover,
gboolean mnemonics_visible)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
g_return_if_fail (GTK_IS_POPOVER (popover));
if (priv->mnemonics_visible == mnemonics_visible)
return;
priv->mnemonics_visible = mnemonics_visible;
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_MNEMONICS_VISIBLE]);
gtk_widget_queue_resize (GTK_WIDGET (popover));
if (priv->mnemonics_display_timeout_id)
{
g_source_remove (priv->mnemonics_display_timeout_id);
priv->mnemonics_display_timeout_id = 0;
}
}
/**
* gtk_popover_get_mnemonics_visible:
* @popover: a #GtkPopover
*
* Gets the value of the #GtkPopover:mnemonics-visible property.
*
* Returns: %TRUE if mnemonics are supposed to be visible in this popover
*/
gboolean
gtk_popover_get_mnemonics_visible (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
g_return_val_if_fail (GTK_IS_POPOVER (popover), FALSE);
return priv->mnemonics_visible;
}
void
gtk_popover_disable_auto_mnemonics (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
priv->disable_auto_mnemonics = TRUE;
}

View File

@ -86,6 +86,12 @@ void gtk_popover_set_has_arrow (GtkPopover *popover,
GDK_AVAILABLE_IN_ALL
gboolean gtk_popover_get_has_arrow (GtkPopover *popover);
GDK_AVAILABLE_IN_ALL
void gtk_popover_set_mnemonics_visible (GtkPopover *popover,
gboolean mnemonics_visible);
GDK_AVAILABLE_IN_ALL
gboolean gtk_popover_get_mnemonics_visible (GtkPopover *popover);
GDK_AVAILABLE_IN_ALL
void gtk_popover_popup (GtkPopover *popover);
GDK_AVAILABLE_IN_ALL

View File

@ -32,9 +32,10 @@
#include "gtkeventcontrollermotion.h"
#include "gtkmain.h"
#include "gtktypebuiltins.h"
#include "gtkbindings.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkpopovermenubar.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcutcontroller.h"
/**
@ -200,6 +201,7 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
{
GtkWidget *stack;
GtkEventController *controller;
GList *controllers, *l;
stack = gtk_stack_new ();
gtk_stack_set_vhomogeneous (GTK_STACK (stack), FALSE);
@ -218,6 +220,18 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
controller = gtk_event_controller_motion_new ();
g_signal_connect (controller, "leave", G_CALLBACK (leave_cb), popover);
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
controllers = gtk_widget_list_controllers (GTK_WIDGET (popover), GTK_PHASE_CAPTURE);
for (l = controllers; l; l = l->next)
{
controller = l->data;
if (GTK_IS_SHORTCUT_CONTROLLER (controller) &&
strcmp (gtk_event_controller_get_name (controller), "gtk-shortcut-manager-capture") == 0)
gtk_shortcut_controller_set_mnemonics_modifiers (GTK_SHORTCUT_CONTROLLER (controller), 0);
}
g_list_free (controllers);
gtk_popover_disable_auto_mnemonics (GTK_POPOVER (popover));
}
static void
@ -362,37 +376,37 @@ gtk_popover_menu_focus (GtkWidget *widget,
static void
add_tab_bindings (GtkBindingSet *binding_set,
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Tab, modifiers,
"move-focus",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Tab, modifiers,
"move-focus",
"(i)", direction);
}
static void
add_arrow_bindings (GtkBindingSet *binding_set,
add_arrow_bindings (GtkWidgetClass *widget_class,
guint keysym,
GtkDirectionType direction)
{
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keysym, 0,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class, keysym, 0,
"move-focus",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class, keysym, GDK_CONTROL_MASK,
"move-focus",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, 0,
"move-focus",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, GDK_CONTROL_MASK,
"move-focus",
"(i)", direction);
}
static void
@ -403,12 +417,20 @@ gtk_popover_menu_show (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->show (widget);
}
static void
gtk_popover_menu_move_focus (GtkWidget *widget,
GtkDirectionType direction)
{
gtk_popover_set_mnemonics_visible (GTK_POPOVER (widget), TRUE);
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->move_focus (widget, direction);
}
static void
gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkBindingSet *binding_set;
object_class->dispose = gtk_popover_menu_dispose;
object_class->set_property = gtk_popover_menu_set_property;
@ -418,6 +440,7 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
widget_class->unmap = gtk_popover_menu_unmap;
widget_class->focus = gtk_popover_menu_focus;
widget_class->show = gtk_popover_menu_show;
widget_class->move_focus = gtk_popover_menu_move_focus;
g_object_class_install_property (object_class,
PROP_VISIBLE_SUBMENU,
@ -435,28 +458,26 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
G_TYPE_MENU_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
binding_set = gtk_binding_set_by_class (klass);
add_arrow_bindings (widget_class, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (widget_class, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (widget_class, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (widget_class, GDK_KEY_Right, GTK_DIR_RIGHT);
add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
add_tab_bindings (widget_class, 0, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
"activate-default", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
"activate-default", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0,
"activate-default", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0,
"activate-default", NULL);
}
/**

View File

@ -24,6 +24,8 @@ G_BEGIN_DECLS
GtkWidget *gtk_popover_get_contents_widget (GtkPopover *popover);
void gtk_popover_disable_auto_mnemonics (GtkPopover *popover);
G_END_DECLS
#endif /* __GTK_POPOVER_PRIVATE_H__ */

View File

@ -1883,16 +1883,6 @@ gtk_range_click_gesture_pressed (GtkGestureClick *gesture,
mouse_location == priv->highlight_widget)
mouse_location = priv->trough_widget;
if (mouse_location == priv->slider_widget &&
gdk_event_triggers_context_menu (event))
{
gboolean handled;
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
g_signal_emit_by_name (widget, "popup-menu", &handled);
return;
}
if (mouse_location == priv->slider_widget)
{
/* Shift-click in the slider = fine adjustment */

View File

@ -27,6 +27,8 @@
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkshortcutmanager.h"
/**
* SECTION:gtkroot
* @Title: GtkRoot

View File

@ -28,7 +28,6 @@
#include "gtkscale.h"
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
#include "gtkgizmoprivate.h"
@ -623,10 +622,11 @@ gtk_scale_size_allocate (GtkWidget *widget,
}
}
#define add_slider_binding(binding_set, keyval, mask, scroll) \
gtk_binding_entry_add_signal (binding_set, keyval, mask, \
I_("move-slider"), 1, \
GTK_TYPE_SCROLL_TYPE, scroll)
#define add_slider_binding(binding_set, keyval, mask, scroll) \
gtk_widget_class_add_binding_signal (widget_class, \
keyval, mask, \
I_("move-slider"), \
"(i)", scroll)
static void
gtk_scale_value_changed (GtkRange *range)
@ -650,7 +650,6 @@ gtk_scale_class_init (GtkScaleClass *class)
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkRangeClass *range_class;
GtkBindingSet *binding_set;
gobject_class = G_OBJECT_CLASS (class);
range_class = (GtkRangeClass*) class;
@ -706,8 +705,6 @@ gtk_scale_class_init (GtkScaleClass *class)
* blind users etc. don't care about scale orientation.
*/
binding_set = gtk_binding_set_by_class (class);
add_slider_binding (binding_set, GDK_KEY_Left, 0,
GTK_SCROLL_STEP_LEFT);

View File

@ -37,7 +37,6 @@
#include "gtkscalebutton.h"
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkbuttonprivate.h"
#include "gtkimage.h"
@ -171,7 +170,6 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
GtkBindingSet *binding_set;
gobject_class->constructed = gtk_scale_button_constructed;
gobject_class->finalize = gtk_scale_button_finalize;
@ -298,20 +296,30 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
G_TYPE_NONE, 0);
/* Key bindings */
binding_set = gtk_binding_set_by_class (widget_class);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"popup", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
"popdown", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_space, 0,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Space, 0,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Return, 0,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_ISO_Enter, 0,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Enter, 0,
"popup",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"popdown",
NULL);
/* Bind class to template
*/

View File

@ -209,16 +209,6 @@ gtk_scrollbar_class_init (GtkScrollbarClass *class)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
}
static gboolean
emit_popup_menu (GtkWidget *self)
{
gboolean handled;
g_signal_emit_by_name (self, "popup-menu", &handled);
return handled;
}
static void
gtk_scrollbar_init (GtkScrollbar *self)
{
@ -227,7 +217,6 @@ gtk_scrollbar_init (GtkScrollbar *self)
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
priv->range = g_object_new (GTK_TYPE_RANGE, NULL);
g_signal_connect_swapped (priv->range, "popup-menu", G_CALLBACK (emit_popup_menu), self);
gtk_widget_set_hexpand (priv->range, TRUE);
gtk_widget_set_vexpand (priv->range, TRUE);
gtk_widget_set_parent (priv->range, GTK_WIDGET (self));

View File

@ -28,7 +28,6 @@
#include "gtkadjustment.h"
#include "gtkadjustmentprivate.h"
#include "gtkbindings.h"
#include "gtkeventcontrollermotion.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkgesturedrag.h"
@ -413,7 +412,7 @@ static GParamSpec *properties[NUM_PROPERTIES];
G_DEFINE_TYPE_WITH_PRIVATE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
static void
add_scroll_binding (GtkBindingSet *binding_set,
add_scroll_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mask,
GtkScrollType scroll,
@ -421,27 +420,29 @@ add_scroll_binding (GtkBindingSet *binding_set,
{
guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keyval, mask,
"scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
"scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
gtk_widget_class_add_binding_signal (widget_class,
keyval, mask,
"scroll-child",
"(ib)", scroll, horizontal);
gtk_widget_class_add_binding_signal (widget_class,
keypad_keyval, mask,
"scroll-child",
"(ib)", scroll, horizontal);
}
static void
add_tab_bindings (GtkBindingSet *binding_set,
add_tab_bindings (GtkWidgetClass *widget_class,
GdkModifierType modifiers,
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, modifiers,
"move-focus-out",
"(i)", direction);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, modifiers,
"move-focus-out",
"(i)", direction);
}
static void
@ -517,7 +518,6 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
GtkBindingSet *binding_set;
gobject_class->set_property = gtk_scrolled_window_set_property;
gobject_class->get_property = gtk_scrolled_window_get_property;
@ -789,25 +789,23 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
NULL, NULL, NULL,
G_TYPE_NONE, 1, GTK_TYPE_POSITION_TYPE);
binding_set = gtk_binding_set_by_class (class);
add_scroll_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
add_scroll_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
add_scroll_binding (widget_class, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
add_scroll_binding (widget_class, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
add_scroll_binding (widget_class, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
add_scroll_binding (widget_class, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
add_scroll_binding (widget_class, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
add_scroll_binding (widget_class, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
add_scroll_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
add_scroll_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
add_scroll_binding (widget_class, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
add_scroll_binding (widget_class, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("scrolledwindow"));

View File

@ -30,7 +30,6 @@
#include "gtksearchentryprivate.h"
#include "gtkaccessible.h"
#include "gtkbindings.h"
#include "gtkeditable.h"
#include "gtkboxlayout.h"
#include "gtkgestureclick.h"
@ -267,7 +266,6 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkBindingSet *binding_set;
object_class->finalize = gtk_search_entry_finalize;
object_class->get_property = gtk_search_entry_get_property;
@ -401,14 +399,18 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
NULL,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
"next-match", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"previous-match", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
"stop-search", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_g, GDK_CONTROL_MASK,
"next-match",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_g, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"previous-match",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"stop-search",
NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);

386
gtk/gtkshortcut.c Normal file
View File

@ -0,0 +1,386 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
#include "gtkshortcut.h"
#include "gtkintl.h"
#include "gtkshortcutaction.h"
#include "gtkshortcuttrigger.h"
#include "gtkwidget.h"
/**
* SECTION:gtkshortcut
* @title: GtkShortcut
* @short_description: An object describing a keyboard shortcut
* @see_also: #GtkShortcutController, #GtkShortcutAction,
* #GtkShortcutTrigger
*
* GtkShortcut is the low level object used for managing keyboard
* shortcuts.
*
* It contains a description of how to trigger the shortcut via a
* #GtkShortcutTrigger and a way to activate the shortcut on a widget
* via #GtkShortcutAction.
*
* The actual work is usually done via #GtkShortcutController, which
* decides if and when to activate a shortcut. Using that controller
* directly however is rarely necessary as various higher level
* convenience APIs exist on #GtkWidgets that make it easier to use
* shortcuts in GTK.
*
* #GtkShortcut does provide functionality to make it easy for users
* to work with shortcuts, either by providing informational strings
* for display purposes or by allowing shortcuts to be configured.
*/
struct _GtkShortcut
{
GObject parent_instance;
GtkShortcutAction *action;
GtkShortcutTrigger *trigger;
GVariant *args;
};
enum
{
PROP_0,
PROP_ACTION,
PROP_ARGUMENTS,
PROP_TRIGGER,
N_PROPS
};
G_DEFINE_TYPE (GtkShortcut, gtk_shortcut, G_TYPE_OBJECT)
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_shortcut_dispose (GObject *object)
{
GtkShortcut *self = GTK_SHORTCUT (object);
g_clear_object (&self->action);
g_clear_object (&self->trigger);
g_clear_pointer (&self->args, g_variant_unref);
G_OBJECT_CLASS (gtk_shortcut_parent_class)->dispose (object);
}
static void
gtk_shortcut_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkShortcut *self = GTK_SHORTCUT (object);
switch (property_id)
{
case PROP_ACTION:
g_value_set_boxed (value, self->action);
break;
case PROP_ARGUMENTS:
g_value_set_variant (value, self->args);
break;
case PROP_TRIGGER:
g_value_set_object (value, self->trigger);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_shortcut_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkShortcut *self = GTK_SHORTCUT (object);
switch (property_id)
{
case PROP_ACTION:
gtk_shortcut_set_action (self, g_value_dup_object (value));
break;
case PROP_ARGUMENTS:
gtk_shortcut_set_arguments (self, g_value_get_variant (value));
break;
case PROP_TRIGGER:
gtk_shortcut_set_trigger (self, g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_shortcut_class_init (GtkShortcutClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = gtk_shortcut_dispose;
gobject_class->get_property = gtk_shortcut_get_property;
gobject_class->set_property = gtk_shortcut_set_property;
/**
* GtkShortcut:action:
*
* The action that gets activated by this shortcut.
*/
properties[PROP_ACTION] =
g_param_spec_object ("action",
P_("Action"),
P_("The action activated by this shortcut"),
GTK_TYPE_SHORTCUT_ACTION,
G_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
/**
* GtkShortcut:arguments:
*
* Arguments passed to activation.
*/
properties[PROP_ARGUMENTS] =
g_param_spec_variant ("arguments",
P_("Arguments"),
P_("Arguments passed to activation"),
G_VARIANT_TYPE_ANY,
NULL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcut:trigger:
*
* The trigger that triggers this shortcut.
*/
properties[PROP_TRIGGER] =
g_param_spec_object ("trigger",
P_("Trigger"),
P_("The trigger for this shortcut"),
GTK_TYPE_SHORTCUT_TRIGGER,
G_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
gtk_shortcut_init (GtkShortcut *self)
{
self->action = g_object_ref (gtk_nothing_action_get ());
self->trigger = g_object_ref (gtk_never_trigger_get ());
}
/**
* gtk_shortcut_new:
* @trigger: (transfer full) (nullable): The trigger that will trigger the shortcut
* @action: (transfer full) (nullable): The action that will be activated upon
* triggering
*
* Creates a new #GtkShortcut that is triggered by @trigger and then activates
* @action.
*
* Returns: a new #GtkShortcut
**/
GtkShortcut *
gtk_shortcut_new (GtkShortcutTrigger *trigger,
GtkShortcutAction *action)
{
GtkShortcut *shortcut;
shortcut = g_object_new (GTK_TYPE_SHORTCUT,
"action", action,
"trigger", trigger,
NULL);
if (trigger)
g_object_unref (trigger);
if (action)
g_object_unref (action);
return shortcut;
}
/**
* gtk_shortcut_new_with_arguments: (skip)
* @trigger: (transfer full) (nullable): The trigger that will trigger the shortcut
* @action: (transfer full) (nullable): The action that will be activated upon
* triggering
* @format_string: (allow-none): GVariant format string for arguments or %NULL for
* no arguments
* @...: arguments, as given by format string.
*
* Creates a new #GtkShortcut that is triggered by @trigger and then activates
* @action with arguments given by @format_string.
*
* Returns: a new #GtkShortcut
**/
GtkShortcut *
gtk_shortcut_new_with_arguments (GtkShortcutTrigger *trigger,
GtkShortcutAction *action,
const gchar *format_string,
...)
{
GtkShortcut *shortcut;
GVariant *args;
if (format_string)
{
va_list valist;
va_start (valist, format_string);
args = g_variant_new_va (format_string, NULL, &valist);
va_end (valist);
}
else
{
args = NULL;
}
shortcut = g_object_new (GTK_TYPE_SHORTCUT,
"action", action,
"arguments", args,
"trigger", trigger,
NULL);
if (trigger)
g_object_unref (trigger);
if (action)
g_object_unref (action);
return shortcut;
}
/**
* gtk_shortcut_get_action:
* @self: a #GtkShortcut
*
* Gets the action that is activated by this shortcut.
*
* Returns: (transfer none): the action
**/
GtkShortcutAction *
gtk_shortcut_get_action (GtkShortcut *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT (self), NULL);
return self->action;
}
/**
* gtk_shortcut_set_action:
* @self: a #GtkShortcut
* @action: (transfer full) (nullable): The new action.
* If the @action is %NULL, the nothing action will be used.
*
* Sets the new action for @self to be @action.
**/
void
gtk_shortcut_set_action (GtkShortcut *self,
GtkShortcutAction *action)
{
g_return_if_fail (GTK_IS_SHORTCUT (self));
if (action == NULL)
action = g_object_ref (gtk_nothing_action_get ());
if (g_set_object (&self->action, action))
{
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTION]);
g_object_unref (action);
}
}
/**
* gtk_shortcut_get_trigger:
* @self: a #GtkShortcut
*
* Gets the trigger used to trigger @self.
*
* Returns: (transfer none): the trigger used
**/
GtkShortcutTrigger *
gtk_shortcut_get_trigger (GtkShortcut *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT (self), NULL);
return self->trigger;
}
/**
* gtk_shortcut_set_trigger:
* @self: a #GtkShortcut
* @trigger: (transfer full) (nullable): The new trigger.
* If the @trigger is %NULL, the never trigger will be used.
*
* Sets the new trigger for @self to be @trigger.
**/
void
gtk_shortcut_set_trigger (GtkShortcut *self,
GtkShortcutTrigger *trigger)
{
g_return_if_fail (GTK_IS_SHORTCUT (self));
if (trigger == NULL)
trigger = g_object_ref (gtk_never_trigger_get ());
if (g_set_object (&self->trigger, trigger))
{
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TRIGGER]);
g_object_unref (trigger);
}
}
GVariant *
gtk_shortcut_get_arguments (GtkShortcut *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT (self), NULL);
return self->args;
}
void
gtk_shortcut_set_arguments (GtkShortcut *self,
GVariant *args)
{
g_return_if_fail (GTK_IS_SHORTCUT (self));
if (self->args == args)
return;
g_clear_pointer (&self->args, g_variant_unref);
if (args)
self->args = g_variant_ref_sink (args);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ARGUMENTS]);
}

62
gtk/gtkshortcut.h Normal file
View File

@ -0,0 +1,62 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_H__
#define __GTK_SHORTCUT_H__
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
#define GTK_TYPE_SHORTCUT (gtk_shortcut_get_type ())
GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkShortcut, gtk_shortcut, GTK, SHORTCUT, GObject)
GDK_AVAILABLE_IN_ALL
GtkShortcut * gtk_shortcut_new (GtkShortcutTrigger *trigger,
GtkShortcutAction *action);
GDK_AVAILABLE_IN_ALL
GtkShortcut * gtk_shortcut_new_with_arguments (GtkShortcutTrigger *trigger,
GtkShortcutAction *action,
const gchar *format_string,
...);
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger *
gtk_shortcut_get_trigger (GtkShortcut *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_set_trigger (GtkShortcut *self,
GtkShortcutTrigger *trigger);
GDK_AVAILABLE_IN_ALL
GtkShortcutAction *
gtk_shortcut_get_action (GtkShortcut *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_set_action (GtkShortcut *self,
GtkShortcutAction *action);
GDK_AVAILABLE_IN_ALL
GVariant * gtk_shortcut_get_arguments (GtkShortcut *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_set_arguments (GtkShortcut *self,
GVariant *args);
G_END_DECLS
#endif /* __GTK_SHORTCUT_H__ */

1188
gtk/gtkshortcutaction.c Normal file

File diff suppressed because it is too large Load Diff

158
gtk/gtkshortcutaction.h Normal file
View File

@ -0,0 +1,158 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_ACTION_H__
#define __GTK_SHORTCUT_ACTION_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
#define GTK_TYPE_SHORTCUT_ACTION (gtk_shortcut_action_get_type ())
/**
* GtkShortcutFunc:
* @widget: The widget passed to the activation
* @args: The arguments passed to the activation
* @user_data: The user data provided when activating the action
*
* Prototype for shortcuts based on user callbacks.
*/
typedef gboolean (* GtkShortcutFunc) (GtkWidget *widget,
GVariant *args,
gpointer user_data);
/**
* GtkShortcutActionFlags:
* @GTK_SHORTCUT_ACTION_EXCLUSIVE: The action is the only
* action that can be activated. If this flag is not set,
* a future activation may select a different action.
*
* List of flags that can be passed to action activation.
* More flags may be added in the future.
**/
typedef enum {
GTK_SHORTCUT_ACTION_EXCLUSIVE = 1 << 0
} GtkShortcutActionFlags;
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkShortcutAction, gtk_shortcut_action, GTK, SHORTCUT_ACTION, GObject)
GDK_AVAILABLE_IN_ALL
char * gtk_shortcut_action_to_string (GtkShortcutAction *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_action_print (GtkShortcutAction *self,
GString *string);
GDK_AVAILABLE_IN_ALL
gboolean gtk_shortcut_action_activate (GtkShortcutAction *self,
GtkShortcutActionFlags flags,
GtkWidget *widget,
GVariant *args);
#define GTK_TYPE_NOTHING_ACTION (gtk_nothing_action_get_type())
/**
* GtkNothingAction:
*
* A #GtkShortcutAction that does nothing.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkNothingAction, gtk_nothing_action, GTK, NOTHING_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_nothing_action_get (void);
#define GTK_TYPE_CALLBACK_ACTION (gtk_callback_action_get_type())
/**
* GtkCallbackAction:
*
* A #GtkShortcutAction that invokes a callback.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkCallbackAction, gtk_callback_action, GTK, CALLBACK_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_callback_action_new (GtkShortcutFunc callback,
gpointer data,
GDestroyNotify destroy);
#define GTK_TYPE_MNEMONIC_ACTION (gtk_mnemonic_action_get_type())
/**
* GtkMnemonicAction:
*
* A #GtkShortcutAction that calls gtk_widget_mnemonic_activate().
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkMnemonicAction, gtk_mnemonic_action, GTK, MNEMONIC_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_mnemonic_action_get (void);
#define GTK_TYPE_ACTIVATE_ACTION (gtk_activate_action_get_type())
/**
* GtkActivateAction:
*
* A #GtkShortcutAction that calls gtk_widget_activate().
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkActivateAction, gtk_activate_action, GTK, ACTIVATE_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_activate_action_get (void);
#define GTK_TYPE_SIGNAL_ACTION (gtk_signal_action_get_type())
/**
* GtkSignalAction:
*
* A #GtkShortcutAction that emits a signal.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkSignalAction, gtk_signal_action, GTK, SIGNAL_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_signal_action_new (const char *signal_name);
GDK_AVAILABLE_IN_ALL
const char * gtk_signal_action_get_signal_name (GtkSignalAction *self);
#define GTK_TYPE_NAMED_ACTION (gtk_named_action_get_type())
/**
* GtkNamedAction:
*
* A #GtkShortcutAction that activates an action by name.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkNamedAction, gtk_named_action, GTK, NAMED_ACTION, GtkShortcutAction)
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_named_action_new (const char *name);
GDK_AVAILABLE_IN_ALL
const char * gtk_named_action_get_action_name (GtkNamedAction *self);
G_END_DECLS
#endif /* __GTK_SHORTCUT_ACTION_H__ */

View File

@ -0,0 +1,29 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_ACTION_PRIVATE_H__
#define __GTK_SHORTCUT_ACTION_PRIVATE_H__
#include "gtkshortcutaction.h"
GtkShortcutAction * gtk_shortcut_action_parse_builder (GtkBuilder *builder,
const char *string,
GError **error);
#endif /* __GTK_SHORTCUT_ACTION_PRIVATE_H__ */

835
gtk/gtkshortcutcontroller.c Normal file
View File

@ -0,0 +1,835 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
/**
* SECTION:gtkshortcutcontroller
* @Short_description: Event controller for shortcuts
* @Title: GtkShortcutController
* @See_also: #GtkEventController, #GtkShortcut
*
* #GtkShortcutController is an event controller that manages shortcuts.
*
* Most common shortcuts are using this controller implicitly, e.g. by
* adding a mnemonic underline to a #GtkLabel, or by installing a key
* binding using gtk_widget_class_add_binding(), or by adding accelerators
* to global actions using gtk_application_set_accels_for_action().
*
* But it is possible to create your own shortcut controller, and add
* shortcuts to it.
*
* #GtkShortcutController implements #GListModel for querying the shortcuts that
* have been added to it.
**/
#include "config.h"
#include "gtkshortcutcontrollerprivate.h"
#include "gtkflattenlistmodel.h"
#include "gtkbuildable.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkintl.h"
#include "gtkshortcut.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcuttrigger.h"
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
#include "gtknative.h"
#include <gdk/gdk.h>
struct _GtkShortcutController
{
GtkEventController parent_instance;
GListModel *shortcuts;
GtkShortcutScope scope;
GdkModifierType mnemonics_modifiers;
guint custom_shortcuts : 1;
guint last_activated;
};
struct _GtkShortcutControllerClass
{
GtkEventControllerClass parent_class;
};
enum {
PROP_0,
PROP_MNEMONICS_MODIFIERS,
PROP_MODEL,
PROP_SCOPE,
N_PROPS
};
static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_shortcut_controller_list_model_get_item_type (GListModel *list)
{
return GTK_TYPE_SHORTCUT;
}
static guint
gtk_shortcut_controller_list_model_get_n_items (GListModel *list)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (list);
return g_list_model_get_n_items (self->shortcuts);
}
static gpointer
gtk_shortcut_controller_list_model_get_item (GListModel *list,
guint position)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (list);
return g_list_model_get_item (self->shortcuts, position);
}
static void
gtk_shortcut_controller_list_model_init (GListModelInterface *iface)
{
iface->get_item_type = gtk_shortcut_controller_list_model_get_item_type;
iface->get_n_items = gtk_shortcut_controller_list_model_get_n_items;
iface->get_item = gtk_shortcut_controller_list_model_get_item;
}
static void
gtk_shortcut_controller_buildable_add_child (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *type)
{
if (type != NULL)
{
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
}
if (GTK_IS_SHORTCUT (child))
{
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), GTK_SHORTCUT (child));
}
else
{
g_warning ("Cannot add an object of type %s to a controller of type %s",
g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
}
}
static void
gtk_shortcut_controller_buildable_init (GtkBuildableIface *iface)
{
iface->add_child = gtk_shortcut_controller_buildable_add_child;
}
G_DEFINE_TYPE_WITH_CODE (GtkShortcutController, gtk_shortcut_controller,
GTK_TYPE_EVENT_CONTROLLER,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_shortcut_controller_list_model_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_shortcut_controller_buildable_init))
static gboolean
gtk_shortcut_controller_is_rooted (GtkShortcutController *self)
{
GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (widget == NULL)
return FALSE;
return gtk_widget_get_root (widget) != NULL;
}
static void
gtk_shortcut_controller_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
switch (prop_id)
{
case PROP_MNEMONICS_MODIFIERS:
gtk_shortcut_controller_set_mnemonics_modifiers (self, g_value_get_flags (value));
break;
case PROP_MODEL:
{
GListModel *model = g_value_get_object (value);
if (model && g_list_model_get_item_type (model) != GTK_TYPE_SHORTCUT)
{
g_warning ("Setting a model with type '%s' on a shortcut controller that requires 'GtkShortcut'",
g_type_name (g_list_model_get_item_type (model)));
model = NULL;
}
if (model == NULL)
{
self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT));
self->custom_shortcuts = TRUE;
}
else
{
self->shortcuts = g_object_ref (model);
self->custom_shortcuts = FALSE;
}
g_signal_connect_swapped (self->shortcuts, "items-changed", G_CALLBACK (g_list_model_items_changed), self);
}
break;
case PROP_SCOPE:
gtk_shortcut_controller_set_scope (self, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gtk_shortcut_controller_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
switch (prop_id)
{
case PROP_MNEMONICS_MODIFIERS:
g_value_set_flags (value, self->mnemonics_modifiers);
break;
case PROP_SCOPE:
g_value_set_enum (value, self->scope);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gtk_shortcut_controller_dispose (GObject *object)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
if (self->custom_shortcuts)
g_list_store_remove_all (G_LIST_STORE (self->shortcuts));
G_OBJECT_CLASS (gtk_shortcut_controller_parent_class)->dispose (object);
}
static void
gtk_shortcut_controller_finalize (GObject *object)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
g_signal_handlers_disconnect_by_func (self->shortcuts, g_list_model_items_changed, self);
g_clear_object (&self->shortcuts);
G_OBJECT_CLASS (gtk_shortcut_controller_parent_class)->finalize (object);
}
typedef struct {
GtkShortcut *shortcut;
GtkWidget *widget;
guint index;
} ShortcutData;
static void
shortcut_data_free (gpointer data)
{
ShortcutData *sdata = data;
g_object_unref (sdata->shortcut);
g_free (sdata);
}
static gboolean
gtk_shortcut_controller_run_controllers (GtkEventController *controller,
GdkEvent *event,
double x,
double y,
gboolean enable_mnemonics)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
guint i;
GSList *shortcuts = NULL;
GSList *l;
gboolean has_exact = FALSE;
gboolean retval = FALSE;
for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
{
GtkShortcut *shortcut;
ShortcutData *data;
guint index;
GtkWidget *widget;
GtkNative *native;
index = (self->last_activated + 1 + i) % g_list_model_get_n_items (self->shortcuts);
shortcut = g_list_model_get_item (self->shortcuts, index);
switch (gtk_shortcut_trigger_trigger (gtk_shortcut_get_trigger (shortcut), event, enable_mnemonics))
{
case GTK_SHORTCUT_TRIGGER_MATCH_PARTIAL:
if (!has_exact)
break;
G_GNUC_FALLTHROUGH;
case GTK_SHORTCUT_TRIGGER_MATCH_NONE:
g_object_unref (shortcut);
continue;
case GTK_SHORTCUT_TRIGGER_MATCH_EXACT:
if (!has_exact)
{
g_slist_free_full (shortcuts, shortcut_data_free);
shortcuts = NULL;
}
has_exact = TRUE;
break;
default:
g_assert_not_reached ();
}
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (!self->custom_shortcuts &&
GTK_IS_FLATTEN_LIST_MODEL (self->shortcuts))
{
GListModel *model = gtk_flatten_list_model_get_model_for_item (GTK_FLATTEN_LIST_MODEL (self->shortcuts), index);
if (GTK_IS_SHORTCUT_CONTROLLER (model))
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (model));
}
native = gtk_widget_get_native (widget);
if (!gtk_widget_is_sensitive (widget) ||
!gtk_widget_get_mapped (widget) ||
!gdk_surface_is_viewable (gtk_native_get_surface (native)))
{
g_object_unref (shortcut);
continue;
}
data = g_new0 (ShortcutData, 1);
data->shortcut = shortcut;
data->index = index;
data->widget = widget;
shortcuts = g_slist_append (shortcuts, data);
}
for (l = shortcuts; l; l = l->next)
{
ShortcutData *data = l->data;
if (gtk_shortcut_action_activate (gtk_shortcut_get_action (data->shortcut),
shortcuts->next == NULL ? GTK_SHORTCUT_ACTION_EXCLUSIVE : 0,
data->widget,
gtk_shortcut_get_arguments (data->shortcut)))
{
self->last_activated = data->index;
retval = TRUE;
break;
}
}
g_slist_free_full (shortcuts, shortcut_data_free);
return retval;
}
static gboolean
gtk_shortcut_controller_handle_event (GtkEventController *controller,
GdkEvent *event,
double x,
double y)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
GdkEventType event_type = gdk_event_get_event_type (event);
gboolean enable_mnemonics;
if (self->scope != GTK_SHORTCUT_SCOPE_LOCAL)
return FALSE;
if (event_type != GDK_KEY_PRESS && event_type != GDK_KEY_RELEASE)
return FALSE;
if (event_type == GDK_KEY_PRESS)
{
GdkModifierType modifiers;
modifiers = gdk_event_get_modifier_state (event);
enable_mnemonics = (modifiers & gtk_accelerator_get_default_mod_mask ()) == self->mnemonics_modifiers;
}
else
{
enable_mnemonics = FALSE;
}
return gtk_shortcut_controller_run_controllers (controller, event, x, y, enable_mnemonics);
}
static void
update_accel (GtkShortcut *shortcut,
GtkWidget *widget,
gboolean set)
{
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
GtkActionMuxer *muxer;
GVariant *target;
const char *action_name;
char *action_and_target;
char *accel = NULL;
trigger = gtk_shortcut_get_trigger (shortcut);
action = gtk_shortcut_get_action (shortcut);
if (!GTK_IS_NAMED_ACTION (action) ||
!GTK_IS_KEYVAL_TRIGGER (trigger))
return;
muxer = _gtk_widget_get_action_muxer (widget, set);
if (!muxer)
return;
target = gtk_shortcut_get_arguments (shortcut);
action_name = gtk_named_action_get_action_name (GTK_NAMED_ACTION (action));
action_and_target = gtk_print_action_and_target (NULL, action_name, target);
if (set)
accel = gtk_shortcut_trigger_to_string (trigger);
gtk_action_muxer_set_primary_accel (muxer, action_and_target, accel);
g_free (action_and_target);
g_free (accel);
}
static void
gtk_shortcut_controller_set_widget (GtkEventController *controller,
GtkWidget *widget)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
int i;
GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
{
GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
update_accel (shortcut, widget, TRUE);
g_object_unref (shortcut);
}
if (_gtk_widget_get_root (widget))
gtk_shortcut_controller_root (self);
}
static void
gtk_shortcut_controller_unset_widget (GtkEventController *controller)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
GtkWidget *widget = gtk_event_controller_get_widget (controller);
if (_gtk_widget_get_root (widget))
gtk_shortcut_controller_unroot (self);
#if 0
int i;
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
{
GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
update_accel (shortcut, widget, FALSE);
g_object_unref (shortcut);
}
#endif
GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->unset_widget (controller);
}
static void
gtk_shortcut_controller_class_init (GtkShortcutControllerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
object_class->dispose = gtk_shortcut_controller_dispose;
object_class->finalize = gtk_shortcut_controller_finalize;
object_class->set_property = gtk_shortcut_controller_set_property;
object_class->get_property = gtk_shortcut_controller_get_property;
controller_class->handle_event = gtk_shortcut_controller_handle_event;
controller_class->set_widget = gtk_shortcut_controller_set_widget;
controller_class->unset_widget = gtk_shortcut_controller_unset_widget;
/**
* GtkShortcutController:mnemonic-modifiers:
*
* The modifiers that need to be pressed to allow mnemonics activation.
*/
properties[PROP_MNEMONICS_MODIFIERS] =
g_param_spec_flags ("mnemonic-modifiers",
P_("Mnemonic modifers"),
P_("The modifiers to be pressed to allow mnemonics activation"),
GDK_TYPE_MODIFIER_TYPE,
GDK_MOD1_MASK,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcutController:model:
*
* A list model to take shortcuts from
*/
properties[PROP_MODEL] =
g_param_spec_object ("model",
P_("Model"),
P_("A list model to take shortcuts from"),
G_TYPE_LIST_MODEL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcutController:scope:
*
* What scope the shortcuts will be handled in.
*/
properties[PROP_SCOPE] =
g_param_spec_enum ("scope",
P_("Scope"),
P_("What scope the shortcuts will be handled in"),
GTK_TYPE_SHORTCUT_SCOPE,
GTK_SHORTCUT_SCOPE_LOCAL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
gtk_shortcut_controller_init (GtkShortcutController *self)
{
self->mnemonics_modifiers = GDK_MOD1_MASK;
}
void
gtk_shortcut_controller_root (GtkShortcutController *self)
{
GtkShortcutManager *manager;
switch (self->scope)
{
case GTK_SHORTCUT_SCOPE_LOCAL:
return;
case GTK_SHORTCUT_SCOPE_MANAGED:
{
GtkWidget *widget;
for (widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
!GTK_IS_SHORTCUT_MANAGER (widget);
widget = _gtk_widget_get_parent (widget))
;
if (!GTK_IS_SHORTCUT_MANAGER (widget))
return;
manager = GTK_SHORTCUT_MANAGER (widget);
}
break;
case GTK_SHORTCUT_SCOPE_GLOBAL:
{
GtkRoot *root = gtk_widget_get_root (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self)));
if (!GTK_IS_SHORTCUT_MANAGER (root))
return;
manager = GTK_SHORTCUT_MANAGER (root);
}
break;
default:
g_assert_not_reached ();
return;
}
GTK_SHORTCUT_MANAGER_GET_IFACE (manager)->add_controller (manager, self);
}
void
gtk_shortcut_controller_unroot (GtkShortcutController *self)
{
GtkShortcutManager *manager;
switch (self->scope)
{
case GTK_SHORTCUT_SCOPE_LOCAL:
return;
case GTK_SHORTCUT_SCOPE_MANAGED:
{
GtkWidget *widget;
for (widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
!GTK_IS_SHORTCUT_MANAGER (widget);
widget = _gtk_widget_get_parent (widget))
;
if (!GTK_IS_SHORTCUT_MANAGER (widget))
return;
manager = GTK_SHORTCUT_MANAGER (widget);
}
break;
case GTK_SHORTCUT_SCOPE_GLOBAL:
{
GtkRoot *root = gtk_widget_get_root (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self)));
if (!GTK_IS_SHORTCUT_MANAGER (root))
return;
manager = GTK_SHORTCUT_MANAGER (root);
}
break;
default:
g_assert_not_reached ();
return;
}
GTK_SHORTCUT_MANAGER_GET_IFACE (manager)->remove_controller (manager, self);
}
/**
* gtk_shortcut_controller_new:
*
* Creates a new shortcut controller.
*
* Returns: a newly created shortcut controller
*/
GtkEventController *
gtk_shortcut_controller_new (void)
{
return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
NULL);
}
/**
* gtk_shortcut_controller_new_for_model:
* @model: a #GListModel containing shortcuts
*
* Creates a new shortcut controller that takes its shortcuts from
* the given list model.
*
* A controller created by this function does not let you add or
* remove individual shortcuts using the shortcut controller api,
* but you can change the contents of the model.
*
* Returns: a newly created shortcut controller
*/
GtkEventController *
gtk_shortcut_controller_new_for_model (GListModel *model)
{
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (g_list_model_get_item_type (model) == GTK_TYPE_SHORTCUT, NULL);
return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
"model", model,
NULL);
}
/**
* gtk_shortcut_controller_add_shortcut:
* @self: the controller
* @shortcut: a #GtkShortcut
*
* Adds @shortcut to the list of shortcuts handled by @self.
*
* If this controller uses an external shortcut list, this
* function does nothing.
**/
void
gtk_shortcut_controller_add_shortcut (GtkShortcutController *self,
GtkShortcut *shortcut)
{
GtkWidget *widget;
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
g_return_if_fail (GTK_IS_SHORTCUT (shortcut));
if (!self->custom_shortcuts)
return;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (widget)
update_accel (shortcut, widget, TRUE);
g_list_store_append (G_LIST_STORE (self->shortcuts), shortcut);
}
/**
* gtk_shortcut_controller_remove_shortcut:
* @self: the controller
* @shortcut: a #GtkShortcut
*
* Removes @shortcut from the list of shortcuts handled by @self.
*
* If @shortcut had not been added to @controller or this controller
* uses an external shortcut list, this function does nothing.
**/
void
gtk_shortcut_controller_remove_shortcut (GtkShortcutController *self,
GtkShortcut *shortcut)
{
GtkWidget *widget;
guint i;
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
g_return_if_fail (GTK_IS_SHORTCUT (shortcut));
if (!self->custom_shortcuts)
return;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (widget)
update_accel (shortcut, widget, FALSE);
for (i = 0; i < g_list_model_get_n_items (self->shortcuts); i++)
{
GtkShortcut *item = g_list_model_get_item (self->shortcuts, i);
if (item == shortcut)
{
g_object_unref (item);
g_list_store_remove (G_LIST_STORE (self->shortcuts), i);
return;
}
g_object_unref (item);
}
}
/**
* gtk_shortcut_controller_set_scope:
* @self: a #GtkShortcutController
* @scope: the new scope to use
*
* Sets the controller to have the given @scope.
*
* The scope allows shortcuts to be activated outside of the normal
* event propagation. In particular, it allows installing global
* keyboard shortcuts that can be activated even when a widget does
* not have focus.
*
* With %GTK_SHORTCUT_SCOPE_LOCAL, shortcuts will only be activated
* when the widget has focus.
**/
void
gtk_shortcut_controller_set_scope (GtkShortcutController *self,
GtkShortcutScope scope)
{
gboolean rooted;
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
if (self->scope == scope)
return;
rooted = gtk_shortcut_controller_is_rooted (self);
if (rooted)
gtk_shortcut_controller_unroot (self);
self->scope = scope;
if (rooted)
gtk_shortcut_controller_root (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SCOPE]);
}
/**
* gtk_shortcut_controller_get_scope:
* @self: a #GtkShortcutController
*
* Gets the scope for when this controller activates its shortcuts. See
* gtk_shortcut_controller_set_scope() for details.
*
* Returns: the controller's scope
**/
GtkShortcutScope
gtk_shortcut_controller_get_scope (GtkShortcutController *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self), GTK_SHORTCUT_SCOPE_LOCAL);
return self->scope;
}
/**
* gtk_shortcut_controller_set_mnemonics_modifiers:
* @self: a #GtkShortcutController
* @modifiers: the new mnemonics_modifiers to use
*
* Sets the controller to have the given @mnemonics_modifiers.
*
* The mnemonics modifiers determines which modifiers need to be pressed to allow
* activation of shortcuts with mnemonics triggers.
*
* GTK normally uses the Alt modifier for mnemonics, except in #GtkPopoverMenus,
* where mnemonics can be triggered without any modifiers. It should be very
* rarely necessary to change this, and doing so is likely to interfere with
* other shortcuts.
*
* This value is only relevant for local shortcut controllers. Global and managed
* shortcut controllers will have their shortcuts activated from other places which
* have their own modifiers for activating mnemonics.
**/
void
gtk_shortcut_controller_set_mnemonics_modifiers (GtkShortcutController *self,
GdkModifierType modifiers)
{
g_return_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self));
if (self->mnemonics_modifiers == modifiers)
return;
self->mnemonics_modifiers = modifiers;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MNEMONICS_MODIFIERS]);
}
/**
* gtk_shortcut_controller_get_mnemonics_modifiers:
* @self: a #GtkShortcutController
*
* Gets the mnemonics modifiers for when this controller activates its shortcuts. See
* gtk_shortcut_controller_set_mnemonics_modifiers() for details.
*
* Returns: the controller's mnemonics modifiers
**/
GdkModifierType
gtk_shortcut_controller_get_mnemonics_modifiers (GtkShortcutController *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT_CONTROLLER (self), GTK_SHORTCUT_SCOPE_LOCAL);
return self->mnemonics_modifiers;
}

View File

@ -0,0 +1,70 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_CONTROLLER_H__
#define __GTK_SHORTCUT_CONTROLLER_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkeventcontroller.h>
G_BEGIN_DECLS
#define GTK_TYPE_SHORTCUT_CONTROLLER (gtk_shortcut_controller_get_type ())
#define GTK_SHORTCUT_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_SHORTCUT_CONTROLLER, GtkShortcutController))
#define GTK_SHORTCUT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_SHORTCUT_CONTROLLER, GtkShortcutControllerClass))
#define GTK_IS_SHORTCUT_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_SHORTCUT_CONTROLLER))
#define GTK_IS_SHORTCUT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_SHORTCUT_CONTROLLER))
#define GTK_SHORTCUT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_SHORTCUT_CONTROLLER, GtkShortcutControllerClass))
typedef struct _GtkShortcutController GtkShortcutController;
typedef struct _GtkShortcutControllerClass GtkShortcutControllerClass;
GDK_AVAILABLE_IN_ALL
GType gtk_shortcut_controller_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkEventController * gtk_shortcut_controller_new (void);
GDK_AVAILABLE_IN_ALL
GtkEventController * gtk_shortcut_controller_new_for_model (GListModel *list);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_controller_set_mnemonics_modifiers (GtkShortcutController *self,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
GdkModifierType gtk_shortcut_controller_get_mnemonics_modifiers (GtkShortcutController *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_controller_set_scope (GtkShortcutController *self,
GtkShortcutScope scope);
GDK_AVAILABLE_IN_ALL
GtkShortcutScope gtk_shortcut_controller_get_scope (GtkShortcutController *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_controller_add_shortcut (GtkShortcutController *self,
GtkShortcut *shortcut);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_controller_remove_shortcut (GtkShortcutController *self,
GtkShortcut *shortcut);
G_END_DECLS
#endif /* __GTK_SHORTCUT_CONTROLLER_H__ */

View File

@ -0,0 +1,28 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_CONTROLLER_PRIVATE_H__
#define __GTK_SHORTCUT_CONTROLLER_PRIVATE_H__
#include "gtkshortcutcontroller.h"
void gtk_shortcut_controller_root (GtkShortcutController *controller);
void gtk_shortcut_controller_unroot (GtkShortcutController *controller);
#endif /* __GTK_SHORTCUT_CONTROLLER_H__ */

View File

@ -303,8 +303,7 @@ parse_combination (GtkShortcutLabel *self,
accels = g_strsplit (str, "&", 0);
for (k = 0; accels[k]; k++)
{
gtk_accelerator_parse (accels[k], &key, &modifier);
if (key == 0 && modifier == 0)
if (!gtk_accelerator_parse (accels[k], &key, &modifier))
{
retval = FALSE;
break;

143
gtk/gtkshortcutmanager.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcutmanagerprivate.h"
#include "gtkflattenlistmodel.h"
/**
* SECTION:gtkshortcutmanager
* @title: GtkShortcutManager
* @short_description: Interface for managing shortcuts
*
* The GtkShortcutManager interface is used to implement
* shortcut scopes.
*
* This is important for #GtkNative widgets that have their own surface,
* since the event controllers that are used to implement managed and
* global scopes are limited to the same native.
*
* Examples for widgets implementing #GtkShortcutManager are #GtkWindow
* and #GtkPopover.
*/
G_DEFINE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, G_TYPE_OBJECT)
void
gtk_shortcut_manager_create_controllers (GtkWidget *widget)
{
GListStore *store;
GtkFlattenListModel *model;
GtkEventController *controller;
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-bubble");
gtk_widget_add_controller (widget, controller);
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-capture");
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
gtk_widget_add_controller (widget, controller);
}
static GtkFlattenListModel *
gtk_shortcut_manager_get_model (GtkShortcutManager *self,
GtkPropagationPhase phase)
{
switch (phase)
{
case GTK_PHASE_CAPTURE:
return g_object_get_data (G_OBJECT (self), "gtk-shortcut-manager-capture");
case GTK_PHASE_BUBBLE:
return g_object_get_data (G_OBJECT (self), "gtk-shortcut-manager-bubble");
case GTK_PHASE_NONE:
case GTK_PHASE_TARGET:
return NULL;
default:
g_assert_not_reached ();
return NULL;
}
}
static void
gtk_shortcut_manager_default_add_controller (GtkShortcutManager *self,
GtkShortcutController *controller)
{
GtkFlattenListModel *model;
GtkPropagationPhase phase;
phase = gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER (controller));
model = gtk_shortcut_manager_get_model (self, phase);
if (model)
{
GListModel *store = gtk_flatten_list_model_get_model (model);
g_list_store_append (G_LIST_STORE (store), controller);
}
}
static void
gtk_shortcut_manager_default_remove_controller (GtkShortcutManager *self,
GtkShortcutController *controller)
{
GtkFlattenListModel *model;
GtkPropagationPhase phase;
phase = gtk_event_controller_get_propagation_phase (GTK_EVENT_CONTROLLER (controller));
model = gtk_shortcut_manager_get_model (self, phase);
if (model)
{
GListModel *store;
guint position;
store = gtk_flatten_list_model_get_model (model);
#if 0 && GLIB_CHECK_VERSION(2,64,0)
if (_g_list_store_find (G_LIST_STORE (store), controller, &position))
g_list_store_remove (G_LIST_STORE (store), position);
#else
for (position = 0; position < g_list_model_get_n_items (G_LIST_MODEL (store)); position++)
{
GtkShortcutController *item = g_list_model_get_item (G_LIST_MODEL (store), position);
g_object_unref (item);
if (item == controller)
{
g_list_store_remove (G_LIST_STORE (store), position);
break;
}
}
#endif
}
}
static void
gtk_shortcut_manager_default_init (GtkShortcutManagerInterface *iface)
{
iface->add_controller = gtk_shortcut_manager_default_add_controller;
iface->remove_controller = gtk_shortcut_manager_default_remove_controller;
}

71
gtk/gtkshortcutmanager.h Normal file
View File

@ -0,0 +1,71 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_MANAGER_H__
#define __GTK_SHORTCUT_MANAGER_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkshortcutcontroller.h>
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
#define GTK_TYPE_SHORTCUT_MANAGER (gtk_shortcut_manager_get_type ())
GDK_AVAILABLE_IN_ALL
G_DECLARE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, GTK, SHORTCUT_MANAGER, GtkWidget)
/**
* GtkShortcutManager:
*
* This object is used to implement support for #GtkShortcutScopes. Every
* widget that implements #GtkShortcutManager will be used as a
* %GTK_SHORTCUT_SCOPE_MANAGED.
*/
/**
* GtkShortcutManagerInterface:
* @add_controller: Add a #GtkShortcutController to be managed.
* @remove_controller: Remove a #GtkShortcutController that had previously
* been added.
*
* The list of functions that can be implemented for the #GtkShortcutManager interface.
*
* Note that no function is mandatory to implement, the default implementation will work
* fine.
*/
struct _GtkShortcutManagerInterface
{
/*< private >*/
GTypeInterface g_iface;
/*< public >*/
void (* add_controller) (GtkShortcutManager *self,
GtkShortcutController *controller);
void (* remove_controller) (GtkShortcutManager *self,
GtkShortcutController *controller);
};
G_END_DECLS
#endif /* __GTK_SHORTCUT_MANAGER_H__ */

View File

@ -0,0 +1,12 @@
#ifndef __GTK_SHORTCUT_MANAGER_PRIVATE_H__
#define __GTK_SHORTCUT_MANAGER__PRIVATE_H__
#include "gtkshortcutmanager.h"
G_BEGIN_DECLS
void gtk_shortcut_manager_create_controllers (GtkWidget *widget);
G_END_DECLS
#endif /* __GTK_SHORTCUT_MANAGER_PRIVATE_H__ */

View File

@ -30,7 +30,6 @@
#include "gtkorientable.h"
#include "gtksizegroup.h"
#include "gtkwidget.h"
#include "gtkbindings.h"
#include "gtkprivate.h"
#include "gtkmarshalers.h"
#include "gtkgesturepan.h"
@ -307,7 +306,6 @@ gtk_shortcuts_section_class_init (GtkShortcutsSectionClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
object_class->finalize = gtk_shortcuts_section_finalize;
object_class->get_property = gtk_shortcuts_section_get_property;
@ -388,23 +386,23 @@ gtk_shortcuts_section_class_init (GtkShortcutsSectionClass *klass)
G_TYPE_BOOLEAN, 1,
G_TYPE_INT);
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Up, 0,
"change-current-page", 1,
G_TYPE_INT, -1);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Down, 0,
"change-current-page", 1,
G_TYPE_INT, 1);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Up, GDK_CONTROL_MASK,
"change-current-page", 1,
G_TYPE_INT, -1);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Page_Down, GDK_CONTROL_MASK,
"change-current-page", 1,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, 0,
"change-current-page",
"(i)", -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Down, 0,
"change-current-page",
"(i)", 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Up, GDK_CONTROL_MASK,
"change-current-page",
"(i)", -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Page_Down, GDK_CONTROL_MASK,
"change-current-page",
"(i)", 1);
gtk_widget_class_set_css_name (widget_class, I_("shortcuts-section"));
}

View File

@ -20,7 +20,6 @@
#include "gtkshortcutswindowprivate.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkgrid.h"
#include "gtkheaderbar.h"
@ -774,7 +773,6 @@ gtk_shortcuts_window_class_init (GtkShortcutsWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set = gtk_binding_set_by_class (klass);
object_class->constructed = gtk_shortcuts_window_constructed;
object_class->finalize = gtk_shortcuts_window_finalize;
@ -856,8 +854,14 @@ gtk_shortcuts_window_class_init (GtkShortcutsWindowClass *klass)
G_TYPE_NONE,
0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_f, GDK_CONTROL_MASK, "search", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Escape, 0,
"close",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_f, GDK_CONTROL_MASK,
"search",
NULL);
g_type_ensure (GTK_TYPE_SHORTCUTS_GROUP);
g_type_ensure (GTK_TYPE_SHORTCUTS_SHORTCUT);

1296
gtk/gtkshortcuttrigger.c Normal file

File diff suppressed because it is too large Load Diff

163
gtk/gtkshortcuttrigger.h Normal file
View File

@ -0,0 +1,163 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_SHORTCUT_TRIGGER_H__
#define __GTK_SHORTCUT_TRIGGER_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
#define GTK_TYPE_SHORTCUT_TRIGGER (gtk_shortcut_trigger_get_type ())
/**
* GtkShortcutTrigger:
*
* A trigger for a key shortcut.
*/
/**
* GtkShortcutTriggerMatch:
* @GTK_SHORTCUT_TRIGGER_MATCH_NONE: The key event does not
* match the trigger
* @GTK_SHORTCUT_TRIGGER_MATCH_PARTIAL: The key event matches
* the trigger if keyboard state (specifically, the currently
* active group) is ignored
* @GTK_SHORTCUT_TRIGGER_MATCH_EXACT: The key event matches
* the trigger
*
* The possible return values from gtk_shortcut_trigger_trigger()
* describe if a key event triggers a shortcut.
*/
typedef enum {
GTK_SHORTCUT_TRIGGER_MATCH_NONE,
GTK_SHORTCUT_TRIGGER_MATCH_PARTIAL,
GTK_SHORTCUT_TRIGGER_MATCH_EXACT,
} GtkShortcutTriggerMatch;
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkShortcutTrigger, gtk_shortcut_trigger, GTK, SHORTCUT_TRIGGER, GObject)
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_shortcut_trigger_parse_string (const char *string);
GDK_AVAILABLE_IN_ALL
char * gtk_shortcut_trigger_to_string (GtkShortcutTrigger *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_trigger_print (GtkShortcutTrigger *self,
GString *string);
GDK_AVAILABLE_IN_ALL
char * gtk_shortcut_trigger_to_label (GtkShortcutTrigger *self,
GdkDisplay *display);
GDK_AVAILABLE_IN_ALL
gboolean gtk_shortcut_trigger_print_label (GtkShortcutTrigger *self,
GdkDisplay *display,
GString *string);
GDK_AVAILABLE_IN_ALL
guint gtk_shortcut_trigger_hash (gconstpointer trigger);
GDK_AVAILABLE_IN_ALL
gboolean gtk_shortcut_trigger_equal (gconstpointer trigger1,
gconstpointer trigger2);
GDK_AVAILABLE_IN_ALL
gint gtk_shortcut_trigger_compare (gconstpointer trigger1,
gconstpointer trigger2);
GDK_AVAILABLE_IN_ALL
GtkShortcutTriggerMatch gtk_shortcut_trigger_trigger (GtkShortcutTrigger *self,
GdkEvent *event,
gboolean enable_mnemonics);
#define GTK_TYPE_NEVER_TRIGGER (gtk_never_trigger_get_type())
/**
* GtkNeverTrigger:
*
* A #GtkShortcutTrigger that never triggers.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkNeverTrigger, gtk_never_trigger, GTK, NEVER_TRIGGER, GtkShortcutTrigger)
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_never_trigger_get (void);
#define GTK_TYPE_KEYVAL_TRIGGER (gtk_keyval_trigger_get_type())
/**
* GtkKeyvalTrigger:
*
* A #GtkShortcutTrigger that triggers when a specific keyval
* and (optionally) modifiers are pressed.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkKeyvalTrigger, gtk_keyval_trigger, GTK, KEYVAL_TRIGGER, GtkShortcutTrigger)
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_keyval_trigger_new (guint keyval,
GdkModifierType modifiers);
GDK_AVAILABLE_IN_ALL
GdkModifierType gtk_keyval_trigger_get_modifiers (GtkKeyvalTrigger *self);
GDK_AVAILABLE_IN_ALL
guint gtk_keyval_trigger_get_keyval (GtkKeyvalTrigger *self);
#define GTK_TYPE_MNEMONIC_TRIGGER (gtk_mnemonic_trigger_get_type())
/**
* GtkMnemonicTrigger:
*
* A #GtkShortcutTrigger that triggers when a specific mnemonic
* is pressed.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkMnemonicTrigger, gtk_mnemonic_trigger, GTK, MNEMONIC_TRIGGER, GtkShortcutTrigger)
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_mnemonic_trigger_new (guint keyval);
GDK_AVAILABLE_IN_ALL
guint gtk_mnemonic_trigger_get_keyval (GtkMnemonicTrigger *self);
#define GTK_TYPE_ALTERNATIVE_TRIGGER (gtk_alternative_trigger_get_type())
/**
* GtkAlternativeTrigger:
*
* A #GtkShortcutTrigger that triggers when either of two
* #GtkShortcutTriggers trigger.
*/
GDK_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (GtkAlternativeTrigger, gtk_alternative_trigger, GTK, ALTERNATIVE_TRIGGER, GtkShortcutTrigger)
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_alternative_trigger_new (GtkShortcutTrigger *first,
GtkShortcutTrigger *second);
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_alternative_trigger_get_first (GtkAlternativeTrigger *self);
GDK_AVAILABLE_IN_ALL
GtkShortcutTrigger * gtk_alternative_trigger_get_second (GtkAlternativeTrigger *self);
G_END_DECLS
#endif /* __GTK_SHORTCUT_TRIGGER_H__ */

View File

@ -30,7 +30,6 @@
#include "gtkspinbutton.h"
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkbutton.h"
#include "gtkcssstylepropertyprivate.h"
@ -317,10 +316,10 @@ G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
gtk_spin_button_cell_editable_init))
#define add_spin_binding(binding_set, keyval, mask, scroll) \
gtk_binding_entry_add_signal (binding_set, keyval, mask, \
"change-value", 1, \
GTK_TYPE_SCROLL_TYPE, scroll)
#define add_spin_binding(widget_class, keyval, mask, scroll) \
gtk_widget_class_add_binding_signal (widget_class, keyval, mask, \
"change-value", \
"(i)", scroll)
static gboolean
@ -347,7 +346,6 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkBindingSet *binding_set;
gobject_class->finalize = gtk_spin_button_finalize;
gobject_class->set_property = gtk_spin_button_set_property;
@ -545,18 +543,16 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
G_TYPE_NONE, 1,
GTK_TYPE_SCROLL_TYPE);
binding_set = gtk_binding_set_by_class (class);
add_spin_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
add_spin_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
add_spin_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
add_spin_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
add_spin_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_spin_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_DOWN);
add_spin_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END);
add_spin_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START);
add_spin_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_END);
add_spin_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_START);
add_spin_binding (widget_class, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
add_spin_binding (widget_class, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
add_spin_binding (widget_class, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
add_spin_binding (widget_class, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
add_spin_binding (widget_class, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
add_spin_binding (widget_class, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_DOWN);
add_spin_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END);
add_spin_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START);
add_spin_binding (widget_class, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_END);
add_spin_binding (widget_class, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_START);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SPIN_BUTTON_ACCESSIBLE);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);

View File

@ -25,7 +25,6 @@
#include "gtkactionable.h"
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbox.h"
#include "gtkbutton.h"
#include "gtkcssnodeprivate.h"
@ -390,7 +389,9 @@ static void gtk_text_set_alignment (GtkText *self,
/* Default signal handlers
*/
static GMenuModel *gtk_text_get_menu_model (GtkText *self);
static gboolean gtk_text_popup_menu (GtkWidget *widget);
static void gtk_text_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_text_move_cursor (GtkText *self,
GtkMovementStep step,
int count,
@ -685,7 +686,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkText, gtk_text, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_text_editable_init))
static void
add_move_binding (GtkBindingSet *binding_set,
add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
GtkMovementStep step,
@ -693,28 +694,22 @@ add_move_binding (GtkBindingSet *binding_set,
{
g_return_if_fail ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(iib)", step, count, FALSE);
/* Selection-extending version */
gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | GDK_SHIFT_MASK,
"move-cursor",
"(iib)", step, count, TRUE);
}
static void
gtk_text_class_init (GtkTextClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class;
GtkBindingSet *binding_set;
widget_class = (GtkWidgetClass*) class;
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
gobject_class->dispose = gtk_text_dispose;
gobject_class->finalize = gtk_text_finalize;
@ -734,7 +729,6 @@ gtk_text_class_init (GtkTextClass *class)
widget_class->state_flags_changed = gtk_text_state_flags_changed;
widget_class->root = gtk_text_root;
widget_class->mnemonic_activate = gtk_text_mnemonic_activate;
widget_class->popup_menu = gtk_text_popup_menu;
class->move_cursor = gtk_text_move_cursor;
class->insert_at_cursor = gtk_text_insert_at_cursor;
@ -1202,187 +1196,217 @@ gtk_text_class_init (GtkTextClass *class)
gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_real_undo);
gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_real_redo);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_popup_menu);
/*
* Key bindings
*/
binding_set = gtk_binding_set_by_class (class);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */
add_move_binding (binding_set, GDK_KEY_Right, 0,
add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_Left, 0,
add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_Home, 0,
add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, 0,
add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, 0,
add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
/* Select all
*/
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
(GtkShortcutFunc) gtk_text_select_all,
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding (widget_class,
GDK_KEY_slash, GDK_CONTROL_MASK,
(GtkShortcutFunc) gtk_text_select_all,
NULL);
/* Unselect all
*/
gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_backslash, GDK_CONTROL_MASK,
"move-cursor",
"(iib)", GTK_MOVEMENT_VISUAL_POSITIONS, 0, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor",
"(iib)", GTK_MOVEMENT_VISUAL_POSITIONS, 0, FALSE);
/* Activate
*/
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
"activate",
NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
"activate",
NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
"activate",
NULL);
/* Deleting text */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, 0,
"delete-from-cursor",
"(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, 0,
"delete-from-cursor",
"(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
"backspace", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, 0,
"backspace",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_u, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_u, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_PARAGRAPH_ENDS, -1);
/* Make this do the same as Backspace, to help with mis-typing */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, -1);
/* Cut/copy/paste */
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, GDK_SHIFT_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_SHIFT_MASK,
"paste-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, GDK_SHIFT_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, GDK_SHIFT_MASK,
"paste-clipboard",
NULL);
/* Overwrite */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
"toggle-overwrite", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
"toggle-overwrite", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, 0,
"toggle-overwrite",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, 0,
"toggle-overwrite",
NULL);
/* Emoji */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_period, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_period, GDK_CONTROL_MASK,
"insert-emoji",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji",
NULL);
/* Undo/Redo */
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK,
"text.undo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_y, GDK_CONTROL_MASK,
"text.redo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"text.redo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK,
"text.undo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_y, GDK_CONTROL_MASK,
"text.redo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"text.redo", NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("text"));
@ -5858,11 +5882,12 @@ gtk_text_mnemonic_activate (GtkWidget *widget,
return GDK_EVENT_STOP;
}
static gboolean
gtk_text_popup_menu (GtkWidget *widget)
static void
gtk_text_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
gtk_text_do_popup (GTK_TEXT (widget), -1, -1);
return TRUE;
}
static void

View File

@ -30,7 +30,6 @@
#include <string.h>
#include "gtkadjustmentprivate.h"
#include "gtkbindings.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkdebug.h"
#include "gtkdropcontrollermotion.h"
@ -444,7 +443,9 @@ static gboolean gtk_text_view_drag_drop (GtkDropTarget *dest,
double y,
GtkTextView *text_view);
static gboolean gtk_text_view_popup_menu (GtkWidget *widget);
static void gtk_text_view_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_text_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step,
gint count,
@ -779,7 +780,7 @@ gtk_text_view_drop_scroll_leave (GtkDropControllerMotion *motion,
}
static void
add_move_binding (GtkBindingSet *binding_set,
add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
GtkMovementStep step,
@ -787,18 +788,16 @@ add_move_binding (GtkBindingSet *binding_set,
{
g_assert ((modmask & GDK_SHIFT_MASK) == 0);
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(iib)", step, count, FALSE);
/* Selection-extending version */
gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
"move-cursor", 3,
G_TYPE_ENUM, step,
G_TYPE_INT, count,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask | GDK_SHIFT_MASK,
"move-cursor",
"(iib)", step, count, TRUE);
}
static void
@ -807,7 +806,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
/* Default handlers and virtual methods
*/
@ -827,8 +825,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
widget_class->snapshot = gtk_text_view_snapshot;
widget_class->focus = gtk_text_view_focus;
widget_class->popup_menu = gtk_text_view_popup_menu;
container_class->add = gtk_text_view_add;
container_class->remove = gtk_text_view_remove;
container_class->forall = gtk_text_view_forall;
@ -1471,237 +1467,288 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_view_real_undo);
gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_view_real_redo);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_view_popup_menu);
/*
* Key bindings
*/
binding_set = gtk_binding_set_by_class (klass);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_F10, GDK_SHIFT_MASK,
"menu.popup",
NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_Menu, 0,
"menu.popup",
NULL);
/* Moving the insertion point */
add_move_binding (binding_set, GDK_KEY_Right, 0,
add_move_binding (widget_class, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
add_move_binding (widget_class, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
add_move_binding (binding_set, GDK_KEY_Left, 0,
add_move_binding (widget_class, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
add_move_binding (widget_class, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
add_move_binding (binding_set, GDK_KEY_Up, 0,
add_move_binding (widget_class, GDK_KEY_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
add_move_binding (widget_class, GDK_KEY_KP_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
add_move_binding (binding_set, GDK_KEY_Down, 0,
add_move_binding (widget_class, GDK_KEY_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
add_move_binding (widget_class, GDK_KEY_KP_Down, 0,
GTK_MOVEMENT_DISPLAY_LINES, 1);
add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Up, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Up, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, -1);
add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Down, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, 1);
add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Down, GDK_CONTROL_MASK,
GTK_MOVEMENT_PARAGRAPHS, 1);
add_move_binding (binding_set, GDK_KEY_Home, 0,
add_move_binding (widget_class, GDK_KEY_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
add_move_binding (widget_class, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, 0,
add_move_binding (widget_class, GDK_KEY_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_End, 0,
add_move_binding (widget_class, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
add_move_binding (widget_class, GDK_KEY_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0,
GTK_MOVEMENT_PAGES, -1);
add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
add_move_binding (widget_class, GDK_KEY_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0,
GTK_MOVEMENT_PAGES, 1);
add_move_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Page_Up, GDK_CONTROL_MASK,
GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
add_move_binding (binding_set, GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Page_Up, GDK_CONTROL_MASK,
GTK_MOVEMENT_HORIZONTAL_PAGES, -1);
add_move_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_Page_Down, GDK_CONTROL_MASK,
GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
add_move_binding (binding_set, GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK,
add_move_binding (widget_class, GDK_KEY_KP_Page_Down, GDK_CONTROL_MASK,
GTK_MOVEMENT_HORIZONTAL_PAGES, 1);
/* Select all */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"select-all", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_CONTROL_MASK,
"select-all",
"(b)", TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"select-all", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_slash, GDK_CONTROL_MASK,
"select-all",
"(b)", TRUE);
/* Unselect all */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
"select-all", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_backslash, GDK_CONTROL_MASK,
"select-all",
"(b)", FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"select-all", 1,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"select-all",
"(b)", FALSE);
/* Deleting text */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, 0,
"delete-from-cursor",
"(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, 0,
"delete-from-cursor",
"(ii)", GTK_DELETE_CHARS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
"backspace", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, 0,
"backspace",
NULL);
/* Make this do the same as Backspace, to help with mis-typing */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_WORD_ENDS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_PARAGRAPH_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_PARAGRAPH_ENDS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_BackSpace, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"delete-from-cursor",
"(ii)", GTK_DELETE_PARAGRAPH_ENDS, -1);
/* Cut/copy/paste */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_SHIFT_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, GDK_SHIFT_MASK,
"paste-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Delete, GDK_SHIFT_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, GDK_SHIFT_MASK,
"paste-clipboard",
NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
"cut-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Delete, GDK_SHIFT_MASK,
"cut-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard",
NULL);
/* Undo/Redo */
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK,
"text.undo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_y, GDK_CONTROL_MASK,
"text.redo", NULL);
gtk_binding_entry_add_action (binding_set, GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"text.redo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK,
"text.undo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_y, GDK_CONTROL_MASK,
"text.redo", NULL);
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"text.redo", NULL);
/* Overwrite */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
"toggle-overwrite", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
"toggle-overwrite", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Insert, 0,
"toggle-overwrite",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Insert, 0,
"toggle-overwrite",
NULL);
/* Emoji */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_period, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_period, GDK_CONTROL_MASK,
"insert-emoji",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji",
NULL);
/* Caret mode */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_F7, 0,
"toggle-cursor-visible", 0);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_F7, 0,
"toggle-cursor-visible",
NULL);
/* Control-tab focus motion */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, GDK_CONTROL_MASK,
"move-focus",
"(i)", GTK_DIR_TAB_FORWARD);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, GDK_CONTROL_MASK,
"move-focus",
"(i)", GTK_DIR_TAB_FORWARD);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-focus", 1,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-focus",
"(i)", GTK_DIR_TAB_BACKWARD);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-focus",
"(i)", GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_VIEW_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("textview"));
@ -8640,11 +8687,12 @@ gtk_text_view_do_popup (GtkTextView *text_view,
gdk_event_unref (trigger_event);
}
static gboolean
gtk_text_view_popup_menu (GtkWidget *widget)
static void
gtk_text_view_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters)
{
gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
return TRUE;
}
static void

View File

@ -22,7 +22,6 @@
#include "gtkadjustmentprivate.h"
#include "gtkbox.h"
#include "gtkbindings.h"
#include "gtkbuildable.h"
#include "gtkbutton.h"
#include "gtkcelllayout.h"
@ -54,6 +53,7 @@
#include "gtkrendericonprivate.h"
#include "gtkscrollable.h"
#include "gtksettingsprivate.h"
#include "gtkshortcutcontroller.h"
#include "gtksnapshot.h"
#include "gtkstylecontextprivate.h"
#include "gtktooltip.h"
@ -657,6 +657,11 @@ static void gtk_tree_view_size_allocate (GtkWidget *widget,
static void gtk_tree_view_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
static gboolean gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key,
guint keyval,
guint keycode,
GdkModifierType state,
GtkTreeView *tree_view);
static gboolean gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
guint keyval,
guint keycode,
@ -765,7 +770,7 @@ static void invalidate_empty_focus (GtkTreeView *tree_view);
static gboolean gtk_tree_view_is_expander_column (GtkTreeView *tree_view,
GtkTreeViewColumn *column);
static inline gboolean gtk_tree_view_draw_expanders (GtkTreeView *tree_view);
static void gtk_tree_view_add_move_binding (GtkBindingSet *binding_set,
static void gtk_tree_view_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
gboolean add_shifted_binding,
@ -999,16 +1004,9 @@ G_DEFINE_TYPE_WITH_CODE (GtkTreeView, gtk_tree_view, GTK_TYPE_CONTAINER,
static void
gtk_tree_view_class_init (GtkTreeViewClass *class)
{
GObjectClass *o_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
binding_set = gtk_binding_set_by_class (class);
o_class = (GObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
container_class = (GtkContainerClass *) class;
GObjectClass *o_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
/* GObject signals */
o_class->set_property = gtk_tree_view_set_property;
@ -1503,217 +1501,198 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
_gtk_marshal_BOOLEAN__VOIDv);
/* Key bindings */
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_Up, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Up, 0, TRUE,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Up, 0, TRUE,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_Down, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Down, 0, TRUE,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Down, 0, TRUE,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK, FALSE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_p, GDK_CONTROL_MASK, FALSE,
GTK_MOVEMENT_DISPLAY_LINES, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK, FALSE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_n, GDK_CONTROL_MASK, FALSE,
GTK_MOVEMENT_DISPLAY_LINES, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_Home, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Home, 0, TRUE,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Home, 0, TRUE,
GTK_MOVEMENT_BUFFER_ENDS, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_End, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_End, 0, TRUE,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_End, 0, TRUE,
GTK_MOVEMENT_BUFFER_ENDS, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Page_Up, 0, TRUE,
GTK_MOVEMENT_PAGES, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Page_Up, 0, TRUE,
GTK_MOVEMENT_PAGES, -1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Page_Down, 0, TRUE,
GTK_MOVEMENT_PAGES, 1);
gtk_tree_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, TRUE,
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0, TRUE,
GTK_MOVEMENT_PAGES, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0, "move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Right, 0,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0, "move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Left, 0,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0, "move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Right, 0,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0, "move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Left, 0,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Right, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Left, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Right, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, -1);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Left, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, GDK_CONTROL_MASK, "toggle-cursor-row", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, "select-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK, "select-all", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_a, GDK_CONTROL_MASK, "select-all", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_slash, GDK_CONTROL_MASK, "select-all", NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_backslash, GDK_CONTROL_MASK, "unselect-all", NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, GDK_SHIFT_MASK, "select-cursor-row", "(b)", TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", "(b)", TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, "select-cursor-row", 1,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0, "select-cursor-row", "(b)", TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0, "select-cursor-row", "(b)", TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0, "select-cursor-row", "(b)", TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0, "select-cursor-row", "(b)", TRUE);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0, "select-cursor-row", "(b)", TRUE);
/* expand and collapse rows */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_plus, 0, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_plus, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_asterisk, 0,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Multiply, 0,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_asterisk, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Multiply, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, 0,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Divide, 0,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_slash, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Divide, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, FALSE);
/* Not doable on US keyboards */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_plus, GDK_SHIFT_MASK, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Add, 0, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Add, GDK_SHIFT_MASK, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Add, GDK_SHIFT_MASK, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right,
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right,
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_plus, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Add, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Add, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Add, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", TRUE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Right, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Right, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Right, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Right, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, TRUE, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_minus, 0, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_minus, GDK_SHIFT_MASK, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Subtract, 0, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Subtract, GDK_SHIFT_MASK, "expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, TRUE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left,
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left,
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row", 3,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, FALSE,
G_TYPE_BOOLEAN, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_minus, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_minus, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Subtract, 0,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Subtract, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", TRUE, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Left, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Left, GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_Left, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_KP_Left, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"expand-collapse-cursor-row",
"(bbb)", FALSE, FALSE, TRUE);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0, "select-cursor-parent", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_BackSpace, 0, "select-cursor-parent", NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_f, GDK_CONTROL_MASK, "start-interactive-search", NULL);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_F, GDK_CONTROL_MASK, "start-interactive-search", NULL);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TREE_VIEW_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, I_("treeview"));
@ -1725,6 +1704,7 @@ gtk_tree_view_init (GtkTreeView *tree_view)
GtkCssNode *widget_node;
GtkGesture *gesture;
GtkEventController *controller;
GList *list, *controllers;
gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
gtk_widget_set_overflow (GTK_WIDGET (tree_view), GTK_OVERFLOW_HIDDEN);
@ -1786,6 +1766,24 @@ gtk_tree_view_init (GtkTreeView *tree_view)
gtk_css_node_set_state (tree_view->header_node, gtk_css_node_get_state (widget_node));
g_object_unref (tree_view->header_node);
controller = gtk_event_controller_key_new ();
g_signal_connect (controller, "key-pressed",
G_CALLBACK (gtk_tree_view_forward_controller_key_pressed), tree_view);
gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
controllers = gtk_widget_list_controllers (GTK_WIDGET (tree_view), GTK_PHASE_BUBBLE);
for (list = controllers; list; list = list->next)
{
if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
{
g_object_ref (list->data);
gtk_widget_remove_controller (GTK_WIDGET (tree_view), list->data);
gtk_widget_add_controller (GTK_WIDGET (tree_view), list->data);
break;
}
}
g_list_free (controllers);
tree_view->click_gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (tree_view->click_gesture), 0);
g_signal_connect (tree_view->click_gesture, "pressed",
@ -5312,7 +5310,6 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
{
GtkWidget *widget = GTK_WIDGET (tree_view);
GtkWidget *button;
GdkEvent *event;
if (tree_view->rubber_band_status)
{
@ -5432,16 +5429,16 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
}
}
/* Handle the keybindings. */
event = gtk_get_current_event ();
if (gtk_bindings_activate_event (G_OBJECT (widget), event))
{
gdk_event_unref (event);
return TRUE;
}
gdk_event_unref (event);
return FALSE;
}
static gboolean
gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key,
guint keyval,
guint keycode,
GdkModifierType state,
GtkTreeView *tree_view)
{
if (tree_view->search_entry_avoid_unhandled_binding)
{
tree_view->search_entry_avoid_unhandled_binding = FALSE;
@ -5487,15 +5484,6 @@ gtk_tree_view_key_controller_key_released (GtkEventControllerKey *key,
GdkModifierType state,
GtkTreeView *tree_view)
{
GdkEvent *event;
if (tree_view->rubber_band_status)
return;
/* Handle the keybindings. */
event = gtk_get_current_event ();
gtk_bindings_activate_event (G_OBJECT (tree_view), event);
gdk_event_unref (event);
}
static void
@ -8914,7 +8902,7 @@ gtk_tree_view_draw_expanders (GtkTreeView *tree_view)
}
static void
gtk_tree_view_add_move_binding (GtkBindingSet *binding_set,
gtk_tree_view_add_move_binding (GtkWidgetClass *widget_class,
guint keyval,
guint modmask,
gboolean add_shifted_binding,
@ -8922,29 +8910,29 @@ gtk_tree_view_add_move_binding (GtkBindingSet *binding_set,
gint count)
{
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
"(ii)", step, count);
if (add_shifted_binding)
gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_SHIFT_MASK,
"move-cursor",
"(ii)", step, count);
if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
return;
gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class, keyval,
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"move-cursor",
"(ii)", step, count);
gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
"move-cursor", 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK,
"move-cursor",
"(ii)", step, count);
}
static gint

View File

@ -45,6 +45,9 @@ typedef struct _GtkNative GtkNative;
typedef struct _GtkRequisition GtkRequisition;
typedef struct _GtkRoot GtkRoot;
typedef struct _GtkSettings GtkSettings;
typedef struct _GtkShortcut GtkShortcut;
typedef struct _GtkShortcutAction GtkShortcutAction;
typedef struct _GtkShortcutTrigger GtkShortcutTrigger;
typedef GdkSnapshot GtkSnapshot;
typedef struct _GtkStyleContext GtkStyleContext;
typedef struct _GtkTooltip GtkTooltip;

View File

@ -26,11 +26,9 @@
#include "gtkwidgetprivate.h"
#include "gtkaccelmapprivate.h"
#include "gtkaccelgroupprivate.h"
#include "gtkaccessible.h"
#include "gtkapplicationprivate.h"
#include "gtkbindings.h"
#include "gtkbuildable.h"
#include "gtkbuilderprivate.h"
#include "gtkcontainerprivate.h"
@ -59,6 +57,11 @@
#include "gtknativeprivate.h"
#include "gtkscrollable.h"
#include "gtksettingsprivate.h"
#include "gtkshortcut.h"
#include "gtkshortcutcontrollerprivate.h"
#include "gtkshortcutmanager.h"
#include "gtkshortcutmanagerprivate.h"
#include "gtkshortcuttrigger.h"
#include "gtksizegroup-private.h"
#include "gtksnapshotprivate.h"
#include "gtkstylecontextprivate.h"
@ -499,9 +502,6 @@ enum {
MNEMONIC_ACTIVATE,
MOVE_FOCUS,
KEYNAV_FAILED,
POPUP_MENU,
ACCEL_CLOSURES_CHANGED,
CAN_ACTIVATE_ACCEL,
QUERY_TOOLTIP,
LAST_SIGNAL
};
@ -631,8 +631,6 @@ static void gtk_widget_real_state_flags_changed (GtkWidget
static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
guint signal_id);
static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
@ -685,8 +683,6 @@ static gpointer gtk_widget_parent_class = NULL;
static guint widget_signals[LAST_SIGNAL] = { 0 };
GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
static GQuark quark_accel_path = 0;
static GQuark quark_accel_closures = 0;
static GQuark quark_pango_context = 0;
static GQuark quark_mnemonic_labels = 0;
static GQuark quark_tooltip_markup = 0;
@ -768,9 +764,29 @@ static void
gtk_widget_base_class_init (gpointer g_class)
{
GtkWidgetClass *klass = g_class;
GtkWidgetClassPrivate *priv;
klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
klass->priv->template = NULL;
priv = klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
priv->template = NULL;
if (priv->shortcuts == NULL)
{
priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
}
else
{
GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
guint i;
priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
{
GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
g_list_store_append (priv->shortcuts, shortcut);
g_object_unref (shortcut);
}
}
}
static void
@ -823,12 +839,30 @@ gtk_widget_real_grab_notify (GtkWidget *widget,
static void
gtk_widget_real_root (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GList *l;
gtk_widget_forall (widget, (GtkCallback) gtk_widget_root, NULL);
for (l = priv->event_controllers; l; l = l->next)
{
if (GTK_IS_SHORTCUT_CONTROLLER (l->data))
gtk_shortcut_controller_root (GTK_SHORTCUT_CONTROLLER (l->data));
}
}
static void
gtk_widget_real_unroot (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GList *l;
for (l = priv->event_controllers; l; l = l->next)
{
if (GTK_IS_SHORTCUT_CONTROLLER (l->data))
gtk_shortcut_controller_unroot (GTK_SHORTCUT_CONTROLLER (l->data));
}
gtk_widget_forall (widget, (GtkCallback) gtk_widget_unroot, NULL);
}
@ -836,13 +870,10 @@ static void
gtk_widget_class_init (GtkWidgetClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkBindingSet *binding_set;
g_type_class_adjust_private_offset (klass, &GtkWidget_private_offset);
gtk_widget_parent_class = g_type_class_peek_parent (klass);
quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
@ -880,7 +911,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->focus = gtk_widget_real_focus;
klass->move_focus = gtk_widget_real_move_focus;
klass->keynav_failed = gtk_widget_real_keynav_failed;
klass->can_activate_accel = gtk_widget_real_can_activate_accel;
klass->query_tooltip = gtk_widget_real_query_tooltip;
klass->css_changed = gtk_widget_real_css_changed;
@ -1621,79 +1651,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_TYPE_FROM_CLASS (klass),
_gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECTv);
/**
* GtkWidget::popup-menu:
* @widget: the object which received the signal
*
* This signal gets emitted whenever a widget should pop up a context
* menu. This usually happens through the standard key binding mechanism;
* by pressing a certain key while a widget is focused, the user can cause
* the widget to pop up a menu. For example, the #GtkEntry widget creates
* a menu with clipboard commands. See the
* [Popup Menu Migration Checklist][checklist-popup-menu]
* for an example of how to use this signal.
*
* Returns: %TRUE if a menu was activated
*/
widget_signals[POPUP_MENU] =
g_signal_new (I_("popup-menu"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
g_signal_set_va_marshaller (widget_signals[POPUP_MENU],
G_TYPE_FROM_CLASS (klass),
_gtk_marshal_BOOLEAN__VOIDv);
/**
* GtkWidget::accel-closures-changed:
* @widget: the object which received the signal.
*
* The ::accel-closures-changed signal gets emitted when accelerators for this
* widget get added, removed or changed.
*/
widget_signals[ACCEL_CLOSURES_CHANGED] =
g_signal_new (I_("accel-closures-changed"),
G_TYPE_FROM_CLASS (klass),
0,
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/**
* GtkWidget::can-activate-accel:
* @widget: the object which received the signal
* @signal_id: the ID of a signal installed on @widget
*
* Determines whether an accelerator that activates the signal
* identified by @signal_id can currently be activated.
* This signal is present to allow applications and derived
* widgets to override the default #GtkWidget handling
* for determining whether an accelerator can be activated.
*
* Returns: %TRUE if the signal can be activated.
*/
widget_signals[CAN_ACTIVATE_ACCEL] =
g_signal_new (I_("can-activate-accel"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__UINT,
G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
g_signal_set_va_marshaller (widget_signals[CAN_ACTIVATE_ACCEL],
G_TYPE_FROM_CLASS (klass),
_gtk_marshal_BOOLEAN__UINTv);
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
"popup-menu", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
"popup-menu", 0);
gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
gtk_widget_class_set_css_name (klass, I_("widget"));
}
@ -1701,7 +1658,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
static void
gtk_widget_base_class_finalize (GtkWidgetClass *klass)
{
template_data_free (klass->priv->template);
g_object_unref (klass->priv->shortcuts);
}
static void
@ -2332,6 +2291,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
GtkWidget *widget = GTK_WIDGET (instance);
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GType layout_manager_type;
GtkEventController *controller;
widget->priv = priv;
@ -2400,9 +2360,19 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_ROOT))
priv->root = (GtkRoot *) widget;
if (g_type_is_a (G_TYPE_FROM_CLASS (g_class), GTK_TYPE_SHORTCUT_MANAGER))
gtk_shortcut_manager_create_controllers (widget);
layout_manager_type = gtk_widget_class_get_layout_manager_type (g_class);
if (layout_manager_type != G_TYPE_INVALID)
gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
if (g_list_model_get_n_items (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts)) > 0)
{
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts));
gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
gtk_widget_add_controller (widget, controller);
}
}
/**
@ -4295,350 +4265,179 @@ gtk_widget_real_size_allocate (GtkWidget *widget,
{
}
static gboolean
gtk_widget_real_can_activate_accel (GtkWidget *widget,
guint signal_id)
{
GdkSurface *surface;
/* widgets must be onscreen for accels to take effect */
if (!gtk_widget_is_sensitive (widget) ||
!_gtk_widget_get_mapped (widget))
return FALSE;
surface = gtk_widget_get_surface (widget);
return gdk_surface_is_viewable (surface);
}
/**
* gtk_widget_can_activate_accel:
* @widget: a #GtkWidget
* @signal_id: the ID of a signal installed on @widget
* gtk_widget_class_add_binding: (skip)
* @widget_class: the class to add the binding to
* @keyval: key value of binding to install
* @mods: key modifier of binding to install
* @callback: the callback to call upon activation
* @format_string: GVariant format string for arguments or %NULL for
* no arguments
* @...: arguments, as given by format string.
*
* Determines whether an accelerator that activates the signal
* identified by @signal_id can currently be activated.
* This is done by emitting the #GtkWidget::can-activate-accel
* signal on @widget; if the signal isnt overridden by a
* handler or in a derived widget, then the default check is
* that the widget must be sensitive, and the widget and all
* its ancestors mapped.
* Creates a new shortcut for @widget_class that calls the given @callback
* with arguments read according to @format_string.
* The arguments and format string must be provided in the same way as
* with g_variant_new().
*
* Returns: %TRUE if the accelerator can be activated.
**/
gboolean
gtk_widget_can_activate_accel (GtkWidget *widget,
guint signal_id)
{
gboolean can_activate = FALSE;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
return can_activate;
}
typedef struct {
GClosure closure;
guint signal_id;
} AccelClosure;
static void
closure_accel_activate (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
AccelClosure *aclosure = (AccelClosure*) closure;
gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
if (can_activate)
g_signal_emit (closure->data, aclosure->signal_id, 0);
/* whether accelerator was handled */
g_value_set_boolean (return_value, can_activate);
}
static void
closures_destroy (gpointer data)
{
GSList *slist, *closures = data;
for (slist = closures; slist; slist = slist->next)
{
g_closure_invalidate (slist->data);
g_closure_unref (slist->data);
}
g_slist_free (closures);
}
static GClosure*
widget_new_accel_closure (GtkWidget *widget,
guint signal_id)
{
AccelClosure *aclosure;
GClosure *closure = NULL;
GSList *slist, *closures;
closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
for (slist = closures; slist; slist = slist->next)
if (!gtk_accel_group_from_accel_closure (slist->data))
{
/* reuse this closure */
closure = slist->data;
break;
}
if (!closure)
{
closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
closures = g_slist_prepend (closures, g_closure_ref (closure));
g_closure_sink (closure);
g_closure_set_marshal (closure, closure_accel_activate);
}
g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
aclosure = (AccelClosure*) closure;
g_assert (closure->data == widget);
g_assert (closure->marshal == closure_accel_activate);
aclosure->signal_id = signal_id;
return closure;
}
/**
* gtk_widget_add_accelerator:
* @widget: widget to install an accelerator on
* @accel_signal: widget signal to emit on accelerator activation
* @accel_group: accel group for this widget, added to its toplevel
* @accel_key: GDK keyval of the accelerator
* @accel_mods: modifier key combination of the accelerator
* @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
*
* Installs an accelerator for this @widget in @accel_group that causes
* @accel_signal to be emitted if the accelerator is activated.
* The @accel_group needs to be added to the widgets toplevel via
* gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
* Accelerators added through this function are not user changeable during
* runtime. If you want to support accelerators that can be changed by the
* user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
* gtk_menu_item_set_accel_path() instead.
*/
void
gtk_widget_add_accelerator (GtkWidget *widget,
const gchar *accel_signal,
GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods,
GtkAccelFlags accel_flags)
{
GClosure *closure;
GSignalQuery query;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (accel_signal != NULL);
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
if (!query.signal_id ||
!(query.signal_flags & G_SIGNAL_ACTION) ||
query.return_type != G_TYPE_NONE ||
query.n_params)
{
/* hmm, should be elaborate enough */
g_warning (G_STRLOC ": widget '%s' has no activatable signal \"%s\" without arguments",
G_OBJECT_TYPE_NAME (widget), accel_signal);
return;
}
closure = widget_new_accel_closure (widget, query.signal_id);
g_object_ref (widget);
/* install the accelerator. since we don't map this onto an accel_path,
* the accelerator will automatically be locked.
*/
gtk_accel_group_connect (accel_group,
accel_key,
accel_mods,
accel_flags | GTK_ACCEL_LOCKED,
closure);
g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
g_object_unref (widget);
}
/**
* gtk_widget_remove_accelerator:
* @widget: widget to install an accelerator on
* @accel_group: accel group for this widget
* @accel_key: GDK keyval of the accelerator
* @accel_mods: modifier key combination of the accelerator
*
* Removes an accelerator from @widget, previously installed with
* gtk_widget_add_accelerator().
*
* Returns: whether an accelerator was installed and could be removed
*/
gboolean
gtk_widget_remove_accelerator (GtkWidget *widget,
GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods)
{
GtkAccelGroupEntry *ag_entry;
GList *slist, *clist;
guint n;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
clist = gtk_widget_list_accel_closures (widget);
for (slist = clist; slist; slist = slist->next)
{
guint i;
for (i = 0; i < n; i++)
if (slist->data == (gpointer) ag_entry[i].closure)
{
gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
g_list_free (clist);
return is_removed;
}
}
g_list_free (clist);
g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
accel_key, accel_mods, accel_group,
G_OBJECT_TYPE_NAME (widget), widget);
return FALSE;
}
/**
* gtk_widget_list_accel_closures:
* @widget: widget to list accelerator closures for
*
* Lists the closures used by @widget for accelerator group connections
* with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
* The closures can be used to monitor accelerator changes on @widget,
* by connecting to the @GtkAccelGroup::accel-changed signal of the
* #GtkAccelGroup of a closure which can be found out with
* gtk_accel_group_from_accel_closure().
*
* Returns: (transfer container) (element-type GClosure):
* a newly allocated #GList of closures
*/
GList*
gtk_widget_list_accel_closures (GtkWidget *widget)
{
GSList *slist;
GList *clist = NULL;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
if (gtk_accel_group_from_accel_closure (slist->data))
clist = g_list_prepend (clist, slist->data);
return clist;
}
typedef struct {
GQuark path_quark;
GtkAccelGroup *accel_group;
GClosure *closure;
} AccelPath;
static void
destroy_accel_path (gpointer data)
{
AccelPath *apath = data;
gtk_accel_group_disconnect (apath->accel_group, apath->closure);
/* closures_destroy takes care of unrefing the closure */
g_object_unref (apath->accel_group);
g_slice_free (AccelPath, apath);
}
/**
* gtk_widget_set_accel_path:
* @widget: a #GtkWidget
* @accel_path: (allow-none): path used to look up the accelerator
* @accel_group: (allow-none): a #GtkAccelGroup.
*
* Given an accelerator group, @accel_group, and an accelerator path,
* @accel_path, sets up an accelerator in @accel_group so whenever the
* key binding that is defined for @accel_path is pressed, @widget
* will be activated. This removes any accelerators (for any
* accelerator group) installed by previous calls to
* gtk_widget_set_accel_path(). Associating accelerators with
* paths allows them to be modified by the user and the modifications
* to be saved for future use. (See gtk_accel_map_save().)
*
* This function is a low level function that would most likely
* be used by a menu creation system.
*
* If you only want to
* set up accelerators on menu items gtk_menu_item_set_accel_path()
* provides a somewhat more convenient interface.
*
* Note that @accel_path string will be stored in a #GQuark. Therefore, if you
* pass a static string, you can save some memory by interning it first with
* g_intern_static_string().
* This function is a convenience wrapper around
* gtk_widget_class_add_shortcut() and must be called during class
* initialization. It does not provide for user_data, if you need that,
* you will have to use gtk_widget_class_add_shortcut() with a custom
* shortcut.
**/
void
gtk_widget_set_accel_path (GtkWidget *widget,
const gchar *accel_path,
GtkAccelGroup *accel_group)
gtk_widget_class_add_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mods,
GtkShortcutFunc func,
const gchar *format_string,
...)
{
AccelPath *apath;
GtkShortcut *shortcut;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
if (accel_path)
shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, mods),
gtk_callback_action_new (func, NULL, NULL));
if (format_string)
{
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
gtk_accel_map_add_entry (accel_path, 0, 0);
apath = g_slice_new (AccelPath);
apath->accel_group = g_object_ref (accel_group);
apath->path_quark = g_quark_from_string (accel_path);
apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
va_list args;
va_start (args, format_string);
gtk_shortcut_set_arguments (shortcut,
g_variant_new_va (format_string, NULL, &args));
va_end (args);
}
else
apath = NULL;
/* also removes possible old settings */
g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
gtk_widget_class_add_shortcut (widget_class, shortcut);
if (apath)
gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
g_object_unref (shortcut);
}
const gchar*
_gtk_widget_get_accel_path (GtkWidget *widget,
gboolean *locked)
/**
* gtk_widget_class_add_binding_signal: (skip)
* @widget_class: the class to add the binding to
* @keyval: key value of binding to install
* @mods: key modifier of binding to install
* @signal: the signal to execute
* @format_string: GVariant format string for arguments or %NULL for
* no arguments
* @...: arguments, as given by format string.
*
* Creates a new shortcut for @widget_class that emits the given action
* @signal with arguments read according to @format_string.
* The arguments and format string must be provided in the same way as
* with g_variant_new().
*
* This function is a convenience wrapper around
* gtk_widget_class_add_shortcut() and must be called during class
* initialization.
*/
void
gtk_widget_class_add_binding_signal (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mods,
const gchar *signal,
const gchar *format_string,
...)
{
AccelPath *apath;
GtkShortcut *shortcut;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
g_return_if_fail (g_signal_lookup (signal, G_TYPE_FROM_CLASS (widget_class)));
/* XXX: validate variant format for signal */
apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
if (locked)
*locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
return apath ? g_quark_to_string (apath->path_quark) : NULL;
shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, mods),
gtk_signal_action_new (signal));
if (format_string)
{
va_list args;
va_start (args, format_string);
gtk_shortcut_set_arguments (shortcut,
g_variant_new_va (format_string, NULL, &args));
va_end (args);
}
gtk_widget_class_add_shortcut (widget_class, shortcut);
g_object_unref (shortcut);
}
/**
* gtk_widget_class_add_binding_action: (skip)
* @widget_class: the class to add the binding to
* @keyval: key value of binding to install
* @mods: key modifier of binding to install
* @action_name: the action to activate
* @format_string: GVariant format string for arguments or %NULL for
* no arguments
* @...: arguments, as given by format string.
*
* Creates a new shortcut for @widget_class that activates the given
* @action_name with arguments read according to @format_string.
* The arguments and format string must be provided in the same way as
* with g_variant_new().
*
* This function is a convenience wrapper around
* gtk_widget_class_add_shortcut() and must be called during class
* initialization.
*/
void
gtk_widget_class_add_binding_action (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mods,
const gchar *action_name,
const gchar *format_string,
...)
{
GtkShortcut *shortcut;
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
/* XXX: validate variant format for action */
shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, mods),
gtk_named_action_new (action_name));
if (format_string)
{
va_list args;
va_start (args, format_string);
gtk_shortcut_set_arguments (shortcut,
g_variant_new_va (format_string, NULL, &args));
va_end (args);
}
gtk_widget_class_add_shortcut (widget_class, shortcut);
g_object_unref (shortcut);
}
/**
* gtk_widget_class_add_shortcut:
* @widget_class: the class to add the shortcut to
* @shortcut: (transfer none): the #GtkShortcut to add
*
* Installs a shortcut in @widget_class. Every instance created for
* @widget_class or its subclasses will inherit this shortcut and
* trigger it.
*
* Shortcuts added this way will be triggered in the @GTK_PHASE_BUBBLE
* phase, which means they may also trigger if child widgets have focus.
*
* This function must only be used in class initialization functions
* otherwise it is not guaranteed that the shortcut will be installed.
**/
void
gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
GtkShortcut *shortcut)
{
GtkWidgetClassPrivate *priv;
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
g_return_if_fail (GTK_IS_SHORTCUT (shortcut));
priv = widget_class->priv;
g_list_store_append (priv->shortcuts, shortcut);
}
/**
@ -4894,11 +4693,6 @@ gtk_widget_event (GtkWidget *widget,
if (return_val == FALSE)
return_val |= gtk_widget_run_controllers (widget, event, target, x, y, GTK_PHASE_BUBBLE);
if (return_val == FALSE &&
(gdk_event_get_event_type (event) == GDK_KEY_PRESS ||
gdk_event_get_event_type (event) == GDK_KEY_RELEASE))
return_val |= gtk_bindings_activate_event (G_OBJECT (widget), event);
return return_val;
}
@ -7546,10 +7340,6 @@ gtk_widget_real_destroy (GtkWidget *object)
priv->accessible = NULL;
}
/* wipe accelerator closures (keep order) */
g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
/* Callers of add_mnemonic_label() should disconnect on ::destroy */
g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
@ -8985,90 +8775,6 @@ static const GtkBuildableParser accessibility_parser =
accessibility_text,
};
typedef struct
{
GObject *object;
GtkBuilder *builder;
guint key;
guint modifiers;
gchar *signal;
} AccelGroupParserData;
static void
accel_group_start_element (GtkBuildableParseContext *context,
const gchar *element_name,
const gchar **names,
const gchar **values,
gpointer user_data,
GError **error)
{
AccelGroupParserData *data = (AccelGroupParserData*)user_data;
if (strcmp (element_name, "accelerator") == 0)
{
const gchar *key_str = NULL;
const gchar *signal = NULL;
const gchar *modifiers_str = NULL;
guint key = 0;
guint modifiers = 0;
if (!_gtk_builder_check_parent (data->builder, context, "object", error))
return;
if (!g_markup_collect_attributes (element_name, names, values, error,
G_MARKUP_COLLECT_STRING, "key", &key_str,
G_MARKUP_COLLECT_STRING, "signal", &signal,
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "modifiers", &modifiers_str,
G_MARKUP_COLLECT_INVALID))
{
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
key = gdk_keyval_from_name (key_str);
if (key == 0)
{
g_set_error (error,
GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_VALUE,
"Could not parse key '%s'", key_str);
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
if (modifiers_str != NULL)
{
GFlagsValue aliases[2] = {
{ 0, "primary", "primary" },
{ 0, NULL, NULL }
};
aliases[0].value = _gtk_get_primary_accel_mod ();
if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE, aliases,
modifiers_str, &modifiers, error))
{
_gtk_builder_prefix_error (data->builder, context, error);
return;
}
}
data->key = key;
data->modifiers = modifiers;
data->signal = g_strdup (signal);
}
else
{
_gtk_builder_error_unhandled_tag (data->builder, context,
"GtkWidget", element_name,
error);
}
}
static const GtkBuildableParser accel_group_parser =
{
accel_group_start_element,
};
typedef struct
{
GtkBuilder *builder;
@ -9272,20 +8978,6 @@ gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuildableParser *parser,
gpointer *parser_data)
{
if (strcmp (tagname, "accelerator") == 0)
{
AccelGroupParserData *data;
data = g_slice_new0 (AccelGroupParserData);
data->object = (GObject *)g_object_ref (buildable);
data->builder = builder;
*parser = accel_group_parser;
*parser_data = data;
return TRUE;
}
if (strcmp (tagname, "accessibility") == 0)
{
AccessibilitySubParserData *data;
@ -9338,45 +9030,6 @@ gtk_widget_buildable_custom_tag_end (GtkBuildable *buildable,
{
}
void
_gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
GtkWidget *toplevel,
gpointer user_data)
{
AccelGroupParserData *accel_data;
GSList *accel_groups;
GtkAccelGroup *accel_group;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_WIDGET (toplevel));
g_return_if_fail (user_data != NULL);
accel_data = (AccelGroupParserData*)user_data;
accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
if (g_slist_length (accel_groups) == 0)
{
accel_group = gtk_accel_group_new ();
if (GTK_IS_WINDOW (toplevel))
gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
}
else
{
g_assert (g_slist_length (accel_groups) == 1);
accel_group = g_slist_nth_data (accel_groups, 0);
}
gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
accel_data->signal,
accel_group,
accel_data->key,
accel_data->modifiers,
GTK_ACCEL_VISIBLE);
g_object_unref (accel_data->object);
g_free (accel_data->signal);
g_slice_free (AccelGroupParserData, accel_data);
}
static void
gtk_widget_buildable_finish_layout_properties (GtkWidget *widget,
GtkWidget *parent,
@ -9450,19 +9103,7 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
const gchar *tagname,
gpointer user_data)
{
if (strcmp (tagname, "accelerator") == 0)
{
AccelGroupParserData *accel_data;
GtkRoot *root;
accel_data = (AccelGroupParserData*)user_data;
g_assert (accel_data->object);
root = _gtk_widget_get_root (GTK_WIDGET (accel_data->object));
_gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), GTK_WIDGET (root), user_data);
}
else if (strcmp (tagname, "accessibility") == 0)
if (strcmp (tagname, "accessibility") == 0)
{
AccessibilitySubParserData *a11y_data;
@ -11833,6 +11474,24 @@ gtk_widget_reset_controllers (GtkWidget *widget)
}
}
GList *
gtk_widget_list_controllers (GtkWidget *widget,
GtkPropagationPhase phase)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GList *res = NULL, *l;
for (l = priv->event_controllers; l; l = l->next)
{
GtkEventController *controller = l->data;
if (gtk_event_controller_get_propagation_phase (controller) == phase)
res = g_list_prepend (res, controller);
}
return g_list_reverse (res);
}
static inline void
gtk_widget_maybe_add_debug_render_nodes (GtkWidget *widget,
GtkSnapshot *snapshot)

View File

@ -33,6 +33,8 @@
#include <gsk/gsk.h>
#include <gtk/gtkaccelgroup.h>
#include <gtk/gtkborder.h>
#include <gtk/gtkshortcut.h>
#include <gtk/gtkshortcutaction.h>
#include <gtk/gtktypes.h>
#include <atk/atk.h>
@ -374,23 +376,32 @@ GDK_AVAILABLE_IN_ALL
GType gtk_widget_class_get_layout_manager_type (GtkWidgetClass *widget_class);
GDK_AVAILABLE_IN_ALL
void gtk_widget_add_accelerator (GtkWidget *widget,
const gchar *accel_signal,
GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods,
GtkAccelFlags accel_flags);
void gtk_widget_class_add_binding (GtkWidgetClass *widget_class,
guint keyval,
GdkModifierType mods,
GtkShortcutFunc callback,
const gchar *format_string,
...);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_remove_accelerator (GtkWidget *widget,
GtkAccelGroup *accel_group,
guint accel_key,
GdkModifierType accel_mods);
void gtk_widget_class_add_binding_signal
(GtkWidgetClass *widget_class,
GdkModifierType mods,
guint keyval,
const gchar *signal,
const gchar *format_string,
...);
GDK_AVAILABLE_IN_ALL
void gtk_widget_set_accel_path (GtkWidget *widget,
const gchar *accel_path,
GtkAccelGroup *accel_group);
void gtk_widget_class_add_binding_action
(GtkWidgetClass *widget_class,
GdkModifierType mods,
guint keyval,
const gchar *action_name,
const gchar *format_string,
...);
GDK_AVAILABLE_IN_ALL
GList* gtk_widget_list_accel_closures (GtkWidget *widget);
void gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
GtkShortcut *shortcut);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_can_activate_accel (GtkWidget *widget,
guint signal_id);

View File

@ -211,6 +211,7 @@ typedef struct
struct _GtkWidgetClassPrivate
{
GtkWidgetTemplate *template;
GListStore *shortcuts;
GType accessible_type;
AtkRole accessible_role;
GQuark css_name;
@ -247,9 +248,6 @@ void _gtk_widget_add_attached_window (GtkWidget *widget,
void _gtk_widget_remove_attached_window (GtkWidget *widget,
GtkWindow *window);
const gchar* _gtk_widget_get_accel_path (GtkWidget *widget,
gboolean *locked);
AtkObject * _gtk_widget_peek_accessible (GtkWidget *widget);
void _gtk_widget_set_has_default (GtkWidget *widget,
@ -275,9 +273,6 @@ void _gtk_widget_synthesize_crossing (GtkWidget *fro
GdkDevice *device,
GdkCrossingMode mode);
void _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
GtkWidget *toplevel,
gpointer user_data);
GtkStyleContext * _gtk_widget_peek_style_context (GtkWidget *widget);
gboolean _gtk_widget_captured_event (GtkWidget *widget,
@ -300,6 +295,9 @@ gboolean gtk_widget_has_size_request (GtkWidget *widget);
void gtk_widget_reset_controllers (GtkWidget *widget);
GList * gtk_widget_list_controllers (GtkWidget *widget,
GtkPropagationPhase phase);
gboolean gtk_widget_query_tooltip (GtkWidget *widget,
gint x,
gint y,

File diff suppressed because it is too large Load Diff

View File

@ -97,12 +97,6 @@ GDK_AVAILABLE_IN_ALL
void gtk_window_set_startup_id (GtkWindow *window,
const gchar *startup_id);
GDK_AVAILABLE_IN_ALL
void gtk_window_add_accel_group (GtkWindow *window,
GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
void gtk_window_remove_accel_group (GtkWindow *window,
GtkAccelGroup *accel_group);
GDK_AVAILABLE_IN_ALL
void gtk_window_set_focus (GtkWindow *window,
GtkWidget *focus);
GDK_AVAILABLE_IN_ALL
@ -190,31 +184,6 @@ GDK_AVAILABLE_IN_ALL
void gtk_window_set_has_user_ref_count (GtkWindow *window,
gboolean setting);
GDK_AVAILABLE_IN_ALL
void gtk_window_add_mnemonic (GtkWindow *window,
guint keyval,
GtkWidget *target);
GDK_AVAILABLE_IN_ALL
void gtk_window_remove_mnemonic (GtkWindow *window,
guint keyval,
GtkWidget *target);
GDK_AVAILABLE_IN_ALL
gboolean gtk_window_mnemonic_activate (GtkWindow *window,
guint keyval,
GdkModifierType modifier);
GDK_AVAILABLE_IN_ALL
void gtk_window_set_mnemonic_modifier (GtkWindow *window,
GdkModifierType modifier);
GDK_AVAILABLE_IN_ALL
GdkModifierType gtk_window_get_mnemonic_modifier (GtkWindow *window);
GDK_AVAILABLE_IN_ALL
gboolean gtk_window_activate_key (GtkWindow *window,
GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gtk_window_propagate_key_event (GtkWindow *window,
GdkEvent *event);
GDK_AVAILABLE_IN_ALL
void gtk_window_present (GtkWindow *window);
GDK_AVAILABLE_IN_ALL

View File

@ -56,7 +56,6 @@ void gtk_window_check_resize (GtkWindow *self);
typedef void (*GtkWindowKeysForeachFunc) (GtkWindow *window,
guint keyval,
GdkModifierType modifiers,
gboolean is_mnemonic,
gpointer data);
gboolean gtk_window_emit_close_request (GtkWindow *window);

View File

@ -40,6 +40,7 @@
#include "prop-list.h"
#include "recorder.h"
#include "resource-list.h"
#include "shortcuts.h"
#include "size-groups.h"
#include "statistics.h"
#include "visual.h"
@ -74,6 +75,7 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_RECORDER);
g_type_ensure (GTK_TYPE_INSPECTOR_RESOURCE_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_SHORTCUTS);
g_type_ensure (GTK_TYPE_INSPECTOR_SIZE_GROUPS);
g_type_ensure (GTK_TYPE_INSPECTOR_STATISTICS);
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);

View File

@ -28,6 +28,7 @@ inspector_sources = files(
'recording.c',
'renderrecording.c',
'resource-list.c',
'shortcuts.c',
'size-groups.c',
'startrecording.c',
'statistics.c',

158
gtk/inspector/shortcuts.c Normal file
View File

@ -0,0 +1,158 @@
/*
* Copyright (c) 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include "shortcuts.h"
#include "gtklabel.h"
#include "gtklistbox.h"
#include "gtksizegroup.h"
#include "gtkstack.h"
#include "gtkshortcut.h"
#include "gtkshortcuttrigger.h"
#include "gtkshortcutcontroller.h"
struct _GtkInspectorShortcuts
{
GtkWidget parent;
GtkWidget *box;
GtkWidget *list;
GtkSizeGroup *trigger;
GtkSizeGroup *action;
};
G_DEFINE_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK_TYPE_WIDGET)
static void
gtk_inspector_shortcuts_init (GtkInspectorShortcuts *sl)
{
gtk_widget_init_template (GTK_WIDGET (sl));
}
static GtkWidget *
create_row (gpointer item,
gpointer user_data)
{
GtkShortcut *shortcut = GTK_SHORTCUT (item);
GtkInspectorShortcuts *sl = GTK_INSPECTOR_SHORTCUTS (user_data);
GtkShortcutTrigger *trigger;
GtkShortcutAction *action;
char *s;
GtkWidget *row;
GtkWidget *label;
trigger = gtk_shortcut_get_trigger (shortcut);
action = gtk_shortcut_get_action (shortcut);
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
s = gtk_shortcut_trigger_to_string (trigger);
label = gtk_label_new (s);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
g_free (s);
gtk_container_add (GTK_CONTAINER (row), label);
gtk_size_group_add_widget (sl->trigger, label);
s = gtk_shortcut_action_to_string (action);
label = gtk_label_new (s);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
g_free (s);
gtk_container_add (GTK_CONTAINER (row), label);
gtk_size_group_add_widget (sl->action, label);
return row;
}
void
gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
GObject *object)
{
GtkWidget *stack;
GtkStackPage *page;
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
if (GTK_IS_SHORTCUT_CONTROLLER (object))
{
g_object_set (page, "visible", TRUE, NULL);
gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
G_LIST_MODEL (object),
create_row,
sl,
NULL);
}
else
{
g_object_set (page, "visible", FALSE, NULL);
gtk_list_box_bind_model (GTK_LIST_BOX (sl->list),
NULL,
NULL,
NULL,
NULL);
}
}
static void
gtk_inspector_shortcuts_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget);
gtk_widget_measure (shortcuts->box,
orientation,
for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_inspector_shortcuts_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkInspectorShortcuts *shortcuts = GTK_INSPECTOR_SHORTCUTS (widget);
gtk_widget_size_allocate (shortcuts->box,
&(GtkAllocation) { 0, 0, width, height },
baseline);
}
static void
gtk_inspector_shortcuts_class_init (GtkInspectorShortcutsClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->measure = gtk_inspector_shortcuts_measure;
widget_class->size_allocate = gtk_inspector_shortcuts_size_allocate;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/shortcuts.ui");
gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, box);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, list);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, trigger);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorShortcuts, action);
}

View File

@ -1,5 +1,5 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2011 Red Hat, Inc.
/*
* Copyright (c) 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -15,16 +15,17 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_BINDINGS_PRIVATE_H__
#define __GTK_BINDINGS_PRIVATE_H__
#ifndef _GTK_INSPECTOR_SHORTCUTS_H_
#define _GTK_INSPECTOR_SHORTCUTS_H_
#include "gtkbindings.h"
#include <gtk/gtkbox.h>
G_BEGIN_DECLS
#define GTK_TYPE_INSPECTOR_SHORTCUTS (gtk_inspector_shortcuts_get_type ())
guint _gtk_binding_parse_binding (GScanner *scanner);
void _gtk_binding_reset_parsed (void);
G_DECLARE_FINAL_TYPE (GtkInspectorShortcuts, gtk_inspector_shortcuts, GTK, INSPECTOR_SHORTCUTS, GtkWidget)
G_END_DECLS
#endif /* __GTK_BINDINGS_PRIVATE_H__ */
void gtk_inspector_shortcuts_set_object (GtkInspectorShortcuts *sl,
GObject *object);
#endif

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<template class="GtkInspectorShortcuts" parent="GtkWidget">
<style>
<class name="view"/>
</style>
<child>
<object class="GtkBox" id="box">
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<style>
<class name="header"/>
</style>
<child>
<object class="GtkLabel" id="trigger_heading">
<property name="label" translatable="yes">Trigger</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="action_heading">
<property name="label" translatable="yes">Action</property>
<property name="xalign">0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<child>
<object class="GtkListBox" id="list">
<style>
<class name="list"/>
</style>
<property name="selection-mode">none</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkSizeGroup" id="trigger">
<property name="mode">horizontal</property>
<widgets>
<widget name="trigger_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="action">
<property name="mode">horizontal</property>
<widgets>
<widget name="action_heading"/>
</widgets>
</object>
</interface>

View File

@ -37,6 +37,7 @@
#include "size-groups.h"
#include "data-list.h"
#include "actions.h"
#include "shortcuts.h"
#include "menu.h"
#include "misc-info.h"
#include "magnifier.h"
@ -91,6 +92,7 @@ set_selected_object (GtkInspectorWindow *iw,
gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
gtk_inspector_shortcuts_set_object (GTK_INSPECTOR_SHORTCUTS (iw->shortcuts), selected);
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
gtk_inspector_controllers_set_object (GTK_INSPECTOR_CONTROLLERS (iw->controllers), selected);
gtk_inspector_magnifier_set_object (GTK_INSPECTOR_MAGNIFIER (iw->magnifier), selected);
@ -421,6 +423,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, shortcuts);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);

Some files were not shown because too many files have changed in this diff Show More