summaryrefslogtreecommitdiffstats
path: root/src/windows/leash/CLeashDragListBox.cpp
blob: 27538843016c01e17c6d75caafbdcbd07f6e92c3 (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "stdafx.h"
#include "CLeashDragListBox.h"
#include "leash.h"
#include "lglobals.h"

/////////////////////////////////////////////////////////////////////////////
// CLeashDragListBox

//IMPLEMENT_DYNAMIC(CLeashDragListBox, CDragListBox)

CLeashDragListBox::CLeashDragListBox()
 :CDragListBox()
{

}

CLeashDragListBox::~CLeashDragListBox()
{
	DestroyWindow();
}

void CLeashDragListBox::initOtherListbox(CPropertyPage* pPage, CListBox* pOtherListBox)
{
	m_pPage = pPage;
	m_pOtherListBox = pOtherListBox;
}


void CLeashDragListBox::PreSubclassWindow()
{
	ASSERT(::IsWindow(m_hWnd));
	ASSERT((GetStyle() & (LBS_MULTIPLESEL|LBS_SORT)) == 0);
	MakeDragList(m_hWnd);
}

BOOL CLeashDragListBox::BeginDrag(CPoint pt)
{
	m_nLast = -1;
	DrawInsert(ItemFromPt(pt));
	return TRUE;
}

void CLeashDragListBox::CancelDrag(CPoint)
{
	DrawInsert(-1);
}

UINT CLeashDragListBox::Dragging(CPoint pt)
{
	int nIndex = ItemFromPt(pt, FALSE); // don't allow scrolling just yet
	DrawInsert(nIndex);
	ItemFromPt(pt);
	return (nIndex == LB_ERR) ? DL_STOPCURSOR : DL_MOVECURSOR;
}

void CLeashDragListBox::Dropped(int nSrcIndex, CPoint pt)
{
	ASSERT(!(GetStyle() & (LBS_OWNERDRAWFIXED|LBS_OWNERDRAWVARIABLE)) ||
		(GetStyle() & LBS_HASSTRINGS));

	DrawInsert(-1);
	int nDestIndex = ItemFromPt(pt);

	if (nSrcIndex == -1 || nDestIndex == -1)
		return;
	if (nDestIndex == nSrcIndex || nDestIndex == nSrcIndex+1)
		return; //didn't move
	CString str1, str2;
	DWORD_PTR dwData;
	GetText(nSrcIndex, str1);
	GetText(nDestIndex, str2);
	dwData = GetItemData(nSrcIndex);
	DeleteString(nSrcIndex);
	if (nSrcIndex < nDestIndex)
		nDestIndex--;
	nDestIndex = InsertString(nDestIndex, str1);
	SetItemData(nDestIndex, dwData);
	SetCurSel(nDestIndex);

	// Save new order of items to profile linklist
	char theSection[REALM_SZ + 1];
	const char*  adminServer[] = {"realms", theSection, ADMIN_SERVER, NULL};
	const char* Section[] = {"realms", theSection, NULL};
	const char** adminServ = adminServer;
	const char** section = Section;
	const char* valueSection[] = {"realms", theSection, "kdc", NULL};
	const char** valueSec = valueSection;
	CString theValue;
	CHAR hostServer[MAX_HSTNM];

	if (LB_ERR == m_pOtherListBox->GetText(m_pOtherListBox->GetCurSel(), theSection))
      ASSERT(0);

	long retval = pprofile_rename_section(CLeashApp::m_krbv5_profile,
										   section, NULL);
	if (retval)
	{
		MessageBox("Dropped::There is on error, profile will not be saved!!!\
                   \nIf this error persist, contact your administrator.",
				   "Leash", MB_OK);
		return;
	}

	retval = pprofile_add_relation(CLeashApp::m_krbv5_profile,
								    section, NULL);
	if (retval)
	{
		MessageBox("Dropped::There is on error, profile will not be saved!!!\
                    \nIf this error persist, contact your administrator.",
				   "Leash", MB_OK);
		return;
	}

	for (INT maxItems = GetCount(), item = 0; item < maxItems; item++)
	{
		GetText(item, hostServer);
		//strcpy(hostServer, theValue);

		if (strstr(hostServer, ADMIN_SERVER))
		{
			char* pAdmin = strchr(hostServer, ' ');
			if (pAdmin)
			  *pAdmin = 0;
			else
			  ASSERT(0);

			retval = pprofile_add_relation(CLeashApp::m_krbv5_profile,
											adminServ, hostServer);
			if (retval)
			{
				MessageBox("Dropped::There is on error, profile will not be saved!!!\
                           \nIf this error persist, contact your administrator.",
						   "Leash", MB_OK);
				return;
			}
		}

		retval = pprofile_add_relation(CLeashApp::m_krbv5_profile,
										valueSec, hostServer);
		if (retval)
		{
			MessageBox("Dropped::There is on error, profile will not be saved!!!\
                       \nIf this error persist, contact your administrator.",
					   "Leash", MB_OK);
			return;
		}
	}

	m_pPage->SetModified(TRUE);
}

void CLeashDragListBox::DrawInsert(int nIndex)
{
	if (m_nLast != nIndex)
	{
		DrawSingle(m_nLast);
		DrawSingle(nIndex);
		m_nLast = nIndex;
	}
}

void CLeashDragListBox::DrawSingle(int nIndex)
{
	if (nIndex == -1)
		return;
	CBrush* pBrush = CDC::GetHalftoneBrush();
	CRect rect;
	GetClientRect(&rect);
	CRgn rgn;
	rgn.CreateRectRgnIndirect(&rect);

	CDC* pDC = GetDC();
	// prevent drawing outside of listbox
	// this can happen at the top of the listbox since the listbox's DC is the
	// parent's DC
	pDC->SelectClipRgn(&rgn);

	GetItemRect(nIndex, &rect);
	rect.bottom = rect.top+2;
	rect.top -= 2;
	CBrush* pBrushOld = pDC->SelectObject(pBrush);
	//draw main line
	pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);

	pDC->SelectObject(pBrushOld);
	ReleaseDC(pDC);
}

/*
BOOL CLeashDragListBox::OnChildNotify(UINT nMessage, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	if (nMessage != m_nMsgDragList)
		return CListBox::OnChildNotify(nMessage, wParam, lParam, pResult);

	ASSERT(pResult != NULL);
	LPDRAGLISTINFO pInfo = (LPDRAGLISTINFO)lParam;
	ASSERT(pInfo != NULL);
	switch (pInfo->uNotification)
	{
	case DL_BEGINDRAG:
		*pResult = BeginDrag(pInfo->ptCursor);
		break;
	case DL_CANCELDRAG:
		CancelDrag(pInfo->ptCursor);
		break;
	case DL_DRAGGING:
		*pResult = Dragging(pInfo->ptCursor);
		break;
	case DL_DROPPED:
		Dropped(GetCurSel(), pInfo->ptCursor);
		break;
	}
	return TRUE;
}
*/