/*!
 * Set the Fold level from the XP layer.
 */
void AP_UnixDialog_Lists::setFoldLevelInGUI(void)
{
	setFoldLevel(getCurrentFold(),true);
}
Esempio n. 2
0
/*!
 * This method Does the stuff requested on the "action" button, "Apply" in the
 * Modeless dialog and "OK" in the Modal dialog.
 * Read comments with for all the stuff that can happen.
 */
void AP_Dialog_Lists::Apply(void)
{
	gchar szStart[20];
	if(!isModal() && (!isPageLists() || m_bFoldingLevelChanged))
	{
//
// OK fold up the text according the level specified.
//
	        m_bFoldingLevelChanged = false;
		fl_AutoNum * pAuto = getBlock()->getAutoNum();
		const gchar * props[5] = {"text-folded",NULL,"text-folded-id",NULL,NULL};
		UT_UTF8String sStr = UT_UTF8String_sprintf("%d",getCurrentFold());
		props[1] = sStr.utf8_str();
		UT_uint32 ID = 0;
		if(!pAuto)
		{
		        ID = getView()->getDocument()->getUID(UT_UniqueId::List);
		}
		else
		{
		        ID = pAuto->getID();
		}
		UT_UTF8String sID = UT_UTF8String_sprintf("%d",ID);
		props[3] = sID.utf8_str();
		PT_DocPosition posLow = 0;
		PT_DocPosition posHigh = 0;
		if(getView()->isSelectionEmpty() && pAuto)
		{
		      PL_StruxDocHandle sdhLow = pAuto->getFirstItem();
		      PL_StruxDocHandle sdhHigh = pAuto->getLastItemInHeiracy();
		      posLow = getView()->getDocument()->getStruxPosition(sdhLow)+1;
		      posHigh = getView()->getDocument()->getStruxPosition(sdhHigh)+1;
		}
		else
		{
		      posLow = getView()->getPoint();
		      posHigh = getView()->getSelectionAnchor();
		      if(posLow > posHigh)
		      {
			  PT_DocPosition posTemp = posLow;
			  posLow = posHigh;
			  posHigh = posTemp;
		      }
		}
		getView()->setCollapsedRange(posLow,posHigh,props);
		return;
	}

/*!
 *
 * OK this is failsafe code incase the user has changed the font but wants a
 * bullet list anyway. We don't let then!
 */
	if(m_NewListType == BULLETED_LIST || m_NewListType == IMPLIES_LIST)
	{
		m_pszFont = "Symbol";
	}
	else if(m_NewListType > DASHED_LIST && m_NewListType < OTHER_NUMBERED_LISTS)
	{
		m_pszFont = _getDingbatsFontName();
	}

/*!
 * Just to make things even more confusing this method is also used in a Modal
 * mannor by the styles dialog. This method is called when the users clicks "OK"
 * on the modal dialog. When that happens we fill an output vector with all the
 * properties currently defined.
 */
	if(isModal())
	{
//
// Fill out output vector with gchar * strings to be accessed via the calling
// function.
//
		if(m_OutProps.getItemCount() > 0)
			m_OutProps.clear();
		sprintf(szStart,"%d",m_iStartValue);
		m_OutProps.addItem((void *) "start-value");
		m_Output[0] = (gchar *) szStart;
		m_OutProps.addItem((void *) m_Output[0].c_str());
		m_OutProps.addItem((void *) "list-style");
		m_Output[1] = getBlock()->getListStyleString(m_NewListType);
		m_OutProps.addItem((void *) m_Output[1].c_str());
		m_OutProps.addItem((void *) "list-delim");
		m_OutProps.addItem((void *)  m_pszDelim.c_str());
		m_OutProps.addItem((void *) "list-decimal");
		m_OutProps.addItem((void *) m_pszDecimal.c_str());
		m_OutProps.addItem((void *) "field-font");
		m_OutProps.addItem((void *) m_pszFont.c_str());
		m_OutProps.addItem((void *) "margin-left");
		m_Output[2] =	UT_convertInchesToDimensionString(DIM_IN, m_fAlign, 0);
		m_OutProps.addItem((void *) m_Output[2].c_str());

		m_OutProps.addItem((void *) "text-indent");
		m_Output[3] = UT_convertInchesToDimensionString(DIM_IN, m_fIndent, 0);
		m_OutProps.addItem((void *) m_Output[3].c_str());
		m_Answer = a_OK;
		return;
	}
/*!
 * If the "Apply to current" radio buton is chosen we have two options.
 * 1. If "No list" is chosen we stop the current list at on this block.
 * 2. Otherwise we change the current list to the type requested here.
 * This piece of code changes the list style at the current point to the
 * Style requested by the user.
 */
	UT_GenericVector<fl_BlockLayout*> vBlock;
	UT_uint32 i = 0;
	getView()->getBlocksInSelection(&vBlock);
	UT_uint32 count = vBlock.getItemCount();
	getView()->cmdUnselectSelection();
	if(m_bApplyToCurrent == true && m_isListAtPoint == true &&  m_NewListType != NOT_A_LIST)
	{
		getView()->getDocument()->beginUserAtomicGlob();
		getView()->changeListStyle(getAutoNum(),m_NewListType,m_iStartValue,
                                   m_pszDelim.c_str(), m_pszDecimal.c_str(), 
                                   m_pszFont.c_str(),m_fAlign,m_fIndent);
		if(getAutoNum() != NULL)
		{
			getAutoNum()->update(0);
		}
		getView()->getDocument()->endUserAtomicGlob();
		clearDirty();
		getView()->updateLayout();
		getView()->setPoint(getView()->getPoint());
		getView()->ensureInsertionPointOnScreen();
		return;
	}
/*!
 * This code stops the list at the current point.
 */
	if ( m_isListAtPoint == true &&  m_NewListType == NOT_A_LIST)
	{
		getView()->getDocument()->beginUserAtomicGlob();
		for(i=0;i < count; i++)
		{
			fl_BlockLayout * pBlock = (fl_BlockLayout *) vBlock.getNthItem(i);
			if(pBlock->isListItem() == true)
			{
				getView()->getDocument()->StopList(pBlock->getStruxDocHandle());
			}
		}
		getView()->getDocument()->endUserAtomicGlob();
		clearDirty();
		getView()->updateLayout();
		getView()->setPoint(getView()->getPoint());
		getView()->ensureInsertionPointOnScreen();
		return;
	}
/*!
 * Start new list. 4 Possibilities.
 * 1. If there is a list at the current point and the user choose no list, stop
 *    the list the current point.
 *
 * 2. start a new list with the properties given if there is not a
 * list at the current point.
 *
 * 3. Start a sublist at the current point if a list already exists there and
 *    contains two or more items.
 *
 * 4. Change the list to the requested value if a list already eists but only
 *    has one item in it.
 */
	if(m_bStartNewList == true)
	{
		getView()->getDocument()->beginUserAtomicGlob();
		for(i=0;i < count; i++)
		{
			fl_BlockLayout * pBlock2 = (fl_BlockLayout *) vBlock.getNthItem(i);
			if(pBlock2->isListItem() == true && m_NewListType == NOT_A_LIST)
			{
//
// This stops the current list.
//
				if(pBlock2->isListItem() == true)
				{
					getView()->getDocument()->StopList(pBlock2->getStruxDocHandle());
				}
			}
			else if ( pBlock2->isListItem() == false && m_NewListType != NOT_A_LIST )
			{
//
// This starts the new list
//
				pBlock2->getDocument()->disableListUpdates();
				if(i == 0)
				{
					pBlock2->StartList(m_NewListType,m_iStartValue,
                                       m_pszDelim.c_str(), m_pszDecimal.c_str(),
                                       m_pszFont.c_str(), m_fAlign, 
                                       m_fIndent, 0, 1);
					pBlock2->getDocument()->enableListUpdates();
					pBlock2->getDocument()->updateDirtyLists();
				}
				else
				{
					fl_BlockLayout * pBlock = (fl_BlockLayout *) vBlock.getNthItem(i);
					fl_BlockLayout * rBlock = (fl_BlockLayout *) pBlock->getPrev();
					if(rBlock != NULL)
					{
						pBlock->resumeList(rBlock);
						pBlock->getDocument()->enableListUpdates();
					}
				}

			}
			else if( pBlock2->getAutoNum() && (pBlock2->getAutoNum()->getNumLabels() > 1) && m_NewListType != NOT_A_LIST )
			{
//
// This starts a sublist.
//
				UT_uint32 curlevel = pBlock2->getLevel();
				UT_uint32 currID = pBlock2->getAutoNum()->getID();
				curlevel++;
				pBlock2->getDocument()->disableListUpdates();
//
// Need to update m_fAlign and m_fIndent to reflect the higher level of indentation.
//
				if(i == 0)
				{
					m_fAlign = m_fAlign + (float) LIST_DEFAULT_INDENT;
					pBlock2->StartList(m_NewListType,m_iStartValue,
                                       m_pszDelim.c_str(), m_pszDecimal.c_str(),
                                       m_pszFont.c_str(), m_fAlign, m_fIndent, 
                                       currID,curlevel);
					pBlock2->getDocument()->enableListUpdates();
					pBlock2->getDocument()->updateDirtyLists();
				}
				else
				{
					fl_BlockLayout * pBlock = (fl_BlockLayout *) vBlock.getNthItem(i);
					fl_BlockLayout * rBlock = (fl_BlockLayout *) pBlock->getPrev();
					if(rBlock != NULL)
					{
						pBlock->resumeList(rBlock);
						pBlock->getDocument()->enableListUpdates();
						pBlock->getDocument()->updateDirtyLists();
					}
				}
			}
			else if( pBlock2->getAutoNum() && (pBlock2->getAutoNum()->getNumLabels() <= 1) && m_NewListType != NOT_A_LIST )
			{
//
// The list at the current point only has one item which is the current paragraph.
// We can't share an sdh amongst two autonum's so we can't start a sublist.
// We'll change the list style instead.
//
				getView()->changeListStyle(pBlock2->getAutoNum(),
                                           m_NewListType, m_iStartValue,
                                           m_pszDelim.c_str(), 
                                           m_pszDecimal.c_str(), 
                                           m_pszFont.c_str(), m_fAlign,
                                           m_fIndent);
				if(pBlock2->getAutoNum() != NULL)
				{
					pBlock2->getAutoNum()->update(0);
				}

			}
		}
		clearDirty();
		getView()->updateLayout();
		getView()->setPoint(getView()->getPoint());
		getView()->updateScreen(true);
		getView()->notifyListeners(AV_CHG_MOTION | AV_CHG_HDRFTR);
		getView()->getDocument()->endUserAtomicGlob();
		getView()->ensureInsertionPointOnScreen();
		return;
	}
/*!
 * OK Attach the block at this point to the previous list of the same margin.
 */
	if(m_bResumeList == true &&  m_isListAtPoint != true )
	{
		getView()->getDocument()->beginUserAtomicGlob();
		for(i=0;i < count; i++)
		{
			fl_BlockLayout * pBlock = (fl_BlockLayout *) vBlock.getNthItem(i);
			fl_BlockLayout * rBlock = pBlock->getPreviousListOfSameMargin();
			if(rBlock != NULL)
			{
				pBlock->resumeList(rBlock);
				pBlock->getDocument()->enableListUpdates();
				pBlock->getDocument()->updateDirtyLists();
			}
		}
		getView()->getDocument()->endUserAtomicGlob();
	}
	getView()->updateLayout();
	getView()->setPoint(getView()->getPoint());
	getView()->updateScreen(true);
	getView()->notifyListeners(AV_CHG_MOTION | AV_CHG_HDRFTR);
	getView()->ensureInsertionPointOnScreen();
	clearDirty();
}