1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/* $Id: wins.c,v 1.4 2007/08/04 14:34:03 culot Exp $ */
/*
* Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Send your feedback or comments to : calcurse@culot.org
* Calcurse home page : http://culot.org/calcurse
*
*/
#include <stdlib.h>
#include "i18n.h"
#include "notify.h"
#include "utils.h"
#include "todo.h"
#include "custom.h"
#include "wins.h"
static window_e slctd_win;
/* Initialize the selected window in calcurse's interface. */
void
wins_slctd_init(void)
{
wins_slctd_set(CALENDAR);
}
/* Returns an enum which corresponds to the window which is selected. */
window_e
wins_slctd(void)
{
return (slctd_win);
}
/* Sets the selected window. */
void
wins_slctd_set(window_e window)
{
slctd_win = window;
}
/* TAB key was hit in the interface, need to select next window. */
void
wins_slctd_next(void)
{
if (slctd_win == TODO)
slctd_win = CALENDAR;
else
slctd_win++;
}
/* Create all the windows. */
void
wins_init(window_t *wincal, window_t *winapp, window_t *wintod,
window_t *winbar)
{
char label[BUFSIZ];
/*
* Create the three main windows plus the status bar and the pad used to
* display appointments and event.
*/
cwin = newwin(CALHEIGHT, CALWIDTH, wincal->y, wincal->x);
snprintf(label, BUFSIZ, _("Calendar"));
wins_show(cwin, label);
awin = newwin(winapp->h, winapp->w, winapp->y, winapp->x);
snprintf(label, BUFSIZ, _("Appointments"));
wins_show(awin, label);
apad->width = winapp->w - 3;
apad->ptrwin = newpad(apad->length, apad->width);
twin = newwin(wintod->h, wintod->w, wintod->y, wintod->x);
snprintf(label, BUFSIZ, _("ToDo"));
wins_show(twin, label);
swin = newwin(winbar->h, winbar->w, winbar->y, winbar->x);
/* Enable function keys (i.e. arrow keys) in those windows */
keypad(swin, TRUE);
keypad(twin, TRUE);
keypad(awin, TRUE);
keypad(cwin, TRUE);
}
/*
* Delete the existing windows and recreate them with their new
* size and placement.
*/
void
wins_reinit(conf_t *conf, window_t *winbar, window_t *winapp,
window_t *wintod, window_t *wincal, window_t *winnot)
{
clear();
delwin(swin);
delwin(cwin);
delwin(awin);
delwin(apad->ptrwin);
delwin(twin);
wins_get_config(conf, winbar, winnot, winapp, wintod, wincal);
wins_init(wincal, winapp, wintod, winbar);
if (notify_bar())
notify_reinit_bar(winnot->h, winnot->w, winnot->y, winnot->x);
}
/* Show the window with a border and a label. */
void
wins_show(WINDOW * win, char *label)
{
int startx, starty, height, width;
getbegyx(win, starty, startx);
getmaxyx(win, height, width);
box(win, 0, 0);
mvwaddch(win, 2, 0, ACS_LTEE);
mvwhline(win, 2, 1, ACS_HLINE, width - 2);
mvwaddch(win, 2, width - 1, ACS_RTEE);
print_in_middle(win, 1, 0, width, label);
}
/*
* Get the screen size and recalculate the windows configurations.
*/
void
wins_get_config(conf_t *conf, window_t *status, window_t *notify,
window_t *apts, window_t *todo, window_t *calr)
{
/* Get the screen configuration */
getmaxyx(stdscr, row, col);
/* fixed values for status, notification bars and calendar */
status->h = STATUSHEIGHT;
status->w = col;
status->y = row - status->h;
status->x = 0;
if (notify_bar()) {
notify->h = 1;
notify->w = col;
notify->y = status->y - 1;
notify->x = 0;
} else {
notify->h = 0;
notify->w = 0;
notify->y = 0;
notify->x = 0;
}
if (conf->layout <= 4) { /* APPOINTMENT is the biggest panel */
apts->w = col - CALWIDTH;
apts->h = row - (status->h + notify->h);
todo->w = CALWIDTH;
todo->h = row - (CALHEIGHT + status->h + notify->h);
} else { /* TODO is the biggest panel */
todo->w = col - CALWIDTH;
todo->h = row - (status->h + notify->h);
apts->w = CALWIDTH;
apts->h = row - (CALHEIGHT + status->h + notify->h);
}
/* defining the layout */
switch (conf->layout) {
case 1:
apts->y = 0;
apts->x = 0;
calr->y = 0;
todo->x = apts->w;
todo->y = CALHEIGHT;
calr->x = apts->w;
break;
case 2:
apts->y = 0;
apts->x = 0;
todo->y = 0;
todo->x = apts->w;
calr->x = apts->w;
calr->y = todo->h;
break;
case 3:
apts->y = 0;
todo->x = 0;
calr->x = 0;
calr->y = 0;
apts->x = CALWIDTH;
todo->y = CALHEIGHT;
break;
case 4:
apts->y = 0;
todo->x = 0;
todo->y = 0;
calr->x = 0;
apts->x = CALWIDTH;
calr->y = todo->h;
break;
case 5:
todo->y = 0;
todo->x = 0;
calr->y = 0;
apts->y = CALHEIGHT;
apts->x = todo->w;
calr->x = todo->w;
break;
case 6:
todo->y = 0;
todo->x = 0;
apts->y = 0;
apts->x = todo->w;
calr->x = todo->w;
calr->y = apts->h;
break;
case 7:
todo->y = 0;
apts->x = 0;
calr->x = 0;
calr->y = 0;
todo->x = CALWIDTH;
apts->y = CALHEIGHT;
break;
case 8:
todo->y = 0;
apts->x = 0;
calr->x = 0;
apts->y = 0;
todo->x = CALWIDTH;
calr->y = apts->h;
break;
}
}
/* draw panel border in color */
static void
border_color(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_BOLD;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
box(window, 0, 0);
} else {
wattron(window, no_color_attr);
box(window, 0, 0);
}
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/* draw panel border without any color */
static void
border_nocolor(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_DIM;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattron(window, no_color_attr);
}
box(window, 0, 0);
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/*
* Update all of the three windows and put a border around the
* selected window.
*/
void
wins_update(conf_t *conf, window_t *winbar, window_t *winapp, window_t *wintod,
int hilt_app, int hilt_tod, int nb_tod, int first_todo_onscreen,
char **saved_t_mesg)
{
switch (slctd_win) {
case CALENDAR:
border_color(cwin);
border_nocolor(awin);
border_nocolor(twin);
break;
case APPOINTMENT:
border_color(awin);
border_nocolor(cwin);
border_nocolor(twin);
break;
case TODO:
border_color(twin);
border_nocolor(awin);
border_nocolor(cwin);
break;
default:
ierror(_("FATAL ERROR in wins_update: no window selected\n"));
/* NOTREACHED */
}
apoint_update_panel(winapp, hilt_app, slctd_win);
todo_update_panel(wintod, hilt_tod, nb_tod, slctd_win,
first_todo_onscreen, saved_t_mesg);
calendar_update_panel(cwin);
status_bar();
if (notify_bar())
notify_update_bar();
wmove(swin, 0, 0);
doupdate();
}
|