/** ******************************************************************************* * @file EdnBuf_HighLight.cpp * @brief Editeur De N'ours : Buffer for internal Data - section highlight (Sources) * @author Edouard DUPIN * @date 23/03/2011 * @par Project * Edn * * @par Copyright * Copyright 2010 Edouard DUPIN, all right reserved * * This software is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY. * * Licence summary : * You can modify and redistribute the sources code and binaries. * You can send me the bug-fix * You can not earn money with this Software (if the source extract from Edn * represent less than 50% of original Sources) * Term of the licence in in the file licence.txt. * ******************************************************************************* */ #include "tools_debug.h" #include "tools_globals.h" #include "EdnBuf.h" #undef __class__ #define __class__ "EdnBuf{HighLight}" void EdnBuf::SetHLSystem(Highlight * newHLSystem) { if (m_Highlight != newHLSystem) { m_Highlight = newHLSystem; m_HLDataPass1.clear(); RegenerateHighLightAt(0, 0, m_data.Size()); } } void EdnBuf::RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdded) { GTimeVal timeStart; g_get_current_time(&timeStart); // remove display HL... m_HLDataSequence++; // prevent ERROR... if (NULL == m_Highlight) { return; } // prevent No data Call if( 0 == nbDeleted && 0 == nbAdded) { return; } // normal case EDN_INFO("(pos="<GetName(); } //EDN_DEBUG("HighLight element id=" << i << " S=" << m_HLDataPass1[i].beginStart << " E=" << m_HLDataPass1[i].endStop << " patern name=" << ploppp.c_str() ); } GTimeVal timeStop; g_get_current_time(&timeStop); EDN_DEBUG("HL General = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s"); } void EdnBuf::FindMainHighLightPosition(int32_t startPos, int32_t endPos, int32_t &startId, int32_t &stopId, bool backPreviousNotEnded) { startId = -1; stopId = -1; /* rules to start stop: HighLight data ---- Remove area **** Start pos S End pos E Some Case : ----------- ------------ ------------- ---------- S **** E ----------- ------------ ------------- ---------- S ********** E ----------- ------------ ------------- ---------- S **** E ----------- ------------ ------------- ---------- S ********* E ----------- ------------ ------------- ---------- S ********************* E ----------- ------------ ------------- ---------- S ************************ E ----------- ------------ ------------- ---------- S ***************** E ----------- ------------ ------------- ---------- S *************** E ----------- ------------ S *************** E=-1 ------------ ------------- ---------- S=-1 *************** E */ int32_t i; for (i=0; i< (int32_t)m_HLDataPass1.size(); i++) { if (m_HLDataPass1[i].endStop > startPos) { break; } startId = i; } // go back while the previous element is not eneded if (true == backPreviousNotEnded) { for (i=startId; i>=0; i--) { if (m_HLDataPass1[i].notEnded == false) { break; } startId = i-1; } } int32_t elemStart; if(-1 == startId) { elemStart = 0; } else { elemStart = startId+1; } for (i=elemStart; i< (int32_t)m_HLDataPass1.size(); i++) { if (m_HLDataPass1[i].beginStart > endPos) { stopId = i; break; } } /* if (-1 != startId && startId < (int32_t)m_HLDataPass1.size()) { EDN_DEBUG("==> BEGIN : start="< BEGIN : start=???, stop=??? id=" << startId); } if (-1 != stopId && stopId < (int32_t)m_HLDataPass1.size()) { EDN_DEBUG("==> END : start="< END : start=???, stop=??? id=" << stopId); } */ } void EdnBuf::GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos) { if (NULL == m_Highlight) { return; } //EDN_DEBUG("area : ("<Parse(pos, endPos, m_HLDataPass1, addinPos, m_data); } void EdnBuf::CleanHighLight(void) { // Remove all element in the list... m_HLDataPass1.clear(); } colorInformation_ts *EdnBuf::GetElementColorAtPosition(int32_t pos, int32_t &starPos) { int32_t i; int32_t start = edn_max(0, starPos-1); for (i=start; i<(int32_t)m_HLDataPass1.size(); i++) { starPos = i; if( m_HLDataPass1[i].beginStart <= pos && m_HLDataPass1[i].endStop > pos) { return &m_HLDataPass1[i]; } if(m_HLDataPass1[i].beginStart > pos) { return NULL; } } return NULL; } void EdnBuf::HightlightGenerateLines(displayHLData_ts & MData, int32_t HLStart, int32_t nbLines) { MData.posHLPass1 = 0; MData.posHLPass2 = 0; if (NULL == m_Highlight) { return; } if (MData.idSequence != m_HLDataSequence) { GTimeVal timeStart; g_get_current_time(&timeStart); MData.idSequence = m_HLDataSequence; HLStart = StartOfLine(HLStart); MData.HLData.clear(); int32_t HLStop = CountForwardNLines(HLStart, nbLines); int32_t startId, stopId; // find element previous FindMainHighLightPosition(HLStart, HLStop, startId, stopId, true); int32_t k; //EDN_DEBUG("List of section between : "<< startId << " & " << stopId); int32_t endSearch = stopId+1; if (-1 == stopId) { endSearch = m_HLDataPass1.size(); } for (k=edn_max(startId, 0); k (empty section 1 ) k="< (empty section 2 ) k="< (under section ) k="< (empty section 3 ) k="< (empty section 4 ) k="< pos) { return &MData.HLData[i]; } if(MData.HLData[i].beginStart > pos) { return GetElementColorAtPosition(pos, MData.posHLPass1); } } return GetElementColorAtPosition(pos, MData.posHLPass1); }