1 | /* gtkcelleditable.c |
2 | * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | /** |
19 | * GtkCellEditable: |
20 | * |
21 | * Interface for widgets that can be used for editing cells |
22 | * |
23 | * The `GtkCellEditable` interface must be implemented for widgets to be usable |
24 | * to edit the contents of a `GtkTreeView` cell. It provides a way to specify how |
25 | * temporary widgets should be configured for editing, get the new value, etc. |
26 | */ |
27 | |
28 | #include "config.h" |
29 | #include "gtkcelleditable.h" |
30 | #include "gtkmarshalers.h" |
31 | #include "gtkprivate.h" |
32 | #include "gtkintl.h" |
33 | |
34 | |
35 | typedef GtkCellEditableIface GtkCellEditableInterface; |
36 | G_DEFINE_INTERFACE(GtkCellEditable, gtk_cell_editable, GTK_TYPE_WIDGET) |
37 | |
38 | static void |
39 | gtk_cell_editable_default_init (GtkCellEditableInterface *iface) |
40 | { |
41 | /** |
42 | * GtkCellEditable:editing-canceled: |
43 | * |
44 | * Indicates whether editing on the cell has been canceled. |
45 | */ |
46 | g_object_interface_install_property (g_iface: iface, |
47 | pspec: g_param_spec_boolean (name: "editing-canceled" , |
48 | P_("Editing Canceled" ), |
49 | P_("Indicates that editing has been canceled" ), |
50 | FALSE, |
51 | GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
52 | |
53 | /** |
54 | * GtkCellEditable::editing-done: |
55 | * @cell_editable: the object on which the signal was emitted |
56 | * |
57 | * This signal is a sign for the cell renderer to update its |
58 | * value from the @cell_editable. |
59 | * |
60 | * Implementations of `GtkCellEditable` are responsible for |
61 | * emitting this signal when they are done editing, e.g. |
62 | * `GtkEntry` emits this signal when the user presses Enter. Typical things to |
63 | * do in a handler for ::editing-done are to capture the edited value, |
64 | * disconnect the @cell_editable from signals on the `GtkCellRenderer`, etc. |
65 | * |
66 | * gtk_cell_editable_editing_done() is a convenience method |
67 | * for emitting `GtkCellEditable::editing-done`. |
68 | */ |
69 | g_signal_new (I_("editing-done" ), |
70 | GTK_TYPE_CELL_EDITABLE, |
71 | signal_flags: G_SIGNAL_RUN_LAST, |
72 | G_STRUCT_OFFSET (GtkCellEditableIface, editing_done), |
73 | NULL, NULL, |
74 | NULL, |
75 | G_TYPE_NONE, n_params: 0); |
76 | |
77 | /** |
78 | * GtkCellEditable::remove-widget: |
79 | * @cell_editable: the object on which the signal was emitted |
80 | * |
81 | * This signal is meant to indicate that the cell is finished |
82 | * editing, and the @cell_editable widget is being removed and may |
83 | * subsequently be destroyed. |
84 | * |
85 | * Implementations of `GtkCellEditable` are responsible for |
86 | * emitting this signal when they are done editing. It must |
87 | * be emitted after the `GtkCellEditable::editing-done` signal, |
88 | * to give the cell renderer a chance to update the cell's value |
89 | * before the widget is removed. |
90 | * |
91 | * gtk_cell_editable_remove_widget() is a convenience method |
92 | * for emitting `GtkCellEditable::remove-widget`. |
93 | */ |
94 | g_signal_new (I_("remove-widget" ), |
95 | GTK_TYPE_CELL_EDITABLE, |
96 | signal_flags: G_SIGNAL_RUN_LAST, |
97 | G_STRUCT_OFFSET (GtkCellEditableIface, remove_widget), |
98 | NULL, NULL, |
99 | NULL, |
100 | G_TYPE_NONE, n_params: 0); |
101 | } |
102 | |
103 | /** |
104 | * gtk_cell_editable_start_editing: |
105 | * @cell_editable: A `GtkCellEditable` |
106 | * @event: (nullable): The `GdkEvent` that began the editing process, or |
107 | * %NULL if editing was initiated programmatically |
108 | * |
109 | * Begins editing on a @cell_editable. |
110 | * |
111 | * The `GtkCellRenderer` for the cell creates and returns a `GtkCellEditable` from |
112 | * gtk_cell_renderer_start_editing(), configured for the `GtkCellRenderer` type. |
113 | * |
114 | * gtk_cell_editable_start_editing() can then set up @cell_editable suitably for |
115 | * editing a cell, e.g. making the Esc key emit `GtkCellEditable::editing-done`. |
116 | * |
117 | * Note that the @cell_editable is created on-demand for the current edit; its |
118 | * lifetime is temporary and does not persist across other edits and/or cells. |
119 | **/ |
120 | void |
121 | gtk_cell_editable_start_editing (GtkCellEditable *cell_editable, |
122 | GdkEvent *event) |
123 | { |
124 | g_return_if_fail (GTK_IS_CELL_EDITABLE (cell_editable)); |
125 | |
126 | (* GTK_CELL_EDITABLE_GET_IFACE (cell_editable)->start_editing) (cell_editable, event); |
127 | } |
128 | |
129 | /** |
130 | * gtk_cell_editable_editing_done: |
131 | * @cell_editable: A `GtkCellEditable` |
132 | * |
133 | * Emits the `GtkCellEditable::editing-done` signal. |
134 | */ |
135 | void |
136 | gtk_cell_editable_editing_done (GtkCellEditable *cell_editable) |
137 | { |
138 | g_return_if_fail (GTK_IS_CELL_EDITABLE (cell_editable)); |
139 | |
140 | g_signal_emit_by_name (instance: cell_editable, detailed_signal: "editing-done" ); |
141 | } |
142 | |
143 | /** |
144 | * gtk_cell_editable_remove_widget: |
145 | * @cell_editable: A `GtkCellEditable` |
146 | * |
147 | * Emits the `GtkCellEditable::remove-widget` signal. |
148 | **/ |
149 | void |
150 | gtk_cell_editable_remove_widget (GtkCellEditable *cell_editable) |
151 | { |
152 | g_return_if_fail (GTK_IS_CELL_EDITABLE (cell_editable)); |
153 | |
154 | g_signal_emit_by_name (instance: cell_editable, detailed_signal: "remove-widget" ); |
155 | } |
156 | |