-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark.cpp
100 lines (89 loc) · 3.54 KB
/
bookmark.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
////////////////////////////////////////////////////////////////////////////////
// bookmark.cpp
// David Bracewell
// 5/2001
////////////////////////////////////////////////////////////////////////////////
#include "bookmark.h"
vector<BOOKMARK> bookmarks;
unsigned int numOfBookmarks = 0;
////////////////////////////////////////////////////////////////////////////////
// NAME: readBookmarks
// ARGUMENTS: AnsiString FileName, name of ini file to write
// TMenuItem *parent, Parent to add menu items to
// RETURNS: NONE
// PURPOSE: read bookmark file and display in menu
////////////////////////////////////////////////////////////////////////////////
void readBookmarks(AnsiString FileName, TMenuItem *parent)
{
TIniFile *bmarkFile = new TIniFile( FileName );
int lpp, page;
BOOK_INFO book;
unsigned int TotalNumber;
//Read number of bookmarks
TotalNumber = bmarkFile->ReadInteger( "NUMBER","NUMBER",0);
for( unsigned int i = 0; i < TotalNumber; i++ )
{
book.title = bmarkFile->ReadString( IntToStr(i+1), "Caption", "" );
book.filename = bmarkFile->ReadString( IntToStr(i+1), "Filename", "");
lpp = bmarkFile->ReadInteger( IntToStr(i+1), "LPP", 0 );
page = bmarkFile->ReadInteger( IntToStr(i+1), "Page", 0 );
addBookmark( book, lpp, page, parent );
}
delete bmarkFile;
}
////////////////////////////////////////////////////////////////////////////////
// NAME: writeBookmarks
// ARGUMENTS: AnsiString FileName, name of ini file to write
// RETURNS: NONE
// PURPOSE: Save bookmarks to ini file
////////////////////////////////////////////////////////////////////////////////
void writeBookmarks(AnsiString FileName)
{
if( FileExists(FileName) )
DeleteFile( FileName );
TIniFile *bmarkFile = new TIniFile( FileName );
unsigned int TotalNumber = 0;
for( unsigned int i = 0; i < bookmarks.size(); i++ )
{
//if the menu exists
if( bookmarks[i].menu )
{
TotalNumber++;
bmarkFile->WriteString( IntToStr(TotalNumber), "Caption", bookmarks[i].menu->Caption );
bmarkFile->WriteString( IntToStr(TotalNumber), "Filename", bookmarks[i].filename );
bmarkFile->WriteInteger( IntToStr(TotalNumber), "LPP", bookmarks[i].lpp );
bmarkFile->WriteInteger( IntToStr(TotalNumber), "Page", bookmarks[i].pos );
}
}
bmarkFile->WriteInteger("NUMBER","NUMBER",TotalNumber);
delete bmarkFile;
}
////////////////////////////////////////////////////////////////////////////////
// NAME: addBookmark
// ARGUMENTS: BOOK_INFO &book, book to bookmark
// int lpp, the lines per page as displayed
// unsigned int page, page being displayed
// TMenuItem *parent, menu to add bookmark item to
// RETURNS: NONE
// PURPOSE: Create bookmark and display in menu
////////////////////////////////////////////////////////////////////////////////
void addBookmark( BOOK_INFO &book, int lpp, int page, TMenuItem *parent )
{
BOOKMARK newBookmark;
TMenuItem *newMenu = new TMenuItem(parent);
//Create Menu Item and add to menu
if( book.title.Pos( ", Page " ) > 0 )
newMenu->Caption = book.title;
else
newMenu->Caption = book.title + ", Page " +IntToStr(page+1);
numOfBookmarks++; //Increment Bookmark Counter
newMenu->Tag = numOfBookmarks;
parent->Add(newMenu);
//Setup bookmark info
newBookmark.menu = newMenu;
newBookmark.lpp = lpp;
newBookmark.pos = page;
newBookmark.filename = book.filename;
//add bookmark to list
bookmarks.push_back(newBookmark);
}