Beispiel #1
0
CAVector CToolCervicales::SegmentationGlob(CDib * m_Dib, CRxDoc * i_Document, CList<CPoint, CPoint&>& i_List) {
	CList<CPoint, CPoint&> Result;
	
	Result.AddTail(i_List.GetHead());
	Segmentation(m_Dib, i_Document, i_List.GetHeadPosition(), i_List.GetTailPosition(), i_List, 0, Result);
	Result.AddTail(i_List.GetTail());

	CAVector Vector; CPoint l_Point;
	POSITION c_Pos = Result.GetHeadPosition();
	while (c_Pos != NULL) {
		l_Point = Result.GetNext(c_Pos);
		Vector.Add(CPoint(l_Point.x, m_Dib->GetHeight()-l_Point.y));
	}
	/* replace very close points by an intermediate value */	
	for (int i=2;i<(int)((double)(m_Dib->GetWidth() + m_Dib->GetHeight())/2 * 0.03);i++) RemoveClosePoints(Vector, i);
	/* remove pattern points */
	RemovePatternPoints(Vector);
	//i_Document->Add(Vector);
	return Vector;
}
void CPlayerPlaylistBar::OnLvnKeyDown(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);

    *pResult = FALSE;

    CList<int> items;
    POSITION pos = m_list.GetFirstSelectedItemPosition();
    while (pos) {
        items.AddHead(m_list.GetNextSelectedItem(pos));
    }

    if (pLVKeyDown->wVKey == VK_DELETE && items.GetCount() > 0) {
        pos = items.GetHeadPosition();
        while (pos) {
            int i = items.GetNext(pos);
            if (m_pl.RemoveAt(FindPos(i))) {
                ((CMainFrame*)AfxGetMainWnd())->CloseMedia();
            }
            m_list.DeleteItem(i);
        }

        m_list.SetItemState(-1, 0, LVIS_SELECTED);
        m_list.SetItemState(
            max(min(items.GetTail(), m_list.GetItemCount() - 1), 0),
            LVIS_SELECTED, LVIS_SELECTED);

        ResizeListColumn();

        *pResult = TRUE;
    } else if (pLVKeyDown->wVKey == VK_SPACE && items.GetCount() == 1) {
        m_pl.SetPos(FindPos(items.GetHead()));

        ((CMainFrame*)AfxGetMainWnd())->OpenCurPlaylistItem();

        AfxGetMainWnd()->SetFocus();

        *pResult = TRUE;
    }
}
//************************************************************************************
void CBCGPOutlineParser::DoParse (const CString& strBuffer, 
								  const int nStartOffset, const int nEndOffset, 
								  CObList& lstResults)
{
	ASSERT (nStartOffset >= 0);
	ASSERT (nEndOffset < strBuffer.GetLength ());
	ASSERT (nStartOffset <= nEndOffset);

	m_strOut.Empty ();

	CList <Lexeme, Lexeme&> lstStack;
	Lexeme lexemStackTop (0, LT_Eps, 0, 0);
	lstStack.AddTail (lexemStackTop);

	int nOffset	= nStartOffset;

	while (nOffset <= nEndOffset)
	{
		// Get next lexem:
		Lexeme lexemNext = GetNext (strBuffer, nOffset, nEndOffset);
		Lexeme lexemTop = lstStack.GetTail ();

		if (lexemNext.m_nType == LT_EndOfText)
		{
			break;
		}

		// Parser logic:
		switch (lexemNext.m_nType)
		{
		case LT_BlockStart:
			lstStack.AddTail (lexemNext);
			break;
		case LT_BlockEnd:
			if (lexemTop.m_nType == LT_BlockStart &&
				lexemTop.m_nBlockType == lexemNext.m_nBlockType)
			{
				// Push Block:
				lstStack.RemoveTail ();
				Lexeme lexemRes (lexemTop.m_nBlockType, LT_CompleteBlock, lexemTop.m_nStart, lexemNext.m_nEnd);
				PushResult (lexemRes, lstResults);
			}
			else
			{
				lstStack.AddTail (lexemNext);
			}
			break;
		case LT_CompleteBlock:
			{
				// Push Comment:
				PushResult (lexemNext, lstResults);
			}
			break;

		case LT_CustomBlock:
			break;
		}
	}
	
	// Finish parsing:
	while (!lstStack.IsEmpty ())
	{
		Lexeme lexem = lstStack.RemoveTail ();
		PushResult (lexem, lstResults);
	}
}
Beispiel #4
0
bool Template::ParseHelper()
{
	// Build our master string.
	m_helper->m_buffer.SetCount(0, 1024);
	m_helper->m_outBolPos = 0;

	// Start copying the string in.
	m_helper->m_codePtr = (LPCTSTR)m_code;
	m_helper->m_codeBolPtr = m_helper->m_codePtr;
	LPCTSTR& codePtr = m_helper->m_codePtr;
	CharArray& buffer = m_helper->m_buffer;

	// Conditional stack.
	CList<CondInfo, CondInfo&> conditionalStack;
	int nestedFalseConditionals = 0;

	// Go 'til the end.
	while (*codePtr != 0)
	{
		LPCTSTR outBolPtr = buffer.GetData() + m_helper->m_outBolPos;

		TokenHelper helper;
		helper.m_tabSize = m_helper->m_tabSize;
		helper.m_outBolPtr = outBolPtr;
		helper.m_file = this;
		helper.m_helper = m_helper;

		// See if it is a command.  Commands can only occur at the beginning
		// of a line.
		if (*codePtr == '!'  &&  *(codePtr + 1) == '!'  &&  codePtr == m_helper->m_codeBolPtr)
		{
			// Move past the exclamation points.
			codePtr += 2;

			// Is it a command comment?
			// !!// This is a comment.
			if (*codePtr == '/'  &&  *(codePtr + 1) == '/')
			{
				// Move past the double slash.
				codePtr += 2;
				
				SkipToEol(codePtr);
				
				continue;
			}

			///////////////////////////////////////////////////////////////////
			// Lex the command token.
			char command[256];
			char *comPtr = command;
			while (*codePtr != 0)
			{
				// Is it a space?
				if (*codePtr == ' ')
				{
					// Break at a space.
					codePtr++;
					break;
				}
				else if (*codePtr == '\n'  ||  *codePtr == '\r')
				{
					break;
				}
				else
				{
					// Copy the command or flag.
					*comPtr++ = *codePtr++;
				}
			}
			*comPtr = 0;

			///////////////////////////////////////////////////////////////////
			// "Conditional" commands
			///////////////////////////////////////////////////////////////////
			// If the last conditional was false, then we ignore until the next
			// endif.
			if (conditionalStack.GetCount() > 0  &&
				conditionalStack.GetTail().m_curState == false)
			{
				CondInfo condInfo = conditionalStack.GetTail();
				if (stricmp(command, "if") == 0)
				{
					SkipToEol(codePtr);
					nestedFalseConditionals++;
					continue;
				}
				else if (stricmp(command, "elif") == 0  ||  stricmp(command, "else") == 0)
				{
					// If we're in nested false conditionals, then ignore.
					if (nestedFalseConditionals > 0)
					{
						SkipToEol(codePtr);
						continue;
					}
				}
				else if (stricmp(command, "endif") == 0)
				{
					// If we're in nested false conditionals, then ignore.
					if (nestedFalseConditionals > 0)
					{
						SkipToEol(codePtr);
						nestedFalseConditionals--;
						continue;
					}
				}
			}

			if (stricmp(command, "if") == 0  ||
				stricmp(command, "elif") == 0)
			{
				// Our CondInfo structure.
				CondInfo condInfo;
				
				// If the command is an elif, then pop the old state.
				if (tolower(command[0]) == 'e')
				{
					// The conditional stack can't be empty on an elif.
					if (conditionalStack.IsEmpty())
					{
						CString err;
						err.Format("!!elif used with no preceding !!if.");
						throw TException(TException::CONDSTACK_EMPTY, err);
					}

					// Get the current conditionalStack state.  We are most 
					// interested in retaining the m_thisLevelTrue variable.
					condInfo = conditionalStack.GetTail();
					
					// Remove the old state, because it was false.
					conditionalStack.RemoveTail();
				}
				
				// if and elif are setup in this format:
				// !!if var [cond] [condCheck]
				// condCheck is only optional if cond doesn't exist.
				// var is required.
				// Get the requested dictionary entry name.
				CString var = ParseToken(codePtr, &helper);
/*				if (var.IsEmpty())
				{
					CString err;
					err.Format("The variable is missing.");
					throw TException(TException::IF_VAR_MISSING, err);
				}
*/
				CString cond = ParseToken(codePtr, &helper);
				CString condCheck = ParseToken(codePtr, &helper);
/*				if (!cond.IsEmpty()  &&  condCheck.IsEmpty())
				{
					CString err;
					err.Format("The conditional is missing.");
					throw TException(TException::IF_COND_CHECKVAR_MISSING, err);
				}
*/
				// Check for a ! symbol.
				bool isNot = false;
				if (!var.IsEmpty()  &&  var[0] == '!')
				{
					isNot = true;
					var = var.Mid(1);
				}
				
				// Lookup the value.
				CString value = var;
				SkipToEol(codePtr);

				bool result;
				if (cond.IsEmpty())
				{
					if (value != "0")
						result = true;
					else
						result = false;
				}
				else
				{
					// There is a conditional expression.  Do it.
					result = CheckCondition(value, cond, condCheck);
				}
				if (isNot)
					result ^= 1;
				if (tolower(command[0]) == 'e'  &&  result)
					result ^= condInfo.m_thisLevelTrue;
				condInfo.m_curState = result;
				condInfo.m_thisLevelTrue |= result;		// Retain the old state.
				conditionalStack.AddTail(condInfo);
				continue;
			}

			///////////////////////////////////////////////////////////////////
			else if (stricmp(command, "else") == 0)
			{
				SkipToEol(codePtr);

				if (conditionalStack.IsEmpty())
				{
					CString err;
					err.Format("!!else used with no preceding !!if.");
					throw TException(TException::CONDSTACK_EMPTY, err);
				}

				// Get the current conditionalStack state.  We are most 
				// interested in retaining the m_thisLevelTrue variable.
				CondInfo condInfo = conditionalStack.GetTail();
				
				conditionalStack.RemoveTail();
				condInfo.m_curState = condInfo.m_thisLevelTrue ^ 1;
				conditionalStack.AddTail(condInfo);
				continue;
			}
			else if (stricmp(command, "endif") == 0)
			{
				SkipToEol(codePtr);

				if (conditionalStack.IsEmpty())
				{
					CString err;
					err.Format("!!endif used with no preceding !!if.");
					throw TException(TException::CONDSTACK_EMPTY, err);
				}

				conditionalStack.RemoveTail();

				continue;
			}
			
			if (conditionalStack.GetCount() > 0  &&
				conditionalStack.GetTail().m_curState == false)
			{
				continue;
			}

			///////////////////////////////////////////////////////////////////
			// Look up the command in the map.
			///////////////////////////////////////////////////////////////////
			WWhizTemplateCommand* commandObject = m_helper->GetCommand(command);
			if (commandObject)
			{
				TemplateCommandArgs args;

				// Found a command.  Build the arg list.
				while (true)
				{
					CString arg = ParseToken(codePtr, &helper);
					if (arg.IsEmpty())
						break;
					args.m_argList.Add(arg);
				}

				// Skip anything else.
				SkipToEol(codePtr);

				// Run the command.
				commandObject->Run(this, args);
				RefreshFileInfo();

				// Parse the next part.
				continue;
			}
			else
			{
				CString err;
				err.Format("Unable to find the command [%s].", command);
				if (AfxMessageBox(err + "\n\nKeep executing?", MB_YESNO) == IDNO)
				{
					throw TException(TException::MISSING_COMMAND, err);
				}
			}
		}

		///////////////////////////////////////////////////////////////////////
		else if (*codePtr == '@'  &&  *(codePtr + 1) == '@')
		{
			// If we're ignoring text, then skip.
			if (conditionalStack.GetCount() > 0  &&  conditionalStack.GetTail().m_curState == false)
			{
				codePtr += 2;
				continue;
			}
			
			// Is it a line continuation?
			// @@backslash
			if (*(codePtr + 2) == '\\')
			{
				SkipToEol(codePtr);
				continue;
			}

			CString out;

			// Ugly, but we need that \0 in there.
			buffer.Add(0);
			buffer.RemoveAt(buffer.GetCount() - 1);

			if (ParseTag(codePtr, out, &helper))
			{
				// Move the output string into the buffer.
				for (int i = 0; i < out.GetLength(); i++)
					buffer.Add(out[i]);
			}
		}
		else
		{
			// See if it is an EOL.
			if (*codePtr == '\n')
			{
				m_helper->m_outBolPos = buffer.GetCount() + 1;
				m_helper->m_codeBolPtr = codePtr + 1;
			}

			// If we're ignoring text, then skip.
			if (conditionalStack.GetCount() > 0  &&  conditionalStack.GetTail().m_curState == false)
			{
				codePtr++;
				continue;
			}
			
			// Copy it straight.
			buffer.Add(*codePtr++);
		}
	}

	// Flush what's left.
	FlushText();

	buffer.RemoveAll();

	return true;
}
Beispiel #5
0
CSize CToolPalette::CalcButtonLocations(int nColumns, bool bCalcOnly)
{
    if (nColumns < 1)
    {
        nColumns = 1;
    }
    bool bHorizontal = (GetCurrentAlignment () & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode

    CRect rectClient;
    GetClientRect (rectClient);

    EDisplayOptions edo = GetToolbarDisplayOptions ();
    if ((edo & eDisplayTitle) != 0)
    {
        if (!bHorizontal)
        {
            rectClient.top += m_nCaptionHeight + 4;
        }
    }
    int xBorders = 0;
    int yBorders = 0;
    if ((edo & eDisplayBorder) != 0)
    {
        const CRect& rectCorners = m_imgCaption.GetParams ().m_rectCorners;
        rectClient.left += rectCorners.left + 3;
        rectClient.top += rectCorners.top;
        xBorders = rectCorners.left + rectCorners.right;
        yBorders = rectCorners.top + rectCorners.bottom;
    }
    else
    {
        rectClient.left += 1;
    }
    if ((edo & eDisplaySizeControl) != 0 && bHorizontal)
    {
        const int sizeControlHeight = m_imgCaption.GetParams ().m_rectImage.Height ();
        yBorders += sizeControlHeight;
        rectClient.top += sizeControlHeight;
    }

    // Consider border area

    CPoint xyPos = rectClient.TopLeft (); // Current position
    bool bPrevSeparator = true; // Indicates that previous button was a separator.
                                // Initial 'true' value prevents separator to appear first.
    CClientDC dc (this);
    CSize szButtonDefault (GetColumnWidth (), GetRowHeight ()); // Default button size to pass to button's OnCalculateSize method
    int nMaxSize = nColumns * (bHorizontal ? szButtonDefault.cy : szButtonDefault.cx) * 11 / 10; // (11/10) adds +10% space here
        // The toolbar height (for horizontal layout) or width (for vertical) of toolbar.

    CList<ButtonStripe, const ButtonStripe&> listStripes;

    ButtonStripe stripe; // Current stripe
    CBCGPToolbarButton* pButton = NULL; // Current button
    for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
    {
        pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos);
        if (pButton == NULL)
        {
            break;
        }

        if (!pButton->IsVisible ())
        {
            continue;
        }

        bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0;
        if (bSep && bPrevSeparator)
        {
            continue;
        }

        //  Layout algorithm:
        // -------------------
        // if (separator) AddPreviousStripe, AddSeparatorStripe, BeginNewStripe
        // else {
        //      AddButton
        //      if (stripe.breadth > default_stripe_breadth)
        //          AddPreviousStripe, BeginNewStripe, AddButton
        // }


        CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal);
        if (bHorizontal)
        {

        }
        else // vertical layout
        {
            if (bSep)
            {
                if (stripe.buttonCount > 0)
                {
                    listStripes.AddTail (stripe);
                }
                stripe.buttonCount = 1;
                stripe.breadth = 0; // separator length is set automatically
                stripe.size = szButton.cy; // cx for horz.
                listStripes.AddTail (stripe);
                stripe = ButtonStripe ();
            }
            else if (szButton.cx > nMaxSize) // this button is larger than current toolbar width
            {
                if (stripe.buttonCount > 0)
                {
                    listStripes.AddTail (stripe);
                }
                stripe.buttonCount = 1;
                stripe.breadth = szButton.cx; // cy for horz.
                stripe.size = szButton.cy; // cx for horz.
                listStripes.AddTail (stripe); // stripe with a single large button
                stripe = ButtonStripe ();
            }
            else // usual button
            {
                if (stripe.breadth + szButton.cx <= nMaxSize)
                {
                    stripe.breadth += szButton.cx;
                    stripe.buttonCount ++;
                    if (szButton.cy > stripe.size)
                        stripe.size = szButton.cy;
                }
                else
                {
                    if (stripe.buttonCount > 0)
                    {
                        listStripes.AddTail (stripe);
                    }
                    stripe.buttonCount = 1;
                    stripe.breadth = szButton.cx; // cy for horz.
                    stripe.size = szButton.cy; // cx for horz.
                }
            }
        }
        bPrevSeparator = bSep;
    }
    if (stripe.buttonCount > 0)
    {
        listStripes.AddTail (stripe);
    }
    if (listStripes.IsEmpty ())
    {
        return CSize (0, 0);
    }
    if (listStripes.GetTail ().breadth == 0) // last item is separator
    {
        listStripes.RemoveTail ();
    }

    // Now calculate total size
    int totalLength = m_nCaptionHeight + 4;
    int maxBreadth = nMaxSize;
    POSITION posStripes = listStripes.GetHeadPosition ();
    while (posStripes != NULL)
    {
        stripe = listStripes.GetNext (posStripes);
        ASSERT (stripe.buttonCount > 0);
        totalLength += stripe.size;
        if (stripe.breadth > maxBreadth)
        {
            maxBreadth = stripe.breadth;
        }
    }

    if (!bCalcOnly)
    {
        CPoint ptButtonPos = rectClient.TopLeft ();

        posStripes = listStripes.GetHeadPosition ();
        stripe = ButtonStripe();

        for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
        {
            pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos);
            if (pButton == NULL)
            {
                break;
            }

            if (!pButton->IsVisible ())
            {
                continue;
            }

            bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0;
            if (bSep && bPrevSeparator)
            {
                continue;
            }

            CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal);
            CRect rcButton (0, 0, 0, 0);

            if (stripe.buttonCount == 0) // this member is decremented below
            {
                ptButtonPos.y += stripe.size;
                if (posStripes == NULL)
                {
                    break;
                }
                stripe = listStripes.GetNext (posStripes);
                ptButtonPos.x = rectClient.left + (maxBreadth - stripe.breadth) / 2; // center-alignment
            }

            if (bSep)
            {
                ASSERT (stripe.breadth == 0);
                ASSERT (stripe.buttonCount == 1);
                rcButton.left = rectClient.left;
                rcButton.top = ptButtonPos.y;
                rcButton.right = rcButton.left + maxBreadth;
                rcButton.bottom = rcButton.top + szButton.cy;
            }
            else
            {
                rcButton.left = ptButtonPos.x;
                rcButton.top = ptButtonPos.y + (stripe.size - szButton.cy) / 2; // center-alignment
                rcButton.right = rcButton.left + szButton.cx;
                rcButton.bottom = rcButton.top + szButton.cy;
                ptButtonPos.x += szButton.cx;
            }
            pButton->SetRect (rcButton);
            stripe.buttonCount --;
        }
    }

    if (m_bAdditionalPixel)
    {
        ++maxBreadth;
    }

    return bHorizontal ? 
        CSize (totalLength + xBorders, maxBreadth + yBorders) :
        CSize (maxBreadth + xBorders, totalLength + yBorders);
}