From 845232656b6d668c978747e2fb64c7b85defcc2b Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Tue, 24 Apr 2012 13:17:04 +0200 Subject: [PATCH] Moving the scrolling windows is ok when moving cursor --- jni/appl/Buffer/Buffer.cpp | 233 +++------------------------------ jni/appl/Buffer/Buffer.h | 58 ++++---- jni/appl/Buffer/BufferText.cpp | 120 +++++++---------- jni/appl/Buffer/BufferText.h | 7 +- jni/appl/Gui/CodeView.cpp | 11 +- 5 files changed, 108 insertions(+), 321 deletions(-) diff --git a/jni/appl/Buffer/Buffer.cpp b/jni/appl/Buffer/Buffer.cpp index 5676dc5..e1f8d62 100644 --- a/jni/appl/Buffer/Buffer.cpp +++ b/jni/appl/Buffer/Buffer.cpp @@ -43,6 +43,7 @@ Buffer::Buffer() { static int32_t fileBasicID = 0; + m_updatePositionRequested = false; m_fileModify = true; m_haveName = false; etk::UString mString = "Untitle - "; @@ -100,20 +101,6 @@ void Buffer::SetModify(bool status) } } -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ - // TODO : ne marche plus ... -void Buffer::Save(void) -{ - // nothing to do -} - /** * @brief @@ -123,215 +110,27 @@ void Buffer::Save(void) * @return --- * */ -void Buffer::GetInfo(infoStatBuffer_ts &infoToUpdate) +bool Buffer::NeedToUpdateDisplayPosition(void) { - // nothing to do + bool tmpVal = m_updatePositionRequested; + m_updatePositionRequested = false; + return tmpVal; } -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void Buffer::SetLineDisplay(uint32_t lineNumber) +coord2D_ts Buffer::GetBorderSize(void) { - // nothing to do -} - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -int32_t Buffer::Display(ewol::OObject2DTextColored& OOTextNormal, - ewol::OObject2DTextColored& OOTextBold, - ewol::OObject2DTextColored& OOTextItalic, - ewol::OObject2DTextColored& OOTextBoldItalic, ewol::OObject2DColored& OOColored, - int32_t offsetX, int32_t offsetY, int32_t sizeX, int32_t sizeY) -{ - return ERR_NONE; -} - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - * @todo : Set the move up and DOWN... - * - */ -void Buffer::MouseSelectFromCursorTo(int32_t fontId, int32_t width, int32_t height) -{ - // nothing to do + coord2D_ts tmpVal; + tmpVal.x = 30; + tmpVal.y = 30; + return tmpVal; } - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void Buffer::MouseEvent(int32_t fontId, int32_t width, int32_t height) +coord2D_ts Buffer::GetPosition(int32_t fontId,bool& centerRequested) { - // nothing to do + centerRequested = false; + coord2D_ts tmpVal; + tmpVal.x = 0; + tmpVal.y = 0; + return tmpVal; } - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void Buffer::MouseEventDouble(void) -{ - // nothing to do -} - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void Buffer::MouseEventTriple(void) -{ - // nothing to do -} - - -void Buffer::cursorMove(ewol::eventKbMoveType_te moveTypeEvent) -{ - // nothing to do -} - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void Buffer::AddChar(uniChar_t unicodeData) -{ - // nothing to do -} - -void Buffer::Search(etk::UString &data, bool back, bool caseSensitive, bool wrap, bool regExp) -{ - // nothing to do -} - -void Buffer::Replace(etk::UString &data) -{ - // nothing to do -} - -int32_t Buffer::FindLine(etk::UString &data) -{ - // nothing to do - return 0; -} - -void Buffer::JumpAtLine(int32_t newLine) -{ - // nothing to do -} - - -/** - * @brief Get the current line (to know where to jump) - * - * @param --- - * - * @return Return the current line number - * - */ -int32_t Buffer::GetCurrentLine(void) -{ - return 0; -} - - -/** - * @brief request a copy of the selection in the named clipBoard ID - * - * @param[in] clipboardID Id of the buffer we want to get data [0..10] (0 copy normal / 10 middle button) - * - * @return --- - * - */ -void Buffer::Copy(int8_t clipboardID) -{ - // nothing to do -} - - -/** - * @brief Request a copy and a remove of the curent selection in the named clipBoard ID - * - * @param[in] clipboardID Id of the buffer we want to get data [0..10] (0 copy normal / 10 middle button) - * - * @return --- - * - */ -void Buffer::Cut(int8_t clipboardID) -{ - // nothing to do -} - - -/** - * @brief request the past of a specific clipboard on the curent position or selection - * - * @param[in] clipboardID Id of the buffer we want to get data [0..10] (0 copy normal / 10 middle button) - * - * @return --- - * - */ -void Buffer::Paste(int8_t clipboardID) -{ - // nothing to do -} - -void Buffer::RemoveLine(void) -{ - // nothing to do -} - -void Buffer::SelectAll(void) -{ - // nothing to do -} - -void Buffer::SelectNone(void) -{ - // nothing to do -} - -void Buffer::Undo(void) -{ - // nothing to do -} - -void Buffer::Redo(void) -{ - // nothing to do -} - diff --git a/jni/appl/Buffer/Buffer.h b/jni/appl/Buffer/Buffer.h index 43b8260..cd4de18 100644 --- a/jni/appl/Buffer/Buffer.h +++ b/jni/appl/Buffer/Buffer.h @@ -72,45 +72,57 @@ class Buffer { return m_haveName; } - virtual void Save(void); + virtual void Save(void) {}; bool IsModify(void); protected: void SetModify(bool status); virtual void NameChange(void) { /*APPL_DEBUG("check name change ==> no HL change possible");*/}; public: - virtual void GetInfo(infoStatBuffer_ts &infoToUpdate); - virtual void SetLineDisplay(uint32_t lineNumber); + virtual void GetInfo(infoStatBuffer_ts &infoToUpdate) {}; + virtual void SetLineDisplay(uint32_t lineNumber) {}; virtual int32_t Display(ewol::OObject2DTextColored& OOTextNormal, ewol::OObject2DTextColored& OOTextBold, ewol::OObject2DTextColored& OOTextItalic, ewol::OObject2DTextColored& OOTextBoldItalic, - ewol::OObject2DColored& OOColored, int32_t offsetX, int32_t offsetY, int32_t sizeX, int32_t sizeY); - virtual void AddChar(uniChar_t unicodeData); - virtual void cursorMove(ewol::eventKbMoveType_te moveTypeEvent); - virtual void MouseSelectFromCursorTo(int32_t fontId, int32_t width, int32_t height); - virtual void MouseEvent(int32_t fontId, int32_t width, int32_t height); - virtual void MouseEventDouble(void); - virtual void MouseEventTriple(void); - virtual void RemoveLine(void); - virtual void SelectAll(void); - virtual void SelectNone(void); - virtual void Undo(void); - virtual void Redo(void); + ewol::OObject2DColored& OOColored, int32_t offsetX, int32_t offsetY, int32_t sizeX, int32_t sizeY) + { + return ERR_NONE; + } + virtual void AddChar(uniChar_t unicodeData) {}; + virtual void cursorMove(ewol::eventKbMoveType_te moveTypeEvent) {}; + virtual void MouseSelectFromCursorTo(int32_t fontId, int32_t width, int32_t height) {}; + virtual void MouseEvent(int32_t fontId, int32_t width, int32_t height) {}; + virtual void MouseEventDouble(void) {}; + virtual void MouseEventTriple(void) {}; + virtual void RemoveLine(void) {}; + virtual void SelectAll(void) {}; + virtual void SelectNone(void) {}; + virtual void Undo(void) {}; + virtual void Redo(void) {}; virtual void SetCharset(unicode::charset_te newCharset) {}; //virtual void SelectAll(void); - virtual void Copy(int8_t clipboardID); - virtual void Cut(int8_t clipboardID); - virtual void Paste(int8_t clipboardID); - virtual void Search(etk::UString &data, bool back, bool caseSensitive, bool wrap, bool regExp); - virtual void Replace(etk::UString &data); - virtual int32_t FindLine(etk::UString &data); - virtual void JumpAtLine(int32_t newLine); - virtual int32_t GetCurrentLine(void); + virtual void Copy(int8_t clipboardID) {}; + virtual void Cut(int8_t clipboardID) {}; + virtual void Paste(int8_t clipboardID) {}; + virtual void Search(etk::UString &data, bool back, bool caseSensitive, bool wrap, bool regExp) {}; + virtual void Replace(etk::UString &data) {}; + virtual int32_t FindLine(etk::UString &data) { return 0; }; + virtual void JumpAtLine(int32_t newLine) {}; + virtual int32_t GetCurrentLine(void) { return 0; }; virtual int32_t GetNumberOfLine(void) { return 1; }; + // moving with cursor change position: + private: + bool m_updatePositionRequested; + protected: + void RequestUpdateOfThePosition(void) { m_updatePositionRequested = true; }; + public: + bool NeedToUpdateDisplayPosition(void); + virtual coord2D_ts GetBorderSize(void); // this is to requested the minimum size for the buffer that is not consider as visible ... + virtual coord2D_ts GetPosition(int32_t fontId, bool& centerRequested); protected: bool m_fileModify; //!< // naming diff --git a/jni/appl/Buffer/BufferText.cpp b/jni/appl/Buffer/BufferText.cpp index 48b26d9..6daf0dd 100644 --- a/jni/appl/Buffer/BufferText.cpp +++ b/jni/appl/Buffer/BufferText.cpp @@ -66,6 +66,7 @@ void BufferText::BasicInit(void) //m_cursorMode = CURSOR_DISPLAY_MODE_NORMAL; m_displaySize.x = 200; m_displaySize.y = 20; + m_centerRequested = false; } @@ -135,7 +136,7 @@ BufferText::BufferText(etk::File &fileName) : Buffer(fileName) APPL_WARNING("No File ==> created a new one(" << GetFileName() << ")"); SetModify(true); } - RequestPositionUpdate(); + RequestUpdateOfThePosition(); } @@ -332,7 +333,7 @@ int32_t BufferText::Display(ewol::OObject2DTextColored& OOTextNormal, m_EdnBuf.HightlightGenerateLines(m_displayLocalSyntax, displayStartBufferPos, m_displaySize.y); int64_t stopTime = GetCurrentTime(); - APPL_DEBUG("Parsing Highlight = " << stopTime - startTime << " milli-s"); + APPL_DEBUG("Parsing Highlight = " << stopTime - startTime << " micro-s"); uniChar_t displayChar[MAX_EXP_CHAR_LEN]; memset(displayChar, 0, sizeof(uniChar_t)*MAX_EXP_CHAR_LEN); @@ -458,7 +459,7 @@ int32_t BufferText::Display(ewol::OObject2DTextColored& OOTextNormal, } int64_t stopTime2 = GetCurrentTime(); - APPL_DEBUG("DRAW text (brut) = " << stopTime2 - stopTime << " milli-s"); + APPL_DEBUG("DRAW text (brut) = " << stopTime2 - stopTime << " micro-s"); return ERR_NONE; } @@ -546,7 +547,7 @@ void BufferText::MouseEvent(int32_t fontId, int32_t width, int32_t height) }*/ m_EdnBuf.Unselect(SELECTION_PRIMARY); - RequestPositionUpdate(); + RequestUpdateOfThePosition(); } } @@ -589,7 +590,7 @@ void BufferText::MouseSelectFromCursorTo(int32_t fontId, int32_t width, int32_t } } Copy(ewol::clipBoard::CLIPBOARD_SELECTION); - RequestPositionUpdate(); + RequestUpdateOfThePosition(); } @@ -822,12 +823,12 @@ void BufferText::cursorMove(ewol::eventKbMoveType_te moveTypeEvent) SetInsertPosition(m_EdnBuf.EndOfLine(m_cursorPos) ); break; default: - //LastUpDownCursorPosition = -1; + //LastUpDownoutputPosition = -1; needUpdatePosition = false; break; } if ( true == needUpdatePosition) { - RequestPositionUpdate(); + RequestUpdateOfThePosition(); } } @@ -840,81 +841,49 @@ void BufferText::cursorMove(ewol::eventKbMoveType_te moveTypeEvent) * @return --- * */ -bool BufferText::RequestPositionRequest(coord2D_ts& newPos) +coord2D_ts BufferText::GetPosition(int32_t fontId, bool& centerRequested) { - if (-1 == m_requestDisplayPos.x || -1 == m_requestDisplayPos.y) { - return false; - } - newPos = m_requestDisplayPos; - m_requestDisplayPos.x = -1; - m_requestDisplayPos.y = -1; - return true; -} + centerRequested = m_centerRequested; + m_centerRequested = false; + coord2D_ts outputPosition; + // Display position (Y mode): + APPL_INFO("change the position : " << m_cursorPos); + // get the line id of the curent position of the cursor : + outputPosition.y = m_EdnBuf.CountLines(0, m_cursorPos); + // get the first position of the current line + int32_t lineStartPos = m_EdnBuf.StartOfLine(m_cursorPos); + // count the number of char in the line (real displayed char with whar like ) + outputPosition.x = m_EdnBuf.CountDispChars(lineStartPos, m_cursorPos); + APPL_INFO("Curent cursor pos=" << outputPosition); + + // get font porperties : + // TODO : change this : + etkFloat_t letterWidth = ewol::GetWidth(fontId, "A"); + etkFloat_t letterHeight = ewol::GetHeight(fontId); + outputPosition.x *= letterWidth; + outputPosition.y *= letterHeight; + return outputPosition; -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -void BufferText::RequestPositionUpdate(bool centerPage) -{ - m_requestDisplayPos.x = -1; - m_requestDisplayPos.y = -1; -#if 0 - if (centerPage == false) { - /* - // Display position (Y mode): - //APPL_INFO("BufferText::RequestPositionUpdate() m_displayStart(" << m_displayStartPixelX << "px," << m_displayStartLineId << "id) m_displaySize(" << m_displaySize.x << "," < (int32_t)cursorPosition.y - globals::getNbLineBorder() ) { - m_displayStartLineId = cursorPosition.y - globals::getNbLineBorder(); - if (m_displayStartLineId < 0) { - m_displayStartLineId = 0; - } - } else if (m_displayStartLineId + m_displaySize.y <= (int32_t)cursorPosition.y + globals::getNbLineBorder() ) { - m_displayStartLineId = cursorPosition.y - m_displaySize.y + globals::getNbLineBorder() + 1; - } - // Display position (X mode): - //APPL_INFO("cursorPosition X : " << cursorPosition.y << " windows " << m_displayStartLineId << "=>" << m_displayStartPixelX + m_displaySize.x); - if (m_displayStartPixelX > cursorPosition.x - globals::getNbColoneBorder() ) { - m_displayStartPixelX = cursorPosition.x - globals::getNbColoneBorder(); - if (m_displayStartPixelX < 0) { - m_displayStartPixelX = 0; - } - } else if (m_displayStartPixelX + m_displaySize.x <= cursorPosition.x + globals::getNbColoneBorder() ) { - m_displayStartPixelX = cursorPosition.x - m_displaySize.x + globals::getNbColoneBorder() + 1; - } - - //update the buffer position ID : - m_displayStartBufferPos = m_EdnBuf.CountForwardNLines(0, m_displayStartLineId); - */ + /* if we request a center : } else { // center the line at the middle of the screen : - coord2D_ts cursorPosition; + coord2D_ts outputPosition; //APPL_DEBUG(" -------------------------------------------------"); - cursorPosition.y = m_EdnBuf.CountLines(0, m_cursorPos); - //APPL_DEBUG(" cursor position : " << m_cursorPos << " ==> ligne=" << cursorPosition.y); - cursorPosition.x = 0; + outputPosition.y = m_EdnBuf.CountLines(0, m_cursorPos); + //APPL_DEBUG(" cursor position : " << m_cursorPos << " ==> ligne=" << outputPosition.y); + outputPosition.x = 0; m_displayStartPixelX = 0; //APPL_DEBUG(" display size : " << m_displaySize.y); - m_displayStartLineId = cursorPosition.y - m_displaySize.y/2; + m_displayStartLineId = outputPosition.y - m_displaySize.y/2; m_displayStartLineId = edn_max(m_displayStartLineId, 0); m_displayStartBufferPos = m_EdnBuf.CountForwardNLines(0, m_displayStartLineId); //APPL_DEBUG(" display start : " << m_displayStartPixelX << "x" << m_displayStartLineId); //APPL_DEBUG(" -------------------------------------------------"); } -#endif + */ } @@ -1039,7 +1008,7 @@ void BufferText::AddChar(uniChar_t unicodeData) } SetModify(true); - RequestPositionUpdate(); + RequestUpdateOfThePosition(); } @@ -1073,7 +1042,8 @@ void BufferText::JumpAtLine(int32_t newLine) m_EdnBuf.Unselect(SELECTION_PRIMARY); APPL_DEBUG("jump at the line : " << newLine ); SetInsertPosition(positionLine); - RequestPositionUpdate(true); + m_centerRequested = true; + RequestUpdateOfThePosition(); } /** @@ -1132,7 +1102,6 @@ void BufferText::Search(etk::UString &data, bool back, bool caseSensitive, bool int32_t endSelectionPos = foundPos+mVectSearch.Size(); SetInsertPosition(endSelectionPos); m_EdnBuf.Select(SELECTION_PRIMARY, foundPos, endSelectionPos); - RequestPositionUpdate(); } } else { //APPL_INFO("search data Backward : " << data.GetDirectPointer() ); @@ -1150,10 +1119,11 @@ void BufferText::Search(etk::UString &data, bool back, bool caseSensitive, bool int32_t endSelectionPos = foundPos+mVectSearch.Size(); SetInsertPosition(foundPos); m_EdnBuf.Select(SELECTION_PRIMARY, foundPos, endSelectionPos); - RequestPositionUpdate(); } } */ + m_centerRequested = true; + RequestUpdateOfThePosition(); } @@ -1214,7 +1184,7 @@ void BufferText::Cut(int8_t clipboardID) m_EdnBuf.RemoveSelected(SELECTION_PRIMARY); m_cursorPos = SelectionStart; } - RequestPositionUpdate(); + RequestUpdateOfThePosition(); SetModify(true); } @@ -1246,7 +1216,7 @@ void BufferText::Paste(int8_t clipboardID) int32_t size = m_EdnBuf.Insert(m_cursorPos, mVect); m_cursorPos += size; } - RequestPositionUpdate(); + RequestUpdateOfThePosition(); SetModify(true); } @@ -1256,7 +1226,7 @@ void BufferText::Undo(void) int32_t newPos = m_EdnBuf.Undo(); if (newPos >= 0) { SetInsertPosition(newPos, true); - RequestPositionUpdate(); + RequestUpdateOfThePosition(); SetModify(true); } } @@ -1266,7 +1236,7 @@ void BufferText::Redo(void) int32_t newPos = m_EdnBuf.Redo(); if (newPos >= 0) { SetInsertPosition(newPos, true); - RequestPositionUpdate(); + RequestUpdateOfThePosition(); SetModify(true); } } diff --git a/jni/appl/Buffer/BufferText.h b/jni/appl/Buffer/BufferText.h index caa9ac7..d1da163 100644 --- a/jni/appl/Buffer/BufferText.h +++ b/jni/appl/Buffer/BufferText.h @@ -93,13 +93,10 @@ class BufferText : public Buffer { // internal function void BasicInit(void); - // moving the current position of the display windows ... private: - coord2D_ts m_requestDisplayPos; //!< number of char displayable in the screan - void RequestPositionUpdate(bool centerPage = false); + bool m_centerRequested; public: - bool RequestPositionRequest(coord2D_ts& newPos); - + virtual coord2D_ts GetPosition(int32_t fontId, bool& centerRequested); private: bool TextDMoveUp(int32_t offset); bool TextDMoveDown(int32_t offset); diff --git a/jni/appl/Gui/CodeView.cpp b/jni/appl/Gui/CodeView.cpp index 4716995..07e95ff 100644 --- a/jni/appl/Gui/CodeView.cpp +++ b/jni/appl/Gui/CodeView.cpp @@ -156,6 +156,15 @@ void CodeView::OnRegenerateDisplay(void) m_OObjectTextBoldItalic[m_currentCreateId].Clear(); m_OObjectsColored[ m_currentCreateId].Clear(); + APPL_WARNING("plop"); + if (true == BufferManager::Get(m_bufferID)->NeedToUpdateDisplayPosition() ) { + APPL_WARNING("ploppppppp"); + coord2D_ts borderWidth = BufferManager::Get(m_bufferID)->GetBorderSize(); + bool centerRequested = false; + coord2D_ts currentPosition = BufferManager::Get(m_bufferID)->GetPosition(m_OObjectTextNormal[m_currentCreateId].GetFontID(), centerRequested); + SetScrollingPositionDynamic(borderWidth, currentPosition, centerRequested); + + } // else : nothing to do ... // generate the objects : BufferManager::Get(m_bufferID)->Display(m_OObjectTextNormal[m_currentCreateId], @@ -166,7 +175,7 @@ void CodeView::OnRegenerateDisplay(void) m_originScrooled.x, m_originScrooled.y, m_size.x, m_size.y); int64_t stopTime = GetCurrentTime(); - APPL_DEBUG("Display Code Generation = " << stopTime - startTime << " milli-s"); + APPL_DEBUG("Display Code Generation = " << stopTime - startTime << " micro-s"); // call the herited class... WidgetScrooled::OnRegenerateDisplay();