~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to info/window.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* window.c -- windows in Info.
2
 
   $Id: window.c,v 1.15 2002/01/19 01:08:20 karl Exp $
 
2
   $Id: window.c,v 1.4 2004/04/11 17:56:46 karl Exp $
3
3
 
4
 
   Copyright (C) 1993, 97, 98, 2001, 02 Free Software Foundation, Inc.
 
4
   Copyright (C) 1993, 1997, 1998, 2001, 2002, 2003, 2004 Free Software
 
5
   Foundation, Inc.
5
6
 
6
7
   This program is free software; you can redistribute it and/or modify
7
8
   it under the terms of the GNU General Public License as published by
50
51
   Create the first window ever.
51
52
   You pass the dimensions of the total screen size. */
52
53
void
53
 
window_initialize_windows (width, height)
54
 
     int width, height;
 
54
window_initialize_windows (int width, int height)
55
55
{
56
56
  the_screen = xmalloc (sizeof (WINDOW));
57
57
  the_echo_area = xmalloc (sizeof (WINDOW));
82
82
     area. */
83
83
  the_echo_area->height = ECHO_AREA_HEIGHT;
84
84
  active_window->height = the_screen->height - 1 - the_echo_area->height;
85
 
  window_new_screen_size (width, height, NULL);
 
85
  window_new_screen_size (width, height);
86
86
 
87
87
  /* The echo area uses a different keymap than normal info windows. */
88
88
  the_echo_area->keymap = echo_area_keymap;
102
102
VFunction *window_deletion_notifier = NULL;
103
103
 
104
104
void
105
 
window_new_screen_size (width, height)
106
 
     int width, height;
 
105
window_new_screen_size (int width, int height)
107
106
{
108
107
  register WINDOW *win;
109
108
  int delta_height, delta_each, delta_leftover;
231
230
          if ((win->height < WINDOW_MIN_HEIGHT) ||
232
231
              (win->height > avail))
233
232
            {
234
 
              WINDOW *lastwin;
 
233
              WINDOW *lastwin = NULL;
235
234
 
236
235
              /* Split the space among the available windows. */
237
236
              delta_each = avail / numwins;
261
260
   window.  If the window could not be made return a NULL pointer.  The
262
261
   active window is not changed.*/
263
262
WINDOW *
264
 
window_make_window (node)
265
 
     NODE *node;
 
263
window_make_window (NODE *node)
266
264
{
267
265
  WINDOW *window;
268
266
 
376
374
   the previous and next windows in the chain.  If there is only one user
377
375
   window, then no change takes place. */
378
376
void
379
 
window_change_window_height (window, amount)
380
 
     WINDOW *window;
381
 
     int amount;
 
377
window_change_window_height (WINDOW *window, int amount)
382
378
{
383
379
  register WINDOW *win, *prev, *next;
384
380
 
509
505
   internal nodes as well, otherwise do not change the height of such
510
506
   windows. */
511
507
void
512
 
window_tile_windows (style)
513
 
     int style;
 
508
window_tile_windows (int style)
514
509
{
515
510
  WINDOW *win, *last_adjusted;
516
511
  int numwins, avail, per_win_height, leftover;
563
558
/* Toggle the state of line wrapping in WINDOW.  This can do a bit of fancy
564
559
   redisplay. */
565
560
void
566
 
window_toggle_wrap (window)
567
 
     WINDOW *window;
 
561
window_toggle_wrap (WINDOW *window)
568
562
{
569
563
  if (window->flags & W_NoWrap)
570
564
    window->flags &= ~W_NoWrap;
598
592
 
599
593
/* Set WINDOW to display NODE. */
600
594
void
601
 
window_set_node_of_window (window, node)
602
 
     WINDOW *window;
603
 
     NODE *node;
 
595
window_set_node_of_window (WINDOW *window, NODE *node)
604
596
{
605
597
  window->node = node;
606
598
  window->pagetop = 0;
618
610
   If the active window is the next or previous window, choose that window
619
611
   as the recipient of the extra space.  Otherwise, prefer the next window. */
620
612
void
621
 
window_delete_window (window)
622
 
     WINDOW *window;
 
613
window_delete_window (WINDOW *window)
623
614
{
624
615
  WINDOW *next, *prev, *window_to_fix;
625
616
 
690
681
 
691
682
/* For every window in CHAIN, set the flags member to have FLAG set. */
692
683
void
693
 
window_mark_chain (chain, flag)
694
 
     WINDOW *chain;
695
 
     int flag;
 
684
window_mark_chain (WINDOW *chain, int flag)
696
685
{
697
686
  register WINDOW *win;
698
687
 
702
691
 
703
692
/* For every window in CHAIN, clear the flags member of FLAG. */
704
693
void
705
 
window_unmark_chain (chain, flag)
706
 
     WINDOW *chain;
707
 
     int flag;
 
694
window_unmark_chain (WINDOW *chain, int flag)
708
695
{
709
696
  register WINDOW *win;
710
697
 
715
702
/* Return the number of characters it takes to display CHARACTER on the
716
703
   screen at HPOS. */
717
704
int
718
 
character_width (character, hpos)
719
 
     int character, hpos;
 
705
character_width (int character, int hpos)
720
706
{
721
707
  int printable_limit = 127;
722
708
  int width = 1;
750
736
/* Return the number of characters it takes to display STRING on the screen
751
737
   at HPOS. */
752
738
int
753
 
string_width (string, hpos)
754
 
     char *string;
755
 
     int hpos;
 
739
string_width (char *string, int hpos)
756
740
{
757
741
  register int i, width, this_char_width;
758
742
 
759
743
  for (width = 0, i = 0; string[i]; i++)
760
744
    {
761
 
      this_char_width = character_width (string[i], hpos);
 
745
      /* Support ANSI escape sequences for -R.  */
 
746
      if (raw_escapes_p
 
747
          && string[i] == '\033'
 
748
          && string[i+1] == '['
 
749
          && isdigit (string[i+2])
 
750
          && (string[i+3] == 'm'
 
751
              || (isdigit (string[i+3]) && string[i+4] == 'm')))
 
752
        {
 
753
          while (string[i] != 'm')
 
754
            i++;
 
755
          this_char_width = 0;
 
756
        }
 
757
      else
 
758
        this_char_width = character_width (string[i], hpos);
762
759
      width += this_char_width;
763
760
      hpos += this_char_width;
764
761
    }
768
765
/* Quickly guess the approximate number of lines that NODE would
769
766
   take to display.  This really only counts carriage returns. */
770
767
int
771
 
window_physical_lines (node)
772
 
     NODE *node;
 
768
window_physical_lines (NODE *node)
773
769
{
774
770
  register int i, lines;
775
771
  char *contents;
788
784
/* Calculate a list of line starts for the node belonging to WINDOW.  The line
789
785
   starts are pointers to the actual text within WINDOW->NODE. */
790
786
void
791
 
calculate_line_starts (window)
792
 
     WINDOW *window;
 
787
calculate_line_starts (WINDOW *window)
793
788
{
794
789
  register int i, hpos;
795
790
  char **line_starts = NULL;
830
825
             could be passed as negative integers to character_width
831
826
             and wreak havoc on some naive implementations of iscntrl.  */
832
827
          c = (unsigned char) node->contents[i];
833
 
          cwidth = character_width (c, hpos);
 
828
 
 
829
          /* Support ANSI escape sequences for -R.  */
 
830
          if (raw_escapes_p
 
831
              && c == '\033'
 
832
              && node->contents[i+1] == '['
 
833
              && isdigit (node->contents[i+2]))
 
834
            {
 
835
              if (node->contents[i+3] == 'm')
 
836
                {
 
837
                  i += 3;
 
838
                  cwidth = 0;
 
839
                }
 
840
              else if (isdigit (node->contents[i+3])
 
841
                       && node->contents[i+4] == 'm')
 
842
                {
 
843
                  i += 4;
 
844
                  cwidth = 0;
 
845
                }
 
846
              else
 
847
                cwidth = character_width (c, hpos);
 
848
            }
 
849
          else
 
850
            cwidth = character_width (c, hpos);
834
851
 
835
852
          /* If this character fits within this line, just do the next one. */
836
 
          if ((hpos + cwidth) < window->width)
 
853
          if ((hpos + cwidth) < (unsigned int) window->width)
837
854
            {
838
855
              i++;
839
856
              hpos += cwidth;
882
899
 
883
900
/* Given WINDOW, recalculate the line starts for the node it displays. */
884
901
void
885
 
recalculate_line_starts (window)
886
 
     WINDOW *window;
 
902
recalculate_line_starts (WINDOW *window)
887
903
{
888
904
  maybe_free (window->line_starts);
889
905
  calculate_line_starts (window);
897
913
 
898
914
/* Adjust the pagetop of WINDOW such that the cursor point will be visible. */
899
915
void
900
 
window_adjust_pagetop (window)
901
 
     WINDOW *window;
 
916
window_adjust_pagetop (WINDOW *window)
902
917
{
903
918
  register int line = 0;
904
919
  char *contents;
955
970
 
956
971
/* Return the index of the line containing point. */
957
972
int
958
 
window_line_of_point (window)
959
 
     WINDOW *window;
 
973
window_line_of_point (WINDOW *window)
960
974
{
961
975
  register int i, start = 0;
962
976
 
978
992
 
979
993
/* Get and return the goal column for this window. */
980
994
int
981
 
window_get_goal_column (window)
982
 
     WINDOW *window;
 
995
window_get_goal_column (WINDOW *window)
983
996
{
984
997
  if (!window->node)
985
998
    return (-1);
994
1007
 
995
1008
/* Get and return the printed column offset of the cursor in this window. */
996
1009
int
997
 
window_get_cursor_column (window)
998
 
     WINDOW *window;
 
1010
window_get_cursor_column (WINDOW *window)
999
1011
{
1000
1012
  int i, hpos, end;
1001
1013
  char *line;
1009
1021
  end = window->point - (line - window->node->contents);
1010
1022
 
1011
1023
  for (hpos = 0, i = 0; i < end; i++)
1012
 
    hpos += character_width (line[i], hpos);
 
1024
    {
 
1025
      /* Support ANSI escape sequences for -R.  */
 
1026
      if (raw_escapes_p
 
1027
          && line[i] == '\033'
 
1028
          && line[i+1] == '['
 
1029
          && isdigit (line[i+2]))
 
1030
        {
 
1031
          if (line[i+3] == 'm')
 
1032
            i += 3;
 
1033
          else if (isdigit (line[i+3]) && line[i+4] == 'm')
 
1034
            i += 4;
 
1035
          else
 
1036
            hpos += character_width (line[i], hpos);
 
1037
        }
 
1038
      else
 
1039
        hpos += character_width (line[i], hpos);
 
1040
    }
1013
1041
 
1014
1042
  return (hpos);
1015
1043
}
1017
1045
/* Count the number of characters in LINE that precede the printed column
1018
1046
   offset of GOAL. */
1019
1047
int
1020
 
window_chars_to_goal (line, goal)
1021
 
     char *line;
1022
 
     int goal;
 
1048
window_chars_to_goal (char *line, int goal)
1023
1049
{
1024
 
  register int i, check, hpos;
 
1050
  register int i, check = 0, hpos;
1025
1051
 
1026
1052
  for (hpos = 0, i = 0; line[i] != '\n'; i++)
1027
1053
    {
1028
 
 
1029
 
      check = hpos + character_width (line[i], hpos);
 
1054
      /* Support ANSI escape sequences for -R.  */
 
1055
      if (raw_escapes_p
 
1056
          && line[i] == '\033'
 
1057
          && line[i+1] == '['
 
1058
          && isdigit (line[i+2])
 
1059
          && (line[i+3] == 'm'
 
1060
              || (isdigit (line[i+3]) && line[i+4] == 'm')))
 
1061
        while (line[i] != 'm')
 
1062
          i++;
 
1063
      else
 
1064
        check = hpos + character_width (line[i], hpos);
1030
1065
 
1031
1066
      if (check > goal)
1032
1067
        break;
1038
1073
 
1039
1074
/* Create a modeline for WINDOW, and store it in window->modeline. */
1040
1075
void
1041
 
window_make_modeline (window)
1042
 
     WINDOW *window;
 
1076
window_make_modeline (WINDOW *window)
1043
1077
{
1044
1078
  register int i;
1045
1079
  char *modeline;
1083
1117
    int modeline_len = 0;
1084
1118
    char *parent = NULL, *filename = "*no file*";
1085
1119
    char *nodename = "*no node*";
1086
 
    char *update_message = NULL;
 
1120
    const char *update_message = NULL;
1087
1121
    NODE *node = window->node;
1088
1122
 
1089
1123
    if (node)
1153
1187
 
1154
1188
/* Make WINDOW start displaying at PERCENT percentage of its node. */
1155
1189
void
1156
 
window_goto_percentage (window, percent)
1157
 
     WINDOW *window;
1158
 
     int percent;
 
1190
window_goto_percentage (WINDOW *window, int percent)
1159
1191
{
1160
1192
  int desired_line;
1161
1193
 
1174
1206
 
1175
1207
/* Get the state of WINDOW, and save it in STATE. */
1176
1208
void
1177
 
window_get_state (window, state)
1178
 
     WINDOW *window;
1179
 
     WINDOW_STATE *state;
 
1209
window_get_state (WINDOW *window, SEARCH_STATE *state)
1180
1210
{
1181
1211
  state->node = window->node;
1182
1212
  state->pagetop = window->pagetop;
1185
1215
 
1186
1216
/* Set the node, pagetop, and point of WINDOW. */
1187
1217
void
1188
 
window_set_state (window, state)
1189
 
     WINDOW *window;
1190
 
     WINDOW_STATE *state;
 
1218
window_set_state (WINDOW *window, SEARCH_STATE *state)
1191
1219
{
1192
1220
  if (window->node != state->node)
1193
1221
    window_set_node_of_window (window, state->node);
1203
1231
 
1204
1232
/* Make the node of the_echo_area be an empty one. */
1205
1233
static void
1206
 
free_echo_area ()
 
1234
free_echo_area (void)
1207
1235
{
1208
1236
  if (echo_area_node)
1209
1237
    {
1218
1246
/* Clear the echo area, removing any message that is already present.
1219
1247
   The echo area is cleared immediately. */
1220
1248
void
1221
 
window_clear_echo_area ()
 
1249
window_clear_echo_area (void)
1222
1250
{
1223
1251
  free_echo_area ();
1224
1252
  display_update_one_window (the_echo_area);
1229
1257
   printf () hair is present.  The message appears immediately.  If there was
1230
1258
   already a message appearing in the echo area, it is removed. */
1231
1259
void
1232
 
window_message_in_echo_area (format, arg1, arg2)
1233
 
     char *format;
1234
 
     void *arg1, *arg2;
 
1260
window_message_in_echo_area (char *format, void *arg1, void *arg2)
1235
1261
{
1236
1262
  free_echo_area ();
1237
1263
  echo_area_node = build_message_node (format, arg1, arg2);
1248
1274
static int old_echo_area_nodes_slots = 0;
1249
1275
 
1250
1276
void
1251
 
message_in_echo_area (format, arg1, arg2)
1252
 
     char *format;
1253
 
     void *arg1, *arg2;
 
1277
message_in_echo_area (char *format, void *arg1, void *arg2)
1254
1278
{
1255
1279
  if (echo_area_node)
1256
1280
    {
1263
1287
}
1264
1288
 
1265
1289
void
1266
 
unmessage_in_echo_area ()
 
1290
unmessage_in_echo_area (void)
1267
1291
{
1268
1292
  free_echo_area ();
1269
1293
 
1282
1306
/* Ensure that there is enough space to stuff LENGTH characters into
1283
1307
   MESSAGE_BUFFER. */
1284
1308
static void
1285
 
message_buffer_resize (length)
1286
 
     int length;
 
1309
message_buffer_resize (int length)
1287
1310
{
1288
1311
  if (!message_buffer)
1289
1312
    {
1301
1324
/* Format MESSAGE_BUFFER with the results of printing FORMAT with ARG1 and
1302
1325
   ARG2. */
1303
1326
static void
1304
 
build_message_buffer (format, arg1, arg2, arg3)
1305
 
     char *format;
1306
 
     void *arg1, *arg2, *arg3;
 
1327
build_message_buffer (char *format, void *arg1, void *arg2, void *arg3)
1307
1328
{
1308
1329
  register int i, len;
1309
1330
  void *args[3];
1450
1471
/* Build a new node which has FORMAT printed with ARG1 and ARG2 as the
1451
1472
   contents. */
1452
1473
NODE *
1453
 
build_message_node (format, arg1, arg2)
1454
 
     char *format;
1455
 
     void *arg1, *arg2;
 
1474
build_message_node (char *format, void *arg1, void *arg2)
1456
1475
{
1457
1476
  NODE *node;
1458
1477
 
1465
1484
 
1466
1485
/* Convert the contents of the message buffer to a node. */
1467
1486
NODE *
1468
 
message_buffer_to_node ()
 
1487
message_buffer_to_node (void)
1469
1488
{
1470
1489
  NODE *node;
1471
1490
 
1487
1506
 
1488
1507
/* Useful functions can be called from outside of window.c. */
1489
1508
void
1490
 
initialize_message_buffer ()
 
1509
initialize_message_buffer (void)
1491
1510
{
1492
1511
  message_buffer_index = 0;
1493
1512
}
1494
1513
 
1495
1514
/* Print FORMAT with ARG1,2 to the end of the current message buffer. */
1496
1515
void
1497
 
printf_to_message_buffer (format, arg1, arg2, arg3)
1498
 
     char *format;
1499
 
     void *arg1, *arg2, *arg3;
 
1516
printf_to_message_buffer (char *format, void *arg1, void *arg2, void *arg3)
1500
1517
{
1501
1518
  build_message_buffer (format, arg1, arg2, arg3);
1502
1519
}
1504
1521
/* Return the current horizontal position of the "cursor" on the most
1505
1522
   recently output message buffer line. */
1506
1523
int
1507
 
message_buffer_length_this_line ()
 
1524
message_buffer_length_this_line (void)
1508
1525
{
1509
1526
  register int i;
1510
1527
 
1518
1535
 
1519
1536
/* Pad STRING to COUNT characters by inserting blanks. */
1520
1537
int
1521
 
pad_to (count, string)
1522
 
     int count;
1523
 
     char *string;
 
1538
pad_to (int count, char *string)
1524
1539
{
1525
1540
  register int i;
1526
1541