aboutsummaryrefslogtreecommitdiffstats
path: root/apps/windoze/CBuilder5/BibleCS/TModuleFonts.cpp
blob: 182147af78b91ce0925514add8f7b787ccb4562b (plain) (blame)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TModuleFonts.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RxCombos"
#pragma resource "*.dfm"

TModuleFonts *ModuleFonts;
//---------------------------------------------------------------------------
__fastcall TModuleFonts::TModuleFonts(TComponent* Owner)
	: TForm(Owner)
{
	// Put in the RXLib Font combobox component
	cmbFontSel = new TFontComboBox(this);
	cmbFontSel->Parent = pnlFontComboBox;
	cmbFontSel->Align = alClient;
//    cmbFontSel->Font->Height = -15;
    cmbFontSel->ParentFont = true;
    cmbFontSel->UseFonts = true;
    cmbFontSel->ItemIndex = cmbFontSel->Items->IndexOf("Arial");
    cmbFontSel->OnChange = cmbFontSelChange;
}
//---------------------------------------------------------------------------
void __fastcall TModuleFonts::FormShow(TObject *Sender)
{
    FillList();
}
//---------------------------------------------------------------------------
void __fastcall TModuleFonts::viewAllClick(TObject *Sender)
{
    viewAll->Checked = true;
    viewUnicode->Checked = false;
	FillList();
}
//---------------------------------------------------------------------------
void __fastcall TModuleFonts::viewUnicodeClick(TObject *Sender)
{
   	viewUnicode->Checked = true;
    viewAll->Checked = false;
    FillList();
}
//---------------------------------------------------------------------------

void TModuleFonts::FillList()
{
	BibleCSMGR *manager;
	ModMap::iterator mods;
	TTreeNode *node;
	string nodeName;
    manager = Form1->mainmgr;

	installTree->Items->Clear();

	if (!manager->configPath)
		return;

	for (mods = manager->Modules.begin(); mods != manager->Modules.end(); mods++) {
		for (node = installTree->Items->GetFirstNode(); node; node = node->getNextSibling()) {
			if (!strcmp(node->Text.c_str(), mods->second->Type())) {
				break;
			}
		}
        if(mods->second->isUnicode() || viewAll->Checked){
			if (!node) {	// Add Section
				if (!strncmp(mods->second->Type(), "Bibl", 4))	// If Bibles, put first in list
					node = installTree->Items->AddChildFirst(0, mods->second->Type());
				else	node = installTree->Items->AddChild(0, mods->second->Type());
			}
			nodeName = "[";
			nodeName += mods->second->Name();
			nodeName += "] ";
			nodeName += mods->second->Description();
			node = installTree->Items->AddChildObject(node, nodeName.c_str(), mods->second->Name());
        }
    }
	//for (node = installTree->Items->GetFirstNode(); node; node = node->getNextSibling())
	//	node->Expand(true);
	node = installTree->Items->GetFirstNode();
	if (node)
		node->MakeVisible();

}
void __fastcall TModuleFonts::installTreeChange(TObject *Sender,
      TTreeNode *Node)
{
    TTreeNode* currNode = installTree->Selected;
	BibleCSMGR *manager;
	AnsiString modName, fontName, fontSize;
    ModMap::iterator it;
    manager = Form1->mainmgr;

    if(!currNode->HasChildren){
    	modName = currNode->Text.SubString(2, currNode->Text.Pos("]") - 2);
		it = manager->Modules.find(modName.c_str());
		fontName = (*it).second->getConfigEntry("Font");
		fontSize = (*it).second->getConfigEntry("FontSize");
	   cmbFontSel->ItemIndex = cmbFontSel->Items->IndexOf(fontName);
	   cmbSizeSel->ItemIndex = cmbSizeSel->Items->IndexOf(fontSize);
    }

}
//---------------------------------------------------------------------------

void __fastcall TModuleFonts::cmbFontSelChange(TObject *Sender)
{
    TTreeNode* currNode = installTree->Selected;
	BibleCSMGR *manager = Form1->mainmgr;
    manager->applyUserPrefs();
	AnsiString modName;
    ModMap::iterator it;
   	if(currNode && !currNode->HasChildren){
       	modName = currNode->Text.SubString(2, currNode->Text.Pos("]") - 2);
		manager->getUserPrefs()[modName.c_str()]["Font"] = cmbFontSel->Items->Strings[cmbFontSel->ItemIndex].c_str();
		currNode->Selected = true;
	}
    manager->applyUserPrefs();
}
//---------------------------------------------------------------------------

void __fastcall TModuleFonts::btnResetClick(TObject *Sender)
{
	BibleCSMGR *manager;
	SectionMap::iterator sit;
	ModMap::iterator it;
	manager = Form1->mainmgr;

	sit = manager->getUserPrefs().Sections.begin();
	while(sit != manager->getUserPrefs().Sections.end())
	{
		(*sit).second.erase("Font");
		(*sit).second.erase("FontSize");
		sit++;
	}
	manager->applyUserPrefs();
}
//---------------------------------------------------------------------------


void __fastcall TModuleFonts::cmbSizeSelChange(TObject *Sender)
{
	TTreeNode* currNode = installTree->Selected;
	BibleCSMGR *manager = Form1->mainmgr;
	manager->applyUserPrefs();
	AnsiString modName;
	ModMap::iterator it;
	if(currNode && !currNode->HasChildren){
		modName = currNode->Text.SubString(2, currNode->Text.Pos("]") - 2);
		manager->getUserPrefs()[modName.c_str()]["FontSize"] = cmbSizeSel->Items->Strings[cmbSizeSel->ItemIndex].c_str();
		currNode->Selected = true;
	}
	manager->applyUserPrefs();	
	installTree->Focused();
}
//---------------------------------------------------------------------------