From 9a666d97137b0af0a7d583bb86d7c4a9332f9c3a Mon Sep 17 00:00:00 2001 From: William Johnson Date: Thu, 15 Jul 2021 09:26:17 -0700 Subject: [PATCH] Fix context-menus not showing up in some places, and mobile menus not behaving correctly. --- InterSpec/PopupDiv.h | 2 + src/InterSpec.cpp | 24 ++++----- src/PopupDiv.cpp | 99 +++++++++++++++------------------- src/ShieldingSourceDisplay.cpp | 10 +--- 4 files changed, 57 insertions(+), 78 deletions(-) diff --git a/InterSpec/PopupDiv.h b/InterSpec/PopupDiv.h index b563480b..337da435 100644 --- a/InterSpec/PopupDiv.h +++ b/InterSpec/PopupDiv.h @@ -207,6 +207,8 @@ class PopupDivMenu : public Wt::WPopupMenu void parentMouseWentOver(); void undoParentHoveredOver(); + bool isMobile() const; + protected: void desktopDoHide(); diff --git a/src/InterSpec.cpp b/src/InterSpec.cpp index 7e3cbed2..a87344c7 100644 --- a/src/InterSpec.cpp +++ b/src/InterSpec.cpp @@ -658,8 +658,6 @@ InterSpec::InterSpec( WContainerWidget *parent ) //hamburger PopupDivMenu *popup = new PopupDivMenu( m_mobileMenuButton, PopupDivMenu::AppLevelMenu ); - popup->addPhoneBackItem( nullptr ); - m_mobileMenuButton->removeStyleClass( "Wt-btn" ); menuWidget = popup; @@ -991,16 +989,17 @@ InterSpec::InterSpec( WContainerWidget *parent ) m_spectrum->shiftAltKeyDragged().connect( this, &InterSpec::handleShiftAltDrag ); // m_spectrum->rightClicked().connect( boost::bind( &InterSpec::createPeakEdit, this, _1) ); - m_rightClickMenu = new PopupDivMenu( m_mobileMenuButton, PopupDivMenu::TransientMenu ); - m_rightClickMenu->setPositionScheme( Wt::Absolute ); - m_rightClickMenu->addStyleClass( " Wt-popupmenu Wt-outset" ); + m_rightClickMenu = new PopupDivMenu( nullptr, PopupDivMenu::TransientMenu ); m_rightClickMenu->aboutToHide().connect( this, &InterSpec::rightClickMenuClosed ); - if( isMobile() ) + if( m_rightClickMenu->isMobile() ) + { + m_rightClickMenu->addPhoneBackItem( nullptr ); + }else { - PopupDivMenuItem *item = m_rightClickMenu->addPhoneBackItem( NULL ); - item->triggered().connect( boost::bind(&PopupDivMenu::setHidden, m_rightClickMenu, true, WAnimation()) ); - }//if( isPhone() || isTablet() ) + m_rightClickMenu->setPositionScheme( Wt::Absolute ); + m_rightClickMenu->addStyleClass( " Wt-popupmenu Wt-outset" ); + } for( RightClickItems i = RightClickItems(0); i < kNumRightClickItems; i = RightClickItems(i+1) ) @@ -2613,7 +2612,7 @@ void InterSpec::handleRightClick( double energy, double counts, }//switch( i ) }//for( loop over right click menu items ) - if( isMobile() ) + if( m_rightClickMenu->isMobile() ) m_rightClickMenu->showMobile(); else m_rightClickMenu->popup( WPoint(pageX,pageY) ); @@ -10270,10 +10269,7 @@ void InterSpec::userAskedToFitPeaksInRange( double x0, double x1, menu->aboutToHide().connect( menu, &DeleteOnClosePopupMenu::markForDelete ); menu->setPositionScheme( Wt::Absolute ); - PopupDivMenuItem *item = 0; - if( isMobile() ) - item = menu->addPhoneBackItem( NULL ); -// item->triggered().connect( boost::bind( &deleteMenu, menu ) ); + PopupDivMenuItem *item = nullptr; item = menu->addMenuItem( "Single Peak" ); // item->triggered().connect( boost::bind( &InterSpec::findPeakFromUserRange, this, x0, x1 ) ); diff --git a/src/PopupDiv.cpp b/src/PopupDiv.cpp index 29dad026..c05713e5 100644 --- a/src/PopupDiv.cpp +++ b/src/PopupDiv.cpp @@ -135,7 +135,7 @@ WT_DECLARE_WT_MEMBER }, 500 ); }); -WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", function() +WT_DECLARE_WT_MEMBER(SetupHideOverlay, Wt::JavaScriptFunction, "SetupHideOverlay", function() { function hideverything(e) { @@ -152,21 +152,8 @@ WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", functio //Scroll back to the top of the menu jel.scrollTop(0); - //I cant actually tell the differnce in smoothness between my version - // and jQueries version. var a = -jel.width() - 10; jel.animate({left: a+'px'}, {queue: false, duration: 255}, "linear", function(){jel.hide();}); - -// var w = jel.width(), t0 = (new Date()).valueOf(); -// ( function slideout() -// { -// var t = (new Date()).valueOf(); -// var pos = -w*((t-t0)/250); -// el.style['left'] = pos + 'px'; -// if( pos>-w ) -// setTimeout(slideout,1); -// else jel.hidde(); -// })() }); $('.mobilePopupMenuOverlay').hide(); @@ -668,7 +655,7 @@ PopupDivMenu::PopupDivMenu( Wt::WPushButton *menuParent, { addStyleClass( "PopupDivMenuPhone" ); LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "ShowPhone", wtjsShowPhone); - LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "HideOverlay", wtjsHideOverlay); + LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "SetupHideOverlay", wtjsSetupHideOverlay); // Note: need to call this to reset the menus when a submenu is // selected/hidden. No need to call triggered(), as it will be hidden too. @@ -702,48 +689,47 @@ PopupDivMenu::PopupDivMenu( Wt::WPushButton *menuParent, }//if( useNativeMenu ) #endif - if( menuParent ) + if( m_mobile) { - if( m_mobile) - { - switch( m_type ) - { - case AppLevelMenu: - menuParent->clicked().connect( this, &PopupDivMenu::showMobile ); - break; - - case TransientMenu: - menuParent->setMenu( this ); - break; - }//switch( m_type ) - }else + if( menuParent ) { + addPhoneBackItem( nullptr ); + menuParent->clicked().connect( this, &PopupDivMenu::showMobile ); + }//if( menuParent ) + }else if( menuParent ) + { #if(USE_OSX_NATIVE_MENU) - if( useNativeMenu && (menutype == AppLevelMenu) ) - { - const string buttontxt = menuParent->text().toUTF8(); - if( buttontxt.length() ) - m_nsmenu = addOsxMenu( this, buttontxt.c_str() ); - } //AppLevelMenu + if( useNativeMenu && (menutype == AppLevelMenu) ) + { + const string buttontxt = menuParent->text().toUTF8(); + if( buttontxt.length() ) + m_nsmenu = addOsxMenu( this, buttontxt.c_str() ); + } //AppLevelMenu #endif #if( USING_ELECTRON_NATIVE_MENU ) - if( useNativeMenu && (menutype == AppLevelMenu) ) - { - //Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help" - //In Js, we should find the menu, and get a reference to it. - //app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" ); - app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" ); - m_hasElectronCounterpart = true; - } + if( useNativeMenu && (menutype == AppLevelMenu) ) + { + //Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help" + //In Js, we should find the menu, and get a reference to it. + //app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" ); + app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" ); + m_hasElectronCounterpart = true; + } #endif - if( !useNativeMenu && (menutype == AppLevelMenu) ) - setupDesktopMenuStuff(); - else - menuParent->setMenu( this ); - } //if( m_mobile) / else - }else //if( menuParent ) + if( !useNativeMenu && (menutype == AppLevelMenu) ) + { + setupDesktopMenuStuff(); + }else + { + menuParent->setMenu( this ); + + const string js = "function(){Wt.WT.BringAboveDialogs('" + id() + "');" + "Wt.WT.AdjustTopPos('" + menuParent->id() + "');}"; + menuParent->clicked().connect( js ); + } + }else //if( m_mobile) / else if( menuParent ) { #if( USING_ELECTRON_NATIVE_MENU ) if( m_hasElectronCounterpart && (menutype == AppLevelMenu) ) @@ -941,17 +927,16 @@ void PopupDivMenu::setHidden( bool hidden, const Wt::WAnimation &animation ) void PopupDivMenu::showMobile() { - //Note/Hack: This is needed to check if clicked or mouseover. If clicked, - // calling popup() will somehow cause the popupmenu to not show. - // I know, weird huh. if( m_menuParent ) popup( m_menuParent, Wt::Vertical ); - + else + popup( {0,0} ); + if( m_mobile ) { doJavaScript("$('.mobilePopupMenuOverlay').show();"); doJavaScript( "Wt.WT.ShowPhone('" + id() + "');" ); - doJavaScript( "Wt.WT.HideOverlay();" ); + doJavaScript( "Wt.WT.SetupHideOverlay();" ); }//if( m_mobile ) }//void doShow() @@ -1008,6 +993,10 @@ void PopupDivMenu::undoParentHoveredOver() }//void undoParentHoveredOver() +bool PopupDivMenu::isMobile() const +{ + return m_mobile; +} void PopupDivMenu::setupDesktopMenuStuff() { @@ -1307,7 +1296,7 @@ PopupDivMenuItem *PopupDivMenu::addPhoneBackItem( PopupDivMenu *parent ) PopupDivMenu *PopupDivMenu::addPopupMenuItem( const Wt::WString &text, const std::string &iconPath ) { - PopupDivMenu *menu = new PopupDivMenu( 0, m_type ); + PopupDivMenu *menu = new PopupDivMenu( nullptr, m_type ); if( m_mobile ) { diff --git a/src/ShieldingSourceDisplay.cpp b/src/ShieldingSourceDisplay.cpp index e701eea1..77925afe 100644 --- a/src/ShieldingSourceDisplay.cpp +++ b/src/ShieldingSourceDisplay.cpp @@ -4277,15 +4277,7 @@ ShieldingSourceDisplay::ShieldingSourceDisplay( PeakModel *peakModel, Wt::WPushButton *addItemMenubutton = new WPushButton( " " ); m_addItemMenu = new PopupDivMenu( addItemMenubutton, PopupDivMenu::TransientMenu ); - if( m_specViewer->isMobile() ) - { - m_addItemMenu->addPhoneBackItem( NULL ); - addItemMenubutton->clicked().connect( m_addItemMenu, &PopupDivMenu::showMobile ); - } //mobile - else - { - m_addItemMenu->setButton( addItemMenubutton ); - } //not mobile + addItemMenubutton->setStyleClass( "ShiledingSourceOptionsBtn" ); addItemMenubutton->addStyleClass( "GearIcon" );