diff --git a/apps/home/apps_layout.csv b/apps/home/apps_layout.csv index 77e47e4b8..b17d33f7d 100644 --- a/apps/home/apps_layout.csv +++ b/apps/home/apps_layout.csv @@ -1,2 +1,2 @@ -Default,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,settings -HidePython,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,settings +Default,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,reader,settings +HidePython,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,reader,settings diff --git a/apps/reader/Makefile b/apps/reader/Makefile index 71adec9e0..f786e1510 100644 --- a/apps/reader/Makefile +++ b/apps/reader/Makefile @@ -1,4 +1,4 @@ -apps += reader::App +apps += Reader::App app_headers += apps/reader/app.h app_sreader_src = $(addprefix apps/reader/,\ diff --git a/apps/reader/app.cpp b/apps/reader/app.cpp index 18ae33da0..5d9b8b156 100644 --- a/apps/reader/app.cpp +++ b/apps/reader/app.cpp @@ -4,7 +4,7 @@ #include "apps/i18n.h" -namespace reader { +namespace Reader { I18n::Message App::Descriptor::name() { return I18n::Message::ReaderApp; @@ -32,7 +32,8 @@ App::Descriptor * App::Snapshot::descriptor() { App::App(Snapshot * snapshot) : ::App(snapshot, &m_stackViewController), m_listBookController(&m_stackViewController), - m_stackViewController(nullptr, &m_listBookController) + m_alternateEmptyViewController(&m_stackViewController, &m_listBookController, &m_listBookController), + m_stackViewController(&m_modalViewController, &m_alternateEmptyViewController) { } diff --git a/apps/reader/app.h b/apps/reader/app.h index 1204862c4..8de726e9f 100644 --- a/apps/reader/app.h +++ b/apps/reader/app.h @@ -4,7 +4,7 @@ #include #include "list_book_controller.h" -namespace reader { +namespace Reader { class App : public ::App { public: @@ -22,6 +22,7 @@ public: private: App(Snapshot * snapshot); ListBookController m_listBookController; + AlternateEmptyViewController m_alternateEmptyViewController; StackViewController m_stackViewController; }; diff --git a/apps/reader/base.de.i18n b/apps/reader/base.de.i18n index 68a64986d..3dcf262d7 100644 --- a/apps/reader/base.de.i18n +++ b/apps/reader/base.de.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay = "Keine Dateien zum Anzeigen!" \ No newline at end of file +ReaderApp = "Leser" +ReaderAppCapital = "LESER" +NoFileToDisplay = "Keine Dateien zum Anzeigen" \ No newline at end of file diff --git a/apps/reader/base.en.i18n b/apps/reader/base.en.i18n index 0101ebe2a..0b0a2de2a 100644 --- a/apps/reader/base.en.i18n +++ b/apps/reader/base.en.i18n @@ -1,3 +1,3 @@ ReaderApp = "Reader" ReaderAppCapital = "READER" -NoFileToDisplay = "No file to display!" \ No newline at end of file +NoFileToDisplay = "No file to display" \ No newline at end of file diff --git a/apps/reader/base.es.i18n b/apps/reader/base.es.i18n index 51be1eaf4..bcbe8f0cd 100644 --- a/apps/reader/base.es.i18n +++ b/apps/reader/base.es.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay ="No hay archivos para mostrar!" \ No newline at end of file +ReaderApp = "Lector" +ReaderAppCapital = "LECTOR" +NoFileToDisplay ="No hay archivos para mostrar" \ No newline at end of file diff --git a/apps/reader/base.fr.i18n b/apps/reader/base.fr.i18n index 220c36fa1..f8b97e036 100644 --- a/apps/reader/base.fr.i18n +++ b/apps/reader/base.fr.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay = "Aucun fichier à afficher!" \ No newline at end of file +ReaderApp = "Liseuse" +ReaderAppCapital = "LISEUSE" +NoFileToDisplay = "Aucun fichier à afficher" \ No newline at end of file diff --git a/apps/reader/base.hu.i18n b/apps/reader/base.hu.i18n index 264d6e878..09357ced7 100644 --- a/apps/reader/base.hu.i18n +++ b/apps/reader/base.hu.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay ="Nincs megjeleníthető fájl" \ No newline at end of file +ReaderApp = "Olvasó" +ReaderAppCapital = "OLVASÓ" +NoFileToDisplay = "Nincs megjeleníthető fájl" \ No newline at end of file diff --git a/apps/reader/base.it.i18n b/apps/reader/base.it.i18n index 4464ff077..c553356d9 100644 --- a/apps/reader/base.it.i18n +++ b/apps/reader/base.it.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay ="essun file da visualizzare" \ No newline at end of file +ReaderApp = "Lettore" +ReaderAppCapital = "LETTORE" +NoFileToDisplay = "essun file da visualizzare" \ No newline at end of file diff --git a/apps/reader/base.nl.i18n b/apps/reader/base.nl.i18n index 55693de3e..576752673 100644 --- a/apps/reader/base.nl.i18n +++ b/apps/reader/base.nl.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay ="Geen bestanden om weer te geven" \ No newline at end of file +ReaderApp = "Lezer" +ReaderAppCapital = "LEZER" +NoFileToDisplay = "Geen bestanden om weer te geven" \ No newline at end of file diff --git a/apps/reader/base.pt.i18n b/apps/reader/base.pt.i18n index 886d4930c..2aa88319b 100644 --- a/apps/reader/base.pt.i18n +++ b/apps/reader/base.pt.i18n @@ -1,3 +1,3 @@ -ReaderApp = "Reader" -ReaderAppCapital = "READER" -NoFileToDisplay ="Nenhum arquivo para exibir" \ No newline at end of file +ReaderApp = "Leitor" +ReaderAppCapital = "LEITOR" +NoFileToDisplay = "Nenhum arquivo para exibir" \ No newline at end of file diff --git a/apps/reader/list_book_controller.cpp b/apps/reader/list_book_controller.cpp index d2635129c..814f60d5f 100644 --- a/apps/reader/list_book_controller.cpp +++ b/apps/reader/list_book_controller.cpp @@ -1,102 +1,100 @@ #include "list_book_controller.h" #include "utility.h" +#include #include "apps/i18n.h" -namespace reader +namespace Reader { -View* ListBookController::view() -{ - return &m_tableView; +View* ListBookController::view() { + return &m_tableView; } ListBookController::ListBookController(Responder * parentResponder): - ViewController(parentResponder), - m_tableView(this, this, this), - m_readBookController(this) + ViewController(parentResponder), + m_tableView(this, this, this), + m_readBookController(this) { - m_nbFiles = filesWithExtension(".txt", m_files, NB_FILES); - cleanRemovedBookRecord(); + m_filesNumber = filesWithExtension(".txt", m_files, k_maxFilesNumber); + cleanRemovedBookRecord(); } -int ListBookController::numberOfRows() const -{ - return m_nbFiles; +int ListBookController::numberOfRows() const { + return m_filesNumber; } -KDCoordinate ListBookController::cellHeight() -{ - return 50; +KDCoordinate ListBookController::cellHeight() { + return Metric::StoreRowHeight; } -HighlightCell * ListBookController::reusableCell(int index) -{ - return &m_cells[index]; +HighlightCell * ListBookController::reusableCell(int index) { + return &m_cells[index]; } - -int ListBookController::reusableCellCount() const -{ - return NB_CELLS; + +int ListBookController::reusableCellCount() const { + return k_cellsNumber; } -void ListBookController::willDisplayCellForIndex(HighlightCell * cell, int index) -{ - MessageTableCell* myTextCell = static_cast(cell); - MessageTextView* textView = static_cast(myTextCell->labelView()); - textView->setText(m_files[index].name); - myTextCell->setMessageFont(KDFont::LargeFont); +void ListBookController::willDisplayCellForIndex(HighlightCell * cell, int index) { + MessageTableCell* myTextCell = static_cast(cell); + MessageTextView* textView = static_cast(myTextCell->labelView()); + textView->setText(m_files[index].name); + myTextCell->setMessageFont(KDFont::LargeFont); //TODO set cell font at building ? } -void ListBookController::didBecomeFirstResponder() -{ - if (selectedRow() < 0) { - selectCellAtLocation(0, 0); - } - Container::activeApp()->setFirstResponder(&m_tableView); - if(m_nbFiles == 0) +void ListBookController::didBecomeFirstResponder() { + if (selectedRow() < 0) { + selectCellAtLocation(0, 0); + } + Container::activeApp()->setFirstResponder(&m_tableView); +} + +bool ListBookController::handleEvent(Ion::Events::Event event) { + if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) + { + m_readBookController.setBook(m_files[selectedRow()]); + static_cast(parentResponder())->push(&m_readBookController); + Container::activeApp()->setFirstResponder(&m_readBookController); + return true; + } + + return false; +} + + +bool ListBookController::hasBook(const char* filename) const { + for(int i=0;idisplayWarning(I18n::Message::NoFileToDisplay); + return true; } + } + return false; } -bool ListBookController::handleEvent(Ion::Events::Event event) -{ - if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) - { - - m_readBookController.setBook(m_files[selectedRow()]); - static_cast(parentResponder())->push(&m_readBookController); - Container::activeApp()->setFirstResponder(&m_readBookController); - return true; - } - - return false; -} - - -bool ListBookController::hasBook(const char* filename) const -{ - for(int i=0;inumberOfRecordsWithExtension("txt"); for(int i=0; irecordWithExtensionAtIndex("txt", i); - if(!hasBook(r.fullName())) - { - r.destroy(); - } + Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex("txt", i); + if(!hasBook(r.fullName())) + { + r.destroy(); + } } } +bool ListBookController::isEmpty() const { + return m_filesNumber == 0; +} + +I18n::Message ListBookController::emptyMessage() { + return I18n::Message::NoFileToDisplay; +} + +Responder * ListBookController::defaultController() { + return parentResponder(); +} + } \ No newline at end of file diff --git a/apps/reader/list_book_controller.h b/apps/reader/list_book_controller.h index 82eecf207..ddbd3f553 100644 --- a/apps/reader/list_book_controller.h +++ b/apps/reader/list_book_controller.h @@ -6,35 +6,35 @@ #include "read_book_controller.h" -namespace reader +namespace Reader { -class ListBookController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource +class ListBookController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource, public AlternateEmptyViewDefaultDelegate { public: - ListBookController(Responder * parentResponder); - View* view() override; + ListBookController(Responder * parentResponder); + View* view() override; - int numberOfRows() const override; - KDCoordinate cellHeight() override; - HighlightCell * reusableCell(int index) override; - int reusableCellCount() const override; - void willDisplayCellForIndex(HighlightCell * cell, int index) override; - void didBecomeFirstResponder() override; - bool handleEvent(Ion::Events::Event event) override; - bool hasBook(const char* filename) const; - void cleanRemovedBookRecord(); + int numberOfRows() const override; + KDCoordinate cellHeight() override; + HighlightCell * reusableCell(int index) override; + int reusableCellCount() const override; + void willDisplayCellForIndex(HighlightCell * cell, int index) override; + void didBecomeFirstResponder() override; + bool handleEvent(Ion::Events::Event event) override; + bool hasBook(const char* filename) const; + void cleanRemovedBookRecord(); + bool isEmpty() const override; + I18n::Message emptyMessage() override; + Responder * defaultController() override; private: - SelectableTableView m_tableView; - - static const int NB_FILES = 20; - External::Archive::File m_files[NB_FILES]; - int m_nbFiles = 0; - - static const int NB_CELLS = 6; - MessageTableCell m_cells[NB_CELLS]; - - ReadBookController m_readBookController; + SelectableTableView m_tableView; + static const int k_maxFilesNumber = 20; + External::Archive::File m_files[k_maxFilesNumber]; + int m_filesNumber = 0; + static const int k_cellsNumber = 6; + MessageTableCellWithChevron m_cells[k_cellsNumber]; + ReadBookController m_readBookController; }; } diff --git a/apps/reader/read_book_controller.cpp b/apps/reader/read_book_controller.cpp index 7bdd9380e..144385918 100644 --- a/apps/reader/read_book_controller.cpp +++ b/apps/reader/read_book_controller.cpp @@ -1,6 +1,6 @@ #include "read_book_controller.h" -namespace reader +namespace Reader { ReadBookController::ReadBookController(Responder * parentResponder) : @@ -8,60 +8,49 @@ ReadBookController::ReadBookController(Responder * parentResponder) : { } -View * ReadBookController::view() -{ +View * ReadBookController::view() { return &m_readerView; } -void ReadBookController::setBook(const External::Archive::File& file) -{ - m_file = &file; - loadPosition(); - m_readerView.setText(reinterpret_cast(file.data), file.dataLength); +void ReadBookController::setBook(const External::Archive::File& file) { + m_file = &file; + loadPosition(); + m_readerView.setText(reinterpret_cast(file.data), file.dataLength); } -bool ReadBookController::handleEvent(Ion::Events::Event event) -{ - if(event == Ion::Events::Down) - { - m_readerView.nextPage(); - return true; - } - if(event == Ion::Events::Up) - { - m_readerView.previousPage(); - return true; - } - if(event == Ion::Events::Back || event == Ion::Events::Home) - { - savePosition(); - } - return false; +bool ReadBookController::handleEvent(Ion::Events::Event event) { + if(event == Ion::Events::Down) { + m_readerView.nextPage(); + return true; + } + if(event == Ion::Events::Up) { + m_readerView.previousPage(); + return true; + } + if(event == Ion::Events::Back || event == Ion::Events::Home) { + savePosition(); + } + return false; } -void ReadBookController::savePosition() const -{ +void ReadBookController::savePosition() const { int pageOffset = m_readerView.getPageOffset(); Ion::Storage::Record::ErrorStatus status = Ion::Storage::sharedStorage()->createRecordWithFullName(m_file->name, &pageOffset, sizeof(pageOffset)); - if(Ion::Storage::Record::ErrorStatus::NameTaken == status) - { - Ion::Storage::Record::Data data; - data.buffer = &pageOffset; - data.size = sizeof(pageOffset); - status = Ion::Storage::sharedStorage()->recordNamed(m_file->name).setValue(data); + if(Ion::Storage::Record::ErrorStatus::NameTaken == status) { + Ion::Storage::Record::Data data; + data.buffer = &pageOffset; + data.size = sizeof(pageOffset); + status = Ion::Storage::sharedStorage()->recordNamed(m_file->name).setValue(data); } } -void ReadBookController::loadPosition() -{ +void ReadBookController::loadPosition() { Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordNamed(m_file->name); - if(Ion::Storage::sharedStorage()->hasRecord(r)) - { + if(Ion::Storage::sharedStorage()->hasRecord(r)) { int pageOffset = *(static_cast(r.value().buffer)); m_readerView.setPageOffset(pageOffset); } - else - { + else { m_readerView.setPageOffset(0); } } diff --git a/apps/reader/read_book_controller.h b/apps/reader/read_book_controller.h index c4349be4e..77d4f57f0 100644 --- a/apps/reader/read_book_controller.h +++ b/apps/reader/read_book_controller.h @@ -5,7 +5,7 @@ #include "apps/external/archive.h" #include "word_wrap_view.h" -namespace reader { +namespace Reader { class ReadBookController : public ViewController { public: diff --git a/apps/reader/utility.cpp b/apps/reader/utility.cpp index 2f82b61f3..123fe3920 100644 --- a/apps/reader/utility.cpp +++ b/apps/reader/utility.cpp @@ -8,109 +8,100 @@ #include #endif -namespace reader +namespace Reader { -bool stringEndsWith(const char* str, const char* pattern) -{ - int strLength = strlen(str); - int patternLength = strlen(pattern); - if (patternLength > strLength) - return false; - - const char* strIter = str + strlen(str); - const char* patternIter = pattern + strlen(pattern); - - while(*strIter == *patternIter) - { - if(patternIter == pattern) - return true; - strIter--; - patternIter--; - } +bool stringEndsWith(const char* str, const char* pattern) { + int strLength = strlen(str); + int patternLength = strlen(pattern); + if (patternLength > strLength) { return false; + } + + const char* strIter = str + strlen(str); + const char* patternIter = pattern + strlen(pattern); + + while(*strIter == *patternIter) { + if(patternIter == pattern) { + return true; + } + strIter--; + patternIter--; + } + return false; } -void stringNCopy(char* dest, int max, const char* src, int len) -{ - while(len>0 && max >1 && *src) - { - *dest = *src; - dest++; - src++; - len--; - max--; - } - *dest=0; +void stringNCopy(char* dest, int max, const char* src, int len) { + while(len>0 && max >1 && *src) + { + *dest = *src; + dest++; + src++; + len--; + max--; + } + *dest=0; } #ifdef DEVICE -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) -{ - size_t nbTotalFiles = External::Archive::numberOfFiles(); - int nbFiles = 0; - for(size_t i=0; i < nbTotalFiles; ++i) +int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) { + size_t nbTotalFiles = External::Archive::numberOfFiles(); + int nbFiles = 0; + for(size_t i=0; i < nbTotalFiles; ++i) + { + External::Archive::File file; + External::Archive::fileAtIndex(i, file); + if(stringEndsWith(file.name, ".txt")) { - External::Archive::File file; - External::Archive::fileAtIndex(i, file); - if(stringEndsWith(file.name, ".txt")) - { - files[nbFiles] = file; - nbFiles++; - if(nbFiles == filesSize) - break; - } + files[nbFiles] = file; + nbFiles++; + if(nbFiles == filesSize) + break; } - return nbFiles; + } + return nbFiles; } #else -static void fillFileData(External::Archive::File& file) -{ - file.data = nullptr; - file.dataLength = 0; +static void fillFileData(External::Archive::File& file) { + file.data = nullptr; + file.dataLength = 0; - struct stat info; - if (stat(file.name, &info) != 0) - { - return; - } - - unsigned char* content = new unsigned char[info.st_size]; - if (content == NULL) - { - return ; - } - FILE *fp = fopen(file.name, "rb"); - if (fp == NULL) - { - return ; - } - - fread(content, info.st_size, 1, fp); - fclose(fp); - file.data = content; - file.dataLength = info.st_size; + struct stat info; + if (stat(file.name, &info) != 0) { + return; + } + + unsigned char* content = new unsigned char[info.st_size]; + if (content == NULL) { + return; + } + FILE *fp = fopen(file.name, "rb"); + if (fp == NULL) { + return ; + } + + fread(content, info.st_size, 1, fp); + fclose(fp); + file.data = content; + file.dataLength = info.st_size; } -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) -{ +int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) { dirent *file; DIR *d = opendir("."); int nb = 0; - if (d) - { - while ((file = readdir(d)) != NULL) - { - if(stringEndsWith(file->d_name, extension)) - { + if (d) { + while ((file = readdir(d)) != NULL) { + if(stringEndsWith(file->d_name, extension)) { files[nb].name = strdup(file->d_name);//will probably leak fillFileData(files[nb]); nb++; - if(nb == filesSize) - break; + if(nb == filesSize) { + break; + } } } closedir(d); diff --git a/apps/reader/utility.h b/apps/reader/utility.h index 6893ab95c..36e1d1b4b 100644 --- a/apps/reader/utility.h +++ b/apps/reader/utility.h @@ -3,11 +3,11 @@ #include -namespace reader +namespace Reader { bool stringEndsWith(const char* str, const char* end); -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) ; +int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize); void stringNCopy(char* dest, int max, const char* src, int len); } diff --git a/apps/reader/word_wrap_view.cpp b/apps/reader/word_wrap_view.cpp index 9e4cccd62..c022658cc 100644 --- a/apps/reader/word_wrap_view.cpp +++ b/apps/reader/word_wrap_view.cpp @@ -2,155 +2,138 @@ #include "utility.h" -namespace reader +namespace Reader { -void WordWrapTextView::nextPage() -{ - if(m_nextPageOffset >= m_length) - return; - m_pageOffset = m_nextPageOffset; - markRectAsDirty(bounds()); +void WordWrapTextView::nextPage() { + if(m_nextPageOffset >= m_length) { + return; + } + m_pageOffset = m_nextPageOffset; + markRectAsDirty(bounds()); } -void WordWrapTextView::setText(const char* text, int length) -{ - PointerTextView::setText(text); - m_length = length; +void WordWrapTextView::setText(const char* text, int length) { + PointerTextView::setText(text); + m_length = length; } -void WordWrapTextView::previousPage() -{ - if(m_pageOffset <= 0) - return; +void WordWrapTextView::previousPage() { + if(m_pageOffset <= 0) { + return; + } + const int spaceWidth = m_font->stringSize(" ").width(); - const int spaceWidth = m_font->stringSize(" ").width(); + const char * endOfWord = text() + m_pageOffset; + const char * startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord); + + KDPoint textPosition(m_frame.width() - margin, m_frame.height() - margin); - const char * endOfWord = text() + m_pageOffset; - const char * startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord); + while(startOfWord>=text()) { + endOfWord = UTF8Helper::EndOfWord(startOfWord); + KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord); + KDPoint previousTextPosition = KDPoint(textPosition.x()-textSize.width(), textPosition.y()); - KDPoint textPosition(m_frame.width() - margin, m_frame.height() - margin); + if(previousTextPosition.x() < margin) { + textPosition = KDPoint(m_frame.width() - margin, textPosition.y() - textSize.height()); + previousTextPosition = KDPoint(textPosition.x() - textSize.width(), textPosition.y()); + } + if(textPosition.y() - textSize.height() < margin) { + break; + } - while(startOfWord>=text()) - { - endOfWord = UTF8Helper::EndOfWord(startOfWord); - KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord); - KDPoint previousTextPosition = KDPoint(textPosition.x()-textSize.width(), textPosition.y()); - - if(previousTextPosition.x() < margin) - { - textPosition = KDPoint(m_frame.width() - margin, textPosition.y() - textSize.height()); - previousTextPosition = KDPoint(textPosition.x() - textSize.width(), textPosition.y()); - } - if(textPosition.y() - textSize.height() < margin) - { - break; - } - - - --startOfWord; - while(startOfWord >= text() && *startOfWord == ' ') - { - previousTextPosition = KDPoint(previousTextPosition.x() - spaceWidth, previousTextPosition.y()); - --startOfWord; - } - if(previousTextPosition.x() < margin) - { - previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height()); - } - - while(startOfWord >= text() && *startOfWord == '\n') - { - previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height()); - --startOfWord; - } - - if(previousTextPosition.y() - textSize.height() < margin) - { - break; - } - - textPosition = previousTextPosition; - endOfWord = startOfWord; - startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord); + --startOfWord; + while(startOfWord >= text() && *startOfWord == ' ') { + previousTextPosition = KDPoint(previousTextPosition.x() - spaceWidth, previousTextPosition.y()); + --startOfWord; } - if(startOfWord == text()) - m_pageOffset = 0; - else - m_pageOffset = UTF8Helper::EndOfWord(startOfWord) - text() + 1; - markRectAsDirty(bounds()); -} - -void WordWrapTextView::drawRect(KDContext * ctx, KDRect rect) const -{ - ctx->fillRect(KDRect(0, 0, bounds().width(), bounds().height()), m_backgroundColor); - - const char * endOfFile = text() + m_length; - const char * startOfWord = text() + m_pageOffset; - const char * endOfWord = UTF8Helper::EndOfWord(startOfWord); - KDPoint textPosition(margin, margin); - - const int wordMaxLength = 128; - char word[wordMaxLength]; - - const int spaceWidth = m_font->stringSize(" ").width(); - - while(startOfWord < endOfFile) - { - - KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord); - KDPoint nextTextPosition = KDPoint(textPosition.x()+textSize.width(), textPosition.y()); - - if(nextTextPosition.x() > m_frame.width() - margin) - { - textPosition = KDPoint(margin, textPosition.y() + textSize.height()); - nextTextPosition = KDPoint(margin + textSize.width(), textPosition.y()); - } - if(textPosition.y() + textSize.height() > m_frame.height() - margin) - { - break; - } - - stringNCopy(word, wordMaxLength, startOfWord, endOfWord-startOfWord); - ctx->drawString(word, textPosition, m_font, m_textColor, m_backgroundColor); - - while(*endOfWord == ' ') - { - nextTextPosition = KDPoint(nextTextPosition.x() + spaceWidth, nextTextPosition.y()); - ++endOfWord; - } - if(nextTextPosition.x() > m_frame.width() - margin) - { - nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height()); - } - - while(*endOfWord == '\n') - { - nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height()); - ++endOfWord; - } - - if(nextTextPosition.y() + textSize.height() > m_frame.height() - margin) - { - break; - } - - textPosition = nextTextPosition; - startOfWord = endOfWord; - endOfWord = UTF8Helper::EndOfWord(startOfWord); + if(previousTextPosition.x() < margin) { + previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height()); } - m_nextPageOffset = startOfWord - text(); + + + while(startOfWord >= text() && *startOfWord == '\n') { + previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height()); + --startOfWord; + } + + if(previousTextPosition.y() - textSize.height() < margin) { + break; + } + + textPosition = previousTextPosition; + endOfWord = startOfWord; + startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord); + } + if(startOfWord == text()) { + m_pageOffset = 0; + } + else { + m_pageOffset = UTF8Helper::EndOfWord(startOfWord) - text() + 1; + } + markRectAsDirty(bounds()); } -int WordWrapTextView::getPageOffset() const -{ - return m_pageOffset; +void WordWrapTextView::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(KDRect(0, 0, bounds().width(), bounds().height()), m_backgroundColor); + + const char * endOfFile = text() + m_length; + const char * startOfWord = text() + m_pageOffset; + const char * endOfWord = UTF8Helper::EndOfWord(startOfWord); + KDPoint textPosition(margin, margin); + + const int wordMaxLength = 128; + char word[wordMaxLength]; + + const int spaceWidth = m_font->stringSize(" ").width(); + + while(startOfWord < endOfFile) { + + KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord); + KDPoint nextTextPosition = KDPoint(textPosition.x()+textSize.width(), textPosition.y()); + + if(nextTextPosition.x() > m_frame.width() - margin) { + textPosition = KDPoint(margin, textPosition.y() + textSize.height()); + nextTextPosition = KDPoint(margin + textSize.width(), textPosition.y()); + } + if(textPosition.y() + textSize.height() > m_frame.height() - margin) { + break; + } + + stringNCopy(word, wordMaxLength, startOfWord, endOfWord-startOfWord); + ctx->drawString(word, textPosition, m_font, m_textColor, m_backgroundColor); + + while(*endOfWord == ' ') { + nextTextPosition = KDPoint(nextTextPosition.x() + spaceWidth, nextTextPosition.y()); + ++endOfWord; + } + if(nextTextPosition.x() > m_frame.width() - margin) { + nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height()); + } + + while(*endOfWord == '\n') { + nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height()); + ++endOfWord; + } + + if(nextTextPosition.y() + textSize.height() > m_frame.height() - margin) { + break; + } + + textPosition = nextTextPosition; + startOfWord = endOfWord; + endOfWord = UTF8Helper::EndOfWord(startOfWord); + } + m_nextPageOffset = startOfWord - text(); } -void WordWrapTextView::setPageOffset(int o) -{ - m_pageOffset = o; +int WordWrapTextView::getPageOffset() const { + return m_pageOffset; +} + +void WordWrapTextView::setPageOffset(int o) { + m_pageOffset = o; } } \ No newline at end of file diff --git a/apps/reader/word_wrap_view.h b/apps/reader/word_wrap_view.h index 4075ff4e2..0fc57e295 100644 --- a/apps/reader/word_wrap_view.h +++ b/apps/reader/word_wrap_view.h @@ -3,23 +3,23 @@ #include -namespace reader +namespace Reader { class WordWrapTextView : public PointerTextView { public: - void drawRect(KDContext * ctx, KDRect rect) const override; - void setText(const char*, int length); - void nextPage(); - void previousPage(); - int getPageOffset() const; - void setPageOffset(int o); + void drawRect(KDContext * ctx, KDRect rect) const override; + void setText(const char*, int length); + void nextPage(); + void previousPage(); + int getPageOffset() const; + void setPageOffset(int o); protected: - int m_pageOffset = 0; - mutable int m_nextPageOffset = 0; - int m_length = 0; + int m_pageOffset = 0; + mutable int m_nextPageOffset = 0; + int m_length = 0; - static const int margin = 10; + static const int margin = 10; }; } diff --git a/escher/src/alternate_empty_view_controller.cpp b/escher/src/alternate_empty_view_controller.cpp index be61f67f2..2d64ae2d7 100644 --- a/escher/src/alternate_empty_view_controller.cpp +++ b/escher/src/alternate_empty_view_controller.cpp @@ -57,8 +57,7 @@ const char * AlternateEmptyViewController::title() { bool AlternateEmptyViewController::handleEvent(Ion::Events::Event event) { if (m_contentView.alternateEmptyViewDelegate()->isEmpty()) { if (event != Ion::Events::Home && event != Ion::Events::OnOff) { - m_contentView.alternateEmptyViewDelegate()->defaultController()->handleEvent(Ion::Events::Back); - return true; + return m_contentView.alternateEmptyViewDelegate()->defaultController()->handleEvent(Ion::Events::Back); } return false; }