Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 2982:73f303cb91c1
[gaim-migrate @ 2995]
Thanks BMiller! :-)
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sat, 23 Feb 2002 23:17:43 +0000 |
parents | f6c4f2187c08 |
children | 7239a392486c |
comparison
equal
deleted
inserted
replaced
2981:aebf1d505e1f | 2982:73f303cb91c1 |
---|---|
1049 g_free (buf); | 1049 g_free (buf); |
1050 | 1050 |
1051 return new_string; | 1051 return new_string; |
1052 } | 1052 } |
1053 | 1053 |
1054 static void | |
1055 chunk_select_words (struct line_info *chunk) | |
1056 { | |
1057 char *start, *end; | |
1058 | |
1059 start = chunk->sel_start; | |
1060 end = chunk->sel_end; | |
1061 | |
1062 if (start != chunk->text) | |
1063 while (start > chunk->text && *(start-1) != ' ') | |
1064 start--; | |
1065 chunk->sel_start = start; | |
1066 | |
1067 if (end != NULL) | |
1068 while (*end != '\0' && *end != ' ') | |
1069 end++; | |
1070 chunk->sel_end = end; | |
1071 } | |
1072 | |
1054 #define COORDS_IN_CHUNK(xx, yy) (((xx) < chunk->x + chunk->width) && \ | 1073 #define COORDS_IN_CHUNK(xx, yy) (((xx) < chunk->x + chunk->width) && \ |
1055 ((yy) < chunk->y + chunk->height)) | 1074 ((yy) < chunk->y + chunk->height)) |
1056 | 1075 |
1057 static void | 1076 static void |
1058 gtk_imhtml_select_bits (GtkIMHtml *imhtml) | 1077 gtk_imhtml_select_bits (GtkIMHtml *imhtml) |
1066 starty = imhtml->sel_starty, | 1085 starty = imhtml->sel_starty, |
1067 endx = imhtml->sel_endx, | 1086 endx = imhtml->sel_endx, |
1068 endy = imhtml->sel_endy; | 1087 endy = imhtml->sel_endy; |
1069 gchar *new_pos; | 1088 gchar *new_pos; |
1070 gint selection = 0; | 1089 gint selection = 0; |
1090 guint mode = imhtml->sel_mode; | |
1071 gboolean smileys = imhtml->smileys; | 1091 gboolean smileys = imhtml->smileys; |
1072 gboolean redraw = FALSE; | 1092 gboolean redraw = FALSE; |
1073 gboolean got_start = FALSE; | 1093 gboolean got_start = FALSE; |
1074 gboolean got_end = FALSE; | 1094 gboolean got_end = FALSE; |
1075 | 1095 |
1081 if (imhtml->selected_text) { | 1101 if (imhtml->selected_text) { |
1082 g_string_free (imhtml->selected_text, TRUE); | 1102 g_string_free (imhtml->selected_text, TRUE); |
1083 imhtml->selected_text = g_string_new (""); | 1103 imhtml->selected_text = g_string_new (""); |
1084 } | 1104 } |
1085 | 1105 |
1106 if (mode == 2) | |
1107 startx = endx = 0; | |
1108 | |
1086 bits = imhtml->bits; | 1109 bits = imhtml->bits; |
1087 while (bits) { | 1110 while (bits) { |
1088 bit = bits->data; | 1111 bit = bits->data; |
1089 chunks = bit->chunks; | 1112 chunks = bit->chunks; |
1090 | 1113 |
1093 | 1116 |
1094 switch (selection) { | 1117 switch (selection) { |
1095 case 0: | 1118 case 0: |
1096 if (COORDS_IN_CHUNK (startx, starty)) { | 1119 if (COORDS_IN_CHUNK (startx, starty)) { |
1097 new_pos = get_position (chunk, startx, smileys); | 1120 new_pos = get_position (chunk, startx, smileys); |
1098 if ( !chunk->selected || | 1121 if (!chunk->selected || |
1099 (chunk->sel_start != new_pos) || | 1122 (chunk->sel_start != new_pos) || |
1100 (chunk->sel_end != NULL)) | 1123 (chunk->sel_end != NULL)) |
1101 redraw = TRUE; | 1124 redraw = TRUE; |
1102 chunk->selected = TRUE; | 1125 chunk->selected = TRUE; |
1103 chunk->sel_start = new_pos; | 1126 chunk->sel_start = new_pos; |
1104 chunk->sel_end = NULL; | 1127 chunk->sel_end = NULL; |
1105 selection++; | 1128 selection++; |
1106 got_start = TRUE; | 1129 got_start = TRUE; |
1130 if (mode == 2) | |
1131 endy += chunk->height; | |
1132 if (mode == 1) | |
1133 chunk_select_words (chunk); | |
1107 } | 1134 } |
1108 | 1135 |
1109 if (COORDS_IN_CHUNK (endx, endy)) { | 1136 if (COORDS_IN_CHUNK (endx, endy)) { |
1110 if (got_start) { | 1137 if (got_start) { |
1111 new_pos = get_position (chunk, endx, smileys); | 1138 new_pos = get_position (chunk, endx, smileys); |
1117 } else | 1144 } else |
1118 chunk->sel_end = new_pos; | 1145 chunk->sel_end = new_pos; |
1119 selection = 2; | 1146 selection = 2; |
1120 imhtml->sel_endchunk = chunk; | 1147 imhtml->sel_endchunk = chunk; |
1121 got_end = TRUE; | 1148 got_end = TRUE; |
1149 if (mode == 1) | |
1150 chunk_select_words (chunk); | |
1122 } else { | 1151 } else { |
1123 new_pos = get_position (chunk, endx, smileys); | 1152 new_pos = get_position (chunk, endx, smileys); |
1124 if ( !chunk->selected || | 1153 if ( !chunk->selected || |
1125 (chunk->sel_start != new_pos) || | 1154 (chunk->sel_start != new_pos) || |
1126 (chunk->sel_end != NULL)) | 1155 (chunk->sel_end != NULL)) |
1129 chunk->sel_start = new_pos; | 1158 chunk->sel_start = new_pos; |
1130 chunk->sel_end = NULL; | 1159 chunk->sel_end = NULL; |
1131 selection++; | 1160 selection++; |
1132 imhtml->sel_endchunk = chunk; | 1161 imhtml->sel_endchunk = chunk; |
1133 got_end = TRUE; | 1162 got_end = TRUE; |
1163 if (mode == 2) | |
1164 starty += chunk->height; | |
1165 if (mode == 1) | |
1166 chunk_select_words (chunk); | |
1134 } | 1167 } |
1135 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { | 1168 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { |
1136 if (chunk->selected) | 1169 if (chunk->selected) |
1137 redraw = TRUE; | 1170 redraw = TRUE; |
1138 chunk->selected = FALSE; | 1171 chunk->selected = FALSE; |
1151 chunk->selected = TRUE; | 1184 chunk->selected = TRUE; |
1152 chunk->sel_start = chunk->text; | 1185 chunk->sel_start = chunk->text; |
1153 chunk->sel_end = new_pos; | 1186 chunk->sel_end = new_pos; |
1154 selection++; | 1187 selection++; |
1155 got_start = TRUE; | 1188 got_start = TRUE; |
1189 if (mode == 1) | |
1190 chunk_select_words (chunk); | |
1156 } else if (!got_end && COORDS_IN_CHUNK (endx, endy)) { | 1191 } else if (!got_end && COORDS_IN_CHUNK (endx, endy)) { |
1157 new_pos = get_position (chunk, endx, smileys); | 1192 new_pos = get_position (chunk, endx, smileys); |
1158 if ( !chunk->selected || | 1193 if ( !chunk->selected || |
1159 (chunk->sel_end != new_pos) || | 1194 (chunk->sel_end != new_pos) || |
1160 (chunk->sel_start != chunk->text)) | 1195 (chunk->sel_start != chunk->text)) |
1163 chunk->sel_start = chunk->text; | 1198 chunk->sel_start = chunk->text; |
1164 chunk->sel_end = new_pos; | 1199 chunk->sel_end = new_pos; |
1165 selection++; | 1200 selection++; |
1166 imhtml->sel_endchunk = chunk; | 1201 imhtml->sel_endchunk = chunk; |
1167 got_end = TRUE; | 1202 got_end = TRUE; |
1203 if (mode == 1) | |
1204 chunk_select_words (chunk); | |
1168 } else { | 1205 } else { |
1169 if ( !chunk->selected || | 1206 if ( !chunk->selected || |
1170 (chunk->sel_end != NULL) || | 1207 (chunk->sel_end != NULL) || |
1171 (chunk->sel_start != chunk->text)) | 1208 (chunk->sel_start != chunk->text)) |
1172 redraw = TRUE; | 1209 redraw = TRUE; |
1400 imhtml->sel_endy = MAX (y, 0); | 1437 imhtml->sel_endy = MAX (y, 0); |
1401 if ((chunk == NULL) || | 1438 if ((chunk == NULL) || |
1402 (x < chunk->x) || | 1439 (x < chunk->x) || |
1403 (x > chunk->x + chunk->width) || | 1440 (x > chunk->x + chunk->width) || |
1404 (y < chunk->y) || | 1441 (y < chunk->y) || |
1405 (y > chunk->y + chunk->height)) | 1442 (y > chunk->y + chunk->height) || |
1443 (imhtml->sel_mode > 0)) | |
1406 gtk_imhtml_select_bits (imhtml); | 1444 gtk_imhtml_select_bits (imhtml); |
1407 else | 1445 else |
1408 gtk_imhtml_select_in_chunk (imhtml, chunk); | 1446 gtk_imhtml_select_in_chunk (imhtml, chunk); |
1409 } | 1447 } |
1410 } else { | 1448 } else { |
1507 | 1545 |
1508 x = event->x + hadj->value; | 1546 x = event->x + hadj->value; |
1509 y = event->y + vadj->value; | 1547 y = event->y + vadj->value; |
1510 | 1548 |
1511 if (event->button == 1) { | 1549 if (event->button == 1) { |
1512 imhtml->sel_startx = x; | 1550 imhtml->sel_startx = imhtml->sel_endx = x; |
1513 imhtml->sel_starty = y; | 1551 imhtml->sel_starty = imhtml->sel_endy = y; |
1514 imhtml->selection = TRUE; | 1552 imhtml->selection = TRUE; |
1515 gtk_imhtml_select_none (imhtml); | 1553 if (event->type == GDK_BUTTON_PRESS) { |
1554 imhtml->sel_mode = 0; /* select by letter */ | |
1555 gtk_imhtml_select_none (imhtml); | |
1556 } else if (event->type == GDK_2BUTTON_PRESS) { | |
1557 imhtml->sel_mode = 1; /* select by word */ | |
1558 gtk_imhtml_select_none (imhtml); | |
1559 } else if (event->type == GDK_3BUTTON_PRESS) { | |
1560 imhtml->sel_mode = 2; /* select by line */ | |
1561 gtk_imhtml_select_bits (imhtml); | |
1562 } | |
1516 } | 1563 } |
1517 | 1564 |
1518 if (event->button == 3) { | 1565 if (event->button == 3) { |
1519 GList *click = imhtml->click; | 1566 GList *click = imhtml->click; |
1520 struct clickable *uw; | 1567 struct clickable *uw; |
1572 | 1619 |
1573 x = event->x + hadj->value; | 1620 x = event->x + hadj->value; |
1574 y = event->y + vadj->value; | 1621 y = event->y + vadj->value; |
1575 | 1622 |
1576 if ((event->button == 1) && imhtml->selection) { | 1623 if ((event->button == 1) && imhtml->selection) { |
1577 if ((x == imhtml->sel_startx) && (y == imhtml->sel_starty)) { | 1624 if ((x == imhtml->sel_startx) && (y == imhtml->sel_starty) && |
1625 (imhtml->sel_mode == 0)) { | |
1578 imhtml->sel_startx = imhtml->sel_starty = 0; | 1626 imhtml->sel_startx = imhtml->sel_starty = 0; |
1579 imhtml->selection = FALSE; | 1627 imhtml->selection = FALSE; |
1580 gtk_imhtml_select_none (imhtml); | 1628 gtk_imhtml_select_none (imhtml); |
1581 } else { | 1629 } else { |
1582 imhtml->sel_endx = MAX (x, 0); | 1630 imhtml->sel_endx = MAX (x, 0); |