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:
parent
a85bc85a82
commit
dcef110223
@ -36,10 +36,21 @@ sugar_menu_set_active(SugarMenu *menu, gboolean active)
|
|||||||
void
|
void
|
||||||
sugar_menu_embed(SugarMenu *menu, GtkContainer *parent)
|
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_MENU(menu)->toplevel = gtk_widget_get_toplevel(GTK_WIDGET(parent));
|
||||||
gtk_widget_reparent(GTK_WIDGET(menu), 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
|
static void
|
||||||
sugar_menu_class_init(SugarMenuClass *menu_class)
|
sugar_menu_class_init(SugarMenuClass *menu_class)
|
||||||
{
|
{
|
||||||
@ -48,4 +59,5 @@ sugar_menu_class_init(SugarMenuClass *menu_class)
|
|||||||
static void
|
static void
|
||||||
sugar_menu_init(SugarMenu *menu)
|
sugar_menu_init(SugarMenu *menu)
|
||||||
{
|
{
|
||||||
|
menu->orig_toplevel = NULL;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ typedef struct _SugarMenuClass SugarMenuClass;
|
|||||||
struct _SugarMenu {
|
struct _SugarMenu {
|
||||||
GtkMenu base_instance;
|
GtkMenu base_instance;
|
||||||
|
|
||||||
|
GtkWidget *orig_toplevel;
|
||||||
int min_width;
|
int min_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(define-method unembed
|
||||||
|
(of-object "SugarMenu")
|
||||||
|
(c-name "sugar_menu_unembed")
|
||||||
|
(return-type "none")
|
||||||
|
)
|
||||||
|
|
||||||
;; From sugar-key-grabber.h
|
;; From sugar-key-grabber.h
|
||||||
|
|
||||||
(define-function sugar_key_grabber_get_type
|
(define-function sugar_key_grabber_get_type
|
||||||
|
@ -138,9 +138,9 @@ class Palette(gtk.Window):
|
|||||||
self._separator = gtk.HSeparator()
|
self._separator = gtk.HSeparator()
|
||||||
self._secondary_box.pack_start(self._separator)
|
self._secondary_box.pack_start(self._separator)
|
||||||
|
|
||||||
menu_box = gtk.VBox()
|
self._menu_box = gtk.VBox()
|
||||||
self._secondary_box.pack_start(menu_box)
|
self._secondary_box.pack_start(self._menu_box)
|
||||||
menu_box.show()
|
self._menu_box.show()
|
||||||
|
|
||||||
self._content = gtk.VBox()
|
self._content = gtk.VBox()
|
||||||
self._secondary_box.pack_start(self._content)
|
self._secondary_box.pack_start(self._content)
|
||||||
@ -154,7 +154,6 @@ class Palette(gtk.Window):
|
|||||||
vbox.show()
|
vbox.show()
|
||||||
|
|
||||||
self.menu = _Menu(self)
|
self.menu = _Menu(self)
|
||||||
self.menu.embed(menu_box)
|
|
||||||
self.menu.show()
|
self.menu.show()
|
||||||
|
|
||||||
self.connect('enter-notify-event',
|
self.connect('enter-notify-event',
|
||||||
@ -223,6 +222,10 @@ class Palette(gtk.Window):
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
def do_size_allocate(self, allocation):
|
||||||
|
gtk.Window.do_size_allocate(self, allocation)
|
||||||
|
self.queue_draw()
|
||||||
|
|
||||||
def do_expose_event(self, event):
|
def do_expose_event(self, event):
|
||||||
# We want to draw a border with a beautiful gap
|
# We want to draw a border with a beautiful gap
|
||||||
if self._draw_gap:
|
if self._draw_gap:
|
||||||
@ -428,8 +431,10 @@ class Palette(gtk.Window):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if state == self._PRIMARY:
|
if state == self._PRIMARY:
|
||||||
|
self.menu.unembed()
|
||||||
self._secondary_box.hide()
|
self._secondary_box.hide()
|
||||||
elif state == self._SECONDARY:
|
elif state == self._SECONDARY:
|
||||||
|
self.menu.embed(self._menu_box)
|
||||||
self._secondary_box.show()
|
self._secondary_box.show()
|
||||||
|
|
||||||
self._state = state
|
self._state = state
|
||||||
|
Loading…
Reference in New Issue
Block a user