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

« back to all changes in this revision

Viewing changes to 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 width, int drawing_scrollbar,
214
 
           int num_shown_items)
215
 
{
216
 
  if (! self->menu_box || ! self->selected_item_box)
217
 
    return;
218
 
 
219
 
  int boxpad = self->item_padding;
220
 
  int icon_text_space = self->item_icon_space;
221
 
  int item_vspace = self->item_spacing;
222
 
 
223
 
  int ascent = grub_font_get_ascent (self->item_font);
224
 
  int descent = grub_font_get_descent (self->item_font);
225
 
  int item_height = self->item_height;
226
 
 
227
 
  make_selected_item_visible (self);
228
 
 
229
 
  int scrollbar_h_space = drawing_scrollbar ? self->scrollbar_width : 0;
230
 
 
231
 
  grub_gfxmenu_box_t selbox = self->selected_item_box;
232
 
  int sel_leftpad = selbox->get_left_pad (selbox);
233
 
  int item_top = boxpad;
234
 
  int item_left = boxpad + sel_leftpad;
235
 
  int menu_index;
236
 
  int visible_index;
237
 
 
238
 
  for (visible_index = 0, menu_index = self->first_shown_index;
239
 
       visible_index < num_shown_items && menu_index < self->view->menu->size;
240
 
       visible_index++, menu_index++)
241
 
    {
242
 
      int is_selected = (menu_index == self->view->selected);
243
 
 
244
 
      if (is_selected)
245
 
        {
246
 
          int sel_toppad = selbox->get_top_pad (selbox);
247
 
          selbox->set_content_size (selbox,
248
 
                                    (width - 2 * boxpad
249
 
                                     - scrollbar_h_space),
250
 
                                    item_height);
251
 
          selbox->draw (selbox,
252
 
                        item_left - sel_leftpad,
253
 
                        item_top - sel_toppad);
254
 
        }
255
 
 
256
 
      struct grub_video_bitmap *icon;
257
 
      if ((icon = get_item_icon (self, menu_index)) != 0)
258
 
        grub_video_blit_bitmap (icon, GRUB_VIDEO_BLIT_BLEND,
259
 
                                item_left,
260
 
                                item_top + (item_height - self->icon_height) / 2,
261
 
                                0, 0, self->icon_width, self->icon_height);
262
 
 
263
 
      const char *item_title =
264
 
        grub_menu_get_entry (self->view->menu, menu_index)->title;
265
 
      grub_font_t font =
266
 
        (is_selected && self->selected_item_font
267
 
         ? self->selected_item_font
268
 
         : self->item_font);
269
 
      grub_gui_color_t text_color =
270
 
        ((is_selected && self->selected_item_color_set)
271
 
         ? self->selected_item_color
272
 
         : self->item_color);
273
 
      grub_font_draw_string (item_title,
274
 
                             font,
275
 
                             grub_gui_map_color (text_color),
276
 
                             item_left + self->icon_width + icon_text_space,
277
 
                             (item_top + (item_height - (ascent + descent))
278
 
                              / 2 + ascent));
279
 
 
280
 
      item_top += item_height + item_vspace;
281
 
    }
282
 
}
283
 
 
284
 
static void
285
 
list_paint (void *vself, const grub_video_rect_t *region)
286
 
{
287
 
  list_impl_t self = vself;
288
 
  grub_video_rect_t vpsave;
289
 
 
290
 
  if (! self->visible)
291
 
    return;
292
 
  if (!grub_video_have_common_points (region, &self->bounds))
293
 
    return;
294
 
 
295
 
  check_boxes (self);
296
 
 
297
 
  if (! self->menu_box || ! self->selected_item_box)
298
 
    return;
299
 
 
300
 
  grub_gui_set_viewport (&self->bounds, &vpsave);
301
 
  {
302
 
    grub_gfxmenu_box_t box = self->menu_box;
303
 
    int box_left_pad = box->get_left_pad (box);
304
 
    int box_top_pad = box->get_top_pad (box);
305
 
    int box_right_pad = box->get_right_pad (box);
306
 
    int box_bottom_pad = box->get_bottom_pad (box);
307
 
    grub_video_rect_t vpsave2, content_rect;
308
 
    int num_shown_items = get_num_shown_items (self);
309
 
    int drawing_scrollbar = (self->draw_scrollbar
310
 
                             && (num_shown_items < self->view->menu->size)
311
 
                             && check_scrollbar (self));
312
 
 
313
 
    content_rect.x = box_left_pad;
314
 
    content_rect.y = box_top_pad;
315
 
    content_rect.width = self->bounds.width - box_left_pad - box_right_pad;
316
 
    content_rect.height = self->bounds.height - box_top_pad - box_bottom_pad;
317
 
 
318
 
    box->set_content_size (box, content_rect.width, content_rect.height);
319
 
 
320
 
    box->draw (box, 0, 0);
321
 
 
322
 
    grub_gui_set_viewport (&content_rect, &vpsave2);
323
 
    draw_menu (self, content_rect.width, drawing_scrollbar, num_shown_items);
324
 
    grub_gui_restore_viewport (&vpsave2);
325
 
 
326
 
    if (drawing_scrollbar)
327
 
      draw_scrollbar (self,
328
 
                      self->first_shown_index, num_shown_items,
329
 
                      0, self->view->menu->size,
330
 
                      self->bounds.width - box_right_pad
331
 
                      + self->scrollbar_width,
332
 
                      box_top_pad + self->item_padding,
333
 
                      self->bounds.height - box_top_pad - box_bottom_pad);
334
 
  }
335
 
 
336
 
  grub_gui_restore_viewport (&vpsave);
337
 
}
338
 
 
339
 
static void
340
 
list_set_parent (void *vself, grub_gui_container_t parent)
341
 
{
342
 
  list_impl_t self = vself;
343
 
  self->parent = parent;
344
 
}
345
 
 
346
 
static grub_gui_container_t
347
 
list_get_parent (void *vself)
348
 
{
349
 
  list_impl_t self = vself;
350
 
  return self->parent;
351
 
}
352
 
 
353
 
static void
354
 
list_set_bounds (void *vself, const grub_video_rect_t *bounds)
355
 
{
356
 
  list_impl_t self = vself;
357
 
  self->bounds = *bounds;
358
 
}
359
 
 
360
 
static void
361
 
list_get_bounds (void *vself, grub_video_rect_t *bounds)
362
 
{
363
 
  list_impl_t self = vself;
364
 
  *bounds = self->bounds;
365
 
}
366
 
 
367
 
static void
368
 
list_get_minimal_size (void *vself, unsigned *width, unsigned *height)
369
 
{
370
 
  list_impl_t self = vself;
371
 
 
372
 
  if (check_boxes (self))
373
 
    {
374
 
      int boxpad = self->item_padding;
375
 
      int item_vspace = self->item_spacing;
376
 
      int item_height = self->item_height;
377
 
      int num_items = 3;
378
 
 
379
 
      grub_gfxmenu_box_t box = self->menu_box;
380
 
      int box_left_pad = box->get_left_pad (box);
381
 
      int box_top_pad = box->get_top_pad (box);
382
 
      int box_right_pad = box->get_right_pad (box);
383
 
      int box_bottom_pad = box->get_bottom_pad (box);
384
 
      unsigned width_s;
385
 
      
386
 
      *width = grub_font_get_string_width (self->item_font, "Typical OS");
387
 
      width_s = grub_font_get_string_width (self->selected_item_font,
388
 
                                            "Typical OS");
389
 
      if (*width < width_s)
390
 
        *width = width_s;
391
 
 
392
 
      *width += 2 * boxpad + box_left_pad + box_right_pad;
393
 
 
394
 
      /* Set the menu box height to fit the items.  */
395
 
      *height = (item_height * num_items
396
 
                 + item_vspace * (num_items - 1)
397
 
                 + 2 * boxpad
398
 
                 + box_top_pad + box_bottom_pad);
399
 
    }
400
 
  else
401
 
    {
402
 
      *width = 0;
403
 
      *height = 0;
404
 
    }
405
 
}
406
 
 
407
 
static grub_err_t
408
 
list_set_property (void *vself, const char *name, const char *value)
409
 
{
410
 
  list_impl_t self = vself;
411
 
  if (grub_strcmp (name, "item_font") == 0)
412
 
    {
413
 
      self->item_font = grub_font_get (value);
414
 
    }
415
 
  else if (grub_strcmp (name, "selected_item_font") == 0)
416
 
    {
417
 
      if (! value || grub_strcmp (value, "inherit") == 0)
418
 
        self->selected_item_font = 0;
419
 
      else
420
 
        self->selected_item_font = grub_font_get (value);
421
 
    }
422
 
  else if (grub_strcmp (name, "item_color") == 0)
423
 
    {
424
 
      grub_gui_parse_color (value, &self->item_color);
425
 
    }
426
 
  else if (grub_strcmp (name, "selected_item_color") == 0)
427
 
    {
428
 
      if (! value || grub_strcmp (value, "inherit") == 0)
429
 
        {
430
 
          self->selected_item_color_set = 0;
431
 
        }
432
 
      else
433
 
        {
434
 
          if (grub_gui_parse_color (value, &self->selected_item_color)
435
 
              == GRUB_ERR_NONE)
436
 
            self->selected_item_color_set = 1;
437
 
        }
438
 
    }
439
 
  else if (grub_strcmp (name, "icon_width") == 0)
440
 
    {
441
 
      self->icon_width = grub_strtol (value, 0, 10);
442
 
      grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
443
 
                                               self->icon_width,
444
 
                                               self->icon_height);
445
 
    }
446
 
  else if (grub_strcmp (name, "icon_height") == 0)
447
 
    {
448
 
      self->icon_height = grub_strtol (value, 0, 10);
449
 
      grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
450
 
                                               self->icon_width,
451
 
                                               self->icon_height);
452
 
    }
453
 
  else if (grub_strcmp (name, "item_height") == 0)
454
 
    {
455
 
      self->item_height = grub_strtol (value, 0, 10);
456
 
    }
457
 
  else if (grub_strcmp (name, "item_padding") == 0)
458
 
    {
459
 
      self->item_padding = grub_strtol (value, 0, 10);
460
 
    }
461
 
  else if (grub_strcmp (name, "item_icon_space") == 0)
462
 
    {
463
 
      self->item_icon_space = grub_strtol (value, 0, 10);
464
 
    }
465
 
  else if (grub_strcmp (name, "item_spacing") == 0)
466
 
    {
467
 
      self->item_spacing = grub_strtol (value, 0, 10);
468
 
    }
469
 
  else if (grub_strcmp (name, "visible") == 0)
470
 
    {
471
 
      self->visible = grub_strcmp (value, "false") != 0;
472
 
    }
473
 
  else if (grub_strcmp (name, "menu_pixmap_style") == 0)
474
 
    {
475
 
      self->need_to_recreate_boxes = 1;
476
 
      grub_free (self->menu_box_pattern);
477
 
      self->menu_box_pattern = value ? grub_strdup (value) : 0;
478
 
    }
479
 
  else if (grub_strcmp (name, "selected_item_pixmap_style") == 0)
480
 
    {
481
 
      self->need_to_recreate_boxes = 1;
482
 
      grub_free (self->selected_item_box_pattern);
483
 
      self->selected_item_box_pattern = value ? grub_strdup (value) : 0;
484
 
    }
485
 
  else if (grub_strcmp (name, "scrollbar_frame") == 0)
486
 
    {
487
 
      self->need_to_recreate_scrollbar = 1;
488
 
      grub_free (self->scrollbar_frame_pattern);
489
 
      self->scrollbar_frame_pattern = value ? grub_strdup (value) : 0;
490
 
    }
491
 
  else if (grub_strcmp (name, "scrollbar_thumb") == 0)
492
 
    {
493
 
      self->need_to_recreate_scrollbar = 1;
494
 
      grub_free (self->scrollbar_thumb_pattern);
495
 
      self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0;
496
 
    }
497
 
  else if (grub_strcmp (name, "scrollbar_width") == 0)
498
 
    {
499
 
      self->scrollbar_width = grub_strtol (value, 0, 10);
500
 
    }
501
 
  else if (grub_strcmp (name, "scrollbar") == 0)
502
 
    {
503
 
      self->draw_scrollbar = grub_strcmp (value, "false") != 0;
504
 
    }
505
 
  else if (grub_strcmp (name, "theme_dir") == 0)
506
 
    {
507
 
      self->need_to_recreate_boxes = 1;
508
 
      grub_free (self->theme_dir);
509
 
      self->theme_dir = value ? grub_strdup (value) : 0;
510
 
    }
511
 
  else if (grub_strcmp (name, "id") == 0)
512
 
    {
513
 
      grub_free (self->id);
514
 
      if (value)
515
 
        self->id = grub_strdup (value);
516
 
      else
517
 
        self->id = 0;
518
 
    }
519
 
  return grub_errno;
520
 
}
521
 
 
522
 
/* Set necessary information that the gfxmenu view provides.  */
523
 
static void
524
 
list_set_view_info (void *vself,
525
 
                    grub_gfxmenu_view_t view)
526
 
{
527
 
  list_impl_t self = vself;
528
 
  grub_gfxmenu_icon_manager_set_theme_path (self->icon_manager,
529
 
                                            view->theme_path);
530
 
  self->view = view;
531
 
}
532
 
 
533
 
static struct grub_gui_component_ops list_comp_ops =
534
 
  {
535
 
    .destroy = list_destroy,
536
 
    .get_id = list_get_id,
537
 
    .is_instance = list_is_instance,
538
 
    .paint = list_paint,
539
 
    .set_parent = list_set_parent,
540
 
    .get_parent = list_get_parent,
541
 
    .set_bounds = list_set_bounds,
542
 
    .get_bounds = list_get_bounds,
543
 
    .get_minimal_size = list_get_minimal_size,
544
 
    .set_property = list_set_property
545
 
  };
546
 
 
547
 
static struct grub_gui_list_ops list_ops =
548
 
{
549
 
  .set_view_info = list_set_view_info
550
 
};
551
 
 
552
 
grub_gui_component_t
553
 
grub_gui_list_new (void)
554
 
{
555
 
  list_impl_t self;
556
 
  grub_font_t default_font;
557
 
  grub_gui_color_t default_fg_color;
558
 
  grub_gui_color_t default_bg_color;
559
 
 
560
 
  self = grub_zalloc (sizeof (*self));
561
 
  if (! self)
562
 
    return 0;
563
 
 
564
 
  self->list.ops = &list_ops;
565
 
  self->list.component.ops = &list_comp_ops;
566
 
 
567
 
  self->visible = 1;
568
 
 
569
 
  default_font = grub_font_get ("Helvetica 12");
570
 
  default_fg_color = grub_gui_color_rgb (0, 0, 0);
571
 
  default_bg_color = grub_gui_color_rgb (255, 255, 255);
572
 
 
573
 
  self->icon_width = 32;
574
 
  self->icon_height = 32;
575
 
  self->item_height = 42;
576
 
  self->item_padding = 14;
577
 
  self->item_icon_space = 4;
578
 
  self->item_spacing = 16;
579
 
  self->item_font = default_font;
580
 
  self->selected_item_font = 0;    /* Default to using the item_font.  */
581
 
  self->item_color = default_fg_color;
582
 
  self->selected_item_color_set = 0;  /* Default to using the item_color.  */
583
 
  self->selected_item_color = default_fg_color;
584
 
 
585
 
  self->draw_scrollbar = 1;
586
 
  self->need_to_recreate_scrollbar = 1;
587
 
  self->scrollbar_frame = 0;
588
 
  self->scrollbar_thumb = 0;
589
 
  self->scrollbar_frame_pattern = 0;
590
 
  self->scrollbar_thumb_pattern = 0;
591
 
  self->scrollbar_width = 16;
592
 
 
593
 
  self->first_shown_index = 0;
594
 
 
595
 
  self->need_to_recreate_boxes = 0;
596
 
  self->theme_dir = 0;
597
 
  self->menu_box_pattern = 0;
598
 
  self->selected_item_box_pattern = 0;
599
 
  self->menu_box = grub_gfxmenu_create_box (0, 0);
600
 
  self->selected_item_box = grub_gfxmenu_create_box (0, 0);
601
 
 
602
 
  self->icon_manager = grub_gfxmenu_icon_manager_new ();
603
 
  if (! self->icon_manager)
604
 
    {
605
 
      self->list.component.ops->destroy (self);
606
 
      return 0;
607
 
    }
608
 
  grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
609
 
                                           self->icon_width,
610
 
                                           self->icon_height);
611
 
  return (grub_gui_component_t) self;
612
 
}