comparison mcabber/src/screen.c @ 873:ee39f6d94d43

Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
author Mikael Berthe <mikael@lilotux.net>
date Fri, 26 May 2006 22:51:19 +0200
parents b30df2ab457f
children 293e8955075c
comparison
equal deleted inserted replaced
872:a0ddc43b421e 873:ee39f6d94d43
59 PANEL *panel; 59 PANEL *panel;
60 char *name; 60 char *name;
61 GList *hbuf; 61 GList *hbuf;
62 GList *top; // If top is NULL, we'll display the last lines 62 GList *top; // If top is NULL, we'll display the last lines
63 char cleared; // For ex, user has issued a /clear command... 63 char cleared; // For ex, user has issued a /clear command...
64 char lock;
64 } winbuf; 65 } winbuf;
65 66
66 67
67 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; 68 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd;
68 static WINDOW *mainstatusWnd, *chatstatusWnd; 69 static WINDOW *mainstatusWnd, *chatstatusWnd;
504 n = 0; 505 n = 0;
505 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) { 506 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) {
506 hbuf_head = g_list_previous(hbuf_head); 507 hbuf_head = g_list_previous(hbuf_head);
507 n++; 508 n++;
508 } 509 }
510 // If the buffer is locked, remember current "top" line for the next time.
511 if (win_entry->lock)
512 win_entry->top = hbuf_head;
509 } else 513 } else
510 hbuf_head = win_entry->top; 514 hbuf_head = win_entry->top;
511 515
512 // Get the last CHAT_WIN_HEIGHT lines. 516 // Get the last CHAT_WIN_HEIGHT lines.
513 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); 517 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
589 593
590 top_panel(win_entry->panel); 594 top_panel(win_entry->panel);
591 currentWindow = win_entry; 595 currentWindow = win_entry;
592 chatmode = TRUE; 596 chatmode = TRUE;
593 if (!special) { 597 if (!special) {
594 roster_msg_setflag(winId, FALSE); 598 if (!win_entry->lock)
599 roster_msg_setflag(winId, FALSE);
595 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE); 600 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE);
596 update_roster = TRUE; 601 update_roster = TRUE;
597 } 602 }
598 603
599 // Refresh the window 604 // Refresh the window
656 { 661 {
657 winbuf *win_entry; 662 winbuf *win_entry;
658 char *text_locale; 663 char *text_locale;
659 int dont_show = FALSE; 664 int dont_show = FALSE;
660 int special; 665 int special;
666 bool setmsgflg = FALSE;
661 667
662 // Look for the window entry. 668 // Look for the window entry.
663 special = (winId == NULL); 669 special = (winId == NULL);
664 win_entry = scr_SearchWindow(winId, special); 670 win_entry = scr_SearchWindow(winId, special);
665 671
682 win_entry = scr_CreateBuddyPanel(winId, dont_show); 688 win_entry = scr_CreateBuddyPanel(winId, dont_show);
683 } 689 }
684 } 690 }
685 691
686 // The message must be displayed -> update top pointer 692 // The message must be displayed -> update top pointer
687 if (win_entry->cleared) 693 if (!win_entry->lock && win_entry->cleared)
688 win_entry->top = g_list_last(win_entry->hbuf); 694 win_entry->top = g_list_last(win_entry->hbuf);
689 695
690 text_locale = from_utf8(text); 696 text_locale = from_utf8(text);
691 hbuf_add_line(&win_entry->hbuf, text_locale, timestamp, prefix_flags, 697 hbuf_add_line(&win_entry->hbuf, text_locale, timestamp, prefix_flags,
692 maxX - Roster_Width - PREFIX_WIDTH); 698 maxX - Roster_Width - PREFIX_WIDTH);
693 g_free(text_locale); 699 g_free(text_locale);
694 700
695 if (win_entry->cleared) { 701 if (!win_entry->lock && win_entry->cleared) {
696 win_entry->cleared = FALSE; 702 win_entry->cleared = FALSE;
697 if (g_list_next(win_entry->top)) 703 if (g_list_next(win_entry->top))
698 win_entry->top = g_list_next(win_entry->top); 704 win_entry->top = g_list_next(win_entry->top);
699 } 705 }
700 706
701 // Make sure the last line appears in the window; update top if necessary 707 // Make sure the last line appears in the window; update top if necessary
702 if (win_entry->top) { 708 if (!win_entry->lock && win_entry->top) {
703 int dist; 709 int dist;
704 GList *first = g_list_first(win_entry->hbuf); 710 GList *first = g_list_first(win_entry->hbuf);
705 dist = g_list_position(first, g_list_last(win_entry->hbuf)) - 711 dist = g_list_position(first, g_list_last(win_entry->hbuf)) -
706 g_list_position(first, win_entry->top); 712 g_list_position(first, win_entry->top);
707 if (dist >= CHAT_WIN_HEIGHT) 713 if (dist >= CHAT_WIN_HEIGHT)
708 win_entry->top = NULL; 714 win_entry->top = NULL;
709 } 715 }
710 716
711 if (!dont_show) { 717 if (!dont_show) {
718 if (win_entry->lock)
719 setmsgflg = TRUE;
712 // Show and refresh the window 720 // Show and refresh the window
713 top_panel(win_entry->panel); 721 top_panel(win_entry->panel);
714 scr_UpdateWindow(win_entry); 722 scr_UpdateWindow(win_entry);
715 top_panel(inputPanel); 723 top_panel(inputPanel);
716 update_panels(); 724 update_panels();
717 doupdate(); 725 doupdate();
718 } else if (!special && !(prefix_flags & HBB_PREFIX_NOFLAG)) { 726 } else if (!(prefix_flags & HBB_PREFIX_NOFLAG)) {
727 setmsgflg = TRUE;
728 }
729 if (setmsgflg && !special) {
719 roster_msg_setflag(winId, TRUE); 730 roster_msg_setflag(winId, TRUE);
720 update_roster = TRUE; 731 update_roster = TRUE;
721 } 732 }
722 } 733 }
723 734
1552 // Finished :) 1563 // Finished :)
1553 update_panels(); 1564 update_panels();
1554 doupdate(); 1565 doupdate();
1555 } 1566 }
1556 1567
1557 // scr_BufferTopBottom() 1568 // scr_BufferScrollLock(lock)
1558 // Jump to the head/tail of the current buddy window 1569 // Lock/unlock the current buddy buffer
1559 // (top if topbottom == -1, bottom topbottom == 1) 1570 // lock = 1 : lock
1560 void scr_BufferTopBottom(int topbottom) 1571 // lock = 0 : unlock
1572 // lock = -1: toggle lock status
1573 void scr_BufferScrollLock(int lock)
1561 { 1574 {
1562 winbuf *win_entry; 1575 winbuf *win_entry;
1563 guint isspe; 1576 guint isspe;
1564 1577
1565 // Get win_entry 1578 // Get win_entry
1566 if (!current_buddy) return; 1579 if (!current_buddy) return;
1567 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; 1580 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL;
1568 win_entry = scr_SearchWindow(CURRENT_JID, isspe); 1581 win_entry = scr_SearchWindow(CURRENT_JID, isspe);
1569 if (!win_entry) return; 1582 if (!win_entry) return;
1570 1583
1584 if (lock == -1)
1585 lock = !win_entry->lock;
1586
1587 if (lock) {
1588 win_entry->lock = TRUE;
1589 } else {
1590 win_entry->lock = FALSE;
1591 win_entry->cleared = FALSE;
1592 win_entry->top = NULL;
1593 }
1594
1595 // If chatmode is disabled and we're at the bottom of the buffer,
1596 // we need to set the "top" line, so we need to call scr_ShowBuddyWindow()
1597 // at least once. (Maybe it will cause a double refresh...)
1598 if (!chatmode && !win_entry->top) {
1599 chatmode = TRUE;
1600 scr_ShowBuddyWindow();
1601 chatmode = FALSE;
1602 }
1603
1604 // Refresh the window
1605 scr_UpdateBuddyWindow();
1606
1607 // Finished :)
1608 update_panels();
1609 doupdate();
1610 }
1611
1612 // scr_BufferTopBottom()
1613 // Jump to the head/tail of the current buddy window
1614 // (top if topbottom == -1, bottom topbottom == 1)
1615 void scr_BufferTopBottom(int topbottom)
1616 {
1617 winbuf *win_entry;
1618 guint isspe;
1619
1620 // Get win_entry
1621 if (!current_buddy) return;
1622 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL;
1623 win_entry = scr_SearchWindow(CURRENT_JID, isspe);
1624 if (!win_entry) return;
1625
1571 win_entry->cleared = FALSE; 1626 win_entry->cleared = FALSE;
1572 if (topbottom == 1) 1627 if (topbottom == 1)
1573 win_entry->top = NULL; 1628 win_entry->top = NULL;
1574 else 1629 else
1575 win_entry->top = g_list_first(win_entry->hbuf); 1630 win_entry->top = g_list_first(win_entry->hbuf);
1696 // scr_setmsgflag_if_needed(jid) 1751 // scr_setmsgflag_if_needed(jid)
1697 // Set the message flag unless we're already in the jid buffer window 1752 // Set the message flag unless we're already in the jid buffer window
1698 void scr_setmsgflag_if_needed(const char *jid) 1753 void scr_setmsgflag_if_needed(const char *jid)
1699 { 1754 {
1700 const char *current_jid; 1755 const char *current_jid;
1756 bool iscurrentlocked = FALSE;
1701 1757
1702 if (!jid) 1758 if (!jid)
1703 return; 1759 return;
1704 1760
1705 if (current_buddy) 1761 if (current_buddy) {
1762 guint isspe;
1763 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL;
1706 current_jid = buddy_getjid(BUDDATA(current_buddy)); 1764 current_jid = buddy_getjid(BUDDATA(current_buddy));
1707 else 1765 if (current_jid) {
1766 winbuf *win_entry = scr_SearchWindow(current_jid, isspe);
1767 iscurrentlocked = win_entry->lock;
1768 }
1769 } else {
1708 current_jid = NULL; 1770 current_jid = NULL;
1709 if (!chatmode || !current_jid || strcmp(jid, current_jid)) 1771 }
1772 if (!chatmode || !current_jid || strcmp(jid, current_jid) || iscurrentlocked)
1710 roster_msg_setflag(jid, TRUE); 1773 roster_msg_setflag(jid, TRUE);
1711 } 1774 }
1712 1775
1713 // scr_set_multimode() 1776 // scr_set_multimode()
1714 // Public function to (un)set multimode... 1777 // Public function to (un)set multimode...