summaryrefslogtreecommitdiff
path: root/statusline.cc
blob: dcc9dc22efbfdec1a9899f4baeaae42f262a7bd5 (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
// Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
//
// 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, USA.

#include <config.h>

#include <string.h>

#include "statusline.h"
#include "editor.h"
#include "themes.h"
#include "dbg.h"

StatusLine::StatusLine(const Editor *aBde, EditBox *aEditbox)
{
    create_window();
    aEditbox->set_status_listener(this);
    editbox = aEditbox;
    bde = aBde;
    cursor_position_report = false;
    update_region = rgnAll;
}

void StatusLine::resize(int lines, int columns, int y, int x)
{
    Widget::resize(lines, columns, y, x);
    request_update(rgnAll);
}

void StatusLine::request_update(region rgn)
{
    update_region |= rgn;
}

void StatusLine::invalidate_view()
{
    request_update(rgnAll);
}

void StatusLine::toggle_cursor_position_report()
{
    cursor_position_report = !cursor_position_report;
    request_update(rgnAll);
}

void StatusLine::update()
{
    if (update_region & rgnFilename)
	request_update(rgnAll);

    if (update_region & rgnAll) {
	wbkgd(wnd, get_attr(STATUSLINE_ATTR));
	wmove(wnd, 0, 0);
	wclrtoeol(wnd);
    }
	
    if (update_region & (rgnAll | rgnIndicators)) {
	wmove(wnd, 0, 0);
	waddch(wnd, '[');
    
	waddch(wnd, editbox->is_modified() ? 'M' : '-');

	char wrap_ch = '-';
	switch (editbox->get_wrap_type()) {
	    case EditBox::wrpOff:	    wrap_ch = '$'; break;
	    case EditBox::wrpAnywhere:	    wrap_ch = '\\'; break;
	    case EditBox::wrpAtWhiteSpace:  wrap_ch = '-'; break; // silence the compiler
	}
	waddch(wnd, wrap_ch);
	
	char algo_ch = '-';
	switch (editbox->get_dir_algo()) {
	    case algoUnicode:	    algo_ch = '!'; break;
	    case algoContextStrong: algo_ch = '~'; break;
	    case algoContextRTL:    algo_ch = '-'; break;
	    case algoForceLTR:	    algo_ch = '>'; break;
	    case algoForceRTL:	    algo_ch = '<'; break;
	}
	waddch(wnd, algo_ch);
	
	waddch(wnd, editbox->has_selected_text()
			&& !bde->in_spelling() ? '@' : '-');

	waddch(wnd, editbox->is_read_only() ? 'R' : '-');
	
	waddch(wnd, bde->is_speller_loaded() ? 'S' : '-');

	waddch(wnd, editbox->in_translation_mode() ? '"' : '-');

	waddch(wnd, terminal::do_arabic_shaping ? 'a' : '-');

	waddch(wnd, editbox->get_alt_kbd() ? 'H' : '-');
	
	waddch(wnd, editbox->is_auto_justify() ? 'j' : '-');

	waddch(wnd, editbox->is_auto_indent() ? 'i' : '-');
	
	char maqaf_ch = '-';
	switch (editbox->get_maqaf_display()) {
	    case EditBox::mqfAsis:	     maqaf_ch = '-'; break;
	    case EditBox::mqfTransliterated: maqaf_ch = 'k'; break;
	    case EditBox::mqfHighlighted:    maqaf_ch = 'K'; break;
	}
	waddch(wnd, maqaf_ch);
	
	waddch(wnd, editbox->is_smart_typing() ? 'q' : '-');

	char rtlnsm_ch = '-';
	switch (editbox->get_rtl_nsm_display()) {
	    case EditBox::rtlnsmOff:		rtlnsm_ch = '-'; break;
	    case EditBox::rtlnsmTransliterated: rtlnsm_ch = 'n'; break;
	    case EditBox::rtlnsmAsis:		rtlnsm_ch = 'N'; break;
	}
	waddch(wnd, rtlnsm_ch);
	
	waddch(wnd, editbox->get_visual_cursor_movement() ? 'v' : '-');
	
	waddch(wnd, editbox->has_formatting_marks() ? 'F' : '-');

	waddch(wnd, ']');
    }

    if (update_region & (rgnAll | rgnFilename)) {
	unistring tmp;
	tmp.init_from_filename(bde->get_filename());
	u8string filename;
	filename.init_from_unichars(tmp);

	waddch(wnd, ' ');
	if (filename.empty()) {
	    draw_string(_("UNTITLED"));
	} else {
	    waddch(wnd, '"');
	    draw_string(filename.c_str());
	    waddch(wnd, '"');
	}
	if (bde->is_new())
	    draw_string(_(" [New File]"));
	wmove(wnd, 0, window_width() - strlen(bde->get_encoding()) - (2+5));
	wprintw(wnd, "[disk:%s]", bde->get_encoding());
    }

    if (cursor_position_report && (update_region & (rgnAll | rgnCursorPos))) {
	// we use 16 columns for the cursor position.
	int x = window_width() - strlen(bde->get_encoding()) - (2+5) - 16;
	wmove(wnd, 0, x);
	Point cursor;
	editbox->get_cursor_position(cursor);
        int total = editbox->get_number_of_paragraphs();
	wprintw(wnd, "%4d/%4d,%3d   ", total, cursor.para + 1, cursor.pos + 1);
    }
	    
    wnoutrefresh(wnd);
    update_region = rgnNone;
}