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;
115 static const char *lb_names
[LB_NAMES
] = {
123 * If we are at the end of file, print <EOF>,
124 * otherwise print the current character as is (if printable),
125 * as decimal and as hex.
127 if (edit
->curs1
< edit
->last_byte
)
131 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
133 g_snprintf (byte_str
, sizeof (byte_str
), "%4d 0x%03X",
134 (int) cur_byte
, (unsigned) cur_byte
);
138 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
141 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
142 (unsigned) cur_utf
, (unsigned) cur_utf
);
146 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
147 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
148 (int) cur_utf
, (unsigned) cur_utf
);
155 strcpy (byte_str
, "<EOF> ");
158 /* The field lengths just prevent the status line from shortening too much */
159 if (simple_statusbar
)
161 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s %s",
162 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
163 edit
->modified
? 'M' : '-',
164 macro_index
< 0 ? '-' : 'R',
165 edit
->overwrite
== 0 ? '-' : 'O',
166 edit
->curs_col
+ edit
->over_col
,
168 edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
, byte_str
,
170 mc_global
.source_codepage
>=
171 0 ? get_codepage_id (mc_global
.source_codepage
) : "",
178 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s %s",
179 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
180 edit
->modified
? 'M' : '-',
181 macro_index
< 0 ? '-' : 'R',
182 edit
->overwrite
== 0 ? '-' : 'O',
183 edit
->curs_col
+ edit
->over_col
,
184 edit
->start_line
+ 1,
187 edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
, byte_str
,
189 mc_global
.source_codepage
>=
190 0 ? get_codepage_id (mc_global
.source_codepage
) : "",
197 /* --------------------------------------------------------------------------------------------- */
199 * Draw the status line at the top of the screen for fullscreen editor window.
201 * @param edit editor object
202 * @param color color pair
206 edit_status_fullscreen (WEdit
* edit
, int color
)
208 const int w
= edit
->widget
.owner
->cols
;
209 const size_t status_size
= w
+ 1;
210 char *const status
= g_malloc (status_size
);
212 const char *fname
= "";
214 const int gap
= 3; /* between the filename and the status */
215 const int right_gap
= 5; /* at the right end of the screen */
216 const int preferred_fname_len
= 16;
218 status_string (edit
, status
, status_size
);
219 status_len
= (int) str_term_width1 (status
);
221 if (edit
->filename_vpath
!= NULL
)
222 fname
= x_basename (vfs_path_get_last_path_str (edit
->filename_vpath
));
224 fname_len
= str_term_width1 (fname
);
225 if (fname_len
< preferred_fname_len
)
226 fname_len
= preferred_fname_len
;
228 if (fname_len
+ gap
+ status_len
+ right_gap
>= w
)
230 if (preferred_fname_len
+ gap
+ status_len
+ right_gap
>= w
)
231 fname_len
= preferred_fname_len
;
233 fname_len
= w
- (gap
+ status_len
+ right_gap
);
234 fname
= str_trunc (fname
, fname_len
);
237 dlg_move (edit
->widget
.owner
, 0, 0);
238 tty_setcolor (color
);
239 printwstr (fname
, fname_len
+ gap
);
240 printwstr (status
, w
- (fname_len
+ gap
));
242 if (simple_statusbar
&& w
> EDITOR_MINIMUM_TERMINAL_WIDTH
)
244 size_t percent
= 100;
246 if (edit
->total_lines
+ 1 != 0)
247 percent
= (edit
->curs_line
+ 1) * 100 / (edit
->total_lines
+ 1);
248 dlg_move (edit
->widget
.owner
, 0, w
- 6 - 6);
249 tty_printf (" %3d%%", percent
);
255 /* --------------------------------------------------------------------------------------------- */
257 * Draw status line for editor window if window is not in fullscreen mode.
259 * @param edit editor object
263 edit_status_window (WEdit
* edit
)
266 int cols
= edit
->widget
.cols
;
268 tty_setcolor (STATUSBAR_COLOR
);
272 const char *fname
= N_("NoName");
273 char *full_fname
= NULL
;
275 if (edit
->filename_vpath
!= NULL
)
277 full_fname
= vfs_path_to_str (edit
->filename_vpath
);
278 fname
= x_basename (full_fname
);
286 tty_printf ("[%s]", str_term_trim (fname
, edit
->widget
.cols
- 8 - 6));
293 if (x
+ 6 <= cols
- 2 - 6)
296 tty_printf ("[%c%c%c%c]",
297 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
298 edit
->modified
? 'M' : '-',
299 macro_index
< 0 ? '-' : 'R', edit
->overwrite
== 0 ? '-' : 'O');
304 edit_move (2, edit
->widget
.lines
- 1);
305 tty_printf ("%3ld %5ld/%ld %6ld/%ld",
306 edit
->curs_col
+ edit
->over_col
,
307 edit
->curs_line
+ 1, edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
);
311 * If we are at the end of file, print <EOF>,
312 * otherwise print the current character as is (if printable),
313 * as decimal and as hex.
317 edit_move (32, edit
->widget
.lines
- 1);
318 if (edit
->curs1
>= edit
->last_byte
)
319 tty_print_string ("[<EOF> ]");
323 unsigned int cur_utf
;
326 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
328 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
329 tty_printf ("[%05d 0x%04X]", cur_utf
, cur_utf
);
334 unsigned char cur_byte
;
336 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
337 tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte
, (unsigned int) cur_byte
);
342 /* --------------------------------------------------------------------------------------------- */
344 * Draw a frame around edit area.
346 * @param edit editor object
347 * @param color color pair
348 * @param active TRUE if editor object is focused
352 edit_draw_frame (const WEdit
* edit
, int color
, gboolean active
)
354 const Widget
*w
= (const Widget
*) edit
;
356 /* draw a frame around edit area */
357 tty_setcolor (color
);
358 /* draw double frame for active window if skin supports that */
359 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, !active
);
360 /* draw a drag marker */
361 if (edit
->drag_state
== MCEDIT_DRAG_NORMAL
)
363 tty_setcolor (EDITOR_FRAME_DRAG
);
364 widget_move (w
, w
->lines
- 1, w
->cols
- 1);
365 tty_print_alt_char (ACS_LRCORNER
, TRUE
);
369 /* --------------------------------------------------------------------------------------------- */
371 * Draw a window control buttons.
373 * @param edit editor object
374 * @param color color pair
378 edit_draw_window_icons (const WEdit
* edit
, int color
)
380 const Widget
*w
= (const Widget
*) edit
;
383 tty_setcolor (color
);
384 if (edit
->fullscreen
)
385 dlg_move (w
->owner
, 0, w
->owner
->cols
- 6);
387 widget_move (w
, 0, edit
->widget
.cols
- 8);
388 g_snprintf (tmp
, sizeof (tmp
), "[%s][%s]", edit_window_state_char
, edit_window_close_char
);
389 tty_print_string (tmp
);
392 /* --------------------------------------------------------------------------------------------- */
395 print_to_widget (WEdit
* edit
, long row
, int start_col
, int start_col_real
,
396 long end_col
, struct line_s line
[], char *status
, int bookmarked
)
400 int x
= start_col_real
;
401 int x1
= start_col
+ EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
402 int y
= row
+ EDIT_TEXT_VERTICAL_OFFSET
;
403 int cols_to_skip
= abs (x
);
408 if (!edit
->fullscreen
)
414 tty_setcolor (EDITOR_NORMAL_COLOR
);
416 tty_setcolor (bookmarked
);
418 len
= end_col
+ 1 - start_col
;
419 wrap_start
= option_word_wrap_line_length
+ edit
->start_col
;
421 if (len
> 0 && edit
->widget
.y
+ y
>= 0)
423 if (!show_right_margin
|| wrap_start
> end_col
)
424 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
425 else if (wrap_start
< 0)
427 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
428 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
433 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', wrap_start
);
438 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
439 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
+ wrap_start
, ' ', len
);
444 if (option_line_state
)
446 tty_setcolor (LINE_STATE_COLOR
);
447 for (i
= 0; i
< LINE_STATE_WIDTH
; i
++)
449 edit_move (x1
+ i
- option_line_state_width
, y
);
450 if (status
[i
] == '\0')
452 tty_print_char (status
[i
]);
458 for (p
= line
; p
->ch
!= 0; p
++)
461 unsigned int textchar
;
464 if (cols_to_skip
!= 0)
470 style
= p
->style
& 0xFF00;
472 color
= p
->style
>> 16;
474 if (style
& MOD_ABNORMAL
)
476 /* Non-printable - use black background */
480 if (style
& MOD_WHITESPACE
)
482 if (style
& MOD_MARKED
)
485 tty_setcolor (EDITOR_MARKED_COLOR
);
488 tty_setcolor (EDITOR_WHITESPACE_COLOR
);
490 else if (style
& MOD_BOLD
)
491 tty_setcolor (EDITOR_BOLD_COLOR
);
492 else if (style
& MOD_MARKED
)
493 tty_setcolor (EDITOR_MARKED_COLOR
);
495 tty_lowlevel_setcolor (color
);
497 if (show_right_margin
)
499 if (i
> option_word_wrap_line_length
+ edit
->start_col
)
500 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
504 tty_print_anychar (textchar
);
508 /* --------------------------------------------------------------------------------------------- */
509 /** b is a pointer to the beginning of the line */
512 edit_draw_this_line (WEdit
* edit
, long b
, long row
, long start_col
, long end_col
)
514 struct line_s line
[MAX_LINE_LEN
];
515 struct line_s
*p
= line
;
517 long m1
= 0, m2
= 0, q
, c1
, c2
;
518 int col
, start_col_real
;
524 unsigned int cur_line
= 0;
526 char line_stat
[LINE_STATE_WIDTH
+ 1] = "\0";
528 if (row
> edit
->widget
.lines
- 1 - EDIT_TEXT_VERTICAL_OFFSET
- 2 * (edit
->fullscreen
? 0 : 1))
531 if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_COLOR
))
532 book_mark
= BOOK_MARK_COLOR
;
533 else if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_FOUND_COLOR
))
534 book_mark
= BOOK_MARK_FOUND_COLOR
;
537 abn_style
= book_mark
<< 16;
539 abn_style
= MOD_ABNORMAL
;
541 end_col
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
542 if (!edit
->fullscreen
)
544 const Widget
*w
= (const Widget
*) edit
;
547 if (w
->x
+ w
->cols
<= w
->owner
->cols
)
551 edit_get_syntax_color (edit
, b
- 1, &color
);
552 q
= edit_move_forward3 (edit
, b
, start_col
- edit
->start_col
, 0);
553 start_col_real
= (col
= (int) edit_move_forward3 (edit
, b
, 0, q
)) + edit
->start_col
;
555 if (option_line_state
)
557 cur_line
= edit
->start_line
+ row
;
558 if (cur_line
<= (unsigned int) edit
->total_lines
)
560 g_snprintf (line_stat
, LINE_STATE_WIDTH
+ 1, "%7i ", cur_line
+ 1);
564 memset (line_stat
, ' ', LINE_STATE_WIDTH
);
565 line_stat
[LINE_STATE_WIDTH
] = '\0';
567 if (book_mark_query_color (edit
, cur_line
, BOOK_MARK_COLOR
))
569 g_snprintf (line_stat
, 2, "*");
573 if (col
+ 16 > -edit
->start_col
)
575 eval_marks (edit
, &m1
, &m2
);
577 if (row
<= edit
->total_lines
- edit
->start_line
)
580 if (tty_use_colors () && visible_tws
)
582 tws
= edit_eol (edit
, b
);
583 while (tws
> b
&& ((c
= edit_get_byte (edit
, tws
- 1)) == ' ' || c
== '\t'))
587 while (col
<= end_col
- edit
->start_col
)
591 gboolean wide_width_char
= FALSE
;
592 gboolean control_char
= FALSE
;
596 if (q
== edit
->curs1
)
597 p
->style
|= MOD_CURSOR
;
598 if (q
>= m1
&& q
< m2
)
600 if (edit
->column_highlight
)
603 x
= edit_move_forward3 (edit
, b
, 0, q
);
604 c1
= min (edit
->column1
, edit
->column2
);
605 c2
= max (edit
->column1
, edit
->column2
);
606 if (x
>= c1
&& x
< c2
)
607 p
->style
|= MOD_MARKED
;
610 p
->style
|= MOD_MARKED
;
612 if (q
== edit
->bracket
)
613 p
->style
|= MOD_BOLD
;
614 if (q
>= edit
->found_start
&& q
< edit
->found_start
+ edit
->found_len
)
615 p
->style
|= MOD_BOLD
;
619 c
= edit_get_byte (edit
, q
);
623 c
= edit_get_utf (edit
, q
, &cw
);
625 /* we don't use bg for mc - fg contains both */
628 p
->style
|= book_mark
<< 16;
632 edit_get_syntax_color (edit
, q
, &color
);
633 p
->style
|= color
<< 16;
638 col
= (end_col
+ utf8lag
) - edit
->start_col
+ 1; /* quit */
641 i
= TAB_SIZE
- ((int) col
% TAB_SIZE
);
642 tab_over
= (end_col
- edit
->start_col
) - (col
+ i
- 1);
646 if (tty_use_colors () &&
647 ((visible_tabs
|| (visible_tws
&& q
>= tws
)) && enable_show_tabs_tws
))
649 if (p
->style
& MOD_MARKED
)
652 c
|= book_mark
<< 16;
654 c
= p
->style
| MOD_WHITESPACE
;
686 else if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
689 p
->style
|= MOD_WHITESPACE
;
690 c
= p
->style
& ~MOD_CURSOR
;
702 c
= p
->style
& ~MOD_CURSOR
;
713 if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
716 p
->style
|= MOD_WHITESPACE
;
724 if (mc_global
.utf8_display
)
728 c
= convert_from_8bit_to_utf_c ((unsigned char) c
, edit
->converter
);
732 if (g_unichar_iswide (c
))
734 wide_width_char
= TRUE
;
740 c
= convert_from_utf_to_current_c (c
, edit
->converter
);
742 c
= convert_to_display_c (c
);
745 /* Caret notation for control characters */
749 p
->style
= abn_style
;
752 p
->style
= abn_style
;
761 p
->style
= abn_style
;
764 p
->style
= abn_style
;
772 if ((mc_global
.utf8_display
&& g_unichar_isprint (c
)) ||
773 (!mc_global
.utf8_display
&& is_printable (c
)))
781 p
->style
= abn_style
;
787 if (g_unichar_isprint (c
))
795 p
->style
= abn_style
;
809 if (col
> (end_col
- edit
->start_col
+ 1))
827 start_col_real
= start_col
= 0;
832 print_to_widget (edit
, row
, start_col
, start_col_real
, end_col
, line
, line_stat
, book_mark
);
835 /* --------------------------------------------------------------------------------------------- */
838 edit_draw_this_char (WEdit
* edit
, long curs
, long row
, long start_column
, long end_column
)
840 int b
= edit_bol (edit
, curs
);
841 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
844 /* --------------------------------------------------------------------------------------------- */
845 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
848 render_edit_text (WEdit
* edit
, long start_row
, long start_column
, long end_row
, long end_column
)
850 static long prev_curs_row
= 0;
851 static long prev_curs
= 0;
853 Widget
*w
= (Widget
*) edit
;
854 Dlg_head
*h
= w
->owner
;
856 long row
= 0, curs_row
;
857 int force
= edit
->force
;
864 /* draw only visible region */
866 last_line
= h
->y
+ h
->lines
- 1;
869 if (y1
> last_line
- 1 /* buttonbar */ )
872 last_column
= h
->x
+ h
->cols
- 1;
875 if (x1
> last_column
)
878 y2
= w
->y
+ w
->lines
- 1;
879 if (y2
< h
->y
+ 1 /* menubar */ )
882 x2
= w
->x
+ w
->cols
- 1;
886 if ((force
& REDRAW_IN_BOUNDS
) == 0)
888 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
889 /* draw only visible region */
891 if (y2
<= last_line
- 1 /* buttonbar */ )
892 end_row
= w
->lines
- 1;
893 else if (y1
>= h
->y
+ 1 /* menubar */ )
894 end_row
= h
->lines
- 1 - y1
- 1;
896 end_row
= start_row
+ h
->lines
- 1 - 1;
898 if (x2
<= last_column
)
899 end_column
= w
->cols
- 1;
901 end_column
= h
->cols
- 1 - x1
;
903 end_column
= start_column
+ h
->cols
- 1;
907 * If the position of the page has not moved then we can draw the cursor
908 * character only. This will prevent line flicker when using arrow keys.
910 if ((force
& REDRAW_CHAR_ONLY
) == 0 || (force
& REDRAW_PAGE
) != 0)
912 if ((force
& REDRAW_PAGE
) != 0)
915 b
= edit_move_forward (edit
, edit
->start_display
, start_row
, 0);
916 while (row
<= end_row
)
918 if (key_pending (edit
))
920 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
921 b
= edit_move_forward (edit
, b
, 1, 0);
927 curs_row
= edit
->curs_row
;
929 if ((force
& REDRAW_BEFORE_CURSOR
) != 0 && start_row
< curs_row
)
931 long upto
= curs_row
- 1 <= end_row
? curs_row
- 1 : end_row
;
934 b
= edit
->start_display
;
937 if (key_pending (edit
))
939 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
940 b
= edit_move_forward (edit
, b
, 1, 0);
944 /* if (force & REDRAW_LINE) ---> default */
945 b
= edit_bol (edit
, edit
->curs1
);
946 if (curs_row
>= start_row
&& curs_row
<= end_row
)
948 if (key_pending (edit
))
950 edit_draw_this_line (edit
, b
, curs_row
, start_column
, end_column
);
953 if ((force
& REDRAW_AFTER_CURSOR
) != 0 && end_row
> curs_row
)
955 row
= curs_row
+ 1 < start_row
? start_row
: curs_row
+ 1;
956 b
= edit_move_forward (edit
, b
, 1, 0);
957 while (row
<= end_row
)
959 if (key_pending (edit
))
961 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
962 b
= edit_move_forward (edit
, b
, 1, 0);
967 if ((force
& REDRAW_LINE_ABOVE
) != 0 && curs_row
>= 1)
970 b
= edit_move_backward (edit
, edit_bol (edit
, edit
->curs1
), 1);
971 if (row
>= start_row
&& row
<= end_row
)
973 if (key_pending (edit
))
975 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
979 if ((force
& REDRAW_LINE_BELOW
) != 0 && row
< edit
->widget
.lines
- 1)
982 b
= edit_bol (edit
, edit
->curs1
);
983 b
= edit_move_forward (edit
, b
, 1, 0);
984 if (row
>= start_row
&& row
<= end_row
)
986 if (key_pending (edit
))
988 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
993 else if (prev_curs_row
< edit
->curs_row
)
995 /* with the new text highlighting, we must draw from the top down */
996 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
997 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
1001 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
1002 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
1007 prev_curs_row
= edit
->curs_row
;
1008 prev_curs
= edit
->curs1
;
1011 /* --------------------------------------------------------------------------------------------- */
1014 edit_render (WEdit
* edit
, int page
, int row_start
, int col_start
, int row_end
, int col_end
)
1016 if (page
) /* if it was an expose event, 'page' would be set */
1017 edit
->force
|= REDRAW_PAGE
| REDRAW_IN_BOUNDS
;
1019 render_edit_text (edit
, row_start
, col_start
, row_end
, col_end
);
1022 * edit->force != 0 means a key was pending and the redraw
1023 * was halted, so next time we must redraw everything in case stuff
1024 * was left undrawn from a previous key press.
1027 edit
->force
|= REDRAW_PAGE
;
1030 /* --------------------------------------------------------------------------------------------- */
1031 /*** public functions ****************************************************************************/
1032 /* --------------------------------------------------------------------------------------------- */
1035 edit_status (WEdit
* edit
, gboolean active
)
1039 if (edit
->fullscreen
)
1041 color
= STATUSBAR_COLOR
;
1042 edit_status_fullscreen (edit
, color
);
1046 color
= edit
->drag_state
!= MCEDIT_DRAG_NORMAL
? EDITOR_FRAME_DRAG
: active
?
1047 EDITOR_FRAME_ACTIVE
: EDITOR_FRAME
;
1048 edit_draw_frame (edit
, color
, active
);
1049 edit_status_window (edit
);
1052 edit_draw_window_icons (edit
, color
);
1055 /* --------------------------------------------------------------------------------------------- */
1057 /** this scrolls the text so that cursor is on the screen */
1059 edit_scroll_screen_over_cursor (WEdit
* edit
)
1063 int b_extreme
, t_extreme
, l_extreme
, r_extreme
;
1065 if (edit
->widget
.lines
<= 0 || edit
->widget
.cols
<= 0)
1068 edit
->widget
.lines
-= EDIT_TEXT_VERTICAL_OFFSET
;
1069 edit
->widget
.cols
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1071 if (!edit
->fullscreen
)
1074 edit
->widget
.cols
-= 2;
1076 edit
->widget
.lines
-= 2;
1079 r_extreme
= EDIT_RIGHT_EXTREME
;
1080 l_extreme
= EDIT_LEFT_EXTREME
;
1081 b_extreme
= EDIT_BOTTOM_EXTREME
;
1082 t_extreme
= EDIT_TOP_EXTREME
;
1083 if (edit
->found_len
)
1085 b_extreme
= max (edit
->widget
.lines
/ 4, b_extreme
);
1086 t_extreme
= max (edit
->widget
.lines
/ 4, t_extreme
);
1088 if (b_extreme
+ t_extreme
+ 1 > edit
->widget
.lines
)
1092 n
= b_extreme
+ t_extreme
;
1095 b_extreme
= (b_extreme
* (edit
->widget
.lines
- 1)) / n
;
1096 t_extreme
= (t_extreme
* (edit
->widget
.lines
- 1)) / n
;
1098 if (l_extreme
+ r_extreme
+ 1 > edit
->widget
.cols
)
1102 n
= l_extreme
+ t_extreme
;
1105 l_extreme
= (l_extreme
* (edit
->widget
.cols
- 1)) / n
;
1106 r_extreme
= (r_extreme
* (edit
->widget
.cols
- 1)) / n
;
1108 p
= edit_get_col (edit
) + edit
->over_col
;
1109 edit_update_curs_row (edit
);
1110 outby
= p
+ edit
->start_col
- edit
->widget
.cols
+ 1 + (r_extreme
+ edit
->found_len
);
1112 edit_scroll_right (edit
, outby
);
1113 outby
= l_extreme
- p
- edit
->start_col
;
1115 edit_scroll_left (edit
, outby
);
1117 outby
= p
- edit
->widget
.lines
+ 1 + b_extreme
;
1119 edit_scroll_downward (edit
, outby
);
1120 outby
= t_extreme
- p
;
1122 edit_scroll_upward (edit
, outby
);
1123 edit_update_curs_row (edit
);
1125 edit
->widget
.lines
+= EDIT_TEXT_VERTICAL_OFFSET
;
1126 edit
->widget
.cols
+= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1127 if (!edit
->fullscreen
)
1130 edit
->widget
.cols
+= 2;
1132 edit
->widget
.lines
+= 2;
1136 /* --------------------------------------------------------------------------------------------- */
1139 edit_render_keypress (WEdit
* edit
)
1141 edit_render (edit
, 0, 0, 0, 0, 0);
1144 /* --------------------------------------------------------------------------------------------- */