author | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
commit | 118d03d815a7615b9c53363218a7ac45b3f4c514 (patch) (side-by-side diff) | |
tree | 356953e2413cddcec0f35bd47bb6439767da7051 /noncore/apps/opie-reader/Navigation.cpp | |
parent | 00894537decf01c5a5cdc565b2740b5e67a2e90f (diff) | |
download | opie-118d03d815a7615b9c53363218a7ac45b3f4c514.zip opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.gz opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.bz2 |
Incorporated TimWs current source tree and make it compile
Diffstat (limited to 'noncore/apps/opie-reader/Navigation.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Navigation.cpp | 102 |
1 files changed, 62 insertions, 40 deletions
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp index 4f11887..36e33b4 100644 --- a/noncore/apps/opie-reader/Navigation.cpp +++ b/noncore/apps/opie-reader/Navigation.cpp @@ -1,62 +1,80 @@ -#include "Navigation.h" - +#ifdef _WINDOWS #include <string.h> +#endif +#include "Navigation.h" +//#include <stdio.h> +/* + void saveposn(size_t posn) + save/push position to history buffer for future use of back() function +*/ void CNavigation::saveposn(size_t posn) { -// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); - historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE; + //printf("saving position %u, depth %u\n",posn,historycurrent); history[historycurrent] = posn; - if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE; -// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend); -} - -bool CNavigation::forward(size_t& loc) -{ - if (historycurrent != historyend) - { historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE; - loc = history[historycurrent]; -// qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); - return true; + if (historycurrent==historystart) + // circular buffer full, forget oldest record + historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE; + // no forward possible after saveposn + historyend = historycurrent; } - else + +/* + void writeposn(size_t posn) + overwrite current (unused) position + useful for saving current position before using back button +*/ +void CNavigation::writeposn(size_t posn) { - return false; - } + //printf("witing position %u, depth %u\n",posn,historycurrent); + history[historycurrent] = posn; } -bool CNavigation::back(size_t& loc) -{ - if (historyend != historystart) +/* + bool back(size_t& posn) + go back in history + restore last position saved with saveposn() and return true + return false if there is nothing saved in history +*/ +bool CNavigation::back(size_t& posn) { -// qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); - if (historycurrent == historyend && history[historycurrent] != loc) - { - historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE; - history[historyend] = loc; - } + if (historycurrent!=historystart) { + // buffer is not empty + if (historycurrent==0) + historycurrent=NAVIGATION_HISTORY_SIZE-1; else - { - size_t sv = historycurrent; - historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE; - if (historycurrent == historystart) - { - historycurrent = sv; + historycurrent--; + posn=history[historycurrent]; + //printf("back(): going back to %u depth %u\n",posn,historycurrent); + return true; + + } else { + // circular buffer empty + //printf("back(): empty history\n"); return false; } } - loc = history[historycurrent]; -// qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend); - return true; - } - else + +/* + bool forward(size_t& posn) + go forward in history, if possible + undo calling of back() +*/ +bool CNavigation::forward(size_t& posn) { + if (historycurrent!=historyend) { + // [historycurrent] = current position + // [historycurrent+1] = position we need + historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE; + posn = history[historycurrent]; + //printf("forward(): going to position %d\n",posn); + return true; + } else { + //printf("forward(): there is no future :)\n"); return false; } } -#include <stdio.h> - void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { @@ -73,8 +91,10 @@ void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigne p += sizeof(size_t); memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE); +/* printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); for (int i = historystart; i <= historyend; i++) printf("<%u> ", history[i]); printf("\n"); +*/ } @@ -94,7 +114,9 @@ void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen) srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE); } +/* printf("<%u,%u,%u>\n", historystart, historyend, historycurrent); for (int i = historystart; i <= historyend; i++) printf("<%u> ", history[i]); printf("\n"); +*/ } |