summaryrefslogtreecommitdiff
path: root/Shutdown/ItemDlg.cpp
blob: 04c6264a437079b29f65866e6850502a0f1dbf03 (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// ItemDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ItemDlg.h"



/////////////////////////////////////////////////////////////////////////////
// CItemDlg dialog


CItemDlg::CItemDlg()
	: CDialogImplEx(IDD), CPersistPosWindow<CItemDlg>(_T("Item"))
{
	m_hIcon = ::LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDR_MAINFRAME));
	m_bCancel = false;
}


/////////////////////////////////////////////////////////////////////////////
// CItemDlg message handlers

//////////////////////////////////////////////////////////////////
// Since we can't really cancel the current component
// Set flag and wait till there's a chance to close

LRESULT CItemDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
{
	g_site.Fire_Cancel();
	m_bCancel = true;

	// Give a visual indication that request has been handled
	SetDlgItemText(IDCANCEL, _T("Cancelling..."));
	::EnableWindow(GetDlgItem(IDCANCEL), FALSE);

	return 0;
}

LRESULT CItemDlg::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{
	OnCancel(0, 0, NULL, bHandled);
	return 0;
}

//////////////////////////////////////////////////////////////////
// InitDialog (what more can I say)

LRESULT CItemDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{
	// Set the icon for this dialog.  
	SetIcon(m_hIcon, TRUE);		// Set big icon
	SetIcon(m_hIcon, FALSE);	// Set small icon


	// Create the small icon image list.
	m_ImageListSmall.Create(IDB_CHECKS,
			16,
			0,			// list won't grow
			RGB(255, 0, 255));
	
	// Set Mask color for Image Lists
	m_ImageListSmall.SetBkColor(CLR_NONE);

	m_ctlItems = GetDlgItem(IDC_ITEMS);

	// Associate the image lists with the list view control.
	m_ctlItems.SetImageList(m_ImageListSmall, LVSIL_SMALL);



	// We need at least one bogus column since we're using
	// report view

	LV_COLUMN lvC;      		// list view column structure

	// Now initialize the columns you will need.
	// Initialize the LV_COLUMN structure.
	// The mask specifies that the fmt, width, pszText, and subitem members
	// of the structure are valid.
	lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvC.fmt = LVCFMT_LEFT;  // left-align column
	lvC.cx = 200;            // width of column in pixels
	lvC.iSubItem = 0;
	lvC.pszText = "Item";
		
	if (m_ctlItems.InsertColumn(0, &lvC) == -1)
		return true;


	// Fill List Control
	// Get Names of Windows Components
	// string_array was passed in Create
	// Loop through Items and get the names for Dialog box
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) 
	{

		// If it's a Windows Component
		if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN)

			// If it's currently active
			if(g_aComponents[nCnt]->IsEnabled())

				// Add it's name
				m_ctlItems.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM,
				 					  nCnt, g_aComponents[nCnt]->GetName(), 0, 0, 0, nCnt);

	}
	
	// Try and hide the control as best we can
	m_ctlItems.SetBkColor(::GetSysColor(COLOR_3DFACE));
	m_ctlItems.SetTextBkColor(::GetSysColor(COLOR_3DFACE));
	

	// Make sure the column (although hidden from dlg template)
	// is the width of control

	RECT rect;
	m_ctlItems.GetClientRect(&rect);
	m_ctlItems.SetColumnWidth(0, rect.right);


	// See if we can get the Window Position
	if(!LoadPosition(_Module.m_settings))
	{
		// Move the Window to 50, 50
		GetWindowRect(&rect);
		MoveWindow(50, 50, rect.right - rect.left, rect.bottom - rect.top);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

LRESULT CItemDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	SavePosition(_Module.m_settings);
	return 0;
}

//////////////////////////////////////////////////////////////////
// Gives the item a pointer image and scrolls it into view

bool CItemDlg::SetCurrentItem(int nItem)
{
	// Setup Structures
	LV_ITEM lv;

	lv.mask = LVIF_IMAGE;
	lv.iSubItem = 0;
	lv.iItem = nItem;
	lv.iImage = 1;


	// Scroll to item
	m_ctlItems.EnsureVisible(nItem, false);

	// Give the item the right image
	return m_ctlItems.SetItem(&lv) ? true : false;
}

//////////////////////////////////////////////////////////////////
// Gives the item a tick or cross image depending on bState

bool CItemDlg::CheckOffItem(int nItem, bool bState /*= true*/)
{
	// Setup Structures
	LV_ITEM lv;

	lv.mask = LVIF_IMAGE;
	lv.iSubItem = 0;
	lv.iItem = nItem;
	lv.iImage = bState ? 2 : 3; //  Image 2 is tick, 3 is cross

	// Set right image for item
	return m_ctlItems.SetItem(&lv) ? true : false;

}

LRESULT CItemDlg::OnSetFocusItems(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	CancelItemSelection();
	return 0;
}


void CItemDlg::CancelItemSelection()
{
	// Deselect All
	for(int nCnt = 0; nCnt < m_ctlItems.GetItemCount(); nCnt ++)
		// Set right state for item
		ListView_SetItemState(m_ctlItems, nCnt, 0, (UINT)-1);

	GotoDlgCtrl(GetDlgItem(IDCANCEL));
}