Re: gtk_menu_item_set_accel_path()

2018-02-11 Thread Christian Schoenebeck
On Donnerstag, 8. Februar 2018 20:21:52 CET Christian Schoenebeck wrote:
> Ok, the attached quick hack (on gtkmm3) fixed that issue for me. With that
> patch the acceleration keys are now correctly displayed again with gtkmm3.
> But obviously I have no idea whether the acceleration label was created
> explicitly there for some reason by gtkmm, whether it is still used by any
> Gtkmm subclass or something, or whether it was simply some left over of
> something.
> 
> I guess I just move this discussion onto the gtkmm list now.

JFYI: this issue is fixed now on gtkmm-3-22 branch (gtkmm3) and master branch 
(gtkmm4):

https://mail.gnome.org/archives/gtkmm-list/2018-February/msg7.html

CU
Christian
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: gtk_menu_item_set_accel_path()

2018-02-08 Thread Christian Schoenebeck
On Donnerstag, 8. Februar 2018 16:32:05 CET Christian Schoenebeck wrote:
> And in fact that C code works perfectly even with Gtk 3, but gtkmm3 is doing
> something differently than in above's C code: in the Gtk::MenuItem
> constructor they explicitly create an acceleration label for the menu item
> and I am not sure whether they should not do that, or whether gtk should
> rather be able to handle that:
> 
>   https://github.com/GNOME/gtkmm/blob/gtkmm-3-22/gtk/src/menuitem.ccg
>   (line 46 and line 51-61 being the relevant ones)
> 
> As far as I can read from the gtk sources, gtk automatically creates the
> menu item's acceleration label (even if no accelerators are used at all).
> But right now I cannot judge which side is wrong here (gtkmm3 or gtk3).

Ok, the attached quick hack (on gtkmm3) fixed that issue for me. With that 
patch the acceleration keys are now correctly displayed again with gtkmm3.
But obviously I have no idea whether the acceleration label was created 
explicitly there for some reason by gtkmm, whether it is still used by any 
Gtkmm subclass or something, or whether it was simply some left over of 
something.

I guess I just move this discussion onto the gtkmm list now.

CU
Christiandiff -ruN gtkmm-3-22.old/gtk/src/menuitem.ccg gtkmm-3-22.new/gtk/src/menuitem.ccg
--- gtkmm-3-22.old/gtk/src/menuitem.ccg	2018-02-08 20:09:55.0 +0100
+++ gtkmm-3-22.new/gtk/src/menuitem.ccg	2018-02-08 20:10:46.0 +0100
@@ -48,17 +48,9 @@
 
 void MenuItem::add_accel_label(const Glib::ustring& label, bool mnemonic)
 {
-  auto pLabel = manage(new AccelLabel(label, mnemonic));
-
-  //Labels are centered by default, but in menus they should be left-aligned.
-  pLabel->set_halign(ALIGN_START);
-
-  add(*pLabel);
-
-  //Note that we have to unset the accel_widget in  MenuList::remove() to avoid
-  //a memory leak due to the extra reference:
-  pLabel->set_accel_widget(*this);
-  pLabel->show();
+  GtkMenuItem* menu_item = (GtkMenuItem*) gobj();
+  gtk_menu_item_set_label(menu_item, label.c_str());
+  gtk_menu_item_set_use_underline(menu_item, mnemonic);
 }
 
 void MenuItem::set_accel_key(const AccelKey& accel_key)
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: gtk_menu_item_set_accel_path()

2018-02-08 Thread Christian Schoenebeck
On Donnerstag, 8. Februar 2018 12:17:06 CET Daniel Boles wrote:
> > are correctly updated with the expected textual representation of the
> > keyboard
> > accelerator key(s) (i.e. "Ctrl c", "F1", etc.), however the menu item's
> > GtkAccelLabel would never be displayed on screen.
> 
> I think we'd need to see precisely how you're setting up this MenuItem to
> do anything other than speculate wildly.

Hi Daniel,

first of all, the application code to reproduce this issue is actually gtkmm 
code and it is perfectly working with gtkmm2 & Gtk2. After investigating this 
a bit further, it seems to be a bug on gtkmm(3) level rather than on gtk(3) 
level, but I am not absolutely sure yet.

Here is the setup, first as gtkmm C++ code (followed by unwrapped gtk C code):

// MainWindow being subclass of Gtk::Window
MainWindow::MainWindow() {
...
// create a global keyboard acceleration entry for Shif+F1 and 
acceleration 
// path to be named "/bla"
Gtk::AccelMap::add_entry("/bla", GDK_KEY_F1, Gdk::SHIFT_MASK);

// actually creates (implied) a new acceleration group and assigns it 
to 
// window
Glib::RefPtr accelGroup = this->get_accel_group(); 

// assign newly created acceleration group to menu
menu->set_accel_group(accelGroup);

// add menu item to menu
Gtk::MenuItem* menuItem = new Gtk::MenuItem("Some text");
menu->append(menuItem);

// assign keyboard acceleration path to menu item
menuItem->set_accel_path("/bla");

// assign a callback as action when either menu item is clicked or 
// triggered by keyboard accelerator
menuItem->signal_activate().connect(
sigc::men_fun(*this, ::doSomething)
);
}

That gtkmm code still provides its expected base functionality with gtkmm3, 
that is the menu item's action is triggered correctly when the keyboard 
accelerator is used, but unlike with gtkmm2 the accelerator keys are no longer 
displayed in the menu with gtkmm3.

Now unwrapped as gtk C code it would look like this:

// create a global keyboard acceleration entry for Shif+F1 and 
acceleration 
// path to be named "/bla"
gtk_accel_map_add_entry("/bla", GDK_KEY_F1, GDK_SHIFT_MASK);

// create an acceleration group and assign it to main window and menu
GtkAccelGroup* accelGroup = gtk_accel_group_new();
gtk_window_add_accel_group(mainWindow, accelGroup);
gtk_menu_set_accel_group(menu, accelGroup);

// add menu item to menu
GtkWidget* menuItem = gtk_menu_item_new_with_label("Some text");
gtk_menu_shell_append(menu, menuItem);

// assign keyboard acceleration path to menu item
gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuItem), "/bla");

gtk_widget_show(menuItem);

// assign a callback as action when either menu item is clicked or 
// triggered by keyboard accelerator
g_signal_connect( G_OBJECT(menuItem), "activate",   

G_CALLBACK(doSomething), NULL );

And in fact that C code works perfectly even with Gtk 3, but gtkmm3 is doing 
something differently than in above's C code: in the Gtk::MenuItem constructor 
they explicitly create an acceleration label for the menu item and I am not 
sure whether they should not do that, or whether gtk should rather be able to 
handle that:

https://github.com/GNOME/gtkmm/blob/gtkmm-3-22/gtk/src/menuitem.ccg
(line 46 and line 51-61 being the relevant ones) 

As far as I can read from the gtk sources, gtk automatically creates the menu 
item's acceleration label (even if no accelerators are used at all). But right 
now I cannot judge which side is wrong here (gtkmm3 or gtk3).

> Isn't this a tautology? Why would the size be updated for an accelerator
> that is not being shown...?

Well, if I force a greater allocation size for the menu item, the accelerator 
is in fact displayed (even with gtkmm3 that is).

CU
Christian
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list