void LIB_CIRCLE::CalcEdit( const wxPoint& aPosition ) { if( m_Flags == IS_NEW || m_Flags == IS_RESIZED ) { m_Radius = KiROUND( GetLineLength( m_Pos, aPosition ) ); } else { Move( m_initialPos + aPosition - m_initialCursorPos ); } }
bool LIB_CIRCLE::HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const { if( aThreshold < 0 ) aThreshold = GetPenSize() / 2; int dist = KiROUND( GetLineLength( aPosRef, aTransform.TransformCoordinate( m_Pos ) ) ); if( abs( dist - m_Radius ) <= aThreshold ) return true; return false; }
void RichEdit::GetLine(int line, TCHAR *text, size_t text_len) const { *((WORD*)text) = WORD(text_len - 1); unsigned size = (unsigned)SendMessage(EM_GETLINE, (WPARAM)line, (LPARAM)text); // Sometimes it likes to return size = lineLen+1, adding an \n at the end, so we remove it here // to make both implementations return same size int lineLen = GetLineLength(line); size = (unsigned)max(0, min((int)text_len - 1, min((int)size, lineLen))); text[size] = _T('\0'); }
long wxTextCtrl::XYToPosition(long x, long y) const { /* It seems, that there is a bug in some versions of the Motif library, so the original wxWin-Code doesn't work. */ /* Widget textWidget = (Widget) handle; return (long) XmTextXYToPos (textWidget, (Position) x, (Position) y); */ /* Now a little workaround: */ long r=0; for (int i=0; i<y; i++) r+=(GetLineLength(i)+1); return r+x; }
//--------------------------------------------------------- void CINFO_Messages::_Add_Text(wxString Text) { int i, n; if( m_MaxLength <= (int)(GetLastPosition() + Text.Length()) ) { for(i=0, n=0; i<GetNumberOfLines() && n<(int)Text.Length(); i++) { n += 1 + GetLineLength(i); } Remove(0, n + 1); } AppendText(Text); }
wxString wxTextCtrl::GetLineText( long lLineNo ) const { long lLen = (long)GetLineLength((long)lLineNo) + 1; wxString sStr; wxChar* zBuf; // // There must be at least enough place for the length WORD in the // buffer // lLen += sizeof(WORD); zBuf = new wxChar[lLen]; if (m_bIsMLE) { long lIndex; long lBuflen; long lCopied; lLen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH, 0, 0); lIndex = lLen * lLineNo; ::WinSendMsg(GetHwnd(), MLM_SETSEL, (MPARAM)lIndex, (MPARAM)lIndex); ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT, MPFROMP(zBuf), MPFROMSHORT((USHORT)WXSIZEOF(zBuf))); lBuflen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH, MPFROMLONG(lIndex), MPFROMLONG(-1)); lCopied = (long)::WinSendMsg(GetHwnd(), MLM_EXPORT, MPFROMP(&lIndex), MPFROMP(&lBuflen)); zBuf[lCopied] = '\0'; } else { WNDPARAMS vParams; vParams.fsStatus = WPM_CCHTEXT; if (::WinSendMsg( GetHwnd() ,WM_QUERYWINDOWPARAMS ,&vParams ,0 )) memcpy((char*)zBuf, vParams.pszText, vParams.cchText); zBuf[vParams.cchText] = '\0'; } sStr = zBuf; delete [] zBuf; return sStr; } // end of wxTextCtrl::GetLineText
bool LIB_ARC::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const { if( aThreshold < 0 ) aThreshold = GetPenSize() / 2; // TODO: use aTransMat to calculates parameters wxPoint relativePosition = aPosition; relativePosition.y = -relativePosition.y; // reverse Y axis int distance = KiROUND( GetLineLength( m_Pos, relativePosition ) ); if( abs( distance - m_Radius ) > aThreshold ) return false; // We are on the circle, ensure we are only on the arc, i.e. between // m_ArcStart and m_ArcEnd wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd); wxPoint startRelativePositionVector = twoPointVector( m_ArcStart, relativePosition ); wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart ); wxPoint centerEndVector = twoPointVector( m_Pos, m_ArcEnd ); wxPoint centerRelativePositionVector = twoPointVector( m_Pos, relativePosition ); // Compute the cross product to check if the point is in the sector double crossProductStart = CrossProduct( centerStartVector, centerRelativePositionVector ); double crossProductEnd = CrossProduct( centerEndVector, centerRelativePositionVector ); // The cross products need to be exchanged, depending on which side the center point // relative to the start point to end point vector lies if( CrossProduct( startEndVector, startRelativePositionVector ) < 0 ) { std::swap( crossProductStart, crossProductEnd ); } // When the cross products have a different sign, the point lies in sector // also check, if the reference is near start or end point return HitTestPoints( m_ArcStart, relativePosition, MINIMUM_SELECTION_DISTANCE ) || HitTestPoints( m_ArcEnd, relativePosition, MINIMUM_SELECTION_DISTANCE ) || ( crossProductStart <= 0 && crossProductEnd >= 0 ); }
int LineEdit::RemoveRectSelection() { Rect rect = GetRectSelection(); WString txt; for(int i = rect.top; i <= rect.bottom; i++) { int l, h; CacheLinePos(i); GetRectSelection(rect, i, l, h); WString s = GetWLine(i); s.Remove(l - GetPos(i), h - l); txt.Cat(s); txt.Cat('\n'); } int l = GetPos(rect.top); int h = GetPos(rect.bottom) + GetLineLength(rect.bottom); if(h < GetLength()) h++; Remove(l, h - l); Insert(l, txt); return GetGPos(rect.bottom, rect.left); }
const char *GetLineString(const char *message, const GSM_CutLines *lines, int start) { static char *retval = NULL; int len=0; if (message == NULL) { free(retval); retval = NULL; return NULL; } len = GetLineLength(message, lines, start); retval = (char *)realloc(retval, len + 1); if (retval == NULL) { dbgprintf(NULL, "Allocation failed!\n"); return NULL; } memcpy(retval, message + lines->numbers[start * 2 - 2], len); retval[len] = '\0'; return retval; }
const char *GetLineString(const char *message, GSM_CutLines *lines, int start) { int len=0; const char *pos; pos = GetLineStringPos(message, lines, start); if (pos == NULL) { return NULL; } len = GetLineLength(message, lines, start); lines->retval = (char *)realloc(lines->retval, len + 1); if (lines->retval == NULL) { dbgprintf(NULL, "Allocation failed!\n"); return NULL; } memcpy(lines->retval, pos, len); lines->retval[len] = '\0'; return lines->retval; }
/* TextEditor::onStyleNeeded * Called when text styling is needed *******************************************************************/ void TextEditor::onStyleNeeded(wxStyledTextEvent& e) { // Get range of lines to be updated int line_start = LineFromPosition(GetEndStyled()); int line_end = LineFromPosition(e.GetPosition()); // Lex until done (end of lines, end of file or end of block comment) int l = line_start; bool force_next = false; while (l <= GetNumberOfLines() && (l <= line_end || force_next)) { int end = GetLineEndPosition(l) - 1; int start = end - GetLineLength(l) + 1; if (start > end) end = start; force_next = lexer.doStyling(this, start, end); l++; } if (txed_fold_enable) lexer.updateFolding(this, line_start); }
bool LineEdit::InsertChar(dword key, int count, bool canow) { if(key == K_TAB && !processtab) return false; if(filter && key >= 32 && key < 65535) key = (*filter)(key); if(!IsReadOnly() && (key >= 32 && key < 65536 || key == '\t' || key == '\n' || key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { if(key >= 128 && key < 65536 && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { int q = cursor; int i = GetLinePos(q); if(q + count - 1 < GetLineLength(i)) Remove(cursor, count); } WString text(key == K_ENTER ? '\n' : key == K_SHIFT_SPACE ? ' ' : key, count); Insert(cursor, text, true); PlaceCaret(cursor + count); Action(); return true; } return false; }
int CCrystalEditView::FormatSelection(int nDelta) { CPoint pStartSel,pEndSel; CString sLineBuf,sBegin; GetSelection(pStartSel,pEndSel); int nStartLine,nEndLine,nLineL; nStartLine=pStartSel.y; nEndLine=pEndSel.y; char cTab[2] ={' ',0}; int nTabsCount=0; int nLC,firstFlg; nLC = nStartLine; firstFlg=1; sBegin=""; nLC-=1+nDelta; if(nLC<0) nLC=0; m_pTextBuffer->BeginUndoGroup(); CString csDelta;//левый отступ for(nLC;nLC<=nEndLine;nLC++) { sLineBuf = GetLineChars(nLC); nLineL = GetLineLength(nLC); //ищем левые пробелы for(int i=0;i<nLineL;i++) { if(IsLetter(sLineBuf.GetAt(i),1)) break; } //удаляем их if(i>0) { if(nStartLine-1-nDelta==nLC)//первая строка в выборке csDelta=sLineBuf.Left(i); m_pTextBuffer->DeleteText(this, nLC, 0, nLC, i, CE_ACTION_TYPING); } //добавляем нужное количество пробелов (табуляции) sLineBuf = GetLineChars(nLC); sLineBuf .TrimLeft(); CString sCutLineBuf; sCutLineBuf = sLineBuf.Left(9); sCutLineBuf.MakeUpper(); CString csSpaces=csDelta; //анализ "табов" для текущей позиции if (!sCutLineBuf.Find("ФУНКЦИЯ")) { nTabsCount=0; csSpaces="";//игнорирование пробелов в первой строке csDelta=""; } else if (!sCutLineBuf.Find("ПРОЦЕДУРА")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if(sCutLineBuf.Left(1)=="#") continue; else if (!sCutLineBuf.Find("КОНЕЦПРОЦ")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if (!sCutLineBuf.Find("КОНЕЦФУНК")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if (!sCutLineBuf.Find("КОНЕЦ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } else if (!sCutLineBuf.Find("ИСКЛЮЧЕНИ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } else if (!sCutLineBuf.Find("ИНАЧЕ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } // if(nTabsCount<0) // nTabsCount=0; //Вставка пробелов for(int j=1;j<=nTabsCount;j++) csSpaces+=cTab; int x,y; if(!csSpaces.IsEmpty()) m_pTextBuffer->InsertText(this, nLC, 0,csSpaces,y,x, CE_ACTION_TYPING); //анализ "табов" для следующей позиции if (!sCutLineBuf.Find("ФУНКЦИЯ")) nTabsCount=1; if (!sCutLineBuf.Find("ПРОЦЕДУРА")) nTabsCount=1; if (!sCutLineBuf.Find("КОНЕЦ")); else if (!sCutLineBuf.Find("ДЛЯ")) nTabsCount++; else if (!sCutLineBuf.Find("ПОКА")) nTabsCount++; else if (!sCutLineBuf.Find("ЕСЛИ")) nTabsCount++; else if (!sCutLineBuf.Find("ПОПЫТКА")) nTabsCount++; else if (!sCutLineBuf.Find("ИНАЧЕ")) nTabsCount++; else if (!sCutLineBuf.Find("ИСКЛЮЧЕНИ")) nTabsCount++; } m_pTextBuffer->FlushUndoGroup(this); return 1; }
DWORD CCrystalTextView:: ParseLineVerilog (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bWasCommentStart = false; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars)) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '$' || (pszChars[nPos] == '\'' && nPos > 0 && (xisalpha (*::CharNext(pszChars + nPos))))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "..." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Extended comment /*...*/ if (dwCookie & COOKIE_EXT_COMMENT) { if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } bWasCommentStart = false; continue; } // Line comment //... if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Preprocessor directive `... if (dwCookie & COOKIE_PREPROCESSOR) { if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = true; continue; } bWasCommentStart = false; if (bFirstChar) { if (pszChars[I] == '`') { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '$' || pszChars[I] == '\'') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsVerilogKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsVerilogFunction (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsVerilogNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsVerilogKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsVerilogFunction (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } else if (IsVerilogNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const { // In case the item has a very tiny width defined, allow it to be selected const int MIN_HIT_TEST_RADIUS = Millimeter2iu( 0.01 ); // calculate aRefPos in XY gerber axis: wxPoint ref_pos = GetXYPosition( aRefPos ); SHAPE_POLY_SET poly; switch( m_Shape ) { case GBR_POLYGON: poly = m_Polygon; return poly.Contains( VECTOR2I( ref_pos ), 0 ); case GBR_SPOT_POLY: poly = GetDcodeDescr()->m_Polygon; poly.Move( m_Start ); return poly.Contains( VECTOR2I( ref_pos ), 0 ); case GBR_SPOT_RECT: return GetBoundingBox().Contains( aRefPos ); case GBR_ARC: { double radius = GetLineLength( m_Start, m_ArcCentre ); VECTOR2D test_radius = VECTOR2D( ref_pos ) - VECTOR2D( m_ArcCentre ); int size = ( ( m_Size.x < MIN_HIT_TEST_RADIUS ) ? MIN_HIT_TEST_RADIUS : m_Size.x ); // Are we close enough to the radius? bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < size ); if( radius_hit ) { // Now check that we are within the arc angle VECTOR2D start = VECTOR2D( m_Start ) - VECTOR2D( m_ArcCentre ); VECTOR2D end = VECTOR2D( m_End ) - VECTOR2D( m_ArcCentre ); double start_angle = NormalizeAngleRadiansPos( start.Angle() ); double end_angle = NormalizeAngleRadiansPos( end.Angle() ); if( m_Start == m_End ) { start_angle = 0; end_angle = 2 * M_PI; } else if( end_angle < start_angle ) { end_angle += 2 * M_PI; } double test_angle = NormalizeAngleRadiansPos( test_radius.Angle() ); return ( test_angle > start_angle && test_angle < end_angle ); } return false; } case GBR_SPOT_MACRO: // Aperture macro polygons are already in absolute coordinates auto p = GetDcodeDescr()->GetMacro()->GetApertureMacroShape( this, m_Start ); for( int i = 0; i < p->OutlineCount(); ++i ) { if( p->Contains( VECTOR2I( aRefPos ), i ) ) return true; } return false; } // TODO: a better analyze of the shape (perhaps create a D_CODE::HitTest for flashed items) int radius = std::min( m_Size.x, m_Size.y ) >> 1; if( radius < MIN_HIT_TEST_RADIUS ) radius = MIN_HIT_TEST_RADIUS; if( m_Flashed ) return HitTestPoints( m_Start, ref_pos, radius ); else return TestSegmentHit( ref_pos, m_Start, m_End, radius ); }
void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aOffset, GBR_DISPLAY_OPTIONS* aDrawOptions ) { // used when a D_CODE is not found. default D_CODE to draw a flashed item static D_CODE dummyD_CODE( 0 ); bool isFilled; int radius; int halfPenWidth; static bool show_err; D_CODE* d_codeDescr = GetDcodeDescr(); if( d_codeDescr == NULL ) d_codeDescr = &dummyD_CODE; COLOR4D color = m_GerberImageFile->GetPositiveDrawColor(); if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) ) color.SetToLegacyHighlightColor(); /* isDark is true if flash is positive and should use a drawing * color other than the background color, else use the background color * when drawing so that an erasure happens. */ bool isDark = !(m_LayerNegative ^ m_GerberImageFile->m_ImageNegative); if( !isDark ) { // draw in background color ("negative" color) color = aDrawOptions->m_NegativeDrawColor; } GRSetDrawMode( aDC, aDrawMode ); isFilled = aDrawOptions->m_DisplayLinesFill; switch( m_Shape ) { case GBR_POLYGON: isFilled = aDrawOptions->m_DisplayPolygonsFill; if( !isDark ) isFilled = true; DrawGbrPoly( aPanel->GetClipBox(), aDC, color, aOffset, isFilled ); break; case GBR_CIRCLE: radius = KiROUND( GetLineLength( m_Start, m_End ) ); halfPenWidth = m_Size.x >> 1; if( !isFilled ) { // draw the border of the pen's path using two circles, each as narrow as possible GRCircle( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), radius - halfPenWidth, 0, color ); GRCircle( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), radius + halfPenWidth, 0, color ); } else // Filled mode { GRCircle( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), radius, m_Size.x, color ); } break; case GBR_ARC: // Currently, arcs plotted with a rectangular aperture are not supported. // a round pen only is expected. #if 0 // for arc debug only GRLine( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), GetABPosition( m_ArcCentre ), 0, color ); GRLine( aPanel->GetClipBox(), aDC, GetABPosition( m_End ), GetABPosition( m_ArcCentre ), 0, color ); #endif if( !isFilled ) { GRArc1( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), GetABPosition( m_End ), GetABPosition( m_ArcCentre ), 0, color ); } else { GRArc1( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), GetABPosition( m_End ), GetABPosition( m_ArcCentre ), m_Size.x, color ); } break; case GBR_SPOT_CIRCLE: case GBR_SPOT_RECT: case GBR_SPOT_OVAL: case GBR_SPOT_POLY: case GBR_SPOT_MACRO: isFilled = aDrawOptions->m_DisplayFlashedItemsFill; d_codeDescr->DrawFlashedShape( this, aPanel->GetClipBox(), aDC, color, m_Start, isFilled ); break; case GBR_SEGMENT: /* Plot a line from m_Start to m_End. * Usually, a round pen is used, but some gerber files use a rectangular pen * In fact, any aperture can be used to plot a line. * currently: only a square pen is handled (I believe using a polygon gives a strange plot). */ if( d_codeDescr->m_Shape == APT_RECT ) { if( m_Polygon.OutlineCount() == 0 ) ConvertSegmentToPolygon(); DrawGbrPoly( aPanel->GetClipBox(), aDC, color, aOffset, isFilled ); } else { if( !isFilled ) { GRCSegm( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), GetABPosition( m_End ), m_Size.x, color ); } else { GRFilledSegment( aPanel->GetClipBox(), aDC, GetABPosition( m_Start ), GetABPosition( m_End ), m_Size.x, color ); } } break; default: if( !show_err ) { wxMessageBox( wxT( "Trace_Segment() type error" ) ); show_err = true; } break; } }
const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const { // return a rectangle which is (pos,dim) in nature. therefore the +1 EDA_RECT bbox( m_Start, wxSize( 1, 1 ) ); D_CODE* code = GetDcodeDescr(); // TODO(JE) GERBER_DRAW_ITEM maybe should actually be a number of subclasses. // Until/unless that is changed, we need to do different things depending on // what is actually being represented by this GERBER_DRAW_ITEM. switch( m_Shape ) { case GBR_POLYGON: { auto bb = m_Polygon.BBox(); bbox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 ); bbox.SetOrigin( bb.GetOrigin().x, bb.GetOrigin().y ); break; } case GBR_CIRCLE: { double radius = GetLineLength( m_Start, m_End ); bbox.Inflate( radius, radius ); break; } case GBR_ARC: { // Note: using a larger-than-necessary BB to simplify computation double radius = GetLineLength( m_Start, m_ArcCentre ); bbox.Move( m_ArcCentre - m_Start ); bbox.Inflate( radius + m_Size.x, radius + m_Size.x ); break; } case GBR_SPOT_CIRCLE: { if( code ) { int radius = code->m_Size.x >> 1; bbox.Inflate( radius, radius ); } break; } case GBR_SPOT_RECT: { if( code ) bbox.Inflate( code->m_Size.x / 2, code->m_Size.y / 2 ); break; } case GBR_SPOT_OVAL: { if( code ) bbox.Inflate( code->m_Size.x, code->m_Size.y ); break; } case GBR_SPOT_POLY: { if( code ) { if( code->m_Polygon.OutlineCount() == 0 ) code->ConvertShapeToPolygon(); bbox.Inflate( code->m_Polygon.BBox().GetWidth() / 2, code->m_Polygon.BBox().GetHeight() / 2 ); } break; } case GBR_SPOT_MACRO: { if( code ) { // Update the shape drawings and the bounding box coordiantes: code->GetMacro()->GetApertureMacroShape( this, m_Start ); // now the bounding box is valid: bbox = code->GetMacro()->GetBoundingBox(); } break; } case GBR_SEGMENT: { if( code && code->m_Shape == APT_RECT ) { if( m_Polygon.OutlineCount() > 0 ) { auto bb = m_Polygon.BBox(); bbox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 ); bbox.SetOrigin( bb.GetOrigin().x, bb.GetOrigin().y ); } } else { int radius = ( m_Size.x + 1 ) / 2; int ymax = std::max( m_Start.y, m_End.y ) + radius; int xmax = std::max( m_Start.x, m_End.x ) + radius; int ymin = std::min( m_Start.y, m_End.y ) - radius; int xmin = std::min( m_Start.x, m_End.x ) - radius; bbox = EDA_RECT( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) ); } break; } default: wxASSERT_MSG( false, wxT( "GERBER_DRAW_ITEM shape is unknown!" ) ); break; } // calculate the corners coordinates in current gerber axis orientations wxPoint org = GetABPosition( bbox.GetOrigin() ); wxPoint end = GetABPosition( bbox.GetEnd() ); // Set the corners position: bbox.SetOrigin( org ); bbox.SetEnd( end ); bbox.Normalize(); return bbox; }
MARKER_PCB* DRC::fillMarker( const TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe ) { wxString textA = aTrack->GetSelectMenuText(); wxString textB; wxPoint position; wxPoint posB; if( aItem ) // aItem might be NULL { textB = aItem->GetSelectMenuText(); if( aItem->Type() == PCB_PAD_T ) { posB = position = ((D_PAD*)aItem)->GetPosition(); } else if( aItem->Type() == PCB_VIA_T ) { posB = position = ((VIA*)aItem)->GetPosition(); } else if( aItem->Type() == PCB_TRACE_T ) { TRACK* track = (TRACK*) aItem; posB = track->GetPosition(); wxPoint endPos = track->GetEnd(); // either of aItem's start or end will be used for the marker position // first assume start, then switch at end if needed. decision made on // distance from end of aTrack. position = track->GetStart(); double dToEnd = GetLineLength( endPos, aTrack->GetEnd() ); double dToStart = GetLineLength( position, aTrack->GetEnd() ); if( dToEnd < dToStart ) position = endPos; } } else position = aTrack->GetPosition(); if( fillMe ) { if( aItem ) fillMe->SetData( aErrorCode, position, textA, aTrack->GetPosition(), textB, posB ); else fillMe->SetData( aErrorCode, position, textA, aTrack->GetPosition() ); } else { if( aItem ) fillMe = new MARKER_PCB( aErrorCode, position, textA, aTrack->GetPosition(), textB, posB ); else fillMe = new MARKER_PCB( aErrorCode, position, textA, aTrack->GetPosition() ); } return fillMe; }
//* Plot a graphic item (outline) relative to a footprint void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge ) { int type_trace; // Type of item to plot. int thickness; // Segment thickness. int radius; // Circle radius. if( aEdge->Type() != PCB_MODULE_EDGE_T ) return; m_plotter->SetColor( getColor( aEdge->GetLayer() ) ); type_trace = aEdge->GetShape(); thickness = aEdge->GetWidth(); wxPoint pos( aEdge->GetStart() ); wxPoint end( aEdge->GetEnd() ); switch( type_trace ) { case S_SEGMENT: m_plotter->ThickSegment( pos, end, thickness, GetMode() ); break; case S_CIRCLE: radius = KiROUND( GetLineLength( end, pos ) ); m_plotter->ThickCircle( pos, radius * 2, thickness, GetMode() ); break; case S_ARC: { radius = KiROUND( GetLineLength( end, pos ) ); double startAngle = ArcTangente( end.y - pos.y, end.x - pos.x ); double endAngle = startAngle + aEdge->GetAngle(); m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetMode() ); } break; case S_POLYGON: { const std::vector<wxPoint>& polyPoints = aEdge->GetPolyPoints(); if( polyPoints.size() <= 1 ) // Malformed polygon break; // We must compute true coordinates from m_PolyList // which are relative to module position, orientation 0 MODULE* module = aEdge->GetParentModule(); std::vector< wxPoint > cornerList; cornerList.reserve( polyPoints.size() ); for( unsigned ii = 0; ii < polyPoints.size(); ii++ ) { wxPoint corner = polyPoints[ii]; if( module ) { RotatePoint( &corner, module->GetOrientation() ); corner += module->GetPosition(); } cornerList.push_back( corner ); } m_plotter->PlotPoly( cornerList, FILLED_SHAPE, thickness ); } break; } }
void CCrystalEditView::OnEditUntab() { if (! QueryEditable() || m_pTextBuffer == NULL) return; BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to left m_bHorzScrollBarLocked = TRUE; for (int L = nStartLine; L <= nEndLine; L ++) { int nLength = GetLineLength(L); if (nLength > 0) { LPCTSTR pszChars = GetLineChars(L); int nPos = 0, nOffset = 0; while (nPos < nLength) { if (pszChars[nPos] == _T(' ')) { nPos ++; if (++ nOffset >= GetTabSize()) break; } else { if (pszChars[nPos] == _T('\t')) nPos ++; break; } } if (nPos > 0) m_pTextBuffer->DeleteText(this, L, 0, L, nPos, CE_ACTION_INDENT); // [JRT] } } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); } else { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if (ptCursorPos.x > 0) { int nTabSize = GetTabSize(); int nOffset = CalculateActualOffset(ptCursorPos.y, ptCursorPos.x); int nNewOffset = nOffset / nTabSize * nTabSize; if (nOffset == nNewOffset && nNewOffset > 0) nNewOffset -= nTabSize; ASSERT(nNewOffset >= 0); LPCTSTR pszChars = GetLineChars(ptCursorPos.y); int nCurrentOffset = 0; int I = 0; while (nCurrentOffset < nNewOffset) { if (pszChars[I] == _T('\t')) nCurrentOffset = nCurrentOffset / nTabSize * nTabSize + nTabSize; else nCurrentOffset ++; I ++; } ASSERT(nCurrentOffset == nNewOffset); ptCursorPos.x = I; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); } } }
void CCrystalEditView::OnEditTab() { if (! QueryEditable() || m_pTextBuffer == NULL) return; BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to right m_bHorzScrollBarLocked = TRUE; static const TCHAR pszText[] = _T("\t"); for (int L = nStartLine; L <= nEndLine; L ++) { int x, y; m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); // [JRT] } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); return; } if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int nLineLength = GetLineLength(ptCursorPos.y); LPCTSTR pszLineChars = GetLineChars(ptCursorPos.y); if (ptCursorPos.x < nLineLength) { int nTabSize = GetTabSize(); int nChars = nTabSize - CalculateActualOffset(ptCursorPos.y, ptCursorPos.x) % nTabSize; ASSERT(nChars > 0 && nChars <= nTabSize); while (nChars > 0) { if (ptCursorPos.x == nLineLength) break; if (pszLineChars[ptCursorPos.x] == _T('\t')) { ptCursorPos.x ++; break; } ptCursorPos.x ++; nChars --; } ASSERT(ptCursorPos.x <= nLineLength); ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); static const TCHAR pszText[] = _T("\t"); int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); }
DWORD CCrystalTextView:: ParseLineInnoSetup (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & (COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2); LPCTSTR pszChars = GetLineChars (nLineIndex); BOOL bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; BOOL bRedefineBlock = TRUE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else if (dwCookie & COOKIE_SECTION) { DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = TRUE; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = TRUE; } continue; } // Extended comment (*....*) if (dwCookie & COOKIE_EXT_COMMENT) { // if (I > 0 && pszChars[I] == ')' && pszChars[nPrevI] == '*') if ((I > 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*' && *::CharPrev(pszChars, pszChars + nPrevI) != '(') || (I == 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = TRUE; } continue; } // Extended comment {....} if (dwCookie & COOKIE_EXT_COMMENT2) { if (pszChars[I] == '}') { dwCookie &= ~COOKIE_EXT_COMMENT2; bRedefineBlock = TRUE; } continue; } if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Section header [...] if (dwCookie & COOKIE_SECTION) { if (pszChars[I] == ']') { dwCookie &= ~COOKIE_SECTION; bRedefineBlock = TRUE; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '(') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; continue; } if (pszChars[I] == '{') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT2; continue; } if (bFirstChar) { if (pszChars[I] == ';') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; continue; } if (pszChars[I] == '#') { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (pszChars[I] == '[') { DEFINE_BLOCK (I, COLORINDEX_FUNCNAME); dwCookie |= COOKIE_SECTION; continue; } if (!xisspace (pszChars[I])) bFirstChar = FALSE; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsInnoSetupKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsInnoSetupNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsInnoSetupKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsInnoSetupNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1)) dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2); return dwCookie; }
/** * Style needed */ void FbEditor::onStyleNeeded(wxStyledTextEvent & event) { // startint position auto startPos = GetEndStyled(); auto startLine = LineFromPosition(startPos); startPos = PositionFromLine(startLine); // end position int lastPos = event.GetPosition(); int lastLine = std::max(LineFromPosition(lastPos), std::min(GetLineCount(), GetFirstVisibleLine() + LinesOnScreen())); lastPos = GetLineEndPosition(lastLine); // get token auto token = m_srcCtx->getLine(startLine, lastLine); // set stylling position StartStyling(startPos, INT_MAX); // clear indicatirs SetIndicatorCurrent(ErrorIndicator); IndicatorClearRange(startPos, lastPos - startPos); // no token? just colour to default if (!token) { style(lastPos - startPos, TokenStyle::Default); return; } // style the tokens int line = startLine; int col = 0; while (token && line <= lastLine) { // end of the line? if (token->getKind() == TokenKind::EndOfLine) { token = token->getNext(); continue; } // token line int tline = token->getLine(); // token started before current line if (line > tline) { int start = PositionFromLine(line); int end = PositionFromLine(token->getEndLine()) + token->getEndCol(); style(end - start, token); // end on line and column col = token->getEndCol(); line = token->getEndLine(); // get next token and continue token = token->getNext(); continue; } // empty lines before next token? if (line < tline) { int start = PositionFromLine(line) + col; int end = PositionFromLine(tline) + token->getCol(); style(end - start, TokenStyle::Default); // end on line and column line = token->getLine(); col = token->getCol(); continue; } // started on the current line if (line == tline) { // empty space ? if (token->getCol() > col) { style(token->getCol() - col, TokenStyle::Default); } // style the token style(token->getLength(), token); col = token->getEndCol(); line = token->getEndLine(); // advance to the next one token = token->getNext(); continue; } // some empty space till end of the line int length = GetLineLength(line); if (col < length) { style(length - col, TokenStyle::Default); } // incement line line++; col = 0; } }
/** * @brief 強調表示文字列の検索 * @param pBeforeBetween 前の行の持ち越し色分け * @param plsWords 強調表示文字列リスト * @return 変更に変化があった場合trueが返る */ bool CFootyLine::SearchEmphasis(TakeOver *pBeforeBetween, LsWords *plsWords) { if (!plsWords)return false; // 宣言 WordPt pNowWord; //!< 現在走査中の強調表示文字列 TakeOver::iterator pNowBefore; //!< 前データセット用 const wchar_t *pNowChar = GetLineData(); //!< 現在走査中の文字列 size_t nStringLen = GetLineLength(); //!< 文字列の長さ CStaticStack<WordPt,sizeof(int)*8> cEmpStack; //!< 現在色つけしているスタック EmpPos stInsert; //!< 挿入する構造体 // 初期化 TakeOver vecBetweenBackup; vecBetweenBackup = m_vecLineBetweenAfter; m_vecColorInfo.clear(); m_vecLineBetweenAfter.clear(); // 前からのデータをセットする if (pBeforeBetween){ // データが存在するときのみ stInsert.m_nPosition = 0; stInsert.m_bIsStart = true; for (pNowBefore=pBeforeBetween->begin();pNowBefore!=pBeforeBetween->end();pNowBefore++){ (*pNowBefore)->m_bDuplix = true; // 重複チェック stInsert.m_Color = (*pNowBefore)->GetColor(); // コマンドをリストへ m_vecColorInfo.push_back(stInsert); cEmpStack.push(*pNowBefore); } } // 小文字化 std::wstring strLower = GetLineData(); const wchar_t *pNowLower = strLower.c_str(); CEmphasisWord::SetLower(&strLower[0], nStringLen); // 検索していく for (size_t i=0;i<nStringLen;i++,pNowChar++,pNowLower++) { bool bWordSkipped = false; // 文字列を走査していく for (pNowWord=plsWords->begin();pNowWord!=plsWords->end();pNowWord++) { // この文字が無効であるかチェックする if (pNowWord->m_bDuplix)continue; // 重複チェック if (i != 0) { if (pNowWord->IsOnlyHead())continue; // 先頭に限る if (!pNowWord->CheckIndependence(pNowChar-1,false)) // 独立性チェック(前) continue; } if (cEmpStack.size() == 0) { if (!pNowWord->IsPermitted(0))continue; } else { if (!pNowWord->IsPermitted(cEmpStack.top()->GetLevel()))continue; } if (nStringLen - i < pNowWord->GetLen1()) // 文字の長さは十分か? { continue; } if (nStringLen - i != pNowWord->GetLen1()) { if (!pNowWord->CheckIndependence (pNowChar+pNowWord->GetLen1(),true)) // 独立性チェック(後) continue; } // 文字が一致するかチェック if (!MATCH_STR(pNowWord->GetString1(),pNowWord->GetLen1())) continue; // 開始コマンドを挿入する stInsert.m_nPosition = i; stInsert.m_Color = pNowWord->GetColor(); stInsert.m_bIsStart = true; m_vecColorInfo.push_back(stInsert); // インデックス番号を先へ移動させる i += pNowWord->GetLen1() - 1; pNowChar += pNowWord->GetLen1() - 1; pNowLower+= pNowWord->GetLen1() - 1; bWordSkipped = true; // 強調表示情報によって場合分け if (pNowWord->GetType() == EMP_WORD){ // 単語の時は、それの終了コマンドを挿入する stInsert.m_nPosition = i + 1; stInsert.m_bIsStart = false; m_vecColorInfo.push_back(stInsert); } else{ // スタックを積む pNowWord->m_bDuplix = true; cEmpStack.push(pNowWord); } // 次の文字のループへ移動する goto To_NextLoop; } //終了をチェック if (cEmpStack.size()){ pNowWord = cEmpStack.top(); // 二個目の単語当たりをチェック if ((pNowWord->GetType() == EMP_MULTI_BETWEEN || pNowWord->GetType() == EMP_LINE_BETWEEN) && nStringLen - i >= pNowWord->GetLen2()){ if (MATCH_STR(pNowWord->GetString2(),pNowWord->GetLen2())){ // インデックス番号を先へ移動させる i += pNowWord->GetLen2() - 1; pNowChar += pNowWord->GetLen2() - 1; pNowLower += pNowWord->GetLen2() - 1; bWordSkipped = true; // 終了コマンドを挿入する stInsert.m_nPosition = i + 1; stInsert.m_bIsStart = false; m_vecColorInfo.push_back(stInsert); // スタックを排除 pNowWord->m_bDuplix = false; cEmpStack.pop(); } } } // 次のループへ To_NextLoop:; // サロゲートペアの1文字目で、強調表示が見つからなかったときはさらに一つ進めておく if (!bWordSkipped && IsSurrogateLead(*pNowChar)){ pNowChar++;i++; } } // 次のベクトルへ for (;cEmpStack.size();){ if (cEmpStack.top()->GetType() == EMP_MULTI_BETWEEN) m_vecLineBetweenAfter.push_back(cEmpStack.top()); cEmpStack.top()->m_bDuplix = false; cEmpStack.pop(); } m_bEmphasisChached = true; return !(vecBetweenBackup == m_vecLineBetweenAfter); }
DWORD CCrystalTextView:: ParseLineSgml (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.') { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } // Extended comment <!--....--> if (dwCookie & COOKIE_EXT_COMMENT) { if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-') { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } continue; } // Extended comment <?....?> if (dwCookie & COOKIE_EXT_USER1) { if (I > 0 && pszChars[I] == '>' && pszChars[nPrevI] == '?') { dwCookie &= ~COOKIE_EXT_USER1; bRedefineBlock = true; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); I += 3; dwCookie |= COOKIE_EXT_COMMENT; dwCookie &= ~COOKIE_PREPROCESSOR; continue; } if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (dwCookie & COOKIE_PREPROCESSOR) { if (IsSgmlKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { goto next; } } else if (dwCookie & COOKIE_USER1) { if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else { goto next; } } else if (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { goto next; } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; next: ; } // Preprocessor start: < or bracket if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') || pszChars[I] == '{') { DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; nIdentBegin = -1; continue; } // Preprocessor end: > or bracket if (dwCookie & COOKIE_PREPROCESSOR) { if (pszChars[I] == '>' || pszChars[I] == '}') { dwCookie &= ~COOKIE_PREPROCESSOR; nIdentBegin = -1; bRedefineBlock = true; bDecIndex = true; continue; } } // Preprocessor start: & if (pszChars[I] == '&') { dwCookie |= COOKIE_USER1; nIdentBegin = -1; continue; } // Preprocessor end: ; if (dwCookie & COOKIE_USER1) { if (pszChars[I] == ';') { dwCookie &= ~COOKIE_USER1; nIdentBegin = -1; continue; } } } } if (nIdentBegin >= 0 && (dwCookie & COOKIE_PREPROCESSOR)) { if (IsSgmlKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } // Preprocessor start: < or { if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') || pszChars[I] == '{') { DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; nIdentBegin = -1; goto end; } // Preprocessor end: > or } if (dwCookie & COOKIE_PREPROCESSOR) { if (pszChars[I] == '>' || pszChars[I] == '}') { dwCookie &= ~COOKIE_PREPROCESSOR; nIdentBegin = -1; } } end: dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1); return dwCookie; }
void CCrystalEditView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CCrystalTextView::OnChar(nChar, nRepCnt, nFlags); if ((::GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0 || (::GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0) return; if (nChar ==32 || nChar == VK_RETURN) if(nCursorColor==COLORINDEX_NORMALTEXT||nCursorColor==COLORINDEX_KEYWORD) {//анализ на предмет использования шаблонов CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if(ptCursorPos.y>=0&&ptCursorPos.y<GetLineCount()) { CString Str = GetLineChars(ptCursorPos.y); int nLength = GetLineLength(ptCursorPos.y); Str=Str.Left(min(ptCursorPos.x,nLength)); CValue vDeleteText; CValue vInsertText; extern int AfxCallInitProc(CString csName,CValue Param,CValue &vDeleteText,CValue &vInsertText); int nRet=AfxCallInitProc("ПриВыбореШаблона",String(Str),vDeleteText,vInsertText); if(nRet) { int nDeleteCount=vDeleteText.GetString().GetLength(); int nStartPos=max(0,ptCursorPos.x-nDeleteCount); if(nDeleteCount>0) m_pTextBuffer->DeleteText(this, ptCursorPos.y, nStartPos, ptCursorPos.y, ptCursorPos.x, CE_ACTION_TYPING); int x, y; CString csStrInsert=vInsertText.GetString(); m_pTextBuffer->InsertText(this, ptCursorPos.y, nStartPos, csStrInsert, y, x, CE_ACTION_TYPING); CPoint ptEnd; ptEnd.x=x; ptEnd.y=y; ptCursorPos.x=0; SetSelection(ptCursorPos, ptEnd); FormatSelection(0); ptEnd.y-=(csStrInsert.Replace("\r","\r")+1)/2; ptEnd.x=GetLineLength(ptEnd.y); SetSelection(ptEnd, ptEnd); SetAnchor(ptEnd); SetCursorPos(ptEnd); EnsureVisible(ptEnd); MoveEnd(0); } } } BOOL bTranslated = FALSE; if (nChar == VK_RETURN) { if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if (ptCursorPos.y < GetLineCount() - 1) { ptCursorPos.x = 0; ptCursorPos.y++; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); if (QueryEditable() && m_pTextBuffer != NULL) { DeleteCurrentSelection(); int x, y; CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); const static TCHAR pszText[3] = _T("\r\n"); m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] int nLenght = GetLineLength(ptCursorPos.y); CString sLineBuf = GetLineChars(ptCursorPos.y); CString sBegin=""; for(int i=0;i<=nLenght;i++) { char cChr; cChr = sLineBuf.GetAt(i); if(!IsLetter(cChr,1)) sBegin+=cChr; else break; } int nPos=ptCursorPos.x; m_pTextBuffer->InsertText(this,y,x, sBegin, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); /* FormatSelection(-1); if(nPos>0) { MoveEnd(0); } */ } m_pTextBuffer->FlushUndoGroup(this); return; } if (nChar > 31) { if (QueryEditable() && m_pTextBuffer != NULL) { BOOL bUndoBeginGroup=m_pTextBuffer->m_bUndoGroup; if(!bUndoBeginGroup) m_pTextBuffer->BeginUndoGroup(nChar != _T(' ')); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); CPoint ptCursorPos; if (ptSelStart != ptSelEnd) { ptCursorPos = ptSelStart; DeleteCurrentSelection(); } else { ptCursorPos = GetCursorPos(); if (m_bOvrMode && ptCursorPos.x < GetLineLength(ptCursorPos.y)) m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCursorPos.y, ptCursorPos.x + 1, CE_ACTION_TYPING); // [JRT] } ASSERT_VALIDTEXTPOS(ptCursorPos); char pszText[2]; pszText[0] = (char) nChar; pszText[1] = 0; int x,y; USES_CONVERSION; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, A2T(pszText), y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); if(!bUndoBeginGroup) m_pTextBuffer->FlushUndoGroup(this); } } }
DWORD CCrystalTextView:: ParseLineSiod (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); BOOL bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; BOOL bRedefineBlock = TRUE; BOOL bWasCommentStart = FALSE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; BOOL bDefun = FALSE; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.') { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = TRUE; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = TRUE; } continue; } // Extended comment /*....*/ if (dwCookie & COOKIE_EXT_COMMENT) { // if (I > 0 && pszChars[I] == ';' && pszChars[nPrevI] == '|') if ((I > 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = TRUE; } bWasCommentStart = FALSE; continue; } if (I > 0 && pszChars[I] != '|' && pszChars[nPrevI] == ';') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (I > 0 && pszChars[I] == '|' && pszChars[nPrevI] == ';') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = TRUE; continue; } bWasCommentStart = FALSE; if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = FALSE; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsSiodKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { if (!_tcsnicmp (_T ("defun"), pszChars + nIdentBegin, 5)) { bDefun = TRUE; } DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsSiodNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; if (!bDefun) { for (int j = nIdentBegin; --j >= 0;) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (!bFunction) { for (int j = I; j >= 0; j--) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsSiodKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { if (!_tcsnicmp (_T ("defun"), pszChars + nIdentBegin, 5)) { bDefun = TRUE; } DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsSiodNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; if (!bDefun) { for (int j = nIdentBegin; --j >= 0;) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (!bFunction) { for (int j = I; j >= 0; j--) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
void TRACK::DrawShortNetname( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, EDA_COLOR_T aBgColor ) { /* we must filter tracks, to avoid a lot of texts. * - only tracks with a length > 10 * thickness are eligible * and, of course, if we are not printing the board */ if( DisplayOpt.DisplayNetNamesMode == 0 || DisplayOpt.DisplayNetNamesMode == 1 ) return; #define THRESHOLD 10 int len = KiROUND( GetLineLength( m_Start, m_End ) ); if( len < THRESHOLD * m_Width ) return; // no room to display a text inside track if( aDC->LogicalToDeviceXRel( m_Width ) < MIN_TEXT_SIZE ) return; if( GetNetCode() == NETINFO_LIST::UNCONNECTED ) return; NETINFO_ITEM* net = GetNet(); if( net == NULL ) return; int textlen = net->GetShortNetname().Len(); if( textlen > 0 ) { // calculate a good size for the text int tsize = std::min( m_Width, len / textlen ); int dx = m_End.x - m_Start.x ; int dy = m_End.y - m_Start.y ; wxPoint tpos = m_Start + m_End; tpos.x /= 2; tpos.y /= 2; // Calculate angle: if the track segment is vertical, angle = 90 degrees // If horizontal 0 degrees, otherwise compute it double angle; // angle is in 0.1 degree if( dy == 0 ) // Horizontal segment { angle = 0; } else { if( dx == 0 ) // Vertical segment { angle = 900; } else { /* atan2 is *not* the solution here, since it can give upside down text. We want to work only in the first and fourth quadrant */ angle = RAD2DECIDEG( -atan( double( dy ) / double( dx ) ) ); } } LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; if( ( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) && ( !(!IsOnLayer( curr_layer )&& DisplayOpt.ContrastModeDisplay) ) ) { if( (aDrawMode & GR_XOR) == 0 ) GRSetDrawMode( aDC, GR_COPY ); tsize = (tsize * 7) / 10; // small reduction to give a better look EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL; DrawGraphicHaloText( clipbox, aDC, tpos, aBgColor, BLACK, WHITE, net->GetShortNetname(), angle, wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false ); } } }
DWORD CCrystalTextView:: ParseLineFortran (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } if (pszChars[I] == '!' || !I && (pszChars[I] == 'C' || pszChars[I] == 'c')) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsFortranKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsFortranNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsFortranKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsFortranNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1)) dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
/** * Function Magnetize * tests to see if there are any magnetic items within near reach of the given * "curpos". If yes, then curpos is adjusted appropriately according to that * near magnetic item and true is returned. * @param frame = the current frame * @param aCurrentTool = the current tool id (from vertical right toolbar) * @param aGridSize = the current grid size * @param on_grid = the on grid position near initial position ( often on_grid = curpos) * @param curpos The initial position, and what to adjust if a change is needed. * @return bool - true if the position was adjusted magnetically, else false. */ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ) { bool doCheckNet = g_MagneticPadOption != capture_always && g_Drc_On; bool doTrack = false; bool doPad = false; bool amMovingVia = false; BOARD* m_Pcb = frame->GetBoard(); TRACK* currTrack = g_CurrentTrackSegment; BOARD_ITEM* currItem = frame->GetCurItem(); PCB_SCREEN* screen = frame->GetScreen(); wxPoint pos = frame->RefPos( true ); // D( printf( "currTrack=%p currItem=%p currTrack->Type()=%d currItem->Type()=%d\n", currTrack, currItem, currTrack ? currTrack->Type() : 0, currItem ? currItem->Type() : 0 ); ) if( !currTrack && currItem && currItem->Type()==PCB_VIA_T && currItem->GetFlags() ) { // moving a VIA currTrack = (TRACK*) currItem; amMovingVia = true; return false; // comment this return out and play with it. } else if( currItem != currTrack ) { currTrack = NULL; } if( g_MagneticPadOption == capture_always ) doPad = true; if( g_MagneticTrackOption == capture_always ) doTrack = true; if( aCurrentTool == ID_TRACK_BUTT || amMovingVia ) { int q = capture_cursor_in_track_tool; if( g_MagneticPadOption == q ) doPad = true; if( g_MagneticTrackOption == q ) doTrack = true; } // D(printf("doPad=%d doTrack=%d aCurrentTool=%d amMovingVia=%d\n", doPad, doTrack, aCurrentTool, amMovingVia );) // The search precedence order is pads, then tracks/vias if( doPad ) { LSET layer_mask( screen->m_Active_Layer ); D_PAD* pad = m_Pcb->GetPad( pos, layer_mask ); if( pad ) { if( doCheckNet && currTrack && currTrack->GetNetCode() != pad->GetNetCode() ) return false; *curpos = pad->GetPosition(); return true; } } // after pads, only track & via tests remain, skip them if not desired if( doTrack ) { LAYER_ID layer = screen->m_Active_Layer; for( TRACK* via = m_Pcb->m_Track; via && (via = via->GetVia( *curpos, layer )) != NULL; via = via->Next() ) { if( via != currTrack ) // a via cannot influence itself { if( !doCheckNet || !currTrack || currTrack->GetNetCode() == via->GetNetCode() ) { *curpos = via->GetStart(); // D(printf("via hit\n");) return true; } } } if( !currTrack ) { LSET layers( layer ); TRACK* track = m_Pcb->GetVisibleTrack( m_Pcb->m_Track, pos, layers ); if( !track || track->Type() != PCB_TRACE_T ) { // D(printf("!currTrack and track=%p not found, layer_mask=0x%X\n", track, layer_mask );) return false; } // D( printf( "Project\n" ); ) return Project( curpos, on_grid, track ); } /* * In two segment mode, ignore the final segment if it's inside a grid square. */ if( !amMovingVia && currTrack && g_TwoSegmentTrackBuild && currTrack->Back() && currTrack->GetStart().x - aGridSize.x < currTrack->GetEnd().x && currTrack->GetStart().x + aGridSize.x > currTrack->GetEnd().x && currTrack->GetStart().y - aGridSize.y < currTrack->GetEnd().y && currTrack->GetStart().y + aGridSize.y > currTrack->GetEnd().y ) { currTrack = currTrack->Back(); } for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() ) { if( track->Type() != PCB_TRACE_T ) continue; if( doCheckNet && currTrack && currTrack->GetNetCode() != track->GetNetCode() ) continue; if( m_Pcb->IsLayerVisible( track->GetLayer() ) == false ) continue; // omit the layer check if moving a via if( !amMovingVia && !track->IsOnLayer( layer ) ) continue; if( !track->HitTest( *curpos ) ) continue; // D(printf( "have track prospect\n");) if( Join( curpos, track->GetStart(), track->GetEnd(), currTrack->GetStart(), currTrack->GetEnd() ) ) { // D(printf( "join currTrack->Type()=%d\n", currTrack->Type() );) return true; } if( aCurrentTool == ID_TRACK_BUTT || amMovingVia ) { // At this point we have a drawing mouse on a track, we are drawing // a new track and that new track is parallel to the track the // mouse is on. Find the nearest end point of the track under mouse // to the mouse and return that. double distStart = GetLineLength( *curpos, track->GetStart() ); double distEnd = GetLineLength( *curpos, track->GetEnd() ); // if track not via, or if its a via dragging but not with its adjacent track if( currTrack->Type() != PCB_VIA_T || ( currTrack->GetStart() != track->GetStart() && currTrack->GetStart() != track->GetEnd() )) { double max_dist = currTrack->GetWidth() / 2.0f; if( distStart <= max_dist ) { // D(printf("nearest end is start\n");) *curpos = track->GetStart(); return true; } if( distEnd <= max_dist ) { // D(printf("nearest end is end\n");) *curpos = track->GetEnd(); return true; } // @todo otherwise confine curpos such that it stays centered within "track" } } } } return false; }