2 * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
3 * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 #include "mutt_menu.h"
24 #include "mutt_curses.h"
31 /*BUFFY *CurBuffy = 0;*/
32 static BUFFY *TopBuffy = 0;
33 static BUFFY *BottomBuffy = 0;
34 static int known_lines = 0;
36 static int quick_log10(int n)
39 sprintf(string, "%d", n);
40 return strlen(string);
43 void calc_boundaries (int menu)
45 BUFFY *tmp = Incoming;
47 if ( known_lines != LINES ) {
48 TopBuffy = BottomBuffy = 0;
51 for ( ; tmp->next != 0; tmp = tmp->next )
52 tmp->next->prev = tmp;
54 if ( TopBuffy == 0 && BottomBuffy == 0 )
56 if ( BottomBuffy == 0 ) {
57 int count = LINES - 2 - (menu != MENU_PAGER);
58 BottomBuffy = TopBuffy;
59 while ( --count && BottomBuffy->next )
60 BottomBuffy = BottomBuffy->next;
62 else if ( TopBuffy == CurBuffy->next ) {
63 int count = LINES - 2 - (menu != MENU_PAGER);
64 BottomBuffy = CurBuffy;
66 while ( --count && tmp->prev)
70 else if ( BottomBuffy == CurBuffy->prev ) {
71 int count = LINES - 2 - (menu != MENU_PAGER);
74 while ( --count && tmp->next )
80 char *make_sidebar_entry(char *box, int size, int new)
82 static char *entry = 0;
86 c = realloc(entry, SidebarWidth + 1);
88 entry[SidebarWidth] = 0;
89 for (; i < SidebarWidth; entry[i++] = ' ' );
91 strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
95 entry + SidebarWidth - 5 - quick_log10(size) - quick_log10(new),
96 "% d(%d)", size, new);
98 sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
102 void set_curbuffy(char buf[LONG_STRING])
104 BUFFY* tmp = CurBuffy = Incoming;
110 if(!strcmp(tmp->path, buf)) {
122 int draw_sidebar(int menu) {
124 int lines = option(OPTHELP) ? 1 : 0;
126 #ifndef USE_SLANG_CURSES
131 static bool initialized = false;
132 static int prev_show_value;
133 static short saveSidebarWidth;
135 /* initialize first time */
137 prev_show_value = option(OPTMBOXPANE);
138 saveSidebarWidth = SidebarWidth;
139 if(!option(OPTMBOXPANE)) SidebarWidth = 0;
143 /* save or restore the value SidebarWidth */
144 if(prev_show_value != option(OPTMBOXPANE)) {
145 if(prev_show_value && !option(OPTMBOXPANE)) {
146 saveSidebarWidth = SidebarWidth;
148 } else if(!prev_show_value && option(OPTMBOXPANE)) {
149 SidebarWidth = saveSidebarWidth;
151 prev_show_value = option(OPTMBOXPANE);
155 if ( SidebarWidth == 0 ) return 0;
157 /* get attributes for divider */
158 SETCOLOR(MT_COLOR_STATUS);
159 #ifndef USE_SLANG_CURSES
160 attr_get(&attrs, &color_pair, 0);
162 color_pair = attr_get();
164 SETCOLOR(MT_COLOR_NORMAL);
166 /* draw the divider */
168 for ( ; lines < LINES-1-(menu != MENU_PAGER); lines++ ) {
169 move(lines, SidebarWidth - 1);
171 #ifndef USE_SLANG_CURSES
172 mvchgat(lines, SidebarWidth - 1, 1, 0, color_pair, NULL);
175 if ( Incoming == 0 ) return 0;
176 lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
178 if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
179 calc_boundaries(menu);
180 if ( CurBuffy == 0 ) CurBuffy = Incoming;
184 SETCOLOR(MT_COLOR_NORMAL);
186 for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER); tmp = tmp->next ) {
187 if ( tmp == CurBuffy )
188 SETCOLOR(MT_COLOR_INDICATOR);
189 else if ( tmp->msg_unread > 0 )
190 SETCOLOR(MT_COLOR_NEW);
192 SETCOLOR(MT_COLOR_NORMAL);
195 if ( Context && !strcmp( tmp->path, Context->path ) ) {
196 printw( "%.*s", SidebarWidth,
197 make_sidebar_entry(basename(tmp->path), Context->msgcount,
199 tmp->msg_unread = Context->unread;
200 tmp->msgcount = Context->msgcount;
203 printw( "%.*s", SidebarWidth,
204 make_sidebar_entry(basename(tmp->path), tmp->msgcount,
208 SETCOLOR(MT_COLOR_NORMAL);
209 for ( ; lines < LINES - 1 - (menu != MENU_PAGER); lines++ ) {
212 for ( ; i < SidebarWidth - 1; i++ )
218 void scroll_sidebar(int op, int menu)
220 if(!SidebarWidth) return;
221 if(!CurBuffy) return;
224 case OP_SIDEBAR_NEXT:
225 if ( CurBuffy->next == NULL ) return;
226 CurBuffy = CurBuffy->next;
228 case OP_SIDEBAR_PREV:
229 if ( CurBuffy == Incoming ) return;
231 BUFFY *tmp = Incoming;
232 while ( tmp->next && strcmp(tmp->next->path, CurBuffy->path) ) tmp = tmp->next;
236 case OP_SIDEBAR_SCROLL_UP:
238 if ( CurBuffy != Incoming ) {
239 calc_boundaries(menu);
240 CurBuffy = CurBuffy->prev;
243 case OP_SIDEBAR_SCROLL_DOWN:
244 CurBuffy = BottomBuffy;
245 if ( CurBuffy->next ) {
246 calc_boundaries(menu);
247 CurBuffy = CurBuffy->next;
253 calc_boundaries(menu);