~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/gfxmenu/gui_list.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gui_list.c - GUI component to display a selectable list of items.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2008,2009  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <grub/mm.h>
 
21
#include <grub/misc.h>
 
22
#include <grub/gui.h>
 
23
#include <grub/gui_string_util.h>
 
24
#include <grub/gfxmenu_view.h>
 
25
#include <grub/gfxwidgets.h>
 
26
 
 
27
struct grub_gui_list_impl
 
28
{
 
29
  struct grub_gui_list list;
 
30
 
 
31
  grub_gui_container_t parent;
 
32
  grub_video_rect_t bounds;
 
33
  char *id;
 
34
  int visible;
 
35
 
 
36
  int icon_width;
 
37
  int icon_height;
 
38
  int item_height;
 
39
  int item_padding;
 
40
  int item_icon_space;
 
41
  int item_spacing;
 
42
  grub_font_t item_font;
 
43
  grub_font_t selected_item_font;
 
44
  grub_gui_color_t item_color;
 
45
  int selected_item_color_set;
 
46
  grub_gui_color_t selected_item_color;
 
47
 
 
48
  int draw_scrollbar;
 
49
  int need_to_recreate_scrollbar;
 
50
  char *scrollbar_frame_pattern;
 
51
  char *scrollbar_thumb_pattern;
 
52
  grub_gfxmenu_box_t scrollbar_frame;
 
53
  grub_gfxmenu_box_t scrollbar_thumb;
 
54
  int scrollbar_width;
 
55
 
 
56
  int first_shown_index;
 
57
 
 
58
  int need_to_recreate_boxes;
 
59
  char *theme_dir;
 
60
  char *menu_box_pattern;
 
61
  char *selected_item_box_pattern;
 
62
  grub_gfxmenu_box_t menu_box;
 
63
  grub_gfxmenu_box_t selected_item_box;
 
64
 
 
65
  grub_gfxmenu_icon_manager_t icon_manager;
 
66
 
 
67
  grub_gfxmenu_view_t view;
 
68
};
 
69
 
 
70
typedef struct grub_gui_list_impl *list_impl_t;
 
71
 
 
72
static void
 
73
list_destroy (void *vself)
 
74
{
 
75
  list_impl_t self = vself;
 
76
 
 
77
  grub_free (self->theme_dir);
 
78
  grub_free (self->menu_box_pattern);
 
79
  grub_free (self->selected_item_box_pattern);
 
80
  if (self->menu_box)
 
81
    self->menu_box->destroy (self->menu_box);
 
82
  if (self->selected_item_box)
 
83
    self->selected_item_box->destroy (self->selected_item_box);
 
84
  if (self->icon_manager)
 
85
    grub_gfxmenu_icon_manager_destroy (self->icon_manager);
 
86
 
 
87
  grub_free (self);
 
88
}
 
89
 
 
90
static int
 
91
get_num_shown_items (list_impl_t self)
 
92
{
 
93
  int boxpad = self->item_padding;
 
94
  int item_vspace = self->item_spacing;
 
95
  int item_height = self->item_height;
 
96
  
 
97
  grub_gfxmenu_box_t box = self->menu_box;
 
98
  int box_top_pad = box->get_top_pad (box);
 
99
  int box_bottom_pad = box->get_bottom_pad (box);
 
100
      
 
101
  return (self->bounds.height + item_vspace - 2 * boxpad
 
102
          - box_top_pad - box_bottom_pad) / (item_height + item_vspace);
 
103
}
 
104
 
 
105
static int
 
106
check_boxes (list_impl_t self)
 
107
{
 
108
  if (self->need_to_recreate_boxes)
 
109
    {
 
110
      grub_gui_recreate_box (&self->menu_box,
 
111
                             self->menu_box_pattern,
 
112
                             self->theme_dir);
 
113
 
 
114
      grub_gui_recreate_box (&self->selected_item_box,
 
115
                             self->selected_item_box_pattern,
 
116
                             self->theme_dir);
 
117
 
 
118
      self->need_to_recreate_boxes = 0;
 
119
    }
 
120
 
 
121
  return (self->menu_box != 0 && self->selected_item_box != 0);
 
122
}
 
123
 
 
124
static int
 
125
check_scrollbar (list_impl_t self)
 
126
{
 
127
  if (self->need_to_recreate_scrollbar)
 
128
    {
 
129
      grub_gui_recreate_box (&self->scrollbar_frame,
 
130
                             self->scrollbar_frame_pattern,
 
131
                             self->theme_dir);
 
132
 
 
133
      grub_gui_recreate_box (&self->scrollbar_thumb,
 
134
                             self->scrollbar_thumb_pattern,
 
135
                             self->theme_dir);
 
136
 
 
137
      self->need_to_recreate_scrollbar = 0;
 
138
    }
 
139
 
 
140
  return (self->scrollbar_frame != 0 && self->scrollbar_thumb != 0);
 
141
}
 
142
 
 
143
static const char *
 
144
list_get_id (void *vself)
 
145
{
 
146
  list_impl_t self = vself;
 
147
  return self->id;
 
148
}
 
149
 
 
150
static int
 
151
list_is_instance (void *vself __attribute__((unused)), const char *type)
 
152
{
 
153
  return (grub_strcmp (type, "component") == 0
 
154
          || grub_strcmp (type, "list") == 0);
 
155
}
 
156
 
 
157
static struct grub_video_bitmap *
 
158
get_item_icon (list_impl_t self, int item_index)
 
159
{
 
160
  grub_menu_entry_t entry;
 
161
  entry = grub_menu_get_entry (self->view->menu, item_index);
 
162
  if (! entry)
 
163
    return 0;
 
164
 
 
165
  return grub_gfxmenu_icon_manager_get_icon (self->icon_manager, entry);
 
166
}
 
167
 
 
168
static void
 
169
make_selected_item_visible (list_impl_t self)
 
170
{
 
171
  int selected_index = self->view->selected;
 
172
  if (selected_index < 0)
 
173
    return;   /* No item is selected.  */
 
174
  int num_shown_items = get_num_shown_items (self);
 
175
  int last_shown_index = self->first_shown_index + (num_shown_items - 1);
 
176
  if (selected_index < self->first_shown_index)
 
177
    self->first_shown_index = selected_index;
 
178
  else if (selected_index > last_shown_index)
 
179
    self->first_shown_index = selected_index - (num_shown_items - 1);
 
180
}
 
181
 
 
182
/* Draw a scrollbar on the menu.  */
 
183
static void
 
184
draw_scrollbar (list_impl_t self,
 
185
                int value, int extent, int min, int max,
 
186
                int rightx, int topy, int height)
 
187
{
 
188
  grub_gfxmenu_box_t frame = self->scrollbar_frame;
 
189
  grub_gfxmenu_box_t thumb = self->scrollbar_thumb;
 
190
  int frame_vertical_pad = (frame->get_top_pad (frame)
 
191
                            + frame->get_bottom_pad (frame));
 
192
  int frame_horizontal_pad = (frame->get_left_pad (frame)
 
193
                              + frame->get_right_pad (frame));
 
194
  int tracktop = topy + frame->get_top_pad (frame);
 
195
  int tracklen = height - frame_vertical_pad;
 
196
  frame->set_content_size (frame, self->scrollbar_width, tracklen);
 
197
  int thumby = tracktop + tracklen * (value - min) / (max - min);
 
198
  int thumbheight = tracklen * extent / (max - min) + 1;
 
199
  thumb->set_content_size (thumb,
 
200
                           self->scrollbar_width - frame_horizontal_pad,
 
201
                           thumbheight - (thumb->get_top_pad (thumb)
 
202
                                          + thumb->get_bottom_pad (thumb)));
 
203
  frame->draw (frame,
 
204
               rightx - (self->scrollbar_width + frame_horizontal_pad),
 
205
               topy);
 
206
  thumb->draw (thumb,
 
207
               rightx - (self->scrollbar_width - frame->get_right_pad (frame)),
 
208
               thumby);
 
209
}
 
210
 
 
211
/* Draw the list of items.  */
 
212
static void
 
213
draw_menu (list_impl_t self, int num_shown_items)
 
214
{
 
215
  if (! self->menu_box || ! self->selected_item_box)
 
216
    return;
 
217
 
 
218
  int boxpad = self->item_padding;
 
219
  int icon_text_space = self->item_icon_space;
 
220
  int item_vspace = self->item_spacing;
 
221
 
 
222
  int ascent = grub_font_get_ascent (self->item_font);
 
223
  int descent = grub_font_get_descent (self->item_font);
 
224
  int item_height = self->item_height;
 
225
 
 
226
  make_selected_item_visible (self);
 
227
 
 
228
  grub_gfxmenu_box_t selbox = self->selected_item_box;
 
229
  int sel_leftpad = selbox->get_left_pad (selbox);
 
230
  int sel_toppad = selbox->get_top_pad (selbox);
 
231
  int item_top = sel_toppad;
 
232
  int menu_index;
 
233
  int visible_index;
 
234
  struct grub_video_rect oviewport;
 
235
 
 
236
  grub_video_get_viewport (&oviewport.x, &oviewport.y,
 
237
                           &oviewport.width, &oviewport.height);
 
238
  grub_video_set_viewport (oviewport.x + boxpad, 
 
239
                           oviewport.y + boxpad,
 
240
                           oviewport.width - 2 * boxpad,
 
241
                           oviewport.height - 2 * boxpad);
 
242
 
 
243
  for (visible_index = 0, menu_index = self->first_shown_index;
 
244
       visible_index < num_shown_items && menu_index < self->view->menu->size;
 
245
       visible_index++, menu_index++)
 
246
    {
 
247
      int is_selected = (menu_index == self->view->selected);
 
248
 
 
249
      if (is_selected)
 
250
        {
 
251
          selbox->set_content_size (selbox, oviewport.width - 2 * boxpad - 2,
 
252
                                    item_height - 1);
 
253
          selbox->draw (selbox, 0,
 
254
                        item_top - sel_toppad);
 
255
        }
 
256
 
 
257
      struct grub_video_bitmap *icon;
 
258
      if ((icon = get_item_icon (self, menu_index)) != 0)
 
259
        grub_video_blit_bitmap (icon, GRUB_VIDEO_BLIT_BLEND,
 
260
                                sel_leftpad,
 
261
                                item_top + (item_height - self->icon_height) / 2,
 
262
                                0, 0, self->icon_width, self->icon_height);
 
263
 
 
264
      const char *item_title =
 
265
        grub_menu_get_entry (self->view->menu, menu_index)->title;
 
266
      grub_font_t font =
 
267
        (is_selected && self->selected_item_font
 
268
         ? self->selected_item_font
 
269
         : self->item_font);
 
270
      grub_gui_color_t text_color =
 
271
        ((is_selected && self->selected_item_color_set)
 
272
         ? self->selected_item_color
 
273
         : self->item_color);
 
274
      grub_font_draw_string (item_title,
 
275
                             font,
 
276
                             grub_gui_map_color (text_color),
 
277
                             sel_leftpad + self->icon_width + icon_text_space,
 
278
                             (item_top + (item_height - (ascent + descent))
 
279
                              / 2 + ascent));
 
280
 
 
281
      item_top += item_height + item_vspace;
 
282
    }
 
283
  grub_video_set_viewport (oviewport.x,
 
284
                           oviewport.y,
 
285
                           oviewport.width,
 
286
                           oviewport.height);
 
287
}
 
288
 
 
289
static void
 
290
list_paint (void *vself, const grub_video_rect_t *region)
 
291
{
 
292
  list_impl_t self = vself;
 
293
  grub_video_rect_t vpsave;
 
294
 
 
295
  if (! self->visible)
 
296
    return;
 
297
  if (!grub_video_have_common_points (region, &self->bounds))
 
298
    return;
 
299
 
 
300
  check_boxes (self);
 
301
 
 
302
  if (! self->menu_box || ! self->selected_item_box)
 
303
    return;
 
304
 
 
305
  grub_gui_set_viewport (&self->bounds, &vpsave);
 
306
  {
 
307
    grub_gfxmenu_box_t box = self->menu_box;
 
308
    int box_left_pad = box->get_left_pad (box);
 
309
    int box_top_pad = box->get_top_pad (box);
 
310
    int box_right_pad = box->get_right_pad (box);
 
311
    int box_bottom_pad = box->get_bottom_pad (box);
 
312
    grub_video_rect_t vpsave2, content_rect;
 
313
    int num_shown_items = get_num_shown_items (self);
 
314
    int drawing_scrollbar = (self->draw_scrollbar
 
315
                             && (num_shown_items < self->view->menu->size)
 
316
                             && check_scrollbar (self));
 
317
 
 
318
    content_rect.x = box_left_pad;
 
319
    content_rect.y = box_top_pad;
 
320
    content_rect.width = self->bounds.width - box_left_pad - box_right_pad;
 
321
    content_rect.height = self->bounds.height - box_top_pad - box_bottom_pad;
 
322
 
 
323
    box->set_content_size (box, content_rect.width, content_rect.height);
 
324
 
 
325
    box->draw (box, 0, 0);
 
326
 
 
327
    grub_gui_set_viewport (&content_rect, &vpsave2);
 
328
    draw_menu (self, num_shown_items);
 
329
    grub_gui_restore_viewport (&vpsave2);
 
330
 
 
331
    if (drawing_scrollbar)
 
332
      draw_scrollbar (self,
 
333
                      self->first_shown_index, num_shown_items,
 
334
                      0, self->view->menu->size,
 
335
                      self->bounds.width - box_right_pad
 
336
                      + self->scrollbar_width,
 
337
                      box_top_pad,
 
338
                      self->bounds.height - box_top_pad - box_bottom_pad);
 
339
  }
 
340
 
 
341
  grub_gui_restore_viewport (&vpsave);
 
342
}
 
343
 
 
344
static void
 
345
list_set_parent (void *vself, grub_gui_container_t parent)
 
346
{
 
347
  list_impl_t self = vself;
 
348
  self->parent = parent;
 
349
}
 
350
 
 
351
static grub_gui_container_t
 
352
list_get_parent (void *vself)
 
353
{
 
354
  list_impl_t self = vself;
 
355
  return self->parent;
 
356
}
 
357
 
 
358
static void
 
359
list_set_bounds (void *vself, const grub_video_rect_t *bounds)
 
360
{
 
361
  list_impl_t self = vself;
 
362
  self->bounds = *bounds;
 
363
}
 
364
 
 
365
static void
 
366
list_get_bounds (void *vself, grub_video_rect_t *bounds)
 
367
{
 
368
  list_impl_t self = vself;
 
369
  *bounds = self->bounds;
 
370
}
 
371
 
 
372
static void
 
373
list_get_minimal_size (void *vself, unsigned *width, unsigned *height)
 
374
{
 
375
  list_impl_t self = vself;
 
376
 
 
377
  if (check_boxes (self))
 
378
    {
 
379
      int boxpad = self->item_padding;
 
380
      int item_vspace = self->item_spacing;
 
381
      int item_height = self->item_height;
 
382
      int num_items = 3;
 
383
 
 
384
      grub_gfxmenu_box_t box = self->menu_box;
 
385
      int box_left_pad = box->get_left_pad (box);
 
386
      int box_top_pad = box->get_top_pad (box);
 
387
      int box_right_pad = box->get_right_pad (box);
 
388
      int box_bottom_pad = box->get_bottom_pad (box);
 
389
      unsigned width_s;
 
390
 
 
391
      grub_gfxmenu_box_t selbox = self->selected_item_box;
 
392
      int sel_toppad = selbox->get_top_pad (selbox);
 
393
      
 
394
      *width = grub_font_get_string_width (self->item_font, "Typical OS");
 
395
      width_s = grub_font_get_string_width (self->selected_item_font,
 
396
                                            "Typical OS");
 
397
      if (*width < width_s)
 
398
        *width = width_s;
 
399
 
 
400
      *width += 2 * boxpad + box_left_pad + box_right_pad;
 
401
 
 
402
      /* Set the menu box height to fit the items.  */
 
403
      *height = (item_height * num_items
 
404
                 + item_vspace * (num_items - 1)
 
405
                 + 2 * boxpad
 
406
                 + box_top_pad + box_bottom_pad + sel_toppad);
 
407
    }
 
408
  else
 
409
    {
 
410
      *width = 0;
 
411
      *height = 0;
 
412
    }
 
413
}
 
414
 
 
415
static grub_err_t
 
416
list_set_property (void *vself, const char *name, const char *value)
 
417
{
 
418
  list_impl_t self = vself;
 
419
  if (grub_strcmp (name, "item_font") == 0)
 
420
    {
 
421
      self->item_font = grub_font_get (value);
 
422
    }
 
423
  else if (grub_strcmp (name, "selected_item_font") == 0)
 
424
    {
 
425
      if (! value || grub_strcmp (value, "inherit") == 0)
 
426
        self->selected_item_font = 0;
 
427
      else
 
428
        self->selected_item_font = grub_font_get (value);
 
429
    }
 
430
  else if (grub_strcmp (name, "item_color") == 0)
 
431
    {
 
432
      grub_gui_parse_color (value, &self->item_color);
 
433
    }
 
434
  else if (grub_strcmp (name, "selected_item_color") == 0)
 
435
    {
 
436
      if (! value || grub_strcmp (value, "inherit") == 0)
 
437
        {
 
438
          self->selected_item_color_set = 0;
 
439
        }
 
440
      else
 
441
        {
 
442
          if (grub_gui_parse_color (value, &self->selected_item_color)
 
443
              == GRUB_ERR_NONE)
 
444
            self->selected_item_color_set = 1;
 
445
        }
 
446
    }
 
447
  else if (grub_strcmp (name, "icon_width") == 0)
 
448
    {
 
449
      self->icon_width = grub_strtol (value, 0, 10);
 
450
      grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
 
451
                                               self->icon_width,
 
452
                                               self->icon_height);
 
453
    }
 
454
  else if (grub_strcmp (name, "icon_height") == 0)
 
455
    {
 
456
      self->icon_height = grub_strtol (value, 0, 10);
 
457
      grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
 
458
                                               self->icon_width,
 
459
                                               self->icon_height);
 
460
    }
 
461
  else if (grub_strcmp (name, "item_height") == 0)
 
462
    {
 
463
      self->item_height = grub_strtol (value, 0, 10);
 
464
    }
 
465
  else if (grub_strcmp (name, "item_padding") == 0)
 
466
    {
 
467
      self->item_padding = grub_strtol (value, 0, 10);
 
468
    }
 
469
  else if (grub_strcmp (name, "item_icon_space") == 0)
 
470
    {
 
471
      self->item_icon_space = grub_strtol (value, 0, 10);
 
472
    }
 
473
  else if (grub_strcmp (name, "item_spacing") == 0)
 
474
    {
 
475
      self->item_spacing = grub_strtol (value, 0, 10);
 
476
    }
 
477
  else if (grub_strcmp (name, "visible") == 0)
 
478
    {
 
479
      self->visible = grub_strcmp (value, "false") != 0;
 
480
    }
 
481
  else if (grub_strcmp (name, "menu_pixmap_style") == 0)
 
482
    {
 
483
      self->need_to_recreate_boxes = 1;
 
484
      grub_free (self->menu_box_pattern);
 
485
      self->menu_box_pattern = value ? grub_strdup (value) : 0;
 
486
    }
 
487
  else if (grub_strcmp (name, "selected_item_pixmap_style") == 0)
 
488
    {
 
489
      self->need_to_recreate_boxes = 1;
 
490
      grub_free (self->selected_item_box_pattern);
 
491
      self->selected_item_box_pattern = value ? grub_strdup (value) : 0;
 
492
    }
 
493
  else if (grub_strcmp (name, "scrollbar_frame") == 0)
 
494
    {
 
495
      self->need_to_recreate_scrollbar = 1;
 
496
      grub_free (self->scrollbar_frame_pattern);
 
497
      self->scrollbar_frame_pattern = value ? grub_strdup (value) : 0;
 
498
    }
 
499
  else if (grub_strcmp (name, "scrollbar_thumb") == 0)
 
500
    {
 
501
      self->need_to_recreate_scrollbar = 1;
 
502
      grub_free (self->scrollbar_thumb_pattern);
 
503
      self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0;
 
504
    }
 
505
  else if (grub_strcmp (name, "scrollbar_width") == 0)
 
506
    {
 
507
      self->scrollbar_width = grub_strtol (value, 0, 10);
 
508
    }
 
509
  else if (grub_strcmp (name, "scrollbar") == 0)
 
510
    {
 
511
      self->draw_scrollbar = grub_strcmp (value, "false") != 0;
 
512
    }
 
513
  else if (grub_strcmp (name, "theme_dir") == 0)
 
514
    {
 
515
      self->need_to_recreate_boxes = 1;
 
516
      grub_free (self->theme_dir);
 
517
      self->theme_dir = value ? grub_strdup (value) : 0;
 
518
    }
 
519
  else if (grub_strcmp (name, "id") == 0)
 
520
    {
 
521
      grub_free (self->id);
 
522
      if (value)
 
523
        self->id = grub_strdup (value);
 
524
      else
 
525
        self->id = 0;
 
526
    }
 
527
  return grub_errno;
 
528
}
 
529
 
 
530
/* Set necessary information that the gfxmenu view provides.  */
 
531
static void
 
532
list_set_view_info (void *vself,
 
533
                    grub_gfxmenu_view_t view)
 
534
{
 
535
  list_impl_t self = vself;
 
536
  grub_gfxmenu_icon_manager_set_theme_path (self->icon_manager,
 
537
                                            view->theme_path);
 
538
  self->view = view;
 
539
}
 
540
 
 
541
static struct grub_gui_component_ops list_comp_ops =
 
542
  {
 
543
    .destroy = list_destroy,
 
544
    .get_id = list_get_id,
 
545
    .is_instance = list_is_instance,
 
546
    .paint = list_paint,
 
547
    .set_parent = list_set_parent,
 
548
    .get_parent = list_get_parent,
 
549
    .set_bounds = list_set_bounds,
 
550
    .get_bounds = list_get_bounds,
 
551
    .get_minimal_size = list_get_minimal_size,
 
552
    .set_property = list_set_property
 
553
  };
 
554
 
 
555
static struct grub_gui_list_ops list_ops =
 
556
{
 
557
  .set_view_info = list_set_view_info
 
558
};
 
559
 
 
560
grub_gui_component_t
 
561
grub_gui_list_new (void)
 
562
{
 
563
  list_impl_t self;
 
564
  grub_font_t default_font;
 
565
  grub_gui_color_t default_fg_color;
 
566
 
 
567
  self = grub_zalloc (sizeof (*self));
 
568
  if (! self)
 
569
    return 0;
 
570
 
 
571
  self->list.ops = &list_ops;
 
572
  self->list.component.ops = &list_comp_ops;
 
573
 
 
574
  self->visible = 1;
 
575
 
 
576
  default_font = grub_font_get ("Unknown Regular 16");
 
577
  default_fg_color = grub_gui_color_rgb (0, 0, 0);
 
578
 
 
579
  self->icon_width = 32;
 
580
  self->icon_height = 32;
 
581
  self->item_height = 42;
 
582
  self->item_padding = 14;
 
583
  self->item_icon_space = 4;
 
584
  self->item_spacing = 16;
 
585
  self->item_font = default_font;
 
586
  self->selected_item_font = 0;    /* Default to using the item_font.  */
 
587
  self->item_color = default_fg_color;
 
588
  self->selected_item_color_set = 0;  /* Default to using the item_color.  */
 
589
  self->selected_item_color = default_fg_color;
 
590
 
 
591
  self->draw_scrollbar = 1;
 
592
  self->need_to_recreate_scrollbar = 1;
 
593
  self->scrollbar_frame = 0;
 
594
  self->scrollbar_thumb = 0;
 
595
  self->scrollbar_frame_pattern = 0;
 
596
  self->scrollbar_thumb_pattern = 0;
 
597
  self->scrollbar_width = 16;
 
598
 
 
599
  self->first_shown_index = 0;
 
600
 
 
601
  self->need_to_recreate_boxes = 0;
 
602
  self->theme_dir = 0;
 
603
  self->menu_box_pattern = 0;
 
604
  self->selected_item_box_pattern = 0;
 
605
  self->menu_box = grub_gfxmenu_create_box (0, 0);
 
606
  self->selected_item_box = grub_gfxmenu_create_box (0, 0);
 
607
 
 
608
  self->icon_manager = grub_gfxmenu_icon_manager_new ();
 
609
  if (! self->icon_manager)
 
610
    {
 
611
      self->list.component.ops->destroy (self);
 
612
      return 0;
 
613
    }
 
614
  grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
 
615
                                           self->icon_width,
 
616
                                           self->icon_height);
 
617
  return (grub_gui_component_t) self;
 
618
}