aboutsummaryrefslogtreecommitdiff
path: root/wind.c
blob: e6fb2ed8fd2374e13e4d9c76181bcc0b3ebfe9d4 (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
/*
 * Ache - 2017-08-14 - GPLv3
 */

#include "wind.h"

/* Managed windows */

extern int w_menuContact,h_menuContact;
extern int x_WMessage,y_WMessage;
extern int w_WMessage,h_WMessage;

static short my_fg = COLOR_WHITE;
static short my_bg = COLOR_BLACK;
//extern char status[10];
extern WINDOW *cmd_win;
//extern WINDOW *sep_win;
//


int showMessagePreview(int x, int y, int w, const char* txt, char onlyCount) {
    char line[w];
    memset(line, 0, w);

    int X = 0, Y=0, iS= 0;
    while( txt[iS] ) {
        X = 0;
        while( X < w-1 && txt[iS]) {
            if( txt[iS] == '\n' ) {
                iS++;
                break;
            }
            line[X++] = txt[iS++];
        }
        line[X] = 0;
        if( Y+1 >= h_WMessage -1 )  {
            break;
        }
        Y++;
        if( onlyCount ) {
            move(Y+y, x+2);
            printw("%s", line);
        }
    }
    return Y;
}
void resize() {
    h_menuContact = LINES-2;
    w_menuContact =  COLS/5-1;

    x_WMessage = w_menuContact + 2;
    y_WMessage = 1;

    w_WMessage = (4*COLS)/5-2;
    h_WMessage = LINES-2;

    clear();
    showContactListW();
    move(1, x_WMessage-1);
    vline(ACS_VLINE, h_menuContact);
    showMessageWind();

    cmd_win_redisplay(true);
    CHECK(doupdate);
    move(LINES-1, 1);
}
void runtimeHelp(void) {
    int x = COLS/8;
    int y = LINES/7;

    int w = COLS*2/7;
    int h = LINES/7;

    clear();
    move(y,x);
    printw("This is the help");
    y+=2;
    move(y,0);
    printw(RUNTIME_HELP_STRING);


    move(LINES*6/7,x);
    printw("Type h or q to exit");
    int c = 0;
    while( (c = getch()) && c != EOF && !strchr("hHqQ", c) ) ;

    clear();
}
void showConfirmSend(const char* txt, const char* autheur) {
    int x = COLS/6;
    int w = (COLS*2)/3;
    int nbLignes = showMessagePreview(x, 0, w, txt, 0);
    int y = (LINES - nbLignes - 2) / 2;

    clear();
    refresh();
    move(y,x);
    printw("Voulez-vous vraiment envoyé ce SMS de %d ligne%s à %s ?", nbLignes, nbLignes > 1 ? "s":"", autheur);
    y++;
    move(y,x);

    {
        char line[w];
        memset(line, 0, w);

        int X = 0, Y=0, iS= 0;
        while( txt[iS] ) {
            X = 0;
            while( X < w-1 && txt[iS]) {
                if( txt[iS] == '\n' ) {
                    iS++;
                    break;
                }
                line[X++] = txt[iS++];
            }
            line[X] = 0;
            if( Y+1 >= h_WMessage -1 )  {
                break;
            }
            Y++;
            move(Y+y, x+2);
            printw("%s", line);
        }
    }
}
int confirmSend(const char* txt, const char* autheur) {
    showConfirmSend(txt, autheur);

    int c = 0;
    while( (c = getch()) && c != EOF && !strchr("oyneqOYNEQ", c) ) {
        if (c == KEY_RESIZE) {
            showConfirmSend(txt, autheur);
            refresh();
            continue;
        }
    }

    clear();
    return (c == 'e' || c =='E') ? 2 : (!!strchr("yYoO", c)) ;
}