32
34
gulong notify_back_handler;
33
35
gulong notify_font_handler;
34
36
XpadTextBuffer *buffer;
37
XpadSettings *settings;
37
G_DEFINE_TYPE_WITH_PRIVATE(XpadTextView, xpad_text_view, GTK_TYPE_TEXT_VIEW)
41
G_DEFINE_TYPE_WITH_PRIVATE (XpadTextView, xpad_text_view, GTK_TYPE_TEXT_VIEW)
39
43
static void xpad_text_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
40
44
static void xpad_text_view_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
45
static void xpad_text_view_constructed (GObject *object);
41
46
static void xpad_text_view_dispose (GObject *object);
42
47
static void xpad_text_view_finalize (GObject *object);
43
48
static void xpad_text_view_realize (XpadTextView *widget);
44
static gboolean xpad_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event);
45
static gboolean xpad_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event);
49
static gboolean xpad_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event, XpadSettings *settings);
50
static gboolean xpad_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event, XpadSettings *settings);
46
51
static void xpad_text_view_notify_edit_lock (XpadTextView *view);
47
52
static void xpad_text_view_notify_editable (XpadTextView *view);
48
53
static void xpad_text_view_notify_fontname (XpadTextView *view);
68
77
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
79
gobject_class->constructed = xpad_text_view_constructed;
70
80
gobject_class->dispose = xpad_text_view_dispose;
71
81
gobject_class->finalize = xpad_text_view_finalize;
72
82
gobject_class->set_property = xpad_text_view_set_property;
73
83
gobject_class->get_property = xpad_text_view_get_property;
77
g_object_class_install_property (gobject_class,
78
PROP_FOLLOW_FONT_STYLE,
79
g_param_spec_boolean ("follow-font-style",
81
"Whether to use the default xpad font style",
85
g_object_class_install_property (gobject_class,
86
PROP_FOLLOW_COLOR_STYLE,
87
g_param_spec_boolean ("follow-color-style",
89
"Whether to use the default xpad color style",
85
obj_prop[PROP_SETTINGS] = g_param_spec_pointer ("settings", "Xpad settings", "Xpad global settings", G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
86
obj_prop[PROP_PAD] = g_param_spec_pointer ("pad", "Pad", "Pad connected to this textview", G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
87
obj_prop[PROP_FOLLOW_FONT_STYLE] = g_param_spec_boolean ("follow-font-style", "Follow font style", "Whether to use the default xpad font style", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
88
obj_prop[PROP_FOLLOW_COLOR_STYLE] = g_param_spec_boolean ("follow-color-style", "Follow color style", "Whether to use the default xpad color style", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
90
g_object_class_install_properties (gobject_class, N_PROPERTIES, obj_prop);
95
94
xpad_text_view_init (XpadTextView *view)
99
view->priv = xpad_text_view_get_instance_private(view);
101
view->priv->follow_font_style = TRUE;
102
view->priv->follow_color_style = TRUE;
104
view->priv->buffer = xpad_text_buffer_new();
96
view->priv = xpad_text_view_get_instance_private (view);
99
static void xpad_text_view_constructed (GObject *object)
101
XpadTextView *view = XPAD_TEXT_VIEW (object);
103
view->priv->buffer = xpad_text_buffer_new (view->priv->pad);
105
105
gtk_text_view_set_buffer (GTK_TEXT_VIEW (view), GTK_TEXT_BUFFER (view->priv->buffer));
107
106
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
108
107
gtk_container_set_border_width (GTK_CONTAINER (view), 5);
110
name = g_strdup_printf ("%p", (void *) view);
111
gtk_widget_set_name (GTK_WIDGET (view), name);
114
g_signal_connect (view, "button-press-event", G_CALLBACK (xpad_text_view_button_press_event), NULL);
115
g_signal_connect_after (view, "focus-out-event", G_CALLBACK (xpad_text_view_focus_out_event), NULL);
108
gtk_widget_set_name (GTK_WIDGET (view), g_strdup_printf ("%p", (void *) view));
110
g_signal_connect (view, "button-press-event", G_CALLBACK (xpad_text_view_button_press_event), view->priv->settings);
111
g_signal_connect_after (view, "focus-out-event", G_CALLBACK (xpad_text_view_focus_out_event), view->priv->settings);
116
112
g_signal_connect (view, "realize", G_CALLBACK (xpad_text_view_realize), NULL);
117
113
g_signal_connect (view, "notify::editable", G_CALLBACK (xpad_text_view_notify_editable), NULL);
118
g_signal_connect_swapped (xpad_global_settings, "notify::edit-lock", G_CALLBACK (xpad_text_view_notify_edit_lock), view);
119
view->priv->notify_font_handler = g_signal_connect_swapped (xpad_global_settings, "notify::fontname", G_CALLBACK (xpad_text_view_notify_fontname), view);
120
view->priv->notify_text_handler = g_signal_connect_swapped (xpad_global_settings, "notify::text-color", G_CALLBACK (xpad_text_view_notify_colors), view);
121
view->priv->notify_back_handler = g_signal_connect_swapped (xpad_global_settings, "notify::back-color", G_CALLBACK (xpad_text_view_notify_colors), view);
122
xpad_text_view_notify_colors (view);
123
xpad_text_view_notify_fontname (view);
114
g_signal_connect_swapped (view->priv->settings, "notify::edit-lock", G_CALLBACK (xpad_text_view_notify_edit_lock), view);
116
view->priv->notify_font_handler = g_signal_connect_swapped (view->priv->settings, "notify::fontname", G_CALLBACK (xpad_text_view_notify_fontname), view);
117
view->priv->notify_text_handler = g_signal_connect_swapped (view->priv->settings, "notify::text-color", G_CALLBACK (xpad_text_view_notify_colors), view);
118
view->priv->notify_back_handler = g_signal_connect_swapped (view->priv->settings, "notify::back-color", G_CALLBACK (xpad_text_view_notify_colors), view);
120
g_signal_handler_block (view->priv->settings, view->priv->notify_font_handler);
150
156
xpad_text_view_realize (XpadTextView *view)
152
158
gboolean edit_lock;
153
g_object_get (xpad_global_settings, "edit-lock", &edit_lock, NULL);
159
g_object_get (view->priv->settings, "edit-lock", &edit_lock, NULL);
154
160
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), !edit_lock);
164
xpad_text_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
166
XpadTextView *view = XPAD_TEXT_VIEW (object);
171
view->priv->settings = g_value_get_pointer (value);
172
g_object_ref (view->priv->settings);
176
view->priv->pad = g_value_get_pointer (value);
177
g_object_ref (view->priv->pad);
180
case PROP_FOLLOW_FONT_STYLE:
181
view->priv->follow_font_style = g_value_get_boolean (value);
182
if (view->priv->follow_font_style) {
183
xpad_text_view_notify_fontname (view);
184
if (view->priv->notify_font_handler != 0) {
185
g_signal_handler_unblock (view->priv->settings, view->priv->notify_font_handler);
189
g_signal_handler_block (view->priv->settings, view->priv->notify_font_handler);
192
case PROP_FOLLOW_COLOR_STYLE:
193
view->priv->follow_color_style = g_value_get_boolean (value);
194
xpad_text_view_notify_colors (view);
198
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204
xpad_text_view_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
206
XpadTextView *view = XPAD_TEXT_VIEW (object);
211
g_value_set_pointer (value, view->priv->settings);
215
g_value_set_pointer (value, view->priv->pad);
218
case PROP_FOLLOW_FONT_STYLE:
219
g_value_set_boolean (value, view->priv->follow_font_style);
222
case PROP_FOLLOW_COLOR_STYLE:
223
g_value_set_boolean (value, view->priv->follow_color_style);
227
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158
xpad_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
233
xpad_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event, XpadSettings *settings)
160
235
/* A dirty way to silence the compiler for these unused variables. */
163
238
gboolean edit_lock;
164
g_object_get (xpad_global_settings, "edit-lock", &edit_lock, NULL);
239
g_object_get (settings, "edit-lock", &edit_lock, NULL);
245
319
xpad_text_view_notify_colors (XpadTextView *view)
321
GtkWidget *view_widget = GTK_WIDGET (view);
247
322
/* Set the colors of this individual pad to the global setting preference. */
248
323
const GdkRGBA *text_color, *back_color;
249
g_object_get (xpad_global_settings, "text-color", &text_color, "back-color", &back_color, NULL);
251
gtk_widget_override_cursor (GTK_WIDGET (view), text_color, text_color);
252
gtk_widget_override_color (GTK_WIDGET (view), GTK_STATE_FLAG_NORMAL, text_color);
253
gtk_widget_override_background_color (GTK_WIDGET (view), GTK_STATE_FLAG_NORMAL, back_color);
255
/* Inverse the text and background colors for selected text, so it is likely to be visible by any choice of the colors. */
256
gtk_widget_override_color (GTK_WIDGET (view), GTK_STATE_FLAG_SELECTED, back_color);
257
gtk_widget_override_background_color (GTK_WIDGET (view), GTK_STATE_FLAG_SELECTED, text_color);
261
xpad_text_view_set_follow_font_style (XpadTextView *view, gboolean follow)
263
g_return_if_fail (view);
265
if (follow != view->priv->follow_font_style)
269
g_signal_handler_unblock (xpad_global_settings, view->priv->notify_font_handler);
270
xpad_text_view_notify_fontname (view);
274
g_signal_handler_block (xpad_global_settings, view->priv->notify_font_handler);
278
view->priv->follow_font_style = follow;
280
g_object_notify (G_OBJECT (view), "follow_font_style");
284
xpad_text_view_get_follow_font_style (XpadTextView *view)
289
return view->priv->follow_font_style;
293
xpad_text_view_set_follow_color_style (XpadTextView *view, gboolean follow)
295
g_return_if_fail (view);
297
if (follow != view->priv->follow_color_style)
301
xpad_text_view_notify_colors (view);
302
g_signal_handler_unblock (xpad_global_settings, view->priv->notify_text_handler);
303
g_signal_handler_unblock (xpad_global_settings, view->priv->notify_back_handler);
307
g_signal_handler_block (xpad_global_settings, view->priv->notify_text_handler);
308
g_signal_handler_block (xpad_global_settings, view->priv->notify_back_handler);
311
view->priv->follow_color_style = follow;
314
g_object_notify (G_OBJECT (view), "follow_color_style");
318
xpad_text_view_get_follow_color_style (XpadTextView *view)
323
return view->priv->follow_color_style;
327
xpad_text_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
331
view = XPAD_TEXT_VIEW (object);
335
case PROP_FOLLOW_FONT_STYLE:
336
xpad_text_view_set_follow_font_style (view, g_value_get_boolean (value));
339
case PROP_FOLLOW_COLOR_STYLE:
340
xpad_text_view_set_follow_color_style (view, g_value_get_boolean (value));
344
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
350
xpad_text_view_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
354
view = XPAD_TEXT_VIEW (object);
358
case PROP_FOLLOW_FONT_STYLE:
359
g_value_set_boolean (value, xpad_text_view_get_follow_font_style (view));
362
case PROP_FOLLOW_COLOR_STYLE:
363
g_value_set_boolean (value, xpad_text_view_get_follow_color_style (view));
367
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
372
XpadPad *xpad_text_view_get_pad (XpadTextView *view)
374
return xpad_text_buffer_get_pad (view->priv->buffer);
377
void xpad_text_view_set_pad (XpadTextView *view, XpadPad *pad)
379
xpad_text_buffer_set_pad (view->priv->buffer, pad);
325
if (view->priv->follow_color_style) {
326
/* Set the colors to the global preferences colors */
327
g_object_get (view->priv->settings, "text-color", &text_color, "back-color", &back_color, NULL);
329
gtk_widget_override_cursor (view_widget, text_color, text_color);
330
gtk_widget_override_color (view_widget, GTK_STATE_FLAG_NORMAL, text_color);
331
gtk_widget_override_background_color (view_widget, GTK_STATE_FLAG_NORMAL, back_color);
333
/* Inverse the text and background colors for selected text, so it is likely to be visible by any choice of the colors. */
334
gtk_widget_override_color (view_widget, GTK_STATE_FLAG_SELECTED, back_color);
335
gtk_widget_override_background_color (view_widget, GTK_STATE_FLAG_SELECTED, text_color);