@@ -1198,11 +1198,12 @@ void CMenuContainer::AddStandardItems( bool bPlacePinned )
11981198 item.bInlineFirst =bInlineFirst;
11991199 bAlignBottom=bInlineFirst=false ;
12001200
1201- if (pStdItem->id ==MENU_PINNED_PROGRAMS )
1201+ bool bPinned=(pStdItem->id ==MENU_PINNED_PROGRAMS );
1202+ if (bPinned || IsRecentProgramList (pStdItem))
12021203 {
1203- // a placeholder, replaced once all other items are known (PlacePinnedPrograms).
1204+ // a placeholder, replaced once all other items are known (InsertRecentProgramLists, PlacePinnedPrograms).
12041205 // only the Classic main menu can place its pinned programs
1205- if (pInlineParent || m_bSubMenu || s_bWin7Style)
1206+ if (pInlineParent || (bPinned && ( m_bSubMenu || s_bWin7Style)) )
12061207 continue ;
12071208 m_Items.insert (m_Items.begin ()+menuIdx,1 ,item);
12081209 menuIdx++;
@@ -1514,10 +1515,48 @@ void CMenuContainer::AddStandardItems( bool bPlacePinned )
15141515 menuIdx++;
15151516 }
15161517 }
1518+ InsertRecentProgramLists ();
15171519 PlacePinnedPrograms (bPlacePinned);
15181520 }
15191521}
15201522
1523+ // The number of recent programs to show
1524+ int CMenuContainer::GetRecentProgramCount ( void )
1525+ {
1526+ // the sign of MaxRecentPrograms only picks the order
1527+ int count=GetSettingInt (L" MaxRecentPrograms" );
1528+ if (count<0 ) count=-count;
1529+ if (count>MRU_PROGRAMS_COUNT ) count=MRU_PROGRAMS_COUNT ;
1530+ return count;
1531+ }
1532+
1533+ // Lets the items that have a jump list open it as a split sub-menu
1534+ void CMenuContainer::SetJumplistFlags ( std::vector<MenuItem> &items )
1535+ {
1536+ for (std::vector<MenuItem>::iterator it=items.begin ();it!=items.end ();++it)
1537+ {
1538+ MenuItem &item=*it;
1539+ if (!item.bLink || item.bFolder || !item.pItem1 ) continue ;
1540+ CItemManager::RWLock lock (&g_ItemManager,false ,CItemManager::RWLOCK_ITEMS );
1541+ item.bFolder =(!item.pItemInfo ->GetAppid ().IsEmpty () && HasJumplist (item.pItemInfo ->GetAppid ()));
1542+ item.bHasJumpList =item.bFolder ;
1543+ item.bSplit =item.bFolder ;
1544+ }
1545+ }
1546+
1547+ // Whether the item at index gets the second-pane look, going by the column breaks before it (for items added before the layout)
1548+ bool CMenuContainer::IsInSecondPane ( int index )
1549+ {
1550+ int breaks=0 , count=0 ;
1551+ for (int i=1 ;i<(int )m_Items.size ();i++)
1552+ {
1553+ if (!m_Items[i].bBreak || m_Items[i].bOverflow ) continue ; // overflow columns never change the panes
1554+ count++;
1555+ if (i<=index) breaks++;
1556+ }
1557+ return IsSecondPaneAfterBreaks (breaks,count);
1558+ }
1559+
15211560// Passes a placeholder's column break and bottom alignment to the item that takes its place
15221561void CMenuContainer::InheritColumnFlags ( const MenuItem &placeholder, MenuItem &item )
15231562{
@@ -1536,6 +1575,42 @@ void CMenuContainer::SetOverflowBreaks( std::vector<MenuItem> &items, int first,
15361575 }
15371576}
15381577
1578+ // Whether the item is a Recent Programs item shown as a list (MENU_FLAT_LIST)
1579+ bool CMenuContainer::IsRecentProgramList ( const StdMenuItem *pStdItem )
1580+ {
1581+ return pStdItem && pStdItem->id ==MENU_RECENT_PROGRAMS && (pStdItem->settings &StdMenuItem::MENU_FLAT_LIST );
1582+ }
1583+
1584+ // The recent programs that take the place of the Recent Programs item at index, with their overflow breaks
1585+ void CMenuContainer::GetRecentProgramList ( int index, std::vector<MenuItem> &items )
1586+ {
1587+ int count=GetRecentProgramCount ();
1588+ if (count>0 )
1589+ GetRecentPrograms (items,count,IsInSecondPane (index));
1590+ if (!m_bSubMenu && GetSettingBool (L" EnableJumplists" ))
1591+ SetJumplistFlags (items);
1592+ SetOverflowBreaks (items,0 ,(int )items.size (),m_Items[index].pStdItem ->rows );
1593+ }
1594+
1595+ // Replaces each Recent Programs item shown as a list by the recent programs themselves
1596+ void CMenuContainer::InsertRecentProgramLists ( void )
1597+ {
1598+ // this runs after all other items are added, because GetRecentPrograms skips programs that are already in the main menu
1599+ for (int i=0 ;i<(int )m_Items.size ();i++)
1600+ {
1601+ if (!IsRecentProgramList (m_Items[i].pStdItem ))
1602+ continue ;
1603+ std::vector<MenuItem> items;
1604+ GetRecentProgramList (i,items);
1605+ MenuItem copy=m_Items[i];
1606+ m_Items.erase (m_Items.begin ()+i);
1607+ m_Items.insert (m_Items.begin ()+i,items.begin (),items.end ());
1608+ if (i<(int )m_Items.size ())
1609+ InheritColumnFlags (copy,m_Items[i]);
1610+ i+=(int )items.size ()-1 ; // continue after the inserted items
1611+ }
1612+ }
1613+
15391614// Removes the Pinned Programs placeholders and remembers where the first one was (m_PinnedPosition)
15401615void CMenuContainer::PlacePinnedPrograms ( bool bSetPosition )
15411616{
@@ -1837,12 +1912,13 @@ static bool IgnoreUserAssistItem(const UserAssistItem& uaItem)
18371912 return false ;
18381913}
18391914
1840- void CMenuContainer::GetRecentPrograms ( std::vector<MenuItem> &items, int maxCount )
1915+ void CMenuContainer::GetRecentPrograms ( std::vector<MenuItem> &items, int maxCount, bool bSecondPane )
18411916{
18421917 bool bShowMetro=GetSettingBool (L" RecentMetroApps" );
18431918 const std::vector<MenuItem> &mainItems=s_Menus[0 ]->m_Items ;
18441919
1845- int iconSizeFlag=(!m_bSubMenu && s_Skin.Main_icon_size ==MenuSkin::ICON_SIZE_LARGE )?CItemManager::INFO_LARGE_ICON :CItemManager::INFO_SMALL_ICON ;
1920+ MenuSkin::TIconSize mainIconSize=bSecondPane?s_Skin.Main2_icon_size :s_Skin.Main_icon_size ;
1921+ int iconSizeFlag=(!m_bSubMenu && mainIconSize==MenuSkin::ICON_SIZE_LARGE )?CItemManager::INFO_LARGE_ICON :CItemManager::INFO_SMALL_ICON ;
18461922 if (s_RecentPrograms==RECENT_PROGRAMS_RECENT )
18471923 {
18481924 for (int i=0 ;i<MRU_PROGRAMS_COUNT ;i++)
@@ -2790,10 +2866,7 @@ void CMenuContainer::InitItems( void )
27902866
27912867 if (m_Options&CONTAINER_RECENT )
27922868 {
2793- int nRecent=GetSettingInt (L" MaxRecentPrograms" );
2794- if (nRecent<0 )
2795- nRecent=-nRecent;
2796- if (nRecent>MRU_PROGRAMS_COUNT ) nRecent=MRU_PROGRAMS_COUNT ;
2869+ int nRecent=GetRecentProgramCount ();
27972870 if (nRecent>0 )
27982871 {
27992872 // prepend recent programs
@@ -2817,19 +2890,7 @@ void CMenuContainer::InitItems( void )
28172890 }
28182891
28192892 if (!m_bSubMenu && GetSettingBool (L" EnableJumplists" ))
2820- {
2821- for (std::vector<MenuItem>::iterator it=m_Items.begin ();it!=m_Items.end ();++it)
2822- {
2823- MenuItem &item=*it;
2824- if (item.bLink && !item.bFolder && item.pItem1 )
2825- {
2826- CItemManager::RWLock lock (&g_ItemManager,false ,CItemManager::RWLOCK_ITEMS );
2827- item.bFolder =(!item.pItemInfo ->GetAppid ().IsEmpty () && HasJumplist (item.pItemInfo ->GetAppid ()));
2828- item.bHasJumpList =item.bFolder ;
2829- item.bSplit =item.bFolder ;
2830- }
2831- }
2832- }
2893+ SetJumplistFlags (m_Items);
28332894
28342895 m_ScrollCount=(int )m_Items.size ();
28352896 if (m_ScrollCount>0 && m_Items[m_ScrollCount-1 ].id ==MENU_PROGRAMS_TREE )
@@ -3302,21 +3363,20 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
33023363 bool bRecentReverse=GetSettingInt (L" MaxRecentPrograms" )<0 ;
33033364 bool bRecentByName=GetSettingBool (L" RecentSortName" );
33043365
3305- int firstRecent=-1 , lastRecent=-1 ;
3366+ // the layout is done in MRU order, and each block of recent programs is put in display order after it.
3367+ // every Recent Programs item shown as a list adds a block of its own
3368+ std::vector<std::pair<int ,int >> recentBlocks; // [first,last) of each block
33063369 if ((bRecentReverse || bRecentByName) && (!m_bSubMenu || (m_Options&CONTAINER_RECENT )))
33073370 {
33083371 for (int i=0 ;i<(int )m_Items.size ();i++)
33093372 {
3310- if (m_Items[i].id ==MENU_RECENT )
3311- {
3312- if (firstRecent==-1 ) firstRecent=i;
3313- lastRecent=i+1 ;
3314- }
3315- else if (firstRecent!=-1 )
3316- break ;
3373+ if (m_Items[i].id !=MENU_RECENT ) continue ;
3374+ int first=i;
3375+ while (i<(int )m_Items.size () && m_Items[i].id ==MENU_RECENT )
3376+ i++;
3377+ std::sort (m_Items.begin ()+first,m_Items.begin ()+i,MenuItem::MruOrderComparator ());
3378+ recentBlocks.push_back (std::make_pair (first,i));
33173379 }
3318- if (firstRecent>=0 )
3319- std::sort (m_Items.begin ()+firstRecent,m_Items.begin ()+lastRecent,MenuItem::MruOrderComparator ());
33203380 }
33213381
33223382 m_bTwoColumns=(!m_bSubMenu && s_Skin.TwoColumns );
@@ -3476,7 +3536,7 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
34763536 int y=0 ;
34773537 int maxw=0 ;
34783538 int index=m_bSecondPaneFirst?1 :0 ;
3479- int overflowTop=0 ; // where the pinned programs start , so their overflow columns line up with them
3539+ int overflowTop=0 ; // where the current list starts , so its overflow columns line up with it
34803540 for (int k=0 ;k<(int )order.size ();k++)
34813541 {
34823542 int i=order[k];
@@ -3503,7 +3563,9 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
35033563 else
35043564 index=GetPaneOfNewColumn (column,index,lastBreak<0 || k==lastBreak);
35053565 }
3506- if (i==0 && m_ScrollCount>0 )
3566+ bool bPinnedStart=(i==0 && m_ScrollCount>0 );
3567+ bool bRecentStart=(item.id ==MENU_RECENT && (k==0 || m_Items[order[k-1 ]].id !=MENU_RECENT ));
3568+ if (bPinnedStart || bRecentStart)
35073569 overflowTop=y;
35083570 item.bNew =false ;
35093571 if (m_bTwoColumns && i<m_OriginalCount && s_MenuMode!=MODE_NORMAL && (i<=m_SearchIndex-m_SearchItemCount || i>m_SearchIndex) && item.id !=MENU_SHUTDOWN_BUTTON )
@@ -4192,11 +4254,17 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
41924254 }
41934255 }
41944256
4195- if (firstRecent>= 0 )
4257+ for (std::vector<std::pair< int , int >>::const_iterator block=recentBlocks. begin ();block!=recentBlocks. end ();++block )
41964258 {
4197- // reorder recent items
4198- int top=m_Items[firstRecent].itemRect .top ;
4199- int firstRow=m_Items[firstRecent].row ;
4259+ // reorder recent items. they take the places the layout gave them in MRU order, which may span several columns
4260+ int firstRecent=block->first , lastRecent=block->second ;
4261+ struct Place { RECT rect; int row, column; };
4262+ std::vector<Place> places;
4263+ for (int i=firstRecent;i<lastRecent;i++)
4264+ {
4265+ Place place={m_Items[i].itemRect ,m_Items[i].row ,m_Items[i].column };
4266+ places.push_back (place);
4267+ }
42004268 if (bRecentByName)
42014269 std::sort (m_Items.begin ()+firstRecent,m_Items.begin ()+lastRecent,MenuItem::MruNameComparator ());
42024270
@@ -4232,12 +4300,10 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
42324300 std::reverse (m_Items.begin ()+firstRecent,m_Items.begin ()+lastRecent);
42334301 for (int i=firstRecent;i<lastRecent;i++)
42344302 {
4235- RECT &rc=m_Items[i].itemRect ;
4236- int h=rc.bottom -rc.top ;
4237- rc.top =top;
4238- top+=h;
4239- rc.bottom =top;
4240- m_Items[i].row =firstRow-firstRecent+i;
4303+ const Place &place=places[i-firstRecent];
4304+ m_Items[i].itemRect =place.rect ;
4305+ m_Items[i].row =place.row ;
4306+ m_Items[i].column =place.column ;
42414307 }
42424308 }
42434309 }
0 commit comments