Mercurial > pidgin.yaz
comparison src/buddy_chat.c @ 3790:12b29552f1d7
[gaim-migrate @ 3930]
Better than cheddar, it's i18n input...
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Wed, 23 Oct 2002 00:12:49 +0000 |
parents | 165ae100e0a7 |
children | 9bcb42faccc0 |
comparison
equal
deleted
inserted
replaced
3789:fb519383a058 | 3790:12b29552f1d7 |
---|---|
467 gtk_widget_show(invite); | 467 gtk_widget_show(invite); |
468 } | 468 } |
469 | 469 |
470 void tab_complete(struct conversation *c) | 470 void tab_complete(struct conversation *c) |
471 { | 471 { |
472 int pos = GTK_OLD_EDITABLE(c->entry)->current_pos; | 472 GtkTextIter cursor, word_start, start_buffer; |
473 int start = pos; | 473 int start; |
474 int most_matched = -1; | 474 int most_matched = -1; |
475 char *entered, *partial = NULL; | 475 char *entered, *partial = NULL; |
476 char *text; | 476 char *text; |
477 GList *matches = NULL; | 477 GList *matches = NULL; |
478 GList *nicks = c->in_room; | 478 GList *nicks = NULL; |
479 | |
480 gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer); | |
481 gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor, | |
482 gtk_text_buffer_get_insert(c->entry_buffer)); | |
483 word_start = cursor; | |
479 | 484 |
480 /* if there's nothing there just return */ | 485 /* if there's nothing there just return */ |
481 if (!start) | 486 if (!gtk_text_iter_compare(&cursor, &start_buffer)) |
482 return; | 487 return; |
483 | 488 |
484 text = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, pos); | 489 text = gtk_text_buffer_get_text(c->entry_buffer, &start_buffer, &cursor, FALSE); |
485 | 490 |
486 /* if we're at the end of ": " we need to move back 2 spaces */ | 491 /* if we're at the end of ": " we need to move back 2 spaces */ |
487 if (start >= 2 && text[start - 1] == ' ' && text[start - 2] == ':') | 492 start = strlen(text)-1; |
488 start -= 2; | 493 if (strlen(text)>=2 && !strncmp(&text[start-1], ": ", 2)) { |
489 | 494 gtk_text_iter_backward_chars(&word_start, 2); |
495 } | |
496 | |
490 /* find the start of the word that we're tabbing */ | 497 /* find the start of the word that we're tabbing */ |
491 while (start > 0 && text[start - 1] != ' ') | 498 while (start >= 0 && text[start] != ' ') { |
499 gtk_text_iter_backward_char(&word_start); | |
492 start--; | 500 start--; |
493 | 501 } |
494 entered = text + start; | 502 g_free(text); |
503 | |
504 entered = gtk_text_buffer_get_text(c->entry_buffer, &word_start, &cursor, FALSE); | |
495 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | 505 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { |
496 if (strlen(entered) >= 2 && !strncmp(": ", entered + strlen(entered) - 2, 2)) | 506 if (strlen(entered) >= 2 && !strncmp(": ", entered + strlen(entered) - 2, 2)) |
497 entered[strlen(entered) - 2] = 0; | 507 entered[strlen(entered) - 2] = 0; |
498 } | 508 } |
499 | 509 |
500 if (!strlen(entered)) { | 510 if (!strlen(entered)) { |
501 g_free(text); | 511 g_free(entered); |
502 return; | 512 return; |
503 } | 513 } |
504 | 514 |
505 debug_printf("checking tab-completion for %s\n", entered); | 515 debug_printf("checking tab-completion for %s\n", entered); |
506 | 516 |
517 nicks = c->in_room; | |
507 while (nicks) { | 518 while (nicks) { |
508 char *nick = nicks->data; | 519 char *nick = nicks->data; |
509 /* this checks to see if the current nick could be a completion */ | 520 /* this checks to see if the current nick could be a completion */ |
510 if (g_strncasecmp(nick, entered, strlen(entered))) { | 521 if (g_strncasecmp(nick, entered, strlen(entered))) { |
511 if (nick[0] != '+' && nick[0] != '@') { | 522 if (nick[0] != '+' && nick[0] != '@') { |
529 /* if we're here, it's a possible completion */ | 540 /* if we're here, it's a possible completion */ |
530 debug_printf("possible completion: %s\n", nick); | 541 debug_printf("possible completion: %s\n", nick); |
531 | 542 |
532 /* if we're doing old-style, just fill in the completion */ | 543 /* if we're doing old-style, just fill in the completion */ |
533 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | 544 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { |
534 gtk_editable_delete_text(GTK_EDITABLE(c->entry), start, pos); | 545 gtk_text_buffer_delete(c->entry_buffer, &word_start, &cursor); |
535 if (strlen(nick) == strlen(entered)) { | 546 if (strlen(nick) == strlen(entered)) { |
536 nicks = nicks->next ? nicks->next : c->in_room; | 547 nicks = nicks->next ? nicks->next : c->in_room; |
537 nick = nicks->data; | 548 nick = nicks->data; |
538 if (*nick == '@') | 549 if (*nick == '@') |
539 nick++; | 550 nick++; |
540 if (*nick == '+') | 551 if (*nick == '+') |
541 nick++; | 552 nick++; |
542 } | 553 } |
543 | 554 |
544 if (start == 0) { | 555 gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer); |
556 gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor, | |
557 gtk_text_buffer_get_insert(c->entry_buffer)); | |
558 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
545 char *tmp = g_strdup_printf("%s: ", nick); | 559 char *tmp = g_strdup_printf("%s: ", nick); |
546 int t = start; | 560 gtk_text_buffer_insert_at_cursor(c->entry_buffer, tmp, -1); |
547 gtk_editable_insert_text(GTK_EDITABLE(c->entry), tmp, strlen(tmp), &start); | |
548 if (t == start) { | |
549 t = start + strlen(tmp); | |
550 gtk_editable_set_position(GTK_EDITABLE(c->entry), t); | |
551 } | |
552 g_free(tmp); | 561 g_free(tmp); |
553 } else { | 562 } else { |
554 int t = start; | 563 gtk_text_buffer_insert_at_cursor(c->entry_buffer, nick, -1); |
555 gtk_editable_insert_text(GTK_EDITABLE(c->entry), nick, strlen(nick), &start); | |
556 if (t == start) { | |
557 t = start + strlen(nick); | |
558 gtk_editable_set_position(GTK_EDITABLE(c->entry), t); | |
559 } | |
560 } | 564 } |
561 g_free(text); | 565 g_free(entered); |
562 return; | 566 return; |
563 } | 567 } |
564 | 568 |
565 /* we're only here if we're doing new style */ | 569 /* we're only here if we're doing new style */ |
566 if (most_matched == -1) { | 570 if (most_matched == -1) { |
579 /* we're only here if we're doing new style */ | 583 /* we're only here if we're doing new style */ |
580 | 584 |
581 /* if there weren't any matches, return */ | 585 /* if there weren't any matches, return */ |
582 if (!matches) { | 586 if (!matches) { |
583 /* if matches isn't set partials won't be either */ | 587 /* if matches isn't set partials won't be either */ |
584 g_free(text); | 588 g_free(entered); |
585 return; | 589 return; |
586 } | 590 } |
587 | 591 |
588 gtk_editable_delete_text(GTK_EDITABLE(c->entry), start, pos); | 592 gtk_text_buffer_delete(c->entry_buffer, &word_start, &cursor); |
589 if (!matches->next) { | 593 if (!matches->next) { |
590 /* there was only one match. fill it in. */ | 594 /* there was only one match. fill it in. */ |
591 if (start == 0) { | 595 gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer); |
596 gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor, | |
597 gtk_text_buffer_get_insert(c->entry_buffer)); | |
598 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
592 char *tmp = g_strdup_printf("%s: ", (char *)matches->data); | 599 char *tmp = g_strdup_printf("%s: ", (char *)matches->data); |
593 int t = start; | 600 gtk_text_buffer_insert_at_cursor(c->entry_buffer, tmp, -1); |
594 gtk_editable_insert_text(GTK_EDITABLE(c->entry), tmp, strlen(tmp), &start); | |
595 if (t == start) { | |
596 t = start + strlen(tmp); | |
597 gtk_editable_set_position(GTK_EDITABLE(c->entry), t); | |
598 } | |
599 g_free(tmp); | 601 g_free(tmp); |
600 } else { | 602 } else { |
601 gtk_editable_insert_text(GTK_EDITABLE(c->entry), matches->data, strlen(matches->data), &start); | 603 gtk_text_buffer_insert_at_cursor(c->entry_buffer, matches->data, -1); |
602 } | 604 } |
603 matches = g_list_remove(matches, matches->data); | 605 matches = g_list_remove(matches, matches->data); |
604 } else { | 606 } else { |
605 /* there were lots of matches, fill in as much as possible and display all of them */ | 607 /* there were lots of matches, fill in as much as possible and display all of them */ |
606 char *addthis = g_malloc0(1); | 608 char *addthis = g_malloc0(1); |
607 int t = start; | |
608 while (matches) { | 609 while (matches) { |
609 char *tmp = addthis; | 610 char *tmp = addthis; |
610 addthis = g_strconcat(tmp, matches->data, " ", NULL); | 611 addthis = g_strconcat(tmp, matches->data, " ", NULL); |
611 g_free(tmp); | 612 g_free(tmp); |
612 matches = g_list_remove(matches, matches->data); | 613 matches = g_list_remove(matches, matches->data); |
613 } | 614 } |
614 write_to_conv(c, addthis, WFLAG_NOLOG, NULL, time(NULL), -1); | 615 write_to_conv(c, addthis, WFLAG_NOLOG, NULL, time(NULL), -1); |
615 gtk_editable_insert_text(GTK_EDITABLE(c->entry), partial, strlen(partial), &start); | 616 gtk_text_buffer_insert_at_cursor(c->entry_buffer, partial, -1); |
616 if (t == start) { | |
617 t = start + strlen(partial); | |
618 gtk_editable_set_position(GTK_EDITABLE(c->entry), t); | |
619 } | |
620 g_free(addthis); | 617 g_free(addthis); |
621 } | 618 } |
622 | 619 |
623 g_free(text); | 620 g_free(entered); |
624 g_free(partial); | 621 g_free(partial); |
625 } | 622 } |
626 | 623 |
627 gboolean meify(char *message, int len) | 624 gboolean meify(char *message, int len) |
628 { | 625 { |
1178 void show_new_buddy_chat(struct conversation *b) | 1175 void show_new_buddy_chat(struct conversation *b) |
1179 { | 1176 { |
1180 GtkWidget *win; | 1177 GtkWidget *win; |
1181 GtkWidget *cont; | 1178 GtkWidget *cont; |
1182 GtkWidget *text; | 1179 GtkWidget *text; |
1180 /*GtkWidget *close;*/ | |
1181 GtkWidget *frame; | |
1183 GtkWidget *chatentry; | 1182 GtkWidget *chatentry; |
1184 GtkWidget *lbox; | 1183 GtkWidget *lbox; |
1185 GtkWidget *bbox; | 1184 GtkWidget *bbox; |
1186 GtkWidget *bbox2; | 1185 GtkWidget *bbox2; |
1187 GtkWidget *button; | 1186 GtkWidget *button; |
1381 | 1380 |
1382 vbox = gtk_vbox_new(FALSE, 5); | 1381 vbox = gtk_vbox_new(FALSE, 5); |
1383 gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE); | 1382 gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE); |
1384 gtk_widget_show(vbox); | 1383 gtk_widget_show(vbox); |
1385 | 1384 |
1386 chatentry = gtk_text_new(NULL, NULL); | 1385 toolbar = build_conv_toolbar(b); |
1386 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | |
1387 | |
1388 frame = gtk_frame_new(NULL); | |
1389 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
1390 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(frame), TRUE, TRUE, 0); | |
1391 gtk_widget_show(frame); | |
1392 | |
1393 b->entry_buffer = gtk_text_buffer_new(NULL); | |
1394 g_object_set_data(G_OBJECT(b->entry_buffer), "user_data", b); | |
1395 chatentry = gtk_text_view_new_with_buffer(b->entry_buffer); | |
1387 b->entry = chatentry; | 1396 b->entry = chatentry; |
1388 if (!(chat_options & OPT_CHAT_ONE_WINDOW)) | 1397 if (!(chat_options & OPT_CHAT_ONE_WINDOW)) |
1389 gtk_window_set_focus(GTK_WINDOW(b->window), b->entry); | 1398 gtk_window_set_focus(GTK_WINDOW(b->window), b->entry); |
1390 | 1399 |
1391 | 1400 |
1392 b->makesound = 1; /* Need to do this until we get a menu */ | 1401 b->makesound = 1; /* Need to do this until we get a menu */ |
1393 | 1402 |
1394 toolbar = build_conv_toolbar(b); | 1403 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(b->entry), GTK_WRAP_WORD); |
1395 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | 1404 g_signal_connect(G_OBJECT(b->entry), "key_press_event", G_CALLBACK(keypress_callback), b); |
1396 | 1405 g_signal_connect_after(G_OBJECT(b->entry), "button_press_event", |
1397 gtk_object_set_user_data(GTK_OBJECT(chatentry), b); | 1406 G_CALLBACK(stop_rclick_callback), NULL); |
1398 gtk_text_set_editable(GTK_TEXT(chatentry), TRUE); | 1407 g_signal_connect_swapped(G_OBJECT(chatentry), "key_press_event", |
1399 gtk_text_set_word_wrap(GTK_TEXT(chatentry), TRUE); | 1408 G_CALLBACK(entry_key_pressed), chatentry); |
1400 gtk_signal_connect(GTK_OBJECT(chatentry), "activate", GTK_SIGNAL_FUNC(send_callback), b); | 1409 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(chatentry)); |
1401 gtk_signal_connect(GTK_OBJECT(chatentry), "key_press_event", GTK_SIGNAL_FUNC(keypress_callback), | |
1402 b); | |
1403 gtk_signal_connect(GTK_OBJECT(chatentry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), | |
1404 chatentry); | |
1405 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
1406 gtkspell_attach(GTK_TEXT(chatentry)); | |
1407 gtk_box_pack_start(GTK_BOX(vbox), chatentry, TRUE, TRUE, 0); | |
1408 gtk_widget_set_usize(chatentry, buddy_chat_size.width, MAX(buddy_chat_size.entry_height, 25)); | 1410 gtk_widget_set_usize(chatentry, buddy_chat_size.width, MAX(buddy_chat_size.entry_height, 25)); |
1409 gtk_window_set_focus(GTK_WINDOW(win), chatentry); | 1411 gtk_window_set_focus(GTK_WINDOW(win), chatentry); |
1410 gtk_widget_show(chatentry); | 1412 gtk_widget_show(chatentry); |
1413 /*if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
1414 gtkspell_attach(GTK_TEXT(chatentry));*/ | |
1411 | 1415 |
1412 bbox = gtk_hbox_new(FALSE, 5); | 1416 bbox = gtk_hbox_new(FALSE, 5); |
1413 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | 1417 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); |
1414 gtk_widget_show(bbox); | 1418 gtk_widget_show(bbox); |
1415 | 1419 |