72
72
enum DndTargetType {
73
DND_TARGET_TYPE_MESSAGE_RFC822,
74
DND_TARGET_TYPE_X_UID_LIST,
75
73
DND_TARGET_TYPE_TEXT_URI_LIST,
76
74
DND_TARGET_TYPE_MOZILLA_URL,
77
DND_TARGET_TYPE_TEXT_VCARD,
78
DND_TARGET_TYPE_TEXT_CALENDAR,
79
75
DND_TARGET_TYPE_TEXT_HTML,
80
76
DND_TARGET_TYPE_UTF8_STRING,
81
77
DND_TARGET_TYPE_TEXT_PLAIN,
82
78
DND_TARGET_TYPE_STRING
85
static GtkTargetEntry dnd_link_sources [] = {
86
{ (gchar *) "message/rfc822", 0, DND_TARGET_TYPE_MESSAGE_RFC822 },
87
{ (gchar *) "x-uid-list", 0, DND_TARGET_TYPE_X_UID_LIST },
88
{ (gchar *) "text/uri-list", 0, DND_TARGET_TYPE_TEXT_URI_LIST },
89
{ (gchar *) "_NETSCAPE_URL", 0, DND_TARGET_TYPE_MOZILLA_URL },
90
{ (gchar *) "text/x-vcard", 0, DND_TARGET_TYPE_TEXT_VCARD },
91
{ (gchar *) "text/calendar", 0, DND_TARGET_TYPE_TEXT_CALENDAR },
92
{ (gchar *) "text/html", 0, DND_TARGET_TYPE_TEXT_HTML },
93
{ (gchar *) "UTF8_STRING", 0, DND_TARGET_TYPE_UTF8_STRING },
94
{ (gchar *) "text/plain", 0, DND_TARGET_TYPE_TEXT_PLAIN },
95
{ (gchar *) "STRING", 0, DND_TARGET_TYPE_STRING },
97
#define DND_LINK_SOURCES sizeof (dnd_link_sources) / sizeof (GtkTargetEntry)
81
static GtkTargetEntry drag_dest_targets[] = {
82
{ (gchar *) "text/uri-list", 0, DND_TARGET_TYPE_TEXT_URI_LIST },
83
{ (gchar *) "_NETSCAPE_URL", 0, DND_TARGET_TYPE_MOZILLA_URL },
84
{ (gchar *) "text/html", 0, DND_TARGET_TYPE_TEXT_HTML },
85
{ (gchar *) "UTF8_STRING", 0, DND_TARGET_TYPE_UTF8_STRING },
86
{ (gchar *) "text/plain", 0, DND_TARGET_TYPE_TEXT_PLAIN },
87
{ (gchar *) "STRING", 0, DND_TARGET_TYPE_STRING },
90
static GtkTargetEntry drag_source_targets[] = {
91
{ (gchar *) "text/uri-list", 0, DND_TARGET_TYPE_TEXT_URI_LIST },
92
{ (gchar *) "_NETSCAPE_URL", 0, DND_TARGET_TYPE_MOZILLA_URL },
93
{ (gchar *) "text/html", 0, DND_TARGET_TYPE_TEXT_HTML },
94
{ (gchar *) "UTF8_STRING", 0, DND_TARGET_TYPE_UTF8_STRING },
95
{ (gchar *) "text/plain", 0, DND_TARGET_TYPE_TEXT_PLAIN },
96
{ (gchar *) "STRING", 0, DND_TARGET_TYPE_STRING },
347
347
if (paragraph_style != html->priv->paragraph_style) {
348
348
html->priv->paragraph_style = paragraph_style;
349
g_signal_emit (html, signals [CURRENT_PARAGRAPH_STYLE_CHANGED], 0, paragraph_style);
349
g_signal_emit (html, signals[CURRENT_PARAGRAPH_STYLE_CHANGED], 0, paragraph_style);
352
352
indentation = html_engine_get_current_clueflow_indentation (engine);
353
353
if (indentation != html->priv->paragraph_indentation) {
354
354
html->priv->paragraph_indentation = indentation;
355
g_signal_emit (html, signals [CURRENT_PARAGRAPH_INDENTATION_CHANGED], 0, indentation);
355
g_signal_emit (html, signals[CURRENT_PARAGRAPH_INDENTATION_CHANGED], 0, indentation);
358
358
alignment = html_alignment_to_paragraph (html_engine_get_current_clueflow_alignment (engine));
359
359
if (alignment != html->priv->paragraph_alignment) {
360
360
html->priv->paragraph_alignment = alignment;
361
g_signal_emit (html, signals [CURRENT_PARAGRAPH_ALIGNMENT_CHANGED], 0, alignment);
361
g_signal_emit (html, signals[CURRENT_PARAGRAPH_ALIGNMENT_CHANGED], 0, alignment);
364
364
if (html_engine_update_insertion_font_style (engine))
365
g_signal_emit (html, signals [INSERTION_FONT_STYLE_CHANGED], 0, engine->insertion_font_style);
365
g_signal_emit (html, signals[INSERTION_FONT_STYLE_CHANGED], 0, engine->insertion_font_style);
366
366
if (html_engine_update_insertion_color (engine))
367
g_signal_emit (html, signals [INSERTION_COLOR_CHANGED], 0, engine->insertion_color);
367
g_signal_emit (html, signals[INSERTION_COLOR_CHANGED], 0, engine->insertion_color);
369
369
/* TODO add insertion_url_or_targed_changed signal */
370
370
html_engine_update_insertion_url_and_target (engine);
692
688
window = gtk_widget_get_window (widget);
693
689
gdk_window_get_pointer (window, &x, &y, NULL);
691
gtk_widget_get_allocation (widget, &allocation);
697
695
if (x + engine->x_offset >= 0)
699
} else if (x >= widget->allocation.width) {
700
x_scroll = x - widget->allocation.width + 1;
701
x = widget->allocation.width;
697
} else if (x >= allocation.width) {
698
x_scroll = x - allocation.width + 1;
699
x = allocation.width;
724
722
vadjustment = gtk_layout_get_vadjustment (GTK_LAYOUT (widget));
726
724
inc_adjustment (hadjustment, html_engine_get_doc_width (html->engine),
727
widget->allocation.width, x_scroll);
725
allocation.width, x_scroll);
728
726
inc_adjustment (vadjustment, html_engine_get_doc_height (html->engine),
729
widget->allocation.height, y_scroll);
727
allocation.height, y_scroll);
731
729
GDK_THREADS_LEAVE ();
1140
1138
gtk_html_drag_dest_set (GtkHTML *html)
1142
1140
if (html_engine_get_editable (html->engine))
1143
gtk_drag_dest_set (GTK_WIDGET (html), GTK_DEST_DEFAULT_ALL,
1144
dnd_link_sources, DND_LINK_SOURCES, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1143
GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
1144
drag_dest_targets, G_N_ELEMENTS (drag_dest_targets),
1145
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1146
1147
gtk_drag_dest_unset (GTK_WIDGET (html));
1286
set_adjustment_upper (GtkAdjustment *adjustment,
1293
/* XXX Stolen from gtklayout.c and simplified. */
1295
value = gtk_adjustment_get_value (adjustment);
1296
page_size = gtk_adjustment_get_page_size (adjustment);
1297
min = MAX (0., upper - page_size);
1299
gtk_adjustment_set_upper (adjustment, upper);
1302
gtk_adjustment_set_value (adjustment, min);
1306
gtk_layout_faux_size_allocate (GtkWidget *widget,
1307
GtkAllocation *allocation)
1309
GtkLayout *layout = GTK_LAYOUT (widget);
1310
GtkAdjustment *adjustment;
1311
guint width, height;
1313
/* XXX This is essentially a copy of GtkLayout's size_allocate()
1314
* method, but with the GtkLayoutChild loop removed. We call
1315
* this instead of chaining up to GtkLayout. */
1317
gtk_widget_set_allocation (widget, allocation);
1318
gtk_layout_get_size (layout, &width, &height);
1320
if (gtk_widget_get_realized (widget)) {
1321
gdk_window_move_resize (
1322
gtk_widget_get_window (widget),
1323
allocation->x, allocation->y,
1324
allocation->width, allocation->height);
1327
gtk_layout_get_bin_window (layout),
1328
MAX (width, allocation->width),
1329
MAX (height, allocation->height));
1332
/* XXX Does the previous logic alter the GtkLayout size?
1333
* Not sure, so best refetch the size just to be safe. */
1334
gtk_layout_get_size (layout, &width, &height);
1336
adjustment = gtk_layout_get_hadjustment (layout);
1337
g_object_freeze_notify (G_OBJECT (adjustment));
1338
gtk_adjustment_set_page_size (adjustment, allocation->width);
1339
gtk_adjustment_set_page_increment (adjustment, allocation->width * 0.9);
1340
gtk_adjustment_set_lower (adjustment, 0);
1341
set_adjustment_upper (adjustment, MAX (allocation->width, width));
1342
g_object_thaw_notify (G_OBJECT (adjustment));
1344
adjustment = gtk_layout_get_vadjustment (layout);
1345
g_object_freeze_notify (G_OBJECT (adjustment));
1346
gtk_adjustment_set_page_size (adjustment, allocation->height);
1347
gtk_adjustment_set_page_increment (adjustment, allocation->height * 0.9);
1348
gtk_adjustment_set_lower (adjustment, 0);
1349
set_adjustment_upper (adjustment, MAX (allocation->height, height));
1350
g_object_thaw_notify (G_OBJECT (adjustment));
1285
1354
size_allocate (GtkWidget *widget, GtkAllocation *allocation)
1288
1357
GtkLayout *layout;
1289
1358
gboolean changed_x = FALSE, changed_y = FALSE;
1292
1360
g_return_if_fail (widget != NULL);
1293
1361
g_return_if_fail (GTK_IS_HTML (widget));
1299
1367
/* isolate childs from layout - we want to set them after calc size is performed
1300
1368
and we know the children positions */
1301
children = GTK_LAYOUT (widget)->children;
1302
GTK_LAYOUT (widget)->children = NULL;
1303
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
1304
(*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
1305
GTK_LAYOUT (widget)->children = children;
1369
gtk_layout_faux_size_allocate (widget, allocation);
1307
1371
if (html->engine->width != allocation->width
1308
1372
|| html->engine->height != allocation->height) {
1361
1425
if (!html_engine_get_editable (GTK_HTML (widget)->engine)) {
1362
1426
/* printf ("dnd_link_set %p\n", o); */
1364
gtk_drag_source_set (widget, GDK_BUTTON1_MASK,
1365
dnd_link_sources, DND_LINK_SOURCES,
1366
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1428
gtk_drag_source_set (
1429
widget, GDK_BUTTON1_MASK,
1430
drag_source_targets, G_N_ELEMENTS (drag_source_targets),
1431
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
1367
1432
GTK_HTML (widget)->priv->dnd_object = o;
1368
1433
GTK_HTML (widget)->priv->dnd_object_offset = offset;
1746
1810
shift_to_iframe_parent (GtkWidget *widget, gint *x, gint *y)
1748
1812
while (GTK_HTML (widget)->iframe_parent) {
1813
GtkAllocation allocation;
1815
gtk_widget_get_allocation (widget, &allocation);
1750
*x += widget->allocation.x - GTK_HTML (widget)->engine->x_offset;
1818
*x += allocation.x - GTK_HTML (widget)->engine->x_offset;
1752
*y += widget->allocation.y - GTK_HTML (widget)->engine->y_offset;
1820
*y += allocation.y - GTK_HTML (widget)->engine->y_offset;
1754
1822
widget = GTK_HTML (widget)->iframe_parent;
3065
3131
g_object_class_install_property (gobject_class,
3067
3133
g_param_spec_boolean ("editable",
3069
_("Whether the html can be edited"),
3135
"Whether the html can be edited",
3071
3137
G_PARAM_READABLE | G_PARAM_WRITABLE));
3072
3138
g_object_class_install_property (gobject_class,
3074
3140
g_param_spec_string ("title",
3075
_("Document Title"),
3076
_("The title of the current document"),
3142
"The title of the current document",
3078
3144
G_PARAM_WRITABLE | G_PARAM_READABLE));
3079
3145
g_object_class_install_property (gobject_class,
3080
3146
PROP_DOCUMENT_BASE,
3081
3147
g_param_spec_string ("document_base",
3083
_("The base URL for relative references"),
3149
"The base URL for relative references",
3085
3151
G_PARAM_WRITABLE | G_PARAM_READABLE));
3086
3152
g_object_class_install_property (gobject_class,
3087
3153
PROP_TARGET_BASE,
3088
3154
g_param_spec_string ("target_base",
3090
_("The base URL of the target frame"),
3156
"The base URL of the target frame",
3092
3158
G_PARAM_WRITABLE | G_PARAM_READABLE));
3096
3162
gtk_widget_class_install_style_property (widget_class,
3097
3163
g_param_spec_string ("fixed_font_name",
3098
_("Fixed Width Font"),
3099
_("The Monospace font to use for typewriter text"),
3165
"The Monospace font to use for typewriter text",
3101
3167
G_PARAM_READABLE));
3103
3169
gtk_widget_class_install_style_property (widget_class,
3104
3170
g_param_spec_boxed ("link_color",
3105
_("New Link Color"),
3106
_("The color of new link elements"),
3172
"The color of new link elements",
3107
3173
GDK_TYPE_COLOR,
3108
3174
G_PARAM_READABLE));
3109
3175
gtk_widget_class_install_style_property (widget_class,
3110
3176
g_param_spec_boxed ("vlink_color",
3111
_("Visited Link Color"),
3112
_("The color of visited link elements"),
3177
"Visited Link Color",
3178
"The color of visited link elements",
3113
3179
GDK_TYPE_COLOR,
3114
3180
G_PARAM_READABLE));
3115
3181
gtk_widget_class_install_style_property (widget_class,
3116
3182
g_param_spec_boxed ("alink_color",
3117
_("Active Link Color"),
3118
_("The color of active link elements"),
3183
"Active Link Color",
3184
"The color of active link elements",
3119
3185
GDK_TYPE_COLOR,
3120
3186
G_PARAM_READABLE));
3121
3187
gtk_widget_class_install_style_property (widget_class,
3122
3188
g_param_spec_boxed ("spell_error_color",
3123
_("Spelling Error Color"),
3124
_("The color of the spelling error markers"),
3189
"Spelling Error Color",
3190
"The color of the spelling error markers",
3125
3191
GDK_TYPE_COLOR,
3126
3192
G_PARAM_READABLE));
3127
3193
gtk_widget_class_install_style_property (widget_class,
3128
3194
g_param_spec_boxed ("cite_color",
3129
_("Cite Quotation Color"),
3130
_("The color of the cited text"),
3195
"Cite Quotation Color",
3196
"The color of the cited text",
3131
3197
GDK_TYPE_COLOR,
3132
3198
G_PARAM_READABLE));
4365
4431
if (html_engine_set_clueflow_style (html->engine, 0, 0, align, 0, NULL,
4366
4432
HTML_ENGINE_SET_CLUEFLOW_ALIGNMENT, HTML_UNDO_UNDO, TRUE)) {
4367
4433
html->priv->paragraph_alignment = alignment;
4368
g_signal_emit (html, signals [CURRENT_PARAGRAPH_ALIGNMENT_CHANGED], 0, alignment);
4434
g_signal_emit (html, signals[CURRENT_PARAGRAPH_ALIGNMENT_CHANGED], 0, alignment);
4901
4967
case GTK_HTML_CURSOR_SKIP_PAGE: {
4968
GtkAllocation allocation;
4902
4969
gint line_height;
4904
line_height = GTK_WIDGET (html)->allocation.height > (3 * get_line_height (html))
4971
gtk_widget_get_allocation (GTK_WIDGET (html), &allocation);
4972
line_height = allocation.height > (3 * get_line_height (html))
4905
4973
? get_line_height (html) : 0;
4907
4975
switch (dir_type) {
4908
4976
case GTK_DIR_UP:
4909
4977
case GTK_DIR_LEFT:
4910
4978
if ((amount = html_engine_scroll_up (html->engine,
4911
GTK_WIDGET (html)->allocation.height - line_height)) > 0)
4979
allocation.height - line_height)) > 0)
4912
4980
scroll_by_amount (html, - amount);
4914
4982
case GTK_DIR_DOWN:
4915
4983
case GTK_DIR_RIGHT:
4916
4984
if ((amount = html_engine_scroll_down (html->engine,
4917
GTK_WIDGET (html)->allocation.height - line_height)) > 0)
4985
allocation.height - line_height)) > 0)
4918
4986
scroll_by_amount (html, amount);
4949
5017
gtk_html_edit_make_cursor_visible (html);
4950
5018
html_engine_update_selection_active_state (html->engine, html->priv->event_time);
4951
5019
update_primary_selection (html);
4952
g_signal_emit (GTK_HTML (html), signals [CURSOR_CHANGED], 0);
5020
g_signal_emit (GTK_HTML (html), signals[CURSOR_CHANGED], 0);
4955
5023
static gboolean
4956
5024
move_selection (GtkHTML *html, GtkHTMLCommandType com_type)
5026
GtkAllocation allocation;
4961
5030
if (!html_engine_get_editable (html->engine) && !html->engine->caret_mode)
5033
gtk_widget_get_allocation (GTK_WIDGET (html), &allocation);
4964
5035
html->priv->cursor_moved = TRUE;
4965
5036
html->engine->shift_selection = TRUE;
4966
5037
if (!html->engine->mark)
4999
5070
rv = html_engine_forward_word (html->engine);
5001
5072
case GTK_HTML_COMMAND_MODIFY_SELECTION_PAGEUP:
5002
if ((amount = html_engine_scroll_up (html->engine, GTK_WIDGET (html)->allocation.height)) > 0) {
5073
if ((amount = html_engine_scroll_up (html->engine, allocation.height)) > 0) {
5003
5074
scroll_by_amount (html, - amount);
5008
5079
case GTK_HTML_COMMAND_MODIFY_SELECTION_PAGEDOWN:
5009
if ((amount = html_engine_scroll_down (html->engine, GTK_WIDGET (html)->allocation.height)) > 0) {
5080
if ((amount = html_engine_scroll_down (html->engine, allocation.height)) > 0) {
5010
5081
scroll_by_amount (html, amount);