CSettings Class Reference

#include <Settings.h>

Collaboration diagram for CSettings:

Collaboration graph
[legend]

List of all members.

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


Detailed Description

Definition at line 123 of file Settings.h.


Constructor & Destructor Documentation

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 }

Here is the call graph for this function:


Member Function Documentation

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  ) 

Definition at line 66 of file Settings.cpp.

00067 {
00068     record.zoom = zoom;
00069     zoom = z; 
00070     record.x = screenX; 
00071     record.y = screenY;
00072     zbState = iconState_normal; 
00073 }

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 }

Here is the call graph for this function:

GBool CSettings::canZoomBack (  ) 

Definition at line 122 of file Settings.cpp.

00123 {
00124     return (InvalidZoom != record.zoom);
00125 }

int CSettings::getZoomBackState (  )  const [inline]

Definition at line 154 of file Settings.h.

00154 { return zbState; }

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]

Definition at line 156 of file Settings.h.

00156 { return zoom; }

void CSettings::setZoom ( const double  z  )  [inline]

Definition at line 157 of file Settings.h.

00157 { zoom = z; }

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", &currentPage);
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 }

Here is the call graph for this function:

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 }

Here is the call graph for this function:

int CSettings::getRotate (  )  const [inline]

Definition at line 164 of file Settings.h.

00164 { return rotate; }

void CSettings::setRotate ( const int  r  )  [inline]

Definition at line 165 of file Settings.h.

00165 { rotate = r; }

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 }

Here is the call graph for this function:

int CSettings::getScreenX (  )  const [inline]

Definition at line 169 of file Settings.h.

00169 { return screenX; }

int CSettings::getScreenY (  )  const [inline]

Definition at line 170 of file Settings.h.

00170 { return screenY; }

int CSettings::getScreenWidth (  )  const [inline]

Definition at line 171 of file Settings.h.

00171 { return drawAreaWidth; }

int CSettings::getScreenHeight (  )  const [inline]

Definition at line 172 of file Settings.h.

00172 { return drawAreaHeight; }

void CSettings::setScreenX ( const int  x  )  [inline]

Definition at line 173 of file Settings.h.

00173 { screenX = x; }

void CSettings::setScreenY ( const int  y  )  [inline]

Definition at line 174 of file Settings.h.

00174 { screenY = y; }

void CSettings::moveScreenX ( const int  d  )  [inline]

Definition at line 175 of file Settings.h.

00175 { screenX += d; }

void CSettings::moveScreenY ( const int  d  )  [inline]

Definition at line 176 of file Settings.h.

00176 { screenY += d; }

void CSettings::setScreenPosition ( const int  nX,
const int  nY 
)

Definition at line 286 of file Settings.cpp.

00287 {
00288     screenX = nX; screenY = nY;
00289 }

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]

Definition at line 182 of file Settings.h.

00182 { return currentPage; }

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 }

Here is the call graph for this function:

int CSettings::getRenderDir (  )  const [inline]

Definition at line 186 of file Settings.h.

00186 { return renderDir; }

void CSettings::setRenderDir ( const int  d  )  [inline]

Definition at line 187 of file Settings.h.

00187 { renderDir =d ;  }

int CSettings::getMode (  )  const [inline]

Definition at line 190 of file Settings.h.

00190 { return mode; }

void CSettings::setMode ( const int  m  )  [inline]

Definition at line 191 of file Settings.h.

00191 { mode = m; }

GBool CSettings::isScribbleEnabled (  )  const [inline]

Definition at line 194 of file Settings.h.

00194 { return enableScb; }

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 }

Here is the call graph for this function:

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 }


Member Data Documentation

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.

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.

Definition at line 140 of file Settings.h.

Definition at line 141 of file Settings.h.


The documentation for this class was generated from the following files:

Generated on Wed Feb 4 18:26:34 2009 by  doxygen 1.5.6