comparison mcabber/src/screen.c @ 105:91d3ec21c24e

[/trunk] Changeset 119 by mikael * History scrolling.
author mikael
date Fri, 22 Apr 2005 21:35:51 +0000
parents fe7257d251ac
children 7fb72bc13732
comparison
equal deleted inserted replaced
104:fe7257d251ac 105:91d3ec21c24e
25 typedef struct _window_entry_t { 25 typedef struct _window_entry_t {
26 WINDOW *win; 26 WINDOW *win;
27 PANEL *panel; 27 PANEL *panel;
28 char *name; 28 char *name;
29 GList *hbuf; 29 GList *hbuf;
30 GList *top; // If top is not specified (NULL), we'll display the last lines
30 struct list_head list; 31 struct list_head list;
31 } window_entry_t; 32 } window_entry_t;
32 33
33 34
34 static WINDOW *rosterWnd, *chatWnd, *inputWnd; 35 static WINDOW *rosterWnd, *chatWnd, *inputWnd;
223 int n; 224 int n;
224 int width; 225 int width;
225 char **lines; 226 char **lines;
226 GList *hbuf_head; 227 GList *hbuf_head;
227 228
229 // win_entry->top is the top message of the screen. If it set to NULL, we
230 // are displaying the last messages.
231
228 // We will show the last CHAT_WIN_HEIGHT lines. 232 // We will show the last CHAT_WIN_HEIGHT lines.
229 // Let's find out where it begins. 233 // Let's find out where it begins.
230 win_entry->hbuf = g_list_last(win_entry->hbuf); 234 if (!win_entry->top ||
231 hbuf_head = win_entry->hbuf; 235 (g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) {
232 for (n=0; hbuf_head && n<(CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head); n++) 236 // Move up CHAT_WIN_HEIGHT lines
233 hbuf_head = g_list_previous(hbuf_head); 237 win_entry->hbuf = g_list_last(win_entry->hbuf);
238 hbuf_head = win_entry->hbuf;
239 win_entry->top = NULL; // (Just to make sure)
240 n = 0;
241 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) {
242 hbuf_head = g_list_previous(hbuf_head);
243 n++;
244 }
245 } else
246 hbuf_head = win_entry->top;
234 247
235 // Get the last CHAT_WIN_HEIGHT lines. 248 // Get the last CHAT_WIN_HEIGHT lines.
236 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); 249 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
237 250
238 // Display these lines 251 // Display these lines
268 currentWindow = win_entry; 281 currentWindow = win_entry;
269 chatmode = TRUE; 282 chatmode = TRUE;
270 roster_setflags(winId, ROSTER_FLAG_MSG, FALSE); 283 roster_setflags(winId, ROSTER_FLAG_MSG, FALSE);
271 update_roster = TRUE; 284 update_roster = TRUE;
272 285
273 // Refresh the window entry 286 // Refresh the window
274 scr_UpdateWindow(win_entry); 287 scr_UpdateWindow(win_entry);
275 288
276 // Finished :) 289 // Finished :)
277 update_panels(); 290 update_panels();
278 doupdate(); 291 doupdate();
282 } 295 }
283 } 296 }
284 297
285 void scr_ShowBuddyWindow(void) 298 void scr_ShowBuddyWindow(void)
286 { 299 {
287 const gchar *jid = CURRENT_JID; 300 const gchar *jid;
288 if (jid != NULL) 301 if (!current_buddy)
289 scr_ShowWindow(jid); 302 return;
303 jid = CURRENT_JID;
304 if (!jid)
305 return;
306 scr_ShowWindow(jid);
290 top_panel(inputPanel); 307 top_panel(inputPanel);
291 } 308 }
292 309
293 310
294 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, 311 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp,
533 WINDOW *scr_GetInputWindow(void) 550 WINDOW *scr_GetInputWindow(void)
534 { 551 {
535 return inputWnd; 552 return inputWnd;
536 } 553 }
537 554
538 void scr_RosterTop() 555 void scr_RosterTop(void)
539 { 556 {
540 current_buddy = buddylist; 557 current_buddy = buddylist;
541 // XXX We should rebuild the buddylist but perhaps not everytime? 558 // XXX We should rebuild the buddylist but perhaps not everytime?
542 if (chatmode) 559 if (chatmode)
543 scr_ShowBuddyWindow(); 560 scr_ShowBuddyWindow();
544 } 561 }
545 562
546 void scr_RosterBottom() 563 void scr_RosterBottom(void)
547 { 564 {
548 current_buddy = g_list_last(buddylist); 565 current_buddy = g_list_last(buddylist);
549 // XXX We should rebuild the buddylist but perhaps not everytime? 566 // XXX We should rebuild the buddylist but perhaps not everytime?
550 if (chatmode) 567 if (chatmode)
551 scr_ShowBuddyWindow(); 568 scr_ShowBuddyWindow();
552 } 569 }
553 570
554 void scr_RosterUp() 571 void scr_RosterUp(void)
555 { 572 {
556 if (current_buddy) { 573 if (current_buddy) {
557 if (g_list_previous(current_buddy)) { 574 if (g_list_previous(current_buddy)) {
558 current_buddy = g_list_previous(current_buddy); 575 current_buddy = g_list_previous(current_buddy);
559 scr_DrawRoster(); 576 scr_DrawRoster();
563 580
564 if (chatmode) 581 if (chatmode)
565 scr_ShowBuddyWindow(); 582 scr_ShowBuddyWindow();
566 } 583 }
567 584
568 void scr_RosterDown() 585 void scr_RosterDown(void)
569 { 586 {
570 if (current_buddy) { 587 if (current_buddy) {
571 if (g_list_next(current_buddy)) { 588 if (g_list_next(current_buddy)) {
572 current_buddy = g_list_next(current_buddy); 589 current_buddy = g_list_next(current_buddy);
573 scr_DrawRoster(); 590 scr_DrawRoster();
575 } 592 }
576 // XXX We should rebuild the buddylist but perhaps not everytime? 593 // XXX We should rebuild the buddylist but perhaps not everytime?
577 594
578 if (chatmode) 595 if (chatmode)
579 scr_ShowBuddyWindow(); 596 scr_ShowBuddyWindow();
597 }
598
599 void scr_ScrollUp(void)
600 {
601 const gchar *jid;
602 window_entry_t *win_entry;
603 int n, nblines;
604 GList *hbuf_top;
605
606 // Get win_entry
607 if (!current_buddy)
608 return;
609 jid = CURRENT_JID;
610 if (!jid)
611 return;
612 win_entry = scr_SearchWindow(jid);
613 if (!win_entry)
614 return;
615
616 // Scroll up half a screen (or less)
617 nblines = CHAT_WIN_HEIGHT/2-1;
618 hbuf_top = win_entry->top;
619 if (!hbuf_top) {
620 hbuf_top = g_list_last(win_entry->hbuf);
621 nblines *= 3;
622 }
623
624 n = 0;
625 while (hbuf_top && n < nblines && g_list_previous(hbuf_top)) {
626 hbuf_top = g_list_previous(hbuf_top);
627 n++;
628 }
629 win_entry->top = hbuf_top;
630
631 // Refresh the window
632 scr_UpdateWindow(win_entry);
633
634 // Finished :)
635 update_panels();
636 doupdate();
637 }
638
639 void scr_ScrollDown(void)
640 {
641 const gchar *jid;
642 window_entry_t *win_entry;
643 int n, nblines;
644 GList *hbuf_top;
645
646 // Get win_entry
647 if (!current_buddy)
648 return;
649 jid = CURRENT_JID;
650 if (!jid)
651 return;
652 win_entry = scr_SearchWindow(jid);
653 if (!win_entry)
654 return;
655
656 // Scroll down half a screen (or less)
657 nblines = CHAT_WIN_HEIGHT/2-1;
658 hbuf_top = win_entry->top;
659
660 for (n=0 ; hbuf_top && n < nblines ; n++)
661 hbuf_top = g_list_next(hbuf_top);
662 win_entry->top = hbuf_top;
663 // Check if we are at the bottom
664 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++)
665 hbuf_top = g_list_next(hbuf_top);
666 if (!hbuf_top)
667 win_entry->top = NULL; // End reached
668
669 // Refresh the window
670 scr_UpdateWindow(win_entry);
671
672 // Finished :)
673 update_panels();
674 doupdate();
580 } 675 }
581 676
582 // scr_LogPrint(...) 677 // scr_LogPrint(...)
583 // Display a message in the log window. 678 // Display a message in the log window.
584 void scr_LogPrint(const char *fmt, ...) 679 void scr_LogPrint(const char *fmt, ...)
812 break; 907 break;
813 case KEY_DOWN: 908 case KEY_DOWN:
814 scr_RosterDown(); 909 scr_RosterDown();
815 break; 910 break;
816 case KEY_PPAGE: 911 case KEY_PPAGE:
817 scr_LogPrint("PageUp??"); 912 scr_ScrollUp();
818 break; 913 break;
819 case KEY_NPAGE: 914 case KEY_NPAGE:
820 scr_LogPrint("PageDown??"); 915 scr_ScrollDown();
821 break; 916 break;
822 case KEY_HOME: 917 case KEY_HOME:
823 case 1: 918 case 1:
824 ptr_inputline = inputLine; 919 ptr_inputline = inputLine;
825 inputline_offset = 0; 920 inputline_offset = 0;