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

« back to all changes in this revision

Viewing changes to grub-core/gfxmenu/gui_canvas.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_canvas.c - GUI container allowing manually placed components. */
 
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
 
 
25
/* TODO Add layering so that components can be properly overlaid. */
 
26
 
 
27
struct component_node
 
28
{
 
29
  grub_gui_component_t component;
 
30
  struct component_node *next;
 
31
};
 
32
 
 
33
struct grub_gui_canvas
 
34
{
 
35
  struct grub_gui_container container;
 
36
 
 
37
  grub_gui_container_t parent;
 
38
  grub_video_rect_t bounds;
 
39
  char *id;
 
40
  /* Component list (dummy head node).  */
 
41
  struct component_node components;
 
42
};
 
43
 
 
44
typedef struct grub_gui_canvas *grub_gui_canvas_t;
 
45
 
 
46
static void
 
47
canvas_destroy (void *vself)
 
48
{
 
49
  grub_gui_canvas_t self = vself;
 
50
  struct component_node *cur;
 
51
  struct component_node *next;
 
52
  for (cur = self->components.next; cur; cur = next)
 
53
    {
 
54
      /* Copy the 'next' pointer, since we need it for the next iteration,
 
55
         and we're going to free the memory it is stored in.  */
 
56
      next = cur->next;
 
57
      /* Destroy the child component.  */
 
58
      cur->component->ops->destroy (cur->component);
 
59
      /* Free the linked list node.  */
 
60
      grub_free (cur);
 
61
    }
 
62
  grub_free (self);
 
63
}
 
64
 
 
65
static const char *
 
66
canvas_get_id (void *vself)
 
67
{
 
68
  grub_gui_canvas_t self = vself;
 
69
  return self->id;
 
70
}
 
71
 
 
72
static int
 
73
canvas_is_instance (void *vself __attribute__((unused)), const char *type)
 
74
{
 
75
  return (grub_strcmp (type, "component") == 0
 
76
          || grub_strcmp (type, "container") == 0);
 
77
}
 
78
 
 
79
static void
 
80
canvas_paint (void *vself, const grub_video_rect_t *region)
 
81
{
 
82
  grub_gui_canvas_t self = vself;
 
83
  struct component_node *cur;
 
84
  grub_video_rect_t vpsave;
 
85
 
 
86
  grub_gui_set_viewport (&self->bounds, &vpsave);
 
87
  for (cur = self->components.next; cur; cur = cur->next)
 
88
    {
 
89
      grub_video_rect_t r;
 
90
      grub_gui_component_t comp;
 
91
      signed x, y, w, h;
 
92
 
 
93
      comp = cur->component;
 
94
 
 
95
      w = grub_fixed_sfs_multiply (self->bounds.width, comp->wfrac) + comp->w;
 
96
      h = grub_fixed_sfs_multiply (self->bounds.height, comp->hfrac) + comp->h;
 
97
      x = grub_fixed_sfs_multiply (self->bounds.width, comp->xfrac) + comp->x;
 
98
      y = grub_fixed_sfs_multiply (self->bounds.height, comp->yfrac) + comp->y;
 
99
 
 
100
      if (comp->ops->get_minimal_size)
 
101
        {
 
102
          unsigned mw;
 
103
          unsigned mh;
 
104
          comp->ops->get_minimal_size (comp, &mw, &mh);
 
105
          if (w < (signed) mw)
 
106
            w = mw;
 
107
          if (h < (signed) mh)
 
108
            h = mh;
 
109
        }
 
110
 
 
111
      /* Sanity checks.  */
 
112
      if (w <= 0)
 
113
        w = 32;
 
114
      if (h <= 0)
 
115
        h = 32;
 
116
 
 
117
      if (x >= (signed) self->bounds.width)
 
118
        x = self->bounds.width - 32;
 
119
      if (y >= (signed) self->bounds.height)
 
120
        y = self->bounds.height - 32;
 
121
 
 
122
      if (x < 0)
 
123
        x = 0;
 
124
      if (y < 0)
 
125
        y = 0;
 
126
 
 
127
      if (x + w >= (signed) self->bounds.width)
 
128
        w = self->bounds.width - x;
 
129
      if (y + h >= (signed) self->bounds.height)
 
130
        h = self->bounds.height - y;
 
131
 
 
132
      r.x = x;
 
133
      r.y = y;
 
134
      r.width = w;
 
135
      r.height = h;
 
136
      comp->ops->set_bounds (comp, &r);
 
137
 
 
138
      /* Paint the child.  */
 
139
      if (grub_video_have_common_points (region, &r))
 
140
        comp->ops->paint (comp, region);
 
141
    }
 
142
  grub_gui_restore_viewport (&vpsave);
 
143
}
 
144
 
 
145
static void
 
146
canvas_set_parent (void *vself, grub_gui_container_t parent)
 
147
{
 
148
  grub_gui_canvas_t self = vself;
 
149
  self->parent = parent;
 
150
}
 
151
 
 
152
static grub_gui_container_t
 
153
canvas_get_parent (void *vself)
 
154
{
 
155
  grub_gui_canvas_t self = vself;
 
156
  return self->parent;
 
157
}
 
158
 
 
159
static void
 
160
canvas_set_bounds (void *vself, const grub_video_rect_t *bounds)
 
161
{
 
162
  grub_gui_canvas_t self = vself;
 
163
  self->bounds = *bounds;
 
164
}
 
165
 
 
166
static void
 
167
canvas_get_bounds (void *vself, grub_video_rect_t *bounds)
 
168
{
 
169
  grub_gui_canvas_t self = vself;
 
170
  *bounds = self->bounds;
 
171
}
 
172
 
 
173
static grub_err_t
 
174
canvas_set_property (void *vself, const char *name, const char *value)
 
175
{
 
176
  grub_gui_canvas_t self = vself;
 
177
  if (grub_strcmp (name, "id") == 0)
 
178
    {
 
179
      grub_free (self->id);
 
180
      if (value)
 
181
        {
 
182
          self->id = grub_strdup (value);
 
183
          if (! self->id)
 
184
            return grub_errno;
 
185
        }
 
186
      else
 
187
        self->id = 0;
 
188
    }
 
189
  return grub_errno;
 
190
}
 
191
 
 
192
static void
 
193
canvas_add (void *vself, grub_gui_component_t comp)
 
194
{
 
195
  grub_gui_canvas_t self = vself;
 
196
  struct component_node *node;
 
197
  node = grub_malloc (sizeof (*node));
 
198
  if (! node)
 
199
    return;   /* Note: probably should handle the error.  */
 
200
  node->component = comp;
 
201
  node->next = self->components.next;
 
202
  self->components.next = node;
 
203
  comp->ops->set_parent (comp, (grub_gui_container_t) self);
 
204
}
 
205
 
 
206
static void
 
207
canvas_remove (void *vself, grub_gui_component_t comp)
 
208
{
 
209
  grub_gui_canvas_t self = vself;
 
210
  struct component_node *cur;
 
211
  struct component_node *prev;
 
212
  prev = &self->components;
 
213
  for (cur = self->components.next; cur; prev = cur, cur = cur->next)
 
214
    {
 
215
      if (cur->component == comp)
 
216
        {
 
217
          /* Unlink 'cur' from the list.  */
 
218
          prev->next = cur->next;
 
219
          /* Free the node's memory (but don't destroy the component).  */
 
220
          grub_free (cur);
 
221
          /* Must not loop again, since 'cur' would be dereferenced!  */
 
222
          return;
 
223
        }
 
224
    }
 
225
}
 
226
 
 
227
static void
 
228
canvas_iterate_children (void *vself,
 
229
                         grub_gui_component_callback cb, void *userdata)
 
230
{
 
231
  grub_gui_canvas_t self = vself;
 
232
  struct component_node *cur;
 
233
  for (cur = self->components.next; cur; cur = cur->next)
 
234
    cb (cur->component, userdata);
 
235
}
 
236
 
 
237
static struct grub_gui_component_ops canvas_comp_ops =
 
238
{
 
239
  .destroy = canvas_destroy,
 
240
  .get_id = canvas_get_id,
 
241
  .is_instance = canvas_is_instance,
 
242
  .paint = canvas_paint,
 
243
  .set_parent = canvas_set_parent,
 
244
  .get_parent = canvas_get_parent,
 
245
  .set_bounds = canvas_set_bounds,
 
246
  .get_bounds = canvas_get_bounds,
 
247
  .set_property = canvas_set_property
 
248
};
 
249
 
 
250
static struct grub_gui_container_ops canvas_ops =
 
251
{
 
252
  .add = canvas_add,
 
253
  .remove = canvas_remove,
 
254
  .iterate_children = canvas_iterate_children
 
255
};
 
256
 
 
257
grub_gui_container_t
 
258
grub_gui_canvas_new (void)
 
259
{
 
260
  grub_gui_canvas_t canvas;
 
261
  canvas = grub_zalloc (sizeof (*canvas));
 
262
  if (! canvas)
 
263
    return 0;
 
264
  canvas->container.ops = &canvas_ops;
 
265
  canvas->container.component.ops = &canvas_comp_ops;
 
266
  return (grub_gui_container_t) canvas;
 
267
}