summaryrefslogtreecommitdiff
path: root/src/custom.c
blob: 4a2ea7217dfec2d21c6057d7bf3db16dc3f07648 (plain)
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
/*	$calcurse: custom.c,v 1.1 2006/07/31 21:00:02 culot Exp $	*/

/*
 * Calcurse - text-based organizer
 * Copyright (c) 2004-2006 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 <ncurses.h>

#include "i18n.h"
#include "utils.h"
#include "custom.h"
#include "vars.h"

static struct attribute_s attr;

/* 
 * Define window attributes (for both color and non-color terminals):
 * ATTR_HIGHEST are for window titles
 * ATTR_HIGH are for month and days names
 * ATTR_MIDDLE are for the selected day inside calendar panel
 * ATTR_LOW are for days inside calendar panel which contains an event
 * ATTR_LOWEST are for current day inside calendar panel
 */
void custom_init_attr(int colr)
{
	attr.color[ATTR_HIGHEST]   = COLOR_PAIR(colr);
	attr.color[ATTR_HIGH]      = COLOR_PAIR(6);
	attr.color[ATTR_MIDDLE]    = COLOR_PAIR(1);
	attr.color[ATTR_LOW]       = COLOR_PAIR(4);
	attr.color[ATTR_LOWEST]    = COLOR_PAIR(5);
	attr.color[ATTR_TRUE]      = COLOR_PAIR(2);
	attr.color[ATTR_FALSE]     = COLOR_PAIR(1);

	attr.nocolor[ATTR_HIGHEST] = A_BOLD;
	attr.nocolor[ATTR_HIGH]    = A_REVERSE;
	attr.nocolor[ATTR_MIDDLE]  = A_REVERSE;
	attr.nocolor[ATTR_LOW]     = A_UNDERLINE;
	attr.nocolor[ATTR_LOWEST]  = A_BOLD;
	attr.nocolor[ATTR_TRUE]    = A_BOLD;
	attr.nocolor[ATTR_FALSE]   = A_DIM;
}

/* Apply window attribute */
void custom_apply_attr(WINDOW *win, int attr_num)
{
	if (colorize)
		wattron(win, attr.color[attr_num]);
	else
		wattron(win, attr.nocolor[attr_num]);
}

/* Remove window attribute */
void custom_remove_attr(WINDOW *win, int attr_num)
{
	if (colorize)
		wattroff(win, attr.color[attr_num]);
	else
		wattroff(win, attr.nocolor[attr_num]);
}

/* Draws the configuration bar */
void config_bar()
{
	int smlspc, spc;

	smlspc = 2;
	spc = 15;

	custom_apply_attr(swin, ATTR_HIGHEST);
	mvwprintw(swin, 0, 2, "Q");
	mvwprintw(swin, 1, 2, "G");
	mvwprintw(swin, 0, 2 + spc, "L");
	mvwprintw(swin, 1, 2 + spc, "C");
	custom_remove_attr(swin, ATTR_HIGHEST);

	mvwprintw(swin, 0, 2 + smlspc, _("Exit"));
	mvwprintw(swin, 1, 2 + smlspc, _("General"));
	mvwprintw(swin, 0, 2 + spc + smlspc, _("Layout"));
	mvwprintw(swin, 1, 2 + spc + smlspc, _("Color"));
	
	wnoutrefresh(swin);
        wmove(swin, 0, 0);
	doupdate();
}

/* Choose the layout */
int layout_config(int layout, int colr)
{
	int ch, old_layout;
	char *layout_mesg = _("Pick the desired layout on next screen [press ENTER]");
	char *choice_mesg = _("('A'= Appointment panel, 'c'= calendar panel, 't'= todo panel)");
	char *layout_up_mesg   = _("   |Ac|      |At|      |cA|      |tA|");
	char *layout_down_mesg = _("[1]|At|   [2]|Ac|   [3]|tA|   [4]|cA|");

	old_layout = layout;
	status_mesg(layout_mesg, choice_mesg);
	wgetch(swin);
	status_mesg(layout_up_mesg, layout_down_mesg);
	wnoutrefresh(swin);
	doupdate();
	while ((ch = wgetch(swin)) != 'q') {
		switch (ch) {
		case '1':
			layout = 1;
			return layout;
		case '2':
			layout = 2;
			return layout;
		case '3':
			layout = 3;
			return layout;
		case '4':
			layout = 4;
			return layout;
		}
	}
	layout = old_layout;
	return layout;
}

/* Choose the color theme */
int color_config(int colr)
{
        int ascii2dec = 48;
	int i, ch, old_colr;
        int max_colors = 9;
        int spc = 6;
        char *choose_color = _("Pick the number corresponding to the color scheme "
                "(Q to exit) :");

	old_colr = colr;
	erase_window_part(swin, 0, 0, col, 2);
	for (i = 1; i < max_colors; i++) {
		wattron(swin, COLOR_PAIR(i));
		mvwprintw(swin, 1, (i - 1) * spc, "[>%d<]", i);
		wattroff(swin, COLOR_PAIR(i));
	}
        mvwprintw(swin, 1, 50, _("([>0<] for black & white)"));
	custom_apply_attr(swin, ATTR_HIGHEST);
	mvwprintw(swin, 0, 0, choose_color);
	custom_remove_attr(swin, ATTR_HIGHEST);
	wnoutrefresh(swin);
	doupdate();
	while ((ch = wgetch(swin)) != 'q') {
                ch = ch - ascii2dec;
                if ( (ch > 0) && (ch <= max_colors) ) {
                        colorize = true;
                        return ch;
                } else if (ch == 0) {
                        colorize = false;
                        return 0;
                } else {
                        colr = old_colr;
                }
        }
        if (colr == 0) colorize = false;
        return colr;
}