File: box_selection.inc

package info (click to toggle)
elmo 1.3.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,244 kB
  • ctags: 3,673
  • sloc: ansic: 24,299; sh: 4,169; lex: 3,626; cpp: 2,739; perl: 1,047; pascal: 811; makefile: 359; yacc: 318
file content (129 lines) | stat: -rw-r--r-- 3,736 bytes parent folder | download | duplicates (3)
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
/* -*- c -*- */
/* 
   elmo - ELectronic Mail Operator

   Copyright (C) 2003, 2004 rzyjontko
   
   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; version 2.

   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.  
*/

#define FOCUS     1
#define LABEL_TXT 1
#define LABEL_DEF 1


#ifndef GET_COLOR_DEFINED
#define GET_COLOR_DEFINED 1

static chtype
get_color (ask_t *ask, const char *fg_field, const char *bg_field,
           const char *fg_def, const char *bg_def)
{
        char *fg;
        char *bg;

        fg = ask_get_field (ask, fg_field);
        bg = ask_get_field (ask, bg_field);

        if (fg && bg){
                return color_from_str (fg, bg);
        }
        else if (fg){
                return color_from_str (fg, bg_def);
        }
        else if (bg){
                return color_from_str (fg_def, bg);
        }
        return color_from_str (fg_def, bg_def);
}

#endif


static WINDOW *
interface_init (void)
{
        ask_t  *ask       = ask_select_default ("win_boxes");
        int     height    = -12;
        int     width     = 25;
        int     top       = 2;
        int     left      = 0;
        int     maxheight = LINES;
        int     maxwidth  = COLS;
        WINDOW *win;

        hilight_color = get_color (ask, "hilight_fg", "hilight_bg", "black", "green");
        tree_color = get_color (ask, "tree_fg", "tree_bg", "red", "black");
        text_color = get_color (ask, "text_fg", "text_bg", "lightgrey", "black");
        root_color = get_color (ask, "root_fg", "root_bg", "white", "black");
        tree_bar_color = get_color (ask, "tree_bar_fg", "tree_bar_bg", "red", "cyan");

        left = ask_get_field_int_default (ask, "left", 0);
        width = ask_get_field_int_default (ask, "width", 25);
        height = ask_get_field_int_default (ask, "height", -12);
        top = ask_get_field_int_default (ask, "top", 2);
        box_fmt = ask_get_field (ask, "box_fmt");
        if (box_fmt == NULL){
                box_fmt = " %010n (%u/%t)";
        }


        if (height <= 0)
                height += maxheight;
        if (width <= 0)
                width += maxwidth;
        if (top < 0)
                top += maxheight;
        if (left < 0)
                left += maxwidth;

        if (height > maxheight)
                height = maxheight;
        if (width > maxwidth)
                width = maxwidth;

        if (top + height > maxheight)
                top = maxheight - height;
        if (left + width > maxwidth)
                left = maxwidth - width;

        win = window_create ("boxes", height, width, top, left, 1);

        if (ask){
#if FOCUS
                if (ask_get_field_int_default (ask, "label", 1)){
                        label = label_create (win);
                }
                else {
                        label = NULL;
                }
#endif /* FOCUS */
                ask_destroy (ask);
        }
#if LABEL_DEF
        else {
                label = label_create (win);
        }
#endif /* LABEL_DEF */


#if LABEL_TXT
        if (label){
                label_set_text (label,  "select box");
        }
#endif /* LABEL_TXT */

        wattrset (win, text_color);
        return win;
}