[Libreoffice-commits] .: Branch 'feature/unitymenus' - vcl/inc vcl/source vcl/unx

Antonio Fernandez afernandez at kemper.freedesktop.org
Thu Aug 9 07:59:33 PDT 2012


 vcl/inc/vcl/menu.hxx              |   12 ++--
 vcl/source/window/menu.cxx        |    5 +
 vcl/unx/gtk/window/gtksalmenu.cxx |   97 +++++++++++++++-----------------------
 3 files changed, 50 insertions(+), 64 deletions(-)

New commits:
commit 17e0471b2a2bc15a6f20a26bd26c64404451e879
Author: Antonio Fernandez <antonio.fernandez at aentos.es>
Date:   Thu Aug 9 15:58:03 2012 +0100

    Most actions seem to work now. Enabled ImplSelectWithStart() for all builds.
    
    Change-Id: Ib309112de07d125fbe3b61ea20d5e26d1016912b

diff --git a/vcl/inc/vcl/menu.hxx b/vcl/inc/vcl/menu.hxx
index f98e87e..7538faf 100644
--- a/vcl/inc/vcl/menu.hxx
+++ b/vcl/inc/vcl/menu.hxx
@@ -298,11 +298,13 @@ public:
                             Menu();
                             Menu( sal_Bool bMenuBar );
     SAL_DLLPRIVATE Window*  ImplGetWindow() const { return pWindow; }
-#if defined(QUARTZ)
-    // ImplSelectWithStart() is used in vcl/aqua/source/window/salnsmenu.mm
-    SAL_DLLPRIVATE void ImplSelectWithStart( Menu* pStartMenu = NULL );
-#endif
-public:
+//#if defined(QUARTZ)
+//    // ImplSelectWithStart() is used in vcl/aqua/source/window/salnsmenu.mm
+//    SAL_DLLPRIVATE void ImplSelectWithStart( Menu* pStartMenu = NULL );
+//#endif
+    void ImplSelectWithStart( Menu* pStartMenu = NULL );
+
+    public:
     virtual             ~Menu();
 
     virtual void        Activate();
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 02fbe67..2361a18 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -1146,7 +1146,8 @@ void Menu::Select()
     }
 }
 
-#if defined(QUARTZ)
+// FIXME: Workaround to make GLOMenu without defining macros.
+//#if defined(QUARTZ)
 void Menu::ImplSelectWithStart( Menu* pSMenu )
 {
     Menu* pOldStartedFrom = pStartedFrom;
@@ -1157,7 +1158,7 @@ void Menu::ImplSelectWithStart( Menu* pSMenu )
         pOldStartedFrom->pStartedFrom = pOldStartedStarted;
     pStartedFrom = pOldStartedFrom;
 }
-#endif
+//#endif
 
 void Menu::RequestHelp( const HelpEvent& )
 {
diff --git a/vcl/unx/gtk/window/gtksalmenu.cxx b/vcl/unx/gtk/window/gtksalmenu.cxx
index a7a3ba6..4016a08 100644
--- a/vcl/unx/gtk/window/gtksalmenu.cxx
+++ b/vcl/unx/gtk/window/gtksalmenu.cxx
@@ -4,6 +4,8 @@
 //#include <gtk/gtk.h>
 #include <unx/gtk/glomenu.h>
 #include <unx/gtk/gloactiongroup.h>
+#include <vcl/menu.hxx>
+#include <unx/gtk/gtkinst.hxx>
 
 #include <iostream>
 
@@ -18,6 +20,7 @@ dispatchAction (GSimpleAction   *action,
                 gpointer        user_data)
 {
     cout << "ACTION: " << g_action_get_name( G_ACTION( action ) ) << " triggered." << endl;
+    GTK_YIELD_GRAB();
 
     if ( user_data ) {
         GtkSalMenuItem *pSalMenuItem = static_cast< GtkSalMenuItem* >( user_data );
@@ -25,20 +28,43 @@ dispatchAction (GSimpleAction   *action,
         if ( !pSalMenuItem->mpSubMenu ) {
             const GtkSalFrame *pFrame = pSalMenuItem->mpParentMenu ? pSalMenuItem->mpParentMenu->getFrame() : NULL;
 
-            if ( pFrame ) {
+            if ( pFrame && !pFrame->GetParent() ) {
                 ((PopupMenu*) pSalMenuItem->mpVCLMenu)->SetSelectedEntry( pSalMenuItem->mnId );
                 SalMenuEvent aMenuEvt( pSalMenuItem->mnId, pSalMenuItem->mpVCLMenu );
                 pFrame->CallCallback( SALEVENT_MENUCOMMAND, &aMenuEvt );
             }
+            else if ( pSalMenuItem->mpVCLMenu )
+            {
+                // if an item from submenu was selected. the corresponding Window does not exist because
+                // we use native popup menus, so we have to set the selected menuitem directly
+                // incidentally this of course works for top level popup menus, too
+                PopupMenu * pPopupMenu = dynamic_cast<PopupMenu *>(pSalMenuItem->mpVCLMenu);
+                if( pPopupMenu )
+                {
+                    // FIXME: revise this ugly code
+
+                    // select handlers in vcl are dispatch on the original menu
+                    // if not consumed by the select handler of the current menu
+                    // however since only the starting menu ever came into Execute
+                    // the hierarchy is not build up. Workaround this by getting
+                    // the menu it should have been
+
+                    // get started from hierarchy in vcl menus
+                    GtkSalMenu* pParentMenu = pSalMenuItem->mpParentMenu;
+                    Menu* pCurMenu = pSalMenuItem->mpVCLMenu;
+                    while( pParentMenu && pParentMenu->mpVCLMenu )
+                    {
+                        pCurMenu = pParentMenu->mpVCLMenu;
+                        pParentMenu = pParentMenu->mpParentSalMenu;
+                    }
+
+                    pPopupMenu->SetSelectedEntry( pSalMenuItem->mnId );
+                    pPopupMenu->ImplSelectWithStart( pCurMenu );
+                }
+                else
+                    OSL_FAIL( "menubar item without frame !" );
+            }
         }
-
-//        if ( !pSalMenuItem->mpSubMenu ) {
-//            if ( !pSalMenuItem->mpVCLMenu->IsMenuBar() ) {
-////                ((PopupMenu*) pSalMenuItem->mpVCLMenu)->SetSelectedEntry( pSalMenuItem->mnId );
-////                pSalMenuItem->mpVCLMenu->Select();
-////                pSalMenuItem->mpVCLMenu->DeSelect();
-//            }
-//        }
     }
 }
 
@@ -82,50 +108,6 @@ dispatchAction (GSimpleAction   *action,
 //    return G_MENU_MODEL( pMenuModel );
 //}
 
-GMenuModel *generateMockMenuModel()
-{
-//    GLOMenu *menu = g_lo_menu_new ();
-
-//    GLOMenu *fileMenu = g_lo_menu_new();
-//    GLOMenu *fileSubmenu = g_lo_menu_new ();
-//    g_lo_menu_append( fileSubmenu, "NewMenuOption1", NULL );
-//    g_lo_menu_append_submenu( fileMenu, "New", G_MENU_MODEL( fileSubmenu ) );
-//    g_lo_menu_append( fileMenu, "Quit", "app.quit" );
-
-//    GLOMenu *editMenu = g_lo_menu_new();
-//    GLOMenu *editSubmenu = g_lo_menu_new ();
-//    g_lo_menu_append( editSubmenu, "EditMenuOption1", NULL );
-//    g_lo_menu_append_item( editSubmenu, editMenuItem );
-//    g_lo_menu_append_submenu( editMenu, "Format", G_MENU_MODEL( editSubmenu ) );
-
-//    g_lo_menu_append_submenu( menu, "File", G_MENU_MODEL( fileMenu ) );
-//    g_lo_menu_append_submenu( menu, "Edit", G_MENU_MODEL( editMenu ) );
-
-    GMenu *menu = g_menu_new();
-
-    GMenu *fileMenu = g_menu_new();
-    GMenu *fileSubmenu = g_menu_new();
-    g_menu_append( fileSubmenu, "Text Document", "app.private:factory/swriter" );
-    g_menu_append_submenu( fileMenu, "New", G_MENU_MODEL( fileSubmenu ) );
-    g_menu_append( fileMenu, "Exit", "app..uno:Quit" );
-
-//    g_lo_menu_append_section( fileMenu, NULL, G_MENU_MODEL(submenu));
-//    GMenu *editMenu = g_menu_new();
-//    GMenu *editSubmenu = g_menu_new();
-//    g_menu_append( editSubmenu, "EditMenuOption1", "app.dispatch" );
-//    g_lo_menu_append_item( editSubmenu, editMenuItem );
-//    g_menu_append_submenu( editMenu, "Format", G_MENU_MODEL( editSubmenu ) );
-//    g_lo_menu_append( editMenu, "Quit", "app.quit" );
-
-
-    g_menu_append_submenu( menu, "File", G_MENU_MODEL( fileMenu ) );
-//    g_menu_append_submenu( menu, "Edit", G_MENU_MODEL( editMenu ) );
-
-//    g_menu_append_submenu( menu, "Test", G_MENU_MODEL( fileMenu ));
-
-
-    return G_MENU_MODEL( menu );
-}
 
 GMenuModel *generateMenuModelAndActions( GtkSalMenu*, GLOActionGroup* );
 
@@ -136,7 +118,7 @@ GMenuModel *generateSectionMenuModel( GtkSalMenuSection *pSection, GLOActionGrou
 
     GMenu *pSectionMenuModel = g_menu_new();
 
-    for (int i=0; i < pSection->maItems.size(); i++) {
+    for (sal_uInt16 i = 0; i < pSection->maItems.size(); i++) {
         GtkSalMenuItem *pSalMenuItem = pSection->maItems[ i ];
         GMenuItem *pMenuItem = pSalMenuItem->mpMenuItem;
 
@@ -162,7 +144,7 @@ GMenuModel *generateMenuModelAndActions( GtkSalMenu *pMenu, GLOActionGroup *pAct
 
     GMenu *pMenuModel = g_menu_new();
 
-    for (int i=0; i < pMenu->maItems.size(); i++) {
+    for (sal_uInt16 i = 0; i < pMenu->maItems.size(); i++) {
         GtkSalMenuItem *pSalMenuItem = pMenu->maItems[ i ];
         GMenuItem *pMenuItem = pSalMenuItem->mpMenuItem;
 
@@ -175,7 +157,7 @@ GMenuModel *generateMenuModelAndActions( GtkSalMenu *pMenu, GLOActionGroup *pAct
         g_lo_action_group_insert( pActionGroup, pSalMenuItem->mpAction );
     }
 
-    for (int i=0; i < pMenu->maSections.size(); i++) {
+    for (sal_uInt16 i = 0; i < pMenu->maSections.size(); i++) {
         GtkSalMenuSection *pSection = pMenu->maSections[ i ];
 
         GMenuModel *pSectionMenuModel = generateSectionMenuModel( pSection, pActionGroup );
@@ -233,6 +215,7 @@ void GtkSalMenu::publishMenu( GMenuModel *pMenu, GActionGroup *pActionGroup )
 GtkSalMenu::GtkSalMenu( sal_Bool bMenuBar ) :
     mbMenuBar( bMenuBar ),
     mpVCLMenu( NULL ),
+    mpFrame( NULL ),
     mpParentSalMenu( NULL ),
     aDBusMenubarPath( NULL ),
     pSessionBus( NULL ),
@@ -346,7 +329,7 @@ void GtkSalMenu::SetFrame( const SalFrame* pFrame )
     if (gdkWindow) {
         XLIB_Window windowId = GDK_WINDOW_XID( gdkWindow );
 
-        gchar *aWindowObjectPath = g_strdup_printf( "%s/window/%u", GTK_MENU_OBJ_PATH, windowId );
+        gchar *aWindowObjectPath = g_strdup_printf( "%s/window/%lu", GTK_MENU_OBJ_PATH, windowId );
         gchar *aMenubarObjectPath = g_strconcat( GTK_MENU_OBJ_PATH, "/menus/menubar", NULL );
 
 //        gdk_x11_window_set_utf8_property (gdkWindow, "_GTK_APPLICATION_ID", "org.libreoffice");


More information about the Libreoffice-commits mailing list