Mercurial > hg
comparison mcabber/src/screen.c @ 108:7fb72bc13732
[/trunk] Changeset 122 by mikael
* Add /clear command.
author | mikael |
---|---|
date | Fri, 22 Apr 2005 22:06:53 +0000 |
parents | 91d3ec21c24e |
children | 96d239239c7a |
comparison
equal
deleted
inserted
replaced
107:57daf8da91d1 | 108:7fb72bc13732 |
---|---|
22 | 22 |
23 LIST_HEAD(window_list); | 23 LIST_HEAD(window_list); |
24 | 24 |
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 GList *top; // If top is not specified (NULL), we'll display the last lines |
31 char cleared; // For ex, user has issued a /clear command... | |
31 struct list_head list; | 32 struct list_head list; |
32 } window_entry_t; | 33 } window_entry_t; |
33 | 34 |
34 | 35 |
35 static WINDOW *rosterWnd, *chatWnd, *inputWnd; | 36 static WINDOW *rosterWnd, *chatWnd, *inputWnd; |
224 int n; | 225 int n; |
225 int width; | 226 int width; |
226 char **lines; | 227 char **lines; |
227 GList *hbuf_head; | 228 GList *hbuf_head; |
228 | 229 |
230 width = scr_WindowWidth(win_entry->win); | |
231 | |
232 // Should the window be empty? | |
233 if (win_entry->cleared) { | |
234 scr_clear_box(win_entry->win, 0, 0, CHAT_WIN_HEIGHT, width, COLOR_GENERAL); | |
235 return; | |
236 } | |
237 | |
229 // win_entry->top is the top message of the screen. If it set to NULL, we | 238 // win_entry->top is the top message of the screen. If it set to NULL, we |
230 // are displaying the last messages. | 239 // are displaying the last messages. |
231 | 240 |
232 // We will show the last CHAT_WIN_HEIGHT lines. | 241 // We will show the last CHAT_WIN_HEIGHT lines. |
233 // Let's find out where it begins. | 242 // Let's find out where it begins. |
247 | 256 |
248 // Get the last CHAT_WIN_HEIGHT lines. | 257 // Get the last CHAT_WIN_HEIGHT lines. |
249 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); | 258 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); |
250 | 259 |
251 // Display these lines | 260 // Display these lines |
252 width = scr_WindowWidth(win_entry->win); | |
253 wmove(win_entry->win, 0, 0); | 261 wmove(win_entry->win, 0, 0); |
254 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | 262 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
255 int r = width; | 263 int r = width; |
256 if (*(lines+2*n)) { | 264 if (*(lines+2*n)) { |
257 if (**(lines+2*n)) | 265 if (**(lines+2*n)) |
345 | 353 |
346 hbuf_add_line(&win_entry->hbuf, text, fullprefix, | 354 hbuf_add_line(&win_entry->hbuf, text, fullprefix, |
347 maxX - scr_WindowWidth(rosterWnd) - 14); | 355 maxX - scr_WindowWidth(rosterWnd) - 14); |
348 free(fullprefix); | 356 free(fullprefix); |
349 | 357 |
358 if (win_entry->cleared) { | |
359 win_entry->cleared = 0; // The message must be displayed | |
360 win_entry->top = g_list_last(win_entry->hbuf); | |
361 } | |
362 | |
350 if (!dont_show) { | 363 if (!dont_show) { |
351 // Show and refresh the window | 364 // Show and refresh the window |
352 top_panel(win_entry->panel); | 365 top_panel(win_entry->panel); |
353 scr_UpdateWindow(win_entry); | 366 scr_UpdateWindow(win_entry); |
354 update_panels(); | 367 update_panels(); |
663 // Check if we are at the bottom | 676 // Check if we are at the bottom |
664 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) | 677 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) |
665 hbuf_top = g_list_next(hbuf_top); | 678 hbuf_top = g_list_next(hbuf_top); |
666 if (!hbuf_top) | 679 if (!hbuf_top) |
667 win_entry->top = NULL; // End reached | 680 win_entry->top = NULL; // End reached |
681 | |
682 // Refresh the window | |
683 scr_UpdateWindow(win_entry); | |
684 | |
685 // Finished :) | |
686 update_panels(); | |
687 doupdate(); | |
688 } | |
689 | |
690 void scr_Clear(void) | |
691 { | |
692 const gchar *jid; | |
693 window_entry_t *win_entry; | |
694 | |
695 // Get win_entry | |
696 if (!current_buddy) | |
697 return; | |
698 jid = CURRENT_JID; | |
699 if (!jid) | |
700 return; | |
701 win_entry = scr_SearchWindow(jid); | |
702 if (!win_entry) | |
703 return; | |
704 | |
705 win_entry->cleared = TRUE; | |
668 | 706 |
669 // Refresh the window | 707 // Refresh the window |
670 scr_UpdateWindow(win_entry); | 708 scr_UpdateWindow(win_entry); |
671 | 709 |
672 // Finished :) | 710 // Finished :) |