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

« back to all changes in this revision

Viewing changes to gfxmenu/gui_label.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gui_label.c - GUI component to display a line of text.  */
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/font.h>
24
 
#include <grub/gui_string_util.h>
25
 
 
26
 
static const char *align_options[] =
27
 
{
28
 
  "left",
29
 
  "center",
30
 
  "right",
31
 
  0
32
 
};
33
 
 
34
 
enum align_mode {
35
 
  align_left,
36
 
  align_center,
37
 
  align_right
38
 
};
39
 
 
40
 
struct grub_gui_label
41
 
{
42
 
  struct grub_gui_component comp;
43
 
 
44
 
  grub_gui_container_t parent;
45
 
  grub_video_rect_t bounds;
46
 
  char *id;
47
 
  int visible;
48
 
  char *text;
49
 
  char *template;
50
 
  grub_font_t font;
51
 
  grub_gui_color_t color;
52
 
  int value;
53
 
  enum align_mode align;
54
 
};
55
 
 
56
 
typedef struct grub_gui_label *grub_gui_label_t;
57
 
 
58
 
static void
59
 
label_destroy (void *vself)
60
 
{
61
 
  grub_gui_label_t self = vself;
62
 
  grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
63
 
  grub_free (self->text);
64
 
  grub_free (self->template);
65
 
  grub_free (self);
66
 
}
67
 
 
68
 
static const char *
69
 
label_get_id (void *vself)
70
 
{
71
 
  grub_gui_label_t self = vself;
72
 
  return self->id;
73
 
}
74
 
 
75
 
static int
76
 
label_is_instance (void *vself __attribute__((unused)), const char *type)
77
 
{
78
 
  return grub_strcmp (type, "component") == 0;
79
 
}
80
 
 
81
 
static void
82
 
label_paint (void *vself, const grub_video_rect_t *region)
83
 
{
84
 
  grub_gui_label_t self = vself;
85
 
 
86
 
  if (! self->visible)
87
 
    return;
88
 
 
89
 
  if (!grub_video_have_common_points (region, &self->bounds))
90
 
    return;
91
 
 
92
 
  /* Calculate the starting x coordinate.  */
93
 
  int left_x;
94
 
  if (self->align == align_left)
95
 
    left_x = 0;
96
 
  else if (self->align == align_center)
97
 
    left_x = ((self->bounds.width
98
 
               - grub_font_get_string_width (self->font, self->text))
99
 
             ) / 2;
100
 
  else if (self->align == align_right)
101
 
    left_x = (self->bounds.width
102
 
              - grub_font_get_string_width (self->font, self->text));
103
 
  else
104
 
    return;   /* Invalid alignment.  */
105
 
 
106
 
  grub_video_rect_t vpsave;
107
 
  grub_gui_set_viewport (&self->bounds, &vpsave);
108
 
  grub_font_draw_string (self->text,
109
 
                         self->font,
110
 
                         grub_gui_map_color (self->color),
111
 
                         left_x,
112
 
                         grub_font_get_ascent (self->font));
113
 
  grub_gui_restore_viewport (&vpsave);
114
 
}
115
 
 
116
 
static void
117
 
label_set_parent (void *vself, grub_gui_container_t parent)
118
 
{
119
 
  grub_gui_label_t self = vself;
120
 
  self->parent = parent;
121
 
}
122
 
 
123
 
static grub_gui_container_t
124
 
label_get_parent (void *vself)
125
 
{
126
 
  grub_gui_label_t self = vself;
127
 
  return self->parent;
128
 
}
129
 
 
130
 
static void
131
 
label_set_bounds (void *vself, const grub_video_rect_t *bounds)
132
 
{
133
 
  grub_gui_label_t self = vself;
134
 
  self->bounds = *bounds;
135
 
}
136
 
 
137
 
static void
138
 
label_get_bounds (void *vself, grub_video_rect_t *bounds)
139
 
{
140
 
  grub_gui_label_t self = vself;
141
 
  *bounds = self->bounds;
142
 
}
143
 
 
144
 
static void
145
 
label_get_minimal_size (void *vself, unsigned *width, unsigned *height)
146
 
{
147
 
  grub_gui_label_t self = vself;
148
 
  *width = grub_font_get_string_width (self->font, self->text);
149
 
  *height = (grub_font_get_ascent (self->font)
150
 
             + grub_font_get_descent (self->font));
151
 
}
152
 
 
153
 
static void
154
 
label_set_state (void *vself, int visible, int start __attribute__ ((unused)),
155
 
                 int current, int end __attribute__ ((unused)))
156
 
{
157
 
  grub_gui_label_t self = vself;  
158
 
  self->value = -current;
159
 
  self->visible = visible;
160
 
  grub_free (self->text);
161
 
  self->text = grub_xasprintf (self->template ? : "%d", self->value);
162
 
}
163
 
 
164
 
static grub_err_t
165
 
label_set_property (void *vself, const char *name, const char *value)
166
 
{
167
 
  grub_gui_label_t self = vself;
168
 
  if (grub_strcmp (name, "text") == 0)
169
 
    {
170
 
      grub_free (self->text);
171
 
      grub_free (self->template);
172
 
      if (! value)
173
 
        {
174
 
          self->template = NULL;
175
 
          self->text = grub_strdup ("");
176
 
        }
177
 
      else
178
 
        {
179
 
          self->template = grub_strdup (value);
180
 
          self->text = grub_xasprintf (value, self->value);
181
 
        }
182
 
    }
183
 
  else if (grub_strcmp (name, "font") == 0)
184
 
    {
185
 
      self->font = grub_font_get (value);
186
 
    }
187
 
  else if (grub_strcmp (name, "color") == 0)
188
 
    {
189
 
      grub_gui_parse_color (value, &self->color);
190
 
    }
191
 
  else if (grub_strcmp (name, "align") == 0)
192
 
    {
193
 
      int i;
194
 
      for (i = 0; align_options[i]; i++)
195
 
        {
196
 
          if (grub_strcmp (align_options[i], value) == 0)
197
 
            {
198
 
              self->align = i;   /* Set the alignment mode.  */
199
 
              break;
200
 
            }
201
 
        }
202
 
    }
203
 
  else if (grub_strcmp (name, "visible") == 0)
204
 
    {
205
 
      self->visible = grub_strcmp (value, "false") != 0;
206
 
    }
207
 
  else if (grub_strcmp (name, "id") == 0)
208
 
    {
209
 
      grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
210
 
      grub_free (self->id);
211
 
      if (value)
212
 
        self->id = grub_strdup (value);
213
 
      else
214
 
        self->id = 0;
215
 
      if (self->id && grub_strcmp (self->id, GRUB_GFXMENU_TIMEOUT_COMPONENT_ID)
216
 
          == 0)
217
 
        grub_gfxmenu_timeout_register ((grub_gui_component_t) self,
218
 
                                       label_set_state);
219
 
    }
220
 
  return GRUB_ERR_NONE;
221
 
}
222
 
 
223
 
static struct grub_gui_component_ops label_ops =
224
 
{
225
 
  .destroy = label_destroy,
226
 
  .get_id = label_get_id,
227
 
  .is_instance = label_is_instance,
228
 
  .paint = label_paint,
229
 
  .set_parent = label_set_parent,
230
 
  .get_parent = label_get_parent,
231
 
  .set_bounds = label_set_bounds,
232
 
  .get_bounds = label_get_bounds,
233
 
  .get_minimal_size = label_get_minimal_size,
234
 
  .set_property = label_set_property
235
 
};
236
 
 
237
 
grub_gui_component_t
238
 
grub_gui_label_new (void)
239
 
{
240
 
  grub_gui_label_t label;
241
 
  label = grub_zalloc (sizeof (*label));
242
 
  if (! label)
243
 
    return 0;
244
 
  label->comp.ops = &label_ops;
245
 
  label->visible = 1;
246
 
  label->text = grub_strdup ("");
247
 
  label->font = grub_font_get ("Unknown Regular 16");
248
 
  label->color.red = 0;
249
 
  label->color.green = 0;
250
 
  label->color.blue = 0;
251
 
  label->color.alpha = 255;
252
 
  label->align = align_left;
253
 
  return (grub_gui_component_t) label;
254
 
}