forked from NOVACProject/MobileDOAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FluxPathListBox.cpp
73 lines (59 loc) · 1.73 KB
/
FluxPathListBox.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
#include "stdafx.h"
#include "fluxpathlistbox.h"
#include "DMSpec.h"
CFluxPathListBox::CFluxPathListBox(void)
{
m_parentWindow = nullptr;
}
CFluxPathListBox::~CFluxPathListBox(void)
{
}
BEGIN_MESSAGE_MAP(CFluxPathListBox, CListBox)
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
/* Show the context menu */
void CFluxPathListBox::OnContextMenu(CWnd* pWnd, CPoint point)
{
if(m_parentWindow == nullptr)
return;
CMenu menu;
VERIFY(menu.LoadMenu(IDR_FLUX_PATH_MENU));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != nullptr);
int selected = this->GetCurSel();
if(selected == LB_ERR){
/* no selection made */
pPopup->EnableMenuItem(ID_RELOAD_LOGFILE, MF_DISABLED | MF_GRAYED);
}else{
pPopup->EnableMenuItem(ID_RELOAD_LOGFILE, MF_ENABLED);
}
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, m_parentWindow);
}
void CFluxPathListBox::UpdateWidth(){
// Find the longest string in the list box.
CString str;
CSize sz;
int dx = 0;
TEXTMETRIC tm;
CDC* pDC = this->GetDC();
CFont* pFont = this->GetFont();
// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);
for (int i = 0; i < this->GetCount(); i++)
{
this->GetText(i, str);
sz = pDC->GetTextExtent(str);
// Add the avg width to prevent clipping
sz.cx += tm.tmAveCharWidth;
if (sz.cx > dx)
dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
this->ReleaseDC(pDC);
// Set the horizontal extent so every character of all strings
// can be scrolled to.
this->SetHorizontalExtent(dx);
}