#include <Settings.h>
Public Member Functions | |
CSettings (void) | |
~CSettings (void) | |
void | setNewZoom (const double z) |
GBool | zoomBack () |
GBool | canZoomBack () |
int | getZoomBackState () const |
void | disableZoomBack () |
double | getZoom () const |
void | setZoom (const double z) |
void | load (const char *manifest) |
void | save (const char *manifest) |
int | getRotate () const |
void | setRotate (const int r) |
void | getScreenRect (rectangle &rect) |
int | getScreenX () const |
int | getScreenY () const |
int | getScreenWidth () const |
int | getScreenHeight () const |
void | setScreenX (const int x) |
void | setScreenY (const int y) |
void | moveScreenX (const int d) |
void | moveScreenY (const int d) |
void | setScreenPosition (const int, const int) |
void | setScreenSize (const int, const int) |
void | setScreenRect (const rectangle &rect) |
int | getCurrentPage () const |
void | setCurrentPage (const int p) |
int | getRenderDir () const |
void | setRenderDir (const int d) |
int | getMode () const |
void | setMode (const int m) |
GBool | isScribbleEnabled () const |
void | addNewItem (HistoryItemPtr ptr) |
void | addNewItem (const int page) |
HistoryItemPtr | goBackward () |
HistoryItemPtr | goForward () |
GBool | canGoBack () |
GBool | canGoForward () |
Private Member Functions | |
void | clearHistory () |
Private Attributes | |
double | zoom |
int | rotate |
int | screenX |
int | screenY |
int | drawAreaWidth |
int | drawAreaHeight |
int | currentPage |
int | renderDir |
int | mode |
int | zbState |
GBool | enableScb |
GooList | backward |
GooList | forward |
HistoryItemPtr | currentItem |
HistoryItem | record |
Definition at line 123 of file Settings.h.
CSettings::CSettings | ( | void | ) |
Definition at line 50 of file Settings.cpp.
00051 { 00052 zoom = ZoomPage; rotate = 0; screenX = screenY = 0; 00053 currentPage = INVALID_PAGE_NUMBER; 00054 drawAreaWidth = SCREEN_WIDTH; 00055 drawAreaHeight = CLIENT_AREA; 00056 renderDir = RenderNext; 00057 mode = ModePage; zbState = iconState_grey; 00058 enableScb = gTrue; currentItem = 0; 00059 }
CSettings::~CSettings | ( | void | ) |
Definition at line 61 of file Settings.cpp.
00062 { 00063 clearHistory(); 00064 }
void CSettings::clearHistory | ( | ) | [private] |
Definition at line 303 of file Settings.cpp.
00304 { 00305 // clear the forward list. 00306 HistoryItemPtr ptr = 0; 00307 while (forward.getLength() > 0) 00308 { 00309 ptr = (HistoryItemPtr)forward.del(0); 00310 delete ptr; 00311 } 00312 00313 // clear backward list 00314 while (backward.getLength() > 0) 00315 { 00316 ptr = (HistoryItemPtr)backward.del(0); 00317 delete ptr; 00318 } 00319 00320 // clear current item 00321 delete currentItem; 00322 currentItem = 0; 00323 00324 #if (HISTORY_DEBUG) 00325 // Count should reach 1, because the member variable record is still not released. 00326 printf("\n\nHistoryItem count reaches %d\n\n", HistoryItem::count); 00327 #endif 00328 }
void CSettings::setNewZoom | ( | const double | z | ) |
GBool CSettings::zoomBack | ( | ) |
Definition at line 75 of file Settings.cpp.
00076 { 00077 if (InvalidZoom == record.zoom) 00078 { 00079 return gFalse; 00080 } 00081 00082 if (mode == ModePage) 00083 { 00084 swap(zoom, record.zoom); 00085 swap(screenX, record.x); 00086 swap(screenY, record.y); 00087 } 00088 else 00089 { 00090 double ratio = record.zoom / zoom; 00091 swap(zoom, record.zoom); 00092 if (rotate == 270) 00093 { 00094 record.x = (int)(screenX * ratio); 00095 swap(screenX, record.x); 00096 swap(screenY, record.y); 00097 } 00098 else if (rotate == 0) 00099 { 00100 record.y = (int)(screenY * ratio); 00101 swap(screenY, record.y); 00102 swap(screenX, record.x); 00103 } 00104 } 00105 if (iconState_normal == zbState) 00106 { 00107 zbState = iconState_selected; 00108 } 00109 else if (iconState_selected == zbState) 00110 { 00111 zbState = iconState_normal; 00112 } 00113 return gTrue; 00114 }
GBool CSettings::canZoomBack | ( | ) |
Definition at line 122 of file Settings.cpp.
00123 { 00124 return (InvalidZoom != record.zoom); 00125 }
int CSettings::getZoomBackState | ( | ) | const [inline] |
void CSettings::disableZoomBack | ( | ) |
Definition at line 116 of file Settings.cpp.
00117 { 00118 record.zoom = InvalidZoom; 00119 zbState = iconState_grey; 00120 }
double CSettings::getZoom | ( | ) | const [inline] |
void CSettings::setZoom | ( | const double | z | ) | [inline] |
void CSettings::load | ( | const char * | manifest | ) |
Definition at line 127 of file Settings.cpp.
00128 { 00129 erManifest manifest; 00130 if (RET_OK == ermXmlOpenManifest(pathName, &manifest)) 00131 { 00132 // usually the manifest file is existing 00133 ermXmlGetInt(&manifest, "/package/last-location/pagenumber", ¤tPage); 00134 00135 // zoom 00136 static const int MAX = 20; 00137 char tmp[MAX] = {0}; 00138 ermXmlGetString(&manifest, "/package/viewer-settings/zoomfactor", tmp, MAX); 00139 00140 if (0 == strcasecmp(tmp, "zoomPage")) 00141 { 00142 zoom = ZoomPage; 00143 } 00144 else if (0 == strcasecmp(tmp, "zoomWidth")) 00145 { 00146 zoom = ZoomWidth; 00147 } 00148 else 00149 { 00150 sscanf(tmp, "%lf", &zoom); 00151 } 00152 00153 // rotation , position and mode 00154 ermXmlGetInt(&manifest, "/package/viewer-settings/rotation", &rotate); 00155 ermXmlGetInt(&manifest, "/package/viewer-settings/positionx", &screenX); 00156 ermXmlGetInt(&manifest, "/package/viewer-settings/positiony", &screenY); 00157 ermXmlGetString(&manifest, "/package/viewer-settings/mode", tmp, MAX); 00158 00159 if (0 == strcasecmp(tmp, "continous")) 00160 { 00161 mode = ModeContinous; 00162 } 00163 else if (0 == strcasecmp(tmp, "page")) 00164 { 00165 mode = ModePage; 00166 } 00167 00168 // check scribble state at first. 00169 // if the string contains any invalid characters, just disable scribble. 00170 enableScb = gTrue; 00171 if (RET_OK == ermXmlGetString(&manifest, "/package/metadata/y-metadata/modify-enable/scribble-enable", tmp, MAX)) 00172 { 00173 if (strncmp(tmp, "true", MAX) != 0) 00174 { 00175 enableScb = gFalse; 00176 } 00177 } 00178 // if children nodes are not available, check parent node. 00179 else if (RET_OK == ermXmlGetAttributeString(&manifest, 00180 "/package/metadata/y-metadata/modify-enable", 00181 "default", tmp, MAX)) 00182 { 00183 if (strncmp(tmp, "true", MAX) != 0) 00184 { 00185 enableScb = gFalse; 00186 } 00187 } 00188 } 00189 ermXmlClose(&manifest); 00190 }
void CSettings::save | ( | const char * | manifest | ) |
Definition at line 192 of file Settings.cpp.
00193 { 00194 erManifest manifest; 00195 if (RET_OK == ermXmlOpenManifest(pathName, &manifest)) 00196 { 00197 // usually the manifest file is existing 00198 00199 // dump for debug 00200 // s.dump(); 00201 00202 // page 00203 if (RET_OK != ermXmlExist(&manifest, "/package/last-location/pagenumber")) 00204 { 00205 ermXmlNewString(&manifest, "/package", "last-location", ""); 00206 ermXmlNewString(&manifest, "/package/last-location", "pagenumber", ""); 00207 } 00208 ermXmlSetInt(&manifest, "/package/last-location/pagenumber", currentPage); 00209 00210 // zoom 00211 if (RET_OK != ermXmlExist(&manifest, "/package/viewer-settings/zoomfactor")) 00212 { 00213 ermXmlNewString(&manifest, "/package", "viewer-settings", ""); 00214 ermXmlNewString(&manifest, "/package/viewer-settings", "zoomfactor", ""); 00215 } 00216 if (zoom == ZoomPage) 00217 { 00218 ermXmlSetString(&manifest, "/package/viewer-settings/zoomfactor", "zoomPage"); 00219 } 00220 else if (zoom == ZoomWidth) 00221 { 00222 ermXmlSetString(&manifest, "/package/viewer-settings/zoomfactor", "zoomWidth"); 00223 } 00224 else 00225 { 00226 char tmp[20] = {0}; 00227 snprintf(tmp, 20, "%lf", zoom); 00228 ermXmlSetString(&manifest, "/package/viewer-settings/zoomfactor", tmp); 00229 } 00230 00231 // rotation 00232 if (RET_OK != ermXmlExist(&manifest, "/package/viewer-settings/rotation")) 00233 { 00234 ermXmlNewString(&manifest, "/package/viewer-settings", "rotation", ""); 00235 } 00236 ermXmlSetInt(&manifest, "/package/viewer-settings/rotation", rotate); 00237 00238 // position x 00239 if (RET_OK != ermXmlExist(&manifest, "/package/viewer-settings/positionx")) 00240 { 00241 ermXmlNewString(&manifest, "/package/viewer-settings", "positionx", ""); 00242 } 00243 ermXmlSetInt(&manifest, "/package/viewer-settings/positionx", screenX); 00244 00245 // position y 00246 if (RET_OK != ermXmlExist(&manifest, "/package/viewer-settings/positiony")) 00247 { 00248 ermXmlNewString(&manifest, "/package/viewer-settings", "positiony", ""); 00249 } 00250 ermXmlSetInt(&manifest, "/package/viewer-settings/positiony", screenY); 00251 00252 // mode 00253 if (RET_OK != ermXmlExist(&manifest, "/package/viewer-settings/mode")) 00254 { 00255 ermXmlNewString(&manifest, "/package/viewer-settings", "mode", ""); 00256 } 00257 if (mode == ModeContinous) 00258 { 00259 ermXmlSetString(&manifest, "/package/viewer-settings/mode", "continous"); 00260 } 00261 else 00262 { 00263 ermXmlSetString(&manifest, "/package/viewer-settings/mode", "page"); 00264 } 00265 00266 ermXmlSaveAndClose(&manifest); 00267 } 00268 }
int CSettings::getRotate | ( | ) | const [inline] |
void CSettings::setRotate | ( | const int | r | ) | [inline] |
void CSettings::getScreenRect | ( | rectangle & | rect | ) |
Definition at line 270 of file Settings.cpp.
00271 { 00272 if (getRotate() == 0 || getRotate() == 180) 00273 { 00274 rect.left = screenX; rect.top = screenY; 00275 rect.right = screenX + drawAreaWidth; 00276 rect.bottom = screenY + drawAreaHeight; 00277 } 00278 else if (getRotate() == 90 || getRotate() == 270) 00279 { 00280 rect.left = screenY; rect.top = screenX; 00281 rect.right = screenY + drawAreaHeight; 00282 rect.bottom = screenX + drawAreaWidth; 00283 } 00284 }
int CSettings::getScreenX | ( | ) | const [inline] |
int CSettings::getScreenY | ( | ) | const [inline] |
int CSettings::getScreenWidth | ( | ) | const [inline] |
int CSettings::getScreenHeight | ( | ) | const [inline] |
void CSettings::setScreenX | ( | const int | x | ) | [inline] |
void CSettings::setScreenY | ( | const int | y | ) | [inline] |
void CSettings::moveScreenX | ( | const int | d | ) | [inline] |
void CSettings::moveScreenY | ( | const int | d | ) | [inline] |
void CSettings::setScreenPosition | ( | const int | nX, | |
const int | nY | |||
) |
void CSettings::setScreenSize | ( | const int | width, | |
const int | height | |||
) |
Definition at line 291 of file Settings.cpp.
00292 { 00293 drawAreaWidth = width; drawAreaHeight = height; 00294 }
void CSettings::setScreenRect | ( | const rectangle & | rect | ) |
Definition at line 296 of file Settings.cpp.
00297 { 00298 screenX = rect.left; screenY = rect.top; 00299 drawAreaWidth = rect.right - rect.left; 00300 drawAreaHeight = rect.bottom - rect.top; 00301 }
int CSettings::getCurrentPage | ( | ) | const [inline] |
void CSettings::setCurrentPage | ( | const int | p | ) |
Definition at line 331 of file Settings.cpp.
00332 { 00333 // page change signal. 00334 if (currentPage != p && currentPage != INVALID_PAGE_NUMBER) 00335 { 00336 // add the current one into history list. 00337 addNewItem(currentPage); 00338 } 00339 00340 if (currentItem == 0) 00341 { 00342 currentItem = new HistoryItem; 00343 } 00344 00345 // always update the page number. 00346 currentItem->pageNumber = p; 00347 currentPage = p; 00348 00349 #if (HISTORY_DEBUG) 00350 dumpHistory(); 00351 #endif 00352 }
int CSettings::getRenderDir | ( | ) | const [inline] |
void CSettings::setRenderDir | ( | const int | d | ) | [inline] |
int CSettings::getMode | ( | ) | const [inline] |
void CSettings::setMode | ( | const int | m | ) | [inline] |
GBool CSettings::isScribbleEnabled | ( | ) | const [inline] |
void CSettings::addNewItem | ( | HistoryItemPtr | ptr | ) |
Definition at line 355 of file Settings.cpp.
00356 { 00357 // check length before adding new one. 00358 if (backward.getLength() >= HISTORY_MAX_LENGTH) 00359 { 00360 delete (HistoryItemPtr)backward.del(0); 00361 } 00362 00363 backward.append(ptr); 00364 00365 // clear the forward list. 00366 while (forward.getLength() > 0) 00367 { 00368 ptr = (HistoryItemPtr)forward.del(0); 00369 delete ptr; 00370 } 00371 }
void CSettings::addNewItem | ( | const int | page | ) |
Definition at line 373 of file Settings.cpp.
00374 { 00375 HistoryItemPtr ptr = new HistoryItem; 00376 ptr->pageNumber = page; 00377 addNewItem(ptr); 00378 }
HistoryItemPtr CSettings::goBackward | ( | ) |
Definition at line 380 of file Settings.cpp.
00381 { 00382 int last = backward.getLength(); 00383 if (last <= 0) 00384 { 00385 return 0; 00386 } 00387 00388 forward.append(currentItem); 00389 currentItem = (HistoryItemPtr)backward.del(last - 1); 00390 currentPage = currentItem->pageNumber; 00391 return currentItem; 00392 }
HistoryItemPtr CSettings::goForward | ( | ) |
Definition at line 394 of file Settings.cpp.
00395 { 00396 int last = forward.getLength(); 00397 if (last <= 0) 00398 { 00399 return 0; 00400 } 00401 00402 backward.append(currentItem); 00403 currentItem = (HistoryItemPtr)forward.del(last - 1); 00404 currentPage = currentItem->pageNumber; 00405 return currentItem; 00406 }
GBool CSettings::canGoBack | ( | ) |
Definition at line 408 of file Settings.cpp.
00409 { 00410 return (backward.getLength() > 0); 00411 }
GBool CSettings::canGoForward | ( | ) |
Definition at line 413 of file Settings.cpp.
00414 { 00415 return (forward.getLength() > 0); 00416 }
double CSettings::zoom [private] |
Definition at line 126 of file Settings.h.
int CSettings::rotate [private] |
Definition at line 127 of file Settings.h.
int CSettings::screenX [private] |
Definition at line 128 of file Settings.h.
int CSettings::screenY [private] |
Definition at line 129 of file Settings.h.
int CSettings::drawAreaWidth [private] |
Definition at line 130 of file Settings.h.
int CSettings::drawAreaHeight [private] |
Definition at line 131 of file Settings.h.
int CSettings::currentPage [private] |
Definition at line 132 of file Settings.h.
int CSettings::renderDir [private] |
Definition at line 133 of file Settings.h.
int CSettings::mode [private] |
Definition at line 134 of file Settings.h.
int CSettings::zbState [private] |
Definition at line 135 of file Settings.h.
GBool CSettings::enableScb [private] |
Definition at line 136 of file Settings.h.
GooList CSettings::backward [private] |
Definition at line 137 of file Settings.h.
GooList CSettings::forward [private] |
Definition at line 138 of file Settings.h.
HistoryItemPtr CSettings::currentItem [private] |
Definition at line 140 of file Settings.h.
HistoryItem CSettings::record [private] |
Definition at line 141 of file Settings.h.