forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeviewedit.cpp
104 lines (92 loc) · 4.56 KB
/
codeviewedit.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
101
102
103
104
#include "stdafx.h"
#include "codeviewedit.h"
UserData::UserData()
: m_lineNum(0),
eTyping(eUnknown)
{
}
UserData::UserData(const int LineNo, const string &Desc, const string &Name, const WordType TypeIn)
: m_lineNum(LineNo),
m_keyName(Name),
eTyping(TypeIn),
m_description(Desc)
{
}
////////////////Preferences
CVPreference::CVPreference(
const COLORREF crTextColor,
const bool bDisplay, const string& szRegistryName,
const int szScintillaKeyword, const int IDC_ChkBox,
const int IDC_ColorBut, const int IDC_Font)
: m_rgb(crTextColor),
m_sciKeywordID(szScintillaKeyword),
IDC_ChkBox_code(IDC_ChkBox),
IDC_ColorBut_code(IDC_ColorBut),
IDC_Font_code(IDC_Font),
m_szRegName(szRegistryName),
m_highlight(bDisplay)
{
memset(&m_logFont, 0, sizeof(LOGFONT));
}
void CVPreference::SetCheckBox(const HWND hwndDlg)
{
SNDMSG(GetDlgItem(hwndDlg, IDC_ChkBox_code), BM_SETCHECK, m_highlight ? BST_CHECKED : BST_UNCHECKED, 0L);
}
void CVPreference::ReadCheckBox(const HWND hwndDlg)
{
m_highlight = !!IsDlgButtonChecked(hwndDlg, IDC_ChkBox_code);
}
void CVPreference::GetPrefsFromReg()
{
m_highlight = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName, m_highlight);
m_rgb = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_color", (int)m_rgb);
m_pointSize = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_FontPointSize", m_pointSize);
char bakupFaceName[LF_FACESIZE]; // to save the default font name, in case the corresponding registry entry is empty
strncpy_s(bakupFaceName, m_logFont.lfFaceName, sizeof(bakupFaceName)-1);
if (!g_pvp->m_settings.LoadValue(Settings::CVEdit, m_szRegName + "_Font", m_logFont.lfFaceName, LF_FACESIZE))
strncpy_s(m_logFont.lfFaceName, bakupFaceName, sizeof(m_logFont.lfFaceName)-1);
m_logFont.lfWeight = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_FontWeight", (int)m_logFont.lfWeight);
m_logFont.lfItalic = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_FontItalic", m_logFont.lfItalic);
m_logFont.lfUnderline = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_FontUnderline", m_logFont.lfUnderline);
m_logFont.lfStrikeOut = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, m_szRegName + "_FontStrike", m_logFont.lfStrikeOut);
}
void CVPreference::SetPrefsToReg()
{
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName, m_highlight);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_color", (int)m_rgb);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_FontPointSize", m_pointSize);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_Font", m_logFont.lfFaceName);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_FontWeight", (int)m_logFont.lfWeight);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_FontItalic", m_logFont.lfItalic);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_FontUnderline", m_logFont.lfUnderline);
g_pvp->m_settings.SaveValue(Settings::CVEdit, m_szRegName + "_FontStrike", m_logFont.lfStrikeOut);
}
void CVPreference::SetDefaultFont(const HWND hwndDlg)
{
LOGFONT* const plfont = &m_logFont;
memset(plfont, 0, sizeof(LOGFONT));
HFONT hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
if (hFont == nullptr)
hFont = (HFONT)GetStockObject(SYSTEM_FONT);
GetObject(hFont, sizeof(LOGFONT), plfont);
m_pointSize = 10;
GetHeightFromPointSize(hwndDlg);
}
int CVPreference::GetHeightFromPointSize(const HWND hwndDlg)
{
const CClientDC clientDC(hwndDlg);
const int Height = -MulDiv(m_pointSize, clientDC.GetDeviceCaps(LOGPIXELSY), 72);
return Height;
}
void CVPreference::ApplyPreferences(const HWND hwndScin, const CVPreference* DefaultPref)
{
const int id = m_sciKeywordID;
const bool HL = m_highlight;
SendMessage(hwndScin, SCI_STYLESETFORE, id, HL ? (LPARAM)m_rgb : (LPARAM)DefaultPref->m_rgb);
SendMessage(hwndScin, SCI_STYLESETFONT, id, HL ? (LPARAM)m_logFont.lfFaceName : (LPARAM)DefaultPref->m_logFont.lfFaceName);
SendMessage(hwndScin, SCI_STYLESETSIZE, id, HL ? (LPARAM)m_pointSize : (LPARAM)DefaultPref->m_pointSize);
SendMessage(hwndScin, SCI_STYLESETWEIGHT, id, HL ? (LPARAM)m_logFont.lfWeight : (LPARAM)DefaultPref->m_logFont.lfWeight);
SendMessage(hwndScin, SCI_STYLESETITALIC, id, HL ? (LPARAM)m_logFont.lfItalic : (LPARAM)DefaultPref->m_logFont.lfItalic);
SendMessage(hwndScin, SCI_STYLESETUNDERLINE, id, HL ? (LPARAM)m_logFont.lfUnderline : (LPARAM)DefaultPref->m_logFont.lfUnderline);
// There is no strike through in Scintilla (yet!)
}