Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 143:300bb88f631f
[/trunk] Changeset 155 by mikael
* Check top_panel() occurences etc. for cursor problems...
* Replace scr_DrawRoaster() by "update_roster = TRUE" when possible
to have some optimization.
* Comments, clean up...
author | mikael |
---|---|
date | Fri, 29 Apr 2005 14:44:02 +0000 |
parents | bb6fe91589b9 |
children | c3624b2a7059 |
comparison
equal
deleted
inserted
replaced
142:bb6fe91589b9 | 143:300bb88f631f |
---|---|
185 tmp->panel = new_panel(tmp->win); | 185 tmp->panel = new_panel(tmp->win); |
186 tmp->name = (char *) calloc(1, 1024); | 186 tmp->name = (char *) calloc(1, 1024); |
187 strncpy(tmp->name, title, 1024); | 187 strncpy(tmp->name, title, 1024); |
188 scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL); | 188 scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL); |
189 | 189 |
190 if ((!dont_show)) { | 190 if (!dont_show) { |
191 currentWindow = tmp; | 191 currentWindow = tmp; |
192 } else { | 192 } else { |
193 if (currentWindow) | 193 if (currentWindow) |
194 top_panel(currentWindow->panel); | 194 top_panel(currentWindow->panel); |
195 else | 195 else |
196 top_panel(chatPanel); | 196 top_panel(chatPanel); |
197 } | 197 } |
198 update_panels(); | |
198 | 199 |
199 list_add_tail(&tmp->list, &window_list); | 200 list_add_tail(&tmp->list, &window_list); |
200 update_panels(); | |
201 | 201 |
202 return tmp; | 202 return tmp; |
203 } | 203 } |
204 | 204 |
205 window_entry_t *scr_SearchWindow(const char *winId) | 205 window_entry_t *scr_SearchWindow(const char *winId) |
216 } | 216 } |
217 } | 217 } |
218 return NULL; | 218 return NULL; |
219 } | 219 } |
220 | 220 |
221 // scr_UpdateWindow() | |
222 // (Re-)Display the given chat window. | |
221 void scr_UpdateWindow(window_entry_t *win_entry) | 223 void scr_UpdateWindow(window_entry_t *win_entry) |
222 { | 224 { |
223 int n; | 225 int n; |
224 int width; | 226 int width; |
225 char **lines; | 227 char **lines; |
276 //// wclrtoeol(win_entry->win); does not work :( | 278 //// wclrtoeol(win_entry->win); does not work :( |
277 } | 279 } |
278 g_free(lines); | 280 g_free(lines); |
279 } | 281 } |
280 | 282 |
283 // scr_ShowWindow() | |
284 // Display the chat window with the given identifier. | |
281 void scr_ShowWindow(const char *winId) | 285 void scr_ShowWindow(const char *winId) |
282 { | 286 { |
283 window_entry_t *win_entry = scr_SearchWindow(winId); | 287 window_entry_t *win_entry = scr_SearchWindow(winId); |
284 | 288 |
285 if (win_entry != NULL) { | 289 if (win_entry != NULL) { |
302 } | 306 } |
303 | 307 |
304 top_panel(inputPanel); | 308 top_panel(inputPanel); |
305 } | 309 } |
306 | 310 |
311 // scr_ShowBuddyWindow() | |
312 // Display the chat window buffer for the current buddy. | |
307 void scr_ShowBuddyWindow(void) | 313 void scr_ShowBuddyWindow(void) |
308 { | 314 { |
309 const gchar *jid; | 315 const gchar *jid; |
310 | 316 |
311 if (!current_buddy) | 317 if (!current_buddy) |
313 else | 319 else |
314 jid = CURRENT_JID; | 320 jid = CURRENT_JID; |
315 | 321 |
316 if (!jid) { | 322 if (!jid) { |
317 top_panel(chatPanel); | 323 top_panel(chatPanel); |
324 top_panel(inputPanel); | |
318 currentWindow = NULL; | 325 currentWindow = NULL; |
319 return; | 326 return; |
320 } | 327 } |
321 | 328 |
322 scr_ShowWindow(jid); | 329 scr_ShowWindow(jid); |
323 } | 330 } |
324 | 331 |
325 | 332 |
333 // scr_WriteInWindow() | |
334 // Write some text in the winId window (this usually is a jid). | |
335 // Lines are splitted when they are too long to fit in the chat window. | |
336 // If this window doesn't exist, it is created. | |
326 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, | 337 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, |
327 const char *prefix, int force_show) | 338 const char *prefix, int force_show) |
328 { | 339 { |
329 char *fullprefix = NULL; | 340 char *fullprefix = NULL; |
330 window_entry_t *win_entry; | 341 window_entry_t *win_entry; |
441 | 452 |
442 scr_DrawRoster(); | 453 scr_DrawRoster(); |
443 return; | 454 return; |
444 } | 455 } |
445 | 456 |
457 // scr_DrawRoster() | |
458 // Actually, display the buddylist on the screen. | |
446 void scr_DrawRoster(void) | 459 void scr_DrawRoster(void) |
447 { | 460 { |
448 static guint offset = 0; | 461 static guint offset = 0; |
449 char name[ROSTER_WIDTH]; | 462 char name[ROSTER_WIDTH]; |
450 int maxx, maxy; | 463 int maxx, maxy; |
562 } | 575 } |
563 | 576 |
564 int scr_Getch(void) | 577 int scr_Getch(void) |
565 { | 578 { |
566 int ch; | 579 int ch; |
567 // keypad(inputWnd, TRUE); | |
568 ch = wgetch(inputWnd); | 580 ch = wgetch(inputWnd); |
569 return ch; | 581 return ch; |
570 } | 582 } |
571 | 583 |
572 WINDOW *scr_GetRosterWindow(void) | 584 WINDOW *scr_GetRosterWindow(void) |
582 WINDOW *scr_GetInputWindow(void) | 594 WINDOW *scr_GetInputWindow(void) |
583 { | 595 { |
584 return inputWnd; | 596 return inputWnd; |
585 } | 597 } |
586 | 598 |
599 // scr_RosterTop() | |
600 // Go to the first buddy in the buddylist | |
587 void scr_RosterTop(void) | 601 void scr_RosterTop(void) |
588 { | 602 { |
589 enum imstatus prev_st; | 603 enum imstatus prev_st = imstatus_size; // undef |
590 | 604 |
591 if (current_buddy) { | 605 if (current_buddy) { |
592 prev_st = buddy_getstatus(BUDDATA(current_buddy)); | 606 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
593 if (chatmode) | 607 if (chatmode) |
594 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 608 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
596 current_buddy = buddylist; | 610 current_buddy = buddylist; |
597 if (chatmode && current_buddy) | 611 if (chatmode && current_buddy) |
598 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); | 612 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
599 | 613 |
600 // We should rebuild the buddylist but not everytime | 614 // We should rebuild the buddylist but not everytime |
615 // Here we check if we were locking a buddy who is actually offline, | |
616 // and hide_offline_buddies is TRUE. In which case we need to rebuild. | |
601 if (current_buddy && prev_st == offline && | 617 if (current_buddy && prev_st == offline && |
602 buddylist_get_hide_offline_buddies()) | 618 buddylist_get_hide_offline_buddies()) |
603 buddylist_build(); | 619 buddylist_build(); |
604 if (chatmode) | 620 if (chatmode) |
605 scr_ShowBuddyWindow(); | 621 scr_ShowBuddyWindow(); |
606 } | 622 update_roster = TRUE; |
607 | 623 } |
624 | |
625 // scr_RosterBottom() | |
626 // Go to the last buddy in the buddylist | |
608 void scr_RosterBottom(void) | 627 void scr_RosterBottom(void) |
609 { | 628 { |
610 enum imstatus prev_st; | 629 enum imstatus prev_st = imstatus_size; // undef |
611 | 630 |
612 if (current_buddy) { | 631 if (current_buddy) { |
613 prev_st = buddy_getstatus(BUDDATA(current_buddy)); | 632 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
614 if (chatmode) | 633 if (chatmode) |
615 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 634 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
616 } | 635 } |
617 current_buddy = g_list_last(buddylist); | 636 current_buddy = g_list_last(buddylist); |
637 // Lock the buddy in the buddylist if we're in chat mode | |
618 if (chatmode && current_buddy) | 638 if (chatmode && current_buddy) |
619 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); | 639 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
620 | 640 |
621 // We should rebuild the buddylist but not everytime | 641 // We should rebuild the buddylist but not everytime |
642 // Here we check if we were locking a buddy who is actually offline, | |
643 // and hide_offline_buddies is TRUE. In which case we need to rebuild. | |
622 if (current_buddy && prev_st == offline && | 644 if (current_buddy && prev_st == offline && |
623 buddylist_get_hide_offline_buddies()) | 645 buddylist_get_hide_offline_buddies()) |
624 buddylist_build(); | 646 buddylist_build(); |
647 | |
625 if (chatmode) | 648 if (chatmode) |
626 scr_ShowBuddyWindow(); | 649 scr_ShowBuddyWindow(); |
627 } | 650 update_roster = TRUE; |
628 | 651 } |
652 | |
653 // scr_RosterUp() | |
654 // Go to the previous buddy in the buddylist | |
629 void scr_RosterUp(void) | 655 void scr_RosterUp(void) |
630 { | 656 { |
631 enum imstatus prev_st; | 657 enum imstatus prev_st = imstatus_size; // undef |
632 | 658 |
633 if (current_buddy) { | 659 if (current_buddy) { |
634 if (g_list_previous(current_buddy)) { | 660 if (g_list_previous(current_buddy)) { |
635 prev_st = buddy_getstatus(BUDDATA(current_buddy)); | 661 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
636 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 662 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
637 current_buddy = g_list_previous(current_buddy); | 663 current_buddy = g_list_previous(current_buddy); |
664 // Lock the buddy in the buddylist if we're in chat mode | |
638 if (chatmode) | 665 if (chatmode) |
639 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); | 666 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
640 // We should rebuild the buddylist but not everytime | 667 // We should rebuild the buddylist but not everytime |
668 // Here we check if we were locking a buddy who is actually offline, | |
669 // and hide_offline_buddies is TRUE. In which case we need to rebuild. | |
641 if (prev_st == offline && buddylist_get_hide_offline_buddies()) | 670 if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
642 buddylist_build(); | 671 buddylist_build(); |
643 scr_DrawRoster(); | 672 update_roster = TRUE; |
644 } | 673 } |
645 } | 674 } |
646 | 675 |
647 if (chatmode) | 676 if (chatmode) |
648 scr_ShowBuddyWindow(); | 677 scr_ShowBuddyWindow(); |
649 } | 678 } |
650 | 679 |
680 // scr_RosterDown() | |
681 // Go to the next buddy in the buddylist | |
651 void scr_RosterDown(void) | 682 void scr_RosterDown(void) |
652 { | 683 { |
653 enum imstatus prev_st; | 684 enum imstatus prev_st = imstatus_size; // undef |
654 | 685 |
655 if (current_buddy) { | 686 if (current_buddy) { |
656 if (g_list_next(current_buddy)) { | 687 if (g_list_next(current_buddy)) { |
657 prev_st = buddy_getstatus(BUDDATA(current_buddy)); | 688 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
658 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | 689 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
659 current_buddy = g_list_next(current_buddy); | 690 current_buddy = g_list_next(current_buddy); |
660 if (chatmode) | 691 if (chatmode) |
661 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); | 692 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
662 // We should rebuild the buddylist but not everytime | 693 // We should rebuild the buddylist but not everytime |
694 // Here we check if we were locking a buddy who is actually offline, | |
695 // and hide_offline_buddies is TRUE. In which case we need to rebuild. | |
663 if (prev_st == offline && buddylist_get_hide_offline_buddies()) | 696 if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
664 buddylist_build(); | 697 buddylist_build(); |
665 scr_DrawRoster(); | 698 update_roster = TRUE; |
666 } | 699 } |
667 } | 700 } |
668 | 701 |
669 if (chatmode) | 702 if (chatmode) |
670 scr_ShowBuddyWindow(); | 703 scr_ShowBuddyWindow(); |
671 } | 704 } |
672 | 705 |
706 // scr_ScrollUp() | |
707 // Scroll up the current buddy window, half a screen. | |
673 void scr_ScrollUp(void) | 708 void scr_ScrollUp(void) |
674 { | 709 { |
675 const gchar *jid; | 710 const gchar *jid; |
676 window_entry_t *win_entry; | 711 window_entry_t *win_entry; |
677 int n, nblines; | 712 int n, nblines; |
711 // Finished :) | 746 // Finished :) |
712 update_panels(); | 747 update_panels(); |
713 doupdate(); | 748 doupdate(); |
714 } | 749 } |
715 | 750 |
751 // scr_ScrollDown() | |
752 // Scroll down the current buddy window, half a screen. | |
716 void scr_ScrollDown(void) | 753 void scr_ScrollDown(void) |
717 { | 754 { |
718 const gchar *jid; | 755 const gchar *jid; |
719 window_entry_t *win_entry; | 756 window_entry_t *win_entry; |
720 int n, nblines; | 757 int n, nblines; |
749 // Finished :) | 786 // Finished :) |
750 update_panels(); | 787 update_panels(); |
751 doupdate(); | 788 doupdate(); |
752 } | 789 } |
753 | 790 |
791 // scr_Clear() | |
792 // Clear the current buddy window (used for the /clear command) | |
754 void scr_Clear(void) | 793 void scr_Clear(void) |
755 { | 794 { |
756 const gchar *jid; | 795 const gchar *jid; |
757 window_entry_t *win_entry; | 796 window_entry_t *win_entry; |
758 | 797 |
800 | 839 |
801 update_panels(); | 840 update_panels(); |
802 doupdate(); | 841 doupdate(); |
803 } | 842 } |
804 | 843 |
844 // scr_set_chatmode() | |
845 // Public fonction to (un)set chatmode... | |
805 inline void scr_set_chatmode(int enable) | 846 inline void scr_set_chatmode(int enable) |
806 { | 847 { |
807 chatmode = enable; | 848 chatmode = enable; |
808 } | 849 } |
809 | 850 |
840 } | 881 } |
841 } | 882 } |
842 return row; | 883 return row; |
843 } | 884 } |
844 | 885 |
886 // scr_insert_text() | |
887 // Insert the given text at the current cursor position. | |
888 // The cursor is moved. We don't check if the cursor still is in the screen | |
889 // after, the caller should do that. | |
845 void scr_insert_text(const char *text) | 890 void scr_insert_text(const char *text) |
846 { | 891 { |
847 char tmpLine[INPUTLINE_LENGTH+1]; | 892 char tmpLine[INPUTLINE_LENGTH+1]; |
848 int len = strlen(text); | 893 int len = strlen(text); |
849 // Check the line isn't too long | 894 // Check the line isn't too long |
855 strcpy(tmpLine, ptr_inputline); | 900 strcpy(tmpLine, ptr_inputline); |
856 strcpy(ptr_inputline, text); ptr_inputline += len; | 901 strcpy(ptr_inputline, text); ptr_inputline += len; |
857 strcpy(ptr_inputline, tmpLine); | 902 strcpy(ptr_inputline, tmpLine); |
858 } | 903 } |
859 | 904 |
905 // scr_handle_tab() | |
906 // Function called when tab is pressed. | |
907 // Initiate or continue a completion... | |
860 void scr_handle_tab(void) | 908 void scr_handle_tab(void) |
861 { | 909 { |
862 int nrow; | 910 int nrow; |
863 char *row; | 911 char *row; |
864 const char *cchar; | 912 const char *cchar; |