src/gui/widgets/qmenu_symbian.cpp
changeset 7 f7bc934e204c
parent 0 1918ee327afb
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the S60 port of the Qt Toolkit.
     7 ** This file is part of the S60 port of the Qt Toolkit.
     8 **
     8 **
    79 static QList<SymbianMenuItem*> symbianMenus;
    79 static QList<SymbianMenuItem*> symbianMenus;
    80 static QList<QMenuBar*> nativeMenuBars;
    80 static QList<QMenuBar*> nativeMenuBars;
    81 static uint qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM;
    81 static uint qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM;
    82 static QPointer<QWidget> widgetWithContextMenu;
    82 static QPointer<QWidget> widgetWithContextMenu;
    83 static QList<QAction*> contextMenuActionList;
    83 static QList<QAction*> contextMenuActionList;
       
    84 static QWidget* actionMenu = NULL;
    84 static int contexMenuCommand=0;
    85 static int contexMenuCommand=0;
    85 
    86 
    86 bool menuExists()
    87 bool menuExists()
    87 {
    88 {
    88     QWidget *w = qApp->activeWindow();
    89     QWidget *w = qApp->activeWindow();
   222         mb->symbian_menubar->rebuild();
   223         mb->symbian_menubar->rebuild();
   223     }
   224     }
   224 }
   225 }
   225 
   226 
   226 #ifdef Q_WS_S60
   227 #ifdef Q_WS_S60
       
   228 void qt_symbian_next_menu_from_action(QWidget *actionContainer)
       
   229 {
       
   230     actionMenu = actionContainer;
       
   231 }
       
   232 
   227 void qt_symbian_show_toplevel( CEikMenuPane* menuPane)
   233 void qt_symbian_show_toplevel( CEikMenuPane* menuPane)
   228 {
   234 {
       
   235     if (actionMenu) {
       
   236         QMenuBarPrivate *mb = 0;
       
   237         mb = menubars()->value(actionMenu);
       
   238         qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM;
       
   239         deleteAll( &symbianMenus );
       
   240         Q_ASSERT(mb);
       
   241         mb->symbian_menubar->rebuild();
       
   242         for (int i = 0; i < symbianMenus.count(); ++i)
       
   243             QT_TRAP_THROWING(menuPane->AddMenuItemL(symbianMenus.at(i)->menuItemData));
       
   244         actionMenu = NULL;
       
   245         return;
       
   246     }
       
   247 
   229     if (!menuExists())
   248     if (!menuExists())
   230         return;
   249         return;
   231     rebuildMenu();
   250     rebuildMenu();
   232     for (int i = 0; i < symbianMenus.count(); ++i)
   251     for (int i = 0; i < symbianMenus.count(); ++i)
   233         QT_TRAP_THROWING(menuPane->AddMenuItemL(symbianMenus.at(i)->menuItemData));
   252         QT_TRAP_THROWING(menuPane->AddMenuItemL(symbianMenus.at(i)->menuItemData));
   235 
   254 
   236 void qt_symbian_show_submenu( CEikMenuPane* menuPane, int id)
   255 void qt_symbian_show_submenu( CEikMenuPane* menuPane, int id)
   237 {
   256 {
   238     SymbianMenuItem* menu = qt_symbian_find_menu(id, symbianMenus);
   257     SymbianMenuItem* menu = qt_symbian_find_menu(id, symbianMenus);
   239     if (menu) {
   258     if (menu) {
       
   259         // Normally first AddMenuItemL call for menuPane will create the item array.
       
   260         // However if we don't have any items, we still need the item array. Otherwise
       
   261         // menupane will crash. That's why we create item array here manually, and
       
   262         // AddMenuItemL will then use the existing array.
       
   263         CEikMenuPane::CItemArray* itemArray = q_check_ptr(new CEikMenuPane::CItemArray);
       
   264         menuPane->SetItemArray(itemArray);
       
   265         menuPane->SetItemArrayOwnedExternally(EFalse);
       
   266 
   240         for (int i = 0; i < menu->children.count(); ++i)
   267         for (int i = 0; i < menu->children.count(); ++i)
   241             QT_TRAP_THROWING(menuPane->AddMenuItemL(menu->children.at(i)->menuItemData));
   268             QT_TRAP_THROWING(menuPane->AddMenuItemL(menu->children.at(i)->menuItemData));
   242     }
   269     }
   243 }
   270 }
   244 #endif // Q_WS_S60
   271 #endif // Q_WS_S60
   269 }
   296 }
   270 
   297 
   271 void QMenuBarPrivate::symbianCreateMenuBar(QWidget *parent)
   298 void QMenuBarPrivate::symbianCreateMenuBar(QWidget *parent)
   272 {
   299 {
   273     Q_Q(QMenuBar);
   300     Q_Q(QMenuBar);
   274     if (parent && parent->isWindow()){
   301     if (parent) {
   275         menubars()->insert(q->window(), this);
   302         if(parent->isWindow()) {
   276         symbian_menubar = new QSymbianMenuBarPrivate(this);
   303             menubars()->insert(q->window(), this);
   277         nativeMenuBars.append(q);
   304             symbian_menubar = new QSymbianMenuBarPrivate(this);
       
   305             nativeMenuBars.append(q);
       
   306         } else {
       
   307             menubars()->insert(q->parentWidget(), this);
       
   308             symbian_menubar = new QSymbianMenuBarPrivate(this);
       
   309             nativeMenuBars.append(q);
       
   310         }
   278     }
   311     }
   279 }
   312 }
   280 
   313 
   281 void QMenuBarPrivate::symbianDestroyMenuBar()
   314 void QMenuBarPrivate::symbianDestroyMenuBar()
   282 {
   315 {
   283     Q_Q(QMenuBar);
   316     Q_Q(QMenuBar);
   284     int index = nativeMenuBars.indexOf(q);
   317     int index = nativeMenuBars.indexOf(q);
   285     nativeMenuBars.removeAt(index);
   318     nativeMenuBars.removeAt(index);
   286     menubars()->remove(q->window(), this);
   319     menubars()->remove(q->window(), this);
       
   320     menubars()->remove(q->parentWidget(), this);
   287     rebuildMenu();
   321     rebuildMenu();
   288     if (symbian_menubar)
   322     if (symbian_menubar)
   289         delete symbian_menubar;
   323         delete symbian_menubar;
   290     symbian_menubar = 0;
   324     symbian_menubar = 0;
       
   325 }
       
   326 
       
   327 void QMenuBarPrivate::reparentMenuBar(QWidget *oldParent, QWidget *newParent)
       
   328 {
       
   329     if (menubars()->contains(oldParent)) {
       
   330         QMenuBarPrivate *object = menubars()->take(oldParent);
       
   331         menubars()->insert(newParent, object);
       
   332     }
   291 }
   333 }
   292 
   334 
   293 QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar)
   335 QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar)
   294 {
   336 {
   295     d = menubar;
   337     d = menubar;