mulwidgets/mulcoverflowwidget/src/mulcoverflowcontrol.cpp
branchRCL_3
changeset 15 125793e17004
parent 14 03228bb411ae
equal deleted inserted replaced
14:03228bb411ae 15:125793e17004
   793 // ---------------------------------------------------------------------------
   793 // ---------------------------------------------------------------------------
   794 //    
   794 //    
   795 void MulCoverFlowControl::HandleLessItemsUpdate(int aIndex)
   795 void MulCoverFlowControl::HandleLessItemsUpdate(int aIndex)
   796 	{
   796 	{
   797 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleLessItemsUpdate");
   797 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleLessItemsUpdate");
   798 	if(aIndex == mData->mHighlightIndex)
   798 
       
   799 	int highlight = mData->mHighlightIndex;
       
   800     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
   801     if(accessor)
       
   802         {
       
   803         highlight = accessor->Highlight();
       
   804         }
       
   805     
       
   806 	if(aIndex == highlight)
   799 		{
   807 		{
   800 		UpdateCoverflowItem(aIndex,mData->mNumVisibleItem);
   808 		UpdateCoverflowItem(aIndex,mData->mNumVisibleItem);
   801 		if(mData->mNumVisibleItem != 1 && TotalModelCount() == 3)	
   809 		if(mData->mNumVisibleItem != 1 && TotalModelCount() == 3)	
   802 			{
   810 			{
   803 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem + 3);
   811 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem + 3);
   815 		else
   823 		else
   816 			{
   824 			{
   817 			// 2d template landscape mode
   825 			// 2d template landscape mode
   818 			if(TotalModelCount() == 2)
   826 			if(TotalModelCount() == 2)
   819 				{
   827 				{
   820 				UpdateCoverflowItem(aIndex,mData->mNumVisibleItem+(aIndex - mData->mHighlightIndex));	
   828 				UpdateCoverflowItem(aIndex,mData->mNumVisibleItem+(aIndex - highlight));	
   821 				}
   829 				}
   822 			else
   830 			else
   823 				{
   831 				{
   824 				int relativeIndex = (aIndex - mData->mHighlightIndex) + mData->mNumVisibleItem;
   832 				int relativeIndex = (aIndex - highlight) + mData->mNumVisibleItem;
   825 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   833 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   826 					{
   834 					{
   827 					UpdateCoverflowItem(aIndex,relativeIndex);						
   835 					UpdateCoverflowItem(aIndex,relativeIndex);						
   828 					}
   836 					}
   829 				relativeIndex = relativeIndex + TotalModelCount();
   837 				relativeIndex = relativeIndex + TotalModelCount();
   830 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   838 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   831 					{
   839 					{
   832 					UpdateCoverflowItem(aIndex,relativeIndex);	
   840 					UpdateCoverflowItem(aIndex,relativeIndex);	
   833 					}
   841 					}
   834 								
   842 								
   835 				relativeIndex = mData->mNumVisibleItem - (TotalModelCount() - aIndex + mData->mHighlightIndex);
   843 				relativeIndex = mData->mNumVisibleItem - (TotalModelCount() - aIndex + highlight);
   836 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   844 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
   837 					{
   845 					{
   838 					UpdateCoverflowItem(aIndex,relativeIndex);					
   846 					UpdateCoverflowItem(aIndex,relativeIndex);					
   839 					}
   847 					}
   840 				relativeIndex = relativeIndex - TotalModelCount();
   848 				relativeIndex = relativeIndex - TotalModelCount();
   856     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::IsIndexInVisibleWindow");
   864     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::IsIndexInVisibleWindow");
   857 
   865 
   858 	int totalVisual = TotalModelCount();
   866 	int totalVisual = TotalModelCount();
   859     int noOfVisuals = mData->mNumVisibleItem; 
   867     int noOfVisuals = mData->mNumVisibleItem; 
   860     int highlightRelativeIndex = mData->mNumVisibleItem;
   868     int highlightRelativeIndex = mData->mNumVisibleItem;
   861     	
   869     int highlight = mData->mHighlightIndex;
   862 	int leftIndex = mData->mHighlightIndex - noOfVisuals;
   870     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
   863 	int rightIndex = mData->mHighlightIndex + noOfVisuals;
   871     if(accessor)
       
   872         {
       
   873         highlight = accessor->Highlight();
       
   874         }
       
   875 
       
   876 	int leftIndex = highlight - noOfVisuals;
       
   877 	int rightIndex = highlight + noOfVisuals;
   864     
   878     
   865  	if (leftIndex >= 0)
   879  	if (leftIndex >= 0)
   866 	 	{
   880 	 	{
   867 	 	if ((aIndex <= mData->mHighlightIndex) && (aIndex >= leftIndex))
   881 	 	if ((aIndex <= highlight) && (aIndex >= leftIndex))
   868 		 	{
   882 		 	{
   869 		 	aRelativeIndex = highlightRelativeIndex - (mData->mHighlightIndex - aIndex);
   883 		 	aRelativeIndex = highlightRelativeIndex - (highlight - aIndex);
   870 		 	return true;	
   884 		 	return true;	
   871 		 	}
   885 		 	}
   872 	 	}
   886 	 	}
   873 	else
   887 	else
   874 		{
   888 		{
   875 		if (aIndex <= mData->mHighlightIndex)
   889 		if (aIndex <= highlight)
   876 			{
   890 			{
   877 			aRelativeIndex = highlightRelativeIndex - (mData->mHighlightIndex - aIndex);
   891 			aRelativeIndex = highlightRelativeIndex - (highlight - aIndex);
   878 			return true;	
   892 			return true;	
   879 			}
   893 			}
   880 		else
   894 		else
   881 			{
   895 			{
   882 			leftIndex = totalVisual + leftIndex ;
   896 			leftIndex = totalVisual + leftIndex ;
   888 			}	
   902 			}	
   889 		}
   903 		}
   890  
   904  
   891  	if (rightIndex < totalVisual)
   905  	if (rightIndex < totalVisual)
   892 	 	{
   906 	 	{
   893 	 	if ((aIndex >= mData->mHighlightIndex) && (aIndex <= rightIndex))
   907 	 	if ((aIndex >= highlight) && (aIndex <= rightIndex))
   894 		 	{
   908 		 	{
   895 		 	aRelativeIndex = highlightRelativeIndex + (aIndex - mData->mHighlightIndex);
   909 		 	aRelativeIndex = highlightRelativeIndex + (aIndex - highlight);
   896 		 	return true;	
   910 		 	return true;	
   897 		 	}
   911 		 	}
   898 	 	}
   912 	 	}
   899 	else
   913 	else
   900 		{
   914 		{
   901 		if (aIndex >= mData->mHighlightIndex)
   915 		if (aIndex >= highlight)
   902 			{
   916 			{
   903 			aRelativeIndex = highlightRelativeIndex + (aIndex - mData->mHighlightIndex);
   917 			aRelativeIndex = highlightRelativeIndex + (aIndex - highlight);
   904 			return true;	
   918 			return true;	
   905 			}
   919 			}
   906 		rightIndex = rightIndex - totalVisual;
   920 		rightIndex = rightIndex - totalVisual;
   907 		if (aIndex <= rightIndex)
   921 		if (aIndex <= rightIndex)
   908 			{
   922 			{
   923     {
   937     {
   924     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::RelativeToAbsolute");
   938     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::RelativeToAbsolute");
   925     int highlightRelativeIndex = mData->mNumVisibleItem;
   939     int highlightRelativeIndex = mData->mNumVisibleItem;
   926     int absolute = -1;
   940     int absolute = -1;
   927     int totalVisuals = TotalModelCount();
   941     int totalVisuals = TotalModelCount();
       
   942     
       
   943     int highlight = mData->mHighlightIndex;
       
   944     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
   945     if(accessor)
       
   946         {
       
   947         highlight = accessor->Highlight();
       
   948         }
       
   949     
   928     if(totalVisuals <= 0)
   950     if(totalVisuals <= 0)
   929 	    {
   951 	    {
   930 	    // absolute index is always -1, so no need of any calculations
   952 	    // absolute index is always -1, so no need of any calculations
   931 	    }
   953 	    }
   932     else if(totalVisuals < 2*mData->mNumVisibleItem + 1)
   954     else if(totalVisuals < 2*mData->mNumVisibleItem + 1)
   933 	    {
   955 	    {
   934 	    if(aRelativeIndex == highlightRelativeIndex)
   956 	    if(aRelativeIndex == highlightRelativeIndex)
   935 			{
   957 			{
   936 			absolute = 	mData->mHighlightIndex;
   958 			absolute = 	highlight;
   937 			}
   959 			}
   938 		else
   960 		else
   939 			{
   961 			{
   940 			if(mData->mNumVisibleItem == 1)
   962 			if(mData->mNumVisibleItem == 1)
   941 				{
   963 				{
   943 				    {
   965 				    {
   944 				    absolute = -1;
   966 				    absolute = -1;
   945 				    }
   967 				    }
   946 				else if(totalVisuals == 2)
   968 				else if(totalVisuals == 2)
   947 					{
   969 					{
   948 					absolute = mData->mHighlightIndex + 1;
   970 					absolute = highlight + 1;
   949 					absolute = absolute >= totalVisuals ? 0 : absolute;
   971 					absolute = absolute >= totalVisuals ? 0 : absolute;
   950 					}
   972 					}
   951 				}
   973 				}
   952 			else
   974 			else
   953 				{
   975 				{
   955 				    {
   977 				    {
   956 				    absolute = -1;
   978 				    absolute = -1;
   957 				    }
   979 				    }
   958 				else if(totalVisuals == 2)
   980 				else if(totalVisuals == 2)
   959 					{
   981 					{
   960 					absolute = mData->mHighlightIndex + (aRelativeIndex - highlightRelativeIndex);
   982 					absolute = highlight + (aRelativeIndex - highlightRelativeIndex);
   961 					absolute = absolute >= totalVisuals ? -1 : absolute;
   983 					absolute = absolute >= totalVisuals ? -1 : absolute;
   962 					}
   984 					}
   963 				else // totalvisuals > 3
   985 				else // totalvisuals > 3
   964 					{
   986 					{
   965 					if(aRelativeIndex - highlightRelativeIndex > 0)
   987 					if(aRelativeIndex - highlightRelativeIndex > 0)
   966 						{
   988 						{
   967 						absolute = mData->mHighlightIndex + aRelativeIndex - highlightRelativeIndex;	
   989 						absolute = highlight + aRelativeIndex - highlightRelativeIndex;	
   968 						}
   990 						}
   969 					else
   991 					else
   970 						{
   992 						{
   971 						absolute = mData->mHighlightIndex + aRelativeIndex - highlightRelativeIndex
   993 						absolute = highlight + aRelativeIndex - highlightRelativeIndex
   972 							+ TotalModelCount();	
   994 							+ TotalModelCount();	
   973 						}					
   995 						}					
   974 					absolute = absolute >= totalVisuals ? absolute - totalVisuals : absolute;
   996 					absolute = absolute >= totalVisuals ? absolute - totalVisuals : absolute;
   975 					}
   997 					}
   976 				}
   998 				}
   978 	    }
  1000 	    }
   979 	else
  1001 	else
   980 		{
  1002 		{
   981 		if(aRelativeIndex == highlightRelativeIndex)
  1003 		if(aRelativeIndex == highlightRelativeIndex)
   982 			{
  1004 			{
   983 			absolute = 	mData->mHighlightIndex;
  1005 			absolute = highlight;
   984 			}
  1006 			}
   985 		else if (aRelativeIndex > highlightRelativeIndex)
  1007 		else if (aRelativeIndex > highlightRelativeIndex)
   986 		    {
  1008 		    {
   987 		    absolute = mData->mHighlightIndex + (aRelativeIndex - highlightRelativeIndex);
  1009 		    absolute = highlight + (aRelativeIndex - highlightRelativeIndex);
   988 		    absolute = absolute >= totalVisuals ? (absolute - totalVisuals) : absolute;	
  1010 		    absolute = absolute >= totalVisuals ? (absolute - totalVisuals) : absolute;	
   989 		    }
  1011 		    }
   990 		else
  1012 		else
   991 			{
  1013 			{
   992 		    absolute = mData->mHighlightIndex - (highlightRelativeIndex - aRelativeIndex);
  1014 		    absolute = highlight - (highlightRelativeIndex - aRelativeIndex);
   993 		    absolute = absolute <0 ? (totalVisuals + absolute) : absolute;
  1015 		    absolute = absolute <0 ? (totalVisuals + absolute) : absolute;
   994 		    absolute = absolute > totalVisuals - 1 ? -1 : absolute;	    
  1016 		    absolute = absolute > totalVisuals - 1 ? -1 : absolute;	    
   995 			}	
  1017 			}	
   996 		}    
  1018 		}    
   997     return absolute;
  1019     return absolute;
  1057 	Env().CancelCustomCommands(this);
  1079 	Env().CancelCustomCommands(this);
  1058 	// update the highlight index as well as the no of item.
  1080 	// update the highlight index as well as the no of item.
  1059 	mData->mHighlightIndex = aAccessor->Highlight();
  1081 	mData->mHighlightIndex = aAccessor->Highlight();
  1060 
  1082 
  1061 	CAlfLayout* main = (CAlfLayout*) mData->mBaseElement->findVisual( KMainLayoutIndex );
  1083 	CAlfLayout* main = (CAlfLayout*) mData->mBaseElement->findVisual( KMainLayoutIndex );
  1062 	int width = main->Size().Target().AsSize().iWidth;
  1084 	TSize mainSize = main->Size().Target().AsSize();
  1063 	int height = main->Size().Target().AsSize().iHeight;
  1085 	int width = mainSize.iWidth;
       
  1086 	int height = mainSize.iHeight;
  1064 
  1087 
  1065 	if( width == 0 && height == 0 )
  1088 	if( width == 0 && height == 0 )
  1066 		{
  1089 		{
  1067 		return;
  1090 		return;
  1068 		}
  1091 		}