4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
6 The Free Software Foundation, Inc.
10 Andrew Borodin <aborodin@vmail.ru> 2012
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \brief Source: editor text drawing
38 #include <sys/types.h>
45 #include "lib/global.h"
46 #include "lib/tty/tty.h" /* tty_printf() */
47 #include "lib/tty/key.h" /* is_idle() */
49 #include "lib/strutil.h" /* utf string functions */
50 #include "lib/util.h" /* is_printable() */
51 #include "lib/widget.h"
53 #include "lib/charsets.h"
56 #include "src/setup.h" /* edit_tab_spacing */
57 #include "src/main.h" /* macro_index */
59 #include "edit-impl.h"
60 #include "editwidget.h"
62 /*** global variables ****************************************************************************/
64 /* Toggles statusbar draw style */
65 int simple_statusbar
= 0;
67 int visible_tabs
= 1, visible_tws
= 1;
69 /*** file scope macro definitions ****************************************************************/
71 #define MAX_LINE_LEN 1024
74 #define MOD_ABNORMAL (1 << 8)
75 #define MOD_BOLD (1 << 9)
76 #define MOD_MARKED (1 << 10)
77 #define MOD_CURSOR (1 << 11)
78 #define MOD_WHITESPACE (1 << 12)
80 #define edit_move(x,y) widget_move(edit, y, x);
82 #define key_pending(x) (!is_idle())
84 #define EDITOR_MINIMUM_TERMINAL_WIDTH 30
86 /*** file scope type declarations ****************************************************************/
94 /*** file scope variables ************************************************************************/
96 /*** file scope functions ************************************************************************/
99 printwstr (const char *s
, int len
)
102 tty_printf ("%-*.*s", len
, len
, s
);
105 /* --------------------------------------------------------------------------------------------- */
108 status_string (WEdit
* edit
, char *s
, int w
)
111 unsigned char cur_byte
= 0;
112 unsigned int cur_utf
= 0;
116 * If we are at the end of file, print <EOF>,
117 * otherwise print the current character as is (if printable),
118 * as decimal and as hex.
120 if (edit
->curs1
< edit
->last_byte
)
124 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
126 g_snprintf (byte_str
, sizeof (byte_str
), "%4d 0x%03X",
127 (int) cur_byte
, (unsigned) cur_byte
);
131 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
134 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
135 (unsigned) cur_utf
, (unsigned) cur_utf
);
139 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
140 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
141 (int) cur_utf
, (unsigned) cur_utf
);
148 strcpy (byte_str
, "<EOF> ");
151 /* The field lengths just prevent the status line from shortening too much */
152 if (simple_statusbar
)
154 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
155 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
156 edit
->modified
? 'M' : '-',
157 macro_index
< 0 ? '-' : 'R',
158 edit
->overwrite
== 0 ? '-' : 'O',
159 edit
->curs_col
+ edit
->over_col
,
161 edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
, byte_str
,
163 mc_global
.source_codepage
>=
164 0 ? get_codepage_id (mc_global
.source_codepage
) : ""
171 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s",
172 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
173 edit
->modified
? 'M' : '-',
174 macro_index
< 0 ? '-' : 'R',
175 edit
->overwrite
== 0 ? '-' : 'O',
176 edit
->curs_col
+ edit
->over_col
,
177 edit
->start_line
+ 1,
180 edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
, byte_str
,
182 mc_global
.source_codepage
>=
183 0 ? get_codepage_id (mc_global
.source_codepage
) : ""
190 /* --------------------------------------------------------------------------------------------- */
192 * Draw the status line at the top of the screen for fullscreen editor window.
194 * @param edit editor object
195 * @param color color pair
199 edit_status_fullscreen (WEdit
* edit
, int color
)
201 const int w
= edit
->widget
.owner
->cols
;
202 const size_t status_size
= w
+ 1;
203 char *const status
= g_malloc (status_size
);
205 const char *fname
= "";
207 const int gap
= 3; /* between the filename and the status */
208 const int right_gap
= 5; /* at the right end of the screen */
209 const int preferred_fname_len
= 16;
211 status_string (edit
, status
, status_size
);
212 status_len
= (int) str_term_width1 (status
);
214 if (edit
->filename_vpath
!= NULL
)
215 fname
= x_basename (vfs_path_get_last_path_str (edit
->filename_vpath
));
217 fname_len
= str_term_width1 (fname
);
218 if (fname_len
< preferred_fname_len
)
219 fname_len
= preferred_fname_len
;
221 if (fname_len
+ gap
+ status_len
+ right_gap
>= w
)
223 if (preferred_fname_len
+ gap
+ status_len
+ right_gap
>= w
)
224 fname_len
= preferred_fname_len
;
226 fname_len
= w
- (gap
+ status_len
+ right_gap
);
227 fname
= str_trunc (fname
, fname_len
);
230 dlg_move (edit
->widget
.owner
, 0, 0);
231 tty_setcolor (color
);
232 printwstr (fname
, fname_len
+ gap
);
233 printwstr (status
, w
- (fname_len
+ gap
));
235 if (simple_statusbar
&& w
> EDITOR_MINIMUM_TERMINAL_WIDTH
)
237 size_t percent
= 100;
239 if (edit
->total_lines
+ 1 != 0)
240 percent
= (edit
->curs_line
+ 1) * 100 / (edit
->total_lines
+ 1);
241 dlg_move (edit
->widget
.owner
, 0, w
- 6 - 6);
242 tty_printf (" %3d%%", percent
);
248 /* --------------------------------------------------------------------------------------------- */
250 * Draw status line for editor window if window is not in fullscreen mode.
252 * @param edit editor object
256 edit_status_window (WEdit
* edit
)
259 int cols
= edit
->widget
.cols
;
261 tty_setcolor (STATUSBAR_COLOR
);
265 const char *fname
= N_("NoName");
266 char *full_fname
= NULL
;
268 if (edit
->filename_vpath
!= NULL
)
270 full_fname
= vfs_path_to_str (edit
->filename_vpath
);
271 fname
= x_basename (full_fname
);
279 tty_printf ("[%s]", str_term_trim (fname
, edit
->widget
.cols
- 8 - 6));
286 if (x
+ 6 <= cols
- 2 - 6)
289 tty_printf ("[%c%c%c%c]",
290 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
291 edit
->modified
? 'M' : '-',
292 macro_index
< 0 ? '-' : 'R', edit
->overwrite
== 0 ? '-' : 'O');
297 edit_move (2, edit
->widget
.lines
- 1);
298 tty_printf ("%3ld %5ld/%ld %6ld/%ld",
299 edit
->curs_col
+ edit
->over_col
,
300 edit
->curs_line
+ 1, edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
);
304 * If we are at the end of file, print <EOF>,
305 * otherwise print the current character as is (if printable),
306 * as decimal and as hex.
310 edit_move (32, edit
->widget
.lines
- 1);
311 if (edit
->curs1
>= edit
->last_byte
)
312 tty_print_string ("[<EOF> ]");
316 unsigned int cur_utf
;
319 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
321 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
322 tty_printf ("[%05d 0x%04X]", cur_utf
, cur_utf
);
327 unsigned char cur_byte
;
329 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
330 tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte
, (unsigned int) cur_byte
);
335 /* --------------------------------------------------------------------------------------------- */
337 * Draw a frame around edit area.
339 * @param edit editor object
340 * @param color color pair
341 * @param active TRUE if editor object is focused
345 edit_draw_frame (const WEdit
* edit
, int color
, gboolean active
)
347 const Widget
*w
= (const Widget
*) edit
;
349 /* draw a frame around edit area */
350 tty_setcolor (color
);
351 /* draw double frame for active window if skin supports that */
352 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, !active
);
353 /* draw a drag marker */
354 if (edit
->drag_state
== MCEDIT_DRAG_NORMAL
)
356 tty_setcolor (EDITOR_FRAME_DRAG
);
357 widget_move (w
, w
->lines
- 1, w
->cols
- 1);
358 tty_print_alt_char (ACS_LRCORNER
, TRUE
);
362 /* --------------------------------------------------------------------------------------------- */
364 * Draw a window control buttons.
366 * @param edit editor object
367 * @param color color pair
371 edit_draw_window_icons (const WEdit
* edit
, int color
)
373 const Widget
*w
= (const Widget
*) edit
;
376 tty_setcolor (color
);
377 if (edit
->fullscreen
)
378 dlg_move (w
->owner
, 0, w
->owner
->cols
- 6);
380 widget_move (w
, 0, edit
->widget
.cols
- 8);
381 g_snprintf (tmp
, sizeof (tmp
), "[%s][%s]", edit_window_state_char
, edit_window_close_char
);
382 tty_print_string (tmp
);
385 /* --------------------------------------------------------------------------------------------- */
388 print_to_widget (WEdit
* edit
, long row
, int start_col
, int start_col_real
,
389 long end_col
, struct line_s line
[], char *status
, int bookmarked
)
393 int x
= start_col_real
;
394 int x1
= start_col
+ EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
395 int y
= row
+ EDIT_TEXT_VERTICAL_OFFSET
;
396 int cols_to_skip
= abs (x
);
401 if (!edit
->fullscreen
)
407 tty_setcolor (EDITOR_NORMAL_COLOR
);
409 tty_setcolor (bookmarked
);
411 len
= end_col
+ 1 - start_col
;
412 wrap_start
= option_word_wrap_line_length
+ edit
->start_col
;
414 if (len
> 0 && edit
->widget
.y
+ y
>= 0)
416 if (!show_right_margin
|| wrap_start
> end_col
)
417 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
418 else if (wrap_start
< 0)
420 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
421 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
426 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', wrap_start
);
431 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
432 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
+ wrap_start
, ' ', len
);
437 if (option_line_state
)
439 tty_setcolor (LINE_STATE_COLOR
);
440 for (i
= 0; i
< LINE_STATE_WIDTH
; i
++)
442 edit_move (x1
+ i
- option_line_state_width
, y
);
443 if (status
[i
] == '\0')
445 tty_print_char (status
[i
]);
451 for (p
= line
; p
->ch
!= 0; p
++)
454 unsigned int textchar
;
457 if (cols_to_skip
!= 0)
463 style
= p
->style
& 0xFF00;
465 color
= p
->style
>> 16;
467 if (style
& MOD_ABNORMAL
)
469 /* Non-printable - use black background */
473 if (style
& MOD_WHITESPACE
)
475 if (style
& MOD_MARKED
)
478 tty_setcolor (EDITOR_MARKED_COLOR
);
481 tty_setcolor (EDITOR_WHITESPACE_COLOR
);
483 else if (style
& MOD_BOLD
)
484 tty_setcolor (EDITOR_BOLD_COLOR
);
485 else if (style
& MOD_MARKED
)
486 tty_setcolor (EDITOR_MARKED_COLOR
);
488 tty_lowlevel_setcolor (color
);
490 if (show_right_margin
)
492 if (i
> option_word_wrap_line_length
+ edit
->start_col
)
493 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
497 tty_print_anychar (textchar
);
501 /* --------------------------------------------------------------------------------------------- */
502 /** b is a pointer to the beginning of the line */
505 edit_draw_this_line (WEdit
* edit
, long b
, long row
, long start_col
, long end_col
)
507 struct line_s line
[MAX_LINE_LEN
];
508 struct line_s
*p
= line
;
510 long m1
= 0, m2
= 0, q
, c1
, c2
;
511 int col
, start_col_real
;
517 unsigned int cur_line
= 0;
519 char line_stat
[LINE_STATE_WIDTH
+ 1] = "\0";
521 if (row
> edit
->widget
.lines
- 1 - EDIT_TEXT_VERTICAL_OFFSET
- 2 * (edit
->fullscreen
? 0 : 1))
524 if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_COLOR
))
525 book_mark
= BOOK_MARK_COLOR
;
526 else if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_FOUND_COLOR
))
527 book_mark
= BOOK_MARK_FOUND_COLOR
;
530 abn_style
= book_mark
<< 16;
532 abn_style
= MOD_ABNORMAL
;
534 end_col
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
535 if (!edit
->fullscreen
)
537 const Widget
*w
= (const Widget
*) edit
;
540 if (w
->x
+ w
->cols
<= w
->owner
->cols
)
544 edit_get_syntax_color (edit
, b
- 1, &color
);
545 q
= edit_move_forward3 (edit
, b
, start_col
- edit
->start_col
, 0);
546 start_col_real
= (col
= (int) edit_move_forward3 (edit
, b
, 0, q
)) + edit
->start_col
;
548 if (option_line_state
)
550 cur_line
= edit
->start_line
+ row
;
551 if (cur_line
<= (unsigned int) edit
->total_lines
)
553 g_snprintf (line_stat
, LINE_STATE_WIDTH
+ 1, "%7i ", cur_line
+ 1);
557 memset (line_stat
, ' ', LINE_STATE_WIDTH
);
558 line_stat
[LINE_STATE_WIDTH
] = '\0';
560 if (book_mark_query_color (edit
, cur_line
, BOOK_MARK_COLOR
))
562 g_snprintf (line_stat
, 2, "*");
566 if (col
+ 16 > -edit
->start_col
)
568 eval_marks (edit
, &m1
, &m2
);
570 if (row
<= edit
->total_lines
- edit
->start_line
)
573 if (tty_use_colors () && visible_tws
)
575 tws
= edit_eol (edit
, b
);
576 while (tws
> b
&& ((c
= edit_get_byte (edit
, tws
- 1)) == ' ' || c
== '\t'))
580 while (col
<= end_col
- edit
->start_col
)
584 gboolean wide_width_char
= FALSE
;
585 gboolean control_char
= FALSE
;
589 if (q
== edit
->curs1
)
590 p
->style
|= MOD_CURSOR
;
591 if (q
>= m1
&& q
< m2
)
593 if (edit
->column_highlight
)
596 x
= edit_move_forward3 (edit
, b
, 0, q
);
597 c1
= min (edit
->column1
, edit
->column2
);
598 c2
= max (edit
->column1
, edit
->column2
);
599 if (x
>= c1
&& x
< c2
)
600 p
->style
|= MOD_MARKED
;
603 p
->style
|= MOD_MARKED
;
605 if (q
== edit
->bracket
)
606 p
->style
|= MOD_BOLD
;
607 if (q
>= edit
->found_start
&& q
< edit
->found_start
+ edit
->found_len
)
608 p
->style
|= MOD_BOLD
;
612 c
= edit_get_byte (edit
, q
);
616 c
= edit_get_utf (edit
, q
, &cw
);
618 /* we don't use bg for mc - fg contains both */
621 p
->style
|= book_mark
<< 16;
625 edit_get_syntax_color (edit
, q
, &color
);
626 p
->style
|= color
<< 16;
631 col
= (end_col
+ utf8lag
) - edit
->start_col
+ 1; /* quit */
634 i
= TAB_SIZE
- ((int) col
% TAB_SIZE
);
635 tab_over
= (end_col
- edit
->start_col
) - (col
+ i
- 1);
639 if (tty_use_colors () &&
640 ((visible_tabs
|| (visible_tws
&& q
>= tws
)) && enable_show_tabs_tws
))
642 if (p
->style
& MOD_MARKED
)
645 c
|= book_mark
<< 16;
647 c
= p
->style
| MOD_WHITESPACE
;
679 else if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
682 p
->style
|= MOD_WHITESPACE
;
683 c
= p
->style
& ~MOD_CURSOR
;
695 c
= p
->style
& ~MOD_CURSOR
;
706 if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
709 p
->style
|= MOD_WHITESPACE
;
717 if (mc_global
.utf8_display
)
721 c
= convert_from_8bit_to_utf_c ((unsigned char) c
, edit
->converter
);
725 if (g_unichar_iswide (c
))
727 wide_width_char
= TRUE
;
733 c
= convert_from_utf_to_current_c (c
, edit
->converter
);
735 c
= convert_to_display_c (c
);
738 /* Caret notation for control characters */
742 p
->style
= abn_style
;
745 p
->style
= abn_style
;
754 p
->style
= abn_style
;
757 p
->style
= abn_style
;
765 if ((mc_global
.utf8_display
&& g_unichar_isprint (c
)) ||
766 (!mc_global
.utf8_display
&& is_printable (c
)))
774 p
->style
= abn_style
;
780 if (g_unichar_isprint (c
))
788 p
->style
= abn_style
;
802 if (col
> (end_col
- edit
->start_col
+ 1))
820 start_col_real
= start_col
= 0;
825 print_to_widget (edit
, row
, start_col
, start_col_real
, end_col
, line
, line_stat
, book_mark
);
828 /* --------------------------------------------------------------------------------------------- */
831 edit_draw_this_char (WEdit
* edit
, long curs
, long row
, long start_column
, long end_column
)
833 int b
= edit_bol (edit
, curs
);
834 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
837 /* --------------------------------------------------------------------------------------------- */
838 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
841 render_edit_text (WEdit
* edit
, long start_row
, long start_column
, long end_row
, long end_column
)
843 static long prev_curs_row
= 0;
844 static long prev_curs
= 0;
846 Widget
*w
= (Widget
*) edit
;
847 Dlg_head
*h
= w
->owner
;
849 long row
= 0, curs_row
;
850 int force
= edit
->force
;
857 /* draw only visible region */
859 last_line
= h
->y
+ h
->lines
- 1;
862 if (y1
> last_line
- 1 /* buttonbar */ )
865 last_column
= h
->x
+ h
->cols
- 1;
868 if (x1
> last_column
)
871 y2
= w
->y
+ w
->lines
- 1;
872 if (y2
< h
->y
+ 1 /* menubar */ )
875 x2
= w
->x
+ w
->cols
- 1;
879 if ((force
& REDRAW_IN_BOUNDS
) == 0)
881 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
882 /* draw only visible region */
884 if (y2
<= last_line
- 1 /* buttonbar */ )
885 end_row
= w
->lines
- 1;
886 else if (y1
>= h
->y
+ 1 /* menubar */ )
887 end_row
= h
->lines
- 1 - y1
- 1;
889 end_row
= start_row
+ h
->lines
- 1 - 1;
891 if (x2
<= last_column
)
892 end_column
= w
->cols
- 1;
894 end_column
= h
->cols
- 1 - x1
;
896 end_column
= start_column
+ h
->cols
- 1;
900 * If the position of the page has not moved then we can draw the cursor
901 * character only. This will prevent line flicker when using arrow keys.
903 if ((force
& REDRAW_CHAR_ONLY
) == 0 || (force
& REDRAW_PAGE
) != 0)
905 if ((force
& REDRAW_PAGE
) != 0)
908 b
= edit_move_forward (edit
, edit
->start_display
, start_row
, 0);
909 while (row
<= end_row
)
911 if (key_pending (edit
))
913 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
914 b
= edit_move_forward (edit
, b
, 1, 0);
920 curs_row
= edit
->curs_row
;
922 if ((force
& REDRAW_BEFORE_CURSOR
) != 0 && start_row
< curs_row
)
924 long upto
= curs_row
- 1 <= end_row
? curs_row
- 1 : end_row
;
927 b
= edit
->start_display
;
930 if (key_pending (edit
))
932 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
933 b
= edit_move_forward (edit
, b
, 1, 0);
937 /* if (force & REDRAW_LINE) ---> default */
938 b
= edit_bol (edit
, edit
->curs1
);
939 if (curs_row
>= start_row
&& curs_row
<= end_row
)
941 if (key_pending (edit
))
943 edit_draw_this_line (edit
, b
, curs_row
, start_column
, end_column
);
946 if ((force
& REDRAW_AFTER_CURSOR
) != 0 && end_row
> curs_row
)
948 row
= curs_row
+ 1 < start_row
? start_row
: curs_row
+ 1;
949 b
= edit_move_forward (edit
, b
, 1, 0);
950 while (row
<= end_row
)
952 if (key_pending (edit
))
954 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
955 b
= edit_move_forward (edit
, b
, 1, 0);
960 if ((force
& REDRAW_LINE_ABOVE
) != 0 && curs_row
>= 1)
963 b
= edit_move_backward (edit
, edit_bol (edit
, edit
->curs1
), 1);
964 if (row
>= start_row
&& row
<= end_row
)
966 if (key_pending (edit
))
968 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
972 if ((force
& REDRAW_LINE_BELOW
) != 0 && row
< edit
->widget
.lines
- 1)
975 b
= edit_bol (edit
, edit
->curs1
);
976 b
= edit_move_forward (edit
, b
, 1, 0);
977 if (row
>= start_row
&& row
<= end_row
)
979 if (key_pending (edit
))
981 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
986 else if (prev_curs_row
< edit
->curs_row
)
988 /* with the new text highlighting, we must draw from the top down */
989 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
990 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
994 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
995 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
1000 prev_curs_row
= edit
->curs_row
;
1001 prev_curs
= edit
->curs1
;
1004 /* --------------------------------------------------------------------------------------------- */
1007 edit_render (WEdit
* edit
, int page
, int row_start
, int col_start
, int row_end
, int col_end
)
1009 if (page
) /* if it was an expose event, 'page' would be set */
1010 edit
->force
|= REDRAW_PAGE
| REDRAW_IN_BOUNDS
;
1012 render_edit_text (edit
, row_start
, col_start
, row_end
, col_end
);
1015 * edit->force != 0 means a key was pending and the redraw
1016 * was halted, so next time we must redraw everything in case stuff
1017 * was left undrawn from a previous key press.
1020 edit
->force
|= REDRAW_PAGE
;
1023 /* --------------------------------------------------------------------------------------------- */
1024 /*** public functions ****************************************************************************/
1025 /* --------------------------------------------------------------------------------------------- */
1028 edit_status (WEdit
* edit
, gboolean active
)
1032 if (edit
->fullscreen
)
1034 color
= STATUSBAR_COLOR
;
1035 edit_status_fullscreen (edit
, color
);
1039 color
= edit
->drag_state
!= MCEDIT_DRAG_NORMAL
? EDITOR_FRAME_DRAG
: active
?
1040 EDITOR_FRAME_ACTIVE
: EDITOR_FRAME
;
1041 edit_draw_frame (edit
, color
, active
);
1042 edit_status_window (edit
);
1045 edit_draw_window_icons (edit
, color
);
1048 /* --------------------------------------------------------------------------------------------- */
1050 /** this scrolls the text so that cursor is on the screen */
1052 edit_scroll_screen_over_cursor (WEdit
* edit
)
1056 int b_extreme
, t_extreme
, l_extreme
, r_extreme
;
1058 if (edit
->widget
.lines
<= 0 || edit
->widget
.cols
<= 0)
1061 edit
->widget
.lines
-= EDIT_TEXT_VERTICAL_OFFSET
;
1062 edit
->widget
.cols
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1064 if (!edit
->fullscreen
)
1067 edit
->widget
.cols
-= 2;
1069 edit
->widget
.lines
-= 2;
1072 r_extreme
= EDIT_RIGHT_EXTREME
;
1073 l_extreme
= EDIT_LEFT_EXTREME
;
1074 b_extreme
= EDIT_BOTTOM_EXTREME
;
1075 t_extreme
= EDIT_TOP_EXTREME
;
1076 if (edit
->found_len
)
1078 b_extreme
= max (edit
->widget
.lines
/ 4, b_extreme
);
1079 t_extreme
= max (edit
->widget
.lines
/ 4, t_extreme
);
1081 if (b_extreme
+ t_extreme
+ 1 > edit
->widget
.lines
)
1085 n
= b_extreme
+ t_extreme
;
1088 b_extreme
= (b_extreme
* (edit
->widget
.lines
- 1)) / n
;
1089 t_extreme
= (t_extreme
* (edit
->widget
.lines
- 1)) / n
;
1091 if (l_extreme
+ r_extreme
+ 1 > edit
->widget
.cols
)
1095 n
= l_extreme
+ t_extreme
;
1098 l_extreme
= (l_extreme
* (edit
->widget
.cols
- 1)) / n
;
1099 r_extreme
= (r_extreme
* (edit
->widget
.cols
- 1)) / n
;
1101 p
= edit_get_col (edit
) + edit
->over_col
;
1102 edit_update_curs_row (edit
);
1103 outby
= p
+ edit
->start_col
- edit
->widget
.cols
+ 1 + (r_extreme
+ edit
->found_len
);
1105 edit_scroll_right (edit
, outby
);
1106 outby
= l_extreme
- p
- edit
->start_col
;
1108 edit_scroll_left (edit
, outby
);
1110 outby
= p
- edit
->widget
.lines
+ 1 + b_extreme
;
1112 edit_scroll_downward (edit
, outby
);
1113 outby
= t_extreme
- p
;
1115 edit_scroll_upward (edit
, outby
);
1116 edit_update_curs_row (edit
);
1118 edit
->widget
.lines
+= EDIT_TEXT_VERTICAL_OFFSET
;
1119 edit
->widget
.cols
+= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1120 if (!edit
->fullscreen
)
1123 edit
->widget
.cols
+= 2;
1125 edit
->widget
.lines
+= 2;
1129 /* --------------------------------------------------------------------------------------------- */
1132 edit_render_keypress (WEdit
* edit
)
1134 edit_render (edit
, 0, 0, 0, 0, 0);
1137 /* --------------------------------------------------------------------------------------------- */