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
)
113 * If we are at the end of file, print <EOF>,
114 * otherwise print the current character as is (if printable),
115 * as decimal and as hex.
117 if (edit
->curs1
< edit
->last_byte
)
122 unsigned int cur_utf
= 0;
125 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
128 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
129 (unsigned) cur_utf
, (unsigned) cur_utf
);
133 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
134 g_snprintf (byte_str
, sizeof (byte_str
), "%04d 0x%03X",
135 (int) cur_utf
, (unsigned) cur_utf
);
141 unsigned char cur_byte
= 0;
143 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
144 g_snprintf (byte_str
, sizeof (byte_str
), "%4d 0x%03X",
145 (int) cur_byte
, (unsigned) cur_byte
);
150 strcpy (byte_str
, "<EOF> ");
153 /* The field lengths just prevent the status line from shortening too much */
154 if (simple_statusbar
)
156 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
157 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
158 edit
->modified
? 'M' : '-',
159 macro_index
< 0 ? '-' : 'R',
160 edit
->overwrite
== 0 ? '-' : 'O',
161 edit
->curs_col
+ edit
->over_col
,
163 edit
->total_lines
+ 1, (long) edit
->curs1
, (long) edit
->last_byte
, byte_str
,
165 mc_global
.source_codepage
>= 0 ? get_codepage_id (mc_global
.source_codepage
) :
170 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s",
171 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
172 edit
->modified
? 'M' : '-',
173 macro_index
< 0 ? '-' : 'R',
174 edit
->overwrite
== 0 ? '-' : 'O',
175 edit
->curs_col
+ edit
->over_col
,
176 edit
->start_line
+ 1,
179 edit
->total_lines
+ 1, (long) edit
->curs1
, (long) edit
->last_byte
, byte_str
,
181 mc_global
.source_codepage
>= 0 ? get_codepage_id (mc_global
.source_codepage
) :
186 /* --------------------------------------------------------------------------------------------- */
188 * Draw the status line at the top of the screen for fullscreen editor window.
190 * @param edit editor object
191 * @param color color pair
195 edit_status_fullscreen (WEdit
* edit
, int color
)
197 const int w
= edit
->widget
.owner
->cols
;
198 const size_t status_size
= w
+ 1;
199 char *const status
= g_malloc (status_size
);
201 const char *fname
= "";
203 const int gap
= 3; /* between the filename and the status */
204 const int right_gap
= 5; /* at the right end of the screen */
205 const int preferred_fname_len
= 16;
207 status_string (edit
, status
, status_size
);
208 status_len
= (int) str_term_width1 (status
);
210 if (edit
->filename_vpath
!= NULL
)
211 fname
= x_basename (vfs_path_get_last_path_str (edit
->filename_vpath
));
213 fname_len
= str_term_width1 (fname
);
214 if (fname_len
< preferred_fname_len
)
215 fname_len
= preferred_fname_len
;
217 if (fname_len
+ gap
+ status_len
+ right_gap
>= w
)
219 if (preferred_fname_len
+ gap
+ status_len
+ right_gap
>= w
)
220 fname_len
= preferred_fname_len
;
222 fname_len
= w
- (gap
+ status_len
+ right_gap
);
223 fname
= str_trunc (fname
, fname_len
);
226 dlg_move (edit
->widget
.owner
, 0, 0);
227 tty_setcolor (color
);
228 printwstr (fname
, fname_len
+ gap
);
229 printwstr (status
, w
- (fname_len
+ gap
));
231 if (simple_statusbar
&& w
> EDITOR_MINIMUM_TERMINAL_WIDTH
)
233 size_t percent
= 100;
235 if (edit
->total_lines
+ 1 != 0)
236 percent
= (edit
->curs_line
+ 1) * 100 / (edit
->total_lines
+ 1);
237 dlg_move (edit
->widget
.owner
, 0, w
- 6 - 6);
238 tty_printf (" %3d%%", percent
);
244 /* --------------------------------------------------------------------------------------------- */
246 * Draw status line for editor window if window is not in fullscreen mode.
248 * @param edit editor object
252 edit_status_window (WEdit
* edit
)
255 int cols
= edit
->widget
.cols
;
257 tty_setcolor (STATUSBAR_COLOR
);
261 const char *fname
= N_("NoName");
262 char *full_fname
= NULL
;
264 if (edit
->filename_vpath
!= NULL
)
266 full_fname
= vfs_path_to_str (edit
->filename_vpath
);
267 fname
= x_basename (full_fname
);
275 tty_printf ("[%s]", str_term_trim (fname
, edit
->widget
.cols
- 8 - 6));
282 if (x
+ 6 <= cols
- 2 - 6)
285 tty_printf ("[%c%c%c%c]",
286 edit
->mark1
!= edit
->mark2
? (edit
->column_highlight
? 'C' : 'B') : '-',
287 edit
->modified
? 'M' : '-',
288 macro_index
< 0 ? '-' : 'R', edit
->overwrite
== 0 ? '-' : 'O');
293 edit_move (2, edit
->widget
.lines
- 1);
294 tty_printf ("%3ld %5ld/%ld %6ld/%ld",
295 edit
->curs_col
+ edit
->over_col
,
296 edit
->curs_line
+ 1, edit
->total_lines
+ 1, edit
->curs1
, edit
->last_byte
);
300 * If we are at the end of file, print <EOF>,
301 * otherwise print the current character as is (if printable),
302 * as decimal and as hex.
306 edit_move (32, edit
->widget
.lines
- 1);
307 if (edit
->curs1
>= edit
->last_byte
)
308 tty_print_string ("[<EOF> ]");
312 unsigned int cur_utf
;
315 cur_utf
= edit_get_utf (edit
, edit
->curs1
, &cw
);
317 cur_utf
= edit_get_byte (edit
, edit
->curs1
);
318 tty_printf ("[%05d 0x%04X]", cur_utf
, cur_utf
);
323 unsigned char cur_byte
;
325 cur_byte
= edit_get_byte (edit
, edit
->curs1
);
326 tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte
, (unsigned int) cur_byte
);
331 /* --------------------------------------------------------------------------------------------- */
333 * Draw a frame around edit area.
335 * @param edit editor object
336 * @param color color pair
337 * @param active TRUE if editor object is focused
341 edit_draw_frame (const WEdit
* edit
, int color
, gboolean active
)
343 const Widget
*w
= (const Widget
*) edit
;
345 /* draw a frame around edit area */
346 tty_setcolor (color
);
347 /* draw double frame for active window if skin supports that */
348 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, !active
);
349 /* draw a drag marker */
350 if (edit
->drag_state
== MCEDIT_DRAG_NORMAL
)
352 tty_setcolor (EDITOR_FRAME_DRAG
);
353 widget_move (w
, w
->lines
- 1, w
->cols
- 1);
354 tty_print_alt_char (ACS_LRCORNER
, TRUE
);
358 /* --------------------------------------------------------------------------------------------- */
360 * Draw a window control buttons.
362 * @param edit editor object
363 * @param color color pair
367 edit_draw_window_icons (const WEdit
* edit
, int color
)
369 const Widget
*w
= (const Widget
*) edit
;
372 tty_setcolor (color
);
373 if (edit
->fullscreen
)
374 dlg_move (w
->owner
, 0, w
->owner
->cols
- 6);
376 widget_move (w
, 0, edit
->widget
.cols
- 8);
377 g_snprintf (tmp
, sizeof (tmp
), "[%s][%s]", edit_window_state_char
, edit_window_close_char
);
378 tty_print_string (tmp
);
381 /* --------------------------------------------------------------------------------------------- */
384 print_to_widget (WEdit
* edit
, long row
, int start_col
, int start_col_real
,
385 long end_col
, struct line_s line
[], char *status
, int bookmarked
)
389 int x
= start_col_real
;
390 int x1
= start_col
+ EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
391 int y
= row
+ EDIT_TEXT_VERTICAL_OFFSET
;
392 int cols_to_skip
= abs (x
);
397 if (!edit
->fullscreen
)
403 tty_setcolor (EDITOR_NORMAL_COLOR
);
405 tty_setcolor (bookmarked
);
407 len
= end_col
+ 1 - start_col
;
408 wrap_start
= option_word_wrap_line_length
+ edit
->start_col
;
410 if (len
> 0 && edit
->widget
.y
+ y
>= 0)
412 if (!show_right_margin
|| wrap_start
> end_col
)
413 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
414 else if (wrap_start
< 0)
416 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
417 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', len
);
422 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
, ' ', wrap_start
);
427 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
428 tty_draw_hline (edit
->widget
.y
+ y
, edit
->widget
.x
+ x1
+ wrap_start
, ' ', len
);
433 if (option_line_state
)
435 tty_setcolor (LINE_STATE_COLOR
);
436 for (i
= 0; i
< LINE_STATE_WIDTH
; i
++)
438 edit_move (x1
+ i
- option_line_state_width
, y
);
439 if (status
[i
] == '\0')
441 tty_print_char (status
[i
]);
447 for (p
= line
; p
->ch
!= 0; p
++)
450 unsigned int textchar
;
453 if (cols_to_skip
!= 0)
459 style
= p
->style
& 0xFF00;
461 color
= p
->style
>> 16;
463 if (style
& MOD_ABNORMAL
)
465 /* Non-printable - use black background */
469 if (style
& MOD_WHITESPACE
)
471 if (style
& MOD_MARKED
)
474 tty_setcolor (EDITOR_MARKED_COLOR
);
477 tty_setcolor (EDITOR_WHITESPACE_COLOR
);
479 else if (style
& MOD_BOLD
)
480 tty_setcolor (EDITOR_BOLD_COLOR
);
481 else if (style
& MOD_MARKED
)
482 tty_setcolor (EDITOR_MARKED_COLOR
);
484 tty_lowlevel_setcolor (color
);
486 if (show_right_margin
)
488 if (i
> option_word_wrap_line_length
+ edit
->start_col
)
489 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR
);
493 tty_print_anychar (textchar
);
497 /* --------------------------------------------------------------------------------------------- */
498 /** b is a pointer to the beginning of the line */
501 edit_draw_this_line (WEdit
* edit
, off_t b
, long row
, long start_col
, long end_col
)
503 struct line_s line
[MAX_LINE_LEN
];
504 struct line_s
*p
= line
;
506 off_t m1
= 0, m2
= 0, q
;
508 int col
, start_col_real
;
513 unsigned int cur_line
= 0;
515 char line_stat
[LINE_STATE_WIDTH
+ 1] = "\0";
517 if (row
> edit
->widget
.lines
- 1 - EDIT_TEXT_VERTICAL_OFFSET
- 2 * (edit
->fullscreen
? 0 : 1))
520 if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_COLOR
))
521 book_mark
= BOOK_MARK_COLOR
;
522 else if (book_mark_query_color (edit
, edit
->start_line
+ row
, BOOK_MARK_FOUND_COLOR
))
523 book_mark
= BOOK_MARK_FOUND_COLOR
;
526 abn_style
= book_mark
<< 16;
528 abn_style
= MOD_ABNORMAL
;
530 end_col
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
531 if (!edit
->fullscreen
)
533 const Widget
*w
= (const Widget
*) edit
;
536 if (w
->x
+ w
->cols
<= w
->owner
->cols
)
540 edit_get_syntax_color (edit
, b
- 1, &color
);
541 q
= edit_move_forward3 (edit
, b
, start_col
- edit
->start_col
, 0);
542 start_col_real
= (col
= (int) edit_move_forward3 (edit
, b
, 0, q
)) + edit
->start_col
;
544 if (option_line_state
)
546 cur_line
= edit
->start_line
+ row
;
547 if (cur_line
<= (unsigned int) edit
->total_lines
)
549 g_snprintf (line_stat
, LINE_STATE_WIDTH
+ 1, "%7i ", cur_line
+ 1);
553 memset (line_stat
, ' ', LINE_STATE_WIDTH
);
554 line_stat
[LINE_STATE_WIDTH
] = '\0';
556 if (book_mark_query_color (edit
, cur_line
, BOOK_MARK_COLOR
))
558 g_snprintf (line_stat
, 2, "*");
562 if (col
+ 16 > -edit
->start_col
)
564 eval_marks (edit
, &m1
, &m2
);
566 if (row
<= edit
->total_lines
- edit
->start_line
)
569 if (tty_use_colors () && visible_tws
)
571 tws
= edit_eol (edit
, b
);
572 while (tws
> b
&& ((c
= edit_get_byte (edit
, tws
- 1)) == ' ' || c
== '\t'))
576 while (col
<= end_col
- edit
->start_col
)
580 gboolean wide_width_char
= FALSE
;
581 gboolean control_char
= FALSE
;
585 if (q
== edit
->curs1
)
586 p
->style
|= MOD_CURSOR
;
587 if (q
>= m1
&& q
< m2
)
589 if (edit
->column_highlight
)
593 x
= (long) edit_move_forward3 (edit
, b
, 0, q
);
594 c1
= min (edit
->column1
, edit
->column2
);
595 c2
= max (edit
->column1
, edit
->column2
);
596 if (x
>= c1
&& x
< c2
)
597 p
->style
|= MOD_MARKED
;
600 p
->style
|= MOD_MARKED
;
602 if (q
== edit
->bracket
)
603 p
->style
|= MOD_BOLD
;
604 if (q
>= edit
->found_start
&& q
< (off_t
) (edit
->found_start
+ edit
->found_len
))
605 p
->style
|= MOD_BOLD
;
610 c
= edit_get_utf (edit
, q
, &cw
);
615 c
= edit_get_byte (edit
, q
);
617 /* we don't use bg for mc - fg contains both */
620 p
->style
|= book_mark
<< 16;
624 edit_get_syntax_color (edit
, q
, &color
);
625 p
->style
|= color
<< 16;
630 col
= end_col
- edit
->start_col
+ 1; /* quit */
633 i
= TAB_SIZE
- ((int) col
% TAB_SIZE
);
634 tab_over
= (end_col
- edit
->start_col
) - (col
+ i
- 1);
638 if (tty_use_colors () &&
639 ((visible_tabs
|| (visible_tws
&& q
>= tws
)) && enable_show_tabs_tws
))
641 if (p
->style
& MOD_MARKED
)
644 c
|= book_mark
<< 16;
646 c
= p
->style
| MOD_WHITESPACE
;
678 else if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
681 p
->style
|= MOD_WHITESPACE
;
682 c
= p
->style
& ~MOD_CURSOR
;
694 c
= p
->style
& ~MOD_CURSOR
;
705 if (tty_use_colors () && visible_tws
&& q
>= tws
&& enable_show_tabs_tws
)
708 p
->style
|= MOD_WHITESPACE
;
716 if (mc_global
.utf8_display
)
720 c
= convert_from_8bit_to_utf_c ((unsigned char) c
, edit
->converter
);
724 if (g_unichar_iswide (c
))
726 wide_width_char
= TRUE
;
732 c
= convert_from_utf_to_current_c (c
, edit
->converter
);
734 c
= convert_to_display_c (c
);
737 /* Caret notation for control characters */
741 p
->style
= abn_style
;
744 p
->style
= abn_style
;
753 p
->style
= abn_style
;
756 p
->style
= abn_style
;
765 if (g_unichar_isprint (c
))
770 p
->style
= abn_style
;
777 if ((mc_global
.utf8_display
&& g_unichar_isprint (c
)) ||
778 (!mc_global
.utf8_display
&& is_printable (c
)))
786 p
->style
= abn_style
;
800 if (col
> (end_col
- edit
->start_col
+ 1))
818 start_col_real
= start_col
= 0;
823 print_to_widget (edit
, row
, start_col
, start_col_real
, end_col
, line
, line_stat
, book_mark
);
826 /* --------------------------------------------------------------------------------------------- */
829 edit_draw_this_char (WEdit
* edit
, off_t curs
, long row
, long start_column
, long end_column
)
831 off_t b
= edit_bol (edit
, curs
);
833 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
836 /* --------------------------------------------------------------------------------------------- */
837 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
840 render_edit_text (WEdit
* edit
, long start_row
, long start_column
, long end_row
, long end_column
)
842 static long prev_curs_row
= 0;
843 static off_t prev_curs
= 0;
845 Widget
*w
= (Widget
*) edit
;
846 Dlg_head
*h
= w
->owner
;
848 long row
= 0, curs_row
;
849 int force
= edit
->force
;
856 /* draw only visible region */
858 last_line
= h
->y
+ h
->lines
- 1;
861 if (y1
> last_line
- 1 /* buttonbar */ )
864 last_column
= h
->x
+ h
->cols
- 1;
867 if (x1
> last_column
)
870 y2
= w
->y
+ w
->lines
- 1;
871 if (y2
< h
->y
+ 1 /* menubar */ )
874 x2
= w
->x
+ w
->cols
- 1;
878 if ((force
& REDRAW_IN_BOUNDS
) == 0)
880 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
881 /* draw only visible region */
883 if (y2
<= last_line
- 1 /* buttonbar */ )
884 end_row
= w
->lines
- 1;
885 else if (y1
>= h
->y
+ 1 /* menubar */ )
886 end_row
= h
->lines
- 1 - y1
- 1;
888 end_row
= start_row
+ h
->lines
- 1 - 1;
890 if (x2
<= last_column
)
891 end_column
= w
->cols
- 1;
893 end_column
= h
->cols
- 1 - x1
;
895 end_column
= start_column
+ h
->cols
- 1;
899 * If the position of the page has not moved then we can draw the cursor
900 * character only. This will prevent line flicker when using arrow keys.
902 if ((force
& REDRAW_CHAR_ONLY
) == 0 || (force
& REDRAW_PAGE
) != 0)
904 if ((force
& REDRAW_PAGE
) != 0)
907 b
= edit_move_forward (edit
, edit
->start_display
, start_row
, 0);
908 while (row
<= end_row
)
910 if (key_pending (edit
))
912 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
913 b
= edit_move_forward (edit
, b
, 1, 0);
919 curs_row
= edit
->curs_row
;
921 if ((force
& REDRAW_BEFORE_CURSOR
) != 0 && start_row
< curs_row
)
923 long upto
= curs_row
- 1 <= end_row
? curs_row
- 1 : end_row
;
926 b
= edit
->start_display
;
929 if (key_pending (edit
))
931 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
932 b
= edit_move_forward (edit
, b
, 1, 0);
936 /* if (force & REDRAW_LINE) ---> default */
937 b
= edit_bol (edit
, edit
->curs1
);
938 if (curs_row
>= start_row
&& curs_row
<= end_row
)
940 if (key_pending (edit
))
942 edit_draw_this_line (edit
, b
, curs_row
, start_column
, end_column
);
945 if ((force
& REDRAW_AFTER_CURSOR
) != 0 && end_row
> curs_row
)
947 row
= curs_row
+ 1 < start_row
? start_row
: curs_row
+ 1;
948 b
= edit_move_forward (edit
, b
, 1, 0);
949 while (row
<= end_row
)
951 if (key_pending (edit
))
953 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
954 b
= edit_move_forward (edit
, b
, 1, 0);
959 if ((force
& REDRAW_LINE_ABOVE
) != 0 && curs_row
>= 1)
962 b
= edit_move_backward (edit
, edit_bol (edit
, edit
->curs1
), 1);
963 if (row
>= start_row
&& row
<= end_row
)
965 if (key_pending (edit
))
967 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
971 if ((force
& REDRAW_LINE_BELOW
) != 0 && row
< edit
->widget
.lines
- 1)
974 b
= edit_bol (edit
, edit
->curs1
);
975 b
= edit_move_forward (edit
, b
, 1, 0);
976 if (row
>= start_row
&& row
<= end_row
)
978 if (key_pending (edit
))
980 edit_draw_this_line (edit
, b
, row
, start_column
, end_column
);
985 else if (prev_curs_row
< edit
->curs_row
)
987 /* with the new text highlighting, we must draw from the top down */
988 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
989 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
993 edit_draw_this_char (edit
, edit
->curs1
, edit
->curs_row
, start_column
, end_column
);
994 edit_draw_this_char (edit
, prev_curs
, prev_curs_row
, start_column
, end_column
);
999 prev_curs_row
= edit
->curs_row
;
1000 prev_curs
= edit
->curs1
;
1003 /* --------------------------------------------------------------------------------------------- */
1006 edit_render (WEdit
* edit
, int page
, int row_start
, int col_start
, int row_end
, int col_end
)
1008 if (page
) /* if it was an expose event, 'page' would be set */
1009 edit
->force
|= REDRAW_PAGE
| REDRAW_IN_BOUNDS
;
1011 render_edit_text (edit
, row_start
, col_start
, row_end
, col_end
);
1014 * edit->force != 0 means a key was pending and the redraw
1015 * was halted, so next time we must redraw everything in case stuff
1016 * was left undrawn from a previous key press.
1019 edit
->force
|= REDRAW_PAGE
;
1022 /* --------------------------------------------------------------------------------------------- */
1023 /*** public functions ****************************************************************************/
1024 /* --------------------------------------------------------------------------------------------- */
1027 edit_status (WEdit
* edit
, gboolean active
)
1031 if (edit
->fullscreen
)
1033 color
= STATUSBAR_COLOR
;
1034 edit_status_fullscreen (edit
, color
);
1038 color
= edit
->drag_state
!= MCEDIT_DRAG_NORMAL
? EDITOR_FRAME_DRAG
: active
?
1039 EDITOR_FRAME_ACTIVE
: EDITOR_FRAME
;
1040 edit_draw_frame (edit
, color
, active
);
1041 edit_status_window (edit
);
1044 edit_draw_window_icons (edit
, color
);
1047 /* --------------------------------------------------------------------------------------------- */
1049 /** this scrolls the text so that cursor is on the screen */
1051 edit_scroll_screen_over_cursor (WEdit
* edit
)
1055 int b_extreme
, t_extreme
, l_extreme
, r_extreme
;
1057 if (edit
->widget
.lines
<= 0 || edit
->widget
.cols
<= 0)
1060 edit
->widget
.lines
-= EDIT_TEXT_VERTICAL_OFFSET
;
1061 edit
->widget
.cols
-= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1063 if (!edit
->fullscreen
)
1066 edit
->widget
.cols
-= 2;
1068 edit
->widget
.lines
-= 2;
1071 r_extreme
= EDIT_RIGHT_EXTREME
;
1072 l_extreme
= EDIT_LEFT_EXTREME
;
1073 b_extreme
= EDIT_BOTTOM_EXTREME
;
1074 t_extreme
= EDIT_TOP_EXTREME
;
1075 if (edit
->found_len
!= 0)
1077 b_extreme
= max (edit
->widget
.lines
/ 4, b_extreme
);
1078 t_extreme
= max (edit
->widget
.lines
/ 4, t_extreme
);
1080 if (b_extreme
+ t_extreme
+ 1 > edit
->widget
.lines
)
1084 n
= b_extreme
+ t_extreme
;
1087 b_extreme
= (b_extreme
* (edit
->widget
.lines
- 1)) / n
;
1088 t_extreme
= (t_extreme
* (edit
->widget
.lines
- 1)) / n
;
1090 if (l_extreme
+ r_extreme
+ 1 > edit
->widget
.cols
)
1094 n
= l_extreme
+ t_extreme
;
1097 l_extreme
= (l_extreme
* (edit
->widget
.cols
- 1)) / n
;
1098 r_extreme
= (r_extreme
* (edit
->widget
.cols
- 1)) / n
;
1100 p
= edit_get_col (edit
) + edit
->over_col
;
1101 edit_update_curs_row (edit
);
1102 outby
= p
+ edit
->start_col
- edit
->widget
.cols
+ 1 + (r_extreme
+ edit
->found_len
);
1104 edit_scroll_right (edit
, outby
);
1105 outby
= l_extreme
- p
- edit
->start_col
;
1107 edit_scroll_left (edit
, outby
);
1109 outby
= p
- edit
->widget
.lines
+ 1 + b_extreme
;
1111 edit_scroll_downward (edit
, outby
);
1112 outby
= t_extreme
- p
;
1114 edit_scroll_upward (edit
, outby
);
1115 edit_update_curs_row (edit
);
1117 edit
->widget
.lines
+= EDIT_TEXT_VERTICAL_OFFSET
;
1118 edit
->widget
.cols
+= EDIT_TEXT_HORIZONTAL_OFFSET
+ option_line_state_width
;
1119 if (!edit
->fullscreen
)
1122 edit
->widget
.cols
+= 2;
1124 edit
->widget
.lines
+= 2;
1128 /* --------------------------------------------------------------------------------------------- */
1131 edit_render_keypress (WEdit
* edit
)
1133 edit_render (edit
, 0, 0, 0, 0, 0);
1136 /* --------------------------------------------------------------------------------------------- */