Embed/unembed the menu on state changes, keeping it around

cause some weird drawing issues.

Redraw on palette size changes (patch by Benzea).
This commit is contained in:
Marco Pesenti Gritti 2007-08-11 12:16:49 +02:00
parent a85bc85a82
commit dcef110223
4 changed files with 29 additions and 5 deletions

View File

@ -36,10 +36,21 @@ sugar_menu_set_active(SugarMenu *menu, gboolean active)
void
sugar_menu_embed(SugarMenu *menu, GtkContainer *parent)
{
menu->orig_toplevel = GTK_MENU(menu)->toplevel;
GTK_MENU(menu)->toplevel = gtk_widget_get_toplevel(GTK_WIDGET(parent));
gtk_widget_reparent(GTK_WIDGET(menu), GTK_WIDGET(parent));
}
void
sugar_menu_unembed(SugarMenu *menu)
{
if (menu->orig_toplevel) {
GTK_MENU(menu)->toplevel = menu->orig_toplevel;
gtk_widget_reparent(GTK_WIDGET(menu), GTK_WIDGET(menu->orig_toplevel));
}
}
static void
sugar_menu_class_init(SugarMenuClass *menu_class)
{
@ -48,4 +59,5 @@ sugar_menu_class_init(SugarMenuClass *menu_class)
static void
sugar_menu_init(SugarMenu *menu)
{
menu->orig_toplevel = NULL;
}

View File

@ -35,8 +35,9 @@ typedef struct _SugarMenuClass SugarMenuClass;
#define SUGAR_MENU_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_MENU, SugarMenuClass))
struct _SugarMenu {
GtkMenu base_instance;
GtkMenu base_instance;
GtkWidget *orig_toplevel;
int min_width;
};

View File

@ -44,6 +44,12 @@
)
)
(define-method unembed
(of-object "SugarMenu")
(c-name "sugar_menu_unembed")
(return-type "none")
)
;; From sugar-key-grabber.h
(define-function sugar_key_grabber_get_type

View File

@ -138,9 +138,9 @@ class Palette(gtk.Window):
self._separator = gtk.HSeparator()
self._secondary_box.pack_start(self._separator)
menu_box = gtk.VBox()
self._secondary_box.pack_start(menu_box)
menu_box.show()
self._menu_box = gtk.VBox()
self._secondary_box.pack_start(self._menu_box)
self._menu_box.show()
self._content = gtk.VBox()
self._secondary_box.pack_start(self._content)
@ -154,7 +154,6 @@ class Palette(gtk.Window):
vbox.show()
self.menu = _Menu(self)
self.menu.embed(menu_box)
self.menu.show()
self.connect('enter-notify-event',
@ -223,6 +222,10 @@ class Palette(gtk.Window):
else:
raise AssertionError
def do_size_allocate(self, allocation):
gtk.Window.do_size_allocate(self, allocation)
self.queue_draw()
def do_expose_event(self, event):
# We want to draw a border with a beautiful gap
if self._draw_gap:
@ -428,8 +431,10 @@ class Palette(gtk.Window):
return
if state == self._PRIMARY:
self.menu.unembed()
self._secondary_box.hide()
elif state == self._SECONDARY:
self.menu.embed(self._menu_box)
self._secondary_box.show()
self._state = state