-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathOptionUI.cpp
110 lines (100 loc) · 3.34 KB
/
OptionUI.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
105
106
107
108
109
110
#include "OptionUI.h"
#include "OptionsCanvas.h"
#include <CUI/CUIWindow.h>
#include <CUI/CUIThemes.h>
#include <windowsx.h>
#include <LDExporter/LDExporterSetting.h>
#if defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_DEBUG)
#define new DEBUG_CLIENTBLOCK
#endif // _DEBUG
OptionUI::OptionUI(OptionsCanvas *parent, LDExporterSetting &setting):
m_canvas(parent),
m_hParentWnd(parent->getHWindow()),
m_hTooltip(NULL),
m_hTooltipControl(NULL),
m_shown(false),
m_setting(&setting),
m_leftGroupMargin(0),
m_rightGroupMargin(0),
m_bottomGroupMargin(0)
{
HDC hdc = GetDC(m_hParentWnd);
SIZE size;
GetTextExtentPoint32A(hdc, "X", 1, &size);
ReleaseDC(m_hParentWnd, hdc);
// The check box size is calculated based on the font height. The + 4 is
// for the space between the box and the text.
m_checkBoxWidth = size.cy + 4;
}
// Just call calcTextHeight using the setting's name, which is the most common
// text that we need the text height for.
int OptionUI::calcTextHeight(HDC hdc, int width, int &optimalWidth)
{
return CUIWindow::calcTextHeight(hdc, m_setting->getName(), width, optimalWidth);
}
void OptionUI::addTooltip(HWND hControl)
{
m_tooltipText = m_setting->getTooltip();
if (m_tooltipText.size() > 0)
{
m_hTooltip = CUIWindow::createWindowExUC(0, TOOLTIPS_CLASSUC,
NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP /*| TTS_BALLOON*/,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hControl, NULL, GetWindowInstance(hControl), NULL);
m_hTooltipControl = hControl;
}
}
void OptionUI::updateTooltip(void)
{
if (m_hTooltip != NULL)
{
TOOLINFOUC ti;
memset(&ti, 0, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.hwnd = m_hParentWnd;
ti.uId = (UINT_PTR)m_hTooltipControl;
ti.lpszText = &m_tooltipText[0];
// If you don't set the maximum width, multi-line messages aren't
// displayed, so set the maximum width to a somewhat reasonable value.
::SendMessage(m_hTooltip, TTM_SETMAXTIPWIDTH, 0, 800);
::SendMessage(m_hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
// Since the text might be long, leave the tooltip visible for about 32
// seconds. It's treated as a short, so 32,767 is the max.
::SendMessage(m_hTooltip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 32767);
}
}
void OptionUI::reset(void)
{
m_setting->reset();
valueChanged();
}
SIZE OptionUI::fitButtonText(
CUCSTR localText)
{
// "Browse..." needs 40 dialog units
RECT buttonRect = { 0, 0, 40, 14 };
SIZE englishSize;
SIZE localSize;
HDC hdc;
SIZE retValue;
// Convert the default size of a browse button in English to dialog units.
MapDialogRect(m_hParentWnd, &buttonRect);
hdc = GetDC(m_hParentWnd);
// Figure out the width of the English text, which we know the button size
// for.
GetTextExtentPoint32A(hdc, "Browse...", (int)strlen("Browse..."),
&englishSize);
// Figure out the width of the localized button text, which we don't know
// the button size for.
CUIWindow::getTextExtentPoint32UC(hdc, localText, (int)ucstrlen(localText),
&localSize);
// The button width is the known good width for "Browse...", minus the width
// of the string "Browse..." plus the width of the localized verison of
// "Browse...".
retValue.cx = buttonRect.right - englishSize.cx + localSize.cx;;
// The height is purely dependent of the dialog box units mapping.
retValue.cy = buttonRect.bottom;
ReleaseDC(m_hParentWnd, hdc);
return retValue;
}