~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to normal/menu_text.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
  struct grub_term_output *term;
39
39
};
40
40
 
41
 
static void
42
 
print_spaces (int number_spaces, struct grub_term_output *term)
43
 
{
44
 
  int i;
45
 
  for (i = 0; i < number_spaces; i++)
46
 
    grub_putcode (' ', term);
47
 
}
48
 
 
49
 
void
50
 
grub_print_ucs4 (const grub_uint32_t * str,
51
 
                 const grub_uint32_t * last_position,
52
 
                 struct grub_term_output *term)
53
 
{
54
 
  while (str < last_position)
55
 
    {
56
 
      grub_putcode (*str, term);
57
 
      str++;
58
 
    }
59
 
}
60
 
 
61
41
grub_ssize_t
62
42
grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position,
63
43
                     struct grub_term_output *term)
66
46
 
67
47
  while (str < last_position)
68
48
    {
69
 
      width += grub_term_getcharwidth (term, *str);
70
 
      str++;
 
49
      struct grub_unicode_glyph glyph;
 
50
      str += grub_unicode_aglomerate_comb (str, last_position - str, &glyph);
 
51
      width += grub_term_getcharwidth (term, &glyph);
71
52
    }
72
53
  return width;
73
54
}
76
57
grub_print_message_indented (const char *msg, int margin_left, int margin_right,
77
58
                             struct grub_term_output *term)
78
59
{
79
 
  int line_len;
80
 
 
81
60
  grub_uint32_t *unicode_msg;
82
61
  grub_uint32_t *last_position;
83
62
 
84
63
  int msg_len;
85
64
 
86
 
  line_len = grub_term_width (term) - grub_term_getcharwidth (term, 'm') *
87
 
    (margin_left + margin_right);
88
 
 
89
65
  msg_len = grub_utf8_to_ucs4_alloc (msg, &unicode_msg, &last_position);
90
66
 
91
67
  if (msg_len < 0)
93
69
      return;
94
70
    }
95
71
 
96
 
  grub_uint32_t *current_position = unicode_msg;
97
 
 
98
 
  grub_uint32_t *next_new_line = unicode_msg;
99
 
 
100
 
  int first_loop = 1;
101
 
 
102
 
  while (current_position < last_position)
103
 
    {
104
 
      if (! first_loop)
105
 
        grub_putcode ('\n', term);
106
 
     
107
 
      next_new_line = (grub_uint32_t *) last_position;
108
 
 
109
 
      while (grub_getstringwidth (current_position, next_new_line,term) 
110
 
             > line_len
111
 
            || (next_new_line != last_position && *next_new_line != ' '
112
 
                && next_new_line > current_position))
113
 
       {
114
 
         next_new_line--;
115
 
       }
116
 
 
117
 
      if (next_new_line == current_position)
118
 
       {
119
 
         next_new_line = (next_new_line + line_len > last_position) ?
120
 
           (grub_uint32_t *) last_position : next_new_line + line_len;
121
 
       }
122
 
 
123
 
      print_spaces (margin_left, term);
124
 
      grub_print_ucs4 (current_position, next_new_line, term);
125
 
 
126
 
      next_new_line++;
127
 
      current_position = next_new_line;
128
 
      first_loop = 0;
129
 
    }
 
72
  grub_print_ucs4 (unicode_msg, last_position, margin_left, margin_right, term);
 
73
 
130
74
  grub_free (unicode_msg);
131
75
}
132
76
 
139
83
  grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
140
84
 
141
85
  grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y);
142
 
  grub_putcode (GRUB_TERM_DISP_UL, term);
 
86
  grub_putcode (GRUB_UNICODE_CORNER_UL, term);
143
87
  for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
144
 
    grub_putcode (GRUB_TERM_DISP_HLINE, term);
145
 
  grub_putcode (GRUB_TERM_DISP_UR, term);
 
88
    grub_putcode (GRUB_UNICODE_HLINE, term);
 
89
  grub_putcode (GRUB_UNICODE_CORNER_UR, term);
146
90
 
147
91
  for (i = 0; i < (unsigned) grub_term_num_entries (term); i++)
148
92
    {
149
93
      grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
150
 
      grub_putcode (GRUB_TERM_DISP_VLINE, term);
 
94
      grub_putcode (GRUB_UNICODE_VLINE, term);
151
95
      grub_term_gotoxy (term, GRUB_TERM_MARGIN + grub_term_border_width (term)
152
96
                        - 1,
153
97
                        GRUB_TERM_TOP_BORDER_Y + i + 1);
154
 
      grub_putcode (GRUB_TERM_DISP_VLINE, term);
 
98
      grub_putcode (GRUB_UNICODE_VLINE, term);
155
99
    }
156
100
 
157
101
  grub_term_gotoxy (term, GRUB_TERM_MARGIN,
158
102
                    GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + 1);
159
 
  grub_putcode (GRUB_TERM_DISP_LL, term);
 
103
  grub_putcode (GRUB_UNICODE_CORNER_LL, term);
160
104
  for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
161
 
    grub_putcode (GRUB_TERM_DISP_HLINE, term);
162
 
  grub_putcode (GRUB_TERM_DISP_LR, term);
 
105
    grub_putcode (GRUB_UNICODE_HLINE, term);
 
106
  grub_putcode (GRUB_UNICODE_CORNER_LR, term);
163
107
 
164
108
  grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
165
109
 
194
138
                          "entry is highlighted.\n");
195
139
      char *msg_translated;
196
140
 
197
 
      msg_translated = grub_xasprintf (msg, (grub_uint32_t) GRUB_TERM_DISP_UP,
198
 
                                     (grub_uint32_t) GRUB_TERM_DISP_DOWN);
 
141
      msg_translated = grub_xasprintf (msg, GRUB_UNICODE_UPARROW,
 
142
                                       GRUB_UNICODE_DOWNARROW);
199
143
      if (!msg_translated)
200
144
        return;
201
 
      grub_putchar ('\n');
 
145
      grub_putcode ('\n', term);
202
146
      grub_print_message_indented (msg_translated, STANDARD_MARGIN,
203
147
                                   STANDARD_MARGIN, term);
204
148
 
259
203
 
260
204
  grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
261
205
 
 
206
  int last_printed = 0;
262
207
  for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
263
208
       x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
264
 
                  - GRUB_TERM_MARGIN);
265
 
       i++)
 
209
                  - GRUB_TERM_MARGIN);)
266
210
    {
267
211
      if (i < len
268
212
          && x <= (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
269
213
                         - GRUB_TERM_MARGIN - 1))
270
214
        {
271
215
          grub_ssize_t width;
272
 
 
273
 
          width = grub_term_getcharwidth (term, unicode_title[i]);
274
 
 
275
 
          if (x + width > (int) (GRUB_TERM_LEFT_BORDER_X 
 
216
          struct grub_unicode_glyph glyph;
 
217
 
 
218
          i += grub_unicode_aglomerate_comb (unicode_title + i,
 
219
                                             len - i, &glyph);
 
220
 
 
221
          width = grub_term_getcharwidth (term, &glyph);
 
222
          grub_free (glyph.combining);
 
223
 
 
224
          if (x + width <= (int) (GRUB_TERM_LEFT_BORDER_X 
276
225
                                 + grub_term_border_width (term)
277
226
                                 - GRUB_TERM_MARGIN - 1))
278
 
            grub_putcode (GRUB_TERM_DISP_RIGHT, term);
279
 
          else
280
 
            grub_putcode (unicode_title[i], term);
281
 
 
 
227
            last_printed = i;
282
228
          x += width;
283
229
        }
284
230
      else
285
 
        {
286
 
          grub_putcode (' ', term);
287
 
          x++;
288
 
        }
289
 
    }
 
231
        break;
 
232
    }
 
233
 
 
234
  grub_print_ucs4 (unicode_title,
 
235
                   unicode_title + last_printed, 0, 0, term);
 
236
 
 
237
  if (last_printed != len)
 
238
    {
 
239
      grub_putcode (GRUB_UNICODE_RIGHTARROW, term);
 
240
      struct grub_unicode_glyph pseudo_glyph = {
 
241
        .base = GRUB_UNICODE_RIGHTARROW,
 
242
        .variant = 0,
 
243
        .attributes = 0,
 
244
        .ncomb = 0,
 
245
        .combining = 0,
 
246
        .estimated_width = 1
 
247
      };
 
248
      x += grub_term_getcharwidth (term, &pseudo_glyph);
 
249
    }
 
250
 
 
251
  for (; x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
 
252
                    - GRUB_TERM_MARGIN); x++)
 
253
    grub_putcode (' ', term);
 
254
 
290
255
  grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
291
256
  grub_putcode (' ', term);
292
257
 
309
274
                    GRUB_TERM_FIRST_ENTRY_Y);
310
275
 
311
276
  if (first)
312
 
    grub_putcode (GRUB_TERM_DISP_UP, term);
 
277
    grub_putcode (GRUB_UNICODE_UPARROW, term);
313
278
  else
314
279
    grub_putcode (' ', term);
315
280
 
327
292
                    GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term));
328
293
 
329
294
  if (e)
330
 
    grub_putcode (GRUB_TERM_DISP_DOWN, term);
 
295
    grub_putcode (GRUB_UNICODE_DOWNARROW, term);
331
296
  else
332
297
    grub_putcode (' ', term);
333
298
 
385
350
  grub_print_message_indented (msg_translated, 3, 0, data->term);
386
351
 
387
352
  posx = grub_term_getxy (data->term) >> 8;
388
 
  print_spaces (grub_term_width (data->term) - posx - 1, data->term);
 
353
  grub_print_spaces (data->term, grub_term_width (data->term) - posx - 1);
389
354
 
390
355
  grub_term_gotoxy (data->term,
391
356
                    grub_term_cursor_x (data->term),
443
408
  struct menu_viewer_data *data = dataptr;
444
409
 
445
410
  grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3);
446
 
  print_spaces (grub_term_width (data->term) - 1, data->term);
 
411
  grub_print_spaces (data->term, grub_term_width (data->term) - 1);
447
412
  grub_term_gotoxy (data->term, grub_term_cursor_x (data->term),
448
413
                    GRUB_TERM_FIRST_ENTRY_Y + data->offset);
449
414
  grub_term_refresh (data->term);