statusline.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #include <config.h>
  17. #include <string.h>
  18. #include "statusline.h"
  19. #include "editor.h"
  20. #include "themes.h"
  21. #include "dbg.h"
  22. StatusLine::StatusLine(const Editor *aBde, EditBox *aEditbox)
  23. {
  24. create_window();
  25. aEditbox->set_status_listener(this);
  26. editbox = aEditbox;
  27. bde = aBde;
  28. cursor_position_report = false;
  29. update_region = rgnAll;
  30. }
  31. void StatusLine::resize(int lines, int columns, int y, int x)
  32. {
  33. Widget::resize(lines, columns, y, x);
  34. request_update(rgnAll);
  35. }
  36. void StatusLine::request_update(region rgn)
  37. {
  38. update_region |= rgn;
  39. }
  40. void StatusLine::invalidate_view()
  41. {
  42. request_update(rgnAll);
  43. }
  44. void StatusLine::toggle_cursor_position_report()
  45. {
  46. cursor_position_report = !cursor_position_report;
  47. request_update(rgnAll);
  48. }
  49. void StatusLine::update()
  50. {
  51. if (update_region & rgnFilename)
  52. request_update(rgnAll);
  53. if (update_region & rgnAll) {
  54. wbkgd(wnd, get_attr(STATUSLINE_ATTR));
  55. wmove(wnd, 0, 0);
  56. wclrtoeol(wnd);
  57. }
  58. if (update_region & (rgnAll | rgnIndicators)) {
  59. wmove(wnd, 0, 0);
  60. waddch(wnd, '[');
  61. waddch(wnd, editbox->is_modified() ? 'M' : '-');
  62. char wrap_ch = '-';
  63. switch (editbox->get_wrap_type()) {
  64. case EditBox::wrpOff: wrap_ch = '$'; break;
  65. case EditBox::wrpAnywhere: wrap_ch = '\\'; break;
  66. case EditBox::wrpAtWhiteSpace: wrap_ch = '-'; break; // silence the compiler
  67. }
  68. waddch(wnd, wrap_ch);
  69. char algo_ch = '-';
  70. switch (editbox->get_dir_algo()) {
  71. case algoUnicode: algo_ch = '!'; break;
  72. case algoContextStrong: algo_ch = '~'; break;
  73. case algoContextRTL: algo_ch = '-'; break;
  74. case algoForceLTR: algo_ch = '>'; break;
  75. case algoForceRTL: algo_ch = '<'; break;
  76. }
  77. waddch(wnd, algo_ch);
  78. waddch(wnd, editbox->has_selected_text()
  79. && !bde->in_spelling() ? '@' : '-');
  80. waddch(wnd, editbox->is_read_only() ? 'R' : '-');
  81. waddch(wnd, bde->is_speller_loaded() ? 'S' : '-');
  82. waddch(wnd, editbox->in_translation_mode() ? '"' : '-');
  83. waddch(wnd, terminal::do_arabic_shaping ? 'a' : '-');
  84. waddch(wnd, editbox->get_alt_kbd() ? 'H' : '-');
  85. waddch(wnd, editbox->is_auto_justify() ? 'j' : '-');
  86. waddch(wnd, editbox->is_auto_indent() ? 'i' : '-');
  87. char maqaf_ch = '-';
  88. switch (editbox->get_maqaf_display()) {
  89. case EditBox::mqfAsis: maqaf_ch = '-'; break;
  90. case EditBox::mqfTransliterated: maqaf_ch = 'k'; break;
  91. case EditBox::mqfHighlighted: maqaf_ch = 'K'; break;
  92. }
  93. waddch(wnd, maqaf_ch);
  94. waddch(wnd, editbox->is_smart_typing() ? 'q' : '-');
  95. char rtlnsm_ch = '-';
  96. switch (editbox->get_rtl_nsm_display()) {
  97. case EditBox::rtlnsmOff: rtlnsm_ch = '-'; break;
  98. case EditBox::rtlnsmTransliterated: rtlnsm_ch = 'n'; break;
  99. case EditBox::rtlnsmAsis: rtlnsm_ch = 'N'; break;
  100. }
  101. waddch(wnd, rtlnsm_ch);
  102. waddch(wnd, editbox->get_visual_cursor_movement() ? 'v' : '-');
  103. waddch(wnd, editbox->has_formatting_marks() ? 'F' : '-');
  104. waddch(wnd, ']');
  105. }
  106. if (update_region & (rgnAll | rgnFilename)) {
  107. unistring tmp;
  108. tmp.init_from_filename(bde->get_filename());
  109. u8string filename;
  110. filename.init_from_unichars(tmp);
  111. waddch(wnd, ' ');
  112. if (filename.empty()) {
  113. draw_string(_("UNTITLED"));
  114. } else {
  115. waddch(wnd, '"');
  116. draw_string(filename.c_str());
  117. waddch(wnd, '"');
  118. }
  119. if (bde->is_new())
  120. draw_string(_(" [New File]"));
  121. wmove(wnd, 0, window_width() - strlen(bde->get_encoding()) - (2+5));
  122. wprintw(wnd, "[disk:%s]", bde->get_encoding());
  123. }
  124. if (cursor_position_report && (update_region & (rgnAll | rgnCursorPos))) {
  125. // we use 16 columns for the cursor position.
  126. int x = window_width() - strlen(bde->get_encoding()) - (2+5) - 16;
  127. wmove(wnd, 0, x);
  128. Point cursor;
  129. editbox->get_cursor_position(cursor);
  130. int total = editbox->get_number_of_paragraphs();
  131. wprintw(wnd, "%4d/%4d,%3d ", total, cursor.para + 1, cursor.pos + 1);
  132. }
  133. wnoutrefresh(wnd);
  134. update_region = rgnNone;
  135. }