download DirColsDlg.cpp
Language: C++
LOC: 271
Project Info
WinMerge
Server: SourceForge
Type: cvs
...erge\winmerge\WinMerge\Src\
   7zCommon.cpp
   7zCommon.h
   AboutDlg.cpp
   AboutDlg.h
   AppSerialize.cpp
   AppSerialize.h
   BCMenu.cpp
   BCMenu.h
   ByteComparator.cpp
   ByteComparator.h
   CCPrompt.cpp
   CCPrompt.h
   charsets.c
   charsets.h
   ChildFrm.cpp
   ChildFrm.h
   codepage.cpp
   codepage.h
   codepage_detect.cpp
   codepage_detect.h
   ColorButton.cpp
   ColorButton.h
   CompareOptions.h
   CompareStatisticsDlg.cpp
   CompareStatisticsDlg.h
   CompareStats.cpp
   CompareStats.h
   ConfigLog.cpp
   ConfigLog.h
   Diff.cpp
   DiffContext.cpp
   DiffContext.h
   DiffFileData.cpp
   DiffFileData.h
   DiffFileInfo.cpp
   DiffFileInfo.h
   DiffItem.cpp
   DiffItem.h
   DiffItemList.cpp
   DiffItemList.h
   DiffList.cpp
   DiffList.h
   diffmain.c
   DiffThread.cpp
   DiffThread.h
   DiffViewBar.cpp
   DiffViewBar.h
   DiffWrapper.cpp
   DiffWrapper.h
   Dir.cpp
   DirActions.cpp
   DirCmpReport.cpp
   DirCmpReport.h
   DirCmpReportDlg.cpp
   DirCmpReportDlg.h
   DirColsDlg.cpp
   DirColsDlg.h
   DirCompProgressDlg.cpp
   DirCompProgressDlg.h
   DirDoc.cpp
   DirDoc.h
   DirFrame.cpp
   DirFrame.h
   DirReportTypes.h
   DirScan.cpp
   DirScan.h
   DirView.cpp
   DirView.h
   DirViewColHandler.cpp
   DirViewColItems.cpp
   DirViewColItems.h
   dlgutil.cpp
   dlgutil.h
   dllpstub.cpp
   dllpstub.h
   dllver.cpp
   dllver.h
   EditorFilepathBar.cpp
   EditorFilepathBar.h
   Exceptions.h
   FileActionScript.cpp
   FileActionScript.h
   FileFilterHelper.cpp
   FileFilterHelper.h
   FileFilterMgr.cpp
   FileFilterMgr.h
   FileFiltersDlg.cpp
   FileFiltersDlg.h
   FileInfo.cpp
   FileInfo.h
   FileLocation.h
   FilepathEdit.cpp
   FilepathEdit.h
   files.cpp
   files.h
   FileTextEncoding.cpp
   FileTextEncoding.h
   FileTextStats.h
   FileTransform.cpp
   FileTransform.h
   GhostTextBuffer.cpp
   GhostTextBuffer.h
   GhostTextView.cpp
   GhostTextView.h
   IAbortable.h
   IntToIntMap.h
   IOptionsPanel.h
   LoadSaveCodepageDlg.cpp
   LoadSaveCodepageDlg.h
   locality.cpp
   locality.h
   LocationBar.cpp
   LocationBar.h
   LocationView.cpp
   LocationView.h
   MainFrm.cpp
   MainFrm.h
   markdown.cpp
   markdown.h
   Merge.cpp
   Merge.dsp
   Merge.h
   Merge.rc
   MergeArgs.cpp
   MergeDiffDetailView.cpp
   MergeDiffDetailView.h
   MergeDoc.cpp
   MergeDoc.h
   MergeDocEncoding.cpp
   MergeDocLineDiffs.cpp
   MergeEditStatus.h
   MergeEditView.cpp
   MergeEditView.h
   MergeLineFlags.h
   MovedBlocks.cpp
   OpenDlg.cpp
   OpenDlg.h
   OptionsDef.h
   OptionsInit.cpp
   OutputDlg.cpp
   OutputDlg.h
   PatchDlg.cpp
   PatchDlg.h
   PatchTool.cpp
   PatchTool.h
   PathContext.cpp
   PathContext.h
   paths.cpp
   paths.h
   PluginManager.cpp
   PluginManager.h
   Plugins.cpp
   Plugins.h
   ProjectFile.cpp
   ProjectFile.h
   ProjectFilePathsDlg.cpp
   ProjectFilePathsDlg.h
   PropArchive.cpp
   PropArchive.h
   PropCodepage.cpp
   PropCodepage.h
   PropColors.cpp
   PropColors.h
   PropCompare.cpp
   PropCompare.h
   PropEditor.cpp
   PropEditor.h
   PropGeneral.cpp
   PropGeneral.h
   PropLineFilter.cpp
   PropLineFilter.h
   PropRegistry.cpp
   PropRegistry.h
   PropSyntaxColors.cpp
   PropSyntaxColors.h
   PropTextColors.cpp
   PropTextColors.h
   PropVss.cpp
   PropVss.h
   resource.h
   SaveClosingDlg.cpp
   SaveClosingDlg.h
   SelectUnpackerDlg.cpp
   SelectUnpackerDlg.h
   SetResourceVersions.bat
   SetResourceVersions.wsf
   SharedFilterDlg.cpp
   SharedFilterDlg.h
   SourceControl.cpp
   Splash.cpp
   Splash.h
   ssapi.cpp
   ssapi.h
   ssauto.h
   STACK.C
   StdAfx.cpp
   StdAfx.h
   stringdiffs.cpp
   stringdiffs.h
   stringdiffsi.h
   SyntaxColors.cpp
   SyntaxColors.h
   TestFilterDlg.cpp
   TestFilterDlg.h
   ViewableWhitespace.cpp
   ViewableWhitespace.h
   VSSHelper.cpp
   VSSHelper.h
   VssPrompt.cpp
   VssPrompt.h
   WaitStatusCursor.cpp
   WaitStatusCursor.h
   winnt_supp.h
   WMGotoDlg.cpp
   WMGotoDlg.h
   XmlDoc.cpp
   XmlDoc.h

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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/** 
 * @file  DirColsDlg.cpp
 *
 * @brief Implementation file for CDirColsDlg
 *
 * @date  Created: 2003-08-19
 */
// RCS ID line follows -- this is updated by CVS
// $Id: DirColsDlg.cpp,v 1.9 2006/07/19 06:32:01 kimmov Exp $


#include "stdafx.h"
#include "merge.h"
#include "DirColsDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDirColsDlg dialog


CDirColsDlg::CDirColsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDirColsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDirColsDlg)
	m_bReset = FALSE;
	m_bFromKeyboard = FALSE;
	//}}AFX_DATA_INIT
}

void CDirColsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDirColsDlg)
	DDX_Control(pDX, IDC_LIST_SHOW, m_list_show);
	DDX_Control(pDX, IDC_LIST_HIDE, m_list_hide);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDirColsDlg, CDialog)
	//{{AFX_MSG_MAP(CDirColsDlg)
	ON_BN_CLICKED(IDC_UP, OnUp)
	ON_BN_CLICKED(IDC_DOWN, OnDown)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	ON_BN_CLICKED(IDC_COLDLG_DEFAULTS, OnDefaults)
	//}}AFX_MSG_MAP
	ON_LBN_SELCHANGE(IDC_LIST_SHOW, OnLbnSelchangeListShow)
	ON_LBN_SELCHANGE(IDC_LIST_HIDE, OnLbnSelchangeListHide)
	ON_LBN_DBLCLK(IDC_LIST_SHOW, OnLbnDblclkListShow)
	ON_LBN_DBLCLK(IDC_LIST_HIDE, OnLbnDblclkListHide)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDirColsDlg message handlers

/**
 * @brief Dialog initialisation. Load column lists.
 */
BOOL CDirColsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

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

/**
 * @brief Load listboxes on screen from column array
 */
void CDirColsDlg::LoadLists()
{
	for (int i=0; i<m_cols.GetSize(); ++i)
	{
		const column & c = m_cols[i];
		CListBox * list = (c.phy_col >= 0) ? &m_list_show : &m_list_hide;
		int x = list->AddString(m_cols[i].name);
		list->SetItemData(x, c.log_col);
	}
	SortArrayToLogicalOrder();
	UpdateEnables();
}

/**
 * @brief Load listboxes on screen from defaults column array
 */
void CDirColsDlg::LoadDefLists()
{
	for (int i=0; i<m_cols.GetSize(); ++i)
	{
		const column & c = m_defCols[i];
		CListBox * list = (c.phy_col >= 0) ? &m_list_show : &m_list_hide;
		int x = list->AddString(m_defCols[i].name);
		list->SetItemData(x, c.log_col);
	}
	SortArrayToLogicalOrder();
	UpdateEnables();
}

/**
 * @brief Sort m_cols so that it is in logical column order.
 */
void CDirColsDlg::SortArrayToLogicalOrder()
{
	qsort(m_cols.GetData(), m_cols.GetSize(), sizeof(m_cols[0]), &cmpcols);
}

int __cdecl CDirColsDlg::cmpcols(const void * el1, const void * el2)
{
	const column * col1 = reinterpret_cast<const column *>(el1);
	const column * col2 = reinterpret_cast<const column *>(el2);
	return col1->log_col - col2->log_col;
}

/**
 * @brief Move selected items up (in show list)
 */
void CDirColsDlg::OnUp()
{
	CHScrollListBox * list = &m_list_show;
	// find the first item not selected
	int i=0;
	for (i=0; i<list->GetCount(); ++i)
	{
		if (!list->GetSel(i))
			break;
	}
	// continue down, moving up all selected items 
	for (++i; i<list->GetCount(); ++i)
	{
		if (list->GetSel(i))
		{
			int data = list->GetItemData(i);
			CString str;
			list->GetText(i, str);
			list->DeleteString(i);
			int inew = i-1;
			list->InsertString(inew, str);
			list->SetItemData(inew, data);
			if (m_bFromKeyboard) // If from keyboard, don't move selection anymore
			{
				list->SetSel(inew + 1);
				m_bFromKeyboard = FALSE;
			}
			else
				list->SetSel(inew);
		}
	}
}

/**
 * @brief Move selected items down (in show list)
 */
void CDirColsDlg::OnDown() 
{
	CHScrollListBox * list = &m_list_show;
	// find the lst item not selected
	int i=0;
	for (i=list->GetCount()-1; i>=0; --i)
	{
		if (!list->GetSel(i))
			break;
	}
	// continue down, moving up all selected items 
	for (--i; i>=0; --i)
	{
		if (list->GetSel(i))
		{
			int data = list->GetItemData(i);
			CString str;
			list->GetText(i, str);
			list->DeleteString(i);
			int inew = i+1;
			list->InsertString(inew, str);
			list->SetItemData(inew, data);
			if (m_bFromKeyboard) // If from keyboard, don't move selection anymore
			{
				list->SetSel(inew - 1);
				m_bFromKeyboard = FALSE;
			}
			else
				list->SetSel(inew);
		}
	}
}

/**
 * @brief Move selected items from hide list to show list
 */
void CDirColsDlg::OnAdd() 
{
	MoveItems(&m_list_hide, &m_list_show, false);
}

/**
 * @brief Move selected items from show list to hide list
 */
void CDirColsDlg::OnRemove() 
{
	MoveItems(&m_list_show, &m_list_hide, true);
}

/**
 * @brief Move selected items from list1 to list2, putting at top if top==true
 */
void CDirColsDlg::MoveItems(CHScrollListBox * list1, CHScrollListBox * list2, bool top)
{
	for (int i=0; i<list1->GetCount(); ++i)
	{
		if (list1->GetSel(i))
		{
			int data = list1->GetItemData(i);
			CString str;
			list1->GetText(i, str);
			list1->DeleteString(i);
			--i; // new item promoted to slot#i in list1, we need to check it next
			int inew = top ? 0 : list2->GetCount();
			list2->InsertString(inew, str);
			list2->SetItemData(inew, data);
			list2->SetSel(inew);
		}
	}
	UpdateEnables();
}

/**
 * @brief Enable/disable the Add/Remove buttons appropriately
 */
void CDirColsDlg::UpdateEnables()
{
	// TODO: We could enable/disable Up/Down buttons also, but
	// we'd have to trap selection events

	GetDlgItem(IDC_ADD)->EnableWindow(m_list_hide.GetCount() > 0);
	GetDlgItem(IDC_REMOVE)->EnableWindow(m_list_show.GetCount() > 0);
}

/**
 * @brief User clicked ok, so we update m_cols and close
 */
void CDirColsDlg::OnOK() 
{
	// Update all the data in m_cols according to layout on screen
	int i=0;
	for (i=0; i<m_list_show.GetCount(); ++i)
	{
		column * col1 = &m_cols[m_list_show.GetItemData(i)];
		col1->phy_col = i;
	}
	for (i=0; i<m_list_hide.GetCount(); ++i)
	{
		column * col1 = &m_cols[m_list_hide.GetItemData(i)];
		col1->phy_col = -1;
	}
	
	CDialog::OnOK();
}

/**
 * @brief Empty lists and load default columns and order.
 */
void CDirColsDlg::OnDefaults()
{
	m_bReset = TRUE;
	m_list_show.ResetContent();
	m_list_hide.ResetContent();
	LoadDefLists();
}

/**
 * @brief Update description when selected item changes.
 */
void CDirColsDlg::OnLbnSelchangeListShow()
{
	for (int i=0; i<m_list_show.GetCount(); ++i)
	{
		if (m_list_show.GetSel(i))
		{
			int data = m_list_show.GetItemData(i);
			CString str;
			
			int j=0;
			for (j = 0; j < m_cols.GetSize(); j++)
			{
				if (m_cols.GetAt(j).log_col == data)
					break;
			}
			GetDlgItem(IDC_COLDLG_DESC)->SetWindowText(m_cols[j].desc);
			break;
		}
	}
}

/**
 * @brief Update description when selected item changes.
 */
void CDirColsDlg::OnLbnSelchangeListHide()
{
	for (int i=0; i<m_list_hide.GetCount(); ++i)
	{
		if (m_list_hide.GetSel(i))
		{
			int data = m_list_hide.GetItemData(i);
			CString str;
			
			int j=0;
			for (j = 0; j < m_cols.GetSize(); j++)
			{
				if (m_cols.GetAt(j).log_col == data)
					break;
			}
			GetDlgItem(IDC_COLDLG_DESC)->SetWindowText(m_cols[j].desc);
			break;
		}
	}
}

/**
 * @brief Handle keyboard events.
 */
BOOL CDirColsDlg::PreTranslateMessage(MSG* pMsg)
{
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam != VK_CONTROL)
	{
		if (GetAsyncKeyState(VK_CONTROL))
		{
			HWND hwndFocus = 0;
			switch (pMsg->wParam)
			{
			case VK_LEFT:
				OnAdd();
				break;
			case VK_RIGHT:
				OnRemove();
				break;
			case VK_UP:
				m_bFromKeyboard = TRUE;
				OnUp();
				break;
			case VK_DOWN:
				m_bFromKeyboard = TRUE;
				OnDown();
				break;
			case VK_TAB:
				// When CTRL-TAB pressed, switch focus between listboxes
				hwndFocus = ::GetFocus();
				if (m_list_show.GetSafeHwnd() == hwndFocus)
				{
					m_list_hide.SetFocus();
				}
				else if (m_list_hide.GetSafeHwnd() == hwndFocus)
				{
					m_list_show.SetFocus();
				}
				break;
			}	
			return FALSE;
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}

/**
 * @brief Called when mouse is double-clicked over shown columns list.
 */
void CDirColsDlg::OnLbnDblclkListShow()
{
	OnRemove();
}

/**
 * @brief Called when mouse is double-clicked over hidden columns list.
 */
void CDirColsDlg::OnLbnDblclkListHide()
{
	OnAdd();
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us