diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ui/edit.cpp | 238 | ||||
-rw-r--r-- | src/ui/edit.h | 2 |
3 files changed, 74 insertions, 168 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72fcee6..c873d89 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -196,6 +196,7 @@ ${Boost_LIBRARIES} ${LIBSNDFILE_LIBRARY} ${OPTIONAL_LIBS} ${PLATFORM_LIBS} +clipboard ) # Local @@ -216,6 +217,7 @@ ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} ${LIBSNDFILE_INCLUDE_DIR} ${OPTIONAL_INCLUDE_DIRS} +${CLIPBOARD_DIR} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index e60a040..7e657c8 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -20,6 +20,8 @@ #include "app/app.h" +#include "clipboard/clipboard.h" + #include <string.h> namespace Ui { @@ -298,55 +300,53 @@ bool CEdit::EventProcess(const Event &event) bShift = ( (event.kmodState & KEY_MOD(SHIFT) ) != 0 ); bControl = ( (event.kmodState & KEY_MOD(CTRL) ) != 0); - if ( (event.key.unicode == 'X' && !bShift && bControl) || - ((event.kmodState & KEY_MOD(CTRL)) != 0 && bShift && !bControl) ) + if ( (event.key.key == KEY(x) && !bShift && bControl) || + (event.key.key == KEY(DELETE) && bShift && !bControl) ) { Cut(); return true; } - if ( (event.key.unicode == 'C' && !bShift && bControl) || - ((event.kmodState & KEY_MOD(CTRL)) != 0 && !bShift && bControl) ) + if ( (event.key.key == KEY(c) && !bShift && bControl) || + (event.key.key == KEY(INSERT) && !bShift && bControl) ) { Copy(); return true; } - if ( (event.key.unicode == 'V' && !bShift && bControl) || - ((event.kmodState & KEY_MOD(CTRL)) != 0 && bShift && !bControl) ) + if ( (event.key.key == KEY(v) && !bShift && bControl) || + (event.key.key == KEY(INSERT) && bShift && !bControl) ) { Paste(); return true; } - if ( event.key.unicode == 'A' && !bShift && bControl ) + if ( event.key.key == KEY(a) && !bShift && bControl ) { SetCursor(999999, 0); return true; } - if ( event.key.unicode == 'O' && !bShift && bControl ) + if ( event.key.key == KEY(o) && !bShift && bControl ) { Event newEvent(EVENT_STUDIO_OPEN); -// m_event->NewEvent(newEvent, EVENT_STUDIO_OPEN); m_event->AddEvent(newEvent); } - if ( event.key.unicode == 'S' && !bShift && bControl ) + if ( event.key.key == KEY(s) && !bShift && bControl ) { Event newEvent( EVENT_STUDIO_SAVE ); -// m_event->MakeEvent(newEvent, EVENT_STUDIO_SAVE); m_event->AddEvent(newEvent); } - if ( event.key.unicode == 'Z' && !bShift && bControl ) + if ( event.key.key == KEY(z) && !bShift && bControl ) { Undo(); return true; } - if ( event.key.unicode == 'U' && !bShift && bControl ) + if ( event.key.key == KEY(u) && !bShift && bControl ) { if ( MinMaj(false) ) return true; } - if ( event.key.unicode == 'U' && bShift && bControl ) + if ( event.key.key == KEY(u) && bShift && bControl ) { if ( MinMaj(true) ) return true; } @@ -2501,200 +2501,100 @@ void CEdit::ColumnFix() // Cut the selected characters or entire line. -bool CEdit::Cut() // TODO MS Windows allocations +bool CEdit::Cut() { - /* HGLOBAL hg; - char* text; - char c; - int c1, c2, start, len, i, j; - - if ( !m_bEdit ) return false; - - c1 = m_cursor1; - c2 = m_cursor2; - if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2 - - if ( c1 == c2 ) - { - while ( c1 > 0 ) - { - if ( m_text[c1-1] == '\n' ) break; - c1 --; - } - while ( c2 < m_len ) - { - c2 ++; - if ( m_text[c2-1] == '\n' ) break; - } - } - - if ( c1 == c2 ) return false; - - start = c1; - len = c2-c1; - - if ( !(hg = GlobalAlloc(GMEM_DDESHARE, len*2+1)) ) - { - return false; - } - if ( !(text = (char*)GlobalLock(hg)) ) - { - GlobalFree(hg); - return false; - } - - j = 0; - for ( i=start ; i<start+len ; i++ ) - { - c = m_text[i]; - if ( c == '\n' ) text[j++] = '\r'; - text[j++] = c; - } - text[j] = 0; - GlobalUnlock(hg); - - if ( !OpenClipboard(NULL) ) - { - GlobalFree(hg); - return false; - } - if ( !EmptyClipboard() ) - { - GlobalFree(hg); - return false; - } - if ( !SetClipboardData(CF_TEXT, hg) ) - { - GlobalFree(hg); - return false; - } - CloseClipboard(); - UndoMemorize(OPERUNDO_SPEC); - m_cursor1 = c1; - m_cursor2 = c2; + Copy(true); + DeleteOne(0); // deletes the selected characters Justif(); ColumnFix(); - SendModifEvent();*/ + SendModifEvent(); return true; } // Copy the selected characters or entire line. -bool CEdit::Copy() // TODO +bool CEdit::Copy(bool memorize_cursor) { - /* HGLOBAL hg; - char* text; - char c; - int c1, c2, start, len, i, j; + int c1, c2, start, len; + char *text; c1 = m_cursor1; c2 = m_cursor2; - if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2 + if ( c1 > c2 ) { + Math::Swap(c1, c2); // always c1 <= c2 + } - if ( c1 == c2 ) - { - while ( c1 > 0 ) - { - if ( m_text[c1-1] == '\n' ) break; - c1 --; + if ( c1 == c2 ) { + while ( c1 > 0 ) { + if ( m_text[c1 - 1] == '\n' ) { + break; + } + c1--; } - while ( c2 < m_len ) - { - c2 ++; - if ( m_text[c2-1] == '\n' ) break; + while ( c2 < m_len ) { + c2++; + if ( m_text[c2 - 1] == '\n' ) { + break; + } } } - if ( c1 == c2 ) return false; - - start = c1; - len = c2-c1; - - if ( !(hg = GlobalAlloc(GMEM_DDESHARE, len*2+1)) ) - { - return false; - } - if ( !(text = (char*)GlobalLock(hg)) ) - { - GlobalFree(hg); + if ( c1 == c2 ) { return false; } - j = 0; - for ( i=start ; i<start+len ; i++ ) - { - c = m_text[i]; - if ( c == '\n' ) text[j++] = '\r'; - text[j++] = c; - } - text[j] = 0; - GlobalUnlock(hg); + start = c1; + len = c2 - c1; - if ( !OpenClipboard(NULL) ) - { - GlobalFree(hg); - return false; - } - if ( !EmptyClipboard() ) - { - GlobalFree(hg); - return false; - } - if ( !SetClipboardData(CF_TEXT, hg) ) - { - GlobalFree(hg); - return false; + text = new char[len + 1]; + strncpy(text, m_text + start, len); + text[len] = 0; + widgetSetClipboardText(text); + delete []text; + + if (memorize_cursor) { + m_cursor1 = c1; + m_cursor2 = c2; } - CloseClipboard(); -*/ + return true; } // Paste the contents of the notebook. -bool CEdit::Paste() // TODO +bool CEdit::Paste() { - /*HANDLE h; char c; - char* p; - - if ( !m_bEdit ) return false; - - if ( !OpenClipboard(NULL) ) - { - return false; - } + char* text; - if ( !(h = GetClipboardData(CF_TEXT)) ) - { - CloseClipboard(); + if ( !m_bEdit ) { return false; } - if ( !(p = (char*)GlobalLock(h)) ) - { - CloseClipboard(); + text = widgetGetClipboardText(); + + if ( text == nullptr ) { return false; } UndoMemorize(OPERUNDO_SPEC); - - while ( *p != 0 ) - { - c = *p++; - if ( c == '\r' ) continue; - if ( c == '\t' && m_bAutoIndent ) continue; + for ( unsigned int i = 0; i < strlen(text); i++ ) { + c = text[i]; + if ( c == '\r' ) { + continue; + } + if ( c == '\t' && m_bAutoIndent ) { + continue; + } InsertOne(c); } - - GlobalUnlock(h); - CloseClipboard(); - + + free(text); Justif(); ColumnFix(); - SendModifEvent();*/ + SendModifEvent(); return true; } @@ -2703,7 +2603,9 @@ bool CEdit::Paste() // TODO bool CEdit::Undo() { - if ( !m_bEdit ) return false; + if ( !m_bEdit ) { + return false; + } return UndoRecall(); } @@ -2715,7 +2617,9 @@ void CEdit::Insert(char character) { int i, level, tab; - if ( !m_bEdit ) return; + if ( !m_bEdit ) { + return; + } if ( !m_bMulti ) // single-line? { diff --git a/src/ui/edit.h b/src/ui/edit.h index 1cfec80..df4f143 100644 --- a/src/ui/edit.h +++ b/src/ui/edit.h @@ -184,7 +184,7 @@ public: bool GetMultiFont(); bool Cut(); - bool Copy(); + bool Copy(bool memorize_cursor = false); bool Paste(); bool Undo(); |